]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.15.2-201406262058.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.15.2-201406262058.patch
CommitLineData
9ae98541
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index 9de9813..1462492 100644
3--- a/Documentation/dontdiff
4+++ b/Documentation/dontdiff
5@@ -3,9 +3,11 @@
6 *.bc
7 *.bin
8 *.bz2
9+*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13+*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17@@ -15,6 +17,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21+*.gmo
22 *.grep
23 *.grp
24 *.gz
25@@ -51,14 +54,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@@ -72,9 +78,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@@ -83,6 +91,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@@ -95,32 +104,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@@ -128,12 +145,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@@ -148,14 +168,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@@ -165,14 +185,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@@ -188,6 +209,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@@ -197,6 +220,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168+pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172@@ -206,7 +230,12 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176+randomize_layout_hash.h
177+randomize_layout_seed.h
178+realmode.lds
179+realmode.relocs
180 recordmcount
181+regdb.c
182 relocs
183 rlim_names.h
184 rn50_reg_safe.h
185@@ -216,8 +245,12 @@ series
186 setup
187 setup.bin
188 setup.elf
189+signing_key*
190+size_overflow_hash.h
191 sImage
192+slabinfo
193 sm_tbl*
194+sortextable
195 split-include
196 syscalltab.h
197 tables.c
198@@ -227,6 +260,7 @@ tftpboot.img
199 timeconst.h
200 times.h*
201 trix_boot.h
202+user_constants.h
203 utsrelease.h*
204 vdso-syms.lds
205 vdso.lds
206@@ -238,13 +272,17 @@ vdso32.lds
207 vdso32.so.dbg
208 vdso64.lds
209 vdso64.so.dbg
210+vdsox32.lds
211+vdsox32-syms.lds
212 version.h*
213 vmImage
214 vmlinux
215 vmlinux-*
216 vmlinux.aout
217 vmlinux.bin.all
218+vmlinux.bin.bz2
219 vmlinux.lds
220+vmlinux.relocs
221 vmlinuz
222 voffset.h
223 vsyscall.lds
224@@ -252,9 +290,12 @@ vsyscall_32.lds
225 wanxlfw.inc
226 uImage
227 unifdef
228+utsrelease.h
229 wakeup.bin
230 wakeup.elf
231 wakeup.lds
232+x509*
233 zImage*
234 zconf.hash.c
235+zconf.lex.c
236 zoffset.h
237diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
238index 30a8ad0d..2ed9efd 100644
239--- a/Documentation/kernel-parameters.txt
240+++ b/Documentation/kernel-parameters.txt
241@@ -1103,6 +1103,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
242 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
243 Default: 1024
244
245+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
246+ ignore grsecurity's /proc restrictions
247+
248+
249 hashdist= [KNL,NUMA] Large hashes allocated during boot
250 are distributed across NUMA nodes. Defaults on
251 for 64-bit NUMA, off otherwise.
252@@ -2099,6 +2103,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
253 noexec=on: enable non-executable mappings (default)
254 noexec=off: disable non-executable mappings
255
256+ nopcid [X86-64]
257+ Disable PCID (Process-Context IDentifier) even if it
258+ is supported by the processor.
259+
260 nosmap [X86]
261 Disable SMAP (Supervisor Mode Access Prevention)
262 even if it is supported by processor.
263@@ -2366,6 +2374,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
264 the specified number of seconds. This is to be used if
265 your oopses keep scrolling off the screen.
266
267+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
268+ virtualization environments that don't cope well with the
269+ expand down segment used by UDEREF on X86-32 or the frequent
270+ page table updates on X86-64.
271+
272+ pax_sanitize_slab=
273+ 0/1 to disable/enable slab object sanitization (enabled by
274+ default).
275+
276+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
277+
278+ pax_extra_latent_entropy
279+ Enable a very simple form of latent entropy extraction
280+ from the first 4GB of memory as the bootmem allocator
281+ passes the memory pages to the buddy allocator.
282+
283+ pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
284+ when the processor supports PCID.
285+
286 pcbit= [HW,ISDN]
287
288 pcd. [PARIDE]
289diff --git a/Makefile b/Makefile
290index 475e085..ae1de31 100644
291--- a/Makefile
292+++ b/Makefile
293@@ -246,7 +246,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
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 -Wno-array-bounds
301
302 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
303 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
304@@ -438,8 +440,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@@ -600,6 +602,72 @@ 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+RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
343+ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
344+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
345+endif
346+endif
347+ifdef CONFIG_CHECKER_PLUGIN
348+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
349+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
350+endif
351+endif
352+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
353+ifdef CONFIG_PAX_SIZE_OVERFLOW
354+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
355+endif
356+ifdef CONFIG_PAX_LATENT_ENTROPY
357+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
358+endif
359+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
360+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
361+endif
362+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
363+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
364+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
365+GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
366+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
367+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
368+ifeq ($(KBUILD_EXTMOD),)
369+gcc-plugins:
370+ $(Q)$(MAKE) $(build)=tools/gcc
371+else
372+gcc-plugins: ;
373+endif
374+else
375+gcc-plugins:
376+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
377+ $(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.))
378+else
379+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
380+endif
381+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
382+endif
383+endif
384+
385 include $(srctree)/arch/$(SRCARCH)/Makefile
386
387 ifdef CONFIG_READABLE_ASM
388@@ -816,7 +884,7 @@ export mod_sign_cmd
389
390
391 ifeq ($(KBUILD_EXTMOD),)
392-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
393+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
394
395 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
396 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
397@@ -865,6 +933,8 @@ endif
398
399 # The actual objects are generated when descending,
400 # make sure no implicit rule kicks in
401+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
402+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
403 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
404
405 # Handle descending into subdirectories listed in $(vmlinux-dirs)
406@@ -874,7 +944,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
407 # Error messages still appears in the original language
408
409 PHONY += $(vmlinux-dirs)
410-$(vmlinux-dirs): prepare scripts
411+$(vmlinux-dirs): gcc-plugins prepare scripts
412 $(Q)$(MAKE) $(build)=$@
413
414 define filechk_kernel.release
415@@ -917,10 +987,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
416
417 archprepare: archheaders archscripts prepare1 scripts_basic
418
419+prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
420+prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
421 prepare0: archprepare FORCE
422 $(Q)$(MAKE) $(build)=.
423
424 # All the preparing..
425+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
426 prepare: prepare0
427
428 # Generate some files
429@@ -1028,6 +1101,8 @@ all: modules
430 # using awk while concatenating to the final file.
431
432 PHONY += modules
433+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
434+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
435 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
436 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
437 @$(kecho) ' Building modules, stage 2.';
438@@ -1043,7 +1118,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
439
440 # Target to prepare building external modules
441 PHONY += modules_prepare
442-modules_prepare: prepare scripts
443+modules_prepare: gcc-plugins prepare scripts
444
445 # Target to install modules
446 PHONY += modules_install
447@@ -1109,7 +1184,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
448 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
449 signing_key.priv signing_key.x509 x509.genkey \
450 extra_certificates signing_key.x509.keyid \
451- signing_key.x509.signer include/linux/version.h
452+ signing_key.x509.signer include/linux/version.h \
453+ tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
454+ tools/gcc/size_overflow_plugin/size_overflow_hash.h \
455+ tools/gcc/randomize_layout_seed.h
456
457 # clean - Delete most, but leave enough to build external modules
458 #
459@@ -1148,7 +1226,7 @@ distclean: mrproper
460 @find $(srctree) $(RCS_FIND_IGNORE) \
461 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
462 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
463- -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
464+ -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
465 -type f -print | xargs rm -f
466
467
468@@ -1309,6 +1387,8 @@ PHONY += $(module-dirs) modules
469 $(module-dirs): crmodverdir $(objtree)/Module.symvers
470 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
471
472+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
473+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
474 modules: $(module-dirs)
475 @$(kecho) ' Building modules, stage 2.';
476 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
477@@ -1448,17 +1528,21 @@ else
478 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
479 endif
480
481-%.s: %.c prepare scripts FORCE
482+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
483+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
484+%.s: %.c gcc-plugins prepare scripts FORCE
485 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
486 %.i: %.c prepare scripts FORCE
487 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
488-%.o: %.c prepare scripts FORCE
489+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
490+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
491+%.o: %.c gcc-plugins prepare scripts FORCE
492 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
493 %.lst: %.c prepare scripts FORCE
494 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
495-%.s: %.S prepare scripts FORCE
496+%.s: %.S gcc-plugins prepare scripts FORCE
497 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
498-%.o: %.S prepare scripts FORCE
499+%.o: %.S gcc-plugins prepare scripts FORCE
500 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
501 %.symtypes: %.c prepare scripts FORCE
502 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
503@@ -1468,11 +1552,15 @@ endif
504 $(cmd_crmodverdir)
505 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
506 $(build)=$(build-dir)
507-%/: prepare scripts FORCE
508+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
509+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
510+%/: gcc-plugins prepare scripts FORCE
511 $(cmd_crmodverdir)
512 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
513 $(build)=$(build-dir)
514-%.ko: prepare scripts FORCE
515+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
516+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
517+%.ko: gcc-plugins prepare scripts FORCE
518 $(cmd_crmodverdir)
519 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
520 $(build)=$(build-dir) $(@:.ko=.o)
521diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
522index 78b03ef..da28a51 100644
523--- a/arch/alpha/include/asm/atomic.h
524+++ b/arch/alpha/include/asm/atomic.h
525@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
526 #define atomic_dec(v) atomic_sub(1,(v))
527 #define atomic64_dec(v) atomic64_sub(1,(v))
528
529+#define atomic64_read_unchecked(v) atomic64_read(v)
530+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
531+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
532+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
533+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
534+#define atomic64_inc_unchecked(v) atomic64_inc(v)
535+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
536+#define atomic64_dec_unchecked(v) atomic64_dec(v)
537+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
538+
539 #define smp_mb__before_atomic_dec() smp_mb()
540 #define smp_mb__after_atomic_dec() smp_mb()
541 #define smp_mb__before_atomic_inc() smp_mb()
542diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
543index ad368a9..fbe0f25 100644
544--- a/arch/alpha/include/asm/cache.h
545+++ b/arch/alpha/include/asm/cache.h
546@@ -4,19 +4,19 @@
547 #ifndef __ARCH_ALPHA_CACHE_H
548 #define __ARCH_ALPHA_CACHE_H
549
550+#include <linux/const.h>
551
552 /* Bytes per L1 (data) cache line. */
553 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
554-# define L1_CACHE_BYTES 64
555 # define L1_CACHE_SHIFT 6
556 #else
557 /* Both EV4 and EV5 are write-through, read-allocate,
558 direct-mapped, physical.
559 */
560-# define L1_CACHE_BYTES 32
561 # define L1_CACHE_SHIFT 5
562 #endif
563
564+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
565 #define SMP_CACHE_BYTES L1_CACHE_BYTES
566
567 #endif
568diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
569index 968d999..d36b2df 100644
570--- a/arch/alpha/include/asm/elf.h
571+++ b/arch/alpha/include/asm/elf.h
572@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
573
574 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
575
576+#ifdef CONFIG_PAX_ASLR
577+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
578+
579+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
580+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
581+#endif
582+
583 /* $0 is set by ld.so to a pointer to a function which might be
584 registered using atexit. This provides a mean for the dynamic
585 linker to call DT_FINI functions for shared libraries that have
586diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
587index aab14a0..b4fa3e7 100644
588--- a/arch/alpha/include/asm/pgalloc.h
589+++ b/arch/alpha/include/asm/pgalloc.h
590@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
591 pgd_set(pgd, pmd);
592 }
593
594+static inline void
595+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
596+{
597+ pgd_populate(mm, pgd, pmd);
598+}
599+
600 extern pgd_t *pgd_alloc(struct mm_struct *mm);
601
602 static inline void
603diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
604index d8f9b7e..f6222fa 100644
605--- a/arch/alpha/include/asm/pgtable.h
606+++ b/arch/alpha/include/asm/pgtable.h
607@@ -102,6 +102,17 @@ struct vm_area_struct;
608 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
609 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
610 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
611+
612+#ifdef CONFIG_PAX_PAGEEXEC
613+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
614+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
615+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
616+#else
617+# define PAGE_SHARED_NOEXEC PAGE_SHARED
618+# define PAGE_COPY_NOEXEC PAGE_COPY
619+# define PAGE_READONLY_NOEXEC PAGE_READONLY
620+#endif
621+
622 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
623
624 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
625diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
626index 2fd00b7..cfd5069 100644
627--- a/arch/alpha/kernel/module.c
628+++ b/arch/alpha/kernel/module.c
629@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
630
631 /* The small sections were sorted to the end of the segment.
632 The following should definitely cover them. */
633- gp = (u64)me->module_core + me->core_size - 0x8000;
634+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
635 got = sechdrs[me->arch.gotsecindex].sh_addr;
636
637 for (i = 0; i < n; i++) {
638diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
639index 1402fcc..0b1abd2 100644
640--- a/arch/alpha/kernel/osf_sys.c
641+++ b/arch/alpha/kernel/osf_sys.c
642@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
643 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
644
645 static unsigned long
646-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
647- unsigned long limit)
648+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
649+ unsigned long limit, unsigned long flags)
650 {
651 struct vm_unmapped_area_info info;
652+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
653
654 info.flags = 0;
655 info.length = len;
656@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
657 info.high_limit = limit;
658 info.align_mask = 0;
659 info.align_offset = 0;
660+ info.threadstack_offset = offset;
661 return vm_unmapped_area(&info);
662 }
663
664@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
665 merely specific addresses, but regions of memory -- perhaps
666 this feature should be incorporated into all ports? */
667
668+#ifdef CONFIG_PAX_RANDMMAP
669+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
670+#endif
671+
672 if (addr) {
673- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
674+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
675 if (addr != (unsigned long) -ENOMEM)
676 return addr;
677 }
678
679 /* Next, try allocating at TASK_UNMAPPED_BASE. */
680- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
681- len, limit);
682+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
683+
684 if (addr != (unsigned long) -ENOMEM)
685 return addr;
686
687 /* Finally, try allocating in low memory. */
688- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
689+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
690
691 return addr;
692 }
693diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
694index 98838a0..b304fb4 100644
695--- a/arch/alpha/mm/fault.c
696+++ b/arch/alpha/mm/fault.c
697@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
698 __reload_thread(pcb);
699 }
700
701+#ifdef CONFIG_PAX_PAGEEXEC
702+/*
703+ * PaX: decide what to do with offenders (regs->pc = fault address)
704+ *
705+ * returns 1 when task should be killed
706+ * 2 when patched PLT trampoline was detected
707+ * 3 when unpatched PLT trampoline was detected
708+ */
709+static int pax_handle_fetch_fault(struct pt_regs *regs)
710+{
711+
712+#ifdef CONFIG_PAX_EMUPLT
713+ int err;
714+
715+ do { /* PaX: patched PLT emulation #1 */
716+ unsigned int ldah, ldq, jmp;
717+
718+ err = get_user(ldah, (unsigned int *)regs->pc);
719+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
720+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
721+
722+ if (err)
723+ break;
724+
725+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
726+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
727+ jmp == 0x6BFB0000U)
728+ {
729+ unsigned long r27, addr;
730+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
731+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
732+
733+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
734+ err = get_user(r27, (unsigned long *)addr);
735+ if (err)
736+ break;
737+
738+ regs->r27 = r27;
739+ regs->pc = r27;
740+ return 2;
741+ }
742+ } while (0);
743+
744+ do { /* PaX: patched PLT emulation #2 */
745+ unsigned int ldah, lda, br;
746+
747+ err = get_user(ldah, (unsigned int *)regs->pc);
748+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
749+ err |= get_user(br, (unsigned int *)(regs->pc+8));
750+
751+ if (err)
752+ break;
753+
754+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
755+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
756+ (br & 0xFFE00000U) == 0xC3E00000U)
757+ {
758+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
759+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
760+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
761+
762+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
763+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
764+ return 2;
765+ }
766+ } while (0);
767+
768+ do { /* PaX: unpatched PLT emulation */
769+ unsigned int br;
770+
771+ err = get_user(br, (unsigned int *)regs->pc);
772+
773+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
774+ unsigned int br2, ldq, nop, jmp;
775+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
776+
777+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
778+ err = get_user(br2, (unsigned int *)addr);
779+ err |= get_user(ldq, (unsigned int *)(addr+4));
780+ err |= get_user(nop, (unsigned int *)(addr+8));
781+ err |= get_user(jmp, (unsigned int *)(addr+12));
782+ err |= get_user(resolver, (unsigned long *)(addr+16));
783+
784+ if (err)
785+ break;
786+
787+ if (br2 == 0xC3600000U &&
788+ ldq == 0xA77B000CU &&
789+ nop == 0x47FF041FU &&
790+ jmp == 0x6B7B0000U)
791+ {
792+ regs->r28 = regs->pc+4;
793+ regs->r27 = addr+16;
794+ regs->pc = resolver;
795+ return 3;
796+ }
797+ }
798+ } while (0);
799+#endif
800+
801+ return 1;
802+}
803+
804+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
805+{
806+ unsigned long i;
807+
808+ printk(KERN_ERR "PAX: bytes at PC: ");
809+ for (i = 0; i < 5; i++) {
810+ unsigned int c;
811+ if (get_user(c, (unsigned int *)pc+i))
812+ printk(KERN_CONT "???????? ");
813+ else
814+ printk(KERN_CONT "%08x ", c);
815+ }
816+ printk("\n");
817+}
818+#endif
819
820 /*
821 * This routine handles page faults. It determines the address,
822@@ -133,8 +251,29 @@ retry:
823 good_area:
824 si_code = SEGV_ACCERR;
825 if (cause < 0) {
826- if (!(vma->vm_flags & VM_EXEC))
827+ if (!(vma->vm_flags & VM_EXEC)) {
828+
829+#ifdef CONFIG_PAX_PAGEEXEC
830+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
831+ goto bad_area;
832+
833+ up_read(&mm->mmap_sem);
834+ switch (pax_handle_fetch_fault(regs)) {
835+
836+#ifdef CONFIG_PAX_EMUPLT
837+ case 2:
838+ case 3:
839+ return;
840+#endif
841+
842+ }
843+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
844+ do_group_exit(SIGKILL);
845+#else
846 goto bad_area;
847+#endif
848+
849+ }
850 } else if (!cause) {
851 /* Allow reads even for write-only mappings */
852 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
853diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
854index db3c541..a1acc89 100644
855--- a/arch/arm/Kconfig
856+++ b/arch/arm/Kconfig
857@@ -1877,7 +1877,7 @@ config ALIGNMENT_TRAP
858
859 config UACCESS_WITH_MEMCPY
860 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
861- depends on MMU
862+ depends on MMU && !PAX_MEMORY_UDEREF
863 default y if CPU_FEROCEON
864 help
865 Implement faster copy_to_user and clear_user methods for CPU
866@@ -2141,6 +2141,7 @@ config XIP_PHYS_ADDR
867 config KEXEC
868 bool "Kexec system call (EXPERIMENTAL)"
869 depends on (!SMP || PM_SLEEP_SMP)
870+ depends on !GRKERNSEC_KMEM
871 help
872 kexec is a system call that implements the ability to shutdown your
873 current kernel, and to start another kernel. It is like a reboot
874diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
875index 9a92fd7..3502a80 100644
876--- a/arch/arm/include/asm/atomic.h
877+++ b/arch/arm/include/asm/atomic.h
878@@ -18,17 +18,35 @@
879 #include <asm/barrier.h>
880 #include <asm/cmpxchg.h>
881
882+#ifdef CONFIG_GENERIC_ATOMIC64
883+#include <asm-generic/atomic64.h>
884+#endif
885+
886 #define ATOMIC_INIT(i) { (i) }
887
888 #ifdef __KERNEL__
889
890+#define _ASM_EXTABLE(from, to) \
891+" .pushsection __ex_table,\"a\"\n"\
892+" .align 3\n" \
893+" .long " #from ", " #to"\n" \
894+" .popsection"
895+
896 /*
897 * On ARM, ordinary assignment (str instruction) doesn't clear the local
898 * strex/ldrex monitor on some implementations. The reason we can use it for
899 * atomic_set() is the clrex or dummy strex done on every exception return.
900 */
901 #define atomic_read(v) (*(volatile int *)&(v)->counter)
902+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
903+{
904+ return v->counter;
905+}
906 #define atomic_set(v,i) (((v)->counter) = (i))
907+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
908+{
909+ v->counter = i;
910+}
911
912 #if __LINUX_ARM_ARCH__ >= 6
913
914@@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
915
916 prefetchw(&v->counter);
917 __asm__ __volatile__("@ atomic_add\n"
918+"1: ldrex %1, [%3]\n"
919+" adds %0, %1, %4\n"
920+
921+#ifdef CONFIG_PAX_REFCOUNT
922+" bvc 3f\n"
923+"2: bkpt 0xf103\n"
924+"3:\n"
925+#endif
926+
927+" strex %1, %0, [%3]\n"
928+" teq %1, #0\n"
929+" bne 1b"
930+
931+#ifdef CONFIG_PAX_REFCOUNT
932+"\n4:\n"
933+ _ASM_EXTABLE(2b, 4b)
934+#endif
935+
936+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
937+ : "r" (&v->counter), "Ir" (i)
938+ : "cc");
939+}
940+
941+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
942+{
943+ unsigned long tmp;
944+ int result;
945+
946+ prefetchw(&v->counter);
947+ __asm__ __volatile__("@ atomic_add_unchecked\n"
948 "1: ldrex %0, [%3]\n"
949 " add %0, %0, %4\n"
950 " strex %1, %0, [%3]\n"
951@@ -63,6 +111,43 @@ static inline int atomic_add_return(int i, atomic_t *v)
952 prefetchw(&v->counter);
953
954 __asm__ __volatile__("@ atomic_add_return\n"
955+"1: ldrex %1, [%3]\n"
956+" adds %0, %1, %4\n"
957+
958+#ifdef CONFIG_PAX_REFCOUNT
959+" bvc 3f\n"
960+" mov %0, %1\n"
961+"2: bkpt 0xf103\n"
962+"3:\n"
963+#endif
964+
965+" strex %1, %0, [%3]\n"
966+" teq %1, #0\n"
967+" bne 1b"
968+
969+#ifdef CONFIG_PAX_REFCOUNT
970+"\n4:\n"
971+ _ASM_EXTABLE(2b, 4b)
972+#endif
973+
974+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
975+ : "r" (&v->counter), "Ir" (i)
976+ : "cc");
977+
978+ smp_mb();
979+
980+ return result;
981+}
982+
983+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
984+{
985+ unsigned long tmp;
986+ int result;
987+
988+ smp_mb();
989+ prefetchw(&v->counter);
990+
991+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
992 "1: ldrex %0, [%3]\n"
993 " add %0, %0, %4\n"
994 " strex %1, %0, [%3]\n"
995@@ -84,6 +169,36 @@ static inline void atomic_sub(int i, atomic_t *v)
996
997 prefetchw(&v->counter);
998 __asm__ __volatile__("@ atomic_sub\n"
999+"1: ldrex %1, [%3]\n"
1000+" subs %0, %1, %4\n"
1001+
1002+#ifdef CONFIG_PAX_REFCOUNT
1003+" bvc 3f\n"
1004+"2: bkpt 0xf103\n"
1005+"3:\n"
1006+#endif
1007+
1008+" strex %1, %0, [%3]\n"
1009+" teq %1, #0\n"
1010+" bne 1b"
1011+
1012+#ifdef CONFIG_PAX_REFCOUNT
1013+"\n4:\n"
1014+ _ASM_EXTABLE(2b, 4b)
1015+#endif
1016+
1017+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1018+ : "r" (&v->counter), "Ir" (i)
1019+ : "cc");
1020+}
1021+
1022+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1023+{
1024+ unsigned long tmp;
1025+ int result;
1026+
1027+ prefetchw(&v->counter);
1028+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1029 "1: ldrex %0, [%3]\n"
1030 " sub %0, %0, %4\n"
1031 " strex %1, %0, [%3]\n"
1032@@ -103,11 +218,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1033 prefetchw(&v->counter);
1034
1035 __asm__ __volatile__("@ atomic_sub_return\n"
1036-"1: ldrex %0, [%3]\n"
1037-" sub %0, %0, %4\n"
1038+"1: ldrex %1, [%3]\n"
1039+" subs %0, %1, %4\n"
1040+
1041+#ifdef CONFIG_PAX_REFCOUNT
1042+" bvc 3f\n"
1043+" mov %0, %1\n"
1044+"2: bkpt 0xf103\n"
1045+"3:\n"
1046+#endif
1047+
1048 " strex %1, %0, [%3]\n"
1049 " teq %1, #0\n"
1050 " bne 1b"
1051+
1052+#ifdef CONFIG_PAX_REFCOUNT
1053+"\n4:\n"
1054+ _ASM_EXTABLE(2b, 4b)
1055+#endif
1056+
1057 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1058 : "r" (&v->counter), "Ir" (i)
1059 : "cc");
1060@@ -152,12 +281,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1061 __asm__ __volatile__ ("@ atomic_add_unless\n"
1062 "1: ldrex %0, [%4]\n"
1063 " teq %0, %5\n"
1064-" beq 2f\n"
1065-" add %1, %0, %6\n"
1066+" beq 4f\n"
1067+" adds %1, %0, %6\n"
1068+
1069+#ifdef CONFIG_PAX_REFCOUNT
1070+" bvc 3f\n"
1071+"2: bkpt 0xf103\n"
1072+"3:\n"
1073+#endif
1074+
1075 " strex %2, %1, [%4]\n"
1076 " teq %2, #0\n"
1077 " bne 1b\n"
1078-"2:"
1079+"4:"
1080+
1081+#ifdef CONFIG_PAX_REFCOUNT
1082+ _ASM_EXTABLE(2b, 4b)
1083+#endif
1084+
1085 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1086 : "r" (&v->counter), "r" (u), "r" (a)
1087 : "cc");
1088@@ -168,6 +309,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1089 return oldval;
1090 }
1091
1092+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1093+{
1094+ unsigned long oldval, res;
1095+
1096+ smp_mb();
1097+
1098+ do {
1099+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1100+ "ldrex %1, [%3]\n"
1101+ "mov %0, #0\n"
1102+ "teq %1, %4\n"
1103+ "strexeq %0, %5, [%3]\n"
1104+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1105+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1106+ : "cc");
1107+ } while (res);
1108+
1109+ smp_mb();
1110+
1111+ return oldval;
1112+}
1113+
1114 #else /* ARM_ARCH_6 */
1115
1116 #ifdef CONFIG_SMP
1117@@ -186,7 +349,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1118
1119 return val;
1120 }
1121+
1122+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1123+{
1124+ return atomic_add_return(i, v);
1125+}
1126+
1127 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1128+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1129+{
1130+ (void) atomic_add_return(i, v);
1131+}
1132
1133 static inline int atomic_sub_return(int i, atomic_t *v)
1134 {
1135@@ -201,6 +374,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1136 return val;
1137 }
1138 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1139+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1140+{
1141+ (void) atomic_sub_return(i, v);
1142+}
1143
1144 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1145 {
1146@@ -216,6 +393,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1147 return ret;
1148 }
1149
1150+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1151+{
1152+ return atomic_cmpxchg(v, old, new);
1153+}
1154+
1155 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1156 {
1157 int c, old;
1158@@ -229,13 +411,33 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1159 #endif /* __LINUX_ARM_ARCH__ */
1160
1161 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1162+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1163+{
1164+ return xchg(&v->counter, new);
1165+}
1166
1167 #define atomic_inc(v) atomic_add(1, v)
1168+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1169+{
1170+ atomic_add_unchecked(1, v);
1171+}
1172 #define atomic_dec(v) atomic_sub(1, v)
1173+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1174+{
1175+ atomic_sub_unchecked(1, v);
1176+}
1177
1178 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1179+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1180+{
1181+ return atomic_add_return_unchecked(1, v) == 0;
1182+}
1183 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1184 #define atomic_inc_return(v) (atomic_add_return(1, v))
1185+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1186+{
1187+ return atomic_add_return_unchecked(1, v);
1188+}
1189 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1190 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1191
1192@@ -251,6 +453,14 @@ typedef struct {
1193 long long counter;
1194 } atomic64_t;
1195
1196+#ifdef CONFIG_PAX_REFCOUNT
1197+typedef struct {
1198+ long long counter;
1199+} atomic64_unchecked_t;
1200+#else
1201+typedef atomic64_t atomic64_unchecked_t;
1202+#endif
1203+
1204 #define ATOMIC64_INIT(i) { (i) }
1205
1206 #ifdef CONFIG_ARM_LPAE
1207@@ -267,6 +477,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1208 return result;
1209 }
1210
1211+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1212+{
1213+ long long result;
1214+
1215+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1216+" ldrd %0, %H0, [%1]"
1217+ : "=&r" (result)
1218+ : "r" (&v->counter), "Qo" (v->counter)
1219+ );
1220+
1221+ return result;
1222+}
1223+
1224 static inline void atomic64_set(atomic64_t *v, long long i)
1225 {
1226 __asm__ __volatile__("@ atomic64_set\n"
1227@@ -275,6 +498,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1228 : "r" (&v->counter), "r" (i)
1229 );
1230 }
1231+
1232+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1233+{
1234+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1235+" strd %2, %H2, [%1]"
1236+ : "=Qo" (v->counter)
1237+ : "r" (&v->counter), "r" (i)
1238+ );
1239+}
1240 #else
1241 static inline long long atomic64_read(const atomic64_t *v)
1242 {
1243@@ -289,6 +521,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1244 return result;
1245 }
1246
1247+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1248+{
1249+ long long result;
1250+
1251+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1252+" ldrexd %0, %H0, [%1]"
1253+ : "=&r" (result)
1254+ : "r" (&v->counter), "Qo" (v->counter)
1255+ );
1256+
1257+ return result;
1258+}
1259+
1260 static inline void atomic64_set(atomic64_t *v, long long i)
1261 {
1262 long long tmp;
1263@@ -303,6 +548,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1264 : "r" (&v->counter), "r" (i)
1265 : "cc");
1266 }
1267+
1268+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1269+{
1270+ long long tmp;
1271+
1272+ prefetchw(&v->counter);
1273+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1274+"1: ldrexd %0, %H0, [%2]\n"
1275+" strexd %0, %3, %H3, [%2]\n"
1276+" teq %0, #0\n"
1277+" bne 1b"
1278+ : "=&r" (tmp), "=Qo" (v->counter)
1279+ : "r" (&v->counter), "r" (i)
1280+ : "cc");
1281+}
1282 #endif
1283
1284 static inline void atomic64_add(long long i, atomic64_t *v)
1285@@ -314,6 +574,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1286 __asm__ __volatile__("@ atomic64_add\n"
1287 "1: ldrexd %0, %H0, [%3]\n"
1288 " adds %Q0, %Q0, %Q4\n"
1289+" adcs %R0, %R0, %R4\n"
1290+
1291+#ifdef CONFIG_PAX_REFCOUNT
1292+" bvc 3f\n"
1293+"2: bkpt 0xf103\n"
1294+"3:\n"
1295+#endif
1296+
1297+" strexd %1, %0, %H0, [%3]\n"
1298+" teq %1, #0\n"
1299+" bne 1b"
1300+
1301+#ifdef CONFIG_PAX_REFCOUNT
1302+"\n4:\n"
1303+ _ASM_EXTABLE(2b, 4b)
1304+#endif
1305+
1306+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1307+ : "r" (&v->counter), "r" (i)
1308+ : "cc");
1309+}
1310+
1311+static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1312+{
1313+ long long result;
1314+ unsigned long tmp;
1315+
1316+ prefetchw(&v->counter);
1317+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1318+"1: ldrexd %0, %H0, [%3]\n"
1319+" adds %Q0, %Q0, %Q4\n"
1320 " adc %R0, %R0, %R4\n"
1321 " strexd %1, %0, %H0, [%3]\n"
1322 " teq %1, #0\n"
1323@@ -334,6 +625,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1324 __asm__ __volatile__("@ atomic64_add_return\n"
1325 "1: ldrexd %0, %H0, [%3]\n"
1326 " adds %Q0, %Q0, %Q4\n"
1327+" adcs %R0, %R0, %R4\n"
1328+
1329+#ifdef CONFIG_PAX_REFCOUNT
1330+" bvc 3f\n"
1331+" mov %0, %1\n"
1332+" mov %H0, %H1\n"
1333+"2: bkpt 0xf103\n"
1334+"3:\n"
1335+#endif
1336+
1337+" strexd %1, %0, %H0, [%3]\n"
1338+" teq %1, #0\n"
1339+" bne 1b"
1340+
1341+#ifdef CONFIG_PAX_REFCOUNT
1342+"\n4:\n"
1343+ _ASM_EXTABLE(2b, 4b)
1344+#endif
1345+
1346+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1347+ : "r" (&v->counter), "r" (i)
1348+ : "cc");
1349+
1350+ smp_mb();
1351+
1352+ return result;
1353+}
1354+
1355+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1356+{
1357+ long long result;
1358+ unsigned long tmp;
1359+
1360+ smp_mb();
1361+
1362+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1363+"1: ldrexd %0, %H0, [%3]\n"
1364+" adds %Q0, %Q0, %Q4\n"
1365 " adc %R0, %R0, %R4\n"
1366 " strexd %1, %0, %H0, [%3]\n"
1367 " teq %1, #0\n"
1368@@ -356,6 +685,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1369 __asm__ __volatile__("@ atomic64_sub\n"
1370 "1: ldrexd %0, %H0, [%3]\n"
1371 " subs %Q0, %Q0, %Q4\n"
1372+" sbcs %R0, %R0, %R4\n"
1373+
1374+#ifdef CONFIG_PAX_REFCOUNT
1375+" bvc 3f\n"
1376+"2: bkpt 0xf103\n"
1377+"3:\n"
1378+#endif
1379+
1380+" strexd %1, %0, %H0, [%3]\n"
1381+" teq %1, #0\n"
1382+" bne 1b"
1383+
1384+#ifdef CONFIG_PAX_REFCOUNT
1385+"\n4:\n"
1386+ _ASM_EXTABLE(2b, 4b)
1387+#endif
1388+
1389+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1390+ : "r" (&v->counter), "r" (i)
1391+ : "cc");
1392+}
1393+
1394+static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1395+{
1396+ long long result;
1397+ unsigned long tmp;
1398+
1399+ prefetchw(&v->counter);
1400+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1401+"1: ldrexd %0, %H0, [%3]\n"
1402+" subs %Q0, %Q0, %Q4\n"
1403 " sbc %R0, %R0, %R4\n"
1404 " strexd %1, %0, %H0, [%3]\n"
1405 " teq %1, #0\n"
1406@@ -376,16 +736,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1407 __asm__ __volatile__("@ atomic64_sub_return\n"
1408 "1: ldrexd %0, %H0, [%3]\n"
1409 " subs %Q0, %Q0, %Q4\n"
1410-" sbc %R0, %R0, %R4\n"
1411+" sbcs %R0, %R0, %R4\n"
1412+
1413+#ifdef CONFIG_PAX_REFCOUNT
1414+" bvc 3f\n"
1415+" mov %0, %1\n"
1416+" mov %H0, %H1\n"
1417+"2: bkpt 0xf103\n"
1418+"3:\n"
1419+#endif
1420+
1421 " strexd %1, %0, %H0, [%3]\n"
1422 " teq %1, #0\n"
1423 " bne 1b"
1424+
1425+#ifdef CONFIG_PAX_REFCOUNT
1426+"\n4:\n"
1427+ _ASM_EXTABLE(2b, 4b)
1428+#endif
1429+
1430 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1431 : "r" (&v->counter), "r" (i)
1432 : "cc");
1433
1434- smp_mb();
1435-
1436 return result;
1437 }
1438
1439@@ -415,6 +788,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1440 return oldval;
1441 }
1442
1443+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1444+ long long new)
1445+{
1446+ long long oldval;
1447+ unsigned long res;
1448+
1449+ smp_mb();
1450+
1451+ do {
1452+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1453+ "ldrexd %1, %H1, [%3]\n"
1454+ "mov %0, #0\n"
1455+ "teq %1, %4\n"
1456+ "teqeq %H1, %H4\n"
1457+ "strexdeq %0, %5, %H5, [%3]"
1458+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1459+ : "r" (&ptr->counter), "r" (old), "r" (new)
1460+ : "cc");
1461+ } while (res);
1462+
1463+ smp_mb();
1464+
1465+ return oldval;
1466+}
1467+
1468 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1469 {
1470 long long result;
1471@@ -440,21 +838,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1472 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1473 {
1474 long long result;
1475- unsigned long tmp;
1476+ u64 tmp;
1477
1478 smp_mb();
1479 prefetchw(&v->counter);
1480
1481 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1482-"1: ldrexd %0, %H0, [%3]\n"
1483-" subs %Q0, %Q0, #1\n"
1484-" sbc %R0, %R0, #0\n"
1485+"1: ldrexd %1, %H1, [%3]\n"
1486+" subs %Q0, %Q1, #1\n"
1487+" sbcs %R0, %R1, #0\n"
1488+
1489+#ifdef CONFIG_PAX_REFCOUNT
1490+" bvc 3f\n"
1491+" mov %Q0, %Q1\n"
1492+" mov %R0, %R1\n"
1493+"2: bkpt 0xf103\n"
1494+"3:\n"
1495+#endif
1496+
1497 " teq %R0, #0\n"
1498-" bmi 2f\n"
1499+" bmi 4f\n"
1500 " strexd %1, %0, %H0, [%3]\n"
1501 " teq %1, #0\n"
1502 " bne 1b\n"
1503-"2:"
1504+"4:\n"
1505+
1506+#ifdef CONFIG_PAX_REFCOUNT
1507+ _ASM_EXTABLE(2b, 4b)
1508+#endif
1509+
1510 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1511 : "r" (&v->counter)
1512 : "cc");
1513@@ -478,13 +890,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1514 " teq %0, %5\n"
1515 " teqeq %H0, %H5\n"
1516 " moveq %1, #0\n"
1517-" beq 2f\n"
1518+" beq 4f\n"
1519 " adds %Q0, %Q0, %Q6\n"
1520-" adc %R0, %R0, %R6\n"
1521+" adcs %R0, %R0, %R6\n"
1522+
1523+#ifdef CONFIG_PAX_REFCOUNT
1524+" bvc 3f\n"
1525+"2: bkpt 0xf103\n"
1526+"3:\n"
1527+#endif
1528+
1529 " strexd %2, %0, %H0, [%4]\n"
1530 " teq %2, #0\n"
1531 " bne 1b\n"
1532-"2:"
1533+"4:\n"
1534+
1535+#ifdef CONFIG_PAX_REFCOUNT
1536+ _ASM_EXTABLE(2b, 4b)
1537+#endif
1538+
1539 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1540 : "r" (&v->counter), "r" (u), "r" (a)
1541 : "cc");
1542@@ -497,10 +921,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1543
1544 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1545 #define atomic64_inc(v) atomic64_add(1LL, (v))
1546+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1547 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1548+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1549 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1550 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1551 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1552+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1553 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1554 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1555 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1556diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1557index 2f59f74..1594659 100644
1558--- a/arch/arm/include/asm/barrier.h
1559+++ b/arch/arm/include/asm/barrier.h
1560@@ -63,7 +63,7 @@
1561 do { \
1562 compiletime_assert_atomic_type(*p); \
1563 smp_mb(); \
1564- ACCESS_ONCE(*p) = (v); \
1565+ ACCESS_ONCE_RW(*p) = (v); \
1566 } while (0)
1567
1568 #define smp_load_acquire(p) \
1569diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1570index 75fe66b..ba3dee4 100644
1571--- a/arch/arm/include/asm/cache.h
1572+++ b/arch/arm/include/asm/cache.h
1573@@ -4,8 +4,10 @@
1574 #ifndef __ASMARM_CACHE_H
1575 #define __ASMARM_CACHE_H
1576
1577+#include <linux/const.h>
1578+
1579 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1580-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1581+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1582
1583 /*
1584 * Memory returned by kmalloc() may be used for DMA, so we must make
1585@@ -24,5 +26,6 @@
1586 #endif
1587
1588 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1589+#define __read_only __attribute__ ((__section__(".data..read_only")))
1590
1591 #endif
1592diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1593index 8b8b616..d973d24 100644
1594--- a/arch/arm/include/asm/cacheflush.h
1595+++ b/arch/arm/include/asm/cacheflush.h
1596@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1597 void (*dma_unmap_area)(const void *, size_t, int);
1598
1599 void (*dma_flush_range)(const void *, const void *);
1600-};
1601+} __no_const;
1602
1603 /*
1604 * Select the calling method
1605diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1606index 5233151..87a71fa 100644
1607--- a/arch/arm/include/asm/checksum.h
1608+++ b/arch/arm/include/asm/checksum.h
1609@@ -37,7 +37,19 @@ __wsum
1610 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1611
1612 __wsum
1613-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1614+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1615+
1616+static inline __wsum
1617+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1618+{
1619+ __wsum ret;
1620+ pax_open_userland();
1621+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1622+ pax_close_userland();
1623+ return ret;
1624+}
1625+
1626+
1627
1628 /*
1629 * Fold a partial checksum without adding pseudo headers
1630diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1631index abb2c37..96db950 100644
1632--- a/arch/arm/include/asm/cmpxchg.h
1633+++ b/arch/arm/include/asm/cmpxchg.h
1634@@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1635
1636 #define xchg(ptr,x) \
1637 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1638+#define xchg_unchecked(ptr,x) \
1639+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1640
1641 #include <asm-generic/cmpxchg-local.h>
1642
1643diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1644index 6ddbe44..b5e38b1 100644
1645--- a/arch/arm/include/asm/domain.h
1646+++ b/arch/arm/include/asm/domain.h
1647@@ -48,18 +48,37 @@
1648 * Domain types
1649 */
1650 #define DOMAIN_NOACCESS 0
1651-#define DOMAIN_CLIENT 1
1652 #ifdef CONFIG_CPU_USE_DOMAINS
1653+#define DOMAIN_USERCLIENT 1
1654+#define DOMAIN_KERNELCLIENT 1
1655 #define DOMAIN_MANAGER 3
1656+#define DOMAIN_VECTORS DOMAIN_USER
1657 #else
1658+
1659+#ifdef CONFIG_PAX_KERNEXEC
1660 #define DOMAIN_MANAGER 1
1661+#define DOMAIN_KERNEXEC 3
1662+#else
1663+#define DOMAIN_MANAGER 1
1664+#endif
1665+
1666+#ifdef CONFIG_PAX_MEMORY_UDEREF
1667+#define DOMAIN_USERCLIENT 0
1668+#define DOMAIN_UDEREF 1
1669+#define DOMAIN_VECTORS DOMAIN_KERNEL
1670+#else
1671+#define DOMAIN_USERCLIENT 1
1672+#define DOMAIN_VECTORS DOMAIN_USER
1673+#endif
1674+#define DOMAIN_KERNELCLIENT 1
1675+
1676 #endif
1677
1678 #define domain_val(dom,type) ((type) << (2*(dom)))
1679
1680 #ifndef __ASSEMBLY__
1681
1682-#ifdef CONFIG_CPU_USE_DOMAINS
1683+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1684 static inline void set_domain(unsigned val)
1685 {
1686 asm volatile(
1687@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1688 isb();
1689 }
1690
1691-#define modify_domain(dom,type) \
1692- do { \
1693- struct thread_info *thread = current_thread_info(); \
1694- unsigned int domain = thread->cpu_domain; \
1695- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1696- thread->cpu_domain = domain | domain_val(dom, type); \
1697- set_domain(thread->cpu_domain); \
1698- } while (0)
1699-
1700+extern void modify_domain(unsigned int dom, unsigned int type);
1701 #else
1702 static inline void set_domain(unsigned val) { }
1703 static inline void modify_domain(unsigned dom, unsigned type) { }
1704diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1705index f4b46d3..abc9b2b 100644
1706--- a/arch/arm/include/asm/elf.h
1707+++ b/arch/arm/include/asm/elf.h
1708@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1709 the loader. We need to make sure that it is out of the way of the program
1710 that it will "exec", and that there is sufficient room for the brk. */
1711
1712-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1713+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1714+
1715+#ifdef CONFIG_PAX_ASLR
1716+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1717+
1718+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1719+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1720+#endif
1721
1722 /* When the program starts, a1 contains a pointer to a function to be
1723 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1724@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1725 extern void elf_set_personality(const struct elf32_hdr *);
1726 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1727
1728-struct mm_struct;
1729-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1730-#define arch_randomize_brk arch_randomize_brk
1731-
1732 #ifdef CONFIG_MMU
1733 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1734 struct linux_binprm;
1735diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1736index de53547..52b9a28 100644
1737--- a/arch/arm/include/asm/fncpy.h
1738+++ b/arch/arm/include/asm/fncpy.h
1739@@ -81,7 +81,9 @@
1740 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1741 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1742 \
1743+ pax_open_kernel(); \
1744 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1745+ pax_close_kernel(); \
1746 flush_icache_range((unsigned long)(dest_buf), \
1747 (unsigned long)(dest_buf) + (size)); \
1748 \
1749diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1750index 53e69da..3fdc896 100644
1751--- a/arch/arm/include/asm/futex.h
1752+++ b/arch/arm/include/asm/futex.h
1753@@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1754 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1755 return -EFAULT;
1756
1757+ pax_open_userland();
1758+
1759 smp_mb();
1760 /* Prefetching cannot fault */
1761 prefetchw(uaddr);
1762@@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1763 : "cc", "memory");
1764 smp_mb();
1765
1766+ pax_close_userland();
1767+
1768 *uval = val;
1769 return ret;
1770 }
1771@@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1772 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1773 return -EFAULT;
1774
1775+ pax_open_userland();
1776+
1777 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1778 "1: " TUSER(ldr) " %1, [%4]\n"
1779 " teq %1, %2\n"
1780@@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1781 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1782 : "cc", "memory");
1783
1784+ pax_close_userland();
1785+
1786 *uval = val;
1787 return ret;
1788 }
1789@@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1790 return -EFAULT;
1791
1792 pagefault_disable(); /* implies preempt_disable() */
1793+ pax_open_userland();
1794
1795 switch (op) {
1796 case FUTEX_OP_SET:
1797@@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1798 ret = -ENOSYS;
1799 }
1800
1801+ pax_close_userland();
1802 pagefault_enable(); /* subsumes preempt_enable() */
1803
1804 if (!ret) {
1805diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1806index 83eb2f7..ed77159 100644
1807--- a/arch/arm/include/asm/kmap_types.h
1808+++ b/arch/arm/include/asm/kmap_types.h
1809@@ -4,6 +4,6 @@
1810 /*
1811 * This is the "bare minimum". AIO seems to require this.
1812 */
1813-#define KM_TYPE_NR 16
1814+#define KM_TYPE_NR 17
1815
1816 #endif
1817diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1818index 9e614a1..3302cca 100644
1819--- a/arch/arm/include/asm/mach/dma.h
1820+++ b/arch/arm/include/asm/mach/dma.h
1821@@ -22,7 +22,7 @@ struct dma_ops {
1822 int (*residue)(unsigned int, dma_t *); /* optional */
1823 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1824 const char *type;
1825-};
1826+} __do_const;
1827
1828 struct dma_struct {
1829 void *addr; /* single DMA address */
1830diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1831index f98c7f3..e5c626d 100644
1832--- a/arch/arm/include/asm/mach/map.h
1833+++ b/arch/arm/include/asm/mach/map.h
1834@@ -23,17 +23,19 @@ struct map_desc {
1835
1836 /* types 0-3 are defined in asm/io.h */
1837 enum {
1838- MT_UNCACHED = 4,
1839- MT_CACHECLEAN,
1840- MT_MINICLEAN,
1841+ MT_UNCACHED_RW = 4,
1842+ MT_CACHECLEAN_RO,
1843+ MT_MINICLEAN_RO,
1844 MT_LOW_VECTORS,
1845 MT_HIGH_VECTORS,
1846- MT_MEMORY_RWX,
1847+ __MT_MEMORY_RWX,
1848 MT_MEMORY_RW,
1849- MT_ROM,
1850- MT_MEMORY_RWX_NONCACHED,
1851+ MT_MEMORY_RX,
1852+ MT_ROM_RX,
1853+ MT_MEMORY_RW_NONCACHED,
1854+ MT_MEMORY_RX_NONCACHED,
1855 MT_MEMORY_RW_DTCM,
1856- MT_MEMORY_RWX_ITCM,
1857+ MT_MEMORY_RX_ITCM,
1858 MT_MEMORY_RW_SO,
1859 MT_MEMORY_DMA_READY,
1860 };
1861diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1862index f94784f..9a09a4a 100644
1863--- a/arch/arm/include/asm/outercache.h
1864+++ b/arch/arm/include/asm/outercache.h
1865@@ -35,7 +35,7 @@ struct outer_cache_fns {
1866 #endif
1867 void (*set_debug)(unsigned long);
1868 void (*resume)(void);
1869-};
1870+} __no_const;
1871
1872 extern struct outer_cache_fns outer_cache;
1873
1874diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1875index 4355f0e..cd9168e 100644
1876--- a/arch/arm/include/asm/page.h
1877+++ b/arch/arm/include/asm/page.h
1878@@ -23,6 +23,7 @@
1879
1880 #else
1881
1882+#include <linux/compiler.h>
1883 #include <asm/glue.h>
1884
1885 /*
1886@@ -114,7 +115,7 @@ struct cpu_user_fns {
1887 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1888 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1889 unsigned long vaddr, struct vm_area_struct *vma);
1890-};
1891+} __no_const;
1892
1893 #ifdef MULTI_USER
1894 extern struct cpu_user_fns cpu_user;
1895diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1896index 78a7793..e3dc06c 100644
1897--- a/arch/arm/include/asm/pgalloc.h
1898+++ b/arch/arm/include/asm/pgalloc.h
1899@@ -17,6 +17,7 @@
1900 #include <asm/processor.h>
1901 #include <asm/cacheflush.h>
1902 #include <asm/tlbflush.h>
1903+#include <asm/system_info.h>
1904
1905 #define check_pgt_cache() do { } while (0)
1906
1907@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1908 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1909 }
1910
1911+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1912+{
1913+ pud_populate(mm, pud, pmd);
1914+}
1915+
1916 #else /* !CONFIG_ARM_LPAE */
1917
1918 /*
1919@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1920 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1921 #define pmd_free(mm, pmd) do { } while (0)
1922 #define pud_populate(mm,pmd,pte) BUG()
1923+#define pud_populate_kernel(mm,pmd,pte) BUG()
1924
1925 #endif /* CONFIG_ARM_LPAE */
1926
1927@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1928 __free_page(pte);
1929 }
1930
1931+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1932+{
1933+#ifdef CONFIG_ARM_LPAE
1934+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1935+#else
1936+ if (addr & SECTION_SIZE)
1937+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1938+ else
1939+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1940+#endif
1941+ flush_pmd_entry(pmdp);
1942+}
1943+
1944 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1945 pmdval_t prot)
1946 {
1947@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1948 static inline void
1949 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1950 {
1951- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1952+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1953 }
1954 #define pmd_pgtable(pmd) pmd_page(pmd)
1955
1956diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1957index 5cfba15..f415e1a 100644
1958--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1959+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1960@@ -20,12 +20,15 @@
1961 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1962 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1963 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1964+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1965 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1966 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1967 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1968+
1969 /*
1970 * - section
1971 */
1972+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1973 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1974 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1975 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1976@@ -37,6 +40,7 @@
1977 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1978 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1979 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1980+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1981
1982 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1983 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1984@@ -66,6 +70,7 @@
1985 * - extended small page/tiny page
1986 */
1987 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1988+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1989 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1990 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1991 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1992diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1993index 219ac88..73ec32a 100644
1994--- a/arch/arm/include/asm/pgtable-2level.h
1995+++ b/arch/arm/include/asm/pgtable-2level.h
1996@@ -126,6 +126,9 @@
1997 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1998 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1999
2000+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
2001+#define L_PTE_PXN (_AT(pteval_t, 0))
2002+
2003 /*
2004 * These are the memory types, defined to be compatible with
2005 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
2006diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
2007index 626989f..9d67a33 100644
2008--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
2009+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
2010@@ -75,6 +75,7 @@
2011 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2012 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
2013 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
2014+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2015 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
2016
2017 /*
2018diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
2019index 85c60ad..b0bbd7e 100644
2020--- a/arch/arm/include/asm/pgtable-3level.h
2021+++ b/arch/arm/include/asm/pgtable-3level.h
2022@@ -82,6 +82,7 @@
2023 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
2024 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2025 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
2026+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2027 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2028 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
2029 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
2030@@ -95,6 +96,7 @@
2031 /*
2032 * To be used in assembly code with the upper page attributes.
2033 */
2034+#define L_PTE_PXN_HIGH (1 << (53 - 32))
2035 #define L_PTE_XN_HIGH (1 << (54 - 32))
2036 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2037
2038diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2039index 5478e5d..f5b5cb3 100644
2040--- a/arch/arm/include/asm/pgtable.h
2041+++ b/arch/arm/include/asm/pgtable.h
2042@@ -33,6 +33,9 @@
2043 #include <asm/pgtable-2level.h>
2044 #endif
2045
2046+#define ktla_ktva(addr) (addr)
2047+#define ktva_ktla(addr) (addr)
2048+
2049 /*
2050 * Just any arbitrary offset to the start of the vmalloc VM area: the
2051 * current 8MB value just means that there will be a 8MB "hole" after the
2052@@ -48,6 +51,9 @@
2053 #define LIBRARY_TEXT_START 0x0c000000
2054
2055 #ifndef __ASSEMBLY__
2056+extern pteval_t __supported_pte_mask;
2057+extern pmdval_t __supported_pmd_mask;
2058+
2059 extern void __pte_error(const char *file, int line, pte_t);
2060 extern void __pmd_error(const char *file, int line, pmd_t);
2061 extern void __pgd_error(const char *file, int line, pgd_t);
2062@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2063 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2064 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2065
2066+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2067+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2068+
2069+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2070+#include <asm/domain.h>
2071+#include <linux/thread_info.h>
2072+#include <linux/preempt.h>
2073+
2074+static inline int test_domain(int domain, int domaintype)
2075+{
2076+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2077+}
2078+#endif
2079+
2080+#ifdef CONFIG_PAX_KERNEXEC
2081+static inline unsigned long pax_open_kernel(void) {
2082+#ifdef CONFIG_ARM_LPAE
2083+ /* TODO */
2084+#else
2085+ preempt_disable();
2086+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2087+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2088+#endif
2089+ return 0;
2090+}
2091+
2092+static inline unsigned long pax_close_kernel(void) {
2093+#ifdef CONFIG_ARM_LPAE
2094+ /* TODO */
2095+#else
2096+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2097+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2098+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2099+ preempt_enable_no_resched();
2100+#endif
2101+ return 0;
2102+}
2103+#else
2104+static inline unsigned long pax_open_kernel(void) { return 0; }
2105+static inline unsigned long pax_close_kernel(void) { return 0; }
2106+#endif
2107+
2108 /*
2109 * This is the lowest virtual address we can permit any user space
2110 * mapping to be mapped at. This is particularly important for
2111@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2112 /*
2113 * The pgprot_* and protection_map entries will be fixed up in runtime
2114 * to include the cachable and bufferable bits based on memory policy,
2115- * as well as any architecture dependent bits like global/ASID and SMP
2116- * shared mapping bits.
2117+ * as well as any architecture dependent bits like global/ASID, PXN,
2118+ * and SMP shared mapping bits.
2119 */
2120 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2121
2122@@ -265,7 +313,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2123 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2124 {
2125 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2126- L_PTE_NONE | L_PTE_VALID;
2127+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2128 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2129 return pte;
2130 }
2131diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2132index c4ae171..ea0c0c2 100644
2133--- a/arch/arm/include/asm/psci.h
2134+++ b/arch/arm/include/asm/psci.h
2135@@ -29,7 +29,7 @@ struct psci_operations {
2136 int (*cpu_off)(struct psci_power_state state);
2137 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2138 int (*migrate)(unsigned long cpuid);
2139-};
2140+} __no_const;
2141
2142 extern struct psci_operations psci_ops;
2143 extern struct smp_operations psci_smp_ops;
2144diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2145index 2ec765c..beb1fe16 100644
2146--- a/arch/arm/include/asm/smp.h
2147+++ b/arch/arm/include/asm/smp.h
2148@@ -113,7 +113,7 @@ struct smp_operations {
2149 int (*cpu_disable)(unsigned int cpu);
2150 #endif
2151 #endif
2152-};
2153+} __no_const;
2154
2155 struct of_cpu_method {
2156 const char *method;
2157diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2158index f989d7c..e8aa7f0 100644
2159--- a/arch/arm/include/asm/thread_info.h
2160+++ b/arch/arm/include/asm/thread_info.h
2161@@ -88,9 +88,9 @@ struct thread_info {
2162 .flags = 0, \
2163 .preempt_count = INIT_PREEMPT_COUNT, \
2164 .addr_limit = KERNEL_DS, \
2165- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2166- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2167- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2168+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2169+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2170+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2171 .restart_block = { \
2172 .fn = do_no_restart_syscall, \
2173 }, \
2174@@ -158,7 +158,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2175 #define TIF_SYSCALL_AUDIT 9
2176 #define TIF_SYSCALL_TRACEPOINT 10
2177 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2178-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2179+/* within 8 bits of TIF_SYSCALL_TRACE
2180+ * to meet flexible second operand requirements
2181+ */
2182+#define TIF_GRSEC_SETXID 12
2183+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2184 #define TIF_USING_IWMMXT 17
2185 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2186 #define TIF_RESTORE_SIGMASK 20
2187@@ -172,10 +176,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2188 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2189 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2190 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2191+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2192
2193 /* Checks for any syscall work in entry-common.S */
2194 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2195- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2196+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2197
2198 /*
2199 * Change these and you break ASM code in entry-common.S
2200diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2201index 75d9579..b5b40e4 100644
2202--- a/arch/arm/include/asm/uaccess.h
2203+++ b/arch/arm/include/asm/uaccess.h
2204@@ -18,6 +18,7 @@
2205 #include <asm/domain.h>
2206 #include <asm/unified.h>
2207 #include <asm/compiler.h>
2208+#include <asm/pgtable.h>
2209
2210 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2211 #include <asm-generic/uaccess-unaligned.h>
2212@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2213 static inline void set_fs(mm_segment_t fs)
2214 {
2215 current_thread_info()->addr_limit = fs;
2216- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2217+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2218 }
2219
2220 #define segment_eq(a,b) ((a) == (b))
2221
2222+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2223+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2224+
2225+static inline void pax_open_userland(void)
2226+{
2227+
2228+#ifdef CONFIG_PAX_MEMORY_UDEREF
2229+ if (segment_eq(get_fs(), USER_DS)) {
2230+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2231+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2232+ }
2233+#endif
2234+
2235+}
2236+
2237+static inline void pax_close_userland(void)
2238+{
2239+
2240+#ifdef CONFIG_PAX_MEMORY_UDEREF
2241+ if (segment_eq(get_fs(), USER_DS)) {
2242+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2243+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2244+ }
2245+#endif
2246+
2247+}
2248+
2249 #define __addr_ok(addr) ({ \
2250 unsigned long flag; \
2251 __asm__("cmp %2, %0; movlo %0, #0" \
2252@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2253
2254 #define get_user(x,p) \
2255 ({ \
2256+ int __e; \
2257 might_fault(); \
2258- __get_user_check(x,p); \
2259+ pax_open_userland(); \
2260+ __e = __get_user_check(x,p); \
2261+ pax_close_userland(); \
2262+ __e; \
2263 })
2264
2265 extern int __put_user_1(void *, unsigned int);
2266@@ -196,8 +228,12 @@ extern int __put_user_8(void *, unsigned long long);
2267
2268 #define put_user(x,p) \
2269 ({ \
2270+ int __e; \
2271 might_fault(); \
2272- __put_user_check(x,p); \
2273+ pax_open_userland(); \
2274+ __e = __put_user_check(x,p); \
2275+ pax_close_userland(); \
2276+ __e; \
2277 })
2278
2279 #else /* CONFIG_MMU */
2280@@ -221,6 +257,7 @@ static inline void set_fs(mm_segment_t fs)
2281
2282 #endif /* CONFIG_MMU */
2283
2284+#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2285 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2286
2287 #define user_addr_max() \
2288@@ -238,13 +275,17 @@ static inline void set_fs(mm_segment_t fs)
2289 #define __get_user(x,ptr) \
2290 ({ \
2291 long __gu_err = 0; \
2292+ pax_open_userland(); \
2293 __get_user_err((x),(ptr),__gu_err); \
2294+ pax_close_userland(); \
2295 __gu_err; \
2296 })
2297
2298 #define __get_user_error(x,ptr,err) \
2299 ({ \
2300+ pax_open_userland(); \
2301 __get_user_err((x),(ptr),err); \
2302+ pax_close_userland(); \
2303 (void) 0; \
2304 })
2305
2306@@ -320,13 +361,17 @@ do { \
2307 #define __put_user(x,ptr) \
2308 ({ \
2309 long __pu_err = 0; \
2310+ pax_open_userland(); \
2311 __put_user_err((x),(ptr),__pu_err); \
2312+ pax_close_userland(); \
2313 __pu_err; \
2314 })
2315
2316 #define __put_user_error(x,ptr,err) \
2317 ({ \
2318+ pax_open_userland(); \
2319 __put_user_err((x),(ptr),err); \
2320+ pax_close_userland(); \
2321 (void) 0; \
2322 })
2323
2324@@ -426,11 +471,44 @@ do { \
2325
2326
2327 #ifdef CONFIG_MMU
2328-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2329-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2330+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2331+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2332+
2333+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2334+{
2335+ unsigned long ret;
2336+
2337+ check_object_size(to, n, false);
2338+ pax_open_userland();
2339+ ret = ___copy_from_user(to, from, n);
2340+ pax_close_userland();
2341+ return ret;
2342+}
2343+
2344+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2345+{
2346+ unsigned long ret;
2347+
2348+ check_object_size(from, n, true);
2349+ pax_open_userland();
2350+ ret = ___copy_to_user(to, from, n);
2351+ pax_close_userland();
2352+ return ret;
2353+}
2354+
2355 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2356-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2357+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2358 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2359+
2360+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2361+{
2362+ unsigned long ret;
2363+ pax_open_userland();
2364+ ret = ___clear_user(addr, n);
2365+ pax_close_userland();
2366+ return ret;
2367+}
2368+
2369 #else
2370 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2371 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2372@@ -439,6 +517,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2373
2374 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2375 {
2376+ if ((long)n < 0)
2377+ return n;
2378+
2379 if (access_ok(VERIFY_READ, from, n))
2380 n = __copy_from_user(to, from, n);
2381 else /* security hole - plug it */
2382@@ -448,6 +529,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2383
2384 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2385 {
2386+ if ((long)n < 0)
2387+ return n;
2388+
2389 if (access_ok(VERIFY_WRITE, to, n))
2390 n = __copy_to_user(to, from, n);
2391 return n;
2392diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2393index 5af0ed1..cea83883 100644
2394--- a/arch/arm/include/uapi/asm/ptrace.h
2395+++ b/arch/arm/include/uapi/asm/ptrace.h
2396@@ -92,7 +92,7 @@
2397 * ARMv7 groups of PSR bits
2398 */
2399 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2400-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2401+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2402 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2403 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2404
2405diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2406index f7b450f..f5364c5 100644
2407--- a/arch/arm/kernel/armksyms.c
2408+++ b/arch/arm/kernel/armksyms.c
2409@@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2410
2411 /* networking */
2412 EXPORT_SYMBOL(csum_partial);
2413-EXPORT_SYMBOL(csum_partial_copy_from_user);
2414+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2415 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2416 EXPORT_SYMBOL(__csum_ipv6_magic);
2417
2418@@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2419 #ifdef CONFIG_MMU
2420 EXPORT_SYMBOL(copy_page);
2421
2422-EXPORT_SYMBOL(__copy_from_user);
2423-EXPORT_SYMBOL(__copy_to_user);
2424-EXPORT_SYMBOL(__clear_user);
2425+EXPORT_SYMBOL(___copy_from_user);
2426+EXPORT_SYMBOL(___copy_to_user);
2427+EXPORT_SYMBOL(___clear_user);
2428
2429 EXPORT_SYMBOL(__get_user_1);
2430 EXPORT_SYMBOL(__get_user_2);
2431diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2432index 1879e8d..b2207fc 100644
2433--- a/arch/arm/kernel/entry-armv.S
2434+++ b/arch/arm/kernel/entry-armv.S
2435@@ -47,6 +47,87 @@
2436 9997:
2437 .endm
2438
2439+ .macro pax_enter_kernel
2440+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2441+ @ make aligned space for saved DACR
2442+ sub sp, sp, #8
2443+ @ save regs
2444+ stmdb sp!, {r1, r2}
2445+ @ read DACR from cpu_domain into r1
2446+ mov r2, sp
2447+ @ assume 8K pages, since we have to split the immediate in two
2448+ bic r2, r2, #(0x1fc0)
2449+ bic r2, r2, #(0x3f)
2450+ ldr r1, [r2, #TI_CPU_DOMAIN]
2451+ @ store old DACR on stack
2452+ str r1, [sp, #8]
2453+#ifdef CONFIG_PAX_KERNEXEC
2454+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2455+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2456+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2457+#endif
2458+#ifdef CONFIG_PAX_MEMORY_UDEREF
2459+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2460+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2461+#endif
2462+ @ write r1 to current_thread_info()->cpu_domain
2463+ str r1, [r2, #TI_CPU_DOMAIN]
2464+ @ write r1 to DACR
2465+ mcr p15, 0, r1, c3, c0, 0
2466+ @ instruction sync
2467+ instr_sync
2468+ @ restore regs
2469+ ldmia sp!, {r1, r2}
2470+#endif
2471+ .endm
2472+
2473+ .macro pax_open_userland
2474+#ifdef CONFIG_PAX_MEMORY_UDEREF
2475+ @ save regs
2476+ stmdb sp!, {r0, r1}
2477+ @ read DACR from cpu_domain into r1
2478+ mov r0, sp
2479+ @ assume 8K pages, since we have to split the immediate in two
2480+ bic r0, r0, #(0x1fc0)
2481+ bic r0, r0, #(0x3f)
2482+ ldr r1, [r0, #TI_CPU_DOMAIN]
2483+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2484+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2485+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2486+ @ write r1 to current_thread_info()->cpu_domain
2487+ str r1, [r0, #TI_CPU_DOMAIN]
2488+ @ write r1 to DACR
2489+ mcr p15, 0, r1, c3, c0, 0
2490+ @ instruction sync
2491+ instr_sync
2492+ @ restore regs
2493+ ldmia sp!, {r0, r1}
2494+#endif
2495+ .endm
2496+
2497+ .macro pax_close_userland
2498+#ifdef CONFIG_PAX_MEMORY_UDEREF
2499+ @ save regs
2500+ stmdb sp!, {r0, r1}
2501+ @ read DACR from cpu_domain into r1
2502+ mov r0, sp
2503+ @ assume 8K pages, since we have to split the immediate in two
2504+ bic r0, r0, #(0x1fc0)
2505+ bic r0, r0, #(0x3f)
2506+ ldr r1, [r0, #TI_CPU_DOMAIN]
2507+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2508+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2509+ @ write r1 to current_thread_info()->cpu_domain
2510+ str r1, [r0, #TI_CPU_DOMAIN]
2511+ @ write r1 to DACR
2512+ mcr p15, 0, r1, c3, c0, 0
2513+ @ instruction sync
2514+ instr_sync
2515+ @ restore regs
2516+ ldmia sp!, {r0, r1}
2517+#endif
2518+ .endm
2519+
2520 .macro pabt_helper
2521 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2522 #ifdef MULTI_PABORT
2523@@ -89,11 +170,15 @@
2524 * Invalid mode handlers
2525 */
2526 .macro inv_entry, reason
2527+
2528+ pax_enter_kernel
2529+
2530 sub sp, sp, #S_FRAME_SIZE
2531 ARM( stmib sp, {r1 - lr} )
2532 THUMB( stmia sp, {r0 - r12} )
2533 THUMB( str sp, [sp, #S_SP] )
2534 THUMB( str lr, [sp, #S_LR] )
2535+
2536 mov r1, #\reason
2537 .endm
2538
2539@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2540 .macro svc_entry, stack_hole=0
2541 UNWIND(.fnstart )
2542 UNWIND(.save {r0 - pc} )
2543+
2544+ pax_enter_kernel
2545+
2546 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2547+
2548 #ifdef CONFIG_THUMB2_KERNEL
2549 SPFIX( str r0, [sp] ) @ temporarily saved
2550 SPFIX( mov r0, sp )
2551@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2552 ldmia r0, {r3 - r5}
2553 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2554 mov r6, #-1 @ "" "" "" ""
2555+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2556+ @ offset sp by 8 as done in pax_enter_kernel
2557+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2558+#else
2559 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2560+#endif
2561 SPFIX( addeq r2, r2, #4 )
2562 str r3, [sp, #-4]! @ save the "real" r0 copied
2563 @ from the exception stack
2564@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2565 .macro usr_entry
2566 UNWIND(.fnstart )
2567 UNWIND(.cantunwind ) @ don't unwind the user space
2568+
2569+ pax_enter_kernel_user
2570+
2571 sub sp, sp, #S_FRAME_SIZE
2572 ARM( stmib sp, {r1 - r12} )
2573 THUMB( stmia sp, {r0 - r12} )
2574@@ -416,7 +513,9 @@ __und_usr:
2575 tst r3, #PSR_T_BIT @ Thumb mode?
2576 bne __und_usr_thumb
2577 sub r4, r2, #4 @ ARM instr at LR - 4
2578+ pax_open_userland
2579 1: ldrt r0, [r4]
2580+ pax_close_userland
2581 ARM_BE8(rev r0, r0) @ little endian instruction
2582
2583 @ r0 = 32-bit ARM instruction which caused the exception
2584@@ -450,11 +549,15 @@ __und_usr_thumb:
2585 */
2586 .arch armv6t2
2587 #endif
2588+ pax_open_userland
2589 2: ldrht r5, [r4]
2590+ pax_close_userland
2591 ARM_BE8(rev16 r5, r5) @ little endian instruction
2592 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2593 blo __und_usr_fault_16 @ 16bit undefined instruction
2594+ pax_open_userland
2595 3: ldrht r0, [r2]
2596+ pax_close_userland
2597 ARM_BE8(rev16 r0, r0) @ little endian instruction
2598 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2599 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2600@@ -484,7 +587,8 @@ ENDPROC(__und_usr)
2601 */
2602 .pushsection .fixup, "ax"
2603 .align 2
2604-4: mov pc, r9
2605+4: pax_close_userland
2606+ mov pc, r9
2607 .popsection
2608 .pushsection __ex_table,"a"
2609 .long 1b, 4b
2610@@ -694,7 +798,7 @@ ENTRY(__switch_to)
2611 THUMB( str lr, [ip], #4 )
2612 ldr r4, [r2, #TI_TP_VALUE]
2613 ldr r5, [r2, #TI_TP_VALUE + 4]
2614-#ifdef CONFIG_CPU_USE_DOMAINS
2615+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2616 ldr r6, [r2, #TI_CPU_DOMAIN]
2617 #endif
2618 switch_tls r1, r4, r5, r3, r7
2619@@ -703,7 +807,7 @@ ENTRY(__switch_to)
2620 ldr r8, =__stack_chk_guard
2621 ldr r7, [r7, #TSK_STACK_CANARY]
2622 #endif
2623-#ifdef CONFIG_CPU_USE_DOMAINS
2624+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2625 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2626 #endif
2627 mov r5, r0
2628diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2629index a2dcafd..1048b5a 100644
2630--- a/arch/arm/kernel/entry-common.S
2631+++ b/arch/arm/kernel/entry-common.S
2632@@ -10,18 +10,46 @@
2633
2634 #include <asm/unistd.h>
2635 #include <asm/ftrace.h>
2636+#include <asm/domain.h>
2637 #include <asm/unwind.h>
2638
2639+#include "entry-header.S"
2640+
2641 #ifdef CONFIG_NEED_RET_TO_USER
2642 #include <mach/entry-macro.S>
2643 #else
2644 .macro arch_ret_to_user, tmp1, tmp2
2645+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2646+ @ save regs
2647+ stmdb sp!, {r1, r2}
2648+ @ read DACR from cpu_domain into r1
2649+ mov r2, sp
2650+ @ assume 8K pages, since we have to split the immediate in two
2651+ bic r2, r2, #(0x1fc0)
2652+ bic r2, r2, #(0x3f)
2653+ ldr r1, [r2, #TI_CPU_DOMAIN]
2654+#ifdef CONFIG_PAX_KERNEXEC
2655+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2656+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2657+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2658+#endif
2659+#ifdef CONFIG_PAX_MEMORY_UDEREF
2660+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2661+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2662+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2663+#endif
2664+ @ write r1 to current_thread_info()->cpu_domain
2665+ str r1, [r2, #TI_CPU_DOMAIN]
2666+ @ write r1 to DACR
2667+ mcr p15, 0, r1, c3, c0, 0
2668+ @ instruction sync
2669+ instr_sync
2670+ @ restore regs
2671+ ldmia sp!, {r1, r2}
2672+#endif
2673 .endm
2674 #endif
2675
2676-#include "entry-header.S"
2677-
2678-
2679 .align 5
2680 /*
2681 * This is the fast syscall return path. We do as little as
2682@@ -411,6 +439,12 @@ ENTRY(vector_swi)
2683 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2684 #endif
2685
2686+ /*
2687+ * do this here to avoid a performance hit of wrapping the code above
2688+ * that directly dereferences userland to parse the SWI instruction
2689+ */
2690+ pax_enter_kernel_user
2691+
2692 adr tbl, sys_call_table @ load syscall table pointer
2693
2694 #if defined(CONFIG_OABI_COMPAT)
2695diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2696index efb208d..d34bd02 100644
2697--- a/arch/arm/kernel/entry-header.S
2698+++ b/arch/arm/kernel/entry-header.S
2699@@ -188,6 +188,60 @@
2700 msr cpsr_c, \rtemp @ switch back to the SVC mode
2701 .endm
2702
2703+ .macro pax_enter_kernel_user
2704+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2705+ @ save regs
2706+ stmdb sp!, {r0, r1}
2707+ @ read DACR from cpu_domain into r1
2708+ mov r0, sp
2709+ @ assume 8K pages, since we have to split the immediate in two
2710+ bic r0, r0, #(0x1fc0)
2711+ bic r0, r0, #(0x3f)
2712+ ldr r1, [r0, #TI_CPU_DOMAIN]
2713+#ifdef CONFIG_PAX_MEMORY_UDEREF
2714+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2715+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2716+#endif
2717+#ifdef CONFIG_PAX_KERNEXEC
2718+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2719+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2720+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2721+#endif
2722+ @ write r1 to current_thread_info()->cpu_domain
2723+ str r1, [r0, #TI_CPU_DOMAIN]
2724+ @ write r1 to DACR
2725+ mcr p15, 0, r1, c3, c0, 0
2726+ @ instruction sync
2727+ instr_sync
2728+ @ restore regs
2729+ ldmia sp!, {r0, r1}
2730+#endif
2731+ .endm
2732+
2733+ .macro pax_exit_kernel
2734+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2735+ @ save regs
2736+ stmdb sp!, {r0, r1}
2737+ @ read old DACR from stack into r1
2738+ ldr r1, [sp, #(8 + S_SP)]
2739+ sub r1, r1, #8
2740+ ldr r1, [r1]
2741+
2742+ @ write r1 to current_thread_info()->cpu_domain
2743+ mov r0, sp
2744+ @ assume 8K pages, since we have to split the immediate in two
2745+ bic r0, r0, #(0x1fc0)
2746+ bic r0, r0, #(0x3f)
2747+ str r1, [r0, #TI_CPU_DOMAIN]
2748+ @ write r1 to DACR
2749+ mcr p15, 0, r1, c3, c0, 0
2750+ @ instruction sync
2751+ instr_sync
2752+ @ restore regs
2753+ ldmia sp!, {r0, r1}
2754+#endif
2755+ .endm
2756+
2757 #ifndef CONFIG_THUMB2_KERNEL
2758 .macro svc_exit, rpsr, irq = 0
2759 .if \irq != 0
2760@@ -207,6 +261,9 @@
2761 blne trace_hardirqs_off
2762 #endif
2763 .endif
2764+
2765+ pax_exit_kernel
2766+
2767 msr spsr_cxsf, \rpsr
2768 #if defined(CONFIG_CPU_V6)
2769 ldr r0, [sp]
2770@@ -265,6 +322,9 @@
2771 blne trace_hardirqs_off
2772 #endif
2773 .endif
2774+
2775+ pax_exit_kernel
2776+
2777 ldr lr, [sp, #S_SP] @ top of the stack
2778 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2779 clrex @ clear the exclusive monitor
2780diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2781index 918875d..cd5fa27 100644
2782--- a/arch/arm/kernel/fiq.c
2783+++ b/arch/arm/kernel/fiq.c
2784@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2785 void *base = vectors_page;
2786 unsigned offset = FIQ_OFFSET;
2787
2788+ pax_open_kernel();
2789 memcpy(base + offset, start, length);
2790+ pax_close_kernel();
2791+
2792 if (!cache_is_vipt_nonaliasing())
2793 flush_icache_range((unsigned long)base + offset, offset +
2794 length);
2795diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2796index 591d6e4..8322a26 100644
2797--- a/arch/arm/kernel/head.S
2798+++ b/arch/arm/kernel/head.S
2799@@ -437,7 +437,7 @@ __enable_mmu:
2800 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2801 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2802 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2803- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2804+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2805 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2806 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2807 #endif
2808diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2809index 45e4781..8eac93d 100644
2810--- a/arch/arm/kernel/module.c
2811+++ b/arch/arm/kernel/module.c
2812@@ -38,12 +38,39 @@
2813 #endif
2814
2815 #ifdef CONFIG_MMU
2816-void *module_alloc(unsigned long size)
2817+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2818 {
2819+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2820+ return NULL;
2821 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2822- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2823+ GFP_KERNEL, prot, NUMA_NO_NODE,
2824 __builtin_return_address(0));
2825 }
2826+
2827+void *module_alloc(unsigned long size)
2828+{
2829+
2830+#ifdef CONFIG_PAX_KERNEXEC
2831+ return __module_alloc(size, PAGE_KERNEL);
2832+#else
2833+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2834+#endif
2835+
2836+}
2837+
2838+#ifdef CONFIG_PAX_KERNEXEC
2839+void module_free_exec(struct module *mod, void *module_region)
2840+{
2841+ module_free(mod, module_region);
2842+}
2843+EXPORT_SYMBOL(module_free_exec);
2844+
2845+void *module_alloc_exec(unsigned long size)
2846+{
2847+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2848+}
2849+EXPORT_SYMBOL(module_alloc_exec);
2850+#endif
2851 #endif
2852
2853 int
2854diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2855index 07314af..c46655c 100644
2856--- a/arch/arm/kernel/patch.c
2857+++ b/arch/arm/kernel/patch.c
2858@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2859 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2860 int size;
2861
2862+ pax_open_kernel();
2863 if (thumb2 && __opcode_is_thumb16(insn)) {
2864 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2865 size = sizeof(u16);
2866@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2867 *(u32 *)addr = insn;
2868 size = sizeof(u32);
2869 }
2870+ pax_close_kernel();
2871
2872 flush_icache_range((uintptr_t)(addr),
2873 (uintptr_t)(addr) + size);
2874diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2875index 81ef686..f4130b8 100644
2876--- a/arch/arm/kernel/process.c
2877+++ b/arch/arm/kernel/process.c
2878@@ -212,6 +212,7 @@ void machine_power_off(void)
2879
2880 if (pm_power_off)
2881 pm_power_off();
2882+ BUG();
2883 }
2884
2885 /*
2886@@ -225,7 +226,7 @@ void machine_power_off(void)
2887 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2888 * to use. Implementing such co-ordination would be essentially impossible.
2889 */
2890-void machine_restart(char *cmd)
2891+__noreturn void machine_restart(char *cmd)
2892 {
2893 local_irq_disable();
2894 smp_send_stop();
2895@@ -248,8 +249,8 @@ void __show_regs(struct pt_regs *regs)
2896
2897 show_regs_print_info(KERN_DEFAULT);
2898
2899- print_symbol("PC is at %s\n", instruction_pointer(regs));
2900- print_symbol("LR is at %s\n", regs->ARM_lr);
2901+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2902+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2903 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2904 "sp : %08lx ip : %08lx fp : %08lx\n",
2905 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2906@@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2907 return 0;
2908 }
2909
2910-unsigned long arch_randomize_brk(struct mm_struct *mm)
2911-{
2912- unsigned long range_end = mm->brk + 0x02000000;
2913- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2914-}
2915-
2916 #ifdef CONFIG_MMU
2917 #ifdef CONFIG_KUSER_HELPERS
2918 /*
2919@@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2920
2921 static int __init gate_vma_init(void)
2922 {
2923- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2924+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2925 return 0;
2926 }
2927 arch_initcall(gate_vma_init);
2928@@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2929
2930 const char *arch_vma_name(struct vm_area_struct *vma)
2931 {
2932- return is_gate_vma(vma) ? "[vectors]" :
2933- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2934- "[sigpage]" : NULL;
2935+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2936 }
2937
2938-static struct page *signal_page;
2939-extern struct page *get_signal_page(void);
2940-
2941 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2942 {
2943 struct mm_struct *mm = current->mm;
2944- unsigned long addr;
2945- int ret;
2946-
2947- if (!signal_page)
2948- signal_page = get_signal_page();
2949- if (!signal_page)
2950- return -ENOMEM;
2951
2952 down_write(&mm->mmap_sem);
2953- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2954- if (IS_ERR_VALUE(addr)) {
2955- ret = addr;
2956- goto up_fail;
2957- }
2958-
2959- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2960- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2961- &signal_page);
2962-
2963- if (ret == 0)
2964- mm->context.sigpage = addr;
2965-
2966- up_fail:
2967+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2968 up_write(&mm->mmap_sem);
2969- return ret;
2970+ return 0;
2971 }
2972 #endif
2973diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2974index 4693188..4596c5e 100644
2975--- a/arch/arm/kernel/psci.c
2976+++ b/arch/arm/kernel/psci.c
2977@@ -24,7 +24,7 @@
2978 #include <asm/opcodes-virt.h>
2979 #include <asm/psci.h>
2980
2981-struct psci_operations psci_ops;
2982+struct psci_operations psci_ops __read_only;
2983
2984 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2985
2986diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2987index 0dd3b79..e018f64 100644
2988--- a/arch/arm/kernel/ptrace.c
2989+++ b/arch/arm/kernel/ptrace.c
2990@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2991 return current_thread_info()->syscall;
2992 }
2993
2994+#ifdef CONFIG_GRKERNSEC_SETXID
2995+extern void gr_delayed_cred_worker(void);
2996+#endif
2997+
2998 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2999 {
3000 current_thread_info()->syscall = scno;
3001
3002+#ifdef CONFIG_GRKERNSEC_SETXID
3003+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3004+ gr_delayed_cred_worker();
3005+#endif
3006+
3007 /* Do the secure computing check first; failures should be fast. */
3008 if (secure_computing(scno) == -1)
3009 return -1;
3010diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3011index 50e198c..a8b5f49 100644
3012--- a/arch/arm/kernel/setup.c
3013+++ b/arch/arm/kernel/setup.c
3014@@ -103,21 +103,23 @@ EXPORT_SYMBOL(elf_hwcap);
3015 unsigned int elf_hwcap2 __read_mostly;
3016 EXPORT_SYMBOL(elf_hwcap2);
3017
3018+pteval_t __supported_pte_mask __read_only;
3019+pmdval_t __supported_pmd_mask __read_only;
3020
3021 #ifdef MULTI_CPU
3022-struct processor processor __read_mostly;
3023+struct processor processor __read_only;
3024 #endif
3025 #ifdef MULTI_TLB
3026-struct cpu_tlb_fns cpu_tlb __read_mostly;
3027+struct cpu_tlb_fns cpu_tlb __read_only;
3028 #endif
3029 #ifdef MULTI_USER
3030-struct cpu_user_fns cpu_user __read_mostly;
3031+struct cpu_user_fns cpu_user __read_only;
3032 #endif
3033 #ifdef MULTI_CACHE
3034-struct cpu_cache_fns cpu_cache __read_mostly;
3035+struct cpu_cache_fns cpu_cache __read_only;
3036 #endif
3037 #ifdef CONFIG_OUTER_CACHE
3038-struct outer_cache_fns outer_cache __read_mostly;
3039+struct outer_cache_fns outer_cache __read_only;
3040 EXPORT_SYMBOL(outer_cache);
3041 #endif
3042
3043@@ -250,9 +252,13 @@ static int __get_cpu_architecture(void)
3044 asm("mrc p15, 0, %0, c0, c1, 4"
3045 : "=r" (mmfr0));
3046 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3047- (mmfr0 & 0x000000f0) >= 0x00000030)
3048+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3049 cpu_arch = CPU_ARCH_ARMv7;
3050- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3051+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3052+ __supported_pte_mask |= L_PTE_PXN;
3053+ __supported_pmd_mask |= PMD_PXNTABLE;
3054+ }
3055+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3056 (mmfr0 & 0x000000f0) == 0x00000020)
3057 cpu_arch = CPU_ARCH_ARMv6;
3058 else
3059diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3060index bd19834..e4d8c66 100644
3061--- a/arch/arm/kernel/signal.c
3062+++ b/arch/arm/kernel/signal.c
3063@@ -24,8 +24,6 @@
3064
3065 extern const unsigned long sigreturn_codes[7];
3066
3067-static unsigned long signal_return_offset;
3068-
3069 #ifdef CONFIG_CRUNCH
3070 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3071 {
3072@@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3073 * except when the MPU has protected the vectors
3074 * page from PL0
3075 */
3076- retcode = mm->context.sigpage + signal_return_offset +
3077- (idx << 2) + thumb;
3078+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3079 } else
3080 #endif
3081 {
3082@@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3083 } while (thread_flags & _TIF_WORK_MASK);
3084 return 0;
3085 }
3086-
3087-struct page *get_signal_page(void)
3088-{
3089- unsigned long ptr;
3090- unsigned offset;
3091- struct page *page;
3092- void *addr;
3093-
3094- page = alloc_pages(GFP_KERNEL, 0);
3095-
3096- if (!page)
3097- return NULL;
3098-
3099- addr = page_address(page);
3100-
3101- /* Give the signal return code some randomness */
3102- offset = 0x200 + (get_random_int() & 0x7fc);
3103- signal_return_offset = offset;
3104-
3105- /*
3106- * Copy signal return handlers into the vector page, and
3107- * set sigreturn to be a pointer to these.
3108- */
3109- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3110-
3111- ptr = (unsigned long)addr + offset;
3112- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3113-
3114- return page;
3115-}
3116diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3117index 7c4fada..8581286 100644
3118--- a/arch/arm/kernel/smp.c
3119+++ b/arch/arm/kernel/smp.c
3120@@ -73,7 +73,7 @@ enum ipi_msg_type {
3121
3122 static DECLARE_COMPLETION(cpu_running);
3123
3124-static struct smp_operations smp_ops;
3125+static struct smp_operations smp_ops __read_only;
3126
3127 void __init smp_set_ops(struct smp_operations *ops)
3128 {
3129diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3130index 7a3be1d..b00c7de 100644
3131--- a/arch/arm/kernel/tcm.c
3132+++ b/arch/arm/kernel/tcm.c
3133@@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3134 .virtual = ITCM_OFFSET,
3135 .pfn = __phys_to_pfn(ITCM_OFFSET),
3136 .length = 0,
3137- .type = MT_MEMORY_RWX_ITCM,
3138+ .type = MT_MEMORY_RX_ITCM,
3139 }
3140 };
3141
3142@@ -267,7 +267,9 @@ no_dtcm:
3143 start = &__sitcm_text;
3144 end = &__eitcm_text;
3145 ram = &__itcm_start;
3146+ pax_open_kernel();
3147 memcpy(start, ram, itcm_code_sz);
3148+ pax_close_kernel();
3149 pr_debug("CPU ITCM: copied code from %p - %p\n",
3150 start, end);
3151 itcm_present = true;
3152diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3153index abd2fc0..895dbb6 100644
3154--- a/arch/arm/kernel/traps.c
3155+++ b/arch/arm/kernel/traps.c
3156@@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3157 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3158 {
3159 #ifdef CONFIG_KALLSYMS
3160- printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3161+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3162 #else
3163 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3164 #endif
3165@@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3166 static int die_owner = -1;
3167 static unsigned int die_nest_count;
3168
3169+extern void gr_handle_kernel_exploit(void);
3170+
3171 static unsigned long oops_begin(void)
3172 {
3173 int cpu;
3174@@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3175 panic("Fatal exception in interrupt");
3176 if (panic_on_oops)
3177 panic("Fatal exception");
3178+
3179+ gr_handle_kernel_exploit();
3180+
3181 if (signr)
3182 do_exit(signr);
3183 }
3184@@ -643,7 +648,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3185 * The user helper at 0xffff0fe0 must be used instead.
3186 * (see entry-armv.S for details)
3187 */
3188+ pax_open_kernel();
3189 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3190+ pax_close_kernel();
3191 }
3192 return 0;
3193
3194@@ -900,7 +907,11 @@ void __init early_trap_init(void *vectors_base)
3195 kuser_init(vectors_base);
3196
3197 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3198- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3199+
3200+#ifndef CONFIG_PAX_MEMORY_UDEREF
3201+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3202+#endif
3203+
3204 #else /* ifndef CONFIG_CPU_V7M */
3205 /*
3206 * on V7-M there is no need to copy the vector table to a dedicated
3207diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3208index 7bcee5c..e2f3249 100644
3209--- a/arch/arm/kernel/vmlinux.lds.S
3210+++ b/arch/arm/kernel/vmlinux.lds.S
3211@@ -8,7 +8,11 @@
3212 #include <asm/thread_info.h>
3213 #include <asm/memory.h>
3214 #include <asm/page.h>
3215-
3216+
3217+#ifdef CONFIG_PAX_KERNEXEC
3218+#include <asm/pgtable.h>
3219+#endif
3220+
3221 #define PROC_INFO \
3222 . = ALIGN(4); \
3223 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3224@@ -34,7 +38,7 @@
3225 #endif
3226
3227 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3228- defined(CONFIG_GENERIC_BUG)
3229+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3230 #define ARM_EXIT_KEEP(x) x
3231 #define ARM_EXIT_DISCARD(x)
3232 #else
3233@@ -90,6 +94,11 @@ SECTIONS
3234 _text = .;
3235 HEAD_TEXT
3236 }
3237+
3238+#ifdef CONFIG_PAX_KERNEXEC
3239+ . = ALIGN(1<<SECTION_SHIFT);
3240+#endif
3241+
3242 .text : { /* Real text segment */
3243 _stext = .; /* Text and read-only data */
3244 __exception_text_start = .;
3245@@ -112,6 +121,8 @@ SECTIONS
3246 ARM_CPU_KEEP(PROC_INFO)
3247 }
3248
3249+ _etext = .; /* End of text section */
3250+
3251 RO_DATA(PAGE_SIZE)
3252
3253 . = ALIGN(4);
3254@@ -142,7 +153,9 @@ SECTIONS
3255
3256 NOTES
3257
3258- _etext = .; /* End of text and rodata section */
3259+#ifdef CONFIG_PAX_KERNEXEC
3260+ . = ALIGN(1<<SECTION_SHIFT);
3261+#endif
3262
3263 #ifndef CONFIG_XIP_KERNEL
3264 . = ALIGN(PAGE_SIZE);
3265@@ -220,6 +233,11 @@ SECTIONS
3266 . = PAGE_OFFSET + TEXT_OFFSET;
3267 #else
3268 __init_end = .;
3269+
3270+#ifdef CONFIG_PAX_KERNEXEC
3271+ . = ALIGN(1<<SECTION_SHIFT);
3272+#endif
3273+
3274 . = ALIGN(THREAD_SIZE);
3275 __data_loc = .;
3276 #endif
3277diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3278index f0e50a0..8d5d36c 100644
3279--- a/arch/arm/kvm/arm.c
3280+++ b/arch/arm/kvm/arm.c
3281@@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3282 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3283
3284 /* The VMID used in the VTTBR */
3285-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3286+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3287 static u8 kvm_next_vmid;
3288 static DEFINE_SPINLOCK(kvm_vmid_lock);
3289
3290@@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3291 */
3292 static bool need_new_vmid_gen(struct kvm *kvm)
3293 {
3294- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3295+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3296 }
3297
3298 /**
3299@@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3300
3301 /* First user of a new VMID generation? */
3302 if (unlikely(kvm_next_vmid == 0)) {
3303- atomic64_inc(&kvm_vmid_gen);
3304+ atomic64_inc_unchecked(&kvm_vmid_gen);
3305 kvm_next_vmid = 1;
3306
3307 /*
3308@@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3309 kvm_call_hyp(__kvm_flush_vm_context);
3310 }
3311
3312- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3313+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3314 kvm->arch.vmid = kvm_next_vmid;
3315 kvm_next_vmid++;
3316
3317diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3318index 14a0d98..7771a7d 100644
3319--- a/arch/arm/lib/clear_user.S
3320+++ b/arch/arm/lib/clear_user.S
3321@@ -12,14 +12,14 @@
3322
3323 .text
3324
3325-/* Prototype: int __clear_user(void *addr, size_t sz)
3326+/* Prototype: int ___clear_user(void *addr, size_t sz)
3327 * Purpose : clear some user memory
3328 * Params : addr - user memory address to clear
3329 * : sz - number of bytes to clear
3330 * Returns : number of bytes NOT cleared
3331 */
3332 ENTRY(__clear_user_std)
3333-WEAK(__clear_user)
3334+WEAK(___clear_user)
3335 stmfd sp!, {r1, lr}
3336 mov r2, #0
3337 cmp r1, #4
3338@@ -44,7 +44,7 @@ WEAK(__clear_user)
3339 USER( strnebt r2, [r0])
3340 mov r0, #0
3341 ldmfd sp!, {r1, pc}
3342-ENDPROC(__clear_user)
3343+ENDPROC(___clear_user)
3344 ENDPROC(__clear_user_std)
3345
3346 .pushsection .fixup,"ax"
3347diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3348index 66a477a..bee61d3 100644
3349--- a/arch/arm/lib/copy_from_user.S
3350+++ b/arch/arm/lib/copy_from_user.S
3351@@ -16,7 +16,7 @@
3352 /*
3353 * Prototype:
3354 *
3355- * size_t __copy_from_user(void *to, const void *from, size_t n)
3356+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3357 *
3358 * Purpose:
3359 *
3360@@ -84,11 +84,11 @@
3361
3362 .text
3363
3364-ENTRY(__copy_from_user)
3365+ENTRY(___copy_from_user)
3366
3367 #include "copy_template.S"
3368
3369-ENDPROC(__copy_from_user)
3370+ENDPROC(___copy_from_user)
3371
3372 .pushsection .fixup,"ax"
3373 .align 0
3374diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3375index 6ee2f67..d1cce76 100644
3376--- a/arch/arm/lib/copy_page.S
3377+++ b/arch/arm/lib/copy_page.S
3378@@ -10,6 +10,7 @@
3379 * ASM optimised string functions
3380 */
3381 #include <linux/linkage.h>
3382+#include <linux/const.h>
3383 #include <asm/assembler.h>
3384 #include <asm/asm-offsets.h>
3385 #include <asm/cache.h>
3386diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3387index d066df6..df28194 100644
3388--- a/arch/arm/lib/copy_to_user.S
3389+++ b/arch/arm/lib/copy_to_user.S
3390@@ -16,7 +16,7 @@
3391 /*
3392 * Prototype:
3393 *
3394- * size_t __copy_to_user(void *to, const void *from, size_t n)
3395+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3396 *
3397 * Purpose:
3398 *
3399@@ -88,11 +88,11 @@
3400 .text
3401
3402 ENTRY(__copy_to_user_std)
3403-WEAK(__copy_to_user)
3404+WEAK(___copy_to_user)
3405
3406 #include "copy_template.S"
3407
3408-ENDPROC(__copy_to_user)
3409+ENDPROC(___copy_to_user)
3410 ENDPROC(__copy_to_user_std)
3411
3412 .pushsection .fixup,"ax"
3413diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3414index 7d08b43..f7ca7ea 100644
3415--- a/arch/arm/lib/csumpartialcopyuser.S
3416+++ b/arch/arm/lib/csumpartialcopyuser.S
3417@@ -57,8 +57,8 @@
3418 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3419 */
3420
3421-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3422-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3423+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3424+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3425
3426 #include "csumpartialcopygeneric.S"
3427
3428diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3429index 5306de3..aed6d03 100644
3430--- a/arch/arm/lib/delay.c
3431+++ b/arch/arm/lib/delay.c
3432@@ -28,7 +28,7 @@
3433 /*
3434 * Default to the loop-based delay implementation.
3435 */
3436-struct arm_delay_ops arm_delay_ops = {
3437+struct arm_delay_ops arm_delay_ops __read_only = {
3438 .delay = __loop_delay,
3439 .const_udelay = __loop_const_udelay,
3440 .udelay = __loop_udelay,
3441diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3442index 3e58d71..029817c 100644
3443--- a/arch/arm/lib/uaccess_with_memcpy.c
3444+++ b/arch/arm/lib/uaccess_with_memcpy.c
3445@@ -136,7 +136,7 @@ out:
3446 }
3447
3448 unsigned long
3449-__copy_to_user(void __user *to, const void *from, unsigned long n)
3450+___copy_to_user(void __user *to, const void *from, unsigned long n)
3451 {
3452 /*
3453 * This test is stubbed out of the main function above to keep
3454@@ -190,7 +190,7 @@ out:
3455 return n;
3456 }
3457
3458-unsigned long __clear_user(void __user *addr, unsigned long n)
3459+unsigned long ___clear_user(void __user *addr, unsigned long n)
3460 {
3461 /* See rational for this in __copy_to_user() above. */
3462 if (n < 64)
3463diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3464index f7a07a5..258e1f7 100644
3465--- a/arch/arm/mach-at91/setup.c
3466+++ b/arch/arm/mach-at91/setup.c
3467@@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3468
3469 desc->pfn = __phys_to_pfn(base);
3470 desc->length = length;
3471- desc->type = MT_MEMORY_RWX_NONCACHED;
3472+ desc->type = MT_MEMORY_RW_NONCACHED;
3473
3474 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3475 base, length, desc->virtual);
3476diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3477index 255f33a..507b157 100644
3478--- a/arch/arm/mach-kirkwood/common.c
3479+++ b/arch/arm/mach-kirkwood/common.c
3480@@ -157,7 +157,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3481 clk_gate_ops.disable(hw);
3482 }
3483
3484-static struct clk_ops clk_gate_fn_ops;
3485+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3486+{
3487+ return clk_gate_ops.is_enabled(hw);
3488+}
3489+
3490+static struct clk_ops clk_gate_fn_ops = {
3491+ .enable = clk_gate_fn_enable,
3492+ .disable = clk_gate_fn_disable,
3493+ .is_enabled = clk_gate_fn_is_enabled,
3494+};
3495
3496 static struct clk __init *clk_register_gate_fn(struct device *dev,
3497 const char *name,
3498@@ -191,14 +200,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3499 gate_fn->fn_en = fn_en;
3500 gate_fn->fn_dis = fn_dis;
3501
3502- /* ops is the gate ops, but with our enable/disable functions */
3503- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3504- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3505- clk_gate_fn_ops = clk_gate_ops;
3506- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3507- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3508- }
3509-
3510 clk = clk_register(dev, &gate_fn->gate.hw);
3511
3512 if (IS_ERR(clk))
3513diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3514index aead77a..a2253fa 100644
3515--- a/arch/arm/mach-omap2/board-n8x0.c
3516+++ b/arch/arm/mach-omap2/board-n8x0.c
3517@@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3518 }
3519 #endif
3520
3521-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3522+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3523 .late_init = n8x0_menelaus_late_init,
3524 };
3525
3526diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3527index 9fe8c94..c014a4d 100644
3528--- a/arch/arm/mach-omap2/gpmc.c
3529+++ b/arch/arm/mach-omap2/gpmc.c
3530@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3531 };
3532
3533 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3534-static struct irq_chip gpmc_irq_chip;
3535 static int gpmc_irq_start;
3536
3537 static struct resource gpmc_mem_root;
3538@@ -727,6 +726,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3539
3540 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3541
3542+static struct irq_chip gpmc_irq_chip = {
3543+ .name = "gpmc",
3544+ .irq_startup = gpmc_irq_noop_ret,
3545+ .irq_enable = gpmc_irq_enable,
3546+ .irq_disable = gpmc_irq_disable,
3547+ .irq_shutdown = gpmc_irq_noop,
3548+ .irq_ack = gpmc_irq_noop,
3549+ .irq_mask = gpmc_irq_noop,
3550+ .irq_unmask = gpmc_irq_noop,
3551+
3552+};
3553+
3554 static int gpmc_setup_irq(void)
3555 {
3556 int i;
3557@@ -741,15 +752,6 @@ static int gpmc_setup_irq(void)
3558 return gpmc_irq_start;
3559 }
3560
3561- gpmc_irq_chip.name = "gpmc";
3562- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3563- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3564- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3565- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3566- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3567- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3568- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3569-
3570 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3571 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3572
3573diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3574index 667915d..2ee1219 100644
3575--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3576+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3577@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3578 int (*finish_suspend)(unsigned long cpu_state);
3579 void (*resume)(void);
3580 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3581-};
3582+} __no_const;
3583
3584 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3585 static struct powerdomain *mpuss_pd;
3586@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3587 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3588 {}
3589
3590-struct cpu_pm_ops omap_pm_ops = {
3591+static struct cpu_pm_ops omap_pm_ops __read_only = {
3592 .finish_suspend = default_finish_suspend,
3593 .resume = dummy_cpu_resume,
3594 .scu_prepare = dummy_scu_prepare,
3595diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3596index 693fe48..c15ea73 100644
3597--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3598+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3599@@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3600 return NOTIFY_OK;
3601 }
3602
3603-static struct notifier_block __refdata irq_hotplug_notifier = {
3604+static struct notifier_block irq_hotplug_notifier = {
3605 .notifier_call = irq_cpu_hotplug_notify,
3606 };
3607
3608diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3609index 01ef59d..32ae28a8 100644
3610--- a/arch/arm/mach-omap2/omap_device.c
3611+++ b/arch/arm/mach-omap2/omap_device.c
3612@@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3613 struct platform_device __init *omap_device_build(const char *pdev_name,
3614 int pdev_id,
3615 struct omap_hwmod *oh,
3616- void *pdata, int pdata_len)
3617+ const void *pdata, int pdata_len)
3618 {
3619 struct omap_hwmod *ohs[] = { oh };
3620
3621@@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3622 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3623 int pdev_id,
3624 struct omap_hwmod **ohs,
3625- int oh_cnt, void *pdata,
3626+ int oh_cnt, const void *pdata,
3627 int pdata_len)
3628 {
3629 int ret = -ENOMEM;
3630diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3631index 78c02b3..c94109a 100644
3632--- a/arch/arm/mach-omap2/omap_device.h
3633+++ b/arch/arm/mach-omap2/omap_device.h
3634@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3635 /* Core code interface */
3636
3637 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3638- struct omap_hwmod *oh, void *pdata,
3639+ struct omap_hwmod *oh, const void *pdata,
3640 int pdata_len);
3641
3642 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3643 struct omap_hwmod **oh, int oh_cnt,
3644- void *pdata, int pdata_len);
3645+ const void *pdata, int pdata_len);
3646
3647 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3648 struct omap_hwmod **ohs, int oh_cnt);
3649diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3650index 66c60fe..c78950d 100644
3651--- a/arch/arm/mach-omap2/omap_hwmod.c
3652+++ b/arch/arm/mach-omap2/omap_hwmod.c
3653@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3654 int (*init_clkdm)(struct omap_hwmod *oh);
3655 void (*update_context_lost)(struct omap_hwmod *oh);
3656 int (*get_context_lost)(struct omap_hwmod *oh);
3657-};
3658+} __no_const;
3659
3660 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3661-static struct omap_hwmod_soc_ops soc_ops;
3662+static struct omap_hwmod_soc_ops soc_ops __read_only;
3663
3664 /* omap_hwmod_list contains all registered struct omap_hwmods */
3665 static LIST_HEAD(omap_hwmod_list);
3666diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3667index 95fee54..cfa9cf1 100644
3668--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3669+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3670@@ -10,6 +10,7 @@
3671
3672 #include <linux/kernel.h>
3673 #include <linux/init.h>
3674+#include <asm/pgtable.h>
3675
3676 #include "powerdomain.h"
3677
3678@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3679
3680 void __init am43xx_powerdomains_init(void)
3681 {
3682- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3683+ pax_open_kernel();
3684+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3685+ pax_close_kernel();
3686 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3687 pwrdm_register_pwrdms(powerdomains_am43xx);
3688 pwrdm_complete_init();
3689diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3690index d15c7bb..b2d1f0c 100644
3691--- a/arch/arm/mach-omap2/wd_timer.c
3692+++ b/arch/arm/mach-omap2/wd_timer.c
3693@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3694 struct omap_hwmod *oh;
3695 char *oh_name = "wd_timer2";
3696 char *dev_name = "omap_wdt";
3697- struct omap_wd_timer_platform_data pdata;
3698+ static struct omap_wd_timer_platform_data pdata = {
3699+ .read_reset_sources = prm_read_reset_sources
3700+ };
3701
3702 if (!cpu_class_is_omap2() || of_have_populated_dt())
3703 return 0;
3704@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3705 return -EINVAL;
3706 }
3707
3708- pdata.read_reset_sources = prm_read_reset_sources;
3709-
3710 pdev = omap_device_build(dev_name, id, oh, &pdata,
3711 sizeof(struct omap_wd_timer_platform_data));
3712 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3713diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3714index b82dcae..44ee5b6 100644
3715--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3716+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3717@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3718 bool entered_lp2 = false;
3719
3720 if (tegra_pending_sgi())
3721- ACCESS_ONCE(abort_flag) = true;
3722+ ACCESS_ONCE_RW(abort_flag) = true;
3723
3724 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3725
3726diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3727index 2dea8b5..6499da2 100644
3728--- a/arch/arm/mach-ux500/setup.h
3729+++ b/arch/arm/mach-ux500/setup.h
3730@@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3731 .type = MT_DEVICE, \
3732 }
3733
3734-#define __MEM_DEV_DESC(x, sz) { \
3735- .virtual = IO_ADDRESS(x), \
3736- .pfn = __phys_to_pfn(x), \
3737- .length = sz, \
3738- .type = MT_MEMORY_RWX, \
3739-}
3740-
3741 extern struct smp_operations ux500_smp_ops;
3742 extern void ux500_cpu_die(unsigned int cpu);
3743
3744diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3745index 5bf7c3c..571e67e 100644
3746--- a/arch/arm/mm/Kconfig
3747+++ b/arch/arm/mm/Kconfig
3748@@ -446,6 +446,7 @@ config CPU_32v5
3749
3750 config CPU_32v6
3751 bool
3752+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3753 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3754
3755 config CPU_32v6K
3756@@ -600,6 +601,7 @@ config CPU_CP15_MPU
3757
3758 config CPU_USE_DOMAINS
3759 bool
3760+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3761 help
3762 This option enables or disables the use of domain switching
3763 via the set_fs() function.
3764@@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
3765 config KUSER_HELPERS
3766 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3767 default y
3768+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3769 help
3770 Warning: disabling this option may break user programs.
3771
3772@@ -811,7 +814,7 @@ config KUSER_HELPERS
3773 See Documentation/arm/kernel_user_helpers.txt for details.
3774
3775 However, the fixed address nature of these helpers can be used
3776- by ROP (return orientated programming) authors when creating
3777+ by ROP (Return Oriented Programming) authors when creating
3778 exploits.
3779
3780 If all of the binaries and libraries which run on your platform
3781diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3782index 9240364..a2b8cf3 100644
3783--- a/arch/arm/mm/alignment.c
3784+++ b/arch/arm/mm/alignment.c
3785@@ -212,10 +212,12 @@ union offset_union {
3786 #define __get16_unaligned_check(ins,val,addr) \
3787 do { \
3788 unsigned int err = 0, v, a = addr; \
3789+ pax_open_userland(); \
3790 __get8_unaligned_check(ins,v,a,err); \
3791 val = v << ((BE) ? 8 : 0); \
3792 __get8_unaligned_check(ins,v,a,err); \
3793 val |= v << ((BE) ? 0 : 8); \
3794+ pax_close_userland(); \
3795 if (err) \
3796 goto fault; \
3797 } while (0)
3798@@ -229,6 +231,7 @@ union offset_union {
3799 #define __get32_unaligned_check(ins,val,addr) \
3800 do { \
3801 unsigned int err = 0, v, a = addr; \
3802+ pax_open_userland(); \
3803 __get8_unaligned_check(ins,v,a,err); \
3804 val = v << ((BE) ? 24 : 0); \
3805 __get8_unaligned_check(ins,v,a,err); \
3806@@ -237,6 +240,7 @@ union offset_union {
3807 val |= v << ((BE) ? 8 : 16); \
3808 __get8_unaligned_check(ins,v,a,err); \
3809 val |= v << ((BE) ? 0 : 24); \
3810+ pax_close_userland(); \
3811 if (err) \
3812 goto fault; \
3813 } while (0)
3814@@ -250,6 +254,7 @@ union offset_union {
3815 #define __put16_unaligned_check(ins,val,addr) \
3816 do { \
3817 unsigned int err = 0, v = val, a = addr; \
3818+ pax_open_userland(); \
3819 __asm__( FIRST_BYTE_16 \
3820 ARM( "1: "ins" %1, [%2], #1\n" ) \
3821 THUMB( "1: "ins" %1, [%2]\n" ) \
3822@@ -269,6 +274,7 @@ union offset_union {
3823 " .popsection\n" \
3824 : "=r" (err), "=&r" (v), "=&r" (a) \
3825 : "0" (err), "1" (v), "2" (a)); \
3826+ pax_close_userland(); \
3827 if (err) \
3828 goto fault; \
3829 } while (0)
3830@@ -282,6 +288,7 @@ union offset_union {
3831 #define __put32_unaligned_check(ins,val,addr) \
3832 do { \
3833 unsigned int err = 0, v = val, a = addr; \
3834+ pax_open_userland(); \
3835 __asm__( FIRST_BYTE_32 \
3836 ARM( "1: "ins" %1, [%2], #1\n" ) \
3837 THUMB( "1: "ins" %1, [%2]\n" ) \
3838@@ -311,6 +318,7 @@ union offset_union {
3839 " .popsection\n" \
3840 : "=r" (err), "=&r" (v), "=&r" (a) \
3841 : "0" (err), "1" (v), "2" (a)); \
3842+ pax_close_userland(); \
3843 if (err) \
3844 goto fault; \
3845 } while (0)
3846diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3847index 7abde2c..9df495f 100644
3848--- a/arch/arm/mm/cache-l2x0.c
3849+++ b/arch/arm/mm/cache-l2x0.c
3850@@ -46,7 +46,7 @@ struct l2x0_of_data {
3851 void (*setup)(const struct device_node *, u32 *, u32 *);
3852 void (*save)(void);
3853 struct outer_cache_fns outer_cache;
3854-};
3855+} __do_const;
3856
3857 static bool of_init = false;
3858
3859diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3860index 6eb97b3..ac509f6 100644
3861--- a/arch/arm/mm/context.c
3862+++ b/arch/arm/mm/context.c
3863@@ -43,7 +43,7 @@
3864 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3865
3866 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3867-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3868+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3869 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3870
3871 static DEFINE_PER_CPU(atomic64_t, active_asids);
3872@@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3873 {
3874 static u32 cur_idx = 1;
3875 u64 asid = atomic64_read(&mm->context.id);
3876- u64 generation = atomic64_read(&asid_generation);
3877+ u64 generation = atomic64_read_unchecked(&asid_generation);
3878
3879 if (asid != 0 && is_reserved_asid(asid)) {
3880 /*
3881@@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3882 */
3883 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3884 if (asid == NUM_USER_ASIDS) {
3885- generation = atomic64_add_return(ASID_FIRST_VERSION,
3886+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3887 &asid_generation);
3888 flush_context(cpu);
3889 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3890@@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3891 cpu_set_reserved_ttbr0();
3892
3893 asid = atomic64_read(&mm->context.id);
3894- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3895+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3896 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3897 goto switch_mm_fastpath;
3898
3899 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3900 /* Check that our ASID belongs to the current generation. */
3901 asid = atomic64_read(&mm->context.id);
3902- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3903+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3904 asid = new_context(mm, cpu);
3905 atomic64_set(&mm->context.id, asid);
3906 }
3907diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3908index eb8830a..5360ce7 100644
3909--- a/arch/arm/mm/fault.c
3910+++ b/arch/arm/mm/fault.c
3911@@ -25,6 +25,7 @@
3912 #include <asm/system_misc.h>
3913 #include <asm/system_info.h>
3914 #include <asm/tlbflush.h>
3915+#include <asm/sections.h>
3916
3917 #include "fault.h"
3918
3919@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3920 if (fixup_exception(regs))
3921 return;
3922
3923+#ifdef CONFIG_PAX_MEMORY_UDEREF
3924+ if (addr < TASK_SIZE) {
3925+ if (current->signal->curr_ip)
3926+ 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),
3927+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3928+ else
3929+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3930+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3931+ }
3932+#endif
3933+
3934+#ifdef CONFIG_PAX_KERNEXEC
3935+ if ((fsr & FSR_WRITE) &&
3936+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3937+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3938+ {
3939+ if (current->signal->curr_ip)
3940+ 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),
3941+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3942+ else
3943+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3944+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3945+ }
3946+#endif
3947+
3948 /*
3949 * No handler, we'll have to terminate things with extreme prejudice.
3950 */
3951@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3952 }
3953 #endif
3954
3955+#ifdef CONFIG_PAX_PAGEEXEC
3956+ if (fsr & FSR_LNX_PF) {
3957+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3958+ do_group_exit(SIGKILL);
3959+ }
3960+#endif
3961+
3962 tsk->thread.address = addr;
3963 tsk->thread.error_code = fsr;
3964 tsk->thread.trap_no = 14;
3965@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3966 }
3967 #endif /* CONFIG_MMU */
3968
3969+#ifdef CONFIG_PAX_PAGEEXEC
3970+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3971+{
3972+ long i;
3973+
3974+ printk(KERN_ERR "PAX: bytes at PC: ");
3975+ for (i = 0; i < 20; i++) {
3976+ unsigned char c;
3977+ if (get_user(c, (__force unsigned char __user *)pc+i))
3978+ printk(KERN_CONT "?? ");
3979+ else
3980+ printk(KERN_CONT "%02x ", c);
3981+ }
3982+ printk("\n");
3983+
3984+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3985+ for (i = -1; i < 20; i++) {
3986+ unsigned long c;
3987+ if (get_user(c, (__force unsigned long __user *)sp+i))
3988+ printk(KERN_CONT "???????? ");
3989+ else
3990+ printk(KERN_CONT "%08lx ", c);
3991+ }
3992+ printk("\n");
3993+}
3994+#endif
3995+
3996 /*
3997 * First Level Translation Fault Handler
3998 *
3999@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4000 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4001 struct siginfo info;
4002
4003+#ifdef CONFIG_PAX_MEMORY_UDEREF
4004+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4005+ if (current->signal->curr_ip)
4006+ 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),
4007+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4008+ else
4009+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4010+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4011+ goto die;
4012+ }
4013+#endif
4014+
4015 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4016 return;
4017
4018+die:
4019 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4020 inf->name, fsr, addr);
4021
4022@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4023 ifsr_info[nr].name = name;
4024 }
4025
4026+asmlinkage int sys_sigreturn(struct pt_regs *regs);
4027+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4028+
4029 asmlinkage void __exception
4030 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4031 {
4032 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4033 struct siginfo info;
4034+ unsigned long pc = instruction_pointer(regs);
4035+
4036+ if (user_mode(regs)) {
4037+ unsigned long sigpage = current->mm->context.sigpage;
4038+
4039+ if (sigpage <= pc && pc < sigpage + 7*4) {
4040+ if (pc < sigpage + 3*4)
4041+ sys_sigreturn(regs);
4042+ else
4043+ sys_rt_sigreturn(regs);
4044+ return;
4045+ }
4046+ if (pc == 0xffff0f60UL) {
4047+ /*
4048+ * PaX: __kuser_cmpxchg64 emulation
4049+ */
4050+ // TODO
4051+ //regs->ARM_pc = regs->ARM_lr;
4052+ //return;
4053+ }
4054+ if (pc == 0xffff0fa0UL) {
4055+ /*
4056+ * PaX: __kuser_memory_barrier emulation
4057+ */
4058+ // dmb(); implied by the exception
4059+ regs->ARM_pc = regs->ARM_lr;
4060+ return;
4061+ }
4062+ if (pc == 0xffff0fc0UL) {
4063+ /*
4064+ * PaX: __kuser_cmpxchg emulation
4065+ */
4066+ // TODO
4067+ //long new;
4068+ //int op;
4069+
4070+ //op = FUTEX_OP_SET << 28;
4071+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4072+ //regs->ARM_r0 = old != new;
4073+ //regs->ARM_pc = regs->ARM_lr;
4074+ //return;
4075+ }
4076+ if (pc == 0xffff0fe0UL) {
4077+ /*
4078+ * PaX: __kuser_get_tls emulation
4079+ */
4080+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4081+ regs->ARM_pc = regs->ARM_lr;
4082+ return;
4083+ }
4084+ }
4085+
4086+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4087+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4088+ if (current->signal->curr_ip)
4089+ 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),
4090+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4091+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4092+ else
4093+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4094+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4095+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4096+ goto die;
4097+ }
4098+#endif
4099+
4100+#ifdef CONFIG_PAX_REFCOUNT
4101+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4102+ unsigned int bkpt;
4103+
4104+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4105+ current->thread.error_code = ifsr;
4106+ current->thread.trap_no = 0;
4107+ pax_report_refcount_overflow(regs);
4108+ fixup_exception(regs);
4109+ return;
4110+ }
4111+ }
4112+#endif
4113
4114 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4115 return;
4116
4117+die:
4118 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4119 inf->name, ifsr, addr);
4120
4121diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4122index cf08bdf..772656c 100644
4123--- a/arch/arm/mm/fault.h
4124+++ b/arch/arm/mm/fault.h
4125@@ -3,6 +3,7 @@
4126
4127 /*
4128 * Fault status register encodings. We steal bit 31 for our own purposes.
4129+ * Set when the FSR value is from an instruction fault.
4130 */
4131 #define FSR_LNX_PF (1 << 31)
4132 #define FSR_WRITE (1 << 11)
4133@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4134 }
4135 #endif
4136
4137+/* valid for LPAE and !LPAE */
4138+static inline int is_xn_fault(unsigned int fsr)
4139+{
4140+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4141+}
4142+
4143+static inline int is_domain_fault(unsigned int fsr)
4144+{
4145+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4146+}
4147+
4148 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4149 unsigned long search_exception_table(unsigned long addr);
4150
4151diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4152index 2a77ba8..68e6a7a 100644
4153--- a/arch/arm/mm/init.c
4154+++ b/arch/arm/mm/init.c
4155@@ -30,6 +30,8 @@
4156 #include <asm/setup.h>
4157 #include <asm/tlb.h>
4158 #include <asm/fixmap.h>
4159+#include <asm/system_info.h>
4160+#include <asm/cp15.h>
4161
4162 #include <asm/mach/arch.h>
4163 #include <asm/mach/map.h>
4164@@ -627,7 +629,46 @@ void free_initmem(void)
4165 {
4166 #ifdef CONFIG_HAVE_TCM
4167 extern char __tcm_start, __tcm_end;
4168+#endif
4169
4170+#ifdef CONFIG_PAX_KERNEXEC
4171+ unsigned long addr;
4172+ pgd_t *pgd;
4173+ pud_t *pud;
4174+ pmd_t *pmd;
4175+ int cpu_arch = cpu_architecture();
4176+ unsigned int cr = get_cr();
4177+
4178+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4179+ /* make pages tables, etc before .text NX */
4180+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4181+ pgd = pgd_offset_k(addr);
4182+ pud = pud_offset(pgd, addr);
4183+ pmd = pmd_offset(pud, addr);
4184+ __section_update(pmd, addr, PMD_SECT_XN);
4185+ }
4186+ /* make init NX */
4187+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4188+ pgd = pgd_offset_k(addr);
4189+ pud = pud_offset(pgd, addr);
4190+ pmd = pmd_offset(pud, addr);
4191+ __section_update(pmd, addr, PMD_SECT_XN);
4192+ }
4193+ /* make kernel code/rodata RX */
4194+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4195+ pgd = pgd_offset_k(addr);
4196+ pud = pud_offset(pgd, addr);
4197+ pmd = pmd_offset(pud, addr);
4198+#ifdef CONFIG_ARM_LPAE
4199+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4200+#else
4201+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4202+#endif
4203+ }
4204+ }
4205+#endif
4206+
4207+#ifdef CONFIG_HAVE_TCM
4208 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4209 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4210 #endif
4211diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4212index f9c32ba..8540068 100644
4213--- a/arch/arm/mm/ioremap.c
4214+++ b/arch/arm/mm/ioremap.c
4215@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4216 unsigned int mtype;
4217
4218 if (cached)
4219- mtype = MT_MEMORY_RWX;
4220+ mtype = MT_MEMORY_RX;
4221 else
4222- mtype = MT_MEMORY_RWX_NONCACHED;
4223+ mtype = MT_MEMORY_RX_NONCACHED;
4224
4225 return __arm_ioremap_caller(phys_addr, size, mtype,
4226 __builtin_return_address(0));
4227diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4228index 5e85ed3..b10a7ed 100644
4229--- a/arch/arm/mm/mmap.c
4230+++ b/arch/arm/mm/mmap.c
4231@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4232 struct vm_area_struct *vma;
4233 int do_align = 0;
4234 int aliasing = cache_is_vipt_aliasing();
4235+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4236 struct vm_unmapped_area_info info;
4237
4238 /*
4239@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4240 if (len > TASK_SIZE)
4241 return -ENOMEM;
4242
4243+#ifdef CONFIG_PAX_RANDMMAP
4244+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4245+#endif
4246+
4247 if (addr) {
4248 if (do_align)
4249 addr = COLOUR_ALIGN(addr, pgoff);
4250@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4251 addr = PAGE_ALIGN(addr);
4252
4253 vma = find_vma(mm, addr);
4254- if (TASK_SIZE - len >= addr &&
4255- (!vma || addr + len <= vma->vm_start))
4256+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4257 return addr;
4258 }
4259
4260@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4261 info.high_limit = TASK_SIZE;
4262 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4263 info.align_offset = pgoff << PAGE_SHIFT;
4264+ info.threadstack_offset = offset;
4265 return vm_unmapped_area(&info);
4266 }
4267
4268@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4269 unsigned long addr = addr0;
4270 int do_align = 0;
4271 int aliasing = cache_is_vipt_aliasing();
4272+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4273 struct vm_unmapped_area_info info;
4274
4275 /*
4276@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4277 return addr;
4278 }
4279
4280+#ifdef CONFIG_PAX_RANDMMAP
4281+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4282+#endif
4283+
4284 /* requesting a specific address */
4285 if (addr) {
4286 if (do_align)
4287@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4288 else
4289 addr = PAGE_ALIGN(addr);
4290 vma = find_vma(mm, addr);
4291- if (TASK_SIZE - len >= addr &&
4292- (!vma || addr + len <= vma->vm_start))
4293+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4294 return addr;
4295 }
4296
4297@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4298 info.high_limit = mm->mmap_base;
4299 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4300 info.align_offset = pgoff << PAGE_SHIFT;
4301+ info.threadstack_offset = offset;
4302 addr = vm_unmapped_area(&info);
4303
4304 /*
4305@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4306 {
4307 unsigned long random_factor = 0UL;
4308
4309+#ifdef CONFIG_PAX_RANDMMAP
4310+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4311+#endif
4312+
4313 /* 8 bits of randomness in 20 address space bits */
4314 if ((current->flags & PF_RANDOMIZE) &&
4315 !(current->personality & ADDR_NO_RANDOMIZE))
4316@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4317
4318 if (mmap_is_legacy()) {
4319 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4320+
4321+#ifdef CONFIG_PAX_RANDMMAP
4322+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4323+ mm->mmap_base += mm->delta_mmap;
4324+#endif
4325+
4326 mm->get_unmapped_area = arch_get_unmapped_area;
4327 } else {
4328 mm->mmap_base = mmap_base(random_factor);
4329+
4330+#ifdef CONFIG_PAX_RANDMMAP
4331+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4332+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4333+#endif
4334+
4335 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4336 }
4337 }
4338diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4339index b68c6b2..f66c492 100644
4340--- a/arch/arm/mm/mmu.c
4341+++ b/arch/arm/mm/mmu.c
4342@@ -39,6 +39,22 @@
4343 #include "mm.h"
4344 #include "tcm.h"
4345
4346+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4347+void modify_domain(unsigned int dom, unsigned int type)
4348+{
4349+ struct thread_info *thread = current_thread_info();
4350+ unsigned int domain = thread->cpu_domain;
4351+ /*
4352+ * DOMAIN_MANAGER might be defined to some other value,
4353+ * use the arch-defined constant
4354+ */
4355+ domain &= ~domain_val(dom, 3);
4356+ thread->cpu_domain = domain | domain_val(dom, type);
4357+ set_domain(thread->cpu_domain);
4358+}
4359+EXPORT_SYMBOL(modify_domain);
4360+#endif
4361+
4362 /*
4363 * empty_zero_page is a special page that is used for
4364 * zero-initialized data and COW.
4365@@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4366 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4367 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4368
4369-static struct mem_type mem_types[] = {
4370+#ifdef CONFIG_PAX_KERNEXEC
4371+#define L_PTE_KERNEXEC L_PTE_RDONLY
4372+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4373+#else
4374+#define L_PTE_KERNEXEC L_PTE_DIRTY
4375+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4376+#endif
4377+
4378+static struct mem_type mem_types[] __read_only = {
4379 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4380 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4381 L_PTE_SHARED,
4382@@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4383 .prot_sect = PROT_SECT_DEVICE,
4384 .domain = DOMAIN_IO,
4385 },
4386- [MT_UNCACHED] = {
4387+ [MT_UNCACHED_RW] = {
4388 .prot_pte = PROT_PTE_DEVICE,
4389 .prot_l1 = PMD_TYPE_TABLE,
4390 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4391 .domain = DOMAIN_IO,
4392 },
4393- [MT_CACHECLEAN] = {
4394- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4395+ [MT_CACHECLEAN_RO] = {
4396+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4397 .domain = DOMAIN_KERNEL,
4398 },
4399 #ifndef CONFIG_ARM_LPAE
4400- [MT_MINICLEAN] = {
4401- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4402+ [MT_MINICLEAN_RO] = {
4403+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4404 .domain = DOMAIN_KERNEL,
4405 },
4406 #endif
4407@@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4408 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4409 L_PTE_RDONLY,
4410 .prot_l1 = PMD_TYPE_TABLE,
4411- .domain = DOMAIN_USER,
4412+ .domain = DOMAIN_VECTORS,
4413 },
4414 [MT_HIGH_VECTORS] = {
4415 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4416 L_PTE_USER | L_PTE_RDONLY,
4417 .prot_l1 = PMD_TYPE_TABLE,
4418- .domain = DOMAIN_USER,
4419+ .domain = DOMAIN_VECTORS,
4420 },
4421- [MT_MEMORY_RWX] = {
4422+ [__MT_MEMORY_RWX] = {
4423 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4424 .prot_l1 = PMD_TYPE_TABLE,
4425 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4426@@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4427 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4428 .domain = DOMAIN_KERNEL,
4429 },
4430- [MT_ROM] = {
4431- .prot_sect = PMD_TYPE_SECT,
4432+ [MT_MEMORY_RX] = {
4433+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4434+ .prot_l1 = PMD_TYPE_TABLE,
4435+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4436+ .domain = DOMAIN_KERNEL,
4437+ },
4438+ [MT_ROM_RX] = {
4439+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4440 .domain = DOMAIN_KERNEL,
4441 },
4442- [MT_MEMORY_RWX_NONCACHED] = {
4443+ [MT_MEMORY_RW_NONCACHED] = {
4444 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4445 L_PTE_MT_BUFFERABLE,
4446 .prot_l1 = PMD_TYPE_TABLE,
4447 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4448 .domain = DOMAIN_KERNEL,
4449 },
4450+ [MT_MEMORY_RX_NONCACHED] = {
4451+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4452+ L_PTE_MT_BUFFERABLE,
4453+ .prot_l1 = PMD_TYPE_TABLE,
4454+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4455+ .domain = DOMAIN_KERNEL,
4456+ },
4457 [MT_MEMORY_RW_DTCM] = {
4458 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4459 L_PTE_XN,
4460@@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4461 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4462 .domain = DOMAIN_KERNEL,
4463 },
4464- [MT_MEMORY_RWX_ITCM] = {
4465- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4466+ [MT_MEMORY_RX_ITCM] = {
4467+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4468 .prot_l1 = PMD_TYPE_TABLE,
4469+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4470 .domain = DOMAIN_KERNEL,
4471 },
4472 [MT_MEMORY_RW_SO] = {
4473@@ -534,9 +572,14 @@ static void __init build_mem_type_table(void)
4474 * Mark cache clean areas and XIP ROM read only
4475 * from SVC mode and no access from userspace.
4476 */
4477- mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4478- mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4479- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4480+ mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4481+#ifdef CONFIG_PAX_KERNEXEC
4482+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4483+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4484+ mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4485+#endif
4486+ mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4487+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4488 #endif
4489
4490 if (is_smp()) {
4491@@ -552,13 +595,17 @@ static void __init build_mem_type_table(void)
4492 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4493 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4494 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4495- mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4496- mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4497+ mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4498+ mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4499 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4500 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4501+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4502+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4503 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4504- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4505- mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4506+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4507+ mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4508+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4509+ mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4510 }
4511 }
4512
4513@@ -569,15 +616,20 @@ static void __init build_mem_type_table(void)
4514 if (cpu_arch >= CPU_ARCH_ARMv6) {
4515 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4516 /* Non-cacheable Normal is XCB = 001 */
4517- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4518+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4519+ PMD_SECT_BUFFERED;
4520+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4521 PMD_SECT_BUFFERED;
4522 } else {
4523 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4524- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4525+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4526+ PMD_SECT_TEX(1);
4527+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4528 PMD_SECT_TEX(1);
4529 }
4530 } else {
4531- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4532+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4533+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4534 }
4535
4536 #ifdef CONFIG_ARM_LPAE
4537@@ -593,6 +645,8 @@ static void __init build_mem_type_table(void)
4538 vecs_pgprot |= PTE_EXT_AF;
4539 #endif
4540
4541+ user_pgprot |= __supported_pte_mask;
4542+
4543 for (i = 0; i < 16; i++) {
4544 pteval_t v = pgprot_val(protection_map[i]);
4545 protection_map[i] = __pgprot(v | user_pgprot);
4546@@ -610,21 +664,24 @@ static void __init build_mem_type_table(void)
4547
4548 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4549 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4550- mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4551- mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4552+ mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4553+ mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4554 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4555 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4556+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4557+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4558 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4559- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4560- mem_types[MT_ROM].prot_sect |= cp->pmd;
4561+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4562+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4563+ mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4564
4565 switch (cp->pmd) {
4566 case PMD_SECT_WT:
4567- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4568+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4569 break;
4570 case PMD_SECT_WB:
4571 case PMD_SECT_WBWA:
4572- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4573+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4574 break;
4575 }
4576 pr_info("Memory policy: %sData cache %s\n",
4577@@ -842,7 +899,7 @@ static void __init create_mapping(struct map_desc *md)
4578 return;
4579 }
4580
4581- if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4582+ if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4583 md->virtual >= PAGE_OFFSET &&
4584 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4585 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4586@@ -1257,18 +1314,15 @@ void __init arm_mm_memblock_reserve(void)
4587 * called function. This means you can't use any function or debugging
4588 * method which may touch any device, otherwise the kernel _will_ crash.
4589 */
4590+
4591+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4592+
4593 static void __init devicemaps_init(const struct machine_desc *mdesc)
4594 {
4595 struct map_desc map;
4596 unsigned long addr;
4597- void *vectors;
4598
4599- /*
4600- * Allocate the vector page early.
4601- */
4602- vectors = early_alloc(PAGE_SIZE * 2);
4603-
4604- early_trap_init(vectors);
4605+ early_trap_init(&vectors);
4606
4607 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4608 pmd_clear(pmd_off_k(addr));
4609@@ -1281,7 +1335,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4610 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4611 map.virtual = MODULES_VADDR;
4612 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4613- map.type = MT_ROM;
4614+ map.type = MT_ROM_RX;
4615 create_mapping(&map);
4616 #endif
4617
4618@@ -1292,14 +1346,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4619 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4620 map.virtual = FLUSH_BASE;
4621 map.length = SZ_1M;
4622- map.type = MT_CACHECLEAN;
4623+ map.type = MT_CACHECLEAN_RO;
4624 create_mapping(&map);
4625 #endif
4626 #ifdef FLUSH_BASE_MINICACHE
4627 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4628 map.virtual = FLUSH_BASE_MINICACHE;
4629 map.length = SZ_1M;
4630- map.type = MT_MINICLEAN;
4631+ map.type = MT_MINICLEAN_RO;
4632 create_mapping(&map);
4633 #endif
4634
4635@@ -1308,7 +1362,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4636 * location (0xffff0000). If we aren't using high-vectors, also
4637 * create a mapping at the low-vectors virtual address.
4638 */
4639- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4640+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4641 map.virtual = 0xffff0000;
4642 map.length = PAGE_SIZE;
4643 #ifdef CONFIG_KUSER_HELPERS
4644@@ -1365,8 +1419,10 @@ static void __init kmap_init(void)
4645 static void __init map_lowmem(void)
4646 {
4647 struct memblock_region *reg;
4648+#ifndef CONFIG_PAX_KERNEXEC
4649 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4650 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4651+#endif
4652
4653 /* Map all the lowmem memory banks. */
4654 for_each_memblock(memory, reg) {
4655@@ -1379,11 +1435,48 @@ static void __init map_lowmem(void)
4656 if (start >= end)
4657 break;
4658
4659+#ifdef CONFIG_PAX_KERNEXEC
4660+ map.pfn = __phys_to_pfn(start);
4661+ map.virtual = __phys_to_virt(start);
4662+ map.length = end - start;
4663+
4664+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4665+ struct map_desc kernel;
4666+ struct map_desc initmap;
4667+
4668+ /* when freeing initmem we will make this RW */
4669+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4670+ initmap.virtual = (unsigned long)__init_begin;
4671+ initmap.length = _sdata - __init_begin;
4672+ initmap.type = __MT_MEMORY_RWX;
4673+ create_mapping(&initmap);
4674+
4675+ /* when freeing initmem we will make this RX */
4676+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4677+ kernel.virtual = (unsigned long)_stext;
4678+ kernel.length = __init_begin - _stext;
4679+ kernel.type = __MT_MEMORY_RWX;
4680+ create_mapping(&kernel);
4681+
4682+ if (map.virtual < (unsigned long)_stext) {
4683+ map.length = (unsigned long)_stext - map.virtual;
4684+ map.type = __MT_MEMORY_RWX;
4685+ create_mapping(&map);
4686+ }
4687+
4688+ map.pfn = __phys_to_pfn(__pa(_sdata));
4689+ map.virtual = (unsigned long)_sdata;
4690+ map.length = end - __pa(_sdata);
4691+ }
4692+
4693+ map.type = MT_MEMORY_RW;
4694+ create_mapping(&map);
4695+#else
4696 if (end < kernel_x_start || start >= kernel_x_end) {
4697 map.pfn = __phys_to_pfn(start);
4698 map.virtual = __phys_to_virt(start);
4699 map.length = end - start;
4700- map.type = MT_MEMORY_RWX;
4701+ map.type = __MT_MEMORY_RWX;
4702
4703 create_mapping(&map);
4704 } else {
4705@@ -1400,7 +1493,7 @@ static void __init map_lowmem(void)
4706 map.pfn = __phys_to_pfn(kernel_x_start);
4707 map.virtual = __phys_to_virt(kernel_x_start);
4708 map.length = kernel_x_end - kernel_x_start;
4709- map.type = MT_MEMORY_RWX;
4710+ map.type = __MT_MEMORY_RWX;
4711
4712 create_mapping(&map);
4713
4714@@ -1413,6 +1506,7 @@ static void __init map_lowmem(void)
4715 create_mapping(&map);
4716 }
4717 }
4718+#endif
4719 }
4720 }
4721
4722diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4723index 5b217f4..c23f40e 100644
4724--- a/arch/arm/plat-iop/setup.c
4725+++ b/arch/arm/plat-iop/setup.c
4726@@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4727 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4728 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4729 .length = IOP3XX_PERIPHERAL_SIZE,
4730- .type = MT_UNCACHED,
4731+ .type = MT_UNCACHED_RW,
4732 },
4733 };
4734
4735diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4736index a5bc92d..0bb4730 100644
4737--- a/arch/arm/plat-omap/sram.c
4738+++ b/arch/arm/plat-omap/sram.c
4739@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4740 * Looks like we need to preserve some bootloader code at the
4741 * beginning of SRAM for jumping to flash for reboot to work...
4742 */
4743+ pax_open_kernel();
4744 memset_io(omap_sram_base + omap_sram_skip, 0,
4745 omap_sram_size - omap_sram_skip);
4746+ pax_close_kernel();
4747 }
4748diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4749index ce6d763..cfea917 100644
4750--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4751+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4752@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4753 int (*started)(unsigned ch);
4754 int (*flush)(unsigned ch);
4755 int (*stop)(unsigned ch);
4756-};
4757+} __no_const;
4758
4759 extern void *samsung_dmadev_get_ops(void);
4760 extern void *s3c_dma_get_ops(void);
4761diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4762index 66eb764..b529b84 100644
4763--- a/arch/arm64/include/asm/barrier.h
4764+++ b/arch/arm64/include/asm/barrier.h
4765@@ -41,7 +41,7 @@
4766 do { \
4767 compiletime_assert_atomic_type(*p); \
4768 smp_mb(); \
4769- ACCESS_ONCE(*p) = (v); \
4770+ ACCESS_ONCE_RW(*p) = (v); \
4771 } while (0)
4772
4773 #define smp_load_acquire(p) \
4774diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4775index 3bf8f4e..5dd5491 100644
4776--- a/arch/arm64/include/asm/uaccess.h
4777+++ b/arch/arm64/include/asm/uaccess.h
4778@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4779 flag; \
4780 })
4781
4782+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4783 #define access_ok(type, addr, size) __range_ok(addr, size)
4784 #define user_addr_max get_fs
4785
4786diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4787index c3a58a1..78fbf54 100644
4788--- a/arch/avr32/include/asm/cache.h
4789+++ b/arch/avr32/include/asm/cache.h
4790@@ -1,8 +1,10 @@
4791 #ifndef __ASM_AVR32_CACHE_H
4792 #define __ASM_AVR32_CACHE_H
4793
4794+#include <linux/const.h>
4795+
4796 #define L1_CACHE_SHIFT 5
4797-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4798+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4799
4800 /*
4801 * Memory returned by kmalloc() may be used for DMA, so we must make
4802diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4803index d232888..87c8df1 100644
4804--- a/arch/avr32/include/asm/elf.h
4805+++ b/arch/avr32/include/asm/elf.h
4806@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4807 the loader. We need to make sure that it is out of the way of the program
4808 that it will "exec", and that there is sufficient room for the brk. */
4809
4810-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4811+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4812
4813+#ifdef CONFIG_PAX_ASLR
4814+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4815+
4816+#define PAX_DELTA_MMAP_LEN 15
4817+#define PAX_DELTA_STACK_LEN 15
4818+#endif
4819
4820 /* This yields a mask that user programs can use to figure out what
4821 instruction set this CPU supports. This could be done in user space,
4822diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4823index 479330b..53717a8 100644
4824--- a/arch/avr32/include/asm/kmap_types.h
4825+++ b/arch/avr32/include/asm/kmap_types.h
4826@@ -2,9 +2,9 @@
4827 #define __ASM_AVR32_KMAP_TYPES_H
4828
4829 #ifdef CONFIG_DEBUG_HIGHMEM
4830-# define KM_TYPE_NR 29
4831+# define KM_TYPE_NR 30
4832 #else
4833-# define KM_TYPE_NR 14
4834+# define KM_TYPE_NR 15
4835 #endif
4836
4837 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4838diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4839index 0eca933..eb78c7b 100644
4840--- a/arch/avr32/mm/fault.c
4841+++ b/arch/avr32/mm/fault.c
4842@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4843
4844 int exception_trace = 1;
4845
4846+#ifdef CONFIG_PAX_PAGEEXEC
4847+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4848+{
4849+ unsigned long i;
4850+
4851+ printk(KERN_ERR "PAX: bytes at PC: ");
4852+ for (i = 0; i < 20; i++) {
4853+ unsigned char c;
4854+ if (get_user(c, (unsigned char *)pc+i))
4855+ printk(KERN_CONT "???????? ");
4856+ else
4857+ printk(KERN_CONT "%02x ", c);
4858+ }
4859+ printk("\n");
4860+}
4861+#endif
4862+
4863 /*
4864 * This routine handles page faults. It determines the address and the
4865 * problem, and then passes it off to one of the appropriate routines.
4866@@ -176,6 +193,16 @@ bad_area:
4867 up_read(&mm->mmap_sem);
4868
4869 if (user_mode(regs)) {
4870+
4871+#ifdef CONFIG_PAX_PAGEEXEC
4872+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4873+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4874+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4875+ do_group_exit(SIGKILL);
4876+ }
4877+ }
4878+#endif
4879+
4880 if (exception_trace && printk_ratelimit())
4881 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4882 "sp %08lx ecr %lu\n",
4883diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4884index 568885a..f8008df 100644
4885--- a/arch/blackfin/include/asm/cache.h
4886+++ b/arch/blackfin/include/asm/cache.h
4887@@ -7,6 +7,7 @@
4888 #ifndef __ARCH_BLACKFIN_CACHE_H
4889 #define __ARCH_BLACKFIN_CACHE_H
4890
4891+#include <linux/const.h>
4892 #include <linux/linkage.h> /* for asmlinkage */
4893
4894 /*
4895@@ -14,7 +15,7 @@
4896 * Blackfin loads 32 bytes for cache
4897 */
4898 #define L1_CACHE_SHIFT 5
4899-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4900+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4901 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4902
4903 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4904diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4905index aea2718..3639a60 100644
4906--- a/arch/cris/include/arch-v10/arch/cache.h
4907+++ b/arch/cris/include/arch-v10/arch/cache.h
4908@@ -1,8 +1,9 @@
4909 #ifndef _ASM_ARCH_CACHE_H
4910 #define _ASM_ARCH_CACHE_H
4911
4912+#include <linux/const.h>
4913 /* Etrax 100LX have 32-byte cache-lines. */
4914-#define L1_CACHE_BYTES 32
4915 #define L1_CACHE_SHIFT 5
4916+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4917
4918 #endif /* _ASM_ARCH_CACHE_H */
4919diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4920index 7caf25d..ee65ac5 100644
4921--- a/arch/cris/include/arch-v32/arch/cache.h
4922+++ b/arch/cris/include/arch-v32/arch/cache.h
4923@@ -1,11 +1,12 @@
4924 #ifndef _ASM_CRIS_ARCH_CACHE_H
4925 #define _ASM_CRIS_ARCH_CACHE_H
4926
4927+#include <linux/const.h>
4928 #include <arch/hwregs/dma.h>
4929
4930 /* A cache-line is 32 bytes. */
4931-#define L1_CACHE_BYTES 32
4932 #define L1_CACHE_SHIFT 5
4933+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4934
4935 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4936
4937diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4938index b86329d..6709906 100644
4939--- a/arch/frv/include/asm/atomic.h
4940+++ b/arch/frv/include/asm/atomic.h
4941@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4942 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4943 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4944
4945+#define atomic64_read_unchecked(v) atomic64_read(v)
4946+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4947+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4948+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4949+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4950+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4951+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4952+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4953+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4954+
4955 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4956 {
4957 int c, old;
4958diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4959index 2797163..c2a401d 100644
4960--- a/arch/frv/include/asm/cache.h
4961+++ b/arch/frv/include/asm/cache.h
4962@@ -12,10 +12,11 @@
4963 #ifndef __ASM_CACHE_H
4964 #define __ASM_CACHE_H
4965
4966+#include <linux/const.h>
4967
4968 /* bytes per L1 cache line */
4969 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4970-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4971+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4972
4973 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4974 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4975diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4976index 43901f2..0d8b865 100644
4977--- a/arch/frv/include/asm/kmap_types.h
4978+++ b/arch/frv/include/asm/kmap_types.h
4979@@ -2,6 +2,6 @@
4980 #ifndef _ASM_KMAP_TYPES_H
4981 #define _ASM_KMAP_TYPES_H
4982
4983-#define KM_TYPE_NR 17
4984+#define KM_TYPE_NR 18
4985
4986 #endif
4987diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4988index 836f147..4cf23f5 100644
4989--- a/arch/frv/mm/elf-fdpic.c
4990+++ b/arch/frv/mm/elf-fdpic.c
4991@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4992 {
4993 struct vm_area_struct *vma;
4994 struct vm_unmapped_area_info info;
4995+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4996
4997 if (len > TASK_SIZE)
4998 return -ENOMEM;
4999@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5000 if (addr) {
5001 addr = PAGE_ALIGN(addr);
5002 vma = find_vma(current->mm, addr);
5003- if (TASK_SIZE - len >= addr &&
5004- (!vma || addr + len <= vma->vm_start))
5005+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5006 goto success;
5007 }
5008
5009@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5010 info.high_limit = (current->mm->start_stack - 0x00200000);
5011 info.align_mask = 0;
5012 info.align_offset = 0;
5013+ info.threadstack_offset = offset;
5014 addr = vm_unmapped_area(&info);
5015 if (!(addr & ~PAGE_MASK))
5016 goto success;
5017diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5018index f4ca594..adc72fd6 100644
5019--- a/arch/hexagon/include/asm/cache.h
5020+++ b/arch/hexagon/include/asm/cache.h
5021@@ -21,9 +21,11 @@
5022 #ifndef __ASM_CACHE_H
5023 #define __ASM_CACHE_H
5024
5025+#include <linux/const.h>
5026+
5027 /* Bytes per L1 cache line */
5028-#define L1_CACHE_SHIFT (5)
5029-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5030+#define L1_CACHE_SHIFT 5
5031+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5032
5033 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5034 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5035diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5036index 12c3afe..b1abab2 100644
5037--- a/arch/ia64/Kconfig
5038+++ b/arch/ia64/Kconfig
5039@@ -546,6 +546,7 @@ source "drivers/sn/Kconfig"
5040 config KEXEC
5041 bool "kexec system call"
5042 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5043+ depends on !GRKERNSEC_KMEM
5044 help
5045 kexec is a system call that implements the ability to shutdown your
5046 current kernel, and to start another kernel. It is like a reboot
5047diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5048index 6e6fe18..a6ae668 100644
5049--- a/arch/ia64/include/asm/atomic.h
5050+++ b/arch/ia64/include/asm/atomic.h
5051@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5052 #define atomic64_inc(v) atomic64_add(1, (v))
5053 #define atomic64_dec(v) atomic64_sub(1, (v))
5054
5055+#define atomic64_read_unchecked(v) atomic64_read(v)
5056+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5057+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5058+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5059+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5060+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5061+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5062+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5063+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5064+
5065 /* Atomic operations are already serializing */
5066 #define smp_mb__before_atomic_dec() barrier()
5067 #define smp_mb__after_atomic_dec() barrier()
5068diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5069index d0a69aa..142f878 100644
5070--- a/arch/ia64/include/asm/barrier.h
5071+++ b/arch/ia64/include/asm/barrier.h
5072@@ -64,7 +64,7 @@
5073 do { \
5074 compiletime_assert_atomic_type(*p); \
5075 barrier(); \
5076- ACCESS_ONCE(*p) = (v); \
5077+ ACCESS_ONCE_RW(*p) = (v); \
5078 } while (0)
5079
5080 #define smp_load_acquire(p) \
5081diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5082index 988254a..e1ee885 100644
5083--- a/arch/ia64/include/asm/cache.h
5084+++ b/arch/ia64/include/asm/cache.h
5085@@ -1,6 +1,7 @@
5086 #ifndef _ASM_IA64_CACHE_H
5087 #define _ASM_IA64_CACHE_H
5088
5089+#include <linux/const.h>
5090
5091 /*
5092 * Copyright (C) 1998-2000 Hewlett-Packard Co
5093@@ -9,7 +10,7 @@
5094
5095 /* Bytes per L1 (data) cache line. */
5096 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5097-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5098+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5099
5100 #ifdef CONFIG_SMP
5101 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5102diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5103index 5a83c5c..4d7f553 100644
5104--- a/arch/ia64/include/asm/elf.h
5105+++ b/arch/ia64/include/asm/elf.h
5106@@ -42,6 +42,13 @@
5107 */
5108 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5109
5110+#ifdef CONFIG_PAX_ASLR
5111+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5112+
5113+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5114+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5115+#endif
5116+
5117 #define PT_IA_64_UNWIND 0x70000001
5118
5119 /* IA-64 relocations: */
5120diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5121index 5767cdf..7462574 100644
5122--- a/arch/ia64/include/asm/pgalloc.h
5123+++ b/arch/ia64/include/asm/pgalloc.h
5124@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5125 pgd_val(*pgd_entry) = __pa(pud);
5126 }
5127
5128+static inline void
5129+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5130+{
5131+ pgd_populate(mm, pgd_entry, pud);
5132+}
5133+
5134 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5135 {
5136 return quicklist_alloc(0, GFP_KERNEL, NULL);
5137@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5138 pud_val(*pud_entry) = __pa(pmd);
5139 }
5140
5141+static inline void
5142+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5143+{
5144+ pud_populate(mm, pud_entry, pmd);
5145+}
5146+
5147 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5148 {
5149 return quicklist_alloc(0, GFP_KERNEL, NULL);
5150diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5151index 7935115..c0eca6a 100644
5152--- a/arch/ia64/include/asm/pgtable.h
5153+++ b/arch/ia64/include/asm/pgtable.h
5154@@ -12,7 +12,7 @@
5155 * David Mosberger-Tang <davidm@hpl.hp.com>
5156 */
5157
5158-
5159+#include <linux/const.h>
5160 #include <asm/mman.h>
5161 #include <asm/page.h>
5162 #include <asm/processor.h>
5163@@ -142,6 +142,17 @@
5164 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5165 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5166 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5167+
5168+#ifdef CONFIG_PAX_PAGEEXEC
5169+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5170+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5171+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5172+#else
5173+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5174+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5175+# define PAGE_COPY_NOEXEC PAGE_COPY
5176+#endif
5177+
5178 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5179 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5180 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5181diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5182index 45698cd..e8e2dbc 100644
5183--- a/arch/ia64/include/asm/spinlock.h
5184+++ b/arch/ia64/include/asm/spinlock.h
5185@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5186 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5187
5188 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5189- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5190+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5191 }
5192
5193 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5194diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5195index 449c8c0..3d4b1e9 100644
5196--- a/arch/ia64/include/asm/uaccess.h
5197+++ b/arch/ia64/include/asm/uaccess.h
5198@@ -70,6 +70,7 @@
5199 && ((segment).seg == KERNEL_DS.seg \
5200 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5201 })
5202+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5203 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5204
5205 /*
5206@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5207 static inline unsigned long
5208 __copy_to_user (void __user *to, const void *from, unsigned long count)
5209 {
5210+ if (count > INT_MAX)
5211+ return count;
5212+
5213+ if (!__builtin_constant_p(count))
5214+ check_object_size(from, count, true);
5215+
5216 return __copy_user(to, (__force void __user *) from, count);
5217 }
5218
5219 static inline unsigned long
5220 __copy_from_user (void *to, const void __user *from, unsigned long count)
5221 {
5222+ if (count > INT_MAX)
5223+ return count;
5224+
5225+ if (!__builtin_constant_p(count))
5226+ check_object_size(to, count, false);
5227+
5228 return __copy_user((__force void __user *) to, from, count);
5229 }
5230
5231@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5232 ({ \
5233 void __user *__cu_to = (to); \
5234 const void *__cu_from = (from); \
5235- long __cu_len = (n); \
5236+ unsigned long __cu_len = (n); \
5237 \
5238- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5239+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5240+ if (!__builtin_constant_p(n)) \
5241+ check_object_size(__cu_from, __cu_len, true); \
5242 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5243+ } \
5244 __cu_len; \
5245 })
5246
5247@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5248 ({ \
5249 void *__cu_to = (to); \
5250 const void __user *__cu_from = (from); \
5251- long __cu_len = (n); \
5252+ unsigned long __cu_len = (n); \
5253 \
5254 __chk_user_ptr(__cu_from); \
5255- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5256+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5257+ if (!__builtin_constant_p(n)) \
5258+ check_object_size(__cu_to, __cu_len, false); \
5259 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5260+ } \
5261 __cu_len; \
5262 })
5263
5264diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5265index 24603be..948052d 100644
5266--- a/arch/ia64/kernel/module.c
5267+++ b/arch/ia64/kernel/module.c
5268@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5269 void
5270 module_free (struct module *mod, void *module_region)
5271 {
5272- if (mod && mod->arch.init_unw_table &&
5273- module_region == mod->module_init) {
5274+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5275 unw_remove_unwind_table(mod->arch.init_unw_table);
5276 mod->arch.init_unw_table = NULL;
5277 }
5278@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5279 }
5280
5281 static inline int
5282+in_init_rx (const struct module *mod, uint64_t addr)
5283+{
5284+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5285+}
5286+
5287+static inline int
5288+in_init_rw (const struct module *mod, uint64_t addr)
5289+{
5290+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5291+}
5292+
5293+static inline int
5294 in_init (const struct module *mod, uint64_t addr)
5295 {
5296- return addr - (uint64_t) mod->module_init < mod->init_size;
5297+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5298+}
5299+
5300+static inline int
5301+in_core_rx (const struct module *mod, uint64_t addr)
5302+{
5303+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5304+}
5305+
5306+static inline int
5307+in_core_rw (const struct module *mod, uint64_t addr)
5308+{
5309+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5310 }
5311
5312 static inline int
5313 in_core (const struct module *mod, uint64_t addr)
5314 {
5315- return addr - (uint64_t) mod->module_core < mod->core_size;
5316+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5317 }
5318
5319 static inline int
5320@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5321 break;
5322
5323 case RV_BDREL:
5324- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5325+ if (in_init_rx(mod, val))
5326+ val -= (uint64_t) mod->module_init_rx;
5327+ else if (in_init_rw(mod, val))
5328+ val -= (uint64_t) mod->module_init_rw;
5329+ else if (in_core_rx(mod, val))
5330+ val -= (uint64_t) mod->module_core_rx;
5331+ else if (in_core_rw(mod, val))
5332+ val -= (uint64_t) mod->module_core_rw;
5333 break;
5334
5335 case RV_LTV:
5336@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5337 * addresses have been selected...
5338 */
5339 uint64_t gp;
5340- if (mod->core_size > MAX_LTOFF)
5341+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5342 /*
5343 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5344 * at the end of the module.
5345 */
5346- gp = mod->core_size - MAX_LTOFF / 2;
5347+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5348 else
5349- gp = mod->core_size / 2;
5350- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5351+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5352+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5353 mod->arch.gp = gp;
5354 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5355 }
5356diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5357index c39c3cd..3c77738 100644
5358--- a/arch/ia64/kernel/palinfo.c
5359+++ b/arch/ia64/kernel/palinfo.c
5360@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5361 return NOTIFY_OK;
5362 }
5363
5364-static struct notifier_block __refdata palinfo_cpu_notifier =
5365+static struct notifier_block palinfo_cpu_notifier =
5366 {
5367 .notifier_call = palinfo_cpu_callback,
5368 .priority = 0,
5369diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5370index 41e33f8..65180b2a 100644
5371--- a/arch/ia64/kernel/sys_ia64.c
5372+++ b/arch/ia64/kernel/sys_ia64.c
5373@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5374 unsigned long align_mask = 0;
5375 struct mm_struct *mm = current->mm;
5376 struct vm_unmapped_area_info info;
5377+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5378
5379 if (len > RGN_MAP_LIMIT)
5380 return -ENOMEM;
5381@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5382 if (REGION_NUMBER(addr) == RGN_HPAGE)
5383 addr = 0;
5384 #endif
5385+
5386+#ifdef CONFIG_PAX_RANDMMAP
5387+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5388+ addr = mm->free_area_cache;
5389+ else
5390+#endif
5391+
5392 if (!addr)
5393 addr = TASK_UNMAPPED_BASE;
5394
5395@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5396 info.high_limit = TASK_SIZE;
5397 info.align_mask = align_mask;
5398 info.align_offset = 0;
5399+ info.threadstack_offset = offset;
5400 return vm_unmapped_area(&info);
5401 }
5402
5403diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5404index 84f8a52..7c76178 100644
5405--- a/arch/ia64/kernel/vmlinux.lds.S
5406+++ b/arch/ia64/kernel/vmlinux.lds.S
5407@@ -192,7 +192,7 @@ SECTIONS {
5408 /* Per-cpu data: */
5409 . = ALIGN(PERCPU_PAGE_SIZE);
5410 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5411- __phys_per_cpu_start = __per_cpu_load;
5412+ __phys_per_cpu_start = per_cpu_load;
5413 /*
5414 * ensure percpu data fits
5415 * into percpu page size
5416diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5417index 7225dad..2a7c8256 100644
5418--- a/arch/ia64/mm/fault.c
5419+++ b/arch/ia64/mm/fault.c
5420@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5421 return pte_present(pte);
5422 }
5423
5424+#ifdef CONFIG_PAX_PAGEEXEC
5425+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5426+{
5427+ unsigned long i;
5428+
5429+ printk(KERN_ERR "PAX: bytes at PC: ");
5430+ for (i = 0; i < 8; i++) {
5431+ unsigned int c;
5432+ if (get_user(c, (unsigned int *)pc+i))
5433+ printk(KERN_CONT "???????? ");
5434+ else
5435+ printk(KERN_CONT "%08x ", c);
5436+ }
5437+ printk("\n");
5438+}
5439+#endif
5440+
5441 # define VM_READ_BIT 0
5442 # define VM_WRITE_BIT 1
5443 # define VM_EXEC_BIT 2
5444@@ -151,8 +168,21 @@ retry:
5445 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5446 goto bad_area;
5447
5448- if ((vma->vm_flags & mask) != mask)
5449+ if ((vma->vm_flags & mask) != mask) {
5450+
5451+#ifdef CONFIG_PAX_PAGEEXEC
5452+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5453+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5454+ goto bad_area;
5455+
5456+ up_read(&mm->mmap_sem);
5457+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5458+ do_group_exit(SIGKILL);
5459+ }
5460+#endif
5461+
5462 goto bad_area;
5463+ }
5464
5465 /*
5466 * If for any reason at all we couldn't handle the fault, make
5467diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5468index 68232db..6ca80af 100644
5469--- a/arch/ia64/mm/hugetlbpage.c
5470+++ b/arch/ia64/mm/hugetlbpage.c
5471@@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5472 unsigned long pgoff, unsigned long flags)
5473 {
5474 struct vm_unmapped_area_info info;
5475+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5476
5477 if (len > RGN_MAP_LIMIT)
5478 return -ENOMEM;
5479@@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5480 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5481 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5482 info.align_offset = 0;
5483+ info.threadstack_offset = offset;
5484 return vm_unmapped_area(&info);
5485 }
5486
5487diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5488index 25c3502..560dae7 100644
5489--- a/arch/ia64/mm/init.c
5490+++ b/arch/ia64/mm/init.c
5491@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5492 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5493 vma->vm_end = vma->vm_start + PAGE_SIZE;
5494 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5495+
5496+#ifdef CONFIG_PAX_PAGEEXEC
5497+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5498+ vma->vm_flags &= ~VM_EXEC;
5499+
5500+#ifdef CONFIG_PAX_MPROTECT
5501+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5502+ vma->vm_flags &= ~VM_MAYEXEC;
5503+#endif
5504+
5505+ }
5506+#endif
5507+
5508 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5509 down_write(&current->mm->mmap_sem);
5510 if (insert_vm_struct(current->mm, vma)) {
5511diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5512index 40b3ee9..8c2c112 100644
5513--- a/arch/m32r/include/asm/cache.h
5514+++ b/arch/m32r/include/asm/cache.h
5515@@ -1,8 +1,10 @@
5516 #ifndef _ASM_M32R_CACHE_H
5517 #define _ASM_M32R_CACHE_H
5518
5519+#include <linux/const.h>
5520+
5521 /* L1 cache line size */
5522 #define L1_CACHE_SHIFT 4
5523-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5524+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5525
5526 #endif /* _ASM_M32R_CACHE_H */
5527diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5528index 82abd15..d95ae5d 100644
5529--- a/arch/m32r/lib/usercopy.c
5530+++ b/arch/m32r/lib/usercopy.c
5531@@ -14,6 +14,9 @@
5532 unsigned long
5533 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5534 {
5535+ if ((long)n < 0)
5536+ return n;
5537+
5538 prefetch(from);
5539 if (access_ok(VERIFY_WRITE, to, n))
5540 __copy_user(to,from,n);
5541@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5542 unsigned long
5543 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5544 {
5545+ if ((long)n < 0)
5546+ return n;
5547+
5548 prefetchw(to);
5549 if (access_ok(VERIFY_READ, from, n))
5550 __copy_user_zeroing(to,from,n);
5551diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5552index 0395c51..5f26031 100644
5553--- a/arch/m68k/include/asm/cache.h
5554+++ b/arch/m68k/include/asm/cache.h
5555@@ -4,9 +4,11 @@
5556 #ifndef __ARCH_M68K_CACHE_H
5557 #define __ARCH_M68K_CACHE_H
5558
5559+#include <linux/const.h>
5560+
5561 /* bytes per L1 cache line */
5562 #define L1_CACHE_SHIFT 4
5563-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5564+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5565
5566 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5567
5568diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5569index 2d6f0de..de5f5ac 100644
5570--- a/arch/metag/include/asm/barrier.h
5571+++ b/arch/metag/include/asm/barrier.h
5572@@ -89,7 +89,7 @@ static inline void fence(void)
5573 do { \
5574 compiletime_assert_atomic_type(*p); \
5575 smp_mb(); \
5576- ACCESS_ONCE(*p) = (v); \
5577+ ACCESS_ONCE_RW(*p) = (v); \
5578 } while (0)
5579
5580 #define smp_load_acquire(p) \
5581diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5582index 0424315..defcca9 100644
5583--- a/arch/metag/mm/hugetlbpage.c
5584+++ b/arch/metag/mm/hugetlbpage.c
5585@@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5586 info.high_limit = TASK_SIZE;
5587 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5588 info.align_offset = 0;
5589+ info.threadstack_offset = 0;
5590 return vm_unmapped_area(&info);
5591 }
5592
5593diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5594index 4efe96a..60e8699 100644
5595--- a/arch/microblaze/include/asm/cache.h
5596+++ b/arch/microblaze/include/asm/cache.h
5597@@ -13,11 +13,12 @@
5598 #ifndef _ASM_MICROBLAZE_CACHE_H
5599 #define _ASM_MICROBLAZE_CACHE_H
5600
5601+#include <linux/const.h>
5602 #include <asm/registers.h>
5603
5604 #define L1_CACHE_SHIFT 5
5605 /* word-granular cache in microblaze */
5606-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5607+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5608
5609 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5610
5611diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5612index 5cd695f..9a24ad0 100644
5613--- a/arch/mips/Kconfig
5614+++ b/arch/mips/Kconfig
5615@@ -2395,6 +2395,7 @@ source "kernel/Kconfig.preempt"
5616
5617 config KEXEC
5618 bool "Kexec system call"
5619+ depends on !GRKERNSEC_KMEM
5620 help
5621 kexec is a system call that implements the ability to shutdown your
5622 current kernel, and to start another kernel. It is like a reboot
5623diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5624index 02f2444..506969c 100644
5625--- a/arch/mips/cavium-octeon/dma-octeon.c
5626+++ b/arch/mips/cavium-octeon/dma-octeon.c
5627@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5628 if (dma_release_from_coherent(dev, order, vaddr))
5629 return;
5630
5631- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5632+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5633 }
5634
5635 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5636diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5637index e8eb3d5..2e665d1 100644
5638--- a/arch/mips/include/asm/atomic.h
5639+++ b/arch/mips/include/asm/atomic.h
5640@@ -21,15 +21,39 @@
5641 #include <asm/cmpxchg.h>
5642 #include <asm/war.h>
5643
5644+#ifdef CONFIG_GENERIC_ATOMIC64
5645+#include <asm-generic/atomic64.h>
5646+#endif
5647+
5648 #define ATOMIC_INIT(i) { (i) }
5649
5650+#ifdef CONFIG_64BIT
5651+#define _ASM_EXTABLE(from, to) \
5652+" .section __ex_table,\"a\"\n" \
5653+" .dword " #from ", " #to"\n" \
5654+" .previous\n"
5655+#else
5656+#define _ASM_EXTABLE(from, to) \
5657+" .section __ex_table,\"a\"\n" \
5658+" .word " #from ", " #to"\n" \
5659+" .previous\n"
5660+#endif
5661+
5662 /*
5663 * atomic_read - read atomic variable
5664 * @v: pointer of type atomic_t
5665 *
5666 * Atomically reads the value of @v.
5667 */
5668-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5669+static inline int atomic_read(const atomic_t *v)
5670+{
5671+ return (*(volatile const int *) &v->counter);
5672+}
5673+
5674+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5675+{
5676+ return (*(volatile const int *) &v->counter);
5677+}
5678
5679 /*
5680 * atomic_set - set atomic variable
5681@@ -38,7 +62,15 @@
5682 *
5683 * Atomically sets the value of @v to @i.
5684 */
5685-#define atomic_set(v, i) ((v)->counter = (i))
5686+static inline void atomic_set(atomic_t *v, int i)
5687+{
5688+ v->counter = i;
5689+}
5690+
5691+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5692+{
5693+ v->counter = i;
5694+}
5695
5696 /*
5697 * atomic_add - add integer to atomic variable
5698@@ -47,7 +79,67 @@
5699 *
5700 * Atomically adds @i to @v.
5701 */
5702-static __inline__ void atomic_add(int i, atomic_t * v)
5703+static __inline__ void atomic_add(int i, atomic_t *v)
5704+{
5705+ int temp;
5706+
5707+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5708+ __asm__ __volatile__(
5709+ " .set mips3 \n"
5710+ "1: ll %0, %1 # atomic_add \n"
5711+#ifdef CONFIG_PAX_REFCOUNT
5712+ /* Exception on overflow. */
5713+ "2: add %0, %2 \n"
5714+#else
5715+ " addu %0, %2 \n"
5716+#endif
5717+ " sc %0, %1 \n"
5718+ " beqzl %0, 1b \n"
5719+#ifdef CONFIG_PAX_REFCOUNT
5720+ "3: \n"
5721+ _ASM_EXTABLE(2b, 3b)
5722+#endif
5723+ " .set mips0 \n"
5724+ : "=&r" (temp), "+m" (v->counter)
5725+ : "Ir" (i));
5726+ } else if (kernel_uses_llsc) {
5727+ __asm__ __volatile__(
5728+ " .set mips3 \n"
5729+ "1: ll %0, %1 # atomic_add \n"
5730+#ifdef CONFIG_PAX_REFCOUNT
5731+ /* Exception on overflow. */
5732+ "2: add %0, %2 \n"
5733+#else
5734+ " addu %0, %2 \n"
5735+#endif
5736+ " sc %0, %1 \n"
5737+ " beqz %0, 1b \n"
5738+#ifdef CONFIG_PAX_REFCOUNT
5739+ "3: \n"
5740+ _ASM_EXTABLE(2b, 3b)
5741+#endif
5742+ " .set mips0 \n"
5743+ : "=&r" (temp), "+m" (v->counter)
5744+ : "Ir" (i));
5745+ } else {
5746+ unsigned long flags;
5747+
5748+ raw_local_irq_save(flags);
5749+ __asm__ __volatile__(
5750+#ifdef CONFIG_PAX_REFCOUNT
5751+ /* Exception on overflow. */
5752+ "1: add %0, %1 \n"
5753+ "2: \n"
5754+ _ASM_EXTABLE(1b, 2b)
5755+#else
5756+ " addu %0, %1 \n"
5757+#endif
5758+ : "+r" (v->counter) : "Ir" (i));
5759+ raw_local_irq_restore(flags);
5760+ }
5761+}
5762+
5763+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5764 {
5765 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5766 int temp;
5767@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5768 *
5769 * Atomically subtracts @i from @v.
5770 */
5771-static __inline__ void atomic_sub(int i, atomic_t * v)
5772+static __inline__ void atomic_sub(int i, atomic_t *v)
5773+{
5774+ int temp;
5775+
5776+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5777+ __asm__ __volatile__(
5778+ " .set mips3 \n"
5779+ "1: ll %0, %1 # atomic64_sub \n"
5780+#ifdef CONFIG_PAX_REFCOUNT
5781+ /* Exception on overflow. */
5782+ "2: sub %0, %2 \n"
5783+#else
5784+ " subu %0, %2 \n"
5785+#endif
5786+ " sc %0, %1 \n"
5787+ " beqzl %0, 1b \n"
5788+#ifdef CONFIG_PAX_REFCOUNT
5789+ "3: \n"
5790+ _ASM_EXTABLE(2b, 3b)
5791+#endif
5792+ " .set mips0 \n"
5793+ : "=&r" (temp), "+m" (v->counter)
5794+ : "Ir" (i));
5795+ } else if (kernel_uses_llsc) {
5796+ __asm__ __volatile__(
5797+ " .set mips3 \n"
5798+ "1: ll %0, %1 # atomic64_sub \n"
5799+#ifdef CONFIG_PAX_REFCOUNT
5800+ /* Exception on overflow. */
5801+ "2: sub %0, %2 \n"
5802+#else
5803+ " subu %0, %2 \n"
5804+#endif
5805+ " sc %0, %1 \n"
5806+ " beqz %0, 1b \n"
5807+#ifdef CONFIG_PAX_REFCOUNT
5808+ "3: \n"
5809+ _ASM_EXTABLE(2b, 3b)
5810+#endif
5811+ " .set mips0 \n"
5812+ : "=&r" (temp), "+m" (v->counter)
5813+ : "Ir" (i));
5814+ } else {
5815+ unsigned long flags;
5816+
5817+ raw_local_irq_save(flags);
5818+ __asm__ __volatile__(
5819+#ifdef CONFIG_PAX_REFCOUNT
5820+ /* Exception on overflow. */
5821+ "1: sub %0, %1 \n"
5822+ "2: \n"
5823+ _ASM_EXTABLE(1b, 2b)
5824+#else
5825+ " subu %0, %1 \n"
5826+#endif
5827+ : "+r" (v->counter) : "Ir" (i));
5828+ raw_local_irq_restore(flags);
5829+ }
5830+}
5831+
5832+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5833 {
5834 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5835 int temp;
5836@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5837 /*
5838 * Same as above, but return the result value
5839 */
5840-static __inline__ int atomic_add_return(int i, atomic_t * v)
5841+static __inline__ int atomic_add_return(int i, atomic_t *v)
5842+{
5843+ int result;
5844+ int temp;
5845+
5846+ smp_mb__before_llsc();
5847+
5848+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5849+ __asm__ __volatile__(
5850+ " .set mips3 \n"
5851+ "1: ll %1, %2 # atomic_add_return \n"
5852+#ifdef CONFIG_PAX_REFCOUNT
5853+ "2: add %0, %1, %3 \n"
5854+#else
5855+ " addu %0, %1, %3 \n"
5856+#endif
5857+ " sc %0, %2 \n"
5858+ " beqzl %0, 1b \n"
5859+#ifdef CONFIG_PAX_REFCOUNT
5860+ " b 4f \n"
5861+ " .set noreorder \n"
5862+ "3: b 5f \n"
5863+ " move %0, %1 \n"
5864+ " .set reorder \n"
5865+ _ASM_EXTABLE(2b, 3b)
5866+#endif
5867+ "4: addu %0, %1, %3 \n"
5868+#ifdef CONFIG_PAX_REFCOUNT
5869+ "5: \n"
5870+#endif
5871+ " .set mips0 \n"
5872+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5873+ : "Ir" (i));
5874+ } else if (kernel_uses_llsc) {
5875+ __asm__ __volatile__(
5876+ " .set mips3 \n"
5877+ "1: ll %1, %2 # atomic_add_return \n"
5878+#ifdef CONFIG_PAX_REFCOUNT
5879+ "2: add %0, %1, %3 \n"
5880+#else
5881+ " addu %0, %1, %3 \n"
5882+#endif
5883+ " sc %0, %2 \n"
5884+ " bnez %0, 4f \n"
5885+ " b 1b \n"
5886+#ifdef CONFIG_PAX_REFCOUNT
5887+ " .set noreorder \n"
5888+ "3: b 5f \n"
5889+ " move %0, %1 \n"
5890+ " .set reorder \n"
5891+ _ASM_EXTABLE(2b, 3b)
5892+#endif
5893+ "4: addu %0, %1, %3 \n"
5894+#ifdef CONFIG_PAX_REFCOUNT
5895+ "5: \n"
5896+#endif
5897+ " .set mips0 \n"
5898+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5899+ : "Ir" (i));
5900+ } else {
5901+ unsigned long flags;
5902+
5903+ raw_local_irq_save(flags);
5904+ __asm__ __volatile__(
5905+ " lw %0, %1 \n"
5906+#ifdef CONFIG_PAX_REFCOUNT
5907+ /* Exception on overflow. */
5908+ "1: add %0, %2 \n"
5909+#else
5910+ " addu %0, %2 \n"
5911+#endif
5912+ " sw %0, %1 \n"
5913+#ifdef CONFIG_PAX_REFCOUNT
5914+ /* Note: Dest reg is not modified on overflow */
5915+ "2: \n"
5916+ _ASM_EXTABLE(1b, 2b)
5917+#endif
5918+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5919+ raw_local_irq_restore(flags);
5920+ }
5921+
5922+ smp_llsc_mb();
5923+
5924+ return result;
5925+}
5926+
5927+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5928 {
5929 int result;
5930
5931@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5932 return result;
5933 }
5934
5935-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5936+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5937+{
5938+ int result;
5939+ int temp;
5940+
5941+ smp_mb__before_llsc();
5942+
5943+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5944+ __asm__ __volatile__(
5945+ " .set mips3 \n"
5946+ "1: ll %1, %2 # atomic_sub_return \n"
5947+#ifdef CONFIG_PAX_REFCOUNT
5948+ "2: sub %0, %1, %3 \n"
5949+#else
5950+ " subu %0, %1, %3 \n"
5951+#endif
5952+ " sc %0, %2 \n"
5953+ " beqzl %0, 1b \n"
5954+#ifdef CONFIG_PAX_REFCOUNT
5955+ " b 4f \n"
5956+ " .set noreorder \n"
5957+ "3: b 5f \n"
5958+ " move %0, %1 \n"
5959+ " .set reorder \n"
5960+ _ASM_EXTABLE(2b, 3b)
5961+#endif
5962+ "4: subu %0, %1, %3 \n"
5963+#ifdef CONFIG_PAX_REFCOUNT
5964+ "5: \n"
5965+#endif
5966+ " .set mips0 \n"
5967+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5968+ : "Ir" (i), "m" (v->counter)
5969+ : "memory");
5970+ } else if (kernel_uses_llsc) {
5971+ __asm__ __volatile__(
5972+ " .set mips3 \n"
5973+ "1: ll %1, %2 # atomic_sub_return \n"
5974+#ifdef CONFIG_PAX_REFCOUNT
5975+ "2: sub %0, %1, %3 \n"
5976+#else
5977+ " subu %0, %1, %3 \n"
5978+#endif
5979+ " sc %0, %2 \n"
5980+ " bnez %0, 4f \n"
5981+ " b 1b \n"
5982+#ifdef CONFIG_PAX_REFCOUNT
5983+ " .set noreorder \n"
5984+ "3: b 5f \n"
5985+ " move %0, %1 \n"
5986+ " .set reorder \n"
5987+ _ASM_EXTABLE(2b, 3b)
5988+#endif
5989+ "4: subu %0, %1, %3 \n"
5990+#ifdef CONFIG_PAX_REFCOUNT
5991+ "5: \n"
5992+#endif
5993+ " .set mips0 \n"
5994+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5995+ : "Ir" (i));
5996+ } else {
5997+ unsigned long flags;
5998+
5999+ raw_local_irq_save(flags);
6000+ __asm__ __volatile__(
6001+ " lw %0, %1 \n"
6002+#ifdef CONFIG_PAX_REFCOUNT
6003+ /* Exception on overflow. */
6004+ "1: sub %0, %2 \n"
6005+#else
6006+ " subu %0, %2 \n"
6007+#endif
6008+ " sw %0, %1 \n"
6009+#ifdef CONFIG_PAX_REFCOUNT
6010+ /* Note: Dest reg is not modified on overflow */
6011+ "2: \n"
6012+ _ASM_EXTABLE(1b, 2b)
6013+#endif
6014+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6015+ raw_local_irq_restore(flags);
6016+ }
6017+
6018+ smp_llsc_mb();
6019+
6020+ return result;
6021+}
6022+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6023 {
6024 int result;
6025
6026@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6027 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6028 * The function returns the old value of @v minus @i.
6029 */
6030-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6031+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6032 {
6033 int result;
6034
6035@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6036 return result;
6037 }
6038
6039-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6040-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6041+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6042+{
6043+ return cmpxchg(&v->counter, old, new);
6044+}
6045+
6046+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6047+ int new)
6048+{
6049+ return cmpxchg(&(v->counter), old, new);
6050+}
6051+
6052+static inline int atomic_xchg(atomic_t *v, int new)
6053+{
6054+ return xchg(&v->counter, new);
6055+}
6056+
6057+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6058+{
6059+ return xchg(&(v->counter), new);
6060+}
6061
6062 /**
6063 * __atomic_add_unless - add unless the number is a given value
6064@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6065
6066 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6067 #define atomic_inc_return(v) atomic_add_return(1, (v))
6068+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6069+{
6070+ return atomic_add_return_unchecked(1, v);
6071+}
6072
6073 /*
6074 * atomic_sub_and_test - subtract value from variable and test result
6075@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6076 * other cases.
6077 */
6078 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6079+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6080+{
6081+ return atomic_add_return_unchecked(1, v) == 0;
6082+}
6083
6084 /*
6085 * atomic_dec_and_test - decrement by 1 and test
6086@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6087 * Atomically increments @v by 1.
6088 */
6089 #define atomic_inc(v) atomic_add(1, (v))
6090+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6091+{
6092+ atomic_add_unchecked(1, v);
6093+}
6094
6095 /*
6096 * atomic_dec - decrement and test
6097@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6098 * Atomically decrements @v by 1.
6099 */
6100 #define atomic_dec(v) atomic_sub(1, (v))
6101+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6102+{
6103+ atomic_sub_unchecked(1, v);
6104+}
6105
6106 /*
6107 * atomic_add_negative - add and test if negative
6108@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6109 * @v: pointer of type atomic64_t
6110 *
6111 */
6112-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6113+static inline long atomic64_read(const atomic64_t *v)
6114+{
6115+ return (*(volatile const long *) &v->counter);
6116+}
6117+
6118+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6119+{
6120+ return (*(volatile const long *) &v->counter);
6121+}
6122
6123 /*
6124 * atomic64_set - set atomic variable
6125 * @v: pointer of type atomic64_t
6126 * @i: required value
6127 */
6128-#define atomic64_set(v, i) ((v)->counter = (i))
6129+static inline void atomic64_set(atomic64_t *v, long i)
6130+{
6131+ v->counter = i;
6132+}
6133+
6134+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6135+{
6136+ v->counter = i;
6137+}
6138
6139 /*
6140 * atomic64_add - add integer to atomic variable
6141@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6142 *
6143 * Atomically adds @i to @v.
6144 */
6145-static __inline__ void atomic64_add(long i, atomic64_t * v)
6146+static __inline__ void atomic64_add(long i, atomic64_t *v)
6147+{
6148+ long temp;
6149+
6150+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6151+ __asm__ __volatile__(
6152+ " .set mips3 \n"
6153+ "1: lld %0, %1 # atomic64_add \n"
6154+#ifdef CONFIG_PAX_REFCOUNT
6155+ /* Exception on overflow. */
6156+ "2: dadd %0, %2 \n"
6157+#else
6158+ " daddu %0, %2 \n"
6159+#endif
6160+ " scd %0, %1 \n"
6161+ " beqzl %0, 1b \n"
6162+#ifdef CONFIG_PAX_REFCOUNT
6163+ "3: \n"
6164+ _ASM_EXTABLE(2b, 3b)
6165+#endif
6166+ " .set mips0 \n"
6167+ : "=&r" (temp), "+m" (v->counter)
6168+ : "Ir" (i));
6169+ } else if (kernel_uses_llsc) {
6170+ __asm__ __volatile__(
6171+ " .set mips3 \n"
6172+ "1: lld %0, %1 # atomic64_add \n"
6173+#ifdef CONFIG_PAX_REFCOUNT
6174+ /* Exception on overflow. */
6175+ "2: dadd %0, %2 \n"
6176+#else
6177+ " daddu %0, %2 \n"
6178+#endif
6179+ " scd %0, %1 \n"
6180+ " beqz %0, 1b \n"
6181+#ifdef CONFIG_PAX_REFCOUNT
6182+ "3: \n"
6183+ _ASM_EXTABLE(2b, 3b)
6184+#endif
6185+ " .set mips0 \n"
6186+ : "=&r" (temp), "+m" (v->counter)
6187+ : "Ir" (i));
6188+ } else {
6189+ unsigned long flags;
6190+
6191+ raw_local_irq_save(flags);
6192+ __asm__ __volatile__(
6193+#ifdef CONFIG_PAX_REFCOUNT
6194+ /* Exception on overflow. */
6195+ "1: dadd %0, %1 \n"
6196+ "2: \n"
6197+ _ASM_EXTABLE(1b, 2b)
6198+#else
6199+ " daddu %0, %1 \n"
6200+#endif
6201+ : "+r" (v->counter) : "Ir" (i));
6202+ raw_local_irq_restore(flags);
6203+ }
6204+}
6205+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6206 {
6207 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6208 long temp;
6209@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6210 *
6211 * Atomically subtracts @i from @v.
6212 */
6213-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6214+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6215+{
6216+ long temp;
6217+
6218+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6219+ __asm__ __volatile__(
6220+ " .set mips3 \n"
6221+ "1: lld %0, %1 # atomic64_sub \n"
6222+#ifdef CONFIG_PAX_REFCOUNT
6223+ /* Exception on overflow. */
6224+ "2: dsub %0, %2 \n"
6225+#else
6226+ " dsubu %0, %2 \n"
6227+#endif
6228+ " scd %0, %1 \n"
6229+ " beqzl %0, 1b \n"
6230+#ifdef CONFIG_PAX_REFCOUNT
6231+ "3: \n"
6232+ _ASM_EXTABLE(2b, 3b)
6233+#endif
6234+ " .set mips0 \n"
6235+ : "=&r" (temp), "+m" (v->counter)
6236+ : "Ir" (i));
6237+ } else if (kernel_uses_llsc) {
6238+ __asm__ __volatile__(
6239+ " .set mips3 \n"
6240+ "1: lld %0, %1 # atomic64_sub \n"
6241+#ifdef CONFIG_PAX_REFCOUNT
6242+ /* Exception on overflow. */
6243+ "2: dsub %0, %2 \n"
6244+#else
6245+ " dsubu %0, %2 \n"
6246+#endif
6247+ " scd %0, %1 \n"
6248+ " beqz %0, 1b \n"
6249+#ifdef CONFIG_PAX_REFCOUNT
6250+ "3: \n"
6251+ _ASM_EXTABLE(2b, 3b)
6252+#endif
6253+ " .set mips0 \n"
6254+ : "=&r" (temp), "+m" (v->counter)
6255+ : "Ir" (i));
6256+ } else {
6257+ unsigned long flags;
6258+
6259+ raw_local_irq_save(flags);
6260+ __asm__ __volatile__(
6261+#ifdef CONFIG_PAX_REFCOUNT
6262+ /* Exception on overflow. */
6263+ "1: dsub %0, %1 \n"
6264+ "2: \n"
6265+ _ASM_EXTABLE(1b, 2b)
6266+#else
6267+ " dsubu %0, %1 \n"
6268+#endif
6269+ : "+r" (v->counter) : "Ir" (i));
6270+ raw_local_irq_restore(flags);
6271+ }
6272+}
6273+
6274+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6275 {
6276 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6277 long temp;
6278@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6279 /*
6280 * Same as above, but return the result value
6281 */
6282-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6283+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6284+{
6285+ long result;
6286+ long temp;
6287+
6288+ smp_mb__before_llsc();
6289+
6290+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6291+ __asm__ __volatile__(
6292+ " .set mips3 \n"
6293+ "1: lld %1, %2 # atomic64_add_return \n"
6294+#ifdef CONFIG_PAX_REFCOUNT
6295+ "2: dadd %0, %1, %3 \n"
6296+#else
6297+ " daddu %0, %1, %3 \n"
6298+#endif
6299+ " scd %0, %2 \n"
6300+ " beqzl %0, 1b \n"
6301+#ifdef CONFIG_PAX_REFCOUNT
6302+ " b 4f \n"
6303+ " .set noreorder \n"
6304+ "3: b 5f \n"
6305+ " move %0, %1 \n"
6306+ " .set reorder \n"
6307+ _ASM_EXTABLE(2b, 3b)
6308+#endif
6309+ "4: daddu %0, %1, %3 \n"
6310+#ifdef CONFIG_PAX_REFCOUNT
6311+ "5: \n"
6312+#endif
6313+ " .set mips0 \n"
6314+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6315+ : "Ir" (i));
6316+ } else if (kernel_uses_llsc) {
6317+ __asm__ __volatile__(
6318+ " .set mips3 \n"
6319+ "1: lld %1, %2 # atomic64_add_return \n"
6320+#ifdef CONFIG_PAX_REFCOUNT
6321+ "2: dadd %0, %1, %3 \n"
6322+#else
6323+ " daddu %0, %1, %3 \n"
6324+#endif
6325+ " scd %0, %2 \n"
6326+ " bnez %0, 4f \n"
6327+ " b 1b \n"
6328+#ifdef CONFIG_PAX_REFCOUNT
6329+ " .set noreorder \n"
6330+ "3: b 5f \n"
6331+ " move %0, %1 \n"
6332+ " .set reorder \n"
6333+ _ASM_EXTABLE(2b, 3b)
6334+#endif
6335+ "4: daddu %0, %1, %3 \n"
6336+#ifdef CONFIG_PAX_REFCOUNT
6337+ "5: \n"
6338+#endif
6339+ " .set mips0 \n"
6340+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6341+ : "Ir" (i), "m" (v->counter)
6342+ : "memory");
6343+ } else {
6344+ unsigned long flags;
6345+
6346+ raw_local_irq_save(flags);
6347+ __asm__ __volatile__(
6348+ " ld %0, %1 \n"
6349+#ifdef CONFIG_PAX_REFCOUNT
6350+ /* Exception on overflow. */
6351+ "1: dadd %0, %2 \n"
6352+#else
6353+ " daddu %0, %2 \n"
6354+#endif
6355+ " sd %0, %1 \n"
6356+#ifdef CONFIG_PAX_REFCOUNT
6357+ /* Note: Dest reg is not modified on overflow */
6358+ "2: \n"
6359+ _ASM_EXTABLE(1b, 2b)
6360+#endif
6361+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6362+ raw_local_irq_restore(flags);
6363+ }
6364+
6365+ smp_llsc_mb();
6366+
6367+ return result;
6368+}
6369+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6370 {
6371 long result;
6372
6373@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6374 return result;
6375 }
6376
6377-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6378+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6379+{
6380+ long result;
6381+ long temp;
6382+
6383+ smp_mb__before_llsc();
6384+
6385+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6386+ long temp;
6387+
6388+ __asm__ __volatile__(
6389+ " .set mips3 \n"
6390+ "1: lld %1, %2 # atomic64_sub_return \n"
6391+#ifdef CONFIG_PAX_REFCOUNT
6392+ "2: dsub %0, %1, %3 \n"
6393+#else
6394+ " dsubu %0, %1, %3 \n"
6395+#endif
6396+ " scd %0, %2 \n"
6397+ " beqzl %0, 1b \n"
6398+#ifdef CONFIG_PAX_REFCOUNT
6399+ " b 4f \n"
6400+ " .set noreorder \n"
6401+ "3: b 5f \n"
6402+ " move %0, %1 \n"
6403+ " .set reorder \n"
6404+ _ASM_EXTABLE(2b, 3b)
6405+#endif
6406+ "4: dsubu %0, %1, %3 \n"
6407+#ifdef CONFIG_PAX_REFCOUNT
6408+ "5: \n"
6409+#endif
6410+ " .set mips0 \n"
6411+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6412+ : "Ir" (i), "m" (v->counter)
6413+ : "memory");
6414+ } else if (kernel_uses_llsc) {
6415+ __asm__ __volatile__(
6416+ " .set mips3 \n"
6417+ "1: lld %1, %2 # atomic64_sub_return \n"
6418+#ifdef CONFIG_PAX_REFCOUNT
6419+ "2: dsub %0, %1, %3 \n"
6420+#else
6421+ " dsubu %0, %1, %3 \n"
6422+#endif
6423+ " scd %0, %2 \n"
6424+ " bnez %0, 4f \n"
6425+ " b 1b \n"
6426+#ifdef CONFIG_PAX_REFCOUNT
6427+ " .set noreorder \n"
6428+ "3: b 5f \n"
6429+ " move %0, %1 \n"
6430+ " .set reorder \n"
6431+ _ASM_EXTABLE(2b, 3b)
6432+#endif
6433+ "4: dsubu %0, %1, %3 \n"
6434+#ifdef CONFIG_PAX_REFCOUNT
6435+ "5: \n"
6436+#endif
6437+ " .set mips0 \n"
6438+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6439+ : "Ir" (i), "m" (v->counter)
6440+ : "memory");
6441+ } else {
6442+ unsigned long flags;
6443+
6444+ raw_local_irq_save(flags);
6445+ __asm__ __volatile__(
6446+ " ld %0, %1 \n"
6447+#ifdef CONFIG_PAX_REFCOUNT
6448+ /* Exception on overflow. */
6449+ "1: dsub %0, %2 \n"
6450+#else
6451+ " dsubu %0, %2 \n"
6452+#endif
6453+ " sd %0, %1 \n"
6454+#ifdef CONFIG_PAX_REFCOUNT
6455+ /* Note: Dest reg is not modified on overflow */
6456+ "2: \n"
6457+ _ASM_EXTABLE(1b, 2b)
6458+#endif
6459+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6460+ raw_local_irq_restore(flags);
6461+ }
6462+
6463+ smp_llsc_mb();
6464+
6465+ return result;
6466+}
6467+
6468+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6469 {
6470 long result;
6471
6472@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6473 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6474 * The function returns the old value of @v minus @i.
6475 */
6476-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6477+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6478 {
6479 long result;
6480
6481@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6482 return result;
6483 }
6484
6485-#define atomic64_cmpxchg(v, o, n) \
6486- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6487-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6488+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6489+{
6490+ return cmpxchg(&v->counter, old, new);
6491+}
6492+
6493+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6494+ long new)
6495+{
6496+ return cmpxchg(&(v->counter), old, new);
6497+}
6498+
6499+static inline long atomic64_xchg(atomic64_t *v, long new)
6500+{
6501+ return xchg(&v->counter, new);
6502+}
6503+
6504+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6505+{
6506+ return xchg(&(v->counter), new);
6507+}
6508
6509 /**
6510 * atomic64_add_unless - add unless the number is a given value
6511@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6512
6513 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6514 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6515+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6516
6517 /*
6518 * atomic64_sub_and_test - subtract value from variable and test result
6519@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6520 * other cases.
6521 */
6522 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6523+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6524
6525 /*
6526 * atomic64_dec_and_test - decrement by 1 and test
6527@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6528 * Atomically increments @v by 1.
6529 */
6530 #define atomic64_inc(v) atomic64_add(1, (v))
6531+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6532
6533 /*
6534 * atomic64_dec - decrement and test
6535@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6536 * Atomically decrements @v by 1.
6537 */
6538 #define atomic64_dec(v) atomic64_sub(1, (v))
6539+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6540
6541 /*
6542 * atomic64_add_negative - add and test if negative
6543diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6544index e1aa4e4..670b68b 100644
6545--- a/arch/mips/include/asm/barrier.h
6546+++ b/arch/mips/include/asm/barrier.h
6547@@ -184,7 +184,7 @@
6548 do { \
6549 compiletime_assert_atomic_type(*p); \
6550 smp_mb(); \
6551- ACCESS_ONCE(*p) = (v); \
6552+ ACCESS_ONCE_RW(*p) = (v); \
6553 } while (0)
6554
6555 #define smp_load_acquire(p) \
6556diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6557index b4db69f..8f3b093 100644
6558--- a/arch/mips/include/asm/cache.h
6559+++ b/arch/mips/include/asm/cache.h
6560@@ -9,10 +9,11 @@
6561 #ifndef _ASM_CACHE_H
6562 #define _ASM_CACHE_H
6563
6564+#include <linux/const.h>
6565 #include <kmalloc.h>
6566
6567 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6568-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6569+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6570
6571 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6572 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6573diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6574index d414405..6bb4ba2 100644
6575--- a/arch/mips/include/asm/elf.h
6576+++ b/arch/mips/include/asm/elf.h
6577@@ -398,13 +398,16 @@ extern const char *__elf_platform;
6578 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6579 #endif
6580
6581+#ifdef CONFIG_PAX_ASLR
6582+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6583+
6584+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6585+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6586+#endif
6587+
6588 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6589 struct linux_binprm;
6590 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6591 int uses_interp);
6592
6593-struct mm_struct;
6594-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6595-#define arch_randomize_brk arch_randomize_brk
6596-
6597 #endif /* _ASM_ELF_H */
6598diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6599index c1f6afa..38cc6e9 100644
6600--- a/arch/mips/include/asm/exec.h
6601+++ b/arch/mips/include/asm/exec.h
6602@@ -12,6 +12,6 @@
6603 #ifndef _ASM_EXEC_H
6604 #define _ASM_EXEC_H
6605
6606-extern unsigned long arch_align_stack(unsigned long sp);
6607+#define arch_align_stack(x) ((x) & ~0xfUL)
6608
6609 #endif /* _ASM_EXEC_H */
6610diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6611index 9e8ef59..1139d6b 100644
6612--- a/arch/mips/include/asm/hw_irq.h
6613+++ b/arch/mips/include/asm/hw_irq.h
6614@@ -10,7 +10,7 @@
6615
6616 #include <linux/atomic.h>
6617
6618-extern atomic_t irq_err_count;
6619+extern atomic_unchecked_t irq_err_count;
6620
6621 /*
6622 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6623diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6624index 46dfc3c..a16b13a 100644
6625--- a/arch/mips/include/asm/local.h
6626+++ b/arch/mips/include/asm/local.h
6627@@ -12,15 +12,25 @@ typedef struct
6628 atomic_long_t a;
6629 } local_t;
6630
6631+typedef struct {
6632+ atomic_long_unchecked_t a;
6633+} local_unchecked_t;
6634+
6635 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6636
6637 #define local_read(l) atomic_long_read(&(l)->a)
6638+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6639 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6640+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6641
6642 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6643+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6644 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6645+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6646 #define local_inc(l) atomic_long_inc(&(l)->a)
6647+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6648 #define local_dec(l) atomic_long_dec(&(l)->a)
6649+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6650
6651 /*
6652 * Same as above, but return the result value
6653@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6654 return result;
6655 }
6656
6657+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6658+{
6659+ unsigned long result;
6660+
6661+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6662+ unsigned long temp;
6663+
6664+ __asm__ __volatile__(
6665+ " .set mips3 \n"
6666+ "1:" __LL "%1, %2 # local_add_return \n"
6667+ " addu %0, %1, %3 \n"
6668+ __SC "%0, %2 \n"
6669+ " beqzl %0, 1b \n"
6670+ " addu %0, %1, %3 \n"
6671+ " .set mips0 \n"
6672+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6673+ : "Ir" (i), "m" (l->a.counter)
6674+ : "memory");
6675+ } else if (kernel_uses_llsc) {
6676+ unsigned long temp;
6677+
6678+ __asm__ __volatile__(
6679+ " .set mips3 \n"
6680+ "1:" __LL "%1, %2 # local_add_return \n"
6681+ " addu %0, %1, %3 \n"
6682+ __SC "%0, %2 \n"
6683+ " beqz %0, 1b \n"
6684+ " addu %0, %1, %3 \n"
6685+ " .set mips0 \n"
6686+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6687+ : "Ir" (i), "m" (l->a.counter)
6688+ : "memory");
6689+ } else {
6690+ unsigned long flags;
6691+
6692+ local_irq_save(flags);
6693+ result = l->a.counter;
6694+ result += i;
6695+ l->a.counter = result;
6696+ local_irq_restore(flags);
6697+ }
6698+
6699+ return result;
6700+}
6701+
6702 static __inline__ long local_sub_return(long i, local_t * l)
6703 {
6704 unsigned long result;
6705@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6706
6707 #define local_cmpxchg(l, o, n) \
6708 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6709+#define local_cmpxchg_unchecked(l, o, n) \
6710+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6711 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6712
6713 /**
6714diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6715index 5699ec3..95def83 100644
6716--- a/arch/mips/include/asm/page.h
6717+++ b/arch/mips/include/asm/page.h
6718@@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6719 #ifdef CONFIG_CPU_MIPS32
6720 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6721 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6722- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6723+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6724 #else
6725 typedef struct { unsigned long long pte; } pte_t;
6726 #define pte_val(x) ((x).pte)
6727diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6728index b336037..5b874cc 100644
6729--- a/arch/mips/include/asm/pgalloc.h
6730+++ b/arch/mips/include/asm/pgalloc.h
6731@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6732 {
6733 set_pud(pud, __pud((unsigned long)pmd));
6734 }
6735+
6736+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6737+{
6738+ pud_populate(mm, pud, pmd);
6739+}
6740 #endif
6741
6742 /*
6743diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6744index 008324d..f67c239 100644
6745--- a/arch/mips/include/asm/pgtable.h
6746+++ b/arch/mips/include/asm/pgtable.h
6747@@ -20,6 +20,9 @@
6748 #include <asm/io.h>
6749 #include <asm/pgtable-bits.h>
6750
6751+#define ktla_ktva(addr) (addr)
6752+#define ktva_ktla(addr) (addr)
6753+
6754 struct mm_struct;
6755 struct vm_area_struct;
6756
6757diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6758index 25da651..ae2a259 100644
6759--- a/arch/mips/include/asm/smtc_proc.h
6760+++ b/arch/mips/include/asm/smtc_proc.h
6761@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6762
6763 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6764
6765-extern atomic_t smtc_fpu_recoveries;
6766+extern atomic_unchecked_t smtc_fpu_recoveries;
6767
6768 #endif /* __ASM_SMTC_PROC_H */
6769diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6770index d2d961d..a674df0 100644
6771--- a/arch/mips/include/asm/thread_info.h
6772+++ b/arch/mips/include/asm/thread_info.h
6773@@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6774 #define TIF_SECCOMP 4 /* secure computing */
6775 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6776 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6777+/* li takes a 32bit immediate */
6778+#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6779+
6780 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6781 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6782 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6783@@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6784 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6785 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6786 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6787+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6788
6789 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6790 _TIF_SYSCALL_AUDIT | \
6791- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6792+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6793+ _TIF_GRSEC_SETXID)
6794
6795 /* work to do in syscall_trace_leave() */
6796 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6797- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6798+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6799
6800 /* work to do on interrupt/exception return */
6801 #define _TIF_WORK_MASK \
6802@@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6803 /* work to do on any return to u-space */
6804 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6805 _TIF_WORK_SYSCALL_EXIT | \
6806- _TIF_SYSCALL_TRACEPOINT)
6807+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6808
6809 /*
6810 * We stash processor id into a COP0 register to retrieve it fast
6811diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6812index a109510..94ee3f6 100644
6813--- a/arch/mips/include/asm/uaccess.h
6814+++ b/arch/mips/include/asm/uaccess.h
6815@@ -130,6 +130,7 @@ extern u64 __ua_limit;
6816 __ok == 0; \
6817 })
6818
6819+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6820 #define access_ok(type, addr, size) \
6821 likely(__access_ok((addr), (size), __access_mask))
6822
6823diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6824index 1188e00..41cf144 100644
6825--- a/arch/mips/kernel/binfmt_elfn32.c
6826+++ b/arch/mips/kernel/binfmt_elfn32.c
6827@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6828 #undef ELF_ET_DYN_BASE
6829 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6830
6831+#ifdef CONFIG_PAX_ASLR
6832+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6833+
6834+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6835+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6836+#endif
6837+
6838 #include <asm/processor.h>
6839 #include <linux/module.h>
6840 #include <linux/elfcore.h>
6841diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6842index 7faf5f2..f3d3cf4 100644
6843--- a/arch/mips/kernel/binfmt_elfo32.c
6844+++ b/arch/mips/kernel/binfmt_elfo32.c
6845@@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6846 #undef ELF_ET_DYN_BASE
6847 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6848
6849+#ifdef CONFIG_PAX_ASLR
6850+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6851+
6852+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6853+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6854+#endif
6855+
6856 #include <asm/processor.h>
6857
6858 /*
6859diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6860index 2b91fe8..fe4f6b4 100644
6861--- a/arch/mips/kernel/i8259.c
6862+++ b/arch/mips/kernel/i8259.c
6863@@ -205,7 +205,7 @@ spurious_8259A_irq:
6864 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6865 spurious_irq_mask |= irqmask;
6866 }
6867- atomic_inc(&irq_err_count);
6868+ atomic_inc_unchecked(&irq_err_count);
6869 /*
6870 * Theoretically we do not have to handle this IRQ,
6871 * but in Linux this does not cause problems and is
6872diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6873index 44a1f79..2bd6aa3 100644
6874--- a/arch/mips/kernel/irq-gt641xx.c
6875+++ b/arch/mips/kernel/irq-gt641xx.c
6876@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6877 }
6878 }
6879
6880- atomic_inc(&irq_err_count);
6881+ atomic_inc_unchecked(&irq_err_count);
6882 }
6883
6884 void __init gt641xx_irq_init(void)
6885diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6886index d1fea7a..2e591b0 100644
6887--- a/arch/mips/kernel/irq.c
6888+++ b/arch/mips/kernel/irq.c
6889@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6890 printk("unexpected IRQ # %d\n", irq);
6891 }
6892
6893-atomic_t irq_err_count;
6894+atomic_unchecked_t irq_err_count;
6895
6896 int arch_show_interrupts(struct seq_file *p, int prec)
6897 {
6898- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6899+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6900 return 0;
6901 }
6902
6903 asmlinkage void spurious_interrupt(void)
6904 {
6905- atomic_inc(&irq_err_count);
6906+ atomic_inc_unchecked(&irq_err_count);
6907 }
6908
6909 void __init init_IRQ(void)
6910@@ -110,7 +110,10 @@ void __init init_IRQ(void)
6911 #endif
6912 }
6913
6914+
6915 #ifdef DEBUG_STACKOVERFLOW
6916+extern void gr_handle_kernel_exploit(void);
6917+
6918 static inline void check_stack_overflow(void)
6919 {
6920 unsigned long sp;
6921@@ -126,6 +129,7 @@ static inline void check_stack_overflow(void)
6922 printk("do_IRQ: stack overflow: %ld\n",
6923 sp - sizeof(struct thread_info));
6924 dump_stack();
6925+ gr_handle_kernel_exploit();
6926 }
6927 }
6928 #else
6929diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6930index 60e39dc..b4829bf 100644
6931--- a/arch/mips/kernel/process.c
6932+++ b/arch/mips/kernel/process.c
6933@@ -579,15 +579,3 @@ unsigned long get_wchan(struct task_struct *task)
6934 out:
6935 return pc;
6936 }
6937-
6938-/*
6939- * Don't forget that the stack pointer must be aligned on a 8 bytes
6940- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6941- */
6942-unsigned long arch_align_stack(unsigned long sp)
6943-{
6944- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6945- sp -= get_random_int() & ~PAGE_MASK;
6946-
6947- return sp & ALMASK;
6948-}
6949diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6950index f639ccd..e4b110d 100644
6951--- a/arch/mips/kernel/ptrace.c
6952+++ b/arch/mips/kernel/ptrace.c
6953@@ -630,6 +630,10 @@ long arch_ptrace(struct task_struct *child, long request,
6954 return ret;
6955 }
6956
6957+#ifdef CONFIG_GRKERNSEC_SETXID
6958+extern void gr_delayed_cred_worker(void);
6959+#endif
6960+
6961 /*
6962 * Notification of system call entry/exit
6963 * - triggered by current->work.syscall_trace
6964@@ -646,6 +650,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
6965 tracehook_report_syscall_entry(regs))
6966 ret = -1;
6967
6968+#ifdef CONFIG_GRKERNSEC_SETXID
6969+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6970+ gr_delayed_cred_worker();
6971+#endif
6972+
6973 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6974 trace_sys_enter(regs, regs->regs[2]);
6975
6976diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6977index 07fc524..b9d7f28 100644
6978--- a/arch/mips/kernel/reset.c
6979+++ b/arch/mips/kernel/reset.c
6980@@ -13,6 +13,7 @@
6981 #include <linux/reboot.h>
6982
6983 #include <asm/reboot.h>
6984+#include <asm/bug.h>
6985
6986 /*
6987 * Urgs ... Too many MIPS machines to handle this in a generic way.
6988@@ -29,16 +30,19 @@ void machine_restart(char *command)
6989 {
6990 if (_machine_restart)
6991 _machine_restart(command);
6992+ BUG();
6993 }
6994
6995 void machine_halt(void)
6996 {
6997 if (_machine_halt)
6998 _machine_halt();
6999+ BUG();
7000 }
7001
7002 void machine_power_off(void)
7003 {
7004 if (pm_power_off)
7005 pm_power_off();
7006+ BUG();
7007 }
7008diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
7009index 38635a9..3fcd5e0 100644
7010--- a/arch/mips/kernel/smtc-proc.c
7011+++ b/arch/mips/kernel/smtc-proc.c
7012@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
7013
7014 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
7015
7016-atomic_t smtc_fpu_recoveries;
7017+atomic_unchecked_t smtc_fpu_recoveries;
7018
7019 static int smtc_proc_show(struct seq_file *m, void *v)
7020 {
7021@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
7022 for(i = 0; i < NR_CPUS; i++)
7023 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
7024 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
7025- atomic_read(&smtc_fpu_recoveries));
7026+ atomic_read_unchecked(&smtc_fpu_recoveries));
7027 return 0;
7028 }
7029
7030@@ -73,7 +73,7 @@ void init_smtc_stats(void)
7031 smtc_cpu_stats[i].selfipis = 0;
7032 }
7033
7034- atomic_set(&smtc_fpu_recoveries, 0);
7035+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
7036
7037 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
7038 }
7039diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
7040index c1681d6..9f881d1 100644
7041--- a/arch/mips/kernel/smtc.c
7042+++ b/arch/mips/kernel/smtc.c
7043@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
7044 }
7045 smtc_ipi_qdump();
7046 printk("%d Recoveries of \"stolen\" FPU\n",
7047- atomic_read(&smtc_fpu_recoveries));
7048+ atomic_read_unchecked(&smtc_fpu_recoveries));
7049 }
7050
7051
7052diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7053index c24ad5f..9983ab2 100644
7054--- a/arch/mips/kernel/sync-r4k.c
7055+++ b/arch/mips/kernel/sync-r4k.c
7056@@ -20,8 +20,8 @@
7057 #include <asm/mipsregs.h>
7058
7059 static atomic_t count_start_flag = ATOMIC_INIT(0);
7060-static atomic_t count_count_start = ATOMIC_INIT(0);
7061-static atomic_t count_count_stop = ATOMIC_INIT(0);
7062+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7063+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7064 static atomic_t count_reference = ATOMIC_INIT(0);
7065
7066 #define COUNTON 100
7067@@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
7068
7069 for (i = 0; i < NR_LOOPS; i++) {
7070 /* slaves loop on '!= 2' */
7071- while (atomic_read(&count_count_start) != 1)
7072+ while (atomic_read_unchecked(&count_count_start) != 1)
7073 mb();
7074- atomic_set(&count_count_stop, 0);
7075+ atomic_set_unchecked(&count_count_stop, 0);
7076 smp_wmb();
7077
7078 /* this lets the slaves write their count register */
7079- atomic_inc(&count_count_start);
7080+ atomic_inc_unchecked(&count_count_start);
7081
7082 /*
7083 * Everyone initialises count in the last loop:
7084@@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
7085 /*
7086 * Wait for all slaves to leave the synchronization point:
7087 */
7088- while (atomic_read(&count_count_stop) != 1)
7089+ while (atomic_read_unchecked(&count_count_stop) != 1)
7090 mb();
7091- atomic_set(&count_count_start, 0);
7092+ atomic_set_unchecked(&count_count_start, 0);
7093 smp_wmb();
7094- atomic_inc(&count_count_stop);
7095+ atomic_inc_unchecked(&count_count_stop);
7096 }
7097 /* Arrange for an interrupt in a short while */
7098 write_c0_compare(read_c0_count() + COUNTON);
7099@@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
7100 initcount = atomic_read(&count_reference);
7101
7102 for (i = 0; i < NR_LOOPS; i++) {
7103- atomic_inc(&count_count_start);
7104- while (atomic_read(&count_count_start) != 2)
7105+ atomic_inc_unchecked(&count_count_start);
7106+ while (atomic_read_unchecked(&count_count_start) != 2)
7107 mb();
7108
7109 /*
7110@@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
7111 if (i == NR_LOOPS-1)
7112 write_c0_count(initcount);
7113
7114- atomic_inc(&count_count_stop);
7115- while (atomic_read(&count_count_stop) != 2)
7116+ atomic_inc_unchecked(&count_count_stop);
7117+ while (atomic_read_unchecked(&count_count_stop) != 2)
7118 mb();
7119 }
7120 /* Arrange for an interrupt in a short while */
7121diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7122index 8119ac2..b229939 100644
7123--- a/arch/mips/kernel/traps.c
7124+++ b/arch/mips/kernel/traps.c
7125@@ -695,7 +695,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7126 siginfo_t info;
7127
7128 prev_state = exception_enter();
7129- die_if_kernel("Integer overflow", regs);
7130+ if (unlikely(!user_mode(regs))) {
7131+
7132+#ifdef CONFIG_PAX_REFCOUNT
7133+ if (fixup_exception(regs)) {
7134+ pax_report_refcount_overflow(regs);
7135+ exception_exit(prev_state);
7136+ return;
7137+ }
7138+#endif
7139+
7140+ die("Integer overflow", regs);
7141+ }
7142
7143 info.si_code = FPE_INTOVF;
7144 info.si_signo = SIGFPE;
7145diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7146index becc42b..9e43d4b 100644
7147--- a/arch/mips/mm/fault.c
7148+++ b/arch/mips/mm/fault.c
7149@@ -28,6 +28,23 @@
7150 #include <asm/highmem.h> /* For VMALLOC_END */
7151 #include <linux/kdebug.h>
7152
7153+#ifdef CONFIG_PAX_PAGEEXEC
7154+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7155+{
7156+ unsigned long i;
7157+
7158+ printk(KERN_ERR "PAX: bytes at PC: ");
7159+ for (i = 0; i < 5; i++) {
7160+ unsigned int c;
7161+ if (get_user(c, (unsigned int *)pc+i))
7162+ printk(KERN_CONT "???????? ");
7163+ else
7164+ printk(KERN_CONT "%08x ", c);
7165+ }
7166+ printk("\n");
7167+}
7168+#endif
7169+
7170 /*
7171 * This routine handles page faults. It determines the address,
7172 * and the problem, and then passes it off to one of the appropriate
7173@@ -199,6 +216,14 @@ bad_area:
7174 bad_area_nosemaphore:
7175 /* User mode accesses just cause a SIGSEGV */
7176 if (user_mode(regs)) {
7177+
7178+#ifdef CONFIG_PAX_PAGEEXEC
7179+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7180+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7181+ do_group_exit(SIGKILL);
7182+ }
7183+#endif
7184+
7185 tsk->thread.cp0_badvaddr = address;
7186 tsk->thread.error_code = write;
7187 #if 0
7188diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7189index f1baadd..5472dca 100644
7190--- a/arch/mips/mm/mmap.c
7191+++ b/arch/mips/mm/mmap.c
7192@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7193 struct vm_area_struct *vma;
7194 unsigned long addr = addr0;
7195 int do_color_align;
7196+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7197 struct vm_unmapped_area_info info;
7198
7199 if (unlikely(len > TASK_SIZE))
7200@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7201 do_color_align = 1;
7202
7203 /* requesting a specific address */
7204+
7205+#ifdef CONFIG_PAX_RANDMMAP
7206+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7207+#endif
7208+
7209 if (addr) {
7210 if (do_color_align)
7211 addr = COLOUR_ALIGN(addr, pgoff);
7212@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7213 addr = PAGE_ALIGN(addr);
7214
7215 vma = find_vma(mm, addr);
7216- if (TASK_SIZE - len >= addr &&
7217- (!vma || addr + len <= vma->vm_start))
7218+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7219 return addr;
7220 }
7221
7222 info.length = len;
7223 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7224 info.align_offset = pgoff << PAGE_SHIFT;
7225+ info.threadstack_offset = offset;
7226
7227 if (dir == DOWN) {
7228 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7229@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7230 {
7231 unsigned long random_factor = 0UL;
7232
7233+#ifdef CONFIG_PAX_RANDMMAP
7234+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7235+#endif
7236+
7237 if (current->flags & PF_RANDOMIZE) {
7238 random_factor = get_random_int();
7239 random_factor = random_factor << PAGE_SHIFT;
7240@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7241
7242 if (mmap_is_legacy()) {
7243 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7244+
7245+#ifdef CONFIG_PAX_RANDMMAP
7246+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7247+ mm->mmap_base += mm->delta_mmap;
7248+#endif
7249+
7250 mm->get_unmapped_area = arch_get_unmapped_area;
7251 } else {
7252 mm->mmap_base = mmap_base(random_factor);
7253+
7254+#ifdef CONFIG_PAX_RANDMMAP
7255+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7256+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7257+#endif
7258+
7259 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7260 }
7261 }
7262
7263-static inline unsigned long brk_rnd(void)
7264-{
7265- unsigned long rnd = get_random_int();
7266-
7267- rnd = rnd << PAGE_SHIFT;
7268- /* 8MB for 32bit, 256MB for 64bit */
7269- if (TASK_IS_32BIT_ADDR)
7270- rnd = rnd & 0x7ffffful;
7271- else
7272- rnd = rnd & 0xffffffful;
7273-
7274- return rnd;
7275-}
7276-
7277-unsigned long arch_randomize_brk(struct mm_struct *mm)
7278-{
7279- unsigned long base = mm->brk;
7280- unsigned long ret;
7281-
7282- ret = PAGE_ALIGN(base + brk_rnd());
7283-
7284- if (ret < mm->brk)
7285- return mm->brk;
7286-
7287- return ret;
7288-}
7289-
7290 int __virt_addr_valid(const volatile void *kaddr)
7291 {
7292 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7293diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7294index 59cccd9..f39ac2f 100644
7295--- a/arch/mips/pci/pci-octeon.c
7296+++ b/arch/mips/pci/pci-octeon.c
7297@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7298
7299
7300 static struct pci_ops octeon_pci_ops = {
7301- octeon_read_config,
7302- octeon_write_config,
7303+ .read = octeon_read_config,
7304+ .write = octeon_write_config,
7305 };
7306
7307 static struct resource octeon_pci_mem_resource = {
7308diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7309index 5e36c33..eb4a17b 100644
7310--- a/arch/mips/pci/pcie-octeon.c
7311+++ b/arch/mips/pci/pcie-octeon.c
7312@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7313 }
7314
7315 static struct pci_ops octeon_pcie0_ops = {
7316- octeon_pcie0_read_config,
7317- octeon_pcie0_write_config,
7318+ .read = octeon_pcie0_read_config,
7319+ .write = octeon_pcie0_write_config,
7320 };
7321
7322 static struct resource octeon_pcie0_mem_resource = {
7323@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7324 };
7325
7326 static struct pci_ops octeon_pcie1_ops = {
7327- octeon_pcie1_read_config,
7328- octeon_pcie1_write_config,
7329+ .read = octeon_pcie1_read_config,
7330+ .write = octeon_pcie1_write_config,
7331 };
7332
7333 static struct resource octeon_pcie1_mem_resource = {
7334@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7335 };
7336
7337 static struct pci_ops octeon_dummy_ops = {
7338- octeon_dummy_read_config,
7339- octeon_dummy_write_config,
7340+ .read = octeon_dummy_read_config,
7341+ .write = octeon_dummy_write_config,
7342 };
7343
7344 static struct resource octeon_dummy_mem_resource = {
7345diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7346index a2358b4..7cead4f 100644
7347--- a/arch/mips/sgi-ip27/ip27-nmi.c
7348+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7349@@ -187,9 +187,9 @@ void
7350 cont_nmi_dump(void)
7351 {
7352 #ifndef REAL_NMI_SIGNAL
7353- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7354+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7355
7356- atomic_inc(&nmied_cpus);
7357+ atomic_inc_unchecked(&nmied_cpus);
7358 #endif
7359 /*
7360 * Only allow 1 cpu to proceed
7361@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7362 udelay(10000);
7363 }
7364 #else
7365- while (atomic_read(&nmied_cpus) != num_online_cpus());
7366+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7367 #endif
7368
7369 /*
7370diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7371index a046b30..6799527 100644
7372--- a/arch/mips/sni/rm200.c
7373+++ b/arch/mips/sni/rm200.c
7374@@ -270,7 +270,7 @@ spurious_8259A_irq:
7375 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7376 spurious_irq_mask |= irqmask;
7377 }
7378- atomic_inc(&irq_err_count);
7379+ atomic_inc_unchecked(&irq_err_count);
7380 /*
7381 * Theoretically we do not have to handle this IRQ,
7382 * but in Linux this does not cause problems and is
7383diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7384index 41e873b..34d33a7 100644
7385--- a/arch/mips/vr41xx/common/icu.c
7386+++ b/arch/mips/vr41xx/common/icu.c
7387@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7388
7389 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7390
7391- atomic_inc(&irq_err_count);
7392+ atomic_inc_unchecked(&irq_err_count);
7393
7394 return -1;
7395 }
7396diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7397index ae0e4ee..e8f0692 100644
7398--- a/arch/mips/vr41xx/common/irq.c
7399+++ b/arch/mips/vr41xx/common/irq.c
7400@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7401 irq_cascade_t *cascade;
7402
7403 if (irq >= NR_IRQS) {
7404- atomic_inc(&irq_err_count);
7405+ atomic_inc_unchecked(&irq_err_count);
7406 return;
7407 }
7408
7409@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7410 ret = cascade->get_irq(irq);
7411 irq = ret;
7412 if (ret < 0)
7413- atomic_inc(&irq_err_count);
7414+ atomic_inc_unchecked(&irq_err_count);
7415 else
7416 irq_dispatch(irq);
7417 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7418diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7419index 967d144..db12197 100644
7420--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7421+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7422@@ -11,12 +11,14 @@
7423 #ifndef _ASM_PROC_CACHE_H
7424 #define _ASM_PROC_CACHE_H
7425
7426+#include <linux/const.h>
7427+
7428 /* L1 cache */
7429
7430 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7431 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7432-#define L1_CACHE_BYTES 16 /* bytes per entry */
7433 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7434+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7435 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7436
7437 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7438diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7439index bcb5df2..84fabd2 100644
7440--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7441+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7442@@ -16,13 +16,15 @@
7443 #ifndef _ASM_PROC_CACHE_H
7444 #define _ASM_PROC_CACHE_H
7445
7446+#include <linux/const.h>
7447+
7448 /*
7449 * L1 cache
7450 */
7451 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7452 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7453-#define L1_CACHE_BYTES 32 /* bytes per entry */
7454 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7455+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7456 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7457
7458 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7459diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7460index 4ce7a01..449202a 100644
7461--- a/arch/openrisc/include/asm/cache.h
7462+++ b/arch/openrisc/include/asm/cache.h
7463@@ -19,11 +19,13 @@
7464 #ifndef __ASM_OPENRISC_CACHE_H
7465 #define __ASM_OPENRISC_CACHE_H
7466
7467+#include <linux/const.h>
7468+
7469 /* FIXME: How can we replace these with values from the CPU...
7470 * they shouldn't be hard-coded!
7471 */
7472
7473-#define L1_CACHE_BYTES 16
7474 #define L1_CACHE_SHIFT 4
7475+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7476
7477 #endif /* __ASM_OPENRISC_CACHE_H */
7478diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7479index 472886c..00e7df9 100644
7480--- a/arch/parisc/include/asm/atomic.h
7481+++ b/arch/parisc/include/asm/atomic.h
7482@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7483 return dec;
7484 }
7485
7486+#define atomic64_read_unchecked(v) atomic64_read(v)
7487+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7488+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7489+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7490+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7491+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7492+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7493+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7494+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7495+
7496 #endif /* !CONFIG_64BIT */
7497
7498
7499diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7500index 47f11c7..3420df2 100644
7501--- a/arch/parisc/include/asm/cache.h
7502+++ b/arch/parisc/include/asm/cache.h
7503@@ -5,6 +5,7 @@
7504 #ifndef __ARCH_PARISC_CACHE_H
7505 #define __ARCH_PARISC_CACHE_H
7506
7507+#include <linux/const.h>
7508
7509 /*
7510 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7511@@ -15,13 +16,13 @@
7512 * just ruin performance.
7513 */
7514 #ifdef CONFIG_PA20
7515-#define L1_CACHE_BYTES 64
7516 #define L1_CACHE_SHIFT 6
7517 #else
7518-#define L1_CACHE_BYTES 32
7519 #define L1_CACHE_SHIFT 5
7520 #endif
7521
7522+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7523+
7524 #ifndef __ASSEMBLY__
7525
7526 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7527diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7528index 3391d06..c23a2cc 100644
7529--- a/arch/parisc/include/asm/elf.h
7530+++ b/arch/parisc/include/asm/elf.h
7531@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7532
7533 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7534
7535+#ifdef CONFIG_PAX_ASLR
7536+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7537+
7538+#define PAX_DELTA_MMAP_LEN 16
7539+#define PAX_DELTA_STACK_LEN 16
7540+#endif
7541+
7542 /* This yields a mask that user programs can use to figure out what
7543 instruction set this CPU supports. This could be done in user space,
7544 but it's not easy, and we've already done it here. */
7545diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7546index f213f5b..0af3e8e 100644
7547--- a/arch/parisc/include/asm/pgalloc.h
7548+++ b/arch/parisc/include/asm/pgalloc.h
7549@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7550 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7551 }
7552
7553+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7554+{
7555+ pgd_populate(mm, pgd, pmd);
7556+}
7557+
7558 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7559 {
7560 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7561@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7562 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7563 #define pmd_free(mm, x) do { } while (0)
7564 #define pgd_populate(mm, pmd, pte) BUG()
7565+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7566
7567 #endif
7568
7569diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7570index 22b89d1..ce34230 100644
7571--- a/arch/parisc/include/asm/pgtable.h
7572+++ b/arch/parisc/include/asm/pgtable.h
7573@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7574 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7575 #define PAGE_COPY PAGE_EXECREAD
7576 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7577+
7578+#ifdef CONFIG_PAX_PAGEEXEC
7579+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7580+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7581+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7582+#else
7583+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7584+# define PAGE_COPY_NOEXEC PAGE_COPY
7585+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7586+#endif
7587+
7588 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7589 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7590 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7591diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7592index 4006964..fcb3cc2 100644
7593--- a/arch/parisc/include/asm/uaccess.h
7594+++ b/arch/parisc/include/asm/uaccess.h
7595@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7596 const void __user *from,
7597 unsigned long n)
7598 {
7599- int sz = __compiletime_object_size(to);
7600+ size_t sz = __compiletime_object_size(to);
7601 int ret = -EFAULT;
7602
7603- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7604+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7605 ret = __copy_from_user(to, from, n);
7606 else
7607 copy_from_user_overflow();
7608diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7609index 50dfafc..b9fc230 100644
7610--- a/arch/parisc/kernel/module.c
7611+++ b/arch/parisc/kernel/module.c
7612@@ -98,16 +98,38 @@
7613
7614 /* three functions to determine where in the module core
7615 * or init pieces the location is */
7616+static inline int in_init_rx(struct module *me, void *loc)
7617+{
7618+ return (loc >= me->module_init_rx &&
7619+ loc < (me->module_init_rx + me->init_size_rx));
7620+}
7621+
7622+static inline int in_init_rw(struct module *me, void *loc)
7623+{
7624+ return (loc >= me->module_init_rw &&
7625+ loc < (me->module_init_rw + me->init_size_rw));
7626+}
7627+
7628 static inline int in_init(struct module *me, void *loc)
7629 {
7630- return (loc >= me->module_init &&
7631- loc <= (me->module_init + me->init_size));
7632+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7633+}
7634+
7635+static inline int in_core_rx(struct module *me, void *loc)
7636+{
7637+ return (loc >= me->module_core_rx &&
7638+ loc < (me->module_core_rx + me->core_size_rx));
7639+}
7640+
7641+static inline int in_core_rw(struct module *me, void *loc)
7642+{
7643+ return (loc >= me->module_core_rw &&
7644+ loc < (me->module_core_rw + me->core_size_rw));
7645 }
7646
7647 static inline int in_core(struct module *me, void *loc)
7648 {
7649- return (loc >= me->module_core &&
7650- loc <= (me->module_core + me->core_size));
7651+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7652 }
7653
7654 static inline int in_local(struct module *me, void *loc)
7655@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7656 }
7657
7658 /* align things a bit */
7659- me->core_size = ALIGN(me->core_size, 16);
7660- me->arch.got_offset = me->core_size;
7661- me->core_size += gots * sizeof(struct got_entry);
7662+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7663+ me->arch.got_offset = me->core_size_rw;
7664+ me->core_size_rw += gots * sizeof(struct got_entry);
7665
7666- me->core_size = ALIGN(me->core_size, 16);
7667- me->arch.fdesc_offset = me->core_size;
7668- me->core_size += fdescs * sizeof(Elf_Fdesc);
7669+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7670+ me->arch.fdesc_offset = me->core_size_rw;
7671+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7672
7673 me->arch.got_max = gots;
7674 me->arch.fdesc_max = fdescs;
7675@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7676
7677 BUG_ON(value == 0);
7678
7679- got = me->module_core + me->arch.got_offset;
7680+ got = me->module_core_rw + me->arch.got_offset;
7681 for (i = 0; got[i].addr; i++)
7682 if (got[i].addr == value)
7683 goto out;
7684@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7685 #ifdef CONFIG_64BIT
7686 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7687 {
7688- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7689+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7690
7691 if (!value) {
7692 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7693@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7694
7695 /* Create new one */
7696 fdesc->addr = value;
7697- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7698+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7699 return (Elf_Addr)fdesc;
7700 }
7701 #endif /* CONFIG_64BIT */
7702@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7703
7704 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7705 end = table + sechdrs[me->arch.unwind_section].sh_size;
7706- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7707+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7708
7709 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7710 me->arch.unwind_section, table, end, gp);
7711diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7712index e1ffea2..46ed66e 100644
7713--- a/arch/parisc/kernel/sys_parisc.c
7714+++ b/arch/parisc/kernel/sys_parisc.c
7715@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7716 unsigned long task_size = TASK_SIZE;
7717 int do_color_align, last_mmap;
7718 struct vm_unmapped_area_info info;
7719+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7720
7721 if (len > task_size)
7722 return -ENOMEM;
7723@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7724 goto found_addr;
7725 }
7726
7727+#ifdef CONFIG_PAX_RANDMMAP
7728+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7729+#endif
7730+
7731 if (addr) {
7732 if (do_color_align && last_mmap)
7733 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7734@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7735 info.high_limit = mmap_upper_limit();
7736 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7737 info.align_offset = shared_align_offset(last_mmap, pgoff);
7738+ info.threadstack_offset = offset;
7739 addr = vm_unmapped_area(&info);
7740
7741 found_addr:
7742@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7743 unsigned long addr = addr0;
7744 int do_color_align, last_mmap;
7745 struct vm_unmapped_area_info info;
7746+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7747
7748 #ifdef CONFIG_64BIT
7749 /* This should only ever run for 32-bit processes. */
7750@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7751 }
7752
7753 /* requesting a specific address */
7754+#ifdef CONFIG_PAX_RANDMMAP
7755+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7756+#endif
7757+
7758 if (addr) {
7759 if (do_color_align && last_mmap)
7760 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7761@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7762 info.high_limit = mm->mmap_base;
7763 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7764 info.align_offset = shared_align_offset(last_mmap, pgoff);
7765+ info.threadstack_offset = offset;
7766 addr = vm_unmapped_area(&info);
7767 if (!(addr & ~PAGE_MASK))
7768 goto found_addr;
7769@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7770 mm->mmap_legacy_base = mmap_legacy_base();
7771 mm->mmap_base = mmap_upper_limit();
7772
7773+#ifdef CONFIG_PAX_RANDMMAP
7774+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
7775+ mm->mmap_legacy_base += mm->delta_mmap;
7776+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7777+ }
7778+#endif
7779+
7780 if (mmap_is_legacy()) {
7781 mm->mmap_base = mm->mmap_legacy_base;
7782 mm->get_unmapped_area = arch_get_unmapped_area;
7783diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7784index 47ee620..1107387 100644
7785--- a/arch/parisc/kernel/traps.c
7786+++ b/arch/parisc/kernel/traps.c
7787@@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7788
7789 down_read(&current->mm->mmap_sem);
7790 vma = find_vma(current->mm,regs->iaoq[0]);
7791- if (vma && (regs->iaoq[0] >= vma->vm_start)
7792- && (vma->vm_flags & VM_EXEC)) {
7793-
7794+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7795 fault_address = regs->iaoq[0];
7796 fault_space = regs->iasq[0];
7797
7798diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7799index 3ca9c11..d163ef7 100644
7800--- a/arch/parisc/mm/fault.c
7801+++ b/arch/parisc/mm/fault.c
7802@@ -15,6 +15,7 @@
7803 #include <linux/sched.h>
7804 #include <linux/interrupt.h>
7805 #include <linux/module.h>
7806+#include <linux/unistd.h>
7807
7808 #include <asm/uaccess.h>
7809 #include <asm/traps.h>
7810@@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7811 static unsigned long
7812 parisc_acctyp(unsigned long code, unsigned int inst)
7813 {
7814- if (code == 6 || code == 16)
7815+ if (code == 6 || code == 7 || code == 16)
7816 return VM_EXEC;
7817
7818 switch (inst & 0xf0000000) {
7819@@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7820 }
7821 #endif
7822
7823+#ifdef CONFIG_PAX_PAGEEXEC
7824+/*
7825+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7826+ *
7827+ * returns 1 when task should be killed
7828+ * 2 when rt_sigreturn trampoline was detected
7829+ * 3 when unpatched PLT trampoline was detected
7830+ */
7831+static int pax_handle_fetch_fault(struct pt_regs *regs)
7832+{
7833+
7834+#ifdef CONFIG_PAX_EMUPLT
7835+ int err;
7836+
7837+ do { /* PaX: unpatched PLT emulation */
7838+ unsigned int bl, depwi;
7839+
7840+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7841+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7842+
7843+ if (err)
7844+ break;
7845+
7846+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7847+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7848+
7849+ err = get_user(ldw, (unsigned int *)addr);
7850+ err |= get_user(bv, (unsigned int *)(addr+4));
7851+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7852+
7853+ if (err)
7854+ break;
7855+
7856+ if (ldw == 0x0E801096U &&
7857+ bv == 0xEAC0C000U &&
7858+ ldw2 == 0x0E881095U)
7859+ {
7860+ unsigned int resolver, map;
7861+
7862+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7863+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7864+ if (err)
7865+ break;
7866+
7867+ regs->gr[20] = instruction_pointer(regs)+8;
7868+ regs->gr[21] = map;
7869+ regs->gr[22] = resolver;
7870+ regs->iaoq[0] = resolver | 3UL;
7871+ regs->iaoq[1] = regs->iaoq[0] + 4;
7872+ return 3;
7873+ }
7874+ }
7875+ } while (0);
7876+#endif
7877+
7878+#ifdef CONFIG_PAX_EMUTRAMP
7879+
7880+#ifndef CONFIG_PAX_EMUSIGRT
7881+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7882+ return 1;
7883+#endif
7884+
7885+ do { /* PaX: rt_sigreturn emulation */
7886+ unsigned int ldi1, ldi2, bel, nop;
7887+
7888+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7889+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7890+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7891+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7892+
7893+ if (err)
7894+ break;
7895+
7896+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7897+ ldi2 == 0x3414015AU &&
7898+ bel == 0xE4008200U &&
7899+ nop == 0x08000240U)
7900+ {
7901+ regs->gr[25] = (ldi1 & 2) >> 1;
7902+ regs->gr[20] = __NR_rt_sigreturn;
7903+ regs->gr[31] = regs->iaoq[1] + 16;
7904+ regs->sr[0] = regs->iasq[1];
7905+ regs->iaoq[0] = 0x100UL;
7906+ regs->iaoq[1] = regs->iaoq[0] + 4;
7907+ regs->iasq[0] = regs->sr[2];
7908+ regs->iasq[1] = regs->sr[2];
7909+ return 2;
7910+ }
7911+ } while (0);
7912+#endif
7913+
7914+ return 1;
7915+}
7916+
7917+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7918+{
7919+ unsigned long i;
7920+
7921+ printk(KERN_ERR "PAX: bytes at PC: ");
7922+ for (i = 0; i < 5; i++) {
7923+ unsigned int c;
7924+ if (get_user(c, (unsigned int *)pc+i))
7925+ printk(KERN_CONT "???????? ");
7926+ else
7927+ printk(KERN_CONT "%08x ", c);
7928+ }
7929+ printk("\n");
7930+}
7931+#endif
7932+
7933 int fixup_exception(struct pt_regs *regs)
7934 {
7935 const struct exception_table_entry *fix;
7936@@ -234,8 +345,33 @@ retry:
7937
7938 good_area:
7939
7940- if ((vma->vm_flags & acc_type) != acc_type)
7941+ if ((vma->vm_flags & acc_type) != acc_type) {
7942+
7943+#ifdef CONFIG_PAX_PAGEEXEC
7944+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7945+ (address & ~3UL) == instruction_pointer(regs))
7946+ {
7947+ up_read(&mm->mmap_sem);
7948+ switch (pax_handle_fetch_fault(regs)) {
7949+
7950+#ifdef CONFIG_PAX_EMUPLT
7951+ case 3:
7952+ return;
7953+#endif
7954+
7955+#ifdef CONFIG_PAX_EMUTRAMP
7956+ case 2:
7957+ return;
7958+#endif
7959+
7960+ }
7961+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7962+ do_group_exit(SIGKILL);
7963+ }
7964+#endif
7965+
7966 goto bad_area;
7967+ }
7968
7969 /*
7970 * If for any reason at all we couldn't handle the fault, make
7971diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7972index e099899..457d6a8 100644
7973--- a/arch/powerpc/Kconfig
7974+++ b/arch/powerpc/Kconfig
7975@@ -397,6 +397,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7976 config KEXEC
7977 bool "kexec system call"
7978 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7979+ depends on !GRKERNSEC_KMEM
7980 help
7981 kexec is a system call that implements the ability to shutdown your
7982 current kernel, and to start another kernel. It is like a reboot
7983diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7984index e3b1d41..8e81edf 100644
7985--- a/arch/powerpc/include/asm/atomic.h
7986+++ b/arch/powerpc/include/asm/atomic.h
7987@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7988 return t1;
7989 }
7990
7991+#define atomic64_read_unchecked(v) atomic64_read(v)
7992+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7993+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7994+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7995+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7996+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7997+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7998+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7999+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8000+
8001 #endif /* __powerpc64__ */
8002
8003 #endif /* __KERNEL__ */
8004diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8005index f89da80..7f5b05a 100644
8006--- a/arch/powerpc/include/asm/barrier.h
8007+++ b/arch/powerpc/include/asm/barrier.h
8008@@ -73,7 +73,7 @@
8009 do { \
8010 compiletime_assert_atomic_type(*p); \
8011 __lwsync(); \
8012- ACCESS_ONCE(*p) = (v); \
8013+ ACCESS_ONCE_RW(*p) = (v); \
8014 } while (0)
8015
8016 #define smp_load_acquire(p) \
8017diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8018index ed0afc1..0332825 100644
8019--- a/arch/powerpc/include/asm/cache.h
8020+++ b/arch/powerpc/include/asm/cache.h
8021@@ -3,6 +3,7 @@
8022
8023 #ifdef __KERNEL__
8024
8025+#include <linux/const.h>
8026
8027 /* bytes per L1 cache line */
8028 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8029@@ -22,7 +23,7 @@
8030 #define L1_CACHE_SHIFT 7
8031 #endif
8032
8033-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8034+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8035
8036 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8037
8038diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8039index 935b5e7..7001d2d 100644
8040--- a/arch/powerpc/include/asm/elf.h
8041+++ b/arch/powerpc/include/asm/elf.h
8042@@ -28,8 +28,19 @@
8043 the loader. We need to make sure that it is out of the way of the program
8044 that it will "exec", and that there is sufficient room for the brk. */
8045
8046-extern unsigned long randomize_et_dyn(unsigned long base);
8047-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8048+#define ELF_ET_DYN_BASE (0x20000000)
8049+
8050+#ifdef CONFIG_PAX_ASLR
8051+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8052+
8053+#ifdef __powerpc64__
8054+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8055+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8056+#else
8057+#define PAX_DELTA_MMAP_LEN 15
8058+#define PAX_DELTA_STACK_LEN 15
8059+#endif
8060+#endif
8061
8062 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8063
8064@@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8065 (0x7ff >> (PAGE_SHIFT - 12)) : \
8066 (0x3ffff >> (PAGE_SHIFT - 12)))
8067
8068-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8069-#define arch_randomize_brk arch_randomize_brk
8070-
8071-
8072 #ifdef CONFIG_SPU_BASE
8073 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8074 #define NT_SPU 1
8075diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8076index 8196e9c..d83a9f3 100644
8077--- a/arch/powerpc/include/asm/exec.h
8078+++ b/arch/powerpc/include/asm/exec.h
8079@@ -4,6 +4,6 @@
8080 #ifndef _ASM_POWERPC_EXEC_H
8081 #define _ASM_POWERPC_EXEC_H
8082
8083-extern unsigned long arch_align_stack(unsigned long sp);
8084+#define arch_align_stack(x) ((x) & ~0xfUL)
8085
8086 #endif /* _ASM_POWERPC_EXEC_H */
8087diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8088index 5acabbd..7ea14fa 100644
8089--- a/arch/powerpc/include/asm/kmap_types.h
8090+++ b/arch/powerpc/include/asm/kmap_types.h
8091@@ -10,7 +10,7 @@
8092 * 2 of the License, or (at your option) any later version.
8093 */
8094
8095-#define KM_TYPE_NR 16
8096+#define KM_TYPE_NR 17
8097
8098 #endif /* __KERNEL__ */
8099 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8100diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8101index b8da913..60b608a 100644
8102--- a/arch/powerpc/include/asm/local.h
8103+++ b/arch/powerpc/include/asm/local.h
8104@@ -9,15 +9,26 @@ typedef struct
8105 atomic_long_t a;
8106 } local_t;
8107
8108+typedef struct
8109+{
8110+ atomic_long_unchecked_t a;
8111+} local_unchecked_t;
8112+
8113 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8114
8115 #define local_read(l) atomic_long_read(&(l)->a)
8116+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8117 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8118+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8119
8120 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8121+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8122 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8123+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8124 #define local_inc(l) atomic_long_inc(&(l)->a)
8125+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8126 #define local_dec(l) atomic_long_dec(&(l)->a)
8127+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8128
8129 static __inline__ long local_add_return(long a, local_t *l)
8130 {
8131@@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8132
8133 return t;
8134 }
8135+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8136
8137 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8138
8139@@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8140
8141 return t;
8142 }
8143+#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8144
8145 static __inline__ long local_inc_return(local_t *l)
8146 {
8147@@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8148
8149 #define local_cmpxchg(l, o, n) \
8150 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8151+#define local_cmpxchg_unchecked(l, o, n) \
8152+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8153 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8154
8155 /**
8156diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8157index 8565c25..2865190 100644
8158--- a/arch/powerpc/include/asm/mman.h
8159+++ b/arch/powerpc/include/asm/mman.h
8160@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8161 }
8162 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8163
8164-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8165+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8166 {
8167 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8168 }
8169diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8170index 32e4e21..62afb12 100644
8171--- a/arch/powerpc/include/asm/page.h
8172+++ b/arch/powerpc/include/asm/page.h
8173@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8174 * and needs to be executable. This means the whole heap ends
8175 * up being executable.
8176 */
8177-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8178- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8179+#define VM_DATA_DEFAULT_FLAGS32 \
8180+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8181+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8182
8183 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8184 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8185@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8186 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8187 #endif
8188
8189+#define ktla_ktva(addr) (addr)
8190+#define ktva_ktla(addr) (addr)
8191+
8192 #ifndef CONFIG_PPC_BOOK3S_64
8193 /*
8194 * Use the top bit of the higher-level page table entries to indicate whether
8195diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8196index 88693ce..ac6f9ab 100644
8197--- a/arch/powerpc/include/asm/page_64.h
8198+++ b/arch/powerpc/include/asm/page_64.h
8199@@ -153,15 +153,18 @@ do { \
8200 * stack by default, so in the absence of a PT_GNU_STACK program header
8201 * we turn execute permission off.
8202 */
8203-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8204- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8205+#define VM_STACK_DEFAULT_FLAGS32 \
8206+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8207+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8208
8209 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8210 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8211
8212+#ifndef CONFIG_PAX_PAGEEXEC
8213 #define VM_STACK_DEFAULT_FLAGS \
8214 (is_32bit_task() ? \
8215 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8216+#endif
8217
8218 #include <asm-generic/getorder.h>
8219
8220diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8221index 4b0be20..c15a27d 100644
8222--- a/arch/powerpc/include/asm/pgalloc-64.h
8223+++ b/arch/powerpc/include/asm/pgalloc-64.h
8224@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8225 #ifndef CONFIG_PPC_64K_PAGES
8226
8227 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8228+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8229
8230 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8231 {
8232@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8233 pud_set(pud, (unsigned long)pmd);
8234 }
8235
8236+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8237+{
8238+ pud_populate(mm, pud, pmd);
8239+}
8240+
8241 #define pmd_populate(mm, pmd, pte_page) \
8242 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8243 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8244@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8245 #endif
8246
8247 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8248+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8249
8250 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8251 pte_t *pte)
8252diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8253index 3ebb188..e17dddf 100644
8254--- a/arch/powerpc/include/asm/pgtable.h
8255+++ b/arch/powerpc/include/asm/pgtable.h
8256@@ -2,6 +2,7 @@
8257 #define _ASM_POWERPC_PGTABLE_H
8258 #ifdef __KERNEL__
8259
8260+#include <linux/const.h>
8261 #ifndef __ASSEMBLY__
8262 #include <linux/mmdebug.h>
8263 #include <asm/processor.h> /* For TASK_SIZE */
8264diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8265index 4aad413..85d86bf 100644
8266--- a/arch/powerpc/include/asm/pte-hash32.h
8267+++ b/arch/powerpc/include/asm/pte-hash32.h
8268@@ -21,6 +21,7 @@
8269 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8270 #define _PAGE_USER 0x004 /* usermode access allowed */
8271 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8272+#define _PAGE_EXEC _PAGE_GUARDED
8273 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8274 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8275 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8276diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8277index e5d2e0b..9ac74b1 100644
8278--- a/arch/powerpc/include/asm/reg.h
8279+++ b/arch/powerpc/include/asm/reg.h
8280@@ -249,6 +249,7 @@
8281 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8282 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8283 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8284+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8285 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8286 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8287 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8288diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8289index ff51046..b982dd4 100644
8290--- a/arch/powerpc/include/asm/smp.h
8291+++ b/arch/powerpc/include/asm/smp.h
8292@@ -51,7 +51,7 @@ struct smp_ops_t {
8293 int (*cpu_disable)(void);
8294 void (*cpu_die)(unsigned int nr);
8295 int (*cpu_bootable)(unsigned int nr);
8296-};
8297+} __no_const;
8298
8299 extern void smp_send_debugger_break(void);
8300 extern void start_secondary_resume(void);
8301diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8302index b034ecd..af7e31f 100644
8303--- a/arch/powerpc/include/asm/thread_info.h
8304+++ b/arch/powerpc/include/asm/thread_info.h
8305@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8306 #if defined(CONFIG_PPC64)
8307 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8308 #endif
8309+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8310+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8311
8312 /* as above, but as bit values */
8313 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8314@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8315 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8316 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8317 #define _TIF_NOHZ (1<<TIF_NOHZ)
8318+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8319 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8320 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8321- _TIF_NOHZ)
8322+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8323
8324 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8325 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8326diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8327index 9485b43..3bd3c16 100644
8328--- a/arch/powerpc/include/asm/uaccess.h
8329+++ b/arch/powerpc/include/asm/uaccess.h
8330@@ -58,6 +58,7 @@
8331
8332 #endif
8333
8334+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8335 #define access_ok(type, addr, size) \
8336 (__chk_user_ptr(addr), \
8337 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8338@@ -318,52 +319,6 @@ do { \
8339 extern unsigned long __copy_tofrom_user(void __user *to,
8340 const void __user *from, unsigned long size);
8341
8342-#ifndef __powerpc64__
8343-
8344-static inline unsigned long copy_from_user(void *to,
8345- const void __user *from, unsigned long n)
8346-{
8347- unsigned long over;
8348-
8349- if (access_ok(VERIFY_READ, from, n))
8350- return __copy_tofrom_user((__force void __user *)to, from, n);
8351- if ((unsigned long)from < TASK_SIZE) {
8352- over = (unsigned long)from + n - TASK_SIZE;
8353- return __copy_tofrom_user((__force void __user *)to, from,
8354- n - over) + over;
8355- }
8356- return n;
8357-}
8358-
8359-static inline unsigned long copy_to_user(void __user *to,
8360- const void *from, unsigned long n)
8361-{
8362- unsigned long over;
8363-
8364- if (access_ok(VERIFY_WRITE, to, n))
8365- return __copy_tofrom_user(to, (__force void __user *)from, n);
8366- if ((unsigned long)to < TASK_SIZE) {
8367- over = (unsigned long)to + n - TASK_SIZE;
8368- return __copy_tofrom_user(to, (__force void __user *)from,
8369- n - over) + over;
8370- }
8371- return n;
8372-}
8373-
8374-#else /* __powerpc64__ */
8375-
8376-#define __copy_in_user(to, from, size) \
8377- __copy_tofrom_user((to), (from), (size))
8378-
8379-extern unsigned long copy_from_user(void *to, const void __user *from,
8380- unsigned long n);
8381-extern unsigned long copy_to_user(void __user *to, const void *from,
8382- unsigned long n);
8383-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8384- unsigned long n);
8385-
8386-#endif /* __powerpc64__ */
8387-
8388 static inline unsigned long __copy_from_user_inatomic(void *to,
8389 const void __user *from, unsigned long n)
8390 {
8391@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8392 if (ret == 0)
8393 return 0;
8394 }
8395+
8396+ if (!__builtin_constant_p(n))
8397+ check_object_size(to, n, false);
8398+
8399 return __copy_tofrom_user((__force void __user *)to, from, n);
8400 }
8401
8402@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8403 if (ret == 0)
8404 return 0;
8405 }
8406+
8407+ if (!__builtin_constant_p(n))
8408+ check_object_size(from, n, true);
8409+
8410 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8411 }
8412
8413@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8414 return __copy_to_user_inatomic(to, from, size);
8415 }
8416
8417+#ifndef __powerpc64__
8418+
8419+static inline unsigned long __must_check copy_from_user(void *to,
8420+ const void __user *from, unsigned long n)
8421+{
8422+ unsigned long over;
8423+
8424+ if ((long)n < 0)
8425+ return n;
8426+
8427+ if (access_ok(VERIFY_READ, from, n)) {
8428+ if (!__builtin_constant_p(n))
8429+ check_object_size(to, n, false);
8430+ return __copy_tofrom_user((__force void __user *)to, from, n);
8431+ }
8432+ if ((unsigned long)from < TASK_SIZE) {
8433+ over = (unsigned long)from + n - TASK_SIZE;
8434+ if (!__builtin_constant_p(n - over))
8435+ check_object_size(to, n - over, false);
8436+ return __copy_tofrom_user((__force void __user *)to, from,
8437+ n - over) + over;
8438+ }
8439+ return n;
8440+}
8441+
8442+static inline unsigned long __must_check copy_to_user(void __user *to,
8443+ const void *from, unsigned long n)
8444+{
8445+ unsigned long over;
8446+
8447+ if ((long)n < 0)
8448+ return n;
8449+
8450+ if (access_ok(VERIFY_WRITE, to, n)) {
8451+ if (!__builtin_constant_p(n))
8452+ check_object_size(from, n, true);
8453+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8454+ }
8455+ if ((unsigned long)to < TASK_SIZE) {
8456+ over = (unsigned long)to + n - TASK_SIZE;
8457+ if (!__builtin_constant_p(n))
8458+ check_object_size(from, n - over, true);
8459+ return __copy_tofrom_user(to, (__force void __user *)from,
8460+ n - over) + over;
8461+ }
8462+ return n;
8463+}
8464+
8465+#else /* __powerpc64__ */
8466+
8467+#define __copy_in_user(to, from, size) \
8468+ __copy_tofrom_user((to), (from), (size))
8469+
8470+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8471+{
8472+ if ((long)n < 0 || n > INT_MAX)
8473+ return n;
8474+
8475+ if (!__builtin_constant_p(n))
8476+ check_object_size(to, n, false);
8477+
8478+ if (likely(access_ok(VERIFY_READ, from, n)))
8479+ n = __copy_from_user(to, from, n);
8480+ else
8481+ memset(to, 0, n);
8482+ return n;
8483+}
8484+
8485+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8486+{
8487+ if ((long)n < 0 || n > INT_MAX)
8488+ return n;
8489+
8490+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8491+ if (!__builtin_constant_p(n))
8492+ check_object_size(from, n, true);
8493+ n = __copy_to_user(to, from, n);
8494+ }
8495+ return n;
8496+}
8497+
8498+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8499+ unsigned long n);
8500+
8501+#endif /* __powerpc64__ */
8502+
8503 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8504
8505 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8506diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8507index fcc9a89..07be2bb 100644
8508--- a/arch/powerpc/kernel/Makefile
8509+++ b/arch/powerpc/kernel/Makefile
8510@@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8511 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8512 endif
8513
8514+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8515+
8516 obj-y := cputable.o ptrace.o syscalls.o \
8517 irq.o align.o signal_32.o pmc.o vdso.o \
8518 process.o systbl.o idle.o \
8519diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8520index c1bee3c..5b42583 100644
8521--- a/arch/powerpc/kernel/exceptions-64e.S
8522+++ b/arch/powerpc/kernel/exceptions-64e.S
8523@@ -1010,6 +1010,7 @@ storage_fault_common:
8524 std r14,_DAR(r1)
8525 std r15,_DSISR(r1)
8526 addi r3,r1,STACK_FRAME_OVERHEAD
8527+ bl .save_nvgprs
8528 mr r4,r14
8529 mr r5,r15
8530 ld r14,PACA_EXGEN+EX_R14(r13)
8531@@ -1018,8 +1019,7 @@ storage_fault_common:
8532 cmpdi r3,0
8533 bne- 1f
8534 b .ret_from_except_lite
8535-1: bl .save_nvgprs
8536- mr r5,r3
8537+1: mr r5,r3
8538 addi r3,r1,STACK_FRAME_OVERHEAD
8539 ld r4,_DAR(r1)
8540 bl .bad_page_fault
8541diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8542index 3afd391..18f9e36 100644
8543--- a/arch/powerpc/kernel/exceptions-64s.S
8544+++ b/arch/powerpc/kernel/exceptions-64s.S
8545@@ -1587,10 +1587,10 @@ handle_page_fault:
8546 11: ld r4,_DAR(r1)
8547 ld r5,_DSISR(r1)
8548 addi r3,r1,STACK_FRAME_OVERHEAD
8549+ bl .save_nvgprs
8550 bl .do_page_fault
8551 cmpdi r3,0
8552 beq+ 12f
8553- bl .save_nvgprs
8554 mr r5,r3
8555 addi r3,r1,STACK_FRAME_OVERHEAD
8556 lwz r4,_DAR(r1)
8557diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8558index ca1cd74..6f0241a 100644
8559--- a/arch/powerpc/kernel/irq.c
8560+++ b/arch/powerpc/kernel/irq.c
8561@@ -447,6 +447,8 @@ void migrate_irqs(void)
8562 }
8563 #endif
8564
8565+extern void gr_handle_kernel_exploit(void);
8566+
8567 static inline void check_stack_overflow(void)
8568 {
8569 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8570@@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
8571 printk("do_IRQ: stack overflow: %ld\n",
8572 sp - sizeof(struct thread_info));
8573 dump_stack();
8574+ gr_handle_kernel_exploit();
8575 }
8576 #endif
8577 }
8578diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8579index 6cff040..74ac5d1 100644
8580--- a/arch/powerpc/kernel/module_32.c
8581+++ b/arch/powerpc/kernel/module_32.c
8582@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8583 me->arch.core_plt_section = i;
8584 }
8585 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8586- printk("Module doesn't contain .plt or .init.plt sections.\n");
8587+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8588 return -ENOEXEC;
8589 }
8590
8591@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8592
8593 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8594 /* Init, or core PLT? */
8595- if (location >= mod->module_core
8596- && location < mod->module_core + mod->core_size)
8597+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8598+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8599 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8600- else
8601+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8602+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8603 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8604+ else {
8605+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8606+ return ~0UL;
8607+ }
8608
8609 /* Find this entry, or if that fails, the next avail. entry */
8610 while (entry->jump[0]) {
8611@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8612 }
8613 #ifdef CONFIG_DYNAMIC_FTRACE
8614 module->arch.tramp =
8615- do_plt_call(module->module_core,
8616+ do_plt_call(module->module_core_rx,
8617 (unsigned long)ftrace_caller,
8618 sechdrs, module);
8619 #endif
8620diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8621index 31d0215..206af70 100644
8622--- a/arch/powerpc/kernel/process.c
8623+++ b/arch/powerpc/kernel/process.c
8624@@ -1031,8 +1031,8 @@ void show_regs(struct pt_regs * regs)
8625 * Lookup NIP late so we have the best change of getting the
8626 * above info out without failing
8627 */
8628- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8629- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8630+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8631+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8632 #endif
8633 show_stack(current, (unsigned long *) regs->gpr[1]);
8634 if (!user_mode(regs))
8635@@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8636 newsp = stack[0];
8637 ip = stack[STACK_FRAME_LR_SAVE];
8638 if (!firstframe || ip != lr) {
8639- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8640+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8641 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8642 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8643- printk(" (%pS)",
8644+ printk(" (%pA)",
8645 (void *)current->ret_stack[curr_frame].ret);
8646 curr_frame--;
8647 }
8648@@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8649 struct pt_regs *regs = (struct pt_regs *)
8650 (sp + STACK_FRAME_OVERHEAD);
8651 lr = regs->link;
8652- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8653+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8654 regs->trap, (void *)regs->nip, (void *)lr);
8655 firstframe = 1;
8656 }
8657@@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
8658 mtspr(SPRN_CTRLT, ctrl);
8659 }
8660 #endif /* CONFIG_PPC64 */
8661-
8662-unsigned long arch_align_stack(unsigned long sp)
8663-{
8664- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8665- sp -= get_random_int() & ~PAGE_MASK;
8666- return sp & ~0xf;
8667-}
8668-
8669-static inline unsigned long brk_rnd(void)
8670-{
8671- unsigned long rnd = 0;
8672-
8673- /* 8MB for 32bit, 1GB for 64bit */
8674- if (is_32bit_task())
8675- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8676- else
8677- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8678-
8679- return rnd << PAGE_SHIFT;
8680-}
8681-
8682-unsigned long arch_randomize_brk(struct mm_struct *mm)
8683-{
8684- unsigned long base = mm->brk;
8685- unsigned long ret;
8686-
8687-#ifdef CONFIG_PPC_STD_MMU_64
8688- /*
8689- * If we are using 1TB segments and we are allowed to randomise
8690- * the heap, we can put it above 1TB so it is backed by a 1TB
8691- * segment. Otherwise the heap will be in the bottom 1TB
8692- * which always uses 256MB segments and this may result in a
8693- * performance penalty.
8694- */
8695- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8696- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8697-#endif
8698-
8699- ret = PAGE_ALIGN(base + brk_rnd());
8700-
8701- if (ret < mm->brk)
8702- return mm->brk;
8703-
8704- return ret;
8705-}
8706-
8707-unsigned long randomize_et_dyn(unsigned long base)
8708-{
8709- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8710-
8711- if (ret < base)
8712- return base;
8713-
8714- return ret;
8715-}
8716diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8717index 2e3d2bf..35df241 100644
8718--- a/arch/powerpc/kernel/ptrace.c
8719+++ b/arch/powerpc/kernel/ptrace.c
8720@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8721 return ret;
8722 }
8723
8724+#ifdef CONFIG_GRKERNSEC_SETXID
8725+extern void gr_delayed_cred_worker(void);
8726+#endif
8727+
8728 /*
8729 * We must return the syscall number to actually look up in the table.
8730 * This can be -1L to skip running any syscall at all.
8731@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8732
8733 secure_computing_strict(regs->gpr[0]);
8734
8735+#ifdef CONFIG_GRKERNSEC_SETXID
8736+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8737+ gr_delayed_cred_worker();
8738+#endif
8739+
8740 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8741 tracehook_report_syscall_entry(regs))
8742 /*
8743@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8744 {
8745 int step;
8746
8747+#ifdef CONFIG_GRKERNSEC_SETXID
8748+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8749+ gr_delayed_cred_worker();
8750+#endif
8751+
8752 audit_syscall_exit(regs);
8753
8754 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8755diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8756index 4e47db6..6dcc96e 100644
8757--- a/arch/powerpc/kernel/signal_32.c
8758+++ b/arch/powerpc/kernel/signal_32.c
8759@@ -1013,7 +1013,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8760 /* Save user registers on the stack */
8761 frame = &rt_sf->uc.uc_mcontext;
8762 addr = frame;
8763- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8764+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8765 sigret = 0;
8766 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8767 } else {
8768diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8769index d501dc4..e5a0de0 100644
8770--- a/arch/powerpc/kernel/signal_64.c
8771+++ b/arch/powerpc/kernel/signal_64.c
8772@@ -760,7 +760,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8773 current->thread.fp_state.fpscr = 0;
8774
8775 /* Set up to return from userspace. */
8776- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8777+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8778 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8779 } else {
8780 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8781diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8782index 1bd7ca2..9b78c2f 100644
8783--- a/arch/powerpc/kernel/traps.c
8784+++ b/arch/powerpc/kernel/traps.c
8785@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8786 return flags;
8787 }
8788
8789+extern void gr_handle_kernel_exploit(void);
8790+
8791 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8792 int signr)
8793 {
8794@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8795 panic("Fatal exception in interrupt");
8796 if (panic_on_oops)
8797 panic("Fatal exception");
8798+
8799+ gr_handle_kernel_exploit();
8800+
8801 do_exit(signr);
8802 }
8803
8804diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8805index ce74c33..0803371 100644
8806--- a/arch/powerpc/kernel/vdso.c
8807+++ b/arch/powerpc/kernel/vdso.c
8808@@ -35,6 +35,7 @@
8809 #include <asm/vdso.h>
8810 #include <asm/vdso_datapage.h>
8811 #include <asm/setup.h>
8812+#include <asm/mman.h>
8813
8814 #undef DEBUG
8815
8816@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8817 vdso_base = VDSO32_MBASE;
8818 #endif
8819
8820- current->mm->context.vdso_base = 0;
8821+ current->mm->context.vdso_base = ~0UL;
8822
8823 /* vDSO has a problem and was disabled, just don't "enable" it for the
8824 * process
8825@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8826 vdso_base = get_unmapped_area(NULL, vdso_base,
8827 (vdso_pages << PAGE_SHIFT) +
8828 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8829- 0, 0);
8830+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8831 if (IS_ERR_VALUE(vdso_base)) {
8832 rc = vdso_base;
8833 goto fail_mmapsem;
8834diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8835index 3cf541a..ab2d825 100644
8836--- a/arch/powerpc/kvm/powerpc.c
8837+++ b/arch/powerpc/kvm/powerpc.c
8838@@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8839 }
8840 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8841
8842-int kvm_arch_init(void *opaque)
8843+int kvm_arch_init(const void *opaque)
8844 {
8845 return 0;
8846 }
8847diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8848index 5eea6f3..5d10396 100644
8849--- a/arch/powerpc/lib/usercopy_64.c
8850+++ b/arch/powerpc/lib/usercopy_64.c
8851@@ -9,22 +9,6 @@
8852 #include <linux/module.h>
8853 #include <asm/uaccess.h>
8854
8855-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8856-{
8857- if (likely(access_ok(VERIFY_READ, from, n)))
8858- n = __copy_from_user(to, from, n);
8859- else
8860- memset(to, 0, n);
8861- return n;
8862-}
8863-
8864-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8865-{
8866- if (likely(access_ok(VERIFY_WRITE, to, n)))
8867- n = __copy_to_user(to, from, n);
8868- return n;
8869-}
8870-
8871 unsigned long copy_in_user(void __user *to, const void __user *from,
8872 unsigned long n)
8873 {
8874@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8875 return n;
8876 }
8877
8878-EXPORT_SYMBOL(copy_from_user);
8879-EXPORT_SYMBOL(copy_to_user);
8880 EXPORT_SYMBOL(copy_in_user);
8881
8882diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8883index 51ab9e7..7d3c78b 100644
8884--- a/arch/powerpc/mm/fault.c
8885+++ b/arch/powerpc/mm/fault.c
8886@@ -33,6 +33,10 @@
8887 #include <linux/magic.h>
8888 #include <linux/ratelimit.h>
8889 #include <linux/context_tracking.h>
8890+#include <linux/slab.h>
8891+#include <linux/pagemap.h>
8892+#include <linux/compiler.h>
8893+#include <linux/unistd.h>
8894
8895 #include <asm/firmware.h>
8896 #include <asm/page.h>
8897@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8898 }
8899 #endif
8900
8901+#ifdef CONFIG_PAX_PAGEEXEC
8902+/*
8903+ * PaX: decide what to do with offenders (regs->nip = fault address)
8904+ *
8905+ * returns 1 when task should be killed
8906+ */
8907+static int pax_handle_fetch_fault(struct pt_regs *regs)
8908+{
8909+ return 1;
8910+}
8911+
8912+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8913+{
8914+ unsigned long i;
8915+
8916+ printk(KERN_ERR "PAX: bytes at PC: ");
8917+ for (i = 0; i < 5; i++) {
8918+ unsigned int c;
8919+ if (get_user(c, (unsigned int __user *)pc+i))
8920+ printk(KERN_CONT "???????? ");
8921+ else
8922+ printk(KERN_CONT "%08x ", c);
8923+ }
8924+ printk("\n");
8925+}
8926+#endif
8927+
8928 /*
8929 * Check whether the instruction at regs->nip is a store using
8930 * an update addressing form which will update r1.
8931@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8932 * indicate errors in DSISR but can validly be set in SRR1.
8933 */
8934 if (trap == 0x400)
8935- error_code &= 0x48200000;
8936+ error_code &= 0x58200000;
8937 else
8938 is_write = error_code & DSISR_ISSTORE;
8939 #else
8940@@ -378,7 +409,7 @@ good_area:
8941 * "undefined". Of those that can be set, this is the only
8942 * one which seems bad.
8943 */
8944- if (error_code & 0x10000000)
8945+ if (error_code & DSISR_GUARDED)
8946 /* Guarded storage error. */
8947 goto bad_area;
8948 #endif /* CONFIG_8xx */
8949@@ -393,7 +424,7 @@ good_area:
8950 * processors use the same I/D cache coherency mechanism
8951 * as embedded.
8952 */
8953- if (error_code & DSISR_PROTFAULT)
8954+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8955 goto bad_area;
8956 #endif /* CONFIG_PPC_STD_MMU */
8957
8958@@ -483,6 +514,23 @@ bad_area:
8959 bad_area_nosemaphore:
8960 /* User mode accesses cause a SIGSEGV */
8961 if (user_mode(regs)) {
8962+
8963+#ifdef CONFIG_PAX_PAGEEXEC
8964+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8965+#ifdef CONFIG_PPC_STD_MMU
8966+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8967+#else
8968+ if (is_exec && regs->nip == address) {
8969+#endif
8970+ switch (pax_handle_fetch_fault(regs)) {
8971+ }
8972+
8973+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8974+ do_group_exit(SIGKILL);
8975+ }
8976+ }
8977+#endif
8978+
8979 _exception(SIGSEGV, regs, code, address);
8980 goto bail;
8981 }
8982diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8983index cb8bdbe..cde4bc7 100644
8984--- a/arch/powerpc/mm/mmap.c
8985+++ b/arch/powerpc/mm/mmap.c
8986@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8987 return sysctl_legacy_va_layout;
8988 }
8989
8990-static unsigned long mmap_rnd(void)
8991+static unsigned long mmap_rnd(struct mm_struct *mm)
8992 {
8993 unsigned long rnd = 0;
8994
8995+#ifdef CONFIG_PAX_RANDMMAP
8996+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8997+#endif
8998+
8999 if (current->flags & PF_RANDOMIZE) {
9000 /* 8MB for 32bit, 1GB for 64bit */
9001 if (is_32bit_task())
9002@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9003 return rnd << PAGE_SHIFT;
9004 }
9005
9006-static inline unsigned long mmap_base(void)
9007+static inline unsigned long mmap_base(struct mm_struct *mm)
9008 {
9009 unsigned long gap = rlimit(RLIMIT_STACK);
9010
9011@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9012 else if (gap > MAX_GAP)
9013 gap = MAX_GAP;
9014
9015- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9016+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9017 }
9018
9019 /*
9020@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9021 */
9022 if (mmap_is_legacy()) {
9023 mm->mmap_base = TASK_UNMAPPED_BASE;
9024+
9025+#ifdef CONFIG_PAX_RANDMMAP
9026+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9027+ mm->mmap_base += mm->delta_mmap;
9028+#endif
9029+
9030 mm->get_unmapped_area = arch_get_unmapped_area;
9031 } else {
9032- mm->mmap_base = mmap_base();
9033+ mm->mmap_base = mmap_base(mm);
9034+
9035+#ifdef CONFIG_PAX_RANDMMAP
9036+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9037+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9038+#endif
9039+
9040 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9041 }
9042 }
9043diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9044index b0c75cc..ef7fb93 100644
9045--- a/arch/powerpc/mm/slice.c
9046+++ b/arch/powerpc/mm/slice.c
9047@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9048 if ((mm->task_size - len) < addr)
9049 return 0;
9050 vma = find_vma(mm, addr);
9051- return (!vma || (addr + len) <= vma->vm_start);
9052+ return check_heap_stack_gap(vma, addr, len, 0);
9053 }
9054
9055 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9056@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9057 info.align_offset = 0;
9058
9059 addr = TASK_UNMAPPED_BASE;
9060+
9061+#ifdef CONFIG_PAX_RANDMMAP
9062+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9063+ addr += mm->delta_mmap;
9064+#endif
9065+
9066 while (addr < TASK_SIZE) {
9067 info.low_limit = addr;
9068 if (!slice_scan_available(addr, available, 1, &addr))
9069@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9070 if (fixed && addr > (mm->task_size - len))
9071 return -ENOMEM;
9072
9073+#ifdef CONFIG_PAX_RANDMMAP
9074+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9075+ addr = 0;
9076+#endif
9077+
9078 /* If hint, make sure it matches our alignment restrictions */
9079 if (!fixed && addr) {
9080 addr = _ALIGN_UP(addr, 1ul << pshift);
9081diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9082index 4278acf..67fd0e6 100644
9083--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9084+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9085@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9086 }
9087
9088 static struct pci_ops scc_pciex_pci_ops = {
9089- scc_pciex_read_config,
9090- scc_pciex_write_config,
9091+ .read = scc_pciex_read_config,
9092+ .write = scc_pciex_write_config,
9093 };
9094
9095 static void pciex_clear_intr_all(unsigned int __iomem *base)
9096diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9097index 9098692..3d54cd1 100644
9098--- a/arch/powerpc/platforms/cell/spufs/file.c
9099+++ b/arch/powerpc/platforms/cell/spufs/file.c
9100@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9101 return VM_FAULT_NOPAGE;
9102 }
9103
9104-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9105+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9106 unsigned long address,
9107- void *buf, int len, int write)
9108+ void *buf, size_t len, int write)
9109 {
9110 struct spu_context *ctx = vma->vm_file->private_data;
9111 unsigned long offset = address - vma->vm_start;
9112diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9113index 1d47061..0714963 100644
9114--- a/arch/s390/include/asm/atomic.h
9115+++ b/arch/s390/include/asm/atomic.h
9116@@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9117 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9118 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9119
9120+#define atomic64_read_unchecked(v) atomic64_read(v)
9121+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9122+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9123+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9124+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9125+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9126+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9127+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9128+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9129+
9130 #define smp_mb__before_atomic_dec() smp_mb()
9131 #define smp_mb__after_atomic_dec() smp_mb()
9132 #define smp_mb__before_atomic_inc() smp_mb()
9133diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9134index 578680f..0eb3b11 100644
9135--- a/arch/s390/include/asm/barrier.h
9136+++ b/arch/s390/include/asm/barrier.h
9137@@ -36,7 +36,7 @@
9138 do { \
9139 compiletime_assert_atomic_type(*p); \
9140 barrier(); \
9141- ACCESS_ONCE(*p) = (v); \
9142+ ACCESS_ONCE_RW(*p) = (v); \
9143 } while (0)
9144
9145 #define smp_load_acquire(p) \
9146diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9147index 4d7ccac..d03d0ad 100644
9148--- a/arch/s390/include/asm/cache.h
9149+++ b/arch/s390/include/asm/cache.h
9150@@ -9,8 +9,10 @@
9151 #ifndef __ARCH_S390_CACHE_H
9152 #define __ARCH_S390_CACHE_H
9153
9154-#define L1_CACHE_BYTES 256
9155+#include <linux/const.h>
9156+
9157 #define L1_CACHE_SHIFT 8
9158+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9159 #define NET_SKB_PAD 32
9160
9161 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9162diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9163index 78f4f87..598ce39 100644
9164--- a/arch/s390/include/asm/elf.h
9165+++ b/arch/s390/include/asm/elf.h
9166@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9167 the loader. We need to make sure that it is out of the way of the program
9168 that it will "exec", and that there is sufficient room for the brk. */
9169
9170-extern unsigned long randomize_et_dyn(unsigned long base);
9171-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9172+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9173+
9174+#ifdef CONFIG_PAX_ASLR
9175+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9176+
9177+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9178+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9179+#endif
9180
9181 /* This yields a mask that user programs can use to figure out what
9182 instruction set this CPU supports. */
9183@@ -222,9 +228,6 @@ struct linux_binprm;
9184 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9185 int arch_setup_additional_pages(struct linux_binprm *, int);
9186
9187-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9188-#define arch_randomize_brk arch_randomize_brk
9189-
9190 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9191
9192 #endif
9193diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9194index c4a93d6..4d2a9b4 100644
9195--- a/arch/s390/include/asm/exec.h
9196+++ b/arch/s390/include/asm/exec.h
9197@@ -7,6 +7,6 @@
9198 #ifndef __ASM_EXEC_H
9199 #define __ASM_EXEC_H
9200
9201-extern unsigned long arch_align_stack(unsigned long sp);
9202+#define arch_align_stack(x) ((x) & ~0xfUL)
9203
9204 #endif /* __ASM_EXEC_H */
9205diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9206index 1be64a1..086839d1 100644
9207--- a/arch/s390/include/asm/uaccess.h
9208+++ b/arch/s390/include/asm/uaccess.h
9209@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9210 __range_ok((unsigned long)(addr), (size)); \
9211 })
9212
9213+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9214 #define access_ok(type, addr, size) __access_ok(addr, size)
9215
9216 /*
9217@@ -245,6 +246,10 @@ static inline unsigned long __must_check
9218 copy_to_user(void __user *to, const void *from, unsigned long n)
9219 {
9220 might_fault();
9221+
9222+ if ((long)n < 0)
9223+ return n;
9224+
9225 return __copy_to_user(to, from, n);
9226 }
9227
9228@@ -273,10 +278,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9229 static inline unsigned long __must_check
9230 copy_from_user(void *to, const void __user *from, unsigned long n)
9231 {
9232- unsigned int sz = __compiletime_object_size(to);
9233+ size_t sz = __compiletime_object_size(to);
9234
9235 might_fault();
9236- if (unlikely(sz != -1 && sz < n)) {
9237+
9238+ if ((long)n < 0)
9239+ return n;
9240+
9241+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9242 copy_from_user_overflow();
9243 return n;
9244 }
9245diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9246index b89b591..fd9609d 100644
9247--- a/arch/s390/kernel/module.c
9248+++ b/arch/s390/kernel/module.c
9249@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9250
9251 /* Increase core size by size of got & plt and set start
9252 offsets for got and plt. */
9253- me->core_size = ALIGN(me->core_size, 4);
9254- me->arch.got_offset = me->core_size;
9255- me->core_size += me->arch.got_size;
9256- me->arch.plt_offset = me->core_size;
9257- me->core_size += me->arch.plt_size;
9258+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9259+ me->arch.got_offset = me->core_size_rw;
9260+ me->core_size_rw += me->arch.got_size;
9261+ me->arch.plt_offset = me->core_size_rx;
9262+ me->core_size_rx += me->arch.plt_size;
9263 return 0;
9264 }
9265
9266@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9267 if (info->got_initialized == 0) {
9268 Elf_Addr *gotent;
9269
9270- gotent = me->module_core + me->arch.got_offset +
9271+ gotent = me->module_core_rw + me->arch.got_offset +
9272 info->got_offset;
9273 *gotent = val;
9274 info->got_initialized = 1;
9275@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9276 rc = apply_rela_bits(loc, val, 0, 64, 0);
9277 else if (r_type == R_390_GOTENT ||
9278 r_type == R_390_GOTPLTENT) {
9279- val += (Elf_Addr) me->module_core - loc;
9280+ val += (Elf_Addr) me->module_core_rw - loc;
9281 rc = apply_rela_bits(loc, val, 1, 32, 1);
9282 }
9283 break;
9284@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9285 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9286 if (info->plt_initialized == 0) {
9287 unsigned int *ip;
9288- ip = me->module_core + me->arch.plt_offset +
9289+ ip = me->module_core_rx + me->arch.plt_offset +
9290 info->plt_offset;
9291 #ifndef CONFIG_64BIT
9292 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9293@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9294 val - loc + 0xffffUL < 0x1ffffeUL) ||
9295 (r_type == R_390_PLT32DBL &&
9296 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9297- val = (Elf_Addr) me->module_core +
9298+ val = (Elf_Addr) me->module_core_rx +
9299 me->arch.plt_offset +
9300 info->plt_offset;
9301 val += rela->r_addend - loc;
9302@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9303 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9304 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9305 val = val + rela->r_addend -
9306- ((Elf_Addr) me->module_core + me->arch.got_offset);
9307+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9308 if (r_type == R_390_GOTOFF16)
9309 rc = apply_rela_bits(loc, val, 0, 16, 0);
9310 else if (r_type == R_390_GOTOFF32)
9311@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9312 break;
9313 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9314 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9315- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9316+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9317 rela->r_addend - loc;
9318 if (r_type == R_390_GOTPC)
9319 rc = apply_rela_bits(loc, val, 1, 32, 0);
9320diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9321index dd14532..1dfc145 100644
9322--- a/arch/s390/kernel/process.c
9323+++ b/arch/s390/kernel/process.c
9324@@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9325 }
9326 return 0;
9327 }
9328-
9329-unsigned long arch_align_stack(unsigned long sp)
9330-{
9331- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9332- sp -= get_random_int() & ~PAGE_MASK;
9333- return sp & ~0xf;
9334-}
9335-
9336-static inline unsigned long brk_rnd(void)
9337-{
9338- /* 8MB for 32bit, 1GB for 64bit */
9339- if (is_32bit_task())
9340- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9341- else
9342- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9343-}
9344-
9345-unsigned long arch_randomize_brk(struct mm_struct *mm)
9346-{
9347- unsigned long ret;
9348-
9349- ret = PAGE_ALIGN(mm->brk + brk_rnd());
9350- return (ret > mm->brk) ? ret : mm->brk;
9351-}
9352-
9353-unsigned long randomize_et_dyn(unsigned long base)
9354-{
9355- unsigned long ret;
9356-
9357- if (!(current->flags & PF_RANDOMIZE))
9358- return base;
9359- ret = PAGE_ALIGN(base + brk_rnd());
9360- return (ret > base) ? ret : base;
9361-}
9362diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9363index 9b436c2..54fbf0a 100644
9364--- a/arch/s390/mm/mmap.c
9365+++ b/arch/s390/mm/mmap.c
9366@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9367 */
9368 if (mmap_is_legacy()) {
9369 mm->mmap_base = mmap_base_legacy();
9370+
9371+#ifdef CONFIG_PAX_RANDMMAP
9372+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9373+ mm->mmap_base += mm->delta_mmap;
9374+#endif
9375+
9376 mm->get_unmapped_area = arch_get_unmapped_area;
9377 } else {
9378 mm->mmap_base = mmap_base();
9379+
9380+#ifdef CONFIG_PAX_RANDMMAP
9381+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9382+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9383+#endif
9384+
9385 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9386 }
9387 }
9388@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9389 */
9390 if (mmap_is_legacy()) {
9391 mm->mmap_base = mmap_base_legacy();
9392+
9393+#ifdef CONFIG_PAX_RANDMMAP
9394+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9395+ mm->mmap_base += mm->delta_mmap;
9396+#endif
9397+
9398 mm->get_unmapped_area = s390_get_unmapped_area;
9399 } else {
9400 mm->mmap_base = mmap_base();
9401+
9402+#ifdef CONFIG_PAX_RANDMMAP
9403+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9404+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9405+#endif
9406+
9407 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9408 }
9409 }
9410diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9411index ae3d59f..f65f075 100644
9412--- a/arch/score/include/asm/cache.h
9413+++ b/arch/score/include/asm/cache.h
9414@@ -1,7 +1,9 @@
9415 #ifndef _ASM_SCORE_CACHE_H
9416 #define _ASM_SCORE_CACHE_H
9417
9418+#include <linux/const.h>
9419+
9420 #define L1_CACHE_SHIFT 4
9421-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9422+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9423
9424 #endif /* _ASM_SCORE_CACHE_H */
9425diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9426index f9f3cd5..58ff438 100644
9427--- a/arch/score/include/asm/exec.h
9428+++ b/arch/score/include/asm/exec.h
9429@@ -1,6 +1,6 @@
9430 #ifndef _ASM_SCORE_EXEC_H
9431 #define _ASM_SCORE_EXEC_H
9432
9433-extern unsigned long arch_align_stack(unsigned long sp);
9434+#define arch_align_stack(x) (x)
9435
9436 #endif /* _ASM_SCORE_EXEC_H */
9437diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9438index a1519ad3..e8ac1ff 100644
9439--- a/arch/score/kernel/process.c
9440+++ b/arch/score/kernel/process.c
9441@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9442
9443 return task_pt_regs(task)->cp0_epc;
9444 }
9445-
9446-unsigned long arch_align_stack(unsigned long sp)
9447-{
9448- return sp;
9449-}
9450diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9451index ef9e555..331bd29 100644
9452--- a/arch/sh/include/asm/cache.h
9453+++ b/arch/sh/include/asm/cache.h
9454@@ -9,10 +9,11 @@
9455 #define __ASM_SH_CACHE_H
9456 #ifdef __KERNEL__
9457
9458+#include <linux/const.h>
9459 #include <linux/init.h>
9460 #include <cpu/cache.h>
9461
9462-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9463+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9464
9465 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9466
9467diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9468index 6777177..cb5e44f 100644
9469--- a/arch/sh/mm/mmap.c
9470+++ b/arch/sh/mm/mmap.c
9471@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9472 struct mm_struct *mm = current->mm;
9473 struct vm_area_struct *vma;
9474 int do_colour_align;
9475+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9476 struct vm_unmapped_area_info info;
9477
9478 if (flags & MAP_FIXED) {
9479@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9480 if (filp || (flags & MAP_SHARED))
9481 do_colour_align = 1;
9482
9483+#ifdef CONFIG_PAX_RANDMMAP
9484+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9485+#endif
9486+
9487 if (addr) {
9488 if (do_colour_align)
9489 addr = COLOUR_ALIGN(addr, pgoff);
9490@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9491 addr = PAGE_ALIGN(addr);
9492
9493 vma = find_vma(mm, addr);
9494- if (TASK_SIZE - len >= addr &&
9495- (!vma || addr + len <= vma->vm_start))
9496+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9497 return addr;
9498 }
9499
9500 info.flags = 0;
9501 info.length = len;
9502- info.low_limit = TASK_UNMAPPED_BASE;
9503+ info.low_limit = mm->mmap_base;
9504 info.high_limit = TASK_SIZE;
9505 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9506 info.align_offset = pgoff << PAGE_SHIFT;
9507@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9508 struct mm_struct *mm = current->mm;
9509 unsigned long addr = addr0;
9510 int do_colour_align;
9511+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9512 struct vm_unmapped_area_info info;
9513
9514 if (flags & MAP_FIXED) {
9515@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9516 if (filp || (flags & MAP_SHARED))
9517 do_colour_align = 1;
9518
9519+#ifdef CONFIG_PAX_RANDMMAP
9520+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9521+#endif
9522+
9523 /* requesting a specific address */
9524 if (addr) {
9525 if (do_colour_align)
9526@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9527 addr = PAGE_ALIGN(addr);
9528
9529 vma = find_vma(mm, addr);
9530- if (TASK_SIZE - len >= addr &&
9531- (!vma || addr + len <= vma->vm_start))
9532+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9533 return addr;
9534 }
9535
9536@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9537 VM_BUG_ON(addr != -ENOMEM);
9538 info.flags = 0;
9539 info.low_limit = TASK_UNMAPPED_BASE;
9540+
9541+#ifdef CONFIG_PAX_RANDMMAP
9542+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9543+ info.low_limit += mm->delta_mmap;
9544+#endif
9545+
9546 info.high_limit = TASK_SIZE;
9547 addr = vm_unmapped_area(&info);
9548 }
9549diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9550index be56a24..443328f 100644
9551--- a/arch/sparc/include/asm/atomic_64.h
9552+++ b/arch/sparc/include/asm/atomic_64.h
9553@@ -14,18 +14,40 @@
9554 #define ATOMIC64_INIT(i) { (i) }
9555
9556 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9557+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9558+{
9559+ return v->counter;
9560+}
9561 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9562+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9563+{
9564+ return v->counter;
9565+}
9566
9567 #define atomic_set(v, i) (((v)->counter) = i)
9568+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9569+{
9570+ v->counter = i;
9571+}
9572 #define atomic64_set(v, i) (((v)->counter) = i)
9573+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9574+{
9575+ v->counter = i;
9576+}
9577
9578 extern void atomic_add(int, atomic_t *);
9579+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9580 extern void atomic64_add(long, atomic64_t *);
9581+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9582 extern void atomic_sub(int, atomic_t *);
9583+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9584 extern void atomic64_sub(long, atomic64_t *);
9585+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9586
9587 extern int atomic_add_ret(int, atomic_t *);
9588+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9589 extern long atomic64_add_ret(long, atomic64_t *);
9590+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9591 extern int atomic_sub_ret(int, atomic_t *);
9592 extern long atomic64_sub_ret(long, atomic64_t *);
9593
9594@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9595 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9596
9597 #define atomic_inc_return(v) atomic_add_ret(1, v)
9598+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9599+{
9600+ return atomic_add_ret_unchecked(1, v);
9601+}
9602 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9603+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9604+{
9605+ return atomic64_add_ret_unchecked(1, v);
9606+}
9607
9608 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9609 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9610
9611 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9612+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9613+{
9614+ return atomic_add_ret_unchecked(i, v);
9615+}
9616 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9617+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9618+{
9619+ return atomic64_add_ret_unchecked(i, v);
9620+}
9621
9622 /*
9623 * atomic_inc_and_test - increment and test
9624@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9625 * other cases.
9626 */
9627 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9628+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9629+{
9630+ return atomic_inc_return_unchecked(v) == 0;
9631+}
9632 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9633
9634 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9635@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9636 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9637
9638 #define atomic_inc(v) atomic_add(1, v)
9639+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9640+{
9641+ atomic_add_unchecked(1, v);
9642+}
9643 #define atomic64_inc(v) atomic64_add(1, v)
9644+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9645+{
9646+ atomic64_add_unchecked(1, v);
9647+}
9648
9649 #define atomic_dec(v) atomic_sub(1, v)
9650+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9651+{
9652+ atomic_sub_unchecked(1, v);
9653+}
9654 #define atomic64_dec(v) atomic64_sub(1, v)
9655+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9656+{
9657+ atomic64_sub_unchecked(1, v);
9658+}
9659
9660 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9661 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9662
9663 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9664+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9665+{
9666+ return cmpxchg(&v->counter, old, new);
9667+}
9668 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9669+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9670+{
9671+ return xchg(&v->counter, new);
9672+}
9673
9674 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9675 {
9676- int c, old;
9677+ int c, old, new;
9678 c = atomic_read(v);
9679 for (;;) {
9680- if (unlikely(c == (u)))
9681+ if (unlikely(c == u))
9682 break;
9683- old = atomic_cmpxchg((v), c, c + (a));
9684+
9685+ asm volatile("addcc %2, %0, %0\n"
9686+
9687+#ifdef CONFIG_PAX_REFCOUNT
9688+ "tvs %%icc, 6\n"
9689+#endif
9690+
9691+ : "=r" (new)
9692+ : "0" (c), "ir" (a)
9693+ : "cc");
9694+
9695+ old = atomic_cmpxchg(v, c, new);
9696 if (likely(old == c))
9697 break;
9698 c = old;
9699@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9700 #define atomic64_cmpxchg(v, o, n) \
9701 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9702 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9703+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9704+{
9705+ return xchg(&v->counter, new);
9706+}
9707
9708 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9709 {
9710- long c, old;
9711+ long c, old, new;
9712 c = atomic64_read(v);
9713 for (;;) {
9714- if (unlikely(c == (u)))
9715+ if (unlikely(c == u))
9716 break;
9717- old = atomic64_cmpxchg((v), c, c + (a));
9718+
9719+ asm volatile("addcc %2, %0, %0\n"
9720+
9721+#ifdef CONFIG_PAX_REFCOUNT
9722+ "tvs %%xcc, 6\n"
9723+#endif
9724+
9725+ : "=r" (new)
9726+ : "0" (c), "ir" (a)
9727+ : "cc");
9728+
9729+ old = atomic64_cmpxchg(v, c, new);
9730 if (likely(old == c))
9731 break;
9732 c = old;
9733 }
9734- return c != (u);
9735+ return c != u;
9736 }
9737
9738 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9739diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
9740index b5aad96..99d7465 100644
9741--- a/arch/sparc/include/asm/barrier_64.h
9742+++ b/arch/sparc/include/asm/barrier_64.h
9743@@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
9744 do { \
9745 compiletime_assert_atomic_type(*p); \
9746 barrier(); \
9747- ACCESS_ONCE(*p) = (v); \
9748+ ACCESS_ONCE_RW(*p) = (v); \
9749 } while (0)
9750
9751 #define smp_load_acquire(p) \
9752diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9753index 5bb6991..5c2132e 100644
9754--- a/arch/sparc/include/asm/cache.h
9755+++ b/arch/sparc/include/asm/cache.h
9756@@ -7,10 +7,12 @@
9757 #ifndef _SPARC_CACHE_H
9758 #define _SPARC_CACHE_H
9759
9760+#include <linux/const.h>
9761+
9762 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9763
9764 #define L1_CACHE_SHIFT 5
9765-#define L1_CACHE_BYTES 32
9766+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9767
9768 #ifdef CONFIG_SPARC32
9769 #define SMP_CACHE_BYTES_SHIFT 5
9770diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9771index a24e41f..47677ff 100644
9772--- a/arch/sparc/include/asm/elf_32.h
9773+++ b/arch/sparc/include/asm/elf_32.h
9774@@ -114,6 +114,13 @@ typedef struct {
9775
9776 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9777
9778+#ifdef CONFIG_PAX_ASLR
9779+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9780+
9781+#define PAX_DELTA_MMAP_LEN 16
9782+#define PAX_DELTA_STACK_LEN 16
9783+#endif
9784+
9785 /* This yields a mask that user programs can use to figure out what
9786 instruction set this cpu supports. This can NOT be done in userspace
9787 on Sparc. */
9788diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9789index 370ca1e..d4f4a98 100644
9790--- a/arch/sparc/include/asm/elf_64.h
9791+++ b/arch/sparc/include/asm/elf_64.h
9792@@ -189,6 +189,13 @@ typedef struct {
9793 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9794 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9795
9796+#ifdef CONFIG_PAX_ASLR
9797+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9798+
9799+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9800+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9801+#endif
9802+
9803 extern unsigned long sparc64_elf_hwcap;
9804 #define ELF_HWCAP sparc64_elf_hwcap
9805
9806diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9807index 9b1c36d..209298b 100644
9808--- a/arch/sparc/include/asm/pgalloc_32.h
9809+++ b/arch/sparc/include/asm/pgalloc_32.h
9810@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9811 }
9812
9813 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9814+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9815
9816 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9817 unsigned long address)
9818diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9819index bcfe063..b333142 100644
9820--- a/arch/sparc/include/asm/pgalloc_64.h
9821+++ b/arch/sparc/include/asm/pgalloc_64.h
9822@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9823 }
9824
9825 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9826+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9827
9828 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9829 {
9830diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9831index 59ba6f6..4518128 100644
9832--- a/arch/sparc/include/asm/pgtable.h
9833+++ b/arch/sparc/include/asm/pgtable.h
9834@@ -5,4 +5,8 @@
9835 #else
9836 #include <asm/pgtable_32.h>
9837 #endif
9838+
9839+#define ktla_ktva(addr) (addr)
9840+#define ktva_ktla(addr) (addr)
9841+
9842 #endif
9843diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9844index 502f632..da1917f 100644
9845--- a/arch/sparc/include/asm/pgtable_32.h
9846+++ b/arch/sparc/include/asm/pgtable_32.h
9847@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9848 #define PAGE_SHARED SRMMU_PAGE_SHARED
9849 #define PAGE_COPY SRMMU_PAGE_COPY
9850 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9851+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9852+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9853+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9854 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9855
9856 /* Top-level page directory - dummy used by init-mm.
9857@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9858
9859 /* xwr */
9860 #define __P000 PAGE_NONE
9861-#define __P001 PAGE_READONLY
9862-#define __P010 PAGE_COPY
9863-#define __P011 PAGE_COPY
9864+#define __P001 PAGE_READONLY_NOEXEC
9865+#define __P010 PAGE_COPY_NOEXEC
9866+#define __P011 PAGE_COPY_NOEXEC
9867 #define __P100 PAGE_READONLY
9868 #define __P101 PAGE_READONLY
9869 #define __P110 PAGE_COPY
9870 #define __P111 PAGE_COPY
9871
9872 #define __S000 PAGE_NONE
9873-#define __S001 PAGE_READONLY
9874-#define __S010 PAGE_SHARED
9875-#define __S011 PAGE_SHARED
9876+#define __S001 PAGE_READONLY_NOEXEC
9877+#define __S010 PAGE_SHARED_NOEXEC
9878+#define __S011 PAGE_SHARED_NOEXEC
9879 #define __S100 PAGE_READONLY
9880 #define __S101 PAGE_READONLY
9881 #define __S110 PAGE_SHARED
9882diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9883index 79da178..c2eede8 100644
9884--- a/arch/sparc/include/asm/pgtsrmmu.h
9885+++ b/arch/sparc/include/asm/pgtsrmmu.h
9886@@ -115,6 +115,11 @@
9887 SRMMU_EXEC | SRMMU_REF)
9888 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9889 SRMMU_EXEC | SRMMU_REF)
9890+
9891+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9892+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9893+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9894+
9895 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9896 SRMMU_DIRTY | SRMMU_REF)
9897
9898diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9899index 9689176..63c18ea 100644
9900--- a/arch/sparc/include/asm/spinlock_64.h
9901+++ b/arch/sparc/include/asm/spinlock_64.h
9902@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9903
9904 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9905
9906-static void inline arch_read_lock(arch_rwlock_t *lock)
9907+static inline void arch_read_lock(arch_rwlock_t *lock)
9908 {
9909 unsigned long tmp1, tmp2;
9910
9911 __asm__ __volatile__ (
9912 "1: ldsw [%2], %0\n"
9913 " brlz,pn %0, 2f\n"
9914-"4: add %0, 1, %1\n"
9915+"4: addcc %0, 1, %1\n"
9916+
9917+#ifdef CONFIG_PAX_REFCOUNT
9918+" tvs %%icc, 6\n"
9919+#endif
9920+
9921 " cas [%2], %0, %1\n"
9922 " cmp %0, %1\n"
9923 " bne,pn %%icc, 1b\n"
9924@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9925 " .previous"
9926 : "=&r" (tmp1), "=&r" (tmp2)
9927 : "r" (lock)
9928- : "memory");
9929+ : "memory", "cc");
9930 }
9931
9932-static int inline arch_read_trylock(arch_rwlock_t *lock)
9933+static inline int arch_read_trylock(arch_rwlock_t *lock)
9934 {
9935 int tmp1, tmp2;
9936
9937@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9938 "1: ldsw [%2], %0\n"
9939 " brlz,a,pn %0, 2f\n"
9940 " mov 0, %0\n"
9941-" add %0, 1, %1\n"
9942+" addcc %0, 1, %1\n"
9943+
9944+#ifdef CONFIG_PAX_REFCOUNT
9945+" tvs %%icc, 6\n"
9946+#endif
9947+
9948 " cas [%2], %0, %1\n"
9949 " cmp %0, %1\n"
9950 " bne,pn %%icc, 1b\n"
9951@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9952 return tmp1;
9953 }
9954
9955-static void inline arch_read_unlock(arch_rwlock_t *lock)
9956+static inline void arch_read_unlock(arch_rwlock_t *lock)
9957 {
9958 unsigned long tmp1, tmp2;
9959
9960 __asm__ __volatile__(
9961 "1: lduw [%2], %0\n"
9962-" sub %0, 1, %1\n"
9963+" subcc %0, 1, %1\n"
9964+
9965+#ifdef CONFIG_PAX_REFCOUNT
9966+" tvs %%icc, 6\n"
9967+#endif
9968+
9969 " cas [%2], %0, %1\n"
9970 " cmp %0, %1\n"
9971 " bne,pn %%xcc, 1b\n"
9972@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9973 : "memory");
9974 }
9975
9976-static void inline arch_write_lock(arch_rwlock_t *lock)
9977+static inline void arch_write_lock(arch_rwlock_t *lock)
9978 {
9979 unsigned long mask, tmp1, tmp2;
9980
9981@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9982 : "memory");
9983 }
9984
9985-static void inline arch_write_unlock(arch_rwlock_t *lock)
9986+static inline void arch_write_unlock(arch_rwlock_t *lock)
9987 {
9988 __asm__ __volatile__(
9989 " stw %%g0, [%0]"
9990@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9991 : "memory");
9992 }
9993
9994-static int inline arch_write_trylock(arch_rwlock_t *lock)
9995+static inline int arch_write_trylock(arch_rwlock_t *lock)
9996 {
9997 unsigned long mask, tmp1, tmp2, result;
9998
9999diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10000index 96efa7a..16858bf 100644
10001--- a/arch/sparc/include/asm/thread_info_32.h
10002+++ b/arch/sparc/include/asm/thread_info_32.h
10003@@ -49,6 +49,8 @@ struct thread_info {
10004 unsigned long w_saved;
10005
10006 struct restart_block restart_block;
10007+
10008+ unsigned long lowest_stack;
10009 };
10010
10011 /*
10012diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10013index a5f01ac..703b554 100644
10014--- a/arch/sparc/include/asm/thread_info_64.h
10015+++ b/arch/sparc/include/asm/thread_info_64.h
10016@@ -63,6 +63,8 @@ struct thread_info {
10017 struct pt_regs *kern_una_regs;
10018 unsigned int kern_una_insn;
10019
10020+ unsigned long lowest_stack;
10021+
10022 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10023 };
10024
10025@@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10026 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10027 /* flag bit 4 is available */
10028 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10029-/* flag bit 6 is available */
10030+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10031 #define TIF_32BIT 7 /* 32-bit binary */
10032 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10033 #define TIF_SECCOMP 9 /* secure computing */
10034 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10035 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10036+
10037 /* NOTE: Thread flags >= 12 should be ones we have no interest
10038 * in using in assembly, else we can't use the mask as
10039 * an immediate value in instructions such as andcc.
10040@@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10041 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10042 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10043 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10044+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10045
10046 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10047 _TIF_DO_NOTIFY_RESUME_MASK | \
10048 _TIF_NEED_RESCHED)
10049 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10050
10051+#define _TIF_WORK_SYSCALL \
10052+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10053+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10054+
10055+
10056 /*
10057 * Thread-synchronous status.
10058 *
10059diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10060index 0167d26..767bb0c 100644
10061--- a/arch/sparc/include/asm/uaccess.h
10062+++ b/arch/sparc/include/asm/uaccess.h
10063@@ -1,5 +1,6 @@
10064 #ifndef ___ASM_SPARC_UACCESS_H
10065 #define ___ASM_SPARC_UACCESS_H
10066+
10067 #if defined(__sparc__) && defined(__arch64__)
10068 #include <asm/uaccess_64.h>
10069 #else
10070diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10071index 53a28dd..50c38c3 100644
10072--- a/arch/sparc/include/asm/uaccess_32.h
10073+++ b/arch/sparc/include/asm/uaccess_32.h
10074@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
10075
10076 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10077 {
10078- if (n && __access_ok((unsigned long) to, n))
10079+ if ((long)n < 0)
10080+ return n;
10081+
10082+ if (n && __access_ok((unsigned long) to, n)) {
10083+ if (!__builtin_constant_p(n))
10084+ check_object_size(from, n, true);
10085 return __copy_user(to, (__force void __user *) from, n);
10086- else
10087+ } else
10088 return n;
10089 }
10090
10091 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10092 {
10093+ if ((long)n < 0)
10094+ return n;
10095+
10096+ if (!__builtin_constant_p(n))
10097+ check_object_size(from, n, true);
10098+
10099 return __copy_user(to, (__force void __user *) from, n);
10100 }
10101
10102 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10103 {
10104- if (n && __access_ok((unsigned long) from, n))
10105+ if ((long)n < 0)
10106+ return n;
10107+
10108+ if (n && __access_ok((unsigned long) from, n)) {
10109+ if (!__builtin_constant_p(n))
10110+ check_object_size(to, n, false);
10111 return __copy_user((__force void __user *) to, from, n);
10112- else
10113+ } else
10114 return n;
10115 }
10116
10117 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10118 {
10119+ if ((long)n < 0)
10120+ return n;
10121+
10122 return __copy_user((__force void __user *) to, from, n);
10123 }
10124
10125diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10126index ad7e178..c9e7423 100644
10127--- a/arch/sparc/include/asm/uaccess_64.h
10128+++ b/arch/sparc/include/asm/uaccess_64.h
10129@@ -10,6 +10,7 @@
10130 #include <linux/compiler.h>
10131 #include <linux/string.h>
10132 #include <linux/thread_info.h>
10133+#include <linux/kernel.h>
10134 #include <asm/asi.h>
10135 #include <asm/spitfire.h>
10136 #include <asm-generic/uaccess-unaligned.h>
10137@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10138 static inline unsigned long __must_check
10139 copy_from_user(void *to, const void __user *from, unsigned long size)
10140 {
10141- unsigned long ret = ___copy_from_user(to, from, size);
10142+ unsigned long ret;
10143
10144+ if ((long)size < 0 || size > INT_MAX)
10145+ return size;
10146+
10147+ if (!__builtin_constant_p(size))
10148+ check_object_size(to, size, false);
10149+
10150+ ret = ___copy_from_user(to, from, size);
10151 if (unlikely(ret))
10152 ret = copy_from_user_fixup(to, from, size);
10153
10154@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10155 static inline unsigned long __must_check
10156 copy_to_user(void __user *to, const void *from, unsigned long size)
10157 {
10158- unsigned long ret = ___copy_to_user(to, from, size);
10159+ unsigned long ret;
10160
10161+ if ((long)size < 0 || size > INT_MAX)
10162+ return size;
10163+
10164+ if (!__builtin_constant_p(size))
10165+ check_object_size(from, size, true);
10166+
10167+ ret = ___copy_to_user(to, from, size);
10168 if (unlikely(ret))
10169 ret = copy_to_user_fixup(to, from, size);
10170 return ret;
10171diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10172index d15cc17..d0ae796 100644
10173--- a/arch/sparc/kernel/Makefile
10174+++ b/arch/sparc/kernel/Makefile
10175@@ -4,7 +4,7 @@
10176 #
10177
10178 asflags-y := -ansi
10179-ccflags-y := -Werror
10180+#ccflags-y := -Werror
10181
10182 extra-y := head_$(BITS).o
10183
10184diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10185index 510baec..9ff2607 100644
10186--- a/arch/sparc/kernel/process_32.c
10187+++ b/arch/sparc/kernel/process_32.c
10188@@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10189
10190 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10191 r->psr, r->pc, r->npc, r->y, print_tainted());
10192- printk("PC: <%pS>\n", (void *) r->pc);
10193+ printk("PC: <%pA>\n", (void *) r->pc);
10194 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10195 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10196 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10197 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10198 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10199 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10200- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10201+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10202
10203 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10204 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10205@@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10206 rw = (struct reg_window32 *) fp;
10207 pc = rw->ins[7];
10208 printk("[%08lx : ", pc);
10209- printk("%pS ] ", (void *) pc);
10210+ printk("%pA ] ", (void *) pc);
10211 fp = rw->ins[6];
10212 } while (++count < 16);
10213 printk("\n");
10214diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10215index d7b4967..2edf827 100644
10216--- a/arch/sparc/kernel/process_64.c
10217+++ b/arch/sparc/kernel/process_64.c
10218@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10219 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10220 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10221 if (regs->tstate & TSTATE_PRIV)
10222- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10223+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10224 }
10225
10226 void show_regs(struct pt_regs *regs)
10227@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10228
10229 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10230 regs->tpc, regs->tnpc, regs->y, print_tainted());
10231- printk("TPC: <%pS>\n", (void *) regs->tpc);
10232+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10233 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10234 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10235 regs->u_regs[3]);
10236@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10237 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10238 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10239 regs->u_regs[15]);
10240- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10241+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10242 show_regwindow(regs);
10243 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10244 }
10245@@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10246 ((tp && tp->task) ? tp->task->pid : -1));
10247
10248 if (gp->tstate & TSTATE_PRIV) {
10249- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10250+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10251 (void *) gp->tpc,
10252 (void *) gp->o7,
10253 (void *) gp->i7,
10254diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10255index 79cc0d1..ec62734 100644
10256--- a/arch/sparc/kernel/prom_common.c
10257+++ b/arch/sparc/kernel/prom_common.c
10258@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10259
10260 unsigned int prom_early_allocated __initdata;
10261
10262-static struct of_pdt_ops prom_sparc_ops __initdata = {
10263+static struct of_pdt_ops prom_sparc_ops __initconst = {
10264 .nextprop = prom_common_nextprop,
10265 .getproplen = prom_getproplen,
10266 .getproperty = prom_getproperty,
10267diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10268index c13c9f2..d572c34 100644
10269--- a/arch/sparc/kernel/ptrace_64.c
10270+++ b/arch/sparc/kernel/ptrace_64.c
10271@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10272 return ret;
10273 }
10274
10275+#ifdef CONFIG_GRKERNSEC_SETXID
10276+extern void gr_delayed_cred_worker(void);
10277+#endif
10278+
10279 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10280 {
10281 int ret = 0;
10282@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10283 if (test_thread_flag(TIF_NOHZ))
10284 user_exit();
10285
10286+#ifdef CONFIG_GRKERNSEC_SETXID
10287+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10288+ gr_delayed_cred_worker();
10289+#endif
10290+
10291 if (test_thread_flag(TIF_SYSCALL_TRACE))
10292 ret = tracehook_report_syscall_entry(regs);
10293
10294@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10295 if (test_thread_flag(TIF_NOHZ))
10296 user_exit();
10297
10298+#ifdef CONFIG_GRKERNSEC_SETXID
10299+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10300+ gr_delayed_cred_worker();
10301+#endif
10302+
10303 audit_syscall_exit(regs);
10304
10305 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10306diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10307index 745a363..b5566b1 100644
10308--- a/arch/sparc/kernel/smp_64.c
10309+++ b/arch/sparc/kernel/smp_64.c
10310@@ -868,8 +868,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10311 extern unsigned long xcall_flush_dcache_page_spitfire;
10312
10313 #ifdef CONFIG_DEBUG_DCFLUSH
10314-extern atomic_t dcpage_flushes;
10315-extern atomic_t dcpage_flushes_xcall;
10316+extern atomic_unchecked_t dcpage_flushes;
10317+extern atomic_unchecked_t dcpage_flushes_xcall;
10318 #endif
10319
10320 static inline void __local_flush_dcache_page(struct page *page)
10321@@ -893,7 +893,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10322 return;
10323
10324 #ifdef CONFIG_DEBUG_DCFLUSH
10325- atomic_inc(&dcpage_flushes);
10326+ atomic_inc_unchecked(&dcpage_flushes);
10327 #endif
10328
10329 this_cpu = get_cpu();
10330@@ -917,7 +917,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10331 xcall_deliver(data0, __pa(pg_addr),
10332 (u64) pg_addr, cpumask_of(cpu));
10333 #ifdef CONFIG_DEBUG_DCFLUSH
10334- atomic_inc(&dcpage_flushes_xcall);
10335+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10336 #endif
10337 }
10338 }
10339@@ -936,7 +936,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10340 preempt_disable();
10341
10342 #ifdef CONFIG_DEBUG_DCFLUSH
10343- atomic_inc(&dcpage_flushes);
10344+ atomic_inc_unchecked(&dcpage_flushes);
10345 #endif
10346 data0 = 0;
10347 pg_addr = page_address(page);
10348@@ -953,7 +953,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10349 xcall_deliver(data0, __pa(pg_addr),
10350 (u64) pg_addr, cpu_online_mask);
10351 #ifdef CONFIG_DEBUG_DCFLUSH
10352- atomic_inc(&dcpage_flushes_xcall);
10353+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10354 #endif
10355 }
10356 __local_flush_dcache_page(page);
10357diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10358index 3a8d184..49498a8 100644
10359--- a/arch/sparc/kernel/sys_sparc_32.c
10360+++ b/arch/sparc/kernel/sys_sparc_32.c
10361@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10362 if (len > TASK_SIZE - PAGE_SIZE)
10363 return -ENOMEM;
10364 if (!addr)
10365- addr = TASK_UNMAPPED_BASE;
10366+ addr = current->mm->mmap_base;
10367
10368 info.flags = 0;
10369 info.length = len;
10370diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10371index beb0b5a..5a153f7 100644
10372--- a/arch/sparc/kernel/sys_sparc_64.c
10373+++ b/arch/sparc/kernel/sys_sparc_64.c
10374@@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10375 struct vm_area_struct * vma;
10376 unsigned long task_size = TASK_SIZE;
10377 int do_color_align;
10378+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10379 struct vm_unmapped_area_info info;
10380
10381 if (flags & MAP_FIXED) {
10382 /* We do not accept a shared mapping if it would violate
10383 * cache aliasing constraints.
10384 */
10385- if ((flags & MAP_SHARED) &&
10386+ if ((filp || (flags & MAP_SHARED)) &&
10387 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10388 return -EINVAL;
10389 return addr;
10390@@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10391 if (filp || (flags & MAP_SHARED))
10392 do_color_align = 1;
10393
10394+#ifdef CONFIG_PAX_RANDMMAP
10395+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10396+#endif
10397+
10398 if (addr) {
10399 if (do_color_align)
10400 addr = COLOR_ALIGN(addr, pgoff);
10401@@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10402 addr = PAGE_ALIGN(addr);
10403
10404 vma = find_vma(mm, addr);
10405- if (task_size - len >= addr &&
10406- (!vma || addr + len <= vma->vm_start))
10407+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10408 return addr;
10409 }
10410
10411 info.flags = 0;
10412 info.length = len;
10413- info.low_limit = TASK_UNMAPPED_BASE;
10414+ info.low_limit = mm->mmap_base;
10415 info.high_limit = min(task_size, VA_EXCLUDE_START);
10416 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10417 info.align_offset = pgoff << PAGE_SHIFT;
10418+ info.threadstack_offset = offset;
10419 addr = vm_unmapped_area(&info);
10420
10421 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10422 VM_BUG_ON(addr != -ENOMEM);
10423 info.low_limit = VA_EXCLUDE_END;
10424+
10425+#ifdef CONFIG_PAX_RANDMMAP
10426+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10427+ info.low_limit += mm->delta_mmap;
10428+#endif
10429+
10430 info.high_limit = task_size;
10431 addr = vm_unmapped_area(&info);
10432 }
10433@@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10434 unsigned long task_size = STACK_TOP32;
10435 unsigned long addr = addr0;
10436 int do_color_align;
10437+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10438 struct vm_unmapped_area_info info;
10439
10440 /* This should only ever run for 32-bit processes. */
10441@@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10442 /* We do not accept a shared mapping if it would violate
10443 * cache aliasing constraints.
10444 */
10445- if ((flags & MAP_SHARED) &&
10446+ if ((filp || (flags & MAP_SHARED)) &&
10447 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10448 return -EINVAL;
10449 return addr;
10450@@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10451 if (filp || (flags & MAP_SHARED))
10452 do_color_align = 1;
10453
10454+#ifdef CONFIG_PAX_RANDMMAP
10455+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10456+#endif
10457+
10458 /* requesting a specific address */
10459 if (addr) {
10460 if (do_color_align)
10461@@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10462 addr = PAGE_ALIGN(addr);
10463
10464 vma = find_vma(mm, addr);
10465- if (task_size - len >= addr &&
10466- (!vma || addr + len <= vma->vm_start))
10467+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10468 return addr;
10469 }
10470
10471@@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10472 info.high_limit = mm->mmap_base;
10473 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10474 info.align_offset = pgoff << PAGE_SHIFT;
10475+ info.threadstack_offset = offset;
10476 addr = vm_unmapped_area(&info);
10477
10478 /*
10479@@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10480 VM_BUG_ON(addr != -ENOMEM);
10481 info.flags = 0;
10482 info.low_limit = TASK_UNMAPPED_BASE;
10483+
10484+#ifdef CONFIG_PAX_RANDMMAP
10485+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10486+ info.low_limit += mm->delta_mmap;
10487+#endif
10488+
10489 info.high_limit = STACK_TOP32;
10490 addr = vm_unmapped_area(&info);
10491 }
10492@@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10493 EXPORT_SYMBOL(get_fb_unmapped_area);
10494
10495 /* Essentially the same as PowerPC. */
10496-static unsigned long mmap_rnd(void)
10497+static unsigned long mmap_rnd(struct mm_struct *mm)
10498 {
10499 unsigned long rnd = 0UL;
10500
10501+#ifdef CONFIG_PAX_RANDMMAP
10502+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10503+#endif
10504+
10505 if (current->flags & PF_RANDOMIZE) {
10506 unsigned long val = get_random_int();
10507 if (test_thread_flag(TIF_32BIT))
10508@@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10509
10510 void arch_pick_mmap_layout(struct mm_struct *mm)
10511 {
10512- unsigned long random_factor = mmap_rnd();
10513+ unsigned long random_factor = mmap_rnd(mm);
10514 unsigned long gap;
10515
10516 /*
10517@@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10518 gap == RLIM_INFINITY ||
10519 sysctl_legacy_va_layout) {
10520 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10521+
10522+#ifdef CONFIG_PAX_RANDMMAP
10523+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10524+ mm->mmap_base += mm->delta_mmap;
10525+#endif
10526+
10527 mm->get_unmapped_area = arch_get_unmapped_area;
10528 } else {
10529 /* We know it's 32-bit */
10530@@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10531 gap = (task_size / 6 * 5);
10532
10533 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10534+
10535+#ifdef CONFIG_PAX_RANDMMAP
10536+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10537+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10538+#endif
10539+
10540 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10541 }
10542 }
10543diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10544index 33a17e7..d87fb1f 100644
10545--- a/arch/sparc/kernel/syscalls.S
10546+++ b/arch/sparc/kernel/syscalls.S
10547@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10548 #endif
10549 .align 32
10550 1: ldx [%g6 + TI_FLAGS], %l5
10551- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10552+ andcc %l5, _TIF_WORK_SYSCALL, %g0
10553 be,pt %icc, rtrap
10554 nop
10555 call syscall_trace_leave
10556@@ -184,7 +184,7 @@ linux_sparc_syscall32:
10557
10558 srl %i3, 0, %o3 ! IEU0
10559 srl %i2, 0, %o2 ! IEU0 Group
10560- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10561+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10562 bne,pn %icc, linux_syscall_trace32 ! CTI
10563 mov %i0, %l5 ! IEU1
10564 5: call %l7 ! CTI Group brk forced
10565@@ -208,7 +208,7 @@ linux_sparc_syscall:
10566
10567 mov %i3, %o3 ! IEU1
10568 mov %i4, %o4 ! IEU0 Group
10569- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10570+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10571 bne,pn %icc, linux_syscall_trace ! CTI Group
10572 mov %i0, %l5 ! IEU0
10573 2: call %l7 ! CTI Group brk forced
10574@@ -223,7 +223,7 @@ ret_sys_call:
10575
10576 cmp %o0, -ERESTART_RESTARTBLOCK
10577 bgeu,pn %xcc, 1f
10578- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10579+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10580 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10581
10582 2:
10583diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10584index 6629829..036032d 100644
10585--- a/arch/sparc/kernel/traps_32.c
10586+++ b/arch/sparc/kernel/traps_32.c
10587@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10588 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10589 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10590
10591+extern void gr_handle_kernel_exploit(void);
10592+
10593 void die_if_kernel(char *str, struct pt_regs *regs)
10594 {
10595 static int die_counter;
10596@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10597 count++ < 30 &&
10598 (((unsigned long) rw) >= PAGE_OFFSET) &&
10599 !(((unsigned long) rw) & 0x7)) {
10600- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10601+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10602 (void *) rw->ins[7]);
10603 rw = (struct reg_window32 *)rw->ins[6];
10604 }
10605 }
10606 printk("Instruction DUMP:");
10607 instruction_dump ((unsigned long *) regs->pc);
10608- if(regs->psr & PSR_PS)
10609+ if(regs->psr & PSR_PS) {
10610+ gr_handle_kernel_exploit();
10611 do_exit(SIGKILL);
10612+ }
10613 do_exit(SIGSEGV);
10614 }
10615
10616diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10617index 4ced92f..965eeed 100644
10618--- a/arch/sparc/kernel/traps_64.c
10619+++ b/arch/sparc/kernel/traps_64.c
10620@@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10621 i + 1,
10622 p->trapstack[i].tstate, p->trapstack[i].tpc,
10623 p->trapstack[i].tnpc, p->trapstack[i].tt);
10624- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10625+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10626 }
10627 }
10628
10629@@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10630
10631 lvl -= 0x100;
10632 if (regs->tstate & TSTATE_PRIV) {
10633+
10634+#ifdef CONFIG_PAX_REFCOUNT
10635+ if (lvl == 6)
10636+ pax_report_refcount_overflow(regs);
10637+#endif
10638+
10639 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10640 die_if_kernel(buffer, regs);
10641 }
10642@@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10643 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10644 {
10645 char buffer[32];
10646-
10647+
10648 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10649 0, lvl, SIGTRAP) == NOTIFY_STOP)
10650 return;
10651
10652+#ifdef CONFIG_PAX_REFCOUNT
10653+ if (lvl == 6)
10654+ pax_report_refcount_overflow(regs);
10655+#endif
10656+
10657 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10658
10659 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10660@@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10661 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10662 printk("%s" "ERROR(%d): ",
10663 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10664- printk("TPC<%pS>\n", (void *) regs->tpc);
10665+ printk("TPC<%pA>\n", (void *) regs->tpc);
10666 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10667 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10668 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10669@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10670 smp_processor_id(),
10671 (type & 0x1) ? 'I' : 'D',
10672 regs->tpc);
10673- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10674+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10675 panic("Irrecoverable Cheetah+ parity error.");
10676 }
10677
10678@@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10679 smp_processor_id(),
10680 (type & 0x1) ? 'I' : 'D',
10681 regs->tpc);
10682- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10683+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10684 }
10685
10686 struct sun4v_error_entry {
10687@@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10688 /*0x38*/u64 reserved_5;
10689 };
10690
10691-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10692-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10693+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10694+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10695
10696 static const char *sun4v_err_type_to_str(u8 type)
10697 {
10698@@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10699 }
10700
10701 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10702- int cpu, const char *pfx, atomic_t *ocnt)
10703+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10704 {
10705 u64 *raw_ptr = (u64 *) ent;
10706 u32 attrs;
10707@@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10708
10709 show_regs(regs);
10710
10711- if ((cnt = atomic_read(ocnt)) != 0) {
10712- atomic_set(ocnt, 0);
10713+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10714+ atomic_set_unchecked(ocnt, 0);
10715 wmb();
10716 printk("%s: Queue overflowed %d times.\n",
10717 pfx, cnt);
10718@@ -2046,7 +2057,7 @@ out:
10719 */
10720 void sun4v_resum_overflow(struct pt_regs *regs)
10721 {
10722- atomic_inc(&sun4v_resum_oflow_cnt);
10723+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10724 }
10725
10726 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10727@@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10728 /* XXX Actually even this can make not that much sense. Perhaps
10729 * XXX we should just pull the plug and panic directly from here?
10730 */
10731- atomic_inc(&sun4v_nonresum_oflow_cnt);
10732+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10733 }
10734
10735 unsigned long sun4v_err_itlb_vaddr;
10736@@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10737
10738 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10739 regs->tpc, tl);
10740- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10741+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10742 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10743- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10744+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10745 (void *) regs->u_regs[UREG_I7]);
10746 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10747 "pte[%lx] error[%lx]\n",
10748@@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10749
10750 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10751 regs->tpc, tl);
10752- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10753+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10754 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10755- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10756+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10757 (void *) regs->u_regs[UREG_I7]);
10758 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10759 "pte[%lx] error[%lx]\n",
10760@@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10761 fp = (unsigned long)sf->fp + STACK_BIAS;
10762 }
10763
10764- printk(" [%016lx] %pS\n", pc, (void *) pc);
10765+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10766 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10767 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10768 int index = tsk->curr_ret_stack;
10769 if (tsk->ret_stack && index >= graph) {
10770 pc = tsk->ret_stack[index - graph].ret;
10771- printk(" [%016lx] %pS\n", pc, (void *) pc);
10772+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10773 graph++;
10774 }
10775 }
10776@@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10777 return (struct reg_window *) (fp + STACK_BIAS);
10778 }
10779
10780+extern void gr_handle_kernel_exploit(void);
10781+
10782 void die_if_kernel(char *str, struct pt_regs *regs)
10783 {
10784 static int die_counter;
10785@@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10786 while (rw &&
10787 count++ < 30 &&
10788 kstack_valid(tp, (unsigned long) rw)) {
10789- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10790+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10791 (void *) rw->ins[7]);
10792
10793 rw = kernel_stack_up(rw);
10794@@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10795 }
10796 user_instruction_dump ((unsigned int __user *) regs->tpc);
10797 }
10798- if (regs->tstate & TSTATE_PRIV)
10799+ if (regs->tstate & TSTATE_PRIV) {
10800+ gr_handle_kernel_exploit();
10801 do_exit(SIGKILL);
10802+ }
10803 do_exit(SIGSEGV);
10804 }
10805 EXPORT_SYMBOL(die_if_kernel);
10806diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10807index 35ab8b6..9046547 100644
10808--- a/arch/sparc/kernel/unaligned_64.c
10809+++ b/arch/sparc/kernel/unaligned_64.c
10810@@ -295,7 +295,7 @@ static void log_unaligned(struct pt_regs *regs)
10811 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10812
10813 if (__ratelimit(&ratelimit)) {
10814- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10815+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10816 regs->tpc, (void *) regs->tpc);
10817 }
10818 }
10819diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10820index dbe119b..089c7c1 100644
10821--- a/arch/sparc/lib/Makefile
10822+++ b/arch/sparc/lib/Makefile
10823@@ -2,7 +2,7 @@
10824 #
10825
10826 asflags-y := -ansi -DST_DIV0=0x02
10827-ccflags-y := -Werror
10828+#ccflags-y := -Werror
10829
10830 lib-$(CONFIG_SPARC32) += ashrdi3.o
10831 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10832diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10833index 85c233d..68500e0 100644
10834--- a/arch/sparc/lib/atomic_64.S
10835+++ b/arch/sparc/lib/atomic_64.S
10836@@ -17,7 +17,12 @@
10837 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10838 BACKOFF_SETUP(%o2)
10839 1: lduw [%o1], %g1
10840- add %g1, %o0, %g7
10841+ addcc %g1, %o0, %g7
10842+
10843+#ifdef CONFIG_PAX_REFCOUNT
10844+ tvs %icc, 6
10845+#endif
10846+
10847 cas [%o1], %g1, %g7
10848 cmp %g1, %g7
10849 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10850@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10851 2: BACKOFF_SPIN(%o2, %o3, 1b)
10852 ENDPROC(atomic_add)
10853
10854+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10855+ BACKOFF_SETUP(%o2)
10856+1: lduw [%o1], %g1
10857+ add %g1, %o0, %g7
10858+ cas [%o1], %g1, %g7
10859+ cmp %g1, %g7
10860+ bne,pn %icc, 2f
10861+ nop
10862+ retl
10863+ nop
10864+2: BACKOFF_SPIN(%o2, %o3, 1b)
10865+ENDPROC(atomic_add_unchecked)
10866+
10867 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10868 BACKOFF_SETUP(%o2)
10869 1: lduw [%o1], %g1
10870- sub %g1, %o0, %g7
10871+ subcc %g1, %o0, %g7
10872+
10873+#ifdef CONFIG_PAX_REFCOUNT
10874+ tvs %icc, 6
10875+#endif
10876+
10877 cas [%o1], %g1, %g7
10878 cmp %g1, %g7
10879 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10880@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10881 2: BACKOFF_SPIN(%o2, %o3, 1b)
10882 ENDPROC(atomic_sub)
10883
10884+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10885+ BACKOFF_SETUP(%o2)
10886+1: lduw [%o1], %g1
10887+ sub %g1, %o0, %g7
10888+ cas [%o1], %g1, %g7
10889+ cmp %g1, %g7
10890+ bne,pn %icc, 2f
10891+ nop
10892+ retl
10893+ nop
10894+2: BACKOFF_SPIN(%o2, %o3, 1b)
10895+ENDPROC(atomic_sub_unchecked)
10896+
10897 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10898 BACKOFF_SETUP(%o2)
10899 1: lduw [%o1], %g1
10900- add %g1, %o0, %g7
10901+ addcc %g1, %o0, %g7
10902+
10903+#ifdef CONFIG_PAX_REFCOUNT
10904+ tvs %icc, 6
10905+#endif
10906+
10907 cas [%o1], %g1, %g7
10908 cmp %g1, %g7
10909 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10910@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10911 2: BACKOFF_SPIN(%o2, %o3, 1b)
10912 ENDPROC(atomic_add_ret)
10913
10914+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10915+ BACKOFF_SETUP(%o2)
10916+1: lduw [%o1], %g1
10917+ addcc %g1, %o0, %g7
10918+ cas [%o1], %g1, %g7
10919+ cmp %g1, %g7
10920+ bne,pn %icc, 2f
10921+ add %g7, %o0, %g7
10922+ sra %g7, 0, %o0
10923+ retl
10924+ nop
10925+2: BACKOFF_SPIN(%o2, %o3, 1b)
10926+ENDPROC(atomic_add_ret_unchecked)
10927+
10928 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10929 BACKOFF_SETUP(%o2)
10930 1: lduw [%o1], %g1
10931- sub %g1, %o0, %g7
10932+ subcc %g1, %o0, %g7
10933+
10934+#ifdef CONFIG_PAX_REFCOUNT
10935+ tvs %icc, 6
10936+#endif
10937+
10938 cas [%o1], %g1, %g7
10939 cmp %g1, %g7
10940 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10941@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10942 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10943 BACKOFF_SETUP(%o2)
10944 1: ldx [%o1], %g1
10945- add %g1, %o0, %g7
10946+ addcc %g1, %o0, %g7
10947+
10948+#ifdef CONFIG_PAX_REFCOUNT
10949+ tvs %xcc, 6
10950+#endif
10951+
10952 casx [%o1], %g1, %g7
10953 cmp %g1, %g7
10954 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10955@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10956 2: BACKOFF_SPIN(%o2, %o3, 1b)
10957 ENDPROC(atomic64_add)
10958
10959+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10960+ BACKOFF_SETUP(%o2)
10961+1: ldx [%o1], %g1
10962+ addcc %g1, %o0, %g7
10963+ casx [%o1], %g1, %g7
10964+ cmp %g1, %g7
10965+ bne,pn %xcc, 2f
10966+ nop
10967+ retl
10968+ nop
10969+2: BACKOFF_SPIN(%o2, %o3, 1b)
10970+ENDPROC(atomic64_add_unchecked)
10971+
10972 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10973 BACKOFF_SETUP(%o2)
10974 1: ldx [%o1], %g1
10975- sub %g1, %o0, %g7
10976+ subcc %g1, %o0, %g7
10977+
10978+#ifdef CONFIG_PAX_REFCOUNT
10979+ tvs %xcc, 6
10980+#endif
10981+
10982 casx [%o1], %g1, %g7
10983 cmp %g1, %g7
10984 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10985@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10986 2: BACKOFF_SPIN(%o2, %o3, 1b)
10987 ENDPROC(atomic64_sub)
10988
10989+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10990+ BACKOFF_SETUP(%o2)
10991+1: ldx [%o1], %g1
10992+ subcc %g1, %o0, %g7
10993+ casx [%o1], %g1, %g7
10994+ cmp %g1, %g7
10995+ bne,pn %xcc, 2f
10996+ nop
10997+ retl
10998+ nop
10999+2: BACKOFF_SPIN(%o2, %o3, 1b)
11000+ENDPROC(atomic64_sub_unchecked)
11001+
11002 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11003 BACKOFF_SETUP(%o2)
11004 1: ldx [%o1], %g1
11005- add %g1, %o0, %g7
11006+ addcc %g1, %o0, %g7
11007+
11008+#ifdef CONFIG_PAX_REFCOUNT
11009+ tvs %xcc, 6
11010+#endif
11011+
11012 casx [%o1], %g1, %g7
11013 cmp %g1, %g7
11014 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11015@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11016 2: BACKOFF_SPIN(%o2, %o3, 1b)
11017 ENDPROC(atomic64_add_ret)
11018
11019+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11020+ BACKOFF_SETUP(%o2)
11021+1: ldx [%o1], %g1
11022+ addcc %g1, %o0, %g7
11023+ casx [%o1], %g1, %g7
11024+ cmp %g1, %g7
11025+ bne,pn %xcc, 2f
11026+ add %g7, %o0, %g7
11027+ mov %g7, %o0
11028+ retl
11029+ nop
11030+2: BACKOFF_SPIN(%o2, %o3, 1b)
11031+ENDPROC(atomic64_add_ret_unchecked)
11032+
11033 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11034 BACKOFF_SETUP(%o2)
11035 1: ldx [%o1], %g1
11036- sub %g1, %o0, %g7
11037+ subcc %g1, %o0, %g7
11038+
11039+#ifdef CONFIG_PAX_REFCOUNT
11040+ tvs %xcc, 6
11041+#endif
11042+
11043 casx [%o1], %g1, %g7
11044 cmp %g1, %g7
11045 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11046diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11047index 323335b..ed85ea2 100644
11048--- a/arch/sparc/lib/ksyms.c
11049+++ b/arch/sparc/lib/ksyms.c
11050@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11051
11052 /* Atomic counter implementation. */
11053 EXPORT_SYMBOL(atomic_add);
11054+EXPORT_SYMBOL(atomic_add_unchecked);
11055 EXPORT_SYMBOL(atomic_add_ret);
11056+EXPORT_SYMBOL(atomic_add_ret_unchecked);
11057 EXPORT_SYMBOL(atomic_sub);
11058+EXPORT_SYMBOL(atomic_sub_unchecked);
11059 EXPORT_SYMBOL(atomic_sub_ret);
11060 EXPORT_SYMBOL(atomic64_add);
11061+EXPORT_SYMBOL(atomic64_add_unchecked);
11062 EXPORT_SYMBOL(atomic64_add_ret);
11063+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11064 EXPORT_SYMBOL(atomic64_sub);
11065+EXPORT_SYMBOL(atomic64_sub_unchecked);
11066 EXPORT_SYMBOL(atomic64_sub_ret);
11067 EXPORT_SYMBOL(atomic64_dec_if_positive);
11068
11069diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11070index 30c3ecc..736f015 100644
11071--- a/arch/sparc/mm/Makefile
11072+++ b/arch/sparc/mm/Makefile
11073@@ -2,7 +2,7 @@
11074 #
11075
11076 asflags-y := -ansi
11077-ccflags-y := -Werror
11078+#ccflags-y := -Werror
11079
11080 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11081 obj-y += fault_$(BITS).o
11082diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11083index 59dbd46..1dd7f5e 100644
11084--- a/arch/sparc/mm/fault_32.c
11085+++ b/arch/sparc/mm/fault_32.c
11086@@ -21,6 +21,9 @@
11087 #include <linux/perf_event.h>
11088 #include <linux/interrupt.h>
11089 #include <linux/kdebug.h>
11090+#include <linux/slab.h>
11091+#include <linux/pagemap.h>
11092+#include <linux/compiler.h>
11093
11094 #include <asm/page.h>
11095 #include <asm/pgtable.h>
11096@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11097 return safe_compute_effective_address(regs, insn);
11098 }
11099
11100+#ifdef CONFIG_PAX_PAGEEXEC
11101+#ifdef CONFIG_PAX_DLRESOLVE
11102+static void pax_emuplt_close(struct vm_area_struct *vma)
11103+{
11104+ vma->vm_mm->call_dl_resolve = 0UL;
11105+}
11106+
11107+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11108+{
11109+ unsigned int *kaddr;
11110+
11111+ vmf->page = alloc_page(GFP_HIGHUSER);
11112+ if (!vmf->page)
11113+ return VM_FAULT_OOM;
11114+
11115+ kaddr = kmap(vmf->page);
11116+ memset(kaddr, 0, PAGE_SIZE);
11117+ kaddr[0] = 0x9DE3BFA8U; /* save */
11118+ flush_dcache_page(vmf->page);
11119+ kunmap(vmf->page);
11120+ return VM_FAULT_MAJOR;
11121+}
11122+
11123+static const struct vm_operations_struct pax_vm_ops = {
11124+ .close = pax_emuplt_close,
11125+ .fault = pax_emuplt_fault
11126+};
11127+
11128+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11129+{
11130+ int ret;
11131+
11132+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11133+ vma->vm_mm = current->mm;
11134+ vma->vm_start = addr;
11135+ vma->vm_end = addr + PAGE_SIZE;
11136+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11137+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11138+ vma->vm_ops = &pax_vm_ops;
11139+
11140+ ret = insert_vm_struct(current->mm, vma);
11141+ if (ret)
11142+ return ret;
11143+
11144+ ++current->mm->total_vm;
11145+ return 0;
11146+}
11147+#endif
11148+
11149+/*
11150+ * PaX: decide what to do with offenders (regs->pc = fault address)
11151+ *
11152+ * returns 1 when task should be killed
11153+ * 2 when patched PLT trampoline was detected
11154+ * 3 when unpatched PLT trampoline was detected
11155+ */
11156+static int pax_handle_fetch_fault(struct pt_regs *regs)
11157+{
11158+
11159+#ifdef CONFIG_PAX_EMUPLT
11160+ int err;
11161+
11162+ do { /* PaX: patched PLT emulation #1 */
11163+ unsigned int sethi1, sethi2, jmpl;
11164+
11165+ err = get_user(sethi1, (unsigned int *)regs->pc);
11166+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11167+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11168+
11169+ if (err)
11170+ break;
11171+
11172+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11173+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11174+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11175+ {
11176+ unsigned int addr;
11177+
11178+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11179+ addr = regs->u_regs[UREG_G1];
11180+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11181+ regs->pc = addr;
11182+ regs->npc = addr+4;
11183+ return 2;
11184+ }
11185+ } while (0);
11186+
11187+ do { /* PaX: patched PLT emulation #2 */
11188+ unsigned int ba;
11189+
11190+ err = get_user(ba, (unsigned int *)regs->pc);
11191+
11192+ if (err)
11193+ break;
11194+
11195+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11196+ unsigned int addr;
11197+
11198+ if ((ba & 0xFFC00000U) == 0x30800000U)
11199+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11200+ else
11201+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11202+ regs->pc = addr;
11203+ regs->npc = addr+4;
11204+ return 2;
11205+ }
11206+ } while (0);
11207+
11208+ do { /* PaX: patched PLT emulation #3 */
11209+ unsigned int sethi, bajmpl, nop;
11210+
11211+ err = get_user(sethi, (unsigned int *)regs->pc);
11212+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11213+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11214+
11215+ if (err)
11216+ break;
11217+
11218+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11219+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11220+ nop == 0x01000000U)
11221+ {
11222+ unsigned int addr;
11223+
11224+ addr = (sethi & 0x003FFFFFU) << 10;
11225+ regs->u_regs[UREG_G1] = addr;
11226+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11227+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11228+ else
11229+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11230+ regs->pc = addr;
11231+ regs->npc = addr+4;
11232+ return 2;
11233+ }
11234+ } while (0);
11235+
11236+ do { /* PaX: unpatched PLT emulation step 1 */
11237+ unsigned int sethi, ba, nop;
11238+
11239+ err = get_user(sethi, (unsigned int *)regs->pc);
11240+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11241+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11242+
11243+ if (err)
11244+ break;
11245+
11246+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11247+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11248+ nop == 0x01000000U)
11249+ {
11250+ unsigned int addr, save, call;
11251+
11252+ if ((ba & 0xFFC00000U) == 0x30800000U)
11253+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11254+ else
11255+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11256+
11257+ err = get_user(save, (unsigned int *)addr);
11258+ err |= get_user(call, (unsigned int *)(addr+4));
11259+ err |= get_user(nop, (unsigned int *)(addr+8));
11260+ if (err)
11261+ break;
11262+
11263+#ifdef CONFIG_PAX_DLRESOLVE
11264+ if (save == 0x9DE3BFA8U &&
11265+ (call & 0xC0000000U) == 0x40000000U &&
11266+ nop == 0x01000000U)
11267+ {
11268+ struct vm_area_struct *vma;
11269+ unsigned long call_dl_resolve;
11270+
11271+ down_read(&current->mm->mmap_sem);
11272+ call_dl_resolve = current->mm->call_dl_resolve;
11273+ up_read(&current->mm->mmap_sem);
11274+ if (likely(call_dl_resolve))
11275+ goto emulate;
11276+
11277+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11278+
11279+ down_write(&current->mm->mmap_sem);
11280+ if (current->mm->call_dl_resolve) {
11281+ call_dl_resolve = current->mm->call_dl_resolve;
11282+ up_write(&current->mm->mmap_sem);
11283+ if (vma)
11284+ kmem_cache_free(vm_area_cachep, vma);
11285+ goto emulate;
11286+ }
11287+
11288+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11289+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11290+ up_write(&current->mm->mmap_sem);
11291+ if (vma)
11292+ kmem_cache_free(vm_area_cachep, vma);
11293+ return 1;
11294+ }
11295+
11296+ if (pax_insert_vma(vma, call_dl_resolve)) {
11297+ up_write(&current->mm->mmap_sem);
11298+ kmem_cache_free(vm_area_cachep, vma);
11299+ return 1;
11300+ }
11301+
11302+ current->mm->call_dl_resolve = call_dl_resolve;
11303+ up_write(&current->mm->mmap_sem);
11304+
11305+emulate:
11306+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11307+ regs->pc = call_dl_resolve;
11308+ regs->npc = addr+4;
11309+ return 3;
11310+ }
11311+#endif
11312+
11313+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11314+ if ((save & 0xFFC00000U) == 0x05000000U &&
11315+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11316+ nop == 0x01000000U)
11317+ {
11318+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11319+ regs->u_regs[UREG_G2] = addr + 4;
11320+ addr = (save & 0x003FFFFFU) << 10;
11321+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11322+ regs->pc = addr;
11323+ regs->npc = addr+4;
11324+ return 3;
11325+ }
11326+ }
11327+ } while (0);
11328+
11329+ do { /* PaX: unpatched PLT emulation step 2 */
11330+ unsigned int save, call, nop;
11331+
11332+ err = get_user(save, (unsigned int *)(regs->pc-4));
11333+ err |= get_user(call, (unsigned int *)regs->pc);
11334+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11335+ if (err)
11336+ break;
11337+
11338+ if (save == 0x9DE3BFA8U &&
11339+ (call & 0xC0000000U) == 0x40000000U &&
11340+ nop == 0x01000000U)
11341+ {
11342+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11343+
11344+ regs->u_regs[UREG_RETPC] = regs->pc;
11345+ regs->pc = dl_resolve;
11346+ regs->npc = dl_resolve+4;
11347+ return 3;
11348+ }
11349+ } while (0);
11350+#endif
11351+
11352+ return 1;
11353+}
11354+
11355+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11356+{
11357+ unsigned long i;
11358+
11359+ printk(KERN_ERR "PAX: bytes at PC: ");
11360+ for (i = 0; i < 8; i++) {
11361+ unsigned int c;
11362+ if (get_user(c, (unsigned int *)pc+i))
11363+ printk(KERN_CONT "???????? ");
11364+ else
11365+ printk(KERN_CONT "%08x ", c);
11366+ }
11367+ printk("\n");
11368+}
11369+#endif
11370+
11371 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11372 int text_fault)
11373 {
11374@@ -229,6 +503,24 @@ good_area:
11375 if (!(vma->vm_flags & VM_WRITE))
11376 goto bad_area;
11377 } else {
11378+
11379+#ifdef CONFIG_PAX_PAGEEXEC
11380+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11381+ up_read(&mm->mmap_sem);
11382+ switch (pax_handle_fetch_fault(regs)) {
11383+
11384+#ifdef CONFIG_PAX_EMUPLT
11385+ case 2:
11386+ case 3:
11387+ return;
11388+#endif
11389+
11390+ }
11391+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11392+ do_group_exit(SIGKILL);
11393+ }
11394+#endif
11395+
11396 /* Allow reads even for write-only mappings */
11397 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11398 goto bad_area;
11399diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11400index 4ced3fc..234f1e4 100644
11401--- a/arch/sparc/mm/fault_64.c
11402+++ b/arch/sparc/mm/fault_64.c
11403@@ -22,6 +22,9 @@
11404 #include <linux/kdebug.h>
11405 #include <linux/percpu.h>
11406 #include <linux/context_tracking.h>
11407+#include <linux/slab.h>
11408+#include <linux/pagemap.h>
11409+#include <linux/compiler.h>
11410
11411 #include <asm/page.h>
11412 #include <asm/pgtable.h>
11413@@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11414 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11415 regs->tpc);
11416 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11417- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11418+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11419 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11420 dump_stack();
11421 unhandled_fault(regs->tpc, current, regs);
11422@@ -281,6 +284,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11423 show_regs(regs);
11424 }
11425
11426+#ifdef CONFIG_PAX_PAGEEXEC
11427+#ifdef CONFIG_PAX_DLRESOLVE
11428+static void pax_emuplt_close(struct vm_area_struct *vma)
11429+{
11430+ vma->vm_mm->call_dl_resolve = 0UL;
11431+}
11432+
11433+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11434+{
11435+ unsigned int *kaddr;
11436+
11437+ vmf->page = alloc_page(GFP_HIGHUSER);
11438+ if (!vmf->page)
11439+ return VM_FAULT_OOM;
11440+
11441+ kaddr = kmap(vmf->page);
11442+ memset(kaddr, 0, PAGE_SIZE);
11443+ kaddr[0] = 0x9DE3BFA8U; /* save */
11444+ flush_dcache_page(vmf->page);
11445+ kunmap(vmf->page);
11446+ return VM_FAULT_MAJOR;
11447+}
11448+
11449+static const struct vm_operations_struct pax_vm_ops = {
11450+ .close = pax_emuplt_close,
11451+ .fault = pax_emuplt_fault
11452+};
11453+
11454+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11455+{
11456+ int ret;
11457+
11458+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11459+ vma->vm_mm = current->mm;
11460+ vma->vm_start = addr;
11461+ vma->vm_end = addr + PAGE_SIZE;
11462+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11463+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11464+ vma->vm_ops = &pax_vm_ops;
11465+
11466+ ret = insert_vm_struct(current->mm, vma);
11467+ if (ret)
11468+ return ret;
11469+
11470+ ++current->mm->total_vm;
11471+ return 0;
11472+}
11473+#endif
11474+
11475+/*
11476+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11477+ *
11478+ * returns 1 when task should be killed
11479+ * 2 when patched PLT trampoline was detected
11480+ * 3 when unpatched PLT trampoline was detected
11481+ */
11482+static int pax_handle_fetch_fault(struct pt_regs *regs)
11483+{
11484+
11485+#ifdef CONFIG_PAX_EMUPLT
11486+ int err;
11487+
11488+ do { /* PaX: patched PLT emulation #1 */
11489+ unsigned int sethi1, sethi2, jmpl;
11490+
11491+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11492+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11493+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11494+
11495+ if (err)
11496+ break;
11497+
11498+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11499+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11500+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11501+ {
11502+ unsigned long addr;
11503+
11504+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11505+ addr = regs->u_regs[UREG_G1];
11506+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11507+
11508+ if (test_thread_flag(TIF_32BIT))
11509+ addr &= 0xFFFFFFFFUL;
11510+
11511+ regs->tpc = addr;
11512+ regs->tnpc = addr+4;
11513+ return 2;
11514+ }
11515+ } while (0);
11516+
11517+ do { /* PaX: patched PLT emulation #2 */
11518+ unsigned int ba;
11519+
11520+ err = get_user(ba, (unsigned int *)regs->tpc);
11521+
11522+ if (err)
11523+ break;
11524+
11525+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11526+ unsigned long addr;
11527+
11528+ if ((ba & 0xFFC00000U) == 0x30800000U)
11529+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11530+ else
11531+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11532+
11533+ if (test_thread_flag(TIF_32BIT))
11534+ addr &= 0xFFFFFFFFUL;
11535+
11536+ regs->tpc = addr;
11537+ regs->tnpc = addr+4;
11538+ return 2;
11539+ }
11540+ } while (0);
11541+
11542+ do { /* PaX: patched PLT emulation #3 */
11543+ unsigned int sethi, bajmpl, nop;
11544+
11545+ err = get_user(sethi, (unsigned int *)regs->tpc);
11546+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11547+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11548+
11549+ if (err)
11550+ break;
11551+
11552+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11553+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11554+ nop == 0x01000000U)
11555+ {
11556+ unsigned long addr;
11557+
11558+ addr = (sethi & 0x003FFFFFU) << 10;
11559+ regs->u_regs[UREG_G1] = addr;
11560+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11561+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11562+ else
11563+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11564+
11565+ if (test_thread_flag(TIF_32BIT))
11566+ addr &= 0xFFFFFFFFUL;
11567+
11568+ regs->tpc = addr;
11569+ regs->tnpc = addr+4;
11570+ return 2;
11571+ }
11572+ } while (0);
11573+
11574+ do { /* PaX: patched PLT emulation #4 */
11575+ unsigned int sethi, mov1, call, mov2;
11576+
11577+ err = get_user(sethi, (unsigned int *)regs->tpc);
11578+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11579+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11580+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11581+
11582+ if (err)
11583+ break;
11584+
11585+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11586+ mov1 == 0x8210000FU &&
11587+ (call & 0xC0000000U) == 0x40000000U &&
11588+ mov2 == 0x9E100001U)
11589+ {
11590+ unsigned long addr;
11591+
11592+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11593+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11594+
11595+ if (test_thread_flag(TIF_32BIT))
11596+ addr &= 0xFFFFFFFFUL;
11597+
11598+ regs->tpc = addr;
11599+ regs->tnpc = addr+4;
11600+ return 2;
11601+ }
11602+ } while (0);
11603+
11604+ do { /* PaX: patched PLT emulation #5 */
11605+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11606+
11607+ err = get_user(sethi, (unsigned int *)regs->tpc);
11608+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11609+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11610+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11611+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11612+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11613+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11614+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11615+
11616+ if (err)
11617+ break;
11618+
11619+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11620+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11621+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11622+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11623+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11624+ sllx == 0x83287020U &&
11625+ jmpl == 0x81C04005U &&
11626+ nop == 0x01000000U)
11627+ {
11628+ unsigned long addr;
11629+
11630+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11631+ regs->u_regs[UREG_G1] <<= 32;
11632+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11633+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11634+ regs->tpc = addr;
11635+ regs->tnpc = addr+4;
11636+ return 2;
11637+ }
11638+ } while (0);
11639+
11640+ do { /* PaX: patched PLT emulation #6 */
11641+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11642+
11643+ err = get_user(sethi, (unsigned int *)regs->tpc);
11644+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11645+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11646+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11647+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11648+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11649+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11650+
11651+ if (err)
11652+ break;
11653+
11654+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11655+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11656+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11657+ sllx == 0x83287020U &&
11658+ (or & 0xFFFFE000U) == 0x8A116000U &&
11659+ jmpl == 0x81C04005U &&
11660+ nop == 0x01000000U)
11661+ {
11662+ unsigned long addr;
11663+
11664+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11665+ regs->u_regs[UREG_G1] <<= 32;
11666+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11667+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11668+ regs->tpc = addr;
11669+ regs->tnpc = addr+4;
11670+ return 2;
11671+ }
11672+ } while (0);
11673+
11674+ do { /* PaX: unpatched PLT emulation step 1 */
11675+ unsigned int sethi, ba, nop;
11676+
11677+ err = get_user(sethi, (unsigned int *)regs->tpc);
11678+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11679+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11680+
11681+ if (err)
11682+ break;
11683+
11684+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11685+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11686+ nop == 0x01000000U)
11687+ {
11688+ unsigned long addr;
11689+ unsigned int save, call;
11690+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11691+
11692+ if ((ba & 0xFFC00000U) == 0x30800000U)
11693+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11694+ else
11695+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11696+
11697+ if (test_thread_flag(TIF_32BIT))
11698+ addr &= 0xFFFFFFFFUL;
11699+
11700+ err = get_user(save, (unsigned int *)addr);
11701+ err |= get_user(call, (unsigned int *)(addr+4));
11702+ err |= get_user(nop, (unsigned int *)(addr+8));
11703+ if (err)
11704+ break;
11705+
11706+#ifdef CONFIG_PAX_DLRESOLVE
11707+ if (save == 0x9DE3BFA8U &&
11708+ (call & 0xC0000000U) == 0x40000000U &&
11709+ nop == 0x01000000U)
11710+ {
11711+ struct vm_area_struct *vma;
11712+ unsigned long call_dl_resolve;
11713+
11714+ down_read(&current->mm->mmap_sem);
11715+ call_dl_resolve = current->mm->call_dl_resolve;
11716+ up_read(&current->mm->mmap_sem);
11717+ if (likely(call_dl_resolve))
11718+ goto emulate;
11719+
11720+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11721+
11722+ down_write(&current->mm->mmap_sem);
11723+ if (current->mm->call_dl_resolve) {
11724+ call_dl_resolve = current->mm->call_dl_resolve;
11725+ up_write(&current->mm->mmap_sem);
11726+ if (vma)
11727+ kmem_cache_free(vm_area_cachep, vma);
11728+ goto emulate;
11729+ }
11730+
11731+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11732+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11733+ up_write(&current->mm->mmap_sem);
11734+ if (vma)
11735+ kmem_cache_free(vm_area_cachep, vma);
11736+ return 1;
11737+ }
11738+
11739+ if (pax_insert_vma(vma, call_dl_resolve)) {
11740+ up_write(&current->mm->mmap_sem);
11741+ kmem_cache_free(vm_area_cachep, vma);
11742+ return 1;
11743+ }
11744+
11745+ current->mm->call_dl_resolve = call_dl_resolve;
11746+ up_write(&current->mm->mmap_sem);
11747+
11748+emulate:
11749+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11750+ regs->tpc = call_dl_resolve;
11751+ regs->tnpc = addr+4;
11752+ return 3;
11753+ }
11754+#endif
11755+
11756+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11757+ if ((save & 0xFFC00000U) == 0x05000000U &&
11758+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11759+ nop == 0x01000000U)
11760+ {
11761+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11762+ regs->u_regs[UREG_G2] = addr + 4;
11763+ addr = (save & 0x003FFFFFU) << 10;
11764+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11765+
11766+ if (test_thread_flag(TIF_32BIT))
11767+ addr &= 0xFFFFFFFFUL;
11768+
11769+ regs->tpc = addr;
11770+ regs->tnpc = addr+4;
11771+ return 3;
11772+ }
11773+
11774+ /* PaX: 64-bit PLT stub */
11775+ err = get_user(sethi1, (unsigned int *)addr);
11776+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11777+ err |= get_user(or1, (unsigned int *)(addr+8));
11778+ err |= get_user(or2, (unsigned int *)(addr+12));
11779+ err |= get_user(sllx, (unsigned int *)(addr+16));
11780+ err |= get_user(add, (unsigned int *)(addr+20));
11781+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11782+ err |= get_user(nop, (unsigned int *)(addr+28));
11783+ if (err)
11784+ break;
11785+
11786+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11787+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11788+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11789+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11790+ sllx == 0x89293020U &&
11791+ add == 0x8A010005U &&
11792+ jmpl == 0x89C14000U &&
11793+ nop == 0x01000000U)
11794+ {
11795+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11796+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11797+ regs->u_regs[UREG_G4] <<= 32;
11798+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11799+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11800+ regs->u_regs[UREG_G4] = addr + 24;
11801+ addr = regs->u_regs[UREG_G5];
11802+ regs->tpc = addr;
11803+ regs->tnpc = addr+4;
11804+ return 3;
11805+ }
11806+ }
11807+ } while (0);
11808+
11809+#ifdef CONFIG_PAX_DLRESOLVE
11810+ do { /* PaX: unpatched PLT emulation step 2 */
11811+ unsigned int save, call, nop;
11812+
11813+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11814+ err |= get_user(call, (unsigned int *)regs->tpc);
11815+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11816+ if (err)
11817+ break;
11818+
11819+ if (save == 0x9DE3BFA8U &&
11820+ (call & 0xC0000000U) == 0x40000000U &&
11821+ nop == 0x01000000U)
11822+ {
11823+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11824+
11825+ if (test_thread_flag(TIF_32BIT))
11826+ dl_resolve &= 0xFFFFFFFFUL;
11827+
11828+ regs->u_regs[UREG_RETPC] = regs->tpc;
11829+ regs->tpc = dl_resolve;
11830+ regs->tnpc = dl_resolve+4;
11831+ return 3;
11832+ }
11833+ } while (0);
11834+#endif
11835+
11836+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11837+ unsigned int sethi, ba, nop;
11838+
11839+ err = get_user(sethi, (unsigned int *)regs->tpc);
11840+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11841+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11842+
11843+ if (err)
11844+ break;
11845+
11846+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11847+ (ba & 0xFFF00000U) == 0x30600000U &&
11848+ nop == 0x01000000U)
11849+ {
11850+ unsigned long addr;
11851+
11852+ addr = (sethi & 0x003FFFFFU) << 10;
11853+ regs->u_regs[UREG_G1] = addr;
11854+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11855+
11856+ if (test_thread_flag(TIF_32BIT))
11857+ addr &= 0xFFFFFFFFUL;
11858+
11859+ regs->tpc = addr;
11860+ regs->tnpc = addr+4;
11861+ return 2;
11862+ }
11863+ } while (0);
11864+
11865+#endif
11866+
11867+ return 1;
11868+}
11869+
11870+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11871+{
11872+ unsigned long i;
11873+
11874+ printk(KERN_ERR "PAX: bytes at PC: ");
11875+ for (i = 0; i < 8; i++) {
11876+ unsigned int c;
11877+ if (get_user(c, (unsigned int *)pc+i))
11878+ printk(KERN_CONT "???????? ");
11879+ else
11880+ printk(KERN_CONT "%08x ", c);
11881+ }
11882+ printk("\n");
11883+}
11884+#endif
11885+
11886 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11887 {
11888 enum ctx_state prev_state = exception_enter();
11889@@ -352,6 +815,29 @@ retry:
11890 if (!vma)
11891 goto bad_area;
11892
11893+#ifdef CONFIG_PAX_PAGEEXEC
11894+ /* PaX: detect ITLB misses on non-exec pages */
11895+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11896+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11897+ {
11898+ if (address != regs->tpc)
11899+ goto good_area;
11900+
11901+ up_read(&mm->mmap_sem);
11902+ switch (pax_handle_fetch_fault(regs)) {
11903+
11904+#ifdef CONFIG_PAX_EMUPLT
11905+ case 2:
11906+ case 3:
11907+ return;
11908+#endif
11909+
11910+ }
11911+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11912+ do_group_exit(SIGKILL);
11913+ }
11914+#endif
11915+
11916 /* Pure DTLB misses do not tell us whether the fault causing
11917 * load/store/atomic was a write or not, it only says that there
11918 * was no match. So in such a case we (carefully) read the
11919diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11920index 9bd9ce8..dc84852 100644
11921--- a/arch/sparc/mm/hugetlbpage.c
11922+++ b/arch/sparc/mm/hugetlbpage.c
11923@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11924 unsigned long addr,
11925 unsigned long len,
11926 unsigned long pgoff,
11927- unsigned long flags)
11928+ unsigned long flags,
11929+ unsigned long offset)
11930 {
11931+ struct mm_struct *mm = current->mm;
11932 unsigned long task_size = TASK_SIZE;
11933 struct vm_unmapped_area_info info;
11934
11935@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11936
11937 info.flags = 0;
11938 info.length = len;
11939- info.low_limit = TASK_UNMAPPED_BASE;
11940+ info.low_limit = mm->mmap_base;
11941 info.high_limit = min(task_size, VA_EXCLUDE_START);
11942 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11943 info.align_offset = 0;
11944+ info.threadstack_offset = offset;
11945 addr = vm_unmapped_area(&info);
11946
11947 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11948 VM_BUG_ON(addr != -ENOMEM);
11949 info.low_limit = VA_EXCLUDE_END;
11950+
11951+#ifdef CONFIG_PAX_RANDMMAP
11952+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11953+ info.low_limit += mm->delta_mmap;
11954+#endif
11955+
11956 info.high_limit = task_size;
11957 addr = vm_unmapped_area(&info);
11958 }
11959@@ -55,7 +64,8 @@ static unsigned long
11960 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11961 const unsigned long len,
11962 const unsigned long pgoff,
11963- const unsigned long flags)
11964+ const unsigned long flags,
11965+ const unsigned long offset)
11966 {
11967 struct mm_struct *mm = current->mm;
11968 unsigned long addr = addr0;
11969@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11970 info.high_limit = mm->mmap_base;
11971 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11972 info.align_offset = 0;
11973+ info.threadstack_offset = offset;
11974 addr = vm_unmapped_area(&info);
11975
11976 /*
11977@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11978 VM_BUG_ON(addr != -ENOMEM);
11979 info.flags = 0;
11980 info.low_limit = TASK_UNMAPPED_BASE;
11981+
11982+#ifdef CONFIG_PAX_RANDMMAP
11983+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11984+ info.low_limit += mm->delta_mmap;
11985+#endif
11986+
11987 info.high_limit = STACK_TOP32;
11988 addr = vm_unmapped_area(&info);
11989 }
11990@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11991 struct mm_struct *mm = current->mm;
11992 struct vm_area_struct *vma;
11993 unsigned long task_size = TASK_SIZE;
11994+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11995
11996 if (test_thread_flag(TIF_32BIT))
11997 task_size = STACK_TOP32;
11998@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11999 return addr;
12000 }
12001
12002+#ifdef CONFIG_PAX_RANDMMAP
12003+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12004+#endif
12005+
12006 if (addr) {
12007 addr = ALIGN(addr, HPAGE_SIZE);
12008 vma = find_vma(mm, addr);
12009- if (task_size - len >= addr &&
12010- (!vma || addr + len <= vma->vm_start))
12011+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12012 return addr;
12013 }
12014 if (mm->get_unmapped_area == arch_get_unmapped_area)
12015 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12016- pgoff, flags);
12017+ pgoff, flags, offset);
12018 else
12019 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12020- pgoff, flags);
12021+ pgoff, flags, offset);
12022 }
12023
12024 pte_t *huge_pte_alloc(struct mm_struct *mm,
12025diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12026index ed3c969..42fe48d 100644
12027--- a/arch/sparc/mm/init_64.c
12028+++ b/arch/sparc/mm/init_64.c
12029@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12030 int num_kernel_image_mappings;
12031
12032 #ifdef CONFIG_DEBUG_DCFLUSH
12033-atomic_t dcpage_flushes = ATOMIC_INIT(0);
12034+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12035 #ifdef CONFIG_SMP
12036-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12037+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12038 #endif
12039 #endif
12040
12041@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
12042 {
12043 BUG_ON(tlb_type == hypervisor);
12044 #ifdef CONFIG_DEBUG_DCFLUSH
12045- atomic_inc(&dcpage_flushes);
12046+ atomic_inc_unchecked(&dcpage_flushes);
12047 #endif
12048
12049 #ifdef DCACHE_ALIASING_POSSIBLE
12050@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
12051
12052 #ifdef CONFIG_DEBUG_DCFLUSH
12053 seq_printf(m, "DCPageFlushes\t: %d\n",
12054- atomic_read(&dcpage_flushes));
12055+ atomic_read_unchecked(&dcpage_flushes));
12056 #ifdef CONFIG_SMP
12057 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12058- atomic_read(&dcpage_flushes_xcall));
12059+ atomic_read_unchecked(&dcpage_flushes_xcall));
12060 #endif /* CONFIG_SMP */
12061 #endif /* CONFIG_DEBUG_DCFLUSH */
12062 }
12063diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12064index 85258ca..df97c79 100644
12065--- a/arch/tile/Kconfig
12066+++ b/arch/tile/Kconfig
12067@@ -190,6 +190,7 @@ source "kernel/Kconfig.hz"
12068
12069 config KEXEC
12070 bool "kexec system call"
12071+ depends on !GRKERNSEC_KMEM
12072 ---help---
12073 kexec is a system call that implements the ability to shutdown your
12074 current kernel, and to start another kernel. It is like a reboot
12075diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12076index ad220ee..2f537b3 100644
12077--- a/arch/tile/include/asm/atomic_64.h
12078+++ b/arch/tile/include/asm/atomic_64.h
12079@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12080
12081 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12082
12083+#define atomic64_read_unchecked(v) atomic64_read(v)
12084+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12085+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12086+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12087+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12088+#define atomic64_inc_unchecked(v) atomic64_inc(v)
12089+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12090+#define atomic64_dec_unchecked(v) atomic64_dec(v)
12091+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12092+
12093 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
12094 #define smp_mb__before_atomic_dec() smp_mb()
12095 #define smp_mb__after_atomic_dec() smp_mb()
12096diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12097index 6160761..00cac88 100644
12098--- a/arch/tile/include/asm/cache.h
12099+++ b/arch/tile/include/asm/cache.h
12100@@ -15,11 +15,12 @@
12101 #ifndef _ASM_TILE_CACHE_H
12102 #define _ASM_TILE_CACHE_H
12103
12104+#include <linux/const.h>
12105 #include <arch/chip.h>
12106
12107 /* bytes per L1 data cache line */
12108 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12109-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12110+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12111
12112 /* bytes per L2 cache line */
12113 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12114diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12115index b6cde32..c0cb736 100644
12116--- a/arch/tile/include/asm/uaccess.h
12117+++ b/arch/tile/include/asm/uaccess.h
12118@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12119 const void __user *from,
12120 unsigned long n)
12121 {
12122- int sz = __compiletime_object_size(to);
12123+ size_t sz = __compiletime_object_size(to);
12124
12125- if (likely(sz == -1 || sz >= n))
12126+ if (likely(sz == (size_t)-1 || sz >= n))
12127 n = _copy_from_user(to, from, n);
12128 else
12129 copy_from_user_overflow();
12130diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12131index 0cb3bba..7338b2d 100644
12132--- a/arch/tile/mm/hugetlbpage.c
12133+++ b/arch/tile/mm/hugetlbpage.c
12134@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12135 info.high_limit = TASK_SIZE;
12136 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12137 info.align_offset = 0;
12138+ info.threadstack_offset = 0;
12139 return vm_unmapped_area(&info);
12140 }
12141
12142@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12143 info.high_limit = current->mm->mmap_base;
12144 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12145 info.align_offset = 0;
12146+ info.threadstack_offset = 0;
12147 addr = vm_unmapped_area(&info);
12148
12149 /*
12150diff --git a/arch/um/Makefile b/arch/um/Makefile
12151index 36e658a..71a5c5a 100644
12152--- a/arch/um/Makefile
12153+++ b/arch/um/Makefile
12154@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12155 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12156 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12157
12158+ifdef CONSTIFY_PLUGIN
12159+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12160+endif
12161+
12162 #This will adjust *FLAGS accordingly to the platform.
12163 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12164
12165diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12166index 19e1bdd..3665b77 100644
12167--- a/arch/um/include/asm/cache.h
12168+++ b/arch/um/include/asm/cache.h
12169@@ -1,6 +1,7 @@
12170 #ifndef __UM_CACHE_H
12171 #define __UM_CACHE_H
12172
12173+#include <linux/const.h>
12174
12175 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12176 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12177@@ -12,6 +13,6 @@
12178 # define L1_CACHE_SHIFT 5
12179 #endif
12180
12181-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12182+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12183
12184 #endif
12185diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12186index 2e0a6b1..a64d0f5 100644
12187--- a/arch/um/include/asm/kmap_types.h
12188+++ b/arch/um/include/asm/kmap_types.h
12189@@ -8,6 +8,6 @@
12190
12191 /* No more #include "asm/arch/kmap_types.h" ! */
12192
12193-#define KM_TYPE_NR 14
12194+#define KM_TYPE_NR 15
12195
12196 #endif
12197diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12198index 5ff53d9..5850cdf 100644
12199--- a/arch/um/include/asm/page.h
12200+++ b/arch/um/include/asm/page.h
12201@@ -14,6 +14,9 @@
12202 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12203 #define PAGE_MASK (~(PAGE_SIZE-1))
12204
12205+#define ktla_ktva(addr) (addr)
12206+#define ktva_ktla(addr) (addr)
12207+
12208 #ifndef __ASSEMBLY__
12209
12210 struct page;
12211diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12212index 0032f92..cd151e0 100644
12213--- a/arch/um/include/asm/pgtable-3level.h
12214+++ b/arch/um/include/asm/pgtable-3level.h
12215@@ -58,6 +58,7 @@
12216 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12217 #define pud_populate(mm, pud, pmd) \
12218 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12219+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12220
12221 #ifdef CONFIG_64BIT
12222 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12223diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12224index f17bca8..48adb87 100644
12225--- a/arch/um/kernel/process.c
12226+++ b/arch/um/kernel/process.c
12227@@ -356,22 +356,6 @@ int singlestepping(void * t)
12228 return 2;
12229 }
12230
12231-/*
12232- * Only x86 and x86_64 have an arch_align_stack().
12233- * All other arches have "#define arch_align_stack(x) (x)"
12234- * in their asm/exec.h
12235- * As this is included in UML from asm-um/system-generic.h,
12236- * we can use it to behave as the subarch does.
12237- */
12238-#ifndef arch_align_stack
12239-unsigned long arch_align_stack(unsigned long sp)
12240-{
12241- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12242- sp -= get_random_int() % 8192;
12243- return sp & ~0xf;
12244-}
12245-#endif
12246-
12247 unsigned long get_wchan(struct task_struct *p)
12248 {
12249 unsigned long stack_page, sp, ip;
12250diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12251index ad8f795..2c7eec6 100644
12252--- a/arch/unicore32/include/asm/cache.h
12253+++ b/arch/unicore32/include/asm/cache.h
12254@@ -12,8 +12,10 @@
12255 #ifndef __UNICORE_CACHE_H__
12256 #define __UNICORE_CACHE_H__
12257
12258-#define L1_CACHE_SHIFT (5)
12259-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12260+#include <linux/const.h>
12261+
12262+#define L1_CACHE_SHIFT 5
12263+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12264
12265 /*
12266 * Memory returned by kmalloc() may be used for DMA, so we must make
12267diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12268index 25d2c6f..f280b3a 100644
12269--- a/arch/x86/Kconfig
12270+++ b/arch/x86/Kconfig
12271@@ -127,7 +127,7 @@ config X86
12272 select RTC_LIB
12273 select HAVE_DEBUG_STACKOVERFLOW
12274 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12275- select HAVE_CC_STACKPROTECTOR
12276+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12277 select GENERIC_CPU_AUTOPROBE
12278 select HAVE_ARCH_AUDITSYSCALL
12279
12280@@ -251,7 +251,7 @@ config X86_HT
12281
12282 config X86_32_LAZY_GS
12283 def_bool y
12284- depends on X86_32 && !CC_STACKPROTECTOR
12285+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12286
12287 config ARCH_HWEIGHT_CFLAGS
12288 string
12289@@ -545,6 +545,7 @@ config SCHED_OMIT_FRAME_POINTER
12290
12291 menuconfig HYPERVISOR_GUEST
12292 bool "Linux guest support"
12293+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12294 ---help---
12295 Say Y here to enable options for running Linux under various hyper-
12296 visors. This option enables basic hypervisor detection and platform
12297@@ -1054,6 +1055,7 @@ choice
12298
12299 config NOHIGHMEM
12300 bool "off"
12301+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12302 ---help---
12303 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12304 However, the address space of 32-bit x86 processors is only 4
12305@@ -1090,6 +1092,7 @@ config NOHIGHMEM
12306
12307 config HIGHMEM4G
12308 bool "4GB"
12309+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12310 ---help---
12311 Select this if you have a 32-bit processor and between 1 and 4
12312 gigabytes of physical RAM.
12313@@ -1142,7 +1145,7 @@ config PAGE_OFFSET
12314 hex
12315 default 0xB0000000 if VMSPLIT_3G_OPT
12316 default 0x80000000 if VMSPLIT_2G
12317- default 0x78000000 if VMSPLIT_2G_OPT
12318+ default 0x70000000 if VMSPLIT_2G_OPT
12319 default 0x40000000 if VMSPLIT_1G
12320 default 0xC0000000
12321 depends on X86_32
12322@@ -1555,6 +1558,7 @@ source kernel/Kconfig.hz
12323
12324 config KEXEC
12325 bool "kexec system call"
12326+ depends on !GRKERNSEC_KMEM
12327 ---help---
12328 kexec is a system call that implements the ability to shutdown your
12329 current kernel, and to start another kernel. It is like a reboot
12330@@ -1706,7 +1710,9 @@ config X86_NEED_RELOCS
12331
12332 config PHYSICAL_ALIGN
12333 hex "Alignment value to which kernel should be aligned"
12334- default "0x200000"
12335+ default "0x1000000"
12336+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12337+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12338 range 0x2000 0x1000000 if X86_32
12339 range 0x200000 0x1000000 if X86_64
12340 ---help---
12341@@ -1789,6 +1795,7 @@ config COMPAT_VDSO
12342 def_bool n
12343 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12344 depends on X86_32 || IA32_EMULATION
12345+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12346 ---help---
12347 Certain buggy versions of glibc will crash if they are
12348 presented with a 32-bit vDSO that is not mapped at the address
12349diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12350index 6983314..54ad7e8 100644
12351--- a/arch/x86/Kconfig.cpu
12352+++ b/arch/x86/Kconfig.cpu
12353@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12354
12355 config X86_F00F_BUG
12356 def_bool y
12357- depends on M586MMX || M586TSC || M586 || M486
12358+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12359
12360 config X86_INVD_BUG
12361 def_bool y
12362@@ -327,7 +327,7 @@ config X86_INVD_BUG
12363
12364 config X86_ALIGNMENT_16
12365 def_bool y
12366- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12367+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12368
12369 config X86_INTEL_USERCOPY
12370 def_bool y
12371@@ -369,7 +369,7 @@ config X86_CMPXCHG64
12372 # generates cmov.
12373 config X86_CMOV
12374 def_bool y
12375- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12376+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12377
12378 config X86_MINIMUM_CPU_FAMILY
12379 int
12380diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12381index 61bd2ad..50b625d 100644
12382--- a/arch/x86/Kconfig.debug
12383+++ b/arch/x86/Kconfig.debug
12384@@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12385 config DEBUG_RODATA
12386 bool "Write protect kernel read-only data structures"
12387 default y
12388- depends on DEBUG_KERNEL
12389+ depends on DEBUG_KERNEL && BROKEN
12390 ---help---
12391 Mark the kernel read-only data as write-protected in the pagetables,
12392 in order to catch accidental (and incorrect) writes to such const
12393@@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12394
12395 config DEBUG_SET_MODULE_RONX
12396 bool "Set loadable kernel module data as NX and text as RO"
12397- depends on MODULES
12398+ depends on MODULES && BROKEN
12399 ---help---
12400 This option helps catch unintended modifications to loadable
12401 kernel module's text and read-only data. It also prevents execution
12402diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12403index 33f71b0..c2cefa2 100644
12404--- a/arch/x86/Makefile
12405+++ b/arch/x86/Makefile
12406@@ -71,9 +71,6 @@ ifeq ($(CONFIG_X86_32),y)
12407 # CPU-specific tuning. Anything which can be shared with UML should go here.
12408 include $(srctree)/arch/x86/Makefile_32.cpu
12409 KBUILD_CFLAGS += $(cflags-y)
12410-
12411- # temporary until string.h is fixed
12412- KBUILD_CFLAGS += -ffreestanding
12413 else
12414 BITS := 64
12415 UTS_MACHINE := x86_64
12416@@ -114,6 +111,9 @@ else
12417 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12418 endif
12419
12420+# temporary until string.h is fixed
12421+KBUILD_CFLAGS += -ffreestanding
12422+
12423 # Make sure compiler does not have buggy stack-protector support.
12424 ifdef CONFIG_CC_STACKPROTECTOR
12425 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12426@@ -271,3 +271,12 @@ define archhelp
12427 echo ' FDINITRD=file initrd for the booted kernel'
12428 echo ' kvmconfig - Enable additional options for guest kernel support'
12429 endef
12430+
12431+define OLD_LD
12432+
12433+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12434+*** Please upgrade your binutils to 2.18 or newer
12435+endef
12436+
12437+archprepare:
12438+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12439diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12440index dbe8dd2..2f0a98f 100644
12441--- a/arch/x86/boot/Makefile
12442+++ b/arch/x86/boot/Makefile
12443@@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12444 # ---------------------------------------------------------------------------
12445
12446 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12447+ifdef CONSTIFY_PLUGIN
12448+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12449+endif
12450 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12451 GCOV_PROFILE := n
12452
12453diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12454index 878e4b9..20537ab 100644
12455--- a/arch/x86/boot/bitops.h
12456+++ b/arch/x86/boot/bitops.h
12457@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12458 u8 v;
12459 const u32 *p = (const u32 *)addr;
12460
12461- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12462+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12463 return v;
12464 }
12465
12466@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12467
12468 static inline void set_bit(int nr, void *addr)
12469 {
12470- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12471+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12472 }
12473
12474 #endif /* BOOT_BITOPS_H */
12475diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12476index bd49ec6..94c7f58 100644
12477--- a/arch/x86/boot/boot.h
12478+++ b/arch/x86/boot/boot.h
12479@@ -84,7 +84,7 @@ static inline void io_delay(void)
12480 static inline u16 ds(void)
12481 {
12482 u16 seg;
12483- asm("movw %%ds,%0" : "=rm" (seg));
12484+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12485 return seg;
12486 }
12487
12488diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12489index 0fcd913..3bb5c42 100644
12490--- a/arch/x86/boot/compressed/Makefile
12491+++ b/arch/x86/boot/compressed/Makefile
12492@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12493 KBUILD_CFLAGS += -mno-mmx -mno-sse
12494 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12495 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12496+ifdef CONSTIFY_PLUGIN
12497+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12498+endif
12499
12500 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12501 GCOV_PROFILE := n
12502diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12503index a53440e..c3dbf1e 100644
12504--- a/arch/x86/boot/compressed/efi_stub_32.S
12505+++ b/arch/x86/boot/compressed/efi_stub_32.S
12506@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12507 * parameter 2, ..., param n. To make things easy, we save the return
12508 * address of efi_call_phys in a global variable.
12509 */
12510- popl %ecx
12511- movl %ecx, saved_return_addr(%edx)
12512- /* get the function pointer into ECX*/
12513- popl %ecx
12514- movl %ecx, efi_rt_function_ptr(%edx)
12515+ popl saved_return_addr(%edx)
12516+ popl efi_rt_function_ptr(%edx)
12517
12518 /*
12519 * 3. Call the physical function.
12520 */
12521- call *%ecx
12522+ call *efi_rt_function_ptr(%edx)
12523
12524 /*
12525 * 4. Balance the stack. And because EAX contain the return value,
12526@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12527 1: popl %edx
12528 subl $1b, %edx
12529
12530- movl efi_rt_function_ptr(%edx), %ecx
12531- pushl %ecx
12532+ pushl efi_rt_function_ptr(%edx)
12533
12534 /*
12535 * 10. Push the saved return address onto the stack and return.
12536 */
12537- movl saved_return_addr(%edx), %ecx
12538- pushl %ecx
12539- ret
12540+ jmpl *saved_return_addr(%edx)
12541 ENDPROC(efi_call_phys)
12542 .previous
12543
12544diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12545index cbed140..5f2ca57 100644
12546--- a/arch/x86/boot/compressed/head_32.S
12547+++ b/arch/x86/boot/compressed/head_32.S
12548@@ -140,10 +140,10 @@ preferred_addr:
12549 addl %eax, %ebx
12550 notl %eax
12551 andl %eax, %ebx
12552- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12553+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12554 jge 1f
12555 #endif
12556- movl $LOAD_PHYSICAL_ADDR, %ebx
12557+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12558 1:
12559
12560 /* Target address to relocate to for decompression */
12561diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12562index 0d558ee..58f257e 100644
12563--- a/arch/x86/boot/compressed/head_64.S
12564+++ b/arch/x86/boot/compressed/head_64.S
12565@@ -94,10 +94,10 @@ ENTRY(startup_32)
12566 addl %eax, %ebx
12567 notl %eax
12568 andl %eax, %ebx
12569- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12570+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12571 jge 1f
12572 #endif
12573- movl $LOAD_PHYSICAL_ADDR, %ebx
12574+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12575 1:
12576
12577 /* Target address to relocate to for decompression */
12578@@ -322,10 +322,10 @@ preferred_addr:
12579 addq %rax, %rbp
12580 notq %rax
12581 andq %rax, %rbp
12582- cmpq $LOAD_PHYSICAL_ADDR, %rbp
12583+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12584 jge 1f
12585 #endif
12586- movq $LOAD_PHYSICAL_ADDR, %rbp
12587+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12588 1:
12589
12590 /* Target address to relocate to for decompression */
12591@@ -431,8 +431,8 @@ gdt:
12592 .long gdt
12593 .word 0
12594 .quad 0x0000000000000000 /* NULL descriptor */
12595- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12596- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12597+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12598+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12599 .quad 0x0080890000000000 /* TS descriptor */
12600 .quad 0x0000000000000000 /* TS continued */
12601 gdt_end:
12602diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12603index 57ab74d..7c52182 100644
12604--- a/arch/x86/boot/compressed/misc.c
12605+++ b/arch/x86/boot/compressed/misc.c
12606@@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12607 * Calculate the delta between where vmlinux was linked to load
12608 * and where it was actually loaded.
12609 */
12610- delta = min_addr - LOAD_PHYSICAL_ADDR;
12611+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12612 if (!delta) {
12613 debug_putstr("No relocation needed... ");
12614 return;
12615@@ -312,7 +312,7 @@ static void parse_elf(void *output)
12616 Elf32_Ehdr ehdr;
12617 Elf32_Phdr *phdrs, *phdr;
12618 #endif
12619- void *dest;
12620+ void *dest, *prev;
12621 int i;
12622
12623 memcpy(&ehdr, output, sizeof(ehdr));
12624@@ -339,13 +339,16 @@ static void parse_elf(void *output)
12625 case PT_LOAD:
12626 #ifdef CONFIG_RELOCATABLE
12627 dest = output;
12628- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12629+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12630 #else
12631 dest = (void *)(phdr->p_paddr);
12632 #endif
12633 memcpy(dest,
12634 output + phdr->p_offset,
12635 phdr->p_filesz);
12636+ if (i)
12637+ memset(prev, 0xff, dest - prev);
12638+ prev = dest + phdr->p_filesz;
12639 break;
12640 default: /* Ignore other PT_* */ break;
12641 }
12642@@ -395,7 +398,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
12643 error("Destination address too large");
12644 #endif
12645 #ifndef CONFIG_RELOCATABLE
12646- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12647+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12648 error("Wrong destination address");
12649 #endif
12650
12651diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12652index 1fd7d57..0f7d096 100644
12653--- a/arch/x86/boot/cpucheck.c
12654+++ b/arch/x86/boot/cpucheck.c
12655@@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12656 u32 ecx = MSR_K7_HWCR;
12657 u32 eax, edx;
12658
12659- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12660+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12661 eax &= ~(1 << 15);
12662- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12663+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12664
12665 get_cpuflags(); /* Make sure it really did something */
12666 err = check_cpuflags();
12667@@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12668 u32 ecx = MSR_VIA_FCR;
12669 u32 eax, edx;
12670
12671- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12672+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12673 eax |= (1<<1)|(1<<7);
12674- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12675+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12676
12677 set_bit(X86_FEATURE_CX8, cpu.flags);
12678 err = check_cpuflags();
12679@@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12680 u32 eax, edx;
12681 u32 level = 1;
12682
12683- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12684- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12685- asm("cpuid"
12686+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12687+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12688+ asm volatile("cpuid"
12689 : "+a" (level), "=d" (cpu.flags[0])
12690 : : "ecx", "ebx");
12691- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12692+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12693
12694 err = check_cpuflags();
12695 } else if (err == 0x01 &&
12696diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12697index 84c2234..3ef6360 100644
12698--- a/arch/x86/boot/header.S
12699+++ b/arch/x86/boot/header.S
12700@@ -420,10 +420,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12701 # single linked list of
12702 # struct setup_data
12703
12704-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12705+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12706
12707 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12708+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12709+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12710+#else
12711 #define VO_INIT_SIZE (VO__end - VO__text)
12712+#endif
12713 #if ZO_INIT_SIZE > VO_INIT_SIZE
12714 #define INIT_SIZE ZO_INIT_SIZE
12715 #else
12716diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12717index db75d07..8e6d0af 100644
12718--- a/arch/x86/boot/memory.c
12719+++ b/arch/x86/boot/memory.c
12720@@ -19,7 +19,7 @@
12721
12722 static int detect_memory_e820(void)
12723 {
12724- int count = 0;
12725+ unsigned int count = 0;
12726 struct biosregs ireg, oreg;
12727 struct e820entry *desc = boot_params.e820_map;
12728 static struct e820entry buf; /* static so it is zeroed */
12729diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12730index ba3e100..6501b8f 100644
12731--- a/arch/x86/boot/video-vesa.c
12732+++ b/arch/x86/boot/video-vesa.c
12733@@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
12734
12735 boot_params.screen_info.vesapm_seg = oreg.es;
12736 boot_params.screen_info.vesapm_off = oreg.di;
12737+ boot_params.screen_info.vesapm_size = oreg.cx;
12738 }
12739
12740 /*
12741diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12742index 43eda28..5ab5fdb 100644
12743--- a/arch/x86/boot/video.c
12744+++ b/arch/x86/boot/video.c
12745@@ -96,7 +96,7 @@ static void store_mode_params(void)
12746 static unsigned int get_entry(void)
12747 {
12748 char entry_buf[4];
12749- int i, len = 0;
12750+ unsigned int i, len = 0;
12751 int key;
12752 unsigned int v;
12753
12754diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12755index 9105655..41779c1 100644
12756--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12757+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12758@@ -8,6 +8,8 @@
12759 * including this sentence is retained in full.
12760 */
12761
12762+#include <asm/alternative-asm.h>
12763+
12764 .extern crypto_ft_tab
12765 .extern crypto_it_tab
12766 .extern crypto_fl_tab
12767@@ -70,6 +72,8 @@
12768 je B192; \
12769 leaq 32(r9),r9;
12770
12771+#define ret pax_force_retaddr; ret
12772+
12773 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12774 movq r1,r2; \
12775 movq r3,r4; \
12776diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12777index 477e9d7..c92c7d8 100644
12778--- a/arch/x86/crypto/aesni-intel_asm.S
12779+++ b/arch/x86/crypto/aesni-intel_asm.S
12780@@ -31,6 +31,7 @@
12781
12782 #include <linux/linkage.h>
12783 #include <asm/inst.h>
12784+#include <asm/alternative-asm.h>
12785
12786 #ifdef __x86_64__
12787 .data
12788@@ -205,7 +206,7 @@ enc: .octa 0x2
12789 * num_initial_blocks = b mod 4
12790 * encrypt the initial num_initial_blocks blocks and apply ghash on
12791 * the ciphertext
12792-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12793+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12794 * are clobbered
12795 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12796 */
12797@@ -214,8 +215,8 @@ enc: .octa 0x2
12798 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12799 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12800 mov arg7, %r10 # %r10 = AAD
12801- mov arg8, %r12 # %r12 = aadLen
12802- mov %r12, %r11
12803+ mov arg8, %r15 # %r15 = aadLen
12804+ mov %r15, %r11
12805 pxor %xmm\i, %xmm\i
12806 _get_AAD_loop\num_initial_blocks\operation:
12807 movd (%r10), \TMP1
12808@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12809 psrldq $4, %xmm\i
12810 pxor \TMP1, %xmm\i
12811 add $4, %r10
12812- sub $4, %r12
12813+ sub $4, %r15
12814 jne _get_AAD_loop\num_initial_blocks\operation
12815 cmp $16, %r11
12816 je _get_AAD_loop2_done\num_initial_blocks\operation
12817- mov $16, %r12
12818+ mov $16, %r15
12819 _get_AAD_loop2\num_initial_blocks\operation:
12820 psrldq $4, %xmm\i
12821- sub $4, %r12
12822- cmp %r11, %r12
12823+ sub $4, %r15
12824+ cmp %r11, %r15
12825 jne _get_AAD_loop2\num_initial_blocks\operation
12826 _get_AAD_loop2_done\num_initial_blocks\operation:
12827 movdqa SHUF_MASK(%rip), %xmm14
12828@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12829 * num_initial_blocks = b mod 4
12830 * encrypt the initial num_initial_blocks blocks and apply ghash on
12831 * the ciphertext
12832-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12833+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12834 * are clobbered
12835 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12836 */
12837@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12838 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12839 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12840 mov arg7, %r10 # %r10 = AAD
12841- mov arg8, %r12 # %r12 = aadLen
12842- mov %r12, %r11
12843+ mov arg8, %r15 # %r15 = aadLen
12844+ mov %r15, %r11
12845 pxor %xmm\i, %xmm\i
12846 _get_AAD_loop\num_initial_blocks\operation:
12847 movd (%r10), \TMP1
12848@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12849 psrldq $4, %xmm\i
12850 pxor \TMP1, %xmm\i
12851 add $4, %r10
12852- sub $4, %r12
12853+ sub $4, %r15
12854 jne _get_AAD_loop\num_initial_blocks\operation
12855 cmp $16, %r11
12856 je _get_AAD_loop2_done\num_initial_blocks\operation
12857- mov $16, %r12
12858+ mov $16, %r15
12859 _get_AAD_loop2\num_initial_blocks\operation:
12860 psrldq $4, %xmm\i
12861- sub $4, %r12
12862- cmp %r11, %r12
12863+ sub $4, %r15
12864+ cmp %r11, %r15
12865 jne _get_AAD_loop2\num_initial_blocks\operation
12866 _get_AAD_loop2_done\num_initial_blocks\operation:
12867 movdqa SHUF_MASK(%rip), %xmm14
12868@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12869 *
12870 *****************************************************************************/
12871 ENTRY(aesni_gcm_dec)
12872- push %r12
12873+ push %r15
12874 push %r13
12875 push %r14
12876 mov %rsp, %r14
12877@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12878 */
12879 sub $VARIABLE_OFFSET, %rsp
12880 and $~63, %rsp # align rsp to 64 bytes
12881- mov %arg6, %r12
12882- movdqu (%r12), %xmm13 # %xmm13 = HashKey
12883+ mov %arg6, %r15
12884+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
12885 movdqa SHUF_MASK(%rip), %xmm2
12886 PSHUFB_XMM %xmm2, %xmm13
12887
12888@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12889 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12890 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12891 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12892- mov %r13, %r12
12893- and $(3<<4), %r12
12894+ mov %r13, %r15
12895+ and $(3<<4), %r15
12896 jz _initial_num_blocks_is_0_decrypt
12897- cmp $(2<<4), %r12
12898+ cmp $(2<<4), %r15
12899 jb _initial_num_blocks_is_1_decrypt
12900 je _initial_num_blocks_is_2_decrypt
12901 _initial_num_blocks_is_3_decrypt:
12902@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12903 sub $16, %r11
12904 add %r13, %r11
12905 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12906- lea SHIFT_MASK+16(%rip), %r12
12907- sub %r13, %r12
12908+ lea SHIFT_MASK+16(%rip), %r15
12909+ sub %r13, %r15
12910 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12911 # (%r13 is the number of bytes in plaintext mod 16)
12912- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12913+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12914 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12915
12916 movdqa %xmm1, %xmm2
12917 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12918- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12919+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12920 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12921 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12922 pand %xmm1, %xmm2
12923@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12924 sub $1, %r13
12925 jne _less_than_8_bytes_left_decrypt
12926 _multiple_of_16_bytes_decrypt:
12927- mov arg8, %r12 # %r13 = aadLen (number of bytes)
12928- shl $3, %r12 # convert into number of bits
12929- movd %r12d, %xmm15 # len(A) in %xmm15
12930+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
12931+ shl $3, %r15 # convert into number of bits
12932+ movd %r15d, %xmm15 # len(A) in %xmm15
12933 shl $3, %arg4 # len(C) in bits (*128)
12934 MOVQ_R64_XMM %arg4, %xmm1
12935 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12936@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12937 mov %r14, %rsp
12938 pop %r14
12939 pop %r13
12940- pop %r12
12941+ pop %r15
12942+ pax_force_retaddr
12943 ret
12944 ENDPROC(aesni_gcm_dec)
12945
12946@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12947 * poly = x^128 + x^127 + x^126 + x^121 + 1
12948 ***************************************************************************/
12949 ENTRY(aesni_gcm_enc)
12950- push %r12
12951+ push %r15
12952 push %r13
12953 push %r14
12954 mov %rsp, %r14
12955@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12956 #
12957 sub $VARIABLE_OFFSET, %rsp
12958 and $~63, %rsp
12959- mov %arg6, %r12
12960- movdqu (%r12), %xmm13
12961+ mov %arg6, %r15
12962+ movdqu (%r15), %xmm13
12963 movdqa SHUF_MASK(%rip), %xmm2
12964 PSHUFB_XMM %xmm2, %xmm13
12965
12966@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12967 movdqa %xmm13, HashKey(%rsp)
12968 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12969 and $-16, %r13
12970- mov %r13, %r12
12971+ mov %r13, %r15
12972
12973 # Encrypt first few blocks
12974
12975- and $(3<<4), %r12
12976+ and $(3<<4), %r15
12977 jz _initial_num_blocks_is_0_encrypt
12978- cmp $(2<<4), %r12
12979+ cmp $(2<<4), %r15
12980 jb _initial_num_blocks_is_1_encrypt
12981 je _initial_num_blocks_is_2_encrypt
12982 _initial_num_blocks_is_3_encrypt:
12983@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12984 sub $16, %r11
12985 add %r13, %r11
12986 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12987- lea SHIFT_MASK+16(%rip), %r12
12988- sub %r13, %r12
12989+ lea SHIFT_MASK+16(%rip), %r15
12990+ sub %r13, %r15
12991 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12992 # (%r13 is the number of bytes in plaintext mod 16)
12993- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12994+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12995 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12996 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12997- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12998+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12999 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13000 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13001 movdqa SHUF_MASK(%rip), %xmm10
13002@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13003 sub $1, %r13
13004 jne _less_than_8_bytes_left_encrypt
13005 _multiple_of_16_bytes_encrypt:
13006- mov arg8, %r12 # %r12 = addLen (number of bytes)
13007- shl $3, %r12
13008- movd %r12d, %xmm15 # len(A) in %xmm15
13009+ mov arg8, %r15 # %r15 = addLen (number of bytes)
13010+ shl $3, %r15
13011+ movd %r15d, %xmm15 # len(A) in %xmm15
13012 shl $3, %arg4 # len(C) in bits (*128)
13013 MOVQ_R64_XMM %arg4, %xmm1
13014 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13015@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13016 mov %r14, %rsp
13017 pop %r14
13018 pop %r13
13019- pop %r12
13020+ pop %r15
13021+ pax_force_retaddr
13022 ret
13023 ENDPROC(aesni_gcm_enc)
13024
13025@@ -1722,6 +1725,7 @@ _key_expansion_256a:
13026 pxor %xmm1, %xmm0
13027 movaps %xmm0, (TKEYP)
13028 add $0x10, TKEYP
13029+ pax_force_retaddr
13030 ret
13031 ENDPROC(_key_expansion_128)
13032 ENDPROC(_key_expansion_256a)
13033@@ -1748,6 +1752,7 @@ _key_expansion_192a:
13034 shufps $0b01001110, %xmm2, %xmm1
13035 movaps %xmm1, 0x10(TKEYP)
13036 add $0x20, TKEYP
13037+ pax_force_retaddr
13038 ret
13039 ENDPROC(_key_expansion_192a)
13040
13041@@ -1768,6 +1773,7 @@ _key_expansion_192b:
13042
13043 movaps %xmm0, (TKEYP)
13044 add $0x10, TKEYP
13045+ pax_force_retaddr
13046 ret
13047 ENDPROC(_key_expansion_192b)
13048
13049@@ -1781,6 +1787,7 @@ _key_expansion_256b:
13050 pxor %xmm1, %xmm2
13051 movaps %xmm2, (TKEYP)
13052 add $0x10, TKEYP
13053+ pax_force_retaddr
13054 ret
13055 ENDPROC(_key_expansion_256b)
13056
13057@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13058 #ifndef __x86_64__
13059 popl KEYP
13060 #endif
13061+ pax_force_retaddr
13062 ret
13063 ENDPROC(aesni_set_key)
13064
13065@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13066 popl KLEN
13067 popl KEYP
13068 #endif
13069+ pax_force_retaddr
13070 ret
13071 ENDPROC(aesni_enc)
13072
13073@@ -1974,6 +1983,7 @@ _aesni_enc1:
13074 AESENC KEY STATE
13075 movaps 0x70(TKEYP), KEY
13076 AESENCLAST KEY STATE
13077+ pax_force_retaddr
13078 ret
13079 ENDPROC(_aesni_enc1)
13080
13081@@ -2083,6 +2093,7 @@ _aesni_enc4:
13082 AESENCLAST KEY STATE2
13083 AESENCLAST KEY STATE3
13084 AESENCLAST KEY STATE4
13085+ pax_force_retaddr
13086 ret
13087 ENDPROC(_aesni_enc4)
13088
13089@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13090 popl KLEN
13091 popl KEYP
13092 #endif
13093+ pax_force_retaddr
13094 ret
13095 ENDPROC(aesni_dec)
13096
13097@@ -2164,6 +2176,7 @@ _aesni_dec1:
13098 AESDEC KEY STATE
13099 movaps 0x70(TKEYP), KEY
13100 AESDECLAST KEY STATE
13101+ pax_force_retaddr
13102 ret
13103 ENDPROC(_aesni_dec1)
13104
13105@@ -2273,6 +2286,7 @@ _aesni_dec4:
13106 AESDECLAST KEY STATE2
13107 AESDECLAST KEY STATE3
13108 AESDECLAST KEY STATE4
13109+ pax_force_retaddr
13110 ret
13111 ENDPROC(_aesni_dec4)
13112
13113@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13114 popl KEYP
13115 popl LEN
13116 #endif
13117+ pax_force_retaddr
13118 ret
13119 ENDPROC(aesni_ecb_enc)
13120
13121@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13122 popl KEYP
13123 popl LEN
13124 #endif
13125+ pax_force_retaddr
13126 ret
13127 ENDPROC(aesni_ecb_dec)
13128
13129@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13130 popl LEN
13131 popl IVP
13132 #endif
13133+ pax_force_retaddr
13134 ret
13135 ENDPROC(aesni_cbc_enc)
13136
13137@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13138 popl LEN
13139 popl IVP
13140 #endif
13141+ pax_force_retaddr
13142 ret
13143 ENDPROC(aesni_cbc_dec)
13144
13145@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13146 mov $1, TCTR_LOW
13147 MOVQ_R64_XMM TCTR_LOW INC
13148 MOVQ_R64_XMM CTR TCTR_LOW
13149+ pax_force_retaddr
13150 ret
13151 ENDPROC(_aesni_inc_init)
13152
13153@@ -2579,6 +2598,7 @@ _aesni_inc:
13154 .Linc_low:
13155 movaps CTR, IV
13156 PSHUFB_XMM BSWAP_MASK IV
13157+ pax_force_retaddr
13158 ret
13159 ENDPROC(_aesni_inc)
13160
13161@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13162 .Lctr_enc_ret:
13163 movups IV, (IVP)
13164 .Lctr_enc_just_ret:
13165+ pax_force_retaddr
13166 ret
13167 ENDPROC(aesni_ctr_enc)
13168
13169@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13170 pxor INC, STATE4
13171 movdqu STATE4, 0x70(OUTP)
13172
13173+ pax_force_retaddr
13174 ret
13175 ENDPROC(aesni_xts_crypt8)
13176
13177diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13178index 246c670..466e2d6 100644
13179--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13180+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13181@@ -21,6 +21,7 @@
13182 */
13183
13184 #include <linux/linkage.h>
13185+#include <asm/alternative-asm.h>
13186
13187 .file "blowfish-x86_64-asm.S"
13188 .text
13189@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13190 jnz .L__enc_xor;
13191
13192 write_block();
13193+ pax_force_retaddr
13194 ret;
13195 .L__enc_xor:
13196 xor_block();
13197+ pax_force_retaddr
13198 ret;
13199 ENDPROC(__blowfish_enc_blk)
13200
13201@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13202
13203 movq %r11, %rbp;
13204
13205+ pax_force_retaddr
13206 ret;
13207 ENDPROC(blowfish_dec_blk)
13208
13209@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13210
13211 popq %rbx;
13212 popq %rbp;
13213+ pax_force_retaddr
13214 ret;
13215
13216 .L__enc_xor4:
13217@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13218
13219 popq %rbx;
13220 popq %rbp;
13221+ pax_force_retaddr
13222 ret;
13223 ENDPROC(__blowfish_enc_blk_4way)
13224
13225@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13226 popq %rbx;
13227 popq %rbp;
13228
13229+ pax_force_retaddr
13230 ret;
13231 ENDPROC(blowfish_dec_blk_4way)
13232diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13233index ce71f92..1dce7ec 100644
13234--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13235+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13236@@ -16,6 +16,7 @@
13237 */
13238
13239 #include <linux/linkage.h>
13240+#include <asm/alternative-asm.h>
13241
13242 #define CAMELLIA_TABLE_BYTE_LEN 272
13243
13244@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13245 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13246 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13247 %rcx, (%r9));
13248+ pax_force_retaddr
13249 ret;
13250 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13251
13252@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13253 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13254 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13255 %rax, (%r9));
13256+ pax_force_retaddr
13257 ret;
13258 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13259
13260@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13261 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13262 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13263
13264+ pax_force_retaddr
13265 ret;
13266
13267 .align 8
13268@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13269 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13270 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13271
13272+ pax_force_retaddr
13273 ret;
13274
13275 .align 8
13276@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13277 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13278 %xmm8, %rsi);
13279
13280+ pax_force_retaddr
13281 ret;
13282 ENDPROC(camellia_ecb_enc_16way)
13283
13284@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13285 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13286 %xmm8, %rsi);
13287
13288+ pax_force_retaddr
13289 ret;
13290 ENDPROC(camellia_ecb_dec_16way)
13291
13292@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13293 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13294 %xmm8, %rsi);
13295
13296+ pax_force_retaddr
13297 ret;
13298 ENDPROC(camellia_cbc_dec_16way)
13299
13300@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13301 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13302 %xmm8, %rsi);
13303
13304+ pax_force_retaddr
13305 ret;
13306 ENDPROC(camellia_ctr_16way)
13307
13308@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13309 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13310 %xmm8, %rsi);
13311
13312+ pax_force_retaddr
13313 ret;
13314 ENDPROC(camellia_xts_crypt_16way)
13315
13316diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13317index 0e0b886..5a3123c 100644
13318--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13319+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13320@@ -11,6 +11,7 @@
13321 */
13322
13323 #include <linux/linkage.h>
13324+#include <asm/alternative-asm.h>
13325
13326 #define CAMELLIA_TABLE_BYTE_LEN 272
13327
13328@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13329 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13330 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13331 %rcx, (%r9));
13332+ pax_force_retaddr
13333 ret;
13334 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13335
13336@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13337 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13338 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13339 %rax, (%r9));
13340+ pax_force_retaddr
13341 ret;
13342 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13343
13344@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13345 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13346 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13347
13348+ pax_force_retaddr
13349 ret;
13350
13351 .align 8
13352@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13353 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13354 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13355
13356+ pax_force_retaddr
13357 ret;
13358
13359 .align 8
13360@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13361
13362 vzeroupper;
13363
13364+ pax_force_retaddr
13365 ret;
13366 ENDPROC(camellia_ecb_enc_32way)
13367
13368@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13369
13370 vzeroupper;
13371
13372+ pax_force_retaddr
13373 ret;
13374 ENDPROC(camellia_ecb_dec_32way)
13375
13376@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13377
13378 vzeroupper;
13379
13380+ pax_force_retaddr
13381 ret;
13382 ENDPROC(camellia_cbc_dec_32way)
13383
13384@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13385
13386 vzeroupper;
13387
13388+ pax_force_retaddr
13389 ret;
13390 ENDPROC(camellia_ctr_32way)
13391
13392@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13393
13394 vzeroupper;
13395
13396+ pax_force_retaddr
13397 ret;
13398 ENDPROC(camellia_xts_crypt_32way)
13399
13400diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13401index 310319c..db3d7b5 100644
13402--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13403+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13404@@ -21,6 +21,7 @@
13405 */
13406
13407 #include <linux/linkage.h>
13408+#include <asm/alternative-asm.h>
13409
13410 .file "camellia-x86_64-asm_64.S"
13411 .text
13412@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13413 enc_outunpack(mov, RT1);
13414
13415 movq RRBP, %rbp;
13416+ pax_force_retaddr
13417 ret;
13418
13419 .L__enc_xor:
13420 enc_outunpack(xor, RT1);
13421
13422 movq RRBP, %rbp;
13423+ pax_force_retaddr
13424 ret;
13425 ENDPROC(__camellia_enc_blk)
13426
13427@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13428 dec_outunpack();
13429
13430 movq RRBP, %rbp;
13431+ pax_force_retaddr
13432 ret;
13433 ENDPROC(camellia_dec_blk)
13434
13435@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13436
13437 movq RRBP, %rbp;
13438 popq %rbx;
13439+ pax_force_retaddr
13440 ret;
13441
13442 .L__enc2_xor:
13443@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13444
13445 movq RRBP, %rbp;
13446 popq %rbx;
13447+ pax_force_retaddr
13448 ret;
13449 ENDPROC(__camellia_enc_blk_2way)
13450
13451@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13452
13453 movq RRBP, %rbp;
13454 movq RXOR, %rbx;
13455+ pax_force_retaddr
13456 ret;
13457 ENDPROC(camellia_dec_blk_2way)
13458diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13459index c35fd5d..2d8c7db 100644
13460--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13461+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13462@@ -24,6 +24,7 @@
13463 */
13464
13465 #include <linux/linkage.h>
13466+#include <asm/alternative-asm.h>
13467
13468 .file "cast5-avx-x86_64-asm_64.S"
13469
13470@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13471 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13472 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13473
13474+ pax_force_retaddr
13475 ret;
13476 ENDPROC(__cast5_enc_blk16)
13477
13478@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13479 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13480 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13481
13482+ pax_force_retaddr
13483 ret;
13484
13485 .L__skip_dec:
13486@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13487 vmovdqu RR4, (6*4*4)(%r11);
13488 vmovdqu RL4, (7*4*4)(%r11);
13489
13490+ pax_force_retaddr
13491 ret;
13492 ENDPROC(cast5_ecb_enc_16way)
13493
13494@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13495 vmovdqu RR4, (6*4*4)(%r11);
13496 vmovdqu RL4, (7*4*4)(%r11);
13497
13498+ pax_force_retaddr
13499 ret;
13500 ENDPROC(cast5_ecb_dec_16way)
13501
13502@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13503 * %rdx: src
13504 */
13505
13506- pushq %r12;
13507+ pushq %r14;
13508
13509 movq %rsi, %r11;
13510- movq %rdx, %r12;
13511+ movq %rdx, %r14;
13512
13513 vmovdqu (0*16)(%rdx), RL1;
13514 vmovdqu (1*16)(%rdx), RR1;
13515@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13516 call __cast5_dec_blk16;
13517
13518 /* xor with src */
13519- vmovq (%r12), RX;
13520+ vmovq (%r14), RX;
13521 vpshufd $0x4f, RX, RX;
13522 vpxor RX, RR1, RR1;
13523- vpxor 0*16+8(%r12), RL1, RL1;
13524- vpxor 1*16+8(%r12), RR2, RR2;
13525- vpxor 2*16+8(%r12), RL2, RL2;
13526- vpxor 3*16+8(%r12), RR3, RR3;
13527- vpxor 4*16+8(%r12), RL3, RL3;
13528- vpxor 5*16+8(%r12), RR4, RR4;
13529- vpxor 6*16+8(%r12), RL4, RL4;
13530+ vpxor 0*16+8(%r14), RL1, RL1;
13531+ vpxor 1*16+8(%r14), RR2, RR2;
13532+ vpxor 2*16+8(%r14), RL2, RL2;
13533+ vpxor 3*16+8(%r14), RR3, RR3;
13534+ vpxor 4*16+8(%r14), RL3, RL3;
13535+ vpxor 5*16+8(%r14), RR4, RR4;
13536+ vpxor 6*16+8(%r14), RL4, RL4;
13537
13538 vmovdqu RR1, (0*16)(%r11);
13539 vmovdqu RL1, (1*16)(%r11);
13540@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13541 vmovdqu RR4, (6*16)(%r11);
13542 vmovdqu RL4, (7*16)(%r11);
13543
13544- popq %r12;
13545+ popq %r14;
13546
13547+ pax_force_retaddr
13548 ret;
13549 ENDPROC(cast5_cbc_dec_16way)
13550
13551@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13552 * %rcx: iv (big endian, 64bit)
13553 */
13554
13555- pushq %r12;
13556+ pushq %r14;
13557
13558 movq %rsi, %r11;
13559- movq %rdx, %r12;
13560+ movq %rdx, %r14;
13561
13562 vpcmpeqd RTMP, RTMP, RTMP;
13563 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13564@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13565 call __cast5_enc_blk16;
13566
13567 /* dst = src ^ iv */
13568- vpxor (0*16)(%r12), RR1, RR1;
13569- vpxor (1*16)(%r12), RL1, RL1;
13570- vpxor (2*16)(%r12), RR2, RR2;
13571- vpxor (3*16)(%r12), RL2, RL2;
13572- vpxor (4*16)(%r12), RR3, RR3;
13573- vpxor (5*16)(%r12), RL3, RL3;
13574- vpxor (6*16)(%r12), RR4, RR4;
13575- vpxor (7*16)(%r12), RL4, RL4;
13576+ vpxor (0*16)(%r14), RR1, RR1;
13577+ vpxor (1*16)(%r14), RL1, RL1;
13578+ vpxor (2*16)(%r14), RR2, RR2;
13579+ vpxor (3*16)(%r14), RL2, RL2;
13580+ vpxor (4*16)(%r14), RR3, RR3;
13581+ vpxor (5*16)(%r14), RL3, RL3;
13582+ vpxor (6*16)(%r14), RR4, RR4;
13583+ vpxor (7*16)(%r14), RL4, RL4;
13584 vmovdqu RR1, (0*16)(%r11);
13585 vmovdqu RL1, (1*16)(%r11);
13586 vmovdqu RR2, (2*16)(%r11);
13587@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13588 vmovdqu RR4, (6*16)(%r11);
13589 vmovdqu RL4, (7*16)(%r11);
13590
13591- popq %r12;
13592+ popq %r14;
13593
13594+ pax_force_retaddr
13595 ret;
13596 ENDPROC(cast5_ctr_16way)
13597diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13598index e3531f8..e123f35 100644
13599--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13600+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13601@@ -24,6 +24,7 @@
13602 */
13603
13604 #include <linux/linkage.h>
13605+#include <asm/alternative-asm.h>
13606 #include "glue_helper-asm-avx.S"
13607
13608 .file "cast6-avx-x86_64-asm_64.S"
13609@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13610 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13611 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13612
13613+ pax_force_retaddr
13614 ret;
13615 ENDPROC(__cast6_enc_blk8)
13616
13617@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13618 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13619 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13620
13621+ pax_force_retaddr
13622 ret;
13623 ENDPROC(__cast6_dec_blk8)
13624
13625@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13626
13627 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13628
13629+ pax_force_retaddr
13630 ret;
13631 ENDPROC(cast6_ecb_enc_8way)
13632
13633@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13634
13635 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13636
13637+ pax_force_retaddr
13638 ret;
13639 ENDPROC(cast6_ecb_dec_8way)
13640
13641@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13642 * %rdx: src
13643 */
13644
13645- pushq %r12;
13646+ pushq %r14;
13647
13648 movq %rsi, %r11;
13649- movq %rdx, %r12;
13650+ movq %rdx, %r14;
13651
13652 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13653
13654 call __cast6_dec_blk8;
13655
13656- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13657+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13658
13659- popq %r12;
13660+ popq %r14;
13661
13662+ pax_force_retaddr
13663 ret;
13664 ENDPROC(cast6_cbc_dec_8way)
13665
13666@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13667 * %rcx: iv (little endian, 128bit)
13668 */
13669
13670- pushq %r12;
13671+ pushq %r14;
13672
13673 movq %rsi, %r11;
13674- movq %rdx, %r12;
13675+ movq %rdx, %r14;
13676
13677 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13678 RD2, RX, RKR, RKM);
13679
13680 call __cast6_enc_blk8;
13681
13682- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13683+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13684
13685- popq %r12;
13686+ popq %r14;
13687
13688+ pax_force_retaddr
13689 ret;
13690 ENDPROC(cast6_ctr_8way)
13691
13692@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13693 /* dst <= regs xor IVs(in dst) */
13694 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13695
13696+ pax_force_retaddr
13697 ret;
13698 ENDPROC(cast6_xts_enc_8way)
13699
13700@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13701 /* dst <= regs xor IVs(in dst) */
13702 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13703
13704+ pax_force_retaddr
13705 ret;
13706 ENDPROC(cast6_xts_dec_8way)
13707diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13708index dbc4339..de6e120 100644
13709--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13710+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13711@@ -45,6 +45,7 @@
13712
13713 #include <asm/inst.h>
13714 #include <linux/linkage.h>
13715+#include <asm/alternative-asm.h>
13716
13717 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13718
13719@@ -312,6 +313,7 @@ do_return:
13720 popq %rsi
13721 popq %rdi
13722 popq %rbx
13723+ pax_force_retaddr
13724 ret
13725
13726 ################################################################
13727diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13728index 185fad4..ff4cd36 100644
13729--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13730+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13731@@ -18,6 +18,7 @@
13732
13733 #include <linux/linkage.h>
13734 #include <asm/inst.h>
13735+#include <asm/alternative-asm.h>
13736
13737 .data
13738
13739@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13740 psrlq $1, T2
13741 pxor T2, T1
13742 pxor T1, DATA
13743+ pax_force_retaddr
13744 ret
13745 ENDPROC(__clmul_gf128mul_ble)
13746
13747@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13748 call __clmul_gf128mul_ble
13749 PSHUFB_XMM BSWAP DATA
13750 movups DATA, (%rdi)
13751+ pax_force_retaddr
13752 ret
13753 ENDPROC(clmul_ghash_mul)
13754
13755@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13756 PSHUFB_XMM BSWAP DATA
13757 movups DATA, (%rdi)
13758 .Lupdate_just_ret:
13759+ pax_force_retaddr
13760 ret
13761 ENDPROC(clmul_ghash_update)
13762diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13763index 9279e0b..c4b3d2c 100644
13764--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13765+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13766@@ -1,4 +1,5 @@
13767 #include <linux/linkage.h>
13768+#include <asm/alternative-asm.h>
13769
13770 # enter salsa20_encrypt_bytes
13771 ENTRY(salsa20_encrypt_bytes)
13772@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13773 add %r11,%rsp
13774 mov %rdi,%rax
13775 mov %rsi,%rdx
13776+ pax_force_retaddr
13777 ret
13778 # bytesatleast65:
13779 ._bytesatleast65:
13780@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13781 add %r11,%rsp
13782 mov %rdi,%rax
13783 mov %rsi,%rdx
13784+ pax_force_retaddr
13785 ret
13786 ENDPROC(salsa20_keysetup)
13787
13788@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13789 add %r11,%rsp
13790 mov %rdi,%rax
13791 mov %rsi,%rdx
13792+ pax_force_retaddr
13793 ret
13794 ENDPROC(salsa20_ivsetup)
13795diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13796index 2f202f4..d9164d6 100644
13797--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13798+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13799@@ -24,6 +24,7 @@
13800 */
13801
13802 #include <linux/linkage.h>
13803+#include <asm/alternative-asm.h>
13804 #include "glue_helper-asm-avx.S"
13805
13806 .file "serpent-avx-x86_64-asm_64.S"
13807@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13808 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13809 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13810
13811+ pax_force_retaddr
13812 ret;
13813 ENDPROC(__serpent_enc_blk8_avx)
13814
13815@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13816 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13817 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13818
13819+ pax_force_retaddr
13820 ret;
13821 ENDPROC(__serpent_dec_blk8_avx)
13822
13823@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13824
13825 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13826
13827+ pax_force_retaddr
13828 ret;
13829 ENDPROC(serpent_ecb_enc_8way_avx)
13830
13831@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13832
13833 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13834
13835+ pax_force_retaddr
13836 ret;
13837 ENDPROC(serpent_ecb_dec_8way_avx)
13838
13839@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13840
13841 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13842
13843+ pax_force_retaddr
13844 ret;
13845 ENDPROC(serpent_cbc_dec_8way_avx)
13846
13847@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13848
13849 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13850
13851+ pax_force_retaddr
13852 ret;
13853 ENDPROC(serpent_ctr_8way_avx)
13854
13855@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13856 /* dst <= regs xor IVs(in dst) */
13857 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13858
13859+ pax_force_retaddr
13860 ret;
13861 ENDPROC(serpent_xts_enc_8way_avx)
13862
13863@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13864 /* dst <= regs xor IVs(in dst) */
13865 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13866
13867+ pax_force_retaddr
13868 ret;
13869 ENDPROC(serpent_xts_dec_8way_avx)
13870diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13871index b222085..abd483c 100644
13872--- a/arch/x86/crypto/serpent-avx2-asm_64.S
13873+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13874@@ -15,6 +15,7 @@
13875 */
13876
13877 #include <linux/linkage.h>
13878+#include <asm/alternative-asm.h>
13879 #include "glue_helper-asm-avx2.S"
13880
13881 .file "serpent-avx2-asm_64.S"
13882@@ -610,6 +611,7 @@ __serpent_enc_blk16:
13883 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13884 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13885
13886+ pax_force_retaddr
13887 ret;
13888 ENDPROC(__serpent_enc_blk16)
13889
13890@@ -664,6 +666,7 @@ __serpent_dec_blk16:
13891 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13892 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13893
13894+ pax_force_retaddr
13895 ret;
13896 ENDPROC(__serpent_dec_blk16)
13897
13898@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13899
13900 vzeroupper;
13901
13902+ pax_force_retaddr
13903 ret;
13904 ENDPROC(serpent_ecb_enc_16way)
13905
13906@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13907
13908 vzeroupper;
13909
13910+ pax_force_retaddr
13911 ret;
13912 ENDPROC(serpent_ecb_dec_16way)
13913
13914@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13915
13916 vzeroupper;
13917
13918+ pax_force_retaddr
13919 ret;
13920 ENDPROC(serpent_cbc_dec_16way)
13921
13922@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13923
13924 vzeroupper;
13925
13926+ pax_force_retaddr
13927 ret;
13928 ENDPROC(serpent_ctr_16way)
13929
13930@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13931
13932 vzeroupper;
13933
13934+ pax_force_retaddr
13935 ret;
13936 ENDPROC(serpent_xts_enc_16way)
13937
13938@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13939
13940 vzeroupper;
13941
13942+ pax_force_retaddr
13943 ret;
13944 ENDPROC(serpent_xts_dec_16way)
13945diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13946index acc066c..1559cc4 100644
13947--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13948+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13949@@ -25,6 +25,7 @@
13950 */
13951
13952 #include <linux/linkage.h>
13953+#include <asm/alternative-asm.h>
13954
13955 .file "serpent-sse2-x86_64-asm_64.S"
13956 .text
13957@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13958 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13959 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13960
13961+ pax_force_retaddr
13962 ret;
13963
13964 .L__enc_xor8:
13965 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13966 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13967
13968+ pax_force_retaddr
13969 ret;
13970 ENDPROC(__serpent_enc_blk_8way)
13971
13972@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13973 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13974 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13975
13976+ pax_force_retaddr
13977 ret;
13978 ENDPROC(serpent_dec_blk_8way)
13979diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13980index a410950..9dfe7ad 100644
13981--- a/arch/x86/crypto/sha1_ssse3_asm.S
13982+++ b/arch/x86/crypto/sha1_ssse3_asm.S
13983@@ -29,6 +29,7 @@
13984 */
13985
13986 #include <linux/linkage.h>
13987+#include <asm/alternative-asm.h>
13988
13989 #define CTX %rdi // arg1
13990 #define BUF %rsi // arg2
13991@@ -75,9 +76,9 @@
13992
13993 push %rbx
13994 push %rbp
13995- push %r12
13996+ push %r14
13997
13998- mov %rsp, %r12
13999+ mov %rsp, %r14
14000 sub $64, %rsp # allocate workspace
14001 and $~15, %rsp # align stack
14002
14003@@ -99,11 +100,12 @@
14004 xor %rax, %rax
14005 rep stosq
14006
14007- mov %r12, %rsp # deallocate workspace
14008+ mov %r14, %rsp # deallocate workspace
14009
14010- pop %r12
14011+ pop %r14
14012 pop %rbp
14013 pop %rbx
14014+ pax_force_retaddr
14015 ret
14016
14017 ENDPROC(\name)
14018diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14019index 642f156..51a513c 100644
14020--- a/arch/x86/crypto/sha256-avx-asm.S
14021+++ b/arch/x86/crypto/sha256-avx-asm.S
14022@@ -49,6 +49,7 @@
14023
14024 #ifdef CONFIG_AS_AVX
14025 #include <linux/linkage.h>
14026+#include <asm/alternative-asm.h>
14027
14028 ## assume buffers not aligned
14029 #define VMOVDQ vmovdqu
14030@@ -460,6 +461,7 @@ done_hash:
14031 popq %r13
14032 popq %rbp
14033 popq %rbx
14034+ pax_force_retaddr
14035 ret
14036 ENDPROC(sha256_transform_avx)
14037
14038diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14039index 9e86944..3795e6a 100644
14040--- a/arch/x86/crypto/sha256-avx2-asm.S
14041+++ b/arch/x86/crypto/sha256-avx2-asm.S
14042@@ -50,6 +50,7 @@
14043
14044 #ifdef CONFIG_AS_AVX2
14045 #include <linux/linkage.h>
14046+#include <asm/alternative-asm.h>
14047
14048 ## assume buffers not aligned
14049 #define VMOVDQ vmovdqu
14050@@ -720,6 +721,7 @@ done_hash:
14051 popq %r12
14052 popq %rbp
14053 popq %rbx
14054+ pax_force_retaddr
14055 ret
14056 ENDPROC(sha256_transform_rorx)
14057
14058diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14059index f833b74..8c62a9e 100644
14060--- a/arch/x86/crypto/sha256-ssse3-asm.S
14061+++ b/arch/x86/crypto/sha256-ssse3-asm.S
14062@@ -47,6 +47,7 @@
14063 ########################################################################
14064
14065 #include <linux/linkage.h>
14066+#include <asm/alternative-asm.h>
14067
14068 ## assume buffers not aligned
14069 #define MOVDQ movdqu
14070@@ -471,6 +472,7 @@ done_hash:
14071 popq %rbp
14072 popq %rbx
14073
14074+ pax_force_retaddr
14075 ret
14076 ENDPROC(sha256_transform_ssse3)
14077
14078diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14079index 974dde9..a823ff9 100644
14080--- a/arch/x86/crypto/sha512-avx-asm.S
14081+++ b/arch/x86/crypto/sha512-avx-asm.S
14082@@ -49,6 +49,7 @@
14083
14084 #ifdef CONFIG_AS_AVX
14085 #include <linux/linkage.h>
14086+#include <asm/alternative-asm.h>
14087
14088 .text
14089
14090@@ -364,6 +365,7 @@ updateblock:
14091 mov frame_RSPSAVE(%rsp), %rsp
14092
14093 nowork:
14094+ pax_force_retaddr
14095 ret
14096 ENDPROC(sha512_transform_avx)
14097
14098diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14099index 568b961..ed20c37 100644
14100--- a/arch/x86/crypto/sha512-avx2-asm.S
14101+++ b/arch/x86/crypto/sha512-avx2-asm.S
14102@@ -51,6 +51,7 @@
14103
14104 #ifdef CONFIG_AS_AVX2
14105 #include <linux/linkage.h>
14106+#include <asm/alternative-asm.h>
14107
14108 .text
14109
14110@@ -678,6 +679,7 @@ done_hash:
14111
14112 # Restore Stack Pointer
14113 mov frame_RSPSAVE(%rsp), %rsp
14114+ pax_force_retaddr
14115 ret
14116 ENDPROC(sha512_transform_rorx)
14117
14118diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14119index fb56855..6edd768 100644
14120--- a/arch/x86/crypto/sha512-ssse3-asm.S
14121+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14122@@ -48,6 +48,7 @@
14123 ########################################################################
14124
14125 #include <linux/linkage.h>
14126+#include <asm/alternative-asm.h>
14127
14128 .text
14129
14130@@ -363,6 +364,7 @@ updateblock:
14131 mov frame_RSPSAVE(%rsp), %rsp
14132
14133 nowork:
14134+ pax_force_retaddr
14135 ret
14136 ENDPROC(sha512_transform_ssse3)
14137
14138diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14139index 0505813..b067311 100644
14140--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14141+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14142@@ -24,6 +24,7 @@
14143 */
14144
14145 #include <linux/linkage.h>
14146+#include <asm/alternative-asm.h>
14147 #include "glue_helper-asm-avx.S"
14148
14149 .file "twofish-avx-x86_64-asm_64.S"
14150@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14151 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14152 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14153
14154+ pax_force_retaddr
14155 ret;
14156 ENDPROC(__twofish_enc_blk8)
14157
14158@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14159 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14160 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14161
14162+ pax_force_retaddr
14163 ret;
14164 ENDPROC(__twofish_dec_blk8)
14165
14166@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14167
14168 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14169
14170+ pax_force_retaddr
14171 ret;
14172 ENDPROC(twofish_ecb_enc_8way)
14173
14174@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14175
14176 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14177
14178+ pax_force_retaddr
14179 ret;
14180 ENDPROC(twofish_ecb_dec_8way)
14181
14182@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14183 * %rdx: src
14184 */
14185
14186- pushq %r12;
14187+ pushq %r14;
14188
14189 movq %rsi, %r11;
14190- movq %rdx, %r12;
14191+ movq %rdx, %r14;
14192
14193 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14194
14195 call __twofish_dec_blk8;
14196
14197- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14198+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14199
14200- popq %r12;
14201+ popq %r14;
14202
14203+ pax_force_retaddr
14204 ret;
14205 ENDPROC(twofish_cbc_dec_8way)
14206
14207@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14208 * %rcx: iv (little endian, 128bit)
14209 */
14210
14211- pushq %r12;
14212+ pushq %r14;
14213
14214 movq %rsi, %r11;
14215- movq %rdx, %r12;
14216+ movq %rdx, %r14;
14217
14218 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14219 RD2, RX0, RX1, RY0);
14220
14221 call __twofish_enc_blk8;
14222
14223- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14224+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14225
14226- popq %r12;
14227+ popq %r14;
14228
14229+ pax_force_retaddr
14230 ret;
14231 ENDPROC(twofish_ctr_8way)
14232
14233@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14234 /* dst <= regs xor IVs(in dst) */
14235 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14236
14237+ pax_force_retaddr
14238 ret;
14239 ENDPROC(twofish_xts_enc_8way)
14240
14241@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14242 /* dst <= regs xor IVs(in dst) */
14243 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14244
14245+ pax_force_retaddr
14246 ret;
14247 ENDPROC(twofish_xts_dec_8way)
14248diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14249index 1c3b7ce..02f578d 100644
14250--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14251+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14252@@ -21,6 +21,7 @@
14253 */
14254
14255 #include <linux/linkage.h>
14256+#include <asm/alternative-asm.h>
14257
14258 .file "twofish-x86_64-asm-3way.S"
14259 .text
14260@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14261 popq %r13;
14262 popq %r14;
14263 popq %r15;
14264+ pax_force_retaddr
14265 ret;
14266
14267 .L__enc_xor3:
14268@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14269 popq %r13;
14270 popq %r14;
14271 popq %r15;
14272+ pax_force_retaddr
14273 ret;
14274 ENDPROC(__twofish_enc_blk_3way)
14275
14276@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14277 popq %r13;
14278 popq %r14;
14279 popq %r15;
14280+ pax_force_retaddr
14281 ret;
14282 ENDPROC(twofish_dec_blk_3way)
14283diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14284index a039d21..524b8b2 100644
14285--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14286+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14287@@ -22,6 +22,7 @@
14288
14289 #include <linux/linkage.h>
14290 #include <asm/asm-offsets.h>
14291+#include <asm/alternative-asm.h>
14292
14293 #define a_offset 0
14294 #define b_offset 4
14295@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14296
14297 popq R1
14298 movq $1,%rax
14299+ pax_force_retaddr
14300 ret
14301 ENDPROC(twofish_enc_blk)
14302
14303@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14304
14305 popq R1
14306 movq $1,%rax
14307+ pax_force_retaddr
14308 ret
14309 ENDPROC(twofish_dec_blk)
14310diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14311index d21ff89..6da8e6e 100644
14312--- a/arch/x86/ia32/ia32_aout.c
14313+++ b/arch/x86/ia32/ia32_aout.c
14314@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14315 unsigned long dump_start, dump_size;
14316 struct user32 dump;
14317
14318+ memset(&dump, 0, sizeof(dump));
14319+
14320 fs = get_fs();
14321 set_fs(KERNEL_DS);
14322 has_dumped = 1;
14323diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14324index 2206757..85cbcfa 100644
14325--- a/arch/x86/ia32/ia32_signal.c
14326+++ b/arch/x86/ia32/ia32_signal.c
14327@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14328 if (__get_user(set.sig[0], &frame->sc.oldmask)
14329 || (_COMPAT_NSIG_WORDS > 1
14330 && __copy_from_user((((char *) &set.sig) + 4),
14331- &frame->extramask,
14332+ frame->extramask,
14333 sizeof(frame->extramask))))
14334 goto badframe;
14335
14336@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14337 sp -= frame_size;
14338 /* Align the stack pointer according to the i386 ABI,
14339 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14340- sp = ((sp + 4) & -16ul) - 4;
14341+ sp = ((sp - 12) & -16ul) - 4;
14342 return (void __user *) sp;
14343 }
14344
14345@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14346 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14347 sigreturn);
14348 else
14349- restorer = &frame->retcode;
14350+ restorer = frame->retcode;
14351 }
14352
14353 put_user_try {
14354@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14355 * These are actually not used anymore, but left because some
14356 * gdb versions depend on them as a marker.
14357 */
14358- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14359+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14360 } put_user_catch(err);
14361
14362 if (err)
14363@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14364 0xb8,
14365 __NR_ia32_rt_sigreturn,
14366 0x80cd,
14367- 0,
14368+ 0
14369 };
14370
14371 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14372@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14373
14374 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14375 restorer = ksig->ka.sa.sa_restorer;
14376+ else if (current->mm->context.vdso)
14377+ /* Return stub is in 32bit vsyscall page */
14378+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14379 else
14380- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14381- rt_sigreturn);
14382+ restorer = frame->retcode;
14383 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14384
14385 /*
14386 * Not actually used anymore, but left because some gdb
14387 * versions need it.
14388 */
14389- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14390+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14391 } put_user_catch(err);
14392
14393 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14394diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14395index 4299eb0..c0687a7 100644
14396--- a/arch/x86/ia32/ia32entry.S
14397+++ b/arch/x86/ia32/ia32entry.S
14398@@ -15,8 +15,10 @@
14399 #include <asm/irqflags.h>
14400 #include <asm/asm.h>
14401 #include <asm/smap.h>
14402+#include <asm/pgtable.h>
14403 #include <linux/linkage.h>
14404 #include <linux/err.h>
14405+#include <asm/alternative-asm.h>
14406
14407 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14408 #include <linux/elf-em.h>
14409@@ -62,12 +64,12 @@
14410 */
14411 .macro LOAD_ARGS32 offset, _r9=0
14412 .if \_r9
14413- movl \offset+16(%rsp),%r9d
14414+ movl \offset+R9(%rsp),%r9d
14415 .endif
14416- movl \offset+40(%rsp),%ecx
14417- movl \offset+48(%rsp),%edx
14418- movl \offset+56(%rsp),%esi
14419- movl \offset+64(%rsp),%edi
14420+ movl \offset+RCX(%rsp),%ecx
14421+ movl \offset+RDX(%rsp),%edx
14422+ movl \offset+RSI(%rsp),%esi
14423+ movl \offset+RDI(%rsp),%edi
14424 movl %eax,%eax /* zero extension */
14425 .endm
14426
14427@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14428 ENDPROC(native_irq_enable_sysexit)
14429 #endif
14430
14431+ .macro pax_enter_kernel_user
14432+ pax_set_fptr_mask
14433+#ifdef CONFIG_PAX_MEMORY_UDEREF
14434+ call pax_enter_kernel_user
14435+#endif
14436+ .endm
14437+
14438+ .macro pax_exit_kernel_user
14439+#ifdef CONFIG_PAX_MEMORY_UDEREF
14440+ call pax_exit_kernel_user
14441+#endif
14442+#ifdef CONFIG_PAX_RANDKSTACK
14443+ pushq %rax
14444+ pushq %r11
14445+ call pax_randomize_kstack
14446+ popq %r11
14447+ popq %rax
14448+#endif
14449+ .endm
14450+
14451+ .macro pax_erase_kstack
14452+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14453+ call pax_erase_kstack
14454+#endif
14455+ .endm
14456+
14457 /*
14458 * 32bit SYSENTER instruction entry.
14459 *
14460@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14461 CFI_REGISTER rsp,rbp
14462 SWAPGS_UNSAFE_STACK
14463 movq PER_CPU_VAR(kernel_stack), %rsp
14464- addq $(KERNEL_STACK_OFFSET),%rsp
14465- /*
14466- * No need to follow this irqs on/off section: the syscall
14467- * disabled irqs, here we enable it straight after entry:
14468- */
14469- ENABLE_INTERRUPTS(CLBR_NONE)
14470 movl %ebp,%ebp /* zero extension */
14471 pushq_cfi $__USER32_DS
14472 /*CFI_REL_OFFSET ss,0*/
14473@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14474 CFI_REL_OFFSET rsp,0
14475 pushfq_cfi
14476 /*CFI_REL_OFFSET rflags,0*/
14477- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14478- CFI_REGISTER rip,r10
14479+ orl $X86_EFLAGS_IF,(%rsp)
14480+ GET_THREAD_INFO(%r11)
14481+ movl TI_sysenter_return(%r11), %r11d
14482+ CFI_REGISTER rip,r11
14483 pushq_cfi $__USER32_CS
14484 /*CFI_REL_OFFSET cs,0*/
14485 movl %eax, %eax
14486- pushq_cfi %r10
14487+ pushq_cfi %r11
14488 CFI_REL_OFFSET rip,0
14489 pushq_cfi %rax
14490 cld
14491 SAVE_ARGS 0,1,0
14492+ pax_enter_kernel_user
14493+
14494+#ifdef CONFIG_PAX_RANDKSTACK
14495+ pax_erase_kstack
14496+#endif
14497+
14498+ /*
14499+ * No need to follow this irqs on/off section: the syscall
14500+ * disabled irqs, here we enable it straight after entry:
14501+ */
14502+ ENABLE_INTERRUPTS(CLBR_NONE)
14503 /* no need to do an access_ok check here because rbp has been
14504 32bit zero extended */
14505+
14506+#ifdef CONFIG_PAX_MEMORY_UDEREF
14507+ addq pax_user_shadow_base,%rbp
14508+ ASM_PAX_OPEN_USERLAND
14509+#endif
14510+
14511 ASM_STAC
14512 1: movl (%rbp),%ebp
14513 _ASM_EXTABLE(1b,ia32_badarg)
14514 ASM_CLAC
14515- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14516- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14517+
14518+#ifdef CONFIG_PAX_MEMORY_UDEREF
14519+ ASM_PAX_CLOSE_USERLAND
14520+#endif
14521+
14522+ GET_THREAD_INFO(%r11)
14523+ orl $TS_COMPAT,TI_status(%r11)
14524+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14525 CFI_REMEMBER_STATE
14526 jnz sysenter_tracesys
14527 cmpq $(IA32_NR_syscalls-1),%rax
14528@@ -162,15 +209,18 @@ sysenter_do_call:
14529 sysenter_dispatch:
14530 call *ia32_sys_call_table(,%rax,8)
14531 movq %rax,RAX-ARGOFFSET(%rsp)
14532+ GET_THREAD_INFO(%r11)
14533 DISABLE_INTERRUPTS(CLBR_NONE)
14534 TRACE_IRQS_OFF
14535- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14536+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14537 jnz sysexit_audit
14538 sysexit_from_sys_call:
14539- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14540+ pax_exit_kernel_user
14541+ pax_erase_kstack
14542+ andl $~TS_COMPAT,TI_status(%r11)
14543 /* clear IF, that popfq doesn't enable interrupts early */
14544- andl $~0x200,EFLAGS-R11(%rsp)
14545- movl RIP-R11(%rsp),%edx /* User %eip */
14546+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14547+ movl RIP(%rsp),%edx /* User %eip */
14548 CFI_REGISTER rip,rdx
14549 RESTORE_ARGS 0,24,0,0,0,0
14550 xorq %r8,%r8
14551@@ -193,6 +243,9 @@ sysexit_from_sys_call:
14552 movl %eax,%esi /* 2nd arg: syscall number */
14553 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14554 call __audit_syscall_entry
14555+
14556+ pax_erase_kstack
14557+
14558 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14559 cmpq $(IA32_NR_syscalls-1),%rax
14560 ja ia32_badsys
14561@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14562 .endm
14563
14564 .macro auditsys_exit exit
14565- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14566+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14567 jnz ia32_ret_from_sys_call
14568 TRACE_IRQS_ON
14569 ENABLE_INTERRUPTS(CLBR_NONE)
14570@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14571 1: setbe %al /* 1 if error, 0 if not */
14572 movzbl %al,%edi /* zero-extend that into %edi */
14573 call __audit_syscall_exit
14574+ GET_THREAD_INFO(%r11)
14575 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14576 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14577 DISABLE_INTERRUPTS(CLBR_NONE)
14578 TRACE_IRQS_OFF
14579- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14580+ testl %edi,TI_flags(%r11)
14581 jz \exit
14582 CLEAR_RREGS -ARGOFFSET
14583 jmp int_with_check
14584@@ -237,7 +291,7 @@ sysexit_audit:
14585
14586 sysenter_tracesys:
14587 #ifdef CONFIG_AUDITSYSCALL
14588- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14589+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14590 jz sysenter_auditsys
14591 #endif
14592 SAVE_REST
14593@@ -249,6 +303,9 @@ sysenter_tracesys:
14594 RESTORE_REST
14595 cmpq $(IA32_NR_syscalls-1),%rax
14596 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14597+
14598+ pax_erase_kstack
14599+
14600 jmp sysenter_do_call
14601 CFI_ENDPROC
14602 ENDPROC(ia32_sysenter_target)
14603@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14604 ENTRY(ia32_cstar_target)
14605 CFI_STARTPROC32 simple
14606 CFI_SIGNAL_FRAME
14607- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14608+ CFI_DEF_CFA rsp,0
14609 CFI_REGISTER rip,rcx
14610 /*CFI_REGISTER rflags,r11*/
14611 SWAPGS_UNSAFE_STACK
14612 movl %esp,%r8d
14613 CFI_REGISTER rsp,r8
14614 movq PER_CPU_VAR(kernel_stack),%rsp
14615+ SAVE_ARGS 8*6,0,0
14616+ pax_enter_kernel_user
14617+
14618+#ifdef CONFIG_PAX_RANDKSTACK
14619+ pax_erase_kstack
14620+#endif
14621+
14622 /*
14623 * No need to follow this irqs on/off section: the syscall
14624 * disabled irqs and here we enable it straight after entry:
14625 */
14626 ENABLE_INTERRUPTS(CLBR_NONE)
14627- SAVE_ARGS 8,0,0
14628 movl %eax,%eax /* zero extension */
14629 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14630 movq %rcx,RIP-ARGOFFSET(%rsp)
14631@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14632 /* no need to do an access_ok check here because r8 has been
14633 32bit zero extended */
14634 /* hardware stack frame is complete now */
14635+
14636+#ifdef CONFIG_PAX_MEMORY_UDEREF
14637+ ASM_PAX_OPEN_USERLAND
14638+ movq pax_user_shadow_base,%r8
14639+ addq RSP-ARGOFFSET(%rsp),%r8
14640+#endif
14641+
14642 ASM_STAC
14643 1: movl (%r8),%r9d
14644 _ASM_EXTABLE(1b,ia32_badarg)
14645 ASM_CLAC
14646- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14647- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14648+
14649+#ifdef CONFIG_PAX_MEMORY_UDEREF
14650+ ASM_PAX_CLOSE_USERLAND
14651+#endif
14652+
14653+ GET_THREAD_INFO(%r11)
14654+ orl $TS_COMPAT,TI_status(%r11)
14655+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14656 CFI_REMEMBER_STATE
14657 jnz cstar_tracesys
14658 cmpq $IA32_NR_syscalls-1,%rax
14659@@ -319,13 +395,16 @@ cstar_do_call:
14660 cstar_dispatch:
14661 call *ia32_sys_call_table(,%rax,8)
14662 movq %rax,RAX-ARGOFFSET(%rsp)
14663+ GET_THREAD_INFO(%r11)
14664 DISABLE_INTERRUPTS(CLBR_NONE)
14665 TRACE_IRQS_OFF
14666- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14667+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14668 jnz sysretl_audit
14669 sysretl_from_sys_call:
14670- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14671- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14672+ pax_exit_kernel_user
14673+ pax_erase_kstack
14674+ andl $~TS_COMPAT,TI_status(%r11)
14675+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14676 movl RIP-ARGOFFSET(%rsp),%ecx
14677 CFI_REGISTER rip,rcx
14678 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14679@@ -352,7 +431,7 @@ sysretl_audit:
14680
14681 cstar_tracesys:
14682 #ifdef CONFIG_AUDITSYSCALL
14683- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14684+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14685 jz cstar_auditsys
14686 #endif
14687 xchgl %r9d,%ebp
14688@@ -366,11 +445,19 @@ cstar_tracesys:
14689 xchgl %ebp,%r9d
14690 cmpq $(IA32_NR_syscalls-1),%rax
14691 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14692+
14693+ pax_erase_kstack
14694+
14695 jmp cstar_do_call
14696 END(ia32_cstar_target)
14697
14698 ia32_badarg:
14699 ASM_CLAC
14700+
14701+#ifdef CONFIG_PAX_MEMORY_UDEREF
14702+ ASM_PAX_CLOSE_USERLAND
14703+#endif
14704+
14705 movq $-EFAULT,%rax
14706 jmp ia32_sysret
14707 CFI_ENDPROC
14708@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14709 CFI_REL_OFFSET rip,RIP-RIP
14710 PARAVIRT_ADJUST_EXCEPTION_FRAME
14711 SWAPGS
14712- /*
14713- * No need to follow this irqs on/off section: the syscall
14714- * disabled irqs and here we enable it straight after entry:
14715- */
14716- ENABLE_INTERRUPTS(CLBR_NONE)
14717 movl %eax,%eax
14718 pushq_cfi %rax
14719 cld
14720 /* note the registers are not zero extended to the sf.
14721 this could be a problem. */
14722 SAVE_ARGS 0,1,0
14723- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14724- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14725+ pax_enter_kernel_user
14726+
14727+#ifdef CONFIG_PAX_RANDKSTACK
14728+ pax_erase_kstack
14729+#endif
14730+
14731+ /*
14732+ * No need to follow this irqs on/off section: the syscall
14733+ * disabled irqs and here we enable it straight after entry:
14734+ */
14735+ ENABLE_INTERRUPTS(CLBR_NONE)
14736+ GET_THREAD_INFO(%r11)
14737+ orl $TS_COMPAT,TI_status(%r11)
14738+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14739 jnz ia32_tracesys
14740 cmpq $(IA32_NR_syscalls-1),%rax
14741 ja ia32_badsys
14742@@ -442,6 +536,9 @@ ia32_tracesys:
14743 RESTORE_REST
14744 cmpq $(IA32_NR_syscalls-1),%rax
14745 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14746+
14747+ pax_erase_kstack
14748+
14749 jmp ia32_do_call
14750 END(ia32_syscall)
14751
14752diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14753index 8e0ceec..af13504 100644
14754--- a/arch/x86/ia32/sys_ia32.c
14755+++ b/arch/x86/ia32/sys_ia32.c
14756@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14757 */
14758 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14759 {
14760- typeof(ubuf->st_uid) uid = 0;
14761- typeof(ubuf->st_gid) gid = 0;
14762+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
14763+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
14764 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14765 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14766 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14767diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14768index 372231c..51b537d 100644
14769--- a/arch/x86/include/asm/alternative-asm.h
14770+++ b/arch/x86/include/asm/alternative-asm.h
14771@@ -18,6 +18,45 @@
14772 .endm
14773 #endif
14774
14775+#ifdef KERNEXEC_PLUGIN
14776+ .macro pax_force_retaddr_bts rip=0
14777+ btsq $63,\rip(%rsp)
14778+ .endm
14779+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14780+ .macro pax_force_retaddr rip=0, reload=0
14781+ btsq $63,\rip(%rsp)
14782+ .endm
14783+ .macro pax_force_fptr ptr
14784+ btsq $63,\ptr
14785+ .endm
14786+ .macro pax_set_fptr_mask
14787+ .endm
14788+#endif
14789+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14790+ .macro pax_force_retaddr rip=0, reload=0
14791+ .if \reload
14792+ pax_set_fptr_mask
14793+ .endif
14794+ orq %r12,\rip(%rsp)
14795+ .endm
14796+ .macro pax_force_fptr ptr
14797+ orq %r12,\ptr
14798+ .endm
14799+ .macro pax_set_fptr_mask
14800+ movabs $0x8000000000000000,%r12
14801+ .endm
14802+#endif
14803+#else
14804+ .macro pax_force_retaddr rip=0, reload=0
14805+ .endm
14806+ .macro pax_force_fptr ptr
14807+ .endm
14808+ .macro pax_force_retaddr_bts rip=0
14809+ .endm
14810+ .macro pax_set_fptr_mask
14811+ .endm
14812+#endif
14813+
14814 .macro altinstruction_entry orig alt feature orig_len alt_len
14815 .long \orig - .
14816 .long \alt - .
14817diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14818index 0a3f9c9..c9d081d 100644
14819--- a/arch/x86/include/asm/alternative.h
14820+++ b/arch/x86/include/asm/alternative.h
14821@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14822 ".pushsection .discard,\"aw\",@progbits\n" \
14823 DISCARD_ENTRY(1) \
14824 ".popsection\n" \
14825- ".pushsection .altinstr_replacement, \"ax\"\n" \
14826+ ".pushsection .altinstr_replacement, \"a\"\n" \
14827 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14828 ".popsection"
14829
14830@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14831 DISCARD_ENTRY(1) \
14832 DISCARD_ENTRY(2) \
14833 ".popsection\n" \
14834- ".pushsection .altinstr_replacement, \"ax\"\n" \
14835+ ".pushsection .altinstr_replacement, \"a\"\n" \
14836 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14837 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14838 ".popsection"
14839diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14840index 19b0eba..12254cd 100644
14841--- a/arch/x86/include/asm/apic.h
14842+++ b/arch/x86/include/asm/apic.h
14843@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14844
14845 #ifdef CONFIG_X86_LOCAL_APIC
14846
14847-extern unsigned int apic_verbosity;
14848+extern int apic_verbosity;
14849 extern int local_apic_timer_c2_ok;
14850
14851 extern int disable_apic;
14852diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14853index 20370c6..a2eb9b0 100644
14854--- a/arch/x86/include/asm/apm.h
14855+++ b/arch/x86/include/asm/apm.h
14856@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14857 __asm__ __volatile__(APM_DO_ZERO_SEGS
14858 "pushl %%edi\n\t"
14859 "pushl %%ebp\n\t"
14860- "lcall *%%cs:apm_bios_entry\n\t"
14861+ "lcall *%%ss:apm_bios_entry\n\t"
14862 "setc %%al\n\t"
14863 "popl %%ebp\n\t"
14864 "popl %%edi\n\t"
14865@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14866 __asm__ __volatile__(APM_DO_ZERO_SEGS
14867 "pushl %%edi\n\t"
14868 "pushl %%ebp\n\t"
14869- "lcall *%%cs:apm_bios_entry\n\t"
14870+ "lcall *%%ss:apm_bios_entry\n\t"
14871 "setc %%bl\n\t"
14872 "popl %%ebp\n\t"
14873 "popl %%edi\n\t"
14874diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14875index b17f4f4..9620151 100644
14876--- a/arch/x86/include/asm/atomic.h
14877+++ b/arch/x86/include/asm/atomic.h
14878@@ -23,7 +23,18 @@
14879 */
14880 static inline int atomic_read(const atomic_t *v)
14881 {
14882- return (*(volatile int *)&(v)->counter);
14883+ return (*(volatile const int *)&(v)->counter);
14884+}
14885+
14886+/**
14887+ * atomic_read_unchecked - read atomic variable
14888+ * @v: pointer of type atomic_unchecked_t
14889+ *
14890+ * Atomically reads the value of @v.
14891+ */
14892+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14893+{
14894+ return (*(volatile const int *)&(v)->counter);
14895 }
14896
14897 /**
14898@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14899 }
14900
14901 /**
14902+ * atomic_set_unchecked - set atomic variable
14903+ * @v: pointer of type atomic_unchecked_t
14904+ * @i: required value
14905+ *
14906+ * Atomically sets the value of @v to @i.
14907+ */
14908+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14909+{
14910+ v->counter = i;
14911+}
14912+
14913+/**
14914 * atomic_add - add integer to atomic variable
14915 * @i: integer value to add
14916 * @v: pointer of type atomic_t
14917@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14918 */
14919 static inline void atomic_add(int i, atomic_t *v)
14920 {
14921- asm volatile(LOCK_PREFIX "addl %1,%0"
14922+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14923+
14924+#ifdef CONFIG_PAX_REFCOUNT
14925+ "jno 0f\n"
14926+ LOCK_PREFIX "subl %1,%0\n"
14927+ "int $4\n0:\n"
14928+ _ASM_EXTABLE(0b, 0b)
14929+#endif
14930+
14931+ : "+m" (v->counter)
14932+ : "ir" (i));
14933+}
14934+
14935+/**
14936+ * atomic_add_unchecked - add integer to atomic variable
14937+ * @i: integer value to add
14938+ * @v: pointer of type atomic_unchecked_t
14939+ *
14940+ * Atomically adds @i to @v.
14941+ */
14942+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14943+{
14944+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14945 : "+m" (v->counter)
14946 : "ir" (i));
14947 }
14948@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14949 */
14950 static inline void atomic_sub(int i, atomic_t *v)
14951 {
14952- asm volatile(LOCK_PREFIX "subl %1,%0"
14953+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14954+
14955+#ifdef CONFIG_PAX_REFCOUNT
14956+ "jno 0f\n"
14957+ LOCK_PREFIX "addl %1,%0\n"
14958+ "int $4\n0:\n"
14959+ _ASM_EXTABLE(0b, 0b)
14960+#endif
14961+
14962+ : "+m" (v->counter)
14963+ : "ir" (i));
14964+}
14965+
14966+/**
14967+ * atomic_sub_unchecked - subtract integer from atomic variable
14968+ * @i: integer value to subtract
14969+ * @v: pointer of type atomic_unchecked_t
14970+ *
14971+ * Atomically subtracts @i from @v.
14972+ */
14973+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14974+{
14975+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14976 : "+m" (v->counter)
14977 : "ir" (i));
14978 }
14979@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14980 */
14981 static inline int atomic_sub_and_test(int i, atomic_t *v)
14982 {
14983- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14984+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14985 }
14986
14987 /**
14988@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14989 */
14990 static inline void atomic_inc(atomic_t *v)
14991 {
14992- asm volatile(LOCK_PREFIX "incl %0"
14993+ asm volatile(LOCK_PREFIX "incl %0\n"
14994+
14995+#ifdef CONFIG_PAX_REFCOUNT
14996+ "jno 0f\n"
14997+ LOCK_PREFIX "decl %0\n"
14998+ "int $4\n0:\n"
14999+ _ASM_EXTABLE(0b, 0b)
15000+#endif
15001+
15002+ : "+m" (v->counter));
15003+}
15004+
15005+/**
15006+ * atomic_inc_unchecked - increment atomic variable
15007+ * @v: pointer of type atomic_unchecked_t
15008+ *
15009+ * Atomically increments @v by 1.
15010+ */
15011+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15012+{
15013+ asm volatile(LOCK_PREFIX "incl %0\n"
15014 : "+m" (v->counter));
15015 }
15016
15017@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
15018 */
15019 static inline void atomic_dec(atomic_t *v)
15020 {
15021- asm volatile(LOCK_PREFIX "decl %0"
15022+ asm volatile(LOCK_PREFIX "decl %0\n"
15023+
15024+#ifdef CONFIG_PAX_REFCOUNT
15025+ "jno 0f\n"
15026+ LOCK_PREFIX "incl %0\n"
15027+ "int $4\n0:\n"
15028+ _ASM_EXTABLE(0b, 0b)
15029+#endif
15030+
15031+ : "+m" (v->counter));
15032+}
15033+
15034+/**
15035+ * atomic_dec_unchecked - decrement atomic variable
15036+ * @v: pointer of type atomic_unchecked_t
15037+ *
15038+ * Atomically decrements @v by 1.
15039+ */
15040+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15041+{
15042+ asm volatile(LOCK_PREFIX "decl %0\n"
15043 : "+m" (v->counter));
15044 }
15045
15046@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15047 */
15048 static inline int atomic_dec_and_test(atomic_t *v)
15049 {
15050- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15051+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15052 }
15053
15054 /**
15055@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15056 */
15057 static inline int atomic_inc_and_test(atomic_t *v)
15058 {
15059- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15060+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15061+}
15062+
15063+/**
15064+ * atomic_inc_and_test_unchecked - increment and test
15065+ * @v: pointer of type atomic_unchecked_t
15066+ *
15067+ * Atomically increments @v by 1
15068+ * and returns true if the result is zero, or false for all
15069+ * other cases.
15070+ */
15071+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15072+{
15073+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15074 }
15075
15076 /**
15077@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15078 */
15079 static inline int atomic_add_negative(int i, atomic_t *v)
15080 {
15081- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15082+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15083 }
15084
15085 /**
15086@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15087 */
15088 static inline int atomic_add_return(int i, atomic_t *v)
15089 {
15090+ return i + xadd_check_overflow(&v->counter, i);
15091+}
15092+
15093+/**
15094+ * atomic_add_return_unchecked - add integer and return
15095+ * @i: integer value to add
15096+ * @v: pointer of type atomic_unchecked_t
15097+ *
15098+ * Atomically adds @i to @v and returns @i + @v
15099+ */
15100+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15101+{
15102 return i + xadd(&v->counter, i);
15103 }
15104
15105@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15106 }
15107
15108 #define atomic_inc_return(v) (atomic_add_return(1, v))
15109+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15110+{
15111+ return atomic_add_return_unchecked(1, v);
15112+}
15113 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15114
15115-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15116+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15117+{
15118+ return cmpxchg(&v->counter, old, new);
15119+}
15120+
15121+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15122 {
15123 return cmpxchg(&v->counter, old, new);
15124 }
15125@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15126 return xchg(&v->counter, new);
15127 }
15128
15129+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15130+{
15131+ return xchg(&v->counter, new);
15132+}
15133+
15134 /**
15135 * __atomic_add_unless - add unless the number is already a given value
15136 * @v: pointer of type atomic_t
15137@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15138 * Atomically adds @a to @v, so long as @v was not already @u.
15139 * Returns the old value of @v.
15140 */
15141-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15142+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15143 {
15144- int c, old;
15145+ int c, old, new;
15146 c = atomic_read(v);
15147 for (;;) {
15148- if (unlikely(c == (u)))
15149+ if (unlikely(c == u))
15150 break;
15151- old = atomic_cmpxchg((v), c, c + (a));
15152+
15153+ asm volatile("addl %2,%0\n"
15154+
15155+#ifdef CONFIG_PAX_REFCOUNT
15156+ "jno 0f\n"
15157+ "subl %2,%0\n"
15158+ "int $4\n0:\n"
15159+ _ASM_EXTABLE(0b, 0b)
15160+#endif
15161+
15162+ : "=r" (new)
15163+ : "0" (c), "ir" (a));
15164+
15165+ old = atomic_cmpxchg(v, c, new);
15166 if (likely(old == c))
15167 break;
15168 c = old;
15169@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15170 }
15171
15172 /**
15173+ * atomic_inc_not_zero_hint - increment if not null
15174+ * @v: pointer of type atomic_t
15175+ * @hint: probable value of the atomic before the increment
15176+ *
15177+ * This version of atomic_inc_not_zero() gives a hint of probable
15178+ * value of the atomic. This helps processor to not read the memory
15179+ * before doing the atomic read/modify/write cycle, lowering
15180+ * number of bus transactions on some arches.
15181+ *
15182+ * Returns: 0 if increment was not done, 1 otherwise.
15183+ */
15184+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15185+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15186+{
15187+ int val, c = hint, new;
15188+
15189+ /* sanity test, should be removed by compiler if hint is a constant */
15190+ if (!hint)
15191+ return __atomic_add_unless(v, 1, 0);
15192+
15193+ do {
15194+ asm volatile("incl %0\n"
15195+
15196+#ifdef CONFIG_PAX_REFCOUNT
15197+ "jno 0f\n"
15198+ "decl %0\n"
15199+ "int $4\n0:\n"
15200+ _ASM_EXTABLE(0b, 0b)
15201+#endif
15202+
15203+ : "=r" (new)
15204+ : "0" (c));
15205+
15206+ val = atomic_cmpxchg(v, c, new);
15207+ if (val == c)
15208+ return 1;
15209+ c = val;
15210+ } while (c);
15211+
15212+ return 0;
15213+}
15214+
15215+/**
15216 * atomic_inc_short - increment of a short integer
15217 * @v: pointer to type int
15218 *
15219@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15220 #endif
15221
15222 /* These are x86-specific, used by some header files */
15223-#define atomic_clear_mask(mask, addr) \
15224- asm volatile(LOCK_PREFIX "andl %0,%1" \
15225- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15226+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15227+{
15228+ asm volatile(LOCK_PREFIX "andl %1,%0"
15229+ : "+m" (v->counter)
15230+ : "r" (~(mask))
15231+ : "memory");
15232+}
15233
15234-#define atomic_set_mask(mask, addr) \
15235- asm volatile(LOCK_PREFIX "orl %0,%1" \
15236- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15237- : "memory")
15238+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15239+{
15240+ asm volatile(LOCK_PREFIX "andl %1,%0"
15241+ : "+m" (v->counter)
15242+ : "r" (~(mask))
15243+ : "memory");
15244+}
15245+
15246+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15247+{
15248+ asm volatile(LOCK_PREFIX "orl %1,%0"
15249+ : "+m" (v->counter)
15250+ : "r" (mask)
15251+ : "memory");
15252+}
15253+
15254+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15255+{
15256+ asm volatile(LOCK_PREFIX "orl %1,%0"
15257+ : "+m" (v->counter)
15258+ : "r" (mask)
15259+ : "memory");
15260+}
15261
15262 /* Atomic operations are already serializing on x86 */
15263 #define smp_mb__before_atomic_dec() barrier()
15264diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15265index b154de7..bf18a5a 100644
15266--- a/arch/x86/include/asm/atomic64_32.h
15267+++ b/arch/x86/include/asm/atomic64_32.h
15268@@ -12,6 +12,14 @@ typedef struct {
15269 u64 __aligned(8) counter;
15270 } atomic64_t;
15271
15272+#ifdef CONFIG_PAX_REFCOUNT
15273+typedef struct {
15274+ u64 __aligned(8) counter;
15275+} atomic64_unchecked_t;
15276+#else
15277+typedef atomic64_t atomic64_unchecked_t;
15278+#endif
15279+
15280 #define ATOMIC64_INIT(val) { (val) }
15281
15282 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15283@@ -37,21 +45,31 @@ typedef struct {
15284 ATOMIC64_DECL_ONE(sym##_386)
15285
15286 ATOMIC64_DECL_ONE(add_386);
15287+ATOMIC64_DECL_ONE(add_unchecked_386);
15288 ATOMIC64_DECL_ONE(sub_386);
15289+ATOMIC64_DECL_ONE(sub_unchecked_386);
15290 ATOMIC64_DECL_ONE(inc_386);
15291+ATOMIC64_DECL_ONE(inc_unchecked_386);
15292 ATOMIC64_DECL_ONE(dec_386);
15293+ATOMIC64_DECL_ONE(dec_unchecked_386);
15294 #endif
15295
15296 #define alternative_atomic64(f, out, in...) \
15297 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15298
15299 ATOMIC64_DECL(read);
15300+ATOMIC64_DECL(read_unchecked);
15301 ATOMIC64_DECL(set);
15302+ATOMIC64_DECL(set_unchecked);
15303 ATOMIC64_DECL(xchg);
15304 ATOMIC64_DECL(add_return);
15305+ATOMIC64_DECL(add_return_unchecked);
15306 ATOMIC64_DECL(sub_return);
15307+ATOMIC64_DECL(sub_return_unchecked);
15308 ATOMIC64_DECL(inc_return);
15309+ATOMIC64_DECL(inc_return_unchecked);
15310 ATOMIC64_DECL(dec_return);
15311+ATOMIC64_DECL(dec_return_unchecked);
15312 ATOMIC64_DECL(dec_if_positive);
15313 ATOMIC64_DECL(inc_not_zero);
15314 ATOMIC64_DECL(add_unless);
15315@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15316 }
15317
15318 /**
15319+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15320+ * @p: pointer to type atomic64_unchecked_t
15321+ * @o: expected value
15322+ * @n: new value
15323+ *
15324+ * Atomically sets @v to @n if it was equal to @o and returns
15325+ * the old value.
15326+ */
15327+
15328+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15329+{
15330+ return cmpxchg64(&v->counter, o, n);
15331+}
15332+
15333+/**
15334 * atomic64_xchg - xchg atomic64 variable
15335 * @v: pointer to type atomic64_t
15336 * @n: value to assign
15337@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15338 }
15339
15340 /**
15341+ * atomic64_set_unchecked - set atomic64 variable
15342+ * @v: pointer to type atomic64_unchecked_t
15343+ * @n: value to assign
15344+ *
15345+ * Atomically sets the value of @v to @n.
15346+ */
15347+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15348+{
15349+ unsigned high = (unsigned)(i >> 32);
15350+ unsigned low = (unsigned)i;
15351+ alternative_atomic64(set, /* no output */,
15352+ "S" (v), "b" (low), "c" (high)
15353+ : "eax", "edx", "memory");
15354+}
15355+
15356+/**
15357 * atomic64_read - read atomic64 variable
15358 * @v: pointer to type atomic64_t
15359 *
15360@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15361 }
15362
15363 /**
15364+ * atomic64_read_unchecked - read atomic64 variable
15365+ * @v: pointer to type atomic64_unchecked_t
15366+ *
15367+ * Atomically reads the value of @v and returns it.
15368+ */
15369+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15370+{
15371+ long long r;
15372+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15373+ return r;
15374+ }
15375+
15376+/**
15377 * atomic64_add_return - add and return
15378 * @i: integer value to add
15379 * @v: pointer to type atomic64_t
15380@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15381 return i;
15382 }
15383
15384+/**
15385+ * atomic64_add_return_unchecked - add and return
15386+ * @i: integer value to add
15387+ * @v: pointer to type atomic64_unchecked_t
15388+ *
15389+ * Atomically adds @i to @v and returns @i + *@v
15390+ */
15391+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15392+{
15393+ alternative_atomic64(add_return_unchecked,
15394+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15395+ ASM_NO_INPUT_CLOBBER("memory"));
15396+ return i;
15397+}
15398+
15399 /*
15400 * Other variants with different arithmetic operators:
15401 */
15402@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15403 return a;
15404 }
15405
15406+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15407+{
15408+ long long a;
15409+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15410+ "S" (v) : "memory", "ecx");
15411+ return a;
15412+}
15413+
15414 static inline long long atomic64_dec_return(atomic64_t *v)
15415 {
15416 long long a;
15417@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15418 }
15419
15420 /**
15421+ * atomic64_add_unchecked - add integer to atomic64 variable
15422+ * @i: integer value to add
15423+ * @v: pointer to type atomic64_unchecked_t
15424+ *
15425+ * Atomically adds @i to @v.
15426+ */
15427+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15428+{
15429+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15430+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15431+ ASM_NO_INPUT_CLOBBER("memory"));
15432+ return i;
15433+}
15434+
15435+/**
15436 * atomic64_sub - subtract the atomic64 variable
15437 * @i: integer value to subtract
15438 * @v: pointer to type atomic64_t
15439diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15440index 46e9052..ae45136 100644
15441--- a/arch/x86/include/asm/atomic64_64.h
15442+++ b/arch/x86/include/asm/atomic64_64.h
15443@@ -18,7 +18,19 @@
15444 */
15445 static inline long atomic64_read(const atomic64_t *v)
15446 {
15447- return (*(volatile long *)&(v)->counter);
15448+ return (*(volatile const long *)&(v)->counter);
15449+}
15450+
15451+/**
15452+ * atomic64_read_unchecked - read atomic64 variable
15453+ * @v: pointer of type atomic64_unchecked_t
15454+ *
15455+ * Atomically reads the value of @v.
15456+ * Doesn't imply a read memory barrier.
15457+ */
15458+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15459+{
15460+ return (*(volatile const long *)&(v)->counter);
15461 }
15462
15463 /**
15464@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15465 }
15466
15467 /**
15468+ * atomic64_set_unchecked - set atomic64 variable
15469+ * @v: pointer to type atomic64_unchecked_t
15470+ * @i: required value
15471+ *
15472+ * Atomically sets the value of @v to @i.
15473+ */
15474+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15475+{
15476+ v->counter = i;
15477+}
15478+
15479+/**
15480 * atomic64_add - add integer to atomic64 variable
15481 * @i: integer value to add
15482 * @v: pointer to type atomic64_t
15483@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15484 */
15485 static inline void atomic64_add(long i, atomic64_t *v)
15486 {
15487+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15488+
15489+#ifdef CONFIG_PAX_REFCOUNT
15490+ "jno 0f\n"
15491+ LOCK_PREFIX "subq %1,%0\n"
15492+ "int $4\n0:\n"
15493+ _ASM_EXTABLE(0b, 0b)
15494+#endif
15495+
15496+ : "=m" (v->counter)
15497+ : "er" (i), "m" (v->counter));
15498+}
15499+
15500+/**
15501+ * atomic64_add_unchecked - add integer to atomic64 variable
15502+ * @i: integer value to add
15503+ * @v: pointer to type atomic64_unchecked_t
15504+ *
15505+ * Atomically adds @i to @v.
15506+ */
15507+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15508+{
15509 asm volatile(LOCK_PREFIX "addq %1,%0"
15510 : "=m" (v->counter)
15511 : "er" (i), "m" (v->counter));
15512@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15513 */
15514 static inline void atomic64_sub(long i, atomic64_t *v)
15515 {
15516- asm volatile(LOCK_PREFIX "subq %1,%0"
15517+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15518+
15519+#ifdef CONFIG_PAX_REFCOUNT
15520+ "jno 0f\n"
15521+ LOCK_PREFIX "addq %1,%0\n"
15522+ "int $4\n0:\n"
15523+ _ASM_EXTABLE(0b, 0b)
15524+#endif
15525+
15526+ : "=m" (v->counter)
15527+ : "er" (i), "m" (v->counter));
15528+}
15529+
15530+/**
15531+ * atomic64_sub_unchecked - subtract the atomic64 variable
15532+ * @i: integer value to subtract
15533+ * @v: pointer to type atomic64_unchecked_t
15534+ *
15535+ * Atomically subtracts @i from @v.
15536+ */
15537+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15538+{
15539+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15540 : "=m" (v->counter)
15541 : "er" (i), "m" (v->counter));
15542 }
15543@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15544 */
15545 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15546 {
15547- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15548+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15549 }
15550
15551 /**
15552@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15553 */
15554 static inline void atomic64_inc(atomic64_t *v)
15555 {
15556+ asm volatile(LOCK_PREFIX "incq %0\n"
15557+
15558+#ifdef CONFIG_PAX_REFCOUNT
15559+ "jno 0f\n"
15560+ LOCK_PREFIX "decq %0\n"
15561+ "int $4\n0:\n"
15562+ _ASM_EXTABLE(0b, 0b)
15563+#endif
15564+
15565+ : "=m" (v->counter)
15566+ : "m" (v->counter));
15567+}
15568+
15569+/**
15570+ * atomic64_inc_unchecked - increment atomic64 variable
15571+ * @v: pointer to type atomic64_unchecked_t
15572+ *
15573+ * Atomically increments @v by 1.
15574+ */
15575+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15576+{
15577 asm volatile(LOCK_PREFIX "incq %0"
15578 : "=m" (v->counter)
15579 : "m" (v->counter));
15580@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15581 */
15582 static inline void atomic64_dec(atomic64_t *v)
15583 {
15584- asm volatile(LOCK_PREFIX "decq %0"
15585+ asm volatile(LOCK_PREFIX "decq %0\n"
15586+
15587+#ifdef CONFIG_PAX_REFCOUNT
15588+ "jno 0f\n"
15589+ LOCK_PREFIX "incq %0\n"
15590+ "int $4\n0:\n"
15591+ _ASM_EXTABLE(0b, 0b)
15592+#endif
15593+
15594+ : "=m" (v->counter)
15595+ : "m" (v->counter));
15596+}
15597+
15598+/**
15599+ * atomic64_dec_unchecked - decrement atomic64 variable
15600+ * @v: pointer to type atomic64_t
15601+ *
15602+ * Atomically decrements @v by 1.
15603+ */
15604+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15605+{
15606+ asm volatile(LOCK_PREFIX "decq %0\n"
15607 : "=m" (v->counter)
15608 : "m" (v->counter));
15609 }
15610@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15611 */
15612 static inline int atomic64_dec_and_test(atomic64_t *v)
15613 {
15614- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15615+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15616 }
15617
15618 /**
15619@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15620 */
15621 static inline int atomic64_inc_and_test(atomic64_t *v)
15622 {
15623- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15624+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15625 }
15626
15627 /**
15628@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15629 */
15630 static inline int atomic64_add_negative(long i, atomic64_t *v)
15631 {
15632- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15633+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15634 }
15635
15636 /**
15637@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15638 */
15639 static inline long atomic64_add_return(long i, atomic64_t *v)
15640 {
15641+ return i + xadd_check_overflow(&v->counter, i);
15642+}
15643+
15644+/**
15645+ * atomic64_add_return_unchecked - add and return
15646+ * @i: integer value to add
15647+ * @v: pointer to type atomic64_unchecked_t
15648+ *
15649+ * Atomically adds @i to @v and returns @i + @v
15650+ */
15651+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15652+{
15653 return i + xadd(&v->counter, i);
15654 }
15655
15656@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15657 }
15658
15659 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15660+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15661+{
15662+ return atomic64_add_return_unchecked(1, v);
15663+}
15664 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15665
15666 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15667@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15668 return cmpxchg(&v->counter, old, new);
15669 }
15670
15671+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15672+{
15673+ return cmpxchg(&v->counter, old, new);
15674+}
15675+
15676 static inline long atomic64_xchg(atomic64_t *v, long new)
15677 {
15678 return xchg(&v->counter, new);
15679@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15680 */
15681 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15682 {
15683- long c, old;
15684+ long c, old, new;
15685 c = atomic64_read(v);
15686 for (;;) {
15687- if (unlikely(c == (u)))
15688+ if (unlikely(c == u))
15689 break;
15690- old = atomic64_cmpxchg((v), c, c + (a));
15691+
15692+ asm volatile("add %2,%0\n"
15693+
15694+#ifdef CONFIG_PAX_REFCOUNT
15695+ "jno 0f\n"
15696+ "sub %2,%0\n"
15697+ "int $4\n0:\n"
15698+ _ASM_EXTABLE(0b, 0b)
15699+#endif
15700+
15701+ : "=r" (new)
15702+ : "0" (c), "ir" (a));
15703+
15704+ old = atomic64_cmpxchg(v, c, new);
15705 if (likely(old == c))
15706 break;
15707 c = old;
15708 }
15709- return c != (u);
15710+ return c != u;
15711 }
15712
15713 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15714diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
15715index 69bbb48..32517fe 100644
15716--- a/arch/x86/include/asm/barrier.h
15717+++ b/arch/x86/include/asm/barrier.h
15718@@ -107,7 +107,7 @@
15719 do { \
15720 compiletime_assert_atomic_type(*p); \
15721 smp_mb(); \
15722- ACCESS_ONCE(*p) = (v); \
15723+ ACCESS_ONCE_RW(*p) = (v); \
15724 } while (0)
15725
15726 #define smp_load_acquire(p) \
15727@@ -124,7 +124,7 @@ do { \
15728 do { \
15729 compiletime_assert_atomic_type(*p); \
15730 barrier(); \
15731- ACCESS_ONCE(*p) = (v); \
15732+ ACCESS_ONCE_RW(*p) = (v); \
15733 } while (0)
15734
15735 #define smp_load_acquire(p) \
15736diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15737index 9fc1af7..fc71228 100644
15738--- a/arch/x86/include/asm/bitops.h
15739+++ b/arch/x86/include/asm/bitops.h
15740@@ -49,7 +49,7 @@
15741 * a mask operation on a byte.
15742 */
15743 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15744-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15745+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15746 #define CONST_MASK(nr) (1 << ((nr) & 7))
15747
15748 /**
15749@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15750 */
15751 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15752 {
15753- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15754+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15755 }
15756
15757 /**
15758@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15759 */
15760 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15761 {
15762- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15763+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15764 }
15765
15766 /**
15767@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15768 */
15769 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15770 {
15771- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15772+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15773 }
15774
15775 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15776@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15777 *
15778 * Undefined if no bit exists, so code should check against 0 first.
15779 */
15780-static inline unsigned long __ffs(unsigned long word)
15781+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15782 {
15783 asm("rep; bsf %1,%0"
15784 : "=r" (word)
15785@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15786 *
15787 * Undefined if no zero exists, so code should check against ~0UL first.
15788 */
15789-static inline unsigned long ffz(unsigned long word)
15790+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15791 {
15792 asm("rep; bsf %1,%0"
15793 : "=r" (word)
15794@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15795 *
15796 * Undefined if no set bit exists, so code should check against 0 first.
15797 */
15798-static inline unsigned long __fls(unsigned long word)
15799+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15800 {
15801 asm("bsr %1,%0"
15802 : "=r" (word)
15803@@ -436,7 +436,7 @@ static inline int ffs(int x)
15804 * set bit if value is nonzero. The last (most significant) bit is
15805 * at position 32.
15806 */
15807-static inline int fls(int x)
15808+static inline int __intentional_overflow(-1) fls(int x)
15809 {
15810 int r;
15811
15812@@ -478,7 +478,7 @@ static inline int fls(int x)
15813 * at position 64.
15814 */
15815 #ifdef CONFIG_X86_64
15816-static __always_inline int fls64(__u64 x)
15817+static __always_inline long fls64(__u64 x)
15818 {
15819 int bitpos = -1;
15820 /*
15821diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15822index 4fa687a..60f2d39 100644
15823--- a/arch/x86/include/asm/boot.h
15824+++ b/arch/x86/include/asm/boot.h
15825@@ -6,10 +6,15 @@
15826 #include <uapi/asm/boot.h>
15827
15828 /* Physical address where kernel should be loaded. */
15829-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15830+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15831 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15832 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15833
15834+#ifndef __ASSEMBLY__
15835+extern unsigned char __LOAD_PHYSICAL_ADDR[];
15836+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15837+#endif
15838+
15839 /* Minimum kernel alignment, as a power of two */
15840 #ifdef CONFIG_X86_64
15841 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15842diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15843index 48f99f1..d78ebf9 100644
15844--- a/arch/x86/include/asm/cache.h
15845+++ b/arch/x86/include/asm/cache.h
15846@@ -5,12 +5,13 @@
15847
15848 /* L1 cache line size */
15849 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15850-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15851+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15852
15853 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15854+#define __read_only __attribute__((__section__(".data..read_only")))
15855
15856 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15857-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15858+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15859
15860 #ifdef CONFIG_X86_VSMP
15861 #ifdef CONFIG_SMP
15862diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15863index 9863ee3..4a1f8e1 100644
15864--- a/arch/x86/include/asm/cacheflush.h
15865+++ b/arch/x86/include/asm/cacheflush.h
15866@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15867 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15868
15869 if (pg_flags == _PGMT_DEFAULT)
15870- return -1;
15871+ return ~0UL;
15872 else if (pg_flags == _PGMT_WC)
15873 return _PAGE_CACHE_WC;
15874 else if (pg_flags == _PGMT_UC_MINUS)
15875diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15876index cb4c73b..c473c29 100644
15877--- a/arch/x86/include/asm/calling.h
15878+++ b/arch/x86/include/asm/calling.h
15879@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15880 #define RSP 152
15881 #define SS 160
15882
15883-#define ARGOFFSET R11
15884-#define SWFRAME ORIG_RAX
15885+#define ARGOFFSET R15
15886
15887 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15888- subq $9*8+\addskip, %rsp
15889- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15890- movq_cfi rdi, 8*8
15891- movq_cfi rsi, 7*8
15892- movq_cfi rdx, 6*8
15893+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15894+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15895+ movq_cfi rdi, RDI
15896+ movq_cfi rsi, RSI
15897+ movq_cfi rdx, RDX
15898
15899 .if \save_rcx
15900- movq_cfi rcx, 5*8
15901+ movq_cfi rcx, RCX
15902 .endif
15903
15904- movq_cfi rax, 4*8
15905+ movq_cfi rax, RAX
15906
15907 .if \save_r891011
15908- movq_cfi r8, 3*8
15909- movq_cfi r9, 2*8
15910- movq_cfi r10, 1*8
15911- movq_cfi r11, 0*8
15912+ movq_cfi r8, R8
15913+ movq_cfi r9, R9
15914+ movq_cfi r10, R10
15915+ movq_cfi r11, R11
15916 .endif
15917
15918+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15919+ movq_cfi r12, R12
15920+#endif
15921+
15922 .endm
15923
15924-#define ARG_SKIP (9*8)
15925+#define ARG_SKIP ORIG_RAX
15926
15927 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15928 rstor_r8910=1, rstor_rdx=1
15929+
15930+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15931+ movq_cfi_restore R12, r12
15932+#endif
15933+
15934 .if \rstor_r11
15935- movq_cfi_restore 0*8, r11
15936+ movq_cfi_restore R11, r11
15937 .endif
15938
15939 .if \rstor_r8910
15940- movq_cfi_restore 1*8, r10
15941- movq_cfi_restore 2*8, r9
15942- movq_cfi_restore 3*8, r8
15943+ movq_cfi_restore R10, r10
15944+ movq_cfi_restore R9, r9
15945+ movq_cfi_restore R8, r8
15946 .endif
15947
15948 .if \rstor_rax
15949- movq_cfi_restore 4*8, rax
15950+ movq_cfi_restore RAX, rax
15951 .endif
15952
15953 .if \rstor_rcx
15954- movq_cfi_restore 5*8, rcx
15955+ movq_cfi_restore RCX, rcx
15956 .endif
15957
15958 .if \rstor_rdx
15959- movq_cfi_restore 6*8, rdx
15960+ movq_cfi_restore RDX, rdx
15961 .endif
15962
15963- movq_cfi_restore 7*8, rsi
15964- movq_cfi_restore 8*8, rdi
15965+ movq_cfi_restore RSI, rsi
15966+ movq_cfi_restore RDI, rdi
15967
15968- .if ARG_SKIP+\addskip > 0
15969- addq $ARG_SKIP+\addskip, %rsp
15970- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15971+ .if ORIG_RAX+\addskip > 0
15972+ addq $ORIG_RAX+\addskip, %rsp
15973+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15974 .endif
15975 .endm
15976
15977- .macro LOAD_ARGS offset, skiprax=0
15978- movq \offset(%rsp), %r11
15979- movq \offset+8(%rsp), %r10
15980- movq \offset+16(%rsp), %r9
15981- movq \offset+24(%rsp), %r8
15982- movq \offset+40(%rsp), %rcx
15983- movq \offset+48(%rsp), %rdx
15984- movq \offset+56(%rsp), %rsi
15985- movq \offset+64(%rsp), %rdi
15986+ .macro LOAD_ARGS skiprax=0
15987+ movq R11(%rsp), %r11
15988+ movq R10(%rsp), %r10
15989+ movq R9(%rsp), %r9
15990+ movq R8(%rsp), %r8
15991+ movq RCX(%rsp), %rcx
15992+ movq RDX(%rsp), %rdx
15993+ movq RSI(%rsp), %rsi
15994+ movq RDI(%rsp), %rdi
15995 .if \skiprax
15996 .else
15997- movq \offset+72(%rsp), %rax
15998+ movq RAX(%rsp), %rax
15999 .endif
16000 .endm
16001
16002-#define REST_SKIP (6*8)
16003-
16004 .macro SAVE_REST
16005- subq $REST_SKIP, %rsp
16006- CFI_ADJUST_CFA_OFFSET REST_SKIP
16007- movq_cfi rbx, 5*8
16008- movq_cfi rbp, 4*8
16009- movq_cfi r12, 3*8
16010- movq_cfi r13, 2*8
16011- movq_cfi r14, 1*8
16012- movq_cfi r15, 0*8
16013+ movq_cfi rbx, RBX
16014+ movq_cfi rbp, RBP
16015+
16016+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16017+ movq_cfi r12, R12
16018+#endif
16019+
16020+ movq_cfi r13, R13
16021+ movq_cfi r14, R14
16022+ movq_cfi r15, R15
16023 .endm
16024
16025 .macro RESTORE_REST
16026- movq_cfi_restore 0*8, r15
16027- movq_cfi_restore 1*8, r14
16028- movq_cfi_restore 2*8, r13
16029- movq_cfi_restore 3*8, r12
16030- movq_cfi_restore 4*8, rbp
16031- movq_cfi_restore 5*8, rbx
16032- addq $REST_SKIP, %rsp
16033- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16034+ movq_cfi_restore R15, r15
16035+ movq_cfi_restore R14, r14
16036+ movq_cfi_restore R13, r13
16037+
16038+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16039+ movq_cfi_restore R12, r12
16040+#endif
16041+
16042+ movq_cfi_restore RBP, rbp
16043+ movq_cfi_restore RBX, rbx
16044 .endm
16045
16046 .macro SAVE_ALL
16047diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16048index f50de69..2b0a458 100644
16049--- a/arch/x86/include/asm/checksum_32.h
16050+++ b/arch/x86/include/asm/checksum_32.h
16051@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16052 int len, __wsum sum,
16053 int *src_err_ptr, int *dst_err_ptr);
16054
16055+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16056+ int len, __wsum sum,
16057+ int *src_err_ptr, int *dst_err_ptr);
16058+
16059+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16060+ int len, __wsum sum,
16061+ int *src_err_ptr, int *dst_err_ptr);
16062+
16063 /*
16064 * Note: when you get a NULL pointer exception here this means someone
16065 * passed in an incorrect kernel address to one of these functions.
16066@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16067
16068 might_sleep();
16069 stac();
16070- ret = csum_partial_copy_generic((__force void *)src, dst,
16071+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16072 len, sum, err_ptr, NULL);
16073 clac();
16074
16075@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16076 might_sleep();
16077 if (access_ok(VERIFY_WRITE, dst, len)) {
16078 stac();
16079- ret = csum_partial_copy_generic(src, (__force void *)dst,
16080+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16081 len, sum, NULL, err_ptr);
16082 clac();
16083 return ret;
16084diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16085index d47786a..2d8883e 100644
16086--- a/arch/x86/include/asm/cmpxchg.h
16087+++ b/arch/x86/include/asm/cmpxchg.h
16088@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16089 __compiletime_error("Bad argument size for cmpxchg");
16090 extern void __xadd_wrong_size(void)
16091 __compiletime_error("Bad argument size for xadd");
16092+extern void __xadd_check_overflow_wrong_size(void)
16093+ __compiletime_error("Bad argument size for xadd_check_overflow");
16094 extern void __add_wrong_size(void)
16095 __compiletime_error("Bad argument size for add");
16096+extern void __add_check_overflow_wrong_size(void)
16097+ __compiletime_error("Bad argument size for add_check_overflow");
16098
16099 /*
16100 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16101@@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16102 __ret; \
16103 })
16104
16105+#ifdef CONFIG_PAX_REFCOUNT
16106+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16107+ ({ \
16108+ __typeof__ (*(ptr)) __ret = (arg); \
16109+ switch (sizeof(*(ptr))) { \
16110+ case __X86_CASE_L: \
16111+ asm volatile (lock #op "l %0, %1\n" \
16112+ "jno 0f\n" \
16113+ "mov %0,%1\n" \
16114+ "int $4\n0:\n" \
16115+ _ASM_EXTABLE(0b, 0b) \
16116+ : "+r" (__ret), "+m" (*(ptr)) \
16117+ : : "memory", "cc"); \
16118+ break; \
16119+ case __X86_CASE_Q: \
16120+ asm volatile (lock #op "q %q0, %1\n" \
16121+ "jno 0f\n" \
16122+ "mov %0,%1\n" \
16123+ "int $4\n0:\n" \
16124+ _ASM_EXTABLE(0b, 0b) \
16125+ : "+r" (__ret), "+m" (*(ptr)) \
16126+ : : "memory", "cc"); \
16127+ break; \
16128+ default: \
16129+ __ ## op ## _check_overflow_wrong_size(); \
16130+ } \
16131+ __ret; \
16132+ })
16133+#else
16134+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16135+#endif
16136+
16137 /*
16138 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16139 * Since this is generally used to protect other memory information, we
16140@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16141 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16142 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16143
16144+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16145+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16146+
16147 #define __add(ptr, inc, lock) \
16148 ({ \
16149 __typeof__ (*(ptr)) __ret = (inc); \
16150diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16151index 59c6c40..5e0b22c 100644
16152--- a/arch/x86/include/asm/compat.h
16153+++ b/arch/x86/include/asm/compat.h
16154@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16155 typedef u32 compat_uint_t;
16156 typedef u32 compat_ulong_t;
16157 typedef u64 __attribute__((aligned(4))) compat_u64;
16158-typedef u32 compat_uptr_t;
16159+typedef u32 __user compat_uptr_t;
16160
16161 struct compat_timespec {
16162 compat_time_t tv_sec;
16163diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16164index e265ff9..72c253b 100644
16165--- a/arch/x86/include/asm/cpufeature.h
16166+++ b/arch/x86/include/asm/cpufeature.h
16167@@ -203,7 +203,7 @@
16168 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16169 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16170 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16171-
16172+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16173
16174 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16175 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16176@@ -211,7 +211,7 @@
16177 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16178 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16179 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16180-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16181+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16182 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16183 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16184 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16185@@ -359,6 +359,7 @@ extern const char * const x86_power_flags[32];
16186 #undef cpu_has_centaur_mcr
16187 #define cpu_has_centaur_mcr 0
16188
16189+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16190 #endif /* CONFIG_X86_64 */
16191
16192 #if __GNUC__ >= 4
16193@@ -411,7 +412,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16194
16195 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16196 t_warn:
16197- warn_pre_alternatives();
16198+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16199+ warn_pre_alternatives();
16200 return false;
16201 #endif
16202
16203@@ -431,7 +433,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16204 ".section .discard,\"aw\",@progbits\n"
16205 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16206 ".previous\n"
16207- ".section .altinstr_replacement,\"ax\"\n"
16208+ ".section .altinstr_replacement,\"a\"\n"
16209 "3: movb $1,%0\n"
16210 "4:\n"
16211 ".previous\n"
16212@@ -468,7 +470,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16213 " .byte 2b - 1b\n" /* src len */
16214 " .byte 4f - 3f\n" /* repl len */
16215 ".previous\n"
16216- ".section .altinstr_replacement,\"ax\"\n"
16217+ ".section .altinstr_replacement,\"a\"\n"
16218 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16219 "4:\n"
16220 ".previous\n"
16221@@ -501,7 +503,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16222 ".section .discard,\"aw\",@progbits\n"
16223 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16224 ".previous\n"
16225- ".section .altinstr_replacement,\"ax\"\n"
16226+ ".section .altinstr_replacement,\"a\"\n"
16227 "3: movb $0,%0\n"
16228 "4:\n"
16229 ".previous\n"
16230@@ -515,7 +517,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16231 ".section .discard,\"aw\",@progbits\n"
16232 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16233 ".previous\n"
16234- ".section .altinstr_replacement,\"ax\"\n"
16235+ ".section .altinstr_replacement,\"a\"\n"
16236 "5: movb $1,%0\n"
16237 "6:\n"
16238 ".previous\n"
16239diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16240index 50d033a..37deb26 100644
16241--- a/arch/x86/include/asm/desc.h
16242+++ b/arch/x86/include/asm/desc.h
16243@@ -4,6 +4,7 @@
16244 #include <asm/desc_defs.h>
16245 #include <asm/ldt.h>
16246 #include <asm/mmu.h>
16247+#include <asm/pgtable.h>
16248
16249 #include <linux/smp.h>
16250 #include <linux/percpu.h>
16251@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16252
16253 desc->type = (info->read_exec_only ^ 1) << 1;
16254 desc->type |= info->contents << 2;
16255+ desc->type |= info->seg_not_present ^ 1;
16256
16257 desc->s = 1;
16258 desc->dpl = 0x3;
16259@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16260 }
16261
16262 extern struct desc_ptr idt_descr;
16263-extern gate_desc idt_table[];
16264-extern struct desc_ptr debug_idt_descr;
16265-extern gate_desc debug_idt_table[];
16266-
16267-struct gdt_page {
16268- struct desc_struct gdt[GDT_ENTRIES];
16269-} __attribute__((aligned(PAGE_SIZE)));
16270-
16271-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16272+extern gate_desc idt_table[IDT_ENTRIES];
16273+extern const struct desc_ptr debug_idt_descr;
16274+extern gate_desc debug_idt_table[IDT_ENTRIES];
16275
16276+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16277 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16278 {
16279- return per_cpu(gdt_page, cpu).gdt;
16280+ return cpu_gdt_table[cpu];
16281 }
16282
16283 #ifdef CONFIG_X86_64
16284@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16285 unsigned long base, unsigned dpl, unsigned flags,
16286 unsigned short seg)
16287 {
16288- gate->a = (seg << 16) | (base & 0xffff);
16289- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16290+ gate->gate.offset_low = base;
16291+ gate->gate.seg = seg;
16292+ gate->gate.reserved = 0;
16293+ gate->gate.type = type;
16294+ gate->gate.s = 0;
16295+ gate->gate.dpl = dpl;
16296+ gate->gate.p = 1;
16297+ gate->gate.offset_high = base >> 16;
16298 }
16299
16300 #endif
16301@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16302
16303 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16304 {
16305+ pax_open_kernel();
16306 memcpy(&idt[entry], gate, sizeof(*gate));
16307+ pax_close_kernel();
16308 }
16309
16310 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16311 {
16312+ pax_open_kernel();
16313 memcpy(&ldt[entry], desc, 8);
16314+ pax_close_kernel();
16315 }
16316
16317 static inline void
16318@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16319 default: size = sizeof(*gdt); break;
16320 }
16321
16322+ pax_open_kernel();
16323 memcpy(&gdt[entry], desc, size);
16324+ pax_close_kernel();
16325 }
16326
16327 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16328@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16329
16330 static inline void native_load_tr_desc(void)
16331 {
16332+ pax_open_kernel();
16333 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16334+ pax_close_kernel();
16335 }
16336
16337 static inline void native_load_gdt(const struct desc_ptr *dtr)
16338@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16339 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16340 unsigned int i;
16341
16342+ pax_open_kernel();
16343 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16344 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16345+ pax_close_kernel();
16346 }
16347
16348 #define _LDT_empty(info) \
16349@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16350 preempt_enable();
16351 }
16352
16353-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16354+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16355 {
16356 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16357 }
16358@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16359 }
16360
16361 #ifdef CONFIG_X86_64
16362-static inline void set_nmi_gate(int gate, void *addr)
16363+static inline void set_nmi_gate(int gate, const void *addr)
16364 {
16365 gate_desc s;
16366
16367@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16368 #endif
16369
16370 #ifdef CONFIG_TRACING
16371-extern struct desc_ptr trace_idt_descr;
16372-extern gate_desc trace_idt_table[];
16373+extern const struct desc_ptr trace_idt_descr;
16374+extern gate_desc trace_idt_table[IDT_ENTRIES];
16375 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16376 {
16377 write_idt_entry(trace_idt_table, entry, gate);
16378 }
16379
16380-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16381+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16382 unsigned dpl, unsigned ist, unsigned seg)
16383 {
16384 gate_desc s;
16385@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16386 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16387 #endif
16388
16389-static inline void _set_gate(int gate, unsigned type, void *addr,
16390+static inline void _set_gate(int gate, unsigned type, const void *addr,
16391 unsigned dpl, unsigned ist, unsigned seg)
16392 {
16393 gate_desc s;
16394@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16395 #define set_intr_gate(n, addr) \
16396 do { \
16397 BUG_ON((unsigned)n > 0xFF); \
16398- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16399+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16400 __KERNEL_CS); \
16401- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16402+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16403 0, 0, __KERNEL_CS); \
16404 } while (0)
16405
16406@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16407 /*
16408 * This routine sets up an interrupt gate at directory privilege level 3.
16409 */
16410-static inline void set_system_intr_gate(unsigned int n, void *addr)
16411+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16412 {
16413 BUG_ON((unsigned)n > 0xFF);
16414 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16415 }
16416
16417-static inline void set_system_trap_gate(unsigned int n, void *addr)
16418+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16419 {
16420 BUG_ON((unsigned)n > 0xFF);
16421 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16422 }
16423
16424-static inline void set_trap_gate(unsigned int n, void *addr)
16425+static inline void set_trap_gate(unsigned int n, const void *addr)
16426 {
16427 BUG_ON((unsigned)n > 0xFF);
16428 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16429@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16430 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16431 {
16432 BUG_ON((unsigned)n > 0xFF);
16433- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16434+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16435 }
16436
16437-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16438+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16439 {
16440 BUG_ON((unsigned)n > 0xFF);
16441 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16442 }
16443
16444-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16445+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16446 {
16447 BUG_ON((unsigned)n > 0xFF);
16448 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16449@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16450 else
16451 load_idt((const struct desc_ptr *)&idt_descr);
16452 }
16453+
16454+#ifdef CONFIG_X86_32
16455+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16456+{
16457+ struct desc_struct d;
16458+
16459+ if (likely(limit))
16460+ limit = (limit - 1UL) >> PAGE_SHIFT;
16461+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16462+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16463+}
16464+#endif
16465+
16466 #endif /* _ASM_X86_DESC_H */
16467diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16468index 278441f..b95a174 100644
16469--- a/arch/x86/include/asm/desc_defs.h
16470+++ b/arch/x86/include/asm/desc_defs.h
16471@@ -31,6 +31,12 @@ struct desc_struct {
16472 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16473 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16474 };
16475+ struct {
16476+ u16 offset_low;
16477+ u16 seg;
16478+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16479+ unsigned offset_high: 16;
16480+ } gate;
16481 };
16482 } __attribute__((packed));
16483
16484diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16485index ced283a..ffe04cc 100644
16486--- a/arch/x86/include/asm/div64.h
16487+++ b/arch/x86/include/asm/div64.h
16488@@ -39,7 +39,7 @@
16489 __mod; \
16490 })
16491
16492-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16493+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16494 {
16495 union {
16496 u64 v64;
16497diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16498index 2c71182..731124d 100644
16499--- a/arch/x86/include/asm/elf.h
16500+++ b/arch/x86/include/asm/elf.h
16501@@ -243,7 +243,25 @@ extern int force_personality32;
16502 the loader. We need to make sure that it is out of the way of the program
16503 that it will "exec", and that there is sufficient room for the brk. */
16504
16505+#ifdef CONFIG_PAX_SEGMEXEC
16506+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16507+#else
16508 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16509+#endif
16510+
16511+#ifdef CONFIG_PAX_ASLR
16512+#ifdef CONFIG_X86_32
16513+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16514+
16515+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16516+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16517+#else
16518+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16519+
16520+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16521+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16522+#endif
16523+#endif
16524
16525 /* This yields a mask that user programs can use to figure out what
16526 instruction set this CPU supports. This could be done in user space,
16527@@ -292,16 +310,12 @@ do { \
16528
16529 #define ARCH_DLINFO \
16530 do { \
16531- if (vdso_enabled) \
16532- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16533- (unsigned long)current->mm->context.vdso); \
16534+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16535 } while (0)
16536
16537 #define ARCH_DLINFO_X32 \
16538 do { \
16539- if (vdso_enabled) \
16540- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16541- (unsigned long)current->mm->context.vdso); \
16542+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16543 } while (0)
16544
16545 #define AT_SYSINFO 32
16546@@ -316,7 +330,7 @@ else \
16547
16548 #endif /* !CONFIG_X86_32 */
16549
16550-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16551+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16552
16553 #define VDSO_ENTRY \
16554 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16555@@ -332,9 +346,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16556 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16557 #define compat_arch_setup_additional_pages syscall32_setup_pages
16558
16559-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16560-#define arch_randomize_brk arch_randomize_brk
16561-
16562 /*
16563 * True on X86_32 or when emulating IA32 on X86_64
16564 */
16565diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16566index 77a99ac..39ff7f5 100644
16567--- a/arch/x86/include/asm/emergency-restart.h
16568+++ b/arch/x86/include/asm/emergency-restart.h
16569@@ -1,6 +1,6 @@
16570 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16571 #define _ASM_X86_EMERGENCY_RESTART_H
16572
16573-extern void machine_emergency_restart(void);
16574+extern void machine_emergency_restart(void) __noreturn;
16575
16576 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16577diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16578index 1c7eefe..d0e4702 100644
16579--- a/arch/x86/include/asm/floppy.h
16580+++ b/arch/x86/include/asm/floppy.h
16581@@ -229,18 +229,18 @@ static struct fd_routine_l {
16582 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16583 } fd_routine[] = {
16584 {
16585- request_dma,
16586- free_dma,
16587- get_dma_residue,
16588- dma_mem_alloc,
16589- hard_dma_setup
16590+ ._request_dma = request_dma,
16591+ ._free_dma = free_dma,
16592+ ._get_dma_residue = get_dma_residue,
16593+ ._dma_mem_alloc = dma_mem_alloc,
16594+ ._dma_setup = hard_dma_setup
16595 },
16596 {
16597- vdma_request_dma,
16598- vdma_nop,
16599- vdma_get_dma_residue,
16600- vdma_mem_alloc,
16601- vdma_dma_setup
16602+ ._request_dma = vdma_request_dma,
16603+ ._free_dma = vdma_nop,
16604+ ._get_dma_residue = vdma_get_dma_residue,
16605+ ._dma_mem_alloc = vdma_mem_alloc,
16606+ ._dma_setup = vdma_dma_setup
16607 }
16608 };
16609
16610diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16611index cea1c76..6c0d79b 100644
16612--- a/arch/x86/include/asm/fpu-internal.h
16613+++ b/arch/x86/include/asm/fpu-internal.h
16614@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16615 #define user_insn(insn, output, input...) \
16616 ({ \
16617 int err; \
16618+ pax_open_userland(); \
16619 asm volatile(ASM_STAC "\n" \
16620- "1:" #insn "\n\t" \
16621+ "1:" \
16622+ __copyuser_seg \
16623+ #insn "\n\t" \
16624 "2: " ASM_CLAC "\n" \
16625 ".section .fixup,\"ax\"\n" \
16626 "3: movl $-1,%[err]\n" \
16627@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16628 _ASM_EXTABLE(1b, 3b) \
16629 : [err] "=r" (err), output \
16630 : "0"(0), input); \
16631+ pax_close_userland(); \
16632 err; \
16633 })
16634
16635@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16636 "fnclex\n\t"
16637 "emms\n\t"
16638 "fildl %P[addr]" /* set F?P to defined value */
16639- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16640+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16641 }
16642
16643 return fpu_restore_checking(&tsk->thread.fpu);
16644diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16645index b4c1f54..e290c08 100644
16646--- a/arch/x86/include/asm/futex.h
16647+++ b/arch/x86/include/asm/futex.h
16648@@ -12,6 +12,7 @@
16649 #include <asm/smap.h>
16650
16651 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16652+ typecheck(u32 __user *, uaddr); \
16653 asm volatile("\t" ASM_STAC "\n" \
16654 "1:\t" insn "\n" \
16655 "2:\t" ASM_CLAC "\n" \
16656@@ -20,15 +21,16 @@
16657 "\tjmp\t2b\n" \
16658 "\t.previous\n" \
16659 _ASM_EXTABLE(1b, 3b) \
16660- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16661+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16662 : "i" (-EFAULT), "0" (oparg), "1" (0))
16663
16664 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16665+ typecheck(u32 __user *, uaddr); \
16666 asm volatile("\t" ASM_STAC "\n" \
16667 "1:\tmovl %2, %0\n" \
16668 "\tmovl\t%0, %3\n" \
16669 "\t" insn "\n" \
16670- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16671+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16672 "\tjnz\t1b\n" \
16673 "3:\t" ASM_CLAC "\n" \
16674 "\t.section .fixup,\"ax\"\n" \
16675@@ -38,7 +40,7 @@
16676 _ASM_EXTABLE(1b, 4b) \
16677 _ASM_EXTABLE(2b, 4b) \
16678 : "=&a" (oldval), "=&r" (ret), \
16679- "+m" (*uaddr), "=&r" (tem) \
16680+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16681 : "r" (oparg), "i" (-EFAULT), "1" (0))
16682
16683 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16684@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16685
16686 pagefault_disable();
16687
16688+ pax_open_userland();
16689 switch (op) {
16690 case FUTEX_OP_SET:
16691- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16692+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16693 break;
16694 case FUTEX_OP_ADD:
16695- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16696+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16697 uaddr, oparg);
16698 break;
16699 case FUTEX_OP_OR:
16700@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16701 default:
16702 ret = -ENOSYS;
16703 }
16704+ pax_close_userland();
16705
16706 pagefault_enable();
16707
16708diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16709index a307b75..ec74ca2 100644
16710--- a/arch/x86/include/asm/hw_irq.h
16711+++ b/arch/x86/include/asm/hw_irq.h
16712@@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
16713 extern void enable_IO_APIC(void);
16714
16715 /* Statistics */
16716-extern atomic_t irq_err_count;
16717-extern atomic_t irq_mis_count;
16718+extern atomic_unchecked_t irq_err_count;
16719+extern atomic_unchecked_t irq_mis_count;
16720
16721 /* EISA */
16722 extern void eisa_set_level_irq(unsigned int irq);
16723diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16724index a203659..9889f1c 100644
16725--- a/arch/x86/include/asm/i8259.h
16726+++ b/arch/x86/include/asm/i8259.h
16727@@ -62,7 +62,7 @@ struct legacy_pic {
16728 void (*init)(int auto_eoi);
16729 int (*irq_pending)(unsigned int irq);
16730 void (*make_irq)(unsigned int irq);
16731-};
16732+} __do_const;
16733
16734 extern struct legacy_pic *legacy_pic;
16735 extern struct legacy_pic null_legacy_pic;
16736diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16737index b8237d8..3e8864e 100644
16738--- a/arch/x86/include/asm/io.h
16739+++ b/arch/x86/include/asm/io.h
16740@@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16741 "m" (*(volatile type __force *)addr) barrier); }
16742
16743 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16744-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16745-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16746+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16747+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16748
16749 build_mmio_read(__readb, "b", unsigned char, "=q", )
16750-build_mmio_read(__readw, "w", unsigned short, "=r", )
16751-build_mmio_read(__readl, "l", unsigned int, "=r", )
16752+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16753+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16754
16755 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16756 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16757@@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
16758 * this function
16759 */
16760
16761-static inline phys_addr_t virt_to_phys(volatile void *address)
16762+static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
16763 {
16764 return __pa(address);
16765 }
16766@@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16767 return ioremap_nocache(offset, size);
16768 }
16769
16770-extern void iounmap(volatile void __iomem *addr);
16771+extern void iounmap(const volatile void __iomem *addr);
16772
16773 extern void set_iounmap_nonlazy(void);
16774
16775@@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
16776
16777 #include <linux/vmalloc.h>
16778
16779+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16780+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16781+{
16782+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16783+}
16784+
16785+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16786+{
16787+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16788+}
16789+
16790 /*
16791 * Convert a virtual cached pointer to an uncached pointer
16792 */
16793diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16794index bba3cf8..06bc8da 100644
16795--- a/arch/x86/include/asm/irqflags.h
16796+++ b/arch/x86/include/asm/irqflags.h
16797@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16798 sti; \
16799 sysexit
16800
16801+#define GET_CR0_INTO_RDI mov %cr0, %rdi
16802+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16803+#define GET_CR3_INTO_RDI mov %cr3, %rdi
16804+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16805+
16806 #else
16807 #define INTERRUPT_RETURN iret
16808 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16809diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16810index 9454c16..e4100e3 100644
16811--- a/arch/x86/include/asm/kprobes.h
16812+++ b/arch/x86/include/asm/kprobes.h
16813@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16814 #define RELATIVEJUMP_SIZE 5
16815 #define RELATIVECALL_OPCODE 0xe8
16816 #define RELATIVE_ADDR_SIZE 4
16817-#define MAX_STACK_SIZE 64
16818-#define MIN_STACK_SIZE(ADDR) \
16819- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16820- THREAD_SIZE - (unsigned long)(ADDR))) \
16821- ? (MAX_STACK_SIZE) \
16822- : (((unsigned long)current_thread_info()) + \
16823- THREAD_SIZE - (unsigned long)(ADDR)))
16824+#define MAX_STACK_SIZE 64UL
16825+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16826
16827 #define flush_insn_slot(p) do { } while (0)
16828
16829diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16830index 4ad6560..75c7bdd 100644
16831--- a/arch/x86/include/asm/local.h
16832+++ b/arch/x86/include/asm/local.h
16833@@ -10,33 +10,97 @@ typedef struct {
16834 atomic_long_t a;
16835 } local_t;
16836
16837+typedef struct {
16838+ atomic_long_unchecked_t a;
16839+} local_unchecked_t;
16840+
16841 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16842
16843 #define local_read(l) atomic_long_read(&(l)->a)
16844+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16845 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16846+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16847
16848 static inline void local_inc(local_t *l)
16849 {
16850- asm volatile(_ASM_INC "%0"
16851+ asm volatile(_ASM_INC "%0\n"
16852+
16853+#ifdef CONFIG_PAX_REFCOUNT
16854+ "jno 0f\n"
16855+ _ASM_DEC "%0\n"
16856+ "int $4\n0:\n"
16857+ _ASM_EXTABLE(0b, 0b)
16858+#endif
16859+
16860+ : "+m" (l->a.counter));
16861+}
16862+
16863+static inline void local_inc_unchecked(local_unchecked_t *l)
16864+{
16865+ asm volatile(_ASM_INC "%0\n"
16866 : "+m" (l->a.counter));
16867 }
16868
16869 static inline void local_dec(local_t *l)
16870 {
16871- asm volatile(_ASM_DEC "%0"
16872+ asm volatile(_ASM_DEC "%0\n"
16873+
16874+#ifdef CONFIG_PAX_REFCOUNT
16875+ "jno 0f\n"
16876+ _ASM_INC "%0\n"
16877+ "int $4\n0:\n"
16878+ _ASM_EXTABLE(0b, 0b)
16879+#endif
16880+
16881+ : "+m" (l->a.counter));
16882+}
16883+
16884+static inline void local_dec_unchecked(local_unchecked_t *l)
16885+{
16886+ asm volatile(_ASM_DEC "%0\n"
16887 : "+m" (l->a.counter));
16888 }
16889
16890 static inline void local_add(long i, local_t *l)
16891 {
16892- asm volatile(_ASM_ADD "%1,%0"
16893+ asm volatile(_ASM_ADD "%1,%0\n"
16894+
16895+#ifdef CONFIG_PAX_REFCOUNT
16896+ "jno 0f\n"
16897+ _ASM_SUB "%1,%0\n"
16898+ "int $4\n0:\n"
16899+ _ASM_EXTABLE(0b, 0b)
16900+#endif
16901+
16902+ : "+m" (l->a.counter)
16903+ : "ir" (i));
16904+}
16905+
16906+static inline void local_add_unchecked(long i, local_unchecked_t *l)
16907+{
16908+ asm volatile(_ASM_ADD "%1,%0\n"
16909 : "+m" (l->a.counter)
16910 : "ir" (i));
16911 }
16912
16913 static inline void local_sub(long i, local_t *l)
16914 {
16915- asm volatile(_ASM_SUB "%1,%0"
16916+ asm volatile(_ASM_SUB "%1,%0\n"
16917+
16918+#ifdef CONFIG_PAX_REFCOUNT
16919+ "jno 0f\n"
16920+ _ASM_ADD "%1,%0\n"
16921+ "int $4\n0:\n"
16922+ _ASM_EXTABLE(0b, 0b)
16923+#endif
16924+
16925+ : "+m" (l->a.counter)
16926+ : "ir" (i));
16927+}
16928+
16929+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16930+{
16931+ asm volatile(_ASM_SUB "%1,%0\n"
16932 : "+m" (l->a.counter)
16933 : "ir" (i));
16934 }
16935@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16936 */
16937 static inline int local_sub_and_test(long i, local_t *l)
16938 {
16939- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16940+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16941 }
16942
16943 /**
16944@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16945 */
16946 static inline int local_dec_and_test(local_t *l)
16947 {
16948- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16949+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16950 }
16951
16952 /**
16953@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16954 */
16955 static inline int local_inc_and_test(local_t *l)
16956 {
16957- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16958+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16959 }
16960
16961 /**
16962@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16963 */
16964 static inline int local_add_negative(long i, local_t *l)
16965 {
16966- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16967+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16968 }
16969
16970 /**
16971@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16972 static inline long local_add_return(long i, local_t *l)
16973 {
16974 long __i = i;
16975+ asm volatile(_ASM_XADD "%0, %1\n"
16976+
16977+#ifdef CONFIG_PAX_REFCOUNT
16978+ "jno 0f\n"
16979+ _ASM_MOV "%0,%1\n"
16980+ "int $4\n0:\n"
16981+ _ASM_EXTABLE(0b, 0b)
16982+#endif
16983+
16984+ : "+r" (i), "+m" (l->a.counter)
16985+ : : "memory");
16986+ return i + __i;
16987+}
16988+
16989+/**
16990+ * local_add_return_unchecked - add and return
16991+ * @i: integer value to add
16992+ * @l: pointer to type local_unchecked_t
16993+ *
16994+ * Atomically adds @i to @l and returns @i + @l
16995+ */
16996+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16997+{
16998+ long __i = i;
16999 asm volatile(_ASM_XADD "%0, %1;"
17000 : "+r" (i), "+m" (l->a.counter)
17001 : : "memory");
17002@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17003
17004 #define local_cmpxchg(l, o, n) \
17005 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17006+#define local_cmpxchg_unchecked(l, o, n) \
17007+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
17008 /* Always has a lock prefix */
17009 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17010
17011diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17012new file mode 100644
17013index 0000000..2bfd3ba
17014--- /dev/null
17015+++ b/arch/x86/include/asm/mman.h
17016@@ -0,0 +1,15 @@
17017+#ifndef _X86_MMAN_H
17018+#define _X86_MMAN_H
17019+
17020+#include <uapi/asm/mman.h>
17021+
17022+#ifdef __KERNEL__
17023+#ifndef __ASSEMBLY__
17024+#ifdef CONFIG_X86_32
17025+#define arch_mmap_check i386_mmap_check
17026+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17027+#endif
17028+#endif
17029+#endif
17030+
17031+#endif /* X86_MMAN_H */
17032diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17033index 5f55e69..e20bfb1 100644
17034--- a/arch/x86/include/asm/mmu.h
17035+++ b/arch/x86/include/asm/mmu.h
17036@@ -9,7 +9,7 @@
17037 * we put the segment information here.
17038 */
17039 typedef struct {
17040- void *ldt;
17041+ struct desc_struct *ldt;
17042 int size;
17043
17044 #ifdef CONFIG_X86_64
17045@@ -18,7 +18,19 @@ typedef struct {
17046 #endif
17047
17048 struct mutex lock;
17049- void *vdso;
17050+ unsigned long vdso;
17051+
17052+#ifdef CONFIG_X86_32
17053+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17054+ unsigned long user_cs_base;
17055+ unsigned long user_cs_limit;
17056+
17057+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17058+ cpumask_t cpu_user_cs_mask;
17059+#endif
17060+
17061+#endif
17062+#endif
17063 } mm_context_t;
17064
17065 #ifdef CONFIG_SMP
17066diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17067index be12c53..4d24039 100644
17068--- a/arch/x86/include/asm/mmu_context.h
17069+++ b/arch/x86/include/asm/mmu_context.h
17070@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17071
17072 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17073 {
17074+
17075+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17076+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
17077+ unsigned int i;
17078+ pgd_t *pgd;
17079+
17080+ pax_open_kernel();
17081+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
17082+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17083+ set_pgd_batched(pgd+i, native_make_pgd(0));
17084+ pax_close_kernel();
17085+ }
17086+#endif
17087+
17088 #ifdef CONFIG_SMP
17089 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17090 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17091@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17092 struct task_struct *tsk)
17093 {
17094 unsigned cpu = smp_processor_id();
17095+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17096+ int tlbstate = TLBSTATE_OK;
17097+#endif
17098
17099 if (likely(prev != next)) {
17100 #ifdef CONFIG_SMP
17101+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17102+ tlbstate = this_cpu_read(cpu_tlbstate.state);
17103+#endif
17104 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17105 this_cpu_write(cpu_tlbstate.active_mm, next);
17106 #endif
17107 cpumask_set_cpu(cpu, mm_cpumask(next));
17108
17109 /* Re-load page tables */
17110+#ifdef CONFIG_PAX_PER_CPU_PGD
17111+ pax_open_kernel();
17112+
17113+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17114+ if (static_cpu_has(X86_FEATURE_PCID))
17115+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17116+ else
17117+#endif
17118+
17119+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17120+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17121+ pax_close_kernel();
17122+ 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));
17123+
17124+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17125+ if (static_cpu_has(X86_FEATURE_PCID)) {
17126+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17127+ u64 descriptor[2];
17128+ descriptor[0] = PCID_USER;
17129+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17130+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17131+ descriptor[0] = PCID_KERNEL;
17132+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17133+ }
17134+ } else {
17135+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17136+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17137+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17138+ else
17139+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17140+ }
17141+ } else
17142+#endif
17143+
17144+ load_cr3(get_cpu_pgd(cpu, kernel));
17145+#else
17146 load_cr3(next->pgd);
17147+#endif
17148
17149 /* Stop flush ipis for the previous mm */
17150 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17151@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17152 /* Load the LDT, if the LDT is different: */
17153 if (unlikely(prev->context.ldt != next->context.ldt))
17154 load_LDT_nolock(&next->context);
17155+
17156+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17157+ if (!(__supported_pte_mask & _PAGE_NX)) {
17158+ smp_mb__before_clear_bit();
17159+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17160+ smp_mb__after_clear_bit();
17161+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17162+ }
17163+#endif
17164+
17165+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17166+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17167+ prev->context.user_cs_limit != next->context.user_cs_limit))
17168+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17169+#ifdef CONFIG_SMP
17170+ else if (unlikely(tlbstate != TLBSTATE_OK))
17171+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17172+#endif
17173+#endif
17174+
17175 }
17176+ else {
17177+
17178+#ifdef CONFIG_PAX_PER_CPU_PGD
17179+ pax_open_kernel();
17180+
17181+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17182+ if (static_cpu_has(X86_FEATURE_PCID))
17183+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17184+ else
17185+#endif
17186+
17187+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17188+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17189+ pax_close_kernel();
17190+ 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));
17191+
17192+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17193+ if (static_cpu_has(X86_FEATURE_PCID)) {
17194+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17195+ u64 descriptor[2];
17196+ descriptor[0] = PCID_USER;
17197+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17198+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17199+ descriptor[0] = PCID_KERNEL;
17200+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17201+ }
17202+ } else {
17203+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17204+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17205+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17206+ else
17207+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17208+ }
17209+ } else
17210+#endif
17211+
17212+ load_cr3(get_cpu_pgd(cpu, kernel));
17213+#endif
17214+
17215 #ifdef CONFIG_SMP
17216- else {
17217 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17218 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17219
17220@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17221 * tlb flush IPI delivery. We must reload CR3
17222 * to make sure to use no freed page tables.
17223 */
17224+
17225+#ifndef CONFIG_PAX_PER_CPU_PGD
17226 load_cr3(next->pgd);
17227+#endif
17228+
17229 load_LDT_nolock(&next->context);
17230+
17231+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17232+ if (!(__supported_pte_mask & _PAGE_NX))
17233+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17234+#endif
17235+
17236+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17237+#ifdef CONFIG_PAX_PAGEEXEC
17238+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17239+#endif
17240+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17241+#endif
17242+
17243 }
17244+#endif
17245 }
17246-#endif
17247 }
17248
17249 #define activate_mm(prev, next) \
17250diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17251index e3b7819..b257c64 100644
17252--- a/arch/x86/include/asm/module.h
17253+++ b/arch/x86/include/asm/module.h
17254@@ -5,6 +5,7 @@
17255
17256 #ifdef CONFIG_X86_64
17257 /* X86_64 does not define MODULE_PROC_FAMILY */
17258+#define MODULE_PROC_FAMILY ""
17259 #elif defined CONFIG_M486
17260 #define MODULE_PROC_FAMILY "486 "
17261 #elif defined CONFIG_M586
17262@@ -57,8 +58,20 @@
17263 #error unknown processor family
17264 #endif
17265
17266-#ifdef CONFIG_X86_32
17267-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17268+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17269+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17270+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17271+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17272+#else
17273+#define MODULE_PAX_KERNEXEC ""
17274 #endif
17275
17276+#ifdef CONFIG_PAX_MEMORY_UDEREF
17277+#define MODULE_PAX_UDEREF "UDEREF "
17278+#else
17279+#define MODULE_PAX_UDEREF ""
17280+#endif
17281+
17282+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17283+
17284 #endif /* _ASM_X86_MODULE_H */
17285diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17286index 5f2fc44..106caa6 100644
17287--- a/arch/x86/include/asm/nmi.h
17288+++ b/arch/x86/include/asm/nmi.h
17289@@ -36,26 +36,35 @@ enum {
17290
17291 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17292
17293+struct nmiaction;
17294+
17295+struct nmiwork {
17296+ const struct nmiaction *action;
17297+ u64 max_duration;
17298+ struct irq_work irq_work;
17299+};
17300+
17301 struct nmiaction {
17302 struct list_head list;
17303 nmi_handler_t handler;
17304- u64 max_duration;
17305- struct irq_work irq_work;
17306 unsigned long flags;
17307 const char *name;
17308-};
17309+ struct nmiwork *work;
17310+} __do_const;
17311
17312 #define register_nmi_handler(t, fn, fg, n, init...) \
17313 ({ \
17314- static struct nmiaction init fn##_na = { \
17315+ static struct nmiwork fn##_nw; \
17316+ static const struct nmiaction init fn##_na = { \
17317 .handler = (fn), \
17318 .name = (n), \
17319 .flags = (fg), \
17320+ .work = &fn##_nw, \
17321 }; \
17322 __register_nmi_handler((t), &fn##_na); \
17323 })
17324
17325-int __register_nmi_handler(unsigned int, struct nmiaction *);
17326+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17327
17328 void unregister_nmi_handler(unsigned int, const char *);
17329
17330diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17331index 775873d..04cd306 100644
17332--- a/arch/x86/include/asm/page.h
17333+++ b/arch/x86/include/asm/page.h
17334@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17335 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17336
17337 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17338+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17339
17340 #define __boot_va(x) __va(x)
17341 #define __boot_pa(x) __pa(x)
17342@@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17343 * virt_to_page(kaddr) returns a valid pointer if and only if
17344 * virt_addr_valid(kaddr) returns true.
17345 */
17346-#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17347 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17348 extern bool __virt_addr_valid(unsigned long kaddr);
17349 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17350
17351+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17352+#define virt_to_page(kaddr) \
17353+ ({ \
17354+ const void *__kaddr = (const void *)(kaddr); \
17355+ BUG_ON(!virt_addr_valid(__kaddr)); \
17356+ pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17357+ })
17358+#else
17359+#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17360+#endif
17361+
17362 #endif /* __ASSEMBLY__ */
17363
17364 #include <asm-generic/memory_model.h>
17365diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17366index 0f1ddee..e2fc3d1 100644
17367--- a/arch/x86/include/asm/page_64.h
17368+++ b/arch/x86/include/asm/page_64.h
17369@@ -7,9 +7,9 @@
17370
17371 /* duplicated to the one in bootmem.h */
17372 extern unsigned long max_pfn;
17373-extern unsigned long phys_base;
17374+extern const unsigned long phys_base;
17375
17376-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17377+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17378 {
17379 unsigned long y = x - __START_KERNEL_map;
17380
17381diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17382index cd6e1610..70f4418 100644
17383--- a/arch/x86/include/asm/paravirt.h
17384+++ b/arch/x86/include/asm/paravirt.h
17385@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17386 return (pmd_t) { ret };
17387 }
17388
17389-static inline pmdval_t pmd_val(pmd_t pmd)
17390+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17391 {
17392 pmdval_t ret;
17393
17394@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17395 val);
17396 }
17397
17398+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17399+{
17400+ pgdval_t val = native_pgd_val(pgd);
17401+
17402+ if (sizeof(pgdval_t) > sizeof(long))
17403+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17404+ val, (u64)val >> 32);
17405+ else
17406+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17407+ val);
17408+}
17409+
17410 static inline void pgd_clear(pgd_t *pgdp)
17411 {
17412 set_pgd(pgdp, __pgd(0));
17413@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17414 pv_mmu_ops.set_fixmap(idx, phys, flags);
17415 }
17416
17417+#ifdef CONFIG_PAX_KERNEXEC
17418+static inline unsigned long pax_open_kernel(void)
17419+{
17420+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17421+}
17422+
17423+static inline unsigned long pax_close_kernel(void)
17424+{
17425+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17426+}
17427+#else
17428+static inline unsigned long pax_open_kernel(void) { return 0; }
17429+static inline unsigned long pax_close_kernel(void) { return 0; }
17430+#endif
17431+
17432 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17433
17434 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17435@@ -906,7 +933,7 @@ extern void default_banner(void);
17436
17437 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17438 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17439-#define PARA_INDIRECT(addr) *%cs:addr
17440+#define PARA_INDIRECT(addr) *%ss:addr
17441 #endif
17442
17443 #define INTERRUPT_RETURN \
17444@@ -981,6 +1008,21 @@ extern void default_banner(void);
17445 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17446 CLBR_NONE, \
17447 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17448+
17449+#define GET_CR0_INTO_RDI \
17450+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17451+ mov %rax,%rdi
17452+
17453+#define SET_RDI_INTO_CR0 \
17454+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17455+
17456+#define GET_CR3_INTO_RDI \
17457+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17458+ mov %rax,%rdi
17459+
17460+#define SET_RDI_INTO_CR3 \
17461+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17462+
17463 #endif /* CONFIG_X86_32 */
17464
17465 #endif /* __ASSEMBLY__ */
17466diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17467index 7549b8b..f0edfda 100644
17468--- a/arch/x86/include/asm/paravirt_types.h
17469+++ b/arch/x86/include/asm/paravirt_types.h
17470@@ -84,7 +84,7 @@ struct pv_init_ops {
17471 */
17472 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17473 unsigned long addr, unsigned len);
17474-};
17475+} __no_const __no_randomize_layout;
17476
17477
17478 struct pv_lazy_ops {
17479@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17480 void (*enter)(void);
17481 void (*leave)(void);
17482 void (*flush)(void);
17483-};
17484+} __no_randomize_layout;
17485
17486 struct pv_time_ops {
17487 unsigned long long (*sched_clock)(void);
17488 unsigned long long (*steal_clock)(int cpu);
17489 unsigned long (*get_tsc_khz)(void);
17490-};
17491+} __no_const __no_randomize_layout;
17492
17493 struct pv_cpu_ops {
17494 /* hooks for various privileged instructions */
17495@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17496
17497 void (*start_context_switch)(struct task_struct *prev);
17498 void (*end_context_switch)(struct task_struct *next);
17499-};
17500+} __no_const __no_randomize_layout;
17501
17502 struct pv_irq_ops {
17503 /*
17504@@ -215,7 +215,7 @@ struct pv_irq_ops {
17505 #ifdef CONFIG_X86_64
17506 void (*adjust_exception_frame)(void);
17507 #endif
17508-};
17509+} __no_randomize_layout;
17510
17511 struct pv_apic_ops {
17512 #ifdef CONFIG_X86_LOCAL_APIC
17513@@ -223,7 +223,7 @@ struct pv_apic_ops {
17514 unsigned long start_eip,
17515 unsigned long start_esp);
17516 #endif
17517-};
17518+} __no_const __no_randomize_layout;
17519
17520 struct pv_mmu_ops {
17521 unsigned long (*read_cr2)(void);
17522@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17523 struct paravirt_callee_save make_pud;
17524
17525 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17526+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17527 #endif /* PAGETABLE_LEVELS == 4 */
17528 #endif /* PAGETABLE_LEVELS >= 3 */
17529
17530@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17531 an mfn. We can tell which is which from the index. */
17532 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17533 phys_addr_t phys, pgprot_t flags);
17534-};
17535+
17536+#ifdef CONFIG_PAX_KERNEXEC
17537+ unsigned long (*pax_open_kernel)(void);
17538+ unsigned long (*pax_close_kernel)(void);
17539+#endif
17540+
17541+} __no_randomize_layout;
17542
17543 struct arch_spinlock;
17544 #ifdef CONFIG_SMP
17545@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17546 struct pv_lock_ops {
17547 struct paravirt_callee_save lock_spinning;
17548 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17549-};
17550+} __no_randomize_layout;
17551
17552 /* This contains all the paravirt structures: we get a convenient
17553 * number for each function using the offset which we use to indicate
17554- * what to patch. */
17555+ * what to patch.
17556+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17557+ */
17558+
17559 struct paravirt_patch_template {
17560 struct pv_init_ops pv_init_ops;
17561 struct pv_time_ops pv_time_ops;
17562@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17563 struct pv_apic_ops pv_apic_ops;
17564 struct pv_mmu_ops pv_mmu_ops;
17565 struct pv_lock_ops pv_lock_ops;
17566-};
17567+} __no_randomize_layout;
17568
17569 extern struct pv_info pv_info;
17570 extern struct pv_init_ops pv_init_ops;
17571diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17572index c4412e9..90e88c5 100644
17573--- a/arch/x86/include/asm/pgalloc.h
17574+++ b/arch/x86/include/asm/pgalloc.h
17575@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17576 pmd_t *pmd, pte_t *pte)
17577 {
17578 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17579+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17580+}
17581+
17582+static inline void pmd_populate_user(struct mm_struct *mm,
17583+ pmd_t *pmd, pte_t *pte)
17584+{
17585+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17586 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17587 }
17588
17589@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17590
17591 #ifdef CONFIG_X86_PAE
17592 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17593+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17594+{
17595+ pud_populate(mm, pudp, pmd);
17596+}
17597 #else /* !CONFIG_X86_PAE */
17598 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17599 {
17600 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17601 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17602 }
17603+
17604+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17605+{
17606+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17607+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17608+}
17609 #endif /* CONFIG_X86_PAE */
17610
17611 #if PAGETABLE_LEVELS > 3
17612@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17613 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17614 }
17615
17616+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17617+{
17618+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17619+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17620+}
17621+
17622 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17623 {
17624 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17625diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17626index 0d193e2..bf59aeb 100644
17627--- a/arch/x86/include/asm/pgtable-2level.h
17628+++ b/arch/x86/include/asm/pgtable-2level.h
17629@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17630
17631 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17632 {
17633+ pax_open_kernel();
17634 *pmdp = pmd;
17635+ pax_close_kernel();
17636 }
17637
17638 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17639diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17640index 81bb91b..9392125 100644
17641--- a/arch/x86/include/asm/pgtable-3level.h
17642+++ b/arch/x86/include/asm/pgtable-3level.h
17643@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17644
17645 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17646 {
17647+ pax_open_kernel();
17648 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17649+ pax_close_kernel();
17650 }
17651
17652 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17653 {
17654+ pax_open_kernel();
17655 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17656+ pax_close_kernel();
17657 }
17658
17659 /*
17660diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17661index b459ddf..b44081b 100644
17662--- a/arch/x86/include/asm/pgtable.h
17663+++ b/arch/x86/include/asm/pgtable.h
17664@@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17665
17666 #ifndef __PAGETABLE_PUD_FOLDED
17667 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17668+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17669 #define pgd_clear(pgd) native_pgd_clear(pgd)
17670 #endif
17671
17672@@ -83,12 +84,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17673
17674 #define arch_end_context_switch(prev) do {} while(0)
17675
17676+#define pax_open_kernel() native_pax_open_kernel()
17677+#define pax_close_kernel() native_pax_close_kernel()
17678 #endif /* CONFIG_PARAVIRT */
17679
17680+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17681+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17682+
17683+#ifdef CONFIG_PAX_KERNEXEC
17684+static inline unsigned long native_pax_open_kernel(void)
17685+{
17686+ unsigned long cr0;
17687+
17688+ preempt_disable();
17689+ barrier();
17690+ cr0 = read_cr0() ^ X86_CR0_WP;
17691+ BUG_ON(cr0 & X86_CR0_WP);
17692+ write_cr0(cr0);
17693+ return cr0 ^ X86_CR0_WP;
17694+}
17695+
17696+static inline unsigned long native_pax_close_kernel(void)
17697+{
17698+ unsigned long cr0;
17699+
17700+ cr0 = read_cr0() ^ X86_CR0_WP;
17701+ BUG_ON(!(cr0 & X86_CR0_WP));
17702+ write_cr0(cr0);
17703+ barrier();
17704+ preempt_enable_no_resched();
17705+ return cr0 ^ X86_CR0_WP;
17706+}
17707+#else
17708+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17709+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17710+#endif
17711+
17712 /*
17713 * The following only work if pte_present() is true.
17714 * Undefined behaviour if not..
17715 */
17716+static inline int pte_user(pte_t pte)
17717+{
17718+ return pte_val(pte) & _PAGE_USER;
17719+}
17720+
17721 static inline int pte_dirty(pte_t pte)
17722 {
17723 return pte_flags(pte) & _PAGE_DIRTY;
17724@@ -149,6 +189,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17725 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17726 }
17727
17728+static inline unsigned long pgd_pfn(pgd_t pgd)
17729+{
17730+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17731+}
17732+
17733 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17734
17735 static inline int pmd_large(pmd_t pte)
17736@@ -202,9 +247,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17737 return pte_clear_flags(pte, _PAGE_RW);
17738 }
17739
17740+static inline pte_t pte_mkread(pte_t pte)
17741+{
17742+ return __pte(pte_val(pte) | _PAGE_USER);
17743+}
17744+
17745 static inline pte_t pte_mkexec(pte_t pte)
17746 {
17747- return pte_clear_flags(pte, _PAGE_NX);
17748+#ifdef CONFIG_X86_PAE
17749+ if (__supported_pte_mask & _PAGE_NX)
17750+ return pte_clear_flags(pte, _PAGE_NX);
17751+ else
17752+#endif
17753+ return pte_set_flags(pte, _PAGE_USER);
17754+}
17755+
17756+static inline pte_t pte_exprotect(pte_t pte)
17757+{
17758+#ifdef CONFIG_X86_PAE
17759+ if (__supported_pte_mask & _PAGE_NX)
17760+ return pte_set_flags(pte, _PAGE_NX);
17761+ else
17762+#endif
17763+ return pte_clear_flags(pte, _PAGE_USER);
17764 }
17765
17766 static inline pte_t pte_mkdirty(pte_t pte)
17767@@ -431,6 +496,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17768 #endif
17769
17770 #ifndef __ASSEMBLY__
17771+
17772+#ifdef CONFIG_PAX_PER_CPU_PGD
17773+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17774+enum cpu_pgd_type {kernel = 0, user = 1};
17775+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17776+{
17777+ return cpu_pgd[cpu][type];
17778+}
17779+#endif
17780+
17781 #include <linux/mm_types.h>
17782 #include <linux/mmdebug.h>
17783 #include <linux/log2.h>
17784@@ -571,7 +646,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17785 * Currently stuck as a macro due to indirect forward reference to
17786 * linux/mmzone.h's __section_mem_map_addr() definition:
17787 */
17788-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17789+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17790
17791 /* Find an entry in the second-level page table.. */
17792 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17793@@ -611,7 +686,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17794 * Currently stuck as a macro due to indirect forward reference to
17795 * linux/mmzone.h's __section_mem_map_addr() definition:
17796 */
17797-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17798+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17799
17800 /* to find an entry in a page-table-directory. */
17801 static inline unsigned long pud_index(unsigned long address)
17802@@ -626,7 +701,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17803
17804 static inline int pgd_bad(pgd_t pgd)
17805 {
17806- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17807+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17808 }
17809
17810 static inline int pgd_none(pgd_t pgd)
17811@@ -649,7 +724,12 @@ static inline int pgd_none(pgd_t pgd)
17812 * pgd_offset() returns a (pgd_t *)
17813 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17814 */
17815-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17816+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17817+
17818+#ifdef CONFIG_PAX_PER_CPU_PGD
17819+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17820+#endif
17821+
17822 /*
17823 * a shortcut which implies the use of the kernel's pgd, instead
17824 * of a process's
17825@@ -660,6 +740,23 @@ static inline int pgd_none(pgd_t pgd)
17826 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17827 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17828
17829+#ifdef CONFIG_X86_32
17830+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17831+#else
17832+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17833+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17834+
17835+#ifdef CONFIG_PAX_MEMORY_UDEREF
17836+#ifdef __ASSEMBLY__
17837+#define pax_user_shadow_base pax_user_shadow_base(%rip)
17838+#else
17839+extern unsigned long pax_user_shadow_base;
17840+extern pgdval_t clone_pgd_mask;
17841+#endif
17842+#endif
17843+
17844+#endif
17845+
17846 #ifndef __ASSEMBLY__
17847
17848 extern int direct_gbpages;
17849@@ -826,11 +923,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17850 * dst and src can be on the same page, but the range must not overlap,
17851 * and must not cross a page boundary.
17852 */
17853-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17854+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17855 {
17856- memcpy(dst, src, count * sizeof(pgd_t));
17857+ pax_open_kernel();
17858+ while (count--)
17859+ *dst++ = *src++;
17860+ pax_close_kernel();
17861 }
17862
17863+#ifdef CONFIG_PAX_PER_CPU_PGD
17864+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17865+#endif
17866+
17867+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17868+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17869+#else
17870+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17871+#endif
17872+
17873 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17874 static inline int page_level_shift(enum pg_level level)
17875 {
17876diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17877index 9ee3221..b979c6b 100644
17878--- a/arch/x86/include/asm/pgtable_32.h
17879+++ b/arch/x86/include/asm/pgtable_32.h
17880@@ -25,9 +25,6 @@
17881 struct mm_struct;
17882 struct vm_area_struct;
17883
17884-extern pgd_t swapper_pg_dir[1024];
17885-extern pgd_t initial_page_table[1024];
17886-
17887 static inline void pgtable_cache_init(void) { }
17888 static inline void check_pgt_cache(void) { }
17889 void paging_init(void);
17890@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17891 # include <asm/pgtable-2level.h>
17892 #endif
17893
17894+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17895+extern pgd_t initial_page_table[PTRS_PER_PGD];
17896+#ifdef CONFIG_X86_PAE
17897+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17898+#endif
17899+
17900 #if defined(CONFIG_HIGHPTE)
17901 #define pte_offset_map(dir, address) \
17902 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17903@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17904 /* Clear a kernel PTE and flush it from the TLB */
17905 #define kpte_clear_flush(ptep, vaddr) \
17906 do { \
17907+ pax_open_kernel(); \
17908 pte_clear(&init_mm, (vaddr), (ptep)); \
17909+ pax_close_kernel(); \
17910 __flush_tlb_one((vaddr)); \
17911 } while (0)
17912
17913 #endif /* !__ASSEMBLY__ */
17914
17915+#define HAVE_ARCH_UNMAPPED_AREA
17916+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17917+
17918 /*
17919 * kern_addr_valid() is (1) for FLATMEM and (0) for
17920 * SPARSEMEM and DISCONTIGMEM
17921diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17922index ed5903b..c7fe163 100644
17923--- a/arch/x86/include/asm/pgtable_32_types.h
17924+++ b/arch/x86/include/asm/pgtable_32_types.h
17925@@ -8,7 +8,7 @@
17926 */
17927 #ifdef CONFIG_X86_PAE
17928 # include <asm/pgtable-3level_types.h>
17929-# define PMD_SIZE (1UL << PMD_SHIFT)
17930+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17931 # define PMD_MASK (~(PMD_SIZE - 1))
17932 #else
17933 # include <asm/pgtable-2level_types.h>
17934@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17935 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17936 #endif
17937
17938+#ifdef CONFIG_PAX_KERNEXEC
17939+#ifndef __ASSEMBLY__
17940+extern unsigned char MODULES_EXEC_VADDR[];
17941+extern unsigned char MODULES_EXEC_END[];
17942+#endif
17943+#include <asm/boot.h>
17944+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17945+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17946+#else
17947+#define ktla_ktva(addr) (addr)
17948+#define ktva_ktla(addr) (addr)
17949+#endif
17950+
17951 #define MODULES_VADDR VMALLOC_START
17952 #define MODULES_END VMALLOC_END
17953 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17954diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17955index e22c1db..23a625a 100644
17956--- a/arch/x86/include/asm/pgtable_64.h
17957+++ b/arch/x86/include/asm/pgtable_64.h
17958@@ -16,10 +16,14 @@
17959
17960 extern pud_t level3_kernel_pgt[512];
17961 extern pud_t level3_ident_pgt[512];
17962+extern pud_t level3_vmalloc_start_pgt[512];
17963+extern pud_t level3_vmalloc_end_pgt[512];
17964+extern pud_t level3_vmemmap_pgt[512];
17965+extern pud_t level2_vmemmap_pgt[512];
17966 extern pmd_t level2_kernel_pgt[512];
17967 extern pmd_t level2_fixmap_pgt[512];
17968-extern pmd_t level2_ident_pgt[512];
17969-extern pgd_t init_level4_pgt[];
17970+extern pmd_t level2_ident_pgt[512*2];
17971+extern pgd_t init_level4_pgt[512];
17972
17973 #define swapper_pg_dir init_level4_pgt
17974
17975@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17976
17977 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17978 {
17979+ pax_open_kernel();
17980 *pmdp = pmd;
17981+ pax_close_kernel();
17982 }
17983
17984 static inline void native_pmd_clear(pmd_t *pmd)
17985@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17986
17987 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17988 {
17989+ pax_open_kernel();
17990 *pudp = pud;
17991+ pax_close_kernel();
17992 }
17993
17994 static inline void native_pud_clear(pud_t *pud)
17995@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17996
17997 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17998 {
17999+ pax_open_kernel();
18000+ *pgdp = pgd;
18001+ pax_close_kernel();
18002+}
18003+
18004+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18005+{
18006 *pgdp = pgd;
18007 }
18008
18009diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18010index c883bf7..19970b3 100644
18011--- a/arch/x86/include/asm/pgtable_64_types.h
18012+++ b/arch/x86/include/asm/pgtable_64_types.h
18013@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
18014 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18015 #define MODULES_END _AC(0xffffffffff000000, UL)
18016 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18017+#define MODULES_EXEC_VADDR MODULES_VADDR
18018+#define MODULES_EXEC_END MODULES_END
18019+
18020+#define ktla_ktva(addr) (addr)
18021+#define ktva_ktla(addr) (addr)
18022
18023 #define EARLY_DYNAMIC_PAGE_TABLES 64
18024
18025diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18026index eb3d449..8d95316 100644
18027--- a/arch/x86/include/asm/pgtable_types.h
18028+++ b/arch/x86/include/asm/pgtable_types.h
18029@@ -16,13 +16,12 @@
18030 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
18031 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
18032 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
18033-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
18034+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
18035 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
18036 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
18037 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
18038-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
18039-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
18040-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
18041+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
18042+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
18043 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
18044
18045 /* If _PAGE_BIT_PRESENT is clear, we use these: */
18046@@ -40,7 +39,6 @@
18047 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
18048 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
18049 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
18050-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
18051 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
18052 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
18053 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
18054@@ -87,8 +85,10 @@
18055
18056 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18057 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18058-#else
18059+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18060 #define _PAGE_NX (_AT(pteval_t, 0))
18061+#else
18062+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18063 #endif
18064
18065 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18066@@ -147,6 +147,9 @@
18067 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18068 _PAGE_ACCESSED)
18069
18070+#define PAGE_READONLY_NOEXEC PAGE_READONLY
18071+#define PAGE_SHARED_NOEXEC PAGE_SHARED
18072+
18073 #define __PAGE_KERNEL_EXEC \
18074 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18075 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18076@@ -157,7 +160,7 @@
18077 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18078 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18079 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18080-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18081+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18082 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18083 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18084 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18085@@ -214,7 +217,7 @@
18086 #ifdef CONFIG_X86_64
18087 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18088 #else
18089-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18090+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18091 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18092 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18093 #endif
18094@@ -253,7 +256,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18095 {
18096 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18097 }
18098+#endif
18099
18100+#if PAGETABLE_LEVELS == 3
18101+#include <asm-generic/pgtable-nopud.h>
18102+#endif
18103+
18104+#if PAGETABLE_LEVELS == 2
18105+#include <asm-generic/pgtable-nopmd.h>
18106+#endif
18107+
18108+#ifndef __ASSEMBLY__
18109 #if PAGETABLE_LEVELS > 3
18110 typedef struct { pudval_t pud; } pud_t;
18111
18112@@ -267,8 +280,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18113 return pud.pud;
18114 }
18115 #else
18116-#include <asm-generic/pgtable-nopud.h>
18117-
18118 static inline pudval_t native_pud_val(pud_t pud)
18119 {
18120 return native_pgd_val(pud.pgd);
18121@@ -288,8 +299,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18122 return pmd.pmd;
18123 }
18124 #else
18125-#include <asm-generic/pgtable-nopmd.h>
18126-
18127 static inline pmdval_t native_pmd_val(pmd_t pmd)
18128 {
18129 return native_pgd_val(pmd.pud.pgd);
18130@@ -329,7 +338,6 @@ typedef struct page *pgtable_t;
18131
18132 extern pteval_t __supported_pte_mask;
18133 extern void set_nx(void);
18134-extern int nx_enabled;
18135
18136 #define pgprot_writecombine pgprot_writecombine
18137 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18138diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18139index 7024c12..71c46b9 100644
18140--- a/arch/x86/include/asm/preempt.h
18141+++ b/arch/x86/include/asm/preempt.h
18142@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18143 */
18144 static __always_inline bool __preempt_count_dec_and_test(void)
18145 {
18146- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18147+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18148 }
18149
18150 /*
18151diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18152index a4ea023..33aa874 100644
18153--- a/arch/x86/include/asm/processor.h
18154+++ b/arch/x86/include/asm/processor.h
18155@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18156 /* Index into per_cpu list: */
18157 u16 cpu_index;
18158 u32 microcode;
18159-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18160+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18161
18162 #define X86_VENDOR_INTEL 0
18163 #define X86_VENDOR_CYRIX 1
18164@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18165 : "memory");
18166 }
18167
18168+/* invpcid (%rdx),%rax */
18169+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18170+
18171+#define INVPCID_SINGLE_ADDRESS 0UL
18172+#define INVPCID_SINGLE_CONTEXT 1UL
18173+#define INVPCID_ALL_GLOBAL 2UL
18174+#define INVPCID_ALL_MONGLOBAL 3UL
18175+
18176+#define PCID_KERNEL 0UL
18177+#define PCID_USER 1UL
18178+#define PCID_NOFLUSH (1UL << 63)
18179+
18180 static inline void load_cr3(pgd_t *pgdir)
18181 {
18182- write_cr3(__pa(pgdir));
18183+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18184 }
18185
18186 #ifdef CONFIG_X86_32
18187@@ -283,7 +295,7 @@ struct tss_struct {
18188
18189 } ____cacheline_aligned;
18190
18191-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18192+extern struct tss_struct init_tss[NR_CPUS];
18193
18194 /*
18195 * Save the original ist values for checking stack pointers during debugging
18196@@ -479,6 +491,7 @@ struct thread_struct {
18197 unsigned short ds;
18198 unsigned short fsindex;
18199 unsigned short gsindex;
18200+ unsigned short ss;
18201 #endif
18202 #ifdef CONFIG_X86_32
18203 unsigned long ip;
18204@@ -588,29 +601,8 @@ static inline void load_sp0(struct tss_struct *tss,
18205 extern unsigned long mmu_cr4_features;
18206 extern u32 *trampoline_cr4_features;
18207
18208-static inline void set_in_cr4(unsigned long mask)
18209-{
18210- unsigned long cr4;
18211-
18212- mmu_cr4_features |= mask;
18213- if (trampoline_cr4_features)
18214- *trampoline_cr4_features = mmu_cr4_features;
18215- cr4 = read_cr4();
18216- cr4 |= mask;
18217- write_cr4(cr4);
18218-}
18219-
18220-static inline void clear_in_cr4(unsigned long mask)
18221-{
18222- unsigned long cr4;
18223-
18224- mmu_cr4_features &= ~mask;
18225- if (trampoline_cr4_features)
18226- *trampoline_cr4_features = mmu_cr4_features;
18227- cr4 = read_cr4();
18228- cr4 &= ~mask;
18229- write_cr4(cr4);
18230-}
18231+extern void set_in_cr4(unsigned long mask);
18232+extern void clear_in_cr4(unsigned long mask);
18233
18234 typedef struct {
18235 unsigned long seg;
18236@@ -836,11 +828,18 @@ static inline void spin_lock_prefetch(const void *x)
18237 */
18238 #define TASK_SIZE PAGE_OFFSET
18239 #define TASK_SIZE_MAX TASK_SIZE
18240+
18241+#ifdef CONFIG_PAX_SEGMEXEC
18242+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18243+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18244+#else
18245 #define STACK_TOP TASK_SIZE
18246-#define STACK_TOP_MAX STACK_TOP
18247+#endif
18248+
18249+#define STACK_TOP_MAX TASK_SIZE
18250
18251 #define INIT_THREAD { \
18252- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18253+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18254 .vm86_info = NULL, \
18255 .sysenter_cs = __KERNEL_CS, \
18256 .io_bitmap_ptr = NULL, \
18257@@ -854,7 +853,7 @@ static inline void spin_lock_prefetch(const void *x)
18258 */
18259 #define INIT_TSS { \
18260 .x86_tss = { \
18261- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18262+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18263 .ss0 = __KERNEL_DS, \
18264 .ss1 = __KERNEL_CS, \
18265 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18266@@ -865,11 +864,7 @@ static inline void spin_lock_prefetch(const void *x)
18267 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18268
18269 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18270-#define KSTK_TOP(info) \
18271-({ \
18272- unsigned long *__ptr = (unsigned long *)(info); \
18273- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18274-})
18275+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18276
18277 /*
18278 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18279@@ -884,7 +879,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18280 #define task_pt_regs(task) \
18281 ({ \
18282 struct pt_regs *__regs__; \
18283- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18284+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18285 __regs__ - 1; \
18286 })
18287
18288@@ -894,13 +889,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18289 /*
18290 * User space process size. 47bits minus one guard page.
18291 */
18292-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18293+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18294
18295 /* This decides where the kernel will search for a free chunk of vm
18296 * space during mmap's.
18297 */
18298 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18299- 0xc0000000 : 0xFFFFe000)
18300+ 0xc0000000 : 0xFFFFf000)
18301
18302 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18303 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18304@@ -911,11 +906,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18305 #define STACK_TOP_MAX TASK_SIZE_MAX
18306
18307 #define INIT_THREAD { \
18308- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18309+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18310 }
18311
18312 #define INIT_TSS { \
18313- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18314+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18315 }
18316
18317 /*
18318@@ -943,6 +938,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18319 */
18320 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18321
18322+#ifdef CONFIG_PAX_SEGMEXEC
18323+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18324+#endif
18325+
18326 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18327
18328 /* Get/set a process' ability to use the timestamp counter instruction */
18329@@ -969,7 +968,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18330 return 0;
18331 }
18332
18333-extern unsigned long arch_align_stack(unsigned long sp);
18334+#define arch_align_stack(x) ((x) & ~0xfUL)
18335 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18336
18337 void default_idle(void);
18338@@ -979,6 +978,6 @@ bool xen_set_default_idle(void);
18339 #define xen_set_default_idle 0
18340 #endif
18341
18342-void stop_this_cpu(void *dummy);
18343+void stop_this_cpu(void *dummy) __noreturn;
18344 void df_debug(struct pt_regs *regs, long error_code);
18345 #endif /* _ASM_X86_PROCESSOR_H */
18346diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18347index 14fd6fd..6740420 100644
18348--- a/arch/x86/include/asm/ptrace.h
18349+++ b/arch/x86/include/asm/ptrace.h
18350@@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18351 }
18352
18353 /*
18354- * user_mode_vm(regs) determines whether a register set came from user mode.
18355+ * user_mode(regs) determines whether a register set came from user mode.
18356 * This is true if V8086 mode was enabled OR if the register set was from
18357 * protected mode with RPL-3 CS value. This tricky test checks that with
18358 * one comparison. Many places in the kernel can bypass this full check
18359- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18360+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18361+ * be used.
18362 */
18363-static inline int user_mode(struct pt_regs *regs)
18364+static inline int user_mode_novm(struct pt_regs *regs)
18365 {
18366 #ifdef CONFIG_X86_32
18367 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18368 #else
18369- return !!(regs->cs & 3);
18370+ return !!(regs->cs & SEGMENT_RPL_MASK);
18371 #endif
18372 }
18373
18374-static inline int user_mode_vm(struct pt_regs *regs)
18375+static inline int user_mode(struct pt_regs *regs)
18376 {
18377 #ifdef CONFIG_X86_32
18378 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18379 USER_RPL;
18380 #else
18381- return user_mode(regs);
18382+ return user_mode_novm(regs);
18383 #endif
18384 }
18385
18386@@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18387 #ifdef CONFIG_X86_64
18388 static inline bool user_64bit_mode(struct pt_regs *regs)
18389 {
18390+ unsigned long cs = regs->cs & 0xffff;
18391 #ifndef CONFIG_PARAVIRT
18392 /*
18393 * On non-paravirt systems, this is the only long mode CPL 3
18394 * selector. We do not allow long mode selectors in the LDT.
18395 */
18396- return regs->cs == __USER_CS;
18397+ return cs == __USER_CS;
18398 #else
18399 /* Headers are too twisted for this to go in paravirt.h. */
18400- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18401+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18402 #endif
18403 }
18404
18405@@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18406 * Traps from the kernel do not save sp and ss.
18407 * Use the helper function to retrieve sp.
18408 */
18409- if (offset == offsetof(struct pt_regs, sp) &&
18410- regs->cs == __KERNEL_CS)
18411- return kernel_stack_pointer(regs);
18412+ if (offset == offsetof(struct pt_regs, sp)) {
18413+ unsigned long cs = regs->cs & 0xffff;
18414+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18415+ return kernel_stack_pointer(regs);
18416+ }
18417 #endif
18418 return *(unsigned long *)((unsigned long)regs + offset);
18419 }
18420diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18421index 9c6b890..5305f53 100644
18422--- a/arch/x86/include/asm/realmode.h
18423+++ b/arch/x86/include/asm/realmode.h
18424@@ -22,16 +22,14 @@ struct real_mode_header {
18425 #endif
18426 /* APM/BIOS reboot */
18427 u32 machine_real_restart_asm;
18428-#ifdef CONFIG_X86_64
18429 u32 machine_real_restart_seg;
18430-#endif
18431 };
18432
18433 /* This must match data at trampoline_32/64.S */
18434 struct trampoline_header {
18435 #ifdef CONFIG_X86_32
18436 u32 start;
18437- u16 gdt_pad;
18438+ u16 boot_cs;
18439 u16 gdt_limit;
18440 u32 gdt_base;
18441 #else
18442diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18443index a82c4f1..ac45053 100644
18444--- a/arch/x86/include/asm/reboot.h
18445+++ b/arch/x86/include/asm/reboot.h
18446@@ -6,13 +6,13 @@
18447 struct pt_regs;
18448
18449 struct machine_ops {
18450- void (*restart)(char *cmd);
18451- void (*halt)(void);
18452- void (*power_off)(void);
18453+ void (* __noreturn restart)(char *cmd);
18454+ void (* __noreturn halt)(void);
18455+ void (* __noreturn power_off)(void);
18456 void (*shutdown)(void);
18457 void (*crash_shutdown)(struct pt_regs *);
18458- void (*emergency_restart)(void);
18459-};
18460+ void (* __noreturn emergency_restart)(void);
18461+} __no_const;
18462
18463 extern struct machine_ops machine_ops;
18464
18465diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18466index 8f7866a..e442f20 100644
18467--- a/arch/x86/include/asm/rmwcc.h
18468+++ b/arch/x86/include/asm/rmwcc.h
18469@@ -3,7 +3,34 @@
18470
18471 #ifdef CC_HAVE_ASM_GOTO
18472
18473-#define __GEN_RMWcc(fullop, var, cc, ...) \
18474+#ifdef CONFIG_PAX_REFCOUNT
18475+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18476+do { \
18477+ asm_volatile_goto (fullop \
18478+ ";jno 0f\n" \
18479+ fullantiop \
18480+ ";int $4\n0:\n" \
18481+ _ASM_EXTABLE(0b, 0b) \
18482+ ";j" cc " %l[cc_label]" \
18483+ : : "m" (var), ## __VA_ARGS__ \
18484+ : "memory" : cc_label); \
18485+ return 0; \
18486+cc_label: \
18487+ return 1; \
18488+} while (0)
18489+#else
18490+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18491+do { \
18492+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18493+ : : "m" (var), ## __VA_ARGS__ \
18494+ : "memory" : cc_label); \
18495+ return 0; \
18496+cc_label: \
18497+ return 1; \
18498+} while (0)
18499+#endif
18500+
18501+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18502 do { \
18503 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18504 : : "m" (var), ## __VA_ARGS__ \
18505@@ -13,15 +40,46 @@ cc_label: \
18506 return 1; \
18507 } while (0)
18508
18509-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18510- __GEN_RMWcc(op " " arg0, var, cc)
18511+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18512+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18513
18514-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18515- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18516+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18517+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18518+
18519+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18520+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18521+
18522+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18523+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18524
18525 #else /* !CC_HAVE_ASM_GOTO */
18526
18527-#define __GEN_RMWcc(fullop, var, cc, ...) \
18528+#ifdef CONFIG_PAX_REFCOUNT
18529+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18530+do { \
18531+ char c; \
18532+ asm volatile (fullop \
18533+ ";jno 0f\n" \
18534+ fullantiop \
18535+ ";int $4\n0:\n" \
18536+ _ASM_EXTABLE(0b, 0b) \
18537+ "; set" cc " %1" \
18538+ : "+m" (var), "=qm" (c) \
18539+ : __VA_ARGS__ : "memory"); \
18540+ return c != 0; \
18541+} while (0)
18542+#else
18543+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18544+do { \
18545+ char c; \
18546+ asm volatile (fullop "; set" cc " %1" \
18547+ : "+m" (var), "=qm" (c) \
18548+ : __VA_ARGS__ : "memory"); \
18549+ return c != 0; \
18550+} while (0)
18551+#endif
18552+
18553+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18554 do { \
18555 char c; \
18556 asm volatile (fullop "; set" cc " %1" \
18557@@ -30,11 +88,17 @@ do { \
18558 return c != 0; \
18559 } while (0)
18560
18561-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18562- __GEN_RMWcc(op " " arg0, var, cc)
18563+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18564+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18565+
18566+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18567+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18568+
18569+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18570+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18571
18572-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18573- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18574+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18575+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18576
18577 #endif /* CC_HAVE_ASM_GOTO */
18578
18579diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18580index cad82c9..2e5c5c1 100644
18581--- a/arch/x86/include/asm/rwsem.h
18582+++ b/arch/x86/include/asm/rwsem.h
18583@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18584 {
18585 asm volatile("# beginning down_read\n\t"
18586 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18587+
18588+#ifdef CONFIG_PAX_REFCOUNT
18589+ "jno 0f\n"
18590+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18591+ "int $4\n0:\n"
18592+ _ASM_EXTABLE(0b, 0b)
18593+#endif
18594+
18595 /* adds 0x00000001 */
18596 " jns 1f\n"
18597 " call call_rwsem_down_read_failed\n"
18598@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18599 "1:\n\t"
18600 " mov %1,%2\n\t"
18601 " add %3,%2\n\t"
18602+
18603+#ifdef CONFIG_PAX_REFCOUNT
18604+ "jno 0f\n"
18605+ "sub %3,%2\n"
18606+ "int $4\n0:\n"
18607+ _ASM_EXTABLE(0b, 0b)
18608+#endif
18609+
18610 " jle 2f\n\t"
18611 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18612 " jnz 1b\n\t"
18613@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18614 long tmp;
18615 asm volatile("# beginning down_write\n\t"
18616 LOCK_PREFIX " xadd %1,(%2)\n\t"
18617+
18618+#ifdef CONFIG_PAX_REFCOUNT
18619+ "jno 0f\n"
18620+ "mov %1,(%2)\n"
18621+ "int $4\n0:\n"
18622+ _ASM_EXTABLE(0b, 0b)
18623+#endif
18624+
18625 /* adds 0xffff0001, returns the old value */
18626 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18627 /* was the active mask 0 before? */
18628@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18629 long tmp;
18630 asm volatile("# beginning __up_read\n\t"
18631 LOCK_PREFIX " xadd %1,(%2)\n\t"
18632+
18633+#ifdef CONFIG_PAX_REFCOUNT
18634+ "jno 0f\n"
18635+ "mov %1,(%2)\n"
18636+ "int $4\n0:\n"
18637+ _ASM_EXTABLE(0b, 0b)
18638+#endif
18639+
18640 /* subtracts 1, returns the old value */
18641 " jns 1f\n\t"
18642 " call call_rwsem_wake\n" /* expects old value in %edx */
18643@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18644 long tmp;
18645 asm volatile("# beginning __up_write\n\t"
18646 LOCK_PREFIX " xadd %1,(%2)\n\t"
18647+
18648+#ifdef CONFIG_PAX_REFCOUNT
18649+ "jno 0f\n"
18650+ "mov %1,(%2)\n"
18651+ "int $4\n0:\n"
18652+ _ASM_EXTABLE(0b, 0b)
18653+#endif
18654+
18655 /* subtracts 0xffff0001, returns the old value */
18656 " jns 1f\n\t"
18657 " call call_rwsem_wake\n" /* expects old value in %edx */
18658@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18659 {
18660 asm volatile("# beginning __downgrade_write\n\t"
18661 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18662+
18663+#ifdef CONFIG_PAX_REFCOUNT
18664+ "jno 0f\n"
18665+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18666+ "int $4\n0:\n"
18667+ _ASM_EXTABLE(0b, 0b)
18668+#endif
18669+
18670 /*
18671 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18672 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18673@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18674 */
18675 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18676 {
18677- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18678+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18679+
18680+#ifdef CONFIG_PAX_REFCOUNT
18681+ "jno 0f\n"
18682+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18683+ "int $4\n0:\n"
18684+ _ASM_EXTABLE(0b, 0b)
18685+#endif
18686+
18687 : "+m" (sem->count)
18688 : "er" (delta));
18689 }
18690@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18691 */
18692 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18693 {
18694- return delta + xadd(&sem->count, delta);
18695+ return delta + xadd_check_overflow(&sem->count, delta);
18696 }
18697
18698 #endif /* __KERNEL__ */
18699diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18700index 6f1c3a8..7744f19 100644
18701--- a/arch/x86/include/asm/segment.h
18702+++ b/arch/x86/include/asm/segment.h
18703@@ -64,10 +64,15 @@
18704 * 26 - ESPFIX small SS
18705 * 27 - per-cpu [ offset to per-cpu data area ]
18706 * 28 - stack_canary-20 [ for stack protector ]
18707- * 29 - unused
18708- * 30 - unused
18709+ * 29 - PCI BIOS CS
18710+ * 30 - PCI BIOS DS
18711 * 31 - TSS for double fault handler
18712 */
18713+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18714+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18715+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18716+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18717+
18718 #define GDT_ENTRY_TLS_MIN 6
18719 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18720
18721@@ -79,6 +84,8 @@
18722
18723 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18724
18725+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18726+
18727 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18728
18729 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18730@@ -104,6 +111,12 @@
18731 #define __KERNEL_STACK_CANARY 0
18732 #endif
18733
18734+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18735+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18736+
18737+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18738+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18739+
18740 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18741
18742 /*
18743@@ -141,7 +154,7 @@
18744 */
18745
18746 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18747-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18748+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18749
18750
18751 #else
18752@@ -165,6 +178,8 @@
18753 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18754 #define __USER32_DS __USER_DS
18755
18756+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18757+
18758 #define GDT_ENTRY_TSS 8 /* needs two entries */
18759 #define GDT_ENTRY_LDT 10 /* needs two entries */
18760 #define GDT_ENTRY_TLS_MIN 12
18761@@ -173,6 +188,8 @@
18762 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18763 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18764
18765+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18766+
18767 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18768 #define FS_TLS 0
18769 #define GS_TLS 1
18770@@ -180,12 +197,14 @@
18771 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18772 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18773
18774-#define GDT_ENTRIES 16
18775+#define GDT_ENTRIES 17
18776
18777 #endif
18778
18779 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18780+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18781 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18782+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18783 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18784 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18785 #ifndef CONFIG_PARAVIRT
18786@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18787 {
18788 unsigned long __limit;
18789 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18790- return __limit + 1;
18791+ return __limit;
18792 }
18793
18794 #endif /* !__ASSEMBLY__ */
18795diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18796index 8d3120f..352b440 100644
18797--- a/arch/x86/include/asm/smap.h
18798+++ b/arch/x86/include/asm/smap.h
18799@@ -25,11 +25,40 @@
18800
18801 #include <asm/alternative-asm.h>
18802
18803+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18804+#define ASM_PAX_OPEN_USERLAND \
18805+ 661: jmp 663f; \
18806+ .pushsection .altinstr_replacement, "a" ; \
18807+ 662: pushq %rax; nop; \
18808+ .popsection ; \
18809+ .pushsection .altinstructions, "a" ; \
18810+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18811+ .popsection ; \
18812+ call __pax_open_userland; \
18813+ popq %rax; \
18814+ 663:
18815+
18816+#define ASM_PAX_CLOSE_USERLAND \
18817+ 661: jmp 663f; \
18818+ .pushsection .altinstr_replacement, "a" ; \
18819+ 662: pushq %rax; nop; \
18820+ .popsection; \
18821+ .pushsection .altinstructions, "a" ; \
18822+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18823+ .popsection; \
18824+ call __pax_close_userland; \
18825+ popq %rax; \
18826+ 663:
18827+#else
18828+#define ASM_PAX_OPEN_USERLAND
18829+#define ASM_PAX_CLOSE_USERLAND
18830+#endif
18831+
18832 #ifdef CONFIG_X86_SMAP
18833
18834 #define ASM_CLAC \
18835 661: ASM_NOP3 ; \
18836- .pushsection .altinstr_replacement, "ax" ; \
18837+ .pushsection .altinstr_replacement, "a" ; \
18838 662: __ASM_CLAC ; \
18839 .popsection ; \
18840 .pushsection .altinstructions, "a" ; \
18841@@ -38,7 +67,7 @@
18842
18843 #define ASM_STAC \
18844 661: ASM_NOP3 ; \
18845- .pushsection .altinstr_replacement, "ax" ; \
18846+ .pushsection .altinstr_replacement, "a" ; \
18847 662: __ASM_STAC ; \
18848 .popsection ; \
18849 .pushsection .altinstructions, "a" ; \
18850@@ -56,6 +85,37 @@
18851
18852 #include <asm/alternative.h>
18853
18854+#define __HAVE_ARCH_PAX_OPEN_USERLAND
18855+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18856+
18857+extern void __pax_open_userland(void);
18858+static __always_inline unsigned long pax_open_userland(void)
18859+{
18860+
18861+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18862+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18863+ :
18864+ : [open] "i" (__pax_open_userland)
18865+ : "memory", "rax");
18866+#endif
18867+
18868+ return 0;
18869+}
18870+
18871+extern void __pax_close_userland(void);
18872+static __always_inline unsigned long pax_close_userland(void)
18873+{
18874+
18875+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18876+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18877+ :
18878+ : [close] "i" (__pax_close_userland)
18879+ : "memory", "rax");
18880+#endif
18881+
18882+ return 0;
18883+}
18884+
18885 #ifdef CONFIG_X86_SMAP
18886
18887 static __always_inline void clac(void)
18888diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18889index 8cd27e0..7f05ec8 100644
18890--- a/arch/x86/include/asm/smp.h
18891+++ b/arch/x86/include/asm/smp.h
18892@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18893 /* cpus sharing the last level cache: */
18894 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18895 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18896-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18897+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18898
18899 static inline struct cpumask *cpu_sibling_mask(int cpu)
18900 {
18901@@ -78,7 +78,7 @@ struct smp_ops {
18902
18903 void (*send_call_func_ipi)(const struct cpumask *mask);
18904 void (*send_call_func_single_ipi)(int cpu);
18905-};
18906+} __no_const;
18907
18908 /* Globals due to paravirt */
18909 extern void set_cpu_sibling_map(int cpu);
18910@@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
18911 extern int safe_smp_processor_id(void);
18912
18913 #elif defined(CONFIG_X86_64_SMP)
18914-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18915-
18916-#define stack_smp_processor_id() \
18917-({ \
18918- struct thread_info *ti; \
18919- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18920- ti->cpu; \
18921-})
18922+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18923+#define stack_smp_processor_id() raw_smp_processor_id()
18924 #define safe_smp_processor_id() smp_processor_id()
18925
18926 #endif
18927diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18928index 0f62f54..cb5d0dd 100644
18929--- a/arch/x86/include/asm/spinlock.h
18930+++ b/arch/x86/include/asm/spinlock.h
18931@@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18932 static inline void arch_read_lock(arch_rwlock_t *rw)
18933 {
18934 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18935+
18936+#ifdef CONFIG_PAX_REFCOUNT
18937+ "jno 0f\n"
18938+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18939+ "int $4\n0:\n"
18940+ _ASM_EXTABLE(0b, 0b)
18941+#endif
18942+
18943 "jns 1f\n"
18944 "call __read_lock_failed\n\t"
18945 "1:\n"
18946@@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18947 static inline void arch_write_lock(arch_rwlock_t *rw)
18948 {
18949 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18950+
18951+#ifdef CONFIG_PAX_REFCOUNT
18952+ "jno 0f\n"
18953+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18954+ "int $4\n0:\n"
18955+ _ASM_EXTABLE(0b, 0b)
18956+#endif
18957+
18958 "jz 1f\n"
18959 "call __write_lock_failed\n\t"
18960 "1:\n"
18961@@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18962
18963 static inline void arch_read_unlock(arch_rwlock_t *rw)
18964 {
18965- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18966+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18967+
18968+#ifdef CONFIG_PAX_REFCOUNT
18969+ "jno 0f\n"
18970+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18971+ "int $4\n0:\n"
18972+ _ASM_EXTABLE(0b, 0b)
18973+#endif
18974+
18975 :"+m" (rw->lock) : : "memory");
18976 }
18977
18978 static inline void arch_write_unlock(arch_rwlock_t *rw)
18979 {
18980- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18981+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18982+
18983+#ifdef CONFIG_PAX_REFCOUNT
18984+ "jno 0f\n"
18985+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18986+ "int $4\n0:\n"
18987+ _ASM_EXTABLE(0b, 0b)
18988+#endif
18989+
18990 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18991 }
18992
18993diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18994index 6a99859..03cb807 100644
18995--- a/arch/x86/include/asm/stackprotector.h
18996+++ b/arch/x86/include/asm/stackprotector.h
18997@@ -47,7 +47,7 @@
18998 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18999 */
19000 #define GDT_STACK_CANARY_INIT \
19001- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19002+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19003
19004 /*
19005 * Initialize the stackprotector canary value.
19006@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19007
19008 static inline void load_stack_canary_segment(void)
19009 {
19010-#ifdef CONFIG_X86_32
19011+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19012 asm volatile ("mov %0, %%gs" : : "r" (0));
19013 #endif
19014 }
19015diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19016index 70bbe39..4ae2bd4 100644
19017--- a/arch/x86/include/asm/stacktrace.h
19018+++ b/arch/x86/include/asm/stacktrace.h
19019@@ -11,28 +11,20 @@
19020
19021 extern int kstack_depth_to_print;
19022
19023-struct thread_info;
19024+struct task_struct;
19025 struct stacktrace_ops;
19026
19027-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19028- unsigned long *stack,
19029- unsigned long bp,
19030- const struct stacktrace_ops *ops,
19031- void *data,
19032- unsigned long *end,
19033- int *graph);
19034+typedef unsigned long walk_stack_t(struct task_struct *task,
19035+ void *stack_start,
19036+ unsigned long *stack,
19037+ unsigned long bp,
19038+ const struct stacktrace_ops *ops,
19039+ void *data,
19040+ unsigned long *end,
19041+ int *graph);
19042
19043-extern unsigned long
19044-print_context_stack(struct thread_info *tinfo,
19045- unsigned long *stack, unsigned long bp,
19046- const struct stacktrace_ops *ops, void *data,
19047- unsigned long *end, int *graph);
19048-
19049-extern unsigned long
19050-print_context_stack_bp(struct thread_info *tinfo,
19051- unsigned long *stack, unsigned long bp,
19052- const struct stacktrace_ops *ops, void *data,
19053- unsigned long *end, int *graph);
19054+extern walk_stack_t print_context_stack;
19055+extern walk_stack_t print_context_stack_bp;
19056
19057 /* Generic stack tracer with callbacks */
19058
19059@@ -40,7 +32,7 @@ struct stacktrace_ops {
19060 void (*address)(void *data, unsigned long address, int reliable);
19061 /* On negative return stop dumping */
19062 int (*stack)(void *data, char *name);
19063- walk_stack_t walk_stack;
19064+ walk_stack_t *walk_stack;
19065 };
19066
19067 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19068diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19069index d7f3b3b..3cc39f1 100644
19070--- a/arch/x86/include/asm/switch_to.h
19071+++ b/arch/x86/include/asm/switch_to.h
19072@@ -108,7 +108,7 @@ do { \
19073 "call __switch_to\n\t" \
19074 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19075 __switch_canary \
19076- "movq %P[thread_info](%%rsi),%%r8\n\t" \
19077+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19078 "movq %%rax,%%rdi\n\t" \
19079 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19080 "jnz ret_from_fork\n\t" \
19081@@ -119,7 +119,7 @@ do { \
19082 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19083 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19084 [_tif_fork] "i" (_TIF_FORK), \
19085- [thread_info] "i" (offsetof(struct task_struct, stack)), \
19086+ [thread_info] "m" (current_tinfo), \
19087 [current_task] "m" (current_task) \
19088 __switch_canary_iparam \
19089 : "memory", "cc" __EXTRA_CLOBBER)
19090diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19091index 47e5de2..d3dda54 100644
19092--- a/arch/x86/include/asm/thread_info.h
19093+++ b/arch/x86/include/asm/thread_info.h
19094@@ -24,7 +24,6 @@ struct exec_domain;
19095 #include <linux/atomic.h>
19096
19097 struct thread_info {
19098- struct task_struct *task; /* main task structure */
19099 struct exec_domain *exec_domain; /* execution domain */
19100 __u32 flags; /* low level flags */
19101 __u32 status; /* thread synchronous flags */
19102@@ -33,13 +32,13 @@ struct thread_info {
19103 mm_segment_t addr_limit;
19104 struct restart_block restart_block;
19105 void __user *sysenter_return;
19106+ unsigned long lowest_stack;
19107 unsigned int sig_on_uaccess_error:1;
19108 unsigned int uaccess_err:1; /* uaccess failed */
19109 };
19110
19111-#define INIT_THREAD_INFO(tsk) \
19112+#define INIT_THREAD_INFO \
19113 { \
19114- .task = &tsk, \
19115 .exec_domain = &default_exec_domain, \
19116 .flags = 0, \
19117 .cpu = 0, \
19118@@ -50,7 +49,7 @@ struct thread_info {
19119 }, \
19120 }
19121
19122-#define init_thread_info (init_thread_union.thread_info)
19123+#define init_thread_info (init_thread_union.stack)
19124 #define init_stack (init_thread_union.stack)
19125
19126 #else /* !__ASSEMBLY__ */
19127@@ -90,6 +89,7 @@ struct thread_info {
19128 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19129 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19130 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19131+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19132
19133 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19134 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19135@@ -113,17 +113,18 @@ struct thread_info {
19136 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19137 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19138 #define _TIF_X32 (1 << TIF_X32)
19139+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19140
19141 /* work to do in syscall_trace_enter() */
19142 #define _TIF_WORK_SYSCALL_ENTRY \
19143 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19144 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19145- _TIF_NOHZ)
19146+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19147
19148 /* work to do in syscall_trace_leave() */
19149 #define _TIF_WORK_SYSCALL_EXIT \
19150 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19151- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19152+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19153
19154 /* work to do on interrupt/exception return */
19155 #define _TIF_WORK_MASK \
19156@@ -134,7 +135,7 @@ struct thread_info {
19157 /* work to do on any return to user space */
19158 #define _TIF_ALLWORK_MASK \
19159 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19160- _TIF_NOHZ)
19161+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19162
19163 /* Only used for 64 bit */
19164 #define _TIF_DO_NOTIFY_MASK \
19165@@ -149,7 +150,6 @@ struct thread_info {
19166 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19167
19168 #define STACK_WARN (THREAD_SIZE/8)
19169-#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19170
19171 /*
19172 * macros/functions for gaining access to the thread information structure
19173@@ -160,26 +160,18 @@ struct thread_info {
19174
19175 DECLARE_PER_CPU(unsigned long, kernel_stack);
19176
19177+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19178+
19179 static inline struct thread_info *current_thread_info(void)
19180 {
19181- struct thread_info *ti;
19182- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19183- KERNEL_STACK_OFFSET - THREAD_SIZE);
19184- return ti;
19185+ return this_cpu_read_stable(current_tinfo);
19186 }
19187
19188 #else /* !__ASSEMBLY__ */
19189
19190 /* how to get the thread information struct from ASM */
19191 #define GET_THREAD_INFO(reg) \
19192- _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19193- _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19194-
19195-/*
19196- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19197- * a certain register (to be used in assembler memory operands).
19198- */
19199-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19200+ _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19201
19202 #endif
19203
19204@@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19205 extern void arch_task_cache_init(void);
19206 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19207 extern void arch_release_task_struct(struct task_struct *tsk);
19208+
19209+#define __HAVE_THREAD_FUNCTIONS
19210+#define task_thread_info(task) (&(task)->tinfo)
19211+#define task_stack_page(task) ((task)->stack)
19212+#define setup_thread_stack(p, org) do {} while (0)
19213+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19214+
19215 #endif
19216 #endif /* _ASM_X86_THREAD_INFO_H */
19217diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19218index 04905bf..49203ca 100644
19219--- a/arch/x86/include/asm/tlbflush.h
19220+++ b/arch/x86/include/asm/tlbflush.h
19221@@ -17,18 +17,44 @@
19222
19223 static inline void __native_flush_tlb(void)
19224 {
19225+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19226+ u64 descriptor[2];
19227+
19228+ descriptor[0] = PCID_KERNEL;
19229+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19230+ return;
19231+ }
19232+
19233+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19234+ if (static_cpu_has(X86_FEATURE_PCID)) {
19235+ unsigned int cpu = raw_get_cpu();
19236+
19237+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19238+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19239+ raw_put_cpu_no_resched();
19240+ return;
19241+ }
19242+#endif
19243+
19244 native_write_cr3(native_read_cr3());
19245 }
19246
19247 static inline void __native_flush_tlb_global_irq_disabled(void)
19248 {
19249- unsigned long cr4;
19250+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19251+ u64 descriptor[2];
19252
19253- cr4 = native_read_cr4();
19254- /* clear PGE */
19255- native_write_cr4(cr4 & ~X86_CR4_PGE);
19256- /* write old PGE again and flush TLBs */
19257- native_write_cr4(cr4);
19258+ descriptor[0] = PCID_KERNEL;
19259+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19260+ } else {
19261+ unsigned long cr4;
19262+
19263+ cr4 = native_read_cr4();
19264+ /* clear PGE */
19265+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19266+ /* write old PGE again and flush TLBs */
19267+ native_write_cr4(cr4);
19268+ }
19269 }
19270
19271 static inline void __native_flush_tlb_global(void)
19272@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19273
19274 static inline void __native_flush_tlb_single(unsigned long addr)
19275 {
19276+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19277+ u64 descriptor[2];
19278+
19279+ descriptor[0] = PCID_KERNEL;
19280+ descriptor[1] = addr;
19281+
19282+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19283+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19284+ if (addr < TASK_SIZE_MAX)
19285+ descriptor[1] += pax_user_shadow_base;
19286+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19287+ }
19288+
19289+ descriptor[0] = PCID_USER;
19290+ descriptor[1] = addr;
19291+#endif
19292+
19293+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19294+ return;
19295+ }
19296+
19297+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19298+ if (static_cpu_has(X86_FEATURE_PCID)) {
19299+ unsigned int cpu = raw_get_cpu();
19300+
19301+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19302+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19303+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19304+ raw_put_cpu_no_resched();
19305+
19306+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19307+ addr += pax_user_shadow_base;
19308+ }
19309+#endif
19310+
19311 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19312 }
19313
19314diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19315index 0d592e0..7437fcc 100644
19316--- a/arch/x86/include/asm/uaccess.h
19317+++ b/arch/x86/include/asm/uaccess.h
19318@@ -7,6 +7,7 @@
19319 #include <linux/compiler.h>
19320 #include <linux/thread_info.h>
19321 #include <linux/string.h>
19322+#include <linux/spinlock.h>
19323 #include <asm/asm.h>
19324 #include <asm/page.h>
19325 #include <asm/smap.h>
19326@@ -29,7 +30,12 @@
19327
19328 #define get_ds() (KERNEL_DS)
19329 #define get_fs() (current_thread_info()->addr_limit)
19330+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19331+void __set_fs(mm_segment_t x);
19332+void set_fs(mm_segment_t x);
19333+#else
19334 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19335+#endif
19336
19337 #define segment_eq(a, b) ((a).seg == (b).seg)
19338
19339@@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19340 * checks that the pointer is in the user space range - after calling
19341 * this function, memory access functions may still return -EFAULT.
19342 */
19343-#define access_ok(type, addr, size) \
19344- likely(!__range_not_ok(addr, size, user_addr_max()))
19345+extern int _cond_resched(void);
19346+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19347+#define access_ok(type, addr, size) \
19348+({ \
19349+ unsigned long __size = size; \
19350+ unsigned long __addr = (unsigned long)addr; \
19351+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19352+ if (__ret_ao && __size) { \
19353+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19354+ unsigned long __end_ao = __addr + __size - 1; \
19355+ if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19356+ while (__addr_ao <= __end_ao) { \
19357+ char __c_ao; \
19358+ __addr_ao += PAGE_SIZE; \
19359+ if (__size > PAGE_SIZE) \
19360+ _cond_resched(); \
19361+ if (__get_user(__c_ao, (char __user *)__addr)) \
19362+ break; \
19363+ if (type != VERIFY_WRITE) { \
19364+ __addr = __addr_ao; \
19365+ continue; \
19366+ } \
19367+ if (__put_user(__c_ao, (char __user *)__addr)) \
19368+ break; \
19369+ __addr = __addr_ao; \
19370+ } \
19371+ } \
19372+ } \
19373+ __ret_ao; \
19374+})
19375
19376 /*
19377 * The exception table consists of pairs of addresses relative to the
19378@@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19379 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19380 __chk_user_ptr(ptr); \
19381 might_fault(); \
19382+ pax_open_userland(); \
19383 asm volatile("call __get_user_%P3" \
19384 : "=a" (__ret_gu), "=r" (__val_gu) \
19385 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19386 (x) = (__typeof__(*(ptr))) __val_gu; \
19387+ pax_close_userland(); \
19388 __ret_gu; \
19389 })
19390
19391@@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19392 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19393 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19394
19395-
19396+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19397+#define __copyuser_seg "gs;"
19398+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19399+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19400+#else
19401+#define __copyuser_seg
19402+#define __COPYUSER_SET_ES
19403+#define __COPYUSER_RESTORE_ES
19404+#endif
19405
19406 #ifdef CONFIG_X86_32
19407 #define __put_user_asm_u64(x, addr, err, errret) \
19408 asm volatile(ASM_STAC "\n" \
19409- "1: movl %%eax,0(%2)\n" \
19410- "2: movl %%edx,4(%2)\n" \
19411+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19412+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19413 "3: " ASM_CLAC "\n" \
19414 ".section .fixup,\"ax\"\n" \
19415 "4: movl %3,%0\n" \
19416@@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19417
19418 #define __put_user_asm_ex_u64(x, addr) \
19419 asm volatile(ASM_STAC "\n" \
19420- "1: movl %%eax,0(%1)\n" \
19421- "2: movl %%edx,4(%1)\n" \
19422+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19423+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19424 "3: " ASM_CLAC "\n" \
19425 _ASM_EXTABLE_EX(1b, 2b) \
19426 _ASM_EXTABLE_EX(2b, 3b) \
19427@@ -257,7 +301,8 @@ extern void __put_user_8(void);
19428 __typeof__(*(ptr)) __pu_val; \
19429 __chk_user_ptr(ptr); \
19430 might_fault(); \
19431- __pu_val = x; \
19432+ __pu_val = (x); \
19433+ pax_open_userland(); \
19434 switch (sizeof(*(ptr))) { \
19435 case 1: \
19436 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19437@@ -275,6 +320,7 @@ extern void __put_user_8(void);
19438 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19439 break; \
19440 } \
19441+ pax_close_userland(); \
19442 __ret_pu; \
19443 })
19444
19445@@ -355,8 +401,10 @@ do { \
19446 } while (0)
19447
19448 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19449+do { \
19450+ pax_open_userland(); \
19451 asm volatile(ASM_STAC "\n" \
19452- "1: mov"itype" %2,%"rtype"1\n" \
19453+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19454 "2: " ASM_CLAC "\n" \
19455 ".section .fixup,\"ax\"\n" \
19456 "3: mov %3,%0\n" \
19457@@ -364,8 +412,10 @@ do { \
19458 " jmp 2b\n" \
19459 ".previous\n" \
19460 _ASM_EXTABLE(1b, 3b) \
19461- : "=r" (err), ltype(x) \
19462- : "m" (__m(addr)), "i" (errret), "0" (err))
19463+ : "=r" (err), ltype (x) \
19464+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19465+ pax_close_userland(); \
19466+} while (0)
19467
19468 #define __get_user_size_ex(x, ptr, size) \
19469 do { \
19470@@ -389,7 +439,7 @@ do { \
19471 } while (0)
19472
19473 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19474- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19475+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19476 "2:\n" \
19477 _ASM_EXTABLE_EX(1b, 2b) \
19478 : ltype(x) : "m" (__m(addr)))
19479@@ -406,13 +456,24 @@ do { \
19480 int __gu_err; \
19481 unsigned long __gu_val; \
19482 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19483- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19484+ (x) = (__typeof__(*(ptr)))__gu_val; \
19485 __gu_err; \
19486 })
19487
19488 /* FIXME: this hack is definitely wrong -AK */
19489 struct __large_struct { unsigned long buf[100]; };
19490-#define __m(x) (*(struct __large_struct __user *)(x))
19491+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19492+#define ____m(x) \
19493+({ \
19494+ unsigned long ____x = (unsigned long)(x); \
19495+ if (____x < pax_user_shadow_base) \
19496+ ____x += pax_user_shadow_base; \
19497+ (typeof(x))____x; \
19498+})
19499+#else
19500+#define ____m(x) (x)
19501+#endif
19502+#define __m(x) (*(struct __large_struct __user *)____m(x))
19503
19504 /*
19505 * Tell gcc we read from memory instead of writing: this is because
19506@@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19507 * aliasing issues.
19508 */
19509 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19510+do { \
19511+ pax_open_userland(); \
19512 asm volatile(ASM_STAC "\n" \
19513- "1: mov"itype" %"rtype"1,%2\n" \
19514+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19515 "2: " ASM_CLAC "\n" \
19516 ".section .fixup,\"ax\"\n" \
19517 "3: mov %3,%0\n" \
19518@@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19519 ".previous\n" \
19520 _ASM_EXTABLE(1b, 3b) \
19521 : "=r"(err) \
19522- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19523+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19524+ pax_close_userland(); \
19525+} while (0)
19526
19527 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19528- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19529+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19530 "2:\n" \
19531 _ASM_EXTABLE_EX(1b, 2b) \
19532 : : ltype(x), "m" (__m(addr)))
19533@@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19534 */
19535 #define uaccess_try do { \
19536 current_thread_info()->uaccess_err = 0; \
19537+ pax_open_userland(); \
19538 stac(); \
19539 barrier();
19540
19541 #define uaccess_catch(err) \
19542 clac(); \
19543+ pax_close_userland(); \
19544 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19545 } while (0)
19546
19547@@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19548 * On error, the variable @x is set to zero.
19549 */
19550
19551+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19552+#define __get_user(x, ptr) get_user((x), (ptr))
19553+#else
19554 #define __get_user(x, ptr) \
19555 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19556+#endif
19557
19558 /**
19559 * __put_user: - Write a simple value into user space, with less checking.
19560@@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19561 * Returns zero on success, or -EFAULT on error.
19562 */
19563
19564+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19565+#define __put_user(x, ptr) put_user((x), (ptr))
19566+#else
19567 #define __put_user(x, ptr) \
19568 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19569+#endif
19570
19571 #define __get_user_unaligned __get_user
19572 #define __put_user_unaligned __put_user
19573@@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19574 #define get_user_ex(x, ptr) do { \
19575 unsigned long __gue_val; \
19576 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19577- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19578+ (x) = (__typeof__(*(ptr)))__gue_val; \
19579 } while (0)
19580
19581 #define put_user_try uaccess_try
19582@@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19583 __typeof__(ptr) __uval = (uval); \
19584 __typeof__(*(ptr)) __old = (old); \
19585 __typeof__(*(ptr)) __new = (new); \
19586+ pax_open_userland(); \
19587 switch (size) { \
19588 case 1: \
19589 { \
19590 asm volatile("\t" ASM_STAC "\n" \
19591- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19592+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19593 "2:\t" ASM_CLAC "\n" \
19594 "\t.section .fixup, \"ax\"\n" \
19595 "3:\tmov %3, %0\n" \
19596 "\tjmp 2b\n" \
19597 "\t.previous\n" \
19598 _ASM_EXTABLE(1b, 3b) \
19599- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19600+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19601 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19602 : "memory" \
19603 ); \
19604@@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19605 case 2: \
19606 { \
19607 asm volatile("\t" ASM_STAC "\n" \
19608- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19609+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19610 "2:\t" ASM_CLAC "\n" \
19611 "\t.section .fixup, \"ax\"\n" \
19612 "3:\tmov %3, %0\n" \
19613 "\tjmp 2b\n" \
19614 "\t.previous\n" \
19615 _ASM_EXTABLE(1b, 3b) \
19616- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19617+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19618 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19619 : "memory" \
19620 ); \
19621@@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19622 case 4: \
19623 { \
19624 asm volatile("\t" ASM_STAC "\n" \
19625- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19626+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19627 "2:\t" ASM_CLAC "\n" \
19628 "\t.section .fixup, \"ax\"\n" \
19629 "3:\tmov %3, %0\n" \
19630 "\tjmp 2b\n" \
19631 "\t.previous\n" \
19632 _ASM_EXTABLE(1b, 3b) \
19633- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19634+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19635 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19636 : "memory" \
19637 ); \
19638@@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19639 __cmpxchg_wrong_size(); \
19640 \
19641 asm volatile("\t" ASM_STAC "\n" \
19642- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19643+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19644 "2:\t" ASM_CLAC "\n" \
19645 "\t.section .fixup, \"ax\"\n" \
19646 "3:\tmov %3, %0\n" \
19647 "\tjmp 2b\n" \
19648 "\t.previous\n" \
19649 _ASM_EXTABLE(1b, 3b) \
19650- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19651+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19652 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19653 : "memory" \
19654 ); \
19655@@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19656 default: \
19657 __cmpxchg_wrong_size(); \
19658 } \
19659+ pax_close_userland(); \
19660 *__uval = __old; \
19661 __ret; \
19662 })
19663@@ -636,17 +713,6 @@ extern struct movsl_mask {
19664
19665 #define ARCH_HAS_NOCACHE_UACCESS 1
19666
19667-#ifdef CONFIG_X86_32
19668-# include <asm/uaccess_32.h>
19669-#else
19670-# include <asm/uaccess_64.h>
19671-#endif
19672-
19673-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19674- unsigned n);
19675-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19676- unsigned n);
19677-
19678 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19679 # define copy_user_diag __compiletime_error
19680 #else
19681@@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19682 extern void copy_user_diag("copy_from_user() buffer size is too small")
19683 copy_from_user_overflow(void);
19684 extern void copy_user_diag("copy_to_user() buffer size is too small")
19685-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19686+copy_to_user_overflow(void);
19687
19688 #undef copy_user_diag
19689
19690@@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19691
19692 extern void
19693 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19694-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19695+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19696 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19697
19698 #else
19699@@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19700
19701 #endif
19702
19703+#ifdef CONFIG_X86_32
19704+# include <asm/uaccess_32.h>
19705+#else
19706+# include <asm/uaccess_64.h>
19707+#endif
19708+
19709 static inline unsigned long __must_check
19710 copy_from_user(void *to, const void __user *from, unsigned long n)
19711 {
19712- int sz = __compiletime_object_size(to);
19713+ size_t sz = __compiletime_object_size(to);
19714
19715 might_fault();
19716
19717@@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19718 * case, and do only runtime checking for non-constant sizes.
19719 */
19720
19721- if (likely(sz < 0 || sz >= n))
19722- n = _copy_from_user(to, from, n);
19723- else if(__builtin_constant_p(n))
19724- copy_from_user_overflow();
19725- else
19726- __copy_from_user_overflow(sz, n);
19727+ if (likely(sz != (size_t)-1 && sz < n)) {
19728+ if(__builtin_constant_p(n))
19729+ copy_from_user_overflow();
19730+ else
19731+ __copy_from_user_overflow(sz, n);
19732+ } if (access_ok(VERIFY_READ, from, n))
19733+ n = __copy_from_user(to, from, n);
19734+ else if ((long)n > 0)
19735+ memset(to, 0, n);
19736
19737 return n;
19738 }
19739@@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19740 static inline unsigned long __must_check
19741 copy_to_user(void __user *to, const void *from, unsigned long n)
19742 {
19743- int sz = __compiletime_object_size(from);
19744+ size_t sz = __compiletime_object_size(from);
19745
19746 might_fault();
19747
19748 /* See the comment in copy_from_user() above. */
19749- if (likely(sz < 0 || sz >= n))
19750- n = _copy_to_user(to, from, n);
19751- else if(__builtin_constant_p(n))
19752- copy_to_user_overflow();
19753- else
19754- __copy_to_user_overflow(sz, n);
19755+ if (likely(sz != (size_t)-1 && sz < n)) {
19756+ if(__builtin_constant_p(n))
19757+ copy_to_user_overflow();
19758+ else
19759+ __copy_to_user_overflow(sz, n);
19760+ } else if (access_ok(VERIFY_WRITE, to, n))
19761+ n = __copy_to_user(to, from, n);
19762
19763 return n;
19764 }
19765diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19766index 3c03a5d..1071638 100644
19767--- a/arch/x86/include/asm/uaccess_32.h
19768+++ b/arch/x86/include/asm/uaccess_32.h
19769@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19770 static __always_inline unsigned long __must_check
19771 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19772 {
19773+ if ((long)n < 0)
19774+ return n;
19775+
19776+ check_object_size(from, n, true);
19777+
19778 if (__builtin_constant_p(n)) {
19779 unsigned long ret;
19780
19781@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19782 __copy_to_user(void __user *to, const void *from, unsigned long n)
19783 {
19784 might_fault();
19785+
19786 return __copy_to_user_inatomic(to, from, n);
19787 }
19788
19789 static __always_inline unsigned long
19790 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19791 {
19792+ if ((long)n < 0)
19793+ return n;
19794+
19795 /* Avoid zeroing the tail if the copy fails..
19796 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19797 * but as the zeroing behaviour is only significant when n is not
19798@@ -137,6 +146,12 @@ static __always_inline unsigned long
19799 __copy_from_user(void *to, const void __user *from, unsigned long n)
19800 {
19801 might_fault();
19802+
19803+ if ((long)n < 0)
19804+ return n;
19805+
19806+ check_object_size(to, n, false);
19807+
19808 if (__builtin_constant_p(n)) {
19809 unsigned long ret;
19810
19811@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19812 const void __user *from, unsigned long n)
19813 {
19814 might_fault();
19815+
19816+ if ((long)n < 0)
19817+ return n;
19818+
19819 if (__builtin_constant_p(n)) {
19820 unsigned long ret;
19821
19822@@ -181,7 +200,10 @@ static __always_inline unsigned long
19823 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19824 unsigned long n)
19825 {
19826- return __copy_from_user_ll_nocache_nozero(to, from, n);
19827+ if ((long)n < 0)
19828+ return n;
19829+
19830+ return __copy_from_user_ll_nocache_nozero(to, from, n);
19831 }
19832
19833 #endif /* _ASM_X86_UACCESS_32_H */
19834diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19835index 12a26b9..206c200 100644
19836--- a/arch/x86/include/asm/uaccess_64.h
19837+++ b/arch/x86/include/asm/uaccess_64.h
19838@@ -10,6 +10,9 @@
19839 #include <asm/alternative.h>
19840 #include <asm/cpufeature.h>
19841 #include <asm/page.h>
19842+#include <asm/pgtable.h>
19843+
19844+#define set_fs(x) (current_thread_info()->addr_limit = (x))
19845
19846 /*
19847 * Copy To/From Userspace
19848@@ -17,14 +20,14 @@
19849
19850 /* Handles exceptions in both to and from, but doesn't do access_ok */
19851 __must_check unsigned long
19852-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19853+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19854 __must_check unsigned long
19855-copy_user_generic_string(void *to, const void *from, unsigned len);
19856+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19857 __must_check unsigned long
19858-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19859+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19860
19861 static __always_inline __must_check unsigned long
19862-copy_user_generic(void *to, const void *from, unsigned len)
19863+copy_user_generic(void *to, const void *from, unsigned long len)
19864 {
19865 unsigned ret;
19866
19867@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19868 }
19869
19870 __must_check unsigned long
19871-copy_in_user(void __user *to, const void __user *from, unsigned len);
19872+copy_in_user(void __user *to, const void __user *from, unsigned long len);
19873
19874 static __always_inline __must_check
19875-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19876+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19877 {
19878- int ret = 0;
19879+ size_t sz = __compiletime_object_size(dst);
19880+ unsigned ret = 0;
19881+
19882+ if (size > INT_MAX)
19883+ return size;
19884+
19885+ check_object_size(dst, size, false);
19886+
19887+#ifdef CONFIG_PAX_MEMORY_UDEREF
19888+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19889+ return size;
19890+#endif
19891+
19892+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19893+ if(__builtin_constant_p(size))
19894+ copy_from_user_overflow();
19895+ else
19896+ __copy_from_user_overflow(sz, size);
19897+ return size;
19898+ }
19899
19900 if (!__builtin_constant_p(size))
19901- return copy_user_generic(dst, (__force void *)src, size);
19902+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19903 switch (size) {
19904- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19905+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19906 ret, "b", "b", "=q", 1);
19907 return ret;
19908- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19909+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19910 ret, "w", "w", "=r", 2);
19911 return ret;
19912- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19913+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19914 ret, "l", "k", "=r", 4);
19915 return ret;
19916- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19917+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19918 ret, "q", "", "=r", 8);
19919 return ret;
19920 case 10:
19921- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19922+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19923 ret, "q", "", "=r", 10);
19924 if (unlikely(ret))
19925 return ret;
19926 __get_user_asm(*(u16 *)(8 + (char *)dst),
19927- (u16 __user *)(8 + (char __user *)src),
19928+ (const u16 __user *)(8 + (const char __user *)src),
19929 ret, "w", "w", "=r", 2);
19930 return ret;
19931 case 16:
19932- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19933+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19934 ret, "q", "", "=r", 16);
19935 if (unlikely(ret))
19936 return ret;
19937 __get_user_asm(*(u64 *)(8 + (char *)dst),
19938- (u64 __user *)(8 + (char __user *)src),
19939+ (const u64 __user *)(8 + (const char __user *)src),
19940 ret, "q", "", "=r", 8);
19941 return ret;
19942 default:
19943- return copy_user_generic(dst, (__force void *)src, size);
19944+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19945 }
19946 }
19947
19948 static __always_inline __must_check
19949-int __copy_from_user(void *dst, const void __user *src, unsigned size)
19950+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19951 {
19952 might_fault();
19953 return __copy_from_user_nocheck(dst, src, size);
19954 }
19955
19956 static __always_inline __must_check
19957-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19958+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19959 {
19960- int ret = 0;
19961+ size_t sz = __compiletime_object_size(src);
19962+ unsigned ret = 0;
19963+
19964+ if (size > INT_MAX)
19965+ return size;
19966+
19967+ check_object_size(src, size, true);
19968+
19969+#ifdef CONFIG_PAX_MEMORY_UDEREF
19970+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19971+ return size;
19972+#endif
19973+
19974+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19975+ if(__builtin_constant_p(size))
19976+ copy_to_user_overflow();
19977+ else
19978+ __copy_to_user_overflow(sz, size);
19979+ return size;
19980+ }
19981
19982 if (!__builtin_constant_p(size))
19983- return copy_user_generic((__force void *)dst, src, size);
19984+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19985 switch (size) {
19986- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19987+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19988 ret, "b", "b", "iq", 1);
19989 return ret;
19990- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19991+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19992 ret, "w", "w", "ir", 2);
19993 return ret;
19994- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19995+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19996 ret, "l", "k", "ir", 4);
19997 return ret;
19998- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19999+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20000 ret, "q", "", "er", 8);
20001 return ret;
20002 case 10:
20003- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20004+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20005 ret, "q", "", "er", 10);
20006 if (unlikely(ret))
20007 return ret;
20008 asm("":::"memory");
20009- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20010+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20011 ret, "w", "w", "ir", 2);
20012 return ret;
20013 case 16:
20014- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20015+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20016 ret, "q", "", "er", 16);
20017 if (unlikely(ret))
20018 return ret;
20019 asm("":::"memory");
20020- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20021+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20022 ret, "q", "", "er", 8);
20023 return ret;
20024 default:
20025- return copy_user_generic((__force void *)dst, src, size);
20026+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20027 }
20028 }
20029
20030 static __always_inline __must_check
20031-int __copy_to_user(void __user *dst, const void *src, unsigned size)
20032+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20033 {
20034 might_fault();
20035 return __copy_to_user_nocheck(dst, src, size);
20036 }
20037
20038 static __always_inline __must_check
20039-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20040+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20041 {
20042- int ret = 0;
20043+ unsigned ret = 0;
20044
20045 might_fault();
20046+
20047+ if (size > INT_MAX)
20048+ return size;
20049+
20050+#ifdef CONFIG_PAX_MEMORY_UDEREF
20051+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20052+ return size;
20053+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20054+ return size;
20055+#endif
20056+
20057 if (!__builtin_constant_p(size))
20058- return copy_user_generic((__force void *)dst,
20059- (__force void *)src, size);
20060+ return copy_user_generic((__force_kernel void *)____m(dst),
20061+ (__force_kernel const void *)____m(src), size);
20062 switch (size) {
20063 case 1: {
20064 u8 tmp;
20065- __get_user_asm(tmp, (u8 __user *)src,
20066+ __get_user_asm(tmp, (const u8 __user *)src,
20067 ret, "b", "b", "=q", 1);
20068 if (likely(!ret))
20069 __put_user_asm(tmp, (u8 __user *)dst,
20070@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20071 }
20072 case 2: {
20073 u16 tmp;
20074- __get_user_asm(tmp, (u16 __user *)src,
20075+ __get_user_asm(tmp, (const u16 __user *)src,
20076 ret, "w", "w", "=r", 2);
20077 if (likely(!ret))
20078 __put_user_asm(tmp, (u16 __user *)dst,
20079@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20080
20081 case 4: {
20082 u32 tmp;
20083- __get_user_asm(tmp, (u32 __user *)src,
20084+ __get_user_asm(tmp, (const u32 __user *)src,
20085 ret, "l", "k", "=r", 4);
20086 if (likely(!ret))
20087 __put_user_asm(tmp, (u32 __user *)dst,
20088@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20089 }
20090 case 8: {
20091 u64 tmp;
20092- __get_user_asm(tmp, (u64 __user *)src,
20093+ __get_user_asm(tmp, (const u64 __user *)src,
20094 ret, "q", "", "=r", 8);
20095 if (likely(!ret))
20096 __put_user_asm(tmp, (u64 __user *)dst,
20097@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20098 return ret;
20099 }
20100 default:
20101- return copy_user_generic((__force void *)dst,
20102- (__force void *)src, size);
20103+ return copy_user_generic((__force_kernel void *)____m(dst),
20104+ (__force_kernel const void *)____m(src), size);
20105 }
20106 }
20107
20108-static __must_check __always_inline int
20109-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20110+static __must_check __always_inline unsigned long
20111+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20112 {
20113 return __copy_from_user_nocheck(dst, src, size);
20114 }
20115
20116-static __must_check __always_inline int
20117-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20118+static __must_check __always_inline unsigned long
20119+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20120 {
20121 return __copy_to_user_nocheck(dst, src, size);
20122 }
20123
20124-extern long __copy_user_nocache(void *dst, const void __user *src,
20125- unsigned size, int zerorest);
20126+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20127+ unsigned long size, int zerorest);
20128
20129-static inline int
20130-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20131+static inline unsigned long
20132+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20133 {
20134 might_fault();
20135+
20136+ if (size > INT_MAX)
20137+ return size;
20138+
20139+#ifdef CONFIG_PAX_MEMORY_UDEREF
20140+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20141+ return size;
20142+#endif
20143+
20144 return __copy_user_nocache(dst, src, size, 1);
20145 }
20146
20147-static inline int
20148+static inline unsigned long
20149 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20150- unsigned size)
20151+ unsigned long size)
20152 {
20153+ if (size > INT_MAX)
20154+ return size;
20155+
20156+#ifdef CONFIG_PAX_MEMORY_UDEREF
20157+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20158+ return size;
20159+#endif
20160+
20161 return __copy_user_nocache(dst, src, size, 0);
20162 }
20163
20164 unsigned long
20165-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20166+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20167
20168 #endif /* _ASM_X86_UACCESS_64_H */
20169diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20170index 5b238981..77fdd78 100644
20171--- a/arch/x86/include/asm/word-at-a-time.h
20172+++ b/arch/x86/include/asm/word-at-a-time.h
20173@@ -11,7 +11,7 @@
20174 * and shift, for example.
20175 */
20176 struct word_at_a_time {
20177- const unsigned long one_bits, high_bits;
20178+ unsigned long one_bits, high_bits;
20179 };
20180
20181 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20182diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20183index e45e4da..44e8572 100644
20184--- a/arch/x86/include/asm/x86_init.h
20185+++ b/arch/x86/include/asm/x86_init.h
20186@@ -129,7 +129,7 @@ struct x86_init_ops {
20187 struct x86_init_timers timers;
20188 struct x86_init_iommu iommu;
20189 struct x86_init_pci pci;
20190-};
20191+} __no_const;
20192
20193 /**
20194 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20195@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20196 void (*setup_percpu_clockev)(void);
20197 void (*early_percpu_clock_init)(void);
20198 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20199-};
20200+} __no_const;
20201
20202 struct timespec;
20203
20204@@ -168,7 +168,7 @@ struct x86_platform_ops {
20205 void (*save_sched_clock_state)(void);
20206 void (*restore_sched_clock_state)(void);
20207 void (*apic_post_init)(void);
20208-};
20209+} __no_const;
20210
20211 struct pci_dev;
20212 struct msi_msg;
20213@@ -185,7 +185,7 @@ struct x86_msi_ops {
20214 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20215 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20216 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20217-};
20218+} __no_const;
20219
20220 struct IO_APIC_route_entry;
20221 struct io_apic_irq_attr;
20222@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20223 unsigned int destination, int vector,
20224 struct io_apic_irq_attr *attr);
20225 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20226-};
20227+} __no_const;
20228
20229 extern struct x86_init_ops x86_init;
20230 extern struct x86_cpuinit_ops x86_cpuinit;
20231diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20232index c949923..c22bfa4 100644
20233--- a/arch/x86/include/asm/xen/page.h
20234+++ b/arch/x86/include/asm/xen/page.h
20235@@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20236 extern struct page *m2p_find_override(unsigned long mfn);
20237 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20238
20239-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20240+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20241 {
20242 unsigned long mfn;
20243
20244diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20245index d949ef2..479b9d1 100644
20246--- a/arch/x86/include/asm/xsave.h
20247+++ b/arch/x86/include/asm/xsave.h
20248@@ -82,8 +82,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20249 if (unlikely(err))
20250 return -EFAULT;
20251
20252+ pax_open_userland();
20253 __asm__ __volatile__(ASM_STAC "\n"
20254- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20255+ "1:"
20256+ __copyuser_seg
20257+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20258 "2: " ASM_CLAC "\n"
20259 ".section .fixup,\"ax\"\n"
20260 "3: movl $-1,%[err]\n"
20261@@ -93,18 +96,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20262 : [err] "=r" (err)
20263 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20264 : "memory");
20265+ pax_close_userland();
20266 return err;
20267 }
20268
20269 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20270 {
20271 int err;
20272- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20273+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20274 u32 lmask = mask;
20275 u32 hmask = mask >> 32;
20276
20277+ pax_open_userland();
20278 __asm__ __volatile__(ASM_STAC "\n"
20279- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20280+ "1:"
20281+ __copyuser_seg
20282+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20283 "2: " ASM_CLAC "\n"
20284 ".section .fixup,\"ax\"\n"
20285 "3: movl $-1,%[err]\n"
20286@@ -114,6 +121,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20287 : [err] "=r" (err)
20288 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20289 : "memory"); /* memory required? */
20290+ pax_close_userland();
20291 return err;
20292 }
20293
20294diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20295index bbae024..e1528f9 100644
20296--- a/arch/x86/include/uapi/asm/e820.h
20297+++ b/arch/x86/include/uapi/asm/e820.h
20298@@ -63,7 +63,7 @@ struct e820map {
20299 #define ISA_START_ADDRESS 0xa0000
20300 #define ISA_END_ADDRESS 0x100000
20301
20302-#define BIOS_BEGIN 0x000a0000
20303+#define BIOS_BEGIN 0x000c0000
20304 #define BIOS_END 0x00100000
20305
20306 #define BIOS_ROM_BASE 0xffe00000
20307diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20308index 7b0a55a..ad115bf 100644
20309--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20310+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20311@@ -49,7 +49,6 @@
20312 #define EFLAGS 144
20313 #define RSP 152
20314 #define SS 160
20315-#define ARGOFFSET R11
20316 #endif /* __ASSEMBLY__ */
20317
20318 /* top of stack page */
20319diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20320index f4d9600..b45af01 100644
20321--- a/arch/x86/kernel/Makefile
20322+++ b/arch/x86/kernel/Makefile
20323@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20324 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20325 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20326 obj-y += probe_roms.o
20327-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20328+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20329 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20330 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20331 obj-$(CONFIG_X86_64) += vsyscall_64.o
20332diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20333index 86281ff..e046fc2 100644
20334--- a/arch/x86/kernel/acpi/boot.c
20335+++ b/arch/x86/kernel/acpi/boot.c
20336@@ -1296,7 +1296,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20337 * If your system is blacklisted here, but you find that acpi=force
20338 * works for you, please contact linux-acpi@vger.kernel.org
20339 */
20340-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20341+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20342 /*
20343 * Boxes that need ACPI disabled
20344 */
20345@@ -1371,7 +1371,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20346 };
20347
20348 /* second table for DMI checks that should run after early-quirks */
20349-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20350+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20351 /*
20352 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20353 * which includes some code which overrides all temperature
20354diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20355index 3136820..e2c6577 100644
20356--- a/arch/x86/kernel/acpi/sleep.c
20357+++ b/arch/x86/kernel/acpi/sleep.c
20358@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20359 #else /* CONFIG_64BIT */
20360 #ifdef CONFIG_SMP
20361 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20362+
20363+ pax_open_kernel();
20364 early_gdt_descr.address =
20365 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20366+ pax_close_kernel();
20367+
20368 initial_gs = per_cpu_offset(smp_processor_id());
20369 #endif
20370 initial_code = (unsigned long)wakeup_long64;
20371diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20372index 665c6b7..eae4d56 100644
20373--- a/arch/x86/kernel/acpi/wakeup_32.S
20374+++ b/arch/x86/kernel/acpi/wakeup_32.S
20375@@ -29,13 +29,11 @@ wakeup_pmode_return:
20376 # and restore the stack ... but you need gdt for this to work
20377 movl saved_context_esp, %esp
20378
20379- movl %cs:saved_magic, %eax
20380- cmpl $0x12345678, %eax
20381+ cmpl $0x12345678, saved_magic
20382 jne bogus_magic
20383
20384 # jump to place where we left off
20385- movl saved_eip, %eax
20386- jmp *%eax
20387+ jmp *(saved_eip)
20388
20389 bogus_magic:
20390 jmp bogus_magic
20391diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20392index df94598..b7162f9 100644
20393--- a/arch/x86/kernel/alternative.c
20394+++ b/arch/x86/kernel/alternative.c
20395@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20396 */
20397 for (a = start; a < end; a++) {
20398 instr = (u8 *)&a->instr_offset + a->instr_offset;
20399+
20400+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20401+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20402+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20403+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20404+#endif
20405+
20406 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20407 BUG_ON(a->replacementlen > a->instrlen);
20408 BUG_ON(a->instrlen > sizeof(insnbuf));
20409@@ -285,6 +292,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20410 add_nops(insnbuf + a->replacementlen,
20411 a->instrlen - a->replacementlen);
20412
20413+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20414+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20415+ instr = ktva_ktla(instr);
20416+#endif
20417+
20418 text_poke_early(instr, insnbuf, a->instrlen);
20419 }
20420 }
20421@@ -300,10 +312,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20422 for (poff = start; poff < end; poff++) {
20423 u8 *ptr = (u8 *)poff + *poff;
20424
20425+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20426+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20427+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20428+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20429+#endif
20430+
20431 if (!*poff || ptr < text || ptr >= text_end)
20432 continue;
20433 /* turn DS segment override prefix into lock prefix */
20434- if (*ptr == 0x3e)
20435+ if (*ktla_ktva(ptr) == 0x3e)
20436 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20437 }
20438 mutex_unlock(&text_mutex);
20439@@ -318,10 +336,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20440 for (poff = start; poff < end; poff++) {
20441 u8 *ptr = (u8 *)poff + *poff;
20442
20443+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20444+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20445+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20446+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20447+#endif
20448+
20449 if (!*poff || ptr < text || ptr >= text_end)
20450 continue;
20451 /* turn lock prefix into DS segment override prefix */
20452- if (*ptr == 0xf0)
20453+ if (*ktla_ktva(ptr) == 0xf0)
20454 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20455 }
20456 mutex_unlock(&text_mutex);
20457@@ -458,7 +482,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20458
20459 BUG_ON(p->len > MAX_PATCH_LEN);
20460 /* prep the buffer with the original instructions */
20461- memcpy(insnbuf, p->instr, p->len);
20462+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20463 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20464 (unsigned long)p->instr, p->len);
20465
20466@@ -505,7 +529,7 @@ void __init alternative_instructions(void)
20467 if (!uniproc_patched || num_possible_cpus() == 1)
20468 free_init_pages("SMP alternatives",
20469 (unsigned long)__smp_locks,
20470- (unsigned long)__smp_locks_end);
20471+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20472 #endif
20473
20474 apply_paravirt(__parainstructions, __parainstructions_end);
20475@@ -525,13 +549,17 @@ void __init alternative_instructions(void)
20476 * instructions. And on the local CPU you need to be protected again NMI or MCE
20477 * handlers seeing an inconsistent instruction while you patch.
20478 */
20479-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20480+void *__kprobes text_poke_early(void *addr, const void *opcode,
20481 size_t len)
20482 {
20483 unsigned long flags;
20484 local_irq_save(flags);
20485- memcpy(addr, opcode, len);
20486+
20487+ pax_open_kernel();
20488+ memcpy(ktla_ktva(addr), opcode, len);
20489 sync_core();
20490+ pax_close_kernel();
20491+
20492 local_irq_restore(flags);
20493 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20494 that causes hangs on some VIA CPUs. */
20495@@ -553,36 +581,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20496 */
20497 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20498 {
20499- unsigned long flags;
20500- char *vaddr;
20501+ unsigned char *vaddr = ktla_ktva(addr);
20502 struct page *pages[2];
20503- int i;
20504+ size_t i;
20505
20506 if (!core_kernel_text((unsigned long)addr)) {
20507- pages[0] = vmalloc_to_page(addr);
20508- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20509+ pages[0] = vmalloc_to_page(vaddr);
20510+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20511 } else {
20512- pages[0] = virt_to_page(addr);
20513+ pages[0] = virt_to_page(vaddr);
20514 WARN_ON(!PageReserved(pages[0]));
20515- pages[1] = virt_to_page(addr + PAGE_SIZE);
20516+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20517 }
20518 BUG_ON(!pages[0]);
20519- local_irq_save(flags);
20520- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20521- if (pages[1])
20522- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20523- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20524- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20525- clear_fixmap(FIX_TEXT_POKE0);
20526- if (pages[1])
20527- clear_fixmap(FIX_TEXT_POKE1);
20528- local_flush_tlb();
20529- sync_core();
20530- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20531- that causes hangs on some VIA CPUs. */
20532+ text_poke_early(addr, opcode, len);
20533 for (i = 0; i < len; i++)
20534- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20535- local_irq_restore(flags);
20536+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20537 return addr;
20538 }
20539
20540@@ -602,7 +616,7 @@ int poke_int3_handler(struct pt_regs *regs)
20541 if (likely(!bp_patching_in_progress))
20542 return 0;
20543
20544- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20545+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20546 return 0;
20547
20548 /* set up the specified breakpoint handler */
20549@@ -636,7 +650,7 @@ int poke_int3_handler(struct pt_regs *regs)
20550 */
20551 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20552 {
20553- unsigned char int3 = 0xcc;
20554+ const unsigned char int3 = 0xcc;
20555
20556 bp_int3_handler = handler;
20557 bp_int3_addr = (u8 *)addr + sizeof(int3);
20558diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20559index ad28db7..c538b2c 100644
20560--- a/arch/x86/kernel/apic/apic.c
20561+++ b/arch/x86/kernel/apic/apic.c
20562@@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20563 /*
20564 * Debug level, exported for io_apic.c
20565 */
20566-unsigned int apic_verbosity;
20567+int apic_verbosity;
20568
20569 int pic_mode;
20570
20571@@ -2000,7 +2000,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20572 apic_write(APIC_ESR, 0);
20573 v = apic_read(APIC_ESR);
20574 ack_APIC_irq();
20575- atomic_inc(&irq_err_count);
20576+ atomic_inc_unchecked(&irq_err_count);
20577
20578 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20579 smp_processor_id(), v);
20580diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20581index 7c1b294..e71d27f 100644
20582--- a/arch/x86/kernel/apic/apic_flat_64.c
20583+++ b/arch/x86/kernel/apic/apic_flat_64.c
20584@@ -154,7 +154,7 @@ static int flat_probe(void)
20585 return 1;
20586 }
20587
20588-static struct apic apic_flat = {
20589+static struct apic apic_flat __read_only = {
20590 .name = "flat",
20591 .probe = flat_probe,
20592 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20593@@ -268,7 +268,7 @@ static int physflat_probe(void)
20594 return 0;
20595 }
20596
20597-static struct apic apic_physflat = {
20598+static struct apic apic_physflat __read_only = {
20599
20600 .name = "physical flat",
20601 .probe = physflat_probe,
20602diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20603index 8c7c982..a225910 100644
20604--- a/arch/x86/kernel/apic/apic_noop.c
20605+++ b/arch/x86/kernel/apic/apic_noop.c
20606@@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20607 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20608 }
20609
20610-struct apic apic_noop = {
20611+struct apic apic_noop __read_only = {
20612 .name = "noop",
20613 .probe = noop_probe,
20614 .acpi_madt_oem_check = NULL,
20615diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20616index e4840aa..e7d9dac 100644
20617--- a/arch/x86/kernel/apic/bigsmp_32.c
20618+++ b/arch/x86/kernel/apic/bigsmp_32.c
20619@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20620 return dmi_bigsmp;
20621 }
20622
20623-static struct apic apic_bigsmp = {
20624+static struct apic apic_bigsmp __read_only = {
20625
20626 .name = "bigsmp",
20627 .probe = probe_bigsmp,
20628diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20629index 992060e..ecdc3b3 100644
20630--- a/arch/x86/kernel/apic/io_apic.c
20631+++ b/arch/x86/kernel/apic/io_apic.c
20632@@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20633 }
20634 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20635
20636-void lock_vector_lock(void)
20637+void lock_vector_lock(void) __acquires(vector_lock)
20638 {
20639 /* Used to the online set of cpus does not change
20640 * during assign_irq_vector.
20641@@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20642 raw_spin_lock(&vector_lock);
20643 }
20644
20645-void unlock_vector_lock(void)
20646+void unlock_vector_lock(void) __releases(vector_lock)
20647 {
20648 raw_spin_unlock(&vector_lock);
20649 }
20650@@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20651 ack_APIC_irq();
20652 }
20653
20654-atomic_t irq_mis_count;
20655+atomic_unchecked_t irq_mis_count;
20656
20657 #ifdef CONFIG_GENERIC_PENDING_IRQ
20658 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20659@@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20660 * at the cpu.
20661 */
20662 if (!(v & (1 << (i & 0x1f)))) {
20663- atomic_inc(&irq_mis_count);
20664+ atomic_inc_unchecked(&irq_mis_count);
20665
20666 eoi_ioapic_irq(irq, cfg);
20667 }
20668diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20669index cceb352..a635fd8 100644
20670--- a/arch/x86/kernel/apic/probe_32.c
20671+++ b/arch/x86/kernel/apic/probe_32.c
20672@@ -72,7 +72,7 @@ static int probe_default(void)
20673 return 1;
20674 }
20675
20676-static struct apic apic_default = {
20677+static struct apic apic_default __read_only = {
20678
20679 .name = "default",
20680 .probe = probe_default,
20681diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20682index e66766b..1c008ba 100644
20683--- a/arch/x86/kernel/apic/x2apic_cluster.c
20684+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20685@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20686 return notifier_from_errno(err);
20687 }
20688
20689-static struct notifier_block __refdata x2apic_cpu_notifier = {
20690+static struct notifier_block x2apic_cpu_notifier = {
20691 .notifier_call = update_clusterinfo,
20692 };
20693
20694@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20695 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20696 }
20697
20698-static struct apic apic_x2apic_cluster = {
20699+static struct apic apic_x2apic_cluster __read_only = {
20700
20701 .name = "cluster x2apic",
20702 .probe = x2apic_cluster_probe,
20703diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20704index 6d600eb..0300c00 100644
20705--- a/arch/x86/kernel/apic/x2apic_phys.c
20706+++ b/arch/x86/kernel/apic/x2apic_phys.c
20707@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20708 return apic == &apic_x2apic_phys;
20709 }
20710
20711-static struct apic apic_x2apic_phys = {
20712+static struct apic apic_x2apic_phys __read_only = {
20713
20714 .name = "physical x2apic",
20715 .probe = x2apic_phys_probe,
20716diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20717index 7834389..4ffc9c8 100644
20718--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20719+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20720@@ -350,7 +350,7 @@ static int uv_probe(void)
20721 return apic == &apic_x2apic_uv_x;
20722 }
20723
20724-static struct apic __refdata apic_x2apic_uv_x = {
20725+static struct apic apic_x2apic_uv_x __read_only = {
20726
20727 .name = "UV large system",
20728 .probe = uv_probe,
20729diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20730index 3ab0343..814c4787 100644
20731--- a/arch/x86/kernel/apm_32.c
20732+++ b/arch/x86/kernel/apm_32.c
20733@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20734 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20735 * even though they are called in protected mode.
20736 */
20737-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20738+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20739 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20740
20741 static const char driver_version[] = "1.16ac"; /* no spaces */
20742@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20743 BUG_ON(cpu != 0);
20744 gdt = get_cpu_gdt_table(cpu);
20745 save_desc_40 = gdt[0x40 / 8];
20746+
20747+ pax_open_kernel();
20748 gdt[0x40 / 8] = bad_bios_desc;
20749+ pax_close_kernel();
20750
20751 apm_irq_save(flags);
20752 APM_DO_SAVE_SEGS;
20753@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20754 &call->esi);
20755 APM_DO_RESTORE_SEGS;
20756 apm_irq_restore(flags);
20757+
20758+ pax_open_kernel();
20759 gdt[0x40 / 8] = save_desc_40;
20760+ pax_close_kernel();
20761+
20762 put_cpu();
20763
20764 return call->eax & 0xff;
20765@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20766 BUG_ON(cpu != 0);
20767 gdt = get_cpu_gdt_table(cpu);
20768 save_desc_40 = gdt[0x40 / 8];
20769+
20770+ pax_open_kernel();
20771 gdt[0x40 / 8] = bad_bios_desc;
20772+ pax_close_kernel();
20773
20774 apm_irq_save(flags);
20775 APM_DO_SAVE_SEGS;
20776@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20777 &call->eax);
20778 APM_DO_RESTORE_SEGS;
20779 apm_irq_restore(flags);
20780+
20781+ pax_open_kernel();
20782 gdt[0x40 / 8] = save_desc_40;
20783+ pax_close_kernel();
20784+
20785 put_cpu();
20786 return error;
20787 }
20788@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20789 * code to that CPU.
20790 */
20791 gdt = get_cpu_gdt_table(0);
20792+
20793+ pax_open_kernel();
20794 set_desc_base(&gdt[APM_CS >> 3],
20795 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20796 set_desc_base(&gdt[APM_CS_16 >> 3],
20797 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20798 set_desc_base(&gdt[APM_DS >> 3],
20799 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20800+ pax_close_kernel();
20801
20802 proc_create("apm", 0, NULL, &apm_file_ops);
20803
20804diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20805index 9f6b934..cf5ffb3 100644
20806--- a/arch/x86/kernel/asm-offsets.c
20807+++ b/arch/x86/kernel/asm-offsets.c
20808@@ -32,6 +32,8 @@ void common(void) {
20809 OFFSET(TI_flags, thread_info, flags);
20810 OFFSET(TI_status, thread_info, status);
20811 OFFSET(TI_addr_limit, thread_info, addr_limit);
20812+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20813+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20814
20815 BLANK();
20816 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20817@@ -52,8 +54,26 @@ void common(void) {
20818 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20819 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20820 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20821+
20822+#ifdef CONFIG_PAX_KERNEXEC
20823+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20824 #endif
20825
20826+#ifdef CONFIG_PAX_MEMORY_UDEREF
20827+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20828+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20829+#ifdef CONFIG_X86_64
20830+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20831+#endif
20832+#endif
20833+
20834+#endif
20835+
20836+ BLANK();
20837+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20838+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20839+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20840+
20841 #ifdef CONFIG_XEN
20842 BLANK();
20843 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20844diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20845index e7c798b..2b2019b 100644
20846--- a/arch/x86/kernel/asm-offsets_64.c
20847+++ b/arch/x86/kernel/asm-offsets_64.c
20848@@ -77,6 +77,7 @@ int main(void)
20849 BLANK();
20850 #undef ENTRY
20851
20852+ DEFINE(TSS_size, sizeof(struct tss_struct));
20853 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20854 BLANK();
20855
20856diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20857index 7fd54f0..0691410 100644
20858--- a/arch/x86/kernel/cpu/Makefile
20859+++ b/arch/x86/kernel/cpu/Makefile
20860@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20861 CFLAGS_REMOVE_perf_event.o = -pg
20862 endif
20863
20864-# Make sure load_percpu_segment has no stackprotector
20865-nostackp := $(call cc-option, -fno-stack-protector)
20866-CFLAGS_common.o := $(nostackp)
20867-
20868 obj-y := intel_cacheinfo.o scattered.o topology.o
20869 obj-y += proc.o capflags.o powerflags.o common.o
20870 obj-y += rdrand.o
20871diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20872index ce8b8ff..d7d8851 100644
20873--- a/arch/x86/kernel/cpu/amd.c
20874+++ b/arch/x86/kernel/cpu/amd.c
20875@@ -728,7 +728,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20876 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20877 {
20878 /* AMD errata T13 (order #21922) */
20879- if ((c->x86 == 6)) {
20880+ if (c->x86 == 6) {
20881 /* Duron Rev A0 */
20882 if (c->x86_model == 3 && c->x86_mask == 0)
20883 size = 64;
20884diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20885index a135239..41fb30a 100644
20886--- a/arch/x86/kernel/cpu/common.c
20887+++ b/arch/x86/kernel/cpu/common.c
20888@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20889
20890 static const struct cpu_dev *this_cpu = &default_cpu;
20891
20892-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20893-#ifdef CONFIG_X86_64
20894- /*
20895- * We need valid kernel segments for data and code in long mode too
20896- * IRET will check the segment types kkeil 2000/10/28
20897- * Also sysret mandates a special GDT layout
20898- *
20899- * TLS descriptors are currently at a different place compared to i386.
20900- * Hopefully nobody expects them at a fixed place (Wine?)
20901- */
20902- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20903- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20904- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20905- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20906- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20907- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20908-#else
20909- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20910- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20911- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20912- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20913- /*
20914- * Segments used for calling PnP BIOS have byte granularity.
20915- * They code segments and data segments have fixed 64k limits,
20916- * the transfer segment sizes are set at run time.
20917- */
20918- /* 32-bit code */
20919- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20920- /* 16-bit code */
20921- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20922- /* 16-bit data */
20923- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20924- /* 16-bit data */
20925- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20926- /* 16-bit data */
20927- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20928- /*
20929- * The APM segments have byte granularity and their bases
20930- * are set at run time. All have 64k limits.
20931- */
20932- /* 32-bit code */
20933- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20934- /* 16-bit code */
20935- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20936- /* data */
20937- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20938-
20939- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20940- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20941- GDT_STACK_CANARY_INIT
20942-#endif
20943-} };
20944-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20945-
20946 static int __init x86_xsave_setup(char *s)
20947 {
20948 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20949@@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20950 }
20951 }
20952
20953+#ifdef CONFIG_X86_64
20954+static __init int setup_disable_pcid(char *arg)
20955+{
20956+ setup_clear_cpu_cap(X86_FEATURE_PCID);
20957+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20958+
20959+#ifdef CONFIG_PAX_MEMORY_UDEREF
20960+ if (clone_pgd_mask != ~(pgdval_t)0UL)
20961+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20962+#endif
20963+
20964+ return 1;
20965+}
20966+__setup("nopcid", setup_disable_pcid);
20967+
20968+static void setup_pcid(struct cpuinfo_x86 *c)
20969+{
20970+ if (!cpu_has(c, X86_FEATURE_PCID)) {
20971+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
20972+
20973+#ifdef CONFIG_PAX_MEMORY_UDEREF
20974+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
20975+ pax_open_kernel();
20976+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20977+ pax_close_kernel();
20978+ printk("PAX: slow and weak UDEREF enabled\n");
20979+ } else
20980+ printk("PAX: UDEREF disabled\n");
20981+#endif
20982+
20983+ return;
20984+ }
20985+
20986+ printk("PAX: PCID detected\n");
20987+ set_in_cr4(X86_CR4_PCIDE);
20988+
20989+#ifdef CONFIG_PAX_MEMORY_UDEREF
20990+ pax_open_kernel();
20991+ clone_pgd_mask = ~(pgdval_t)0UL;
20992+ pax_close_kernel();
20993+ if (pax_user_shadow_base)
20994+ printk("PAX: weak UDEREF enabled\n");
20995+ else {
20996+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20997+ printk("PAX: strong UDEREF enabled\n");
20998+ }
20999+#endif
21000+
21001+ if (cpu_has(c, X86_FEATURE_INVPCID))
21002+ printk("PAX: INVPCID detected\n");
21003+}
21004+#endif
21005+
21006 /*
21007 * Some CPU features depend on higher CPUID levels, which may not always
21008 * be available due to CPUID level capping or broken virtualization
21009@@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
21010 {
21011 struct desc_ptr gdt_descr;
21012
21013- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21014+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21015 gdt_descr.size = GDT_SIZE - 1;
21016 load_gdt(&gdt_descr);
21017 /* Reload the per-cpu base */
21018@@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21019 setup_smep(c);
21020 setup_smap(c);
21021
21022+#ifdef CONFIG_X86_64
21023+ setup_pcid(c);
21024+#endif
21025+
21026 /*
21027 * The vendor-specific functions might have changed features.
21028 * Now we do "generic changes."
21029@@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21030 /* Filter out anything that depends on CPUID levels we don't have */
21031 filter_cpuid_features(c, true);
21032
21033+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21034+ setup_clear_cpu_cap(X86_FEATURE_SEP);
21035+#endif
21036+
21037 /* If the model name is still unset, do table lookup. */
21038 if (!c->x86_model_id[0]) {
21039 const char *p;
21040@@ -1079,14 +1086,16 @@ static __init int setup_disablecpuid(char *arg)
21041 }
21042 __setup("clearcpuid=", setup_disablecpuid);
21043
21044+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21045+EXPORT_PER_CPU_SYMBOL(current_tinfo);
21046+
21047 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21048- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21049+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21050 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21051
21052 #ifdef CONFIG_X86_64
21053-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21054-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21055- (unsigned long) debug_idt_table };
21056+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21057+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21058
21059 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21060 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21061@@ -1246,7 +1255,7 @@ void cpu_init(void)
21062 load_ucode_ap();
21063
21064 cpu = stack_smp_processor_id();
21065- t = &per_cpu(init_tss, cpu);
21066+ t = init_tss + cpu;
21067 oist = &per_cpu(orig_ist, cpu);
21068
21069 #ifdef CONFIG_NUMA
21070@@ -1281,7 +1290,6 @@ void cpu_init(void)
21071 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21072 barrier();
21073
21074- x86_configure_nx();
21075 enable_x2apic();
21076
21077 /*
21078@@ -1333,7 +1341,7 @@ void cpu_init(void)
21079 {
21080 int cpu = smp_processor_id();
21081 struct task_struct *curr = current;
21082- struct tss_struct *t = &per_cpu(init_tss, cpu);
21083+ struct tss_struct *t = init_tss + cpu;
21084 struct thread_struct *thread = &curr->thread;
21085
21086 show_ucode_info_early();
21087diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21088index a952e9c..58a4cbb 100644
21089--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21090+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21091@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21092 };
21093
21094 #ifdef CONFIG_AMD_NB
21095+static struct attribute *default_attrs_amd_nb[] = {
21096+ &type.attr,
21097+ &level.attr,
21098+ &coherency_line_size.attr,
21099+ &physical_line_partition.attr,
21100+ &ways_of_associativity.attr,
21101+ &number_of_sets.attr,
21102+ &size.attr,
21103+ &shared_cpu_map.attr,
21104+ &shared_cpu_list.attr,
21105+ NULL,
21106+ NULL,
21107+ NULL,
21108+ NULL
21109+};
21110+
21111 static struct attribute **amd_l3_attrs(void)
21112 {
21113 static struct attribute **attrs;
21114@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21115
21116 n = ARRAY_SIZE(default_attrs);
21117
21118- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21119- n += 2;
21120-
21121- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21122- n += 1;
21123-
21124- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21125- if (attrs == NULL)
21126- return attrs = default_attrs;
21127-
21128- for (n = 0; default_attrs[n]; n++)
21129- attrs[n] = default_attrs[n];
21130+ attrs = default_attrs_amd_nb;
21131
21132 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21133 attrs[n++] = &cache_disable_0.attr;
21134@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21135 .default_attrs = default_attrs,
21136 };
21137
21138+#ifdef CONFIG_AMD_NB
21139+static struct kobj_type ktype_cache_amd_nb = {
21140+ .sysfs_ops = &sysfs_ops,
21141+ .default_attrs = default_attrs_amd_nb,
21142+};
21143+#endif
21144+
21145 static struct kobj_type ktype_percpu_entry = {
21146 .sysfs_ops = &sysfs_ops,
21147 };
21148@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21149 return retval;
21150 }
21151
21152+#ifdef CONFIG_AMD_NB
21153+ amd_l3_attrs();
21154+#endif
21155+
21156 for (i = 0; i < num_cache_leaves; i++) {
21157+ struct kobj_type *ktype;
21158+
21159 this_object = INDEX_KOBJECT_PTR(cpu, i);
21160 this_object->cpu = cpu;
21161 this_object->index = i;
21162
21163 this_leaf = CPUID4_INFO_IDX(cpu, i);
21164
21165- ktype_cache.default_attrs = default_attrs;
21166+ ktype = &ktype_cache;
21167 #ifdef CONFIG_AMD_NB
21168 if (this_leaf->base.nb)
21169- ktype_cache.default_attrs = amd_l3_attrs();
21170+ ktype = &ktype_cache_amd_nb;
21171 #endif
21172 retval = kobject_init_and_add(&(this_object->kobj),
21173- &ktype_cache,
21174+ ktype,
21175 per_cpu(ici_cache_kobject, cpu),
21176 "index%1lu", i);
21177 if (unlikely(retval)) {
21178diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21179index 68317c8..c860d41 100644
21180--- a/arch/x86/kernel/cpu/mcheck/mce.c
21181+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21182@@ -45,6 +45,7 @@
21183 #include <asm/processor.h>
21184 #include <asm/mce.h>
21185 #include <asm/msr.h>
21186+#include <asm/local.h>
21187
21188 #include "mce-internal.h"
21189
21190@@ -261,7 +262,7 @@ static void print_mce(struct mce *m)
21191 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21192 m->cs, m->ip);
21193
21194- if (m->cs == __KERNEL_CS)
21195+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21196 print_symbol("{%s}", m->ip);
21197 pr_cont("\n");
21198 }
21199@@ -294,10 +295,10 @@ static void print_mce(struct mce *m)
21200
21201 #define PANIC_TIMEOUT 5 /* 5 seconds */
21202
21203-static atomic_t mce_paniced;
21204+static atomic_unchecked_t mce_paniced;
21205
21206 static int fake_panic;
21207-static atomic_t mce_fake_paniced;
21208+static atomic_unchecked_t mce_fake_paniced;
21209
21210 /* Panic in progress. Enable interrupts and wait for final IPI */
21211 static void wait_for_panic(void)
21212@@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21213 /*
21214 * Make sure only one CPU runs in machine check panic
21215 */
21216- if (atomic_inc_return(&mce_paniced) > 1)
21217+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21218 wait_for_panic();
21219 barrier();
21220
21221@@ -329,7 +330,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21222 console_verbose();
21223 } else {
21224 /* Don't log too much for fake panic */
21225- if (atomic_inc_return(&mce_fake_paniced) > 1)
21226+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21227 return;
21228 }
21229 /* First print corrected ones that are still unlogged */
21230@@ -368,7 +369,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21231 if (!fake_panic) {
21232 if (panic_timeout == 0)
21233 panic_timeout = mca_cfg.panic_timeout;
21234- panic(msg);
21235+ panic("%s", msg);
21236 } else
21237 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21238 }
21239@@ -699,7 +700,7 @@ static int mce_timed_out(u64 *t)
21240 * might have been modified by someone else.
21241 */
21242 rmb();
21243- if (atomic_read(&mce_paniced))
21244+ if (atomic_read_unchecked(&mce_paniced))
21245 wait_for_panic();
21246 if (!mca_cfg.monarch_timeout)
21247 goto out;
21248@@ -1680,7 +1681,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21249 }
21250
21251 /* Call the installed machine check handler for this CPU setup. */
21252-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21253+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21254 unexpected_machine_check;
21255
21256 /*
21257@@ -1703,7 +1704,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21258 return;
21259 }
21260
21261+ pax_open_kernel();
21262 machine_check_vector = do_machine_check;
21263+ pax_close_kernel();
21264
21265 __mcheck_cpu_init_generic();
21266 __mcheck_cpu_init_vendor(c);
21267@@ -1717,7 +1720,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21268 */
21269
21270 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21271-static int mce_chrdev_open_count; /* #times opened */
21272+static local_t mce_chrdev_open_count; /* #times opened */
21273 static int mce_chrdev_open_exclu; /* already open exclusive? */
21274
21275 static int mce_chrdev_open(struct inode *inode, struct file *file)
21276@@ -1725,7 +1728,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21277 spin_lock(&mce_chrdev_state_lock);
21278
21279 if (mce_chrdev_open_exclu ||
21280- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21281+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21282 spin_unlock(&mce_chrdev_state_lock);
21283
21284 return -EBUSY;
21285@@ -1733,7 +1736,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21286
21287 if (file->f_flags & O_EXCL)
21288 mce_chrdev_open_exclu = 1;
21289- mce_chrdev_open_count++;
21290+ local_inc(&mce_chrdev_open_count);
21291
21292 spin_unlock(&mce_chrdev_state_lock);
21293
21294@@ -1744,7 +1747,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21295 {
21296 spin_lock(&mce_chrdev_state_lock);
21297
21298- mce_chrdev_open_count--;
21299+ local_dec(&mce_chrdev_open_count);
21300 mce_chrdev_open_exclu = 0;
21301
21302 spin_unlock(&mce_chrdev_state_lock);
21303@@ -2420,7 +2423,7 @@ static __init void mce_init_banks(void)
21304
21305 for (i = 0; i < mca_cfg.banks; i++) {
21306 struct mce_bank *b = &mce_banks[i];
21307- struct device_attribute *a = &b->attr;
21308+ device_attribute_no_const *a = &b->attr;
21309
21310 sysfs_attr_init(&a->attr);
21311 a->attr.name = b->attrname;
21312@@ -2492,7 +2495,7 @@ struct dentry *mce_get_debugfs_dir(void)
21313 static void mce_reset(void)
21314 {
21315 cpu_missing = 0;
21316- atomic_set(&mce_fake_paniced, 0);
21317+ atomic_set_unchecked(&mce_fake_paniced, 0);
21318 atomic_set(&mce_executing, 0);
21319 atomic_set(&mce_callin, 0);
21320 atomic_set(&global_nwo, 0);
21321diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21322index a304298..49b6d06 100644
21323--- a/arch/x86/kernel/cpu/mcheck/p5.c
21324+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21325@@ -10,6 +10,7 @@
21326 #include <asm/processor.h>
21327 #include <asm/mce.h>
21328 #include <asm/msr.h>
21329+#include <asm/pgtable.h>
21330
21331 /* By default disabled */
21332 int mce_p5_enabled __read_mostly;
21333@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21334 if (!cpu_has(c, X86_FEATURE_MCE))
21335 return;
21336
21337+ pax_open_kernel();
21338 machine_check_vector = pentium_machine_check;
21339+ pax_close_kernel();
21340 /* Make sure the vector pointer is visible before we enable MCEs: */
21341 wmb();
21342
21343diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21344index 7dc5564..1273569 100644
21345--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21346+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21347@@ -9,6 +9,7 @@
21348 #include <asm/processor.h>
21349 #include <asm/mce.h>
21350 #include <asm/msr.h>
21351+#include <asm/pgtable.h>
21352
21353 /* Machine check handler for WinChip C6: */
21354 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21355@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21356 {
21357 u32 lo, hi;
21358
21359+ pax_open_kernel();
21360 machine_check_vector = winchip_machine_check;
21361+ pax_close_kernel();
21362 /* Make sure the vector pointer is visible before we enable MCEs: */
21363 wmb();
21364
21365diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21366index 15c9876..0a43909 100644
21367--- a/arch/x86/kernel/cpu/microcode/core.c
21368+++ b/arch/x86/kernel/cpu/microcode/core.c
21369@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21370 return NOTIFY_OK;
21371 }
21372
21373-static struct notifier_block __refdata mc_cpu_notifier = {
21374+static struct notifier_block mc_cpu_notifier = {
21375 .notifier_call = mc_cpu_callback,
21376 };
21377
21378diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21379index a276fa7..e66810f 100644
21380--- a/arch/x86/kernel/cpu/microcode/intel.c
21381+++ b/arch/x86/kernel/cpu/microcode/intel.c
21382@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21383
21384 static int get_ucode_user(void *to, const void *from, size_t n)
21385 {
21386- return copy_from_user(to, from, n);
21387+ return copy_from_user(to, (const void __force_user *)from, n);
21388 }
21389
21390 static enum ucode_state
21391 request_microcode_user(int cpu, const void __user *buf, size_t size)
21392 {
21393- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21394+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21395 }
21396
21397 static void microcode_fini_cpu(int cpu)
21398diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21399index f961de9..8a9d332 100644
21400--- a/arch/x86/kernel/cpu/mtrr/main.c
21401+++ b/arch/x86/kernel/cpu/mtrr/main.c
21402@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21403 u64 size_or_mask, size_and_mask;
21404 static bool mtrr_aps_delayed_init;
21405
21406-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21407+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21408
21409 const struct mtrr_ops *mtrr_if;
21410
21411diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21412index df5e41f..816c719 100644
21413--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21414+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21415@@ -25,7 +25,7 @@ struct mtrr_ops {
21416 int (*validate_add_page)(unsigned long base, unsigned long size,
21417 unsigned int type);
21418 int (*have_wrcomb)(void);
21419-};
21420+} __do_const;
21421
21422 extern int generic_get_free_region(unsigned long base, unsigned long size,
21423 int replace_reg);
21424diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21425index ae407f7..39c5b00 100644
21426--- a/arch/x86/kernel/cpu/perf_event.c
21427+++ b/arch/x86/kernel/cpu/perf_event.c
21428@@ -1367,7 +1367,7 @@ static void __init pmu_check_apic(void)
21429 pr_info("no hardware sampling interrupt available.\n");
21430 }
21431
21432-static struct attribute_group x86_pmu_format_group = {
21433+static attribute_group_no_const x86_pmu_format_group = {
21434 .name = "format",
21435 .attrs = NULL,
21436 };
21437@@ -1466,7 +1466,7 @@ static struct attribute *events_attr[] = {
21438 NULL,
21439 };
21440
21441-static struct attribute_group x86_pmu_events_group = {
21442+static attribute_group_no_const x86_pmu_events_group = {
21443 .name = "events",
21444 .attrs = events_attr,
21445 };
21446@@ -1990,7 +1990,7 @@ static unsigned long get_segment_base(unsigned int segment)
21447 if (idx > GDT_ENTRIES)
21448 return 0;
21449
21450- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21451+ desc = get_cpu_gdt_table(smp_processor_id());
21452 }
21453
21454 return get_desc_base(desc + idx);
21455@@ -2080,7 +2080,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21456 break;
21457
21458 perf_callchain_store(entry, frame.return_address);
21459- fp = frame.next_frame;
21460+ fp = (const void __force_user *)frame.next_frame;
21461 }
21462 }
21463
21464diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21465index 639d128..e92d7e5 100644
21466--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21467+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21468@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21469 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21470 {
21471 struct attribute **attrs;
21472- struct attribute_group *attr_group;
21473+ attribute_group_no_const *attr_group;
21474 int i = 0, j;
21475
21476 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21477diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21478index adb02aa..9688c02 100644
21479--- a/arch/x86/kernel/cpu/perf_event_intel.c
21480+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21481@@ -2308,10 +2308,10 @@ __init int intel_pmu_init(void)
21482 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21483
21484 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21485- u64 capabilities;
21486+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21487
21488- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21489- x86_pmu.intel_cap.capabilities = capabilities;
21490+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21491+ x86_pmu.intel_cap.capabilities = capabilities;
21492 }
21493
21494 intel_ds_init();
21495diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21496index 619f769..d510008 100644
21497--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21498+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21499@@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21500 NULL,
21501 };
21502
21503-static struct attribute_group rapl_pmu_events_group = {
21504+static attribute_group_no_const rapl_pmu_events_group __read_only = {
21505 .name = "events",
21506 .attrs = NULL, /* patched at runtime */
21507 };
21508diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21509index 65bbbea..1438d9e 100644
21510--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21511+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21512@@ -3693,7 +3693,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21513 static int __init uncore_type_init(struct intel_uncore_type *type)
21514 {
21515 struct intel_uncore_pmu *pmus;
21516- struct attribute_group *attr_group;
21517+ attribute_group_no_const *attr_group;
21518 struct attribute **attrs;
21519 int i, j;
21520
21521diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21522index 90236f0..54cb20d 100644
21523--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21524+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21525@@ -503,7 +503,7 @@ struct intel_uncore_box {
21526 struct uncore_event_desc {
21527 struct kobj_attribute attr;
21528 const char *config;
21529-};
21530+} __do_const;
21531
21532 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21533 { \
21534diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21535index 3225ae6c..ee3c6db 100644
21536--- a/arch/x86/kernel/cpuid.c
21537+++ b/arch/x86/kernel/cpuid.c
21538@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21539 return notifier_from_errno(err);
21540 }
21541
21542-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21543+static struct notifier_block cpuid_class_cpu_notifier =
21544 {
21545 .notifier_call = cpuid_class_cpu_callback,
21546 };
21547diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21548index 507de80..ebaae2a 100644
21549--- a/arch/x86/kernel/crash.c
21550+++ b/arch/x86/kernel/crash.c
21551@@ -58,7 +58,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21552 #ifdef CONFIG_X86_32
21553 struct pt_regs fixed_regs;
21554
21555- if (!user_mode_vm(regs)) {
21556+ if (!user_mode(regs)) {
21557 crash_fixup_ss_esp(&fixed_regs, regs);
21558 regs = &fixed_regs;
21559 }
21560diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21561index afa64ad..dce67dd 100644
21562--- a/arch/x86/kernel/crash_dump_64.c
21563+++ b/arch/x86/kernel/crash_dump_64.c
21564@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21565 return -ENOMEM;
21566
21567 if (userbuf) {
21568- if (copy_to_user(buf, vaddr + offset, csize)) {
21569+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21570 iounmap(vaddr);
21571 return -EFAULT;
21572 }
21573diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21574index f6dfd93..892ade4 100644
21575--- a/arch/x86/kernel/doublefault.c
21576+++ b/arch/x86/kernel/doublefault.c
21577@@ -12,7 +12,7 @@
21578
21579 #define DOUBLEFAULT_STACKSIZE (1024)
21580 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21581-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21582+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21583
21584 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21585
21586@@ -22,7 +22,7 @@ static void doublefault_fn(void)
21587 unsigned long gdt, tss;
21588
21589 native_store_gdt(&gdt_desc);
21590- gdt = gdt_desc.address;
21591+ gdt = (unsigned long)gdt_desc.address;
21592
21593 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21594
21595@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21596 /* 0x2 bit is always set */
21597 .flags = X86_EFLAGS_SF | 0x2,
21598 .sp = STACK_START,
21599- .es = __USER_DS,
21600+ .es = __KERNEL_DS,
21601 .cs = __KERNEL_CS,
21602 .ss = __KERNEL_DS,
21603- .ds = __USER_DS,
21604+ .ds = __KERNEL_DS,
21605 .fs = __KERNEL_PERCPU,
21606
21607 .__cr3 = __pa_nodebug(swapper_pg_dir),
21608diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21609index d9c12d3..7858b62 100644
21610--- a/arch/x86/kernel/dumpstack.c
21611+++ b/arch/x86/kernel/dumpstack.c
21612@@ -2,6 +2,9 @@
21613 * Copyright (C) 1991, 1992 Linus Torvalds
21614 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21615 */
21616+#ifdef CONFIG_GRKERNSEC_HIDESYM
21617+#define __INCLUDED_BY_HIDESYM 1
21618+#endif
21619 #include <linux/kallsyms.h>
21620 #include <linux/kprobes.h>
21621 #include <linux/uaccess.h>
21622@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21623 static void
21624 print_ftrace_graph_addr(unsigned long addr, void *data,
21625 const struct stacktrace_ops *ops,
21626- struct thread_info *tinfo, int *graph)
21627+ struct task_struct *task, int *graph)
21628 {
21629- struct task_struct *task;
21630 unsigned long ret_addr;
21631 int index;
21632
21633 if (addr != (unsigned long)return_to_handler)
21634 return;
21635
21636- task = tinfo->task;
21637 index = task->curr_ret_stack;
21638
21639 if (!task->ret_stack || index < *graph)
21640@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21641 static inline void
21642 print_ftrace_graph_addr(unsigned long addr, void *data,
21643 const struct stacktrace_ops *ops,
21644- struct thread_info *tinfo, int *graph)
21645+ struct task_struct *task, int *graph)
21646 { }
21647 #endif
21648
21649@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21650 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21651 */
21652
21653-static inline int valid_stack_ptr(struct thread_info *tinfo,
21654- void *p, unsigned int size, void *end)
21655+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21656 {
21657- void *t = tinfo;
21658 if (end) {
21659 if (p < end && p >= (end-THREAD_SIZE))
21660 return 1;
21661@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21662 }
21663
21664 unsigned long
21665-print_context_stack(struct thread_info *tinfo,
21666+print_context_stack(struct task_struct *task, void *stack_start,
21667 unsigned long *stack, unsigned long bp,
21668 const struct stacktrace_ops *ops, void *data,
21669 unsigned long *end, int *graph)
21670 {
21671 struct stack_frame *frame = (struct stack_frame *)bp;
21672
21673- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21674+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21675 unsigned long addr;
21676
21677 addr = *stack;
21678@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21679 } else {
21680 ops->address(data, addr, 0);
21681 }
21682- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21683+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21684 }
21685 stack++;
21686 }
21687@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21688 EXPORT_SYMBOL_GPL(print_context_stack);
21689
21690 unsigned long
21691-print_context_stack_bp(struct thread_info *tinfo,
21692+print_context_stack_bp(struct task_struct *task, void *stack_start,
21693 unsigned long *stack, unsigned long bp,
21694 const struct stacktrace_ops *ops, void *data,
21695 unsigned long *end, int *graph)
21696@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21697 struct stack_frame *frame = (struct stack_frame *)bp;
21698 unsigned long *ret_addr = &frame->return_address;
21699
21700- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21701+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21702 unsigned long addr = *ret_addr;
21703
21704 if (!__kernel_text_address(addr))
21705@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21706 ops->address(data, addr, 1);
21707 frame = frame->next_frame;
21708 ret_addr = &frame->return_address;
21709- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21710+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21711 }
21712
21713 return (unsigned long)frame;
21714@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21715 static void print_trace_address(void *data, unsigned long addr, int reliable)
21716 {
21717 touch_nmi_watchdog();
21718- printk(data);
21719+ printk("%s", (char *)data);
21720 printk_stack_address(addr, reliable);
21721 }
21722
21723@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21724 }
21725 EXPORT_SYMBOL_GPL(oops_begin);
21726
21727+extern void gr_handle_kernel_exploit(void);
21728+
21729 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21730 {
21731 if (regs && kexec_should_crash(current))
21732@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21733 panic("Fatal exception in interrupt");
21734 if (panic_on_oops)
21735 panic("Fatal exception");
21736- do_exit(signr);
21737+
21738+ gr_handle_kernel_exploit();
21739+
21740+ do_group_exit(signr);
21741 }
21742
21743 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21744@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21745 print_modules();
21746 show_regs(regs);
21747 #ifdef CONFIG_X86_32
21748- if (user_mode_vm(regs)) {
21749+ if (user_mode(regs)) {
21750 sp = regs->sp;
21751 ss = regs->ss & 0xffff;
21752 } else {
21753@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21754 unsigned long flags = oops_begin();
21755 int sig = SIGSEGV;
21756
21757- if (!user_mode_vm(regs))
21758+ if (!user_mode(regs))
21759 report_bug(regs->ip, regs);
21760
21761 if (__die(str, regs, err))
21762diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21763index 5abd4cd..c65733b 100644
21764--- a/arch/x86/kernel/dumpstack_32.c
21765+++ b/arch/x86/kernel/dumpstack_32.c
21766@@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21767 bp = stack_frame(task, regs);
21768
21769 for (;;) {
21770- struct thread_info *context;
21771+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21772 void *end_stack;
21773
21774 end_stack = is_hardirq_stack(stack, cpu);
21775 if (!end_stack)
21776 end_stack = is_softirq_stack(stack, cpu);
21777
21778- context = task_thread_info(task);
21779- bp = ops->walk_stack(context, stack, bp, ops, data,
21780+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
21781 end_stack, &graph);
21782
21783 /* Stop if not on irq stack */
21784@@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
21785 int i;
21786
21787 show_regs_print_info(KERN_EMERG);
21788- __show_regs(regs, !user_mode_vm(regs));
21789+ __show_regs(regs, !user_mode(regs));
21790
21791 /*
21792 * When in-kernel, we also print out the stack and code at the
21793 * time of the fault..
21794 */
21795- if (!user_mode_vm(regs)) {
21796+ if (!user_mode(regs)) {
21797 unsigned int code_prologue = code_bytes * 43 / 64;
21798 unsigned int code_len = code_bytes;
21799 unsigned char c;
21800 u8 *ip;
21801+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21802
21803 pr_emerg("Stack:\n");
21804 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21805
21806 pr_emerg("Code:");
21807
21808- ip = (u8 *)regs->ip - code_prologue;
21809+ ip = (u8 *)regs->ip - code_prologue + cs_base;
21810 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21811 /* try starting at IP */
21812- ip = (u8 *)regs->ip;
21813+ ip = (u8 *)regs->ip + cs_base;
21814 code_len = code_len - code_prologue + 1;
21815 }
21816 for (i = 0; i < code_len; i++, ip++) {
21817@@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
21818 pr_cont(" Bad EIP value.");
21819 break;
21820 }
21821- if (ip == (u8 *)regs->ip)
21822+ if (ip == (u8 *)regs->ip + cs_base)
21823 pr_cont(" <%02x>", c);
21824 else
21825 pr_cont(" %02x", c);
21826@@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
21827 {
21828 unsigned short ud2;
21829
21830+ ip = ktla_ktva(ip);
21831 if (ip < PAGE_OFFSET)
21832 return 0;
21833 if (probe_kernel_address((unsigned short *)ip, ud2))
21834@@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
21835
21836 return ud2 == 0x0b0f;
21837 }
21838+
21839+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21840+void pax_check_alloca(unsigned long size)
21841+{
21842+ unsigned long sp = (unsigned long)&sp, stack_left;
21843+
21844+ /* all kernel stacks are of the same size */
21845+ stack_left = sp & (THREAD_SIZE - 1);
21846+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21847+}
21848+EXPORT_SYMBOL(pax_check_alloca);
21849+#endif
21850diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21851index 1abcb50..6c8d702 100644
21852--- a/arch/x86/kernel/dumpstack_64.c
21853+++ b/arch/x86/kernel/dumpstack_64.c
21854@@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21855 const struct stacktrace_ops *ops, void *data)
21856 {
21857 const unsigned cpu = get_cpu();
21858- struct thread_info *tinfo;
21859 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21860 unsigned long dummy;
21861 unsigned used = 0;
21862 int graph = 0;
21863 int done = 0;
21864+ void *stack_start;
21865
21866 if (!task)
21867 task = current;
21868@@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21869 * current stack address. If the stacks consist of nested
21870 * exceptions
21871 */
21872- tinfo = task_thread_info(task);
21873 while (!done) {
21874 unsigned long *stack_end;
21875 enum stack_type stype;
21876@@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21877 if (ops->stack(data, id) < 0)
21878 break;
21879
21880- bp = ops->walk_stack(tinfo, stack, bp, ops,
21881+ bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
21882 data, stack_end, &graph);
21883 ops->stack(data, "<EOE>");
21884 /*
21885@@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21886 * second-to-last pointer (index -2 to end) in the
21887 * exception stack:
21888 */
21889+ if ((u16)stack_end[-1] != __KERNEL_DS)
21890+ goto out;
21891 stack = (unsigned long *) stack_end[-2];
21892 done = 0;
21893 break;
21894@@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21895
21896 if (ops->stack(data, "IRQ") < 0)
21897 break;
21898- bp = ops->walk_stack(tinfo, stack, bp,
21899+ bp = ops->walk_stack(task, irq_stack, stack, bp,
21900 ops, data, stack_end, &graph);
21901 /*
21902 * We link to the next stack (which would be
21903@@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21904 /*
21905 * This handles the process stack:
21906 */
21907- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21908+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21909+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21910+out:
21911 put_cpu();
21912 }
21913 EXPORT_SYMBOL(dump_trace);
21914@@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
21915
21916 return ud2 == 0x0b0f;
21917 }
21918+
21919+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21920+void pax_check_alloca(unsigned long size)
21921+{
21922+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21923+ unsigned cpu, used;
21924+ char *id;
21925+
21926+ /* check the process stack first */
21927+ stack_start = (unsigned long)task_stack_page(current);
21928+ stack_end = stack_start + THREAD_SIZE;
21929+ if (likely(stack_start <= sp && sp < stack_end)) {
21930+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
21931+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21932+ return;
21933+ }
21934+
21935+ cpu = get_cpu();
21936+
21937+ /* check the irq stacks */
21938+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21939+ stack_start = stack_end - IRQ_STACK_SIZE;
21940+ if (stack_start <= sp && sp < stack_end) {
21941+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21942+ put_cpu();
21943+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21944+ return;
21945+ }
21946+
21947+ /* check the exception stacks */
21948+ used = 0;
21949+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21950+ stack_start = stack_end - EXCEPTION_STKSZ;
21951+ if (stack_end && stack_start <= sp && sp < stack_end) {
21952+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21953+ put_cpu();
21954+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21955+ return;
21956+ }
21957+
21958+ put_cpu();
21959+
21960+ /* unknown stack */
21961+ BUG();
21962+}
21963+EXPORT_SYMBOL(pax_check_alloca);
21964+#endif
21965diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21966index 988c00a..4f673b6 100644
21967--- a/arch/x86/kernel/e820.c
21968+++ b/arch/x86/kernel/e820.c
21969@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21970
21971 static void early_panic(char *msg)
21972 {
21973- early_printk(msg);
21974- panic(msg);
21975+ early_printk("%s", msg);
21976+ panic("%s", msg);
21977 }
21978
21979 static int userdef __initdata;
21980diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21981index 01d1c18..8073693 100644
21982--- a/arch/x86/kernel/early_printk.c
21983+++ b/arch/x86/kernel/early_printk.c
21984@@ -7,6 +7,7 @@
21985 #include <linux/pci_regs.h>
21986 #include <linux/pci_ids.h>
21987 #include <linux/errno.h>
21988+#include <linux/sched.h>
21989 #include <asm/io.h>
21990 #include <asm/processor.h>
21991 #include <asm/fcntl.h>
21992diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21993index a2a4f46..6cab058 100644
21994--- a/arch/x86/kernel/entry_32.S
21995+++ b/arch/x86/kernel/entry_32.S
21996@@ -177,13 +177,153 @@
21997 /*CFI_REL_OFFSET gs, PT_GS*/
21998 .endm
21999 .macro SET_KERNEL_GS reg
22000+
22001+#ifdef CONFIG_CC_STACKPROTECTOR
22002 movl $(__KERNEL_STACK_CANARY), \reg
22003+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22004+ movl $(__USER_DS), \reg
22005+#else
22006+ xorl \reg, \reg
22007+#endif
22008+
22009 movl \reg, %gs
22010 .endm
22011
22012 #endif /* CONFIG_X86_32_LAZY_GS */
22013
22014-.macro SAVE_ALL
22015+.macro pax_enter_kernel
22016+#ifdef CONFIG_PAX_KERNEXEC
22017+ call pax_enter_kernel
22018+#endif
22019+.endm
22020+
22021+.macro pax_exit_kernel
22022+#ifdef CONFIG_PAX_KERNEXEC
22023+ call pax_exit_kernel
22024+#endif
22025+.endm
22026+
22027+#ifdef CONFIG_PAX_KERNEXEC
22028+ENTRY(pax_enter_kernel)
22029+#ifdef CONFIG_PARAVIRT
22030+ pushl %eax
22031+ pushl %ecx
22032+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22033+ mov %eax, %esi
22034+#else
22035+ mov %cr0, %esi
22036+#endif
22037+ bts $16, %esi
22038+ jnc 1f
22039+ mov %cs, %esi
22040+ cmp $__KERNEL_CS, %esi
22041+ jz 3f
22042+ ljmp $__KERNEL_CS, $3f
22043+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22044+2:
22045+#ifdef CONFIG_PARAVIRT
22046+ mov %esi, %eax
22047+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22048+#else
22049+ mov %esi, %cr0
22050+#endif
22051+3:
22052+#ifdef CONFIG_PARAVIRT
22053+ popl %ecx
22054+ popl %eax
22055+#endif
22056+ ret
22057+ENDPROC(pax_enter_kernel)
22058+
22059+ENTRY(pax_exit_kernel)
22060+#ifdef CONFIG_PARAVIRT
22061+ pushl %eax
22062+ pushl %ecx
22063+#endif
22064+ mov %cs, %esi
22065+ cmp $__KERNEXEC_KERNEL_CS, %esi
22066+ jnz 2f
22067+#ifdef CONFIG_PARAVIRT
22068+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22069+ mov %eax, %esi
22070+#else
22071+ mov %cr0, %esi
22072+#endif
22073+ btr $16, %esi
22074+ ljmp $__KERNEL_CS, $1f
22075+1:
22076+#ifdef CONFIG_PARAVIRT
22077+ mov %esi, %eax
22078+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22079+#else
22080+ mov %esi, %cr0
22081+#endif
22082+2:
22083+#ifdef CONFIG_PARAVIRT
22084+ popl %ecx
22085+ popl %eax
22086+#endif
22087+ ret
22088+ENDPROC(pax_exit_kernel)
22089+#endif
22090+
22091+ .macro pax_erase_kstack
22092+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22093+ call pax_erase_kstack
22094+#endif
22095+ .endm
22096+
22097+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22098+/*
22099+ * ebp: thread_info
22100+ */
22101+ENTRY(pax_erase_kstack)
22102+ pushl %edi
22103+ pushl %ecx
22104+ pushl %eax
22105+
22106+ mov TI_lowest_stack(%ebp), %edi
22107+ mov $-0xBEEF, %eax
22108+ std
22109+
22110+1: mov %edi, %ecx
22111+ and $THREAD_SIZE_asm - 1, %ecx
22112+ shr $2, %ecx
22113+ repne scasl
22114+ jecxz 2f
22115+
22116+ cmp $2*16, %ecx
22117+ jc 2f
22118+
22119+ mov $2*16, %ecx
22120+ repe scasl
22121+ jecxz 2f
22122+ jne 1b
22123+
22124+2: cld
22125+ mov %esp, %ecx
22126+ sub %edi, %ecx
22127+
22128+ cmp $THREAD_SIZE_asm, %ecx
22129+ jb 3f
22130+ ud2
22131+3:
22132+
22133+ shr $2, %ecx
22134+ rep stosl
22135+
22136+ mov TI_task_thread_sp0(%ebp), %edi
22137+ sub $128, %edi
22138+ mov %edi, TI_lowest_stack(%ebp)
22139+
22140+ popl %eax
22141+ popl %ecx
22142+ popl %edi
22143+ ret
22144+ENDPROC(pax_erase_kstack)
22145+#endif
22146+
22147+.macro __SAVE_ALL _DS
22148 cld
22149 PUSH_GS
22150 pushl_cfi %fs
22151@@ -206,7 +346,7 @@
22152 CFI_REL_OFFSET ecx, 0
22153 pushl_cfi %ebx
22154 CFI_REL_OFFSET ebx, 0
22155- movl $(__USER_DS), %edx
22156+ movl $\_DS, %edx
22157 movl %edx, %ds
22158 movl %edx, %es
22159 movl $(__KERNEL_PERCPU), %edx
22160@@ -214,6 +354,15 @@
22161 SET_KERNEL_GS %edx
22162 .endm
22163
22164+.macro SAVE_ALL
22165+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22166+ __SAVE_ALL __KERNEL_DS
22167+ pax_enter_kernel
22168+#else
22169+ __SAVE_ALL __USER_DS
22170+#endif
22171+.endm
22172+
22173 .macro RESTORE_INT_REGS
22174 popl_cfi %ebx
22175 CFI_RESTORE ebx
22176@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22177 popfl_cfi
22178 jmp syscall_exit
22179 CFI_ENDPROC
22180-END(ret_from_fork)
22181+ENDPROC(ret_from_fork)
22182
22183 ENTRY(ret_from_kernel_thread)
22184 CFI_STARTPROC
22185@@ -344,7 +493,15 @@ ret_from_intr:
22186 andl $SEGMENT_RPL_MASK, %eax
22187 #endif
22188 cmpl $USER_RPL, %eax
22189+
22190+#ifdef CONFIG_PAX_KERNEXEC
22191+ jae resume_userspace
22192+
22193+ pax_exit_kernel
22194+ jmp resume_kernel
22195+#else
22196 jb resume_kernel # not returning to v8086 or userspace
22197+#endif
22198
22199 ENTRY(resume_userspace)
22200 LOCKDEP_SYS_EXIT
22201@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22202 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22203 # int/exception return?
22204 jne work_pending
22205- jmp restore_all
22206-END(ret_from_exception)
22207+ jmp restore_all_pax
22208+ENDPROC(ret_from_exception)
22209
22210 #ifdef CONFIG_PREEMPT
22211 ENTRY(resume_kernel)
22212@@ -369,7 +526,7 @@ need_resched:
22213 jz restore_all
22214 call preempt_schedule_irq
22215 jmp need_resched
22216-END(resume_kernel)
22217+ENDPROC(resume_kernel)
22218 #endif
22219 CFI_ENDPROC
22220 /*
22221@@ -403,30 +560,45 @@ sysenter_past_esp:
22222 /*CFI_REL_OFFSET cs, 0*/
22223 /*
22224 * Push current_thread_info()->sysenter_return to the stack.
22225- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22226- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22227 */
22228- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22229+ pushl_cfi $0
22230 CFI_REL_OFFSET eip, 0
22231
22232 pushl_cfi %eax
22233 SAVE_ALL
22234+ GET_THREAD_INFO(%ebp)
22235+ movl TI_sysenter_return(%ebp),%ebp
22236+ movl %ebp,PT_EIP(%esp)
22237 ENABLE_INTERRUPTS(CLBR_NONE)
22238
22239 /*
22240 * Load the potential sixth argument from user stack.
22241 * Careful about security.
22242 */
22243+ movl PT_OLDESP(%esp),%ebp
22244+
22245+#ifdef CONFIG_PAX_MEMORY_UDEREF
22246+ mov PT_OLDSS(%esp),%ds
22247+1: movl %ds:(%ebp),%ebp
22248+ push %ss
22249+ pop %ds
22250+#else
22251 cmpl $__PAGE_OFFSET-3,%ebp
22252 jae syscall_fault
22253 ASM_STAC
22254 1: movl (%ebp),%ebp
22255 ASM_CLAC
22256+#endif
22257+
22258 movl %ebp,PT_EBP(%esp)
22259 _ASM_EXTABLE(1b,syscall_fault)
22260
22261 GET_THREAD_INFO(%ebp)
22262
22263+#ifdef CONFIG_PAX_RANDKSTACK
22264+ pax_erase_kstack
22265+#endif
22266+
22267 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22268 jnz sysenter_audit
22269 sysenter_do_call:
22270@@ -441,12 +613,24 @@ sysenter_do_call:
22271 testl $_TIF_ALLWORK_MASK, %ecx
22272 jne sysexit_audit
22273 sysenter_exit:
22274+
22275+#ifdef CONFIG_PAX_RANDKSTACK
22276+ pushl_cfi %eax
22277+ movl %esp, %eax
22278+ call pax_randomize_kstack
22279+ popl_cfi %eax
22280+#endif
22281+
22282+ pax_erase_kstack
22283+
22284 /* if something modifies registers it must also disable sysexit */
22285 movl PT_EIP(%esp), %edx
22286 movl PT_OLDESP(%esp), %ecx
22287 xorl %ebp,%ebp
22288 TRACE_IRQS_ON
22289 1: mov PT_FS(%esp), %fs
22290+2: mov PT_DS(%esp), %ds
22291+3: mov PT_ES(%esp), %es
22292 PTGS_TO_GS
22293 ENABLE_INTERRUPTS_SYSEXIT
22294
22295@@ -463,6 +647,9 @@ sysenter_audit:
22296 movl %eax,%edx /* 2nd arg: syscall number */
22297 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22298 call __audit_syscall_entry
22299+
22300+ pax_erase_kstack
22301+
22302 pushl_cfi %ebx
22303 movl PT_EAX(%esp),%eax /* reload syscall number */
22304 jmp sysenter_do_call
22305@@ -488,10 +675,16 @@ sysexit_audit:
22306
22307 CFI_ENDPROC
22308 .pushsection .fixup,"ax"
22309-2: movl $0,PT_FS(%esp)
22310+4: movl $0,PT_FS(%esp)
22311+ jmp 1b
22312+5: movl $0,PT_DS(%esp)
22313+ jmp 1b
22314+6: movl $0,PT_ES(%esp)
22315 jmp 1b
22316 .popsection
22317- _ASM_EXTABLE(1b,2b)
22318+ _ASM_EXTABLE(1b,4b)
22319+ _ASM_EXTABLE(2b,5b)
22320+ _ASM_EXTABLE(3b,6b)
22321 PTGS_TO_GS_EX
22322 ENDPROC(ia32_sysenter_target)
22323
22324@@ -506,6 +699,11 @@ ENTRY(system_call)
22325 pushl_cfi %eax # save orig_eax
22326 SAVE_ALL
22327 GET_THREAD_INFO(%ebp)
22328+
22329+#ifdef CONFIG_PAX_RANDKSTACK
22330+ pax_erase_kstack
22331+#endif
22332+
22333 # system call tracing in operation / emulation
22334 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22335 jnz syscall_trace_entry
22336@@ -524,6 +722,15 @@ syscall_exit:
22337 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22338 jne syscall_exit_work
22339
22340+restore_all_pax:
22341+
22342+#ifdef CONFIG_PAX_RANDKSTACK
22343+ movl %esp, %eax
22344+ call pax_randomize_kstack
22345+#endif
22346+
22347+ pax_erase_kstack
22348+
22349 restore_all:
22350 TRACE_IRQS_IRET
22351 restore_all_notrace:
22352@@ -580,14 +787,34 @@ ldt_ss:
22353 * compensating for the offset by changing to the ESPFIX segment with
22354 * a base address that matches for the difference.
22355 */
22356-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22357+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22358 mov %esp, %edx /* load kernel esp */
22359 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22360 mov %dx, %ax /* eax: new kernel esp */
22361 sub %eax, %edx /* offset (low word is 0) */
22362+#ifdef CONFIG_SMP
22363+ movl PER_CPU_VAR(cpu_number), %ebx
22364+ shll $PAGE_SHIFT_asm, %ebx
22365+ addl $cpu_gdt_table, %ebx
22366+#else
22367+ movl $cpu_gdt_table, %ebx
22368+#endif
22369 shr $16, %edx
22370- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22371- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22372+
22373+#ifdef CONFIG_PAX_KERNEXEC
22374+ mov %cr0, %esi
22375+ btr $16, %esi
22376+ mov %esi, %cr0
22377+#endif
22378+
22379+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22380+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22381+
22382+#ifdef CONFIG_PAX_KERNEXEC
22383+ bts $16, %esi
22384+ mov %esi, %cr0
22385+#endif
22386+
22387 pushl_cfi $__ESPFIX_SS
22388 pushl_cfi %eax /* new kernel esp */
22389 /* Disable interrupts, but do not irqtrace this section: we
22390@@ -616,20 +843,18 @@ work_resched:
22391 movl TI_flags(%ebp), %ecx
22392 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22393 # than syscall tracing?
22394- jz restore_all
22395+ jz restore_all_pax
22396 testb $_TIF_NEED_RESCHED, %cl
22397 jnz work_resched
22398
22399 work_notifysig: # deal with pending signals and
22400 # notify-resume requests
22401+ movl %esp, %eax
22402 #ifdef CONFIG_VM86
22403 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22404- movl %esp, %eax
22405 jne work_notifysig_v86 # returning to kernel-space or
22406 # vm86-space
22407 1:
22408-#else
22409- movl %esp, %eax
22410 #endif
22411 TRACE_IRQS_ON
22412 ENABLE_INTERRUPTS(CLBR_NONE)
22413@@ -650,7 +875,7 @@ work_notifysig_v86:
22414 movl %eax, %esp
22415 jmp 1b
22416 #endif
22417-END(work_pending)
22418+ENDPROC(work_pending)
22419
22420 # perform syscall exit tracing
22421 ALIGN
22422@@ -658,11 +883,14 @@ syscall_trace_entry:
22423 movl $-ENOSYS,PT_EAX(%esp)
22424 movl %esp, %eax
22425 call syscall_trace_enter
22426+
22427+ pax_erase_kstack
22428+
22429 /* What it returned is what we'll actually use. */
22430 cmpl $(NR_syscalls), %eax
22431 jnae syscall_call
22432 jmp syscall_exit
22433-END(syscall_trace_entry)
22434+ENDPROC(syscall_trace_entry)
22435
22436 # perform syscall exit tracing
22437 ALIGN
22438@@ -675,21 +903,25 @@ syscall_exit_work:
22439 movl %esp, %eax
22440 call syscall_trace_leave
22441 jmp resume_userspace
22442-END(syscall_exit_work)
22443+ENDPROC(syscall_exit_work)
22444 CFI_ENDPROC
22445
22446 RING0_INT_FRAME # can't unwind into user space anyway
22447 syscall_fault:
22448+#ifdef CONFIG_PAX_MEMORY_UDEREF
22449+ push %ss
22450+ pop %ds
22451+#endif
22452 ASM_CLAC
22453 GET_THREAD_INFO(%ebp)
22454 movl $-EFAULT,PT_EAX(%esp)
22455 jmp resume_userspace
22456-END(syscall_fault)
22457+ENDPROC(syscall_fault)
22458
22459 syscall_badsys:
22460 movl $-ENOSYS,PT_EAX(%esp)
22461 jmp resume_userspace
22462-END(syscall_badsys)
22463+ENDPROC(syscall_badsys)
22464 CFI_ENDPROC
22465 /*
22466 * End of kprobes section
22467@@ -705,8 +937,15 @@ END(syscall_badsys)
22468 * normal stack and adjusts ESP with the matching offset.
22469 */
22470 /* fixup the stack */
22471- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22472- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22473+#ifdef CONFIG_SMP
22474+ movl PER_CPU_VAR(cpu_number), %ebx
22475+ shll $PAGE_SHIFT_asm, %ebx
22476+ addl $cpu_gdt_table, %ebx
22477+#else
22478+ movl $cpu_gdt_table, %ebx
22479+#endif
22480+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22481+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22482 shl $16, %eax
22483 addl %esp, %eax /* the adjusted stack pointer */
22484 pushl_cfi $__KERNEL_DS
22485@@ -759,7 +998,7 @@ vector=vector+1
22486 .endr
22487 2: jmp common_interrupt
22488 .endr
22489-END(irq_entries_start)
22490+ENDPROC(irq_entries_start)
22491
22492 .previous
22493 END(interrupt)
22494@@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22495 pushl_cfi $do_coprocessor_error
22496 jmp error_code
22497 CFI_ENDPROC
22498-END(coprocessor_error)
22499+ENDPROC(coprocessor_error)
22500
22501 ENTRY(simd_coprocessor_error)
22502 RING0_INT_FRAME
22503@@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22504 .section .altinstructions,"a"
22505 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22506 .previous
22507-.section .altinstr_replacement,"ax"
22508+.section .altinstr_replacement,"a"
22509 663: pushl $do_simd_coprocessor_error
22510 664:
22511 .previous
22512@@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22513 #endif
22514 jmp error_code
22515 CFI_ENDPROC
22516-END(simd_coprocessor_error)
22517+ENDPROC(simd_coprocessor_error)
22518
22519 ENTRY(device_not_available)
22520 RING0_INT_FRAME
22521@@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22522 pushl_cfi $do_device_not_available
22523 jmp error_code
22524 CFI_ENDPROC
22525-END(device_not_available)
22526+ENDPROC(device_not_available)
22527
22528 #ifdef CONFIG_PARAVIRT
22529 ENTRY(native_iret)
22530 iret
22531 _ASM_EXTABLE(native_iret, iret_exc)
22532-END(native_iret)
22533+ENDPROC(native_iret)
22534
22535 ENTRY(native_irq_enable_sysexit)
22536 sti
22537 sysexit
22538-END(native_irq_enable_sysexit)
22539+ENDPROC(native_irq_enable_sysexit)
22540 #endif
22541
22542 ENTRY(overflow)
22543@@ -872,7 +1111,7 @@ ENTRY(overflow)
22544 pushl_cfi $do_overflow
22545 jmp error_code
22546 CFI_ENDPROC
22547-END(overflow)
22548+ENDPROC(overflow)
22549
22550 ENTRY(bounds)
22551 RING0_INT_FRAME
22552@@ -881,7 +1120,7 @@ ENTRY(bounds)
22553 pushl_cfi $do_bounds
22554 jmp error_code
22555 CFI_ENDPROC
22556-END(bounds)
22557+ENDPROC(bounds)
22558
22559 ENTRY(invalid_op)
22560 RING0_INT_FRAME
22561@@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22562 pushl_cfi $do_invalid_op
22563 jmp error_code
22564 CFI_ENDPROC
22565-END(invalid_op)
22566+ENDPROC(invalid_op)
22567
22568 ENTRY(coprocessor_segment_overrun)
22569 RING0_INT_FRAME
22570@@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22571 pushl_cfi $do_coprocessor_segment_overrun
22572 jmp error_code
22573 CFI_ENDPROC
22574-END(coprocessor_segment_overrun)
22575+ENDPROC(coprocessor_segment_overrun)
22576
22577 ENTRY(invalid_TSS)
22578 RING0_EC_FRAME
22579@@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22580 pushl_cfi $do_invalid_TSS
22581 jmp error_code
22582 CFI_ENDPROC
22583-END(invalid_TSS)
22584+ENDPROC(invalid_TSS)
22585
22586 ENTRY(segment_not_present)
22587 RING0_EC_FRAME
22588@@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22589 pushl_cfi $do_segment_not_present
22590 jmp error_code
22591 CFI_ENDPROC
22592-END(segment_not_present)
22593+ENDPROC(segment_not_present)
22594
22595 ENTRY(stack_segment)
22596 RING0_EC_FRAME
22597@@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22598 pushl_cfi $do_stack_segment
22599 jmp error_code
22600 CFI_ENDPROC
22601-END(stack_segment)
22602+ENDPROC(stack_segment)
22603
22604 ENTRY(alignment_check)
22605 RING0_EC_FRAME
22606@@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22607 pushl_cfi $do_alignment_check
22608 jmp error_code
22609 CFI_ENDPROC
22610-END(alignment_check)
22611+ENDPROC(alignment_check)
22612
22613 ENTRY(divide_error)
22614 RING0_INT_FRAME
22615@@ -940,7 +1179,7 @@ ENTRY(divide_error)
22616 pushl_cfi $do_divide_error
22617 jmp error_code
22618 CFI_ENDPROC
22619-END(divide_error)
22620+ENDPROC(divide_error)
22621
22622 #ifdef CONFIG_X86_MCE
22623 ENTRY(machine_check)
22624@@ -950,7 +1189,7 @@ ENTRY(machine_check)
22625 pushl_cfi machine_check_vector
22626 jmp error_code
22627 CFI_ENDPROC
22628-END(machine_check)
22629+ENDPROC(machine_check)
22630 #endif
22631
22632 ENTRY(spurious_interrupt_bug)
22633@@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22634 pushl_cfi $do_spurious_interrupt_bug
22635 jmp error_code
22636 CFI_ENDPROC
22637-END(spurious_interrupt_bug)
22638+ENDPROC(spurious_interrupt_bug)
22639 /*
22640 * End of kprobes section
22641 */
22642@@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22643
22644 ENTRY(mcount)
22645 ret
22646-END(mcount)
22647+ENDPROC(mcount)
22648
22649 ENTRY(ftrace_caller)
22650 cmpl $0, function_trace_stop
22651@@ -1103,7 +1342,7 @@ ftrace_graph_call:
22652 .globl ftrace_stub
22653 ftrace_stub:
22654 ret
22655-END(ftrace_caller)
22656+ENDPROC(ftrace_caller)
22657
22658 ENTRY(ftrace_regs_caller)
22659 pushf /* push flags before compare (in cs location) */
22660@@ -1207,7 +1446,7 @@ trace:
22661 popl %ecx
22662 popl %eax
22663 jmp ftrace_stub
22664-END(mcount)
22665+ENDPROC(mcount)
22666 #endif /* CONFIG_DYNAMIC_FTRACE */
22667 #endif /* CONFIG_FUNCTION_TRACER */
22668
22669@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22670 popl %ecx
22671 popl %eax
22672 ret
22673-END(ftrace_graph_caller)
22674+ENDPROC(ftrace_graph_caller)
22675
22676 .globl return_to_handler
22677 return_to_handler:
22678@@ -1291,15 +1530,18 @@ error_code:
22679 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22680 REG_TO_PTGS %ecx
22681 SET_KERNEL_GS %ecx
22682- movl $(__USER_DS), %ecx
22683+ movl $(__KERNEL_DS), %ecx
22684 movl %ecx, %ds
22685 movl %ecx, %es
22686+
22687+ pax_enter_kernel
22688+
22689 TRACE_IRQS_OFF
22690 movl %esp,%eax # pt_regs pointer
22691 call *%edi
22692 jmp ret_from_exception
22693 CFI_ENDPROC
22694-END(page_fault)
22695+ENDPROC(page_fault)
22696
22697 /*
22698 * Debug traps and NMI can happen at the one SYSENTER instruction
22699@@ -1342,7 +1584,7 @@ debug_stack_correct:
22700 call do_debug
22701 jmp ret_from_exception
22702 CFI_ENDPROC
22703-END(debug)
22704+ENDPROC(debug)
22705
22706 /*
22707 * NMI is doubly nasty. It can happen _while_ we're handling
22708@@ -1380,6 +1622,9 @@ nmi_stack_correct:
22709 xorl %edx,%edx # zero error code
22710 movl %esp,%eax # pt_regs pointer
22711 call do_nmi
22712+
22713+ pax_exit_kernel
22714+
22715 jmp restore_all_notrace
22716 CFI_ENDPROC
22717
22718@@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22719 FIXUP_ESPFIX_STACK # %eax == %esp
22720 xorl %edx,%edx # zero error code
22721 call do_nmi
22722+
22723+ pax_exit_kernel
22724+
22725 RESTORE_REGS
22726 lss 12+4(%esp), %esp # back to espfix stack
22727 CFI_ADJUST_CFA_OFFSET -24
22728 jmp irq_return
22729 CFI_ENDPROC
22730-END(nmi)
22731+ENDPROC(nmi)
22732
22733 ENTRY(int3)
22734 RING0_INT_FRAME
22735@@ -1434,14 +1682,14 @@ ENTRY(int3)
22736 call do_int3
22737 jmp ret_from_exception
22738 CFI_ENDPROC
22739-END(int3)
22740+ENDPROC(int3)
22741
22742 ENTRY(general_protection)
22743 RING0_EC_FRAME
22744 pushl_cfi $do_general_protection
22745 jmp error_code
22746 CFI_ENDPROC
22747-END(general_protection)
22748+ENDPROC(general_protection)
22749
22750 #ifdef CONFIG_KVM_GUEST
22751 ENTRY(async_page_fault)
22752@@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22753 pushl_cfi $do_async_page_fault
22754 jmp error_code
22755 CFI_ENDPROC
22756-END(async_page_fault)
22757+ENDPROC(async_page_fault)
22758 #endif
22759
22760 /*
22761diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22762index 1e96c36..3ff710a 100644
22763--- a/arch/x86/kernel/entry_64.S
22764+++ b/arch/x86/kernel/entry_64.S
22765@@ -59,6 +59,8 @@
22766 #include <asm/context_tracking.h>
22767 #include <asm/smap.h>
22768 #include <linux/err.h>
22769+#include <asm/pgtable.h>
22770+#include <asm/alternative-asm.h>
22771
22772 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22773 #include <linux/elf-em.h>
22774@@ -80,8 +82,9 @@
22775 #ifdef CONFIG_DYNAMIC_FTRACE
22776
22777 ENTRY(function_hook)
22778+ pax_force_retaddr
22779 retq
22780-END(function_hook)
22781+ENDPROC(function_hook)
22782
22783 /* skip is set if stack has been adjusted */
22784 .macro ftrace_caller_setup skip=0
22785@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22786 #endif
22787
22788 GLOBAL(ftrace_stub)
22789+ pax_force_retaddr
22790 retq
22791-END(ftrace_caller)
22792+ENDPROC(ftrace_caller)
22793
22794 ENTRY(ftrace_regs_caller)
22795 /* Save the current flags before compare (in SS location)*/
22796@@ -191,7 +195,7 @@ ftrace_restore_flags:
22797 popfq
22798 jmp ftrace_stub
22799
22800-END(ftrace_regs_caller)
22801+ENDPROC(ftrace_regs_caller)
22802
22803
22804 #else /* ! CONFIG_DYNAMIC_FTRACE */
22805@@ -212,6 +216,7 @@ ENTRY(function_hook)
22806 #endif
22807
22808 GLOBAL(ftrace_stub)
22809+ pax_force_retaddr
22810 retq
22811
22812 trace:
22813@@ -225,12 +230,13 @@ trace:
22814 #endif
22815 subq $MCOUNT_INSN_SIZE, %rdi
22816
22817+ pax_force_fptr ftrace_trace_function
22818 call *ftrace_trace_function
22819
22820 MCOUNT_RESTORE_FRAME
22821
22822 jmp ftrace_stub
22823-END(function_hook)
22824+ENDPROC(function_hook)
22825 #endif /* CONFIG_DYNAMIC_FTRACE */
22826 #endif /* CONFIG_FUNCTION_TRACER */
22827
22828@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22829
22830 MCOUNT_RESTORE_FRAME
22831
22832+ pax_force_retaddr
22833 retq
22834-END(ftrace_graph_caller)
22835+ENDPROC(ftrace_graph_caller)
22836
22837 GLOBAL(return_to_handler)
22838 subq $24, %rsp
22839@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22840 movq 8(%rsp), %rdx
22841 movq (%rsp), %rax
22842 addq $24, %rsp
22843+ pax_force_fptr %rdi
22844 jmp *%rdi
22845+ENDPROC(return_to_handler)
22846 #endif
22847
22848
22849@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22850 ENDPROC(native_usergs_sysret64)
22851 #endif /* CONFIG_PARAVIRT */
22852
22853+ .macro ljmpq sel, off
22854+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22855+ .byte 0x48; ljmp *1234f(%rip)
22856+ .pushsection .rodata
22857+ .align 16
22858+ 1234: .quad \off; .word \sel
22859+ .popsection
22860+#else
22861+ pushq $\sel
22862+ pushq $\off
22863+ lretq
22864+#endif
22865+ .endm
22866+
22867+ .macro pax_enter_kernel
22868+ pax_set_fptr_mask
22869+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22870+ call pax_enter_kernel
22871+#endif
22872+ .endm
22873+
22874+ .macro pax_exit_kernel
22875+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22876+ call pax_exit_kernel
22877+#endif
22878+
22879+ .endm
22880+
22881+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22882+ENTRY(pax_enter_kernel)
22883+ pushq %rdi
22884+
22885+#ifdef CONFIG_PARAVIRT
22886+ PV_SAVE_REGS(CLBR_RDI)
22887+#endif
22888+
22889+#ifdef CONFIG_PAX_KERNEXEC
22890+ GET_CR0_INTO_RDI
22891+ bts $16,%rdi
22892+ jnc 3f
22893+ mov %cs,%edi
22894+ cmp $__KERNEL_CS,%edi
22895+ jnz 2f
22896+1:
22897+#endif
22898+
22899+#ifdef CONFIG_PAX_MEMORY_UDEREF
22900+ 661: jmp 111f
22901+ .pushsection .altinstr_replacement, "a"
22902+ 662: ASM_NOP2
22903+ .popsection
22904+ .pushsection .altinstructions, "a"
22905+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22906+ .popsection
22907+ GET_CR3_INTO_RDI
22908+ cmp $0,%dil
22909+ jnz 112f
22910+ mov $__KERNEL_DS,%edi
22911+ mov %edi,%ss
22912+ jmp 111f
22913+112: cmp $1,%dil
22914+ jz 113f
22915+ ud2
22916+113: sub $4097,%rdi
22917+ bts $63,%rdi
22918+ SET_RDI_INTO_CR3
22919+ mov $__UDEREF_KERNEL_DS,%edi
22920+ mov %edi,%ss
22921+111:
22922+#endif
22923+
22924+#ifdef CONFIG_PARAVIRT
22925+ PV_RESTORE_REGS(CLBR_RDI)
22926+#endif
22927+
22928+ popq %rdi
22929+ pax_force_retaddr
22930+ retq
22931+
22932+#ifdef CONFIG_PAX_KERNEXEC
22933+2: ljmpq __KERNEL_CS,1b
22934+3: ljmpq __KERNEXEC_KERNEL_CS,4f
22935+4: SET_RDI_INTO_CR0
22936+ jmp 1b
22937+#endif
22938+ENDPROC(pax_enter_kernel)
22939+
22940+ENTRY(pax_exit_kernel)
22941+ pushq %rdi
22942+
22943+#ifdef CONFIG_PARAVIRT
22944+ PV_SAVE_REGS(CLBR_RDI)
22945+#endif
22946+
22947+#ifdef CONFIG_PAX_KERNEXEC
22948+ mov %cs,%rdi
22949+ cmp $__KERNEXEC_KERNEL_CS,%edi
22950+ jz 2f
22951+ GET_CR0_INTO_RDI
22952+ bts $16,%rdi
22953+ jnc 4f
22954+1:
22955+#endif
22956+
22957+#ifdef CONFIG_PAX_MEMORY_UDEREF
22958+ 661: jmp 111f
22959+ .pushsection .altinstr_replacement, "a"
22960+ 662: ASM_NOP2
22961+ .popsection
22962+ .pushsection .altinstructions, "a"
22963+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22964+ .popsection
22965+ mov %ss,%edi
22966+ cmp $__UDEREF_KERNEL_DS,%edi
22967+ jnz 111f
22968+ GET_CR3_INTO_RDI
22969+ cmp $0,%dil
22970+ jz 112f
22971+ ud2
22972+112: add $4097,%rdi
22973+ bts $63,%rdi
22974+ SET_RDI_INTO_CR3
22975+ mov $__KERNEL_DS,%edi
22976+ mov %edi,%ss
22977+111:
22978+#endif
22979+
22980+#ifdef CONFIG_PARAVIRT
22981+ PV_RESTORE_REGS(CLBR_RDI);
22982+#endif
22983+
22984+ popq %rdi
22985+ pax_force_retaddr
22986+ retq
22987+
22988+#ifdef CONFIG_PAX_KERNEXEC
22989+2: GET_CR0_INTO_RDI
22990+ btr $16,%rdi
22991+ jnc 4f
22992+ ljmpq __KERNEL_CS,3f
22993+3: SET_RDI_INTO_CR0
22994+ jmp 1b
22995+4: ud2
22996+ jmp 4b
22997+#endif
22998+ENDPROC(pax_exit_kernel)
22999+#endif
23000+
23001+ .macro pax_enter_kernel_user
23002+ pax_set_fptr_mask
23003+#ifdef CONFIG_PAX_MEMORY_UDEREF
23004+ call pax_enter_kernel_user
23005+#endif
23006+ .endm
23007+
23008+ .macro pax_exit_kernel_user
23009+#ifdef CONFIG_PAX_MEMORY_UDEREF
23010+ call pax_exit_kernel_user
23011+#endif
23012+#ifdef CONFIG_PAX_RANDKSTACK
23013+ pushq %rax
23014+ pushq %r11
23015+ call pax_randomize_kstack
23016+ popq %r11
23017+ popq %rax
23018+#endif
23019+ .endm
23020+
23021+#ifdef CONFIG_PAX_MEMORY_UDEREF
23022+ENTRY(pax_enter_kernel_user)
23023+ pushq %rdi
23024+ pushq %rbx
23025+
23026+#ifdef CONFIG_PARAVIRT
23027+ PV_SAVE_REGS(CLBR_RDI)
23028+#endif
23029+
23030+ 661: jmp 111f
23031+ .pushsection .altinstr_replacement, "a"
23032+ 662: ASM_NOP2
23033+ .popsection
23034+ .pushsection .altinstructions, "a"
23035+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23036+ .popsection
23037+ GET_CR3_INTO_RDI
23038+ cmp $1,%dil
23039+ jnz 4f
23040+ sub $4097,%rdi
23041+ bts $63,%rdi
23042+ SET_RDI_INTO_CR3
23043+ jmp 3f
23044+111:
23045+
23046+ GET_CR3_INTO_RDI
23047+ mov %rdi,%rbx
23048+ add $__START_KERNEL_map,%rbx
23049+ sub phys_base(%rip),%rbx
23050+
23051+#ifdef CONFIG_PARAVIRT
23052+ cmpl $0, pv_info+PARAVIRT_enabled
23053+ jz 1f
23054+ pushq %rdi
23055+ i = 0
23056+ .rept USER_PGD_PTRS
23057+ mov i*8(%rbx),%rsi
23058+ mov $0,%sil
23059+ lea i*8(%rbx),%rdi
23060+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23061+ i = i + 1
23062+ .endr
23063+ popq %rdi
23064+ jmp 2f
23065+1:
23066+#endif
23067+
23068+ i = 0
23069+ .rept USER_PGD_PTRS
23070+ movb $0,i*8(%rbx)
23071+ i = i + 1
23072+ .endr
23073+
23074+2: SET_RDI_INTO_CR3
23075+
23076+#ifdef CONFIG_PAX_KERNEXEC
23077+ GET_CR0_INTO_RDI
23078+ bts $16,%rdi
23079+ SET_RDI_INTO_CR0
23080+#endif
23081+
23082+3:
23083+
23084+#ifdef CONFIG_PARAVIRT
23085+ PV_RESTORE_REGS(CLBR_RDI)
23086+#endif
23087+
23088+ popq %rbx
23089+ popq %rdi
23090+ pax_force_retaddr
23091+ retq
23092+4: ud2
23093+ENDPROC(pax_enter_kernel_user)
23094+
23095+ENTRY(pax_exit_kernel_user)
23096+ pushq %rdi
23097+ pushq %rbx
23098+
23099+#ifdef CONFIG_PARAVIRT
23100+ PV_SAVE_REGS(CLBR_RDI)
23101+#endif
23102+
23103+ GET_CR3_INTO_RDI
23104+ 661: jmp 1f
23105+ .pushsection .altinstr_replacement, "a"
23106+ 662: ASM_NOP2
23107+ .popsection
23108+ .pushsection .altinstructions, "a"
23109+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23110+ .popsection
23111+ cmp $0,%dil
23112+ jnz 3f
23113+ add $4097,%rdi
23114+ bts $63,%rdi
23115+ SET_RDI_INTO_CR3
23116+ jmp 2f
23117+1:
23118+
23119+ mov %rdi,%rbx
23120+
23121+#ifdef CONFIG_PAX_KERNEXEC
23122+ GET_CR0_INTO_RDI
23123+ btr $16,%rdi
23124+ jnc 3f
23125+ SET_RDI_INTO_CR0
23126+#endif
23127+
23128+ add $__START_KERNEL_map,%rbx
23129+ sub phys_base(%rip),%rbx
23130+
23131+#ifdef CONFIG_PARAVIRT
23132+ cmpl $0, pv_info+PARAVIRT_enabled
23133+ jz 1f
23134+ i = 0
23135+ .rept USER_PGD_PTRS
23136+ mov i*8(%rbx),%rsi
23137+ mov $0x67,%sil
23138+ lea i*8(%rbx),%rdi
23139+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23140+ i = i + 1
23141+ .endr
23142+ jmp 2f
23143+1:
23144+#endif
23145+
23146+ i = 0
23147+ .rept USER_PGD_PTRS
23148+ movb $0x67,i*8(%rbx)
23149+ i = i + 1
23150+ .endr
23151+2:
23152+
23153+#ifdef CONFIG_PARAVIRT
23154+ PV_RESTORE_REGS(CLBR_RDI)
23155+#endif
23156+
23157+ popq %rbx
23158+ popq %rdi
23159+ pax_force_retaddr
23160+ retq
23161+3: ud2
23162+ENDPROC(pax_exit_kernel_user)
23163+#endif
23164+
23165+ .macro pax_enter_kernel_nmi
23166+ pax_set_fptr_mask
23167+
23168+#ifdef CONFIG_PAX_KERNEXEC
23169+ GET_CR0_INTO_RDI
23170+ bts $16,%rdi
23171+ jc 110f
23172+ SET_RDI_INTO_CR0
23173+ or $2,%ebx
23174+110:
23175+#endif
23176+
23177+#ifdef CONFIG_PAX_MEMORY_UDEREF
23178+ 661: jmp 111f
23179+ .pushsection .altinstr_replacement, "a"
23180+ 662: ASM_NOP2
23181+ .popsection
23182+ .pushsection .altinstructions, "a"
23183+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23184+ .popsection
23185+ GET_CR3_INTO_RDI
23186+ cmp $0,%dil
23187+ jz 111f
23188+ sub $4097,%rdi
23189+ or $4,%ebx
23190+ bts $63,%rdi
23191+ SET_RDI_INTO_CR3
23192+ mov $__UDEREF_KERNEL_DS,%edi
23193+ mov %edi,%ss
23194+111:
23195+#endif
23196+ .endm
23197+
23198+ .macro pax_exit_kernel_nmi
23199+#ifdef CONFIG_PAX_KERNEXEC
23200+ btr $1,%ebx
23201+ jnc 110f
23202+ GET_CR0_INTO_RDI
23203+ btr $16,%rdi
23204+ SET_RDI_INTO_CR0
23205+110:
23206+#endif
23207+
23208+#ifdef CONFIG_PAX_MEMORY_UDEREF
23209+ btr $2,%ebx
23210+ jnc 111f
23211+ GET_CR3_INTO_RDI
23212+ add $4097,%rdi
23213+ bts $63,%rdi
23214+ SET_RDI_INTO_CR3
23215+ mov $__KERNEL_DS,%edi
23216+ mov %edi,%ss
23217+111:
23218+#endif
23219+ .endm
23220+
23221+ .macro pax_erase_kstack
23222+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23223+ call pax_erase_kstack
23224+#endif
23225+ .endm
23226+
23227+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23228+ENTRY(pax_erase_kstack)
23229+ pushq %rdi
23230+ pushq %rcx
23231+ pushq %rax
23232+ pushq %r11
23233+
23234+ GET_THREAD_INFO(%r11)
23235+ mov TI_lowest_stack(%r11), %rdi
23236+ mov $-0xBEEF, %rax
23237+ std
23238+
23239+1: mov %edi, %ecx
23240+ and $THREAD_SIZE_asm - 1, %ecx
23241+ shr $3, %ecx
23242+ repne scasq
23243+ jecxz 2f
23244+
23245+ cmp $2*8, %ecx
23246+ jc 2f
23247+
23248+ mov $2*8, %ecx
23249+ repe scasq
23250+ jecxz 2f
23251+ jne 1b
23252+
23253+2: cld
23254+ mov %esp, %ecx
23255+ sub %edi, %ecx
23256+
23257+ cmp $THREAD_SIZE_asm, %rcx
23258+ jb 3f
23259+ ud2
23260+3:
23261+
23262+ shr $3, %ecx
23263+ rep stosq
23264+
23265+ mov TI_task_thread_sp0(%r11), %rdi
23266+ sub $256, %rdi
23267+ mov %rdi, TI_lowest_stack(%r11)
23268+
23269+ popq %r11
23270+ popq %rax
23271+ popq %rcx
23272+ popq %rdi
23273+ pax_force_retaddr
23274+ ret
23275+ENDPROC(pax_erase_kstack)
23276+#endif
23277
23278 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23279 #ifdef CONFIG_TRACE_IRQFLAGS
23280@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23281 .endm
23282
23283 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23284- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23285+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23286 jnc 1f
23287 TRACE_IRQS_ON_DEBUG
23288 1:
23289@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23290 movq \tmp,R11+\offset(%rsp)
23291 .endm
23292
23293- .macro FAKE_STACK_FRAME child_rip
23294- /* push in order ss, rsp, eflags, cs, rip */
23295- xorl %eax, %eax
23296- pushq_cfi $__KERNEL_DS /* ss */
23297- /*CFI_REL_OFFSET ss,0*/
23298- pushq_cfi %rax /* rsp */
23299- CFI_REL_OFFSET rsp,0
23300- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23301- /*CFI_REL_OFFSET rflags,0*/
23302- pushq_cfi $__KERNEL_CS /* cs */
23303- /*CFI_REL_OFFSET cs,0*/
23304- pushq_cfi \child_rip /* rip */
23305- CFI_REL_OFFSET rip,0
23306- pushq_cfi %rax /* orig rax */
23307- .endm
23308-
23309- .macro UNFAKE_STACK_FRAME
23310- addq $8*6, %rsp
23311- CFI_ADJUST_CFA_OFFSET -(6*8)
23312- .endm
23313-
23314 /*
23315 * initial frame state for interrupts (and exceptions without error code)
23316 */
23317@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23318 /* save partial stack frame */
23319 .macro SAVE_ARGS_IRQ
23320 cld
23321- /* start from rbp in pt_regs and jump over */
23322- movq_cfi rdi, (RDI-RBP)
23323- movq_cfi rsi, (RSI-RBP)
23324- movq_cfi rdx, (RDX-RBP)
23325- movq_cfi rcx, (RCX-RBP)
23326- movq_cfi rax, (RAX-RBP)
23327- movq_cfi r8, (R8-RBP)
23328- movq_cfi r9, (R9-RBP)
23329- movq_cfi r10, (R10-RBP)
23330- movq_cfi r11, (R11-RBP)
23331+ /* start from r15 in pt_regs and jump over */
23332+ movq_cfi rdi, RDI
23333+ movq_cfi rsi, RSI
23334+ movq_cfi rdx, RDX
23335+ movq_cfi rcx, RCX
23336+ movq_cfi rax, RAX
23337+ movq_cfi r8, R8
23338+ movq_cfi r9, R9
23339+ movq_cfi r10, R10
23340+ movq_cfi r11, R11
23341+ movq_cfi r12, R12
23342
23343 /* Save rbp so that we can unwind from get_irq_regs() */
23344- movq_cfi rbp, 0
23345+ movq_cfi rbp, RBP
23346
23347 /* Save previous stack value */
23348 movq %rsp, %rsi
23349
23350- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23351- testl $3, CS-RBP(%rsi)
23352+ movq %rsp,%rdi /* arg1 for handler */
23353+ testb $3, CS(%rsi)
23354 je 1f
23355 SWAPGS
23356 /*
23357@@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23358 0x06 /* DW_OP_deref */, \
23359 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23360 0x22 /* DW_OP_plus */
23361+
23362+#ifdef CONFIG_PAX_MEMORY_UDEREF
23363+ testb $3, CS(%rdi)
23364+ jnz 1f
23365+ pax_enter_kernel
23366+ jmp 2f
23367+1: pax_enter_kernel_user
23368+2:
23369+#else
23370+ pax_enter_kernel
23371+#endif
23372+
23373 /* We entered an interrupt context - irqs are off: */
23374 TRACE_IRQS_OFF
23375 .endm
23376@@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23377 js 1f /* negative -> in kernel */
23378 SWAPGS
23379 xorl %ebx,%ebx
23380-1: ret
23381+1:
23382+#ifdef CONFIG_PAX_MEMORY_UDEREF
23383+ testb $3, CS+8(%rsp)
23384+ jnz 1f
23385+ pax_enter_kernel
23386+ jmp 2f
23387+1: pax_enter_kernel_user
23388+2:
23389+#else
23390+ pax_enter_kernel
23391+#endif
23392+ pax_force_retaddr
23393+ ret
23394 CFI_ENDPROC
23395-END(save_paranoid)
23396+ENDPROC(save_paranoid)
23397+
23398+ENTRY(save_paranoid_nmi)
23399+ XCPT_FRAME 1 RDI+8
23400+ cld
23401+ movq_cfi rdi, RDI+8
23402+ movq_cfi rsi, RSI+8
23403+ movq_cfi rdx, RDX+8
23404+ movq_cfi rcx, RCX+8
23405+ movq_cfi rax, RAX+8
23406+ movq_cfi r8, R8+8
23407+ movq_cfi r9, R9+8
23408+ movq_cfi r10, R10+8
23409+ movq_cfi r11, R11+8
23410+ movq_cfi rbx, RBX+8
23411+ movq_cfi rbp, RBP+8
23412+ movq_cfi r12, R12+8
23413+ movq_cfi r13, R13+8
23414+ movq_cfi r14, R14+8
23415+ movq_cfi r15, R15+8
23416+ movl $1,%ebx
23417+ movl $MSR_GS_BASE,%ecx
23418+ rdmsr
23419+ testl %edx,%edx
23420+ js 1f /* negative -> in kernel */
23421+ SWAPGS
23422+ xorl %ebx,%ebx
23423+1: pax_enter_kernel_nmi
23424+ pax_force_retaddr
23425+ ret
23426+ CFI_ENDPROC
23427+ENDPROC(save_paranoid_nmi)
23428 .popsection
23429
23430 /*
23431@@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23432
23433 RESTORE_REST
23434
23435- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23436+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23437 jz 1f
23438
23439 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23440@@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23441 jmp ret_from_sys_call # go to the SYSRET fastpath
23442
23443 1:
23444- subq $REST_SKIP, %rsp # leave space for volatiles
23445- CFI_ADJUST_CFA_OFFSET REST_SKIP
23446 movq %rbp, %rdi
23447 call *%rbx
23448 movl $0, RAX(%rsp)
23449 RESTORE_REST
23450 jmp int_ret_from_sys_call
23451 CFI_ENDPROC
23452-END(ret_from_fork)
23453+ENDPROC(ret_from_fork)
23454
23455 /*
23456 * System call entry. Up to 6 arguments in registers are supported.
23457@@ -593,7 +1059,7 @@ END(ret_from_fork)
23458 ENTRY(system_call)
23459 CFI_STARTPROC simple
23460 CFI_SIGNAL_FRAME
23461- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23462+ CFI_DEF_CFA rsp,0
23463 CFI_REGISTER rip,rcx
23464 /*CFI_REGISTER rflags,r11*/
23465 SWAPGS_UNSAFE_STACK
23466@@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23467
23468 movq %rsp,PER_CPU_VAR(old_rsp)
23469 movq PER_CPU_VAR(kernel_stack),%rsp
23470+ SAVE_ARGS 8*6,0
23471+ pax_enter_kernel_user
23472+
23473+#ifdef CONFIG_PAX_RANDKSTACK
23474+ pax_erase_kstack
23475+#endif
23476+
23477 /*
23478 * No need to follow this irqs off/on section - it's straight
23479 * and short:
23480 */
23481 ENABLE_INTERRUPTS(CLBR_NONE)
23482- SAVE_ARGS 8,0
23483 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23484 movq %rcx,RIP-ARGOFFSET(%rsp)
23485 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23486- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23487+ GET_THREAD_INFO(%rcx)
23488+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23489 jnz tracesys
23490 system_call_fastpath:
23491 #if __SYSCALL_MASK == ~0
23492@@ -639,10 +1112,13 @@ sysret_check:
23493 LOCKDEP_SYS_EXIT
23494 DISABLE_INTERRUPTS(CLBR_NONE)
23495 TRACE_IRQS_OFF
23496- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23497+ GET_THREAD_INFO(%rcx)
23498+ movl TI_flags(%rcx),%edx
23499 andl %edi,%edx
23500 jnz sysret_careful
23501 CFI_REMEMBER_STATE
23502+ pax_exit_kernel_user
23503+ pax_erase_kstack
23504 /*
23505 * sysretq will re-enable interrupts:
23506 */
23507@@ -701,6 +1177,9 @@ auditsys:
23508 movq %rax,%rsi /* 2nd arg: syscall number */
23509 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23510 call __audit_syscall_entry
23511+
23512+ pax_erase_kstack
23513+
23514 LOAD_ARGS 0 /* reload call-clobbered registers */
23515 jmp system_call_fastpath
23516
23517@@ -722,7 +1201,7 @@ sysret_audit:
23518 /* Do syscall tracing */
23519 tracesys:
23520 #ifdef CONFIG_AUDITSYSCALL
23521- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23522+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23523 jz auditsys
23524 #endif
23525 SAVE_REST
23526@@ -730,12 +1209,15 @@ tracesys:
23527 FIXUP_TOP_OF_STACK %rdi
23528 movq %rsp,%rdi
23529 call syscall_trace_enter
23530+
23531+ pax_erase_kstack
23532+
23533 /*
23534 * Reload arg registers from stack in case ptrace changed them.
23535 * We don't reload %rax because syscall_trace_enter() returned
23536 * the value it wants us to use in the table lookup.
23537 */
23538- LOAD_ARGS ARGOFFSET, 1
23539+ LOAD_ARGS 1
23540 RESTORE_REST
23541 #if __SYSCALL_MASK == ~0
23542 cmpq $__NR_syscall_max,%rax
23543@@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23544 andl %edi,%edx
23545 jnz int_careful
23546 andl $~TS_COMPAT,TI_status(%rcx)
23547- jmp retint_swapgs
23548+ pax_exit_kernel_user
23549+ pax_erase_kstack
23550+ jmp retint_swapgs_pax
23551
23552 /* Either reschedule or signal or syscall exit tracking needed. */
23553 /* First do a reschedule test. */
23554@@ -811,7 +1295,7 @@ int_restore_rest:
23555 TRACE_IRQS_OFF
23556 jmp int_with_check
23557 CFI_ENDPROC
23558-END(system_call)
23559+ENDPROC(system_call)
23560
23561 .macro FORK_LIKE func
23562 ENTRY(stub_\func)
23563@@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23564 DEFAULT_FRAME 0 8 /* offset 8: return address */
23565 call sys_\func
23566 RESTORE_TOP_OF_STACK %r11, 8
23567- ret $REST_SKIP /* pop extended registers */
23568+ pax_force_retaddr
23569+ ret
23570 CFI_ENDPROC
23571-END(stub_\func)
23572+ENDPROC(stub_\func)
23573 .endm
23574
23575 .macro FIXED_FRAME label,func
23576@@ -836,9 +1321,10 @@ ENTRY(\label)
23577 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23578 call \func
23579 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23580+ pax_force_retaddr
23581 ret
23582 CFI_ENDPROC
23583-END(\label)
23584+ENDPROC(\label)
23585 .endm
23586
23587 FORK_LIKE clone
23588@@ -846,19 +1332,6 @@ END(\label)
23589 FORK_LIKE vfork
23590 FIXED_FRAME stub_iopl, sys_iopl
23591
23592-ENTRY(ptregscall_common)
23593- DEFAULT_FRAME 1 8 /* offset 8: return address */
23594- RESTORE_TOP_OF_STACK %r11, 8
23595- movq_cfi_restore R15+8, r15
23596- movq_cfi_restore R14+8, r14
23597- movq_cfi_restore R13+8, r13
23598- movq_cfi_restore R12+8, r12
23599- movq_cfi_restore RBP+8, rbp
23600- movq_cfi_restore RBX+8, rbx
23601- ret $REST_SKIP /* pop extended registers */
23602- CFI_ENDPROC
23603-END(ptregscall_common)
23604-
23605 ENTRY(stub_execve)
23606 CFI_STARTPROC
23607 addq $8, %rsp
23608@@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23609 RESTORE_REST
23610 jmp int_ret_from_sys_call
23611 CFI_ENDPROC
23612-END(stub_execve)
23613+ENDPROC(stub_execve)
23614
23615 /*
23616 * sigreturn is special because it needs to restore all registers on return.
23617@@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23618 RESTORE_REST
23619 jmp int_ret_from_sys_call
23620 CFI_ENDPROC
23621-END(stub_rt_sigreturn)
23622+ENDPROC(stub_rt_sigreturn)
23623
23624 #ifdef CONFIG_X86_X32_ABI
23625 ENTRY(stub_x32_rt_sigreturn)
23626@@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23627 RESTORE_REST
23628 jmp int_ret_from_sys_call
23629 CFI_ENDPROC
23630-END(stub_x32_rt_sigreturn)
23631+ENDPROC(stub_x32_rt_sigreturn)
23632
23633 ENTRY(stub_x32_execve)
23634 CFI_STARTPROC
23635@@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23636 RESTORE_REST
23637 jmp int_ret_from_sys_call
23638 CFI_ENDPROC
23639-END(stub_x32_execve)
23640+ENDPROC(stub_x32_execve)
23641
23642 #endif
23643
23644@@ -952,7 +1425,7 @@ vector=vector+1
23645 2: jmp common_interrupt
23646 .endr
23647 CFI_ENDPROC
23648-END(irq_entries_start)
23649+ENDPROC(irq_entries_start)
23650
23651 .previous
23652 END(interrupt)
23653@@ -969,8 +1442,8 @@ END(interrupt)
23654 /* 0(%rsp): ~(interrupt number) */
23655 .macro interrupt func
23656 /* reserve pt_regs for scratch regs and rbp */
23657- subq $ORIG_RAX-RBP, %rsp
23658- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23659+ subq $ORIG_RAX, %rsp
23660+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23661 SAVE_ARGS_IRQ
23662 call \func
23663 .endm
23664@@ -997,14 +1470,14 @@ ret_from_intr:
23665
23666 /* Restore saved previous stack */
23667 popq %rsi
23668- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23669- leaq ARGOFFSET-RBP(%rsi), %rsp
23670+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23671+ movq %rsi, %rsp
23672 CFI_DEF_CFA_REGISTER rsp
23673- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23674+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23675
23676 exit_intr:
23677 GET_THREAD_INFO(%rcx)
23678- testl $3,CS-ARGOFFSET(%rsp)
23679+ testb $3,CS-ARGOFFSET(%rsp)
23680 je retint_kernel
23681
23682 /* Interrupt came from user space */
23683@@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23684 * The iretq could re-enable interrupts:
23685 */
23686 DISABLE_INTERRUPTS(CLBR_ANY)
23687+ pax_exit_kernel_user
23688+retint_swapgs_pax:
23689 TRACE_IRQS_IRETQ
23690 SWAPGS
23691 jmp restore_args
23692
23693 retint_restore_args: /* return to kernel space */
23694 DISABLE_INTERRUPTS(CLBR_ANY)
23695+ pax_exit_kernel
23696+ pax_force_retaddr (RIP-ARGOFFSET)
23697 /*
23698 * The iretq could re-enable interrupts:
23699 */
23700@@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23701 #endif
23702
23703 CFI_ENDPROC
23704-END(common_interrupt)
23705+ENDPROC(common_interrupt)
23706 /*
23707 * End of kprobes section
23708 */
23709@@ -1130,7 +1607,7 @@ ENTRY(\sym)
23710 interrupt \do_sym
23711 jmp ret_from_intr
23712 CFI_ENDPROC
23713-END(\sym)
23714+ENDPROC(\sym)
23715 .endm
23716
23717 #ifdef CONFIG_TRACING
23718@@ -1218,7 +1695,7 @@ ENTRY(\sym)
23719 call \do_sym
23720 jmp error_exit /* %ebx: no swapgs flag */
23721 CFI_ENDPROC
23722-END(\sym)
23723+ENDPROC(\sym)
23724 .endm
23725
23726 .macro paranoidzeroentry sym do_sym
23727@@ -1236,10 +1713,10 @@ ENTRY(\sym)
23728 call \do_sym
23729 jmp paranoid_exit /* %ebx: no swapgs flag */
23730 CFI_ENDPROC
23731-END(\sym)
23732+ENDPROC(\sym)
23733 .endm
23734
23735-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23736+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23737 .macro paranoidzeroentry_ist sym do_sym ist
23738 ENTRY(\sym)
23739 INTR_FRAME
23740@@ -1252,12 +1729,18 @@ ENTRY(\sym)
23741 TRACE_IRQS_OFF_DEBUG
23742 movq %rsp,%rdi /* pt_regs pointer */
23743 xorl %esi,%esi /* no error code */
23744+#ifdef CONFIG_SMP
23745+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23746+ lea init_tss(%r13), %r13
23747+#else
23748+ lea init_tss(%rip), %r13
23749+#endif
23750 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23751 call \do_sym
23752 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23753 jmp paranoid_exit /* %ebx: no swapgs flag */
23754 CFI_ENDPROC
23755-END(\sym)
23756+ENDPROC(\sym)
23757 .endm
23758
23759 .macro errorentry sym do_sym
23760@@ -1275,7 +1758,7 @@ ENTRY(\sym)
23761 call \do_sym
23762 jmp error_exit /* %ebx: no swapgs flag */
23763 CFI_ENDPROC
23764-END(\sym)
23765+ENDPROC(\sym)
23766 .endm
23767
23768 #ifdef CONFIG_TRACING
23769@@ -1306,7 +1789,7 @@ ENTRY(\sym)
23770 call \do_sym
23771 jmp paranoid_exit /* %ebx: no swapgs flag */
23772 CFI_ENDPROC
23773-END(\sym)
23774+ENDPROC(\sym)
23775 .endm
23776
23777 zeroentry divide_error do_divide_error
23778@@ -1336,9 +1819,10 @@ gs_change:
23779 2: mfence /* workaround */
23780 SWAPGS
23781 popfq_cfi
23782+ pax_force_retaddr
23783 ret
23784 CFI_ENDPROC
23785-END(native_load_gs_index)
23786+ENDPROC(native_load_gs_index)
23787
23788 _ASM_EXTABLE(gs_change,bad_gs)
23789 .section .fixup,"ax"
23790@@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23791 CFI_DEF_CFA_REGISTER rsp
23792 CFI_ADJUST_CFA_OFFSET -8
23793 decl PER_CPU_VAR(irq_count)
23794+ pax_force_retaddr
23795 ret
23796 CFI_ENDPROC
23797-END(do_softirq_own_stack)
23798+ENDPROC(do_softirq_own_stack)
23799
23800 #ifdef CONFIG_XEN
23801 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23802@@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23803 decl PER_CPU_VAR(irq_count)
23804 jmp error_exit
23805 CFI_ENDPROC
23806-END(xen_do_hypervisor_callback)
23807+ENDPROC(xen_do_hypervisor_callback)
23808
23809 /*
23810 * Hypervisor uses this for application faults while it executes.
23811@@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23812 SAVE_ALL
23813 jmp error_exit
23814 CFI_ENDPROC
23815-END(xen_failsafe_callback)
23816+ENDPROC(xen_failsafe_callback)
23817
23818 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23819 xen_hvm_callback_vector xen_evtchn_do_upcall
23820@@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23821 DEFAULT_FRAME
23822 DISABLE_INTERRUPTS(CLBR_NONE)
23823 TRACE_IRQS_OFF_DEBUG
23824- testl %ebx,%ebx /* swapgs needed? */
23825+ testl $1,%ebx /* swapgs needed? */
23826 jnz paranoid_restore
23827- testl $3,CS(%rsp)
23828+ testb $3,CS(%rsp)
23829 jnz paranoid_userspace
23830+#ifdef CONFIG_PAX_MEMORY_UDEREF
23831+ pax_exit_kernel
23832+ TRACE_IRQS_IRETQ 0
23833+ SWAPGS_UNSAFE_STACK
23834+ RESTORE_ALL 8
23835+ pax_force_retaddr_bts
23836+ jmp irq_return
23837+#endif
23838 paranoid_swapgs:
23839+#ifdef CONFIG_PAX_MEMORY_UDEREF
23840+ pax_exit_kernel_user
23841+#else
23842+ pax_exit_kernel
23843+#endif
23844 TRACE_IRQS_IRETQ 0
23845 SWAPGS_UNSAFE_STACK
23846 RESTORE_ALL 8
23847 jmp irq_return
23848 paranoid_restore:
23849+ pax_exit_kernel
23850 TRACE_IRQS_IRETQ_DEBUG 0
23851 RESTORE_ALL 8
23852+ pax_force_retaddr_bts
23853 jmp irq_return
23854 paranoid_userspace:
23855 GET_THREAD_INFO(%rcx)
23856@@ -1557,7 +2057,7 @@ paranoid_schedule:
23857 TRACE_IRQS_OFF
23858 jmp paranoid_userspace
23859 CFI_ENDPROC
23860-END(paranoid_exit)
23861+ENDPROC(paranoid_exit)
23862
23863 /*
23864 * Exception entry point. This expects an error code/orig_rax on the stack.
23865@@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23866 movq_cfi r14, R14+8
23867 movq_cfi r15, R15+8
23868 xorl %ebx,%ebx
23869- testl $3,CS+8(%rsp)
23870+ testb $3,CS+8(%rsp)
23871 je error_kernelspace
23872 error_swapgs:
23873 SWAPGS
23874 error_sti:
23875+#ifdef CONFIG_PAX_MEMORY_UDEREF
23876+ testb $3, CS+8(%rsp)
23877+ jnz 1f
23878+ pax_enter_kernel
23879+ jmp 2f
23880+1: pax_enter_kernel_user
23881+2:
23882+#else
23883+ pax_enter_kernel
23884+#endif
23885 TRACE_IRQS_OFF
23886+ pax_force_retaddr
23887 ret
23888
23889 /*
23890@@ -1616,7 +2127,7 @@ bstep_iret:
23891 movq %rcx,RIP+8(%rsp)
23892 jmp error_swapgs
23893 CFI_ENDPROC
23894-END(error_entry)
23895+ENDPROC(error_entry)
23896
23897
23898 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23899@@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23900 DISABLE_INTERRUPTS(CLBR_NONE)
23901 TRACE_IRQS_OFF
23902 GET_THREAD_INFO(%rcx)
23903- testl %eax,%eax
23904+ testl $1,%eax
23905 jne retint_kernel
23906 LOCKDEP_SYS_EXIT_IRQ
23907 movl TI_flags(%rcx),%edx
23908@@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23909 jnz retint_careful
23910 jmp retint_swapgs
23911 CFI_ENDPROC
23912-END(error_exit)
23913+ENDPROC(error_exit)
23914
23915 /*
23916 * Test if a given stack is an NMI stack or not.
23917@@ -1694,9 +2205,11 @@ ENTRY(nmi)
23918 * If %cs was not the kernel segment, then the NMI triggered in user
23919 * space, which means it is definitely not nested.
23920 */
23921+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23922+ je 1f
23923 cmpl $__KERNEL_CS, 16(%rsp)
23924 jne first_nmi
23925-
23926+1:
23927 /*
23928 * Check the special variable on the stack to see if NMIs are
23929 * executing.
23930@@ -1730,8 +2243,7 @@ nested_nmi:
23931
23932 1:
23933 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23934- leaq -1*8(%rsp), %rdx
23935- movq %rdx, %rsp
23936+ subq $8, %rsp
23937 CFI_ADJUST_CFA_OFFSET 1*8
23938 leaq -10*8(%rsp), %rdx
23939 pushq_cfi $__KERNEL_DS
23940@@ -1749,6 +2261,7 @@ nested_nmi_out:
23941 CFI_RESTORE rdx
23942
23943 /* No need to check faults here */
23944+# pax_force_retaddr_bts
23945 INTERRUPT_RETURN
23946
23947 CFI_RESTORE_STATE
23948@@ -1845,13 +2358,13 @@ end_repeat_nmi:
23949 subq $ORIG_RAX-R15, %rsp
23950 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23951 /*
23952- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23953+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23954 * as we should not be calling schedule in NMI context.
23955 * Even with normal interrupts enabled. An NMI should not be
23956 * setting NEED_RESCHED or anything that normal interrupts and
23957 * exceptions might do.
23958 */
23959- call save_paranoid
23960+ call save_paranoid_nmi
23961 DEFAULT_FRAME 0
23962
23963 /*
23964@@ -1861,9 +2374,9 @@ end_repeat_nmi:
23965 * NMI itself takes a page fault, the page fault that was preempted
23966 * will read the information from the NMI page fault and not the
23967 * origin fault. Save it off and restore it if it changes.
23968- * Use the r12 callee-saved register.
23969+ * Use the r13 callee-saved register.
23970 */
23971- movq %cr2, %r12
23972+ movq %cr2, %r13
23973
23974 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23975 movq %rsp,%rdi
23976@@ -1872,31 +2385,36 @@ end_repeat_nmi:
23977
23978 /* Did the NMI take a page fault? Restore cr2 if it did */
23979 movq %cr2, %rcx
23980- cmpq %rcx, %r12
23981+ cmpq %rcx, %r13
23982 je 1f
23983- movq %r12, %cr2
23984+ movq %r13, %cr2
23985 1:
23986
23987- testl %ebx,%ebx /* swapgs needed? */
23988+ testl $1,%ebx /* swapgs needed? */
23989 jnz nmi_restore
23990 nmi_swapgs:
23991 SWAPGS_UNSAFE_STACK
23992 nmi_restore:
23993+ pax_exit_kernel_nmi
23994 /* Pop the extra iret frame at once */
23995 RESTORE_ALL 6*8
23996+ testb $3, 8(%rsp)
23997+ jnz 1f
23998+ pax_force_retaddr_bts
23999+1:
24000
24001 /* Clear the NMI executing stack variable */
24002 movq $0, 5*8(%rsp)
24003 jmp irq_return
24004 CFI_ENDPROC
24005-END(nmi)
24006+ENDPROC(nmi)
24007
24008 ENTRY(ignore_sysret)
24009 CFI_STARTPROC
24010 mov $-ENOSYS,%eax
24011 sysret
24012 CFI_ENDPROC
24013-END(ignore_sysret)
24014+ENDPROC(ignore_sysret)
24015
24016 /*
24017 * End of kprobes section
24018diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24019index 52819e8..b6d1dbd 100644
24020--- a/arch/x86/kernel/ftrace.c
24021+++ b/arch/x86/kernel/ftrace.c
24022@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24023 {
24024 unsigned char replaced[MCOUNT_INSN_SIZE];
24025
24026+ ip = ktla_ktva(ip);
24027+
24028 /*
24029 * Note: Due to modules and __init, code can
24030 * disappear and change, we need to protect against faulting
24031@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24032 unsigned char old[MCOUNT_INSN_SIZE];
24033 int ret;
24034
24035- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24036+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24037
24038 ftrace_update_func = ip;
24039 /* Make sure the breakpoints see the ftrace_update_func update */
24040@@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
24041 * kernel identity mapping to modify code.
24042 */
24043 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24044- ip = (unsigned long)__va(__pa_symbol(ip));
24045+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24046
24047 if (probe_kernel_write((void *)ip, val, size))
24048 return -EPERM;
24049@@ -319,7 +321,7 @@ static int add_break(unsigned long ip, const char *old)
24050 unsigned char replaced[MCOUNT_INSN_SIZE];
24051 unsigned char brk = BREAKPOINT_INSTRUCTION;
24052
24053- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24054+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24055 return -EFAULT;
24056
24057 /* Make sure it is what we expect it to be */
24058diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24059index 068054f..c248bcd 100644
24060--- a/arch/x86/kernel/head64.c
24061+++ b/arch/x86/kernel/head64.c
24062@@ -67,12 +67,12 @@ again:
24063 pgd = *pgd_p;
24064
24065 /*
24066- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24067- * critical -- __PAGE_OFFSET would point us back into the dynamic
24068+ * The use of __early_va rather than __va here is critical:
24069+ * __va would point us back into the dynamic
24070 * range and we might end up looping forever...
24071 */
24072 if (pgd)
24073- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24074+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24075 else {
24076 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24077 reset_early_page_tables();
24078@@ -82,13 +82,13 @@ again:
24079 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24080 for (i = 0; i < PTRS_PER_PUD; i++)
24081 pud_p[i] = 0;
24082- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24083+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24084 }
24085 pud_p += pud_index(address);
24086 pud = *pud_p;
24087
24088 if (pud)
24089- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24090+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24091 else {
24092 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24093 reset_early_page_tables();
24094@@ -98,7 +98,7 @@ again:
24095 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24096 for (i = 0; i < PTRS_PER_PMD; i++)
24097 pmd_p[i] = 0;
24098- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24099+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24100 }
24101 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24102 pmd_p[pmd_index(address)] = pmd;
24103@@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24104 if (console_loglevel == 10)
24105 early_printk("Kernel alive\n");
24106
24107- clear_page(init_level4_pgt);
24108 /* set init_level4_pgt kernel high mapping*/
24109 init_level4_pgt[511] = early_level4_pgt[511];
24110
24111diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24112index f36bd42..56ee1534 100644
24113--- a/arch/x86/kernel/head_32.S
24114+++ b/arch/x86/kernel/head_32.S
24115@@ -26,6 +26,12 @@
24116 /* Physical address */
24117 #define pa(X) ((X) - __PAGE_OFFSET)
24118
24119+#ifdef CONFIG_PAX_KERNEXEC
24120+#define ta(X) (X)
24121+#else
24122+#define ta(X) ((X) - __PAGE_OFFSET)
24123+#endif
24124+
24125 /*
24126 * References to members of the new_cpu_data structure.
24127 */
24128@@ -55,11 +61,7 @@
24129 * and small than max_low_pfn, otherwise will waste some page table entries
24130 */
24131
24132-#if PTRS_PER_PMD > 1
24133-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24134-#else
24135-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24136-#endif
24137+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24138
24139 /* Number of possible pages in the lowmem region */
24140 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24141@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24142 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24143
24144 /*
24145+ * Real beginning of normal "text" segment
24146+ */
24147+ENTRY(stext)
24148+ENTRY(_stext)
24149+
24150+/*
24151 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24152 * %esi points to the real-mode code as a 32-bit pointer.
24153 * CS and DS must be 4 GB flat segments, but we don't depend on
24154@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24155 * can.
24156 */
24157 __HEAD
24158+
24159+#ifdef CONFIG_PAX_KERNEXEC
24160+ jmp startup_32
24161+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24162+.fill PAGE_SIZE-5,1,0xcc
24163+#endif
24164+
24165 ENTRY(startup_32)
24166 movl pa(stack_start),%ecx
24167
24168@@ -106,6 +121,59 @@ ENTRY(startup_32)
24169 2:
24170 leal -__PAGE_OFFSET(%ecx),%esp
24171
24172+#ifdef CONFIG_SMP
24173+ movl $pa(cpu_gdt_table),%edi
24174+ movl $__per_cpu_load,%eax
24175+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24176+ rorl $16,%eax
24177+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24178+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24179+ movl $__per_cpu_end - 1,%eax
24180+ subl $__per_cpu_start,%eax
24181+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24182+#endif
24183+
24184+#ifdef CONFIG_PAX_MEMORY_UDEREF
24185+ movl $NR_CPUS,%ecx
24186+ movl $pa(cpu_gdt_table),%edi
24187+1:
24188+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24189+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24190+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24191+ addl $PAGE_SIZE_asm,%edi
24192+ loop 1b
24193+#endif
24194+
24195+#ifdef CONFIG_PAX_KERNEXEC
24196+ movl $pa(boot_gdt),%edi
24197+ movl $__LOAD_PHYSICAL_ADDR,%eax
24198+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24199+ rorl $16,%eax
24200+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24201+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24202+ rorl $16,%eax
24203+
24204+ ljmp $(__BOOT_CS),$1f
24205+1:
24206+
24207+ movl $NR_CPUS,%ecx
24208+ movl $pa(cpu_gdt_table),%edi
24209+ addl $__PAGE_OFFSET,%eax
24210+1:
24211+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24212+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24213+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24214+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24215+ rorl $16,%eax
24216+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24217+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24218+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24219+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24220+ rorl $16,%eax
24221+ addl $PAGE_SIZE_asm,%edi
24222+ loop 1b
24223+#endif
24224+
24225 /*
24226 * Clear BSS first so that there are no surprises...
24227 */
24228@@ -201,8 +269,11 @@ ENTRY(startup_32)
24229 movl %eax, pa(max_pfn_mapped)
24230
24231 /* Do early initialization of the fixmap area */
24232- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24233- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24234+#ifdef CONFIG_COMPAT_VDSO
24235+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24236+#else
24237+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24238+#endif
24239 #else /* Not PAE */
24240
24241 page_pde_offset = (__PAGE_OFFSET >> 20);
24242@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24243 movl %eax, pa(max_pfn_mapped)
24244
24245 /* Do early initialization of the fixmap area */
24246- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24247- movl %eax,pa(initial_page_table+0xffc)
24248+#ifdef CONFIG_COMPAT_VDSO
24249+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24250+#else
24251+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24252+#endif
24253 #endif
24254
24255 #ifdef CONFIG_PARAVIRT
24256@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24257 cmpl $num_subarch_entries, %eax
24258 jae bad_subarch
24259
24260- movl pa(subarch_entries)(,%eax,4), %eax
24261- subl $__PAGE_OFFSET, %eax
24262- jmp *%eax
24263+ jmp *pa(subarch_entries)(,%eax,4)
24264
24265 bad_subarch:
24266 WEAK(lguest_entry)
24267@@ -261,10 +333,10 @@ WEAK(xen_entry)
24268 __INITDATA
24269
24270 subarch_entries:
24271- .long default_entry /* normal x86/PC */
24272- .long lguest_entry /* lguest hypervisor */
24273- .long xen_entry /* Xen hypervisor */
24274- .long default_entry /* Moorestown MID */
24275+ .long ta(default_entry) /* normal x86/PC */
24276+ .long ta(lguest_entry) /* lguest hypervisor */
24277+ .long ta(xen_entry) /* Xen hypervisor */
24278+ .long ta(default_entry) /* Moorestown MID */
24279 num_subarch_entries = (. - subarch_entries) / 4
24280 .previous
24281 #else
24282@@ -354,6 +426,7 @@ default_entry:
24283 movl pa(mmu_cr4_features),%eax
24284 movl %eax,%cr4
24285
24286+#ifdef CONFIG_X86_PAE
24287 testb $X86_CR4_PAE, %al # check if PAE is enabled
24288 jz enable_paging
24289
24290@@ -382,6 +455,9 @@ default_entry:
24291 /* Make changes effective */
24292 wrmsr
24293
24294+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24295+#endif
24296+
24297 enable_paging:
24298
24299 /*
24300@@ -449,14 +525,20 @@ is486:
24301 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24302 movl %eax,%ss # after changing gdt.
24303
24304- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24305+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24306 movl %eax,%ds
24307 movl %eax,%es
24308
24309 movl $(__KERNEL_PERCPU), %eax
24310 movl %eax,%fs # set this cpu's percpu
24311
24312+#ifdef CONFIG_CC_STACKPROTECTOR
24313 movl $(__KERNEL_STACK_CANARY),%eax
24314+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24315+ movl $(__USER_DS),%eax
24316+#else
24317+ xorl %eax,%eax
24318+#endif
24319 movl %eax,%gs
24320
24321 xorl %eax,%eax # Clear LDT
24322@@ -512,8 +594,11 @@ setup_once:
24323 * relocation. Manually set base address in stack canary
24324 * segment descriptor.
24325 */
24326- movl $gdt_page,%eax
24327+ movl $cpu_gdt_table,%eax
24328 movl $stack_canary,%ecx
24329+#ifdef CONFIG_SMP
24330+ addl $__per_cpu_load,%ecx
24331+#endif
24332 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24333 shrl $16, %ecx
24334 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24335@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24336 cmpl $2,(%esp) # X86_TRAP_NMI
24337 je is_nmi # Ignore NMI
24338
24339- cmpl $2,%ss:early_recursion_flag
24340+ cmpl $1,%ss:early_recursion_flag
24341 je hlt_loop
24342 incl %ss:early_recursion_flag
24343
24344@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24345 pushl (20+6*4)(%esp) /* trapno */
24346 pushl $fault_msg
24347 call printk
24348-#endif
24349 call dump_stack
24350+#endif
24351 hlt_loop:
24352 hlt
24353 jmp hlt_loop
24354@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24355 /* This is the default interrupt "handler" :-) */
24356 ALIGN
24357 ignore_int:
24358- cld
24359 #ifdef CONFIG_PRINTK
24360+ cmpl $2,%ss:early_recursion_flag
24361+ je hlt_loop
24362+ incl %ss:early_recursion_flag
24363+ cld
24364 pushl %eax
24365 pushl %ecx
24366 pushl %edx
24367@@ -617,9 +705,6 @@ ignore_int:
24368 movl $(__KERNEL_DS),%eax
24369 movl %eax,%ds
24370 movl %eax,%es
24371- cmpl $2,early_recursion_flag
24372- je hlt_loop
24373- incl early_recursion_flag
24374 pushl 16(%esp)
24375 pushl 24(%esp)
24376 pushl 32(%esp)
24377@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24378 /*
24379 * BSS section
24380 */
24381-__PAGE_ALIGNED_BSS
24382- .align PAGE_SIZE
24383 #ifdef CONFIG_X86_PAE
24384+.section .initial_pg_pmd,"a",@progbits
24385 initial_pg_pmd:
24386 .fill 1024*KPMDS,4,0
24387 #else
24388+.section .initial_page_table,"a",@progbits
24389 ENTRY(initial_page_table)
24390 .fill 1024,4,0
24391 #endif
24392+.section .initial_pg_fixmap,"a",@progbits
24393 initial_pg_fixmap:
24394 .fill 1024,4,0
24395+.section .empty_zero_page,"a",@progbits
24396 ENTRY(empty_zero_page)
24397 .fill 4096,1,0
24398+.section .swapper_pg_dir,"a",@progbits
24399 ENTRY(swapper_pg_dir)
24400+#ifdef CONFIG_X86_PAE
24401+ .fill 4,8,0
24402+#else
24403 .fill 1024,4,0
24404+#endif
24405
24406 /*
24407 * This starts the data section.
24408 */
24409 #ifdef CONFIG_X86_PAE
24410-__PAGE_ALIGNED_DATA
24411- /* Page-aligned for the benefit of paravirt? */
24412- .align PAGE_SIZE
24413+.section .initial_page_table,"a",@progbits
24414 ENTRY(initial_page_table)
24415 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24416 # if KPMDS == 3
24417@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24418 # error "Kernel PMDs should be 1, 2 or 3"
24419 # endif
24420 .align PAGE_SIZE /* needs to be page-sized too */
24421+
24422+#ifdef CONFIG_PAX_PER_CPU_PGD
24423+ENTRY(cpu_pgd)
24424+ .rept 2*NR_CPUS
24425+ .fill 4,8,0
24426+ .endr
24427+#endif
24428+
24429 #endif
24430
24431 .data
24432 .balign 4
24433 ENTRY(stack_start)
24434- .long init_thread_union+THREAD_SIZE
24435+ .long init_thread_union+THREAD_SIZE-8
24436
24437 __INITRODATA
24438 int_msg:
24439@@ -727,7 +825,7 @@ fault_msg:
24440 * segment size, and 32-bit linear address value:
24441 */
24442
24443- .data
24444+.section .rodata,"a",@progbits
24445 .globl boot_gdt_descr
24446 .globl idt_descr
24447
24448@@ -736,7 +834,7 @@ fault_msg:
24449 .word 0 # 32 bit align gdt_desc.address
24450 boot_gdt_descr:
24451 .word __BOOT_DS+7
24452- .long boot_gdt - __PAGE_OFFSET
24453+ .long pa(boot_gdt)
24454
24455 .word 0 # 32-bit align idt_desc.address
24456 idt_descr:
24457@@ -747,7 +845,7 @@ idt_descr:
24458 .word 0 # 32 bit align gdt_desc.address
24459 ENTRY(early_gdt_descr)
24460 .word GDT_ENTRIES*8-1
24461- .long gdt_page /* Overwritten for secondary CPUs */
24462+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24463
24464 /*
24465 * The boot_gdt must mirror the equivalent in setup.S and is
24466@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24467 .align L1_CACHE_BYTES
24468 ENTRY(boot_gdt)
24469 .fill GDT_ENTRY_BOOT_CS,8,0
24470- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24471- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24472+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24473+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24474+
24475+ .align PAGE_SIZE_asm
24476+ENTRY(cpu_gdt_table)
24477+ .rept NR_CPUS
24478+ .quad 0x0000000000000000 /* NULL descriptor */
24479+ .quad 0x0000000000000000 /* 0x0b reserved */
24480+ .quad 0x0000000000000000 /* 0x13 reserved */
24481+ .quad 0x0000000000000000 /* 0x1b reserved */
24482+
24483+#ifdef CONFIG_PAX_KERNEXEC
24484+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24485+#else
24486+ .quad 0x0000000000000000 /* 0x20 unused */
24487+#endif
24488+
24489+ .quad 0x0000000000000000 /* 0x28 unused */
24490+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24491+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24492+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24493+ .quad 0x0000000000000000 /* 0x4b reserved */
24494+ .quad 0x0000000000000000 /* 0x53 reserved */
24495+ .quad 0x0000000000000000 /* 0x5b reserved */
24496+
24497+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24498+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24499+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24500+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24501+
24502+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24503+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24504+
24505+ /*
24506+ * Segments used for calling PnP BIOS have byte granularity.
24507+ * The code segments and data segments have fixed 64k limits,
24508+ * the transfer segment sizes are set at run time.
24509+ */
24510+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24511+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24512+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24513+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24514+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24515+
24516+ /*
24517+ * The APM segments have byte granularity and their bases
24518+ * are set at run time. All have 64k limits.
24519+ */
24520+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24521+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24522+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24523+
24524+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24525+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24526+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24527+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24528+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24529+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24530+
24531+ /* Be sure this is zeroed to avoid false validations in Xen */
24532+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24533+ .endr
24534diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24535index a468c0a..c7dec74 100644
24536--- a/arch/x86/kernel/head_64.S
24537+++ b/arch/x86/kernel/head_64.S
24538@@ -20,6 +20,8 @@
24539 #include <asm/processor-flags.h>
24540 #include <asm/percpu.h>
24541 #include <asm/nops.h>
24542+#include <asm/cpufeature.h>
24543+#include <asm/alternative-asm.h>
24544
24545 #ifdef CONFIG_PARAVIRT
24546 #include <asm/asm-offsets.h>
24547@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24548 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24549 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24550 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24551+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24552+L3_VMALLOC_START = pud_index(VMALLOC_START)
24553+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24554+L3_VMALLOC_END = pud_index(VMALLOC_END)
24555+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24556+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24557
24558 .text
24559 __HEAD
24560@@ -89,11 +97,24 @@ startup_64:
24561 * Fixup the physical addresses in the page table
24562 */
24563 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24564+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24565+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24566+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24567+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24568+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24569
24570- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24571- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24572+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24573+#ifndef CONFIG_XEN
24574+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24575+#endif
24576+
24577+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24578+
24579+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24580+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24581
24582 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24583+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24584
24585 /*
24586 * Set up the identity mapping for the switchover. These
24587@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24588 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24589 1:
24590
24591- /* Enable PAE mode and PGE */
24592- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24593+ /* Enable PAE mode and PSE/PGE */
24594+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24595 movq %rcx, %cr4
24596
24597 /* Setup early boot stage 4 level pagetables. */
24598@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24599 movl $MSR_EFER, %ecx
24600 rdmsr
24601 btsl $_EFER_SCE, %eax /* Enable System Call */
24602- btl $20,%edi /* No Execute supported? */
24603+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24604 jnc 1f
24605 btsl $_EFER_NX, %eax
24606 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24607+#ifndef CONFIG_EFI
24608+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24609+#endif
24610+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24611+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24612+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24613+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24614+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24615+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24616 1: wrmsr /* Make changes effective */
24617
24618 /* Setup cr0 */
24619@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24620 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24621 * address given in m16:64.
24622 */
24623+ pax_set_fptr_mask
24624 movq initial_code(%rip),%rax
24625 pushq $0 # fake return address to stop unwinder
24626 pushq $__KERNEL_CS # set correct cs
24627@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24628 .quad INIT_PER_CPU_VAR(irq_stack_union)
24629
24630 GLOBAL(stack_start)
24631- .quad init_thread_union+THREAD_SIZE-8
24632+ .quad init_thread_union+THREAD_SIZE-16
24633 .word 0
24634 __FINITDATA
24635
24636@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24637 call dump_stack
24638 #ifdef CONFIG_KALLSYMS
24639 leaq early_idt_ripmsg(%rip),%rdi
24640- movq 40(%rsp),%rsi # %rip again
24641+ movq 88(%rsp),%rsi # %rip again
24642 call __print_symbol
24643 #endif
24644 #endif /* EARLY_PRINTK */
24645@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24646 early_recursion_flag:
24647 .long 0
24648
24649+ .section .rodata,"a",@progbits
24650 #ifdef CONFIG_EARLY_PRINTK
24651 early_idt_msg:
24652 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24653@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24654 NEXT_PAGE(early_dynamic_pgts)
24655 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24656
24657- .data
24658+ .section .rodata,"a",@progbits
24659
24660-#ifndef CONFIG_XEN
24661 NEXT_PAGE(init_level4_pgt)
24662- .fill 512,8,0
24663-#else
24664-NEXT_PAGE(init_level4_pgt)
24665- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24666 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24667 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24668+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24669+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24670+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24671+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24672+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24673+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24674 .org init_level4_pgt + L4_START_KERNEL*8, 0
24675 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24676 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24677
24678+#ifdef CONFIG_PAX_PER_CPU_PGD
24679+NEXT_PAGE(cpu_pgd)
24680+ .rept 2*NR_CPUS
24681+ .fill 512,8,0
24682+ .endr
24683+#endif
24684+
24685 NEXT_PAGE(level3_ident_pgt)
24686 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24687+#ifdef CONFIG_XEN
24688 .fill 511, 8, 0
24689+#else
24690+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24691+ .fill 510,8,0
24692+#endif
24693+
24694+NEXT_PAGE(level3_vmalloc_start_pgt)
24695+ .fill 512,8,0
24696+
24697+NEXT_PAGE(level3_vmalloc_end_pgt)
24698+ .fill 512,8,0
24699+
24700+NEXT_PAGE(level3_vmemmap_pgt)
24701+ .fill L3_VMEMMAP_START,8,0
24702+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24703+
24704 NEXT_PAGE(level2_ident_pgt)
24705- /* Since I easily can, map the first 1G.
24706+ /* Since I easily can, map the first 2G.
24707 * Don't set NX because code runs from these pages.
24708 */
24709- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24710-#endif
24711+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24712
24713 NEXT_PAGE(level3_kernel_pgt)
24714 .fill L3_START_KERNEL,8,0
24715@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24716 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24717 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24718
24719+NEXT_PAGE(level2_vmemmap_pgt)
24720+ .fill 512,8,0
24721+
24722 NEXT_PAGE(level2_kernel_pgt)
24723 /*
24724 * 512 MB kernel mapping. We spend a full page on this pagetable
24725@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24726 NEXT_PAGE(level2_fixmap_pgt)
24727 .fill 506,8,0
24728 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24729- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24730- .fill 5,8,0
24731+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24732+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24733+ .fill 4,8,0
24734
24735 NEXT_PAGE(level1_fixmap_pgt)
24736 .fill 512,8,0
24737
24738+NEXT_PAGE(level1_vsyscall_pgt)
24739+ .fill 512,8,0
24740+
24741 #undef PMDS
24742
24743- .data
24744+ .align PAGE_SIZE
24745+ENTRY(cpu_gdt_table)
24746+ .rept NR_CPUS
24747+ .quad 0x0000000000000000 /* NULL descriptor */
24748+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24749+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24750+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
24751+ .quad 0x00cffb000000ffff /* __USER32_CS */
24752+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24753+ .quad 0x00affb000000ffff /* __USER_CS */
24754+
24755+#ifdef CONFIG_PAX_KERNEXEC
24756+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24757+#else
24758+ .quad 0x0 /* unused */
24759+#endif
24760+
24761+ .quad 0,0 /* TSS */
24762+ .quad 0,0 /* LDT */
24763+ .quad 0,0,0 /* three TLS descriptors */
24764+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
24765+ /* asm/segment.h:GDT_ENTRIES must match this */
24766+
24767+#ifdef CONFIG_PAX_MEMORY_UDEREF
24768+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24769+#else
24770+ .quad 0x0 /* unused */
24771+#endif
24772+
24773+ /* zero the remaining page */
24774+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24775+ .endr
24776+
24777 .align 16
24778 .globl early_gdt_descr
24779 early_gdt_descr:
24780 .word GDT_ENTRIES*8-1
24781 early_gdt_descr_base:
24782- .quad INIT_PER_CPU_VAR(gdt_page)
24783+ .quad cpu_gdt_table
24784
24785 ENTRY(phys_base)
24786 /* This must match the first entry in level2_kernel_pgt */
24787 .quad 0x0000000000000000
24788
24789 #include "../../x86/xen/xen-head.S"
24790-
24791- __PAGE_ALIGNED_BSS
24792+
24793+ .section .rodata,"a",@progbits
24794 NEXT_PAGE(empty_zero_page)
24795 .skip PAGE_SIZE
24796diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24797index 05fd74f..c3548b1 100644
24798--- a/arch/x86/kernel/i386_ksyms_32.c
24799+++ b/arch/x86/kernel/i386_ksyms_32.c
24800@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24801 EXPORT_SYMBOL(cmpxchg8b_emu);
24802 #endif
24803
24804+EXPORT_SYMBOL_GPL(cpu_gdt_table);
24805+
24806 /* Networking helper routines. */
24807 EXPORT_SYMBOL(csum_partial_copy_generic);
24808+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24809+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24810
24811 EXPORT_SYMBOL(__get_user_1);
24812 EXPORT_SYMBOL(__get_user_2);
24813@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24814 EXPORT_SYMBOL(___preempt_schedule_context);
24815 #endif
24816 #endif
24817+
24818+#ifdef CONFIG_PAX_KERNEXEC
24819+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24820+#endif
24821+
24822+#ifdef CONFIG_PAX_PER_CPU_PGD
24823+EXPORT_SYMBOL(cpu_pgd);
24824+#endif
24825diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24826index d5dd808..b6432cf 100644
24827--- a/arch/x86/kernel/i387.c
24828+++ b/arch/x86/kernel/i387.c
24829@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24830 static inline bool interrupted_user_mode(void)
24831 {
24832 struct pt_regs *regs = get_irq_regs();
24833- return regs && user_mode_vm(regs);
24834+ return regs && user_mode(regs);
24835 }
24836
24837 /*
24838diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24839index 2e977b5..5f2c273 100644
24840--- a/arch/x86/kernel/i8259.c
24841+++ b/arch/x86/kernel/i8259.c
24842@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24843 static void make_8259A_irq(unsigned int irq)
24844 {
24845 disable_irq_nosync(irq);
24846- io_apic_irqs &= ~(1<<irq);
24847+ io_apic_irqs &= ~(1UL<<irq);
24848 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24849 i8259A_chip.name);
24850 enable_irq(irq);
24851@@ -209,7 +209,7 @@ spurious_8259A_irq:
24852 "spurious 8259A interrupt: IRQ%d.\n", irq);
24853 spurious_irq_mask |= irqmask;
24854 }
24855- atomic_inc(&irq_err_count);
24856+ atomic_inc_unchecked(&irq_err_count);
24857 /*
24858 * Theoretically we do not have to handle this IRQ,
24859 * but in Linux this does not cause problems and is
24860@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24861 /* (slave's support for AEOI in flat mode is to be investigated) */
24862 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24863
24864+ pax_open_kernel();
24865 if (auto_eoi)
24866 /*
24867 * In AEOI mode we just have to mask the interrupt
24868 * when acking.
24869 */
24870- i8259A_chip.irq_mask_ack = disable_8259A_irq;
24871+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24872 else
24873- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24874+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24875+ pax_close_kernel();
24876
24877 udelay(100); /* wait for 8259A to initialize */
24878
24879diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24880index a979b5b..1d6db75 100644
24881--- a/arch/x86/kernel/io_delay.c
24882+++ b/arch/x86/kernel/io_delay.c
24883@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24884 * Quirk table for systems that misbehave (lock up, etc.) if port
24885 * 0x80 is used:
24886 */
24887-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24888+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24889 {
24890 .callback = dmi_io_delay_0xed_port,
24891 .ident = "Compaq Presario V6000",
24892diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24893index 4ddaf66..49d5c18 100644
24894--- a/arch/x86/kernel/ioport.c
24895+++ b/arch/x86/kernel/ioport.c
24896@@ -6,6 +6,7 @@
24897 #include <linux/sched.h>
24898 #include <linux/kernel.h>
24899 #include <linux/capability.h>
24900+#include <linux/security.h>
24901 #include <linux/errno.h>
24902 #include <linux/types.h>
24903 #include <linux/ioport.h>
24904@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24905 return -EINVAL;
24906 if (turn_on && !capable(CAP_SYS_RAWIO))
24907 return -EPERM;
24908+#ifdef CONFIG_GRKERNSEC_IO
24909+ if (turn_on && grsec_disable_privio) {
24910+ gr_handle_ioperm();
24911+ return -ENODEV;
24912+ }
24913+#endif
24914
24915 /*
24916 * If it's the first ioperm() call in this thread's lifetime, set the
24917@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24918 * because the ->io_bitmap_max value must match the bitmap
24919 * contents:
24920 */
24921- tss = &per_cpu(init_tss, get_cpu());
24922+ tss = init_tss + get_cpu();
24923
24924 if (turn_on)
24925 bitmap_clear(t->io_bitmap_ptr, from, num);
24926@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24927 if (level > old) {
24928 if (!capable(CAP_SYS_RAWIO))
24929 return -EPERM;
24930+#ifdef CONFIG_GRKERNSEC_IO
24931+ if (grsec_disable_privio) {
24932+ gr_handle_iopl();
24933+ return -ENODEV;
24934+ }
24935+#endif
24936 }
24937 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24938 t->iopl = level << 12;
24939diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24940index 11ccfb0..ec1e46f 100644
24941--- a/arch/x86/kernel/irq.c
24942+++ b/arch/x86/kernel/irq.c
24943@@ -22,7 +22,7 @@
24944 #define CREATE_TRACE_POINTS
24945 #include <asm/trace/irq_vectors.h>
24946
24947-atomic_t irq_err_count;
24948+atomic_unchecked_t irq_err_count;
24949
24950 /* Function pointer for generic interrupt vector handling */
24951 void (*x86_platform_ipi_callback)(void) = NULL;
24952@@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24953 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
24954 seq_printf(p, " Hypervisor callback interrupts\n");
24955 #endif
24956- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24957+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24958 #if defined(CONFIG_X86_IO_APIC)
24959- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24960+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24961 #endif
24962 return 0;
24963 }
24964@@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24965
24966 u64 arch_irq_stat(void)
24967 {
24968- u64 sum = atomic_read(&irq_err_count);
24969+ u64 sum = atomic_read_unchecked(&irq_err_count);
24970 return sum;
24971 }
24972
24973diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24974index 63ce838..2ea3e06 100644
24975--- a/arch/x86/kernel/irq_32.c
24976+++ b/arch/x86/kernel/irq_32.c
24977@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
24978
24979 #ifdef CONFIG_DEBUG_STACKOVERFLOW
24980
24981+extern void gr_handle_kernel_exploit(void);
24982+
24983 int sysctl_panic_on_stackoverflow __read_mostly;
24984
24985 /* Debugging check for stack overflow: is there less than 1KB free? */
24986@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
24987 __asm__ __volatile__("andl %%esp,%0" :
24988 "=r" (sp) : "0" (THREAD_SIZE - 1));
24989
24990- return sp < (sizeof(struct thread_info) + STACK_WARN);
24991+ return sp < STACK_WARN;
24992 }
24993
24994 static void print_stack_overflow(void)
24995 {
24996 printk(KERN_WARNING "low stack detected by irq handler\n");
24997 dump_stack();
24998+ gr_handle_kernel_exploit();
24999 if (sysctl_panic_on_stackoverflow)
25000 panic("low stack detected by irq handler - check messages\n");
25001 }
25002@@ -84,10 +87,9 @@ static inline void *current_stack(void)
25003 static inline int
25004 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25005 {
25006- struct irq_stack *curstk, *irqstk;
25007+ struct irq_stack *irqstk;
25008 u32 *isp, *prev_esp, arg1, arg2;
25009
25010- curstk = (struct irq_stack *) current_stack();
25011 irqstk = __this_cpu_read(hardirq_stack);
25012
25013 /*
25014@@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25015 * handler) we can't do that and just have to keep using the
25016 * current stack (which is the irq stack already after all)
25017 */
25018- if (unlikely(curstk == irqstk))
25019+ if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25020 return 0;
25021
25022- isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25023+ isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25024
25025 /* Save the next esp at the bottom of the stack */
25026 prev_esp = (u32 *)irqstk;
25027 *prev_esp = current_stack_pointer;
25028
25029+#ifdef CONFIG_PAX_MEMORY_UDEREF
25030+ __set_fs(MAKE_MM_SEG(0));
25031+#endif
25032+
25033 if (unlikely(overflow))
25034 call_on_stack(print_stack_overflow, isp);
25035
25036@@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25037 : "0" (irq), "1" (desc), "2" (isp),
25038 "D" (desc->handle_irq)
25039 : "memory", "cc", "ecx");
25040+
25041+#ifdef CONFIG_PAX_MEMORY_UDEREF
25042+ __set_fs(current_thread_info()->addr_limit);
25043+#endif
25044+
25045 return 1;
25046 }
25047
25048@@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25049 */
25050 void irq_ctx_init(int cpu)
25051 {
25052- struct irq_stack *irqstk;
25053-
25054 if (per_cpu(hardirq_stack, cpu))
25055 return;
25056
25057- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25058- THREADINFO_GFP,
25059- THREAD_SIZE_ORDER));
25060- per_cpu(hardirq_stack, cpu) = irqstk;
25061-
25062- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25063- THREADINFO_GFP,
25064- THREAD_SIZE_ORDER));
25065- per_cpu(softirq_stack, cpu) = irqstk;
25066-
25067- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25068- cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25069+ per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25070+ per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25071 }
25072
25073 void do_softirq_own_stack(void)
25074 {
25075- struct thread_info *curstk;
25076 struct irq_stack *irqstk;
25077 u32 *isp, *prev_esp;
25078
25079- curstk = current_stack();
25080 irqstk = __this_cpu_read(softirq_stack);
25081
25082 /* build the stack frame on the softirq stack */
25083@@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25084 prev_esp = (u32 *)irqstk;
25085 *prev_esp = current_stack_pointer;
25086
25087+#ifdef CONFIG_PAX_MEMORY_UDEREF
25088+ __set_fs(MAKE_MM_SEG(0));
25089+#endif
25090+
25091 call_on_stack(__do_softirq, isp);
25092+
25093+#ifdef CONFIG_PAX_MEMORY_UDEREF
25094+ __set_fs(current_thread_info()->addr_limit);
25095+#endif
25096+
25097 }
25098
25099 bool handle_irq(unsigned irq, struct pt_regs *regs)
25100@@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25101 if (unlikely(!desc))
25102 return false;
25103
25104- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25105+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25106 if (unlikely(overflow))
25107 print_stack_overflow();
25108 desc->handle_irq(irq, desc);
25109diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25110index 4d1c746..55a22d6 100644
25111--- a/arch/x86/kernel/irq_64.c
25112+++ b/arch/x86/kernel/irq_64.c
25113@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25114 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25115 EXPORT_PER_CPU_SYMBOL(irq_regs);
25116
25117+extern void gr_handle_kernel_exploit(void);
25118+
25119 int sysctl_panic_on_stackoverflow;
25120
25121 /*
25122@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25123 u64 estack_top, estack_bottom;
25124 u64 curbase = (u64)task_stack_page(current);
25125
25126- if (user_mode_vm(regs))
25127+ if (user_mode(regs))
25128 return;
25129
25130 if (regs->sp >= curbase + sizeof(struct thread_info) +
25131@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25132 irq_stack_top, irq_stack_bottom,
25133 estack_top, estack_bottom);
25134
25135+ gr_handle_kernel_exploit();
25136+
25137 if (sysctl_panic_on_stackoverflow)
25138 panic("low stack detected by irq handler - check messages\n");
25139 #endif
25140diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25141index 26d5a55..a01160a 100644
25142--- a/arch/x86/kernel/jump_label.c
25143+++ b/arch/x86/kernel/jump_label.c
25144@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25145 * Jump label is enabled for the first time.
25146 * So we expect a default_nop...
25147 */
25148- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25149+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25150 != 0))
25151 bug_at((void *)entry->code, __LINE__);
25152 } else {
25153@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25154 * ...otherwise expect an ideal_nop. Otherwise
25155 * something went horribly wrong.
25156 */
25157- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25158+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25159 != 0))
25160 bug_at((void *)entry->code, __LINE__);
25161 }
25162@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25163 * are converting the default nop to the ideal nop.
25164 */
25165 if (init) {
25166- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25167+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25168 bug_at((void *)entry->code, __LINE__);
25169 } else {
25170 code.jump = 0xe9;
25171 code.offset = entry->target -
25172 (entry->code + JUMP_LABEL_NOP_SIZE);
25173- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25174+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25175 bug_at((void *)entry->code, __LINE__);
25176 }
25177 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25178diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25179index 7ec1d5f..5a7d130 100644
25180--- a/arch/x86/kernel/kgdb.c
25181+++ b/arch/x86/kernel/kgdb.c
25182@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25183 #ifdef CONFIG_X86_32
25184 switch (regno) {
25185 case GDB_SS:
25186- if (!user_mode_vm(regs))
25187+ if (!user_mode(regs))
25188 *(unsigned long *)mem = __KERNEL_DS;
25189 break;
25190 case GDB_SP:
25191- if (!user_mode_vm(regs))
25192+ if (!user_mode(regs))
25193 *(unsigned long *)mem = kernel_stack_pointer(regs);
25194 break;
25195 case GDB_GS:
25196@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25197 bp->attr.bp_addr = breakinfo[breakno].addr;
25198 bp->attr.bp_len = breakinfo[breakno].len;
25199 bp->attr.bp_type = breakinfo[breakno].type;
25200- info->address = breakinfo[breakno].addr;
25201+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25202+ info->address = ktla_ktva(breakinfo[breakno].addr);
25203+ else
25204+ info->address = breakinfo[breakno].addr;
25205 info->len = breakinfo[breakno].len;
25206 info->type = breakinfo[breakno].type;
25207 val = arch_install_hw_breakpoint(bp);
25208@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25209 case 'k':
25210 /* clear the trace bit */
25211 linux_regs->flags &= ~X86_EFLAGS_TF;
25212- atomic_set(&kgdb_cpu_doing_single_step, -1);
25213+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25214
25215 /* set the trace bit if we're stepping */
25216 if (remcomInBuffer[0] == 's') {
25217 linux_regs->flags |= X86_EFLAGS_TF;
25218- atomic_set(&kgdb_cpu_doing_single_step,
25219+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25220 raw_smp_processor_id());
25221 }
25222
25223@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25224
25225 switch (cmd) {
25226 case DIE_DEBUG:
25227- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25228+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25229 if (user_mode(regs))
25230 return single_step_cont(regs, args);
25231 break;
25232@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25233 #endif /* CONFIG_DEBUG_RODATA */
25234
25235 bpt->type = BP_BREAKPOINT;
25236- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25237+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25238 BREAK_INSTR_SIZE);
25239 if (err)
25240 return err;
25241- err = probe_kernel_write((char *)bpt->bpt_addr,
25242+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25243 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25244 #ifdef CONFIG_DEBUG_RODATA
25245 if (!err)
25246@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25247 return -EBUSY;
25248 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25249 BREAK_INSTR_SIZE);
25250- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25251+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25252 if (err)
25253 return err;
25254 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25255@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25256 if (mutex_is_locked(&text_mutex))
25257 goto knl_write;
25258 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25259- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25260+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25261 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25262 goto knl_write;
25263 return err;
25264 knl_write:
25265 #endif /* CONFIG_DEBUG_RODATA */
25266- return probe_kernel_write((char *)bpt->bpt_addr,
25267+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25268 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25269 }
25270
25271diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25272index 61b17dc..784bfe9 100644
25273--- a/arch/x86/kernel/kprobes/core.c
25274+++ b/arch/x86/kernel/kprobes/core.c
25275@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25276 s32 raddr;
25277 } __packed *insn;
25278
25279- insn = (struct __arch_relative_insn *)from;
25280+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25281+
25282+ pax_open_kernel();
25283 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25284 insn->op = op;
25285+ pax_close_kernel();
25286 }
25287
25288 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25289@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25290 kprobe_opcode_t opcode;
25291 kprobe_opcode_t *orig_opcodes = opcodes;
25292
25293- if (search_exception_tables((unsigned long)opcodes))
25294+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25295 return 0; /* Page fault may occur on this address. */
25296
25297 retry:
25298@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25299 * for the first byte, we can recover the original instruction
25300 * from it and kp->opcode.
25301 */
25302- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25303+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25304 buf[0] = kp->opcode;
25305- return (unsigned long)buf;
25306+ return ktva_ktla((unsigned long)buf);
25307 }
25308
25309 /*
25310@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25311 /* Another subsystem puts a breakpoint, failed to recover */
25312 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25313 return 0;
25314+ pax_open_kernel();
25315 memcpy(dest, insn.kaddr, insn.length);
25316+ pax_close_kernel();
25317
25318 #ifdef CONFIG_X86_64
25319 if (insn_rip_relative(&insn)) {
25320@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25321 return 0;
25322 }
25323 disp = (u8 *) dest + insn_offset_displacement(&insn);
25324+ pax_open_kernel();
25325 *(s32 *) disp = (s32) newdisp;
25326+ pax_close_kernel();
25327 }
25328 #endif
25329 return insn.length;
25330@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25331 * nor set current_kprobe, because it doesn't use single
25332 * stepping.
25333 */
25334- regs->ip = (unsigned long)p->ainsn.insn;
25335+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25336 preempt_enable_no_resched();
25337 return;
25338 }
25339@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25340 regs->flags &= ~X86_EFLAGS_IF;
25341 /* single step inline if the instruction is an int3 */
25342 if (p->opcode == BREAKPOINT_INSTRUCTION)
25343- regs->ip = (unsigned long)p->addr;
25344+ regs->ip = ktla_ktva((unsigned long)p->addr);
25345 else
25346- regs->ip = (unsigned long)p->ainsn.insn;
25347+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25348 }
25349
25350 /*
25351@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25352 setup_singlestep(p, regs, kcb, 0);
25353 return 1;
25354 }
25355- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25356+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25357 /*
25358 * The breakpoint instruction was removed right
25359 * after we hit it. Another cpu has removed
25360@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25361 " movq %rax, 152(%rsp)\n"
25362 RESTORE_REGS_STRING
25363 " popfq\n"
25364+#ifdef KERNEXEC_PLUGIN
25365+ " btsq $63,(%rsp)\n"
25366+#endif
25367 #else
25368 " pushf\n"
25369 SAVE_REGS_STRING
25370@@ -779,7 +789,7 @@ static void __kprobes
25371 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25372 {
25373 unsigned long *tos = stack_addr(regs);
25374- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25375+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25376 unsigned long orig_ip = (unsigned long)p->addr;
25377 kprobe_opcode_t *insn = p->ainsn.insn;
25378
25379@@ -959,7 +969,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25380 struct die_args *args = data;
25381 int ret = NOTIFY_DONE;
25382
25383- if (args->regs && user_mode_vm(args->regs))
25384+ if (args->regs && user_mode(args->regs))
25385 return ret;
25386
25387 switch (val) {
25388diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25389index 898160b..758cde8 100644
25390--- a/arch/x86/kernel/kprobes/opt.c
25391+++ b/arch/x86/kernel/kprobes/opt.c
25392@@ -79,6 +79,7 @@ found:
25393 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25394 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25395 {
25396+ pax_open_kernel();
25397 #ifdef CONFIG_X86_64
25398 *addr++ = 0x48;
25399 *addr++ = 0xbf;
25400@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25401 *addr++ = 0xb8;
25402 #endif
25403 *(unsigned long *)addr = val;
25404+ pax_close_kernel();
25405 }
25406
25407 asm (
25408@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25409 * Verify if the address gap is in 2GB range, because this uses
25410 * a relative jump.
25411 */
25412- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25413+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25414 if (abs(rel) > 0x7fffffff)
25415 return -ERANGE;
25416
25417@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25418 op->optinsn.size = ret;
25419
25420 /* Copy arch-dep-instance from template */
25421- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25422+ pax_open_kernel();
25423+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25424+ pax_close_kernel();
25425
25426 /* Set probe information */
25427 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25428
25429 /* Set probe function call */
25430- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25431+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25432
25433 /* Set returning jmp instruction at the tail of out-of-line buffer */
25434- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25435+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25436 (u8 *)op->kp.addr + op->optinsn.size);
25437
25438 flush_icache_range((unsigned long) buf,
25439@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25440 WARN_ON(kprobe_disabled(&op->kp));
25441
25442 /* Backup instructions which will be replaced by jump address */
25443- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25444+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25445 RELATIVE_ADDR_SIZE);
25446
25447 insn_buf[0] = RELATIVEJUMP_OPCODE;
25448@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25449 /* This kprobe is really able to run optimized path. */
25450 op = container_of(p, struct optimized_kprobe, kp);
25451 /* Detour through copied instructions */
25452- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25453+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25454 if (!reenter)
25455 reset_current_kprobe();
25456 preempt_enable_no_resched();
25457diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25458index c2bedae..25e7ab6 100644
25459--- a/arch/x86/kernel/ksysfs.c
25460+++ b/arch/x86/kernel/ksysfs.c
25461@@ -184,7 +184,7 @@ out:
25462
25463 static struct kobj_attribute type_attr = __ATTR_RO(type);
25464
25465-static struct bin_attribute data_attr = {
25466+static bin_attribute_no_const data_attr __read_only = {
25467 .attr = {
25468 .name = "data",
25469 .mode = S_IRUGO,
25470diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25471index dcbbaa1..81ae763 100644
25472--- a/arch/x86/kernel/ldt.c
25473+++ b/arch/x86/kernel/ldt.c
25474@@ -68,13 +68,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25475 if (reload) {
25476 #ifdef CONFIG_SMP
25477 preempt_disable();
25478- load_LDT(pc);
25479+ load_LDT_nolock(pc);
25480 if (!cpumask_equal(mm_cpumask(current->mm),
25481 cpumask_of(smp_processor_id())))
25482 smp_call_function(flush_ldt, current->mm, 1);
25483 preempt_enable();
25484 #else
25485- load_LDT(pc);
25486+ load_LDT_nolock(pc);
25487 #endif
25488 }
25489 if (oldsize) {
25490@@ -96,7 +96,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25491 return err;
25492
25493 for (i = 0; i < old->size; i++)
25494- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25495+ write_ldt_entry(new->ldt, i, old->ldt + i);
25496 return 0;
25497 }
25498
25499@@ -117,6 +117,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25500 retval = copy_ldt(&mm->context, &old_mm->context);
25501 mutex_unlock(&old_mm->context.lock);
25502 }
25503+
25504+ if (tsk == current) {
25505+ mm->context.vdso = 0;
25506+
25507+#ifdef CONFIG_X86_32
25508+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25509+ mm->context.user_cs_base = 0UL;
25510+ mm->context.user_cs_limit = ~0UL;
25511+
25512+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25513+ cpus_clear(mm->context.cpu_user_cs_mask);
25514+#endif
25515+
25516+#endif
25517+#endif
25518+
25519+ }
25520+
25521 return retval;
25522 }
25523
25524@@ -231,6 +249,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25525 }
25526 }
25527
25528+#ifdef CONFIG_PAX_SEGMEXEC
25529+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25530+ error = -EINVAL;
25531+ goto out_unlock;
25532+ }
25533+#endif
25534+
25535 /*
25536 * On x86-64 we do not support 16-bit segments due to
25537 * IRET leaking the high bits of the kernel stack address.
25538diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25539index 1667b1d..16492c5 100644
25540--- a/arch/x86/kernel/machine_kexec_32.c
25541+++ b/arch/x86/kernel/machine_kexec_32.c
25542@@ -25,7 +25,7 @@
25543 #include <asm/cacheflush.h>
25544 #include <asm/debugreg.h>
25545
25546-static void set_idt(void *newidt, __u16 limit)
25547+static void set_idt(struct desc_struct *newidt, __u16 limit)
25548 {
25549 struct desc_ptr curidt;
25550
25551@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25552 }
25553
25554
25555-static void set_gdt(void *newgdt, __u16 limit)
25556+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25557 {
25558 struct desc_ptr curgdt;
25559
25560@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25561 }
25562
25563 control_page = page_address(image->control_code_page);
25564- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25565+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25566
25567 relocate_kernel_ptr = control_page;
25568 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25569diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25570index e69f988..da078ea 100644
25571--- a/arch/x86/kernel/module.c
25572+++ b/arch/x86/kernel/module.c
25573@@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25574 }
25575 #endif
25576
25577-void *module_alloc(unsigned long size)
25578+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25579 {
25580- if (PAGE_ALIGN(size) > MODULES_LEN)
25581+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25582 return NULL;
25583 return __vmalloc_node_range(size, 1,
25584 MODULES_VADDR + get_module_load_offset(),
25585- MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25586- PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25587+ MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25588+ prot, NUMA_NO_NODE,
25589 __builtin_return_address(0));
25590 }
25591
25592+void *module_alloc(unsigned long size)
25593+{
25594+
25595+#ifdef CONFIG_PAX_KERNEXEC
25596+ return __module_alloc(size, PAGE_KERNEL);
25597+#else
25598+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25599+#endif
25600+
25601+}
25602+
25603+#ifdef CONFIG_PAX_KERNEXEC
25604+#ifdef CONFIG_X86_32
25605+void *module_alloc_exec(unsigned long size)
25606+{
25607+ struct vm_struct *area;
25608+
25609+ if (size == 0)
25610+ return NULL;
25611+
25612+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25613+return area ? area->addr : NULL;
25614+}
25615+EXPORT_SYMBOL(module_alloc_exec);
25616+
25617+void module_free_exec(struct module *mod, void *module_region)
25618+{
25619+ vunmap(module_region);
25620+}
25621+EXPORT_SYMBOL(module_free_exec);
25622+#else
25623+void module_free_exec(struct module *mod, void *module_region)
25624+{
25625+ module_free(mod, module_region);
25626+}
25627+EXPORT_SYMBOL(module_free_exec);
25628+
25629+void *module_alloc_exec(unsigned long size)
25630+{
25631+ return __module_alloc(size, PAGE_KERNEL_RX);
25632+}
25633+EXPORT_SYMBOL(module_alloc_exec);
25634+#endif
25635+#endif
25636+
25637 #ifdef CONFIG_X86_32
25638 int apply_relocate(Elf32_Shdr *sechdrs,
25639 const char *strtab,
25640@@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25641 unsigned int i;
25642 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25643 Elf32_Sym *sym;
25644- uint32_t *location;
25645+ uint32_t *plocation, location;
25646
25647 DEBUGP("Applying relocate section %u to %u\n",
25648 relsec, sechdrs[relsec].sh_info);
25649 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25650 /* This is where to make the change */
25651- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25652- + rel[i].r_offset;
25653+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25654+ location = (uint32_t)plocation;
25655+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25656+ plocation = ktla_ktva((void *)plocation);
25657 /* This is the symbol it is referring to. Note that all
25658 undefined symbols have been resolved. */
25659 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25660@@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25661 switch (ELF32_R_TYPE(rel[i].r_info)) {
25662 case R_386_32:
25663 /* We add the value into the location given */
25664- *location += sym->st_value;
25665+ pax_open_kernel();
25666+ *plocation += sym->st_value;
25667+ pax_close_kernel();
25668 break;
25669 case R_386_PC32:
25670 /* Add the value, subtract its position */
25671- *location += sym->st_value - (uint32_t)location;
25672+ pax_open_kernel();
25673+ *plocation += sym->st_value - location;
25674+ pax_close_kernel();
25675 break;
25676 default:
25677 pr_err("%s: Unknown relocation: %u\n",
25678@@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25679 case R_X86_64_NONE:
25680 break;
25681 case R_X86_64_64:
25682+ pax_open_kernel();
25683 *(u64 *)loc = val;
25684+ pax_close_kernel();
25685 break;
25686 case R_X86_64_32:
25687+ pax_open_kernel();
25688 *(u32 *)loc = val;
25689+ pax_close_kernel();
25690 if (val != *(u32 *)loc)
25691 goto overflow;
25692 break;
25693 case R_X86_64_32S:
25694+ pax_open_kernel();
25695 *(s32 *)loc = val;
25696+ pax_close_kernel();
25697 if ((s64)val != *(s32 *)loc)
25698 goto overflow;
25699 break;
25700 case R_X86_64_PC32:
25701 val -= (u64)loc;
25702+ pax_open_kernel();
25703 *(u32 *)loc = val;
25704+ pax_close_kernel();
25705+
25706 #if 0
25707 if ((s64)val != *(s32 *)loc)
25708 goto overflow;
25709diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25710index c9603ac..9f88728 100644
25711--- a/arch/x86/kernel/msr.c
25712+++ b/arch/x86/kernel/msr.c
25713@@ -37,6 +37,7 @@
25714 #include <linux/notifier.h>
25715 #include <linux/uaccess.h>
25716 #include <linux/gfp.h>
25717+#include <linux/grsecurity.h>
25718
25719 #include <asm/processor.h>
25720 #include <asm/msr.h>
25721@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25722 int err = 0;
25723 ssize_t bytes = 0;
25724
25725+#ifdef CONFIG_GRKERNSEC_KMEM
25726+ gr_handle_msr_write();
25727+ return -EPERM;
25728+#endif
25729+
25730 if (count % 8)
25731 return -EINVAL; /* Invalid chunk size */
25732
25733@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25734 err = -EBADF;
25735 break;
25736 }
25737+#ifdef CONFIG_GRKERNSEC_KMEM
25738+ gr_handle_msr_write();
25739+ return -EPERM;
25740+#endif
25741 if (copy_from_user(&regs, uregs, sizeof regs)) {
25742 err = -EFAULT;
25743 break;
25744@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25745 return notifier_from_errno(err);
25746 }
25747
25748-static struct notifier_block __refdata msr_class_cpu_notifier = {
25749+static struct notifier_block msr_class_cpu_notifier = {
25750 .notifier_call = msr_class_cpu_callback,
25751 };
25752
25753diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25754index b4872b9..5bf0684 100644
25755--- a/arch/x86/kernel/nmi.c
25756+++ b/arch/x86/kernel/nmi.c
25757@@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
25758
25759 static void nmi_max_handler(struct irq_work *w)
25760 {
25761- struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
25762+ struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
25763 int remainder_ns, decimal_msecs;
25764- u64 whole_msecs = ACCESS_ONCE(a->max_duration);
25765+ u64 whole_msecs = ACCESS_ONCE(n->max_duration);
25766
25767 remainder_ns = do_div(whole_msecs, (1000 * 1000));
25768 decimal_msecs = remainder_ns / 1000;
25769
25770 printk_ratelimited(KERN_INFO
25771 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
25772- a->handler, whole_msecs, decimal_msecs);
25773+ n->action->handler, whole_msecs, decimal_msecs);
25774 }
25775
25776 static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
25777@@ -134,11 +134,11 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25778 delta = sched_clock() - delta;
25779 trace_nmi_handler(a->handler, (int)delta, thishandled);
25780
25781- if (delta < nmi_longest_ns || delta < a->max_duration)
25782+ if (delta < nmi_longest_ns || delta < a->work->max_duration)
25783 continue;
25784
25785- a->max_duration = delta;
25786- irq_work_queue(&a->irq_work);
25787+ a->work->max_duration = delta;
25788+ irq_work_queue(&a->work->irq_work);
25789 }
25790
25791 rcu_read_unlock();
25792@@ -147,7 +147,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25793 return handled;
25794 }
25795
25796-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25797+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25798 {
25799 struct nmi_desc *desc = nmi_to_desc(type);
25800 unsigned long flags;
25801@@ -155,7 +155,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25802 if (!action->handler)
25803 return -EINVAL;
25804
25805- init_irq_work(&action->irq_work, nmi_max_handler);
25806+ action->work->action = action;
25807+ init_irq_work(&action->work->irq_work, nmi_max_handler);
25808
25809 spin_lock_irqsave(&desc->lock, flags);
25810
25811@@ -173,9 +174,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25812 * event confuses some handlers (kdump uses this flag)
25813 */
25814 if (action->flags & NMI_FLAG_FIRST)
25815- list_add_rcu(&action->list, &desc->head);
25816+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25817 else
25818- list_add_tail_rcu(&action->list, &desc->head);
25819+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25820
25821 spin_unlock_irqrestore(&desc->lock, flags);
25822 return 0;
25823@@ -198,7 +199,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25824 if (!strcmp(n->name, name)) {
25825 WARN(in_nmi(),
25826 "Trying to free NMI (%s) from NMI context!\n", n->name);
25827- list_del_rcu(&n->list);
25828+ pax_list_del_rcu((struct list_head *)&n->list);
25829 break;
25830 }
25831 }
25832@@ -523,6 +524,17 @@ static inline void nmi_nesting_postprocess(void)
25833 dotraplinkage notrace __kprobes void
25834 do_nmi(struct pt_regs *regs, long error_code)
25835 {
25836+
25837+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25838+ if (!user_mode(regs)) {
25839+ unsigned long cs = regs->cs & 0xFFFF;
25840+ unsigned long ip = ktva_ktla(regs->ip);
25841+
25842+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25843+ regs->ip = ip;
25844+ }
25845+#endif
25846+
25847 nmi_nesting_preprocess(regs);
25848
25849 nmi_enter();
25850diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25851index 6d9582e..f746287 100644
25852--- a/arch/x86/kernel/nmi_selftest.c
25853+++ b/arch/x86/kernel/nmi_selftest.c
25854@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25855 {
25856 /* trap all the unknown NMIs we may generate */
25857 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25858- __initdata);
25859+ __initconst);
25860 }
25861
25862 static void __init cleanup_nmi_testsuite(void)
25863@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25864 unsigned long timeout;
25865
25866 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25867- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25868+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25869 nmi_fail = FAILURE;
25870 return;
25871 }
25872diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25873index bbb6c73..24a58ef 100644
25874--- a/arch/x86/kernel/paravirt-spinlocks.c
25875+++ b/arch/x86/kernel/paravirt-spinlocks.c
25876@@ -8,7 +8,7 @@
25877
25878 #include <asm/paravirt.h>
25879
25880-struct pv_lock_ops pv_lock_ops = {
25881+struct pv_lock_ops pv_lock_ops __read_only = {
25882 #ifdef CONFIG_SMP
25883 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25884 .unlock_kick = paravirt_nop,
25885diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25886index 1b10af8..45bfbec 100644
25887--- a/arch/x86/kernel/paravirt.c
25888+++ b/arch/x86/kernel/paravirt.c
25889@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25890 {
25891 return x;
25892 }
25893+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25894+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25895+#endif
25896
25897 void __init default_banner(void)
25898 {
25899@@ -141,16 +144,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25900
25901 if (opfunc == NULL)
25902 /* If there's no function, patch it with a ud2a (BUG) */
25903- ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25904- else if (opfunc == _paravirt_nop)
25905+ ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
25906+ else if (opfunc == (void *)_paravirt_nop)
25907 /* If the operation is a nop, then nop the callsite */
25908 ret = paravirt_patch_nop();
25909
25910 /* identity functions just return their single argument */
25911- else if (opfunc == _paravirt_ident_32)
25912+ else if (opfunc == (void *)_paravirt_ident_32)
25913 ret = paravirt_patch_ident_32(insnbuf, len);
25914- else if (opfunc == _paravirt_ident_64)
25915+ else if (opfunc == (void *)_paravirt_ident_64)
25916 ret = paravirt_patch_ident_64(insnbuf, len);
25917+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25918+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25919+ ret = paravirt_patch_ident_64(insnbuf, len);
25920+#endif
25921
25922 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25923 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25924@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25925 if (insn_len > len || start == NULL)
25926 insn_len = len;
25927 else
25928- memcpy(insnbuf, start, insn_len);
25929+ memcpy(insnbuf, ktla_ktva(start), insn_len);
25930
25931 return insn_len;
25932 }
25933@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25934 return this_cpu_read(paravirt_lazy_mode);
25935 }
25936
25937-struct pv_info pv_info = {
25938+struct pv_info pv_info __read_only = {
25939 .name = "bare hardware",
25940 .paravirt_enabled = 0,
25941 .kernel_rpl = 0,
25942@@ -310,16 +317,16 @@ struct pv_info pv_info = {
25943 #endif
25944 };
25945
25946-struct pv_init_ops pv_init_ops = {
25947+struct pv_init_ops pv_init_ops __read_only = {
25948 .patch = native_patch,
25949 };
25950
25951-struct pv_time_ops pv_time_ops = {
25952+struct pv_time_ops pv_time_ops __read_only = {
25953 .sched_clock = native_sched_clock,
25954 .steal_clock = native_steal_clock,
25955 };
25956
25957-__visible struct pv_irq_ops pv_irq_ops = {
25958+__visible struct pv_irq_ops pv_irq_ops __read_only = {
25959 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25960 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25961 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25962@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25963 #endif
25964 };
25965
25966-__visible struct pv_cpu_ops pv_cpu_ops = {
25967+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25968 .cpuid = native_cpuid,
25969 .get_debugreg = native_get_debugreg,
25970 .set_debugreg = native_set_debugreg,
25971@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25972 .end_context_switch = paravirt_nop,
25973 };
25974
25975-struct pv_apic_ops pv_apic_ops = {
25976+struct pv_apic_ops pv_apic_ops __read_only= {
25977 #ifdef CONFIG_X86_LOCAL_APIC
25978 .startup_ipi_hook = paravirt_nop,
25979 #endif
25980 };
25981
25982-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25983+#ifdef CONFIG_X86_32
25984+#ifdef CONFIG_X86_PAE
25985+/* 64-bit pagetable entries */
25986+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25987+#else
25988 /* 32-bit pagetable entries */
25989 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25990+#endif
25991 #else
25992 /* 64-bit pagetable entries */
25993 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25994 #endif
25995
25996-struct pv_mmu_ops pv_mmu_ops = {
25997+struct pv_mmu_ops pv_mmu_ops __read_only = {
25998
25999 .read_cr2 = native_read_cr2,
26000 .write_cr2 = native_write_cr2,
26001@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26002 .make_pud = PTE_IDENT,
26003
26004 .set_pgd = native_set_pgd,
26005+ .set_pgd_batched = native_set_pgd_batched,
26006 #endif
26007 #endif /* PAGETABLE_LEVELS >= 3 */
26008
26009@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26010 },
26011
26012 .set_fixmap = native_set_fixmap,
26013+
26014+#ifdef CONFIG_PAX_KERNEXEC
26015+ .pax_open_kernel = native_pax_open_kernel,
26016+ .pax_close_kernel = native_pax_close_kernel,
26017+#endif
26018+
26019 };
26020
26021 EXPORT_SYMBOL_GPL(pv_time_ops);
26022diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26023index 0497f71..7186c0d 100644
26024--- a/arch/x86/kernel/pci-calgary_64.c
26025+++ b/arch/x86/kernel/pci-calgary_64.c
26026@@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26027 tce_space = be64_to_cpu(readq(target));
26028 tce_space = tce_space & TAR_SW_BITS;
26029
26030- tce_space = tce_space & (~specified_table_size);
26031+ tce_space = tce_space & (~(unsigned long)specified_table_size);
26032 info->tce_space = (u64 *)__va(tce_space);
26033 }
26034 }
26035diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26036index 35ccf75..7a15747 100644
26037--- a/arch/x86/kernel/pci-iommu_table.c
26038+++ b/arch/x86/kernel/pci-iommu_table.c
26039@@ -2,7 +2,7 @@
26040 #include <asm/iommu_table.h>
26041 #include <linux/string.h>
26042 #include <linux/kallsyms.h>
26043-
26044+#include <linux/sched.h>
26045
26046 #define DEBUG 1
26047
26048diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26049index 6c483ba..d10ce2f 100644
26050--- a/arch/x86/kernel/pci-swiotlb.c
26051+++ b/arch/x86/kernel/pci-swiotlb.c
26052@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26053 void *vaddr, dma_addr_t dma_addr,
26054 struct dma_attrs *attrs)
26055 {
26056- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26057+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26058 }
26059
26060 static struct dma_map_ops swiotlb_dma_ops = {
26061diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26062index ca7f0d5..8996469 100644
26063--- a/arch/x86/kernel/preempt.S
26064+++ b/arch/x86/kernel/preempt.S
26065@@ -3,12 +3,14 @@
26066 #include <asm/dwarf2.h>
26067 #include <asm/asm.h>
26068 #include <asm/calling.h>
26069+#include <asm/alternative-asm.h>
26070
26071 ENTRY(___preempt_schedule)
26072 CFI_STARTPROC
26073 SAVE_ALL
26074 call preempt_schedule
26075 RESTORE_ALL
26076+ pax_force_retaddr
26077 ret
26078 CFI_ENDPROC
26079
26080@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26081 SAVE_ALL
26082 call preempt_schedule_context
26083 RESTORE_ALL
26084+ pax_force_retaddr
26085 ret
26086 CFI_ENDPROC
26087
26088diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26089index 4505e2a..ae28b0d 100644
26090--- a/arch/x86/kernel/process.c
26091+++ b/arch/x86/kernel/process.c
26092@@ -36,7 +36,8 @@
26093 * section. Since TSS's are completely CPU-local, we want them
26094 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26095 */
26096-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26097+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26098+EXPORT_SYMBOL(init_tss);
26099
26100 #ifdef CONFIG_X86_64
26101 static DEFINE_PER_CPU(unsigned char, is_idle);
26102@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26103 task_xstate_cachep =
26104 kmem_cache_create("task_xstate", xstate_size,
26105 __alignof__(union thread_xstate),
26106- SLAB_PANIC | SLAB_NOTRACK, NULL);
26107+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26108 }
26109
26110 /*
26111@@ -105,7 +106,7 @@ void exit_thread(void)
26112 unsigned long *bp = t->io_bitmap_ptr;
26113
26114 if (bp) {
26115- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26116+ struct tss_struct *tss = init_tss + get_cpu();
26117
26118 t->io_bitmap_ptr = NULL;
26119 clear_thread_flag(TIF_IO_BITMAP);
26120@@ -125,6 +126,9 @@ void flush_thread(void)
26121 {
26122 struct task_struct *tsk = current;
26123
26124+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26125+ loadsegment(gs, 0);
26126+#endif
26127 flush_ptrace_hw_breakpoint(tsk);
26128 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26129 drop_init_fpu(tsk);
26130@@ -271,7 +275,7 @@ static void __exit_idle(void)
26131 void exit_idle(void)
26132 {
26133 /* idle loop has pid 0 */
26134- if (current->pid)
26135+ if (task_pid_nr(current))
26136 return;
26137 __exit_idle();
26138 }
26139@@ -324,7 +328,7 @@ bool xen_set_default_idle(void)
26140 return ret;
26141 }
26142 #endif
26143-void stop_this_cpu(void *dummy)
26144+__noreturn void stop_this_cpu(void *dummy)
26145 {
26146 local_irq_disable();
26147 /*
26148@@ -453,16 +457,37 @@ static int __init idle_setup(char *str)
26149 }
26150 early_param("idle", idle_setup);
26151
26152-unsigned long arch_align_stack(unsigned long sp)
26153+#ifdef CONFIG_PAX_RANDKSTACK
26154+void pax_randomize_kstack(struct pt_regs *regs)
26155 {
26156- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26157- sp -= get_random_int() % 8192;
26158- return sp & ~0xf;
26159-}
26160+ struct thread_struct *thread = &current->thread;
26161+ unsigned long time;
26162
26163-unsigned long arch_randomize_brk(struct mm_struct *mm)
26164-{
26165- unsigned long range_end = mm->brk + 0x02000000;
26166- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26167-}
26168+ if (!randomize_va_space)
26169+ return;
26170+
26171+ if (v8086_mode(regs))
26172+ return;
26173
26174+ rdtscl(time);
26175+
26176+ /* P4 seems to return a 0 LSB, ignore it */
26177+#ifdef CONFIG_MPENTIUM4
26178+ time &= 0x3EUL;
26179+ time <<= 2;
26180+#elif defined(CONFIG_X86_64)
26181+ time &= 0xFUL;
26182+ time <<= 4;
26183+#else
26184+ time &= 0x1FUL;
26185+ time <<= 3;
26186+#endif
26187+
26188+ thread->sp0 ^= time;
26189+ load_sp0(init_tss + smp_processor_id(), thread);
26190+
26191+#ifdef CONFIG_X86_64
26192+ this_cpu_write(kernel_stack, thread->sp0);
26193+#endif
26194+}
26195+#endif
26196diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26197index 7bc86bb..0ea06e8 100644
26198--- a/arch/x86/kernel/process_32.c
26199+++ b/arch/x86/kernel/process_32.c
26200@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26201 unsigned long thread_saved_pc(struct task_struct *tsk)
26202 {
26203 return ((unsigned long *)tsk->thread.sp)[3];
26204+//XXX return tsk->thread.eip;
26205 }
26206
26207 void __show_regs(struct pt_regs *regs, int all)
26208@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26209 unsigned long sp;
26210 unsigned short ss, gs;
26211
26212- if (user_mode_vm(regs)) {
26213+ if (user_mode(regs)) {
26214 sp = regs->sp;
26215 ss = regs->ss & 0xffff;
26216- gs = get_user_gs(regs);
26217 } else {
26218 sp = kernel_stack_pointer(regs);
26219 savesegment(ss, ss);
26220- savesegment(gs, gs);
26221 }
26222+ gs = get_user_gs(regs);
26223
26224 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26225 (u16)regs->cs, regs->ip, regs->flags,
26226- smp_processor_id());
26227+ raw_smp_processor_id());
26228 print_symbol("EIP is at %s\n", regs->ip);
26229
26230 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26231@@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26232 int copy_thread(unsigned long clone_flags, unsigned long sp,
26233 unsigned long arg, struct task_struct *p)
26234 {
26235- struct pt_regs *childregs = task_pt_regs(p);
26236+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26237 struct task_struct *tsk;
26238 int err;
26239
26240 p->thread.sp = (unsigned long) childregs;
26241 p->thread.sp0 = (unsigned long) (childregs+1);
26242+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26243
26244 if (unlikely(p->flags & PF_KTHREAD)) {
26245 /* kernel thread */
26246 memset(childregs, 0, sizeof(struct pt_regs));
26247 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26248- task_user_gs(p) = __KERNEL_STACK_CANARY;
26249- childregs->ds = __USER_DS;
26250- childregs->es = __USER_DS;
26251+ savesegment(gs, childregs->gs);
26252+ childregs->ds = __KERNEL_DS;
26253+ childregs->es = __KERNEL_DS;
26254 childregs->fs = __KERNEL_PERCPU;
26255 childregs->bx = sp; /* function */
26256 childregs->bp = arg;
26257@@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26258 struct thread_struct *prev = &prev_p->thread,
26259 *next = &next_p->thread;
26260 int cpu = smp_processor_id();
26261- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26262+ struct tss_struct *tss = init_tss + cpu;
26263 fpu_switch_t fpu;
26264
26265 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26266@@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26267 */
26268 lazy_save_gs(prev->gs);
26269
26270+#ifdef CONFIG_PAX_MEMORY_UDEREF
26271+ __set_fs(task_thread_info(next_p)->addr_limit);
26272+#endif
26273+
26274 /*
26275 * Load the per-thread Thread-Local Storage descriptor.
26276 */
26277@@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26278 */
26279 arch_end_context_switch(next_p);
26280
26281- this_cpu_write(kernel_stack,
26282- (unsigned long)task_stack_page(next_p) +
26283- THREAD_SIZE - KERNEL_STACK_OFFSET);
26284+ this_cpu_write(current_task, next_p);
26285+ this_cpu_write(current_tinfo, &next_p->tinfo);
26286+ this_cpu_write(kernel_stack, next->sp0);
26287
26288 /*
26289 * Restore %gs if needed (which is common)
26290@@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26291
26292 switch_fpu_finish(next_p, fpu);
26293
26294- this_cpu_write(current_task, next_p);
26295-
26296 return prev_p;
26297 }
26298
26299@@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26300 } while (count++ < 16);
26301 return 0;
26302 }
26303-
26304diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26305index 898d077..4c458ff 100644
26306--- a/arch/x86/kernel/process_64.c
26307+++ b/arch/x86/kernel/process_64.c
26308@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26309 struct pt_regs *childregs;
26310 struct task_struct *me = current;
26311
26312- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26313+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26314 childregs = task_pt_regs(p);
26315 p->thread.sp = (unsigned long) childregs;
26316 p->thread.usersp = me->thread.usersp;
26317+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26318 set_tsk_thread_flag(p, TIF_FORK);
26319 p->thread.fpu_counter = 0;
26320 p->thread.io_bitmap_ptr = NULL;
26321@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26322 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26323 savesegment(es, p->thread.es);
26324 savesegment(ds, p->thread.ds);
26325+ savesegment(ss, p->thread.ss);
26326+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26327 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26328
26329 if (unlikely(p->flags & PF_KTHREAD)) {
26330@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26331 struct thread_struct *prev = &prev_p->thread;
26332 struct thread_struct *next = &next_p->thread;
26333 int cpu = smp_processor_id();
26334- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26335+ struct tss_struct *tss = init_tss + cpu;
26336 unsigned fsindex, gsindex;
26337 fpu_switch_t fpu;
26338
26339@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26340 if (unlikely(next->ds | prev->ds))
26341 loadsegment(ds, next->ds);
26342
26343+ savesegment(ss, prev->ss);
26344+ if (unlikely(next->ss != prev->ss))
26345+ loadsegment(ss, next->ss);
26346
26347 /* We must save %fs and %gs before load_TLS() because
26348 * %fs and %gs may be cleared by load_TLS().
26349@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26350 prev->usersp = this_cpu_read(old_rsp);
26351 this_cpu_write(old_rsp, next->usersp);
26352 this_cpu_write(current_task, next_p);
26353+ this_cpu_write(current_tinfo, &next_p->tinfo);
26354
26355 /*
26356 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26357@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26358 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26359 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26360
26361- this_cpu_write(kernel_stack,
26362- (unsigned long)task_stack_page(next_p) +
26363- THREAD_SIZE - KERNEL_STACK_OFFSET);
26364+ this_cpu_write(kernel_stack, next->sp0);
26365
26366 /*
26367 * Now maybe reload the debug registers and handle I/O bitmaps
26368@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26369 if (!p || p == current || p->state == TASK_RUNNING)
26370 return 0;
26371 stack = (unsigned long)task_stack_page(p);
26372- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26373+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26374 return 0;
26375 fp = *(u64 *)(p->thread.sp);
26376 do {
26377- if (fp < (unsigned long)stack ||
26378- fp >= (unsigned long)stack+THREAD_SIZE)
26379+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26380 return 0;
26381 ip = *(u64 *)(fp+8);
26382 if (!in_sched_functions(ip))
26383diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26384index 678c0ad..d309ccb 100644
26385--- a/arch/x86/kernel/ptrace.c
26386+++ b/arch/x86/kernel/ptrace.c
26387@@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26388 unsigned long sp = (unsigned long)&regs->sp;
26389 u32 *prev_esp;
26390
26391- if (context == (sp & ~(THREAD_SIZE - 1)))
26392+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26393 return sp;
26394
26395- prev_esp = (u32 *)(context);
26396+ prev_esp = *(u32 **)(context);
26397 if (prev_esp)
26398 return (unsigned long)prev_esp;
26399
26400@@ -588,7 +588,7 @@ static void ptrace_triggered(struct perf_event *bp,
26401 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26402 {
26403 int i;
26404- int dr7 = 0;
26405+ unsigned long dr7 = 0;
26406 struct arch_hw_breakpoint *info;
26407
26408 for (i = 0; i < HBP_NUM; i++) {
26409@@ -822,7 +822,7 @@ long arch_ptrace(struct task_struct *child, long request,
26410 unsigned long addr, unsigned long data)
26411 {
26412 int ret;
26413- unsigned long __user *datap = (unsigned long __user *)data;
26414+ unsigned long __user *datap = (__force unsigned long __user *)data;
26415
26416 switch (request) {
26417 /* read the word at location addr in the USER area. */
26418@@ -907,14 +907,14 @@ long arch_ptrace(struct task_struct *child, long request,
26419 if ((int) addr < 0)
26420 return -EIO;
26421 ret = do_get_thread_area(child, addr,
26422- (struct user_desc __user *)data);
26423+ (__force struct user_desc __user *) data);
26424 break;
26425
26426 case PTRACE_SET_THREAD_AREA:
26427 if ((int) addr < 0)
26428 return -EIO;
26429 ret = do_set_thread_area(child, addr,
26430- (struct user_desc __user *)data, 0);
26431+ (__force struct user_desc __user *) data, 0);
26432 break;
26433 #endif
26434
26435@@ -1292,7 +1292,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26436
26437 #ifdef CONFIG_X86_64
26438
26439-static struct user_regset x86_64_regsets[] __read_mostly = {
26440+static user_regset_no_const x86_64_regsets[] __read_only = {
26441 [REGSET_GENERAL] = {
26442 .core_note_type = NT_PRSTATUS,
26443 .n = sizeof(struct user_regs_struct) / sizeof(long),
26444@@ -1333,7 +1333,7 @@ static const struct user_regset_view user_x86_64_view = {
26445 #endif /* CONFIG_X86_64 */
26446
26447 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26448-static struct user_regset x86_32_regsets[] __read_mostly = {
26449+static user_regset_no_const x86_32_regsets[] __read_only = {
26450 [REGSET_GENERAL] = {
26451 .core_note_type = NT_PRSTATUS,
26452 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26453@@ -1386,7 +1386,7 @@ static const struct user_regset_view user_x86_32_view = {
26454 */
26455 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26456
26457-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26458+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26459 {
26460 #ifdef CONFIG_X86_64
26461 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26462@@ -1421,7 +1421,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26463 memset(info, 0, sizeof(*info));
26464 info->si_signo = SIGTRAP;
26465 info->si_code = si_code;
26466- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26467+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26468 }
26469
26470 void user_single_step_siginfo(struct task_struct *tsk,
26471@@ -1450,6 +1450,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26472 # define IS_IA32 0
26473 #endif
26474
26475+#ifdef CONFIG_GRKERNSEC_SETXID
26476+extern void gr_delayed_cred_worker(void);
26477+#endif
26478+
26479 /*
26480 * We must return the syscall number to actually look up in the table.
26481 * This can be -1L to skip running any syscall at all.
26482@@ -1460,6 +1464,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26483
26484 user_exit();
26485
26486+#ifdef CONFIG_GRKERNSEC_SETXID
26487+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26488+ gr_delayed_cred_worker();
26489+#endif
26490+
26491 /*
26492 * If we stepped into a sysenter/syscall insn, it trapped in
26493 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26494@@ -1515,6 +1524,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26495 */
26496 user_exit();
26497
26498+#ifdef CONFIG_GRKERNSEC_SETXID
26499+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26500+ gr_delayed_cred_worker();
26501+#endif
26502+
26503 audit_syscall_exit(regs);
26504
26505 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26506diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26507index 2f355d2..e75ed0a 100644
26508--- a/arch/x86/kernel/pvclock.c
26509+++ b/arch/x86/kernel/pvclock.c
26510@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26511 reset_hung_task_detector();
26512 }
26513
26514-static atomic64_t last_value = ATOMIC64_INIT(0);
26515+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26516
26517 void pvclock_resume(void)
26518 {
26519- atomic64_set(&last_value, 0);
26520+ atomic64_set_unchecked(&last_value, 0);
26521 }
26522
26523 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26524@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26525 * updating at the same time, and one of them could be slightly behind,
26526 * making the assumption that last_value always go forward fail to hold.
26527 */
26528- last = atomic64_read(&last_value);
26529+ last = atomic64_read_unchecked(&last_value);
26530 do {
26531 if (ret < last)
26532 return last;
26533- last = atomic64_cmpxchg(&last_value, last, ret);
26534+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26535 } while (unlikely(last != ret));
26536
26537 return ret;
26538diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26539index 52b1157..c6e67c4 100644
26540--- a/arch/x86/kernel/reboot.c
26541+++ b/arch/x86/kernel/reboot.c
26542@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26543
26544 void __noreturn machine_real_restart(unsigned int type)
26545 {
26546+
26547+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26548+ struct desc_struct *gdt;
26549+#endif
26550+
26551 local_irq_disable();
26552
26553 /*
26554@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26555
26556 /* Jump to the identity-mapped low memory code */
26557 #ifdef CONFIG_X86_32
26558- asm volatile("jmpl *%0" : :
26559+
26560+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26561+ gdt = get_cpu_gdt_table(smp_processor_id());
26562+ pax_open_kernel();
26563+#ifdef CONFIG_PAX_MEMORY_UDEREF
26564+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26565+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26566+ loadsegment(ds, __KERNEL_DS);
26567+ loadsegment(es, __KERNEL_DS);
26568+ loadsegment(ss, __KERNEL_DS);
26569+#endif
26570+#ifdef CONFIG_PAX_KERNEXEC
26571+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26572+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26573+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26574+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26575+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26576+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26577+#endif
26578+ pax_close_kernel();
26579+#endif
26580+
26581+ asm volatile("ljmpl *%0" : :
26582 "rm" (real_mode_header->machine_real_restart_asm),
26583 "a" (type));
26584 #else
26585@@ -486,7 +513,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26586 * This means that this function can never return, it can misbehave
26587 * by not rebooting properly and hanging.
26588 */
26589-static void native_machine_emergency_restart(void)
26590+static void __noreturn native_machine_emergency_restart(void)
26591 {
26592 int i;
26593 int attempt = 0;
26594@@ -610,13 +637,13 @@ void native_machine_shutdown(void)
26595 #endif
26596 }
26597
26598-static void __machine_emergency_restart(int emergency)
26599+static void __noreturn __machine_emergency_restart(int emergency)
26600 {
26601 reboot_emergency = emergency;
26602 machine_ops.emergency_restart();
26603 }
26604
26605-static void native_machine_restart(char *__unused)
26606+static void __noreturn native_machine_restart(char *__unused)
26607 {
26608 pr_notice("machine restart\n");
26609
26610@@ -625,7 +652,7 @@ static void native_machine_restart(char *__unused)
26611 __machine_emergency_restart(0);
26612 }
26613
26614-static void native_machine_halt(void)
26615+static void __noreturn native_machine_halt(void)
26616 {
26617 /* Stop other cpus and apics */
26618 machine_shutdown();
26619@@ -635,7 +662,7 @@ static void native_machine_halt(void)
26620 stop_this_cpu(NULL);
26621 }
26622
26623-static void native_machine_power_off(void)
26624+static void __noreturn native_machine_power_off(void)
26625 {
26626 if (pm_power_off) {
26627 if (!reboot_force)
26628@@ -644,9 +671,10 @@ static void native_machine_power_off(void)
26629 }
26630 /* A fallback in case there is no PM info available */
26631 tboot_shutdown(TB_SHUTDOWN_HALT);
26632+ unreachable();
26633 }
26634
26635-struct machine_ops machine_ops = {
26636+struct machine_ops machine_ops __read_only = {
26637 .power_off = native_machine_power_off,
26638 .shutdown = native_machine_shutdown,
26639 .emergency_restart = native_machine_emergency_restart,
26640diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26641index c8e41e9..64049ef 100644
26642--- a/arch/x86/kernel/reboot_fixups_32.c
26643+++ b/arch/x86/kernel/reboot_fixups_32.c
26644@@ -57,7 +57,7 @@ struct device_fixup {
26645 unsigned int vendor;
26646 unsigned int device;
26647 void (*reboot_fixup)(struct pci_dev *);
26648-};
26649+} __do_const;
26650
26651 /*
26652 * PCI ids solely used for fixups_table go here
26653diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26654index 3fd2c69..a444264 100644
26655--- a/arch/x86/kernel/relocate_kernel_64.S
26656+++ b/arch/x86/kernel/relocate_kernel_64.S
26657@@ -96,8 +96,7 @@ relocate_kernel:
26658
26659 /* jump to identity mapped page */
26660 addq $(identity_mapped - relocate_kernel), %r8
26661- pushq %r8
26662- ret
26663+ jmp *%r8
26664
26665 identity_mapped:
26666 /* set return address to 0 if not preserving context */
26667diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26668index 09c76d2..7f33fc2 100644
26669--- a/arch/x86/kernel/setup.c
26670+++ b/arch/x86/kernel/setup.c
26671@@ -110,6 +110,7 @@
26672 #include <asm/mce.h>
26673 #include <asm/alternative.h>
26674 #include <asm/prom.h>
26675+#include <asm/boot.h>
26676
26677 /*
26678 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26679@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26680 #endif
26681
26682
26683-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26684-__visible unsigned long mmu_cr4_features;
26685+#ifdef CONFIG_X86_64
26686+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26687+#elif defined(CONFIG_X86_PAE)
26688+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26689 #else
26690-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26691+__visible unsigned long mmu_cr4_features __read_only;
26692 #endif
26693
26694+void set_in_cr4(unsigned long mask)
26695+{
26696+ unsigned long cr4 = read_cr4();
26697+
26698+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26699+ return;
26700+
26701+ pax_open_kernel();
26702+ mmu_cr4_features |= mask;
26703+ pax_close_kernel();
26704+
26705+ if (trampoline_cr4_features)
26706+ *trampoline_cr4_features = mmu_cr4_features;
26707+ cr4 |= mask;
26708+ write_cr4(cr4);
26709+}
26710+EXPORT_SYMBOL(set_in_cr4);
26711+
26712+void clear_in_cr4(unsigned long mask)
26713+{
26714+ unsigned long cr4 = read_cr4();
26715+
26716+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26717+ return;
26718+
26719+ pax_open_kernel();
26720+ mmu_cr4_features &= ~mask;
26721+ pax_close_kernel();
26722+
26723+ if (trampoline_cr4_features)
26724+ *trampoline_cr4_features = mmu_cr4_features;
26725+ cr4 &= ~mask;
26726+ write_cr4(cr4);
26727+}
26728+EXPORT_SYMBOL(clear_in_cr4);
26729+
26730 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26731 int bootloader_type, bootloader_version;
26732
26733@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
26734 * area (640->1Mb) as ram even though it is not.
26735 * take them out.
26736 */
26737- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26738+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26739
26740 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26741 }
26742@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
26743 /* called before trim_bios_range() to spare extra sanitize */
26744 static void __init e820_add_kernel_range(void)
26745 {
26746- u64 start = __pa_symbol(_text);
26747+ u64 start = __pa_symbol(ktla_ktva(_text));
26748 u64 size = __pa_symbol(_end) - start;
26749
26750 /*
26751@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
26752
26753 void __init setup_arch(char **cmdline_p)
26754 {
26755+#ifdef CONFIG_X86_32
26756+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26757+#else
26758 memblock_reserve(__pa_symbol(_text),
26759 (unsigned long)__bss_stop - (unsigned long)_text);
26760+#endif
26761
26762 early_reserve_initrd();
26763
26764@@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
26765
26766 if (!boot_params.hdr.root_flags)
26767 root_mountflags &= ~MS_RDONLY;
26768- init_mm.start_code = (unsigned long) _text;
26769- init_mm.end_code = (unsigned long) _etext;
26770+ init_mm.start_code = ktla_ktva((unsigned long) _text);
26771+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
26772 init_mm.end_data = (unsigned long) _edata;
26773 init_mm.brk = _brk_end;
26774
26775- code_resource.start = __pa_symbol(_text);
26776- code_resource.end = __pa_symbol(_etext)-1;
26777- data_resource.start = __pa_symbol(_etext);
26778+ code_resource.start = __pa_symbol(ktla_ktva(_text));
26779+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26780+ data_resource.start = __pa_symbol(_sdata);
26781 data_resource.end = __pa_symbol(_edata)-1;
26782 bss_resource.start = __pa_symbol(__bss_start);
26783 bss_resource.end = __pa_symbol(__bss_stop)-1;
26784diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26785index 5cdff03..80fa283 100644
26786--- a/arch/x86/kernel/setup_percpu.c
26787+++ b/arch/x86/kernel/setup_percpu.c
26788@@ -21,19 +21,17 @@
26789 #include <asm/cpu.h>
26790 #include <asm/stackprotector.h>
26791
26792-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26793+#ifdef CONFIG_SMP
26794+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26795 EXPORT_PER_CPU_SYMBOL(cpu_number);
26796+#endif
26797
26798-#ifdef CONFIG_X86_64
26799 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26800-#else
26801-#define BOOT_PERCPU_OFFSET 0
26802-#endif
26803
26804 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26805 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26806
26807-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26808+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26809 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26810 };
26811 EXPORT_SYMBOL(__per_cpu_offset);
26812@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26813 {
26814 #ifdef CONFIG_NEED_MULTIPLE_NODES
26815 pg_data_t *last = NULL;
26816- unsigned int cpu;
26817+ int cpu;
26818
26819 for_each_possible_cpu(cpu) {
26820 int node = early_cpu_to_node(cpu);
26821@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26822 {
26823 #ifdef CONFIG_X86_32
26824 struct desc_struct gdt;
26825+ unsigned long base = per_cpu_offset(cpu);
26826
26827- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26828- 0x2 | DESCTYPE_S, 0x8);
26829- gdt.s = 1;
26830+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26831+ 0x83 | DESCTYPE_S, 0xC);
26832 write_gdt_entry(get_cpu_gdt_table(cpu),
26833 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26834 #endif
26835@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26836 /* alrighty, percpu areas up and running */
26837 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26838 for_each_possible_cpu(cpu) {
26839+#ifdef CONFIG_CC_STACKPROTECTOR
26840+#ifdef CONFIG_X86_32
26841+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
26842+#endif
26843+#endif
26844 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26845 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26846 per_cpu(cpu_number, cpu) = cpu;
26847@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26848 */
26849 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26850 #endif
26851+#ifdef CONFIG_CC_STACKPROTECTOR
26852+#ifdef CONFIG_X86_32
26853+ if (!cpu)
26854+ per_cpu(stack_canary.canary, cpu) = canary;
26855+#endif
26856+#endif
26857 /*
26858 * Up to this point, the boot CPU has been using .init.data
26859 * area. Reload any changed state for the boot CPU.
26860diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26861index 9e5de68..16c53cb 100644
26862--- a/arch/x86/kernel/signal.c
26863+++ b/arch/x86/kernel/signal.c
26864@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26865 * Align the stack pointer according to the i386 ABI,
26866 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26867 */
26868- sp = ((sp + 4) & -16ul) - 4;
26869+ sp = ((sp - 12) & -16ul) - 4;
26870 #else /* !CONFIG_X86_32 */
26871 sp = round_down(sp, 16) - 8;
26872 #endif
26873@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26874 }
26875
26876 if (current->mm->context.vdso)
26877- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26878+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26879 else
26880- restorer = &frame->retcode;
26881+ restorer = (void __user *)&frame->retcode;
26882 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26883 restorer = ksig->ka.sa.sa_restorer;
26884
26885@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26886 * reasons and because gdb uses it as a signature to notice
26887 * signal handler stack frames.
26888 */
26889- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26890+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26891
26892 if (err)
26893 return -EFAULT;
26894@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26895 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26896
26897 /* Set up to return from userspace. */
26898- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26899+ if (current->mm->context.vdso)
26900+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26901+ else
26902+ restorer = (void __user *)&frame->retcode;
26903 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26904 restorer = ksig->ka.sa.sa_restorer;
26905 put_user_ex(restorer, &frame->pretcode);
26906@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26907 * reasons and because gdb uses it as a signature to notice
26908 * signal handler stack frames.
26909 */
26910- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26911+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26912 } put_user_catch(err);
26913
26914 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26915@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26916 {
26917 int usig = signr_convert(ksig->sig);
26918 sigset_t *set = sigmask_to_save();
26919- compat_sigset_t *cset = (compat_sigset_t *) set;
26920+ sigset_t sigcopy;
26921+ compat_sigset_t *cset;
26922+
26923+ sigcopy = *set;
26924+
26925+ cset = (compat_sigset_t *) &sigcopy;
26926
26927 /* Set up the stack frame */
26928 if (is_ia32_frame()) {
26929@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26930 } else if (is_x32_frame()) {
26931 return x32_setup_rt_frame(ksig, cset, regs);
26932 } else {
26933- return __setup_rt_frame(ksig->sig, ksig, set, regs);
26934+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26935 }
26936 }
26937
26938diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26939index be8e1bd..a3d93fa 100644
26940--- a/arch/x86/kernel/smp.c
26941+++ b/arch/x86/kernel/smp.c
26942@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26943
26944 __setup("nonmi_ipi", nonmi_ipi_setup);
26945
26946-struct smp_ops smp_ops = {
26947+struct smp_ops smp_ops __read_only = {
26948 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26949 .smp_prepare_cpus = native_smp_prepare_cpus,
26950 .smp_cpus_done = native_smp_cpus_done,
26951diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26952index ae2fd975..c0c8d10 100644
26953--- a/arch/x86/kernel/smpboot.c
26954+++ b/arch/x86/kernel/smpboot.c
26955@@ -230,14 +230,17 @@ static void notrace start_secondary(void *unused)
26956
26957 enable_start_cpu0 = 0;
26958
26959-#ifdef CONFIG_X86_32
26960+ /* otherwise gcc will move up smp_processor_id before the cpu_init */
26961+ barrier();
26962+
26963 /* switch away from the initial page table */
26964+#ifdef CONFIG_PAX_PER_CPU_PGD
26965+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26966+#else
26967 load_cr3(swapper_pg_dir);
26968+#endif
26969 __flush_tlb_all();
26970-#endif
26971
26972- /* otherwise gcc will move up smp_processor_id before the cpu_init */
26973- barrier();
26974 /*
26975 * Check TSC synchronization with the BP:
26976 */
26977@@ -757,8 +760,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26978 alternatives_enable_smp();
26979
26980 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26981- (THREAD_SIZE + task_stack_page(idle))) - 1);
26982+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
26983 per_cpu(current_task, cpu) = idle;
26984+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
26985
26986 #ifdef CONFIG_X86_32
26987 /* Stack for startup_32 can be just as for start_secondary onwards */
26988@@ -767,10 +771,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26989 clear_tsk_thread_flag(idle, TIF_FORK);
26990 initial_gs = per_cpu_offset(cpu);
26991 #endif
26992- per_cpu(kernel_stack, cpu) =
26993- (unsigned long)task_stack_page(idle) -
26994- KERNEL_STACK_OFFSET + THREAD_SIZE;
26995+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26996+ pax_open_kernel();
26997 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26998+ pax_close_kernel();
26999 initial_code = (unsigned long)start_secondary;
27000 stack_start = idle->thread.sp;
27001
27002@@ -916,6 +920,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27003 /* the FPU context is blank, nobody can own it */
27004 __cpu_disable_lazy_restore(cpu);
27005
27006+#ifdef CONFIG_PAX_PER_CPU_PGD
27007+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27008+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27009+ KERNEL_PGD_PTRS);
27010+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27011+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27012+ KERNEL_PGD_PTRS);
27013+#endif
27014+
27015 err = do_boot_cpu(apicid, cpu, tidle);
27016 if (err) {
27017 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27018diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27019index 9b4d51d..5d28b58 100644
27020--- a/arch/x86/kernel/step.c
27021+++ b/arch/x86/kernel/step.c
27022@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27023 struct desc_struct *desc;
27024 unsigned long base;
27025
27026- seg &= ~7UL;
27027+ seg >>= 3;
27028
27029 mutex_lock(&child->mm->context.lock);
27030- if (unlikely((seg >> 3) >= child->mm->context.size))
27031+ if (unlikely(seg >= child->mm->context.size))
27032 addr = -1L; /* bogus selector, access would fault */
27033 else {
27034 desc = child->mm->context.ldt + seg;
27035@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27036 addr += base;
27037 }
27038 mutex_unlock(&child->mm->context.lock);
27039- }
27040+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27041+ addr = ktla_ktva(addr);
27042
27043 return addr;
27044 }
27045@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27046 unsigned char opcode[15];
27047 unsigned long addr = convert_ip_to_linear(child, regs);
27048
27049+ if (addr == -EINVAL)
27050+ return 0;
27051+
27052 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27053 for (i = 0; i < copied; i++) {
27054 switch (opcode[i]) {
27055diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27056new file mode 100644
27057index 0000000..5877189
27058--- /dev/null
27059+++ b/arch/x86/kernel/sys_i386_32.c
27060@@ -0,0 +1,189 @@
27061+/*
27062+ * This file contains various random system calls that
27063+ * have a non-standard calling sequence on the Linux/i386
27064+ * platform.
27065+ */
27066+
27067+#include <linux/errno.h>
27068+#include <linux/sched.h>
27069+#include <linux/mm.h>
27070+#include <linux/fs.h>
27071+#include <linux/smp.h>
27072+#include <linux/sem.h>
27073+#include <linux/msg.h>
27074+#include <linux/shm.h>
27075+#include <linux/stat.h>
27076+#include <linux/syscalls.h>
27077+#include <linux/mman.h>
27078+#include <linux/file.h>
27079+#include <linux/utsname.h>
27080+#include <linux/ipc.h>
27081+#include <linux/elf.h>
27082+
27083+#include <linux/uaccess.h>
27084+#include <linux/unistd.h>
27085+
27086+#include <asm/syscalls.h>
27087+
27088+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27089+{
27090+ unsigned long pax_task_size = TASK_SIZE;
27091+
27092+#ifdef CONFIG_PAX_SEGMEXEC
27093+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27094+ pax_task_size = SEGMEXEC_TASK_SIZE;
27095+#endif
27096+
27097+ if (flags & MAP_FIXED)
27098+ if (len > pax_task_size || addr > pax_task_size - len)
27099+ return -EINVAL;
27100+
27101+ return 0;
27102+}
27103+
27104+/*
27105+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27106+ */
27107+static unsigned long get_align_mask(void)
27108+{
27109+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27110+ return 0;
27111+
27112+ if (!(current->flags & PF_RANDOMIZE))
27113+ return 0;
27114+
27115+ return va_align.mask;
27116+}
27117+
27118+unsigned long
27119+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27120+ unsigned long len, unsigned long pgoff, unsigned long flags)
27121+{
27122+ struct mm_struct *mm = current->mm;
27123+ struct vm_area_struct *vma;
27124+ unsigned long pax_task_size = TASK_SIZE;
27125+ struct vm_unmapped_area_info info;
27126+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27127+
27128+#ifdef CONFIG_PAX_SEGMEXEC
27129+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27130+ pax_task_size = SEGMEXEC_TASK_SIZE;
27131+#endif
27132+
27133+ pax_task_size -= PAGE_SIZE;
27134+
27135+ if (len > pax_task_size)
27136+ return -ENOMEM;
27137+
27138+ if (flags & MAP_FIXED)
27139+ return addr;
27140+
27141+#ifdef CONFIG_PAX_RANDMMAP
27142+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27143+#endif
27144+
27145+ if (addr) {
27146+ addr = PAGE_ALIGN(addr);
27147+ if (pax_task_size - len >= addr) {
27148+ vma = find_vma(mm, addr);
27149+ if (check_heap_stack_gap(vma, addr, len, offset))
27150+ return addr;
27151+ }
27152+ }
27153+
27154+ info.flags = 0;
27155+ info.length = len;
27156+ info.align_mask = filp ? get_align_mask() : 0;
27157+ info.align_offset = pgoff << PAGE_SHIFT;
27158+ info.threadstack_offset = offset;
27159+
27160+#ifdef CONFIG_PAX_PAGEEXEC
27161+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27162+ info.low_limit = 0x00110000UL;
27163+ info.high_limit = mm->start_code;
27164+
27165+#ifdef CONFIG_PAX_RANDMMAP
27166+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27167+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27168+#endif
27169+
27170+ if (info.low_limit < info.high_limit) {
27171+ addr = vm_unmapped_area(&info);
27172+ if (!IS_ERR_VALUE(addr))
27173+ return addr;
27174+ }
27175+ } else
27176+#endif
27177+
27178+ info.low_limit = mm->mmap_base;
27179+ info.high_limit = pax_task_size;
27180+
27181+ return vm_unmapped_area(&info);
27182+}
27183+
27184+unsigned long
27185+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27186+ const unsigned long len, const unsigned long pgoff,
27187+ const unsigned long flags)
27188+{
27189+ struct vm_area_struct *vma;
27190+ struct mm_struct *mm = current->mm;
27191+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27192+ struct vm_unmapped_area_info info;
27193+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27194+
27195+#ifdef CONFIG_PAX_SEGMEXEC
27196+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27197+ pax_task_size = SEGMEXEC_TASK_SIZE;
27198+#endif
27199+
27200+ pax_task_size -= PAGE_SIZE;
27201+
27202+ /* requested length too big for entire address space */
27203+ if (len > pax_task_size)
27204+ return -ENOMEM;
27205+
27206+ if (flags & MAP_FIXED)
27207+ return addr;
27208+
27209+#ifdef CONFIG_PAX_PAGEEXEC
27210+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27211+ goto bottomup;
27212+#endif
27213+
27214+#ifdef CONFIG_PAX_RANDMMAP
27215+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27216+#endif
27217+
27218+ /* requesting a specific address */
27219+ if (addr) {
27220+ addr = PAGE_ALIGN(addr);
27221+ if (pax_task_size - len >= addr) {
27222+ vma = find_vma(mm, addr);
27223+ if (check_heap_stack_gap(vma, addr, len, offset))
27224+ return addr;
27225+ }
27226+ }
27227+
27228+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27229+ info.length = len;
27230+ info.low_limit = PAGE_SIZE;
27231+ info.high_limit = mm->mmap_base;
27232+ info.align_mask = filp ? get_align_mask() : 0;
27233+ info.align_offset = pgoff << PAGE_SHIFT;
27234+ info.threadstack_offset = offset;
27235+
27236+ addr = vm_unmapped_area(&info);
27237+ if (!(addr & ~PAGE_MASK))
27238+ return addr;
27239+ VM_BUG_ON(addr != -ENOMEM);
27240+
27241+bottomup:
27242+ /*
27243+ * A failed mmap() very likely causes application failure,
27244+ * so fall back to the bottom-up function here. This scenario
27245+ * can happen with large stack limits and large mmap()
27246+ * allocations.
27247+ */
27248+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27249+}
27250diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27251index 30277e2..5664a29 100644
27252--- a/arch/x86/kernel/sys_x86_64.c
27253+++ b/arch/x86/kernel/sys_x86_64.c
27254@@ -81,8 +81,8 @@ out:
27255 return error;
27256 }
27257
27258-static void find_start_end(unsigned long flags, unsigned long *begin,
27259- unsigned long *end)
27260+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27261+ unsigned long *begin, unsigned long *end)
27262 {
27263 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27264 unsigned long new_begin;
27265@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27266 *begin = new_begin;
27267 }
27268 } else {
27269- *begin = current->mm->mmap_legacy_base;
27270+ *begin = mm->mmap_legacy_base;
27271 *end = TASK_SIZE;
27272 }
27273 }
27274@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27275 struct vm_area_struct *vma;
27276 struct vm_unmapped_area_info info;
27277 unsigned long begin, end;
27278+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27279
27280 if (flags & MAP_FIXED)
27281 return addr;
27282
27283- find_start_end(flags, &begin, &end);
27284+ find_start_end(mm, flags, &begin, &end);
27285
27286 if (len > end)
27287 return -ENOMEM;
27288
27289+#ifdef CONFIG_PAX_RANDMMAP
27290+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27291+#endif
27292+
27293 if (addr) {
27294 addr = PAGE_ALIGN(addr);
27295 vma = find_vma(mm, addr);
27296- if (end - len >= addr &&
27297- (!vma || addr + len <= vma->vm_start))
27298+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27299 return addr;
27300 }
27301
27302@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27303 info.high_limit = end;
27304 info.align_mask = filp ? get_align_mask() : 0;
27305 info.align_offset = pgoff << PAGE_SHIFT;
27306+ info.threadstack_offset = offset;
27307 return vm_unmapped_area(&info);
27308 }
27309
27310@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27311 struct mm_struct *mm = current->mm;
27312 unsigned long addr = addr0;
27313 struct vm_unmapped_area_info info;
27314+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27315
27316 /* requested length too big for entire address space */
27317 if (len > TASK_SIZE)
27318@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27319 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27320 goto bottomup;
27321
27322+#ifdef CONFIG_PAX_RANDMMAP
27323+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27324+#endif
27325+
27326 /* requesting a specific address */
27327 if (addr) {
27328 addr = PAGE_ALIGN(addr);
27329 vma = find_vma(mm, addr);
27330- if (TASK_SIZE - len >= addr &&
27331- (!vma || addr + len <= vma->vm_start))
27332+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27333 return addr;
27334 }
27335
27336@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27337 info.high_limit = mm->mmap_base;
27338 info.align_mask = filp ? get_align_mask() : 0;
27339 info.align_offset = pgoff << PAGE_SHIFT;
27340+ info.threadstack_offset = offset;
27341 addr = vm_unmapped_area(&info);
27342 if (!(addr & ~PAGE_MASK))
27343 return addr;
27344diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27345index 91a4496..bb87552 100644
27346--- a/arch/x86/kernel/tboot.c
27347+++ b/arch/x86/kernel/tboot.c
27348@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27349
27350 void tboot_shutdown(u32 shutdown_type)
27351 {
27352- void (*shutdown)(void);
27353+ void (* __noreturn shutdown)(void);
27354
27355 if (!tboot_enabled())
27356 return;
27357@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27358
27359 switch_to_tboot_pt();
27360
27361- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27362+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27363 shutdown();
27364
27365 /* should not reach here */
27366@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27367 return -ENODEV;
27368 }
27369
27370-static atomic_t ap_wfs_count;
27371+static atomic_unchecked_t ap_wfs_count;
27372
27373 static int tboot_wait_for_aps(int num_aps)
27374 {
27375@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27376 {
27377 switch (action) {
27378 case CPU_DYING:
27379- atomic_inc(&ap_wfs_count);
27380+ atomic_inc_unchecked(&ap_wfs_count);
27381 if (num_online_cpus() == 1)
27382- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27383+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27384 return NOTIFY_BAD;
27385 break;
27386 }
27387@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27388
27389 tboot_create_trampoline();
27390
27391- atomic_set(&ap_wfs_count, 0);
27392+ atomic_set_unchecked(&ap_wfs_count, 0);
27393 register_hotcpu_notifier(&tboot_cpu_notifier);
27394
27395 #ifdef CONFIG_DEBUG_FS
27396diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27397index bf7ef5c..59d0ac9 100644
27398--- a/arch/x86/kernel/time.c
27399+++ b/arch/x86/kernel/time.c
27400@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27401 {
27402 unsigned long pc = instruction_pointer(regs);
27403
27404- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27405+ if (!user_mode(regs) && in_lock_functions(pc)) {
27406 #ifdef CONFIG_FRAME_POINTER
27407- return *(unsigned long *)(regs->bp + sizeof(long));
27408+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27409 #else
27410 unsigned long *sp =
27411 (unsigned long *)kernel_stack_pointer(regs);
27412@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27413 * or above a saved flags. Eflags has bits 22-31 zero,
27414 * kernel addresses don't.
27415 */
27416+
27417+#ifdef CONFIG_PAX_KERNEXEC
27418+ return ktla_ktva(sp[0]);
27419+#else
27420 if (sp[0] >> 22)
27421 return sp[0];
27422 if (sp[1] >> 22)
27423 return sp[1];
27424 #endif
27425+
27426+#endif
27427 }
27428 return pc;
27429 }
27430diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27431index f7fec09..9991981 100644
27432--- a/arch/x86/kernel/tls.c
27433+++ b/arch/x86/kernel/tls.c
27434@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27435 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27436 return -EINVAL;
27437
27438+#ifdef CONFIG_PAX_SEGMEXEC
27439+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27440+ return -EINVAL;
27441+#endif
27442+
27443 set_tls_desc(p, idx, &info, 1);
27444
27445 return 0;
27446@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27447
27448 if (kbuf)
27449 info = kbuf;
27450- else if (__copy_from_user(infobuf, ubuf, count))
27451+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27452 return -EFAULT;
27453 else
27454 info = infobuf;
27455diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27456index 1c113db..287b42e 100644
27457--- a/arch/x86/kernel/tracepoint.c
27458+++ b/arch/x86/kernel/tracepoint.c
27459@@ -9,11 +9,11 @@
27460 #include <linux/atomic.h>
27461
27462 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27463-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27464+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27465 (unsigned long) trace_idt_table };
27466
27467 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27468-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27469+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27470
27471 static int trace_irq_vector_refcount;
27472 static DEFINE_MUTEX(irq_vector_mutex);
27473diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27474index f73b5d4..0adcc9a 100644
27475--- a/arch/x86/kernel/traps.c
27476+++ b/arch/x86/kernel/traps.c
27477@@ -66,7 +66,7 @@
27478 #include <asm/proto.h>
27479
27480 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27481-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27482+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27483 #else
27484 #include <asm/processor-flags.h>
27485 #include <asm/setup.h>
27486@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27487 #endif
27488
27489 /* Must be page-aligned because the real IDT is used in a fixmap. */
27490-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27491+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27492
27493 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27494 EXPORT_SYMBOL_GPL(used_vectors);
27495@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27496 }
27497
27498 static int __kprobes
27499-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27500+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27501 struct pt_regs *regs, long error_code)
27502 {
27503 #ifdef CONFIG_X86_32
27504- if (regs->flags & X86_VM_MASK) {
27505+ if (v8086_mode(regs)) {
27506 /*
27507 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27508 * On nmi (interrupt 2), do_trap should not be called.
27509@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27510 return -1;
27511 }
27512 #endif
27513- if (!user_mode(regs)) {
27514+ if (!user_mode_novm(regs)) {
27515 if (!fixup_exception(regs)) {
27516 tsk->thread.error_code = error_code;
27517 tsk->thread.trap_nr = trapnr;
27518+
27519+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27520+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27521+ str = "PAX: suspicious stack segment fault";
27522+#endif
27523+
27524 die(str, regs, error_code);
27525 }
27526+
27527+#ifdef CONFIG_PAX_REFCOUNT
27528+ if (trapnr == X86_TRAP_OF)
27529+ pax_report_refcount_overflow(regs);
27530+#endif
27531+
27532 return 0;
27533 }
27534
27535@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27536 }
27537
27538 static void __kprobes
27539-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27540+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27541 long error_code, siginfo_t *info)
27542 {
27543 struct task_struct *tsk = current;
27544@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27545 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27546 printk_ratelimit()) {
27547 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27548- tsk->comm, tsk->pid, str,
27549+ tsk->comm, task_pid_nr(tsk), str,
27550 regs->ip, regs->sp, error_code);
27551 print_vma_addr(" in ", regs->ip);
27552 pr_cont("\n");
27553@@ -251,6 +263,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
27554 tsk->thread.error_code = error_code;
27555 tsk->thread.trap_nr = X86_TRAP_DF;
27556
27557+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
27558+ if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
27559+ die("grsec: kernel stack overflow detected", regs, error_code);
27560+#endif
27561+
27562 #ifdef CONFIG_DOUBLEFAULT
27563 df_debug(regs, error_code);
27564 #endif
27565@@ -273,7 +290,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27566 conditional_sti(regs);
27567
27568 #ifdef CONFIG_X86_32
27569- if (regs->flags & X86_VM_MASK) {
27570+ if (v8086_mode(regs)) {
27571 local_irq_enable();
27572 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27573 goto exit;
27574@@ -281,18 +298,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27575 #endif
27576
27577 tsk = current;
27578- if (!user_mode(regs)) {
27579+ if (!user_mode_novm(regs)) {
27580 if (fixup_exception(regs))
27581 goto exit;
27582
27583 tsk->thread.error_code = error_code;
27584 tsk->thread.trap_nr = X86_TRAP_GP;
27585 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27586- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27587+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27588+
27589+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27590+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27591+ die("PAX: suspicious general protection fault", regs, error_code);
27592+ else
27593+#endif
27594+
27595 die("general protection fault", regs, error_code);
27596+ }
27597 goto exit;
27598 }
27599
27600+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27601+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27602+ struct mm_struct *mm = tsk->mm;
27603+ unsigned long limit;
27604+
27605+ down_write(&mm->mmap_sem);
27606+ limit = mm->context.user_cs_limit;
27607+ if (limit < TASK_SIZE) {
27608+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27609+ up_write(&mm->mmap_sem);
27610+ return;
27611+ }
27612+ up_write(&mm->mmap_sem);
27613+ }
27614+#endif
27615+
27616 tsk->thread.error_code = error_code;
27617 tsk->thread.trap_nr = X86_TRAP_GP;
27618
27619@@ -453,7 +494,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27620 /* It's safe to allow irq's after DR6 has been saved */
27621 preempt_conditional_sti(regs);
27622
27623- if (regs->flags & X86_VM_MASK) {
27624+ if (v8086_mode(regs)) {
27625 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27626 X86_TRAP_DB);
27627 preempt_conditional_cli(regs);
27628@@ -468,7 +509,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27629 * We already checked v86 mode above, so we can check for kernel mode
27630 * by just checking the CPL of CS.
27631 */
27632- if ((dr6 & DR_STEP) && !user_mode(regs)) {
27633+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27634 tsk->thread.debugreg6 &= ~DR_STEP;
27635 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27636 regs->flags &= ~X86_EFLAGS_TF;
27637@@ -500,7 +541,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27638 return;
27639 conditional_sti(regs);
27640
27641- if (!user_mode_vm(regs))
27642+ if (!user_mode(regs))
27643 {
27644 if (!fixup_exception(regs)) {
27645 task->thread.error_code = error_code;
27646diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27647index 57e5ce1..20b0040 100644
27648--- a/arch/x86/kernel/tsc.c
27649+++ b/arch/x86/kernel/tsc.c
27650@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27651 */
27652 smp_wmb();
27653
27654- ACCESS_ONCE(c2n->head) = data;
27655+ ACCESS_ONCE_RW(c2n->head) = data;
27656 }
27657
27658 /*
27659diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27660index 2ed8459..7cf329f 100644
27661--- a/arch/x86/kernel/uprobes.c
27662+++ b/arch/x86/kernel/uprobes.c
27663@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27664 int ret = NOTIFY_DONE;
27665
27666 /* We are only interested in userspace traps */
27667- if (regs && !user_mode_vm(regs))
27668+ if (regs && !user_mode(regs))
27669 return NOTIFY_DONE;
27670
27671 switch (val) {
27672@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27673
27674 if (ncopied != rasize) {
27675 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27676- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27677+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27678
27679 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27680 }
27681diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27682index b9242ba..50c5edd 100644
27683--- a/arch/x86/kernel/verify_cpu.S
27684+++ b/arch/x86/kernel/verify_cpu.S
27685@@ -20,6 +20,7 @@
27686 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27687 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27688 * arch/x86/kernel/head_32.S: processor startup
27689+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27690 *
27691 * verify_cpu, returns the status of longmode and SSE in register %eax.
27692 * 0: Success 1: Failure
27693diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27694index e8edcf5..27f9344 100644
27695--- a/arch/x86/kernel/vm86_32.c
27696+++ b/arch/x86/kernel/vm86_32.c
27697@@ -44,6 +44,7 @@
27698 #include <linux/ptrace.h>
27699 #include <linux/audit.h>
27700 #include <linux/stddef.h>
27701+#include <linux/grsecurity.h>
27702
27703 #include <asm/uaccess.h>
27704 #include <asm/io.h>
27705@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27706 do_exit(SIGSEGV);
27707 }
27708
27709- tss = &per_cpu(init_tss, get_cpu());
27710+ tss = init_tss + get_cpu();
27711 current->thread.sp0 = current->thread.saved_sp0;
27712 current->thread.sysenter_cs = __KERNEL_CS;
27713 load_sp0(tss, &current->thread);
27714@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27715
27716 if (tsk->thread.saved_sp0)
27717 return -EPERM;
27718+
27719+#ifdef CONFIG_GRKERNSEC_VM86
27720+ if (!capable(CAP_SYS_RAWIO)) {
27721+ gr_handle_vm86();
27722+ return -EPERM;
27723+ }
27724+#endif
27725+
27726 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27727 offsetof(struct kernel_vm86_struct, vm86plus) -
27728 sizeof(info.regs));
27729@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27730 int tmp;
27731 struct vm86plus_struct __user *v86;
27732
27733+#ifdef CONFIG_GRKERNSEC_VM86
27734+ if (!capable(CAP_SYS_RAWIO)) {
27735+ gr_handle_vm86();
27736+ return -EPERM;
27737+ }
27738+#endif
27739+
27740 tsk = current;
27741 switch (cmd) {
27742 case VM86_REQUEST_IRQ:
27743@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27744 tsk->thread.saved_fs = info->regs32->fs;
27745 tsk->thread.saved_gs = get_user_gs(info->regs32);
27746
27747- tss = &per_cpu(init_tss, get_cpu());
27748+ tss = init_tss + get_cpu();
27749 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27750 if (cpu_has_sep)
27751 tsk->thread.sysenter_cs = 0;
27752@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27753 goto cannot_handle;
27754 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27755 goto cannot_handle;
27756- intr_ptr = (unsigned long __user *) (i << 2);
27757+ intr_ptr = (__force unsigned long __user *) (i << 2);
27758 if (get_user(segoffs, intr_ptr))
27759 goto cannot_handle;
27760 if ((segoffs >> 16) == BIOSSEG)
27761diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27762index 49edf2d..c0d1362 100644
27763--- a/arch/x86/kernel/vmlinux.lds.S
27764+++ b/arch/x86/kernel/vmlinux.lds.S
27765@@ -26,6 +26,13 @@
27766 #include <asm/page_types.h>
27767 #include <asm/cache.h>
27768 #include <asm/boot.h>
27769+#include <asm/segment.h>
27770+
27771+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27772+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27773+#else
27774+#define __KERNEL_TEXT_OFFSET 0
27775+#endif
27776
27777 #undef i386 /* in case the preprocessor is a 32bit one */
27778
27779@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27780
27781 PHDRS {
27782 text PT_LOAD FLAGS(5); /* R_E */
27783+#ifdef CONFIG_X86_32
27784+ module PT_LOAD FLAGS(5); /* R_E */
27785+#endif
27786+#ifdef CONFIG_XEN
27787+ rodata PT_LOAD FLAGS(5); /* R_E */
27788+#else
27789+ rodata PT_LOAD FLAGS(4); /* R__ */
27790+#endif
27791 data PT_LOAD FLAGS(6); /* RW_ */
27792-#ifdef CONFIG_X86_64
27793+ init.begin PT_LOAD FLAGS(6); /* RW_ */
27794 #ifdef CONFIG_SMP
27795 percpu PT_LOAD FLAGS(6); /* RW_ */
27796 #endif
27797+ text.init PT_LOAD FLAGS(5); /* R_E */
27798+ text.exit PT_LOAD FLAGS(5); /* R_E */
27799 init PT_LOAD FLAGS(7); /* RWE */
27800-#endif
27801 note PT_NOTE FLAGS(0); /* ___ */
27802 }
27803
27804 SECTIONS
27805 {
27806 #ifdef CONFIG_X86_32
27807- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27808- phys_startup_32 = startup_32 - LOAD_OFFSET;
27809+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27810 #else
27811- . = __START_KERNEL;
27812- phys_startup_64 = startup_64 - LOAD_OFFSET;
27813+ . = __START_KERNEL;
27814 #endif
27815
27816 /* Text and read-only data */
27817- .text : AT(ADDR(.text) - LOAD_OFFSET) {
27818- _text = .;
27819+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27820 /* bootstrapping code */
27821+#ifdef CONFIG_X86_32
27822+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27823+#else
27824+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27825+#endif
27826+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27827+ _text = .;
27828 HEAD_TEXT
27829 . = ALIGN(8);
27830 _stext = .;
27831@@ -104,13 +124,47 @@ SECTIONS
27832 IRQENTRY_TEXT
27833 *(.fixup)
27834 *(.gnu.warning)
27835- /* End of text section */
27836- _etext = .;
27837 } :text = 0x9090
27838
27839- NOTES :text :note
27840+ . += __KERNEL_TEXT_OFFSET;
27841
27842- EXCEPTION_TABLE(16) :text = 0x9090
27843+#ifdef CONFIG_X86_32
27844+ . = ALIGN(PAGE_SIZE);
27845+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27846+
27847+#ifdef CONFIG_PAX_KERNEXEC
27848+ MODULES_EXEC_VADDR = .;
27849+ BYTE(0)
27850+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27851+ . = ALIGN(HPAGE_SIZE) - 1;
27852+ MODULES_EXEC_END = .;
27853+#endif
27854+
27855+ } :module
27856+#endif
27857+
27858+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27859+ /* End of text section */
27860+ BYTE(0)
27861+ _etext = . - __KERNEL_TEXT_OFFSET;
27862+ }
27863+
27864+#ifdef CONFIG_X86_32
27865+ . = ALIGN(PAGE_SIZE);
27866+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27867+ . = ALIGN(PAGE_SIZE);
27868+ *(.empty_zero_page)
27869+ *(.initial_pg_fixmap)
27870+ *(.initial_pg_pmd)
27871+ *(.initial_page_table)
27872+ *(.swapper_pg_dir)
27873+ } :rodata
27874+#endif
27875+
27876+ . = ALIGN(PAGE_SIZE);
27877+ NOTES :rodata :note
27878+
27879+ EXCEPTION_TABLE(16) :rodata
27880
27881 #if defined(CONFIG_DEBUG_RODATA)
27882 /* .text should occupy whole number of pages */
27883@@ -122,16 +176,20 @@ SECTIONS
27884
27885 /* Data */
27886 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27887+
27888+#ifdef CONFIG_PAX_KERNEXEC
27889+ . = ALIGN(HPAGE_SIZE);
27890+#else
27891+ . = ALIGN(PAGE_SIZE);
27892+#endif
27893+
27894 /* Start of data section */
27895 _sdata = .;
27896
27897 /* init_task */
27898 INIT_TASK_DATA(THREAD_SIZE)
27899
27900-#ifdef CONFIG_X86_32
27901- /* 32 bit has nosave before _edata */
27902 NOSAVE_DATA
27903-#endif
27904
27905 PAGE_ALIGNED_DATA(PAGE_SIZE)
27906
27907@@ -174,12 +232,19 @@ SECTIONS
27908 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
27909
27910 /* Init code and data - will be freed after init */
27911- . = ALIGN(PAGE_SIZE);
27912 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27913+ BYTE(0)
27914+
27915+#ifdef CONFIG_PAX_KERNEXEC
27916+ . = ALIGN(HPAGE_SIZE);
27917+#else
27918+ . = ALIGN(PAGE_SIZE);
27919+#endif
27920+
27921 __init_begin = .; /* paired with __init_end */
27922- }
27923+ } :init.begin
27924
27925-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27926+#ifdef CONFIG_SMP
27927 /*
27928 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27929 * output PHDR, so the next output section - .init.text - should
27930@@ -188,12 +253,27 @@ SECTIONS
27931 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27932 #endif
27933
27934- INIT_TEXT_SECTION(PAGE_SIZE)
27935-#ifdef CONFIG_X86_64
27936- :init
27937-#endif
27938+ . = ALIGN(PAGE_SIZE);
27939+ init_begin = .;
27940+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27941+ VMLINUX_SYMBOL(_sinittext) = .;
27942+ INIT_TEXT
27943+ VMLINUX_SYMBOL(_einittext) = .;
27944+ . = ALIGN(PAGE_SIZE);
27945+ } :text.init
27946
27947- INIT_DATA_SECTION(16)
27948+ /*
27949+ * .exit.text is discard at runtime, not link time, to deal with
27950+ * references from .altinstructions and .eh_frame
27951+ */
27952+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27953+ EXIT_TEXT
27954+ . = ALIGN(16);
27955+ } :text.exit
27956+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27957+
27958+ . = ALIGN(PAGE_SIZE);
27959+ INIT_DATA_SECTION(16) :init
27960
27961 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27962 __x86_cpu_dev_start = .;
27963@@ -264,19 +344,12 @@ SECTIONS
27964 }
27965
27966 . = ALIGN(8);
27967- /*
27968- * .exit.text is discard at runtime, not link time, to deal with
27969- * references from .altinstructions and .eh_frame
27970- */
27971- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27972- EXIT_TEXT
27973- }
27974
27975 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27976 EXIT_DATA
27977 }
27978
27979-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27980+#ifndef CONFIG_SMP
27981 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27982 #endif
27983
27984@@ -295,16 +368,10 @@ SECTIONS
27985 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27986 __smp_locks = .;
27987 *(.smp_locks)
27988- . = ALIGN(PAGE_SIZE);
27989 __smp_locks_end = .;
27990+ . = ALIGN(PAGE_SIZE);
27991 }
27992
27993-#ifdef CONFIG_X86_64
27994- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27995- NOSAVE_DATA
27996- }
27997-#endif
27998-
27999 /* BSS */
28000 . = ALIGN(PAGE_SIZE);
28001 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28002@@ -320,6 +387,7 @@ SECTIONS
28003 __brk_base = .;
28004 . += 64 * 1024; /* 64k alignment slop space */
28005 *(.brk_reservation) /* areas brk users have reserved */
28006+ . = ALIGN(HPAGE_SIZE);
28007 __brk_limit = .;
28008 }
28009
28010@@ -346,13 +414,12 @@ SECTIONS
28011 * for the boot processor.
28012 */
28013 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28014-INIT_PER_CPU(gdt_page);
28015 INIT_PER_CPU(irq_stack_union);
28016
28017 /*
28018 * Build-time check on the image size:
28019 */
28020-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28021+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28022 "kernel image bigger than KERNEL_IMAGE_SIZE");
28023
28024 #ifdef CONFIG_SMP
28025diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28026index 8b3b3eb..9395aa9 100644
28027--- a/arch/x86/kernel/vsyscall_64.c
28028+++ b/arch/x86/kernel/vsyscall_64.c
28029@@ -54,15 +54,13 @@
28030
28031 DEFINE_VVAR(int, vgetcpu_mode);
28032
28033-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28034+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28035
28036 static int __init vsyscall_setup(char *str)
28037 {
28038 if (str) {
28039 if (!strcmp("emulate", str))
28040 vsyscall_mode = EMULATE;
28041- else if (!strcmp("native", str))
28042- vsyscall_mode = NATIVE;
28043 else if (!strcmp("none", str))
28044 vsyscall_mode = NONE;
28045 else
28046@@ -279,8 +277,7 @@ do_ret:
28047 return true;
28048
28049 sigsegv:
28050- force_sig(SIGSEGV, current);
28051- return true;
28052+ do_group_exit(SIGKILL);
28053 }
28054
28055 /*
28056@@ -332,10 +329,7 @@ void __init map_vsyscall(void)
28057 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28058 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
28059
28060- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
28061- vsyscall_mode == NATIVE
28062- ? PAGE_KERNEL_VSYSCALL
28063- : PAGE_KERNEL_VVAR);
28064+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28065 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
28066 (unsigned long)VSYSCALL_START);
28067
28068diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28069index 04068192..4d75aa6 100644
28070--- a/arch/x86/kernel/x8664_ksyms_64.c
28071+++ b/arch/x86/kernel/x8664_ksyms_64.c
28072@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28073 EXPORT_SYMBOL(copy_user_generic_unrolled);
28074 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28075 EXPORT_SYMBOL(__copy_user_nocache);
28076-EXPORT_SYMBOL(_copy_from_user);
28077-EXPORT_SYMBOL(_copy_to_user);
28078
28079 EXPORT_SYMBOL(copy_page);
28080 EXPORT_SYMBOL(clear_page);
28081@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28082 EXPORT_SYMBOL(___preempt_schedule_context);
28083 #endif
28084 #endif
28085+
28086+#ifdef CONFIG_PAX_PER_CPU_PGD
28087+EXPORT_SYMBOL(cpu_pgd);
28088+#endif
28089diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28090index e48b674..a451dd9 100644
28091--- a/arch/x86/kernel/x86_init.c
28092+++ b/arch/x86/kernel/x86_init.c
28093@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28094 static void default_nmi_init(void) { };
28095 static int default_i8042_detect(void) { return 1; };
28096
28097-struct x86_platform_ops x86_platform = {
28098+struct x86_platform_ops x86_platform __read_only = {
28099 .calibrate_tsc = native_calibrate_tsc,
28100 .get_wallclock = mach_get_cmos_time,
28101 .set_wallclock = mach_set_rtc_mmss,
28102@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28103 EXPORT_SYMBOL_GPL(x86_platform);
28104
28105 #if defined(CONFIG_PCI_MSI)
28106-struct x86_msi_ops x86_msi = {
28107+struct x86_msi_ops x86_msi __read_only = {
28108 .setup_msi_irqs = native_setup_msi_irqs,
28109 .compose_msi_msg = native_compose_msi_msg,
28110 .teardown_msi_irq = native_teardown_msi_irq,
28111@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28112 }
28113 #endif
28114
28115-struct x86_io_apic_ops x86_io_apic_ops = {
28116+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28117 .init = native_io_apic_init_mappings,
28118 .read = native_io_apic_read,
28119 .write = native_io_apic_write,
28120diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28121index a4b451c..8dfe1ad 100644
28122--- a/arch/x86/kernel/xsave.c
28123+++ b/arch/x86/kernel/xsave.c
28124@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28125
28126 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28127 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28128- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28129+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28130
28131 if (!use_xsave())
28132 return err;
28133
28134- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28135+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28136
28137 /*
28138 * Read the xstate_bv which we copied (directly from the cpu or
28139 * from the state in task struct) to the user buffers.
28140 */
28141- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28142+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28143
28144 /*
28145 * For legacy compatible, we always set FP/SSE bits in the bit
28146@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28147 */
28148 xstate_bv |= XSTATE_FPSSE;
28149
28150- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28151+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28152
28153 return err;
28154 }
28155@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28156 {
28157 int err;
28158
28159+ buf = (struct xsave_struct __user *)____m(buf);
28160 if (use_xsave())
28161 err = xsave_user(buf);
28162 else if (use_fxsr())
28163@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28164 */
28165 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28166 {
28167+ buf = (void __user *)____m(buf);
28168 if (use_xsave()) {
28169 if ((unsigned long)buf % 64 || fx_only) {
28170 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28171diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28172index f47a104..5ce59a8 100644
28173--- a/arch/x86/kvm/cpuid.c
28174+++ b/arch/x86/kvm/cpuid.c
28175@@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28176 struct kvm_cpuid2 *cpuid,
28177 struct kvm_cpuid_entry2 __user *entries)
28178 {
28179- int r;
28180+ int r, i;
28181
28182 r = -E2BIG;
28183 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28184 goto out;
28185 r = -EFAULT;
28186- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28187- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28188+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28189 goto out;
28190+ for (i = 0; i < cpuid->nent; ++i) {
28191+ struct kvm_cpuid_entry2 cpuid_entry;
28192+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28193+ goto out;
28194+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28195+ }
28196 vcpu->arch.cpuid_nent = cpuid->nent;
28197 kvm_apic_set_version(vcpu);
28198 kvm_x86_ops->cpuid_update(vcpu);
28199@@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28200 struct kvm_cpuid2 *cpuid,
28201 struct kvm_cpuid_entry2 __user *entries)
28202 {
28203- int r;
28204+ int r, i;
28205
28206 r = -E2BIG;
28207 if (cpuid->nent < vcpu->arch.cpuid_nent)
28208 goto out;
28209 r = -EFAULT;
28210- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28211- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28212+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28213 goto out;
28214+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28215+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28216+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28217+ goto out;
28218+ }
28219 return 0;
28220
28221 out:
28222diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28223index 0069118..c28ec0a 100644
28224--- a/arch/x86/kvm/lapic.c
28225+++ b/arch/x86/kvm/lapic.c
28226@@ -55,7 +55,7 @@
28227 #define APIC_BUS_CYCLE_NS 1
28228
28229 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28230-#define apic_debug(fmt, arg...)
28231+#define apic_debug(fmt, arg...) do {} while (0)
28232
28233 #define APIC_LVT_NUM 6
28234 /* 14 is the version for Xeon and Pentium 8.4.8*/
28235diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28236index 123efd3..ad7726e 100644
28237--- a/arch/x86/kvm/paging_tmpl.h
28238+++ b/arch/x86/kvm/paging_tmpl.h
28239@@ -331,7 +331,7 @@ retry_walk:
28240 if (unlikely(kvm_is_error_hva(host_addr)))
28241 goto error;
28242
28243- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28244+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28245 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28246 goto error;
28247 walker->ptep_user[walker->level - 1] = ptep_user;
28248diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28249index 7f4f9c2..67b1db0 100644
28250--- a/arch/x86/kvm/svm.c
28251+++ b/arch/x86/kvm/svm.c
28252@@ -3535,7 +3535,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28253 int cpu = raw_smp_processor_id();
28254
28255 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28256+
28257+ pax_open_kernel();
28258 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28259+ pax_close_kernel();
28260+
28261 load_TR_desc();
28262 }
28263
28264@@ -3936,6 +3940,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28265 #endif
28266 #endif
28267
28268+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28269+ __set_fs(current_thread_info()->addr_limit);
28270+#endif
28271+
28272 reload_tss(vcpu);
28273
28274 local_irq_disable();
28275diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28276index 138ceff..2e584f0 100644
28277--- a/arch/x86/kvm/vmx.c
28278+++ b/arch/x86/kvm/vmx.c
28279@@ -1339,12 +1339,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28280 #endif
28281 }
28282
28283-static void vmcs_clear_bits(unsigned long field, u32 mask)
28284+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28285 {
28286 vmcs_writel(field, vmcs_readl(field) & ~mask);
28287 }
28288
28289-static void vmcs_set_bits(unsigned long field, u32 mask)
28290+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28291 {
28292 vmcs_writel(field, vmcs_readl(field) | mask);
28293 }
28294@@ -1604,7 +1604,11 @@ static void reload_tss(void)
28295 struct desc_struct *descs;
28296
28297 descs = (void *)gdt->address;
28298+
28299+ pax_open_kernel();
28300 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28301+ pax_close_kernel();
28302+
28303 load_TR_desc();
28304 }
28305
28306@@ -1832,6 +1836,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28307 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28308 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28309
28310+#ifdef CONFIG_PAX_PER_CPU_PGD
28311+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28312+#endif
28313+
28314 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28315 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28316 vmx->loaded_vmcs->cpu = cpu;
28317@@ -2121,7 +2129,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28318 * reads and returns guest's timestamp counter "register"
28319 * guest_tsc = host_tsc + tsc_offset -- 21.3
28320 */
28321-static u64 guest_read_tsc(void)
28322+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28323 {
28324 u64 host_tsc, tsc_offset;
28325
28326@@ -3093,8 +3101,11 @@ static __init int hardware_setup(void)
28327 if (!cpu_has_vmx_flexpriority())
28328 flexpriority_enabled = 0;
28329
28330- if (!cpu_has_vmx_tpr_shadow())
28331- kvm_x86_ops->update_cr8_intercept = NULL;
28332+ if (!cpu_has_vmx_tpr_shadow()) {
28333+ pax_open_kernel();
28334+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28335+ pax_close_kernel();
28336+ }
28337
28338 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28339 kvm_disable_largepages();
28340@@ -3105,13 +3116,15 @@ static __init int hardware_setup(void)
28341 if (!cpu_has_vmx_apicv())
28342 enable_apicv = 0;
28343
28344+ pax_open_kernel();
28345 if (enable_apicv)
28346- kvm_x86_ops->update_cr8_intercept = NULL;
28347+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28348 else {
28349- kvm_x86_ops->hwapic_irr_update = NULL;
28350- kvm_x86_ops->deliver_posted_interrupt = NULL;
28351- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28352+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28353+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28354+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28355 }
28356+ pax_close_kernel();
28357
28358 if (nested)
28359 nested_vmx_setup_ctls_msrs();
28360@@ -4235,7 +4248,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28361
28362 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28363 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28364+
28365+#ifndef CONFIG_PAX_PER_CPU_PGD
28366 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28367+#endif
28368
28369 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28370 #ifdef CONFIG_X86_64
28371@@ -4257,7 +4273,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28372 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28373 vmx->host_idt_base = dt.address;
28374
28375- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28376+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28377
28378 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28379 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28380@@ -7333,6 +7349,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28381 "jmp 2f \n\t"
28382 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28383 "2: "
28384+
28385+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28386+ "ljmp %[cs],$3f\n\t"
28387+ "3: "
28388+#endif
28389+
28390 /* Save guest registers, load host registers, keep flags */
28391 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28392 "pop %0 \n\t"
28393@@ -7385,6 +7407,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28394 #endif
28395 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28396 [wordsize]"i"(sizeof(ulong))
28397+
28398+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28399+ ,[cs]"i"(__KERNEL_CS)
28400+#endif
28401+
28402 : "cc", "memory"
28403 #ifdef CONFIG_X86_64
28404 , "rax", "rbx", "rdi", "rsi"
28405@@ -7398,7 +7425,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28406 if (debugctlmsr)
28407 update_debugctlmsr(debugctlmsr);
28408
28409-#ifndef CONFIG_X86_64
28410+#ifdef CONFIG_X86_32
28411 /*
28412 * The sysexit path does not restore ds/es, so we must set them to
28413 * a reasonable value ourselves.
28414@@ -7407,8 +7434,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28415 * may be executed in interrupt context, which saves and restore segments
28416 * around it, nullifying its effect.
28417 */
28418- loadsegment(ds, __USER_DS);
28419- loadsegment(es, __USER_DS);
28420+ loadsegment(ds, __KERNEL_DS);
28421+ loadsegment(es, __KERNEL_DS);
28422+ loadsegment(ss, __KERNEL_DS);
28423+
28424+#ifdef CONFIG_PAX_KERNEXEC
28425+ loadsegment(fs, __KERNEL_PERCPU);
28426+#endif
28427+
28428+#ifdef CONFIG_PAX_MEMORY_UDEREF
28429+ __set_fs(current_thread_info()->addr_limit);
28430+#endif
28431+
28432 #endif
28433
28434 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28435diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28436index 20316c6..9b3dddc 100644
28437--- a/arch/x86/kvm/x86.c
28438+++ b/arch/x86/kvm/x86.c
28439@@ -1822,8 +1822,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28440 {
28441 struct kvm *kvm = vcpu->kvm;
28442 int lm = is_long_mode(vcpu);
28443- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28444- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28445+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28446+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28447 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28448 : kvm->arch.xen_hvm_config.blob_size_32;
28449 u32 page_num = data & ~PAGE_MASK;
28450@@ -2738,6 +2738,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28451 if (n < msr_list.nmsrs)
28452 goto out;
28453 r = -EFAULT;
28454+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28455+ goto out;
28456 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28457 num_msrs_to_save * sizeof(u32)))
28458 goto out;
28459@@ -5574,7 +5576,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28460 };
28461 #endif
28462
28463-int kvm_arch_init(void *opaque)
28464+int kvm_arch_init(const void *opaque)
28465 {
28466 int r;
28467 struct kvm_x86_ops *ops = opaque;
28468diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28469index aae9413..d11e829 100644
28470--- a/arch/x86/lguest/boot.c
28471+++ b/arch/x86/lguest/boot.c
28472@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28473 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28474 * Launcher to reboot us.
28475 */
28476-static void lguest_restart(char *reason)
28477+static __noreturn void lguest_restart(char *reason)
28478 {
28479 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28480+ BUG();
28481 }
28482
28483 /*G:050
28484diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28485index 00933d5..3a64af9 100644
28486--- a/arch/x86/lib/atomic64_386_32.S
28487+++ b/arch/x86/lib/atomic64_386_32.S
28488@@ -48,6 +48,10 @@ BEGIN(read)
28489 movl (v), %eax
28490 movl 4(v), %edx
28491 RET_ENDP
28492+BEGIN(read_unchecked)
28493+ movl (v), %eax
28494+ movl 4(v), %edx
28495+RET_ENDP
28496 #undef v
28497
28498 #define v %esi
28499@@ -55,6 +59,10 @@ BEGIN(set)
28500 movl %ebx, (v)
28501 movl %ecx, 4(v)
28502 RET_ENDP
28503+BEGIN(set_unchecked)
28504+ movl %ebx, (v)
28505+ movl %ecx, 4(v)
28506+RET_ENDP
28507 #undef v
28508
28509 #define v %esi
28510@@ -70,6 +78,20 @@ RET_ENDP
28511 BEGIN(add)
28512 addl %eax, (v)
28513 adcl %edx, 4(v)
28514+
28515+#ifdef CONFIG_PAX_REFCOUNT
28516+ jno 0f
28517+ subl %eax, (v)
28518+ sbbl %edx, 4(v)
28519+ int $4
28520+0:
28521+ _ASM_EXTABLE(0b, 0b)
28522+#endif
28523+
28524+RET_ENDP
28525+BEGIN(add_unchecked)
28526+ addl %eax, (v)
28527+ adcl %edx, 4(v)
28528 RET_ENDP
28529 #undef v
28530
28531@@ -77,6 +99,24 @@ RET_ENDP
28532 BEGIN(add_return)
28533 addl (v), %eax
28534 adcl 4(v), %edx
28535+
28536+#ifdef CONFIG_PAX_REFCOUNT
28537+ into
28538+1234:
28539+ _ASM_EXTABLE(1234b, 2f)
28540+#endif
28541+
28542+ movl %eax, (v)
28543+ movl %edx, 4(v)
28544+
28545+#ifdef CONFIG_PAX_REFCOUNT
28546+2:
28547+#endif
28548+
28549+RET_ENDP
28550+BEGIN(add_return_unchecked)
28551+ addl (v), %eax
28552+ adcl 4(v), %edx
28553 movl %eax, (v)
28554 movl %edx, 4(v)
28555 RET_ENDP
28556@@ -86,6 +126,20 @@ RET_ENDP
28557 BEGIN(sub)
28558 subl %eax, (v)
28559 sbbl %edx, 4(v)
28560+
28561+#ifdef CONFIG_PAX_REFCOUNT
28562+ jno 0f
28563+ addl %eax, (v)
28564+ adcl %edx, 4(v)
28565+ int $4
28566+0:
28567+ _ASM_EXTABLE(0b, 0b)
28568+#endif
28569+
28570+RET_ENDP
28571+BEGIN(sub_unchecked)
28572+ subl %eax, (v)
28573+ sbbl %edx, 4(v)
28574 RET_ENDP
28575 #undef v
28576
28577@@ -96,6 +150,27 @@ BEGIN(sub_return)
28578 sbbl $0, %edx
28579 addl (v), %eax
28580 adcl 4(v), %edx
28581+
28582+#ifdef CONFIG_PAX_REFCOUNT
28583+ into
28584+1234:
28585+ _ASM_EXTABLE(1234b, 2f)
28586+#endif
28587+
28588+ movl %eax, (v)
28589+ movl %edx, 4(v)
28590+
28591+#ifdef CONFIG_PAX_REFCOUNT
28592+2:
28593+#endif
28594+
28595+RET_ENDP
28596+BEGIN(sub_return_unchecked)
28597+ negl %edx
28598+ negl %eax
28599+ sbbl $0, %edx
28600+ addl (v), %eax
28601+ adcl 4(v), %edx
28602 movl %eax, (v)
28603 movl %edx, 4(v)
28604 RET_ENDP
28605@@ -105,6 +180,20 @@ RET_ENDP
28606 BEGIN(inc)
28607 addl $1, (v)
28608 adcl $0, 4(v)
28609+
28610+#ifdef CONFIG_PAX_REFCOUNT
28611+ jno 0f
28612+ subl $1, (v)
28613+ sbbl $0, 4(v)
28614+ int $4
28615+0:
28616+ _ASM_EXTABLE(0b, 0b)
28617+#endif
28618+
28619+RET_ENDP
28620+BEGIN(inc_unchecked)
28621+ addl $1, (v)
28622+ adcl $0, 4(v)
28623 RET_ENDP
28624 #undef v
28625
28626@@ -114,6 +203,26 @@ BEGIN(inc_return)
28627 movl 4(v), %edx
28628 addl $1, %eax
28629 adcl $0, %edx
28630+
28631+#ifdef CONFIG_PAX_REFCOUNT
28632+ into
28633+1234:
28634+ _ASM_EXTABLE(1234b, 2f)
28635+#endif
28636+
28637+ movl %eax, (v)
28638+ movl %edx, 4(v)
28639+
28640+#ifdef CONFIG_PAX_REFCOUNT
28641+2:
28642+#endif
28643+
28644+RET_ENDP
28645+BEGIN(inc_return_unchecked)
28646+ movl (v), %eax
28647+ movl 4(v), %edx
28648+ addl $1, %eax
28649+ adcl $0, %edx
28650 movl %eax, (v)
28651 movl %edx, 4(v)
28652 RET_ENDP
28653@@ -123,6 +232,20 @@ RET_ENDP
28654 BEGIN(dec)
28655 subl $1, (v)
28656 sbbl $0, 4(v)
28657+
28658+#ifdef CONFIG_PAX_REFCOUNT
28659+ jno 0f
28660+ addl $1, (v)
28661+ adcl $0, 4(v)
28662+ int $4
28663+0:
28664+ _ASM_EXTABLE(0b, 0b)
28665+#endif
28666+
28667+RET_ENDP
28668+BEGIN(dec_unchecked)
28669+ subl $1, (v)
28670+ sbbl $0, 4(v)
28671 RET_ENDP
28672 #undef v
28673
28674@@ -132,6 +255,26 @@ BEGIN(dec_return)
28675 movl 4(v), %edx
28676 subl $1, %eax
28677 sbbl $0, %edx
28678+
28679+#ifdef CONFIG_PAX_REFCOUNT
28680+ into
28681+1234:
28682+ _ASM_EXTABLE(1234b, 2f)
28683+#endif
28684+
28685+ movl %eax, (v)
28686+ movl %edx, 4(v)
28687+
28688+#ifdef CONFIG_PAX_REFCOUNT
28689+2:
28690+#endif
28691+
28692+RET_ENDP
28693+BEGIN(dec_return_unchecked)
28694+ movl (v), %eax
28695+ movl 4(v), %edx
28696+ subl $1, %eax
28697+ sbbl $0, %edx
28698 movl %eax, (v)
28699 movl %edx, 4(v)
28700 RET_ENDP
28701@@ -143,6 +286,13 @@ BEGIN(add_unless)
28702 adcl %edx, %edi
28703 addl (v), %eax
28704 adcl 4(v), %edx
28705+
28706+#ifdef CONFIG_PAX_REFCOUNT
28707+ into
28708+1234:
28709+ _ASM_EXTABLE(1234b, 2f)
28710+#endif
28711+
28712 cmpl %eax, %ecx
28713 je 3f
28714 1:
28715@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28716 1:
28717 addl $1, %eax
28718 adcl $0, %edx
28719+
28720+#ifdef CONFIG_PAX_REFCOUNT
28721+ into
28722+1234:
28723+ _ASM_EXTABLE(1234b, 2f)
28724+#endif
28725+
28726 movl %eax, (v)
28727 movl %edx, 4(v)
28728 movl $1, %eax
28729@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28730 movl 4(v), %edx
28731 subl $1, %eax
28732 sbbl $0, %edx
28733+
28734+#ifdef CONFIG_PAX_REFCOUNT
28735+ into
28736+1234:
28737+ _ASM_EXTABLE(1234b, 1f)
28738+#endif
28739+
28740 js 1f
28741 movl %eax, (v)
28742 movl %edx, 4(v)
28743diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28744index f5cc9eb..51fa319 100644
28745--- a/arch/x86/lib/atomic64_cx8_32.S
28746+++ b/arch/x86/lib/atomic64_cx8_32.S
28747@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28748 CFI_STARTPROC
28749
28750 read64 %ecx
28751+ pax_force_retaddr
28752 ret
28753 CFI_ENDPROC
28754 ENDPROC(atomic64_read_cx8)
28755
28756+ENTRY(atomic64_read_unchecked_cx8)
28757+ CFI_STARTPROC
28758+
28759+ read64 %ecx
28760+ pax_force_retaddr
28761+ ret
28762+ CFI_ENDPROC
28763+ENDPROC(atomic64_read_unchecked_cx8)
28764+
28765 ENTRY(atomic64_set_cx8)
28766 CFI_STARTPROC
28767
28768@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28769 cmpxchg8b (%esi)
28770 jne 1b
28771
28772+ pax_force_retaddr
28773 ret
28774 CFI_ENDPROC
28775 ENDPROC(atomic64_set_cx8)
28776
28777+ENTRY(atomic64_set_unchecked_cx8)
28778+ CFI_STARTPROC
28779+
28780+1:
28781+/* we don't need LOCK_PREFIX since aligned 64-bit writes
28782+ * are atomic on 586 and newer */
28783+ cmpxchg8b (%esi)
28784+ jne 1b
28785+
28786+ pax_force_retaddr
28787+ ret
28788+ CFI_ENDPROC
28789+ENDPROC(atomic64_set_unchecked_cx8)
28790+
28791 ENTRY(atomic64_xchg_cx8)
28792 CFI_STARTPROC
28793
28794@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28795 cmpxchg8b (%esi)
28796 jne 1b
28797
28798+ pax_force_retaddr
28799 ret
28800 CFI_ENDPROC
28801 ENDPROC(atomic64_xchg_cx8)
28802
28803-.macro addsub_return func ins insc
28804-ENTRY(atomic64_\func\()_return_cx8)
28805+.macro addsub_return func ins insc unchecked=""
28806+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28807 CFI_STARTPROC
28808 SAVE ebp
28809 SAVE ebx
28810@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28811 movl %edx, %ecx
28812 \ins\()l %esi, %ebx
28813 \insc\()l %edi, %ecx
28814+
28815+.ifb \unchecked
28816+#ifdef CONFIG_PAX_REFCOUNT
28817+ into
28818+2:
28819+ _ASM_EXTABLE(2b, 3f)
28820+#endif
28821+.endif
28822+
28823 LOCK_PREFIX
28824 cmpxchg8b (%ebp)
28825 jne 1b
28826-
28827-10:
28828 movl %ebx, %eax
28829 movl %ecx, %edx
28830+
28831+.ifb \unchecked
28832+#ifdef CONFIG_PAX_REFCOUNT
28833+3:
28834+#endif
28835+.endif
28836+
28837 RESTORE edi
28838 RESTORE esi
28839 RESTORE ebx
28840 RESTORE ebp
28841+ pax_force_retaddr
28842 ret
28843 CFI_ENDPROC
28844-ENDPROC(atomic64_\func\()_return_cx8)
28845+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28846 .endm
28847
28848 addsub_return add add adc
28849 addsub_return sub sub sbb
28850+addsub_return add add adc _unchecked
28851+addsub_return sub sub sbb _unchecked
28852
28853-.macro incdec_return func ins insc
28854-ENTRY(atomic64_\func\()_return_cx8)
28855+.macro incdec_return func ins insc unchecked=""
28856+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28857 CFI_STARTPROC
28858 SAVE ebx
28859
28860@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28861 movl %edx, %ecx
28862 \ins\()l $1, %ebx
28863 \insc\()l $0, %ecx
28864+
28865+.ifb \unchecked
28866+#ifdef CONFIG_PAX_REFCOUNT
28867+ into
28868+2:
28869+ _ASM_EXTABLE(2b, 3f)
28870+#endif
28871+.endif
28872+
28873 LOCK_PREFIX
28874 cmpxchg8b (%esi)
28875 jne 1b
28876
28877-10:
28878 movl %ebx, %eax
28879 movl %ecx, %edx
28880+
28881+.ifb \unchecked
28882+#ifdef CONFIG_PAX_REFCOUNT
28883+3:
28884+#endif
28885+.endif
28886+
28887 RESTORE ebx
28888+ pax_force_retaddr
28889 ret
28890 CFI_ENDPROC
28891-ENDPROC(atomic64_\func\()_return_cx8)
28892+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28893 .endm
28894
28895 incdec_return inc add adc
28896 incdec_return dec sub sbb
28897+incdec_return inc add adc _unchecked
28898+incdec_return dec sub sbb _unchecked
28899
28900 ENTRY(atomic64_dec_if_positive_cx8)
28901 CFI_STARTPROC
28902@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28903 movl %edx, %ecx
28904 subl $1, %ebx
28905 sbb $0, %ecx
28906+
28907+#ifdef CONFIG_PAX_REFCOUNT
28908+ into
28909+1234:
28910+ _ASM_EXTABLE(1234b, 2f)
28911+#endif
28912+
28913 js 2f
28914 LOCK_PREFIX
28915 cmpxchg8b (%esi)
28916@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28917 movl %ebx, %eax
28918 movl %ecx, %edx
28919 RESTORE ebx
28920+ pax_force_retaddr
28921 ret
28922 CFI_ENDPROC
28923 ENDPROC(atomic64_dec_if_positive_cx8)
28924@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28925 movl %edx, %ecx
28926 addl %ebp, %ebx
28927 adcl %edi, %ecx
28928+
28929+#ifdef CONFIG_PAX_REFCOUNT
28930+ into
28931+1234:
28932+ _ASM_EXTABLE(1234b, 3f)
28933+#endif
28934+
28935 LOCK_PREFIX
28936 cmpxchg8b (%esi)
28937 jne 1b
28938@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28939 CFI_ADJUST_CFA_OFFSET -8
28940 RESTORE ebx
28941 RESTORE ebp
28942+ pax_force_retaddr
28943 ret
28944 4:
28945 cmpl %edx, 4(%esp)
28946@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28947 xorl %ecx, %ecx
28948 addl $1, %ebx
28949 adcl %edx, %ecx
28950+
28951+#ifdef CONFIG_PAX_REFCOUNT
28952+ into
28953+1234:
28954+ _ASM_EXTABLE(1234b, 3f)
28955+#endif
28956+
28957 LOCK_PREFIX
28958 cmpxchg8b (%esi)
28959 jne 1b
28960@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28961 movl $1, %eax
28962 3:
28963 RESTORE ebx
28964+ pax_force_retaddr
28965 ret
28966 CFI_ENDPROC
28967 ENDPROC(atomic64_inc_not_zero_cx8)
28968diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28969index e78b8ee..7e173a8 100644
28970--- a/arch/x86/lib/checksum_32.S
28971+++ b/arch/x86/lib/checksum_32.S
28972@@ -29,7 +29,8 @@
28973 #include <asm/dwarf2.h>
28974 #include <asm/errno.h>
28975 #include <asm/asm.h>
28976-
28977+#include <asm/segment.h>
28978+
28979 /*
28980 * computes a partial checksum, e.g. for TCP/UDP fragments
28981 */
28982@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28983
28984 #define ARGBASE 16
28985 #define FP 12
28986-
28987-ENTRY(csum_partial_copy_generic)
28988+
28989+ENTRY(csum_partial_copy_generic_to_user)
28990 CFI_STARTPROC
28991+
28992+#ifdef CONFIG_PAX_MEMORY_UDEREF
28993+ pushl_cfi %gs
28994+ popl_cfi %es
28995+ jmp csum_partial_copy_generic
28996+#endif
28997+
28998+ENTRY(csum_partial_copy_generic_from_user)
28999+
29000+#ifdef CONFIG_PAX_MEMORY_UDEREF
29001+ pushl_cfi %gs
29002+ popl_cfi %ds
29003+#endif
29004+
29005+ENTRY(csum_partial_copy_generic)
29006 subl $4,%esp
29007 CFI_ADJUST_CFA_OFFSET 4
29008 pushl_cfi %edi
29009@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29010 jmp 4f
29011 SRC(1: movw (%esi), %bx )
29012 addl $2, %esi
29013-DST( movw %bx, (%edi) )
29014+DST( movw %bx, %es:(%edi) )
29015 addl $2, %edi
29016 addw %bx, %ax
29017 adcl $0, %eax
29018@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29019 SRC(1: movl (%esi), %ebx )
29020 SRC( movl 4(%esi), %edx )
29021 adcl %ebx, %eax
29022-DST( movl %ebx, (%edi) )
29023+DST( movl %ebx, %es:(%edi) )
29024 adcl %edx, %eax
29025-DST( movl %edx, 4(%edi) )
29026+DST( movl %edx, %es:4(%edi) )
29027
29028 SRC( movl 8(%esi), %ebx )
29029 SRC( movl 12(%esi), %edx )
29030 adcl %ebx, %eax
29031-DST( movl %ebx, 8(%edi) )
29032+DST( movl %ebx, %es:8(%edi) )
29033 adcl %edx, %eax
29034-DST( movl %edx, 12(%edi) )
29035+DST( movl %edx, %es:12(%edi) )
29036
29037 SRC( movl 16(%esi), %ebx )
29038 SRC( movl 20(%esi), %edx )
29039 adcl %ebx, %eax
29040-DST( movl %ebx, 16(%edi) )
29041+DST( movl %ebx, %es:16(%edi) )
29042 adcl %edx, %eax
29043-DST( movl %edx, 20(%edi) )
29044+DST( movl %edx, %es:20(%edi) )
29045
29046 SRC( movl 24(%esi), %ebx )
29047 SRC( movl 28(%esi), %edx )
29048 adcl %ebx, %eax
29049-DST( movl %ebx, 24(%edi) )
29050+DST( movl %ebx, %es:24(%edi) )
29051 adcl %edx, %eax
29052-DST( movl %edx, 28(%edi) )
29053+DST( movl %edx, %es:28(%edi) )
29054
29055 lea 32(%esi), %esi
29056 lea 32(%edi), %edi
29057@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29058 shrl $2, %edx # This clears CF
29059 SRC(3: movl (%esi), %ebx )
29060 adcl %ebx, %eax
29061-DST( movl %ebx, (%edi) )
29062+DST( movl %ebx, %es:(%edi) )
29063 lea 4(%esi), %esi
29064 lea 4(%edi), %edi
29065 dec %edx
29066@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29067 jb 5f
29068 SRC( movw (%esi), %cx )
29069 leal 2(%esi), %esi
29070-DST( movw %cx, (%edi) )
29071+DST( movw %cx, %es:(%edi) )
29072 leal 2(%edi), %edi
29073 je 6f
29074 shll $16,%ecx
29075 SRC(5: movb (%esi), %cl )
29076-DST( movb %cl, (%edi) )
29077+DST( movb %cl, %es:(%edi) )
29078 6: addl %ecx, %eax
29079 adcl $0, %eax
29080 7:
29081@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29082
29083 6001:
29084 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29085- movl $-EFAULT, (%ebx)
29086+ movl $-EFAULT, %ss:(%ebx)
29087
29088 # zero the complete destination - computing the rest
29089 # is too much work
29090@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29091
29092 6002:
29093 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29094- movl $-EFAULT,(%ebx)
29095+ movl $-EFAULT,%ss:(%ebx)
29096 jmp 5000b
29097
29098 .previous
29099
29100+ pushl_cfi %ss
29101+ popl_cfi %ds
29102+ pushl_cfi %ss
29103+ popl_cfi %es
29104 popl_cfi %ebx
29105 CFI_RESTORE ebx
29106 popl_cfi %esi
29107@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29108 popl_cfi %ecx # equivalent to addl $4,%esp
29109 ret
29110 CFI_ENDPROC
29111-ENDPROC(csum_partial_copy_generic)
29112+ENDPROC(csum_partial_copy_generic_to_user)
29113
29114 #else
29115
29116 /* Version for PentiumII/PPro */
29117
29118 #define ROUND1(x) \
29119+ nop; nop; nop; \
29120 SRC(movl x(%esi), %ebx ) ; \
29121 addl %ebx, %eax ; \
29122- DST(movl %ebx, x(%edi) ) ;
29123+ DST(movl %ebx, %es:x(%edi)) ;
29124
29125 #define ROUND(x) \
29126+ nop; nop; nop; \
29127 SRC(movl x(%esi), %ebx ) ; \
29128 adcl %ebx, %eax ; \
29129- DST(movl %ebx, x(%edi) ) ;
29130+ DST(movl %ebx, %es:x(%edi)) ;
29131
29132 #define ARGBASE 12
29133-
29134-ENTRY(csum_partial_copy_generic)
29135+
29136+ENTRY(csum_partial_copy_generic_to_user)
29137 CFI_STARTPROC
29138+
29139+#ifdef CONFIG_PAX_MEMORY_UDEREF
29140+ pushl_cfi %gs
29141+ popl_cfi %es
29142+ jmp csum_partial_copy_generic
29143+#endif
29144+
29145+ENTRY(csum_partial_copy_generic_from_user)
29146+
29147+#ifdef CONFIG_PAX_MEMORY_UDEREF
29148+ pushl_cfi %gs
29149+ popl_cfi %ds
29150+#endif
29151+
29152+ENTRY(csum_partial_copy_generic)
29153 pushl_cfi %ebx
29154 CFI_REL_OFFSET ebx, 0
29155 pushl_cfi %edi
29156@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29157 subl %ebx, %edi
29158 lea -1(%esi),%edx
29159 andl $-32,%edx
29160- lea 3f(%ebx,%ebx), %ebx
29161+ lea 3f(%ebx,%ebx,2), %ebx
29162 testl %esi, %esi
29163 jmp *%ebx
29164 1: addl $64,%esi
29165@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29166 jb 5f
29167 SRC( movw (%esi), %dx )
29168 leal 2(%esi), %esi
29169-DST( movw %dx, (%edi) )
29170+DST( movw %dx, %es:(%edi) )
29171 leal 2(%edi), %edi
29172 je 6f
29173 shll $16,%edx
29174 5:
29175 SRC( movb (%esi), %dl )
29176-DST( movb %dl, (%edi) )
29177+DST( movb %dl, %es:(%edi) )
29178 6: addl %edx, %eax
29179 adcl $0, %eax
29180 7:
29181 .section .fixup, "ax"
29182 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29183- movl $-EFAULT, (%ebx)
29184+ movl $-EFAULT, %ss:(%ebx)
29185 # zero the complete destination (computing the rest is too much work)
29186 movl ARGBASE+8(%esp),%edi # dst
29187 movl ARGBASE+12(%esp),%ecx # len
29188@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29189 rep; stosb
29190 jmp 7b
29191 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29192- movl $-EFAULT, (%ebx)
29193+ movl $-EFAULT, %ss:(%ebx)
29194 jmp 7b
29195 .previous
29196
29197+#ifdef CONFIG_PAX_MEMORY_UDEREF
29198+ pushl_cfi %ss
29199+ popl_cfi %ds
29200+ pushl_cfi %ss
29201+ popl_cfi %es
29202+#endif
29203+
29204 popl_cfi %esi
29205 CFI_RESTORE esi
29206 popl_cfi %edi
29207@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29208 CFI_RESTORE ebx
29209 ret
29210 CFI_ENDPROC
29211-ENDPROC(csum_partial_copy_generic)
29212+ENDPROC(csum_partial_copy_generic_to_user)
29213
29214 #undef ROUND
29215 #undef ROUND1
29216diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29217index f2145cf..cea889d 100644
29218--- a/arch/x86/lib/clear_page_64.S
29219+++ b/arch/x86/lib/clear_page_64.S
29220@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29221 movl $4096/8,%ecx
29222 xorl %eax,%eax
29223 rep stosq
29224+ pax_force_retaddr
29225 ret
29226 CFI_ENDPROC
29227 ENDPROC(clear_page_c)
29228@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29229 movl $4096,%ecx
29230 xorl %eax,%eax
29231 rep stosb
29232+ pax_force_retaddr
29233 ret
29234 CFI_ENDPROC
29235 ENDPROC(clear_page_c_e)
29236@@ -43,6 +45,7 @@ ENTRY(clear_page)
29237 leaq 64(%rdi),%rdi
29238 jnz .Lloop
29239 nop
29240+ pax_force_retaddr
29241 ret
29242 CFI_ENDPROC
29243 .Lclear_page_end:
29244@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29245
29246 #include <asm/cpufeature.h>
29247
29248- .section .altinstr_replacement,"ax"
29249+ .section .altinstr_replacement,"a"
29250 1: .byte 0xeb /* jmp <disp8> */
29251 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29252 2: .byte 0xeb /* jmp <disp8> */
29253diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29254index 1e572c5..2a162cd 100644
29255--- a/arch/x86/lib/cmpxchg16b_emu.S
29256+++ b/arch/x86/lib/cmpxchg16b_emu.S
29257@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29258
29259 popf
29260 mov $1, %al
29261+ pax_force_retaddr
29262 ret
29263
29264 not_same:
29265 popf
29266 xor %al,%al
29267+ pax_force_retaddr
29268 ret
29269
29270 CFI_ENDPROC
29271diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29272index 176cca6..e0d658e 100644
29273--- a/arch/x86/lib/copy_page_64.S
29274+++ b/arch/x86/lib/copy_page_64.S
29275@@ -9,6 +9,7 @@ copy_page_rep:
29276 CFI_STARTPROC
29277 movl $4096/8, %ecx
29278 rep movsq
29279+ pax_force_retaddr
29280 ret
29281 CFI_ENDPROC
29282 ENDPROC(copy_page_rep)
29283@@ -24,8 +25,8 @@ ENTRY(copy_page)
29284 CFI_ADJUST_CFA_OFFSET 2*8
29285 movq %rbx, (%rsp)
29286 CFI_REL_OFFSET rbx, 0
29287- movq %r12, 1*8(%rsp)
29288- CFI_REL_OFFSET r12, 1*8
29289+ movq %r13, 1*8(%rsp)
29290+ CFI_REL_OFFSET r13, 1*8
29291
29292 movl $(4096/64)-5, %ecx
29293 .p2align 4
29294@@ -38,7 +39,7 @@ ENTRY(copy_page)
29295 movq 0x8*4(%rsi), %r9
29296 movq 0x8*5(%rsi), %r10
29297 movq 0x8*6(%rsi), %r11
29298- movq 0x8*7(%rsi), %r12
29299+ movq 0x8*7(%rsi), %r13
29300
29301 prefetcht0 5*64(%rsi)
29302
29303@@ -49,7 +50,7 @@ ENTRY(copy_page)
29304 movq %r9, 0x8*4(%rdi)
29305 movq %r10, 0x8*5(%rdi)
29306 movq %r11, 0x8*6(%rdi)
29307- movq %r12, 0x8*7(%rdi)
29308+ movq %r13, 0x8*7(%rdi)
29309
29310 leaq 64 (%rsi), %rsi
29311 leaq 64 (%rdi), %rdi
29312@@ -68,7 +69,7 @@ ENTRY(copy_page)
29313 movq 0x8*4(%rsi), %r9
29314 movq 0x8*5(%rsi), %r10
29315 movq 0x8*6(%rsi), %r11
29316- movq 0x8*7(%rsi), %r12
29317+ movq 0x8*7(%rsi), %r13
29318
29319 movq %rax, 0x8*0(%rdi)
29320 movq %rbx, 0x8*1(%rdi)
29321@@ -77,7 +78,7 @@ ENTRY(copy_page)
29322 movq %r9, 0x8*4(%rdi)
29323 movq %r10, 0x8*5(%rdi)
29324 movq %r11, 0x8*6(%rdi)
29325- movq %r12, 0x8*7(%rdi)
29326+ movq %r13, 0x8*7(%rdi)
29327
29328 leaq 64(%rdi), %rdi
29329 leaq 64(%rsi), %rsi
29330@@ -85,10 +86,11 @@ ENTRY(copy_page)
29331
29332 movq (%rsp), %rbx
29333 CFI_RESTORE rbx
29334- movq 1*8(%rsp), %r12
29335- CFI_RESTORE r12
29336+ movq 1*8(%rsp), %r13
29337+ CFI_RESTORE r13
29338 addq $2*8, %rsp
29339 CFI_ADJUST_CFA_OFFSET -2*8
29340+ pax_force_retaddr
29341 ret
29342 .Lcopy_page_end:
29343 CFI_ENDPROC
29344@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29345
29346 #include <asm/cpufeature.h>
29347
29348- .section .altinstr_replacement,"ax"
29349+ .section .altinstr_replacement,"a"
29350 1: .byte 0xeb /* jmp <disp8> */
29351 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29352 2:
29353diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29354index dee945d..a84067b 100644
29355--- a/arch/x86/lib/copy_user_64.S
29356+++ b/arch/x86/lib/copy_user_64.S
29357@@ -18,31 +18,7 @@
29358 #include <asm/alternative-asm.h>
29359 #include <asm/asm.h>
29360 #include <asm/smap.h>
29361-
29362-/*
29363- * By placing feature2 after feature1 in altinstructions section, we logically
29364- * implement:
29365- * If CPU has feature2, jmp to alt2 is used
29366- * else if CPU has feature1, jmp to alt1 is used
29367- * else jmp to orig is used.
29368- */
29369- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29370-0:
29371- .byte 0xe9 /* 32bit jump */
29372- .long \orig-1f /* by default jump to orig */
29373-1:
29374- .section .altinstr_replacement,"ax"
29375-2: .byte 0xe9 /* near jump with 32bit immediate */
29376- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29377-3: .byte 0xe9 /* near jump with 32bit immediate */
29378- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29379- .previous
29380-
29381- .section .altinstructions,"a"
29382- altinstruction_entry 0b,2b,\feature1,5,5
29383- altinstruction_entry 0b,3b,\feature2,5,5
29384- .previous
29385- .endm
29386+#include <asm/pgtable.h>
29387
29388 .macro ALIGN_DESTINATION
29389 #ifdef FIX_ALIGNMENT
29390@@ -70,52 +46,6 @@
29391 #endif
29392 .endm
29393
29394-/* Standard copy_to_user with segment limit checking */
29395-ENTRY(_copy_to_user)
29396- CFI_STARTPROC
29397- GET_THREAD_INFO(%rax)
29398- movq %rdi,%rcx
29399- addq %rdx,%rcx
29400- jc bad_to_user
29401- cmpq TI_addr_limit(%rax),%rcx
29402- ja bad_to_user
29403- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29404- copy_user_generic_unrolled,copy_user_generic_string, \
29405- copy_user_enhanced_fast_string
29406- CFI_ENDPROC
29407-ENDPROC(_copy_to_user)
29408-
29409-/* Standard copy_from_user with segment limit checking */
29410-ENTRY(_copy_from_user)
29411- CFI_STARTPROC
29412- GET_THREAD_INFO(%rax)
29413- movq %rsi,%rcx
29414- addq %rdx,%rcx
29415- jc bad_from_user
29416- cmpq TI_addr_limit(%rax),%rcx
29417- ja bad_from_user
29418- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29419- copy_user_generic_unrolled,copy_user_generic_string, \
29420- copy_user_enhanced_fast_string
29421- CFI_ENDPROC
29422-ENDPROC(_copy_from_user)
29423-
29424- .section .fixup,"ax"
29425- /* must zero dest */
29426-ENTRY(bad_from_user)
29427-bad_from_user:
29428- CFI_STARTPROC
29429- movl %edx,%ecx
29430- xorl %eax,%eax
29431- rep
29432- stosb
29433-bad_to_user:
29434- movl %edx,%eax
29435- ret
29436- CFI_ENDPROC
29437-ENDPROC(bad_from_user)
29438- .previous
29439-
29440 /*
29441 * copy_user_generic_unrolled - memory copy with exception handling.
29442 * This version is for CPUs like P4 that don't have efficient micro
29443@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29444 */
29445 ENTRY(copy_user_generic_unrolled)
29446 CFI_STARTPROC
29447+ ASM_PAX_OPEN_USERLAND
29448 ASM_STAC
29449 cmpl $8,%edx
29450 jb 20f /* less then 8 bytes, go to byte copy loop */
29451@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29452 jnz 21b
29453 23: xor %eax,%eax
29454 ASM_CLAC
29455+ ASM_PAX_CLOSE_USERLAND
29456+ pax_force_retaddr
29457 ret
29458
29459 .section .fixup,"ax"
29460@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29461 */
29462 ENTRY(copy_user_generic_string)
29463 CFI_STARTPROC
29464+ ASM_PAX_OPEN_USERLAND
29465 ASM_STAC
29466 cmpl $8,%edx
29467 jb 2f /* less than 8 bytes, go to byte copy loop */
29468@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29469 movsb
29470 xorl %eax,%eax
29471 ASM_CLAC
29472+ ASM_PAX_CLOSE_USERLAND
29473+ pax_force_retaddr
29474 ret
29475
29476 .section .fixup,"ax"
29477@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29478 */
29479 ENTRY(copy_user_enhanced_fast_string)
29480 CFI_STARTPROC
29481+ ASM_PAX_OPEN_USERLAND
29482 ASM_STAC
29483 movl %edx,%ecx
29484 1: rep
29485 movsb
29486 xorl %eax,%eax
29487 ASM_CLAC
29488+ ASM_PAX_CLOSE_USERLAND
29489+ pax_force_retaddr
29490 ret
29491
29492 .section .fixup,"ax"
29493diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29494index 6a4f43c..c70fb52 100644
29495--- a/arch/x86/lib/copy_user_nocache_64.S
29496+++ b/arch/x86/lib/copy_user_nocache_64.S
29497@@ -8,6 +8,7 @@
29498
29499 #include <linux/linkage.h>
29500 #include <asm/dwarf2.h>
29501+#include <asm/alternative-asm.h>
29502
29503 #define FIX_ALIGNMENT 1
29504
29505@@ -16,6 +17,7 @@
29506 #include <asm/thread_info.h>
29507 #include <asm/asm.h>
29508 #include <asm/smap.h>
29509+#include <asm/pgtable.h>
29510
29511 .macro ALIGN_DESTINATION
29512 #ifdef FIX_ALIGNMENT
29513@@ -49,6 +51,16 @@
29514 */
29515 ENTRY(__copy_user_nocache)
29516 CFI_STARTPROC
29517+
29518+#ifdef CONFIG_PAX_MEMORY_UDEREF
29519+ mov pax_user_shadow_base,%rcx
29520+ cmp %rcx,%rsi
29521+ jae 1f
29522+ add %rcx,%rsi
29523+1:
29524+#endif
29525+
29526+ ASM_PAX_OPEN_USERLAND
29527 ASM_STAC
29528 cmpl $8,%edx
29529 jb 20f /* less then 8 bytes, go to byte copy loop */
29530@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29531 jnz 21b
29532 23: xorl %eax,%eax
29533 ASM_CLAC
29534+ ASM_PAX_CLOSE_USERLAND
29535 sfence
29536+ pax_force_retaddr
29537 ret
29538
29539 .section .fixup,"ax"
29540diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29541index 2419d5f..fe52d0e 100644
29542--- a/arch/x86/lib/csum-copy_64.S
29543+++ b/arch/x86/lib/csum-copy_64.S
29544@@ -9,6 +9,7 @@
29545 #include <asm/dwarf2.h>
29546 #include <asm/errno.h>
29547 #include <asm/asm.h>
29548+#include <asm/alternative-asm.h>
29549
29550 /*
29551 * Checksum copy with exception handling.
29552@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29553 CFI_ADJUST_CFA_OFFSET 7*8
29554 movq %rbx, 2*8(%rsp)
29555 CFI_REL_OFFSET rbx, 2*8
29556- movq %r12, 3*8(%rsp)
29557- CFI_REL_OFFSET r12, 3*8
29558+ movq %r15, 3*8(%rsp)
29559+ CFI_REL_OFFSET r15, 3*8
29560 movq %r14, 4*8(%rsp)
29561 CFI_REL_OFFSET r14, 4*8
29562 movq %r13, 5*8(%rsp)
29563@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29564 movl %edx, %ecx
29565
29566 xorl %r9d, %r9d
29567- movq %rcx, %r12
29568+ movq %rcx, %r15
29569
29570- shrq $6, %r12
29571+ shrq $6, %r15
29572 jz .Lhandle_tail /* < 64 */
29573
29574 clc
29575
29576 /* main loop. clear in 64 byte blocks */
29577 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29578- /* r11: temp3, rdx: temp4, r12 loopcnt */
29579+ /* r11: temp3, rdx: temp4, r15 loopcnt */
29580 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29581 .p2align 4
29582 .Lloop:
29583@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29584 adcq %r14, %rax
29585 adcq %r13, %rax
29586
29587- decl %r12d
29588+ decl %r15d
29589
29590 dest
29591 movq %rbx, (%rsi)
29592@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29593 .Lende:
29594 movq 2*8(%rsp), %rbx
29595 CFI_RESTORE rbx
29596- movq 3*8(%rsp), %r12
29597- CFI_RESTORE r12
29598+ movq 3*8(%rsp), %r15
29599+ CFI_RESTORE r15
29600 movq 4*8(%rsp), %r14
29601 CFI_RESTORE r14
29602 movq 5*8(%rsp), %r13
29603@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29604 CFI_RESTORE rbp
29605 addq $7*8, %rsp
29606 CFI_ADJUST_CFA_OFFSET -7*8
29607+ pax_force_retaddr
29608 ret
29609 CFI_RESTORE_STATE
29610
29611diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29612index 7609e0e..b449b98 100644
29613--- a/arch/x86/lib/csum-wrappers_64.c
29614+++ b/arch/x86/lib/csum-wrappers_64.c
29615@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29616 len -= 2;
29617 }
29618 }
29619+ pax_open_userland();
29620 stac();
29621- isum = csum_partial_copy_generic((__force const void *)src,
29622+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29623 dst, len, isum, errp, NULL);
29624 clac();
29625+ pax_close_userland();
29626 if (unlikely(*errp))
29627 goto out_err;
29628
29629@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29630 }
29631
29632 *errp = 0;
29633+ pax_open_userland();
29634 stac();
29635- ret = csum_partial_copy_generic(src, (void __force *)dst,
29636+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29637 len, isum, NULL, errp);
29638 clac();
29639+ pax_close_userland();
29640 return ret;
29641 }
29642 EXPORT_SYMBOL(csum_partial_copy_to_user);
29643diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29644index a451235..1daa956 100644
29645--- a/arch/x86/lib/getuser.S
29646+++ b/arch/x86/lib/getuser.S
29647@@ -33,17 +33,40 @@
29648 #include <asm/thread_info.h>
29649 #include <asm/asm.h>
29650 #include <asm/smap.h>
29651+#include <asm/segment.h>
29652+#include <asm/pgtable.h>
29653+#include <asm/alternative-asm.h>
29654+
29655+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29656+#define __copyuser_seg gs;
29657+#else
29658+#define __copyuser_seg
29659+#endif
29660
29661 .text
29662 ENTRY(__get_user_1)
29663 CFI_STARTPROC
29664+
29665+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29666 GET_THREAD_INFO(%_ASM_DX)
29667 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29668 jae bad_get_user
29669 ASM_STAC
29670-1: movzbl (%_ASM_AX),%edx
29671+
29672+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29673+ mov pax_user_shadow_base,%_ASM_DX
29674+ cmp %_ASM_DX,%_ASM_AX
29675+ jae 1234f
29676+ add %_ASM_DX,%_ASM_AX
29677+1234:
29678+#endif
29679+
29680+#endif
29681+
29682+1: __copyuser_seg movzbl (%_ASM_AX),%edx
29683 xor %eax,%eax
29684 ASM_CLAC
29685+ pax_force_retaddr
29686 ret
29687 CFI_ENDPROC
29688 ENDPROC(__get_user_1)
29689@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29690 ENTRY(__get_user_2)
29691 CFI_STARTPROC
29692 add $1,%_ASM_AX
29693+
29694+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29695 jc bad_get_user
29696 GET_THREAD_INFO(%_ASM_DX)
29697 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29698 jae bad_get_user
29699 ASM_STAC
29700-2: movzwl -1(%_ASM_AX),%edx
29701+
29702+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29703+ mov pax_user_shadow_base,%_ASM_DX
29704+ cmp %_ASM_DX,%_ASM_AX
29705+ jae 1234f
29706+ add %_ASM_DX,%_ASM_AX
29707+1234:
29708+#endif
29709+
29710+#endif
29711+
29712+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29713 xor %eax,%eax
29714 ASM_CLAC
29715+ pax_force_retaddr
29716 ret
29717 CFI_ENDPROC
29718 ENDPROC(__get_user_2)
29719@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29720 ENTRY(__get_user_4)
29721 CFI_STARTPROC
29722 add $3,%_ASM_AX
29723+
29724+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29725 jc bad_get_user
29726 GET_THREAD_INFO(%_ASM_DX)
29727 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29728 jae bad_get_user
29729 ASM_STAC
29730-3: movl -3(%_ASM_AX),%edx
29731+
29732+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29733+ mov pax_user_shadow_base,%_ASM_DX
29734+ cmp %_ASM_DX,%_ASM_AX
29735+ jae 1234f
29736+ add %_ASM_DX,%_ASM_AX
29737+1234:
29738+#endif
29739+
29740+#endif
29741+
29742+3: __copyuser_seg movl -3(%_ASM_AX),%edx
29743 xor %eax,%eax
29744 ASM_CLAC
29745+ pax_force_retaddr
29746 ret
29747 CFI_ENDPROC
29748 ENDPROC(__get_user_4)
29749@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29750 GET_THREAD_INFO(%_ASM_DX)
29751 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29752 jae bad_get_user
29753+
29754+#ifdef CONFIG_PAX_MEMORY_UDEREF
29755+ mov pax_user_shadow_base,%_ASM_DX
29756+ cmp %_ASM_DX,%_ASM_AX
29757+ jae 1234f
29758+ add %_ASM_DX,%_ASM_AX
29759+1234:
29760+#endif
29761+
29762 ASM_STAC
29763 4: movq -7(%_ASM_AX),%rdx
29764 xor %eax,%eax
29765 ASM_CLAC
29766+ pax_force_retaddr
29767 ret
29768 #else
29769 add $7,%_ASM_AX
29770@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29771 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29772 jae bad_get_user_8
29773 ASM_STAC
29774-4: movl -7(%_ASM_AX),%edx
29775-5: movl -3(%_ASM_AX),%ecx
29776+4: __copyuser_seg movl -7(%_ASM_AX),%edx
29777+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29778 xor %eax,%eax
29779 ASM_CLAC
29780+ pax_force_retaddr
29781 ret
29782 #endif
29783 CFI_ENDPROC
29784@@ -113,6 +175,7 @@ bad_get_user:
29785 xor %edx,%edx
29786 mov $(-EFAULT),%_ASM_AX
29787 ASM_CLAC
29788+ pax_force_retaddr
29789 ret
29790 CFI_ENDPROC
29791 END(bad_get_user)
29792@@ -124,6 +187,7 @@ bad_get_user_8:
29793 xor %ecx,%ecx
29794 mov $(-EFAULT),%_ASM_AX
29795 ASM_CLAC
29796+ pax_force_retaddr
29797 ret
29798 CFI_ENDPROC
29799 END(bad_get_user_8)
29800diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29801index 54fcffe..7be149e 100644
29802--- a/arch/x86/lib/insn.c
29803+++ b/arch/x86/lib/insn.c
29804@@ -20,8 +20,10 @@
29805
29806 #ifdef __KERNEL__
29807 #include <linux/string.h>
29808+#include <asm/pgtable_types.h>
29809 #else
29810 #include <string.h>
29811+#define ktla_ktva(addr) addr
29812 #endif
29813 #include <asm/inat.h>
29814 #include <asm/insn.h>
29815@@ -53,8 +55,8 @@
29816 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29817 {
29818 memset(insn, 0, sizeof(*insn));
29819- insn->kaddr = kaddr;
29820- insn->next_byte = kaddr;
29821+ insn->kaddr = ktla_ktva(kaddr);
29822+ insn->next_byte = ktla_ktva(kaddr);
29823 insn->x86_64 = x86_64 ? 1 : 0;
29824 insn->opnd_bytes = 4;
29825 if (x86_64)
29826diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29827index 05a95e7..326f2fa 100644
29828--- a/arch/x86/lib/iomap_copy_64.S
29829+++ b/arch/x86/lib/iomap_copy_64.S
29830@@ -17,6 +17,7 @@
29831
29832 #include <linux/linkage.h>
29833 #include <asm/dwarf2.h>
29834+#include <asm/alternative-asm.h>
29835
29836 /*
29837 * override generic version in lib/iomap_copy.c
29838@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29839 CFI_STARTPROC
29840 movl %edx,%ecx
29841 rep movsd
29842+ pax_force_retaddr
29843 ret
29844 CFI_ENDPROC
29845 ENDPROC(__iowrite32_copy)
29846diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29847index 56313a3..0db417e 100644
29848--- a/arch/x86/lib/memcpy_64.S
29849+++ b/arch/x86/lib/memcpy_64.S
29850@@ -24,7 +24,7 @@
29851 * This gets patched over the unrolled variant (below) via the
29852 * alternative instructions framework:
29853 */
29854- .section .altinstr_replacement, "ax", @progbits
29855+ .section .altinstr_replacement, "a", @progbits
29856 .Lmemcpy_c:
29857 movq %rdi, %rax
29858 movq %rdx, %rcx
29859@@ -33,6 +33,7 @@
29860 rep movsq
29861 movl %edx, %ecx
29862 rep movsb
29863+ pax_force_retaddr
29864 ret
29865 .Lmemcpy_e:
29866 .previous
29867@@ -44,11 +45,12 @@
29868 * This gets patched over the unrolled variant (below) via the
29869 * alternative instructions framework:
29870 */
29871- .section .altinstr_replacement, "ax", @progbits
29872+ .section .altinstr_replacement, "a", @progbits
29873 .Lmemcpy_c_e:
29874 movq %rdi, %rax
29875 movq %rdx, %rcx
29876 rep movsb
29877+ pax_force_retaddr
29878 ret
29879 .Lmemcpy_e_e:
29880 .previous
29881@@ -136,6 +138,7 @@ ENTRY(memcpy)
29882 movq %r9, 1*8(%rdi)
29883 movq %r10, -2*8(%rdi, %rdx)
29884 movq %r11, -1*8(%rdi, %rdx)
29885+ pax_force_retaddr
29886 retq
29887 .p2align 4
29888 .Lless_16bytes:
29889@@ -148,6 +151,7 @@ ENTRY(memcpy)
29890 movq -1*8(%rsi, %rdx), %r9
29891 movq %r8, 0*8(%rdi)
29892 movq %r9, -1*8(%rdi, %rdx)
29893+ pax_force_retaddr
29894 retq
29895 .p2align 4
29896 .Lless_8bytes:
29897@@ -161,6 +165,7 @@ ENTRY(memcpy)
29898 movl -4(%rsi, %rdx), %r8d
29899 movl %ecx, (%rdi)
29900 movl %r8d, -4(%rdi, %rdx)
29901+ pax_force_retaddr
29902 retq
29903 .p2align 4
29904 .Lless_3bytes:
29905@@ -179,6 +184,7 @@ ENTRY(memcpy)
29906 movb %cl, (%rdi)
29907
29908 .Lend:
29909+ pax_force_retaddr
29910 retq
29911 CFI_ENDPROC
29912 ENDPROC(memcpy)
29913diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29914index 65268a6..dd1de11 100644
29915--- a/arch/x86/lib/memmove_64.S
29916+++ b/arch/x86/lib/memmove_64.S
29917@@ -202,14 +202,16 @@ ENTRY(memmove)
29918 movb (%rsi), %r11b
29919 movb %r11b, (%rdi)
29920 13:
29921+ pax_force_retaddr
29922 retq
29923 CFI_ENDPROC
29924
29925- .section .altinstr_replacement,"ax"
29926+ .section .altinstr_replacement,"a"
29927 .Lmemmove_begin_forward_efs:
29928 /* Forward moving data. */
29929 movq %rdx, %rcx
29930 rep movsb
29931+ pax_force_retaddr
29932 retq
29933 .Lmemmove_end_forward_efs:
29934 .previous
29935diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29936index 2dcb380..2eb79fe 100644
29937--- a/arch/x86/lib/memset_64.S
29938+++ b/arch/x86/lib/memset_64.S
29939@@ -16,7 +16,7 @@
29940 *
29941 * rax original destination
29942 */
29943- .section .altinstr_replacement, "ax", @progbits
29944+ .section .altinstr_replacement, "a", @progbits
29945 .Lmemset_c:
29946 movq %rdi,%r9
29947 movq %rdx,%rcx
29948@@ -30,6 +30,7 @@
29949 movl %edx,%ecx
29950 rep stosb
29951 movq %r9,%rax
29952+ pax_force_retaddr
29953 ret
29954 .Lmemset_e:
29955 .previous
29956@@ -45,13 +46,14 @@
29957 *
29958 * rax original destination
29959 */
29960- .section .altinstr_replacement, "ax", @progbits
29961+ .section .altinstr_replacement, "a", @progbits
29962 .Lmemset_c_e:
29963 movq %rdi,%r9
29964 movb %sil,%al
29965 movq %rdx,%rcx
29966 rep stosb
29967 movq %r9,%rax
29968+ pax_force_retaddr
29969 ret
29970 .Lmemset_e_e:
29971 .previous
29972@@ -118,6 +120,7 @@ ENTRY(__memset)
29973
29974 .Lende:
29975 movq %r10,%rax
29976+ pax_force_retaddr
29977 ret
29978
29979 CFI_RESTORE_STATE
29980diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29981index c9f2d9b..e7fd2c0 100644
29982--- a/arch/x86/lib/mmx_32.c
29983+++ b/arch/x86/lib/mmx_32.c
29984@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29985 {
29986 void *p;
29987 int i;
29988+ unsigned long cr0;
29989
29990 if (unlikely(in_interrupt()))
29991 return __memcpy(to, from, len);
29992@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29993 kernel_fpu_begin();
29994
29995 __asm__ __volatile__ (
29996- "1: prefetch (%0)\n" /* This set is 28 bytes */
29997- " prefetch 64(%0)\n"
29998- " prefetch 128(%0)\n"
29999- " prefetch 192(%0)\n"
30000- " prefetch 256(%0)\n"
30001+ "1: prefetch (%1)\n" /* This set is 28 bytes */
30002+ " prefetch 64(%1)\n"
30003+ " prefetch 128(%1)\n"
30004+ " prefetch 192(%1)\n"
30005+ " prefetch 256(%1)\n"
30006 "2: \n"
30007 ".section .fixup, \"ax\"\n"
30008- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30009+ "3: \n"
30010+
30011+#ifdef CONFIG_PAX_KERNEXEC
30012+ " movl %%cr0, %0\n"
30013+ " movl %0, %%eax\n"
30014+ " andl $0xFFFEFFFF, %%eax\n"
30015+ " movl %%eax, %%cr0\n"
30016+#endif
30017+
30018+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30019+
30020+#ifdef CONFIG_PAX_KERNEXEC
30021+ " movl %0, %%cr0\n"
30022+#endif
30023+
30024 " jmp 2b\n"
30025 ".previous\n"
30026 _ASM_EXTABLE(1b, 3b)
30027- : : "r" (from));
30028+ : "=&r" (cr0) : "r" (from) : "ax");
30029
30030 for ( ; i > 5; i--) {
30031 __asm__ __volatile__ (
30032- "1: prefetch 320(%0)\n"
30033- "2: movq (%0), %%mm0\n"
30034- " movq 8(%0), %%mm1\n"
30035- " movq 16(%0), %%mm2\n"
30036- " movq 24(%0), %%mm3\n"
30037- " movq %%mm0, (%1)\n"
30038- " movq %%mm1, 8(%1)\n"
30039- " movq %%mm2, 16(%1)\n"
30040- " movq %%mm3, 24(%1)\n"
30041- " movq 32(%0), %%mm0\n"
30042- " movq 40(%0), %%mm1\n"
30043- " movq 48(%0), %%mm2\n"
30044- " movq 56(%0), %%mm3\n"
30045- " movq %%mm0, 32(%1)\n"
30046- " movq %%mm1, 40(%1)\n"
30047- " movq %%mm2, 48(%1)\n"
30048- " movq %%mm3, 56(%1)\n"
30049+ "1: prefetch 320(%1)\n"
30050+ "2: movq (%1), %%mm0\n"
30051+ " movq 8(%1), %%mm1\n"
30052+ " movq 16(%1), %%mm2\n"
30053+ " movq 24(%1), %%mm3\n"
30054+ " movq %%mm0, (%2)\n"
30055+ " movq %%mm1, 8(%2)\n"
30056+ " movq %%mm2, 16(%2)\n"
30057+ " movq %%mm3, 24(%2)\n"
30058+ " movq 32(%1), %%mm0\n"
30059+ " movq 40(%1), %%mm1\n"
30060+ " movq 48(%1), %%mm2\n"
30061+ " movq 56(%1), %%mm3\n"
30062+ " movq %%mm0, 32(%2)\n"
30063+ " movq %%mm1, 40(%2)\n"
30064+ " movq %%mm2, 48(%2)\n"
30065+ " movq %%mm3, 56(%2)\n"
30066 ".section .fixup, \"ax\"\n"
30067- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30068+ "3:\n"
30069+
30070+#ifdef CONFIG_PAX_KERNEXEC
30071+ " movl %%cr0, %0\n"
30072+ " movl %0, %%eax\n"
30073+ " andl $0xFFFEFFFF, %%eax\n"
30074+ " movl %%eax, %%cr0\n"
30075+#endif
30076+
30077+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30078+
30079+#ifdef CONFIG_PAX_KERNEXEC
30080+ " movl %0, %%cr0\n"
30081+#endif
30082+
30083 " jmp 2b\n"
30084 ".previous\n"
30085 _ASM_EXTABLE(1b, 3b)
30086- : : "r" (from), "r" (to) : "memory");
30087+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30088
30089 from += 64;
30090 to += 64;
30091@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30092 static void fast_copy_page(void *to, void *from)
30093 {
30094 int i;
30095+ unsigned long cr0;
30096
30097 kernel_fpu_begin();
30098
30099@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30100 * but that is for later. -AV
30101 */
30102 __asm__ __volatile__(
30103- "1: prefetch (%0)\n"
30104- " prefetch 64(%0)\n"
30105- " prefetch 128(%0)\n"
30106- " prefetch 192(%0)\n"
30107- " prefetch 256(%0)\n"
30108+ "1: prefetch (%1)\n"
30109+ " prefetch 64(%1)\n"
30110+ " prefetch 128(%1)\n"
30111+ " prefetch 192(%1)\n"
30112+ " prefetch 256(%1)\n"
30113 "2: \n"
30114 ".section .fixup, \"ax\"\n"
30115- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30116+ "3: \n"
30117+
30118+#ifdef CONFIG_PAX_KERNEXEC
30119+ " movl %%cr0, %0\n"
30120+ " movl %0, %%eax\n"
30121+ " andl $0xFFFEFFFF, %%eax\n"
30122+ " movl %%eax, %%cr0\n"
30123+#endif
30124+
30125+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30126+
30127+#ifdef CONFIG_PAX_KERNEXEC
30128+ " movl %0, %%cr0\n"
30129+#endif
30130+
30131 " jmp 2b\n"
30132 ".previous\n"
30133- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30134+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30135
30136 for (i = 0; i < (4096-320)/64; i++) {
30137 __asm__ __volatile__ (
30138- "1: prefetch 320(%0)\n"
30139- "2: movq (%0), %%mm0\n"
30140- " movntq %%mm0, (%1)\n"
30141- " movq 8(%0), %%mm1\n"
30142- " movntq %%mm1, 8(%1)\n"
30143- " movq 16(%0), %%mm2\n"
30144- " movntq %%mm2, 16(%1)\n"
30145- " movq 24(%0), %%mm3\n"
30146- " movntq %%mm3, 24(%1)\n"
30147- " movq 32(%0), %%mm4\n"
30148- " movntq %%mm4, 32(%1)\n"
30149- " movq 40(%0), %%mm5\n"
30150- " movntq %%mm5, 40(%1)\n"
30151- " movq 48(%0), %%mm6\n"
30152- " movntq %%mm6, 48(%1)\n"
30153- " movq 56(%0), %%mm7\n"
30154- " movntq %%mm7, 56(%1)\n"
30155+ "1: prefetch 320(%1)\n"
30156+ "2: movq (%1), %%mm0\n"
30157+ " movntq %%mm0, (%2)\n"
30158+ " movq 8(%1), %%mm1\n"
30159+ " movntq %%mm1, 8(%2)\n"
30160+ " movq 16(%1), %%mm2\n"
30161+ " movntq %%mm2, 16(%2)\n"
30162+ " movq 24(%1), %%mm3\n"
30163+ " movntq %%mm3, 24(%2)\n"
30164+ " movq 32(%1), %%mm4\n"
30165+ " movntq %%mm4, 32(%2)\n"
30166+ " movq 40(%1), %%mm5\n"
30167+ " movntq %%mm5, 40(%2)\n"
30168+ " movq 48(%1), %%mm6\n"
30169+ " movntq %%mm6, 48(%2)\n"
30170+ " movq 56(%1), %%mm7\n"
30171+ " movntq %%mm7, 56(%2)\n"
30172 ".section .fixup, \"ax\"\n"
30173- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30174+ "3:\n"
30175+
30176+#ifdef CONFIG_PAX_KERNEXEC
30177+ " movl %%cr0, %0\n"
30178+ " movl %0, %%eax\n"
30179+ " andl $0xFFFEFFFF, %%eax\n"
30180+ " movl %%eax, %%cr0\n"
30181+#endif
30182+
30183+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30184+
30185+#ifdef CONFIG_PAX_KERNEXEC
30186+ " movl %0, %%cr0\n"
30187+#endif
30188+
30189 " jmp 2b\n"
30190 ".previous\n"
30191- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30192+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30193
30194 from += 64;
30195 to += 64;
30196@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30197 static void fast_copy_page(void *to, void *from)
30198 {
30199 int i;
30200+ unsigned long cr0;
30201
30202 kernel_fpu_begin();
30203
30204 __asm__ __volatile__ (
30205- "1: prefetch (%0)\n"
30206- " prefetch 64(%0)\n"
30207- " prefetch 128(%0)\n"
30208- " prefetch 192(%0)\n"
30209- " prefetch 256(%0)\n"
30210+ "1: prefetch (%1)\n"
30211+ " prefetch 64(%1)\n"
30212+ " prefetch 128(%1)\n"
30213+ " prefetch 192(%1)\n"
30214+ " prefetch 256(%1)\n"
30215 "2: \n"
30216 ".section .fixup, \"ax\"\n"
30217- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30218+ "3: \n"
30219+
30220+#ifdef CONFIG_PAX_KERNEXEC
30221+ " movl %%cr0, %0\n"
30222+ " movl %0, %%eax\n"
30223+ " andl $0xFFFEFFFF, %%eax\n"
30224+ " movl %%eax, %%cr0\n"
30225+#endif
30226+
30227+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30228+
30229+#ifdef CONFIG_PAX_KERNEXEC
30230+ " movl %0, %%cr0\n"
30231+#endif
30232+
30233 " jmp 2b\n"
30234 ".previous\n"
30235- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30236+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30237
30238 for (i = 0; i < 4096/64; i++) {
30239 __asm__ __volatile__ (
30240- "1: prefetch 320(%0)\n"
30241- "2: movq (%0), %%mm0\n"
30242- " movq 8(%0), %%mm1\n"
30243- " movq 16(%0), %%mm2\n"
30244- " movq 24(%0), %%mm3\n"
30245- " movq %%mm0, (%1)\n"
30246- " movq %%mm1, 8(%1)\n"
30247- " movq %%mm2, 16(%1)\n"
30248- " movq %%mm3, 24(%1)\n"
30249- " movq 32(%0), %%mm0\n"
30250- " movq 40(%0), %%mm1\n"
30251- " movq 48(%0), %%mm2\n"
30252- " movq 56(%0), %%mm3\n"
30253- " movq %%mm0, 32(%1)\n"
30254- " movq %%mm1, 40(%1)\n"
30255- " movq %%mm2, 48(%1)\n"
30256- " movq %%mm3, 56(%1)\n"
30257+ "1: prefetch 320(%1)\n"
30258+ "2: movq (%1), %%mm0\n"
30259+ " movq 8(%1), %%mm1\n"
30260+ " movq 16(%1), %%mm2\n"
30261+ " movq 24(%1), %%mm3\n"
30262+ " movq %%mm0, (%2)\n"
30263+ " movq %%mm1, 8(%2)\n"
30264+ " movq %%mm2, 16(%2)\n"
30265+ " movq %%mm3, 24(%2)\n"
30266+ " movq 32(%1), %%mm0\n"
30267+ " movq 40(%1), %%mm1\n"
30268+ " movq 48(%1), %%mm2\n"
30269+ " movq 56(%1), %%mm3\n"
30270+ " movq %%mm0, 32(%2)\n"
30271+ " movq %%mm1, 40(%2)\n"
30272+ " movq %%mm2, 48(%2)\n"
30273+ " movq %%mm3, 56(%2)\n"
30274 ".section .fixup, \"ax\"\n"
30275- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30276+ "3:\n"
30277+
30278+#ifdef CONFIG_PAX_KERNEXEC
30279+ " movl %%cr0, %0\n"
30280+ " movl %0, %%eax\n"
30281+ " andl $0xFFFEFFFF, %%eax\n"
30282+ " movl %%eax, %%cr0\n"
30283+#endif
30284+
30285+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30286+
30287+#ifdef CONFIG_PAX_KERNEXEC
30288+ " movl %0, %%cr0\n"
30289+#endif
30290+
30291 " jmp 2b\n"
30292 ".previous\n"
30293 _ASM_EXTABLE(1b, 3b)
30294- : : "r" (from), "r" (to) : "memory");
30295+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30296
30297 from += 64;
30298 to += 64;
30299diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30300index f6d13ee..d789440 100644
30301--- a/arch/x86/lib/msr-reg.S
30302+++ b/arch/x86/lib/msr-reg.S
30303@@ -3,6 +3,7 @@
30304 #include <asm/dwarf2.h>
30305 #include <asm/asm.h>
30306 #include <asm/msr.h>
30307+#include <asm/alternative-asm.h>
30308
30309 #ifdef CONFIG_X86_64
30310 /*
30311@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30312 movl %edi, 28(%r10)
30313 popq_cfi %rbp
30314 popq_cfi %rbx
30315+ pax_force_retaddr
30316 ret
30317 3:
30318 CFI_RESTORE_STATE
30319diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30320index fc6ba17..d4d989d 100644
30321--- a/arch/x86/lib/putuser.S
30322+++ b/arch/x86/lib/putuser.S
30323@@ -16,7 +16,9 @@
30324 #include <asm/errno.h>
30325 #include <asm/asm.h>
30326 #include <asm/smap.h>
30327-
30328+#include <asm/segment.h>
30329+#include <asm/pgtable.h>
30330+#include <asm/alternative-asm.h>
30331
30332 /*
30333 * __put_user_X
30334@@ -30,57 +32,125 @@
30335 * as they get called from within inline assembly.
30336 */
30337
30338-#define ENTER CFI_STARTPROC ; \
30339- GET_THREAD_INFO(%_ASM_BX)
30340-#define EXIT ASM_CLAC ; \
30341- ret ; \
30342+#define ENTER CFI_STARTPROC
30343+#define EXIT ASM_CLAC ; \
30344+ pax_force_retaddr ; \
30345+ ret ; \
30346 CFI_ENDPROC
30347
30348+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30349+#define _DEST %_ASM_CX,%_ASM_BX
30350+#else
30351+#define _DEST %_ASM_CX
30352+#endif
30353+
30354+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30355+#define __copyuser_seg gs;
30356+#else
30357+#define __copyuser_seg
30358+#endif
30359+
30360 .text
30361 ENTRY(__put_user_1)
30362 ENTER
30363+
30364+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30365+ GET_THREAD_INFO(%_ASM_BX)
30366 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30367 jae bad_put_user
30368 ASM_STAC
30369-1: movb %al,(%_ASM_CX)
30370+
30371+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30372+ mov pax_user_shadow_base,%_ASM_BX
30373+ cmp %_ASM_BX,%_ASM_CX
30374+ jb 1234f
30375+ xor %ebx,%ebx
30376+1234:
30377+#endif
30378+
30379+#endif
30380+
30381+1: __copyuser_seg movb %al,(_DEST)
30382 xor %eax,%eax
30383 EXIT
30384 ENDPROC(__put_user_1)
30385
30386 ENTRY(__put_user_2)
30387 ENTER
30388+
30389+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30390+ GET_THREAD_INFO(%_ASM_BX)
30391 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30392 sub $1,%_ASM_BX
30393 cmp %_ASM_BX,%_ASM_CX
30394 jae bad_put_user
30395 ASM_STAC
30396-2: movw %ax,(%_ASM_CX)
30397+
30398+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30399+ mov pax_user_shadow_base,%_ASM_BX
30400+ cmp %_ASM_BX,%_ASM_CX
30401+ jb 1234f
30402+ xor %ebx,%ebx
30403+1234:
30404+#endif
30405+
30406+#endif
30407+
30408+2: __copyuser_seg movw %ax,(_DEST)
30409 xor %eax,%eax
30410 EXIT
30411 ENDPROC(__put_user_2)
30412
30413 ENTRY(__put_user_4)
30414 ENTER
30415+
30416+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30417+ GET_THREAD_INFO(%_ASM_BX)
30418 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30419 sub $3,%_ASM_BX
30420 cmp %_ASM_BX,%_ASM_CX
30421 jae bad_put_user
30422 ASM_STAC
30423-3: movl %eax,(%_ASM_CX)
30424+
30425+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30426+ mov pax_user_shadow_base,%_ASM_BX
30427+ cmp %_ASM_BX,%_ASM_CX
30428+ jb 1234f
30429+ xor %ebx,%ebx
30430+1234:
30431+#endif
30432+
30433+#endif
30434+
30435+3: __copyuser_seg movl %eax,(_DEST)
30436 xor %eax,%eax
30437 EXIT
30438 ENDPROC(__put_user_4)
30439
30440 ENTRY(__put_user_8)
30441 ENTER
30442+
30443+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30444+ GET_THREAD_INFO(%_ASM_BX)
30445 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30446 sub $7,%_ASM_BX
30447 cmp %_ASM_BX,%_ASM_CX
30448 jae bad_put_user
30449 ASM_STAC
30450-4: mov %_ASM_AX,(%_ASM_CX)
30451+
30452+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30453+ mov pax_user_shadow_base,%_ASM_BX
30454+ cmp %_ASM_BX,%_ASM_CX
30455+ jb 1234f
30456+ xor %ebx,%ebx
30457+1234:
30458+#endif
30459+
30460+#endif
30461+
30462+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30463 #ifdef CONFIG_X86_32
30464-5: movl %edx,4(%_ASM_CX)
30465+5: __copyuser_seg movl %edx,4(_DEST)
30466 #endif
30467 xor %eax,%eax
30468 EXIT
30469diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30470index 1cad221..de671ee 100644
30471--- a/arch/x86/lib/rwlock.S
30472+++ b/arch/x86/lib/rwlock.S
30473@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30474 FRAME
30475 0: LOCK_PREFIX
30476 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30477+
30478+#ifdef CONFIG_PAX_REFCOUNT
30479+ jno 1234f
30480+ LOCK_PREFIX
30481+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30482+ int $4
30483+1234:
30484+ _ASM_EXTABLE(1234b, 1234b)
30485+#endif
30486+
30487 1: rep; nop
30488 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30489 jne 1b
30490 LOCK_PREFIX
30491 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30492+
30493+#ifdef CONFIG_PAX_REFCOUNT
30494+ jno 1234f
30495+ LOCK_PREFIX
30496+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30497+ int $4
30498+1234:
30499+ _ASM_EXTABLE(1234b, 1234b)
30500+#endif
30501+
30502 jnz 0b
30503 ENDFRAME
30504+ pax_force_retaddr
30505 ret
30506 CFI_ENDPROC
30507 END(__write_lock_failed)
30508@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30509 FRAME
30510 0: LOCK_PREFIX
30511 READ_LOCK_SIZE(inc) (%__lock_ptr)
30512+
30513+#ifdef CONFIG_PAX_REFCOUNT
30514+ jno 1234f
30515+ LOCK_PREFIX
30516+ READ_LOCK_SIZE(dec) (%__lock_ptr)
30517+ int $4
30518+1234:
30519+ _ASM_EXTABLE(1234b, 1234b)
30520+#endif
30521+
30522 1: rep; nop
30523 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30524 js 1b
30525 LOCK_PREFIX
30526 READ_LOCK_SIZE(dec) (%__lock_ptr)
30527+
30528+#ifdef CONFIG_PAX_REFCOUNT
30529+ jno 1234f
30530+ LOCK_PREFIX
30531+ READ_LOCK_SIZE(inc) (%__lock_ptr)
30532+ int $4
30533+1234:
30534+ _ASM_EXTABLE(1234b, 1234b)
30535+#endif
30536+
30537 js 0b
30538 ENDFRAME
30539+ pax_force_retaddr
30540 ret
30541 CFI_ENDPROC
30542 END(__read_lock_failed)
30543diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30544index 5dff5f0..cadebf4 100644
30545--- a/arch/x86/lib/rwsem.S
30546+++ b/arch/x86/lib/rwsem.S
30547@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30548 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30549 CFI_RESTORE __ASM_REG(dx)
30550 restore_common_regs
30551+ pax_force_retaddr
30552 ret
30553 CFI_ENDPROC
30554 ENDPROC(call_rwsem_down_read_failed)
30555@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30556 movq %rax,%rdi
30557 call rwsem_down_write_failed
30558 restore_common_regs
30559+ pax_force_retaddr
30560 ret
30561 CFI_ENDPROC
30562 ENDPROC(call_rwsem_down_write_failed)
30563@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30564 movq %rax,%rdi
30565 call rwsem_wake
30566 restore_common_regs
30567-1: ret
30568+1: pax_force_retaddr
30569+ ret
30570 CFI_ENDPROC
30571 ENDPROC(call_rwsem_wake)
30572
30573@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30574 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30575 CFI_RESTORE __ASM_REG(dx)
30576 restore_common_regs
30577+ pax_force_retaddr
30578 ret
30579 CFI_ENDPROC
30580 ENDPROC(call_rwsem_downgrade_wake)
30581diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30582index a63efd6..8149fbe 100644
30583--- a/arch/x86/lib/thunk_64.S
30584+++ b/arch/x86/lib/thunk_64.S
30585@@ -8,6 +8,7 @@
30586 #include <linux/linkage.h>
30587 #include <asm/dwarf2.h>
30588 #include <asm/calling.h>
30589+#include <asm/alternative-asm.h>
30590
30591 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30592 .macro THUNK name, func, put_ret_addr_in_rdi=0
30593@@ -15,11 +16,11 @@
30594 \name:
30595 CFI_STARTPROC
30596
30597- /* this one pushes 9 elems, the next one would be %rIP */
30598- SAVE_ARGS
30599+ /* this one pushes 15+1 elems, the next one would be %rIP */
30600+ SAVE_ARGS 8
30601
30602 .if \put_ret_addr_in_rdi
30603- movq_cfi_restore 9*8, rdi
30604+ movq_cfi_restore RIP, rdi
30605 .endif
30606
30607 call \func
30608@@ -38,8 +39,9 @@
30609
30610 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30611 CFI_STARTPROC
30612- SAVE_ARGS
30613+ SAVE_ARGS 8
30614 restore:
30615- RESTORE_ARGS
30616+ RESTORE_ARGS 1,8
30617+ pax_force_retaddr
30618 ret
30619 CFI_ENDPROC
30620diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30621index e2f5e21..4b22130 100644
30622--- a/arch/x86/lib/usercopy_32.c
30623+++ b/arch/x86/lib/usercopy_32.c
30624@@ -42,11 +42,13 @@ do { \
30625 int __d0; \
30626 might_fault(); \
30627 __asm__ __volatile__( \
30628+ __COPYUSER_SET_ES \
30629 ASM_STAC "\n" \
30630 "0: rep; stosl\n" \
30631 " movl %2,%0\n" \
30632 "1: rep; stosb\n" \
30633 "2: " ASM_CLAC "\n" \
30634+ __COPYUSER_RESTORE_ES \
30635 ".section .fixup,\"ax\"\n" \
30636 "3: lea 0(%2,%0,4),%0\n" \
30637 " jmp 2b\n" \
30638@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30639
30640 #ifdef CONFIG_X86_INTEL_USERCOPY
30641 static unsigned long
30642-__copy_user_intel(void __user *to, const void *from, unsigned long size)
30643+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30644 {
30645 int d0, d1;
30646 __asm__ __volatile__(
30647@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30648 " .align 2,0x90\n"
30649 "3: movl 0(%4), %%eax\n"
30650 "4: movl 4(%4), %%edx\n"
30651- "5: movl %%eax, 0(%3)\n"
30652- "6: movl %%edx, 4(%3)\n"
30653+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30654+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30655 "7: movl 8(%4), %%eax\n"
30656 "8: movl 12(%4),%%edx\n"
30657- "9: movl %%eax, 8(%3)\n"
30658- "10: movl %%edx, 12(%3)\n"
30659+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30660+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30661 "11: movl 16(%4), %%eax\n"
30662 "12: movl 20(%4), %%edx\n"
30663- "13: movl %%eax, 16(%3)\n"
30664- "14: movl %%edx, 20(%3)\n"
30665+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30666+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30667 "15: movl 24(%4), %%eax\n"
30668 "16: movl 28(%4), %%edx\n"
30669- "17: movl %%eax, 24(%3)\n"
30670- "18: movl %%edx, 28(%3)\n"
30671+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30672+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30673 "19: movl 32(%4), %%eax\n"
30674 "20: movl 36(%4), %%edx\n"
30675- "21: movl %%eax, 32(%3)\n"
30676- "22: movl %%edx, 36(%3)\n"
30677+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30678+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30679 "23: movl 40(%4), %%eax\n"
30680 "24: movl 44(%4), %%edx\n"
30681- "25: movl %%eax, 40(%3)\n"
30682- "26: movl %%edx, 44(%3)\n"
30683+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30684+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30685 "27: movl 48(%4), %%eax\n"
30686 "28: movl 52(%4), %%edx\n"
30687- "29: movl %%eax, 48(%3)\n"
30688- "30: movl %%edx, 52(%3)\n"
30689+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30690+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30691 "31: movl 56(%4), %%eax\n"
30692 "32: movl 60(%4), %%edx\n"
30693- "33: movl %%eax, 56(%3)\n"
30694- "34: movl %%edx, 60(%3)\n"
30695+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30696+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30697 " addl $-64, %0\n"
30698 " addl $64, %4\n"
30699 " addl $64, %3\n"
30700@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30701 " shrl $2, %0\n"
30702 " andl $3, %%eax\n"
30703 " cld\n"
30704+ __COPYUSER_SET_ES
30705 "99: rep; movsl\n"
30706 "36: movl %%eax, %0\n"
30707 "37: rep; movsb\n"
30708 "100:\n"
30709+ __COPYUSER_RESTORE_ES
30710+ ".section .fixup,\"ax\"\n"
30711+ "101: lea 0(%%eax,%0,4),%0\n"
30712+ " jmp 100b\n"
30713+ ".previous\n"
30714+ _ASM_EXTABLE(1b,100b)
30715+ _ASM_EXTABLE(2b,100b)
30716+ _ASM_EXTABLE(3b,100b)
30717+ _ASM_EXTABLE(4b,100b)
30718+ _ASM_EXTABLE(5b,100b)
30719+ _ASM_EXTABLE(6b,100b)
30720+ _ASM_EXTABLE(7b,100b)
30721+ _ASM_EXTABLE(8b,100b)
30722+ _ASM_EXTABLE(9b,100b)
30723+ _ASM_EXTABLE(10b,100b)
30724+ _ASM_EXTABLE(11b,100b)
30725+ _ASM_EXTABLE(12b,100b)
30726+ _ASM_EXTABLE(13b,100b)
30727+ _ASM_EXTABLE(14b,100b)
30728+ _ASM_EXTABLE(15b,100b)
30729+ _ASM_EXTABLE(16b,100b)
30730+ _ASM_EXTABLE(17b,100b)
30731+ _ASM_EXTABLE(18b,100b)
30732+ _ASM_EXTABLE(19b,100b)
30733+ _ASM_EXTABLE(20b,100b)
30734+ _ASM_EXTABLE(21b,100b)
30735+ _ASM_EXTABLE(22b,100b)
30736+ _ASM_EXTABLE(23b,100b)
30737+ _ASM_EXTABLE(24b,100b)
30738+ _ASM_EXTABLE(25b,100b)
30739+ _ASM_EXTABLE(26b,100b)
30740+ _ASM_EXTABLE(27b,100b)
30741+ _ASM_EXTABLE(28b,100b)
30742+ _ASM_EXTABLE(29b,100b)
30743+ _ASM_EXTABLE(30b,100b)
30744+ _ASM_EXTABLE(31b,100b)
30745+ _ASM_EXTABLE(32b,100b)
30746+ _ASM_EXTABLE(33b,100b)
30747+ _ASM_EXTABLE(34b,100b)
30748+ _ASM_EXTABLE(35b,100b)
30749+ _ASM_EXTABLE(36b,100b)
30750+ _ASM_EXTABLE(37b,100b)
30751+ _ASM_EXTABLE(99b,101b)
30752+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
30753+ : "1"(to), "2"(from), "0"(size)
30754+ : "eax", "edx", "memory");
30755+ return size;
30756+}
30757+
30758+static unsigned long
30759+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30760+{
30761+ int d0, d1;
30762+ __asm__ __volatile__(
30763+ " .align 2,0x90\n"
30764+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30765+ " cmpl $67, %0\n"
30766+ " jbe 3f\n"
30767+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30768+ " .align 2,0x90\n"
30769+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30770+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30771+ "5: movl %%eax, 0(%3)\n"
30772+ "6: movl %%edx, 4(%3)\n"
30773+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30774+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30775+ "9: movl %%eax, 8(%3)\n"
30776+ "10: movl %%edx, 12(%3)\n"
30777+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30778+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30779+ "13: movl %%eax, 16(%3)\n"
30780+ "14: movl %%edx, 20(%3)\n"
30781+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30782+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30783+ "17: movl %%eax, 24(%3)\n"
30784+ "18: movl %%edx, 28(%3)\n"
30785+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30786+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30787+ "21: movl %%eax, 32(%3)\n"
30788+ "22: movl %%edx, 36(%3)\n"
30789+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30790+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30791+ "25: movl %%eax, 40(%3)\n"
30792+ "26: movl %%edx, 44(%3)\n"
30793+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30794+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30795+ "29: movl %%eax, 48(%3)\n"
30796+ "30: movl %%edx, 52(%3)\n"
30797+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30798+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30799+ "33: movl %%eax, 56(%3)\n"
30800+ "34: movl %%edx, 60(%3)\n"
30801+ " addl $-64, %0\n"
30802+ " addl $64, %4\n"
30803+ " addl $64, %3\n"
30804+ " cmpl $63, %0\n"
30805+ " ja 1b\n"
30806+ "35: movl %0, %%eax\n"
30807+ " shrl $2, %0\n"
30808+ " andl $3, %%eax\n"
30809+ " cld\n"
30810+ "99: rep; "__copyuser_seg" movsl\n"
30811+ "36: movl %%eax, %0\n"
30812+ "37: rep; "__copyuser_seg" movsb\n"
30813+ "100:\n"
30814 ".section .fixup,\"ax\"\n"
30815 "101: lea 0(%%eax,%0,4),%0\n"
30816 " jmp 100b\n"
30817@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30818 int d0, d1;
30819 __asm__ __volatile__(
30820 " .align 2,0x90\n"
30821- "0: movl 32(%4), %%eax\n"
30822+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30823 " cmpl $67, %0\n"
30824 " jbe 2f\n"
30825- "1: movl 64(%4), %%eax\n"
30826+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30827 " .align 2,0x90\n"
30828- "2: movl 0(%4), %%eax\n"
30829- "21: movl 4(%4), %%edx\n"
30830+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30831+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30832 " movl %%eax, 0(%3)\n"
30833 " movl %%edx, 4(%3)\n"
30834- "3: movl 8(%4), %%eax\n"
30835- "31: movl 12(%4),%%edx\n"
30836+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30837+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30838 " movl %%eax, 8(%3)\n"
30839 " movl %%edx, 12(%3)\n"
30840- "4: movl 16(%4), %%eax\n"
30841- "41: movl 20(%4), %%edx\n"
30842+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30843+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30844 " movl %%eax, 16(%3)\n"
30845 " movl %%edx, 20(%3)\n"
30846- "10: movl 24(%4), %%eax\n"
30847- "51: movl 28(%4), %%edx\n"
30848+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30849+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30850 " movl %%eax, 24(%3)\n"
30851 " movl %%edx, 28(%3)\n"
30852- "11: movl 32(%4), %%eax\n"
30853- "61: movl 36(%4), %%edx\n"
30854+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30855+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30856 " movl %%eax, 32(%3)\n"
30857 " movl %%edx, 36(%3)\n"
30858- "12: movl 40(%4), %%eax\n"
30859- "71: movl 44(%4), %%edx\n"
30860+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30861+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30862 " movl %%eax, 40(%3)\n"
30863 " movl %%edx, 44(%3)\n"
30864- "13: movl 48(%4), %%eax\n"
30865- "81: movl 52(%4), %%edx\n"
30866+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30867+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30868 " movl %%eax, 48(%3)\n"
30869 " movl %%edx, 52(%3)\n"
30870- "14: movl 56(%4), %%eax\n"
30871- "91: movl 60(%4), %%edx\n"
30872+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30873+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30874 " movl %%eax, 56(%3)\n"
30875 " movl %%edx, 60(%3)\n"
30876 " addl $-64, %0\n"
30877@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30878 " shrl $2, %0\n"
30879 " andl $3, %%eax\n"
30880 " cld\n"
30881- "6: rep; movsl\n"
30882+ "6: rep; "__copyuser_seg" movsl\n"
30883 " movl %%eax,%0\n"
30884- "7: rep; movsb\n"
30885+ "7: rep; "__copyuser_seg" movsb\n"
30886 "8:\n"
30887 ".section .fixup,\"ax\"\n"
30888 "9: lea 0(%%eax,%0,4),%0\n"
30889@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30890
30891 __asm__ __volatile__(
30892 " .align 2,0x90\n"
30893- "0: movl 32(%4), %%eax\n"
30894+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30895 " cmpl $67, %0\n"
30896 " jbe 2f\n"
30897- "1: movl 64(%4), %%eax\n"
30898+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30899 " .align 2,0x90\n"
30900- "2: movl 0(%4), %%eax\n"
30901- "21: movl 4(%4), %%edx\n"
30902+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30903+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30904 " movnti %%eax, 0(%3)\n"
30905 " movnti %%edx, 4(%3)\n"
30906- "3: movl 8(%4), %%eax\n"
30907- "31: movl 12(%4),%%edx\n"
30908+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30909+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30910 " movnti %%eax, 8(%3)\n"
30911 " movnti %%edx, 12(%3)\n"
30912- "4: movl 16(%4), %%eax\n"
30913- "41: movl 20(%4), %%edx\n"
30914+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30915+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30916 " movnti %%eax, 16(%3)\n"
30917 " movnti %%edx, 20(%3)\n"
30918- "10: movl 24(%4), %%eax\n"
30919- "51: movl 28(%4), %%edx\n"
30920+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30921+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30922 " movnti %%eax, 24(%3)\n"
30923 " movnti %%edx, 28(%3)\n"
30924- "11: movl 32(%4), %%eax\n"
30925- "61: movl 36(%4), %%edx\n"
30926+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30927+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30928 " movnti %%eax, 32(%3)\n"
30929 " movnti %%edx, 36(%3)\n"
30930- "12: movl 40(%4), %%eax\n"
30931- "71: movl 44(%4), %%edx\n"
30932+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30933+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30934 " movnti %%eax, 40(%3)\n"
30935 " movnti %%edx, 44(%3)\n"
30936- "13: movl 48(%4), %%eax\n"
30937- "81: movl 52(%4), %%edx\n"
30938+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30939+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30940 " movnti %%eax, 48(%3)\n"
30941 " movnti %%edx, 52(%3)\n"
30942- "14: movl 56(%4), %%eax\n"
30943- "91: movl 60(%4), %%edx\n"
30944+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30945+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30946 " movnti %%eax, 56(%3)\n"
30947 " movnti %%edx, 60(%3)\n"
30948 " addl $-64, %0\n"
30949@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30950 " shrl $2, %0\n"
30951 " andl $3, %%eax\n"
30952 " cld\n"
30953- "6: rep; movsl\n"
30954+ "6: rep; "__copyuser_seg" movsl\n"
30955 " movl %%eax,%0\n"
30956- "7: rep; movsb\n"
30957+ "7: rep; "__copyuser_seg" movsb\n"
30958 "8:\n"
30959 ".section .fixup,\"ax\"\n"
30960 "9: lea 0(%%eax,%0,4),%0\n"
30961@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30962
30963 __asm__ __volatile__(
30964 " .align 2,0x90\n"
30965- "0: movl 32(%4), %%eax\n"
30966+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30967 " cmpl $67, %0\n"
30968 " jbe 2f\n"
30969- "1: movl 64(%4), %%eax\n"
30970+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30971 " .align 2,0x90\n"
30972- "2: movl 0(%4), %%eax\n"
30973- "21: movl 4(%4), %%edx\n"
30974+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30975+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30976 " movnti %%eax, 0(%3)\n"
30977 " movnti %%edx, 4(%3)\n"
30978- "3: movl 8(%4), %%eax\n"
30979- "31: movl 12(%4),%%edx\n"
30980+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30981+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30982 " movnti %%eax, 8(%3)\n"
30983 " movnti %%edx, 12(%3)\n"
30984- "4: movl 16(%4), %%eax\n"
30985- "41: movl 20(%4), %%edx\n"
30986+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30987+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30988 " movnti %%eax, 16(%3)\n"
30989 " movnti %%edx, 20(%3)\n"
30990- "10: movl 24(%4), %%eax\n"
30991- "51: movl 28(%4), %%edx\n"
30992+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30993+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30994 " movnti %%eax, 24(%3)\n"
30995 " movnti %%edx, 28(%3)\n"
30996- "11: movl 32(%4), %%eax\n"
30997- "61: movl 36(%4), %%edx\n"
30998+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30999+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31000 " movnti %%eax, 32(%3)\n"
31001 " movnti %%edx, 36(%3)\n"
31002- "12: movl 40(%4), %%eax\n"
31003- "71: movl 44(%4), %%edx\n"
31004+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31005+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31006 " movnti %%eax, 40(%3)\n"
31007 " movnti %%edx, 44(%3)\n"
31008- "13: movl 48(%4), %%eax\n"
31009- "81: movl 52(%4), %%edx\n"
31010+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31011+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31012 " movnti %%eax, 48(%3)\n"
31013 " movnti %%edx, 52(%3)\n"
31014- "14: movl 56(%4), %%eax\n"
31015- "91: movl 60(%4), %%edx\n"
31016+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31017+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31018 " movnti %%eax, 56(%3)\n"
31019 " movnti %%edx, 60(%3)\n"
31020 " addl $-64, %0\n"
31021@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31022 " shrl $2, %0\n"
31023 " andl $3, %%eax\n"
31024 " cld\n"
31025- "6: rep; movsl\n"
31026+ "6: rep; "__copyuser_seg" movsl\n"
31027 " movl %%eax,%0\n"
31028- "7: rep; movsb\n"
31029+ "7: rep; "__copyuser_seg" movsb\n"
31030 "8:\n"
31031 ".section .fixup,\"ax\"\n"
31032 "9: lea 0(%%eax,%0,4),%0\n"
31033@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31034 */
31035 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31036 unsigned long size);
31037-unsigned long __copy_user_intel(void __user *to, const void *from,
31038+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31039+ unsigned long size);
31040+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31041 unsigned long size);
31042 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31043 const void __user *from, unsigned long size);
31044 #endif /* CONFIG_X86_INTEL_USERCOPY */
31045
31046 /* Generic arbitrary sized copy. */
31047-#define __copy_user(to, from, size) \
31048+#define __copy_user(to, from, size, prefix, set, restore) \
31049 do { \
31050 int __d0, __d1, __d2; \
31051 __asm__ __volatile__( \
31052+ set \
31053 " cmp $7,%0\n" \
31054 " jbe 1f\n" \
31055 " movl %1,%0\n" \
31056 " negl %0\n" \
31057 " andl $7,%0\n" \
31058 " subl %0,%3\n" \
31059- "4: rep; movsb\n" \
31060+ "4: rep; "prefix"movsb\n" \
31061 " movl %3,%0\n" \
31062 " shrl $2,%0\n" \
31063 " andl $3,%3\n" \
31064 " .align 2,0x90\n" \
31065- "0: rep; movsl\n" \
31066+ "0: rep; "prefix"movsl\n" \
31067 " movl %3,%0\n" \
31068- "1: rep; movsb\n" \
31069+ "1: rep; "prefix"movsb\n" \
31070 "2:\n" \
31071+ restore \
31072 ".section .fixup,\"ax\"\n" \
31073 "5: addl %3,%0\n" \
31074 " jmp 2b\n" \
31075@@ -538,14 +650,14 @@ do { \
31076 " negl %0\n" \
31077 " andl $7,%0\n" \
31078 " subl %0,%3\n" \
31079- "4: rep; movsb\n" \
31080+ "4: rep; "__copyuser_seg"movsb\n" \
31081 " movl %3,%0\n" \
31082 " shrl $2,%0\n" \
31083 " andl $3,%3\n" \
31084 " .align 2,0x90\n" \
31085- "0: rep; movsl\n" \
31086+ "0: rep; "__copyuser_seg"movsl\n" \
31087 " movl %3,%0\n" \
31088- "1: rep; movsb\n" \
31089+ "1: rep; "__copyuser_seg"movsb\n" \
31090 "2:\n" \
31091 ".section .fixup,\"ax\"\n" \
31092 "5: addl %3,%0\n" \
31093@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31094 {
31095 stac();
31096 if (movsl_is_ok(to, from, n))
31097- __copy_user(to, from, n);
31098+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31099 else
31100- n = __copy_user_intel(to, from, n);
31101+ n = __generic_copy_to_user_intel(to, from, n);
31102 clac();
31103 return n;
31104 }
31105@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31106 {
31107 stac();
31108 if (movsl_is_ok(to, from, n))
31109- __copy_user(to, from, n);
31110+ __copy_user(to, from, n, __copyuser_seg, "", "");
31111 else
31112- n = __copy_user_intel((void __user *)to,
31113- (const void *)from, n);
31114+ n = __generic_copy_from_user_intel(to, from, n);
31115 clac();
31116 return n;
31117 }
31118@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31119 if (n > 64 && cpu_has_xmm2)
31120 n = __copy_user_intel_nocache(to, from, n);
31121 else
31122- __copy_user(to, from, n);
31123+ __copy_user(to, from, n, __copyuser_seg, "", "");
31124 #else
31125- __copy_user(to, from, n);
31126+ __copy_user(to, from, n, __copyuser_seg, "", "");
31127 #endif
31128 clac();
31129 return n;
31130 }
31131 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31132
31133-/**
31134- * copy_to_user: - Copy a block of data into user space.
31135- * @to: Destination address, in user space.
31136- * @from: Source address, in kernel space.
31137- * @n: Number of bytes to copy.
31138- *
31139- * Context: User context only. This function may sleep.
31140- *
31141- * Copy data from kernel space to user space.
31142- *
31143- * Returns number of bytes that could not be copied.
31144- * On success, this will be zero.
31145- */
31146-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31147+#ifdef CONFIG_PAX_MEMORY_UDEREF
31148+void __set_fs(mm_segment_t x)
31149 {
31150- if (access_ok(VERIFY_WRITE, to, n))
31151- n = __copy_to_user(to, from, n);
31152- return n;
31153+ switch (x.seg) {
31154+ case 0:
31155+ loadsegment(gs, 0);
31156+ break;
31157+ case TASK_SIZE_MAX:
31158+ loadsegment(gs, __USER_DS);
31159+ break;
31160+ case -1UL:
31161+ loadsegment(gs, __KERNEL_DS);
31162+ break;
31163+ default:
31164+ BUG();
31165+ }
31166 }
31167-EXPORT_SYMBOL(_copy_to_user);
31168+EXPORT_SYMBOL(__set_fs);
31169
31170-/**
31171- * copy_from_user: - Copy a block of data from user space.
31172- * @to: Destination address, in kernel space.
31173- * @from: Source address, in user space.
31174- * @n: Number of bytes to copy.
31175- *
31176- * Context: User context only. This function may sleep.
31177- *
31178- * Copy data from user space to kernel space.
31179- *
31180- * Returns number of bytes that could not be copied.
31181- * On success, this will be zero.
31182- *
31183- * If some data could not be copied, this function will pad the copied
31184- * data to the requested size using zero bytes.
31185- */
31186-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31187+void set_fs(mm_segment_t x)
31188 {
31189- if (access_ok(VERIFY_READ, from, n))
31190- n = __copy_from_user(to, from, n);
31191- else
31192- memset(to, 0, n);
31193- return n;
31194+ current_thread_info()->addr_limit = x;
31195+ __set_fs(x);
31196 }
31197-EXPORT_SYMBOL(_copy_from_user);
31198+EXPORT_SYMBOL(set_fs);
31199+#endif
31200diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31201index c905e89..01ab928 100644
31202--- a/arch/x86/lib/usercopy_64.c
31203+++ b/arch/x86/lib/usercopy_64.c
31204@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31205 might_fault();
31206 /* no memory constraint because it doesn't change any memory gcc knows
31207 about */
31208+ pax_open_userland();
31209 stac();
31210 asm volatile(
31211 " testq %[size8],%[size8]\n"
31212@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31213 _ASM_EXTABLE(0b,3b)
31214 _ASM_EXTABLE(1b,2b)
31215 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31216- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31217+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31218 [zero] "r" (0UL), [eight] "r" (8UL));
31219 clac();
31220+ pax_close_userland();
31221 return size;
31222 }
31223 EXPORT_SYMBOL(__clear_user);
31224@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31225 }
31226 EXPORT_SYMBOL(clear_user);
31227
31228-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31229+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31230 {
31231- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31232- return copy_user_generic((__force void *)to, (__force void *)from, len);
31233- }
31234- return len;
31235+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31236+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31237+ return len;
31238 }
31239 EXPORT_SYMBOL(copy_in_user);
31240
31241@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31242 * it is not necessary to optimize tail handling.
31243 */
31244 __visible unsigned long
31245-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31246+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31247 {
31248 char c;
31249 unsigned zero_len;
31250
31251+ clac();
31252+ pax_close_userland();
31253 for (; len; --len, to++) {
31254 if (__get_user_nocheck(c, from++, sizeof(char)))
31255 break;
31256@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31257 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31258 if (__put_user_nocheck(c, to++, sizeof(char)))
31259 break;
31260- clac();
31261 return len;
31262 }
31263diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31264index 6a19ad9..1c48f9a 100644
31265--- a/arch/x86/mm/Makefile
31266+++ b/arch/x86/mm/Makefile
31267@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31268 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31269
31270 obj-$(CONFIG_MEMTEST) += memtest.o
31271+
31272+quote:="
31273+obj-$(CONFIG_X86_64) += uderef_64.o
31274+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31275diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31276index 903ec1e..c4166b2 100644
31277--- a/arch/x86/mm/extable.c
31278+++ b/arch/x86/mm/extable.c
31279@@ -6,12 +6,24 @@
31280 static inline unsigned long
31281 ex_insn_addr(const struct exception_table_entry *x)
31282 {
31283- return (unsigned long)&x->insn + x->insn;
31284+ unsigned long reloc = 0;
31285+
31286+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31287+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31288+#endif
31289+
31290+ return (unsigned long)&x->insn + x->insn + reloc;
31291 }
31292 static inline unsigned long
31293 ex_fixup_addr(const struct exception_table_entry *x)
31294 {
31295- return (unsigned long)&x->fixup + x->fixup;
31296+ unsigned long reloc = 0;
31297+
31298+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31299+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31300+#endif
31301+
31302+ return (unsigned long)&x->fixup + x->fixup + reloc;
31303 }
31304
31305 int fixup_exception(struct pt_regs *regs)
31306@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31307 unsigned long new_ip;
31308
31309 #ifdef CONFIG_PNPBIOS
31310- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31311+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31312 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31313 extern u32 pnp_bios_is_utter_crap;
31314 pnp_bios_is_utter_crap = 1;
31315@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31316 i += 4;
31317 p->fixup -= i;
31318 i += 4;
31319+
31320+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31321+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31322+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31323+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31324+#endif
31325+
31326 }
31327 }
31328
31329diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31330index 8e57229..31cce89 100644
31331--- a/arch/x86/mm/fault.c
31332+++ b/arch/x86/mm/fault.c
31333@@ -14,11 +14,18 @@
31334 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31335 #include <linux/prefetch.h> /* prefetchw */
31336 #include <linux/context_tracking.h> /* exception_enter(), ... */
31337+#include <linux/unistd.h>
31338+#include <linux/compiler.h>
31339
31340 #include <asm/traps.h> /* dotraplinkage, ... */
31341 #include <asm/pgalloc.h> /* pgd_*(), ... */
31342 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31343 #include <asm/fixmap.h> /* VSYSCALL_START */
31344+#include <asm/tlbflush.h>
31345+
31346+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31347+#include <asm/stacktrace.h>
31348+#endif
31349
31350 #define CREATE_TRACE_POINTS
31351 #include <asm/trace/exceptions.h>
31352@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31353 int ret = 0;
31354
31355 /* kprobe_running() needs smp_processor_id() */
31356- if (kprobes_built_in() && !user_mode_vm(regs)) {
31357+ if (kprobes_built_in() && !user_mode(regs)) {
31358 preempt_disable();
31359 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31360 ret = 1;
31361@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31362 return !instr_lo || (instr_lo>>1) == 1;
31363 case 0x00:
31364 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31365- if (probe_kernel_address(instr, opcode))
31366+ if (user_mode(regs)) {
31367+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31368+ return 0;
31369+ } else if (probe_kernel_address(instr, opcode))
31370 return 0;
31371
31372 *prefetch = (instr_lo == 0xF) &&
31373@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31374 while (instr < max_instr) {
31375 unsigned char opcode;
31376
31377- if (probe_kernel_address(instr, opcode))
31378+ if (user_mode(regs)) {
31379+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31380+ break;
31381+ } else if (probe_kernel_address(instr, opcode))
31382 break;
31383
31384 instr++;
31385@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31386 force_sig_info(si_signo, &info, tsk);
31387 }
31388
31389+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31390+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31391+#endif
31392+
31393+#ifdef CONFIG_PAX_EMUTRAMP
31394+static int pax_handle_fetch_fault(struct pt_regs *regs);
31395+#endif
31396+
31397+#ifdef CONFIG_PAX_PAGEEXEC
31398+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31399+{
31400+ pgd_t *pgd;
31401+ pud_t *pud;
31402+ pmd_t *pmd;
31403+
31404+ pgd = pgd_offset(mm, address);
31405+ if (!pgd_present(*pgd))
31406+ return NULL;
31407+ pud = pud_offset(pgd, address);
31408+ if (!pud_present(*pud))
31409+ return NULL;
31410+ pmd = pmd_offset(pud, address);
31411+ if (!pmd_present(*pmd))
31412+ return NULL;
31413+ return pmd;
31414+}
31415+#endif
31416+
31417 DEFINE_SPINLOCK(pgd_lock);
31418 LIST_HEAD(pgd_list);
31419
31420@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31421 for (address = VMALLOC_START & PMD_MASK;
31422 address >= TASK_SIZE && address < FIXADDR_TOP;
31423 address += PMD_SIZE) {
31424+
31425+#ifdef CONFIG_PAX_PER_CPU_PGD
31426+ unsigned long cpu;
31427+#else
31428 struct page *page;
31429+#endif
31430
31431 spin_lock(&pgd_lock);
31432+
31433+#ifdef CONFIG_PAX_PER_CPU_PGD
31434+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31435+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31436+ pmd_t *ret;
31437+
31438+ ret = vmalloc_sync_one(pgd, address);
31439+ if (!ret)
31440+ break;
31441+ pgd = get_cpu_pgd(cpu, kernel);
31442+#else
31443 list_for_each_entry(page, &pgd_list, lru) {
31444+ pgd_t *pgd;
31445 spinlock_t *pgt_lock;
31446 pmd_t *ret;
31447
31448@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31449 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31450
31451 spin_lock(pgt_lock);
31452- ret = vmalloc_sync_one(page_address(page), address);
31453+ pgd = page_address(page);
31454+#endif
31455+
31456+ ret = vmalloc_sync_one(pgd, address);
31457+
31458+#ifndef CONFIG_PAX_PER_CPU_PGD
31459 spin_unlock(pgt_lock);
31460+#endif
31461
31462 if (!ret)
31463 break;
31464@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31465 * an interrupt in the middle of a task switch..
31466 */
31467 pgd_paddr = read_cr3();
31468+
31469+#ifdef CONFIG_PAX_PER_CPU_PGD
31470+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31471+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31472+#endif
31473+
31474 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31475 if (!pmd_k)
31476 return -1;
31477@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31478 * happen within a race in page table update. In the later
31479 * case just flush:
31480 */
31481- pgd = pgd_offset(current->active_mm, address);
31482+
31483 pgd_ref = pgd_offset_k(address);
31484 if (pgd_none(*pgd_ref))
31485 return -1;
31486
31487+#ifdef CONFIG_PAX_PER_CPU_PGD
31488+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31489+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31490+ if (pgd_none(*pgd)) {
31491+ set_pgd(pgd, *pgd_ref);
31492+ arch_flush_lazy_mmu_mode();
31493+ } else {
31494+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31495+ }
31496+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31497+#else
31498+ pgd = pgd_offset(current->active_mm, address);
31499+#endif
31500+
31501 if (pgd_none(*pgd)) {
31502 set_pgd(pgd, *pgd_ref);
31503 arch_flush_lazy_mmu_mode();
31504@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31505 static int is_errata100(struct pt_regs *regs, unsigned long address)
31506 {
31507 #ifdef CONFIG_X86_64
31508- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31509+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31510 return 1;
31511 #endif
31512 return 0;
31513@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31514 }
31515
31516 static const char nx_warning[] = KERN_CRIT
31517-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31518+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31519
31520 static void
31521 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31522@@ -582,7 +666,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31523 if (!oops_may_print())
31524 return;
31525
31526- if (error_code & PF_INSTR) {
31527+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31528 unsigned int level;
31529 pgd_t *pgd;
31530 pte_t *pte;
31531@@ -593,9 +677,21 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31532 pte = lookup_address_in_pgd(pgd, address, &level);
31533
31534 if (pte && pte_present(*pte) && !pte_exec(*pte))
31535- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31536+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31537 }
31538
31539+#ifdef CONFIG_PAX_KERNEXEC
31540+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31541+ if (current->signal->curr_ip)
31542+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31543+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31544+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31545+ else
31546+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31547+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31548+ }
31549+#endif
31550+
31551 printk(KERN_ALERT "BUG: unable to handle kernel ");
31552 if (address < PAGE_SIZE)
31553 printk(KERN_CONT "NULL pointer dereference");
31554@@ -776,6 +872,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31555 return;
31556 }
31557 #endif
31558+
31559+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31560+ if (pax_is_fetch_fault(regs, error_code, address)) {
31561+
31562+#ifdef CONFIG_PAX_EMUTRAMP
31563+ switch (pax_handle_fetch_fault(regs)) {
31564+ case 2:
31565+ return;
31566+ }
31567+#endif
31568+
31569+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31570+ do_group_exit(SIGKILL);
31571+ }
31572+#endif
31573+
31574 /* Kernel addresses are always protection faults: */
31575 if (address >= TASK_SIZE)
31576 error_code |= PF_PROT;
31577@@ -861,7 +973,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31578 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31579 printk(KERN_ERR
31580 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31581- tsk->comm, tsk->pid, address);
31582+ tsk->comm, task_pid_nr(tsk), address);
31583 code = BUS_MCEERR_AR;
31584 }
31585 #endif
31586@@ -915,6 +1027,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31587 return 1;
31588 }
31589
31590+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31591+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31592+{
31593+ pte_t *pte;
31594+ pmd_t *pmd;
31595+ spinlock_t *ptl;
31596+ unsigned char pte_mask;
31597+
31598+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31599+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
31600+ return 0;
31601+
31602+ /* PaX: it's our fault, let's handle it if we can */
31603+
31604+ /* PaX: take a look at read faults before acquiring any locks */
31605+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31606+ /* instruction fetch attempt from a protected page in user mode */
31607+ up_read(&mm->mmap_sem);
31608+
31609+#ifdef CONFIG_PAX_EMUTRAMP
31610+ switch (pax_handle_fetch_fault(regs)) {
31611+ case 2:
31612+ return 1;
31613+ }
31614+#endif
31615+
31616+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31617+ do_group_exit(SIGKILL);
31618+ }
31619+
31620+ pmd = pax_get_pmd(mm, address);
31621+ if (unlikely(!pmd))
31622+ return 0;
31623+
31624+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31625+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31626+ pte_unmap_unlock(pte, ptl);
31627+ return 0;
31628+ }
31629+
31630+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31631+ /* write attempt to a protected page in user mode */
31632+ pte_unmap_unlock(pte, ptl);
31633+ return 0;
31634+ }
31635+
31636+#ifdef CONFIG_SMP
31637+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31638+#else
31639+ if (likely(address > get_limit(regs->cs)))
31640+#endif
31641+ {
31642+ set_pte(pte, pte_mkread(*pte));
31643+ __flush_tlb_one(address);
31644+ pte_unmap_unlock(pte, ptl);
31645+ up_read(&mm->mmap_sem);
31646+ return 1;
31647+ }
31648+
31649+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31650+
31651+ /*
31652+ * PaX: fill DTLB with user rights and retry
31653+ */
31654+ __asm__ __volatile__ (
31655+ "orb %2,(%1)\n"
31656+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31657+/*
31658+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31659+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31660+ * page fault when examined during a TLB load attempt. this is true not only
31661+ * for PTEs holding a non-present entry but also present entries that will
31662+ * raise a page fault (such as those set up by PaX, or the copy-on-write
31663+ * mechanism). in effect it means that we do *not* need to flush the TLBs
31664+ * for our target pages since their PTEs are simply not in the TLBs at all.
31665+
31666+ * the best thing in omitting it is that we gain around 15-20% speed in the
31667+ * fast path of the page fault handler and can get rid of tracing since we
31668+ * can no longer flush unintended entries.
31669+ */
31670+ "invlpg (%0)\n"
31671+#endif
31672+ __copyuser_seg"testb $0,(%0)\n"
31673+ "xorb %3,(%1)\n"
31674+ :
31675+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31676+ : "memory", "cc");
31677+ pte_unmap_unlock(pte, ptl);
31678+ up_read(&mm->mmap_sem);
31679+ return 1;
31680+}
31681+#endif
31682+
31683 /*
31684 * Handle a spurious fault caused by a stale TLB entry.
31685 *
31686@@ -981,6 +1186,9 @@ int show_unhandled_signals = 1;
31687 static inline int
31688 access_error(unsigned long error_code, struct vm_area_struct *vma)
31689 {
31690+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31691+ return 1;
31692+
31693 if (error_code & PF_WRITE) {
31694 /* write, present and write, not present: */
31695 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31696@@ -1015,7 +1223,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31697 if (error_code & PF_USER)
31698 return false;
31699
31700- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31701+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31702 return false;
31703
31704 return true;
31705@@ -1043,6 +1251,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31706 tsk = current;
31707 mm = tsk->mm;
31708
31709+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31710+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31711+ if (!search_exception_tables(regs->ip)) {
31712+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31713+ bad_area_nosemaphore(regs, error_code, address);
31714+ return;
31715+ }
31716+ if (address < pax_user_shadow_base) {
31717+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31718+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31719+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31720+ } else
31721+ address -= pax_user_shadow_base;
31722+ }
31723+#endif
31724+
31725 /*
31726 * Detect and handle instructions that would cause a page fault for
31727 * both a tracked kernel page and a userspace page.
31728@@ -1120,7 +1344,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31729 * User-mode registers count as a user access even for any
31730 * potential system fault or CPU buglet:
31731 */
31732- if (user_mode_vm(regs)) {
31733+ if (user_mode(regs)) {
31734 local_irq_enable();
31735 error_code |= PF_USER;
31736 flags |= FAULT_FLAG_USER;
31737@@ -1167,6 +1391,11 @@ retry:
31738 might_sleep();
31739 }
31740
31741+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31742+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31743+ return;
31744+#endif
31745+
31746 vma = find_vma(mm, address);
31747 if (unlikely(!vma)) {
31748 bad_area(regs, error_code, address);
31749@@ -1178,18 +1407,24 @@ retry:
31750 bad_area(regs, error_code, address);
31751 return;
31752 }
31753- if (error_code & PF_USER) {
31754- /*
31755- * Accessing the stack below %sp is always a bug.
31756- * The large cushion allows instructions like enter
31757- * and pusha to work. ("enter $65535, $31" pushes
31758- * 32 pointers and then decrements %sp by 65535.)
31759- */
31760- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31761- bad_area(regs, error_code, address);
31762- return;
31763- }
31764+ /*
31765+ * Accessing the stack below %sp is always a bug.
31766+ * The large cushion allows instructions like enter
31767+ * and pusha to work. ("enter $65535, $31" pushes
31768+ * 32 pointers and then decrements %sp by 65535.)
31769+ */
31770+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31771+ bad_area(regs, error_code, address);
31772+ return;
31773 }
31774+
31775+#ifdef CONFIG_PAX_SEGMEXEC
31776+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31777+ bad_area(regs, error_code, address);
31778+ return;
31779+ }
31780+#endif
31781+
31782 if (unlikely(expand_stack(vma, address))) {
31783 bad_area(regs, error_code, address);
31784 return;
31785@@ -1301,3 +1536,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31786 exception_exit(prev_state);
31787 }
31788 #endif /* CONFIG_TRACING */
31789+
31790+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31791+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31792+{
31793+ struct mm_struct *mm = current->mm;
31794+ unsigned long ip = regs->ip;
31795+
31796+ if (v8086_mode(regs))
31797+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31798+
31799+#ifdef CONFIG_PAX_PAGEEXEC
31800+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31801+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31802+ return true;
31803+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31804+ return true;
31805+ return false;
31806+ }
31807+#endif
31808+
31809+#ifdef CONFIG_PAX_SEGMEXEC
31810+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31811+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31812+ return true;
31813+ return false;
31814+ }
31815+#endif
31816+
31817+ return false;
31818+}
31819+#endif
31820+
31821+#ifdef CONFIG_PAX_EMUTRAMP
31822+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31823+{
31824+ int err;
31825+
31826+ do { /* PaX: libffi trampoline emulation */
31827+ unsigned char mov, jmp;
31828+ unsigned int addr1, addr2;
31829+
31830+#ifdef CONFIG_X86_64
31831+ if ((regs->ip + 9) >> 32)
31832+ break;
31833+#endif
31834+
31835+ err = get_user(mov, (unsigned char __user *)regs->ip);
31836+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31837+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31838+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31839+
31840+ if (err)
31841+ break;
31842+
31843+ if (mov == 0xB8 && jmp == 0xE9) {
31844+ regs->ax = addr1;
31845+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31846+ return 2;
31847+ }
31848+ } while (0);
31849+
31850+ do { /* PaX: gcc trampoline emulation #1 */
31851+ unsigned char mov1, mov2;
31852+ unsigned short jmp;
31853+ unsigned int addr1, addr2;
31854+
31855+#ifdef CONFIG_X86_64
31856+ if ((regs->ip + 11) >> 32)
31857+ break;
31858+#endif
31859+
31860+ err = get_user(mov1, (unsigned char __user *)regs->ip);
31861+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31862+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31863+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31864+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31865+
31866+ if (err)
31867+ break;
31868+
31869+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31870+ regs->cx = addr1;
31871+ regs->ax = addr2;
31872+ regs->ip = addr2;
31873+ return 2;
31874+ }
31875+ } while (0);
31876+
31877+ do { /* PaX: gcc trampoline emulation #2 */
31878+ unsigned char mov, jmp;
31879+ unsigned int addr1, addr2;
31880+
31881+#ifdef CONFIG_X86_64
31882+ if ((regs->ip + 9) >> 32)
31883+ break;
31884+#endif
31885+
31886+ err = get_user(mov, (unsigned char __user *)regs->ip);
31887+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31888+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31889+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31890+
31891+ if (err)
31892+ break;
31893+
31894+ if (mov == 0xB9 && jmp == 0xE9) {
31895+ regs->cx = addr1;
31896+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31897+ return 2;
31898+ }
31899+ } while (0);
31900+
31901+ return 1; /* PaX in action */
31902+}
31903+
31904+#ifdef CONFIG_X86_64
31905+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31906+{
31907+ int err;
31908+
31909+ do { /* PaX: libffi trampoline emulation */
31910+ unsigned short mov1, mov2, jmp1;
31911+ unsigned char stcclc, jmp2;
31912+ unsigned long addr1, addr2;
31913+
31914+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31915+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31916+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31917+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31918+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31919+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31920+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31921+
31922+ if (err)
31923+ break;
31924+
31925+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31926+ regs->r11 = addr1;
31927+ regs->r10 = addr2;
31928+ if (stcclc == 0xF8)
31929+ regs->flags &= ~X86_EFLAGS_CF;
31930+ else
31931+ regs->flags |= X86_EFLAGS_CF;
31932+ regs->ip = addr1;
31933+ return 2;
31934+ }
31935+ } while (0);
31936+
31937+ do { /* PaX: gcc trampoline emulation #1 */
31938+ unsigned short mov1, mov2, jmp1;
31939+ unsigned char jmp2;
31940+ unsigned int addr1;
31941+ unsigned long addr2;
31942+
31943+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31944+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31945+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31946+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31947+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31948+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31949+
31950+ if (err)
31951+ break;
31952+
31953+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31954+ regs->r11 = addr1;
31955+ regs->r10 = addr2;
31956+ regs->ip = addr1;
31957+ return 2;
31958+ }
31959+ } while (0);
31960+
31961+ do { /* PaX: gcc trampoline emulation #2 */
31962+ unsigned short mov1, mov2, jmp1;
31963+ unsigned char jmp2;
31964+ unsigned long addr1, addr2;
31965+
31966+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31967+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31968+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31969+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31970+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31971+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31972+
31973+ if (err)
31974+ break;
31975+
31976+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31977+ regs->r11 = addr1;
31978+ regs->r10 = addr2;
31979+ regs->ip = addr1;
31980+ return 2;
31981+ }
31982+ } while (0);
31983+
31984+ return 1; /* PaX in action */
31985+}
31986+#endif
31987+
31988+/*
31989+ * PaX: decide what to do with offenders (regs->ip = fault address)
31990+ *
31991+ * returns 1 when task should be killed
31992+ * 2 when gcc trampoline was detected
31993+ */
31994+static int pax_handle_fetch_fault(struct pt_regs *regs)
31995+{
31996+ if (v8086_mode(regs))
31997+ return 1;
31998+
31999+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32000+ return 1;
32001+
32002+#ifdef CONFIG_X86_32
32003+ return pax_handle_fetch_fault_32(regs);
32004+#else
32005+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32006+ return pax_handle_fetch_fault_32(regs);
32007+ else
32008+ return pax_handle_fetch_fault_64(regs);
32009+#endif
32010+}
32011+#endif
32012+
32013+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32014+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32015+{
32016+ long i;
32017+
32018+ printk(KERN_ERR "PAX: bytes at PC: ");
32019+ for (i = 0; i < 20; i++) {
32020+ unsigned char c;
32021+ if (get_user(c, (unsigned char __force_user *)pc+i))
32022+ printk(KERN_CONT "?? ");
32023+ else
32024+ printk(KERN_CONT "%02x ", c);
32025+ }
32026+ printk("\n");
32027+
32028+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32029+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
32030+ unsigned long c;
32031+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
32032+#ifdef CONFIG_X86_32
32033+ printk(KERN_CONT "???????? ");
32034+#else
32035+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32036+ printk(KERN_CONT "???????? ???????? ");
32037+ else
32038+ printk(KERN_CONT "???????????????? ");
32039+#endif
32040+ } else {
32041+#ifdef CONFIG_X86_64
32042+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32043+ printk(KERN_CONT "%08x ", (unsigned int)c);
32044+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32045+ } else
32046+#endif
32047+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32048+ }
32049+ }
32050+ printk("\n");
32051+}
32052+#endif
32053+
32054+/**
32055+ * probe_kernel_write(): safely attempt to write to a location
32056+ * @dst: address to write to
32057+ * @src: pointer to the data that shall be written
32058+ * @size: size of the data chunk
32059+ *
32060+ * Safely write to address @dst from the buffer at @src. If a kernel fault
32061+ * happens, handle that and return -EFAULT.
32062+ */
32063+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32064+{
32065+ long ret;
32066+ mm_segment_t old_fs = get_fs();
32067+
32068+ set_fs(KERNEL_DS);
32069+ pagefault_disable();
32070+ pax_open_kernel();
32071+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32072+ pax_close_kernel();
32073+ pagefault_enable();
32074+ set_fs(old_fs);
32075+
32076+ return ret ? -EFAULT : 0;
32077+}
32078diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32079index 207d9aef..69030980 100644
32080--- a/arch/x86/mm/gup.c
32081+++ b/arch/x86/mm/gup.c
32082@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32083 addr = start;
32084 len = (unsigned long) nr_pages << PAGE_SHIFT;
32085 end = start + len;
32086- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32087+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32088 (void __user *)start, len)))
32089 return 0;
32090
32091@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32092 goto slow_irqon;
32093 #endif
32094
32095+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32096+ (void __user *)start, len)))
32097+ return 0;
32098+
32099 /*
32100 * XXX: batch / limit 'nr', to avoid large irq off latency
32101 * needs some instrumenting to determine the common sizes used by
32102diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32103index 4500142..53a363c 100644
32104--- a/arch/x86/mm/highmem_32.c
32105+++ b/arch/x86/mm/highmem_32.c
32106@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32107 idx = type + KM_TYPE_NR*smp_processor_id();
32108 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32109 BUG_ON(!pte_none(*(kmap_pte-idx)));
32110+
32111+ pax_open_kernel();
32112 set_pte(kmap_pte-idx, mk_pte(page, prot));
32113+ pax_close_kernel();
32114+
32115 arch_flush_lazy_mmu_mode();
32116
32117 return (void *)vaddr;
32118diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32119index 8c9f647..57cb402 100644
32120--- a/arch/x86/mm/hugetlbpage.c
32121+++ b/arch/x86/mm/hugetlbpage.c
32122@@ -90,23 +90,24 @@ int pmd_huge_support(void)
32123 #ifdef CONFIG_HUGETLB_PAGE
32124 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32125 unsigned long addr, unsigned long len,
32126- unsigned long pgoff, unsigned long flags)
32127+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32128 {
32129 struct hstate *h = hstate_file(file);
32130 struct vm_unmapped_area_info info;
32131-
32132+
32133 info.flags = 0;
32134 info.length = len;
32135 info.low_limit = current->mm->mmap_legacy_base;
32136 info.high_limit = TASK_SIZE;
32137 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32138 info.align_offset = 0;
32139+ info.threadstack_offset = offset;
32140 return vm_unmapped_area(&info);
32141 }
32142
32143 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32144 unsigned long addr0, unsigned long len,
32145- unsigned long pgoff, unsigned long flags)
32146+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32147 {
32148 struct hstate *h = hstate_file(file);
32149 struct vm_unmapped_area_info info;
32150@@ -118,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32151 info.high_limit = current->mm->mmap_base;
32152 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32153 info.align_offset = 0;
32154+ info.threadstack_offset = offset;
32155 addr = vm_unmapped_area(&info);
32156
32157 /*
32158@@ -130,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32159 VM_BUG_ON(addr != -ENOMEM);
32160 info.flags = 0;
32161 info.low_limit = TASK_UNMAPPED_BASE;
32162+
32163+#ifdef CONFIG_PAX_RANDMMAP
32164+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32165+ info.low_limit += current->mm->delta_mmap;
32166+#endif
32167+
32168 info.high_limit = TASK_SIZE;
32169 addr = vm_unmapped_area(&info);
32170 }
32171@@ -144,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32172 struct hstate *h = hstate_file(file);
32173 struct mm_struct *mm = current->mm;
32174 struct vm_area_struct *vma;
32175+ unsigned long pax_task_size = TASK_SIZE;
32176+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32177
32178 if (len & ~huge_page_mask(h))
32179 return -EINVAL;
32180- if (len > TASK_SIZE)
32181+
32182+#ifdef CONFIG_PAX_SEGMEXEC
32183+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32184+ pax_task_size = SEGMEXEC_TASK_SIZE;
32185+#endif
32186+
32187+ pax_task_size -= PAGE_SIZE;
32188+
32189+ if (len > pax_task_size)
32190 return -ENOMEM;
32191
32192 if (flags & MAP_FIXED) {
32193@@ -156,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32194 return addr;
32195 }
32196
32197+#ifdef CONFIG_PAX_RANDMMAP
32198+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32199+#endif
32200+
32201 if (addr) {
32202 addr = ALIGN(addr, huge_page_size(h));
32203 vma = find_vma(mm, addr);
32204- if (TASK_SIZE - len >= addr &&
32205- (!vma || addr + len <= vma->vm_start))
32206+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32207 return addr;
32208 }
32209 if (mm->get_unmapped_area == arch_get_unmapped_area)
32210 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32211- pgoff, flags);
32212+ pgoff, flags, offset);
32213 else
32214 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32215- pgoff, flags);
32216+ pgoff, flags, offset);
32217 }
32218 #endif /* CONFIG_HUGETLB_PAGE */
32219
32220diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32221index f971306..e83e0f6 100644
32222--- a/arch/x86/mm/init.c
32223+++ b/arch/x86/mm/init.c
32224@@ -4,6 +4,7 @@
32225 #include <linux/swap.h>
32226 #include <linux/memblock.h>
32227 #include <linux/bootmem.h> /* for max_low_pfn */
32228+#include <linux/tboot.h>
32229
32230 #include <asm/cacheflush.h>
32231 #include <asm/e820.h>
32232@@ -17,6 +18,8 @@
32233 #include <asm/proto.h>
32234 #include <asm/dma.h> /* for MAX_DMA_PFN */
32235 #include <asm/microcode.h>
32236+#include <asm/desc.h>
32237+#include <asm/bios_ebda.h>
32238
32239 #include "mm_internal.h"
32240
32241@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32242 early_ioremap_page_table_range_init();
32243 #endif
32244
32245+#ifdef CONFIG_PAX_PER_CPU_PGD
32246+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32247+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32248+ KERNEL_PGD_PTRS);
32249+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32250+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32251+ KERNEL_PGD_PTRS);
32252+ load_cr3(get_cpu_pgd(0, kernel));
32253+#else
32254 load_cr3(swapper_pg_dir);
32255+#endif
32256+
32257 __flush_tlb_all();
32258
32259 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32260@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32261 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32262 * mmio resources as well as potential bios/acpi data regions.
32263 */
32264+
32265+#ifdef CONFIG_GRKERNSEC_KMEM
32266+static unsigned int ebda_start __read_only;
32267+static unsigned int ebda_end __read_only;
32268+#endif
32269+
32270 int devmem_is_allowed(unsigned long pagenr)
32271 {
32272- if (pagenr < 256)
32273+#ifdef CONFIG_GRKERNSEC_KMEM
32274+ /* allow BDA */
32275+ if (!pagenr)
32276 return 1;
32277+ /* allow EBDA */
32278+ if (pagenr >= ebda_start && pagenr < ebda_end)
32279+ return 1;
32280+ /* if tboot is in use, allow access to its hardcoded serial log range */
32281+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32282+ return 1;
32283+#else
32284+ if (!pagenr)
32285+ return 1;
32286+#ifdef CONFIG_VM86
32287+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32288+ return 1;
32289+#endif
32290+#endif
32291+
32292+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32293+ return 1;
32294+#ifdef CONFIG_GRKERNSEC_KMEM
32295+ /* throw out everything else below 1MB */
32296+ if (pagenr <= 256)
32297+ return 0;
32298+#endif
32299 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32300 return 0;
32301 if (!page_is_ram(pagenr))
32302@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32303 #endif
32304 }
32305
32306+#ifdef CONFIG_GRKERNSEC_KMEM
32307+static inline void gr_init_ebda(void)
32308+{
32309+ unsigned int ebda_addr;
32310+ unsigned int ebda_size = 0;
32311+
32312+ ebda_addr = get_bios_ebda();
32313+ if (ebda_addr) {
32314+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32315+ ebda_size <<= 10;
32316+ }
32317+ if (ebda_addr && ebda_size) {
32318+ ebda_start = ebda_addr >> PAGE_SHIFT;
32319+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32320+ } else {
32321+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32322+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32323+ }
32324+}
32325+#else
32326+static inline void gr_init_ebda(void) { }
32327+#endif
32328+
32329 void free_initmem(void)
32330 {
32331+#ifdef CONFIG_PAX_KERNEXEC
32332+#ifdef CONFIG_X86_32
32333+ /* PaX: limit KERNEL_CS to actual size */
32334+ unsigned long addr, limit;
32335+ struct desc_struct d;
32336+ int cpu;
32337+#else
32338+ pgd_t *pgd;
32339+ pud_t *pud;
32340+ pmd_t *pmd;
32341+ unsigned long addr, end;
32342+#endif
32343+#endif
32344+
32345+ gr_init_ebda();
32346+
32347+#ifdef CONFIG_PAX_KERNEXEC
32348+#ifdef CONFIG_X86_32
32349+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32350+ limit = (limit - 1UL) >> PAGE_SHIFT;
32351+
32352+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32353+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32354+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32355+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32356+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32357+ }
32358+
32359+ /* PaX: make KERNEL_CS read-only */
32360+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32361+ if (!paravirt_enabled())
32362+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32363+/*
32364+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32365+ pgd = pgd_offset_k(addr);
32366+ pud = pud_offset(pgd, addr);
32367+ pmd = pmd_offset(pud, addr);
32368+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32369+ }
32370+*/
32371+#ifdef CONFIG_X86_PAE
32372+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32373+/*
32374+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32375+ pgd = pgd_offset_k(addr);
32376+ pud = pud_offset(pgd, addr);
32377+ pmd = pmd_offset(pud, addr);
32378+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32379+ }
32380+*/
32381+#endif
32382+
32383+#ifdef CONFIG_MODULES
32384+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32385+#endif
32386+
32387+#else
32388+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32389+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32390+ pgd = pgd_offset_k(addr);
32391+ pud = pud_offset(pgd, addr);
32392+ pmd = pmd_offset(pud, addr);
32393+ if (!pmd_present(*pmd))
32394+ continue;
32395+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32396+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32397+ else
32398+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32399+ }
32400+
32401+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32402+ end = addr + KERNEL_IMAGE_SIZE;
32403+ for (; addr < end; addr += PMD_SIZE) {
32404+ pgd = pgd_offset_k(addr);
32405+ pud = pud_offset(pgd, addr);
32406+ pmd = pmd_offset(pud, addr);
32407+ if (!pmd_present(*pmd))
32408+ continue;
32409+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32410+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32411+ }
32412+#endif
32413+
32414+ flush_tlb_all();
32415+#endif
32416+
32417 free_init_pages("unused kernel",
32418 (unsigned long)(&__init_begin),
32419 (unsigned long)(&__init_end));
32420diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32421index e395048..cd38278 100644
32422--- a/arch/x86/mm/init_32.c
32423+++ b/arch/x86/mm/init_32.c
32424@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32425 bool __read_mostly __vmalloc_start_set = false;
32426
32427 /*
32428- * Creates a middle page table and puts a pointer to it in the
32429- * given global directory entry. This only returns the gd entry
32430- * in non-PAE compilation mode, since the middle layer is folded.
32431- */
32432-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32433-{
32434- pud_t *pud;
32435- pmd_t *pmd_table;
32436-
32437-#ifdef CONFIG_X86_PAE
32438- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32439- pmd_table = (pmd_t *)alloc_low_page();
32440- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32441- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32442- pud = pud_offset(pgd, 0);
32443- BUG_ON(pmd_table != pmd_offset(pud, 0));
32444-
32445- return pmd_table;
32446- }
32447-#endif
32448- pud = pud_offset(pgd, 0);
32449- pmd_table = pmd_offset(pud, 0);
32450-
32451- return pmd_table;
32452-}
32453-
32454-/*
32455 * Create a page table and place a pointer to it in a middle page
32456 * directory entry:
32457 */
32458@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32459 pte_t *page_table = (pte_t *)alloc_low_page();
32460
32461 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32462+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32463+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32464+#else
32465 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32466+#endif
32467 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32468 }
32469
32470 return pte_offset_kernel(pmd, 0);
32471 }
32472
32473+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32474+{
32475+ pud_t *pud;
32476+ pmd_t *pmd_table;
32477+
32478+ pud = pud_offset(pgd, 0);
32479+ pmd_table = pmd_offset(pud, 0);
32480+
32481+ return pmd_table;
32482+}
32483+
32484 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32485 {
32486 int pgd_idx = pgd_index(vaddr);
32487@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32488 int pgd_idx, pmd_idx;
32489 unsigned long vaddr;
32490 pgd_t *pgd;
32491+ pud_t *pud;
32492 pmd_t *pmd;
32493 pte_t *pte = NULL;
32494 unsigned long count = page_table_range_init_count(start, end);
32495@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32496 pgd = pgd_base + pgd_idx;
32497
32498 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32499- pmd = one_md_table_init(pgd);
32500- pmd = pmd + pmd_index(vaddr);
32501+ pud = pud_offset(pgd, vaddr);
32502+ pmd = pmd_offset(pud, vaddr);
32503+
32504+#ifdef CONFIG_X86_PAE
32505+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32506+#endif
32507+
32508 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32509 pmd++, pmd_idx++) {
32510 pte = page_table_kmap_check(one_page_table_init(pmd),
32511@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32512 }
32513 }
32514
32515-static inline int is_kernel_text(unsigned long addr)
32516+static inline int is_kernel_text(unsigned long start, unsigned long end)
32517 {
32518- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32519- return 1;
32520- return 0;
32521+ if ((start >= ktla_ktva((unsigned long)_etext) ||
32522+ end <= ktla_ktva((unsigned long)_stext)) &&
32523+ (start >= ktla_ktva((unsigned long)_einittext) ||
32524+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32525+
32526+#ifdef CONFIG_ACPI_SLEEP
32527+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32528+#endif
32529+
32530+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32531+ return 0;
32532+ return 1;
32533 }
32534
32535 /*
32536@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32537 unsigned long last_map_addr = end;
32538 unsigned long start_pfn, end_pfn;
32539 pgd_t *pgd_base = swapper_pg_dir;
32540- int pgd_idx, pmd_idx, pte_ofs;
32541+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32542 unsigned long pfn;
32543 pgd_t *pgd;
32544+ pud_t *pud;
32545 pmd_t *pmd;
32546 pte_t *pte;
32547 unsigned pages_2m, pages_4k;
32548@@ -291,8 +295,13 @@ repeat:
32549 pfn = start_pfn;
32550 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32551 pgd = pgd_base + pgd_idx;
32552- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32553- pmd = one_md_table_init(pgd);
32554+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32555+ pud = pud_offset(pgd, 0);
32556+ pmd = pmd_offset(pud, 0);
32557+
32558+#ifdef CONFIG_X86_PAE
32559+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32560+#endif
32561
32562 if (pfn >= end_pfn)
32563 continue;
32564@@ -304,14 +313,13 @@ repeat:
32565 #endif
32566 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32567 pmd++, pmd_idx++) {
32568- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32569+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32570
32571 /*
32572 * Map with big pages if possible, otherwise
32573 * create normal page tables:
32574 */
32575 if (use_pse) {
32576- unsigned int addr2;
32577 pgprot_t prot = PAGE_KERNEL_LARGE;
32578 /*
32579 * first pass will use the same initial
32580@@ -322,11 +330,7 @@ repeat:
32581 _PAGE_PSE);
32582
32583 pfn &= PMD_MASK >> PAGE_SHIFT;
32584- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32585- PAGE_OFFSET + PAGE_SIZE-1;
32586-
32587- if (is_kernel_text(addr) ||
32588- is_kernel_text(addr2))
32589+ if (is_kernel_text(address, address + PMD_SIZE))
32590 prot = PAGE_KERNEL_LARGE_EXEC;
32591
32592 pages_2m++;
32593@@ -343,7 +347,7 @@ repeat:
32594 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32595 pte += pte_ofs;
32596 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32597- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32598+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32599 pgprot_t prot = PAGE_KERNEL;
32600 /*
32601 * first pass will use the same initial
32602@@ -351,7 +355,7 @@ repeat:
32603 */
32604 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32605
32606- if (is_kernel_text(addr))
32607+ if (is_kernel_text(address, address + PAGE_SIZE))
32608 prot = PAGE_KERNEL_EXEC;
32609
32610 pages_4k++;
32611@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32612
32613 pud = pud_offset(pgd, va);
32614 pmd = pmd_offset(pud, va);
32615- if (!pmd_present(*pmd))
32616+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32617 break;
32618
32619 /* should not be large page here */
32620@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32621
32622 static void __init pagetable_init(void)
32623 {
32624- pgd_t *pgd_base = swapper_pg_dir;
32625-
32626- permanent_kmaps_init(pgd_base);
32627+ permanent_kmaps_init(swapper_pg_dir);
32628 }
32629
32630-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32631+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32632 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32633
32634 /* user-defined highmem size */
32635@@ -787,10 +789,10 @@ void __init mem_init(void)
32636 ((unsigned long)&__init_end -
32637 (unsigned long)&__init_begin) >> 10,
32638
32639- (unsigned long)&_etext, (unsigned long)&_edata,
32640- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32641+ (unsigned long)&_sdata, (unsigned long)&_edata,
32642+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32643
32644- (unsigned long)&_text, (unsigned long)&_etext,
32645+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32646 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32647
32648 /*
32649@@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32650 if (!kernel_set_to_readonly)
32651 return;
32652
32653+ start = ktla_ktva(start);
32654 pr_debug("Set kernel text: %lx - %lx for read write\n",
32655 start, start+size);
32656
32657@@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32658 if (!kernel_set_to_readonly)
32659 return;
32660
32661+ start = ktla_ktva(start);
32662 pr_debug("Set kernel text: %lx - %lx for read only\n",
32663 start, start+size);
32664
32665@@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32666 unsigned long start = PFN_ALIGN(_text);
32667 unsigned long size = PFN_ALIGN(_etext) - start;
32668
32669+ start = ktla_ktva(start);
32670 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32671 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32672 size >> 10);
32673diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32674index f35c66c..84b95ef 100644
32675--- a/arch/x86/mm/init_64.c
32676+++ b/arch/x86/mm/init_64.c
32677@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32678 * around without checking the pgd every time.
32679 */
32680
32681-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32682+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32683 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32684
32685 int force_personality32;
32686@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32687
32688 for (address = start; address <= end; address += PGDIR_SIZE) {
32689 const pgd_t *pgd_ref = pgd_offset_k(address);
32690+
32691+#ifdef CONFIG_PAX_PER_CPU_PGD
32692+ unsigned long cpu;
32693+#else
32694 struct page *page;
32695+#endif
32696
32697 if (pgd_none(*pgd_ref))
32698 continue;
32699
32700 spin_lock(&pgd_lock);
32701+
32702+#ifdef CONFIG_PAX_PER_CPU_PGD
32703+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32704+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32705+
32706+ if (pgd_none(*pgd))
32707+ set_pgd(pgd, *pgd_ref);
32708+ else
32709+ BUG_ON(pgd_page_vaddr(*pgd)
32710+ != pgd_page_vaddr(*pgd_ref));
32711+ pgd = pgd_offset_cpu(cpu, kernel, address);
32712+#else
32713 list_for_each_entry(page, &pgd_list, lru) {
32714 pgd_t *pgd;
32715 spinlock_t *pgt_lock;
32716@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32717 /* the pgt_lock only for Xen */
32718 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32719 spin_lock(pgt_lock);
32720+#endif
32721
32722 if (pgd_none(*pgd))
32723 set_pgd(pgd, *pgd_ref);
32724@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32725 BUG_ON(pgd_page_vaddr(*pgd)
32726 != pgd_page_vaddr(*pgd_ref));
32727
32728+#ifndef CONFIG_PAX_PER_CPU_PGD
32729 spin_unlock(pgt_lock);
32730+#endif
32731+
32732 }
32733 spin_unlock(&pgd_lock);
32734 }
32735@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32736 {
32737 if (pgd_none(*pgd)) {
32738 pud_t *pud = (pud_t *)spp_getpage();
32739- pgd_populate(&init_mm, pgd, pud);
32740+ pgd_populate_kernel(&init_mm, pgd, pud);
32741 if (pud != pud_offset(pgd, 0))
32742 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32743 pud, pud_offset(pgd, 0));
32744@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32745 {
32746 if (pud_none(*pud)) {
32747 pmd_t *pmd = (pmd_t *) spp_getpage();
32748- pud_populate(&init_mm, pud, pmd);
32749+ pud_populate_kernel(&init_mm, pud, pmd);
32750 if (pmd != pmd_offset(pud, 0))
32751 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32752 pmd, pmd_offset(pud, 0));
32753@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32754 pmd = fill_pmd(pud, vaddr);
32755 pte = fill_pte(pmd, vaddr);
32756
32757+ pax_open_kernel();
32758 set_pte(pte, new_pte);
32759+ pax_close_kernel();
32760
32761 /*
32762 * It's enough to flush this one mapping.
32763@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32764 pgd = pgd_offset_k((unsigned long)__va(phys));
32765 if (pgd_none(*pgd)) {
32766 pud = (pud_t *) spp_getpage();
32767- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32768- _PAGE_USER));
32769+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32770 }
32771 pud = pud_offset(pgd, (unsigned long)__va(phys));
32772 if (pud_none(*pud)) {
32773 pmd = (pmd_t *) spp_getpage();
32774- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32775- _PAGE_USER));
32776+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32777 }
32778 pmd = pmd_offset(pud, phys);
32779 BUG_ON(!pmd_none(*pmd));
32780@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32781 prot);
32782
32783 spin_lock(&init_mm.page_table_lock);
32784- pud_populate(&init_mm, pud, pmd);
32785+ pud_populate_kernel(&init_mm, pud, pmd);
32786 spin_unlock(&init_mm.page_table_lock);
32787 }
32788 __flush_tlb_all();
32789@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32790 page_size_mask);
32791
32792 spin_lock(&init_mm.page_table_lock);
32793- pgd_populate(&init_mm, pgd, pud);
32794+ pgd_populate_kernel(&init_mm, pgd, pud);
32795 spin_unlock(&init_mm.page_table_lock);
32796 pgd_changed = true;
32797 }
32798@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32799 static struct vm_area_struct gate_vma = {
32800 .vm_start = VSYSCALL_START,
32801 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32802- .vm_page_prot = PAGE_READONLY_EXEC,
32803- .vm_flags = VM_READ | VM_EXEC
32804+ .vm_page_prot = PAGE_READONLY,
32805+ .vm_flags = VM_READ
32806 };
32807
32808 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32809@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32810
32811 const char *arch_vma_name(struct vm_area_struct *vma)
32812 {
32813- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32814+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32815 return "[vdso]";
32816 if (vma == &gate_vma)
32817 return "[vsyscall]";
32818diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32819index 7b179b4..6bd17777 100644
32820--- a/arch/x86/mm/iomap_32.c
32821+++ b/arch/x86/mm/iomap_32.c
32822@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32823 type = kmap_atomic_idx_push();
32824 idx = type + KM_TYPE_NR * smp_processor_id();
32825 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32826+
32827+ pax_open_kernel();
32828 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32829+ pax_close_kernel();
32830+
32831 arch_flush_lazy_mmu_mode();
32832
32833 return (void *)vaddr;
32834diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32835index 597ac15..49841be 100644
32836--- a/arch/x86/mm/ioremap.c
32837+++ b/arch/x86/mm/ioremap.c
32838@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32839 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32840 int is_ram = page_is_ram(pfn);
32841
32842- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32843+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32844 return NULL;
32845 WARN_ON_ONCE(is_ram);
32846 }
32847@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32848 *
32849 * Caller must ensure there is only one unmapping for the same pointer.
32850 */
32851-void iounmap(volatile void __iomem *addr)
32852+void iounmap(const volatile void __iomem *addr)
32853 {
32854 struct vm_struct *p, *o;
32855
32856@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32857
32858 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32859 if (page_is_ram(start >> PAGE_SHIFT))
32860+#ifdef CONFIG_HIGHMEM
32861+ if ((start >> PAGE_SHIFT) < max_low_pfn)
32862+#endif
32863 return __va(phys);
32864
32865 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32866@@ -322,13 +325,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32867 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32868 {
32869 if (page_is_ram(phys >> PAGE_SHIFT))
32870+#ifdef CONFIG_HIGHMEM
32871+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
32872+#endif
32873 return;
32874
32875 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32876 return;
32877 }
32878
32879-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32880+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32881
32882 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32883 {
32884@@ -358,8 +364,7 @@ void __init early_ioremap_init(void)
32885 early_ioremap_setup();
32886
32887 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32888- memset(bm_pte, 0, sizeof(bm_pte));
32889- pmd_populate_kernel(&init_mm, pmd, bm_pte);
32890+ pmd_populate_user(&init_mm, pmd, bm_pte);
32891
32892 /*
32893 * The boot-ioremap range spans multiple pmds, for which
32894diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32895index dd89a13..d77bdcc 100644
32896--- a/arch/x86/mm/kmemcheck/kmemcheck.c
32897+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32898@@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32899 * memory (e.g. tracked pages)? For now, we need this to avoid
32900 * invoking kmemcheck for PnP BIOS calls.
32901 */
32902- if (regs->flags & X86_VM_MASK)
32903+ if (v8086_mode(regs))
32904 return false;
32905- if (regs->cs != __KERNEL_CS)
32906+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32907 return false;
32908
32909 pte = kmemcheck_pte_lookup(address);
32910diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32911index 25e7e13..1964579 100644
32912--- a/arch/x86/mm/mmap.c
32913+++ b/arch/x86/mm/mmap.c
32914@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32915 * Leave an at least ~128 MB hole with possible stack randomization.
32916 */
32917 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32918-#define MAX_GAP (TASK_SIZE/6*5)
32919+#define MAX_GAP (pax_task_size/6*5)
32920
32921 static int mmap_is_legacy(void)
32922 {
32923@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32924 return rnd << PAGE_SHIFT;
32925 }
32926
32927-static unsigned long mmap_base(void)
32928+static unsigned long mmap_base(struct mm_struct *mm)
32929 {
32930 unsigned long gap = rlimit(RLIMIT_STACK);
32931+ unsigned long pax_task_size = TASK_SIZE;
32932+
32933+#ifdef CONFIG_PAX_SEGMEXEC
32934+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32935+ pax_task_size = SEGMEXEC_TASK_SIZE;
32936+#endif
32937
32938 if (gap < MIN_GAP)
32939 gap = MIN_GAP;
32940 else if (gap > MAX_GAP)
32941 gap = MAX_GAP;
32942
32943- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32944+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32945 }
32946
32947 /*
32948 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32949 * does, but not when emulating X86_32
32950 */
32951-static unsigned long mmap_legacy_base(void)
32952+static unsigned long mmap_legacy_base(struct mm_struct *mm)
32953 {
32954- if (mmap_is_ia32())
32955+ if (mmap_is_ia32()) {
32956+
32957+#ifdef CONFIG_PAX_SEGMEXEC
32958+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32959+ return SEGMEXEC_TASK_UNMAPPED_BASE;
32960+ else
32961+#endif
32962+
32963 return TASK_UNMAPPED_BASE;
32964- else
32965+ } else
32966 return TASK_UNMAPPED_BASE + mmap_rnd();
32967 }
32968
32969@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32970 */
32971 void arch_pick_mmap_layout(struct mm_struct *mm)
32972 {
32973- mm->mmap_legacy_base = mmap_legacy_base();
32974- mm->mmap_base = mmap_base();
32975+ mm->mmap_legacy_base = mmap_legacy_base(mm);
32976+ mm->mmap_base = mmap_base(mm);
32977+
32978+#ifdef CONFIG_PAX_RANDMMAP
32979+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
32980+ mm->mmap_legacy_base += mm->delta_mmap;
32981+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32982+ }
32983+#endif
32984
32985 if (mmap_is_legacy()) {
32986 mm->mmap_base = mm->mmap_legacy_base;
32987diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32988index 0057a7a..95c7edd 100644
32989--- a/arch/x86/mm/mmio-mod.c
32990+++ b/arch/x86/mm/mmio-mod.c
32991@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32992 break;
32993 default:
32994 {
32995- unsigned char *ip = (unsigned char *)instptr;
32996+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32997 my_trace->opcode = MMIO_UNKNOWN_OP;
32998 my_trace->width = 0;
32999 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33000@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33001 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33002 void __iomem *addr)
33003 {
33004- static atomic_t next_id;
33005+ static atomic_unchecked_t next_id;
33006 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33007 /* These are page-unaligned. */
33008 struct mmiotrace_map map = {
33009@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33010 .private = trace
33011 },
33012 .phys = offset,
33013- .id = atomic_inc_return(&next_id)
33014+ .id = atomic_inc_return_unchecked(&next_id)
33015 };
33016 map.map_id = trace->id;
33017
33018@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33019 ioremap_trace_core(offset, size, addr);
33020 }
33021
33022-static void iounmap_trace_core(volatile void __iomem *addr)
33023+static void iounmap_trace_core(const volatile void __iomem *addr)
33024 {
33025 struct mmiotrace_map map = {
33026 .phys = 0,
33027@@ -328,7 +328,7 @@ not_enabled:
33028 }
33029 }
33030
33031-void mmiotrace_iounmap(volatile void __iomem *addr)
33032+void mmiotrace_iounmap(const volatile void __iomem *addr)
33033 {
33034 might_sleep();
33035 if (is_enabled()) /* recheck and proper locking in *_core() */
33036diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33037index 1d045f9..3a00249 100644
33038--- a/arch/x86/mm/numa.c
33039+++ b/arch/x86/mm/numa.c
33040@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33041 return true;
33042 }
33043
33044-static int __init numa_register_memblks(struct numa_meminfo *mi)
33045+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33046 {
33047 unsigned long uninitialized_var(pfn_align);
33048 int i, nid;
33049diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
33050index 461bc82..4e091a3 100644
33051--- a/arch/x86/mm/pageattr-test.c
33052+++ b/arch/x86/mm/pageattr-test.c
33053@@ -35,7 +35,7 @@ enum {
33054
33055 static int pte_testbit(pte_t pte)
33056 {
33057- return pte_flags(pte) & _PAGE_UNUSED1;
33058+ return pte_flags(pte) & _PAGE_CPA_TEST;
33059 }
33060
33061 struct split_state {
33062diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33063index ae242a7..1c7998f 100644
33064--- a/arch/x86/mm/pageattr.c
33065+++ b/arch/x86/mm/pageattr.c
33066@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33067 */
33068 #ifdef CONFIG_PCI_BIOS
33069 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33070- pgprot_val(forbidden) |= _PAGE_NX;
33071+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33072 #endif
33073
33074 /*
33075@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33076 * Does not cover __inittext since that is gone later on. On
33077 * 64bit we do not enforce !NX on the low mapping
33078 */
33079- if (within(address, (unsigned long)_text, (unsigned long)_etext))
33080- pgprot_val(forbidden) |= _PAGE_NX;
33081+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33082+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33083
33084+#ifdef CONFIG_DEBUG_RODATA
33085 /*
33086 * The .rodata section needs to be read-only. Using the pfn
33087 * catches all aliases.
33088@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33089 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33090 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33091 pgprot_val(forbidden) |= _PAGE_RW;
33092+#endif
33093
33094 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33095 /*
33096@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33097 }
33098 #endif
33099
33100+#ifdef CONFIG_PAX_KERNEXEC
33101+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33102+ pgprot_val(forbidden) |= _PAGE_RW;
33103+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33104+ }
33105+#endif
33106+
33107 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33108
33109 return prot;
33110@@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33111 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33112 {
33113 /* change init_mm */
33114+ pax_open_kernel();
33115 set_pte_atomic(kpte, pte);
33116+
33117 #ifdef CONFIG_X86_32
33118 if (!SHARED_KERNEL_PMD) {
33119+
33120+#ifdef CONFIG_PAX_PER_CPU_PGD
33121+ unsigned long cpu;
33122+#else
33123 struct page *page;
33124+#endif
33125
33126+#ifdef CONFIG_PAX_PER_CPU_PGD
33127+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33128+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33129+#else
33130 list_for_each_entry(page, &pgd_list, lru) {
33131- pgd_t *pgd;
33132+ pgd_t *pgd = (pgd_t *)page_address(page);
33133+#endif
33134+
33135 pud_t *pud;
33136 pmd_t *pmd;
33137
33138- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33139+ pgd += pgd_index(address);
33140 pud = pud_offset(pgd, address);
33141 pmd = pmd_offset(pud, address);
33142 set_pte_atomic((pte_t *)pmd, pte);
33143 }
33144 }
33145 #endif
33146+ pax_close_kernel();
33147 }
33148
33149 static int
33150diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33151index 6574388..87e9bef 100644
33152--- a/arch/x86/mm/pat.c
33153+++ b/arch/x86/mm/pat.c
33154@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33155
33156 if (!entry) {
33157 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33158- current->comm, current->pid, start, end - 1);
33159+ current->comm, task_pid_nr(current), start, end - 1);
33160 return -EINVAL;
33161 }
33162
33163@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33164
33165 while (cursor < to) {
33166 if (!devmem_is_allowed(pfn)) {
33167- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33168- current->comm, from, to - 1);
33169+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33170+ current->comm, from, to - 1, cursor);
33171 return 0;
33172 }
33173 cursor += PAGE_SIZE;
33174@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33175 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33176 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33177 "for [mem %#010Lx-%#010Lx]\n",
33178- current->comm, current->pid,
33179+ current->comm, task_pid_nr(current),
33180 cattr_name(flags),
33181 base, (unsigned long long)(base + size-1));
33182 return -EINVAL;
33183@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33184 flags = lookup_memtype(paddr);
33185 if (want_flags != flags) {
33186 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33187- current->comm, current->pid,
33188+ current->comm, task_pid_nr(current),
33189 cattr_name(want_flags),
33190 (unsigned long long)paddr,
33191 (unsigned long long)(paddr + size - 1),
33192@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33193 free_memtype(paddr, paddr + size);
33194 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33195 " for [mem %#010Lx-%#010Lx], got %s\n",
33196- current->comm, current->pid,
33197+ current->comm, task_pid_nr(current),
33198 cattr_name(want_flags),
33199 (unsigned long long)paddr,
33200 (unsigned long long)(paddr + size - 1),
33201diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33202index 415f6c4..d319983 100644
33203--- a/arch/x86/mm/pat_rbtree.c
33204+++ b/arch/x86/mm/pat_rbtree.c
33205@@ -160,7 +160,7 @@ success:
33206
33207 failure:
33208 printk(KERN_INFO "%s:%d conflicting memory types "
33209- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33210+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33211 end, cattr_name(found_type), cattr_name(match->type));
33212 return -EBUSY;
33213 }
33214diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33215index 9f0614d..92ae64a 100644
33216--- a/arch/x86/mm/pf_in.c
33217+++ b/arch/x86/mm/pf_in.c
33218@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33219 int i;
33220 enum reason_type rv = OTHERS;
33221
33222- p = (unsigned char *)ins_addr;
33223+ p = (unsigned char *)ktla_ktva(ins_addr);
33224 p += skip_prefix(p, &prf);
33225 p += get_opcode(p, &opcode);
33226
33227@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33228 struct prefix_bits prf;
33229 int i;
33230
33231- p = (unsigned char *)ins_addr;
33232+ p = (unsigned char *)ktla_ktva(ins_addr);
33233 p += skip_prefix(p, &prf);
33234 p += get_opcode(p, &opcode);
33235
33236@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33237 struct prefix_bits prf;
33238 int i;
33239
33240- p = (unsigned char *)ins_addr;
33241+ p = (unsigned char *)ktla_ktva(ins_addr);
33242 p += skip_prefix(p, &prf);
33243 p += get_opcode(p, &opcode);
33244
33245@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33246 struct prefix_bits prf;
33247 int i;
33248
33249- p = (unsigned char *)ins_addr;
33250+ p = (unsigned char *)ktla_ktva(ins_addr);
33251 p += skip_prefix(p, &prf);
33252 p += get_opcode(p, &opcode);
33253 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33254@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33255 struct prefix_bits prf;
33256 int i;
33257
33258- p = (unsigned char *)ins_addr;
33259+ p = (unsigned char *)ktla_ktva(ins_addr);
33260 p += skip_prefix(p, &prf);
33261 p += get_opcode(p, &opcode);
33262 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33263diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33264index c96314a..433b127 100644
33265--- a/arch/x86/mm/pgtable.c
33266+++ b/arch/x86/mm/pgtable.c
33267@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33268 list_del(&page->lru);
33269 }
33270
33271-#define UNSHARED_PTRS_PER_PGD \
33272- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33273+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33274+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33275
33276+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33277+{
33278+ unsigned int count = USER_PGD_PTRS;
33279
33280+ if (!pax_user_shadow_base)
33281+ return;
33282+
33283+ while (count--)
33284+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33285+}
33286+#endif
33287+
33288+#ifdef CONFIG_PAX_PER_CPU_PGD
33289+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33290+{
33291+ unsigned int count = USER_PGD_PTRS;
33292+
33293+ while (count--) {
33294+ pgd_t pgd;
33295+
33296+#ifdef CONFIG_X86_64
33297+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33298+#else
33299+ pgd = *src++;
33300+#endif
33301+
33302+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33303+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33304+#endif
33305+
33306+ *dst++ = pgd;
33307+ }
33308+
33309+}
33310+#endif
33311+
33312+#ifdef CONFIG_X86_64
33313+#define pxd_t pud_t
33314+#define pyd_t pgd_t
33315+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33316+#define pgtable_pxd_page_ctor(page) true
33317+#define pgtable_pxd_page_dtor(page)
33318+#define pxd_free(mm, pud) pud_free((mm), (pud))
33319+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33320+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33321+#define PYD_SIZE PGDIR_SIZE
33322+#else
33323+#define pxd_t pmd_t
33324+#define pyd_t pud_t
33325+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33326+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33327+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33328+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33329+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33330+#define pyd_offset(mm, address) pud_offset((mm), (address))
33331+#define PYD_SIZE PUD_SIZE
33332+#endif
33333+
33334+#ifdef CONFIG_PAX_PER_CPU_PGD
33335+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33336+static inline void pgd_dtor(pgd_t *pgd) {}
33337+#else
33338 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33339 {
33340 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33341@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33342 pgd_list_del(pgd);
33343 spin_unlock(&pgd_lock);
33344 }
33345+#endif
33346
33347 /*
33348 * List of all pgd's needed for non-PAE so it can invalidate entries
33349@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33350 * -- nyc
33351 */
33352
33353-#ifdef CONFIG_X86_PAE
33354+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33355 /*
33356 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33357 * updating the top-level pagetable entries to guarantee the
33358@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33359 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33360 * and initialize the kernel pmds here.
33361 */
33362-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33363+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33364
33365 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33366 {
33367@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33368 */
33369 flush_tlb_mm(mm);
33370 }
33371+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33372+#define PREALLOCATED_PXDS USER_PGD_PTRS
33373 #else /* !CONFIG_X86_PAE */
33374
33375 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33376-#define PREALLOCATED_PMDS 0
33377+#define PREALLOCATED_PXDS 0
33378
33379 #endif /* CONFIG_X86_PAE */
33380
33381-static void free_pmds(pmd_t *pmds[])
33382+static void free_pxds(pxd_t *pxds[])
33383 {
33384 int i;
33385
33386- for(i = 0; i < PREALLOCATED_PMDS; i++)
33387- if (pmds[i]) {
33388- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33389- free_page((unsigned long)pmds[i]);
33390+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33391+ if (pxds[i]) {
33392+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33393+ free_page((unsigned long)pxds[i]);
33394 }
33395 }
33396
33397-static int preallocate_pmds(pmd_t *pmds[])
33398+static int preallocate_pxds(pxd_t *pxds[])
33399 {
33400 int i;
33401 bool failed = false;
33402
33403- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33404- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33405- if (!pmd)
33406+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33407+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33408+ if (!pxd)
33409 failed = true;
33410- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33411- free_page((unsigned long)pmd);
33412- pmd = NULL;
33413+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33414+ free_page((unsigned long)pxd);
33415+ pxd = NULL;
33416 failed = true;
33417 }
33418- pmds[i] = pmd;
33419+ pxds[i] = pxd;
33420 }
33421
33422 if (failed) {
33423- free_pmds(pmds);
33424+ free_pxds(pxds);
33425 return -ENOMEM;
33426 }
33427
33428@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33429 * preallocate which never got a corresponding vma will need to be
33430 * freed manually.
33431 */
33432-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33433+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33434 {
33435 int i;
33436
33437- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33438+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33439 pgd_t pgd = pgdp[i];
33440
33441 if (pgd_val(pgd) != 0) {
33442- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33443+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33444
33445- pgdp[i] = native_make_pgd(0);
33446+ set_pgd(pgdp + i, native_make_pgd(0));
33447
33448- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33449- pmd_free(mm, pmd);
33450+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33451+ pxd_free(mm, pxd);
33452 }
33453 }
33454 }
33455
33456-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33457+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33458 {
33459- pud_t *pud;
33460+ pyd_t *pyd;
33461 int i;
33462
33463- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33464+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33465 return;
33466
33467- pud = pud_offset(pgd, 0);
33468-
33469- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33470- pmd_t *pmd = pmds[i];
33471+#ifdef CONFIG_X86_64
33472+ pyd = pyd_offset(mm, 0L);
33473+#else
33474+ pyd = pyd_offset(pgd, 0L);
33475+#endif
33476
33477+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33478+ pxd_t *pxd = pxds[i];
33479 if (i >= KERNEL_PGD_BOUNDARY)
33480- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33481- sizeof(pmd_t) * PTRS_PER_PMD);
33482+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33483+ sizeof(pxd_t) * PTRS_PER_PMD);
33484
33485- pud_populate(mm, pud, pmd);
33486+ pyd_populate(mm, pyd, pxd);
33487 }
33488 }
33489
33490 pgd_t *pgd_alloc(struct mm_struct *mm)
33491 {
33492 pgd_t *pgd;
33493- pmd_t *pmds[PREALLOCATED_PMDS];
33494+ pxd_t *pxds[PREALLOCATED_PXDS];
33495
33496 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33497
33498@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33499
33500 mm->pgd = pgd;
33501
33502- if (preallocate_pmds(pmds) != 0)
33503+ if (preallocate_pxds(pxds) != 0)
33504 goto out_free_pgd;
33505
33506 if (paravirt_pgd_alloc(mm) != 0)
33507- goto out_free_pmds;
33508+ goto out_free_pxds;
33509
33510 /*
33511 * Make sure that pre-populating the pmds is atomic with
33512@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33513 spin_lock(&pgd_lock);
33514
33515 pgd_ctor(mm, pgd);
33516- pgd_prepopulate_pmd(mm, pgd, pmds);
33517+ pgd_prepopulate_pxd(mm, pgd, pxds);
33518
33519 spin_unlock(&pgd_lock);
33520
33521 return pgd;
33522
33523-out_free_pmds:
33524- free_pmds(pmds);
33525+out_free_pxds:
33526+ free_pxds(pxds);
33527 out_free_pgd:
33528 free_page((unsigned long)pgd);
33529 out:
33530@@ -313,7 +380,7 @@ out:
33531
33532 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33533 {
33534- pgd_mop_up_pmds(mm, pgd);
33535+ pgd_mop_up_pxds(mm, pgd);
33536 pgd_dtor(pgd);
33537 paravirt_pgd_free(mm, pgd);
33538 free_page((unsigned long)pgd);
33539diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33540index 4dd8cf6..f9d143e 100644
33541--- a/arch/x86/mm/pgtable_32.c
33542+++ b/arch/x86/mm/pgtable_32.c
33543@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33544 return;
33545 }
33546 pte = pte_offset_kernel(pmd, vaddr);
33547+
33548+ pax_open_kernel();
33549 if (pte_val(pteval))
33550 set_pte_at(&init_mm, vaddr, pte, pteval);
33551 else
33552 pte_clear(&init_mm, vaddr, pte);
33553+ pax_close_kernel();
33554
33555 /*
33556 * It's enough to flush this one mapping.
33557diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33558index e666cbb..61788c45 100644
33559--- a/arch/x86/mm/physaddr.c
33560+++ b/arch/x86/mm/physaddr.c
33561@@ -10,7 +10,7 @@
33562 #ifdef CONFIG_X86_64
33563
33564 #ifdef CONFIG_DEBUG_VIRTUAL
33565-unsigned long __phys_addr(unsigned long x)
33566+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33567 {
33568 unsigned long y = x - __START_KERNEL_map;
33569
33570@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33571 #else
33572
33573 #ifdef CONFIG_DEBUG_VIRTUAL
33574-unsigned long __phys_addr(unsigned long x)
33575+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33576 {
33577 unsigned long phys_addr = x - PAGE_OFFSET;
33578 /* VMALLOC_* aren't constants */
33579diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33580index 90555bf..f5f1828 100644
33581--- a/arch/x86/mm/setup_nx.c
33582+++ b/arch/x86/mm/setup_nx.c
33583@@ -5,8 +5,10 @@
33584 #include <asm/pgtable.h>
33585 #include <asm/proto.h>
33586
33587+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33588 static int disable_nx;
33589
33590+#ifndef CONFIG_PAX_PAGEEXEC
33591 /*
33592 * noexec = on|off
33593 *
33594@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33595 return 0;
33596 }
33597 early_param("noexec", noexec_setup);
33598+#endif
33599+
33600+#endif
33601
33602 void x86_configure_nx(void)
33603 {
33604+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33605 if (cpu_has_nx && !disable_nx)
33606 __supported_pte_mask |= _PAGE_NX;
33607 else
33608+#endif
33609 __supported_pte_mask &= ~_PAGE_NX;
33610 }
33611
33612diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33613index dd8dda1..9e9b0f6 100644
33614--- a/arch/x86/mm/tlb.c
33615+++ b/arch/x86/mm/tlb.c
33616@@ -48,7 +48,11 @@ void leave_mm(int cpu)
33617 BUG();
33618 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33619 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33620+
33621+#ifndef CONFIG_PAX_PER_CPU_PGD
33622 load_cr3(swapper_pg_dir);
33623+#endif
33624+
33625 }
33626 }
33627 EXPORT_SYMBOL_GPL(leave_mm);
33628diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33629new file mode 100644
33630index 0000000..dace51c
33631--- /dev/null
33632+++ b/arch/x86/mm/uderef_64.c
33633@@ -0,0 +1,37 @@
33634+#include <linux/mm.h>
33635+#include <asm/pgtable.h>
33636+#include <asm/uaccess.h>
33637+
33638+#ifdef CONFIG_PAX_MEMORY_UDEREF
33639+/* PaX: due to the special call convention these functions must
33640+ * - remain leaf functions under all configurations,
33641+ * - never be called directly, only dereferenced from the wrappers.
33642+ */
33643+void __pax_open_userland(void)
33644+{
33645+ unsigned int cpu;
33646+
33647+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33648+ return;
33649+
33650+ cpu = raw_get_cpu();
33651+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33652+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33653+ raw_put_cpu_no_resched();
33654+}
33655+EXPORT_SYMBOL(__pax_open_userland);
33656+
33657+void __pax_close_userland(void)
33658+{
33659+ unsigned int cpu;
33660+
33661+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33662+ return;
33663+
33664+ cpu = raw_get_cpu();
33665+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33666+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33667+ raw_put_cpu_no_resched();
33668+}
33669+EXPORT_SYMBOL(__pax_close_userland);
33670+#endif
33671diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33672index 0149575..f746de8 100644
33673--- a/arch/x86/net/bpf_jit.S
33674+++ b/arch/x86/net/bpf_jit.S
33675@@ -9,6 +9,7 @@
33676 */
33677 #include <linux/linkage.h>
33678 #include <asm/dwarf2.h>
33679+#include <asm/alternative-asm.h>
33680
33681 /*
33682 * Calling convention :
33683@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33684 jle bpf_slow_path_word
33685 mov (SKBDATA,%rsi),%eax
33686 bswap %eax /* ntohl() */
33687+ pax_force_retaddr
33688 ret
33689
33690 sk_load_half:
33691@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33692 jle bpf_slow_path_half
33693 movzwl (SKBDATA,%rsi),%eax
33694 rol $8,%ax # ntohs()
33695+ pax_force_retaddr
33696 ret
33697
33698 sk_load_byte:
33699@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33700 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33701 jle bpf_slow_path_byte
33702 movzbl (SKBDATA,%rsi),%eax
33703+ pax_force_retaddr
33704 ret
33705
33706 /**
33707@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33708 movzbl (SKBDATA,%rsi),%ebx
33709 and $15,%bl
33710 shl $2,%bl
33711+ pax_force_retaddr
33712 ret
33713
33714 /* rsi contains offset and can be scratched */
33715@@ -109,6 +114,7 @@ bpf_slow_path_word:
33716 js bpf_error
33717 mov -12(%rbp),%eax
33718 bswap %eax
33719+ pax_force_retaddr
33720 ret
33721
33722 bpf_slow_path_half:
33723@@ -117,12 +123,14 @@ bpf_slow_path_half:
33724 mov -12(%rbp),%ax
33725 rol $8,%ax
33726 movzwl %ax,%eax
33727+ pax_force_retaddr
33728 ret
33729
33730 bpf_slow_path_byte:
33731 bpf_slow_path_common(1)
33732 js bpf_error
33733 movzbl -12(%rbp),%eax
33734+ pax_force_retaddr
33735 ret
33736
33737 bpf_slow_path_byte_msh:
33738@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33739 and $15,%al
33740 shl $2,%al
33741 xchg %eax,%ebx
33742+ pax_force_retaddr
33743 ret
33744
33745 #define sk_negative_common(SIZE) \
33746@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33747 sk_negative_common(4)
33748 mov (%rax), %eax
33749 bswap %eax
33750+ pax_force_retaddr
33751 ret
33752
33753 bpf_slow_path_half_neg:
33754@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33755 mov (%rax),%ax
33756 rol $8,%ax
33757 movzwl %ax,%eax
33758+ pax_force_retaddr
33759 ret
33760
33761 bpf_slow_path_byte_neg:
33762@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33763 .globl sk_load_byte_negative_offset
33764 sk_negative_common(1)
33765 movzbl (%rax), %eax
33766+ pax_force_retaddr
33767 ret
33768
33769 bpf_slow_path_byte_msh_neg:
33770@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33771 and $15,%al
33772 shl $2,%al
33773 xchg %eax,%ebx
33774+ pax_force_retaddr
33775 ret
33776
33777 bpf_error:
33778@@ -197,4 +210,5 @@ bpf_error:
33779 xor %eax,%eax
33780 mov -8(%rbp),%rbx
33781 leaveq
33782+ pax_force_retaddr
33783 ret
33784diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33785index 6d5663a..f1ec380 100644
33786--- a/arch/x86/net/bpf_jit_comp.c
33787+++ b/arch/x86/net/bpf_jit_comp.c
33788@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33789 return ptr + len;
33790 }
33791
33792+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33793+#define MAX_INSTR_CODE_SIZE 96
33794+#else
33795+#define MAX_INSTR_CODE_SIZE 64
33796+#endif
33797+
33798 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33799
33800 #define EMIT1(b1) EMIT(b1, 1)
33801 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33802 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33803 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33804+
33805+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33806+/* original constant will appear in ecx */
33807+#define DILUTE_CONST_SEQUENCE(_off, _key) \
33808+do { \
33809+ /* mov ecx, randkey */ \
33810+ EMIT1(0xb9); \
33811+ EMIT(_key, 4); \
33812+ /* xor ecx, randkey ^ off */ \
33813+ EMIT2(0x81, 0xf1); \
33814+ EMIT((_key) ^ (_off), 4); \
33815+} while (0)
33816+
33817+#define EMIT1_off32(b1, _off) \
33818+do { \
33819+ switch (b1) { \
33820+ case 0x05: /* add eax, imm32 */ \
33821+ case 0x2d: /* sub eax, imm32 */ \
33822+ case 0x25: /* and eax, imm32 */ \
33823+ case 0x0d: /* or eax, imm32 */ \
33824+ case 0xb8: /* mov eax, imm32 */ \
33825+ case 0x35: /* xor eax, imm32 */ \
33826+ case 0x3d: /* cmp eax, imm32 */ \
33827+ case 0xa9: /* test eax, imm32 */ \
33828+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33829+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33830+ break; \
33831+ case 0xbb: /* mov ebx, imm32 */ \
33832+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33833+ /* mov ebx, ecx */ \
33834+ EMIT2(0x89, 0xcb); \
33835+ break; \
33836+ case 0xbe: /* mov esi, imm32 */ \
33837+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33838+ /* mov esi, ecx */ \
33839+ EMIT2(0x89, 0xce); \
33840+ break; \
33841+ case 0xe8: /* call rel imm32, always to known funcs */ \
33842+ EMIT1(b1); \
33843+ EMIT(_off, 4); \
33844+ break; \
33845+ case 0xe9: /* jmp rel imm32 */ \
33846+ EMIT1(b1); \
33847+ EMIT(_off, 4); \
33848+ /* prevent fall-through, we're not called if off = 0 */ \
33849+ EMIT(0xcccccccc, 4); \
33850+ EMIT(0xcccccccc, 4); \
33851+ break; \
33852+ default: \
33853+ BUILD_BUG(); \
33854+ } \
33855+} while (0)
33856+
33857+#define EMIT2_off32(b1, b2, _off) \
33858+do { \
33859+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33860+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33861+ EMIT(randkey, 4); \
33862+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33863+ EMIT((_off) - randkey, 4); \
33864+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33865+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33866+ /* imul eax, ecx */ \
33867+ EMIT3(0x0f, 0xaf, 0xc1); \
33868+ } else { \
33869+ BUILD_BUG(); \
33870+ } \
33871+} while (0)
33872+#else
33873 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33874+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33875+#endif
33876
33877 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33878 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33879@@ -91,6 +168,24 @@ do { \
33880 #define X86_JBE 0x76
33881 #define X86_JA 0x77
33882
33883+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33884+#define APPEND_FLOW_VERIFY() \
33885+do { \
33886+ /* mov ecx, randkey */ \
33887+ EMIT1(0xb9); \
33888+ EMIT(randkey, 4); \
33889+ /* cmp ecx, randkey */ \
33890+ EMIT2(0x81, 0xf9); \
33891+ EMIT(randkey, 4); \
33892+ /* jz after 8 int 3s */ \
33893+ EMIT2(0x74, 0x08); \
33894+ EMIT(0xcccccccc, 4); \
33895+ EMIT(0xcccccccc, 4); \
33896+} while (0)
33897+#else
33898+#define APPEND_FLOW_VERIFY() do { } while (0)
33899+#endif
33900+
33901 #define EMIT_COND_JMP(op, offset) \
33902 do { \
33903 if (is_near(offset)) \
33904@@ -98,6 +193,7 @@ do { \
33905 else { \
33906 EMIT2(0x0f, op + 0x10); \
33907 EMIT(offset, 4); /* jxx .+off32 */ \
33908+ APPEND_FLOW_VERIFY(); \
33909 } \
33910 } while (0)
33911
33912@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33913 return -1;
33914 }
33915
33916-struct bpf_binary_header {
33917- unsigned int pages;
33918- /* Note : for security reasons, bpf code will follow a randomly
33919- * sized amount of int3 instructions
33920- */
33921- u8 image[];
33922-};
33923-
33924-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33925+/* Note : for security reasons, bpf code will follow a randomly
33926+ * sized amount of int3 instructions
33927+ */
33928+static u8 *bpf_alloc_binary(unsigned int proglen,
33929 u8 **image_ptr)
33930 {
33931 unsigned int sz, hole;
33932- struct bpf_binary_header *header;
33933+ u8 *header;
33934
33935 /* Most of BPF filters are really small,
33936 * but if some of them fill a page, allow at least
33937 * 128 extra bytes to insert a random section of int3
33938 */
33939- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33940- header = module_alloc(sz);
33941+ sz = round_up(proglen + 128, PAGE_SIZE);
33942+ header = module_alloc_exec(sz);
33943 if (!header)
33944 return NULL;
33945
33946+ pax_open_kernel();
33947 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33948+ pax_close_kernel();
33949
33950- header->pages = sz / PAGE_SIZE;
33951- hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
33952+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33953
33954 /* insert a random number of int3 instructions before BPF code */
33955- *image_ptr = &header->image[prandom_u32() % hole];
33956+ *image_ptr = &header[prandom_u32() % hole];
33957 return header;
33958 }
33959
33960 void bpf_jit_compile(struct sk_filter *fp)
33961 {
33962- u8 temp[64];
33963+ u8 temp[MAX_INSTR_CODE_SIZE];
33964 u8 *prog;
33965 unsigned int proglen, oldproglen = 0;
33966 int ilen, i;
33967 int t_offset, f_offset;
33968 u8 t_op, f_op, seen = 0, pass;
33969 u8 *image = NULL;
33970- struct bpf_binary_header *header = NULL;
33971+ u8 *header = NULL;
33972 u8 *func;
33973 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33974 unsigned int cleanup_addr; /* epilogue code offset */
33975 unsigned int *addrs;
33976 const struct sock_filter *filter = fp->insns;
33977 int flen = fp->len;
33978+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33979+ unsigned int randkey;
33980+#endif
33981
33982 if (!bpf_jit_enable)
33983 return;
33984@@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33985 return;
33986
33987 /* Before first pass, make a rough estimation of addrs[]
33988- * each bpf instruction is translated to less than 64 bytes
33989+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33990 */
33991 for (proglen = 0, i = 0; i < flen; i++) {
33992- proglen += 64;
33993+ proglen += MAX_INSTR_CODE_SIZE;
33994 addrs[i] = proglen;
33995 }
33996 cleanup_addr = proglen; /* epilogue address */
33997@@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33998 for (i = 0; i < flen; i++) {
33999 unsigned int K = filter[i].k;
34000
34001+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34002+ randkey = prandom_u32();
34003+#endif
34004+
34005 switch (filter[i].code) {
34006 case BPF_S_ALU_ADD_X: /* A += X; */
34007 seen |= SEEN_XREG;
34008@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
34009 case BPF_S_ALU_MUL_K: /* A *= K */
34010 if (is_imm8(K))
34011 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
34012- else {
34013- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
34014- EMIT(K, 4);
34015- }
34016+ else
34017+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
34018 break;
34019 case BPF_S_ALU_DIV_X: /* A /= X; */
34020 seen |= SEEN_XREG;
34021@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34022 break;
34023 }
34024 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34025+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34026+ DILUTE_CONST_SEQUENCE(K, randkey);
34027+#else
34028 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34029+#endif
34030 EMIT2(0xf7, 0xf1); /* div %ecx */
34031 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
34032 break;
34033@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34034 if (K == 1)
34035 break;
34036 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34037+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34038+ DILUTE_CONST_SEQUENCE(K, randkey);
34039+#else
34040 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34041+#endif
34042 EMIT2(0xf7, 0xf1); /* div %ecx */
34043 break;
34044 case BPF_S_ALU_AND_X:
34045@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
34046 if (is_imm8(K)) {
34047 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
34048 } else {
34049- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
34050- EMIT(K, 4);
34051+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
34052 }
34053 } else {
34054 EMIT2(0x89,0xde); /* mov %ebx,%esi */
34055@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34056 if (unlikely(proglen + ilen > oldproglen)) {
34057 pr_err("bpb_jit_compile fatal error\n");
34058 kfree(addrs);
34059- module_free(NULL, header);
34060+ module_free_exec(NULL, image);
34061 return;
34062 }
34063+ pax_open_kernel();
34064 memcpy(image + proglen, temp, ilen);
34065+ pax_close_kernel();
34066 }
34067 proglen += ilen;
34068 addrs[i] = proglen;
34069@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34070
34071 if (image) {
34072 bpf_flush_icache(header, image + proglen);
34073- set_memory_ro((unsigned long)header, header->pages);
34074 fp->bpf_func = (void *)image;
34075 fp->jited = 1;
34076 }
34077@@ -783,10 +888,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
34078 {
34079 struct sk_filter *fp = container_of(work, struct sk_filter, work);
34080 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34081- struct bpf_binary_header *header = (void *)addr;
34082
34083- set_memory_rw(addr, header->pages);
34084- module_free(NULL, header);
34085+ set_memory_rw(addr, 1);
34086+ module_free_exec(NULL, (void *)addr);
34087 kfree(fp);
34088 }
34089
34090diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34091index 5d04be5..2beeaa2 100644
34092--- a/arch/x86/oprofile/backtrace.c
34093+++ b/arch/x86/oprofile/backtrace.c
34094@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34095 struct stack_frame_ia32 *fp;
34096 unsigned long bytes;
34097
34098- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34099+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34100 if (bytes != 0)
34101 return NULL;
34102
34103- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34104+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34105
34106 oprofile_add_trace(bufhead[0].return_address);
34107
34108@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34109 struct stack_frame bufhead[2];
34110 unsigned long bytes;
34111
34112- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34113+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34114 if (bytes != 0)
34115 return NULL;
34116
34117@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34118 {
34119 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34120
34121- if (!user_mode_vm(regs)) {
34122+ if (!user_mode(regs)) {
34123 unsigned long stack = kernel_stack_pointer(regs);
34124 if (depth)
34125 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34126diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34127index 379e8bd..6386e09 100644
34128--- a/arch/x86/oprofile/nmi_int.c
34129+++ b/arch/x86/oprofile/nmi_int.c
34130@@ -23,6 +23,7 @@
34131 #include <asm/nmi.h>
34132 #include <asm/msr.h>
34133 #include <asm/apic.h>
34134+#include <asm/pgtable.h>
34135
34136 #include "op_counter.h"
34137 #include "op_x86_model.h"
34138@@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34139 if (ret)
34140 return ret;
34141
34142- if (!model->num_virt_counters)
34143- model->num_virt_counters = model->num_counters;
34144+ if (!model->num_virt_counters) {
34145+ pax_open_kernel();
34146+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34147+ pax_close_kernel();
34148+ }
34149
34150 mux_init(ops);
34151
34152diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34153index 50d86c0..7985318 100644
34154--- a/arch/x86/oprofile/op_model_amd.c
34155+++ b/arch/x86/oprofile/op_model_amd.c
34156@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34157 num_counters = AMD64_NUM_COUNTERS;
34158 }
34159
34160- op_amd_spec.num_counters = num_counters;
34161- op_amd_spec.num_controls = num_counters;
34162- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34163+ pax_open_kernel();
34164+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34165+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34166+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34167+ pax_close_kernel();
34168
34169 return 0;
34170 }
34171diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34172index d90528e..0127e2b 100644
34173--- a/arch/x86/oprofile/op_model_ppro.c
34174+++ b/arch/x86/oprofile/op_model_ppro.c
34175@@ -19,6 +19,7 @@
34176 #include <asm/msr.h>
34177 #include <asm/apic.h>
34178 #include <asm/nmi.h>
34179+#include <asm/pgtable.h>
34180
34181 #include "op_x86_model.h"
34182 #include "op_counter.h"
34183@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34184
34185 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34186
34187- op_arch_perfmon_spec.num_counters = num_counters;
34188- op_arch_perfmon_spec.num_controls = num_counters;
34189+ pax_open_kernel();
34190+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34191+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34192+ pax_close_kernel();
34193 }
34194
34195 static int arch_perfmon_init(struct oprofile_operations *ignore)
34196diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34197index 71e8a67..6a313bb 100644
34198--- a/arch/x86/oprofile/op_x86_model.h
34199+++ b/arch/x86/oprofile/op_x86_model.h
34200@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34201 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34202 struct op_msrs const * const msrs);
34203 #endif
34204-};
34205+} __do_const;
34206
34207 struct op_counter_config;
34208
34209diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34210index 84b9d67..260e5ff 100644
34211--- a/arch/x86/pci/intel_mid_pci.c
34212+++ b/arch/x86/pci/intel_mid_pci.c
34213@@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34214 pr_info("Intel MID platform detected, using MID PCI ops\n");
34215 pci_mmcfg_late_init();
34216 pcibios_enable_irq = intel_mid_pci_irq_enable;
34217- pci_root_ops = intel_mid_pci_ops;
34218+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34219 pci_soc_mode = 1;
34220 /* Continue with standard init */
34221 return 1;
34222diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34223index 84112f5..6334d60 100644
34224--- a/arch/x86/pci/irq.c
34225+++ b/arch/x86/pci/irq.c
34226@@ -50,7 +50,7 @@ struct irq_router {
34227 struct irq_router_handler {
34228 u16 vendor;
34229 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34230-};
34231+} __do_const;
34232
34233 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34234 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34235@@ -790,7 +790,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34236 return 0;
34237 }
34238
34239-static __initdata struct irq_router_handler pirq_routers[] = {
34240+static __initconst const struct irq_router_handler pirq_routers[] = {
34241 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34242 { PCI_VENDOR_ID_AL, ali_router_probe },
34243 { PCI_VENDOR_ID_ITE, ite_router_probe },
34244@@ -817,7 +817,7 @@ static struct pci_dev *pirq_router_dev;
34245 static void __init pirq_find_router(struct irq_router *r)
34246 {
34247 struct irq_routing_table *rt = pirq_table;
34248- struct irq_router_handler *h;
34249+ const struct irq_router_handler *h;
34250
34251 #ifdef CONFIG_PCI_BIOS
34252 if (!rt->signature) {
34253@@ -1090,7 +1090,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34254 return 0;
34255 }
34256
34257-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34258+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34259 {
34260 .callback = fix_broken_hp_bios_irq9,
34261 .ident = "HP Pavilion N5400 Series Laptop",
34262diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34263index c77b24a..c979855 100644
34264--- a/arch/x86/pci/pcbios.c
34265+++ b/arch/x86/pci/pcbios.c
34266@@ -79,7 +79,7 @@ union bios32 {
34267 static struct {
34268 unsigned long address;
34269 unsigned short segment;
34270-} bios32_indirect = { 0, __KERNEL_CS };
34271+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34272
34273 /*
34274 * Returns the entry point for the given service, NULL on error
34275@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34276 unsigned long length; /* %ecx */
34277 unsigned long entry; /* %edx */
34278 unsigned long flags;
34279+ struct desc_struct d, *gdt;
34280
34281 local_irq_save(flags);
34282- __asm__("lcall *(%%edi); cld"
34283+
34284+ gdt = get_cpu_gdt_table(smp_processor_id());
34285+
34286+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34287+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34288+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34289+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34290+
34291+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34292 : "=a" (return_code),
34293 "=b" (address),
34294 "=c" (length),
34295 "=d" (entry)
34296 : "0" (service),
34297 "1" (0),
34298- "D" (&bios32_indirect));
34299+ "D" (&bios32_indirect),
34300+ "r"(__PCIBIOS_DS)
34301+ : "memory");
34302+
34303+ pax_open_kernel();
34304+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34305+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34306+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34307+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34308+ pax_close_kernel();
34309+
34310 local_irq_restore(flags);
34311
34312 switch (return_code) {
34313- case 0:
34314- return address + entry;
34315- case 0x80: /* Not present */
34316- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34317- return 0;
34318- default: /* Shouldn't happen */
34319- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34320- service, return_code);
34321+ case 0: {
34322+ int cpu;
34323+ unsigned char flags;
34324+
34325+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34326+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34327+ printk(KERN_WARNING "bios32_service: not valid\n");
34328 return 0;
34329+ }
34330+ address = address + PAGE_OFFSET;
34331+ length += 16UL; /* some BIOSs underreport this... */
34332+ flags = 4;
34333+ if (length >= 64*1024*1024) {
34334+ length >>= PAGE_SHIFT;
34335+ flags |= 8;
34336+ }
34337+
34338+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34339+ gdt = get_cpu_gdt_table(cpu);
34340+ pack_descriptor(&d, address, length, 0x9b, flags);
34341+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34342+ pack_descriptor(&d, address, length, 0x93, flags);
34343+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34344+ }
34345+ return entry;
34346+ }
34347+ case 0x80: /* Not present */
34348+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34349+ return 0;
34350+ default: /* Shouldn't happen */
34351+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34352+ service, return_code);
34353+ return 0;
34354 }
34355 }
34356
34357 static struct {
34358 unsigned long address;
34359 unsigned short segment;
34360-} pci_indirect = { 0, __KERNEL_CS };
34361+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34362
34363-static int pci_bios_present;
34364+static int pci_bios_present __read_only;
34365
34366 static int check_pcibios(void)
34367 {
34368@@ -131,11 +174,13 @@ static int check_pcibios(void)
34369 unsigned long flags, pcibios_entry;
34370
34371 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34372- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34373+ pci_indirect.address = pcibios_entry;
34374
34375 local_irq_save(flags);
34376- __asm__(
34377- "lcall *(%%edi); cld\n\t"
34378+ __asm__("movw %w6, %%ds\n\t"
34379+ "lcall *%%ss:(%%edi); cld\n\t"
34380+ "push %%ss\n\t"
34381+ "pop %%ds\n\t"
34382 "jc 1f\n\t"
34383 "xor %%ah, %%ah\n"
34384 "1:"
34385@@ -144,7 +189,8 @@ static int check_pcibios(void)
34386 "=b" (ebx),
34387 "=c" (ecx)
34388 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34389- "D" (&pci_indirect)
34390+ "D" (&pci_indirect),
34391+ "r" (__PCIBIOS_DS)
34392 : "memory");
34393 local_irq_restore(flags);
34394
34395@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34396
34397 switch (len) {
34398 case 1:
34399- __asm__("lcall *(%%esi); cld\n\t"
34400+ __asm__("movw %w6, %%ds\n\t"
34401+ "lcall *%%ss:(%%esi); cld\n\t"
34402+ "push %%ss\n\t"
34403+ "pop %%ds\n\t"
34404 "jc 1f\n\t"
34405 "xor %%ah, %%ah\n"
34406 "1:"
34407@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34408 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34409 "b" (bx),
34410 "D" ((long)reg),
34411- "S" (&pci_indirect));
34412+ "S" (&pci_indirect),
34413+ "r" (__PCIBIOS_DS));
34414 /*
34415 * Zero-extend the result beyond 8 bits, do not trust the
34416 * BIOS having done it:
34417@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34418 *value &= 0xff;
34419 break;
34420 case 2:
34421- __asm__("lcall *(%%esi); cld\n\t"
34422+ __asm__("movw %w6, %%ds\n\t"
34423+ "lcall *%%ss:(%%esi); cld\n\t"
34424+ "push %%ss\n\t"
34425+ "pop %%ds\n\t"
34426 "jc 1f\n\t"
34427 "xor %%ah, %%ah\n"
34428 "1:"
34429@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34430 : "1" (PCIBIOS_READ_CONFIG_WORD),
34431 "b" (bx),
34432 "D" ((long)reg),
34433- "S" (&pci_indirect));
34434+ "S" (&pci_indirect),
34435+ "r" (__PCIBIOS_DS));
34436 /*
34437 * Zero-extend the result beyond 16 bits, do not trust the
34438 * BIOS having done it:
34439@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34440 *value &= 0xffff;
34441 break;
34442 case 4:
34443- __asm__("lcall *(%%esi); cld\n\t"
34444+ __asm__("movw %w6, %%ds\n\t"
34445+ "lcall *%%ss:(%%esi); cld\n\t"
34446+ "push %%ss\n\t"
34447+ "pop %%ds\n\t"
34448 "jc 1f\n\t"
34449 "xor %%ah, %%ah\n"
34450 "1:"
34451@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34452 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34453 "b" (bx),
34454 "D" ((long)reg),
34455- "S" (&pci_indirect));
34456+ "S" (&pci_indirect),
34457+ "r" (__PCIBIOS_DS));
34458 break;
34459 }
34460
34461@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34462
34463 switch (len) {
34464 case 1:
34465- __asm__("lcall *(%%esi); cld\n\t"
34466+ __asm__("movw %w6, %%ds\n\t"
34467+ "lcall *%%ss:(%%esi); cld\n\t"
34468+ "push %%ss\n\t"
34469+ "pop %%ds\n\t"
34470 "jc 1f\n\t"
34471 "xor %%ah, %%ah\n"
34472 "1:"
34473@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34474 "c" (value),
34475 "b" (bx),
34476 "D" ((long)reg),
34477- "S" (&pci_indirect));
34478+ "S" (&pci_indirect),
34479+ "r" (__PCIBIOS_DS));
34480 break;
34481 case 2:
34482- __asm__("lcall *(%%esi); cld\n\t"
34483+ __asm__("movw %w6, %%ds\n\t"
34484+ "lcall *%%ss:(%%esi); cld\n\t"
34485+ "push %%ss\n\t"
34486+ "pop %%ds\n\t"
34487 "jc 1f\n\t"
34488 "xor %%ah, %%ah\n"
34489 "1:"
34490@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34491 "c" (value),
34492 "b" (bx),
34493 "D" ((long)reg),
34494- "S" (&pci_indirect));
34495+ "S" (&pci_indirect),
34496+ "r" (__PCIBIOS_DS));
34497 break;
34498 case 4:
34499- __asm__("lcall *(%%esi); cld\n\t"
34500+ __asm__("movw %w6, %%ds\n\t"
34501+ "lcall *%%ss:(%%esi); cld\n\t"
34502+ "push %%ss\n\t"
34503+ "pop %%ds\n\t"
34504 "jc 1f\n\t"
34505 "xor %%ah, %%ah\n"
34506 "1:"
34507@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34508 "c" (value),
34509 "b" (bx),
34510 "D" ((long)reg),
34511- "S" (&pci_indirect));
34512+ "S" (&pci_indirect),
34513+ "r" (__PCIBIOS_DS));
34514 break;
34515 }
34516
34517@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34518
34519 DBG("PCI: Fetching IRQ routing table... ");
34520 __asm__("push %%es\n\t"
34521+ "movw %w8, %%ds\n\t"
34522 "push %%ds\n\t"
34523 "pop %%es\n\t"
34524- "lcall *(%%esi); cld\n\t"
34525+ "lcall *%%ss:(%%esi); cld\n\t"
34526 "pop %%es\n\t"
34527+ "push %%ss\n\t"
34528+ "pop %%ds\n"
34529 "jc 1f\n\t"
34530 "xor %%ah, %%ah\n"
34531 "1:"
34532@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34533 "1" (0),
34534 "D" ((long) &opt),
34535 "S" (&pci_indirect),
34536- "m" (opt)
34537+ "m" (opt),
34538+ "r" (__PCIBIOS_DS)
34539 : "memory");
34540 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34541 if (ret & 0xff00)
34542@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34543 {
34544 int ret;
34545
34546- __asm__("lcall *(%%esi); cld\n\t"
34547+ __asm__("movw %w5, %%ds\n\t"
34548+ "lcall *%%ss:(%%esi); cld\n\t"
34549+ "push %%ss\n\t"
34550+ "pop %%ds\n"
34551 "jc 1f\n\t"
34552 "xor %%ah, %%ah\n"
34553 "1:"
34554@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34555 : "0" (PCIBIOS_SET_PCI_HW_INT),
34556 "b" ((dev->bus->number << 8) | dev->devfn),
34557 "c" ((irq << 8) | (pin + 10)),
34558- "S" (&pci_indirect));
34559+ "S" (&pci_indirect),
34560+ "r" (__PCIBIOS_DS));
34561 return !(ret & 0xff00);
34562 }
34563 EXPORT_SYMBOL(pcibios_set_irq_routing);
34564diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34565index 9ee3491..872192f 100644
34566--- a/arch/x86/platform/efi/efi_32.c
34567+++ b/arch/x86/platform/efi/efi_32.c
34568@@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34569 {
34570 struct desc_ptr gdt_descr;
34571
34572+#ifdef CONFIG_PAX_KERNEXEC
34573+ struct desc_struct d;
34574+#endif
34575+
34576 local_irq_save(efi_rt_eflags);
34577
34578 load_cr3(initial_page_table);
34579 __flush_tlb_all();
34580
34581+#ifdef CONFIG_PAX_KERNEXEC
34582+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34583+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34584+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34585+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34586+#endif
34587+
34588 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34589 gdt_descr.size = GDT_SIZE - 1;
34590 load_gdt(&gdt_descr);
34591@@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34592 {
34593 struct desc_ptr gdt_descr;
34594
34595+#ifdef CONFIG_PAX_KERNEXEC
34596+ struct desc_struct d;
34597+
34598+ memset(&d, 0, sizeof d);
34599+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34600+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34601+#endif
34602+
34603 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34604 gdt_descr.size = GDT_SIZE - 1;
34605 load_gdt(&gdt_descr);
34606
34607+#ifdef CONFIG_PAX_PER_CPU_PGD
34608+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34609+#else
34610 load_cr3(swapper_pg_dir);
34611+#endif
34612+
34613 __flush_tlb_all();
34614
34615 local_irq_restore(efi_rt_eflags);
34616diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34617index 290d397..3906bcd 100644
34618--- a/arch/x86/platform/efi/efi_64.c
34619+++ b/arch/x86/platform/efi/efi_64.c
34620@@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
34621 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34622 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34623 }
34624+
34625+#ifdef CONFIG_PAX_PER_CPU_PGD
34626+ load_cr3(swapper_pg_dir);
34627+#endif
34628+
34629 __flush_tlb_all();
34630 }
34631
34632@@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34633 for (pgd = 0; pgd < n_pgds; pgd++)
34634 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34635 kfree(save_pgd);
34636+
34637+#ifdef CONFIG_PAX_PER_CPU_PGD
34638+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34639+#endif
34640+
34641 __flush_tlb_all();
34642 local_irq_restore(efi_flags);
34643 early_code_mapping_set_exec(0);
34644diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34645index fbe66e6..eae5e38 100644
34646--- a/arch/x86/platform/efi/efi_stub_32.S
34647+++ b/arch/x86/platform/efi/efi_stub_32.S
34648@@ -6,7 +6,9 @@
34649 */
34650
34651 #include <linux/linkage.h>
34652+#include <linux/init.h>
34653 #include <asm/page_types.h>
34654+#include <asm/segment.h>
34655
34656 /*
34657 * efi_call_phys(void *, ...) is a function with variable parameters.
34658@@ -20,7 +22,7 @@
34659 * service functions will comply with gcc calling convention, too.
34660 */
34661
34662-.text
34663+__INIT
34664 ENTRY(efi_call_phys)
34665 /*
34666 * 0. The function can only be called in Linux kernel. So CS has been
34667@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34668 * The mapping of lower virtual memory has been created in prelog and
34669 * epilog.
34670 */
34671- movl $1f, %edx
34672- subl $__PAGE_OFFSET, %edx
34673- jmp *%edx
34674+#ifdef CONFIG_PAX_KERNEXEC
34675+ movl $(__KERNEXEC_EFI_DS), %edx
34676+ mov %edx, %ds
34677+ mov %edx, %es
34678+ mov %edx, %ss
34679+ addl $2f,(1f)
34680+ ljmp *(1f)
34681+
34682+__INITDATA
34683+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34684+.previous
34685+
34686+2:
34687+ subl $2b,(1b)
34688+#else
34689+ jmp 1f-__PAGE_OFFSET
34690 1:
34691+#endif
34692
34693 /*
34694 * 2. Now on the top of stack is the return
34695@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34696 * parameter 2, ..., param n. To make things easy, we save the return
34697 * address of efi_call_phys in a global variable.
34698 */
34699- popl %edx
34700- movl %edx, saved_return_addr
34701- /* get the function pointer into ECX*/
34702- popl %ecx
34703- movl %ecx, efi_rt_function_ptr
34704- movl $2f, %edx
34705- subl $__PAGE_OFFSET, %edx
34706- pushl %edx
34707+ popl (saved_return_addr)
34708+ popl (efi_rt_function_ptr)
34709
34710 /*
34711 * 3. Clear PG bit in %CR0.
34712@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34713 /*
34714 * 5. Call the physical function.
34715 */
34716- jmp *%ecx
34717+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34718
34719-2:
34720 /*
34721 * 6. After EFI runtime service returns, control will return to
34722 * following instruction. We'd better readjust stack pointer first.
34723@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34724 movl %cr0, %edx
34725 orl $0x80000000, %edx
34726 movl %edx, %cr0
34727- jmp 1f
34728-1:
34729+
34730 /*
34731 * 8. Now restore the virtual mode from flat mode by
34732 * adding EIP with PAGE_OFFSET.
34733 */
34734- movl $1f, %edx
34735- jmp *%edx
34736+#ifdef CONFIG_PAX_KERNEXEC
34737+ movl $(__KERNEL_DS), %edx
34738+ mov %edx, %ds
34739+ mov %edx, %es
34740+ mov %edx, %ss
34741+ ljmp $(__KERNEL_CS),$1f
34742+#else
34743+ jmp 1f+__PAGE_OFFSET
34744+#endif
34745 1:
34746
34747 /*
34748 * 9. Balance the stack. And because EAX contain the return value,
34749 * we'd better not clobber it.
34750 */
34751- leal efi_rt_function_ptr, %edx
34752- movl (%edx), %ecx
34753- pushl %ecx
34754+ pushl (efi_rt_function_ptr)
34755
34756 /*
34757- * 10. Push the saved return address onto the stack and return.
34758+ * 10. Return to the saved return address.
34759 */
34760- leal saved_return_addr, %edx
34761- movl (%edx), %ecx
34762- pushl %ecx
34763- ret
34764+ jmpl *(saved_return_addr)
34765 ENDPROC(efi_call_phys)
34766 .previous
34767
34768-.data
34769+__INITDATA
34770 saved_return_addr:
34771 .long 0
34772 efi_rt_function_ptr:
34773diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34774index e0984ef..a062dac 100644
34775--- a/arch/x86/platform/efi/efi_stub_64.S
34776+++ b/arch/x86/platform/efi/efi_stub_64.S
34777@@ -11,6 +11,7 @@
34778 #include <asm/msr.h>
34779 #include <asm/processor-flags.h>
34780 #include <asm/page_types.h>
34781+#include <asm/alternative-asm.h>
34782
34783 #define SAVE_XMM \
34784 mov %rsp, %rax; \
34785@@ -81,6 +82,7 @@ ENTRY(efi_call0)
34786 RESTORE_PGT
34787 addq $32, %rsp
34788 RESTORE_XMM
34789+ pax_force_retaddr 0, 1
34790 ret
34791 ENDPROC(efi_call0)
34792
34793@@ -93,6 +95,7 @@ ENTRY(efi_call1)
34794 RESTORE_PGT
34795 addq $32, %rsp
34796 RESTORE_XMM
34797+ pax_force_retaddr 0, 1
34798 ret
34799 ENDPROC(efi_call1)
34800
34801@@ -105,6 +108,7 @@ ENTRY(efi_call2)
34802 RESTORE_PGT
34803 addq $32, %rsp
34804 RESTORE_XMM
34805+ pax_force_retaddr 0, 1
34806 ret
34807 ENDPROC(efi_call2)
34808
34809@@ -118,6 +122,7 @@ ENTRY(efi_call3)
34810 RESTORE_PGT
34811 addq $32, %rsp
34812 RESTORE_XMM
34813+ pax_force_retaddr 0, 1
34814 ret
34815 ENDPROC(efi_call3)
34816
34817@@ -132,6 +137,7 @@ ENTRY(efi_call4)
34818 RESTORE_PGT
34819 addq $32, %rsp
34820 RESTORE_XMM
34821+ pax_force_retaddr 0, 1
34822 ret
34823 ENDPROC(efi_call4)
34824
34825@@ -147,6 +153,7 @@ ENTRY(efi_call5)
34826 RESTORE_PGT
34827 addq $48, %rsp
34828 RESTORE_XMM
34829+ pax_force_retaddr 0, 1
34830 ret
34831 ENDPROC(efi_call5)
34832
34833@@ -165,6 +172,7 @@ ENTRY(efi_call6)
34834 RESTORE_PGT
34835 addq $48, %rsp
34836 RESTORE_XMM
34837+ pax_force_retaddr 0, 1
34838 ret
34839 ENDPROC(efi_call6)
34840
34841diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34842index 1bbedc4..eb795b5 100644
34843--- a/arch/x86/platform/intel-mid/intel-mid.c
34844+++ b/arch/x86/platform/intel-mid/intel-mid.c
34845@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34846 {
34847 };
34848
34849-static void intel_mid_reboot(void)
34850+static void __noreturn intel_mid_reboot(void)
34851 {
34852 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34853+ BUG();
34854 }
34855
34856 static unsigned long __init intel_mid_calibrate_tsc(void)
34857diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34858index d6ee929..3637cb5 100644
34859--- a/arch/x86/platform/olpc/olpc_dt.c
34860+++ b/arch/x86/platform/olpc/olpc_dt.c
34861@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34862 return res;
34863 }
34864
34865-static struct of_pdt_ops prom_olpc_ops __initdata = {
34866+static struct of_pdt_ops prom_olpc_ops __initconst = {
34867 .nextprop = olpc_dt_nextprop,
34868 .getproplen = olpc_dt_getproplen,
34869 .getproperty = olpc_dt_getproperty,
34870diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34871index 424f4c9..f2a2988 100644
34872--- a/arch/x86/power/cpu.c
34873+++ b/arch/x86/power/cpu.c
34874@@ -137,11 +137,8 @@ static void do_fpu_end(void)
34875 static void fix_processor_context(void)
34876 {
34877 int cpu = smp_processor_id();
34878- struct tss_struct *t = &per_cpu(init_tss, cpu);
34879-#ifdef CONFIG_X86_64
34880- struct desc_struct *desc = get_cpu_gdt_table(cpu);
34881- tss_desc tss;
34882-#endif
34883+ struct tss_struct *t = init_tss + cpu;
34884+
34885 set_tss_desc(cpu, t); /*
34886 * This just modifies memory; should not be
34887 * necessary. But... This is necessary, because
34888@@ -150,10 +147,6 @@ static void fix_processor_context(void)
34889 */
34890
34891 #ifdef CONFIG_X86_64
34892- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34893- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34894- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34895-
34896 syscall_init(); /* This sets MSR_*STAR and related */
34897 #endif
34898 load_TR_desc(); /* This does ltr */
34899diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34900index bad628a..a102610 100644
34901--- a/arch/x86/realmode/init.c
34902+++ b/arch/x86/realmode/init.c
34903@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
34904 __va(real_mode_header->trampoline_header);
34905
34906 #ifdef CONFIG_X86_32
34907- trampoline_header->start = __pa_symbol(startup_32_smp);
34908+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34909+
34910+#ifdef CONFIG_PAX_KERNEXEC
34911+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34912+#endif
34913+
34914+ trampoline_header->boot_cs = __BOOT_CS;
34915 trampoline_header->gdt_limit = __BOOT_DS + 7;
34916 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34917 #else
34918@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
34919 *trampoline_cr4_features = read_cr4();
34920
34921 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34922- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34923+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34924 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34925 #endif
34926 }
34927diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34928index 3497f14..cc73b92 100644
34929--- a/arch/x86/realmode/rm/Makefile
34930+++ b/arch/x86/realmode/rm/Makefile
34931@@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
34932
34933 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
34934 -I$(srctree)/arch/x86/boot
34935+ifdef CONSTIFY_PLUGIN
34936+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34937+endif
34938 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34939 GCOV_PROFILE := n
34940diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34941index a28221d..93c40f1 100644
34942--- a/arch/x86/realmode/rm/header.S
34943+++ b/arch/x86/realmode/rm/header.S
34944@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34945 #endif
34946 /* APM/BIOS reboot */
34947 .long pa_machine_real_restart_asm
34948-#ifdef CONFIG_X86_64
34949+#ifdef CONFIG_X86_32
34950+ .long __KERNEL_CS
34951+#else
34952 .long __KERNEL32_CS
34953 #endif
34954 END(real_mode_header)
34955diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34956index 48ddd76..c26749f 100644
34957--- a/arch/x86/realmode/rm/trampoline_32.S
34958+++ b/arch/x86/realmode/rm/trampoline_32.S
34959@@ -24,6 +24,12 @@
34960 #include <asm/page_types.h>
34961 #include "realmode.h"
34962
34963+#ifdef CONFIG_PAX_KERNEXEC
34964+#define ta(X) (X)
34965+#else
34966+#define ta(X) (pa_ ## X)
34967+#endif
34968+
34969 .text
34970 .code16
34971
34972@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
34973
34974 cli # We should be safe anyway
34975
34976- movl tr_start, %eax # where we need to go
34977-
34978 movl $0xA5A5A5A5, trampoline_status
34979 # write marker for master knows we're running
34980
34981@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
34982 movw $1, %dx # protected mode (PE) bit
34983 lmsw %dx # into protected mode
34984
34985- ljmpl $__BOOT_CS, $pa_startup_32
34986+ ljmpl *(trampoline_header)
34987
34988 .section ".text32","ax"
34989 .code32
34990@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34991 .balign 8
34992 GLOBAL(trampoline_header)
34993 tr_start: .space 4
34994- tr_gdt_pad: .space 2
34995+ tr_boot_cs: .space 2
34996 tr_gdt: .space 6
34997 END(trampoline_header)
34998
34999diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35000index dac7b20..72dbaca 100644
35001--- a/arch/x86/realmode/rm/trampoline_64.S
35002+++ b/arch/x86/realmode/rm/trampoline_64.S
35003@@ -93,6 +93,7 @@ ENTRY(startup_32)
35004 movl %edx, %gs
35005
35006 movl pa_tr_cr4, %eax
35007+ andl $~X86_CR4_PCIDE, %eax
35008 movl %eax, %cr4 # Enable PAE mode
35009
35010 # Setup trampoline 4 level pagetables
35011@@ -106,7 +107,7 @@ ENTRY(startup_32)
35012 wrmsr
35013
35014 # Enable paging and in turn activate Long Mode
35015- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35016+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
35017 movl %eax, %cr0
35018
35019 /*
35020diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35021index 9e7e147..25a4158 100644
35022--- a/arch/x86/realmode/rm/wakeup_asm.S
35023+++ b/arch/x86/realmode/rm/wakeup_asm.S
35024@@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35025 lgdtl pmode_gdt
35026
35027 /* This really couldn't... */
35028- movl pmode_entry, %eax
35029 movl pmode_cr0, %ecx
35030 movl %ecx, %cr0
35031- ljmpl $__KERNEL_CS, $pa_startup_32
35032- /* -> jmp *%eax in trampoline_32.S */
35033+
35034+ ljmpl *pmode_entry
35035 #else
35036 jmp trampoline_start
35037 #endif
35038diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35039index 604a37e..e49702a 100644
35040--- a/arch/x86/tools/Makefile
35041+++ b/arch/x86/tools/Makefile
35042@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35043
35044 $(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
35045
35046-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35047+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35048 hostprogs-y += relocs
35049 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35050 PHONY += relocs
35051diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35052index bbb1d22..e505211 100644
35053--- a/arch/x86/tools/relocs.c
35054+++ b/arch/x86/tools/relocs.c
35055@@ -1,5 +1,7 @@
35056 /* This is included from relocs_32/64.c */
35057
35058+#include "../../../include/generated/autoconf.h"
35059+
35060 #define ElfW(type) _ElfW(ELF_BITS, type)
35061 #define _ElfW(bits, type) __ElfW(bits, type)
35062 #define __ElfW(bits, type) Elf##bits##_##type
35063@@ -11,6 +13,7 @@
35064 #define Elf_Sym ElfW(Sym)
35065
35066 static Elf_Ehdr ehdr;
35067+static Elf_Phdr *phdr;
35068
35069 struct relocs {
35070 uint32_t *offset;
35071@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35072 }
35073 }
35074
35075+static void read_phdrs(FILE *fp)
35076+{
35077+ unsigned int i;
35078+
35079+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35080+ if (!phdr) {
35081+ die("Unable to allocate %d program headers\n",
35082+ ehdr.e_phnum);
35083+ }
35084+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35085+ die("Seek to %d failed: %s\n",
35086+ ehdr.e_phoff, strerror(errno));
35087+ }
35088+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35089+ die("Cannot read ELF program headers: %s\n",
35090+ strerror(errno));
35091+ }
35092+ for(i = 0; i < ehdr.e_phnum; i++) {
35093+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35094+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35095+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35096+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35097+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35098+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35099+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35100+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35101+ }
35102+
35103+}
35104+
35105 static void read_shdrs(FILE *fp)
35106 {
35107- int i;
35108+ unsigned int i;
35109 Elf_Shdr shdr;
35110
35111 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35112@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35113
35114 static void read_strtabs(FILE *fp)
35115 {
35116- int i;
35117+ unsigned int i;
35118 for (i = 0; i < ehdr.e_shnum; i++) {
35119 struct section *sec = &secs[i];
35120 if (sec->shdr.sh_type != SHT_STRTAB) {
35121@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35122
35123 static void read_symtabs(FILE *fp)
35124 {
35125- int i,j;
35126+ unsigned int i,j;
35127 for (i = 0; i < ehdr.e_shnum; i++) {
35128 struct section *sec = &secs[i];
35129 if (sec->shdr.sh_type != SHT_SYMTAB) {
35130@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35131 }
35132
35133
35134-static void read_relocs(FILE *fp)
35135+static void read_relocs(FILE *fp, int use_real_mode)
35136 {
35137- int i,j;
35138+ unsigned int i,j;
35139+ uint32_t base;
35140+
35141 for (i = 0; i < ehdr.e_shnum; i++) {
35142 struct section *sec = &secs[i];
35143 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35144@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35145 die("Cannot read symbol table: %s\n",
35146 strerror(errno));
35147 }
35148+ base = 0;
35149+
35150+#ifdef CONFIG_X86_32
35151+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35152+ if (phdr[j].p_type != PT_LOAD )
35153+ continue;
35154+ 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)
35155+ continue;
35156+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35157+ break;
35158+ }
35159+#endif
35160+
35161 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35162 Elf_Rel *rel = &sec->reltab[j];
35163- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35164+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35165 rel->r_info = elf_xword_to_cpu(rel->r_info);
35166 #if (SHT_REL_TYPE == SHT_RELA)
35167 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35168@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35169
35170 static void print_absolute_symbols(void)
35171 {
35172- int i;
35173+ unsigned int i;
35174 const char *format;
35175
35176 if (ELF_BITS == 64)
35177@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35178 for (i = 0; i < ehdr.e_shnum; i++) {
35179 struct section *sec = &secs[i];
35180 char *sym_strtab;
35181- int j;
35182+ unsigned int j;
35183
35184 if (sec->shdr.sh_type != SHT_SYMTAB) {
35185 continue;
35186@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35187
35188 static void print_absolute_relocs(void)
35189 {
35190- int i, printed = 0;
35191+ unsigned int i, printed = 0;
35192 const char *format;
35193
35194 if (ELF_BITS == 64)
35195@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35196 struct section *sec_applies, *sec_symtab;
35197 char *sym_strtab;
35198 Elf_Sym *sh_symtab;
35199- int j;
35200+ unsigned int j;
35201 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35202 continue;
35203 }
35204@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35205 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35206 Elf_Sym *sym, const char *symname))
35207 {
35208- int i;
35209+ unsigned int i;
35210 /* Walk through the relocations */
35211 for (i = 0; i < ehdr.e_shnum; i++) {
35212 char *sym_strtab;
35213 Elf_Sym *sh_symtab;
35214 struct section *sec_applies, *sec_symtab;
35215- int j;
35216+ unsigned int j;
35217 struct section *sec = &secs[i];
35218
35219 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35220@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35221 {
35222 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35223 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35224+ char *sym_strtab = sec->link->link->strtab;
35225+
35226+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35227+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35228+ return 0;
35229+
35230+#ifdef CONFIG_PAX_KERNEXEC
35231+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35232+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35233+ return 0;
35234+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35235+ return 0;
35236+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35237+ return 0;
35238+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35239+ return 0;
35240+#endif
35241
35242 switch (r_type) {
35243 case R_386_NONE:
35244@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35245
35246 static void emit_relocs(int as_text, int use_real_mode)
35247 {
35248- int i;
35249+ unsigned int i;
35250 int (*write_reloc)(uint32_t, FILE *) = write32;
35251 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35252 const char *symname);
35253@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35254 {
35255 regex_init(use_real_mode);
35256 read_ehdr(fp);
35257+ read_phdrs(fp);
35258 read_shdrs(fp);
35259 read_strtabs(fp);
35260 read_symtabs(fp);
35261- read_relocs(fp);
35262+ read_relocs(fp, use_real_mode);
35263 if (ELF_BITS == 64)
35264 percpu_init();
35265 if (show_absolute_syms) {
35266diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35267index f40281e..92728c9 100644
35268--- a/arch/x86/um/mem_32.c
35269+++ b/arch/x86/um/mem_32.c
35270@@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35271 gate_vma.vm_start = FIXADDR_USER_START;
35272 gate_vma.vm_end = FIXADDR_USER_END;
35273 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35274- gate_vma.vm_page_prot = __P101;
35275+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35276
35277 return 0;
35278 }
35279diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35280index 80ffa5b..a33bd15 100644
35281--- a/arch/x86/um/tls_32.c
35282+++ b/arch/x86/um/tls_32.c
35283@@ -260,7 +260,7 @@ out:
35284 if (unlikely(task == current &&
35285 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35286 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35287- "without flushed TLS.", current->pid);
35288+ "without flushed TLS.", task_pid_nr(current));
35289 }
35290
35291 return 0;
35292diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35293index c580d12..0a0ba35 100644
35294--- a/arch/x86/vdso/Makefile
35295+++ b/arch/x86/vdso/Makefile
35296@@ -196,7 +196,7 @@ quiet_cmd_vdso = VDSO $@
35297 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35298 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35299
35300-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35301+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35302 $(LTO_CFLAGS)
35303 GCOV_PROFILE := n
35304
35305diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35306index 310c5f0..766d0a7 100644
35307--- a/arch/x86/vdso/vdso32-setup.c
35308+++ b/arch/x86/vdso/vdso32-setup.c
35309@@ -29,6 +29,7 @@
35310 #include <asm/fixmap.h>
35311 #include <asm/hpet.h>
35312 #include <asm/vvar.h>
35313+#include <asm/mman.h>
35314
35315 #ifdef CONFIG_COMPAT_VDSO
35316 #define VDSO_DEFAULT 0
35317@@ -99,7 +100,7 @@ void syscall32_cpu_init(void)
35318 void enable_sep_cpu(void)
35319 {
35320 int cpu = get_cpu();
35321- struct tss_struct *tss = &per_cpu(init_tss, cpu);
35322+ struct tss_struct *tss = init_tss + cpu;
35323
35324 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35325 put_cpu();
35326@@ -167,7 +168,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35327
35328 down_write(&mm->mmap_sem);
35329
35330- addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, 0);
35331+ addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, MAP_EXECUTABLE);
35332 if (IS_ERR_VALUE(addr)) {
35333 ret = addr;
35334 goto up_fail;
35335@@ -175,7 +176,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35336
35337 addr += VDSO_OFFSET(VDSO_PREV_PAGES);
35338
35339- current->mm->context.vdso = (void *)addr;
35340+ current->mm->context.vdso = addr;
35341
35342 /*
35343 * MAYWRITE to allow gdb to COW and set breakpoints
35344@@ -224,11 +225,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35345 #endif
35346
35347 current_thread_info()->sysenter_return =
35348- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35349+ (void __force_user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35350
35351 up_fail:
35352 if (ret)
35353- current->mm->context.vdso = NULL;
35354+ current->mm->context.vdso = 0;
35355
35356 up_write(&mm->mmap_sem);
35357
35358@@ -282,8 +283,14 @@ __initcall(ia32_binfmt_init);
35359
35360 const char *arch_vma_name(struct vm_area_struct *vma)
35361 {
35362- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35363+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35364 return "[vdso]";
35365+
35366+#ifdef CONFIG_PAX_SEGMEXEC
35367+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35368+ return "[vdso]";
35369+#endif
35370+
35371 return NULL;
35372 }
35373
35374diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35375index 1ad1026..1a08abe 100644
35376--- a/arch/x86/vdso/vma.c
35377+++ b/arch/x86/vdso/vma.c
35378@@ -17,8 +17,6 @@
35379 #include <asm/page.h>
35380
35381 #if defined(CONFIG_X86_64)
35382-unsigned int __read_mostly vdso_enabled = 1;
35383-
35384 DECLARE_VDSO_IMAGE(vdso);
35385 extern unsigned short vdso_sync_cpuid;
35386 static unsigned vdso_size;
35387@@ -144,7 +142,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35388 * unaligned here as a result of stack start randomization.
35389 */
35390 addr = PAGE_ALIGN(addr);
35391- addr = align_vdso_addr(addr);
35392
35393 return addr;
35394 }
35395@@ -157,30 +154,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35396 unsigned size)
35397 {
35398 struct mm_struct *mm = current->mm;
35399- unsigned long addr;
35400+ unsigned long addr = 0;
35401 int ret;
35402
35403- if (!vdso_enabled)
35404- return 0;
35405-
35406 down_write(&mm->mmap_sem);
35407+
35408+#ifdef CONFIG_PAX_RANDMMAP
35409+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35410+#endif
35411+
35412 addr = vdso_addr(mm->start_stack, size);
35413+ addr = align_vdso_addr(addr);
35414 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35415 if (IS_ERR_VALUE(addr)) {
35416 ret = addr;
35417 goto up_fail;
35418 }
35419
35420- current->mm->context.vdso = (void *)addr;
35421+ mm->context.vdso = addr;
35422
35423 ret = install_special_mapping(mm, addr, size,
35424 VM_READ|VM_EXEC|
35425 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35426 pages);
35427- if (ret) {
35428- current->mm->context.vdso = NULL;
35429- goto up_fail;
35430- }
35431+ if (ret)
35432+ mm->context.vdso = 0;
35433
35434 up_fail:
35435 up_write(&mm->mmap_sem);
35436@@ -200,11 +198,4 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35437 vdsox32_size);
35438 }
35439 #endif
35440-
35441-static __init int vdso_setup(char *s)
35442-{
35443- vdso_enabled = simple_strtoul(s, NULL, 0);
35444- return 0;
35445-}
35446-__setup("vdso=", vdso_setup);
35447 #endif
35448diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35449index e88fda8..76ce7ce 100644
35450--- a/arch/x86/xen/Kconfig
35451+++ b/arch/x86/xen/Kconfig
35452@@ -9,6 +9,7 @@ config XEN
35453 select XEN_HAVE_PVMMU
35454 depends on X86_64 || (X86_32 && X86_PAE)
35455 depends on X86_TSC
35456+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35457 help
35458 This is the Linux Xen port. Enabling this will allow the
35459 kernel to boot in a paravirtualized environment under the
35460diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35461index c34bfc4..e599673 100644
35462--- a/arch/x86/xen/enlighten.c
35463+++ b/arch/x86/xen/enlighten.c
35464@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35465
35466 struct shared_info xen_dummy_shared_info;
35467
35468-void *xen_initial_gdt;
35469-
35470 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35471 __read_mostly int xen_have_vector_callback;
35472 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35473@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35474 {
35475 unsigned long va = dtr->address;
35476 unsigned int size = dtr->size + 1;
35477- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35478- unsigned long frames[pages];
35479+ unsigned long frames[65536 / PAGE_SIZE];
35480 int f;
35481
35482 /*
35483@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35484 {
35485 unsigned long va = dtr->address;
35486 unsigned int size = dtr->size + 1;
35487- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35488- unsigned long frames[pages];
35489+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35490 int f;
35491
35492 /*
35493@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35494 * 8-byte entries, or 16 4k pages..
35495 */
35496
35497- BUG_ON(size > 65536);
35498+ BUG_ON(size > GDT_SIZE);
35499 BUG_ON(va & ~PAGE_MASK);
35500
35501 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35502@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35503 return 0;
35504 }
35505
35506-static void set_xen_basic_apic_ops(void)
35507+static void __init set_xen_basic_apic_ops(void)
35508 {
35509 apic->read = xen_apic_read;
35510 apic->write = xen_apic_write;
35511@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35512 #endif
35513 };
35514
35515-static void xen_reboot(int reason)
35516+static __noreturn void xen_reboot(int reason)
35517 {
35518 struct sched_shutdown r = { .reason = reason };
35519
35520- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35521- BUG();
35522+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35523+ BUG();
35524 }
35525
35526-static void xen_restart(char *msg)
35527+static __noreturn void xen_restart(char *msg)
35528 {
35529 xen_reboot(SHUTDOWN_reboot);
35530 }
35531
35532-static void xen_emergency_restart(void)
35533+static __noreturn void xen_emergency_restart(void)
35534 {
35535 xen_reboot(SHUTDOWN_reboot);
35536 }
35537
35538-static void xen_machine_halt(void)
35539+static __noreturn void xen_machine_halt(void)
35540 {
35541 xen_reboot(SHUTDOWN_poweroff);
35542 }
35543
35544-static void xen_machine_power_off(void)
35545+static __noreturn void xen_machine_power_off(void)
35546 {
35547 if (pm_power_off)
35548 pm_power_off();
35549@@ -1564,7 +1560,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35550 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35551
35552 /* Work out if we support NX */
35553- x86_configure_nx();
35554+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35555+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35556+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35557+ unsigned l, h;
35558+
35559+ __supported_pte_mask |= _PAGE_NX;
35560+ rdmsr(MSR_EFER, l, h);
35561+ l |= EFER_NX;
35562+ wrmsr(MSR_EFER, l, h);
35563+ }
35564+#endif
35565
35566 /* Get mfn list */
35567 xen_build_dynamic_phys_to_machine();
35568@@ -1592,13 +1598,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35569
35570 machine_ops = xen_machine_ops;
35571
35572- /*
35573- * The only reliable way to retain the initial address of the
35574- * percpu gdt_page is to remember it here, so we can go and
35575- * mark it RW later, when the initial percpu area is freed.
35576- */
35577- xen_initial_gdt = &per_cpu(gdt_page, 0);
35578-
35579 xen_smp_init();
35580
35581 #ifdef CONFIG_ACPI_NUMA
35582diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35583index 86e02ea..e3705ca 100644
35584--- a/arch/x86/xen/mmu.c
35585+++ b/arch/x86/xen/mmu.c
35586@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35587 return val;
35588 }
35589
35590-static pteval_t pte_pfn_to_mfn(pteval_t val)
35591+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35592 {
35593 if (val & _PAGE_PRESENT) {
35594 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35595@@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35596 /* L3_k[510] -> level2_kernel_pgt
35597 * L3_i[511] -> level2_fixmap_pgt */
35598 convert_pfn_mfn(level3_kernel_pgt);
35599+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35600+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35601+ convert_pfn_mfn(level3_vmemmap_pgt);
35602 }
35603 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35604 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35605@@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35606 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35607 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35608 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35609+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35610+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35611+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35612 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35613 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35614+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35615 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35616 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35617
35618@@ -2122,6 +2129,7 @@ static void __init xen_post_allocator_init(void)
35619 pv_mmu_ops.set_pud = xen_set_pud;
35620 #if PAGETABLE_LEVELS == 4
35621 pv_mmu_ops.set_pgd = xen_set_pgd;
35622+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35623 #endif
35624
35625 /* This will work as long as patching hasn't happened yet
35626@@ -2200,6 +2208,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35627 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35628 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35629 .set_pgd = xen_set_pgd_hyper,
35630+ .set_pgd_batched = xen_set_pgd_hyper,
35631
35632 .alloc_pud = xen_alloc_pmd_init,
35633 .release_pud = xen_release_pmd_init,
35634diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35635index 7005974..54fb05f 100644
35636--- a/arch/x86/xen/smp.c
35637+++ b/arch/x86/xen/smp.c
35638@@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35639
35640 if (xen_pv_domain()) {
35641 if (!xen_feature(XENFEAT_writable_page_tables))
35642- /* We've switched to the "real" per-cpu gdt, so make
35643- * sure the old memory can be recycled. */
35644- make_lowmem_page_readwrite(xen_initial_gdt);
35645-
35646 #ifdef CONFIG_X86_32
35647 /*
35648 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35649 * expects __USER_DS
35650 */
35651- loadsegment(ds, __USER_DS);
35652- loadsegment(es, __USER_DS);
35653+ loadsegment(ds, __KERNEL_DS);
35654+ loadsegment(es, __KERNEL_DS);
35655 #endif
35656
35657 xen_filter_cpu_maps();
35658@@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35659 #ifdef CONFIG_X86_32
35660 /* Note: PVH is not yet supported on x86_32. */
35661 ctxt->user_regs.fs = __KERNEL_PERCPU;
35662- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35663+ savesegment(gs, ctxt->user_regs.gs);
35664 #endif
35665 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35666
35667@@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35668 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35669 ctxt->flags = VGCF_IN_KERNEL;
35670 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35671- ctxt->user_regs.ds = __USER_DS;
35672- ctxt->user_regs.es = __USER_DS;
35673+ ctxt->user_regs.ds = __KERNEL_DS;
35674+ ctxt->user_regs.es = __KERNEL_DS;
35675 ctxt->user_regs.ss = __KERNEL_DS;
35676
35677 xen_copy_trap_info(ctxt->trap_ctxt);
35678@@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35679 int rc;
35680
35681 per_cpu(current_task, cpu) = idle;
35682+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35683 #ifdef CONFIG_X86_32
35684 irq_ctx_init(cpu);
35685 #else
35686 clear_tsk_thread_flag(idle, TIF_FORK);
35687 #endif
35688- per_cpu(kernel_stack, cpu) =
35689- (unsigned long)task_stack_page(idle) -
35690- KERNEL_STACK_OFFSET + THREAD_SIZE;
35691+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35692
35693 xen_setup_runstate_info(cpu);
35694 xen_setup_timer(cpu);
35695@@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35696
35697 void __init xen_smp_init(void)
35698 {
35699- smp_ops = xen_smp_ops;
35700+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35701 xen_fill_possible_map();
35702 }
35703
35704diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35705index fd92a64..1f72641 100644
35706--- a/arch/x86/xen/xen-asm_32.S
35707+++ b/arch/x86/xen/xen-asm_32.S
35708@@ -99,7 +99,7 @@ ENTRY(xen_iret)
35709 pushw %fs
35710 movl $(__KERNEL_PERCPU), %eax
35711 movl %eax, %fs
35712- movl %fs:xen_vcpu, %eax
35713+ mov PER_CPU_VAR(xen_vcpu), %eax
35714 POP_FS
35715 #else
35716 movl %ss:xen_vcpu, %eax
35717diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35718index 485b695..fda3e7c 100644
35719--- a/arch/x86/xen/xen-head.S
35720+++ b/arch/x86/xen/xen-head.S
35721@@ -39,6 +39,17 @@ ENTRY(startup_xen)
35722 #ifdef CONFIG_X86_32
35723 mov %esi,xen_start_info
35724 mov $init_thread_union+THREAD_SIZE,%esp
35725+#ifdef CONFIG_SMP
35726+ movl $cpu_gdt_table,%edi
35727+ movl $__per_cpu_load,%eax
35728+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35729+ rorl $16,%eax
35730+ movb %al,__KERNEL_PERCPU + 4(%edi)
35731+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35732+ movl $__per_cpu_end - 1,%eax
35733+ subl $__per_cpu_start,%eax
35734+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35735+#endif
35736 #else
35737 mov %rsi,xen_start_info
35738 mov $init_thread_union+THREAD_SIZE,%rsp
35739diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35740index 1cb6f4c..9981524 100644
35741--- a/arch/x86/xen/xen-ops.h
35742+++ b/arch/x86/xen/xen-ops.h
35743@@ -10,8 +10,6 @@
35744 extern const char xen_hypervisor_callback[];
35745 extern const char xen_failsafe_callback[];
35746
35747-extern void *xen_initial_gdt;
35748-
35749 struct trap_info;
35750 void xen_copy_trap_info(struct trap_info *traps);
35751
35752diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35753index 525bd3d..ef888b1 100644
35754--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35755+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35756@@ -119,9 +119,9 @@
35757 ----------------------------------------------------------------------*/
35758
35759 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35760-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35761 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35762 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35763+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35764
35765 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35766 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35767diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35768index 2f33760..835e50a 100644
35769--- a/arch/xtensa/variants/fsf/include/variant/core.h
35770+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35771@@ -11,6 +11,7 @@
35772 #ifndef _XTENSA_CORE_H
35773 #define _XTENSA_CORE_H
35774
35775+#include <linux/const.h>
35776
35777 /****************************************************************************
35778 Parameters Useful for Any Code, USER or PRIVILEGED
35779@@ -112,9 +113,9 @@
35780 ----------------------------------------------------------------------*/
35781
35782 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35783-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35784 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35785 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35786+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35787
35788 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35789 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35790diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35791index af00795..2bb8105 100644
35792--- a/arch/xtensa/variants/s6000/include/variant/core.h
35793+++ b/arch/xtensa/variants/s6000/include/variant/core.h
35794@@ -11,6 +11,7 @@
35795 #ifndef _XTENSA_CORE_CONFIGURATION_H
35796 #define _XTENSA_CORE_CONFIGURATION_H
35797
35798+#include <linux/const.h>
35799
35800 /****************************************************************************
35801 Parameters Useful for Any Code, USER or PRIVILEGED
35802@@ -118,9 +119,9 @@
35803 ----------------------------------------------------------------------*/
35804
35805 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35806-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35807 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35808 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35809+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35810
35811 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35812 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35813diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35814index 1039fb9..d7c0d9a 100644
35815--- a/block/blk-cgroup.c
35816+++ b/block/blk-cgroup.c
35817@@ -825,7 +825,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35818 static struct cgroup_subsys_state *
35819 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35820 {
35821- static atomic64_t id_seq = ATOMIC64_INIT(0);
35822+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35823 struct blkcg *blkcg;
35824
35825 if (!parent_css) {
35826@@ -839,7 +839,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35827
35828 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35829 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35830- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35831+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35832 done:
35833 spin_lock_init(&blkcg->lock);
35834 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35835diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35836index c11d24e..e915d24 100644
35837--- a/block/blk-iopoll.c
35838+++ b/block/blk-iopoll.c
35839@@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35840 }
35841 EXPORT_SYMBOL(blk_iopoll_complete);
35842
35843-static void blk_iopoll_softirq(struct softirq_action *h)
35844+static __latent_entropy void blk_iopoll_softirq(void)
35845 {
35846 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35847 int rearm = 0, budget = blk_iopoll_budget;
35848diff --git a/block/blk-map.c b/block/blk-map.c
35849index f7b22bc..ec2ddf4 100644
35850--- a/block/blk-map.c
35851+++ b/block/blk-map.c
35852@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35853 if (!len || !kbuf)
35854 return -EINVAL;
35855
35856- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35857+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35858 if (do_copy)
35859 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35860 else
35861diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35862index 53b1737..08177d2e 100644
35863--- a/block/blk-softirq.c
35864+++ b/block/blk-softirq.c
35865@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35866 * Softirq action handler - move entries to local list and loop over them
35867 * while passing them to the queue registered handler.
35868 */
35869-static void blk_done_softirq(struct softirq_action *h)
35870+static __latent_entropy void blk_done_softirq(void)
35871 {
35872 struct list_head *cpu_list, local_list;
35873
35874diff --git a/block/bsg.c b/block/bsg.c
35875index 420a5a9..23834aa 100644
35876--- a/block/bsg.c
35877+++ b/block/bsg.c
35878@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35879 struct sg_io_v4 *hdr, struct bsg_device *bd,
35880 fmode_t has_write_perm)
35881 {
35882+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35883+ unsigned char *cmdptr;
35884+
35885 if (hdr->request_len > BLK_MAX_CDB) {
35886 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35887 if (!rq->cmd)
35888 return -ENOMEM;
35889- }
35890+ cmdptr = rq->cmd;
35891+ } else
35892+ cmdptr = tmpcmd;
35893
35894- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35895+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35896 hdr->request_len))
35897 return -EFAULT;
35898
35899+ if (cmdptr != rq->cmd)
35900+ memcpy(rq->cmd, cmdptr, hdr->request_len);
35901+
35902 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35903 if (blk_verify_command(rq->cmd, has_write_perm))
35904 return -EPERM;
35905diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35906index fbd5a67..f24fd95 100644
35907--- a/block/compat_ioctl.c
35908+++ b/block/compat_ioctl.c
35909@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35910 cgc = compat_alloc_user_space(sizeof(*cgc));
35911 cgc32 = compat_ptr(arg);
35912
35913- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35914+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35915 get_user(data, &cgc32->buffer) ||
35916 put_user(compat_ptr(data), &cgc->buffer) ||
35917 copy_in_user(&cgc->buflen, &cgc32->buflen,
35918@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35919 err |= __get_user(f->spec1, &uf->spec1);
35920 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35921 err |= __get_user(name, &uf->name);
35922- f->name = compat_ptr(name);
35923+ f->name = (void __force_kernel *)compat_ptr(name);
35924 if (err) {
35925 err = -EFAULT;
35926 goto out;
35927diff --git a/block/genhd.c b/block/genhd.c
35928index 791f419..89f21c4 100644
35929--- a/block/genhd.c
35930+++ b/block/genhd.c
35931@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35932
35933 /*
35934 * Register device numbers dev..(dev+range-1)
35935- * range must be nonzero
35936+ * Noop if @range is zero.
35937 * The hash chain is sorted on range, so that subranges can override.
35938 */
35939 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35940 struct kobject *(*probe)(dev_t, int *, void *),
35941 int (*lock)(dev_t, void *), void *data)
35942 {
35943- kobj_map(bdev_map, devt, range, module, probe, lock, data);
35944+ if (range)
35945+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
35946 }
35947
35948 EXPORT_SYMBOL(blk_register_region);
35949
35950+/* undo blk_register_region(), noop if @range is zero */
35951 void blk_unregister_region(dev_t devt, unsigned long range)
35952 {
35953- kobj_unmap(bdev_map, devt, range);
35954+ if (range)
35955+ kobj_unmap(bdev_map, devt, range);
35956 }
35957
35958 EXPORT_SYMBOL(blk_unregister_region);
35959diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35960index dc51f46..d5446a8 100644
35961--- a/block/partitions/efi.c
35962+++ b/block/partitions/efi.c
35963@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35964 if (!gpt)
35965 return NULL;
35966
35967+ if (!le32_to_cpu(gpt->num_partition_entries))
35968+ return NULL;
35969+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35970+ if (!pte)
35971+ return NULL;
35972+
35973 count = le32_to_cpu(gpt->num_partition_entries) *
35974 le32_to_cpu(gpt->sizeof_partition_entry);
35975- if (!count)
35976- return NULL;
35977- pte = kmalloc(count, GFP_KERNEL);
35978- if (!pte)
35979- return NULL;
35980-
35981 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35982 (u8 *) pte, count) < count) {
35983 kfree(pte);
35984diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35985index 2648797..92ed21f 100644
35986--- a/block/scsi_ioctl.c
35987+++ b/block/scsi_ioctl.c
35988@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35989 return put_user(0, p);
35990 }
35991
35992-static int sg_get_timeout(struct request_queue *q)
35993+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35994 {
35995 return jiffies_to_clock_t(q->sg_timeout);
35996 }
35997@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35998 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35999 struct sg_io_hdr *hdr, fmode_t mode)
36000 {
36001- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36002+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36003+ unsigned char *cmdptr;
36004+
36005+ if (rq->cmd != rq->__cmd)
36006+ cmdptr = rq->cmd;
36007+ else
36008+ cmdptr = tmpcmd;
36009+
36010+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36011 return -EFAULT;
36012+
36013+ if (cmdptr != rq->cmd)
36014+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36015+
36016 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36017 return -EPERM;
36018
36019@@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36020 int err;
36021 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36022 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36023+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36024+ unsigned char *cmdptr;
36025
36026 if (!sic)
36027 return -EINVAL;
36028@@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36029 */
36030 err = -EFAULT;
36031 rq->cmd_len = cmdlen;
36032- if (copy_from_user(rq->cmd, sic->data, cmdlen))
36033+
36034+ if (rq->cmd != rq->__cmd)
36035+ cmdptr = rq->cmd;
36036+ else
36037+ cmdptr = tmpcmd;
36038+
36039+ if (copy_from_user(cmdptr, sic->data, cmdlen))
36040 goto error;
36041
36042+ if (rq->cmd != cmdptr)
36043+ memcpy(rq->cmd, cmdptr, cmdlen);
36044+
36045 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36046 goto error;
36047
36048diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36049index 7bdd61b..afec999 100644
36050--- a/crypto/cryptd.c
36051+++ b/crypto/cryptd.c
36052@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36053
36054 struct cryptd_blkcipher_request_ctx {
36055 crypto_completion_t complete;
36056-};
36057+} __no_const;
36058
36059 struct cryptd_hash_ctx {
36060 struct crypto_shash *child;
36061@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36062
36063 struct cryptd_aead_request_ctx {
36064 crypto_completion_t complete;
36065-};
36066+} __no_const;
36067
36068 static void cryptd_queue_worker(struct work_struct *work);
36069
36070diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36071index 309d345..1632720 100644
36072--- a/crypto/pcrypt.c
36073+++ b/crypto/pcrypt.c
36074@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36075 int ret;
36076
36077 pinst->kobj.kset = pcrypt_kset;
36078- ret = kobject_add(&pinst->kobj, NULL, name);
36079+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36080 if (!ret)
36081 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36082
36083diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36084index 6921c7f..78e1af7 100644
36085--- a/drivers/acpi/acpica/hwxfsleep.c
36086+++ b/drivers/acpi/acpica/hwxfsleep.c
36087@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36088 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36089
36090 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36091- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36092- acpi_hw_extended_sleep},
36093- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36094- acpi_hw_extended_wake_prep},
36095- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36096+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36097+ .extended_function = acpi_hw_extended_sleep},
36098+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36099+ .extended_function = acpi_hw_extended_wake_prep},
36100+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36101+ .extended_function = acpi_hw_extended_wake}
36102 };
36103
36104 /*
36105diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36106index e5bcd91..74f050d 100644
36107--- a/drivers/acpi/apei/apei-internal.h
36108+++ b/drivers/acpi/apei/apei-internal.h
36109@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36110 struct apei_exec_ins_type {
36111 u32 flags;
36112 apei_exec_ins_func_t run;
36113-};
36114+} __do_const;
36115
36116 struct apei_exec_context {
36117 u32 ip;
36118diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36119index dab7cb7..f0d2994 100644
36120--- a/drivers/acpi/apei/ghes.c
36121+++ b/drivers/acpi/apei/ghes.c
36122@@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
36123 const struct acpi_hest_generic *generic,
36124 const struct acpi_generic_status *estatus)
36125 {
36126- static atomic_t seqno;
36127+ static atomic_unchecked_t seqno;
36128 unsigned int curr_seqno;
36129 char pfx_seq[64];
36130
36131@@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
36132 else
36133 pfx = KERN_ERR;
36134 }
36135- curr_seqno = atomic_inc_return(&seqno);
36136+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36137 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36138 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36139 pfx_seq, generic->header.source_id);
36140diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36141index a83e3c6..c3d617f 100644
36142--- a/drivers/acpi/bgrt.c
36143+++ b/drivers/acpi/bgrt.c
36144@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36145 if (!bgrt_image)
36146 return -ENODEV;
36147
36148- bin_attr_image.private = bgrt_image;
36149- bin_attr_image.size = bgrt_image_size;
36150+ pax_open_kernel();
36151+ *(void **)&bin_attr_image.private = bgrt_image;
36152+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36153+ pax_close_kernel();
36154
36155 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36156 if (!bgrt_kobj)
36157diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36158index 3d8413d..95f638c 100644
36159--- a/drivers/acpi/blacklist.c
36160+++ b/drivers/acpi/blacklist.c
36161@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36162 u32 is_critical_error;
36163 };
36164
36165-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36166+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36167
36168 /*
36169 * POLICY: If *anything* doesn't work, put it on the blacklist.
36170@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36171 return 0;
36172 }
36173
36174-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36175+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36176 {
36177 .callback = dmi_disable_osi_vista,
36178 .ident = "Fujitsu Siemens",
36179diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36180index c68e724..e863008 100644
36181--- a/drivers/acpi/custom_method.c
36182+++ b/drivers/acpi/custom_method.c
36183@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36184 struct acpi_table_header table;
36185 acpi_status status;
36186
36187+#ifdef CONFIG_GRKERNSEC_KMEM
36188+ return -EPERM;
36189+#endif
36190+
36191 if (!(*ppos)) {
36192 /* parse the table header to get the table length */
36193 if (count <= sizeof(struct acpi_table_header))
36194diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36195index 3dca36d..abaf070 100644
36196--- a/drivers/acpi/processor_idle.c
36197+++ b/drivers/acpi/processor_idle.c
36198@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36199 {
36200 int i, count = CPUIDLE_DRIVER_STATE_START;
36201 struct acpi_processor_cx *cx;
36202- struct cpuidle_state *state;
36203+ cpuidle_state_no_const *state;
36204 struct cpuidle_driver *drv = &acpi_idle_driver;
36205
36206 if (!pr->flags.power_setup_done)
36207diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36208index 38cb978..352c761 100644
36209--- a/drivers/acpi/sysfs.c
36210+++ b/drivers/acpi/sysfs.c
36211@@ -423,11 +423,11 @@ static u32 num_counters;
36212 static struct attribute **all_attrs;
36213 static u32 acpi_gpe_count;
36214
36215-static struct attribute_group interrupt_stats_attr_group = {
36216+static attribute_group_no_const interrupt_stats_attr_group = {
36217 .name = "interrupts",
36218 };
36219
36220-static struct kobj_attribute *counter_attrs;
36221+static kobj_attribute_no_const *counter_attrs;
36222
36223 static void delete_gpe_attr_array(void)
36224 {
36225diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36226index b986145..82bddb8 100644
36227--- a/drivers/ata/libahci.c
36228+++ b/drivers/ata/libahci.c
36229@@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36230 }
36231 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36232
36233-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36234+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36235 struct ata_taskfile *tf, int is_cmd, u16 flags,
36236 unsigned long timeout_msec)
36237 {
36238diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36239index 18d97d5..be690af 100644
36240--- a/drivers/ata/libata-core.c
36241+++ b/drivers/ata/libata-core.c
36242@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36243 static void ata_dev_xfermask(struct ata_device *dev);
36244 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36245
36246-atomic_t ata_print_id = ATOMIC_INIT(0);
36247+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36248
36249 struct ata_force_param {
36250 const char *name;
36251@@ -4858,7 +4858,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36252 struct ata_port *ap;
36253 unsigned int tag;
36254
36255- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36256+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36257 ap = qc->ap;
36258
36259 qc->flags = 0;
36260@@ -4874,7 +4874,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36261 struct ata_port *ap;
36262 struct ata_link *link;
36263
36264- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36265+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36266 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36267 ap = qc->ap;
36268 link = qc->dev->link;
36269@@ -5978,6 +5978,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36270 return;
36271
36272 spin_lock(&lock);
36273+ pax_open_kernel();
36274
36275 for (cur = ops->inherits; cur; cur = cur->inherits) {
36276 void **inherit = (void **)cur;
36277@@ -5991,8 +5992,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36278 if (IS_ERR(*pp))
36279 *pp = NULL;
36280
36281- ops->inherits = NULL;
36282+ *(struct ata_port_operations **)&ops->inherits = NULL;
36283
36284+ pax_close_kernel();
36285 spin_unlock(&lock);
36286 }
36287
36288@@ -6185,7 +6187,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36289
36290 /* give ports names and add SCSI hosts */
36291 for (i = 0; i < host->n_ports; i++) {
36292- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36293+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36294 host->ports[i]->local_port_no = i + 1;
36295 }
36296
36297diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36298index ef8567d..8bdbd03 100644
36299--- a/drivers/ata/libata-scsi.c
36300+++ b/drivers/ata/libata-scsi.c
36301@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36302
36303 if (rc)
36304 return rc;
36305- ap->print_id = atomic_inc_return(&ata_print_id);
36306+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36307 return 0;
36308 }
36309 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36310diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36311index 45b5ab3..98446b8 100644
36312--- a/drivers/ata/libata.h
36313+++ b/drivers/ata/libata.h
36314@@ -53,7 +53,7 @@ enum {
36315 ATA_DNXFER_QUIET = (1 << 31),
36316 };
36317
36318-extern atomic_t ata_print_id;
36319+extern atomic_unchecked_t ata_print_id;
36320 extern int atapi_passthru16;
36321 extern int libata_fua;
36322 extern int libata_noacpi;
36323diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36324index 4edb1a8..84e1658 100644
36325--- a/drivers/ata/pata_arasan_cf.c
36326+++ b/drivers/ata/pata_arasan_cf.c
36327@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36328 /* Handle platform specific quirks */
36329 if (quirk) {
36330 if (quirk & CF_BROKEN_PIO) {
36331- ap->ops->set_piomode = NULL;
36332+ pax_open_kernel();
36333+ *(void **)&ap->ops->set_piomode = NULL;
36334+ pax_close_kernel();
36335 ap->pio_mask = 0;
36336 }
36337 if (quirk & CF_BROKEN_MWDMA)
36338diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36339index f9b983a..887b9d8 100644
36340--- a/drivers/atm/adummy.c
36341+++ b/drivers/atm/adummy.c
36342@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36343 vcc->pop(vcc, skb);
36344 else
36345 dev_kfree_skb_any(skb);
36346- atomic_inc(&vcc->stats->tx);
36347+ atomic_inc_unchecked(&vcc->stats->tx);
36348
36349 return 0;
36350 }
36351diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36352index f1a9198..f466a4a 100644
36353--- a/drivers/atm/ambassador.c
36354+++ b/drivers/atm/ambassador.c
36355@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36356 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36357
36358 // VC layer stats
36359- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36360+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36361
36362 // free the descriptor
36363 kfree (tx_descr);
36364@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36365 dump_skb ("<<<", vc, skb);
36366
36367 // VC layer stats
36368- atomic_inc(&atm_vcc->stats->rx);
36369+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36370 __net_timestamp(skb);
36371 // end of our responsibility
36372 atm_vcc->push (atm_vcc, skb);
36373@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36374 } else {
36375 PRINTK (KERN_INFO, "dropped over-size frame");
36376 // should we count this?
36377- atomic_inc(&atm_vcc->stats->rx_drop);
36378+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36379 }
36380
36381 } else {
36382@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36383 }
36384
36385 if (check_area (skb->data, skb->len)) {
36386- atomic_inc(&atm_vcc->stats->tx_err);
36387+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36388 return -ENOMEM; // ?
36389 }
36390
36391diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36392index 0e3f8f9..765a7a5 100644
36393--- a/drivers/atm/atmtcp.c
36394+++ b/drivers/atm/atmtcp.c
36395@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36396 if (vcc->pop) vcc->pop(vcc,skb);
36397 else dev_kfree_skb(skb);
36398 if (dev_data) return 0;
36399- atomic_inc(&vcc->stats->tx_err);
36400+ atomic_inc_unchecked(&vcc->stats->tx_err);
36401 return -ENOLINK;
36402 }
36403 size = skb->len+sizeof(struct atmtcp_hdr);
36404@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36405 if (!new_skb) {
36406 if (vcc->pop) vcc->pop(vcc,skb);
36407 else dev_kfree_skb(skb);
36408- atomic_inc(&vcc->stats->tx_err);
36409+ atomic_inc_unchecked(&vcc->stats->tx_err);
36410 return -ENOBUFS;
36411 }
36412 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36413@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36414 if (vcc->pop) vcc->pop(vcc,skb);
36415 else dev_kfree_skb(skb);
36416 out_vcc->push(out_vcc,new_skb);
36417- atomic_inc(&vcc->stats->tx);
36418- atomic_inc(&out_vcc->stats->rx);
36419+ atomic_inc_unchecked(&vcc->stats->tx);
36420+ atomic_inc_unchecked(&out_vcc->stats->rx);
36421 return 0;
36422 }
36423
36424@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36425 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36426 read_unlock(&vcc_sklist_lock);
36427 if (!out_vcc) {
36428- atomic_inc(&vcc->stats->tx_err);
36429+ atomic_inc_unchecked(&vcc->stats->tx_err);
36430 goto done;
36431 }
36432 skb_pull(skb,sizeof(struct atmtcp_hdr));
36433@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36434 __net_timestamp(new_skb);
36435 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36436 out_vcc->push(out_vcc,new_skb);
36437- atomic_inc(&vcc->stats->tx);
36438- atomic_inc(&out_vcc->stats->rx);
36439+ atomic_inc_unchecked(&vcc->stats->tx);
36440+ atomic_inc_unchecked(&out_vcc->stats->rx);
36441 done:
36442 if (vcc->pop) vcc->pop(vcc,skb);
36443 else dev_kfree_skb(skb);
36444diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36445index b1955ba..b179940 100644
36446--- a/drivers/atm/eni.c
36447+++ b/drivers/atm/eni.c
36448@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36449 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36450 vcc->dev->number);
36451 length = 0;
36452- atomic_inc(&vcc->stats->rx_err);
36453+ atomic_inc_unchecked(&vcc->stats->rx_err);
36454 }
36455 else {
36456 length = ATM_CELL_SIZE-1; /* no HEC */
36457@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36458 size);
36459 }
36460 eff = length = 0;
36461- atomic_inc(&vcc->stats->rx_err);
36462+ atomic_inc_unchecked(&vcc->stats->rx_err);
36463 }
36464 else {
36465 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36466@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36467 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36468 vcc->dev->number,vcc->vci,length,size << 2,descr);
36469 length = eff = 0;
36470- atomic_inc(&vcc->stats->rx_err);
36471+ atomic_inc_unchecked(&vcc->stats->rx_err);
36472 }
36473 }
36474 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36475@@ -767,7 +767,7 @@ rx_dequeued++;
36476 vcc->push(vcc,skb);
36477 pushed++;
36478 }
36479- atomic_inc(&vcc->stats->rx);
36480+ atomic_inc_unchecked(&vcc->stats->rx);
36481 }
36482 wake_up(&eni_dev->rx_wait);
36483 }
36484@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36485 PCI_DMA_TODEVICE);
36486 if (vcc->pop) vcc->pop(vcc,skb);
36487 else dev_kfree_skb_irq(skb);
36488- atomic_inc(&vcc->stats->tx);
36489+ atomic_inc_unchecked(&vcc->stats->tx);
36490 wake_up(&eni_dev->tx_wait);
36491 dma_complete++;
36492 }
36493diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36494index 82f2ae0..f205c02 100644
36495--- a/drivers/atm/firestream.c
36496+++ b/drivers/atm/firestream.c
36497@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36498 }
36499 }
36500
36501- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36502+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36503
36504 fs_dprintk (FS_DEBUG_TXMEM, "i");
36505 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36506@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36507 #endif
36508 skb_put (skb, qe->p1 & 0xffff);
36509 ATM_SKB(skb)->vcc = atm_vcc;
36510- atomic_inc(&atm_vcc->stats->rx);
36511+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36512 __net_timestamp(skb);
36513 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36514 atm_vcc->push (atm_vcc, skb);
36515@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36516 kfree (pe);
36517 }
36518 if (atm_vcc)
36519- atomic_inc(&atm_vcc->stats->rx_drop);
36520+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36521 break;
36522 case 0x1f: /* Reassembly abort: no buffers. */
36523 /* Silently increment error counter. */
36524 if (atm_vcc)
36525- atomic_inc(&atm_vcc->stats->rx_drop);
36526+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36527 break;
36528 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36529 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36530diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36531index 204814e..cede831 100644
36532--- a/drivers/atm/fore200e.c
36533+++ b/drivers/atm/fore200e.c
36534@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36535 #endif
36536 /* check error condition */
36537 if (*entry->status & STATUS_ERROR)
36538- atomic_inc(&vcc->stats->tx_err);
36539+ atomic_inc_unchecked(&vcc->stats->tx_err);
36540 else
36541- atomic_inc(&vcc->stats->tx);
36542+ atomic_inc_unchecked(&vcc->stats->tx);
36543 }
36544 }
36545
36546@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36547 if (skb == NULL) {
36548 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36549
36550- atomic_inc(&vcc->stats->rx_drop);
36551+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36552 return -ENOMEM;
36553 }
36554
36555@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36556
36557 dev_kfree_skb_any(skb);
36558
36559- atomic_inc(&vcc->stats->rx_drop);
36560+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36561 return -ENOMEM;
36562 }
36563
36564 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36565
36566 vcc->push(vcc, skb);
36567- atomic_inc(&vcc->stats->rx);
36568+ atomic_inc_unchecked(&vcc->stats->rx);
36569
36570 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36571
36572@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36573 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36574 fore200e->atm_dev->number,
36575 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36576- atomic_inc(&vcc->stats->rx_err);
36577+ atomic_inc_unchecked(&vcc->stats->rx_err);
36578 }
36579 }
36580
36581@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36582 goto retry_here;
36583 }
36584
36585- atomic_inc(&vcc->stats->tx_err);
36586+ atomic_inc_unchecked(&vcc->stats->tx_err);
36587
36588 fore200e->tx_sat++;
36589 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36590diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36591index aa6be26..f70a785 100644
36592--- a/drivers/atm/he.c
36593+++ b/drivers/atm/he.c
36594@@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36595
36596 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36597 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36598- atomic_inc(&vcc->stats->rx_drop);
36599+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36600 goto return_host_buffers;
36601 }
36602
36603@@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36604 RBRQ_LEN_ERR(he_dev->rbrq_head)
36605 ? "LEN_ERR" : "",
36606 vcc->vpi, vcc->vci);
36607- atomic_inc(&vcc->stats->rx_err);
36608+ atomic_inc_unchecked(&vcc->stats->rx_err);
36609 goto return_host_buffers;
36610 }
36611
36612@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36613 vcc->push(vcc, skb);
36614 spin_lock(&he_dev->global_lock);
36615
36616- atomic_inc(&vcc->stats->rx);
36617+ atomic_inc_unchecked(&vcc->stats->rx);
36618
36619 return_host_buffers:
36620 ++pdus_assembled;
36621@@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36622 tpd->vcc->pop(tpd->vcc, tpd->skb);
36623 else
36624 dev_kfree_skb_any(tpd->skb);
36625- atomic_inc(&tpd->vcc->stats->tx_err);
36626+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36627 }
36628 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36629 return;
36630@@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36631 vcc->pop(vcc, skb);
36632 else
36633 dev_kfree_skb_any(skb);
36634- atomic_inc(&vcc->stats->tx_err);
36635+ atomic_inc_unchecked(&vcc->stats->tx_err);
36636 return -EINVAL;
36637 }
36638
36639@@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36640 vcc->pop(vcc, skb);
36641 else
36642 dev_kfree_skb_any(skb);
36643- atomic_inc(&vcc->stats->tx_err);
36644+ atomic_inc_unchecked(&vcc->stats->tx_err);
36645 return -EINVAL;
36646 }
36647 #endif
36648@@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36649 vcc->pop(vcc, skb);
36650 else
36651 dev_kfree_skb_any(skb);
36652- atomic_inc(&vcc->stats->tx_err);
36653+ atomic_inc_unchecked(&vcc->stats->tx_err);
36654 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36655 return -ENOMEM;
36656 }
36657@@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36658 vcc->pop(vcc, skb);
36659 else
36660 dev_kfree_skb_any(skb);
36661- atomic_inc(&vcc->stats->tx_err);
36662+ atomic_inc_unchecked(&vcc->stats->tx_err);
36663 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36664 return -ENOMEM;
36665 }
36666@@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36667 __enqueue_tpd(he_dev, tpd, cid);
36668 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36669
36670- atomic_inc(&vcc->stats->tx);
36671+ atomic_inc_unchecked(&vcc->stats->tx);
36672
36673 return 0;
36674 }
36675diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36676index 1dc0519..1aadaf7 100644
36677--- a/drivers/atm/horizon.c
36678+++ b/drivers/atm/horizon.c
36679@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36680 {
36681 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36682 // VC layer stats
36683- atomic_inc(&vcc->stats->rx);
36684+ atomic_inc_unchecked(&vcc->stats->rx);
36685 __net_timestamp(skb);
36686 // end of our responsibility
36687 vcc->push (vcc, skb);
36688@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36689 dev->tx_iovec = NULL;
36690
36691 // VC layer stats
36692- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36693+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36694
36695 // free the skb
36696 hrz_kfree_skb (skb);
36697diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36698index 1bdf104..9dc44b1 100644
36699--- a/drivers/atm/idt77252.c
36700+++ b/drivers/atm/idt77252.c
36701@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36702 else
36703 dev_kfree_skb(skb);
36704
36705- atomic_inc(&vcc->stats->tx);
36706+ atomic_inc_unchecked(&vcc->stats->tx);
36707 }
36708
36709 atomic_dec(&scq->used);
36710@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36711 if ((sb = dev_alloc_skb(64)) == NULL) {
36712 printk("%s: Can't allocate buffers for aal0.\n",
36713 card->name);
36714- atomic_add(i, &vcc->stats->rx_drop);
36715+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36716 break;
36717 }
36718 if (!atm_charge(vcc, sb->truesize)) {
36719 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36720 card->name);
36721- atomic_add(i - 1, &vcc->stats->rx_drop);
36722+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36723 dev_kfree_skb(sb);
36724 break;
36725 }
36726@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36727 ATM_SKB(sb)->vcc = vcc;
36728 __net_timestamp(sb);
36729 vcc->push(vcc, sb);
36730- atomic_inc(&vcc->stats->rx);
36731+ atomic_inc_unchecked(&vcc->stats->rx);
36732
36733 cell += ATM_CELL_PAYLOAD;
36734 }
36735@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36736 "(CDC: %08x)\n",
36737 card->name, len, rpp->len, readl(SAR_REG_CDC));
36738 recycle_rx_pool_skb(card, rpp);
36739- atomic_inc(&vcc->stats->rx_err);
36740+ atomic_inc_unchecked(&vcc->stats->rx_err);
36741 return;
36742 }
36743 if (stat & SAR_RSQE_CRC) {
36744 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36745 recycle_rx_pool_skb(card, rpp);
36746- atomic_inc(&vcc->stats->rx_err);
36747+ atomic_inc_unchecked(&vcc->stats->rx_err);
36748 return;
36749 }
36750 if (skb_queue_len(&rpp->queue) > 1) {
36751@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36752 RXPRINTK("%s: Can't alloc RX skb.\n",
36753 card->name);
36754 recycle_rx_pool_skb(card, rpp);
36755- atomic_inc(&vcc->stats->rx_err);
36756+ atomic_inc_unchecked(&vcc->stats->rx_err);
36757 return;
36758 }
36759 if (!atm_charge(vcc, skb->truesize)) {
36760@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36761 __net_timestamp(skb);
36762
36763 vcc->push(vcc, skb);
36764- atomic_inc(&vcc->stats->rx);
36765+ atomic_inc_unchecked(&vcc->stats->rx);
36766
36767 return;
36768 }
36769@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36770 __net_timestamp(skb);
36771
36772 vcc->push(vcc, skb);
36773- atomic_inc(&vcc->stats->rx);
36774+ atomic_inc_unchecked(&vcc->stats->rx);
36775
36776 if (skb->truesize > SAR_FB_SIZE_3)
36777 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36778@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36779 if (vcc->qos.aal != ATM_AAL0) {
36780 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36781 card->name, vpi, vci);
36782- atomic_inc(&vcc->stats->rx_drop);
36783+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36784 goto drop;
36785 }
36786
36787 if ((sb = dev_alloc_skb(64)) == NULL) {
36788 printk("%s: Can't allocate buffers for AAL0.\n",
36789 card->name);
36790- atomic_inc(&vcc->stats->rx_err);
36791+ atomic_inc_unchecked(&vcc->stats->rx_err);
36792 goto drop;
36793 }
36794
36795@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36796 ATM_SKB(sb)->vcc = vcc;
36797 __net_timestamp(sb);
36798 vcc->push(vcc, sb);
36799- atomic_inc(&vcc->stats->rx);
36800+ atomic_inc_unchecked(&vcc->stats->rx);
36801
36802 drop:
36803 skb_pull(queue, 64);
36804@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36805
36806 if (vc == NULL) {
36807 printk("%s: NULL connection in send().\n", card->name);
36808- atomic_inc(&vcc->stats->tx_err);
36809+ atomic_inc_unchecked(&vcc->stats->tx_err);
36810 dev_kfree_skb(skb);
36811 return -EINVAL;
36812 }
36813 if (!test_bit(VCF_TX, &vc->flags)) {
36814 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36815- atomic_inc(&vcc->stats->tx_err);
36816+ atomic_inc_unchecked(&vcc->stats->tx_err);
36817 dev_kfree_skb(skb);
36818 return -EINVAL;
36819 }
36820@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36821 break;
36822 default:
36823 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36824- atomic_inc(&vcc->stats->tx_err);
36825+ atomic_inc_unchecked(&vcc->stats->tx_err);
36826 dev_kfree_skb(skb);
36827 return -EINVAL;
36828 }
36829
36830 if (skb_shinfo(skb)->nr_frags != 0) {
36831 printk("%s: No scatter-gather yet.\n", card->name);
36832- atomic_inc(&vcc->stats->tx_err);
36833+ atomic_inc_unchecked(&vcc->stats->tx_err);
36834 dev_kfree_skb(skb);
36835 return -EINVAL;
36836 }
36837@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36838
36839 err = queue_skb(card, vc, skb, oam);
36840 if (err) {
36841- atomic_inc(&vcc->stats->tx_err);
36842+ atomic_inc_unchecked(&vcc->stats->tx_err);
36843 dev_kfree_skb(skb);
36844 return err;
36845 }
36846@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36847 skb = dev_alloc_skb(64);
36848 if (!skb) {
36849 printk("%s: Out of memory in send_oam().\n", card->name);
36850- atomic_inc(&vcc->stats->tx_err);
36851+ atomic_inc_unchecked(&vcc->stats->tx_err);
36852 return -ENOMEM;
36853 }
36854 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36855diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36856index 4217f29..88f547a 100644
36857--- a/drivers/atm/iphase.c
36858+++ b/drivers/atm/iphase.c
36859@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36860 status = (u_short) (buf_desc_ptr->desc_mode);
36861 if (status & (RX_CER | RX_PTE | RX_OFL))
36862 {
36863- atomic_inc(&vcc->stats->rx_err);
36864+ atomic_inc_unchecked(&vcc->stats->rx_err);
36865 IF_ERR(printk("IA: bad packet, dropping it");)
36866 if (status & RX_CER) {
36867 IF_ERR(printk(" cause: packet CRC error\n");)
36868@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36869 len = dma_addr - buf_addr;
36870 if (len > iadev->rx_buf_sz) {
36871 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36872- atomic_inc(&vcc->stats->rx_err);
36873+ atomic_inc_unchecked(&vcc->stats->rx_err);
36874 goto out_free_desc;
36875 }
36876
36877@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36878 ia_vcc = INPH_IA_VCC(vcc);
36879 if (ia_vcc == NULL)
36880 {
36881- atomic_inc(&vcc->stats->rx_err);
36882+ atomic_inc_unchecked(&vcc->stats->rx_err);
36883 atm_return(vcc, skb->truesize);
36884 dev_kfree_skb_any(skb);
36885 goto INCR_DLE;
36886@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36887 if ((length > iadev->rx_buf_sz) || (length >
36888 (skb->len - sizeof(struct cpcs_trailer))))
36889 {
36890- atomic_inc(&vcc->stats->rx_err);
36891+ atomic_inc_unchecked(&vcc->stats->rx_err);
36892 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36893 length, skb->len);)
36894 atm_return(vcc, skb->truesize);
36895@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36896
36897 IF_RX(printk("rx_dle_intr: skb push");)
36898 vcc->push(vcc,skb);
36899- atomic_inc(&vcc->stats->rx);
36900+ atomic_inc_unchecked(&vcc->stats->rx);
36901 iadev->rx_pkt_cnt++;
36902 }
36903 INCR_DLE:
36904@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36905 {
36906 struct k_sonet_stats *stats;
36907 stats = &PRIV(_ia_dev[board])->sonet_stats;
36908- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36909- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36910- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36911- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36912- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36913- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36914- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36915- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36916- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36917+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36918+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36919+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36920+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36921+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36922+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36923+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36924+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36925+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36926 }
36927 ia_cmds.status = 0;
36928 break;
36929@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36930 if ((desc == 0) || (desc > iadev->num_tx_desc))
36931 {
36932 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36933- atomic_inc(&vcc->stats->tx);
36934+ atomic_inc_unchecked(&vcc->stats->tx);
36935 if (vcc->pop)
36936 vcc->pop(vcc, skb);
36937 else
36938@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36939 ATM_DESC(skb) = vcc->vci;
36940 skb_queue_tail(&iadev->tx_dma_q, skb);
36941
36942- atomic_inc(&vcc->stats->tx);
36943+ atomic_inc_unchecked(&vcc->stats->tx);
36944 iadev->tx_pkt_cnt++;
36945 /* Increment transaction counter */
36946 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36947
36948 #if 0
36949 /* add flow control logic */
36950- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36951+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36952 if (iavcc->vc_desc_cnt > 10) {
36953 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36954 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36955diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36956index fa7d701..1e404c7 100644
36957--- a/drivers/atm/lanai.c
36958+++ b/drivers/atm/lanai.c
36959@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36960 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36961 lanai_endtx(lanai, lvcc);
36962 lanai_free_skb(lvcc->tx.atmvcc, skb);
36963- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36964+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36965 }
36966
36967 /* Try to fill the buffer - don't call unless there is backlog */
36968@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36969 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36970 __net_timestamp(skb);
36971 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36972- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36973+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36974 out:
36975 lvcc->rx.buf.ptr = end;
36976 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36977@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36978 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36979 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36980 lanai->stats.service_rxnotaal5++;
36981- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36982+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36983 return 0;
36984 }
36985 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36986@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36987 int bytes;
36988 read_unlock(&vcc_sklist_lock);
36989 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36990- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36991+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36992 lvcc->stats.x.aal5.service_trash++;
36993 bytes = (SERVICE_GET_END(s) * 16) -
36994 (((unsigned long) lvcc->rx.buf.ptr) -
36995@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36996 }
36997 if (s & SERVICE_STREAM) {
36998 read_unlock(&vcc_sklist_lock);
36999- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37000+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37001 lvcc->stats.x.aal5.service_stream++;
37002 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37003 "PDU on VCI %d!\n", lanai->number, vci);
37004@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37005 return 0;
37006 }
37007 DPRINTK("got rx crc error on vci %d\n", vci);
37008- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37009+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37010 lvcc->stats.x.aal5.service_rxcrc++;
37011 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37012 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37013diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37014index 9988ac9..7c52585 100644
37015--- a/drivers/atm/nicstar.c
37016+++ b/drivers/atm/nicstar.c
37017@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37018 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37019 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37020 card->index);
37021- atomic_inc(&vcc->stats->tx_err);
37022+ atomic_inc_unchecked(&vcc->stats->tx_err);
37023 dev_kfree_skb_any(skb);
37024 return -EINVAL;
37025 }
37026@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37027 if (!vc->tx) {
37028 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37029 card->index);
37030- atomic_inc(&vcc->stats->tx_err);
37031+ atomic_inc_unchecked(&vcc->stats->tx_err);
37032 dev_kfree_skb_any(skb);
37033 return -EINVAL;
37034 }
37035@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37036 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37037 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37038 card->index);
37039- atomic_inc(&vcc->stats->tx_err);
37040+ atomic_inc_unchecked(&vcc->stats->tx_err);
37041 dev_kfree_skb_any(skb);
37042 return -EINVAL;
37043 }
37044
37045 if (skb_shinfo(skb)->nr_frags != 0) {
37046 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37047- atomic_inc(&vcc->stats->tx_err);
37048+ atomic_inc_unchecked(&vcc->stats->tx_err);
37049 dev_kfree_skb_any(skb);
37050 return -EINVAL;
37051 }
37052@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37053 }
37054
37055 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37056- atomic_inc(&vcc->stats->tx_err);
37057+ atomic_inc_unchecked(&vcc->stats->tx_err);
37058 dev_kfree_skb_any(skb);
37059 return -EIO;
37060 }
37061- atomic_inc(&vcc->stats->tx);
37062+ atomic_inc_unchecked(&vcc->stats->tx);
37063
37064 return 0;
37065 }
37066@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37067 printk
37068 ("nicstar%d: Can't allocate buffers for aal0.\n",
37069 card->index);
37070- atomic_add(i, &vcc->stats->rx_drop);
37071+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37072 break;
37073 }
37074 if (!atm_charge(vcc, sb->truesize)) {
37075 RXPRINTK
37076 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37077 card->index);
37078- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37079+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37080 dev_kfree_skb_any(sb);
37081 break;
37082 }
37083@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37084 ATM_SKB(sb)->vcc = vcc;
37085 __net_timestamp(sb);
37086 vcc->push(vcc, sb);
37087- atomic_inc(&vcc->stats->rx);
37088+ atomic_inc_unchecked(&vcc->stats->rx);
37089 cell += ATM_CELL_PAYLOAD;
37090 }
37091
37092@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37093 if (iovb == NULL) {
37094 printk("nicstar%d: Out of iovec buffers.\n",
37095 card->index);
37096- atomic_inc(&vcc->stats->rx_drop);
37097+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37098 recycle_rx_buf(card, skb);
37099 return;
37100 }
37101@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37102 small or large buffer itself. */
37103 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37104 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37105- atomic_inc(&vcc->stats->rx_err);
37106+ atomic_inc_unchecked(&vcc->stats->rx_err);
37107 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37108 NS_MAX_IOVECS);
37109 NS_PRV_IOVCNT(iovb) = 0;
37110@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37111 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37112 card->index);
37113 which_list(card, skb);
37114- atomic_inc(&vcc->stats->rx_err);
37115+ atomic_inc_unchecked(&vcc->stats->rx_err);
37116 recycle_rx_buf(card, skb);
37117 vc->rx_iov = NULL;
37118 recycle_iov_buf(card, iovb);
37119@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37120 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37121 card->index);
37122 which_list(card, skb);
37123- atomic_inc(&vcc->stats->rx_err);
37124+ atomic_inc_unchecked(&vcc->stats->rx_err);
37125 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37126 NS_PRV_IOVCNT(iovb));
37127 vc->rx_iov = NULL;
37128@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37129 printk(" - PDU size mismatch.\n");
37130 else
37131 printk(".\n");
37132- atomic_inc(&vcc->stats->rx_err);
37133+ atomic_inc_unchecked(&vcc->stats->rx_err);
37134 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37135 NS_PRV_IOVCNT(iovb));
37136 vc->rx_iov = NULL;
37137@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37138 /* skb points to a small buffer */
37139 if (!atm_charge(vcc, skb->truesize)) {
37140 push_rxbufs(card, skb);
37141- atomic_inc(&vcc->stats->rx_drop);
37142+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37143 } else {
37144 skb_put(skb, len);
37145 dequeue_sm_buf(card, skb);
37146@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37147 ATM_SKB(skb)->vcc = vcc;
37148 __net_timestamp(skb);
37149 vcc->push(vcc, skb);
37150- atomic_inc(&vcc->stats->rx);
37151+ atomic_inc_unchecked(&vcc->stats->rx);
37152 }
37153 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37154 struct sk_buff *sb;
37155@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37156 if (len <= NS_SMBUFSIZE) {
37157 if (!atm_charge(vcc, sb->truesize)) {
37158 push_rxbufs(card, sb);
37159- atomic_inc(&vcc->stats->rx_drop);
37160+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37161 } else {
37162 skb_put(sb, len);
37163 dequeue_sm_buf(card, sb);
37164@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37165 ATM_SKB(sb)->vcc = vcc;
37166 __net_timestamp(sb);
37167 vcc->push(vcc, sb);
37168- atomic_inc(&vcc->stats->rx);
37169+ atomic_inc_unchecked(&vcc->stats->rx);
37170 }
37171
37172 push_rxbufs(card, skb);
37173@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37174
37175 if (!atm_charge(vcc, skb->truesize)) {
37176 push_rxbufs(card, skb);
37177- atomic_inc(&vcc->stats->rx_drop);
37178+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37179 } else {
37180 dequeue_lg_buf(card, skb);
37181 #ifdef NS_USE_DESTRUCTORS
37182@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37183 ATM_SKB(skb)->vcc = vcc;
37184 __net_timestamp(skb);
37185 vcc->push(vcc, skb);
37186- atomic_inc(&vcc->stats->rx);
37187+ atomic_inc_unchecked(&vcc->stats->rx);
37188 }
37189
37190 push_rxbufs(card, sb);
37191@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37192 printk
37193 ("nicstar%d: Out of huge buffers.\n",
37194 card->index);
37195- atomic_inc(&vcc->stats->rx_drop);
37196+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37197 recycle_iovec_rx_bufs(card,
37198 (struct iovec *)
37199 iovb->data,
37200@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37201 card->hbpool.count++;
37202 } else
37203 dev_kfree_skb_any(hb);
37204- atomic_inc(&vcc->stats->rx_drop);
37205+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37206 } else {
37207 /* Copy the small buffer to the huge buffer */
37208 sb = (struct sk_buff *)iov->iov_base;
37209@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37210 #endif /* NS_USE_DESTRUCTORS */
37211 __net_timestamp(hb);
37212 vcc->push(vcc, hb);
37213- atomic_inc(&vcc->stats->rx);
37214+ atomic_inc_unchecked(&vcc->stats->rx);
37215 }
37216 }
37217
37218diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37219index 943cf0d..37d15d5 100644
37220--- a/drivers/atm/solos-pci.c
37221+++ b/drivers/atm/solos-pci.c
37222@@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37223 }
37224 atm_charge(vcc, skb->truesize);
37225 vcc->push(vcc, skb);
37226- atomic_inc(&vcc->stats->rx);
37227+ atomic_inc_unchecked(&vcc->stats->rx);
37228 break;
37229
37230 case PKT_STATUS:
37231@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37232 vcc = SKB_CB(oldskb)->vcc;
37233
37234 if (vcc) {
37235- atomic_inc(&vcc->stats->tx);
37236+ atomic_inc_unchecked(&vcc->stats->tx);
37237 solos_pop(vcc, oldskb);
37238 } else {
37239 dev_kfree_skb_irq(oldskb);
37240diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37241index 0215934..ce9f5b1 100644
37242--- a/drivers/atm/suni.c
37243+++ b/drivers/atm/suni.c
37244@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37245
37246
37247 #define ADD_LIMITED(s,v) \
37248- atomic_add((v),&stats->s); \
37249- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37250+ atomic_add_unchecked((v),&stats->s); \
37251+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37252
37253
37254 static void suni_hz(unsigned long from_timer)
37255diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37256index 5120a96..e2572bd 100644
37257--- a/drivers/atm/uPD98402.c
37258+++ b/drivers/atm/uPD98402.c
37259@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37260 struct sonet_stats tmp;
37261 int error = 0;
37262
37263- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37264+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37265 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37266 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37267 if (zero && !error) {
37268@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37269
37270
37271 #define ADD_LIMITED(s,v) \
37272- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37273- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37274- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37275+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37276+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37277+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37278
37279
37280 static void stat_event(struct atm_dev *dev)
37281@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37282 if (reason & uPD98402_INT_PFM) stat_event(dev);
37283 if (reason & uPD98402_INT_PCO) {
37284 (void) GET(PCOCR); /* clear interrupt cause */
37285- atomic_add(GET(HECCT),
37286+ atomic_add_unchecked(GET(HECCT),
37287 &PRIV(dev)->sonet_stats.uncorr_hcs);
37288 }
37289 if ((reason & uPD98402_INT_RFO) &&
37290@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37291 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37292 uPD98402_INT_LOS),PIMR); /* enable them */
37293 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37294- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37295- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37296- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37297+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37298+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37299+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37300 return 0;
37301 }
37302
37303diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37304index 969c3c2..9b72956 100644
37305--- a/drivers/atm/zatm.c
37306+++ b/drivers/atm/zatm.c
37307@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37308 }
37309 if (!size) {
37310 dev_kfree_skb_irq(skb);
37311- if (vcc) atomic_inc(&vcc->stats->rx_err);
37312+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37313 continue;
37314 }
37315 if (!atm_charge(vcc,skb->truesize)) {
37316@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37317 skb->len = size;
37318 ATM_SKB(skb)->vcc = vcc;
37319 vcc->push(vcc,skb);
37320- atomic_inc(&vcc->stats->rx);
37321+ atomic_inc_unchecked(&vcc->stats->rx);
37322 }
37323 zout(pos & 0xffff,MTA(mbx));
37324 #if 0 /* probably a stupid idea */
37325@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37326 skb_queue_head(&zatm_vcc->backlog,skb);
37327 break;
37328 }
37329- atomic_inc(&vcc->stats->tx);
37330+ atomic_inc_unchecked(&vcc->stats->tx);
37331 wake_up(&zatm_vcc->tx_wait);
37332 }
37333
37334diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37335index 83e910a..b224a73 100644
37336--- a/drivers/base/bus.c
37337+++ b/drivers/base/bus.c
37338@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37339 return -EINVAL;
37340
37341 mutex_lock(&subsys->p->mutex);
37342- list_add_tail(&sif->node, &subsys->p->interfaces);
37343+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37344 if (sif->add_dev) {
37345 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37346 while ((dev = subsys_dev_iter_next(&iter)))
37347@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37348 subsys = sif->subsys;
37349
37350 mutex_lock(&subsys->p->mutex);
37351- list_del_init(&sif->node);
37352+ pax_list_del_init((struct list_head *)&sif->node);
37353 if (sif->remove_dev) {
37354 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37355 while ((dev = subsys_dev_iter_next(&iter)))
37356diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37357index 25798db..15f130e 100644
37358--- a/drivers/base/devtmpfs.c
37359+++ b/drivers/base/devtmpfs.c
37360@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37361 if (!thread)
37362 return 0;
37363
37364- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37365+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37366 if (err)
37367 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37368 else
37369@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37370 *err = sys_unshare(CLONE_NEWNS);
37371 if (*err)
37372 goto out;
37373- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37374+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37375 if (*err)
37376 goto out;
37377- sys_chdir("/.."); /* will traverse into overmounted root */
37378- sys_chroot(".");
37379+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37380+ sys_chroot((char __force_user *)".");
37381 complete(&setup_done);
37382 while (1) {
37383 spin_lock(&req_lock);
37384diff --git a/drivers/base/node.c b/drivers/base/node.c
37385index 8f7ed99..700dd0c 100644
37386--- a/drivers/base/node.c
37387+++ b/drivers/base/node.c
37388@@ -624,7 +624,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37389 struct node_attr {
37390 struct device_attribute attr;
37391 enum node_states state;
37392-};
37393+} __do_const;
37394
37395 static ssize_t show_node_state(struct device *dev,
37396 struct device_attribute *attr, char *buf)
37397diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37398index ae098a2..0999830 100644
37399--- a/drivers/base/power/domain.c
37400+++ b/drivers/base/power/domain.c
37401@@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37402
37403 if (dev->power.subsys_data->domain_data) {
37404 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37405- gpd_data->ops = (struct gpd_dev_ops){ NULL };
37406+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37407 if (clear_td)
37408- gpd_data->td = (struct gpd_timing_data){ 0 };
37409+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37410
37411 if (--gpd_data->refcount == 0) {
37412 dev->power.subsys_data->domain_data = NULL;
37413@@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37414 {
37415 struct cpuidle_driver *cpuidle_drv;
37416 struct gpd_cpu_data *cpu_data;
37417- struct cpuidle_state *idle_state;
37418+ cpuidle_state_no_const *idle_state;
37419 int ret = 0;
37420
37421 if (IS_ERR_OR_NULL(genpd) || state < 0)
37422@@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37423 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37424 {
37425 struct gpd_cpu_data *cpu_data;
37426- struct cpuidle_state *idle_state;
37427+ cpuidle_state_no_const *idle_state;
37428 int ret = 0;
37429
37430 if (IS_ERR_OR_NULL(genpd))
37431diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37432index 95b181d1..c4f0e19 100644
37433--- a/drivers/base/power/sysfs.c
37434+++ b/drivers/base/power/sysfs.c
37435@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37436 return -EIO;
37437 }
37438 }
37439- return sprintf(buf, p);
37440+ return sprintf(buf, "%s", p);
37441 }
37442
37443 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37444diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37445index 2d56f41..8830f19 100644
37446--- a/drivers/base/power/wakeup.c
37447+++ b/drivers/base/power/wakeup.c
37448@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37449 * They need to be modified together atomically, so it's better to use one
37450 * atomic variable to hold them both.
37451 */
37452-static atomic_t combined_event_count = ATOMIC_INIT(0);
37453+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37454
37455 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37456 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37457
37458 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37459 {
37460- unsigned int comb = atomic_read(&combined_event_count);
37461+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37462
37463 *cnt = (comb >> IN_PROGRESS_BITS);
37464 *inpr = comb & MAX_IN_PROGRESS;
37465@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37466 ws->start_prevent_time = ws->last_time;
37467
37468 /* Increment the counter of events in progress. */
37469- cec = atomic_inc_return(&combined_event_count);
37470+ cec = atomic_inc_return_unchecked(&combined_event_count);
37471
37472 trace_wakeup_source_activate(ws->name, cec);
37473 }
37474@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37475 * Increment the counter of registered wakeup events and decrement the
37476 * couter of wakeup events in progress simultaneously.
37477 */
37478- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37479+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37480 trace_wakeup_source_deactivate(ws->name, cec);
37481
37482 split_counters(&cnt, &inpr);
37483diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37484index e8d11b6..7b1b36f 100644
37485--- a/drivers/base/syscore.c
37486+++ b/drivers/base/syscore.c
37487@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37488 void register_syscore_ops(struct syscore_ops *ops)
37489 {
37490 mutex_lock(&syscore_ops_lock);
37491- list_add_tail(&ops->node, &syscore_ops_list);
37492+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37493 mutex_unlock(&syscore_ops_lock);
37494 }
37495 EXPORT_SYMBOL_GPL(register_syscore_ops);
37496@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37497 void unregister_syscore_ops(struct syscore_ops *ops)
37498 {
37499 mutex_lock(&syscore_ops_lock);
37500- list_del(&ops->node);
37501+ pax_list_del((struct list_head *)&ops->node);
37502 mutex_unlock(&syscore_ops_lock);
37503 }
37504 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37505diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37506index 73894ca..69f64ef 100644
37507--- a/drivers/block/cciss.c
37508+++ b/drivers/block/cciss.c
37509@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37510 while (!list_empty(&h->reqQ)) {
37511 c = list_entry(h->reqQ.next, CommandList_struct, list);
37512 /* can't do anything if fifo is full */
37513- if ((h->access.fifo_full(h))) {
37514+ if ((h->access->fifo_full(h))) {
37515 dev_warn(&h->pdev->dev, "fifo full\n");
37516 break;
37517 }
37518@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37519 h->Qdepth--;
37520
37521 /* Tell the controller execute command */
37522- h->access.submit_command(h, c);
37523+ h->access->submit_command(h, c);
37524
37525 /* Put job onto the completed Q */
37526 addQ(&h->cmpQ, c);
37527@@ -3447,17 +3447,17 @@ startio:
37528
37529 static inline unsigned long get_next_completion(ctlr_info_t *h)
37530 {
37531- return h->access.command_completed(h);
37532+ return h->access->command_completed(h);
37533 }
37534
37535 static inline int interrupt_pending(ctlr_info_t *h)
37536 {
37537- return h->access.intr_pending(h);
37538+ return h->access->intr_pending(h);
37539 }
37540
37541 static inline long interrupt_not_for_us(ctlr_info_t *h)
37542 {
37543- return ((h->access.intr_pending(h) == 0) ||
37544+ return ((h->access->intr_pending(h) == 0) ||
37545 (h->interrupts_enabled == 0));
37546 }
37547
37548@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37549 u32 a;
37550
37551 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37552- return h->access.command_completed(h);
37553+ return h->access->command_completed(h);
37554
37555 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37556 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37557@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37558 trans_support & CFGTBL_Trans_use_short_tags);
37559
37560 /* Change the access methods to the performant access methods */
37561- h->access = SA5_performant_access;
37562+ h->access = &SA5_performant_access;
37563 h->transMethod = CFGTBL_Trans_Performant;
37564
37565 return;
37566@@ -4325,7 +4325,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37567 if (prod_index < 0)
37568 return -ENODEV;
37569 h->product_name = products[prod_index].product_name;
37570- h->access = *(products[prod_index].access);
37571+ h->access = products[prod_index].access;
37572
37573 if (cciss_board_disabled(h)) {
37574 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37575@@ -5057,7 +5057,7 @@ reinit_after_soft_reset:
37576 }
37577
37578 /* make sure the board interrupts are off */
37579- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37580+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37581 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37582 if (rc)
37583 goto clean2;
37584@@ -5107,7 +5107,7 @@ reinit_after_soft_reset:
37585 * fake ones to scoop up any residual completions.
37586 */
37587 spin_lock_irqsave(&h->lock, flags);
37588- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37589+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37590 spin_unlock_irqrestore(&h->lock, flags);
37591 free_irq(h->intr[h->intr_mode], h);
37592 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37593@@ -5127,9 +5127,9 @@ reinit_after_soft_reset:
37594 dev_info(&h->pdev->dev, "Board READY.\n");
37595 dev_info(&h->pdev->dev,
37596 "Waiting for stale completions to drain.\n");
37597- h->access.set_intr_mask(h, CCISS_INTR_ON);
37598+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37599 msleep(10000);
37600- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37601+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37602
37603 rc = controller_reset_failed(h->cfgtable);
37604 if (rc)
37605@@ -5152,7 +5152,7 @@ reinit_after_soft_reset:
37606 cciss_scsi_setup(h);
37607
37608 /* Turn the interrupts on so we can service requests */
37609- h->access.set_intr_mask(h, CCISS_INTR_ON);
37610+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37611
37612 /* Get the firmware version */
37613 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37614@@ -5224,7 +5224,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37615 kfree(flush_buf);
37616 if (return_code != IO_OK)
37617 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37618- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37619+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37620 free_irq(h->intr[h->intr_mode], h);
37621 }
37622
37623diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37624index 7fda30e..2f27946 100644
37625--- a/drivers/block/cciss.h
37626+++ b/drivers/block/cciss.h
37627@@ -101,7 +101,7 @@ struct ctlr_info
37628 /* information about each logical volume */
37629 drive_info_struct *drv[CISS_MAX_LUN];
37630
37631- struct access_method access;
37632+ struct access_method *access;
37633
37634 /* queue and queue Info */
37635 struct list_head reqQ;
37636@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37637 }
37638
37639 static struct access_method SA5_access = {
37640- SA5_submit_command,
37641- SA5_intr_mask,
37642- SA5_fifo_full,
37643- SA5_intr_pending,
37644- SA5_completed,
37645+ .submit_command = SA5_submit_command,
37646+ .set_intr_mask = SA5_intr_mask,
37647+ .fifo_full = SA5_fifo_full,
37648+ .intr_pending = SA5_intr_pending,
37649+ .command_completed = SA5_completed,
37650 };
37651
37652 static struct access_method SA5B_access = {
37653- SA5_submit_command,
37654- SA5B_intr_mask,
37655- SA5_fifo_full,
37656- SA5B_intr_pending,
37657- SA5_completed,
37658+ .submit_command = SA5_submit_command,
37659+ .set_intr_mask = SA5B_intr_mask,
37660+ .fifo_full = SA5_fifo_full,
37661+ .intr_pending = SA5B_intr_pending,
37662+ .command_completed = SA5_completed,
37663 };
37664
37665 static struct access_method SA5_performant_access = {
37666- SA5_submit_command,
37667- SA5_performant_intr_mask,
37668- SA5_fifo_full,
37669- SA5_performant_intr_pending,
37670- SA5_performant_completed,
37671+ .submit_command = SA5_submit_command,
37672+ .set_intr_mask = SA5_performant_intr_mask,
37673+ .fifo_full = SA5_fifo_full,
37674+ .intr_pending = SA5_performant_intr_pending,
37675+ .command_completed = SA5_performant_completed,
37676 };
37677
37678 struct board_type {
37679diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37680index 2b94403..fd6ad1f 100644
37681--- a/drivers/block/cpqarray.c
37682+++ b/drivers/block/cpqarray.c
37683@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37684 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37685 goto Enomem4;
37686 }
37687- hba[i]->access.set_intr_mask(hba[i], 0);
37688+ hba[i]->access->set_intr_mask(hba[i], 0);
37689 if (request_irq(hba[i]->intr, do_ida_intr,
37690 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37691 {
37692@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37693 add_timer(&hba[i]->timer);
37694
37695 /* Enable IRQ now that spinlock and rate limit timer are set up */
37696- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37697+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37698
37699 for(j=0; j<NWD; j++) {
37700 struct gendisk *disk = ida_gendisk[i][j];
37701@@ -694,7 +694,7 @@ DBGINFO(
37702 for(i=0; i<NR_PRODUCTS; i++) {
37703 if (board_id == products[i].board_id) {
37704 c->product_name = products[i].product_name;
37705- c->access = *(products[i].access);
37706+ c->access = products[i].access;
37707 break;
37708 }
37709 }
37710@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37711 hba[ctlr]->intr = intr;
37712 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37713 hba[ctlr]->product_name = products[j].product_name;
37714- hba[ctlr]->access = *(products[j].access);
37715+ hba[ctlr]->access = products[j].access;
37716 hba[ctlr]->ctlr = ctlr;
37717 hba[ctlr]->board_id = board_id;
37718 hba[ctlr]->pci_dev = NULL; /* not PCI */
37719@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37720
37721 while((c = h->reqQ) != NULL) {
37722 /* Can't do anything if we're busy */
37723- if (h->access.fifo_full(h) == 0)
37724+ if (h->access->fifo_full(h) == 0)
37725 return;
37726
37727 /* Get the first entry from the request Q */
37728@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37729 h->Qdepth--;
37730
37731 /* Tell the controller to do our bidding */
37732- h->access.submit_command(h, c);
37733+ h->access->submit_command(h, c);
37734
37735 /* Get onto the completion Q */
37736 addQ(&h->cmpQ, c);
37737@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37738 unsigned long flags;
37739 __u32 a,a1;
37740
37741- istat = h->access.intr_pending(h);
37742+ istat = h->access->intr_pending(h);
37743 /* Is this interrupt for us? */
37744 if (istat == 0)
37745 return IRQ_NONE;
37746@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37747 */
37748 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37749 if (istat & FIFO_NOT_EMPTY) {
37750- while((a = h->access.command_completed(h))) {
37751+ while((a = h->access->command_completed(h))) {
37752 a1 = a; a &= ~3;
37753 if ((c = h->cmpQ) == NULL)
37754 {
37755@@ -1448,11 +1448,11 @@ static int sendcmd(
37756 /*
37757 * Disable interrupt
37758 */
37759- info_p->access.set_intr_mask(info_p, 0);
37760+ info_p->access->set_intr_mask(info_p, 0);
37761 /* Make sure there is room in the command FIFO */
37762 /* Actually it should be completely empty at this time. */
37763 for (i = 200000; i > 0; i--) {
37764- temp = info_p->access.fifo_full(info_p);
37765+ temp = info_p->access->fifo_full(info_p);
37766 if (temp != 0) {
37767 break;
37768 }
37769@@ -1465,7 +1465,7 @@ DBG(
37770 /*
37771 * Send the cmd
37772 */
37773- info_p->access.submit_command(info_p, c);
37774+ info_p->access->submit_command(info_p, c);
37775 complete = pollcomplete(ctlr);
37776
37777 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37778@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37779 * we check the new geometry. Then turn interrupts back on when
37780 * we're done.
37781 */
37782- host->access.set_intr_mask(host, 0);
37783+ host->access->set_intr_mask(host, 0);
37784 getgeometry(ctlr);
37785- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37786+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37787
37788 for(i=0; i<NWD; i++) {
37789 struct gendisk *disk = ida_gendisk[ctlr][i];
37790@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37791 /* Wait (up to 2 seconds) for a command to complete */
37792
37793 for (i = 200000; i > 0; i--) {
37794- done = hba[ctlr]->access.command_completed(hba[ctlr]);
37795+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
37796 if (done == 0) {
37797 udelay(10); /* a short fixed delay */
37798 } else
37799diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37800index be73e9d..7fbf140 100644
37801--- a/drivers/block/cpqarray.h
37802+++ b/drivers/block/cpqarray.h
37803@@ -99,7 +99,7 @@ struct ctlr_info {
37804 drv_info_t drv[NWD];
37805 struct proc_dir_entry *proc;
37806
37807- struct access_method access;
37808+ struct access_method *access;
37809
37810 cmdlist_t *reqQ;
37811 cmdlist_t *cmpQ;
37812diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37813index e7093d4..b364085 100644
37814--- a/drivers/block/drbd/drbd_int.h
37815+++ b/drivers/block/drbd/drbd_int.h
37816@@ -331,7 +331,7 @@ struct drbd_epoch {
37817 struct drbd_connection *connection;
37818 struct list_head list;
37819 unsigned int barrier_nr;
37820- atomic_t epoch_size; /* increased on every request added. */
37821+ atomic_unchecked_t epoch_size; /* increased on every request added. */
37822 atomic_t active; /* increased on every req. added, and dec on every finished. */
37823 unsigned long flags;
37824 };
37825@@ -787,7 +787,7 @@ struct drbd_device {
37826 unsigned int al_tr_number;
37827 int al_tr_cycle;
37828 wait_queue_head_t seq_wait;
37829- atomic_t packet_seq;
37830+ atomic_unchecked_t packet_seq;
37831 unsigned int peer_seq;
37832 spinlock_t peer_seq_lock;
37833 unsigned int minor;
37834@@ -1361,7 +1361,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37835 char __user *uoptval;
37836 int err;
37837
37838- uoptval = (char __user __force *)optval;
37839+ uoptval = (char __force_user *)optval;
37840
37841 set_fs(KERNEL_DS);
37842 if (level == SOL_SOCKET)
37843diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37844index 89c497c..9c736ae 100644
37845--- a/drivers/block/drbd/drbd_interval.c
37846+++ b/drivers/block/drbd/drbd_interval.c
37847@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37848 }
37849
37850 static const struct rb_augment_callbacks augment_callbacks = {
37851- augment_propagate,
37852- augment_copy,
37853- augment_rotate,
37854+ .propagate = augment_propagate,
37855+ .copy = augment_copy,
37856+ .rotate = augment_rotate,
37857 };
37858
37859 /**
37860diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37861index 331e5cc..6d657bce 100644
37862--- a/drivers/block/drbd/drbd_main.c
37863+++ b/drivers/block/drbd/drbd_main.c
37864@@ -1322,7 +1322,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
37865 p->sector = sector;
37866 p->block_id = block_id;
37867 p->blksize = blksize;
37868- p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
37869+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
37870 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
37871 }
37872
37873@@ -1628,7 +1628,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
37874 return -EIO;
37875 p->sector = cpu_to_be64(req->i.sector);
37876 p->block_id = (unsigned long)req;
37877- p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
37878+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
37879 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
37880 if (device->state.conn >= C_SYNC_SOURCE &&
37881 device->state.conn <= C_PAUSED_SYNC_T)
37882@@ -2658,8 +2658,8 @@ void drbd_destroy_connection(struct kref *kref)
37883 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
37884 struct drbd_resource *resource = connection->resource;
37885
37886- if (atomic_read(&connection->current_epoch->epoch_size) != 0)
37887- drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
37888+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
37889+ drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
37890 kfree(connection->current_epoch);
37891
37892 idr_destroy(&connection->peer_devices);
37893diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37894index 526414b..4eb8184 100644
37895--- a/drivers/block/drbd/drbd_nl.c
37896+++ b/drivers/block/drbd/drbd_nl.c
37897@@ -3505,7 +3505,7 @@ out:
37898
37899 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
37900 {
37901- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37902+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37903 struct sk_buff *msg;
37904 struct drbd_genlmsghdr *d_out;
37905 unsigned seq;
37906@@ -3518,7 +3518,7 @@ void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
37907 return;
37908 }
37909
37910- seq = atomic_inc_return(&drbd_genl_seq);
37911+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37912 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37913 if (!msg)
37914 goto failed;
37915diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37916index 68e3992..1aca24a 100644
37917--- a/drivers/block/drbd/drbd_receiver.c
37918+++ b/drivers/block/drbd/drbd_receiver.c
37919@@ -826,7 +826,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
37920 struct drbd_device *device = peer_device->device;
37921 int err;
37922
37923- atomic_set(&device->packet_seq, 0);
37924+ atomic_set_unchecked(&device->packet_seq, 0);
37925 device->peer_seq = 0;
37926
37927 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
37928@@ -1188,7 +1188,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
37929 do {
37930 next_epoch = NULL;
37931
37932- epoch_size = atomic_read(&epoch->epoch_size);
37933+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37934
37935 switch (ev & ~EV_CLEANUP) {
37936 case EV_PUT:
37937@@ -1228,7 +1228,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
37938 rv = FE_DESTROYED;
37939 } else {
37940 epoch->flags = 0;
37941- atomic_set(&epoch->epoch_size, 0);
37942+ atomic_set_unchecked(&epoch->epoch_size, 0);
37943 /* atomic_set(&epoch->active, 0); is already zero */
37944 if (rv == FE_STILL_LIVE)
37945 rv = FE_RECYCLED;
37946@@ -1456,7 +1456,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
37947 conn_wait_active_ee_empty(connection);
37948 drbd_flush(connection);
37949
37950- if (atomic_read(&connection->current_epoch->epoch_size)) {
37951+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
37952 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37953 if (epoch)
37954 break;
37955@@ -1469,11 +1469,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
37956 }
37957
37958 epoch->flags = 0;
37959- atomic_set(&epoch->epoch_size, 0);
37960+ atomic_set_unchecked(&epoch->epoch_size, 0);
37961 atomic_set(&epoch->active, 0);
37962
37963 spin_lock(&connection->epoch_lock);
37964- if (atomic_read(&connection->current_epoch->epoch_size)) {
37965+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
37966 list_add(&epoch->list, &connection->current_epoch->list);
37967 connection->current_epoch = epoch;
37968 connection->epochs++;
37969@@ -2182,7 +2182,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
37970
37971 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
37972 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
37973- atomic_inc(&connection->current_epoch->epoch_size);
37974+ atomic_inc_unchecked(&connection->current_epoch->epoch_size);
37975 err2 = drbd_drain_block(peer_device, pi->size);
37976 if (!err)
37977 err = err2;
37978@@ -2216,7 +2216,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
37979
37980 spin_lock(&connection->epoch_lock);
37981 peer_req->epoch = connection->current_epoch;
37982- atomic_inc(&peer_req->epoch->epoch_size);
37983+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37984 atomic_inc(&peer_req->epoch->active);
37985 spin_unlock(&connection->epoch_lock);
37986
37987@@ -4396,7 +4396,7 @@ struct data_cmd {
37988 int expect_payload;
37989 size_t pkt_size;
37990 int (*fn)(struct drbd_connection *, struct packet_info *);
37991-};
37992+} __do_const;
37993
37994 static struct data_cmd drbd_cmd_handler[] = {
37995 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37996@@ -4506,7 +4506,7 @@ static void conn_disconnect(struct drbd_connection *connection)
37997 if (!list_empty(&connection->current_epoch->list))
37998 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
37999 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38000- atomic_set(&connection->current_epoch->epoch_size, 0);
38001+ atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38002 connection->send.seen_any_write_yet = false;
38003
38004 drbd_info(connection, "Connection closed\n");
38005@@ -5281,7 +5281,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38006 struct asender_cmd {
38007 size_t pkt_size;
38008 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38009-};
38010+} __do_const;
38011
38012 static struct asender_cmd asender_tbl[] = {
38013 [P_PING] = { 0, got_Ping },
38014diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38015index f70a230..9dc90d5 100644
38016--- a/drivers/block/loop.c
38017+++ b/drivers/block/loop.c
38018@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38019
38020 file_start_write(file);
38021 set_fs(get_ds());
38022- bw = file->f_op->write(file, buf, len, &pos);
38023+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38024 set_fs(old_fs);
38025 file_end_write(file);
38026 if (likely(bw == len))
38027diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
38028index 091b9ea..f5428f8 100644
38029--- a/drivers/block/null_blk.c
38030+++ b/drivers/block/null_blk.c
38031@@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
38032 return 0;
38033 }
38034
38035-static struct blk_mq_ops null_mq_ops = {
38036- .queue_rq = null_queue_rq,
38037- .map_queue = blk_mq_map_queue,
38038+static struct blk_mq_ops null_mq_single_ops = {
38039+ .queue_rq = null_queue_rq,
38040+ .map_queue = blk_mq_map_queue,
38041 .init_hctx = null_init_hctx,
38042 .complete = null_softirq_done_fn,
38043+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
38044+ .free_hctx = blk_mq_free_single_hw_queue,
38045+};
38046+
38047+static struct blk_mq_ops null_mq_per_node_ops = {
38048+ .queue_rq = null_queue_rq,
38049+ .map_queue = blk_mq_map_queue,
38050+ .init_hctx = null_init_hctx,
38051+ .alloc_hctx = null_alloc_hctx,
38052+ .free_hctx = null_free_hctx,
38053 };
38054
38055 static struct blk_mq_reg null_mq_reg = {
38056- .ops = &null_mq_ops,
38057+ .ops = &null_mq_single_ops,
38058 .queue_depth = 64,
38059 .cmd_size = sizeof(struct nullb_cmd),
38060 .flags = BLK_MQ_F_SHOULD_MERGE,
38061@@ -521,13 +531,8 @@ static int null_add_dev(void)
38062 null_mq_reg.queue_depth = hw_queue_depth;
38063 null_mq_reg.nr_hw_queues = submit_queues;
38064
38065- if (use_per_node_hctx) {
38066- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
38067- null_mq_reg.ops->free_hctx = null_free_hctx;
38068- } else {
38069- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
38070- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
38071- }
38072+ if (use_per_node_hctx)
38073+ null_mq_reg.ops = &null_mq_per_node_ops;
38074
38075 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
38076 } else if (queue_mode == NULL_Q_BIO) {
38077diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38078index a2af73d..c0b8f61 100644
38079--- a/drivers/block/pktcdvd.c
38080+++ b/drivers/block/pktcdvd.c
38081@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38082
38083 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38084 {
38085- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38086+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38087 }
38088
38089 /*
38090@@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38091 return -EROFS;
38092 }
38093 pd->settings.fp = ti.fp;
38094- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38095+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38096
38097 if (ti.nwa_v) {
38098 pd->nwa = be32_to_cpu(ti.next_writable);
38099diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38100index e5565fb..71be10b4 100644
38101--- a/drivers/block/smart1,2.h
38102+++ b/drivers/block/smart1,2.h
38103@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38104 }
38105
38106 static struct access_method smart4_access = {
38107- smart4_submit_command,
38108- smart4_intr_mask,
38109- smart4_fifo_full,
38110- smart4_intr_pending,
38111- smart4_completed,
38112+ .submit_command = smart4_submit_command,
38113+ .set_intr_mask = smart4_intr_mask,
38114+ .fifo_full = smart4_fifo_full,
38115+ .intr_pending = smart4_intr_pending,
38116+ .command_completed = smart4_completed,
38117 };
38118
38119 /*
38120@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38121 }
38122
38123 static struct access_method smart2_access = {
38124- smart2_submit_command,
38125- smart2_intr_mask,
38126- smart2_fifo_full,
38127- smart2_intr_pending,
38128- smart2_completed,
38129+ .submit_command = smart2_submit_command,
38130+ .set_intr_mask = smart2_intr_mask,
38131+ .fifo_full = smart2_fifo_full,
38132+ .intr_pending = smart2_intr_pending,
38133+ .command_completed = smart2_completed,
38134 };
38135
38136 /*
38137@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38138 }
38139
38140 static struct access_method smart2e_access = {
38141- smart2e_submit_command,
38142- smart2e_intr_mask,
38143- smart2e_fifo_full,
38144- smart2e_intr_pending,
38145- smart2e_completed,
38146+ .submit_command = smart2e_submit_command,
38147+ .set_intr_mask = smart2e_intr_mask,
38148+ .fifo_full = smart2e_fifo_full,
38149+ .intr_pending = smart2e_intr_pending,
38150+ .command_completed = smart2e_completed,
38151 };
38152
38153 /*
38154@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38155 }
38156
38157 static struct access_method smart1_access = {
38158- smart1_submit_command,
38159- smart1_intr_mask,
38160- smart1_fifo_full,
38161- smart1_intr_pending,
38162- smart1_completed,
38163+ .submit_command = smart1_submit_command,
38164+ .set_intr_mask = smart1_intr_mask,
38165+ .fifo_full = smart1_fifo_full,
38166+ .intr_pending = smart1_intr_pending,
38167+ .command_completed = smart1_completed,
38168 };
38169diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38170index f038dba..bb74c08 100644
38171--- a/drivers/bluetooth/btwilink.c
38172+++ b/drivers/bluetooth/btwilink.c
38173@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38174
38175 static int bt_ti_probe(struct platform_device *pdev)
38176 {
38177- static struct ti_st *hst;
38178+ struct ti_st *hst;
38179 struct hci_dev *hdev;
38180 int err;
38181
38182diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38183index 8a3aff7..d7538c2 100644
38184--- a/drivers/cdrom/cdrom.c
38185+++ b/drivers/cdrom/cdrom.c
38186@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38187 ENSURE(reset, CDC_RESET);
38188 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38189 cdi->mc_flags = 0;
38190- cdo->n_minors = 0;
38191 cdi->options = CDO_USE_FFLAGS;
38192
38193 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38194@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38195 else
38196 cdi->cdda_method = CDDA_OLD;
38197
38198- if (!cdo->generic_packet)
38199- cdo->generic_packet = cdrom_dummy_generic_packet;
38200+ if (!cdo->generic_packet) {
38201+ pax_open_kernel();
38202+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38203+ pax_close_kernel();
38204+ }
38205
38206 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38207 mutex_lock(&cdrom_mutex);
38208@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38209 if (cdi->exit)
38210 cdi->exit(cdi);
38211
38212- cdi->ops->n_minors--;
38213 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38214 }
38215
38216@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38217 */
38218 nr = nframes;
38219 do {
38220- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38221+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38222 if (cgc.buffer)
38223 break;
38224
38225@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38226 struct cdrom_device_info *cdi;
38227 int ret;
38228
38229- ret = scnprintf(info + *pos, max_size - *pos, header);
38230+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38231 if (!ret)
38232 return 1;
38233
38234diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38235index 51e75ad..39c4c76 100644
38236--- a/drivers/cdrom/gdrom.c
38237+++ b/drivers/cdrom/gdrom.c
38238@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38239 .audio_ioctl = gdrom_audio_ioctl,
38240 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38241 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38242- .n_minors = 1,
38243 };
38244
38245 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38246diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38247index 6e9f74a..50c7ceae 100644
38248--- a/drivers/char/Kconfig
38249+++ b/drivers/char/Kconfig
38250@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38251
38252 config DEVKMEM
38253 bool "/dev/kmem virtual device support"
38254- default y
38255+ default n
38256+ depends on !GRKERNSEC_KMEM
38257 help
38258 Say Y here if you want to support the /dev/kmem device. The
38259 /dev/kmem device is rarely used, but can be used for certain
38260@@ -577,6 +578,7 @@ config DEVPORT
38261 bool
38262 depends on !M68K
38263 depends on ISA || PCI
38264+ depends on !GRKERNSEC_KMEM
38265 default y
38266
38267 source "drivers/s390/char/Kconfig"
38268diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38269index a48e05b..6bac831 100644
38270--- a/drivers/char/agp/compat_ioctl.c
38271+++ b/drivers/char/agp/compat_ioctl.c
38272@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38273 return -ENOMEM;
38274 }
38275
38276- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38277+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38278 sizeof(*usegment) * ureserve.seg_count)) {
38279 kfree(usegment);
38280 kfree(ksegment);
38281diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38282index b297033..fa217ca 100644
38283--- a/drivers/char/agp/frontend.c
38284+++ b/drivers/char/agp/frontend.c
38285@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38286 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38287 return -EFAULT;
38288
38289- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38290+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38291 return -EFAULT;
38292
38293 client = agp_find_client_by_pid(reserve.pid);
38294@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38295 if (segment == NULL)
38296 return -ENOMEM;
38297
38298- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38299+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38300 sizeof(struct agp_segment) * reserve.seg_count)) {
38301 kfree(segment);
38302 return -EFAULT;
38303diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38304index 4f94375..413694e 100644
38305--- a/drivers/char/genrtc.c
38306+++ b/drivers/char/genrtc.c
38307@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38308 switch (cmd) {
38309
38310 case RTC_PLL_GET:
38311+ memset(&pll, 0, sizeof(pll));
38312 if (get_rtc_pll(&pll))
38313 return -EINVAL;
38314 else
38315diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38316index d5d4cd8..22d561d 100644
38317--- a/drivers/char/hpet.c
38318+++ b/drivers/char/hpet.c
38319@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38320 }
38321
38322 static int
38323-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38324+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38325 struct hpet_info *info)
38326 {
38327 struct hpet_timer __iomem *timer;
38328diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38329index 86fe45c..c0ea948 100644
38330--- a/drivers/char/hw_random/intel-rng.c
38331+++ b/drivers/char/hw_random/intel-rng.c
38332@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38333
38334 if (no_fwh_detect)
38335 return -ENODEV;
38336- printk(warning);
38337+ printk("%s", warning);
38338 return -EBUSY;
38339 }
38340
38341diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38342index e6db938..835e3a2 100644
38343--- a/drivers/char/ipmi/ipmi_msghandler.c
38344+++ b/drivers/char/ipmi/ipmi_msghandler.c
38345@@ -438,7 +438,7 @@ struct ipmi_smi {
38346 struct proc_dir_entry *proc_dir;
38347 char proc_dir_name[10];
38348
38349- atomic_t stats[IPMI_NUM_STATS];
38350+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38351
38352 /*
38353 * run_to_completion duplicate of smb_info, smi_info
38354@@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38355 static DEFINE_MUTEX(smi_watchers_mutex);
38356
38357 #define ipmi_inc_stat(intf, stat) \
38358- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38359+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38360 #define ipmi_get_stat(intf, stat) \
38361- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38362+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38363
38364 static int is_lan_addr(struct ipmi_addr *addr)
38365 {
38366@@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38367 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38368 init_waitqueue_head(&intf->waitq);
38369 for (i = 0; i < IPMI_NUM_STATS; i++)
38370- atomic_set(&intf->stats[i], 0);
38371+ atomic_set_unchecked(&intf->stats[i], 0);
38372
38373 intf->proc_dir = NULL;
38374
38375diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38376index 1c4bb4f..719e873 100644
38377--- a/drivers/char/ipmi/ipmi_si_intf.c
38378+++ b/drivers/char/ipmi/ipmi_si_intf.c
38379@@ -285,7 +285,7 @@ struct smi_info {
38380 unsigned char slave_addr;
38381
38382 /* Counters and things for the proc filesystem. */
38383- atomic_t stats[SI_NUM_STATS];
38384+ atomic_unchecked_t stats[SI_NUM_STATS];
38385
38386 struct task_struct *thread;
38387
38388@@ -294,9 +294,9 @@ struct smi_info {
38389 };
38390
38391 #define smi_inc_stat(smi, stat) \
38392- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38393+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38394 #define smi_get_stat(smi, stat) \
38395- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38396+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38397
38398 #define SI_MAX_PARMS 4
38399
38400@@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
38401 atomic_set(&new_smi->req_events, 0);
38402 new_smi->run_to_completion = false;
38403 for (i = 0; i < SI_NUM_STATS; i++)
38404- atomic_set(&new_smi->stats[i], 0);
38405+ atomic_set_unchecked(&new_smi->stats[i], 0);
38406
38407 new_smi->interrupt_disabled = true;
38408 atomic_set(&new_smi->stop_operation, 0);
38409diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38410index 917403f..dddd899 100644
38411--- a/drivers/char/mem.c
38412+++ b/drivers/char/mem.c
38413@@ -18,6 +18,7 @@
38414 #include <linux/raw.h>
38415 #include <linux/tty.h>
38416 #include <linux/capability.h>
38417+#include <linux/security.h>
38418 #include <linux/ptrace.h>
38419 #include <linux/device.h>
38420 #include <linux/highmem.h>
38421@@ -36,6 +37,10 @@
38422
38423 #define DEVPORT_MINOR 4
38424
38425+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38426+extern const struct file_operations grsec_fops;
38427+#endif
38428+
38429 static inline unsigned long size_inside_page(unsigned long start,
38430 unsigned long size)
38431 {
38432@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38433
38434 while (cursor < to) {
38435 if (!devmem_is_allowed(pfn)) {
38436+#ifdef CONFIG_GRKERNSEC_KMEM
38437+ gr_handle_mem_readwrite(from, to);
38438+#else
38439 printk(KERN_INFO
38440 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38441 current->comm, from, to);
38442+#endif
38443 return 0;
38444 }
38445 cursor += PAGE_SIZE;
38446@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38447 }
38448 return 1;
38449 }
38450+#elif defined(CONFIG_GRKERNSEC_KMEM)
38451+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38452+{
38453+ return 0;
38454+}
38455 #else
38456 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38457 {
38458@@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38459
38460 while (count > 0) {
38461 unsigned long remaining;
38462+ char *temp;
38463
38464 sz = size_inside_page(p, count);
38465
38466@@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38467 if (!ptr)
38468 return -EFAULT;
38469
38470- remaining = copy_to_user(buf, ptr, sz);
38471+#ifdef CONFIG_PAX_USERCOPY
38472+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38473+ if (!temp) {
38474+ unxlate_dev_mem_ptr(p, ptr);
38475+ return -ENOMEM;
38476+ }
38477+ memcpy(temp, ptr, sz);
38478+#else
38479+ temp = ptr;
38480+#endif
38481+
38482+ remaining = copy_to_user(buf, temp, sz);
38483+
38484+#ifdef CONFIG_PAX_USERCOPY
38485+ kfree(temp);
38486+#endif
38487+
38488 unxlate_dev_mem_ptr(p, ptr);
38489 if (remaining)
38490 return -EFAULT;
38491@@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38492 size_t count, loff_t *ppos)
38493 {
38494 unsigned long p = *ppos;
38495- ssize_t low_count, read, sz;
38496+ ssize_t low_count, read, sz, err = 0;
38497 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38498- int err = 0;
38499
38500 read = 0;
38501 if (p < (unsigned long) high_memory) {
38502@@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38503 }
38504 #endif
38505 while (low_count > 0) {
38506+ char *temp;
38507+
38508 sz = size_inside_page(p, low_count);
38509
38510 /*
38511@@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38512 */
38513 kbuf = xlate_dev_kmem_ptr((char *)p);
38514
38515- if (copy_to_user(buf, kbuf, sz))
38516+#ifdef CONFIG_PAX_USERCOPY
38517+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38518+ if (!temp)
38519+ return -ENOMEM;
38520+ memcpy(temp, kbuf, sz);
38521+#else
38522+ temp = kbuf;
38523+#endif
38524+
38525+ err = copy_to_user(buf, temp, sz);
38526+
38527+#ifdef CONFIG_PAX_USERCOPY
38528+ kfree(temp);
38529+#endif
38530+
38531+ if (err)
38532 return -EFAULT;
38533 buf += sz;
38534 p += sz;
38535@@ -827,6 +874,9 @@ static const struct memdev {
38536 #ifdef CONFIG_PRINTK
38537 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38538 #endif
38539+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38540+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38541+#endif
38542 };
38543
38544 static int memory_open(struct inode *inode, struct file *filp)
38545@@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
38546 continue;
38547
38548 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38549- NULL, devlist[minor].name);
38550+ NULL, "%s", devlist[minor].name);
38551 }
38552
38553 return tty_init();
38554diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38555index 9df78e2..01ba9ae 100644
38556--- a/drivers/char/nvram.c
38557+++ b/drivers/char/nvram.c
38558@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38559
38560 spin_unlock_irq(&rtc_lock);
38561
38562- if (copy_to_user(buf, contents, tmp - contents))
38563+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38564 return -EFAULT;
38565
38566 *ppos = i;
38567diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38568index 8320abd..ec48108 100644
38569--- a/drivers/char/pcmcia/synclink_cs.c
38570+++ b/drivers/char/pcmcia/synclink_cs.c
38571@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38572
38573 if (debug_level >= DEBUG_LEVEL_INFO)
38574 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38575- __FILE__, __LINE__, info->device_name, port->count);
38576+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38577
38578- WARN_ON(!port->count);
38579+ WARN_ON(!atomic_read(&port->count));
38580
38581 if (tty_port_close_start(port, tty, filp) == 0)
38582 goto cleanup;
38583@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38584 cleanup:
38585 if (debug_level >= DEBUG_LEVEL_INFO)
38586 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38587- tty->driver->name, port->count);
38588+ tty->driver->name, atomic_read(&port->count));
38589 }
38590
38591 /* Wait until the transmitter is empty.
38592@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38593
38594 if (debug_level >= DEBUG_LEVEL_INFO)
38595 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38596- __FILE__, __LINE__, tty->driver->name, port->count);
38597+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38598
38599 /* If port is closing, signal caller to try again */
38600 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38601@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38602 goto cleanup;
38603 }
38604 spin_lock(&port->lock);
38605- port->count++;
38606+ atomic_inc(&port->count);
38607 spin_unlock(&port->lock);
38608 spin_unlock_irqrestore(&info->netlock, flags);
38609
38610- if (port->count == 1) {
38611+ if (atomic_read(&port->count) == 1) {
38612 /* 1st open on this device, init hardware */
38613 retval = startup(info, tty);
38614 if (retval < 0)
38615@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38616 unsigned short new_crctype;
38617
38618 /* return error if TTY interface open */
38619- if (info->port.count)
38620+ if (atomic_read(&info->port.count))
38621 return -EBUSY;
38622
38623 switch (encoding)
38624@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38625
38626 /* arbitrate between network and tty opens */
38627 spin_lock_irqsave(&info->netlock, flags);
38628- if (info->port.count != 0 || info->netcount != 0) {
38629+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38630 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38631 spin_unlock_irqrestore(&info->netlock, flags);
38632 return -EBUSY;
38633@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38634 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38635
38636 /* return error if TTY interface open */
38637- if (info->port.count)
38638+ if (atomic_read(&info->port.count))
38639 return -EBUSY;
38640
38641 if (cmd != SIOCWANDEV)
38642diff --git a/drivers/char/random.c b/drivers/char/random.c
38643index 102c50d..1295f12 100644
38644--- a/drivers/char/random.c
38645+++ b/drivers/char/random.c
38646@@ -270,10 +270,17 @@
38647 /*
38648 * Configuration information
38649 */
38650+#ifdef CONFIG_GRKERNSEC_RANDNET
38651+#define INPUT_POOL_SHIFT 14
38652+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38653+#define OUTPUT_POOL_SHIFT 12
38654+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38655+#else
38656 #define INPUT_POOL_SHIFT 12
38657 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38658 #define OUTPUT_POOL_SHIFT 10
38659 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38660+#endif
38661 #define SEC_XFER_SIZE 512
38662 #define EXTRACT_SIZE 10
38663
38664@@ -284,9 +291,6 @@
38665 /*
38666 * To allow fractional bits to be tracked, the entropy_count field is
38667 * denominated in units of 1/8th bits.
38668- *
38669- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38670- * credit_entropy_bits() needs to be 64 bits wide.
38671 */
38672 #define ENTROPY_SHIFT 3
38673 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38674@@ -361,12 +365,19 @@ static struct poolinfo {
38675 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38676 int tap1, tap2, tap3, tap4, tap5;
38677 } poolinfo_table[] = {
38678+#ifdef CONFIG_GRKERNSEC_RANDNET
38679+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38680+ { S(512), 411, 308, 208, 104, 1 },
38681+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38682+ { S(128), 104, 76, 51, 25, 1 },
38683+#else
38684 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38685 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38686 { S(128), 104, 76, 51, 25, 1 },
38687 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38688 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38689 { S(32), 26, 19, 14, 7, 1 },
38690+#endif
38691 #if 0
38692 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38693 { S(2048), 1638, 1231, 819, 411, 1 },
38694@@ -433,9 +444,9 @@ struct entropy_store {
38695 };
38696
38697 static void push_to_pool(struct work_struct *work);
38698-static __u32 input_pool_data[INPUT_POOL_WORDS];
38699-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38700-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38701+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38702+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38703+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38704
38705 static struct entropy_store input_pool = {
38706 .poolinfo = &poolinfo_table[0],
38707@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38708 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38709 }
38710
38711- ACCESS_ONCE(r->input_rotate) = input_rotate;
38712- ACCESS_ONCE(r->add_ptr) = i;
38713+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38714+ ACCESS_ONCE_RW(r->add_ptr) = i;
38715 smp_wmb();
38716
38717 if (out)
38718@@ -632,7 +643,7 @@ retry:
38719 /* The +2 corresponds to the /4 in the denominator */
38720
38721 do {
38722- unsigned int anfrac = min(pnfrac, pool_size/2);
38723+ u64 anfrac = min(pnfrac, pool_size/2);
38724 unsigned int add =
38725 ((pool_size - entropy_count)*anfrac*3) >> s;
38726
38727@@ -1165,7 +1176,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38728
38729 extract_buf(r, tmp);
38730 i = min_t(int, nbytes, EXTRACT_SIZE);
38731- if (copy_to_user(buf, tmp, i)) {
38732+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38733 ret = -EFAULT;
38734 break;
38735 }
38736@@ -1554,7 +1565,7 @@ static char sysctl_bootid[16];
38737 static int proc_do_uuid(struct ctl_table *table, int write,
38738 void __user *buffer, size_t *lenp, loff_t *ppos)
38739 {
38740- struct ctl_table fake_table;
38741+ ctl_table_no_const fake_table;
38742 unsigned char buf[64], tmp_uuid[16], *uuid;
38743
38744 uuid = table->data;
38745@@ -1584,7 +1595,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38746 static int proc_do_entropy(ctl_table *table, int write,
38747 void __user *buffer, size_t *lenp, loff_t *ppos)
38748 {
38749- ctl_table fake_table;
38750+ ctl_table_no_const fake_table;
38751 int entropy_count;
38752
38753 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38754diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38755index 7cc1fe22..b602d6b 100644
38756--- a/drivers/char/sonypi.c
38757+++ b/drivers/char/sonypi.c
38758@@ -54,6 +54,7 @@
38759
38760 #include <asm/uaccess.h>
38761 #include <asm/io.h>
38762+#include <asm/local.h>
38763
38764 #include <linux/sonypi.h>
38765
38766@@ -490,7 +491,7 @@ static struct sonypi_device {
38767 spinlock_t fifo_lock;
38768 wait_queue_head_t fifo_proc_list;
38769 struct fasync_struct *fifo_async;
38770- int open_count;
38771+ local_t open_count;
38772 int model;
38773 struct input_dev *input_jog_dev;
38774 struct input_dev *input_key_dev;
38775@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38776 static int sonypi_misc_release(struct inode *inode, struct file *file)
38777 {
38778 mutex_lock(&sonypi_device.lock);
38779- sonypi_device.open_count--;
38780+ local_dec(&sonypi_device.open_count);
38781 mutex_unlock(&sonypi_device.lock);
38782 return 0;
38783 }
38784@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38785 {
38786 mutex_lock(&sonypi_device.lock);
38787 /* Flush input queue on first open */
38788- if (!sonypi_device.open_count)
38789+ if (!local_read(&sonypi_device.open_count))
38790 kfifo_reset(&sonypi_device.fifo);
38791- sonypi_device.open_count++;
38792+ local_inc(&sonypi_device.open_count);
38793 mutex_unlock(&sonypi_device.lock);
38794
38795 return 0;
38796diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38797index b9a57fa..5bb9e38 100644
38798--- a/drivers/char/tpm/tpm_acpi.c
38799+++ b/drivers/char/tpm/tpm_acpi.c
38800@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38801 virt = acpi_os_map_memory(start, len);
38802 if (!virt) {
38803 kfree(log->bios_event_log);
38804+ log->bios_event_log = NULL;
38805 printk("%s: ERROR - Unable to map memory\n", __func__);
38806 return -EIO;
38807 }
38808
38809- memcpy_fromio(log->bios_event_log, virt, len);
38810+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38811
38812 acpi_os_unmap_memory(virt, len);
38813 return 0;
38814diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38815index 59f7cb2..bac8b6d 100644
38816--- a/drivers/char/tpm/tpm_eventlog.c
38817+++ b/drivers/char/tpm/tpm_eventlog.c
38818@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38819 event = addr;
38820
38821 if ((event->event_type == 0 && event->event_size == 0) ||
38822- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38823+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38824 return NULL;
38825
38826 return addr;
38827@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38828 return NULL;
38829
38830 if ((event->event_type == 0 && event->event_size == 0) ||
38831- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38832+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38833 return NULL;
38834
38835 (*pos)++;
38836@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38837 int i;
38838
38839 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38840- seq_putc(m, data[i]);
38841+ if (!seq_putc(m, data[i]))
38842+ return -EFAULT;
38843
38844 return 0;
38845 }
38846diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38847index 60aafb8..10c08e0 100644
38848--- a/drivers/char/virtio_console.c
38849+++ b/drivers/char/virtio_console.c
38850@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38851 if (to_user) {
38852 ssize_t ret;
38853
38854- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38855+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38856 if (ret)
38857 return -EFAULT;
38858 } else {
38859@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38860 if (!port_has_data(port) && !port->host_connected)
38861 return 0;
38862
38863- return fill_readbuf(port, ubuf, count, true);
38864+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38865 }
38866
38867 static int wait_port_writable(struct port *port, bool nonblock)
38868diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38869index 57a078e..c17cde8 100644
38870--- a/drivers/clk/clk-composite.c
38871+++ b/drivers/clk/clk-composite.c
38872@@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38873 struct clk *clk;
38874 struct clk_init_data init;
38875 struct clk_composite *composite;
38876- struct clk_ops *clk_composite_ops;
38877+ clk_ops_no_const *clk_composite_ops;
38878
38879 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38880 if (!composite) {
38881diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
38882index 501d513..fb0ecf9 100644
38883--- a/drivers/clk/socfpga/clk-gate.c
38884+++ b/drivers/clk/socfpga/clk-gate.c
38885@@ -22,6 +22,7 @@
38886 #include <linux/mfd/syscon.h>
38887 #include <linux/of.h>
38888 #include <linux/regmap.h>
38889+#include <asm/pgtable.h>
38890
38891 #include "clk.h"
38892
38893@@ -175,7 +176,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
38894 return 0;
38895 }
38896
38897-static struct clk_ops gateclk_ops = {
38898+static clk_ops_no_const gateclk_ops __read_only = {
38899 .prepare = socfpga_clk_prepare,
38900 .recalc_rate = socfpga_clk_recalc_rate,
38901 .get_parent = socfpga_clk_get_parent,
38902@@ -209,8 +210,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
38903 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
38904 socfpga_clk->hw.bit_idx = clk_gate[1];
38905
38906- gateclk_ops.enable = clk_gate_ops.enable;
38907- gateclk_ops.disable = clk_gate_ops.disable;
38908+ pax_open_kernel();
38909+ *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
38910+ *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
38911+ pax_close_kernel();
38912 }
38913
38914 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
38915diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
38916index de6da95..a2e72c0 100644
38917--- a/drivers/clk/socfpga/clk-pll.c
38918+++ b/drivers/clk/socfpga/clk-pll.c
38919@@ -21,6 +21,7 @@
38920 #include <linux/io.h>
38921 #include <linux/of.h>
38922 #include <linux/of_address.h>
38923+#include <asm/pgtable.h>
38924
38925 #include "clk.h"
38926
38927@@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
38928 CLK_MGR_PLL_CLK_SRC_MASK;
38929 }
38930
38931-static struct clk_ops clk_pll_ops = {
38932+static struct clk_ops_no_const clk_pll_ops __read_only = {
38933 .recalc_rate = clk_pll_recalc_rate,
38934 .get_parent = clk_pll_get_parent,
38935 };
38936@@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
38937 pll_clk->hw.hw.init = &init;
38938
38939 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38940- clk_pll_ops.enable = clk_gate_ops.enable;
38941- clk_pll_ops.disable = clk_gate_ops.disable;
38942+ pax_open_kernel();
38943+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38944+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38945+ pax_close_kernel();
38946
38947 clk = clk_register(NULL, &pll_clk->hw.hw);
38948 if (WARN_ON(IS_ERR(clk))) {
38949diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38950index 000e4e0..4770351 100644
38951--- a/drivers/cpufreq/acpi-cpufreq.c
38952+++ b/drivers/cpufreq/acpi-cpufreq.c
38953@@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38954 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38955 per_cpu(acfreq_data, cpu) = data;
38956
38957- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38958- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38959+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38960+ pax_open_kernel();
38961+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38962+ pax_close_kernel();
38963+ }
38964
38965 result = acpi_processor_register_performance(data->acpi_data, cpu);
38966 if (result)
38967@@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38968 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38969 break;
38970 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38971- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38972+ pax_open_kernel();
38973+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38974+ pax_close_kernel();
38975 break;
38976 default:
38977 break;
38978@@ -904,8 +909,10 @@ static void __init acpi_cpufreq_boost_init(void)
38979 if (!msrs)
38980 return;
38981
38982- acpi_cpufreq_driver.boost_supported = true;
38983- acpi_cpufreq_driver.boost_enabled = boost_state(0);
38984+ pax_open_kernel();
38985+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
38986+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
38987+ pax_close_kernel();
38988
38989 cpu_notifier_register_begin();
38990
38991diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38992index abda660..f1d1de0 100644
38993--- a/drivers/cpufreq/cpufreq.c
38994+++ b/drivers/cpufreq/cpufreq.c
38995@@ -2022,7 +2022,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38996 }
38997
38998 mutex_lock(&cpufreq_governor_mutex);
38999- list_del(&governor->governor_list);
39000+ pax_list_del(&governor->governor_list);
39001 mutex_unlock(&cpufreq_governor_mutex);
39002 return;
39003 }
39004@@ -2240,7 +2240,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39005 return NOTIFY_OK;
39006 }
39007
39008-static struct notifier_block __refdata cpufreq_cpu_notifier = {
39009+static struct notifier_block cpufreq_cpu_notifier = {
39010 .notifier_call = cpufreq_cpu_callback,
39011 };
39012
39013@@ -2280,13 +2280,17 @@ int cpufreq_boost_trigger_state(int state)
39014 return 0;
39015
39016 write_lock_irqsave(&cpufreq_driver_lock, flags);
39017- cpufreq_driver->boost_enabled = state;
39018+ pax_open_kernel();
39019+ *(bool *)&cpufreq_driver->boost_enabled = state;
39020+ pax_close_kernel();
39021 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39022
39023 ret = cpufreq_driver->set_boost(state);
39024 if (ret) {
39025 write_lock_irqsave(&cpufreq_driver_lock, flags);
39026- cpufreq_driver->boost_enabled = !state;
39027+ pax_open_kernel();
39028+ *(bool *)&cpufreq_driver->boost_enabled = !state;
39029+ pax_close_kernel();
39030 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39031
39032 pr_err("%s: Cannot %s BOOST\n",
39033@@ -2342,8 +2346,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39034
39035 pr_debug("trying to register driver %s\n", driver_data->name);
39036
39037- if (driver_data->setpolicy)
39038- driver_data->flags |= CPUFREQ_CONST_LOOPS;
39039+ if (driver_data->setpolicy) {
39040+ pax_open_kernel();
39041+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39042+ pax_close_kernel();
39043+ }
39044
39045 write_lock_irqsave(&cpufreq_driver_lock, flags);
39046 if (cpufreq_driver) {
39047@@ -2358,8 +2365,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39048 * Check if driver provides function to enable boost -
39049 * if not, use cpufreq_boost_set_sw as default
39050 */
39051- if (!cpufreq_driver->set_boost)
39052- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39053+ if (!cpufreq_driver->set_boost) {
39054+ pax_open_kernel();
39055+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39056+ pax_close_kernel();
39057+ }
39058
39059 ret = cpufreq_sysfs_create_file(&boost.attr);
39060 if (ret) {
39061diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39062index e1c6433..31203ae 100644
39063--- a/drivers/cpufreq/cpufreq_governor.c
39064+++ b/drivers/cpufreq/cpufreq_governor.c
39065@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39066 struct dbs_data *dbs_data;
39067 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39068 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39069- struct od_ops *od_ops = NULL;
39070+ const struct od_ops *od_ops = NULL;
39071 struct od_dbs_tuners *od_tuners = NULL;
39072 struct cs_dbs_tuners *cs_tuners = NULL;
39073 struct cpu_dbs_common_info *cpu_cdbs;
39074@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39075
39076 if ((cdata->governor == GOV_CONSERVATIVE) &&
39077 (!policy->governor->initialized)) {
39078- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39079+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39080
39081 cpufreq_register_notifier(cs_ops->notifier_block,
39082 CPUFREQ_TRANSITION_NOTIFIER);
39083@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39084
39085 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39086 (policy->governor->initialized == 1)) {
39087- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39088+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39089
39090 cpufreq_unregister_notifier(cs_ops->notifier_block,
39091 CPUFREQ_TRANSITION_NOTIFIER);
39092diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39093index bfb9ae1..e1d3a7e 100644
39094--- a/drivers/cpufreq/cpufreq_governor.h
39095+++ b/drivers/cpufreq/cpufreq_governor.h
39096@@ -205,7 +205,7 @@ struct common_dbs_data {
39097 void (*exit)(struct dbs_data *dbs_data);
39098
39099 /* Governor specific ops, see below */
39100- void *gov_ops;
39101+ const void *gov_ops;
39102 };
39103
39104 /* Governor Per policy data */
39105@@ -225,7 +225,7 @@ struct od_ops {
39106 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39107 unsigned int freq_next, unsigned int relation);
39108 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39109-};
39110+} __no_const;
39111
39112 struct cs_ops {
39113 struct notifier_block *notifier_block;
39114diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39115index 18d4091..434be15 100644
39116--- a/drivers/cpufreq/cpufreq_ondemand.c
39117+++ b/drivers/cpufreq/cpufreq_ondemand.c
39118@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39119
39120 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39121
39122-static struct od_ops od_ops = {
39123+static struct od_ops od_ops __read_only = {
39124 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39125 .powersave_bias_target = generic_powersave_bias_target,
39126 .freq_increase = dbs_freq_increase,
39127@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39128 (struct cpufreq_policy *, unsigned int, unsigned int),
39129 unsigned int powersave_bias)
39130 {
39131- od_ops.powersave_bias_target = f;
39132+ pax_open_kernel();
39133+ *(void **)&od_ops.powersave_bias_target = f;
39134+ pax_close_kernel();
39135 od_set_powersave_bias(powersave_bias);
39136 }
39137 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39138
39139 void od_unregister_powersave_bias_handler(void)
39140 {
39141- od_ops.powersave_bias_target = generic_powersave_bias_target;
39142+ pax_open_kernel();
39143+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39144+ pax_close_kernel();
39145 od_set_powersave_bias(0);
39146 }
39147 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39148diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39149index db2e45b..72c7d37 100644
39150--- a/drivers/cpufreq/intel_pstate.c
39151+++ b/drivers/cpufreq/intel_pstate.c
39152@@ -125,10 +125,10 @@ struct pstate_funcs {
39153 struct cpu_defaults {
39154 struct pstate_adjust_policy pid_policy;
39155 struct pstate_funcs funcs;
39156-};
39157+} __do_const;
39158
39159 static struct pstate_adjust_policy pid_params;
39160-static struct pstate_funcs pstate_funcs;
39161+static struct pstate_funcs *pstate_funcs;
39162
39163 struct perf_limits {
39164 int no_turbo;
39165@@ -529,7 +529,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39166
39167 cpu->pstate.current_pstate = pstate;
39168
39169- pstate_funcs.set(cpu, pstate);
39170+ pstate_funcs->set(cpu, pstate);
39171 }
39172
39173 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39174@@ -551,12 +551,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39175 {
39176 sprintf(cpu->name, "Intel 2nd generation core");
39177
39178- cpu->pstate.min_pstate = pstate_funcs.get_min();
39179- cpu->pstate.max_pstate = pstate_funcs.get_max();
39180- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39181+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39182+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39183+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39184
39185- if (pstate_funcs.get_vid)
39186- pstate_funcs.get_vid(cpu);
39187+ if (pstate_funcs->get_vid)
39188+ pstate_funcs->get_vid(cpu);
39189 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39190 }
39191
39192@@ -841,9 +841,9 @@ static int intel_pstate_msrs_not_valid(void)
39193 rdmsrl(MSR_IA32_APERF, aperf);
39194 rdmsrl(MSR_IA32_MPERF, mperf);
39195
39196- if (!pstate_funcs.get_max() ||
39197- !pstate_funcs.get_min() ||
39198- !pstate_funcs.get_turbo())
39199+ if (!pstate_funcs->get_max() ||
39200+ !pstate_funcs->get_min() ||
39201+ !pstate_funcs->get_turbo())
39202 return -ENODEV;
39203
39204 rdmsrl(MSR_IA32_APERF, tmp);
39205@@ -857,7 +857,7 @@ static int intel_pstate_msrs_not_valid(void)
39206 return 0;
39207 }
39208
39209-static void copy_pid_params(struct pstate_adjust_policy *policy)
39210+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39211 {
39212 pid_params.sample_rate_ms = policy->sample_rate_ms;
39213 pid_params.p_gain_pct = policy->p_gain_pct;
39214@@ -869,11 +869,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39215
39216 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39217 {
39218- pstate_funcs.get_max = funcs->get_max;
39219- pstate_funcs.get_min = funcs->get_min;
39220- pstate_funcs.get_turbo = funcs->get_turbo;
39221- pstate_funcs.set = funcs->set;
39222- pstate_funcs.get_vid = funcs->get_vid;
39223+ pstate_funcs = funcs;
39224 }
39225
39226 #if IS_ENABLED(CONFIG_ACPI)
39227diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39228index 529cfd9..0e28fff 100644
39229--- a/drivers/cpufreq/p4-clockmod.c
39230+++ b/drivers/cpufreq/p4-clockmod.c
39231@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39232 case 0x0F: /* Core Duo */
39233 case 0x16: /* Celeron Core */
39234 case 0x1C: /* Atom */
39235- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39236+ pax_open_kernel();
39237+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39238+ pax_close_kernel();
39239 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39240 case 0x0D: /* Pentium M (Dothan) */
39241- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39242+ pax_open_kernel();
39243+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39244+ pax_close_kernel();
39245 /* fall through */
39246 case 0x09: /* Pentium M (Banias) */
39247 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39248@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39249
39250 /* on P-4s, the TSC runs with constant frequency independent whether
39251 * throttling is active or not. */
39252- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39253+ pax_open_kernel();
39254+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39255+ pax_close_kernel();
39256
39257 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39258 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39259diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39260index 9bb42ba..b01b4a2 100644
39261--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39262+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39263@@ -18,14 +18,12 @@
39264 #include <asm/head.h>
39265 #include <asm/timer.h>
39266
39267-static struct cpufreq_driver *cpufreq_us3_driver;
39268-
39269 struct us3_freq_percpu_info {
39270 struct cpufreq_frequency_table table[4];
39271 };
39272
39273 /* Indexed by cpu number. */
39274-static struct us3_freq_percpu_info *us3_freq_table;
39275+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39276
39277 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39278 * in the Safari config register.
39279@@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39280
39281 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39282 {
39283- if (cpufreq_us3_driver)
39284- us3_freq_target(policy, 0);
39285+ us3_freq_target(policy, 0);
39286
39287 return 0;
39288 }
39289
39290+static int __init us3_freq_init(void);
39291+static void __exit us3_freq_exit(void);
39292+
39293+static struct cpufreq_driver cpufreq_us3_driver = {
39294+ .init = us3_freq_cpu_init,
39295+ .verify = cpufreq_generic_frequency_table_verify,
39296+ .target_index = us3_freq_target,
39297+ .get = us3_freq_get,
39298+ .exit = us3_freq_cpu_exit,
39299+ .name = "UltraSPARC-III",
39300+
39301+};
39302+
39303 static int __init us3_freq_init(void)
39304 {
39305 unsigned long manuf, impl, ver;
39306- int ret;
39307
39308 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39309 return -ENODEV;
39310@@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39311 (impl == CHEETAH_IMPL ||
39312 impl == CHEETAH_PLUS_IMPL ||
39313 impl == JAGUAR_IMPL ||
39314- impl == PANTHER_IMPL)) {
39315- struct cpufreq_driver *driver;
39316-
39317- ret = -ENOMEM;
39318- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39319- if (!driver)
39320- goto err_out;
39321-
39322- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39323- GFP_KERNEL);
39324- if (!us3_freq_table)
39325- goto err_out;
39326-
39327- driver->init = us3_freq_cpu_init;
39328- driver->verify = cpufreq_generic_frequency_table_verify;
39329- driver->target_index = us3_freq_target;
39330- driver->get = us3_freq_get;
39331- driver->exit = us3_freq_cpu_exit;
39332- strcpy(driver->name, "UltraSPARC-III");
39333-
39334- cpufreq_us3_driver = driver;
39335- ret = cpufreq_register_driver(driver);
39336- if (ret)
39337- goto err_out;
39338-
39339- return 0;
39340-
39341-err_out:
39342- if (driver) {
39343- kfree(driver);
39344- cpufreq_us3_driver = NULL;
39345- }
39346- kfree(us3_freq_table);
39347- us3_freq_table = NULL;
39348- return ret;
39349- }
39350+ impl == PANTHER_IMPL))
39351+ return cpufreq_register_driver(&cpufreq_us3_driver);
39352
39353 return -ENODEV;
39354 }
39355
39356 static void __exit us3_freq_exit(void)
39357 {
39358- if (cpufreq_us3_driver) {
39359- cpufreq_unregister_driver(cpufreq_us3_driver);
39360- kfree(cpufreq_us3_driver);
39361- cpufreq_us3_driver = NULL;
39362- kfree(us3_freq_table);
39363- us3_freq_table = NULL;
39364- }
39365+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39366 }
39367
39368 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39369diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39370index 6723f03..3465190 100644
39371--- a/drivers/cpufreq/speedstep-centrino.c
39372+++ b/drivers/cpufreq/speedstep-centrino.c
39373@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39374 !cpu_has(cpu, X86_FEATURE_EST))
39375 return -ENODEV;
39376
39377- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39378- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39379+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39380+ pax_open_kernel();
39381+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39382+ pax_close_kernel();
39383+ }
39384
39385 if (policy->cpu != 0)
39386 return -ENODEV;
39387diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39388index 136d6a2..06e373d 100644
39389--- a/drivers/cpuidle/driver.c
39390+++ b/drivers/cpuidle/driver.c
39391@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39392
39393 static void poll_idle_init(struct cpuidle_driver *drv)
39394 {
39395- struct cpuidle_state *state = &drv->states[0];
39396+ cpuidle_state_no_const *state = &drv->states[0];
39397
39398 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39399 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39400diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39401index ca89412..a7b9c49 100644
39402--- a/drivers/cpuidle/governor.c
39403+++ b/drivers/cpuidle/governor.c
39404@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39405 mutex_lock(&cpuidle_lock);
39406 if (__cpuidle_find_governor(gov->name) == NULL) {
39407 ret = 0;
39408- list_add_tail(&gov->governor_list, &cpuidle_governors);
39409+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39410 if (!cpuidle_curr_governor ||
39411 cpuidle_curr_governor->rating < gov->rating)
39412 cpuidle_switch_governor(gov);
39413diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39414index efe2f17..b8124f9 100644
39415--- a/drivers/cpuidle/sysfs.c
39416+++ b/drivers/cpuidle/sysfs.c
39417@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39418 NULL
39419 };
39420
39421-static struct attribute_group cpuidle_attr_group = {
39422+static attribute_group_no_const cpuidle_attr_group = {
39423 .attrs = cpuidle_default_attrs,
39424 .name = "cpuidle",
39425 };
39426diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39427index 12fea3e..1e28f47 100644
39428--- a/drivers/crypto/hifn_795x.c
39429+++ b/drivers/crypto/hifn_795x.c
39430@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39431 MODULE_PARM_DESC(hifn_pll_ref,
39432 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39433
39434-static atomic_t hifn_dev_number;
39435+static atomic_unchecked_t hifn_dev_number;
39436
39437 #define ACRYPTO_OP_DECRYPT 0
39438 #define ACRYPTO_OP_ENCRYPT 1
39439@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39440 goto err_out_disable_pci_device;
39441
39442 snprintf(name, sizeof(name), "hifn%d",
39443- atomic_inc_return(&hifn_dev_number)-1);
39444+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39445
39446 err = pci_request_regions(pdev, name);
39447 if (err)
39448diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39449index 2042ec3..a9ce67f 100644
39450--- a/drivers/devfreq/devfreq.c
39451+++ b/drivers/devfreq/devfreq.c
39452@@ -616,7 +616,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39453 goto err_out;
39454 }
39455
39456- list_add(&governor->node, &devfreq_governor_list);
39457+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39458
39459 list_for_each_entry(devfreq, &devfreq_list, node) {
39460 int ret = 0;
39461@@ -704,7 +704,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39462 }
39463 }
39464
39465- list_del(&governor->node);
39466+ pax_list_del((struct list_head *)&governor->node);
39467 err_out:
39468 mutex_unlock(&devfreq_list_lock);
39469
39470diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39471index 5239677..1cb71a8 100644
39472--- a/drivers/dma/sh/shdma-base.c
39473+++ b/drivers/dma/sh/shdma-base.c
39474@@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39475 schan->slave_id = -EINVAL;
39476 }
39477
39478- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39479- sdev->desc_size, GFP_KERNEL);
39480+ schan->desc = kcalloc(sdev->desc_size,
39481+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39482 if (!schan->desc) {
39483 ret = -ENOMEM;
39484 goto edescalloc;
39485diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39486index dda7e75..0a4c867 100644
39487--- a/drivers/dma/sh/shdmac.c
39488+++ b/drivers/dma/sh/shdmac.c
39489@@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39490 return ret;
39491 }
39492
39493-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39494+static struct notifier_block sh_dmae_nmi_notifier = {
39495 .notifier_call = sh_dmae_nmi_handler,
39496
39497 /* Run before NMI debug handler and KGDB */
39498diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39499index 592af5f..bb1d583 100644
39500--- a/drivers/edac/edac_device.c
39501+++ b/drivers/edac/edac_device.c
39502@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39503 */
39504 int edac_device_alloc_index(void)
39505 {
39506- static atomic_t device_indexes = ATOMIC_INIT(0);
39507+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39508
39509- return atomic_inc_return(&device_indexes) - 1;
39510+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39511 }
39512 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39513
39514diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39515index 01fae82..1dd8289 100644
39516--- a/drivers/edac/edac_mc_sysfs.c
39517+++ b/drivers/edac/edac_mc_sysfs.c
39518@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39519 struct dev_ch_attribute {
39520 struct device_attribute attr;
39521 int channel;
39522-};
39523+} __do_const;
39524
39525 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39526 struct dev_ch_attribute dev_attr_legacy_##_name = \
39527@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39528 }
39529
39530 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39531+ pax_open_kernel();
39532 if (mci->get_sdram_scrub_rate) {
39533- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39534- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39535+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39536+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39537 }
39538 if (mci->set_sdram_scrub_rate) {
39539- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39540- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39541+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39542+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39543 }
39544+ pax_close_kernel();
39545 err = device_create_file(&mci->dev,
39546 &dev_attr_sdram_scrub_rate);
39547 if (err) {
39548diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39549index 2cf44b4d..6dd2dc7 100644
39550--- a/drivers/edac/edac_pci.c
39551+++ b/drivers/edac/edac_pci.c
39552@@ -29,7 +29,7 @@
39553
39554 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39555 static LIST_HEAD(edac_pci_list);
39556-static atomic_t pci_indexes = ATOMIC_INIT(0);
39557+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39558
39559 /*
39560 * edac_pci_alloc_ctl_info
39561@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39562 */
39563 int edac_pci_alloc_index(void)
39564 {
39565- return atomic_inc_return(&pci_indexes) - 1;
39566+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39567 }
39568 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39569
39570diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39571index e8658e4..22746d6 100644
39572--- a/drivers/edac/edac_pci_sysfs.c
39573+++ b/drivers/edac/edac_pci_sysfs.c
39574@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39575 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39576 static int edac_pci_poll_msec = 1000; /* one second workq period */
39577
39578-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39579-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39580+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39581+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39582
39583 static struct kobject *edac_pci_top_main_kobj;
39584 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39585@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39586 void *value;
39587 ssize_t(*show) (void *, char *);
39588 ssize_t(*store) (void *, const char *, size_t);
39589-};
39590+} __do_const;
39591
39592 /* Set of show/store abstract level functions for PCI Parity object */
39593 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39594@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39595 edac_printk(KERN_CRIT, EDAC_PCI,
39596 "Signaled System Error on %s\n",
39597 pci_name(dev));
39598- atomic_inc(&pci_nonparity_count);
39599+ atomic_inc_unchecked(&pci_nonparity_count);
39600 }
39601
39602 if (status & (PCI_STATUS_PARITY)) {
39603@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39604 "Master Data Parity Error on %s\n",
39605 pci_name(dev));
39606
39607- atomic_inc(&pci_parity_count);
39608+ atomic_inc_unchecked(&pci_parity_count);
39609 }
39610
39611 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39612@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39613 "Detected Parity Error on %s\n",
39614 pci_name(dev));
39615
39616- atomic_inc(&pci_parity_count);
39617+ atomic_inc_unchecked(&pci_parity_count);
39618 }
39619 }
39620
39621@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39622 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39623 "Signaled System Error on %s\n",
39624 pci_name(dev));
39625- atomic_inc(&pci_nonparity_count);
39626+ atomic_inc_unchecked(&pci_nonparity_count);
39627 }
39628
39629 if (status & (PCI_STATUS_PARITY)) {
39630@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39631 "Master Data Parity Error on "
39632 "%s\n", pci_name(dev));
39633
39634- atomic_inc(&pci_parity_count);
39635+ atomic_inc_unchecked(&pci_parity_count);
39636 }
39637
39638 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39639@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39640 "Detected Parity Error on %s\n",
39641 pci_name(dev));
39642
39643- atomic_inc(&pci_parity_count);
39644+ atomic_inc_unchecked(&pci_parity_count);
39645 }
39646 }
39647 }
39648@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39649 if (!check_pci_errors)
39650 return;
39651
39652- before_count = atomic_read(&pci_parity_count);
39653+ before_count = atomic_read_unchecked(&pci_parity_count);
39654
39655 /* scan all PCI devices looking for a Parity Error on devices and
39656 * bridges.
39657@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39658 /* Only if operator has selected panic on PCI Error */
39659 if (edac_pci_get_panic_on_pe()) {
39660 /* If the count is different 'after' from 'before' */
39661- if (before_count != atomic_read(&pci_parity_count))
39662+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39663 panic("EDAC: PCI Parity Error");
39664 }
39665 }
39666diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39667index 51b7e3a..aa8a3e8 100644
39668--- a/drivers/edac/mce_amd.h
39669+++ b/drivers/edac/mce_amd.h
39670@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39671 bool (*mc0_mce)(u16, u8);
39672 bool (*mc1_mce)(u16, u8);
39673 bool (*mc2_mce)(u16, u8);
39674-};
39675+} __no_const;
39676
39677 void amd_report_gart_errors(bool);
39678 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39679diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39680index 57ea7f4..af06b76 100644
39681--- a/drivers/firewire/core-card.c
39682+++ b/drivers/firewire/core-card.c
39683@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39684 const struct fw_card_driver *driver,
39685 struct device *device)
39686 {
39687- static atomic_t index = ATOMIC_INIT(-1);
39688+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
39689
39690- card->index = atomic_inc_return(&index);
39691+ card->index = atomic_inc_return_unchecked(&index);
39692 card->driver = driver;
39693 card->device = device;
39694 card->current_tlabel = 0;
39695@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39696
39697 void fw_core_remove_card(struct fw_card *card)
39698 {
39699- struct fw_card_driver dummy_driver = dummy_driver_template;
39700+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
39701
39702 card->driver->update_phy_reg(card, 4,
39703 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39704diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39705index 2c6d5e1..a2cca6b 100644
39706--- a/drivers/firewire/core-device.c
39707+++ b/drivers/firewire/core-device.c
39708@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39709 struct config_rom_attribute {
39710 struct device_attribute attr;
39711 u32 key;
39712-};
39713+} __do_const;
39714
39715 static ssize_t show_immediate(struct device *dev,
39716 struct device_attribute *dattr, char *buf)
39717diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39718index eb6935c..3cc2bfa 100644
39719--- a/drivers/firewire/core-transaction.c
39720+++ b/drivers/firewire/core-transaction.c
39721@@ -38,6 +38,7 @@
39722 #include <linux/timer.h>
39723 #include <linux/types.h>
39724 #include <linux/workqueue.h>
39725+#include <linux/sched.h>
39726
39727 #include <asm/byteorder.h>
39728
39729diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39730index f477308..2795f24 100644
39731--- a/drivers/firewire/core.h
39732+++ b/drivers/firewire/core.h
39733@@ -111,6 +111,7 @@ struct fw_card_driver {
39734
39735 int (*stop_iso)(struct fw_iso_context *ctx);
39736 };
39737+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39738
39739 void fw_card_initialize(struct fw_card *card,
39740 const struct fw_card_driver *driver, struct device *device);
39741diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39742index 586f2f7..3545ad2 100644
39743--- a/drivers/firewire/ohci.c
39744+++ b/drivers/firewire/ohci.c
39745@@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39746 be32_to_cpu(ohci->next_header));
39747 }
39748
39749+#ifndef CONFIG_GRKERNSEC
39750 if (param_remote_dma) {
39751 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39752 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39753 }
39754+#endif
39755
39756 spin_unlock_irq(&ohci->lock);
39757
39758@@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39759 unsigned long flags;
39760 int n, ret = 0;
39761
39762+#ifndef CONFIG_GRKERNSEC
39763 if (param_remote_dma)
39764 return 0;
39765+#endif
39766
39767 /*
39768 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39769diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39770index 94a58a0..f5eba42 100644
39771--- a/drivers/firmware/dmi-id.c
39772+++ b/drivers/firmware/dmi-id.c
39773@@ -16,7 +16,7 @@
39774 struct dmi_device_attribute{
39775 struct device_attribute dev_attr;
39776 int field;
39777-};
39778+} __do_const;
39779 #define to_dmi_dev_attr(_dev_attr) \
39780 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39781
39782diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39783index 17afc51..0ef90cd 100644
39784--- a/drivers/firmware/dmi_scan.c
39785+++ b/drivers/firmware/dmi_scan.c
39786@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39787 if (buf == NULL)
39788 return -1;
39789
39790- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39791+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39792
39793 dmi_unmap(buf);
39794 return 0;
39795diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39796index 1491dd4..aa910db 100644
39797--- a/drivers/firmware/efi/cper.c
39798+++ b/drivers/firmware/efi/cper.c
39799@@ -41,12 +41,12 @@
39800 */
39801 u64 cper_next_record_id(void)
39802 {
39803- static atomic64_t seq;
39804+ static atomic64_unchecked_t seq;
39805
39806- if (!atomic64_read(&seq))
39807- atomic64_set(&seq, ((u64)get_seconds()) << 32);
39808+ if (!atomic64_read_unchecked(&seq))
39809+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39810
39811- return atomic64_inc_return(&seq);
39812+ return atomic64_inc_return_unchecked(&seq);
39813 }
39814 EXPORT_SYMBOL_GPL(cper_next_record_id);
39815
39816diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39817index af20f17..4e4e545 100644
39818--- a/drivers/firmware/efi/efi.c
39819+++ b/drivers/firmware/efi/efi.c
39820@@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39821 };
39822
39823 static struct efivars generic_efivars;
39824-static struct efivar_operations generic_ops;
39825+static efivar_operations_no_const generic_ops __read_only;
39826
39827 static int generic_ops_register(void)
39828 {
39829- generic_ops.get_variable = efi.get_variable;
39830- generic_ops.set_variable = efi.set_variable;
39831- generic_ops.get_next_variable = efi.get_next_variable;
39832- generic_ops.query_variable_store = efi_query_variable_store;
39833+ pax_open_kernel();
39834+ *(void **)&generic_ops.get_variable = efi.get_variable;
39835+ *(void **)&generic_ops.set_variable = efi.set_variable;
39836+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39837+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39838+ pax_close_kernel();
39839
39840 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39841 }
39842diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39843index 50ea412..caccd6e9 100644
39844--- a/drivers/firmware/efi/efivars.c
39845+++ b/drivers/firmware/efi/efivars.c
39846@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39847 static int
39848 create_efivars_bin_attributes(void)
39849 {
39850- struct bin_attribute *attr;
39851+ bin_attribute_no_const *attr;
39852 int error;
39853
39854 /* new_var */
39855diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39856index 2f569aa..c95f4fb 100644
39857--- a/drivers/firmware/google/memconsole.c
39858+++ b/drivers/firmware/google/memconsole.c
39859@@ -155,7 +155,10 @@ static int __init memconsole_init(void)
39860 if (!found_memconsole())
39861 return -ENODEV;
39862
39863- memconsole_bin_attr.size = memconsole_length;
39864+ pax_open_kernel();
39865+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39866+ pax_close_kernel();
39867+
39868 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39869 }
39870
39871diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39872index 8765bd6..2e5b147 100644
39873--- a/drivers/gpio/gpio-em.c
39874+++ b/drivers/gpio/gpio-em.c
39875@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39876 struct em_gio_priv *p;
39877 struct resource *io[2], *irq[2];
39878 struct gpio_chip *gpio_chip;
39879- struct irq_chip *irq_chip;
39880+ irq_chip_no_const *irq_chip;
39881 const char *name = dev_name(&pdev->dev);
39882 int ret;
39883
39884diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39885index 7030422..42a3fe9 100644
39886--- a/drivers/gpio/gpio-ich.c
39887+++ b/drivers/gpio/gpio-ich.c
39888@@ -94,7 +94,7 @@ struct ichx_desc {
39889 * this option allows driver caching written output values
39890 */
39891 bool use_outlvl_cache;
39892-};
39893+} __do_const;
39894
39895 static struct {
39896 spinlock_t lock;
39897diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39898index 03c9148..c66e753 100644
39899--- a/drivers/gpio/gpio-rcar.c
39900+++ b/drivers/gpio/gpio-rcar.c
39901@@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39902 struct gpio_rcar_priv *p;
39903 struct resource *io, *irq;
39904 struct gpio_chip *gpio_chip;
39905- struct irq_chip *irq_chip;
39906+ irq_chip_no_const *irq_chip;
39907 struct device *dev = &pdev->dev;
39908 const char *name = dev_name(dev);
39909 int ret;
39910diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39911index 66cbcc1..0c5e622 100644
39912--- a/drivers/gpio/gpio-vr41xx.c
39913+++ b/drivers/gpio/gpio-vr41xx.c
39914@@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
39915 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39916 maskl, pendl, maskh, pendh);
39917
39918- atomic_inc(&irq_err_count);
39919+ atomic_inc_unchecked(&irq_err_count);
39920
39921 return -EINVAL;
39922 }
39923diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39924index d8b7099..8a314a5 100644
39925--- a/drivers/gpu/drm/drm_crtc.c
39926+++ b/drivers/gpu/drm/drm_crtc.c
39927@@ -3500,7 +3500,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39928 goto done;
39929 }
39930
39931- if (copy_to_user(&enum_ptr[copied].name,
39932+ if (copy_to_user(enum_ptr[copied].name,
39933 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39934 ret = -EFAULT;
39935 goto done;
39936diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39937index 03711d0..40e985f 100644
39938--- a/drivers/gpu/drm/drm_drv.c
39939+++ b/drivers/gpu/drm/drm_drv.c
39940@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39941 /**
39942 * Copy and IOCTL return string to user space
39943 */
39944-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39945+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39946 {
39947 int len;
39948
39949@@ -342,7 +342,7 @@ long drm_ioctl(struct file *filp,
39950 struct drm_file *file_priv = filp->private_data;
39951 struct drm_device *dev;
39952 const struct drm_ioctl_desc *ioctl = NULL;
39953- drm_ioctl_t *func;
39954+ drm_ioctl_no_const_t func;
39955 unsigned int nr = DRM_IOCTL_NR(cmd);
39956 int retcode = -EINVAL;
39957 char stack_kdata[128];
39958diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39959index e1eba0b..98f69f9 100644
39960--- a/drivers/gpu/drm/drm_fops.c
39961+++ b/drivers/gpu/drm/drm_fops.c
39962@@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
39963 return PTR_ERR(minor);
39964
39965 dev = minor->dev;
39966- if (!dev->open_count++)
39967+ if (local_inc_return(&dev->open_count) == 1)
39968 need_setup = 1;
39969
39970 /* share address_space across all char-devs of a single device */
39971@@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
39972 return 0;
39973
39974 err_undo:
39975- dev->open_count--;
39976+ local_dec(&dev->open_count);
39977 drm_minor_release(minor);
39978 return retcode;
39979 }
39980@@ -430,7 +430,7 @@ int drm_release(struct inode *inode, struct file *filp)
39981
39982 mutex_lock(&drm_global_mutex);
39983
39984- DRM_DEBUG("open_count = %d\n", dev->open_count);
39985+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39986
39987 if (dev->driver->preclose)
39988 dev->driver->preclose(dev, file_priv);
39989@@ -439,10 +439,10 @@ int drm_release(struct inode *inode, struct file *filp)
39990 * Begin inline drm_release
39991 */
39992
39993- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39994+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39995 task_pid_nr(current),
39996 (long)old_encode_dev(file_priv->minor->kdev->devt),
39997- dev->open_count);
39998+ local_read(&dev->open_count));
39999
40000 /* Release any auth tokens that might point to this file_priv,
40001 (do that under the drm_global_mutex) */
40002@@ -543,7 +543,7 @@ int drm_release(struct inode *inode, struct file *filp)
40003 * End inline drm_release
40004 */
40005
40006- if (!--dev->open_count) {
40007+ if (local_dec_and_test(&dev->open_count)) {
40008 retcode = drm_lastclose(dev);
40009 if (drm_device_is_unplugged(dev))
40010 drm_put_dev(dev);
40011diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40012index 3d2e91c..d31c4c9 100644
40013--- a/drivers/gpu/drm/drm_global.c
40014+++ b/drivers/gpu/drm/drm_global.c
40015@@ -36,7 +36,7 @@
40016 struct drm_global_item {
40017 struct mutex mutex;
40018 void *object;
40019- int refcount;
40020+ atomic_t refcount;
40021 };
40022
40023 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40024@@ -49,7 +49,7 @@ void drm_global_init(void)
40025 struct drm_global_item *item = &glob[i];
40026 mutex_init(&item->mutex);
40027 item->object = NULL;
40028- item->refcount = 0;
40029+ atomic_set(&item->refcount, 0);
40030 }
40031 }
40032
40033@@ -59,7 +59,7 @@ void drm_global_release(void)
40034 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40035 struct drm_global_item *item = &glob[i];
40036 BUG_ON(item->object != NULL);
40037- BUG_ON(item->refcount != 0);
40038+ BUG_ON(atomic_read(&item->refcount) != 0);
40039 }
40040 }
40041
40042@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40043 struct drm_global_item *item = &glob[ref->global_type];
40044
40045 mutex_lock(&item->mutex);
40046- if (item->refcount == 0) {
40047+ if (atomic_read(&item->refcount) == 0) {
40048 item->object = kzalloc(ref->size, GFP_KERNEL);
40049 if (unlikely(item->object == NULL)) {
40050 ret = -ENOMEM;
40051@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40052 goto out_err;
40053
40054 }
40055- ++item->refcount;
40056+ atomic_inc(&item->refcount);
40057 ref->object = item->object;
40058 mutex_unlock(&item->mutex);
40059 return 0;
40060@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40061 struct drm_global_item *item = &glob[ref->global_type];
40062
40063 mutex_lock(&item->mutex);
40064- BUG_ON(item->refcount == 0);
40065+ BUG_ON(atomic_read(&item->refcount) == 0);
40066 BUG_ON(ref->object != item->object);
40067- if (--item->refcount == 0) {
40068+ if (atomic_dec_and_test(&item->refcount)) {
40069 ref->release(ref);
40070 item->object = NULL;
40071 }
40072diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40073index 7473035..a48b9c5 100644
40074--- a/drivers/gpu/drm/drm_info.c
40075+++ b/drivers/gpu/drm/drm_info.c
40076@@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40077 struct drm_local_map *map;
40078 struct drm_map_list *r_list;
40079
40080- /* Hardcoded from _DRM_FRAME_BUFFER,
40081- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40082- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40083- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40084+ static const char * const types[] = {
40085+ [_DRM_FRAME_BUFFER] = "FB",
40086+ [_DRM_REGISTERS] = "REG",
40087+ [_DRM_SHM] = "SHM",
40088+ [_DRM_AGP] = "AGP",
40089+ [_DRM_SCATTER_GATHER] = "SG",
40090+ [_DRM_CONSISTENT] = "PCI"};
40091 const char *type;
40092 int i;
40093
40094@@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40095 map = r_list->map;
40096 if (!map)
40097 continue;
40098- if (map->type < 0 || map->type > 5)
40099+ if (map->type >= ARRAY_SIZE(types))
40100 type = "??";
40101 else
40102 type = types[map->type];
40103@@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40104 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40105 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40106 vma->vm_flags & VM_IO ? 'i' : '-',
40107+#ifdef CONFIG_GRKERNSEC_HIDESYM
40108+ 0);
40109+#else
40110 vma->vm_pgoff);
40111+#endif
40112
40113 #if defined(__i386__)
40114 pgprot = pgprot_val(vma->vm_page_prot);
40115diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40116index 2f4c4343..dd12cd2 100644
40117--- a/drivers/gpu/drm/drm_ioc32.c
40118+++ b/drivers/gpu/drm/drm_ioc32.c
40119@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40120 request = compat_alloc_user_space(nbytes);
40121 if (!access_ok(VERIFY_WRITE, request, nbytes))
40122 return -EFAULT;
40123- list = (struct drm_buf_desc *) (request + 1);
40124+ list = (struct drm_buf_desc __user *) (request + 1);
40125
40126 if (__put_user(count, &request->count)
40127 || __put_user(list, &request->list))
40128@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40129 request = compat_alloc_user_space(nbytes);
40130 if (!access_ok(VERIFY_WRITE, request, nbytes))
40131 return -EFAULT;
40132- list = (struct drm_buf_pub *) (request + 1);
40133+ list = (struct drm_buf_pub __user *) (request + 1);
40134
40135 if (__put_user(count, &request->count)
40136 || __put_user(list, &request->list))
40137@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40138 return 0;
40139 }
40140
40141-drm_ioctl_compat_t *drm_compat_ioctls[] = {
40142+drm_ioctl_compat_t drm_compat_ioctls[] = {
40143 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40144 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40145 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40146@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40147 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40148 {
40149 unsigned int nr = DRM_IOCTL_NR(cmd);
40150- drm_ioctl_compat_t *fn;
40151 int ret;
40152
40153 /* Assume that ioctls without an explicit compat routine will just
40154@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40155 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40156 return drm_ioctl(filp, cmd, arg);
40157
40158- fn = drm_compat_ioctls[nr];
40159-
40160- if (fn != NULL)
40161- ret = (*fn) (filp, cmd, arg);
40162+ if (drm_compat_ioctls[nr] != NULL)
40163+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40164 else
40165 ret = drm_ioctl(filp, cmd, arg);
40166
40167diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40168index 4c24c3a..c903cab 100644
40169--- a/drivers/gpu/drm/drm_stub.c
40170+++ b/drivers/gpu/drm/drm_stub.c
40171@@ -455,7 +455,7 @@ void drm_unplug_dev(struct drm_device *dev)
40172
40173 drm_device_set_unplugged(dev);
40174
40175- if (dev->open_count == 0) {
40176+ if (local_read(&dev->open_count) == 0) {
40177 drm_put_dev(dev);
40178 }
40179 mutex_unlock(&drm_global_mutex);
40180diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40181index c22c309..ae758c3 100644
40182--- a/drivers/gpu/drm/drm_sysfs.c
40183+++ b/drivers/gpu/drm/drm_sysfs.c
40184@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40185 */
40186 int drm_sysfs_device_add(struct drm_minor *minor)
40187 {
40188- char *minor_str;
40189+ const char *minor_str;
40190 int r;
40191
40192 if (minor->type == DRM_MINOR_CONTROL)
40193diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40194index d4d16ed..8fb0b51 100644
40195--- a/drivers/gpu/drm/i810/i810_drv.h
40196+++ b/drivers/gpu/drm/i810/i810_drv.h
40197@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40198 int page_flipping;
40199
40200 wait_queue_head_t irq_queue;
40201- atomic_t irq_received;
40202- atomic_t irq_emitted;
40203+ atomic_unchecked_t irq_received;
40204+ atomic_unchecked_t irq_emitted;
40205
40206 int front_offset;
40207 } drm_i810_private_t;
40208diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40209index eedb023..25076a4 100644
40210--- a/drivers/gpu/drm/i915/i915_dma.c
40211+++ b/drivers/gpu/drm/i915/i915_dma.c
40212@@ -1280,7 +1280,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40213 bool can_switch;
40214
40215 spin_lock(&dev->count_lock);
40216- can_switch = (dev->open_count == 0);
40217+ can_switch = (local_read(&dev->open_count) == 0);
40218 spin_unlock(&dev->count_lock);
40219 return can_switch;
40220 }
40221diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40222index 20fef6c..76c78fb 100644
40223--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40224+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40225@@ -886,9 +886,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40226
40227 static int
40228 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40229- int count)
40230+ unsigned int count)
40231 {
40232- int i;
40233+ unsigned int i;
40234 unsigned relocs_total = 0;
40235 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40236
40237diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40238index 3c59584..500f2e9 100644
40239--- a/drivers/gpu/drm/i915/i915_ioc32.c
40240+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40241@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40242 (unsigned long)request);
40243 }
40244
40245-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40246+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40247 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40248 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40249 [DRM_I915_GETPARAM] = compat_i915_getparam,
40250@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40251 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40252 {
40253 unsigned int nr = DRM_IOCTL_NR(cmd);
40254- drm_ioctl_compat_t *fn = NULL;
40255 int ret;
40256
40257 if (nr < DRM_COMMAND_BASE)
40258 return drm_compat_ioctl(filp, cmd, arg);
40259
40260- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40261- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40262-
40263- if (fn != NULL)
40264+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40265+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40266 ret = (*fn) (filp, cmd, arg);
40267- else
40268+ } else
40269 ret = drm_ioctl(filp, cmd, arg);
40270
40271 return ret;
40272diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40273index 5b60e25..eac1625 100644
40274--- a/drivers/gpu/drm/i915/intel_display.c
40275+++ b/drivers/gpu/drm/i915/intel_display.c
40276@@ -11171,13 +11171,13 @@ struct intel_quirk {
40277 int subsystem_vendor;
40278 int subsystem_device;
40279 void (*hook)(struct drm_device *dev);
40280-};
40281+} __do_const;
40282
40283 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40284 struct intel_dmi_quirk {
40285 void (*hook)(struct drm_device *dev);
40286 const struct dmi_system_id (*dmi_id_list)[];
40287-};
40288+} __do_const;
40289
40290 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40291 {
40292@@ -11185,18 +11185,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40293 return 1;
40294 }
40295
40296-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40297+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40298 {
40299- .dmi_id_list = &(const struct dmi_system_id[]) {
40300- {
40301- .callback = intel_dmi_reverse_brightness,
40302- .ident = "NCR Corporation",
40303- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40304- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40305- },
40306- },
40307- { } /* terminating entry */
40308+ .callback = intel_dmi_reverse_brightness,
40309+ .ident = "NCR Corporation",
40310+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40311+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40312 },
40313+ },
40314+ { } /* terminating entry */
40315+};
40316+
40317+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40318+ {
40319+ .dmi_id_list = &intel_dmi_quirks_table,
40320 .hook = quirk_invert_brightness,
40321 },
40322 };
40323diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40324index fe45321..836fdca 100644
40325--- a/drivers/gpu/drm/mga/mga_drv.h
40326+++ b/drivers/gpu/drm/mga/mga_drv.h
40327@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40328 u32 clear_cmd;
40329 u32 maccess;
40330
40331- atomic_t vbl_received; /**< Number of vblanks received. */
40332+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40333 wait_queue_head_t fence_queue;
40334- atomic_t last_fence_retired;
40335+ atomic_unchecked_t last_fence_retired;
40336 u32 next_fence_to_post;
40337
40338 unsigned int fb_cpp;
40339diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40340index 86b4bb8..ae237ad 100644
40341--- a/drivers/gpu/drm/mga/mga_ioc32.c
40342+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40343@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40344 return 0;
40345 }
40346
40347-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40348+drm_ioctl_compat_t mga_compat_ioctls[] = {
40349 [DRM_MGA_INIT] = compat_mga_init,
40350 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40351 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40352@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40353 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40354 {
40355 unsigned int nr = DRM_IOCTL_NR(cmd);
40356- drm_ioctl_compat_t *fn = NULL;
40357 int ret;
40358
40359 if (nr < DRM_COMMAND_BASE)
40360 return drm_compat_ioctl(filp, cmd, arg);
40361
40362- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40363- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40364-
40365- if (fn != NULL)
40366+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40367+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40368 ret = (*fn) (filp, cmd, arg);
40369- else
40370+ } else
40371 ret = drm_ioctl(filp, cmd, arg);
40372
40373 return ret;
40374diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40375index 1b071b8..de8601a 100644
40376--- a/drivers/gpu/drm/mga/mga_irq.c
40377+++ b/drivers/gpu/drm/mga/mga_irq.c
40378@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40379 if (crtc != 0)
40380 return 0;
40381
40382- return atomic_read(&dev_priv->vbl_received);
40383+ return atomic_read_unchecked(&dev_priv->vbl_received);
40384 }
40385
40386
40387@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40388 /* VBLANK interrupt */
40389 if (status & MGA_VLINEPEN) {
40390 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40391- atomic_inc(&dev_priv->vbl_received);
40392+ atomic_inc_unchecked(&dev_priv->vbl_received);
40393 drm_handle_vblank(dev, 0);
40394 handled = 1;
40395 }
40396@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40397 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40398 MGA_WRITE(MGA_PRIMEND, prim_end);
40399
40400- atomic_inc(&dev_priv->last_fence_retired);
40401+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40402 wake_up(&dev_priv->fence_queue);
40403 handled = 1;
40404 }
40405@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40406 * using fences.
40407 */
40408 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40409- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40410+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40411 - *sequence) <= (1 << 23)));
40412
40413 *sequence = cur_fence;
40414diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40415index 8268a4c..5105708 100644
40416--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40417+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40418@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40419 struct bit_table {
40420 const char id;
40421 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40422-};
40423+} __no_const;
40424
40425 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40426
40427diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40428index 7efbafa..19f8087 100644
40429--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40430+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40431@@ -97,7 +97,6 @@ struct nouveau_drm {
40432 struct drm_global_reference mem_global_ref;
40433 struct ttm_bo_global_ref bo_global_ref;
40434 struct ttm_bo_device bdev;
40435- atomic_t validate_sequence;
40436 int (*move)(struct nouveau_channel *,
40437 struct ttm_buffer_object *,
40438 struct ttm_mem_reg *, struct ttm_mem_reg *);
40439diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40440index c1a7e5a..38b8539 100644
40441--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40442+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40443@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40444 unsigned long arg)
40445 {
40446 unsigned int nr = DRM_IOCTL_NR(cmd);
40447- drm_ioctl_compat_t *fn = NULL;
40448+ drm_ioctl_compat_t fn = NULL;
40449 int ret;
40450
40451 if (nr < DRM_COMMAND_BASE)
40452diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40453index ab0228f..20b756b 100644
40454--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40455+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40456@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40457 }
40458
40459 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40460- nouveau_vram_manager_init,
40461- nouveau_vram_manager_fini,
40462- nouveau_vram_manager_new,
40463- nouveau_vram_manager_del,
40464- nouveau_vram_manager_debug
40465+ .init = nouveau_vram_manager_init,
40466+ .takedown = nouveau_vram_manager_fini,
40467+ .get_node = nouveau_vram_manager_new,
40468+ .put_node = nouveau_vram_manager_del,
40469+ .debug = nouveau_vram_manager_debug
40470 };
40471
40472 static int
40473@@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40474 }
40475
40476 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40477- nouveau_gart_manager_init,
40478- nouveau_gart_manager_fini,
40479- nouveau_gart_manager_new,
40480- nouveau_gart_manager_del,
40481- nouveau_gart_manager_debug
40482+ .init = nouveau_gart_manager_init,
40483+ .takedown = nouveau_gart_manager_fini,
40484+ .get_node = nouveau_gart_manager_new,
40485+ .put_node = nouveau_gart_manager_del,
40486+ .debug = nouveau_gart_manager_debug
40487 };
40488
40489 #include <core/subdev/vm/nv04.h>
40490@@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40491 }
40492
40493 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40494- nv04_gart_manager_init,
40495- nv04_gart_manager_fini,
40496- nv04_gart_manager_new,
40497- nv04_gart_manager_del,
40498- nv04_gart_manager_debug
40499+ .init = nv04_gart_manager_init,
40500+ .takedown = nv04_gart_manager_fini,
40501+ .get_node = nv04_gart_manager_new,
40502+ .put_node = nv04_gart_manager_del,
40503+ .debug = nv04_gart_manager_debug
40504 };
40505
40506 int
40507diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40508index fb84da3..d7ee463 100644
40509--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40510+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40511@@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40512 bool can_switch;
40513
40514 spin_lock(&dev->count_lock);
40515- can_switch = (dev->open_count == 0);
40516+ can_switch = (local_read(&dev->open_count) == 0);
40517 spin_unlock(&dev->count_lock);
40518 return can_switch;
40519 }
40520diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40521index eb89653..613cf71 100644
40522--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40523+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40524@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40525 int ret;
40526
40527 mutex_lock(&qdev->async_io_mutex);
40528- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40529+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40530 if (qdev->last_sent_io_cmd > irq_num) {
40531 if (intr)
40532 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40533- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40534+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40535 else
40536 ret = wait_event_timeout(qdev->io_cmd_event,
40537- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40538+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40539 /* 0 is timeout, just bail the "hw" has gone away */
40540 if (ret <= 0)
40541 goto out;
40542- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40543+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40544 }
40545 outb(val, addr);
40546 qdev->last_sent_io_cmd = irq_num + 1;
40547 if (intr)
40548 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40549- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40550+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40551 else
40552 ret = wait_event_timeout(qdev->io_cmd_event,
40553- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40554+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40555 out:
40556 if (ret > 0)
40557 ret = 0;
40558diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40559index c3c2bbd..bc3c0fb 100644
40560--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40561+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40562@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40563 struct drm_info_node *node = (struct drm_info_node *) m->private;
40564 struct qxl_device *qdev = node->minor->dev->dev_private;
40565
40566- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40567- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40568- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40569- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40570+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40571+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40572+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40573+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40574 seq_printf(m, "%d\n", qdev->irq_received_error);
40575 return 0;
40576 }
40577diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40578index 36ed40b..0397633 100644
40579--- a/drivers/gpu/drm/qxl/qxl_drv.h
40580+++ b/drivers/gpu/drm/qxl/qxl_drv.h
40581@@ -290,10 +290,10 @@ struct qxl_device {
40582 unsigned int last_sent_io_cmd;
40583
40584 /* interrupt handling */
40585- atomic_t irq_received;
40586- atomic_t irq_received_display;
40587- atomic_t irq_received_cursor;
40588- atomic_t irq_received_io_cmd;
40589+ atomic_unchecked_t irq_received;
40590+ atomic_unchecked_t irq_received_display;
40591+ atomic_unchecked_t irq_received_cursor;
40592+ atomic_unchecked_t irq_received_io_cmd;
40593 unsigned irq_received_error;
40594 wait_queue_head_t display_event;
40595 wait_queue_head_t cursor_event;
40596diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40597index 0bb86e6..d41416d 100644
40598--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40599+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40600@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40601
40602 /* TODO copy slow path code from i915 */
40603 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40604- unwritten = __copy_from_user_inatomic_nocache(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_SIZE), (void *)(unsigned long)cmd->command, cmd->command_size);
40605+ unwritten = __copy_from_user_inatomic_nocache(fb_cmd + sizeof(union qxl_release_info) + (release->release_offset & ~PAGE_SIZE), (void __force_user *)(unsigned long)cmd->command, cmd->command_size);
40606
40607 {
40608 struct qxl_drawable *draw = fb_cmd;
40609@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40610 struct drm_qxl_reloc reloc;
40611
40612 if (copy_from_user(&reloc,
40613- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40614+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40615 sizeof(reloc))) {
40616 ret = -EFAULT;
40617 goto out_free_bos;
40618@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40619
40620 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40621
40622- struct drm_qxl_command *commands =
40623- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40624+ struct drm_qxl_command __user *commands =
40625+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40626
40627- if (copy_from_user(&user_cmd, &commands[cmd_num],
40628+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40629 sizeof(user_cmd)))
40630 return -EFAULT;
40631
40632diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40633index 28f84b4..fb3e224 100644
40634--- a/drivers/gpu/drm/qxl/qxl_irq.c
40635+++ b/drivers/gpu/drm/qxl/qxl_irq.c
40636@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40637
40638 pending = xchg(&qdev->ram_header->int_pending, 0);
40639
40640- atomic_inc(&qdev->irq_received);
40641+ atomic_inc_unchecked(&qdev->irq_received);
40642
40643 if (pending & QXL_INTERRUPT_DISPLAY) {
40644- atomic_inc(&qdev->irq_received_display);
40645+ atomic_inc_unchecked(&qdev->irq_received_display);
40646 wake_up_all(&qdev->display_event);
40647 qxl_queue_garbage_collect(qdev, false);
40648 }
40649 if (pending & QXL_INTERRUPT_CURSOR) {
40650- atomic_inc(&qdev->irq_received_cursor);
40651+ atomic_inc_unchecked(&qdev->irq_received_cursor);
40652 wake_up_all(&qdev->cursor_event);
40653 }
40654 if (pending & QXL_INTERRUPT_IO_CMD) {
40655- atomic_inc(&qdev->irq_received_io_cmd);
40656+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40657 wake_up_all(&qdev->io_cmd_event);
40658 }
40659 if (pending & QXL_INTERRUPT_ERROR) {
40660@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40661 init_waitqueue_head(&qdev->io_cmd_event);
40662 INIT_WORK(&qdev->client_monitors_config_work,
40663 qxl_client_monitors_config_work_func);
40664- atomic_set(&qdev->irq_received, 0);
40665- atomic_set(&qdev->irq_received_display, 0);
40666- atomic_set(&qdev->irq_received_cursor, 0);
40667- atomic_set(&qdev->irq_received_io_cmd, 0);
40668+ atomic_set_unchecked(&qdev->irq_received, 0);
40669+ atomic_set_unchecked(&qdev->irq_received_display, 0);
40670+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40671+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40672 qdev->irq_received_error = 0;
40673 ret = drm_irq_install(qdev->ddev);
40674 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40675diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40676index d52c275..4e6b43d 100644
40677--- a/drivers/gpu/drm/qxl/qxl_ttm.c
40678+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40679@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40680 }
40681 }
40682
40683-static struct vm_operations_struct qxl_ttm_vm_ops;
40684+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40685 static const struct vm_operations_struct *ttm_vm_ops;
40686
40687 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40688@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40689 return r;
40690 if (unlikely(ttm_vm_ops == NULL)) {
40691 ttm_vm_ops = vma->vm_ops;
40692+ pax_open_kernel();
40693 qxl_ttm_vm_ops = *ttm_vm_ops;
40694 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40695+ pax_close_kernel();
40696 }
40697 vma->vm_ops = &qxl_ttm_vm_ops;
40698 return 0;
40699@@ -561,25 +563,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40700 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40701 {
40702 #if defined(CONFIG_DEBUG_FS)
40703- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40704- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40705- unsigned i;
40706+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40707+ {
40708+ .name = "qxl_mem_mm",
40709+ .show = &qxl_mm_dump_table,
40710+ },
40711+ {
40712+ .name = "qxl_surf_mm",
40713+ .show = &qxl_mm_dump_table,
40714+ }
40715+ };
40716
40717- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40718- if (i == 0)
40719- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40720- else
40721- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40722- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40723- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40724- qxl_mem_types_list[i].driver_features = 0;
40725- if (i == 0)
40726- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40727- else
40728- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40729+ pax_open_kernel();
40730+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40731+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40732+ pax_close_kernel();
40733
40734- }
40735- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40736+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40737 #else
40738 return 0;
40739 #endif
40740diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40741index 59459fe..be26b31 100644
40742--- a/drivers/gpu/drm/r128/r128_cce.c
40743+++ b/drivers/gpu/drm/r128/r128_cce.c
40744@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40745
40746 /* GH: Simple idle check.
40747 */
40748- atomic_set(&dev_priv->idle_count, 0);
40749+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40750
40751 /* We don't support anything other than bus-mastering ring mode,
40752 * but the ring can be in either AGP or PCI space for the ring
40753diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40754index 5bf3f5f..7000661 100644
40755--- a/drivers/gpu/drm/r128/r128_drv.h
40756+++ b/drivers/gpu/drm/r128/r128_drv.h
40757@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40758 int is_pci;
40759 unsigned long cce_buffers_offset;
40760
40761- atomic_t idle_count;
40762+ atomic_unchecked_t idle_count;
40763
40764 int page_flipping;
40765 int current_page;
40766 u32 crtc_offset;
40767 u32 crtc_offset_cntl;
40768
40769- atomic_t vbl_received;
40770+ atomic_unchecked_t vbl_received;
40771
40772 u32 color_fmt;
40773 unsigned int front_offset;
40774diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40775index b0d0fd3..a6fbbe4 100644
40776--- a/drivers/gpu/drm/r128/r128_ioc32.c
40777+++ b/drivers/gpu/drm/r128/r128_ioc32.c
40778@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40779 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40780 }
40781
40782-drm_ioctl_compat_t *r128_compat_ioctls[] = {
40783+drm_ioctl_compat_t r128_compat_ioctls[] = {
40784 [DRM_R128_INIT] = compat_r128_init,
40785 [DRM_R128_DEPTH] = compat_r128_depth,
40786 [DRM_R128_STIPPLE] = compat_r128_stipple,
40787@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40788 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40789 {
40790 unsigned int nr = DRM_IOCTL_NR(cmd);
40791- drm_ioctl_compat_t *fn = NULL;
40792 int ret;
40793
40794 if (nr < DRM_COMMAND_BASE)
40795 return drm_compat_ioctl(filp, cmd, arg);
40796
40797- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40798- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40799-
40800- if (fn != NULL)
40801+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40802+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40803 ret = (*fn) (filp, cmd, arg);
40804- else
40805+ } else
40806 ret = drm_ioctl(filp, cmd, arg);
40807
40808 return ret;
40809diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40810index c2ae496..30b5993 100644
40811--- a/drivers/gpu/drm/r128/r128_irq.c
40812+++ b/drivers/gpu/drm/r128/r128_irq.c
40813@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40814 if (crtc != 0)
40815 return 0;
40816
40817- return atomic_read(&dev_priv->vbl_received);
40818+ return atomic_read_unchecked(&dev_priv->vbl_received);
40819 }
40820
40821 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40822@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40823 /* VBLANK interrupt */
40824 if (status & R128_CRTC_VBLANK_INT) {
40825 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40826- atomic_inc(&dev_priv->vbl_received);
40827+ atomic_inc_unchecked(&dev_priv->vbl_received);
40828 drm_handle_vblank(dev, 0);
40829 return IRQ_HANDLED;
40830 }
40831diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40832index e806dac..f81d32f 100644
40833--- a/drivers/gpu/drm/r128/r128_state.c
40834+++ b/drivers/gpu/drm/r128/r128_state.c
40835@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40836
40837 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40838 {
40839- if (atomic_read(&dev_priv->idle_count) == 0)
40840+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40841 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40842 else
40843- atomic_set(&dev_priv->idle_count, 0);
40844+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40845 }
40846
40847 #endif
40848diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40849index 4a85bb6..aaea819 100644
40850--- a/drivers/gpu/drm/radeon/mkregtable.c
40851+++ b/drivers/gpu/drm/radeon/mkregtable.c
40852@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40853 regex_t mask_rex;
40854 regmatch_t match[4];
40855 char buf[1024];
40856- size_t end;
40857+ long end;
40858 int len;
40859 int done = 0;
40860 int r;
40861 unsigned o;
40862 struct offset *offset;
40863 char last_reg_s[10];
40864- int last_reg;
40865+ unsigned long last_reg;
40866
40867 if (regcomp
40868 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40869diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40870index 2cd144c..a01c95a 100644
40871--- a/drivers/gpu/drm/radeon/radeon_device.c
40872+++ b/drivers/gpu/drm/radeon/radeon_device.c
40873@@ -1129,7 +1129,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40874 bool can_switch;
40875
40876 spin_lock(&dev->count_lock);
40877- can_switch = (dev->open_count == 0);
40878+ can_switch = (local_read(&dev->open_count) == 0);
40879 spin_unlock(&dev->count_lock);
40880 return can_switch;
40881 }
40882diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40883index dafd812..1bf20c7 100644
40884--- a/drivers/gpu/drm/radeon/radeon_drv.h
40885+++ b/drivers/gpu/drm/radeon/radeon_drv.h
40886@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40887
40888 /* SW interrupt */
40889 wait_queue_head_t swi_queue;
40890- atomic_t swi_emitted;
40891+ atomic_unchecked_t swi_emitted;
40892 int vblank_crtc;
40893 uint32_t irq_enable_reg;
40894 uint32_t r500_disp_irq_reg;
40895diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40896index bdb0f93..5ff558f 100644
40897--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40898+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40899@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40900 request = compat_alloc_user_space(sizeof(*request));
40901 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40902 || __put_user(req32.param, &request->param)
40903- || __put_user((void __user *)(unsigned long)req32.value,
40904+ || __put_user((unsigned long)req32.value,
40905 &request->value))
40906 return -EFAULT;
40907
40908@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40909 #define compat_radeon_cp_setparam NULL
40910 #endif /* X86_64 || IA64 */
40911
40912-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40913+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40914 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40915 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40916 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40917@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40918 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40919 {
40920 unsigned int nr = DRM_IOCTL_NR(cmd);
40921- drm_ioctl_compat_t *fn = NULL;
40922 int ret;
40923
40924 if (nr < DRM_COMMAND_BASE)
40925 return drm_compat_ioctl(filp, cmd, arg);
40926
40927- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40928- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40929-
40930- if (fn != NULL)
40931+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40932+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40933 ret = (*fn) (filp, cmd, arg);
40934- else
40935+ } else
40936 ret = drm_ioctl(filp, cmd, arg);
40937
40938 return ret;
40939diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40940index 244b19b..c19226d 100644
40941--- a/drivers/gpu/drm/radeon/radeon_irq.c
40942+++ b/drivers/gpu/drm/radeon/radeon_irq.c
40943@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40944 unsigned int ret;
40945 RING_LOCALS;
40946
40947- atomic_inc(&dev_priv->swi_emitted);
40948- ret = atomic_read(&dev_priv->swi_emitted);
40949+ atomic_inc_unchecked(&dev_priv->swi_emitted);
40950+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40951
40952 BEGIN_RING(4);
40953 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40954@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40955 drm_radeon_private_t *dev_priv =
40956 (drm_radeon_private_t *) dev->dev_private;
40957
40958- atomic_set(&dev_priv->swi_emitted, 0);
40959+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40960 init_waitqueue_head(&dev_priv->swi_queue);
40961
40962 dev->max_vblank_count = 0x001fffff;
40963diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40964index 956ab7f..fbd36d8 100644
40965--- a/drivers/gpu/drm/radeon/radeon_state.c
40966+++ b/drivers/gpu/drm/radeon/radeon_state.c
40967@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40968 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40969 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40970
40971- if (copy_from_user(&depth_boxes, clear->depth_boxes,
40972+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
40973 sarea_priv->nbox * sizeof(depth_boxes[0])))
40974 return -EFAULT;
40975
40976@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40977 {
40978 drm_radeon_private_t *dev_priv = dev->dev_private;
40979 drm_radeon_getparam_t *param = data;
40980- int value;
40981+ int value = 0;
40982
40983 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40984
40985diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40986index c8a8a51..219dacc 100644
40987--- a/drivers/gpu/drm/radeon/radeon_ttm.c
40988+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40989@@ -797,7 +797,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40990 man->size = size >> PAGE_SHIFT;
40991 }
40992
40993-static struct vm_operations_struct radeon_ttm_vm_ops;
40994+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40995 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40996
40997 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40998@@ -838,8 +838,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40999 }
41000 if (unlikely(ttm_vm_ops == NULL)) {
41001 ttm_vm_ops = vma->vm_ops;
41002+ pax_open_kernel();
41003 radeon_ttm_vm_ops = *ttm_vm_ops;
41004 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41005+ pax_close_kernel();
41006 }
41007 vma->vm_ops = &radeon_ttm_vm_ops;
41008 return 0;
41009diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41010index edb871d..a275c6ed 100644
41011--- a/drivers/gpu/drm/tegra/dc.c
41012+++ b/drivers/gpu/drm/tegra/dc.c
41013@@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41014 }
41015
41016 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41017- dc->debugfs_files[i].data = dc;
41018+ *(void **)&dc->debugfs_files[i].data = dc;
41019
41020 err = drm_debugfs_create_files(dc->debugfs_files,
41021 ARRAY_SIZE(debugfs_files),
41022diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41023index 0e599f0..c9ea7c7 100644
41024--- a/drivers/gpu/drm/tegra/dsi.c
41025+++ b/drivers/gpu/drm/tegra/dsi.c
41026@@ -39,7 +39,7 @@ struct tegra_dsi {
41027 struct clk *clk_lp;
41028 struct clk *clk;
41029
41030- struct drm_info_list *debugfs_files;
41031+ drm_info_list_no_const *debugfs_files;
41032 struct drm_minor *minor;
41033 struct dentry *debugfs;
41034
41035diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41036index 6928015..c9853e7 100644
41037--- a/drivers/gpu/drm/tegra/hdmi.c
41038+++ b/drivers/gpu/drm/tegra/hdmi.c
41039@@ -59,7 +59,7 @@ struct tegra_hdmi {
41040 bool stereo;
41041 bool dvi;
41042
41043- struct drm_info_list *debugfs_files;
41044+ drm_info_list_no_const *debugfs_files;
41045 struct drm_minor *minor;
41046 struct dentry *debugfs;
41047 };
41048diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41049index bd850c9..d9f3573 100644
41050--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41051+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41052@@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41053 }
41054
41055 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41056- ttm_bo_man_init,
41057- ttm_bo_man_takedown,
41058- ttm_bo_man_get_node,
41059- ttm_bo_man_put_node,
41060- ttm_bo_man_debug
41061+ .init = ttm_bo_man_init,
41062+ .takedown = ttm_bo_man_takedown,
41063+ .get_node = ttm_bo_man_get_node,
41064+ .put_node = ttm_bo_man_put_node,
41065+ .debug = ttm_bo_man_debug
41066 };
41067 EXPORT_SYMBOL(ttm_bo_manager_func);
41068diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41069index dbc2def..0a9f710 100644
41070--- a/drivers/gpu/drm/ttm/ttm_memory.c
41071+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41072@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41073 zone->glob = glob;
41074 glob->zone_kernel = zone;
41075 ret = kobject_init_and_add(
41076- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41077+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41078 if (unlikely(ret != 0)) {
41079 kobject_put(&zone->kobj);
41080 return ret;
41081@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41082 zone->glob = glob;
41083 glob->zone_dma32 = zone;
41084 ret = kobject_init_and_add(
41085- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41086+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41087 if (unlikely(ret != 0)) {
41088 kobject_put(&zone->kobj);
41089 return ret;
41090diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41091index 863bef9..cba15cf 100644
41092--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41093+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41094@@ -391,9 +391,9 @@ out:
41095 static unsigned long
41096 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41097 {
41098- static atomic_t start_pool = ATOMIC_INIT(0);
41099+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41100 unsigned i;
41101- unsigned pool_offset = atomic_add_return(1, &start_pool);
41102+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41103 struct ttm_page_pool *pool;
41104 int shrink_pages = sc->nr_to_scan;
41105 unsigned long freed = 0;
41106diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41107index 3771763..883f206 100644
41108--- a/drivers/gpu/drm/udl/udl_fb.c
41109+++ b/drivers/gpu/drm/udl/udl_fb.c
41110@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41111 fb_deferred_io_cleanup(info);
41112 kfree(info->fbdefio);
41113 info->fbdefio = NULL;
41114- info->fbops->fb_mmap = udl_fb_mmap;
41115 }
41116
41117 pr_warn("released /dev/fb%d user=%d count=%d\n",
41118diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41119index ad02732..144f5ed 100644
41120--- a/drivers/gpu/drm/via/via_drv.h
41121+++ b/drivers/gpu/drm/via/via_drv.h
41122@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41123 typedef uint32_t maskarray_t[5];
41124
41125 typedef struct drm_via_irq {
41126- atomic_t irq_received;
41127+ atomic_unchecked_t irq_received;
41128 uint32_t pending_mask;
41129 uint32_t enable_mask;
41130 wait_queue_head_t irq_queue;
41131@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41132 struct timeval last_vblank;
41133 int last_vblank_valid;
41134 unsigned usec_per_vblank;
41135- atomic_t vbl_received;
41136+ atomic_unchecked_t vbl_received;
41137 drm_via_state_t hc_state;
41138 char pci_buf[VIA_PCI_BUF_SIZE];
41139 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41140diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41141index 1319433..a993b0c 100644
41142--- a/drivers/gpu/drm/via/via_irq.c
41143+++ b/drivers/gpu/drm/via/via_irq.c
41144@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41145 if (crtc != 0)
41146 return 0;
41147
41148- return atomic_read(&dev_priv->vbl_received);
41149+ return atomic_read_unchecked(&dev_priv->vbl_received);
41150 }
41151
41152 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41153@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41154
41155 status = VIA_READ(VIA_REG_INTERRUPT);
41156 if (status & VIA_IRQ_VBLANK_PENDING) {
41157- atomic_inc(&dev_priv->vbl_received);
41158- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41159+ atomic_inc_unchecked(&dev_priv->vbl_received);
41160+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41161 do_gettimeofday(&cur_vblank);
41162 if (dev_priv->last_vblank_valid) {
41163 dev_priv->usec_per_vblank =
41164@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41165 dev_priv->last_vblank = cur_vblank;
41166 dev_priv->last_vblank_valid = 1;
41167 }
41168- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41169+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41170 DRM_DEBUG("US per vblank is: %u\n",
41171 dev_priv->usec_per_vblank);
41172 }
41173@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41174
41175 for (i = 0; i < dev_priv->num_irqs; ++i) {
41176 if (status & cur_irq->pending_mask) {
41177- atomic_inc(&cur_irq->irq_received);
41178+ atomic_inc_unchecked(&cur_irq->irq_received);
41179 wake_up(&cur_irq->irq_queue);
41180 handled = 1;
41181 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41182@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41183 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41184 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41185 masks[irq][4]));
41186- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41187+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41188 } else {
41189 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41190 (((cur_irq_sequence =
41191- atomic_read(&cur_irq->irq_received)) -
41192+ atomic_read_unchecked(&cur_irq->irq_received)) -
41193 *sequence) <= (1 << 23)));
41194 }
41195 *sequence = cur_irq_sequence;
41196@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41197 }
41198
41199 for (i = 0; i < dev_priv->num_irqs; ++i) {
41200- atomic_set(&cur_irq->irq_received, 0);
41201+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41202 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41203 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41204 init_waitqueue_head(&cur_irq->irq_queue);
41205@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41206 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41207 case VIA_IRQ_RELATIVE:
41208 irqwait->request.sequence +=
41209- atomic_read(&cur_irq->irq_received);
41210+ atomic_read_unchecked(&cur_irq->irq_received);
41211 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41212 case VIA_IRQ_ABSOLUTE:
41213 break;
41214diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41215index 6b252a8..5975dfe 100644
41216--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41217+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41218@@ -437,7 +437,7 @@ struct vmw_private {
41219 * Fencing and IRQs.
41220 */
41221
41222- atomic_t marker_seq;
41223+ atomic_unchecked_t marker_seq;
41224 wait_queue_head_t fence_queue;
41225 wait_queue_head_t fifo_queue;
41226 int fence_queue_waiters; /* Protected by hw_mutex */
41227diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41228index 6ccd993..618d592 100644
41229--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41230+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41231@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41232 (unsigned int) min,
41233 (unsigned int) fifo->capabilities);
41234
41235- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41236+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41237 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41238 vmw_marker_queue_init(&fifo->marker_queue);
41239 return vmw_fifo_send_fence(dev_priv, &dummy);
41240@@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41241 if (reserveable)
41242 iowrite32(bytes, fifo_mem +
41243 SVGA_FIFO_RESERVED);
41244- return fifo_mem + (next_cmd >> 2);
41245+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41246 } else {
41247 need_bounce = true;
41248 }
41249@@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41250
41251 fm = vmw_fifo_reserve(dev_priv, bytes);
41252 if (unlikely(fm == NULL)) {
41253- *seqno = atomic_read(&dev_priv->marker_seq);
41254+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41255 ret = -ENOMEM;
41256 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41257 false, 3*HZ);
41258@@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41259 }
41260
41261 do {
41262- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41263+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41264 } while (*seqno == 0);
41265
41266 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41267diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41268index b1273e8..9c274fd 100644
41269--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41270+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41271@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41272 }
41273
41274 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41275- vmw_gmrid_man_init,
41276- vmw_gmrid_man_takedown,
41277- vmw_gmrid_man_get_node,
41278- vmw_gmrid_man_put_node,
41279- vmw_gmrid_man_debug
41280+ .init = vmw_gmrid_man_init,
41281+ .takedown = vmw_gmrid_man_takedown,
41282+ .get_node = vmw_gmrid_man_get_node,
41283+ .put_node = vmw_gmrid_man_put_node,
41284+ .debug = vmw_gmrid_man_debug
41285 };
41286diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41287index 37881ec..319065d 100644
41288--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41289+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41290@@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41291 int ret;
41292
41293 num_clips = arg->num_clips;
41294- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41295+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41296
41297 if (unlikely(num_clips == 0))
41298 return 0;
41299@@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41300 int ret;
41301
41302 num_clips = arg->num_clips;
41303- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41304+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41305
41306 if (unlikely(num_clips == 0))
41307 return 0;
41308diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41309index 0c42376..6febe77 100644
41310--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41311+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41312@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41313 * emitted. Then the fence is stale and signaled.
41314 */
41315
41316- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41317+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41318 > VMW_FENCE_WRAP);
41319
41320 return ret;
41321@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41322
41323 if (fifo_idle)
41324 down_read(&fifo_state->rwsem);
41325- signal_seq = atomic_read(&dev_priv->marker_seq);
41326+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41327 ret = 0;
41328
41329 for (;;) {
41330diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41331index 8a8725c2..afed796 100644
41332--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41333+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41334@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41335 while (!vmw_lag_lt(queue, us)) {
41336 spin_lock(&queue->lock);
41337 if (list_empty(&queue->head))
41338- seqno = atomic_read(&dev_priv->marker_seq);
41339+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41340 else {
41341 marker = list_first_entry(&queue->head,
41342 struct vmw_marker, head);
41343diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41344index ec0ae2d..dc0780b 100644
41345--- a/drivers/gpu/vga/vga_switcheroo.c
41346+++ b/drivers/gpu/vga/vga_switcheroo.c
41347@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41348
41349 /* this version is for the case where the power switch is separate
41350 to the device being powered down. */
41351-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41352+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41353 {
41354 /* copy over all the bus versions */
41355 if (dev->bus && dev->bus->pm) {
41356@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41357 return ret;
41358 }
41359
41360-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41361+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41362 {
41363 /* copy over all the bus versions */
41364 if (dev->bus && dev->bus->pm) {
41365diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41366index da52279..83ba0e7 100644
41367--- a/drivers/hid/hid-core.c
41368+++ b/drivers/hid/hid-core.c
41369@@ -2466,7 +2466,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41370
41371 int hid_add_device(struct hid_device *hdev)
41372 {
41373- static atomic_t id = ATOMIC_INIT(0);
41374+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41375 int ret;
41376
41377 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41378@@ -2508,7 +2508,7 @@ int hid_add_device(struct hid_device *hdev)
41379 /* XXX hack, any other cleaner solution after the driver core
41380 * is converted to allow more than 20 bytes as the device name? */
41381 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41382- hdev->vendor, hdev->product, atomic_inc_return(&id));
41383+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41384
41385 hid_debug_register(hdev, dev_name(&hdev->dev));
41386 ret = device_add(&hdev->dev);
41387diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41388index c13fb5b..55a3802 100644
41389--- a/drivers/hid/hid-wiimote-debug.c
41390+++ b/drivers/hid/hid-wiimote-debug.c
41391@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41392 else if (size == 0)
41393 return -EIO;
41394
41395- if (copy_to_user(u, buf, size))
41396+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41397 return -EFAULT;
41398
41399 *off += size;
41400diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41401index 0d078c3..cd0962c 100644
41402--- a/drivers/hid/uhid.c
41403+++ b/drivers/hid/uhid.c
41404@@ -47,7 +47,7 @@ struct uhid_device {
41405 struct mutex report_lock;
41406 wait_queue_head_t report_wait;
41407 atomic_t report_done;
41408- atomic_t report_id;
41409+ atomic_unchecked_t report_id;
41410 struct uhid_event report_buf;
41411 };
41412
41413@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41414
41415 spin_lock_irqsave(&uhid->qlock, flags);
41416 ev->type = UHID_FEATURE;
41417- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41418+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41419 ev->u.feature.rnum = rnum;
41420 ev->u.feature.rtype = report_type;
41421
41422@@ -539,7 +539,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41423 spin_lock_irqsave(&uhid->qlock, flags);
41424
41425 /* id for old report; drop it silently */
41426- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41427+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41428 goto unlock;
41429 if (atomic_read(&uhid->report_done))
41430 goto unlock;
41431diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41432index 602ca86..10a6573 100644
41433--- a/drivers/hv/channel.c
41434+++ b/drivers/hv/channel.c
41435@@ -365,8 +365,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41436 int ret = 0;
41437 int t;
41438
41439- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41440- atomic_inc(&vmbus_connection.next_gpadl_handle);
41441+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41442+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41443
41444 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41445 if (ret)
41446diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41447index bcb4950..61dba6c 100644
41448--- a/drivers/hv/hv.c
41449+++ b/drivers/hv/hv.c
41450@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41451 u64 output_address = (output) ? virt_to_phys(output) : 0;
41452 u32 output_address_hi = output_address >> 32;
41453 u32 output_address_lo = output_address & 0xFFFFFFFF;
41454- void *hypercall_page = hv_context.hypercall_page;
41455+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41456
41457 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41458 "=a"(hv_status_lo) : "d" (control_hi),
41459@@ -154,7 +154,7 @@ int hv_init(void)
41460 /* See if the hypercall page is already set */
41461 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41462
41463- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41464+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41465
41466 if (!virtaddr)
41467 goto cleanup;
41468diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41469index 5e90c5d..d8fcefb 100644
41470--- a/drivers/hv/hv_balloon.c
41471+++ b/drivers/hv/hv_balloon.c
41472@@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41473
41474 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41475 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41476-static atomic_t trans_id = ATOMIC_INIT(0);
41477+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41478
41479 static int dm_ring_size = (5 * PAGE_SIZE);
41480
41481@@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
41482 pr_info("Memory hot add failed\n");
41483
41484 dm->state = DM_INITIALIZED;
41485- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41486+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41487 vmbus_sendpacket(dm->dev->channel, &resp,
41488 sizeof(struct dm_hot_add_response),
41489 (unsigned long)NULL,
41490@@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
41491 memset(&status, 0, sizeof(struct dm_status));
41492 status.hdr.type = DM_STATUS_REPORT;
41493 status.hdr.size = sizeof(struct dm_status);
41494- status.hdr.trans_id = atomic_inc_return(&trans_id);
41495+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41496
41497 /*
41498 * The host expects the guest to report free memory.
41499@@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
41500 * send the status. This can happen if we were interrupted
41501 * after we picked our transaction ID.
41502 */
41503- if (status.hdr.trans_id != atomic_read(&trans_id))
41504+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41505 return;
41506
41507 /*
41508@@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
41509 */
41510
41511 do {
41512- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41513+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41514 ret = vmbus_sendpacket(dm_device.dev->channel,
41515 bl_resp,
41516 bl_resp->hdr.size,
41517@@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41518
41519 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41520 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41521- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41522+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41523 resp.hdr.size = sizeof(struct dm_unballoon_response);
41524
41525 vmbus_sendpacket(dm_device.dev->channel, &resp,
41526@@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41527 memset(&version_req, 0, sizeof(struct dm_version_request));
41528 version_req.hdr.type = DM_VERSION_REQUEST;
41529 version_req.hdr.size = sizeof(struct dm_version_request);
41530- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41531+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41532 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41533 version_req.is_last_attempt = 1;
41534
41535@@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
41536 memset(&version_req, 0, sizeof(struct dm_version_request));
41537 version_req.hdr.type = DM_VERSION_REQUEST;
41538 version_req.hdr.size = sizeof(struct dm_version_request);
41539- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41540+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41541 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41542 version_req.is_last_attempt = 0;
41543
41544@@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
41545 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41546 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41547 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41548- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41549+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41550
41551 cap_msg.caps.cap_bits.balloon = 1;
41552 cap_msg.caps.cap_bits.hot_add = 1;
41553diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41554index 860134d..ea3a79a 100644
41555--- a/drivers/hv/hyperv_vmbus.h
41556+++ b/drivers/hv/hyperv_vmbus.h
41557@@ -602,7 +602,7 @@ enum vmbus_connect_state {
41558 struct vmbus_connection {
41559 enum vmbus_connect_state conn_state;
41560
41561- atomic_t next_gpadl_handle;
41562+ atomic_unchecked_t next_gpadl_handle;
41563
41564 /*
41565 * Represents channel interrupts. Each bit position represents a
41566diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41567index 8e53a3c..7a64e44 100644
41568--- a/drivers/hv/vmbus_drv.c
41569+++ b/drivers/hv/vmbus_drv.c
41570@@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41571 {
41572 int ret = 0;
41573
41574- static atomic_t device_num = ATOMIC_INIT(0);
41575+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41576
41577 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41578- atomic_inc_return(&device_num));
41579+ atomic_inc_return_unchecked(&device_num));
41580
41581 child_device_obj->device.bus = &hv_bus;
41582 child_device_obj->device.parent = &hv_acpi_dev->dev;
41583diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41584index 579bdf9..75118b5 100644
41585--- a/drivers/hwmon/acpi_power_meter.c
41586+++ b/drivers/hwmon/acpi_power_meter.c
41587@@ -116,7 +116,7 @@ struct sensor_template {
41588 struct device_attribute *devattr,
41589 const char *buf, size_t count);
41590 int index;
41591-};
41592+} __do_const;
41593
41594 /* Averaging interval */
41595 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41596@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41597 struct sensor_template *attrs)
41598 {
41599 struct device *dev = &resource->acpi_dev->dev;
41600- struct sensor_device_attribute *sensors =
41601+ sensor_device_attribute_no_const *sensors =
41602 &resource->sensors[resource->num_sensors];
41603 int res = 0;
41604
41605diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41606index 3288f13..71cfb4e 100644
41607--- a/drivers/hwmon/applesmc.c
41608+++ b/drivers/hwmon/applesmc.c
41609@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41610 {
41611 struct applesmc_node_group *grp;
41612 struct applesmc_dev_attr *node;
41613- struct attribute *attr;
41614+ attribute_no_const *attr;
41615 int ret, i;
41616
41617 for (grp = groups; grp->format; grp++) {
41618diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41619index ae208f6..48b6c5b 100644
41620--- a/drivers/hwmon/asus_atk0110.c
41621+++ b/drivers/hwmon/asus_atk0110.c
41622@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41623 struct atk_sensor_data {
41624 struct list_head list;
41625 struct atk_data *data;
41626- struct device_attribute label_attr;
41627- struct device_attribute input_attr;
41628- struct device_attribute limit1_attr;
41629- struct device_attribute limit2_attr;
41630+ device_attribute_no_const label_attr;
41631+ device_attribute_no_const input_attr;
41632+ device_attribute_no_const limit1_attr;
41633+ device_attribute_no_const limit2_attr;
41634 char label_attr_name[ATTR_NAME_SIZE];
41635 char input_attr_name[ATTR_NAME_SIZE];
41636 char limit1_attr_name[ATTR_NAME_SIZE];
41637@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41638 static struct device_attribute atk_name_attr =
41639 __ATTR(name, 0444, atk_name_show, NULL);
41640
41641-static void atk_init_attribute(struct device_attribute *attr, char *name,
41642+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41643 sysfs_show_func show)
41644 {
41645 sysfs_attr_init(&attr->attr);
41646diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41647index d76f0b7..55ae976 100644
41648--- a/drivers/hwmon/coretemp.c
41649+++ b/drivers/hwmon/coretemp.c
41650@@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41651 return NOTIFY_OK;
41652 }
41653
41654-static struct notifier_block coretemp_cpu_notifier __refdata = {
41655+static struct notifier_block coretemp_cpu_notifier = {
41656 .notifier_call = coretemp_cpu_callback,
41657 };
41658
41659diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41660index 632f1dc..57e6a58 100644
41661--- a/drivers/hwmon/ibmaem.c
41662+++ b/drivers/hwmon/ibmaem.c
41663@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41664 struct aem_rw_sensor_template *rw)
41665 {
41666 struct device *dev = &data->pdev->dev;
41667- struct sensor_device_attribute *sensors = data->sensors;
41668+ sensor_device_attribute_no_const *sensors = data->sensors;
41669 int err;
41670
41671 /* Set up read-only sensors */
41672diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41673index 9fbb1b1..efbaa3e 100644
41674--- a/drivers/hwmon/iio_hwmon.c
41675+++ b/drivers/hwmon/iio_hwmon.c
41676@@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41677 {
41678 struct device *dev = &pdev->dev;
41679 struct iio_hwmon_state *st;
41680- struct sensor_device_attribute *a;
41681+ sensor_device_attribute_no_const *a;
41682 int ret, i;
41683 int in_i = 1, temp_i = 1, curr_i = 1;
41684 enum iio_chan_type type;
41685diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41686index 38d5a63..cf2c2ea 100644
41687--- a/drivers/hwmon/nct6775.c
41688+++ b/drivers/hwmon/nct6775.c
41689@@ -944,10 +944,10 @@ static struct attribute_group *
41690 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41691 int repeat)
41692 {
41693- struct attribute_group *group;
41694+ attribute_group_no_const *group;
41695 struct sensor_device_attr_u *su;
41696- struct sensor_device_attribute *a;
41697- struct sensor_device_attribute_2 *a2;
41698+ sensor_device_attribute_no_const *a;
41699+ sensor_device_attribute_2_no_const *a2;
41700 struct attribute **attrs;
41701 struct sensor_device_template **t;
41702 int i, count;
41703diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41704index 291d11f..3f0dbbd 100644
41705--- a/drivers/hwmon/pmbus/pmbus_core.c
41706+++ b/drivers/hwmon/pmbus/pmbus_core.c
41707@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41708 return 0;
41709 }
41710
41711-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41712+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41713 const char *name,
41714 umode_t mode,
41715 ssize_t (*show)(struct device *dev,
41716@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41717 dev_attr->store = store;
41718 }
41719
41720-static void pmbus_attr_init(struct sensor_device_attribute *a,
41721+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41722 const char *name,
41723 umode_t mode,
41724 ssize_t (*show)(struct device *dev,
41725@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41726 u16 reg, u8 mask)
41727 {
41728 struct pmbus_boolean *boolean;
41729- struct sensor_device_attribute *a;
41730+ sensor_device_attribute_no_const *a;
41731
41732 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41733 if (!boolean)
41734@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41735 bool update, bool readonly)
41736 {
41737 struct pmbus_sensor *sensor;
41738- struct device_attribute *a;
41739+ device_attribute_no_const *a;
41740
41741 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41742 if (!sensor)
41743@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41744 const char *lstring, int index)
41745 {
41746 struct pmbus_label *label;
41747- struct device_attribute *a;
41748+ device_attribute_no_const *a;
41749
41750 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41751 if (!label)
41752diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41753index 97cd45a..ac54d8b 100644
41754--- a/drivers/hwmon/sht15.c
41755+++ b/drivers/hwmon/sht15.c
41756@@ -169,7 +169,7 @@ struct sht15_data {
41757 int supply_uv;
41758 bool supply_uv_valid;
41759 struct work_struct update_supply_work;
41760- atomic_t interrupt_handled;
41761+ atomic_unchecked_t interrupt_handled;
41762 };
41763
41764 /**
41765@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41766 ret = gpio_direction_input(data->pdata->gpio_data);
41767 if (ret)
41768 return ret;
41769- atomic_set(&data->interrupt_handled, 0);
41770+ atomic_set_unchecked(&data->interrupt_handled, 0);
41771
41772 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41773 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41774 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41775 /* Only relevant if the interrupt hasn't occurred. */
41776- if (!atomic_read(&data->interrupt_handled))
41777+ if (!atomic_read_unchecked(&data->interrupt_handled))
41778 schedule_work(&data->read_work);
41779 }
41780 ret = wait_event_timeout(data->wait_queue,
41781@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41782
41783 /* First disable the interrupt */
41784 disable_irq_nosync(irq);
41785- atomic_inc(&data->interrupt_handled);
41786+ atomic_inc_unchecked(&data->interrupt_handled);
41787 /* Then schedule a reading work struct */
41788 if (data->state != SHT15_READING_NOTHING)
41789 schedule_work(&data->read_work);
41790@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41791 * If not, then start the interrupt again - care here as could
41792 * have gone low in meantime so verify it hasn't!
41793 */
41794- atomic_set(&data->interrupt_handled, 0);
41795+ atomic_set_unchecked(&data->interrupt_handled, 0);
41796 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41797 /* If still not occurred or another handler was scheduled */
41798 if (gpio_get_value(data->pdata->gpio_data)
41799- || atomic_read(&data->interrupt_handled))
41800+ || atomic_read_unchecked(&data->interrupt_handled))
41801 return;
41802 }
41803
41804diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41805index 8df43c5..b07b91d 100644
41806--- a/drivers/hwmon/via-cputemp.c
41807+++ b/drivers/hwmon/via-cputemp.c
41808@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41809 return NOTIFY_OK;
41810 }
41811
41812-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41813+static struct notifier_block via_cputemp_cpu_notifier = {
41814 .notifier_call = via_cputemp_cpu_callback,
41815 };
41816
41817diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41818index 41fc683..a39cfea 100644
41819--- a/drivers/i2c/busses/i2c-amd756-s4882.c
41820+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41821@@ -43,7 +43,7 @@
41822 extern struct i2c_adapter amd756_smbus;
41823
41824 static struct i2c_adapter *s4882_adapter;
41825-static struct i2c_algorithm *s4882_algo;
41826+static i2c_algorithm_no_const *s4882_algo;
41827
41828 /* Wrapper access functions for multiplexed SMBus */
41829 static DEFINE_MUTEX(amd756_lock);
41830diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41831index 721f7eb..0fd2a09 100644
41832--- a/drivers/i2c/busses/i2c-diolan-u2c.c
41833+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41834@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41835 /* usb layer */
41836
41837 /* Send command to device, and get response. */
41838-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41839+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41840 {
41841 int ret = 0;
41842 int actual;
41843diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41844index b170bdf..3c76427 100644
41845--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41846+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41847@@ -41,7 +41,7 @@
41848 extern struct i2c_adapter *nforce2_smbus;
41849
41850 static struct i2c_adapter *s4985_adapter;
41851-static struct i2c_algorithm *s4985_algo;
41852+static i2c_algorithm_no_const *s4985_algo;
41853
41854 /* Wrapper access functions for multiplexed SMBus */
41855 static DEFINE_MUTEX(nforce2_lock);
41856diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41857index 80b47e8..1a6040d9 100644
41858--- a/drivers/i2c/i2c-dev.c
41859+++ b/drivers/i2c/i2c-dev.c
41860@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41861 break;
41862 }
41863
41864- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41865+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41866 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41867 if (IS_ERR(rdwr_pa[i].buf)) {
41868 res = PTR_ERR(rdwr_pa[i].buf);
41869diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41870index 0b510ba..4fbb5085 100644
41871--- a/drivers/ide/ide-cd.c
41872+++ b/drivers/ide/ide-cd.c
41873@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41874 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41875 if ((unsigned long)buf & alignment
41876 || blk_rq_bytes(rq) & q->dma_pad_mask
41877- || object_is_on_stack(buf))
41878+ || object_starts_on_stack(buf))
41879 drive->dma = 0;
41880 }
41881 }
41882diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41883index ede16aec..e423e8a 100644
41884--- a/drivers/iio/industrialio-core.c
41885+++ b/drivers/iio/industrialio-core.c
41886@@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41887 }
41888
41889 static
41890-int __iio_device_attr_init(struct device_attribute *dev_attr,
41891+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41892 const char *postfix,
41893 struct iio_chan_spec const *chan,
41894 ssize_t (*readfunc)(struct device *dev,
41895diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41896index c323917..6ddea8b 100644
41897--- a/drivers/infiniband/core/cm.c
41898+++ b/drivers/infiniband/core/cm.c
41899@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41900
41901 struct cm_counter_group {
41902 struct kobject obj;
41903- atomic_long_t counter[CM_ATTR_COUNT];
41904+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41905 };
41906
41907 struct cm_counter_attribute {
41908@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41909 struct ib_mad_send_buf *msg = NULL;
41910 int ret;
41911
41912- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41913+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41914 counter[CM_REQ_COUNTER]);
41915
41916 /* Quick state check to discard duplicate REQs. */
41917@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41918 if (!cm_id_priv)
41919 return;
41920
41921- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41922+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41923 counter[CM_REP_COUNTER]);
41924 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41925 if (ret)
41926@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
41927 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41928 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41929 spin_unlock_irq(&cm_id_priv->lock);
41930- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41931+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41932 counter[CM_RTU_COUNTER]);
41933 goto out;
41934 }
41935@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
41936 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41937 dreq_msg->local_comm_id);
41938 if (!cm_id_priv) {
41939- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41940+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41941 counter[CM_DREQ_COUNTER]);
41942 cm_issue_drep(work->port, work->mad_recv_wc);
41943 return -EINVAL;
41944@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
41945 case IB_CM_MRA_REP_RCVD:
41946 break;
41947 case IB_CM_TIMEWAIT:
41948- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41949+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41950 counter[CM_DREQ_COUNTER]);
41951 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41952 goto unlock;
41953@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
41954 cm_free_msg(msg);
41955 goto deref;
41956 case IB_CM_DREQ_RCVD:
41957- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41958+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41959 counter[CM_DREQ_COUNTER]);
41960 goto unlock;
41961 default:
41962@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
41963 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41964 cm_id_priv->msg, timeout)) {
41965 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41966- atomic_long_inc(&work->port->
41967+ atomic_long_inc_unchecked(&work->port->
41968 counter_group[CM_RECV_DUPLICATES].
41969 counter[CM_MRA_COUNTER]);
41970 goto out;
41971@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
41972 break;
41973 case IB_CM_MRA_REQ_RCVD:
41974 case IB_CM_MRA_REP_RCVD:
41975- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41976+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41977 counter[CM_MRA_COUNTER]);
41978 /* fall through */
41979 default:
41980@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
41981 case IB_CM_LAP_IDLE:
41982 break;
41983 case IB_CM_MRA_LAP_SENT:
41984- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41985+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41986 counter[CM_LAP_COUNTER]);
41987 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41988 goto unlock;
41989@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
41990 cm_free_msg(msg);
41991 goto deref;
41992 case IB_CM_LAP_RCVD:
41993- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41994+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41995 counter[CM_LAP_COUNTER]);
41996 goto unlock;
41997 default:
41998@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41999 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42000 if (cur_cm_id_priv) {
42001 spin_unlock_irq(&cm.lock);
42002- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42003+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42004 counter[CM_SIDR_REQ_COUNTER]);
42005 goto out; /* Duplicate message. */
42006 }
42007@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42008 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42009 msg->retries = 1;
42010
42011- atomic_long_add(1 + msg->retries,
42012+ atomic_long_add_unchecked(1 + msg->retries,
42013 &port->counter_group[CM_XMIT].counter[attr_index]);
42014 if (msg->retries)
42015- atomic_long_add(msg->retries,
42016+ atomic_long_add_unchecked(msg->retries,
42017 &port->counter_group[CM_XMIT_RETRIES].
42018 counter[attr_index]);
42019
42020@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42021 }
42022
42023 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42024- atomic_long_inc(&port->counter_group[CM_RECV].
42025+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42026 counter[attr_id - CM_ATTR_ID_OFFSET]);
42027
42028 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42029@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42030 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42031
42032 return sprintf(buf, "%ld\n",
42033- atomic_long_read(&group->counter[cm_attr->index]));
42034+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42035 }
42036
42037 static const struct sysfs_ops cm_counter_ops = {
42038diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42039index 9f5ad7c..588cd84 100644
42040--- a/drivers/infiniband/core/fmr_pool.c
42041+++ b/drivers/infiniband/core/fmr_pool.c
42042@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42043
42044 struct task_struct *thread;
42045
42046- atomic_t req_ser;
42047- atomic_t flush_ser;
42048+ atomic_unchecked_t req_ser;
42049+ atomic_unchecked_t flush_ser;
42050
42051 wait_queue_head_t force_wait;
42052 };
42053@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42054 struct ib_fmr_pool *pool = pool_ptr;
42055
42056 do {
42057- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42058+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42059 ib_fmr_batch_release(pool);
42060
42061- atomic_inc(&pool->flush_ser);
42062+ atomic_inc_unchecked(&pool->flush_ser);
42063 wake_up_interruptible(&pool->force_wait);
42064
42065 if (pool->flush_function)
42066@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42067 }
42068
42069 set_current_state(TASK_INTERRUPTIBLE);
42070- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42071+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42072 !kthread_should_stop())
42073 schedule();
42074 __set_current_state(TASK_RUNNING);
42075@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42076 pool->dirty_watermark = params->dirty_watermark;
42077 pool->dirty_len = 0;
42078 spin_lock_init(&pool->pool_lock);
42079- atomic_set(&pool->req_ser, 0);
42080- atomic_set(&pool->flush_ser, 0);
42081+ atomic_set_unchecked(&pool->req_ser, 0);
42082+ atomic_set_unchecked(&pool->flush_ser, 0);
42083 init_waitqueue_head(&pool->force_wait);
42084
42085 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42086@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42087 }
42088 spin_unlock_irq(&pool->pool_lock);
42089
42090- serial = atomic_inc_return(&pool->req_ser);
42091+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42092 wake_up_process(pool->thread);
42093
42094 if (wait_event_interruptible(pool->force_wait,
42095- atomic_read(&pool->flush_ser) - serial >= 0))
42096+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42097 return -EINTR;
42098
42099 return 0;
42100@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42101 } else {
42102 list_add_tail(&fmr->list, &pool->dirty_list);
42103 if (++pool->dirty_len >= pool->dirty_watermark) {
42104- atomic_inc(&pool->req_ser);
42105+ atomic_inc_unchecked(&pool->req_ser);
42106 wake_up_process(pool->thread);
42107 }
42108 }
42109diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42110index ec7a298..8742e59 100644
42111--- a/drivers/infiniband/hw/cxgb4/mem.c
42112+++ b/drivers/infiniband/hw/cxgb4/mem.c
42113@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42114 int err;
42115 struct fw_ri_tpte tpt;
42116 u32 stag_idx;
42117- static atomic_t key;
42118+ static atomic_unchecked_t key;
42119
42120 if (c4iw_fatal_error(rdev))
42121 return -EIO;
42122@@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42123 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42124 rdev->stats.stag.max = rdev->stats.stag.cur;
42125 mutex_unlock(&rdev->stats.lock);
42126- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42127+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42128 }
42129 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42130 __func__, stag_state, type, pdid, stag_idx);
42131diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42132index 79b3dbc..96e5fcc 100644
42133--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42134+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42135@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42136 struct ib_atomic_eth *ateth;
42137 struct ipath_ack_entry *e;
42138 u64 vaddr;
42139- atomic64_t *maddr;
42140+ atomic64_unchecked_t *maddr;
42141 u64 sdata;
42142 u32 rkey;
42143 u8 next;
42144@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42145 IB_ACCESS_REMOTE_ATOMIC)))
42146 goto nack_acc_unlck;
42147 /* Perform atomic OP and save result. */
42148- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42149+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42150 sdata = be64_to_cpu(ateth->swap_data);
42151 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42152 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42153- (u64) atomic64_add_return(sdata, maddr) - sdata :
42154+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42155 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42156 be64_to_cpu(ateth->compare_data),
42157 sdata);
42158diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42159index 1f95bba..9530f87 100644
42160--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42161+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42162@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42163 unsigned long flags;
42164 struct ib_wc wc;
42165 u64 sdata;
42166- atomic64_t *maddr;
42167+ atomic64_unchecked_t *maddr;
42168 enum ib_wc_status send_status;
42169
42170 /*
42171@@ -382,11 +382,11 @@ again:
42172 IB_ACCESS_REMOTE_ATOMIC)))
42173 goto acc_err;
42174 /* Perform atomic OP and save result. */
42175- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42176+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42177 sdata = wqe->wr.wr.atomic.compare_add;
42178 *(u64 *) sqp->s_sge.sge.vaddr =
42179 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42180- (u64) atomic64_add_return(sdata, maddr) - sdata :
42181+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42182 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42183 sdata, wqe->wr.wr.atomic.swap);
42184 goto send_comp;
42185diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42186index fd36ec6..a6a082f 100644
42187--- a/drivers/infiniband/hw/mlx4/mad.c
42188+++ b/drivers/infiniband/hw/mlx4/mad.c
42189@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42190
42191 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42192 {
42193- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42194+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42195 cpu_to_be64(0xff00000000000000LL);
42196 }
42197
42198diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42199index ed327e6..ca1739e0 100644
42200--- a/drivers/infiniband/hw/mlx4/mcg.c
42201+++ b/drivers/infiniband/hw/mlx4/mcg.c
42202@@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42203 {
42204 char name[20];
42205
42206- atomic_set(&ctx->tid, 0);
42207+ atomic_set_unchecked(&ctx->tid, 0);
42208 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42209 ctx->mcg_wq = create_singlethread_workqueue(name);
42210 if (!ctx->mcg_wq)
42211diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42212index 66b0b7d..f14836a 100644
42213--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42214+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42215@@ -425,7 +425,7 @@ struct mlx4_ib_demux_ctx {
42216 struct list_head mcg_mgid0_list;
42217 struct workqueue_struct *mcg_wq;
42218 struct mlx4_ib_demux_pv_ctx **tun;
42219- atomic_t tid;
42220+ atomic_unchecked_t tid;
42221 int flushing; /* flushing the work queue */
42222 };
42223
42224diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42225index 9d3e5c1..6f166df 100644
42226--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42227+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42228@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42229 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42230 }
42231
42232-int mthca_QUERY_FW(struct mthca_dev *dev)
42233+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42234 {
42235 struct mthca_mailbox *mailbox;
42236 u32 *outbox;
42237@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42238 CMD_TIME_CLASS_B);
42239 }
42240
42241-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42242+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42243 int num_mtt)
42244 {
42245 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42246@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42247 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42248 }
42249
42250-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42251+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42252 int eq_num)
42253 {
42254 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42255@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42256 CMD_TIME_CLASS_B);
42257 }
42258
42259-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42260+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42261 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42262 void *in_mad, void *response_mad)
42263 {
42264diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42265index ded76c1..0cf0a08 100644
42266--- a/drivers/infiniband/hw/mthca/mthca_main.c
42267+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42268@@ -692,7 +692,7 @@ err_close:
42269 return err;
42270 }
42271
42272-static int mthca_setup_hca(struct mthca_dev *dev)
42273+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42274 {
42275 int err;
42276
42277diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42278index ed9a989..6aa5dc2 100644
42279--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42280+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42281@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42282 * through the bitmaps)
42283 */
42284
42285-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42286+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42287 {
42288 int o;
42289 int m;
42290@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42291 return key;
42292 }
42293
42294-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42295+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42296 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42297 {
42298 struct mthca_mailbox *mailbox;
42299@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42300 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42301 }
42302
42303-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42304+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42305 u64 *buffer_list, int buffer_size_shift,
42306 int list_len, u64 iova, u64 total_size,
42307 u32 access, struct mthca_mr *mr)
42308diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42309index 415f8e1..e34214e 100644
42310--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42311+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42312@@ -764,7 +764,7 @@ unlock:
42313 return 0;
42314 }
42315
42316-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42317+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42318 {
42319 struct mthca_dev *dev = to_mdev(ibcq->device);
42320 struct mthca_cq *cq = to_mcq(ibcq);
42321diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42322index 353c7b0..c6ce921 100644
42323--- a/drivers/infiniband/hw/nes/nes.c
42324+++ b/drivers/infiniband/hw/nes/nes.c
42325@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42326 LIST_HEAD(nes_adapter_list);
42327 static LIST_HEAD(nes_dev_list);
42328
42329-atomic_t qps_destroyed;
42330+atomic_unchecked_t qps_destroyed;
42331
42332 static unsigned int ee_flsh_adapter;
42333 static unsigned int sysfs_nonidx_addr;
42334@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42335 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42336 struct nes_adapter *nesadapter = nesdev->nesadapter;
42337
42338- atomic_inc(&qps_destroyed);
42339+ atomic_inc_unchecked(&qps_destroyed);
42340
42341 /* Free the control structures */
42342
42343diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42344index 33cc589..3bd6538 100644
42345--- a/drivers/infiniband/hw/nes/nes.h
42346+++ b/drivers/infiniband/hw/nes/nes.h
42347@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42348 extern unsigned int wqm_quanta;
42349 extern struct list_head nes_adapter_list;
42350
42351-extern atomic_t cm_connects;
42352-extern atomic_t cm_accepts;
42353-extern atomic_t cm_disconnects;
42354-extern atomic_t cm_closes;
42355-extern atomic_t cm_connecteds;
42356-extern atomic_t cm_connect_reqs;
42357-extern atomic_t cm_rejects;
42358-extern atomic_t mod_qp_timouts;
42359-extern atomic_t qps_created;
42360-extern atomic_t qps_destroyed;
42361-extern atomic_t sw_qps_destroyed;
42362+extern atomic_unchecked_t cm_connects;
42363+extern atomic_unchecked_t cm_accepts;
42364+extern atomic_unchecked_t cm_disconnects;
42365+extern atomic_unchecked_t cm_closes;
42366+extern atomic_unchecked_t cm_connecteds;
42367+extern atomic_unchecked_t cm_connect_reqs;
42368+extern atomic_unchecked_t cm_rejects;
42369+extern atomic_unchecked_t mod_qp_timouts;
42370+extern atomic_unchecked_t qps_created;
42371+extern atomic_unchecked_t qps_destroyed;
42372+extern atomic_unchecked_t sw_qps_destroyed;
42373 extern u32 mh_detected;
42374 extern u32 mh_pauses_sent;
42375 extern u32 cm_packets_sent;
42376@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42377 extern u32 cm_packets_received;
42378 extern u32 cm_packets_dropped;
42379 extern u32 cm_packets_retrans;
42380-extern atomic_t cm_listens_created;
42381-extern atomic_t cm_listens_destroyed;
42382+extern atomic_unchecked_t cm_listens_created;
42383+extern atomic_unchecked_t cm_listens_destroyed;
42384 extern u32 cm_backlog_drops;
42385-extern atomic_t cm_loopbacks;
42386-extern atomic_t cm_nodes_created;
42387-extern atomic_t cm_nodes_destroyed;
42388-extern atomic_t cm_accel_dropped_pkts;
42389-extern atomic_t cm_resets_recvd;
42390-extern atomic_t pau_qps_created;
42391-extern atomic_t pau_qps_destroyed;
42392+extern atomic_unchecked_t cm_loopbacks;
42393+extern atomic_unchecked_t cm_nodes_created;
42394+extern atomic_unchecked_t cm_nodes_destroyed;
42395+extern atomic_unchecked_t cm_accel_dropped_pkts;
42396+extern atomic_unchecked_t cm_resets_recvd;
42397+extern atomic_unchecked_t pau_qps_created;
42398+extern atomic_unchecked_t pau_qps_destroyed;
42399
42400 extern u32 int_mod_timer_init;
42401 extern u32 int_mod_cq_depth_256;
42402diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42403index dfa9df4..6bf7221 100644
42404--- a/drivers/infiniband/hw/nes/nes_cm.c
42405+++ b/drivers/infiniband/hw/nes/nes_cm.c
42406@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42407 u32 cm_packets_retrans;
42408 u32 cm_packets_created;
42409 u32 cm_packets_received;
42410-atomic_t cm_listens_created;
42411-atomic_t cm_listens_destroyed;
42412+atomic_unchecked_t cm_listens_created;
42413+atomic_unchecked_t cm_listens_destroyed;
42414 u32 cm_backlog_drops;
42415-atomic_t cm_loopbacks;
42416-atomic_t cm_nodes_created;
42417-atomic_t cm_nodes_destroyed;
42418-atomic_t cm_accel_dropped_pkts;
42419-atomic_t cm_resets_recvd;
42420+atomic_unchecked_t cm_loopbacks;
42421+atomic_unchecked_t cm_nodes_created;
42422+atomic_unchecked_t cm_nodes_destroyed;
42423+atomic_unchecked_t cm_accel_dropped_pkts;
42424+atomic_unchecked_t cm_resets_recvd;
42425
42426 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42427 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42428@@ -134,28 +134,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
42429 /* instance of function pointers for client API */
42430 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42431 static struct nes_cm_ops nes_cm_api = {
42432- mini_cm_accelerated,
42433- mini_cm_listen,
42434- mini_cm_del_listen,
42435- mini_cm_connect,
42436- mini_cm_close,
42437- mini_cm_accept,
42438- mini_cm_reject,
42439- mini_cm_recv_pkt,
42440- mini_cm_dealloc_core,
42441- mini_cm_get,
42442- mini_cm_set
42443+ .accelerated = mini_cm_accelerated,
42444+ .listen = mini_cm_listen,
42445+ .stop_listener = mini_cm_del_listen,
42446+ .connect = mini_cm_connect,
42447+ .close = mini_cm_close,
42448+ .accept = mini_cm_accept,
42449+ .reject = mini_cm_reject,
42450+ .recv_pkt = mini_cm_recv_pkt,
42451+ .destroy_cm_core = mini_cm_dealloc_core,
42452+ .get = mini_cm_get,
42453+ .set = mini_cm_set
42454 };
42455
42456 static struct nes_cm_core *g_cm_core;
42457
42458-atomic_t cm_connects;
42459-atomic_t cm_accepts;
42460-atomic_t cm_disconnects;
42461-atomic_t cm_closes;
42462-atomic_t cm_connecteds;
42463-atomic_t cm_connect_reqs;
42464-atomic_t cm_rejects;
42465+atomic_unchecked_t cm_connects;
42466+atomic_unchecked_t cm_accepts;
42467+atomic_unchecked_t cm_disconnects;
42468+atomic_unchecked_t cm_closes;
42469+atomic_unchecked_t cm_connecteds;
42470+atomic_unchecked_t cm_connect_reqs;
42471+atomic_unchecked_t cm_rejects;
42472
42473 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42474 {
42475@@ -1319,7 +1319,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42476 kfree(listener);
42477 listener = NULL;
42478 ret = 0;
42479- atomic_inc(&cm_listens_destroyed);
42480+ atomic_inc_unchecked(&cm_listens_destroyed);
42481 } else {
42482 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42483 }
42484@@ -1513,7 +1513,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42485 cm_node->rem_mac);
42486
42487 add_hte_node(cm_core, cm_node);
42488- atomic_inc(&cm_nodes_created);
42489+ atomic_inc_unchecked(&cm_nodes_created);
42490
42491 return cm_node;
42492 }
42493@@ -1571,7 +1571,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42494 }
42495
42496 atomic_dec(&cm_core->node_cnt);
42497- atomic_inc(&cm_nodes_destroyed);
42498+ atomic_inc_unchecked(&cm_nodes_destroyed);
42499 nesqp = cm_node->nesqp;
42500 if (nesqp) {
42501 nesqp->cm_node = NULL;
42502@@ -1635,7 +1635,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42503
42504 static void drop_packet(struct sk_buff *skb)
42505 {
42506- atomic_inc(&cm_accel_dropped_pkts);
42507+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42508 dev_kfree_skb_any(skb);
42509 }
42510
42511@@ -1698,7 +1698,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42512 {
42513
42514 int reset = 0; /* whether to send reset in case of err.. */
42515- atomic_inc(&cm_resets_recvd);
42516+ atomic_inc_unchecked(&cm_resets_recvd);
42517 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42518 " refcnt=%d\n", cm_node, cm_node->state,
42519 atomic_read(&cm_node->ref_count));
42520@@ -2339,7 +2339,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42521 rem_ref_cm_node(cm_node->cm_core, cm_node);
42522 return NULL;
42523 }
42524- atomic_inc(&cm_loopbacks);
42525+ atomic_inc_unchecked(&cm_loopbacks);
42526 loopbackremotenode->loopbackpartner = cm_node;
42527 loopbackremotenode->tcp_cntxt.rcv_wscale =
42528 NES_CM_DEFAULT_RCV_WND_SCALE;
42529@@ -2614,7 +2614,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42530 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42531 else {
42532 rem_ref_cm_node(cm_core, cm_node);
42533- atomic_inc(&cm_accel_dropped_pkts);
42534+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42535 dev_kfree_skb_any(skb);
42536 }
42537 break;
42538@@ -2922,7 +2922,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42539
42540 if ((cm_id) && (cm_id->event_handler)) {
42541 if (issue_disconn) {
42542- atomic_inc(&cm_disconnects);
42543+ atomic_inc_unchecked(&cm_disconnects);
42544 cm_event.event = IW_CM_EVENT_DISCONNECT;
42545 cm_event.status = disconn_status;
42546 cm_event.local_addr = cm_id->local_addr;
42547@@ -2944,7 +2944,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42548 }
42549
42550 if (issue_close) {
42551- atomic_inc(&cm_closes);
42552+ atomic_inc_unchecked(&cm_closes);
42553 nes_disconnect(nesqp, 1);
42554
42555 cm_id->provider_data = nesqp;
42556@@ -3082,7 +3082,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42557
42558 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42559 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42560- atomic_inc(&cm_accepts);
42561+ atomic_inc_unchecked(&cm_accepts);
42562
42563 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42564 netdev_refcnt_read(nesvnic->netdev));
42565@@ -3278,7 +3278,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42566 struct nes_cm_core *cm_core;
42567 u8 *start_buff;
42568
42569- atomic_inc(&cm_rejects);
42570+ atomic_inc_unchecked(&cm_rejects);
42571 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42572 loopback = cm_node->loopbackpartner;
42573 cm_core = cm_node->cm_core;
42574@@ -3340,7 +3340,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42575 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42576 ntohs(laddr->sin_port));
42577
42578- atomic_inc(&cm_connects);
42579+ atomic_inc_unchecked(&cm_connects);
42580 nesqp->active_conn = 1;
42581
42582 /* cache the cm_id in the qp */
42583@@ -3451,7 +3451,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42584 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42585 return err;
42586 }
42587- atomic_inc(&cm_listens_created);
42588+ atomic_inc_unchecked(&cm_listens_created);
42589 }
42590
42591 cm_id->add_ref(cm_id);
42592@@ -3558,7 +3558,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42593
42594 if (nesqp->destroyed)
42595 return;
42596- atomic_inc(&cm_connecteds);
42597+ atomic_inc_unchecked(&cm_connecteds);
42598 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42599 " local port 0x%04X. jiffies = %lu.\n",
42600 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42601@@ -3741,7 +3741,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42602
42603 cm_id->add_ref(cm_id);
42604 ret = cm_id->event_handler(cm_id, &cm_event);
42605- atomic_inc(&cm_closes);
42606+ atomic_inc_unchecked(&cm_closes);
42607 cm_event.event = IW_CM_EVENT_CLOSE;
42608 cm_event.status = 0;
42609 cm_event.provider_data = cm_id->provider_data;
42610@@ -3781,7 +3781,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42611 return;
42612 cm_id = cm_node->cm_id;
42613
42614- atomic_inc(&cm_connect_reqs);
42615+ atomic_inc_unchecked(&cm_connect_reqs);
42616 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42617 cm_node, cm_id, jiffies);
42618
42619@@ -3830,7 +3830,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42620 return;
42621 cm_id = cm_node->cm_id;
42622
42623- atomic_inc(&cm_connect_reqs);
42624+ atomic_inc_unchecked(&cm_connect_reqs);
42625 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42626 cm_node, cm_id, jiffies);
42627
42628diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42629index 4166452..fc952c3 100644
42630--- a/drivers/infiniband/hw/nes/nes_mgt.c
42631+++ b/drivers/infiniband/hw/nes/nes_mgt.c
42632@@ -40,8 +40,8 @@
42633 #include "nes.h"
42634 #include "nes_mgt.h"
42635
42636-atomic_t pau_qps_created;
42637-atomic_t pau_qps_destroyed;
42638+atomic_unchecked_t pau_qps_created;
42639+atomic_unchecked_t pau_qps_destroyed;
42640
42641 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42642 {
42643@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42644 {
42645 struct sk_buff *skb;
42646 unsigned long flags;
42647- atomic_inc(&pau_qps_destroyed);
42648+ atomic_inc_unchecked(&pau_qps_destroyed);
42649
42650 /* Free packets that have not yet been forwarded */
42651 /* Lock is acquired by skb_dequeue when removing the skb */
42652@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42653 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42654 skb_queue_head_init(&nesqp->pau_list);
42655 spin_lock_init(&nesqp->pau_lock);
42656- atomic_inc(&pau_qps_created);
42657+ atomic_inc_unchecked(&pau_qps_created);
42658 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42659 }
42660
42661diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42662index 49eb511..a774366 100644
42663--- a/drivers/infiniband/hw/nes/nes_nic.c
42664+++ b/drivers/infiniband/hw/nes/nes_nic.c
42665@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42666 target_stat_values[++index] = mh_detected;
42667 target_stat_values[++index] = mh_pauses_sent;
42668 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42669- target_stat_values[++index] = atomic_read(&cm_connects);
42670- target_stat_values[++index] = atomic_read(&cm_accepts);
42671- target_stat_values[++index] = atomic_read(&cm_disconnects);
42672- target_stat_values[++index] = atomic_read(&cm_connecteds);
42673- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42674- target_stat_values[++index] = atomic_read(&cm_rejects);
42675- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42676- target_stat_values[++index] = atomic_read(&qps_created);
42677- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42678- target_stat_values[++index] = atomic_read(&qps_destroyed);
42679- target_stat_values[++index] = atomic_read(&cm_closes);
42680+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42681+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42682+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42683+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42684+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42685+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42686+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42687+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42688+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42689+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42690+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42691 target_stat_values[++index] = cm_packets_sent;
42692 target_stat_values[++index] = cm_packets_bounced;
42693 target_stat_values[++index] = cm_packets_created;
42694 target_stat_values[++index] = cm_packets_received;
42695 target_stat_values[++index] = cm_packets_dropped;
42696 target_stat_values[++index] = cm_packets_retrans;
42697- target_stat_values[++index] = atomic_read(&cm_listens_created);
42698- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42699+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42700+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42701 target_stat_values[++index] = cm_backlog_drops;
42702- target_stat_values[++index] = atomic_read(&cm_loopbacks);
42703- target_stat_values[++index] = atomic_read(&cm_nodes_created);
42704- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42705- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42706- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42707+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42708+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42709+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42710+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42711+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42712 target_stat_values[++index] = nesadapter->free_4kpbl;
42713 target_stat_values[++index] = nesadapter->free_256pbl;
42714 target_stat_values[++index] = int_mod_timer_init;
42715 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42716 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42717 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42718- target_stat_values[++index] = atomic_read(&pau_qps_created);
42719- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42720+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42721+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42722 }
42723
42724 /**
42725diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42726index 218dd35..97ce31d 100644
42727--- a/drivers/infiniband/hw/nes/nes_verbs.c
42728+++ b/drivers/infiniband/hw/nes/nes_verbs.c
42729@@ -46,9 +46,9 @@
42730
42731 #include <rdma/ib_umem.h>
42732
42733-atomic_t mod_qp_timouts;
42734-atomic_t qps_created;
42735-atomic_t sw_qps_destroyed;
42736+atomic_unchecked_t mod_qp_timouts;
42737+atomic_unchecked_t qps_created;
42738+atomic_unchecked_t sw_qps_destroyed;
42739
42740 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42741
42742@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42743 if (init_attr->create_flags)
42744 return ERR_PTR(-EINVAL);
42745
42746- atomic_inc(&qps_created);
42747+ atomic_inc_unchecked(&qps_created);
42748 switch (init_attr->qp_type) {
42749 case IB_QPT_RC:
42750 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42751@@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42752 struct iw_cm_event cm_event;
42753 int ret = 0;
42754
42755- atomic_inc(&sw_qps_destroyed);
42756+ atomic_inc_unchecked(&sw_qps_destroyed);
42757 nesqp->destroyed = 1;
42758
42759 /* Blow away the connection if it exists. */
42760diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42761index c00ae09..04e91be 100644
42762--- a/drivers/infiniband/hw/qib/qib.h
42763+++ b/drivers/infiniband/hw/qib/qib.h
42764@@ -52,6 +52,7 @@
42765 #include <linux/kref.h>
42766 #include <linux/sched.h>
42767 #include <linux/kthread.h>
42768+#include <linux/slab.h>
42769
42770 #include "qib_common.h"
42771 #include "qib_verbs.h"
42772diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42773index 24c41ba..102d71f 100644
42774--- a/drivers/input/gameport/gameport.c
42775+++ b/drivers/input/gameport/gameport.c
42776@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42777 */
42778 static void gameport_init_port(struct gameport *gameport)
42779 {
42780- static atomic_t gameport_no = ATOMIC_INIT(0);
42781+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42782
42783 __module_get(THIS_MODULE);
42784
42785 mutex_init(&gameport->drv_mutex);
42786 device_initialize(&gameport->dev);
42787 dev_set_name(&gameport->dev, "gameport%lu",
42788- (unsigned long)atomic_inc_return(&gameport_no) - 1);
42789+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42790 gameport->dev.bus = &gameport_bus;
42791 gameport->dev.release = gameport_release_port;
42792 if (gameport->parent)
42793diff --git a/drivers/input/input.c b/drivers/input/input.c
42794index 1c4c0db..6f7abe3 100644
42795--- a/drivers/input/input.c
42796+++ b/drivers/input/input.c
42797@@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
42798 */
42799 struct input_dev *input_allocate_device(void)
42800 {
42801- static atomic_t input_no = ATOMIC_INIT(0);
42802+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42803 struct input_dev *dev;
42804
42805 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42806@@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
42807 INIT_LIST_HEAD(&dev->node);
42808
42809 dev_set_name(&dev->dev, "input%ld",
42810- (unsigned long) atomic_inc_return(&input_no) - 1);
42811+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42812
42813 __module_get(THIS_MODULE);
42814 }
42815diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42816index 4a95b22..874c182 100644
42817--- a/drivers/input/joystick/sidewinder.c
42818+++ b/drivers/input/joystick/sidewinder.c
42819@@ -30,6 +30,7 @@
42820 #include <linux/kernel.h>
42821 #include <linux/module.h>
42822 #include <linux/slab.h>
42823+#include <linux/sched.h>
42824 #include <linux/input.h>
42825 #include <linux/gameport.h>
42826 #include <linux/jiffies.h>
42827diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42828index 603fe0d..f63decc 100644
42829--- a/drivers/input/joystick/xpad.c
42830+++ b/drivers/input/joystick/xpad.c
42831@@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42832
42833 static int xpad_led_probe(struct usb_xpad *xpad)
42834 {
42835- static atomic_t led_seq = ATOMIC_INIT(0);
42836+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42837 long led_no;
42838 struct xpad_led *led;
42839 struct led_classdev *led_cdev;
42840@@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42841 if (!led)
42842 return -ENOMEM;
42843
42844- led_no = (long)atomic_inc_return(&led_seq) - 1;
42845+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42846
42847 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42848 led->xpad = xpad;
42849diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42850index 5a73639..d586683 100644
42851--- a/drivers/input/misc/ims-pcu.c
42852+++ b/drivers/input/misc/ims-pcu.c
42853@@ -1850,7 +1850,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42854
42855 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42856 {
42857- static atomic_t device_no = ATOMIC_INIT(0);
42858+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42859
42860 const struct ims_pcu_device_info *info;
42861 int error;
42862@@ -1881,7 +1881,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42863 }
42864
42865 /* Device appears to be operable, complete initialization */
42866- pcu->device_no = atomic_inc_return(&device_no) - 1;
42867+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42868
42869 /*
42870 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
42871diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42872index 2f0b39d..7370f13 100644
42873--- a/drivers/input/mouse/psmouse.h
42874+++ b/drivers/input/mouse/psmouse.h
42875@@ -116,7 +116,7 @@ struct psmouse_attribute {
42876 ssize_t (*set)(struct psmouse *psmouse, void *data,
42877 const char *buf, size_t count);
42878 bool protect;
42879-};
42880+} __do_const;
42881 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42882
42883 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42884diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42885index b604564..3f14ae4 100644
42886--- a/drivers/input/mousedev.c
42887+++ b/drivers/input/mousedev.c
42888@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42889
42890 spin_unlock_irq(&client->packet_lock);
42891
42892- if (copy_to_user(buffer, data, count))
42893+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
42894 return -EFAULT;
42895
42896 return count;
42897diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42898index b29134d..394deb0 100644
42899--- a/drivers/input/serio/serio.c
42900+++ b/drivers/input/serio/serio.c
42901@@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
42902 */
42903 static void serio_init_port(struct serio *serio)
42904 {
42905- static atomic_t serio_no = ATOMIC_INIT(0);
42906+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42907
42908 __module_get(THIS_MODULE);
42909
42910@@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
42911 mutex_init(&serio->drv_mutex);
42912 device_initialize(&serio->dev);
42913 dev_set_name(&serio->dev, "serio%ld",
42914- (long)atomic_inc_return(&serio_no) - 1);
42915+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
42916 serio->dev.bus = &serio_bus;
42917 serio->dev.release = serio_release_port;
42918 serio->dev.groups = serio_device_attr_groups;
42919diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42920index c9a02fe..0debc75 100644
42921--- a/drivers/input/serio/serio_raw.c
42922+++ b/drivers/input/serio/serio_raw.c
42923@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42924
42925 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42926 {
42927- static atomic_t serio_raw_no = ATOMIC_INIT(0);
42928+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42929 struct serio_raw *serio_raw;
42930 int err;
42931
42932@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42933 }
42934
42935 snprintf(serio_raw->name, sizeof(serio_raw->name),
42936- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42937+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42938 kref_init(&serio_raw->kref);
42939 INIT_LIST_HEAD(&serio_raw->client_list);
42940 init_waitqueue_head(&serio_raw->wait);
42941diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42942index e5555fc..937986d 100644
42943--- a/drivers/iommu/iommu.c
42944+++ b/drivers/iommu/iommu.c
42945@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42946 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42947 {
42948 bus_register_notifier(bus, &iommu_bus_nb);
42949- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42950+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42951 }
42952
42953 /**
42954diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42955index 228632c9..edfe331 100644
42956--- a/drivers/iommu/irq_remapping.c
42957+++ b/drivers/iommu/irq_remapping.c
42958@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42959 void panic_if_irq_remap(const char *msg)
42960 {
42961 if (irq_remapping_enabled)
42962- panic(msg);
42963+ panic("%s", msg);
42964 }
42965
42966 static void ir_ack_apic_edge(struct irq_data *data)
42967@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
42968
42969 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
42970 {
42971- chip->irq_print_chip = ir_print_prefix;
42972- chip->irq_ack = ir_ack_apic_edge;
42973- chip->irq_eoi = ir_ack_apic_level;
42974- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42975+ pax_open_kernel();
42976+ *(void **)&chip->irq_print_chip = ir_print_prefix;
42977+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
42978+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
42979+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42980+ pax_close_kernel();
42981 }
42982
42983 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
42984diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
42985index 57d165e..611997e 100644
42986--- a/drivers/irqchip/irq-gic.c
42987+++ b/drivers/irqchip/irq-gic.c
42988@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
42989 * Supported arch specific GIC irq extension.
42990 * Default make them NULL.
42991 */
42992-struct irq_chip gic_arch_extn = {
42993+irq_chip_no_const gic_arch_extn = {
42994 .irq_eoi = NULL,
42995 .irq_mask = NULL,
42996 .irq_unmask = NULL,
42997@@ -336,7 +336,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
42998 chained_irq_exit(chip, desc);
42999 }
43000
43001-static struct irq_chip gic_chip = {
43002+static irq_chip_no_const gic_chip __read_only = {
43003 .name = "GIC",
43004 .irq_mask = gic_mask_irq,
43005 .irq_unmask = gic_unmask_irq,
43006diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43007index 8777065..a4a9967 100644
43008--- a/drivers/irqchip/irq-renesas-irqc.c
43009+++ b/drivers/irqchip/irq-renesas-irqc.c
43010@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43011 struct irqc_priv *p;
43012 struct resource *io;
43013 struct resource *irq;
43014- struct irq_chip *irq_chip;
43015+ irq_chip_no_const *irq_chip;
43016 const char *name = dev_name(&pdev->dev);
43017 int ret;
43018 int k;
43019diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43020index ac6f72b..81150f2 100644
43021--- a/drivers/isdn/capi/capi.c
43022+++ b/drivers/isdn/capi/capi.c
43023@@ -81,8 +81,8 @@ struct capiminor {
43024
43025 struct capi20_appl *ap;
43026 u32 ncci;
43027- atomic_t datahandle;
43028- atomic_t msgid;
43029+ atomic_unchecked_t datahandle;
43030+ atomic_unchecked_t msgid;
43031
43032 struct tty_port port;
43033 int ttyinstop;
43034@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43035 capimsg_setu16(s, 2, mp->ap->applid);
43036 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43037 capimsg_setu8 (s, 5, CAPI_RESP);
43038- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43039+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43040 capimsg_setu32(s, 8, mp->ncci);
43041 capimsg_setu16(s, 12, datahandle);
43042 }
43043@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43044 mp->outbytes -= len;
43045 spin_unlock_bh(&mp->outlock);
43046
43047- datahandle = atomic_inc_return(&mp->datahandle);
43048+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43049 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43050 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43051 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43052 capimsg_setu16(skb->data, 2, mp->ap->applid);
43053 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43054 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43055- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43056+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43057 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43058 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43059 capimsg_setu16(skb->data, 16, len); /* Data length */
43060diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43061index c44950d..10ac276 100644
43062--- a/drivers/isdn/gigaset/bas-gigaset.c
43063+++ b/drivers/isdn/gigaset/bas-gigaset.c
43064@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43065
43066
43067 static const struct gigaset_ops gigops = {
43068- gigaset_write_cmd,
43069- gigaset_write_room,
43070- gigaset_chars_in_buffer,
43071- gigaset_brkchars,
43072- gigaset_init_bchannel,
43073- gigaset_close_bchannel,
43074- gigaset_initbcshw,
43075- gigaset_freebcshw,
43076- gigaset_reinitbcshw,
43077- gigaset_initcshw,
43078- gigaset_freecshw,
43079- gigaset_set_modem_ctrl,
43080- gigaset_baud_rate,
43081- gigaset_set_line_ctrl,
43082- gigaset_isoc_send_skb,
43083- gigaset_isoc_input,
43084+ .write_cmd = gigaset_write_cmd,
43085+ .write_room = gigaset_write_room,
43086+ .chars_in_buffer = gigaset_chars_in_buffer,
43087+ .brkchars = gigaset_brkchars,
43088+ .init_bchannel = gigaset_init_bchannel,
43089+ .close_bchannel = gigaset_close_bchannel,
43090+ .initbcshw = gigaset_initbcshw,
43091+ .freebcshw = gigaset_freebcshw,
43092+ .reinitbcshw = gigaset_reinitbcshw,
43093+ .initcshw = gigaset_initcshw,
43094+ .freecshw = gigaset_freecshw,
43095+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43096+ .baud_rate = gigaset_baud_rate,
43097+ .set_line_ctrl = gigaset_set_line_ctrl,
43098+ .send_skb = gigaset_isoc_send_skb,
43099+ .handle_input = gigaset_isoc_input,
43100 };
43101
43102 /* bas_gigaset_init
43103diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43104index 600c79b..3752bab 100644
43105--- a/drivers/isdn/gigaset/interface.c
43106+++ b/drivers/isdn/gigaset/interface.c
43107@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43108 }
43109 tty->driver_data = cs;
43110
43111- ++cs->port.count;
43112+ atomic_inc(&cs->port.count);
43113
43114- if (cs->port.count == 1) {
43115+ if (atomic_read(&cs->port.count) == 1) {
43116 tty_port_tty_set(&cs->port, tty);
43117 cs->port.low_latency = 1;
43118 }
43119@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43120
43121 if (!cs->connected)
43122 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43123- else if (!cs->port.count)
43124+ else if (!atomic_read(&cs->port.count))
43125 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43126- else if (!--cs->port.count)
43127+ else if (!atomic_dec_return(&cs->port.count))
43128 tty_port_tty_set(&cs->port, NULL);
43129
43130 mutex_unlock(&cs->mutex);
43131diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43132index 8c91fd5..14f13ce 100644
43133--- a/drivers/isdn/gigaset/ser-gigaset.c
43134+++ b/drivers/isdn/gigaset/ser-gigaset.c
43135@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43136 }
43137
43138 static const struct gigaset_ops ops = {
43139- gigaset_write_cmd,
43140- gigaset_write_room,
43141- gigaset_chars_in_buffer,
43142- gigaset_brkchars,
43143- gigaset_init_bchannel,
43144- gigaset_close_bchannel,
43145- gigaset_initbcshw,
43146- gigaset_freebcshw,
43147- gigaset_reinitbcshw,
43148- gigaset_initcshw,
43149- gigaset_freecshw,
43150- gigaset_set_modem_ctrl,
43151- gigaset_baud_rate,
43152- gigaset_set_line_ctrl,
43153- gigaset_m10x_send_skb, /* asyncdata.c */
43154- gigaset_m10x_input, /* asyncdata.c */
43155+ .write_cmd = gigaset_write_cmd,
43156+ .write_room = gigaset_write_room,
43157+ .chars_in_buffer = gigaset_chars_in_buffer,
43158+ .brkchars = gigaset_brkchars,
43159+ .init_bchannel = gigaset_init_bchannel,
43160+ .close_bchannel = gigaset_close_bchannel,
43161+ .initbcshw = gigaset_initbcshw,
43162+ .freebcshw = gigaset_freebcshw,
43163+ .reinitbcshw = gigaset_reinitbcshw,
43164+ .initcshw = gigaset_initcshw,
43165+ .freecshw = gigaset_freecshw,
43166+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43167+ .baud_rate = gigaset_baud_rate,
43168+ .set_line_ctrl = gigaset_set_line_ctrl,
43169+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43170+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43171 };
43172
43173
43174diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43175index d0a41cb..b953e50 100644
43176--- a/drivers/isdn/gigaset/usb-gigaset.c
43177+++ b/drivers/isdn/gigaset/usb-gigaset.c
43178@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43179 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43180 memcpy(cs->hw.usb->bchars, buf, 6);
43181 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43182- 0, 0, &buf, 6, 2000);
43183+ 0, 0, buf, 6, 2000);
43184 }
43185
43186 static void gigaset_freebcshw(struct bc_state *bcs)
43187@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43188 }
43189
43190 static const struct gigaset_ops ops = {
43191- gigaset_write_cmd,
43192- gigaset_write_room,
43193- gigaset_chars_in_buffer,
43194- gigaset_brkchars,
43195- gigaset_init_bchannel,
43196- gigaset_close_bchannel,
43197- gigaset_initbcshw,
43198- gigaset_freebcshw,
43199- gigaset_reinitbcshw,
43200- gigaset_initcshw,
43201- gigaset_freecshw,
43202- gigaset_set_modem_ctrl,
43203- gigaset_baud_rate,
43204- gigaset_set_line_ctrl,
43205- gigaset_m10x_send_skb,
43206- gigaset_m10x_input,
43207+ .write_cmd = gigaset_write_cmd,
43208+ .write_room = gigaset_write_room,
43209+ .chars_in_buffer = gigaset_chars_in_buffer,
43210+ .brkchars = gigaset_brkchars,
43211+ .init_bchannel = gigaset_init_bchannel,
43212+ .close_bchannel = gigaset_close_bchannel,
43213+ .initbcshw = gigaset_initbcshw,
43214+ .freebcshw = gigaset_freebcshw,
43215+ .reinitbcshw = gigaset_reinitbcshw,
43216+ .initcshw = gigaset_initcshw,
43217+ .freecshw = gigaset_freecshw,
43218+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43219+ .baud_rate = gigaset_baud_rate,
43220+ .set_line_ctrl = gigaset_set_line_ctrl,
43221+ .send_skb = gigaset_m10x_send_skb,
43222+ .handle_input = gigaset_m10x_input,
43223 };
43224
43225 /*
43226diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43227index 4d9b195..455075c 100644
43228--- a/drivers/isdn/hardware/avm/b1.c
43229+++ b/drivers/isdn/hardware/avm/b1.c
43230@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43231 }
43232 if (left) {
43233 if (t4file->user) {
43234- if (copy_from_user(buf, dp, left))
43235+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43236 return -EFAULT;
43237 } else {
43238 memcpy(buf, dp, left);
43239@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43240 }
43241 if (left) {
43242 if (config->user) {
43243- if (copy_from_user(buf, dp, left))
43244+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43245 return -EFAULT;
43246 } else {
43247 memcpy(buf, dp, left);
43248diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43249index 9b856e1..fa03c92 100644
43250--- a/drivers/isdn/i4l/isdn_common.c
43251+++ b/drivers/isdn/i4l/isdn_common.c
43252@@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43253 } else
43254 return -EINVAL;
43255 case IIOCDBGVAR:
43256+ if (!capable(CAP_SYS_RAWIO))
43257+ return -EPERM;
43258 if (arg) {
43259 if (copy_to_user(argp, &dev, sizeof(ulong)))
43260 return -EFAULT;
43261diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43262index 91d5730..336523e 100644
43263--- a/drivers/isdn/i4l/isdn_concap.c
43264+++ b/drivers/isdn/i4l/isdn_concap.c
43265@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43266 }
43267
43268 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43269- &isdn_concap_dl_data_req,
43270- &isdn_concap_dl_connect_req,
43271- &isdn_concap_dl_disconn_req
43272+ .data_req = &isdn_concap_dl_data_req,
43273+ .connect_req = &isdn_concap_dl_connect_req,
43274+ .disconn_req = &isdn_concap_dl_disconn_req
43275 };
43276
43277 /* The following should better go into a dedicated source file such that
43278diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43279index 3c5f249..5fac4d0 100644
43280--- a/drivers/isdn/i4l/isdn_tty.c
43281+++ b/drivers/isdn/i4l/isdn_tty.c
43282@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43283
43284 #ifdef ISDN_DEBUG_MODEM_OPEN
43285 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43286- port->count);
43287+ atomic_read(&port->count));
43288 #endif
43289- port->count++;
43290+ atomic_inc(&port->count);
43291 port->tty = tty;
43292 /*
43293 * Start up serial port
43294@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43295 #endif
43296 return;
43297 }
43298- if ((tty->count == 1) && (port->count != 1)) {
43299+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43300 /*
43301 * Uh, oh. tty->count is 1, which means that the tty
43302 * structure will be freed. Info->count should always
43303@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43304 * serial port won't be shutdown.
43305 */
43306 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43307- "info->count is %d\n", port->count);
43308- port->count = 1;
43309+ "info->count is %d\n", atomic_read(&port->count));
43310+ atomic_set(&port->count, 1);
43311 }
43312- if (--port->count < 0) {
43313+ if (atomic_dec_return(&port->count) < 0) {
43314 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43315- info->line, port->count);
43316- port->count = 0;
43317+ info->line, atomic_read(&port->count));
43318+ atomic_set(&port->count, 0);
43319 }
43320- if (port->count) {
43321+ if (atomic_read(&port->count)) {
43322 #ifdef ISDN_DEBUG_MODEM_OPEN
43323 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43324 #endif
43325@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43326 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43327 return;
43328 isdn_tty_shutdown(info);
43329- port->count = 0;
43330+ atomic_set(&port->count, 0);
43331 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43332 port->tty = NULL;
43333 wake_up_interruptible(&port->open_wait);
43334@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43335 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43336 modem_info *info = &dev->mdm.info[i];
43337
43338- if (info->port.count == 0)
43339+ if (atomic_read(&info->port.count) == 0)
43340 continue;
43341 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43342 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43343diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43344index e2d4e58..40cd045 100644
43345--- a/drivers/isdn/i4l/isdn_x25iface.c
43346+++ b/drivers/isdn/i4l/isdn_x25iface.c
43347@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43348
43349
43350 static struct concap_proto_ops ix25_pops = {
43351- &isdn_x25iface_proto_new,
43352- &isdn_x25iface_proto_del,
43353- &isdn_x25iface_proto_restart,
43354- &isdn_x25iface_proto_close,
43355- &isdn_x25iface_xmit,
43356- &isdn_x25iface_receive,
43357- &isdn_x25iface_connect_ind,
43358- &isdn_x25iface_disconn_ind
43359+ .proto_new = &isdn_x25iface_proto_new,
43360+ .proto_del = &isdn_x25iface_proto_del,
43361+ .restart = &isdn_x25iface_proto_restart,
43362+ .close = &isdn_x25iface_proto_close,
43363+ .encap_and_xmit = &isdn_x25iface_xmit,
43364+ .data_ind = &isdn_x25iface_receive,
43365+ .connect_ind = &isdn_x25iface_connect_ind,
43366+ .disconn_ind = &isdn_x25iface_disconn_ind
43367 };
43368
43369 /* error message helper function */
43370diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43371index 6a7447c..cae33fe 100644
43372--- a/drivers/isdn/icn/icn.c
43373+++ b/drivers/isdn/icn/icn.c
43374@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43375 if (count > len)
43376 count = len;
43377 if (user) {
43378- if (copy_from_user(msg, buf, count))
43379+ if (count > sizeof msg || copy_from_user(msg, buf, count))
43380 return -EFAULT;
43381 } else
43382 memcpy(msg, buf, count);
43383diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43384index a4f05c5..1433bc5 100644
43385--- a/drivers/isdn/mISDN/dsp_cmx.c
43386+++ b/drivers/isdn/mISDN/dsp_cmx.c
43387@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43388 static u16 dsp_count; /* last sample count */
43389 static int dsp_count_valid; /* if we have last sample count */
43390
43391-void
43392+void __intentional_overflow(-1)
43393 dsp_cmx_send(void *arg)
43394 {
43395 struct dsp_conf *conf;
43396diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43397index f58a354..fbae176 100644
43398--- a/drivers/leds/leds-clevo-mail.c
43399+++ b/drivers/leds/leds-clevo-mail.c
43400@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43401 * detected as working, but in reality it is not) as low as
43402 * possible.
43403 */
43404-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43405+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43406 {
43407 .callback = clevo_mail_led_dmi_callback,
43408 .ident = "Clevo D410J",
43409diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43410index 2eb3ef6..295891f 100644
43411--- a/drivers/leds/leds-ss4200.c
43412+++ b/drivers/leds/leds-ss4200.c
43413@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43414 * detected as working, but in reality it is not) as low as
43415 * possible.
43416 */
43417-static struct dmi_system_id nas_led_whitelist[] __initdata = {
43418+static struct dmi_system_id nas_led_whitelist[] __initconst = {
43419 {
43420 .callback = ss4200_led_dmi_callback,
43421 .ident = "Intel SS4200-E",
43422diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43423index 0bf1e4e..b4bf44e 100644
43424--- a/drivers/lguest/core.c
43425+++ b/drivers/lguest/core.c
43426@@ -97,9 +97,17 @@ static __init int map_switcher(void)
43427 * The end address needs +1 because __get_vm_area allocates an
43428 * extra guard page, so we need space for that.
43429 */
43430+
43431+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43432+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43433+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43434+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43435+#else
43436 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43437 VM_ALLOC, switcher_addr, switcher_addr
43438 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43439+#endif
43440+
43441 if (!switcher_vma) {
43442 err = -ENOMEM;
43443 printk("lguest: could not map switcher pages high\n");
43444@@ -124,7 +132,7 @@ static __init int map_switcher(void)
43445 * Now the Switcher is mapped at the right address, we can't fail!
43446 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43447 */
43448- memcpy(switcher_vma->addr, start_switcher_text,
43449+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43450 end_switcher_text - start_switcher_text);
43451
43452 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43453diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43454index e8b55c3..3514c37 100644
43455--- a/drivers/lguest/page_tables.c
43456+++ b/drivers/lguest/page_tables.c
43457@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43458 /*:*/
43459
43460 #ifdef CONFIG_X86_PAE
43461-static void release_pmd(pmd_t *spmd)
43462+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43463 {
43464 /* If the entry's not present, there's nothing to release. */
43465 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43466diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43467index 922a1ac..9dd0c2a 100644
43468--- a/drivers/lguest/x86/core.c
43469+++ b/drivers/lguest/x86/core.c
43470@@ -59,7 +59,7 @@ static struct {
43471 /* Offset from where switcher.S was compiled to where we've copied it */
43472 static unsigned long switcher_offset(void)
43473 {
43474- return switcher_addr - (unsigned long)start_switcher_text;
43475+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43476 }
43477
43478 /* This cpu's struct lguest_pages (after the Switcher text page) */
43479@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43480 * These copies are pretty cheap, so we do them unconditionally: */
43481 /* Save the current Host top-level page directory.
43482 */
43483+
43484+#ifdef CONFIG_PAX_PER_CPU_PGD
43485+ pages->state.host_cr3 = read_cr3();
43486+#else
43487 pages->state.host_cr3 = __pa(current->mm->pgd);
43488+#endif
43489+
43490 /*
43491 * Set up the Guest's page tables to see this CPU's pages (and no
43492 * other CPU's pages).
43493@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43494 * compiled-in switcher code and the high-mapped copy we just made.
43495 */
43496 for (i = 0; i < IDT_ENTRIES; i++)
43497- default_idt_entries[i] += switcher_offset();
43498+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43499
43500 /*
43501 * Set up the Switcher's per-cpu areas.
43502@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43503 * it will be undisturbed when we switch. To change %cs and jump we
43504 * need this structure to feed to Intel's "lcall" instruction.
43505 */
43506- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43507+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43508 lguest_entry.segment = LGUEST_CS;
43509
43510 /*
43511diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43512index 40634b0..4f5855e 100644
43513--- a/drivers/lguest/x86/switcher_32.S
43514+++ b/drivers/lguest/x86/switcher_32.S
43515@@ -87,6 +87,7 @@
43516 #include <asm/page.h>
43517 #include <asm/segment.h>
43518 #include <asm/lguest.h>
43519+#include <asm/processor-flags.h>
43520
43521 // We mark the start of the code to copy
43522 // It's placed in .text tho it's never run here
43523@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43524 // Changes type when we load it: damn Intel!
43525 // For after we switch over our page tables
43526 // That entry will be read-only: we'd crash.
43527+
43528+#ifdef CONFIG_PAX_KERNEXEC
43529+ mov %cr0, %edx
43530+ xor $X86_CR0_WP, %edx
43531+ mov %edx, %cr0
43532+#endif
43533+
43534 movl $(GDT_ENTRY_TSS*8), %edx
43535 ltr %dx
43536
43537@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43538 // Let's clear it again for our return.
43539 // The GDT descriptor of the Host
43540 // Points to the table after two "size" bytes
43541- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43542+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43543 // Clear "used" from type field (byte 5, bit 2)
43544- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43545+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43546+
43547+#ifdef CONFIG_PAX_KERNEXEC
43548+ mov %cr0, %eax
43549+ xor $X86_CR0_WP, %eax
43550+ mov %eax, %cr0
43551+#endif
43552
43553 // Once our page table's switched, the Guest is live!
43554 // The Host fades as we run this final step.
43555@@ -295,13 +309,12 @@ deliver_to_host:
43556 // I consulted gcc, and it gave
43557 // These instructions, which I gladly credit:
43558 leal (%edx,%ebx,8), %eax
43559- movzwl (%eax),%edx
43560- movl 4(%eax), %eax
43561- xorw %ax, %ax
43562- orl %eax, %edx
43563+ movl 4(%eax), %edx
43564+ movw (%eax), %dx
43565 // Now the address of the handler's in %edx
43566 // We call it now: its "iret" drops us home.
43567- jmp *%edx
43568+ ljmp $__KERNEL_CS, $1f
43569+1: jmp *%edx
43570
43571 // Every interrupt can come to us here
43572 // But we must truly tell each apart.
43573diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43574index 7ef7461..5a09dac 100644
43575--- a/drivers/md/bcache/closure.h
43576+++ b/drivers/md/bcache/closure.h
43577@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43578 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43579 struct workqueue_struct *wq)
43580 {
43581- BUG_ON(object_is_on_stack(cl));
43582+ BUG_ON(object_starts_on_stack(cl));
43583 closure_set_ip(cl);
43584 cl->fn = fn;
43585 cl->wq = wq;
43586diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43587index 9a8e66a..10cc762 100644
43588--- a/drivers/md/bitmap.c
43589+++ b/drivers/md/bitmap.c
43590@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43591 chunk_kb ? "KB" : "B");
43592 if (bitmap->storage.file) {
43593 seq_printf(seq, ", file: ");
43594- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43595+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43596 }
43597
43598 seq_printf(seq, "\n");
43599diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43600index 5152142..623d141 100644
43601--- a/drivers/md/dm-ioctl.c
43602+++ b/drivers/md/dm-ioctl.c
43603@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43604 cmd == DM_LIST_VERSIONS_CMD)
43605 return 0;
43606
43607- if ((cmd == DM_DEV_CREATE_CMD)) {
43608+ if (cmd == DM_DEV_CREATE_CMD) {
43609 if (!*param->name) {
43610 DMWARN("name not supplied when creating device");
43611 return -EINVAL;
43612diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43613index 7dfdb5c..4caada6 100644
43614--- a/drivers/md/dm-raid1.c
43615+++ b/drivers/md/dm-raid1.c
43616@@ -40,7 +40,7 @@ enum dm_raid1_error {
43617
43618 struct mirror {
43619 struct mirror_set *ms;
43620- atomic_t error_count;
43621+ atomic_unchecked_t error_count;
43622 unsigned long error_type;
43623 struct dm_dev *dev;
43624 sector_t offset;
43625@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43626 struct mirror *m;
43627
43628 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43629- if (!atomic_read(&m->error_count))
43630+ if (!atomic_read_unchecked(&m->error_count))
43631 return m;
43632
43633 return NULL;
43634@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43635 * simple way to tell if a device has encountered
43636 * errors.
43637 */
43638- atomic_inc(&m->error_count);
43639+ atomic_inc_unchecked(&m->error_count);
43640
43641 if (test_and_set_bit(error_type, &m->error_type))
43642 return;
43643@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43644 struct mirror *m = get_default_mirror(ms);
43645
43646 do {
43647- if (likely(!atomic_read(&m->error_count)))
43648+ if (likely(!atomic_read_unchecked(&m->error_count)))
43649 return m;
43650
43651 if (m-- == ms->mirror)
43652@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43653 {
43654 struct mirror *default_mirror = get_default_mirror(m->ms);
43655
43656- return !atomic_read(&default_mirror->error_count);
43657+ return !atomic_read_unchecked(&default_mirror->error_count);
43658 }
43659
43660 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43661@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43662 */
43663 if (likely(region_in_sync(ms, region, 1)))
43664 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43665- else if (m && atomic_read(&m->error_count))
43666+ else if (m && atomic_read_unchecked(&m->error_count))
43667 m = NULL;
43668
43669 if (likely(m))
43670@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43671 }
43672
43673 ms->mirror[mirror].ms = ms;
43674- atomic_set(&(ms->mirror[mirror].error_count), 0);
43675+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43676 ms->mirror[mirror].error_type = 0;
43677 ms->mirror[mirror].offset = offset;
43678
43679@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43680 */
43681 static char device_status_char(struct mirror *m)
43682 {
43683- if (!atomic_read(&(m->error_count)))
43684+ if (!atomic_read_unchecked(&(m->error_count)))
43685 return 'A';
43686
43687 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43688diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43689index 28a9012..9c0f6a5 100644
43690--- a/drivers/md/dm-stats.c
43691+++ b/drivers/md/dm-stats.c
43692@@ -382,7 +382,7 @@ do_sync_free:
43693 synchronize_rcu_expedited();
43694 dm_stat_free(&s->rcu_head);
43695 } else {
43696- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43697+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43698 call_rcu(&s->rcu_head, dm_stat_free);
43699 }
43700 return 0;
43701@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43702 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43703 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43704 ));
43705- ACCESS_ONCE(last->last_sector) = end_sector;
43706- ACCESS_ONCE(last->last_rw) = bi_rw;
43707+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
43708+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43709 }
43710
43711 rcu_read_lock();
43712diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43713index d1600d2..4c3af3a 100644
43714--- a/drivers/md/dm-stripe.c
43715+++ b/drivers/md/dm-stripe.c
43716@@ -21,7 +21,7 @@ struct stripe {
43717 struct dm_dev *dev;
43718 sector_t physical_start;
43719
43720- atomic_t error_count;
43721+ atomic_unchecked_t error_count;
43722 };
43723
43724 struct stripe_c {
43725@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43726 kfree(sc);
43727 return r;
43728 }
43729- atomic_set(&(sc->stripe[i].error_count), 0);
43730+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43731 }
43732
43733 ti->private = sc;
43734@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43735 DMEMIT("%d ", sc->stripes);
43736 for (i = 0; i < sc->stripes; i++) {
43737 DMEMIT("%s ", sc->stripe[i].dev->name);
43738- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43739+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43740 'D' : 'A';
43741 }
43742 buffer[i] = '\0';
43743@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43744 */
43745 for (i = 0; i < sc->stripes; i++)
43746 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43747- atomic_inc(&(sc->stripe[i].error_count));
43748- if (atomic_read(&(sc->stripe[i].error_count)) <
43749+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
43750+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43751 DM_IO_ERROR_THRESHOLD)
43752 schedule_work(&sc->trigger_event);
43753 }
43754diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43755index 50601ec..6d3b9dc 100644
43756--- a/drivers/md/dm-table.c
43757+++ b/drivers/md/dm-table.c
43758@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43759 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43760 struct mapped_device *md)
43761 {
43762- static char *_claim_ptr = "I belong to device-mapper";
43763+ static char _claim_ptr[] = "I belong to device-mapper";
43764 struct block_device *bdev;
43765
43766 int r;
43767@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43768 if (!dev_size)
43769 return 0;
43770
43771- if ((start >= dev_size) || (start + len > dev_size)) {
43772+ if ((start >= dev_size) || (len > dev_size - start)) {
43773 DMWARN("%s: %s too small for target: "
43774 "start=%llu, len=%llu, dev_size=%llu",
43775 dm_device_name(ti->table->md), bdevname(bdev, b),
43776diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43777index b086a94..74cb67e 100644
43778--- a/drivers/md/dm-thin-metadata.c
43779+++ b/drivers/md/dm-thin-metadata.c
43780@@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43781 {
43782 pmd->info.tm = pmd->tm;
43783 pmd->info.levels = 2;
43784- pmd->info.value_type.context = pmd->data_sm;
43785+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43786 pmd->info.value_type.size = sizeof(__le64);
43787 pmd->info.value_type.inc = data_block_inc;
43788 pmd->info.value_type.dec = data_block_dec;
43789@@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43790
43791 pmd->bl_info.tm = pmd->tm;
43792 pmd->bl_info.levels = 1;
43793- pmd->bl_info.value_type.context = pmd->data_sm;
43794+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43795 pmd->bl_info.value_type.size = sizeof(__le64);
43796 pmd->bl_info.value_type.inc = data_block_inc;
43797 pmd->bl_info.value_type.dec = data_block_dec;
43798diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43799index 455e649..1f214be 100644
43800--- a/drivers/md/dm.c
43801+++ b/drivers/md/dm.c
43802@@ -178,9 +178,9 @@ struct mapped_device {
43803 /*
43804 * Event handling.
43805 */
43806- atomic_t event_nr;
43807+ atomic_unchecked_t event_nr;
43808 wait_queue_head_t eventq;
43809- atomic_t uevent_seq;
43810+ atomic_unchecked_t uevent_seq;
43811 struct list_head uevent_list;
43812 spinlock_t uevent_lock; /* Protect access to uevent_list */
43813
43814@@ -1884,8 +1884,8 @@ static struct mapped_device *alloc_dev(int minor)
43815 spin_lock_init(&md->deferred_lock);
43816 atomic_set(&md->holders, 1);
43817 atomic_set(&md->open_count, 0);
43818- atomic_set(&md->event_nr, 0);
43819- atomic_set(&md->uevent_seq, 0);
43820+ atomic_set_unchecked(&md->event_nr, 0);
43821+ atomic_set_unchecked(&md->uevent_seq, 0);
43822 INIT_LIST_HEAD(&md->uevent_list);
43823 spin_lock_init(&md->uevent_lock);
43824
43825@@ -2039,7 +2039,7 @@ static void event_callback(void *context)
43826
43827 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43828
43829- atomic_inc(&md->event_nr);
43830+ atomic_inc_unchecked(&md->event_nr);
43831 wake_up(&md->eventq);
43832 }
43833
43834@@ -2732,18 +2732,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43835
43836 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43837 {
43838- return atomic_add_return(1, &md->uevent_seq);
43839+ return atomic_add_return_unchecked(1, &md->uevent_seq);
43840 }
43841
43842 uint32_t dm_get_event_nr(struct mapped_device *md)
43843 {
43844- return atomic_read(&md->event_nr);
43845+ return atomic_read_unchecked(&md->event_nr);
43846 }
43847
43848 int dm_wait_event(struct mapped_device *md, int event_nr)
43849 {
43850 return wait_event_interruptible(md->eventq,
43851- (event_nr != atomic_read(&md->event_nr)));
43852+ (event_nr != atomic_read_unchecked(&md->event_nr)));
43853 }
43854
43855 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43856diff --git a/drivers/md/md.c b/drivers/md/md.c
43857index 2382cfc..0d7e551 100644
43858--- a/drivers/md/md.c
43859+++ b/drivers/md/md.c
43860@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43861 * start build, activate spare
43862 */
43863 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43864-static atomic_t md_event_count;
43865+static atomic_unchecked_t md_event_count;
43866 void md_new_event(struct mddev *mddev)
43867 {
43868- atomic_inc(&md_event_count);
43869+ atomic_inc_unchecked(&md_event_count);
43870 wake_up(&md_event_waiters);
43871 }
43872 EXPORT_SYMBOL_GPL(md_new_event);
43873@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43874 */
43875 static void md_new_event_inintr(struct mddev *mddev)
43876 {
43877- atomic_inc(&md_event_count);
43878+ atomic_inc_unchecked(&md_event_count);
43879 wake_up(&md_event_waiters);
43880 }
43881
43882@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43883 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43884 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43885 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43886- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43887+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43888
43889 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43890 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43891@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43892 else
43893 sb->resync_offset = cpu_to_le64(0);
43894
43895- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43896+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43897
43898 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43899 sb->size = cpu_to_le64(mddev->dev_sectors);
43900@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43901 static ssize_t
43902 errors_show(struct md_rdev *rdev, char *page)
43903 {
43904- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43905+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43906 }
43907
43908 static ssize_t
43909@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43910 char *e;
43911 unsigned long n = simple_strtoul(buf, &e, 10);
43912 if (*buf && (*e == 0 || *e == '\n')) {
43913- atomic_set(&rdev->corrected_errors, n);
43914+ atomic_set_unchecked(&rdev->corrected_errors, n);
43915 return len;
43916 }
43917 return -EINVAL;
43918@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
43919 rdev->sb_loaded = 0;
43920 rdev->bb_page = NULL;
43921 atomic_set(&rdev->nr_pending, 0);
43922- atomic_set(&rdev->read_errors, 0);
43923- atomic_set(&rdev->corrected_errors, 0);
43924+ atomic_set_unchecked(&rdev->read_errors, 0);
43925+ atomic_set_unchecked(&rdev->corrected_errors, 0);
43926
43927 INIT_LIST_HEAD(&rdev->same_set);
43928 init_waitqueue_head(&rdev->blocked_wait);
43929@@ -7058,7 +7058,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43930
43931 spin_unlock(&pers_lock);
43932 seq_printf(seq, "\n");
43933- seq->poll_event = atomic_read(&md_event_count);
43934+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43935 return 0;
43936 }
43937 if (v == (void*)2) {
43938@@ -7161,7 +7161,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43939 return error;
43940
43941 seq = file->private_data;
43942- seq->poll_event = atomic_read(&md_event_count);
43943+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43944 return error;
43945 }
43946
43947@@ -7178,7 +7178,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43948 /* always allow read */
43949 mask = POLLIN | POLLRDNORM;
43950
43951- if (seq->poll_event != atomic_read(&md_event_count))
43952+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43953 mask |= POLLERR | POLLPRI;
43954 return mask;
43955 }
43956@@ -7222,7 +7222,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43957 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43958 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43959 (int)part_stat_read(&disk->part0, sectors[1]) -
43960- atomic_read(&disk->sync_io);
43961+ atomic_read_unchecked(&disk->sync_io);
43962 /* sync IO will cause sync_io to increase before the disk_stats
43963 * as sync_io is counted when a request starts, and
43964 * disk_stats is counted when it completes.
43965diff --git a/drivers/md/md.h b/drivers/md/md.h
43966index a49d991..3582bb7 100644
43967--- a/drivers/md/md.h
43968+++ b/drivers/md/md.h
43969@@ -94,13 +94,13 @@ struct md_rdev {
43970 * only maintained for arrays that
43971 * support hot removal
43972 */
43973- atomic_t read_errors; /* number of consecutive read errors that
43974+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
43975 * we have tried to ignore.
43976 */
43977 struct timespec last_read_error; /* monotonic time since our
43978 * last read error
43979 */
43980- atomic_t corrected_errors; /* number of corrected read errors,
43981+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
43982 * for reporting to userspace and storing
43983 * in superblock.
43984 */
43985@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
43986
43987 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
43988 {
43989- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43990+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43991 }
43992
43993 struct md_personality
43994diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
43995index 786b689..ea8c956 100644
43996--- a/drivers/md/persistent-data/dm-space-map-metadata.c
43997+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
43998@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
43999 * Flick into a mode where all blocks get allocated in the new area.
44000 */
44001 smm->begin = old_len;
44002- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44003+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44004
44005 /*
44006 * Extend.
44007@@ -710,7 +710,7 @@ out:
44008 /*
44009 * Switch back to normal behaviour.
44010 */
44011- memcpy(sm, &ops, sizeof(*sm));
44012+ memcpy((void *)sm, &ops, sizeof(*sm));
44013 return r;
44014 }
44015
44016diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44017index 3e6d115..ffecdeb 100644
44018--- a/drivers/md/persistent-data/dm-space-map.h
44019+++ b/drivers/md/persistent-data/dm-space-map.h
44020@@ -71,6 +71,7 @@ struct dm_space_map {
44021 dm_sm_threshold_fn fn,
44022 void *context);
44023 };
44024+typedef struct dm_space_map __no_const dm_space_map_no_const;
44025
44026 /*----------------------------------------------------------------*/
44027
44028diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44029index 56e24c0..e1c8e1f 100644
44030--- a/drivers/md/raid1.c
44031+++ b/drivers/md/raid1.c
44032@@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44033 if (r1_sync_page_io(rdev, sect, s,
44034 bio->bi_io_vec[idx].bv_page,
44035 READ) != 0)
44036- atomic_add(s, &rdev->corrected_errors);
44037+ atomic_add_unchecked(s, &rdev->corrected_errors);
44038 }
44039 sectors -= s;
44040 sect += s;
44041@@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44042 test_bit(In_sync, &rdev->flags)) {
44043 if (r1_sync_page_io(rdev, sect, s,
44044 conf->tmppage, READ)) {
44045- atomic_add(s, &rdev->corrected_errors);
44046+ atomic_add_unchecked(s, &rdev->corrected_errors);
44047 printk(KERN_INFO
44048 "md/raid1:%s: read error corrected "
44049 "(%d sectors at %llu on %s)\n",
44050diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44051index cb882aa..9bd076e 100644
44052--- a/drivers/md/raid10.c
44053+++ b/drivers/md/raid10.c
44054@@ -1949,7 +1949,7 @@ static void end_sync_read(struct bio *bio, int error)
44055 /* The write handler will notice the lack of
44056 * R10BIO_Uptodate and record any errors etc
44057 */
44058- atomic_add(r10_bio->sectors,
44059+ atomic_add_unchecked(r10_bio->sectors,
44060 &conf->mirrors[d].rdev->corrected_errors);
44061
44062 /* for reconstruct, we always reschedule after a read.
44063@@ -2307,7 +2307,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44064 {
44065 struct timespec cur_time_mon;
44066 unsigned long hours_since_last;
44067- unsigned int read_errors = atomic_read(&rdev->read_errors);
44068+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44069
44070 ktime_get_ts(&cur_time_mon);
44071
44072@@ -2329,9 +2329,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44073 * overflowing the shift of read_errors by hours_since_last.
44074 */
44075 if (hours_since_last >= 8 * sizeof(read_errors))
44076- atomic_set(&rdev->read_errors, 0);
44077+ atomic_set_unchecked(&rdev->read_errors, 0);
44078 else
44079- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44080+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44081 }
44082
44083 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44084@@ -2385,8 +2385,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44085 return;
44086
44087 check_decay_read_errors(mddev, rdev);
44088- atomic_inc(&rdev->read_errors);
44089- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44090+ atomic_inc_unchecked(&rdev->read_errors);
44091+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44092 char b[BDEVNAME_SIZE];
44093 bdevname(rdev->bdev, b);
44094
44095@@ -2394,7 +2394,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44096 "md/raid10:%s: %s: Raid device exceeded "
44097 "read_error threshold [cur %d:max %d]\n",
44098 mdname(mddev), b,
44099- atomic_read(&rdev->read_errors), max_read_errors);
44100+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44101 printk(KERN_NOTICE
44102 "md/raid10:%s: %s: Failing raid device\n",
44103 mdname(mddev), b);
44104@@ -2549,7 +2549,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44105 sect +
44106 choose_data_offset(r10_bio, rdev)),
44107 bdevname(rdev->bdev, b));
44108- atomic_add(s, &rdev->corrected_errors);
44109+ atomic_add_unchecked(s, &rdev->corrected_errors);
44110 }
44111
44112 rdev_dec_pending(rdev, mddev);
44113diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44114index ad1b9be..b417412 100644
44115--- a/drivers/md/raid5.c
44116+++ b/drivers/md/raid5.c
44117@@ -1702,6 +1702,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44118 return 1;
44119 }
44120
44121+#ifdef CONFIG_GRKERNSEC_HIDESYM
44122+static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44123+#endif
44124+
44125 static int grow_stripes(struct r5conf *conf, int num)
44126 {
44127 struct kmem_cache *sc;
44128@@ -1713,7 +1717,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44129 "raid%d-%s", conf->level, mdname(conf->mddev));
44130 else
44131 sprintf(conf->cache_name[0],
44132+#ifdef CONFIG_GRKERNSEC_HIDESYM
44133+ "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44134+#else
44135 "raid%d-%p", conf->level, conf->mddev);
44136+#endif
44137 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44138
44139 conf->active_name = 0;
44140@@ -1986,21 +1994,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44141 mdname(conf->mddev), STRIPE_SECTORS,
44142 (unsigned long long)s,
44143 bdevname(rdev->bdev, b));
44144- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44145+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44146 clear_bit(R5_ReadError, &sh->dev[i].flags);
44147 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44148 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44149 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44150
44151- if (atomic_read(&rdev->read_errors))
44152- atomic_set(&rdev->read_errors, 0);
44153+ if (atomic_read_unchecked(&rdev->read_errors))
44154+ atomic_set_unchecked(&rdev->read_errors, 0);
44155 } else {
44156 const char *bdn = bdevname(rdev->bdev, b);
44157 int retry = 0;
44158 int set_bad = 0;
44159
44160 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44161- atomic_inc(&rdev->read_errors);
44162+ atomic_inc_unchecked(&rdev->read_errors);
44163 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44164 printk_ratelimited(
44165 KERN_WARNING
44166@@ -2028,7 +2036,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44167 mdname(conf->mddev),
44168 (unsigned long long)s,
44169 bdn);
44170- } else if (atomic_read(&rdev->read_errors)
44171+ } else if (atomic_read_unchecked(&rdev->read_errors)
44172 > conf->max_nr_stripes)
44173 printk(KERN_WARNING
44174 "md/raid:%s: Too many read errors, failing device %s.\n",
44175diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44176index 983db75..ef9248c 100644
44177--- a/drivers/media/dvb-core/dvbdev.c
44178+++ b/drivers/media/dvb-core/dvbdev.c
44179@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44180 const struct dvb_device *template, void *priv, int type)
44181 {
44182 struct dvb_device *dvbdev;
44183- struct file_operations *dvbdevfops;
44184+ file_operations_no_const *dvbdevfops;
44185 struct device *clsdev;
44186 int minor;
44187 int id;
44188diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
44189index 539f4db..cdd403b 100644
44190--- a/drivers/media/dvb-frontends/af9033.h
44191+++ b/drivers/media/dvb-frontends/af9033.h
44192@@ -82,7 +82,7 @@ struct af9033_ops {
44193 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
44194 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
44195 int onoff);
44196-};
44197+} __no_const;
44198
44199
44200 #if IS_ENABLED(CONFIG_DVB_AF9033)
44201diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44202index 9b6c3bb..baeb5c7 100644
44203--- a/drivers/media/dvb-frontends/dib3000.h
44204+++ b/drivers/media/dvb-frontends/dib3000.h
44205@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44206 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44207 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44208 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44209-};
44210+} __no_const;
44211
44212 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44213 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44214diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44215index ed8cb90..5ef7f79 100644
44216--- a/drivers/media/pci/cx88/cx88-video.c
44217+++ b/drivers/media/pci/cx88/cx88-video.c
44218@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44219
44220 /* ------------------------------------------------------------------ */
44221
44222-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44223-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44224-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44225+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44226+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44227+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44228
44229 module_param_array(video_nr, int, NULL, 0444);
44230 module_param_array(vbi_nr, int, NULL, 0444);
44231diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44232index 802642d..5534900 100644
44233--- a/drivers/media/pci/ivtv/ivtv-driver.c
44234+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44235@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44236 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44237
44238 /* ivtv instance counter */
44239-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44240+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44241
44242 /* Parameter declarations */
44243 static int cardtype[IVTV_MAX_CARDS];
44244diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44245index 9a726ea..f5e9b52 100644
44246--- a/drivers/media/platform/omap/omap_vout.c
44247+++ b/drivers/media/platform/omap/omap_vout.c
44248@@ -63,7 +63,6 @@ enum omap_vout_channels {
44249 OMAP_VIDEO2,
44250 };
44251
44252-static struct videobuf_queue_ops video_vbq_ops;
44253 /* Variables configurable through module params*/
44254 static u32 video1_numbuffers = 3;
44255 static u32 video2_numbuffers = 3;
44256@@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
44257 {
44258 struct videobuf_queue *q;
44259 struct omap_vout_device *vout = NULL;
44260+ static struct videobuf_queue_ops video_vbq_ops = {
44261+ .buf_setup = omap_vout_buffer_setup,
44262+ .buf_prepare = omap_vout_buffer_prepare,
44263+ .buf_release = omap_vout_buffer_release,
44264+ .buf_queue = omap_vout_buffer_queue,
44265+ };
44266
44267 vout = video_drvdata(file);
44268 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44269@@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
44270 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44271
44272 q = &vout->vbq;
44273- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44274- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44275- video_vbq_ops.buf_release = omap_vout_buffer_release;
44276- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44277 spin_lock_init(&vout->vbq_lock);
44278
44279 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44280diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44281index fb2acc5..a2fcbdc4 100644
44282--- a/drivers/media/platform/s5p-tv/mixer.h
44283+++ b/drivers/media/platform/s5p-tv/mixer.h
44284@@ -156,7 +156,7 @@ struct mxr_layer {
44285 /** layer index (unique identifier) */
44286 int idx;
44287 /** callbacks for layer methods */
44288- struct mxr_layer_ops ops;
44289+ struct mxr_layer_ops *ops;
44290 /** format array */
44291 const struct mxr_format **fmt_array;
44292 /** size of format array */
44293diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44294index 74344c7..a39e70e 100644
44295--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44296+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44297@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44298 {
44299 struct mxr_layer *layer;
44300 int ret;
44301- struct mxr_layer_ops ops = {
44302+ static struct mxr_layer_ops ops = {
44303 .release = mxr_graph_layer_release,
44304 .buffer_set = mxr_graph_buffer_set,
44305 .stream_set = mxr_graph_stream_set,
44306diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44307index b713403..53cb5ad 100644
44308--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44309+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44310@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44311 layer->update_buf = next;
44312 }
44313
44314- layer->ops.buffer_set(layer, layer->update_buf);
44315+ layer->ops->buffer_set(layer, layer->update_buf);
44316
44317 if (done && done != layer->shadow_buf)
44318 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44319diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44320index a1ce55f..4a3c4d9 100644
44321--- a/drivers/media/platform/s5p-tv/mixer_video.c
44322+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44323@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44324 layer->geo.src.height = layer->geo.src.full_height;
44325
44326 mxr_geometry_dump(mdev, &layer->geo);
44327- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44328+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44329 mxr_geometry_dump(mdev, &layer->geo);
44330 }
44331
44332@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44333 layer->geo.dst.full_width = mbus_fmt.width;
44334 layer->geo.dst.full_height = mbus_fmt.height;
44335 layer->geo.dst.field = mbus_fmt.field;
44336- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44337+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44338
44339 mxr_geometry_dump(mdev, &layer->geo);
44340 }
44341@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44342 /* set source size to highest accepted value */
44343 geo->src.full_width = max(geo->dst.full_width, pix->width);
44344 geo->src.full_height = max(geo->dst.full_height, pix->height);
44345- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44346+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44347 mxr_geometry_dump(mdev, &layer->geo);
44348 /* set cropping to total visible screen */
44349 geo->src.width = pix->width;
44350@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44351 geo->src.x_offset = 0;
44352 geo->src.y_offset = 0;
44353 /* assure consistency of geometry */
44354- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44355+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44356 mxr_geometry_dump(mdev, &layer->geo);
44357 /* set full size to lowest possible value */
44358 geo->src.full_width = 0;
44359 geo->src.full_height = 0;
44360- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44361+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44362 mxr_geometry_dump(mdev, &layer->geo);
44363
44364 /* returning results */
44365@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44366 target->width = s->r.width;
44367 target->height = s->r.height;
44368
44369- layer->ops.fix_geometry(layer, stage, s->flags);
44370+ layer->ops->fix_geometry(layer, stage, s->flags);
44371
44372 /* retrieve update selection rectangle */
44373 res.left = target->x_offset;
44374@@ -950,13 +950,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44375 mxr_output_get(mdev);
44376
44377 mxr_layer_update_output(layer);
44378- layer->ops.format_set(layer);
44379+ layer->ops->format_set(layer);
44380 /* enabling layer in hardware */
44381 spin_lock_irqsave(&layer->enq_slock, flags);
44382 layer->state = MXR_LAYER_STREAMING;
44383 spin_unlock_irqrestore(&layer->enq_slock, flags);
44384
44385- layer->ops.stream_set(layer, MXR_ENABLE);
44386+ layer->ops->stream_set(layer, MXR_ENABLE);
44387 mxr_streamer_get(mdev);
44388
44389 return 0;
44390@@ -1026,7 +1026,7 @@ static int stop_streaming(struct vb2_queue *vq)
44391 spin_unlock_irqrestore(&layer->enq_slock, flags);
44392
44393 /* disabling layer in hardware */
44394- layer->ops.stream_set(layer, MXR_DISABLE);
44395+ layer->ops->stream_set(layer, MXR_DISABLE);
44396 /* remove one streamer */
44397 mxr_streamer_put(mdev);
44398 /* allow changes in output configuration */
44399@@ -1065,8 +1065,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44400
44401 void mxr_layer_release(struct mxr_layer *layer)
44402 {
44403- if (layer->ops.release)
44404- layer->ops.release(layer);
44405+ if (layer->ops->release)
44406+ layer->ops->release(layer);
44407 }
44408
44409 void mxr_base_layer_release(struct mxr_layer *layer)
44410@@ -1092,7 +1092,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44411
44412 layer->mdev = mdev;
44413 layer->idx = idx;
44414- layer->ops = *ops;
44415+ layer->ops = ops;
44416
44417 spin_lock_init(&layer->enq_slock);
44418 INIT_LIST_HEAD(&layer->enq_list);
44419diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44420index c9388c4..ce71ece 100644
44421--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44422+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44423@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44424 {
44425 struct mxr_layer *layer;
44426 int ret;
44427- struct mxr_layer_ops ops = {
44428+ static struct mxr_layer_ops ops = {
44429 .release = mxr_vp_layer_release,
44430 .buffer_set = mxr_vp_buffer_set,
44431 .stream_set = mxr_vp_stream_set,
44432diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44433index 3890f4f..b5c7511 100644
44434--- a/drivers/media/platform/vivi.c
44435+++ b/drivers/media/platform/vivi.c
44436@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44437 MODULE_LICENSE("Dual BSD/GPL");
44438 MODULE_VERSION(VIVI_VERSION);
44439
44440-static unsigned video_nr = -1;
44441-module_param(video_nr, uint, 0644);
44442+static int video_nr = -1;
44443+module_param(video_nr, int, 0644);
44444 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44445
44446 static unsigned n_devs = 1;
44447diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44448index d719e59..63f3470 100644
44449--- a/drivers/media/radio/radio-cadet.c
44450+++ b/drivers/media/radio/radio-cadet.c
44451@@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44452 unsigned char readbuf[RDS_BUFFER];
44453 int i = 0;
44454
44455+ if (count > RDS_BUFFER)
44456+ return -EFAULT;
44457 mutex_lock(&dev->lock);
44458 if (dev->rdsstat == 0)
44459 cadet_start_rds(dev);
44460@@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44461 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44462 mutex_unlock(&dev->lock);
44463
44464- if (i && copy_to_user(data, readbuf, i))
44465- return -EFAULT;
44466+ if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
44467+ i = -EFAULT;
44468+
44469 return i;
44470 }
44471
44472diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44473index 5236035..c622c74 100644
44474--- a/drivers/media/radio/radio-maxiradio.c
44475+++ b/drivers/media/radio/radio-maxiradio.c
44476@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44477 /* TEA5757 pin mappings */
44478 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44479
44480-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44481+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44482
44483 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44484 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44485diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44486index 050b3bb..79f62b9 100644
44487--- a/drivers/media/radio/radio-shark.c
44488+++ b/drivers/media/radio/radio-shark.c
44489@@ -79,7 +79,7 @@ struct shark_device {
44490 u32 last_val;
44491 };
44492
44493-static atomic_t shark_instance = ATOMIC_INIT(0);
44494+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44495
44496 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44497 {
44498diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44499index 8654e0d..0608a64 100644
44500--- a/drivers/media/radio/radio-shark2.c
44501+++ b/drivers/media/radio/radio-shark2.c
44502@@ -74,7 +74,7 @@ struct shark_device {
44503 u8 *transfer_buffer;
44504 };
44505
44506-static atomic_t shark_instance = ATOMIC_INIT(0);
44507+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44508
44509 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44510 {
44511diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44512index 2fd9009..278cc1e 100644
44513--- a/drivers/media/radio/radio-si476x.c
44514+++ b/drivers/media/radio/radio-si476x.c
44515@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44516 struct si476x_radio *radio;
44517 struct v4l2_ctrl *ctrl;
44518
44519- static atomic_t instance = ATOMIC_INIT(0);
44520+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
44521
44522 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44523 if (!radio)
44524diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44525index a1c641e..3007da9 100644
44526--- a/drivers/media/usb/dvb-usb/cxusb.c
44527+++ b/drivers/media/usb/dvb-usb/cxusb.c
44528@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44529
44530 struct dib0700_adapter_state {
44531 int (*set_param_save) (struct dvb_frontend *);
44532-};
44533+} __no_const;
44534
44535 static int dib7070_set_param_override(struct dvb_frontend *fe)
44536 {
44537diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44538index ae0f56a..ec71784 100644
44539--- a/drivers/media/usb/dvb-usb/dw2102.c
44540+++ b/drivers/media/usb/dvb-usb/dw2102.c
44541@@ -118,7 +118,7 @@ struct su3000_state {
44542
44543 struct s6x0_state {
44544 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44545-};
44546+} __no_const;
44547
44548 /* debug */
44549 static int dvb_usb_dw2102_debug;
44550diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44551index 7e2411c..cef73ca 100644
44552--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44553+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44554@@ -328,7 +328,7 @@ struct v4l2_buffer32 {
44555 __u32 reserved;
44556 };
44557
44558-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44559+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44560 enum v4l2_memory memory)
44561 {
44562 void __user *up_pln;
44563@@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44564 return 0;
44565 }
44566
44567-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44568+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44569 enum v4l2_memory memory)
44570 {
44571 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44572@@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44573 * by passing a very big num_planes value */
44574 uplane = compat_alloc_user_space(num_planes *
44575 sizeof(struct v4l2_plane));
44576- kp->m.planes = uplane;
44577+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44578
44579 while (--num_planes >= 0) {
44580 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44581@@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44582 if (num_planes == 0)
44583 return 0;
44584
44585- uplane = kp->m.planes;
44586+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44587 if (get_user(p, &up->m.planes))
44588 return -EFAULT;
44589 uplane32 = compat_ptr(p);
44590@@ -552,7 +552,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44591 get_user(kp->capability, &up->capability) ||
44592 get_user(kp->flags, &up->flags))
44593 return -EFAULT;
44594- kp->base = compat_ptr(tmp);
44595+ kp->base = (void __force_kernel *)compat_ptr(tmp);
44596 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44597 return 0;
44598 }
44599@@ -658,7 +658,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44600 n * sizeof(struct v4l2_ext_control32)))
44601 return -EFAULT;
44602 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44603- kp->controls = kcontrols;
44604+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44605 while (--n >= 0) {
44606 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44607 return -EFAULT;
44608@@ -680,7 +680,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44609 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44610 {
44611 struct v4l2_ext_control32 __user *ucontrols;
44612- struct v4l2_ext_control __user *kcontrols = kp->controls;
44613+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44614 int n = kp->count;
44615 compat_caddr_t p;
44616
44617@@ -774,7 +774,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
44618 put_user(kp->start_block, &up->start_block) ||
44619 put_user(kp->blocks, &up->blocks) ||
44620 put_user(tmp, &up->edid) ||
44621- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44622+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44623 return -EFAULT;
44624 return 0;
44625 }
44626diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44627index 55c6832..a91c7a6 100644
44628--- a/drivers/media/v4l2-core/v4l2-ctrls.c
44629+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44630@@ -1431,8 +1431,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44631 return 0;
44632
44633 case V4L2_CTRL_TYPE_STRING:
44634- len = strlen(c->string);
44635- if (len < ctrl->minimum)
44636+ len = strlen_user(c->string);
44637+ if (!len || len < ctrl->minimum)
44638 return -ERANGE;
44639 if ((len - ctrl->minimum) % ctrl->step)
44640 return -ERANGE;
44641diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44642index 02d1b63..5fd6b16 100644
44643--- a/drivers/media/v4l2-core/v4l2-device.c
44644+++ b/drivers/media/v4l2-core/v4l2-device.c
44645@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44646 EXPORT_SYMBOL_GPL(v4l2_device_put);
44647
44648 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44649- atomic_t *instance)
44650+ atomic_unchecked_t *instance)
44651 {
44652- int num = atomic_inc_return(instance) - 1;
44653+ int num = atomic_inc_return_unchecked(instance) - 1;
44654 int len = strlen(basename);
44655
44656 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44657diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44658index d9113cc..7de6ccc 100644
44659--- a/drivers/media/v4l2-core/v4l2-ioctl.c
44660+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44661@@ -2003,7 +2003,8 @@ struct v4l2_ioctl_info {
44662 struct file *file, void *fh, void *p);
44663 } u;
44664 void (*debug)(const void *arg, bool write_only);
44665-};
44666+} __do_const;
44667+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44668
44669 /* This control needs a priority check */
44670 #define INFO_FL_PRIO (1 << 0)
44671@@ -2186,7 +2187,7 @@ static long __video_do_ioctl(struct file *file,
44672 struct video_device *vfd = video_devdata(file);
44673 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44674 bool write_only = false;
44675- struct v4l2_ioctl_info default_info;
44676+ v4l2_ioctl_info_no_const default_info;
44677 const struct v4l2_ioctl_info *info;
44678 void *fh = file->private_data;
44679 struct v4l2_fh *vfh = NULL;
44680@@ -2260,7 +2261,7 @@ done:
44681 }
44682
44683 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44684- void * __user *user_ptr, void ***kernel_ptr)
44685+ void __user **user_ptr, void ***kernel_ptr)
44686 {
44687 int ret = 0;
44688
44689@@ -2276,7 +2277,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44690 ret = -EINVAL;
44691 break;
44692 }
44693- *user_ptr = (void __user *)buf->m.planes;
44694+ *user_ptr = (void __force_user *)buf->m.planes;
44695 *kernel_ptr = (void *)&buf->m.planes;
44696 *array_size = sizeof(struct v4l2_plane) * buf->length;
44697 ret = 1;
44698@@ -2311,7 +2312,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44699 ret = -EINVAL;
44700 break;
44701 }
44702- *user_ptr = (void __user *)ctrls->controls;
44703+ *user_ptr = (void __force_user *)ctrls->controls;
44704 *kernel_ptr = (void *)&ctrls->controls;
44705 *array_size = sizeof(struct v4l2_ext_control)
44706 * ctrls->count;
44707@@ -2412,7 +2413,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44708 }
44709
44710 if (has_array_args) {
44711- *kernel_ptr = user_ptr;
44712+ *kernel_ptr = (void __force_kernel *)user_ptr;
44713 if (copy_to_user(user_ptr, mbuf, array_size))
44714 err = -EFAULT;
44715 goto out_array_args;
44716diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44717index 570b18a..f880314 100644
44718--- a/drivers/message/fusion/mptbase.c
44719+++ b/drivers/message/fusion/mptbase.c
44720@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44721 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44722 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44723
44724+#ifdef CONFIG_GRKERNSEC_HIDESYM
44725+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44726+#else
44727 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44728 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44729+#endif
44730+
44731 /*
44732 * Rounding UP to nearest 4-kB boundary here...
44733 */
44734@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44735 ioc->facts.GlobalCredits);
44736
44737 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44738+#ifdef CONFIG_GRKERNSEC_HIDESYM
44739+ NULL, NULL);
44740+#else
44741 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44742+#endif
44743 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44744 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44745 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44746diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44747index 00d339c..2ea899d 100644
44748--- a/drivers/message/fusion/mptsas.c
44749+++ b/drivers/message/fusion/mptsas.c
44750@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44751 return 0;
44752 }
44753
44754+static inline void
44755+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44756+{
44757+ if (phy_info->port_details) {
44758+ phy_info->port_details->rphy = rphy;
44759+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44760+ ioc->name, rphy));
44761+ }
44762+
44763+ if (rphy) {
44764+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44765+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44766+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44767+ ioc->name, rphy, rphy->dev.release));
44768+ }
44769+}
44770+
44771 /* no mutex */
44772 static void
44773 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44774@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44775 return NULL;
44776 }
44777
44778-static inline void
44779-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44780-{
44781- if (phy_info->port_details) {
44782- phy_info->port_details->rphy = rphy;
44783- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44784- ioc->name, rphy));
44785- }
44786-
44787- if (rphy) {
44788- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44789- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44790- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44791- ioc->name, rphy, rphy->dev.release));
44792- }
44793-}
44794-
44795 static inline struct sas_port *
44796 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44797 {
44798diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44799index 727819c..ad74694 100644
44800--- a/drivers/message/fusion/mptscsih.c
44801+++ b/drivers/message/fusion/mptscsih.c
44802@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44803
44804 h = shost_priv(SChost);
44805
44806- if (h) {
44807- if (h->info_kbuf == NULL)
44808- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44809- return h->info_kbuf;
44810- h->info_kbuf[0] = '\0';
44811+ if (!h)
44812+ return NULL;
44813
44814- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44815- h->info_kbuf[size-1] = '\0';
44816- }
44817+ if (h->info_kbuf == NULL)
44818+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44819+ return h->info_kbuf;
44820+ h->info_kbuf[0] = '\0';
44821+
44822+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44823+ h->info_kbuf[size-1] = '\0';
44824
44825 return h->info_kbuf;
44826 }
44827diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44828index b7d87cd..3fb36da 100644
44829--- a/drivers/message/i2o/i2o_proc.c
44830+++ b/drivers/message/i2o/i2o_proc.c
44831@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44832 "Array Controller Device"
44833 };
44834
44835-static char *chtostr(char *tmp, u8 *chars, int n)
44836-{
44837- tmp[0] = 0;
44838- return strncat(tmp, (char *)chars, n);
44839-}
44840-
44841 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44842 char *group)
44843 {
44844@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44845 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44846 {
44847 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44848- static u32 work32[5];
44849- static u8 *work8 = (u8 *) work32;
44850- static u16 *work16 = (u16 *) work32;
44851+ u32 work32[5];
44852+ u8 *work8 = (u8 *) work32;
44853+ u16 *work16 = (u16 *) work32;
44854 int token;
44855 u32 hwcap;
44856
44857@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44858 } *result;
44859
44860 i2o_exec_execute_ddm_table ddm_table;
44861- char tmp[28 + 1];
44862
44863 result = kmalloc(sizeof(*result), GFP_KERNEL);
44864 if (!result)
44865@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44866
44867 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44868 seq_printf(seq, "%-#8x", ddm_table.module_id);
44869- seq_printf(seq, "%-29s",
44870- chtostr(tmp, ddm_table.module_name_version, 28));
44871+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44872 seq_printf(seq, "%9d ", ddm_table.data_size);
44873 seq_printf(seq, "%8d", ddm_table.code_size);
44874
44875@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44876
44877 i2o_driver_result_table *result;
44878 i2o_driver_store_table *dst;
44879- char tmp[28 + 1];
44880
44881 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44882 if (result == NULL)
44883@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44884
44885 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44886 seq_printf(seq, "%-#8x", dst->module_id);
44887- seq_printf(seq, "%-29s",
44888- chtostr(tmp, dst->module_name_version, 28));
44889- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44890+ seq_printf(seq, "%-.28s", dst->module_name_version);
44891+ seq_printf(seq, "%-.8s", dst->date);
44892 seq_printf(seq, "%8d ", dst->module_size);
44893 seq_printf(seq, "%8d ", dst->mpb_size);
44894 seq_printf(seq, "0x%04x", dst->module_flags);
44895@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44896 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44897 {
44898 struct i2o_device *d = (struct i2o_device *)seq->private;
44899- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44900+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44901 // == (allow) 512d bytes (max)
44902- static u16 *work16 = (u16 *) work32;
44903+ u16 *work16 = (u16 *) work32;
44904 int token;
44905- char tmp[16 + 1];
44906
44907 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44908
44909@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44910 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44911 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44912 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44913- seq_printf(seq, "Vendor info : %s\n",
44914- chtostr(tmp, (u8 *) (work32 + 2), 16));
44915- seq_printf(seq, "Product info : %s\n",
44916- chtostr(tmp, (u8 *) (work32 + 6), 16));
44917- seq_printf(seq, "Description : %s\n",
44918- chtostr(tmp, (u8 *) (work32 + 10), 16));
44919- seq_printf(seq, "Product rev. : %s\n",
44920- chtostr(tmp, (u8 *) (work32 + 14), 8));
44921+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44922+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44923+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44924+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44925
44926 seq_printf(seq, "Serial number : ");
44927 print_serial_number(seq, (u8 *) (work32 + 16),
44928@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44929 u8 pad[256]; // allow up to 256 byte (max) serial number
44930 } result;
44931
44932- char tmp[24 + 1];
44933-
44934 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44935
44936 if (token < 0) {
44937@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44938 }
44939
44940 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44941- seq_printf(seq, "Module name : %s\n",
44942- chtostr(tmp, result.module_name, 24));
44943- seq_printf(seq, "Module revision : %s\n",
44944- chtostr(tmp, result.module_rev, 8));
44945+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
44946+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44947
44948 seq_printf(seq, "Serial number : ");
44949 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44950@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44951 u8 instance_number[4];
44952 } result;
44953
44954- char tmp[64 + 1];
44955-
44956 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44957
44958 if (token < 0) {
44959@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44960 return 0;
44961 }
44962
44963- seq_printf(seq, "Device name : %s\n",
44964- chtostr(tmp, result.device_name, 64));
44965- seq_printf(seq, "Service name : %s\n",
44966- chtostr(tmp, result.service_name, 64));
44967- seq_printf(seq, "Physical name : %s\n",
44968- chtostr(tmp, result.physical_location, 64));
44969- seq_printf(seq, "Instance number : %s\n",
44970- chtostr(tmp, result.instance_number, 4));
44971+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
44972+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
44973+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44974+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44975
44976 return 0;
44977 }
44978@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44979 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44980 {
44981 struct i2o_device *d = (struct i2o_device *)seq->private;
44982- static u32 work32[12];
44983- static u16 *work16 = (u16 *) work32;
44984- static u8 *work8 = (u8 *) work32;
44985+ u32 work32[12];
44986+ u16 *work16 = (u16 *) work32;
44987+ u8 *work8 = (u8 *) work32;
44988 int token;
44989
44990 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
44991diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
44992index 92752fb..a7494f6 100644
44993--- a/drivers/message/i2o/iop.c
44994+++ b/drivers/message/i2o/iop.c
44995@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
44996
44997 spin_lock_irqsave(&c->context_list_lock, flags);
44998
44999- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45000- atomic_inc(&c->context_list_counter);
45001+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45002+ atomic_inc_unchecked(&c->context_list_counter);
45003
45004- entry->context = atomic_read(&c->context_list_counter);
45005+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45006
45007 list_add(&entry->list, &c->context_list);
45008
45009@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45010
45011 #if BITS_PER_LONG == 64
45012 spin_lock_init(&c->context_list_lock);
45013- atomic_set(&c->context_list_counter, 0);
45014+ atomic_set_unchecked(&c->context_list_counter, 0);
45015 INIT_LIST_HEAD(&c->context_list);
45016 #endif
45017
45018diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45019index d1a22aa..d0f7bf7 100644
45020--- a/drivers/mfd/ab8500-debugfs.c
45021+++ b/drivers/mfd/ab8500-debugfs.c
45022@@ -100,7 +100,7 @@ static int irq_last;
45023 static u32 *irq_count;
45024 static int num_irqs;
45025
45026-static struct device_attribute **dev_attr;
45027+static device_attribute_no_const **dev_attr;
45028 static char **event_name;
45029
45030 static u8 avg_sample = SAMPLE_16;
45031diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45032index a83eed5..62a58a9 100644
45033--- a/drivers/mfd/max8925-i2c.c
45034+++ b/drivers/mfd/max8925-i2c.c
45035@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45036 const struct i2c_device_id *id)
45037 {
45038 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45039- static struct max8925_chip *chip;
45040+ struct max8925_chip *chip;
45041 struct device_node *node = client->dev.of_node;
45042
45043 if (node && !pdata) {
45044diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45045index 460a014..21d3061 100644
45046--- a/drivers/mfd/tps65910.c
45047+++ b/drivers/mfd/tps65910.c
45048@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45049 struct tps65910_platform_data *pdata)
45050 {
45051 int ret = 0;
45052- static struct regmap_irq_chip *tps6591x_irqs_chip;
45053+ struct regmap_irq_chip *tps6591x_irqs_chip;
45054
45055 if (!irq) {
45056 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45057diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45058index 596b1f6..5b6ab74 100644
45059--- a/drivers/mfd/twl4030-irq.c
45060+++ b/drivers/mfd/twl4030-irq.c
45061@@ -34,6 +34,7 @@
45062 #include <linux/of.h>
45063 #include <linux/irqdomain.h>
45064 #include <linux/i2c/twl.h>
45065+#include <asm/pgtable.h>
45066
45067 #include "twl-core.h"
45068
45069@@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45070 * Install an irq handler for each of the SIH modules;
45071 * clone dummy irq_chip since PIH can't *do* anything
45072 */
45073- twl4030_irq_chip = dummy_irq_chip;
45074- twl4030_irq_chip.name = "twl4030";
45075+ pax_open_kernel();
45076+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45077+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45078
45079- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45080+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45081+ pax_close_kernel();
45082
45083 for (i = irq_base; i < irq_end; i++) {
45084 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45085diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45086index 464419b..64bae8d 100644
45087--- a/drivers/misc/c2port/core.c
45088+++ b/drivers/misc/c2port/core.c
45089@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45090 goto error_idr_alloc;
45091 c2dev->id = ret;
45092
45093- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45094+ pax_open_kernel();
45095+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45096+ pax_close_kernel();
45097
45098 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45099 "c2port%d", c2dev->id);
45100diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45101index 3f2b625..945e179 100644
45102--- a/drivers/misc/eeprom/sunxi_sid.c
45103+++ b/drivers/misc/eeprom/sunxi_sid.c
45104@@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45105
45106 platform_set_drvdata(pdev, sid_data);
45107
45108- sid_bin_attr.size = sid_data->keysize;
45109+ pax_open_kernel();
45110+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45111+ pax_close_kernel();
45112 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45113 return -ENODEV;
45114
45115diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45116index 36f5d52..32311c3 100644
45117--- a/drivers/misc/kgdbts.c
45118+++ b/drivers/misc/kgdbts.c
45119@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45120 char before[BREAK_INSTR_SIZE];
45121 char after[BREAK_INSTR_SIZE];
45122
45123- probe_kernel_read(before, (char *)kgdbts_break_test,
45124+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45125 BREAK_INSTR_SIZE);
45126 init_simple_test();
45127 ts.tst = plant_and_detach_test;
45128@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45129 /* Activate test with initial breakpoint */
45130 if (!is_early)
45131 kgdb_breakpoint();
45132- probe_kernel_read(after, (char *)kgdbts_break_test,
45133+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45134 BREAK_INSTR_SIZE);
45135 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45136 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45137diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45138index 3ef4627..8d00486 100644
45139--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45140+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45141@@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45142 * the lid is closed. This leads to interrupts as soon as a little move
45143 * is done.
45144 */
45145- atomic_inc(&lis3->count);
45146+ atomic_inc_unchecked(&lis3->count);
45147
45148 wake_up_interruptible(&lis3->misc_wait);
45149 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45150@@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45151 if (lis3->pm_dev)
45152 pm_runtime_get_sync(lis3->pm_dev);
45153
45154- atomic_set(&lis3->count, 0);
45155+ atomic_set_unchecked(&lis3->count, 0);
45156 return 0;
45157 }
45158
45159@@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45160 add_wait_queue(&lis3->misc_wait, &wait);
45161 while (true) {
45162 set_current_state(TASK_INTERRUPTIBLE);
45163- data = atomic_xchg(&lis3->count, 0);
45164+ data = atomic_xchg_unchecked(&lis3->count, 0);
45165 if (data)
45166 break;
45167
45168@@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45169 struct lis3lv02d, miscdev);
45170
45171 poll_wait(file, &lis3->misc_wait, wait);
45172- if (atomic_read(&lis3->count))
45173+ if (atomic_read_unchecked(&lis3->count))
45174 return POLLIN | POLLRDNORM;
45175 return 0;
45176 }
45177diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45178index c439c82..1f20f57 100644
45179--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45180+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45181@@ -297,7 +297,7 @@ struct lis3lv02d {
45182 struct input_polled_dev *idev; /* input device */
45183 struct platform_device *pdev; /* platform device */
45184 struct regulator_bulk_data regulators[2];
45185- atomic_t count; /* interrupt count after last read */
45186+ atomic_unchecked_t count; /* interrupt count after last read */
45187 union axis_conversion ac; /* hw -> logical axis */
45188 int mapped_btns[3];
45189
45190diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45191index 2f30bad..c4c13d0 100644
45192--- a/drivers/misc/sgi-gru/gruhandles.c
45193+++ b/drivers/misc/sgi-gru/gruhandles.c
45194@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45195 unsigned long nsec;
45196
45197 nsec = CLKS2NSEC(clks);
45198- atomic_long_inc(&mcs_op_statistics[op].count);
45199- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45200+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45201+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45202 if (mcs_op_statistics[op].max < nsec)
45203 mcs_op_statistics[op].max = nsec;
45204 }
45205diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45206index 4f76359..cdfcb2e 100644
45207--- a/drivers/misc/sgi-gru/gruprocfs.c
45208+++ b/drivers/misc/sgi-gru/gruprocfs.c
45209@@ -32,9 +32,9 @@
45210
45211 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45212
45213-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45214+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45215 {
45216- unsigned long val = atomic_long_read(v);
45217+ unsigned long val = atomic_long_read_unchecked(v);
45218
45219 seq_printf(s, "%16lu %s\n", val, id);
45220 }
45221@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45222
45223 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45224 for (op = 0; op < mcsop_last; op++) {
45225- count = atomic_long_read(&mcs_op_statistics[op].count);
45226- total = atomic_long_read(&mcs_op_statistics[op].total);
45227+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45228+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45229 max = mcs_op_statistics[op].max;
45230 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45231 count ? total / count : 0, max);
45232diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45233index 5c3ce24..4915ccb 100644
45234--- a/drivers/misc/sgi-gru/grutables.h
45235+++ b/drivers/misc/sgi-gru/grutables.h
45236@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45237 * GRU statistics.
45238 */
45239 struct gru_stats_s {
45240- atomic_long_t vdata_alloc;
45241- atomic_long_t vdata_free;
45242- atomic_long_t gts_alloc;
45243- atomic_long_t gts_free;
45244- atomic_long_t gms_alloc;
45245- atomic_long_t gms_free;
45246- atomic_long_t gts_double_allocate;
45247- atomic_long_t assign_context;
45248- atomic_long_t assign_context_failed;
45249- atomic_long_t free_context;
45250- atomic_long_t load_user_context;
45251- atomic_long_t load_kernel_context;
45252- atomic_long_t lock_kernel_context;
45253- atomic_long_t unlock_kernel_context;
45254- atomic_long_t steal_user_context;
45255- atomic_long_t steal_kernel_context;
45256- atomic_long_t steal_context_failed;
45257- atomic_long_t nopfn;
45258- atomic_long_t asid_new;
45259- atomic_long_t asid_next;
45260- atomic_long_t asid_wrap;
45261- atomic_long_t asid_reuse;
45262- atomic_long_t intr;
45263- atomic_long_t intr_cbr;
45264- atomic_long_t intr_tfh;
45265- atomic_long_t intr_spurious;
45266- atomic_long_t intr_mm_lock_failed;
45267- atomic_long_t call_os;
45268- atomic_long_t call_os_wait_queue;
45269- atomic_long_t user_flush_tlb;
45270- atomic_long_t user_unload_context;
45271- atomic_long_t user_exception;
45272- atomic_long_t set_context_option;
45273- atomic_long_t check_context_retarget_intr;
45274- atomic_long_t check_context_unload;
45275- atomic_long_t tlb_dropin;
45276- atomic_long_t tlb_preload_page;
45277- atomic_long_t tlb_dropin_fail_no_asid;
45278- atomic_long_t tlb_dropin_fail_upm;
45279- atomic_long_t tlb_dropin_fail_invalid;
45280- atomic_long_t tlb_dropin_fail_range_active;
45281- atomic_long_t tlb_dropin_fail_idle;
45282- atomic_long_t tlb_dropin_fail_fmm;
45283- atomic_long_t tlb_dropin_fail_no_exception;
45284- atomic_long_t tfh_stale_on_fault;
45285- atomic_long_t mmu_invalidate_range;
45286- atomic_long_t mmu_invalidate_page;
45287- atomic_long_t flush_tlb;
45288- atomic_long_t flush_tlb_gru;
45289- atomic_long_t flush_tlb_gru_tgh;
45290- atomic_long_t flush_tlb_gru_zero_asid;
45291+ atomic_long_unchecked_t vdata_alloc;
45292+ atomic_long_unchecked_t vdata_free;
45293+ atomic_long_unchecked_t gts_alloc;
45294+ atomic_long_unchecked_t gts_free;
45295+ atomic_long_unchecked_t gms_alloc;
45296+ atomic_long_unchecked_t gms_free;
45297+ atomic_long_unchecked_t gts_double_allocate;
45298+ atomic_long_unchecked_t assign_context;
45299+ atomic_long_unchecked_t assign_context_failed;
45300+ atomic_long_unchecked_t free_context;
45301+ atomic_long_unchecked_t load_user_context;
45302+ atomic_long_unchecked_t load_kernel_context;
45303+ atomic_long_unchecked_t lock_kernel_context;
45304+ atomic_long_unchecked_t unlock_kernel_context;
45305+ atomic_long_unchecked_t steal_user_context;
45306+ atomic_long_unchecked_t steal_kernel_context;
45307+ atomic_long_unchecked_t steal_context_failed;
45308+ atomic_long_unchecked_t nopfn;
45309+ atomic_long_unchecked_t asid_new;
45310+ atomic_long_unchecked_t asid_next;
45311+ atomic_long_unchecked_t asid_wrap;
45312+ atomic_long_unchecked_t asid_reuse;
45313+ atomic_long_unchecked_t intr;
45314+ atomic_long_unchecked_t intr_cbr;
45315+ atomic_long_unchecked_t intr_tfh;
45316+ atomic_long_unchecked_t intr_spurious;
45317+ atomic_long_unchecked_t intr_mm_lock_failed;
45318+ atomic_long_unchecked_t call_os;
45319+ atomic_long_unchecked_t call_os_wait_queue;
45320+ atomic_long_unchecked_t user_flush_tlb;
45321+ atomic_long_unchecked_t user_unload_context;
45322+ atomic_long_unchecked_t user_exception;
45323+ atomic_long_unchecked_t set_context_option;
45324+ atomic_long_unchecked_t check_context_retarget_intr;
45325+ atomic_long_unchecked_t check_context_unload;
45326+ atomic_long_unchecked_t tlb_dropin;
45327+ atomic_long_unchecked_t tlb_preload_page;
45328+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45329+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45330+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45331+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45332+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45333+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45334+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45335+ atomic_long_unchecked_t tfh_stale_on_fault;
45336+ atomic_long_unchecked_t mmu_invalidate_range;
45337+ atomic_long_unchecked_t mmu_invalidate_page;
45338+ atomic_long_unchecked_t flush_tlb;
45339+ atomic_long_unchecked_t flush_tlb_gru;
45340+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45341+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45342
45343- atomic_long_t copy_gpa;
45344- atomic_long_t read_gpa;
45345+ atomic_long_unchecked_t copy_gpa;
45346+ atomic_long_unchecked_t read_gpa;
45347
45348- atomic_long_t mesq_receive;
45349- atomic_long_t mesq_receive_none;
45350- atomic_long_t mesq_send;
45351- atomic_long_t mesq_send_failed;
45352- atomic_long_t mesq_noop;
45353- atomic_long_t mesq_send_unexpected_error;
45354- atomic_long_t mesq_send_lb_overflow;
45355- atomic_long_t mesq_send_qlimit_reached;
45356- atomic_long_t mesq_send_amo_nacked;
45357- atomic_long_t mesq_send_put_nacked;
45358- atomic_long_t mesq_page_overflow;
45359- atomic_long_t mesq_qf_locked;
45360- atomic_long_t mesq_qf_noop_not_full;
45361- atomic_long_t mesq_qf_switch_head_failed;
45362- atomic_long_t mesq_qf_unexpected_error;
45363- atomic_long_t mesq_noop_unexpected_error;
45364- atomic_long_t mesq_noop_lb_overflow;
45365- atomic_long_t mesq_noop_qlimit_reached;
45366- atomic_long_t mesq_noop_amo_nacked;
45367- atomic_long_t mesq_noop_put_nacked;
45368- atomic_long_t mesq_noop_page_overflow;
45369+ atomic_long_unchecked_t mesq_receive;
45370+ atomic_long_unchecked_t mesq_receive_none;
45371+ atomic_long_unchecked_t mesq_send;
45372+ atomic_long_unchecked_t mesq_send_failed;
45373+ atomic_long_unchecked_t mesq_noop;
45374+ atomic_long_unchecked_t mesq_send_unexpected_error;
45375+ atomic_long_unchecked_t mesq_send_lb_overflow;
45376+ atomic_long_unchecked_t mesq_send_qlimit_reached;
45377+ atomic_long_unchecked_t mesq_send_amo_nacked;
45378+ atomic_long_unchecked_t mesq_send_put_nacked;
45379+ atomic_long_unchecked_t mesq_page_overflow;
45380+ atomic_long_unchecked_t mesq_qf_locked;
45381+ atomic_long_unchecked_t mesq_qf_noop_not_full;
45382+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
45383+ atomic_long_unchecked_t mesq_qf_unexpected_error;
45384+ atomic_long_unchecked_t mesq_noop_unexpected_error;
45385+ atomic_long_unchecked_t mesq_noop_lb_overflow;
45386+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
45387+ atomic_long_unchecked_t mesq_noop_amo_nacked;
45388+ atomic_long_unchecked_t mesq_noop_put_nacked;
45389+ atomic_long_unchecked_t mesq_noop_page_overflow;
45390
45391 };
45392
45393@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45394 tghop_invalidate, mcsop_last};
45395
45396 struct mcs_op_statistic {
45397- atomic_long_t count;
45398- atomic_long_t total;
45399+ atomic_long_unchecked_t count;
45400+ atomic_long_unchecked_t total;
45401 unsigned long max;
45402 };
45403
45404@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45405
45406 #define STAT(id) do { \
45407 if (gru_options & OPT_STATS) \
45408- atomic_long_inc(&gru_stats.id); \
45409+ atomic_long_inc_unchecked(&gru_stats.id); \
45410 } while (0)
45411
45412 #ifdef CONFIG_SGI_GRU_DEBUG
45413diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45414index c862cd4..0d176fe 100644
45415--- a/drivers/misc/sgi-xp/xp.h
45416+++ b/drivers/misc/sgi-xp/xp.h
45417@@ -288,7 +288,7 @@ struct xpc_interface {
45418 xpc_notify_func, void *);
45419 void (*received) (short, int, void *);
45420 enum xp_retval (*partid_to_nasids) (short, void *);
45421-};
45422+} __no_const;
45423
45424 extern struct xpc_interface xpc_interface;
45425
45426diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45427index 01be66d..e3a0c7e 100644
45428--- a/drivers/misc/sgi-xp/xp_main.c
45429+++ b/drivers/misc/sgi-xp/xp_main.c
45430@@ -78,13 +78,13 @@ xpc_notloaded(void)
45431 }
45432
45433 struct xpc_interface xpc_interface = {
45434- (void (*)(int))xpc_notloaded,
45435- (void (*)(int))xpc_notloaded,
45436- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45437- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45438+ .connect = (void (*)(int))xpc_notloaded,
45439+ .disconnect = (void (*)(int))xpc_notloaded,
45440+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45441+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45442 void *))xpc_notloaded,
45443- (void (*)(short, int, void *))xpc_notloaded,
45444- (enum xp_retval(*)(short, void *))xpc_notloaded
45445+ .received = (void (*)(short, int, void *))xpc_notloaded,
45446+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45447 };
45448 EXPORT_SYMBOL_GPL(xpc_interface);
45449
45450diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45451index b94d5f7..7f494c5 100644
45452--- a/drivers/misc/sgi-xp/xpc.h
45453+++ b/drivers/misc/sgi-xp/xpc.h
45454@@ -835,6 +835,7 @@ struct xpc_arch_operations {
45455 void (*received_payload) (struct xpc_channel *, void *);
45456 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45457 };
45458+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45459
45460 /* struct xpc_partition act_state values (for XPC HB) */
45461
45462@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45463 /* found in xpc_main.c */
45464 extern struct device *xpc_part;
45465 extern struct device *xpc_chan;
45466-extern struct xpc_arch_operations xpc_arch_ops;
45467+extern xpc_arch_operations_no_const xpc_arch_ops;
45468 extern int xpc_disengage_timelimit;
45469 extern int xpc_disengage_timedout;
45470 extern int xpc_activate_IRQ_rcvd;
45471diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45472index 82dc574..8539ab2 100644
45473--- a/drivers/misc/sgi-xp/xpc_main.c
45474+++ b/drivers/misc/sgi-xp/xpc_main.c
45475@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45476 .notifier_call = xpc_system_die,
45477 };
45478
45479-struct xpc_arch_operations xpc_arch_ops;
45480+xpc_arch_operations_no_const xpc_arch_ops;
45481
45482 /*
45483 * Timer function to enforce the timelimit on the partition disengage.
45484@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45485
45486 if (((die_args->trapnr == X86_TRAP_MF) ||
45487 (die_args->trapnr == X86_TRAP_XF)) &&
45488- !user_mode_vm(die_args->regs))
45489+ !user_mode(die_args->regs))
45490 xpc_die_deactivate();
45491
45492 break;
45493diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45494index 452782b..0c10e40 100644
45495--- a/drivers/mmc/card/block.c
45496+++ b/drivers/mmc/card/block.c
45497@@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45498 if (idata->ic.postsleep_min_us)
45499 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45500
45501- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45502+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45503 err = -EFAULT;
45504 goto cmd_rel_host;
45505 }
45506diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45507index f51b5ba..86614a7 100644
45508--- a/drivers/mmc/core/mmc_ops.c
45509+++ b/drivers/mmc/core/mmc_ops.c
45510@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45511 void *data_buf;
45512 int is_on_stack;
45513
45514- is_on_stack = object_is_on_stack(buf);
45515+ is_on_stack = object_starts_on_stack(buf);
45516 if (is_on_stack) {
45517 /*
45518 * dma onto stack is unsafe/nonportable, but callers to this
45519diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45520index 6834977..824ee1b 100644
45521--- a/drivers/mmc/host/dw_mmc.h
45522+++ b/drivers/mmc/host/dw_mmc.h
45523@@ -259,5 +259,5 @@ struct dw_mci_drv_data {
45524 int (*parse_dt)(struct dw_mci *host);
45525 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45526 struct dw_mci_tuning_data *tuning_data);
45527-};
45528+} __do_const;
45529 #endif /* _DW_MMC_H_ */
45530diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45531index 771c60a..12cb615 100644
45532--- a/drivers/mmc/host/mmci.c
45533+++ b/drivers/mmc/host/mmci.c
45534@@ -1570,7 +1570,9 @@ static int mmci_probe(struct amba_device *dev,
45535 mmc->caps2 = plat->capabilities2;
45536
45537 if (variant->busy_detect) {
45538- mmci_ops.card_busy = mmci_card_busy;
45539+ pax_open_kernel();
45540+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
45541+ pax_close_kernel();
45542 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45543 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
45544 mmc->max_busy_timeout = 0;
45545diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45546index b841bb7..d82712f5 100644
45547--- a/drivers/mmc/host/sdhci-esdhc-imx.c
45548+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45549@@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45550 host->mmc->caps |= MMC_CAP_1_8V_DDR;
45551 }
45552
45553- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45554- sdhci_esdhc_ops.platform_execute_tuning =
45555+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45556+ pax_open_kernel();
45557+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45558 esdhc_executing_tuning;
45559+ pax_close_kernel();
45560+ }
45561
45562 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
45563 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
45564diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45565index d61eb5a..88c0f5d 100644
45566--- a/drivers/mmc/host/sdhci-s3c.c
45567+++ b/drivers/mmc/host/sdhci-s3c.c
45568@@ -657,9 +657,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45569 * we can use overriding functions instead of default.
45570 */
45571 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45572- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45573- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45574- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45575+ pax_open_kernel();
45576+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45577+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45578+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45579+ pax_close_kernel();
45580 }
45581
45582 /* It supports additional host capabilities if needed */
45583diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45584index 6293855..3415551 100644
45585--- a/drivers/mtd/chips/cfi_cmdset_0020.c
45586+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45587@@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45588 size_t totlen = 0, thislen;
45589 int ret = 0;
45590 size_t buflen = 0;
45591- static char *buffer;
45592+ char *buffer;
45593
45594 if (!ECCBUF_SIZE) {
45595 /* We should fall back to a general writev implementation.
45596diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45597index c07cd57..61c4fbd 100644
45598--- a/drivers/mtd/nand/denali.c
45599+++ b/drivers/mtd/nand/denali.c
45600@@ -24,6 +24,7 @@
45601 #include <linux/slab.h>
45602 #include <linux/mtd/mtd.h>
45603 #include <linux/module.h>
45604+#include <linux/slab.h>
45605
45606 #include "denali.h"
45607
45608diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45609index bb77f75..47539b1 100644
45610--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45611+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45612@@ -370,7 +370,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
45613
45614 /* first try to map the upper buffer directly */
45615 if (virt_addr_valid(this->upper_buf) &&
45616- !object_is_on_stack(this->upper_buf)) {
45617+ !object_starts_on_stack(this->upper_buf)) {
45618 sg_init_one(sgl, this->upper_buf, this->upper_len);
45619 ret = dma_map_sg(this->dev, sgl, 1, dr);
45620 if (ret == 0)
45621diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45622index 51b9d6a..52af9a7 100644
45623--- a/drivers/mtd/nftlmount.c
45624+++ b/drivers/mtd/nftlmount.c
45625@@ -24,6 +24,7 @@
45626 #include <asm/errno.h>
45627 #include <linux/delay.h>
45628 #include <linux/slab.h>
45629+#include <linux/sched.h>
45630 #include <linux/mtd/mtd.h>
45631 #include <linux/mtd/nand.h>
45632 #include <linux/mtd/nftl.h>
45633diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45634index cf49c22..971b133 100644
45635--- a/drivers/mtd/sm_ftl.c
45636+++ b/drivers/mtd/sm_ftl.c
45637@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45638 #define SM_CIS_VENDOR_OFFSET 0x59
45639 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45640 {
45641- struct attribute_group *attr_group;
45642+ attribute_group_no_const *attr_group;
45643 struct attribute **attributes;
45644 struct sm_sysfs_attribute *vendor_attribute;
45645 char *vendor;
45646diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45647index d3a6789..198ec21 100644
45648--- a/drivers/net/bonding/bond_main.c
45649+++ b/drivers/net/bonding/bond_main.c
45650@@ -4504,6 +4504,7 @@ static void __exit bonding_exit(void)
45651
45652 bond_netlink_fini();
45653 unregister_pernet_subsys(&bond_net_ops);
45654+ rtnl_link_unregister(&bond_link_ops);
45655
45656 #ifdef CONFIG_NET_POLL_CONTROLLER
45657 /*
45658diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45659index f847e16..fc8dbe9 100644
45660--- a/drivers/net/bonding/bond_netlink.c
45661+++ b/drivers/net/bonding/bond_netlink.c
45662@@ -542,7 +542,7 @@ nla_put_failure:
45663 return -EMSGSIZE;
45664 }
45665
45666-struct rtnl_link_ops bond_link_ops __read_mostly = {
45667+struct rtnl_link_ops bond_link_ops = {
45668 .kind = "bond",
45669 .priv_size = sizeof(struct bonding),
45670 .setup = bond_setup,
45671diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45672index 9e7d95d..d447b88 100644
45673--- a/drivers/net/can/Kconfig
45674+++ b/drivers/net/can/Kconfig
45675@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45676
45677 config CAN_FLEXCAN
45678 tristate "Support for Freescale FLEXCAN based chips"
45679- depends on ARM || PPC
45680+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45681 ---help---
45682 Say Y here if you want to support for Freescale FlexCAN.
45683
45684diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45685index 455d4c3..3353ee7 100644
45686--- a/drivers/net/ethernet/8390/ax88796.c
45687+++ b/drivers/net/ethernet/8390/ax88796.c
45688@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
45689 if (ax->plat->reg_offsets)
45690 ei_local->reg_offset = ax->plat->reg_offsets;
45691 else {
45692+ resource_size_t _mem_size = mem_size;
45693+ do_div(_mem_size, 0x18);
45694 ei_local->reg_offset = ax->reg_offsets;
45695 for (ret = 0; ret < 0x18; ret++)
45696- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45697+ ax->reg_offsets[ret] = _mem_size * ret;
45698 }
45699
45700 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45701diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
45702index 7330681..7e9e463 100644
45703--- a/drivers/net/ethernet/altera/altera_tse_main.c
45704+++ b/drivers/net/ethernet/altera/altera_tse_main.c
45705@@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
45706 return 0;
45707 }
45708
45709-static struct net_device_ops altera_tse_netdev_ops = {
45710+static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
45711 .ndo_open = tse_open,
45712 .ndo_stop = tse_shutdown,
45713 .ndo_start_xmit = tse_start_xmit,
45714@@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
45715 ndev->netdev_ops = &altera_tse_netdev_ops;
45716 altera_tse_set_ethtool_ops(ndev);
45717
45718+ pax_open_kernel();
45719 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
45720
45721 if (priv->hash_filter)
45722 altera_tse_netdev_ops.ndo_set_rx_mode =
45723 tse_set_rx_mode_hashfilter;
45724+ pax_close_kernel();
45725
45726 /* Scatter/gather IO is not supported,
45727 * so it is turned off
45728diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45729index 3448cc0..67b2dc4 100644
45730--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45731+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45732@@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45733 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45734 {
45735 /* RX_MODE controlling object */
45736- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45737+ bnx2x_init_rx_mode_obj(bp);
45738
45739 /* multicast configuration controlling object */
45740 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45741diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45742index 31297266..944cf6e 100644
45743--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45744+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45745@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45746 return rc;
45747 }
45748
45749-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45750- struct bnx2x_rx_mode_obj *o)
45751+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45752 {
45753 if (CHIP_IS_E1x(bp)) {
45754- o->wait_comp = bnx2x_empty_rx_mode_wait;
45755- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45756+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45757+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45758 } else {
45759- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45760- o->config_rx_mode = bnx2x_set_rx_mode_e2;
45761+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45762+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45763 }
45764 }
45765
45766diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45767index 80f6c79..fb7d12d 100644
45768--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45769+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45770@@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45771
45772 /********************* RX MODE ****************/
45773
45774-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45775- struct bnx2x_rx_mode_obj *o);
45776+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45777
45778 /**
45779 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45780diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45781index 04321e5..b51cdc4 100644
45782--- a/drivers/net/ethernet/broadcom/tg3.h
45783+++ b/drivers/net/ethernet/broadcom/tg3.h
45784@@ -150,6 +150,7 @@
45785 #define CHIPREV_ID_5750_A0 0x4000
45786 #define CHIPREV_ID_5750_A1 0x4001
45787 #define CHIPREV_ID_5750_A3 0x4003
45788+#define CHIPREV_ID_5750_C1 0x4201
45789 #define CHIPREV_ID_5750_C2 0x4202
45790 #define CHIPREV_ID_5752_A0_HW 0x5000
45791 #define CHIPREV_ID_5752_A0 0x6000
45792diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45793index 13f9636..228040f 100644
45794--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45795+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45796@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45797 }
45798
45799 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45800- bna_cb_ioceth_enable,
45801- bna_cb_ioceth_disable,
45802- bna_cb_ioceth_hbfail,
45803- bna_cb_ioceth_reset
45804+ .enable_cbfn = bna_cb_ioceth_enable,
45805+ .disable_cbfn = bna_cb_ioceth_disable,
45806+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
45807+ .reset_cbfn = bna_cb_ioceth_reset
45808 };
45809
45810 static void bna_attr_init(struct bna_ioceth *ioceth)
45811diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45812index 8cffcdf..aadf043 100644
45813--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45814+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45815@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45816 */
45817 struct l2t_skb_cb {
45818 arp_failure_handler_func arp_failure_handler;
45819-};
45820+} __no_const;
45821
45822 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45823
45824diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45825index 24e16e3..bfe6ef2 100644
45826--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45827+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45828@@ -2139,7 +2139,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45829
45830 int i;
45831 struct adapter *ap = netdev2adap(dev);
45832- static const unsigned int *reg_ranges;
45833+ const unsigned int *reg_ranges;
45834 int arr_size = 0, buf_size = 0;
45835
45836 if (is_t4(ap->params.chip)) {
45837diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45838index c05b66d..ed69872 100644
45839--- a/drivers/net/ethernet/dec/tulip/de4x5.c
45840+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45841@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45842 for (i=0; i<ETH_ALEN; i++) {
45843 tmp.addr[i] = dev->dev_addr[i];
45844 }
45845- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45846+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45847 break;
45848
45849 case DE4X5_SET_HWADDR: /* Set the hardware address */
45850@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45851 spin_lock_irqsave(&lp->lock, flags);
45852 memcpy(&statbuf, &lp->pktStats, ioc->len);
45853 spin_unlock_irqrestore(&lp->lock, flags);
45854- if (copy_to_user(ioc->data, &statbuf, ioc->len))
45855+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45856 return -EFAULT;
45857 break;
45858 }
45859diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45860index dc19bc5..f2d4548 100644
45861--- a/drivers/net/ethernet/emulex/benet/be_main.c
45862+++ b/drivers/net/ethernet/emulex/benet/be_main.c
45863@@ -535,7 +535,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45864
45865 if (wrapped)
45866 newacc += 65536;
45867- ACCESS_ONCE(*acc) = newacc;
45868+ ACCESS_ONCE_RW(*acc) = newacc;
45869 }
45870
45871 static void populate_erx_stats(struct be_adapter *adapter,
45872diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45873index 68069ea..c4484f6 100644
45874--- a/drivers/net/ethernet/faraday/ftgmac100.c
45875+++ b/drivers/net/ethernet/faraday/ftgmac100.c
45876@@ -30,6 +30,8 @@
45877 #include <linux/netdevice.h>
45878 #include <linux/phy.h>
45879 #include <linux/platform_device.h>
45880+#include <linux/interrupt.h>
45881+#include <linux/irqreturn.h>
45882 #include <net/ip.h>
45883
45884 #include "ftgmac100.h"
45885diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45886index 8be5b40..081bc1b 100644
45887--- a/drivers/net/ethernet/faraday/ftmac100.c
45888+++ b/drivers/net/ethernet/faraday/ftmac100.c
45889@@ -31,6 +31,8 @@
45890 #include <linux/module.h>
45891 #include <linux/netdevice.h>
45892 #include <linux/platform_device.h>
45893+#include <linux/interrupt.h>
45894+#include <linux/irqreturn.h>
45895
45896 #include "ftmac100.h"
45897
45898diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45899index e61e637..9117795 100644
45900--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45901+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45902@@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
45903 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
45904
45905 /* Update the base adjustement value. */
45906- ACCESS_ONCE(pf->ptp_base_adj) = incval;
45907+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
45908 smp_mb(); /* Force the above update. */
45909 }
45910
45911diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45912index 8902ae6..e7bcdce 100644
45913--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45914+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45915@@ -771,7 +771,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45916 }
45917
45918 /* update the base incval used to calculate frequency adjustment */
45919- ACCESS_ONCE(adapter->base_incval) = incval;
45920+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
45921 smp_mb();
45922
45923 /* need lock to prevent incorrect read while modifying cyclecounter */
45924diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45925index 089b713..28d87ae 100644
45926--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45927+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45928@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45929 struct __vxge_hw_fifo *fifo;
45930 struct vxge_hw_fifo_config *config;
45931 u32 txdl_size, txdl_per_memblock;
45932- struct vxge_hw_mempool_cbs fifo_mp_callback;
45933+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45934+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45935+ };
45936+
45937 struct __vxge_hw_virtualpath *vpath;
45938
45939 if ((vp == NULL) || (attr == NULL)) {
45940@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45941 goto exit;
45942 }
45943
45944- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45945-
45946 fifo->mempool =
45947 __vxge_hw_mempool_create(vpath->hldev,
45948 fifo->config->memblock_size,
45949diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45950index ba20c72..f30c0fe 100644
45951--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45952+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45953@@ -2176,7 +2176,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45954 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45955 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45956 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45957- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45958+ pax_open_kernel();
45959+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45960+ pax_close_kernel();
45961 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45962 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
45963 max_tx_rings = QLCNIC_MAX_TX_RINGS;
45964diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45965index be7d7a6..a8983f8 100644
45966--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45967+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45968@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45969 case QLCNIC_NON_PRIV_FUNC:
45970 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45971 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45972- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45973+ pax_open_kernel();
45974+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45975+ pax_close_kernel();
45976 break;
45977 case QLCNIC_PRIV_FUNC:
45978 ahw->op_mode = QLCNIC_PRIV_FUNC;
45979 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45980- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45981+ pax_open_kernel();
45982+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45983+ pax_close_kernel();
45984 break;
45985 case QLCNIC_MGMT_FUNC:
45986 ahw->op_mode = QLCNIC_MGMT_FUNC;
45987 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45988- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45989+ pax_open_kernel();
45990+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45991+ pax_close_kernel();
45992 break;
45993 default:
45994 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45995diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45996index 37b979b..50f5b95 100644
45997--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45998+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45999@@ -1217,7 +1217,7 @@ flash_temp:
46000 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46001 {
46002 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46003- static const struct qlcnic_dump_operations *fw_dump_ops;
46004+ const struct qlcnic_dump_operations *fw_dump_ops;
46005 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
46006 u32 entry_offset, dump, no_entries, buf_offset = 0;
46007 int i, k, ops_cnt, ops_index, dump_size = 0;
46008diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46009index aa1c079..2b1a3e8 100644
46010--- a/drivers/net/ethernet/realtek/r8169.c
46011+++ b/drivers/net/ethernet/realtek/r8169.c
46012@@ -758,22 +758,22 @@ struct rtl8169_private {
46013 struct mdio_ops {
46014 void (*write)(struct rtl8169_private *, int, int);
46015 int (*read)(struct rtl8169_private *, int);
46016- } mdio_ops;
46017+ } __no_const mdio_ops;
46018
46019 struct pll_power_ops {
46020 void (*down)(struct rtl8169_private *);
46021 void (*up)(struct rtl8169_private *);
46022- } pll_power_ops;
46023+ } __no_const pll_power_ops;
46024
46025 struct jumbo_ops {
46026 void (*enable)(struct rtl8169_private *);
46027 void (*disable)(struct rtl8169_private *);
46028- } jumbo_ops;
46029+ } __no_const jumbo_ops;
46030
46031 struct csi_ops {
46032 void (*write)(struct rtl8169_private *, int, int);
46033 u32 (*read)(struct rtl8169_private *, int);
46034- } csi_ops;
46035+ } __no_const csi_ops;
46036
46037 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46038 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46039diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46040index 6b861e3..204ac86 100644
46041--- a/drivers/net/ethernet/sfc/ptp.c
46042+++ b/drivers/net/ethernet/sfc/ptp.c
46043@@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46044 ptp->start.dma_addr);
46045
46046 /* Clear flag that signals MC ready */
46047- ACCESS_ONCE(*start) = 0;
46048+ ACCESS_ONCE_RW(*start) = 0;
46049 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46050 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46051 EFX_BUG_ON_PARANOID(rc);
46052diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46053index 50617c5..b13724c 100644
46054--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46055+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46056@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46057
46058 writel(value, ioaddr + MMC_CNTRL);
46059
46060- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46061- MMC_CNTRL, value);
46062+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46063+// MMC_CNTRL, value);
46064 }
46065
46066 /* To mask all all interrupts.*/
46067diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46068index d18f711d..5755800 100644
46069--- a/drivers/net/hyperv/hyperv_net.h
46070+++ b/drivers/net/hyperv/hyperv_net.h
46071@@ -101,7 +101,7 @@ struct rndis_device {
46072
46073 enum rndis_device_state state;
46074 bool link_state;
46075- atomic_t new_req_id;
46076+ atomic_unchecked_t new_req_id;
46077
46078 spinlock_t request_lock;
46079 struct list_head req_list;
46080diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46081index 143a98c..d54fbaa 100644
46082--- a/drivers/net/hyperv/rndis_filter.c
46083+++ b/drivers/net/hyperv/rndis_filter.c
46084@@ -100,7 +100,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46085 * template
46086 */
46087 set = &rndis_msg->msg.set_req;
46088- set->req_id = atomic_inc_return(&dev->new_req_id);
46089+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46090
46091 /* Add to the request list */
46092 spin_lock_irqsave(&dev->request_lock, flags);
46093@@ -834,7 +834,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46094
46095 /* Setup the rndis set */
46096 halt = &request->request_msg.msg.halt_req;
46097- halt->req_id = atomic_inc_return(&dev->new_req_id);
46098+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46099
46100 /* Ignore return since this msg is optional. */
46101 rndis_filter_send_request(dev, request);
46102diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46103index 78f18be..1d19c62 100644
46104--- a/drivers/net/ieee802154/fakehard.c
46105+++ b/drivers/net/ieee802154/fakehard.c
46106@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46107 phy->transmit_power = 0xbf;
46108
46109 dev->netdev_ops = &fake_ops;
46110- dev->ml_priv = &fake_mlme;
46111+ dev->ml_priv = (void *)&fake_mlme;
46112
46113 priv = netdev_priv(dev);
46114 priv->phy = phy;
46115diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46116index 7eec598..90b8428 100644
46117--- a/drivers/net/macvlan.c
46118+++ b/drivers/net/macvlan.c
46119@@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46120 int macvlan_link_register(struct rtnl_link_ops *ops)
46121 {
46122 /* common fields */
46123- ops->priv_size = sizeof(struct macvlan_dev);
46124- ops->validate = macvlan_validate;
46125- ops->maxtype = IFLA_MACVLAN_MAX;
46126- ops->policy = macvlan_policy;
46127- ops->changelink = macvlan_changelink;
46128- ops->get_size = macvlan_get_size;
46129- ops->fill_info = macvlan_fill_info;
46130+ pax_open_kernel();
46131+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46132+ *(void **)&ops->validate = macvlan_validate;
46133+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46134+ *(const void **)&ops->policy = macvlan_policy;
46135+ *(void **)&ops->changelink = macvlan_changelink;
46136+ *(void **)&ops->get_size = macvlan_get_size;
46137+ *(void **)&ops->fill_info = macvlan_fill_info;
46138+ pax_close_kernel();
46139
46140 return rtnl_link_register(ops);
46141 };
46142@@ -1044,7 +1046,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46143 return NOTIFY_DONE;
46144 }
46145
46146-static struct notifier_block macvlan_notifier_block __read_mostly = {
46147+static struct notifier_block macvlan_notifier_block = {
46148 .notifier_call = macvlan_device_event,
46149 };
46150
46151diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46152index 3381c4f..dea5fd5 100644
46153--- a/drivers/net/macvtap.c
46154+++ b/drivers/net/macvtap.c
46155@@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46156 }
46157
46158 ret = 0;
46159- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46160+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46161 put_user(q->flags, &ifr->ifr_flags))
46162 ret = -EFAULT;
46163 macvtap_put_vlan(vlan);
46164@@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46165 return NOTIFY_DONE;
46166 }
46167
46168-static struct notifier_block macvtap_notifier_block __read_mostly = {
46169+static struct notifier_block macvtap_notifier_block = {
46170 .notifier_call = macvtap_device_event,
46171 };
46172
46173diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46174index daec9b0..6428fcb 100644
46175--- a/drivers/net/phy/mdio-bitbang.c
46176+++ b/drivers/net/phy/mdio-bitbang.c
46177@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46178 struct mdiobb_ctrl *ctrl = bus->priv;
46179
46180 module_put(ctrl->ops->owner);
46181+ mdiobus_unregister(bus);
46182 mdiobus_free(bus);
46183 }
46184 EXPORT_SYMBOL(free_mdio_bitbang);
46185diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46186index e3923eb..2a0373b 100644
46187--- a/drivers/net/ppp/ppp_generic.c
46188+++ b/drivers/net/ppp/ppp_generic.c
46189@@ -1012,7 +1012,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46190 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46191 struct ppp_stats stats;
46192 struct ppp_comp_stats cstats;
46193- char *vers;
46194
46195 switch (cmd) {
46196 case SIOCGPPPSTATS:
46197@@ -1034,8 +1033,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46198 break;
46199
46200 case SIOCGPPPVER:
46201- vers = PPP_VERSION;
46202- if (copy_to_user(addr, vers, strlen(vers) + 1))
46203+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46204 break;
46205 err = 0;
46206 break;
46207diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46208index 1252d9c..80e660b 100644
46209--- a/drivers/net/slip/slhc.c
46210+++ b/drivers/net/slip/slhc.c
46211@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46212 register struct tcphdr *thp;
46213 register struct iphdr *ip;
46214 register struct cstate *cs;
46215- int len, hdrlen;
46216+ long len, hdrlen;
46217 unsigned char *cp = icp;
46218
46219 /* We've got a compressed packet; read the change byte */
46220diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46221index ce4989b..b40b328 100644
46222--- a/drivers/net/team/team.c
46223+++ b/drivers/net/team/team.c
46224@@ -2868,7 +2868,7 @@ static int team_device_event(struct notifier_block *unused,
46225 return NOTIFY_DONE;
46226 }
46227
46228-static struct notifier_block team_notifier_block __read_mostly = {
46229+static struct notifier_block team_notifier_block = {
46230 .notifier_call = team_device_event,
46231 };
46232
46233diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46234index ee328ba..c4a0041 100644
46235--- a/drivers/net/tun.c
46236+++ b/drivers/net/tun.c
46237@@ -1876,7 +1876,7 @@ unlock:
46238 }
46239
46240 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46241- unsigned long arg, int ifreq_len)
46242+ unsigned long arg, size_t ifreq_len)
46243 {
46244 struct tun_file *tfile = file->private_data;
46245 struct tun_struct *tun;
46246@@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46247 unsigned int ifindex;
46248 int ret;
46249
46250+ if (ifreq_len > sizeof ifr)
46251+ return -EFAULT;
46252+
46253 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46254 if (copy_from_user(&ifr, argp, ifreq_len))
46255 return -EFAULT;
46256diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46257index 660bd5e..ac59452 100644
46258--- a/drivers/net/usb/hso.c
46259+++ b/drivers/net/usb/hso.c
46260@@ -71,7 +71,7 @@
46261 #include <asm/byteorder.h>
46262 #include <linux/serial_core.h>
46263 #include <linux/serial.h>
46264-
46265+#include <asm/local.h>
46266
46267 #define MOD_AUTHOR "Option Wireless"
46268 #define MOD_DESCRIPTION "USB High Speed Option driver"
46269@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46270 struct urb *urb;
46271
46272 urb = serial->rx_urb[0];
46273- if (serial->port.count > 0) {
46274+ if (atomic_read(&serial->port.count) > 0) {
46275 count = put_rxbuf_data(urb, serial);
46276 if (count == -1)
46277 return;
46278@@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46279 DUMP1(urb->transfer_buffer, urb->actual_length);
46280
46281 /* Anyone listening? */
46282- if (serial->port.count == 0)
46283+ if (atomic_read(&serial->port.count) == 0)
46284 return;
46285
46286 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46287@@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46288 tty_port_tty_set(&serial->port, tty);
46289
46290 /* check for port already opened, if not set the termios */
46291- serial->port.count++;
46292- if (serial->port.count == 1) {
46293+ if (atomic_inc_return(&serial->port.count) == 1) {
46294 serial->rx_state = RX_IDLE;
46295 /* Force default termio settings */
46296 _hso_serial_set_termios(tty, NULL);
46297@@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46298 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46299 if (result) {
46300 hso_stop_serial_device(serial->parent);
46301- serial->port.count--;
46302+ atomic_dec(&serial->port.count);
46303 kref_put(&serial->parent->ref, hso_serial_ref_free);
46304 }
46305 } else {
46306@@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46307
46308 /* reset the rts and dtr */
46309 /* do the actual close */
46310- serial->port.count--;
46311+ atomic_dec(&serial->port.count);
46312
46313- if (serial->port.count <= 0) {
46314- serial->port.count = 0;
46315+ if (atomic_read(&serial->port.count) <= 0) {
46316+ atomic_set(&serial->port.count, 0);
46317 tty_port_tty_set(&serial->port, NULL);
46318 if (!usb_gone)
46319 hso_stop_serial_device(serial->parent);
46320@@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46321
46322 /* the actual setup */
46323 spin_lock_irqsave(&serial->serial_lock, flags);
46324- if (serial->port.count)
46325+ if (atomic_read(&serial->port.count))
46326 _hso_serial_set_termios(tty, old);
46327 else
46328 tty->termios = *old;
46329@@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46330 D1("Pending read interrupt on port %d\n", i);
46331 spin_lock(&serial->serial_lock);
46332 if (serial->rx_state == RX_IDLE &&
46333- serial->port.count > 0) {
46334+ atomic_read(&serial->port.count) > 0) {
46335 /* Setup and send a ctrl req read on
46336 * port i */
46337 if (!serial->rx_urb_filled[0]) {
46338@@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46339 /* Start all serial ports */
46340 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46341 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46342- if (dev2ser(serial_table[i])->port.count) {
46343+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46344 result =
46345 hso_start_serial_device(serial_table[i], GFP_NOIO);
46346 hso_kick_transmit(dev2ser(serial_table[i]));
46347diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46348index 3fbfb08..2c16265 100644
46349--- a/drivers/net/usb/r8152.c
46350+++ b/drivers/net/usb/r8152.c
46351@@ -567,7 +567,7 @@ struct r8152 {
46352 void (*up)(struct r8152 *);
46353 void (*down)(struct r8152 *);
46354 void (*unload)(struct r8152 *);
46355- } rtl_ops;
46356+ } __no_const rtl_ops;
46357
46358 int intr_interval;
46359 u32 saved_wolopts;
46360diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46361index a2515887..6d13233 100644
46362--- a/drivers/net/usb/sierra_net.c
46363+++ b/drivers/net/usb/sierra_net.c
46364@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46365 /* atomic counter partially included in MAC address to make sure 2 devices
46366 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46367 */
46368-static atomic_t iface_counter = ATOMIC_INIT(0);
46369+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46370
46371 /*
46372 * SYNC Timer Delay definition used to set the expiry time
46373@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46374 dev->net->netdev_ops = &sierra_net_device_ops;
46375
46376 /* change MAC addr to include, ifacenum, and to be unique */
46377- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46378+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46379 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46380
46381 /* we will have to manufacture ethernet headers, prepare template */
46382diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46383index 77dcf92..549924a 100644
46384--- a/drivers/net/vxlan.c
46385+++ b/drivers/net/vxlan.c
46386@@ -2839,7 +2839,7 @@ nla_put_failure:
46387 return -EMSGSIZE;
46388 }
46389
46390-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46391+static struct rtnl_link_ops vxlan_link_ops = {
46392 .kind = "vxlan",
46393 .maxtype = IFLA_VXLAN_MAX,
46394 .policy = vxlan_policy,
46395@@ -2886,7 +2886,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46396 return NOTIFY_DONE;
46397 }
46398
46399-static struct notifier_block vxlan_notifier_block __read_mostly = {
46400+static struct notifier_block vxlan_notifier_block = {
46401 .notifier_call = vxlan_lowerdev_event,
46402 };
46403
46404diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46405index 5920c99..ff2e4a5 100644
46406--- a/drivers/net/wan/lmc/lmc_media.c
46407+++ b/drivers/net/wan/lmc/lmc_media.c
46408@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46409 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46410
46411 lmc_media_t lmc_ds3_media = {
46412- lmc_ds3_init, /* special media init stuff */
46413- lmc_ds3_default, /* reset to default state */
46414- lmc_ds3_set_status, /* reset status to state provided */
46415- lmc_dummy_set_1, /* set clock source */
46416- lmc_dummy_set2_1, /* set line speed */
46417- lmc_ds3_set_100ft, /* set cable length */
46418- lmc_ds3_set_scram, /* set scrambler */
46419- lmc_ds3_get_link_status, /* get link status */
46420- lmc_dummy_set_1, /* set link status */
46421- lmc_ds3_set_crc_length, /* set CRC length */
46422- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46423- lmc_ds3_watchdog
46424+ .init = lmc_ds3_init, /* special media init stuff */
46425+ .defaults = lmc_ds3_default, /* reset to default state */
46426+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
46427+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
46428+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46429+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46430+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46431+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
46432+ .set_link_status = lmc_dummy_set_1, /* set link status */
46433+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46434+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46435+ .watchdog = lmc_ds3_watchdog
46436 };
46437
46438 lmc_media_t lmc_hssi_media = {
46439- lmc_hssi_init, /* special media init stuff */
46440- lmc_hssi_default, /* reset to default state */
46441- lmc_hssi_set_status, /* reset status to state provided */
46442- lmc_hssi_set_clock, /* set clock source */
46443- lmc_dummy_set2_1, /* set line speed */
46444- lmc_dummy_set_1, /* set cable length */
46445- lmc_dummy_set_1, /* set scrambler */
46446- lmc_hssi_get_link_status, /* get link status */
46447- lmc_hssi_set_link_status, /* set link status */
46448- lmc_hssi_set_crc_length, /* set CRC length */
46449- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46450- lmc_hssi_watchdog
46451+ .init = lmc_hssi_init, /* special media init stuff */
46452+ .defaults = lmc_hssi_default, /* reset to default state */
46453+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
46454+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46455+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46456+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46457+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46458+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
46459+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
46460+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46461+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46462+ .watchdog = lmc_hssi_watchdog
46463 };
46464
46465-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46466- lmc_ssi_default, /* reset to default state */
46467- lmc_ssi_set_status, /* reset status to state provided */
46468- lmc_ssi_set_clock, /* set clock source */
46469- lmc_ssi_set_speed, /* set line speed */
46470- lmc_dummy_set_1, /* set cable length */
46471- lmc_dummy_set_1, /* set scrambler */
46472- lmc_ssi_get_link_status, /* get link status */
46473- lmc_ssi_set_link_status, /* set link status */
46474- lmc_ssi_set_crc_length, /* set CRC length */
46475- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46476- lmc_ssi_watchdog
46477+lmc_media_t lmc_ssi_media = {
46478+ .init = lmc_ssi_init, /* special media init stuff */
46479+ .defaults = lmc_ssi_default, /* reset to default state */
46480+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
46481+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46482+ .set_speed = lmc_ssi_set_speed, /* set line speed */
46483+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46484+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46485+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
46486+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
46487+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46488+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46489+ .watchdog = lmc_ssi_watchdog
46490 };
46491
46492 lmc_media_t lmc_t1_media = {
46493- lmc_t1_init, /* special media init stuff */
46494- lmc_t1_default, /* reset to default state */
46495- lmc_t1_set_status, /* reset status to state provided */
46496- lmc_t1_set_clock, /* set clock source */
46497- lmc_dummy_set2_1, /* set line speed */
46498- lmc_dummy_set_1, /* set cable length */
46499- lmc_dummy_set_1, /* set scrambler */
46500- lmc_t1_get_link_status, /* get link status */
46501- lmc_dummy_set_1, /* set link status */
46502- lmc_t1_set_crc_length, /* set CRC length */
46503- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46504- lmc_t1_watchdog
46505+ .init = lmc_t1_init, /* special media init stuff */
46506+ .defaults = lmc_t1_default, /* reset to default state */
46507+ .set_status = lmc_t1_set_status, /* reset status to state provided */
46508+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
46509+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46510+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46511+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46512+ .get_link_status = lmc_t1_get_link_status, /* get link status */
46513+ .set_link_status = lmc_dummy_set_1, /* set link status */
46514+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46515+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46516+ .watchdog = lmc_t1_watchdog
46517 };
46518
46519 static void
46520diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46521index feacc3b..5bac0de 100644
46522--- a/drivers/net/wan/z85230.c
46523+++ b/drivers/net/wan/z85230.c
46524@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46525
46526 struct z8530_irqhandler z8530_sync =
46527 {
46528- z8530_rx,
46529- z8530_tx,
46530- z8530_status
46531+ .rx = z8530_rx,
46532+ .tx = z8530_tx,
46533+ .status = z8530_status
46534 };
46535
46536 EXPORT_SYMBOL(z8530_sync);
46537@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46538 }
46539
46540 static struct z8530_irqhandler z8530_dma_sync = {
46541- z8530_dma_rx,
46542- z8530_dma_tx,
46543- z8530_dma_status
46544+ .rx = z8530_dma_rx,
46545+ .tx = z8530_dma_tx,
46546+ .status = z8530_dma_status
46547 };
46548
46549 static struct z8530_irqhandler z8530_txdma_sync = {
46550- z8530_rx,
46551- z8530_dma_tx,
46552- z8530_dma_status
46553+ .rx = z8530_rx,
46554+ .tx = z8530_dma_tx,
46555+ .status = z8530_dma_status
46556 };
46557
46558 /**
46559@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46560
46561 struct z8530_irqhandler z8530_nop=
46562 {
46563- z8530_rx_clear,
46564- z8530_tx_clear,
46565- z8530_status_clear
46566+ .rx = z8530_rx_clear,
46567+ .tx = z8530_tx_clear,
46568+ .status = z8530_status_clear
46569 };
46570
46571
46572diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46573index 0b60295..b8bfa5b 100644
46574--- a/drivers/net/wimax/i2400m/rx.c
46575+++ b/drivers/net/wimax/i2400m/rx.c
46576@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46577 if (i2400m->rx_roq == NULL)
46578 goto error_roq_alloc;
46579
46580- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46581+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46582 GFP_KERNEL);
46583 if (rd == NULL) {
46584 result = -ENOMEM;
46585diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46586index 64747d4..17c4cf3 100644
46587--- a/drivers/net/wireless/airo.c
46588+++ b/drivers/net/wireless/airo.c
46589@@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46590 struct airo_info *ai = dev->ml_priv;
46591 int ridcode;
46592 int enabled;
46593- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46594+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46595 unsigned char *iobuf;
46596
46597 /* Only super-user can write RIDs */
46598diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46599index 99b3bfa..9559372 100644
46600--- a/drivers/net/wireless/at76c50x-usb.c
46601+++ b/drivers/net/wireless/at76c50x-usb.c
46602@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46603 }
46604
46605 /* Convert timeout from the DFU status to jiffies */
46606-static inline unsigned long at76_get_timeout(struct dfu_status *s)
46607+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46608 {
46609 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46610 | (s->poll_timeout[1] << 8)
46611diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46612index 7f1bccd..ca2ffca 100644
46613--- a/drivers/net/wireless/ath/ath10k/htc.c
46614+++ b/drivers/net/wireless/ath/ath10k/htc.c
46615@@ -840,7 +840,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46616 /* registered target arrival callback from the HIF layer */
46617 int ath10k_htc_init(struct ath10k *ar)
46618 {
46619- struct ath10k_hif_cb htc_callbacks;
46620+ static struct ath10k_hif_cb htc_callbacks = {
46621+ .rx_completion = ath10k_htc_rx_completion_handler,
46622+ .tx_completion = ath10k_htc_tx_completion_handler,
46623+ };
46624 struct ath10k_htc_ep *ep = NULL;
46625 struct ath10k_htc *htc = &ar->htc;
46626
46627@@ -850,8 +853,6 @@ int ath10k_htc_init(struct ath10k *ar)
46628 ath10k_htc_reset_endpoint_states(htc);
46629
46630 /* setup HIF layer callbacks */
46631- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46632- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46633 htc->ar = ar;
46634
46635 /* Get HIF default pipe for HTC message exchange */
46636diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46637index 4716d33..a688310 100644
46638--- a/drivers/net/wireless/ath/ath10k/htc.h
46639+++ b/drivers/net/wireless/ath/ath10k/htc.h
46640@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46641
46642 struct ath10k_htc_ops {
46643 void (*target_send_suspend_complete)(struct ath10k *ar);
46644-};
46645+} __no_const;
46646
46647 struct ath10k_htc_ep_ops {
46648 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46649 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46650 void (*ep_tx_credits)(struct ath10k *);
46651-};
46652+} __no_const;
46653
46654 /* service connection information */
46655 struct ath10k_htc_svc_conn_req {
46656diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46657index 741b38d..b7ae41b 100644
46658--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46659+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46660@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46661 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46662 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46663
46664- ACCESS_ONCE(ads->ds_link) = i->link;
46665- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46666+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
46667+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46668
46669 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46670 ctl6 = SM(i->keytype, AR_EncrType);
46671@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46672
46673 if ((i->is_first || i->is_last) &&
46674 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46675- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46676+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46677 | set11nTries(i->rates, 1)
46678 | set11nTries(i->rates, 2)
46679 | set11nTries(i->rates, 3)
46680 | (i->dur_update ? AR_DurUpdateEna : 0)
46681 | SM(0, AR_BurstDur);
46682
46683- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46684+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46685 | set11nRate(i->rates, 1)
46686 | set11nRate(i->rates, 2)
46687 | set11nRate(i->rates, 3);
46688 } else {
46689- ACCESS_ONCE(ads->ds_ctl2) = 0;
46690- ACCESS_ONCE(ads->ds_ctl3) = 0;
46691+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46692+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46693 }
46694
46695 if (!i->is_first) {
46696- ACCESS_ONCE(ads->ds_ctl0) = 0;
46697- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46698- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46699+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46700+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46701+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46702 return;
46703 }
46704
46705@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46706 break;
46707 }
46708
46709- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46710+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46711 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46712 | SM(i->txpower, AR_XmitPower)
46713 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46714@@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46715 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46716 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46717
46718- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46719- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46720+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46721+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46722
46723 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46724 return;
46725
46726- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46727+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46728 | set11nPktDurRTSCTS(i->rates, 1);
46729
46730- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46731+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46732 | set11nPktDurRTSCTS(i->rates, 3);
46733
46734- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46735+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46736 | set11nRateFlags(i->rates, 1)
46737 | set11nRateFlags(i->rates, 2)
46738 | set11nRateFlags(i->rates, 3)
46739diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46740index 729ffbf..49f50e3 100644
46741--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46742+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46743@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46744 (i->qcu << AR_TxQcuNum_S) | desc_len;
46745
46746 checksum += val;
46747- ACCESS_ONCE(ads->info) = val;
46748+ ACCESS_ONCE_RW(ads->info) = val;
46749
46750 checksum += i->link;
46751- ACCESS_ONCE(ads->link) = i->link;
46752+ ACCESS_ONCE_RW(ads->link) = i->link;
46753
46754 checksum += i->buf_addr[0];
46755- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46756+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46757 checksum += i->buf_addr[1];
46758- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46759+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46760 checksum += i->buf_addr[2];
46761- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46762+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46763 checksum += i->buf_addr[3];
46764- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46765+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46766
46767 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46768- ACCESS_ONCE(ads->ctl3) = val;
46769+ ACCESS_ONCE_RW(ads->ctl3) = val;
46770 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46771- ACCESS_ONCE(ads->ctl5) = val;
46772+ ACCESS_ONCE_RW(ads->ctl5) = val;
46773 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46774- ACCESS_ONCE(ads->ctl7) = val;
46775+ ACCESS_ONCE_RW(ads->ctl7) = val;
46776 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46777- ACCESS_ONCE(ads->ctl9) = val;
46778+ ACCESS_ONCE_RW(ads->ctl9) = val;
46779
46780 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46781- ACCESS_ONCE(ads->ctl10) = checksum;
46782+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
46783
46784 if (i->is_first || i->is_last) {
46785- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46786+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46787 | set11nTries(i->rates, 1)
46788 | set11nTries(i->rates, 2)
46789 | set11nTries(i->rates, 3)
46790 | (i->dur_update ? AR_DurUpdateEna : 0)
46791 | SM(0, AR_BurstDur);
46792
46793- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46794+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46795 | set11nRate(i->rates, 1)
46796 | set11nRate(i->rates, 2)
46797 | set11nRate(i->rates, 3);
46798 } else {
46799- ACCESS_ONCE(ads->ctl13) = 0;
46800- ACCESS_ONCE(ads->ctl14) = 0;
46801+ ACCESS_ONCE_RW(ads->ctl13) = 0;
46802+ ACCESS_ONCE_RW(ads->ctl14) = 0;
46803 }
46804
46805 ads->ctl20 = 0;
46806@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46807
46808 ctl17 = SM(i->keytype, AR_EncrType);
46809 if (!i->is_first) {
46810- ACCESS_ONCE(ads->ctl11) = 0;
46811- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46812- ACCESS_ONCE(ads->ctl15) = 0;
46813- ACCESS_ONCE(ads->ctl16) = 0;
46814- ACCESS_ONCE(ads->ctl17) = ctl17;
46815- ACCESS_ONCE(ads->ctl18) = 0;
46816- ACCESS_ONCE(ads->ctl19) = 0;
46817+ ACCESS_ONCE_RW(ads->ctl11) = 0;
46818+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46819+ ACCESS_ONCE_RW(ads->ctl15) = 0;
46820+ ACCESS_ONCE_RW(ads->ctl16) = 0;
46821+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46822+ ACCESS_ONCE_RW(ads->ctl18) = 0;
46823+ ACCESS_ONCE_RW(ads->ctl19) = 0;
46824 return;
46825 }
46826
46827- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46828+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46829 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46830 | SM(i->txpower, AR_XmitPower)
46831 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46832@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46833 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46834 ctl12 |= SM(val, AR_PAPRDChainMask);
46835
46836- ACCESS_ONCE(ads->ctl12) = ctl12;
46837- ACCESS_ONCE(ads->ctl17) = ctl17;
46838+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46839+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46840
46841- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46842+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46843 | set11nPktDurRTSCTS(i->rates, 1);
46844
46845- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46846+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46847 | set11nPktDurRTSCTS(i->rates, 3);
46848
46849- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46850+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46851 | set11nRateFlags(i->rates, 1)
46852 | set11nRateFlags(i->rates, 2)
46853 | set11nRateFlags(i->rates, 3)
46854 | SM(i->rtscts_rate, AR_RTSCTSRate);
46855
46856- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46857+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46858 }
46859
46860 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46861diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46862index 0acd4b5..0591c91 100644
46863--- a/drivers/net/wireless/ath/ath9k/hw.h
46864+++ b/drivers/net/wireless/ath/ath9k/hw.h
46865@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
46866
46867 /* ANI */
46868 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46869-};
46870+} __no_const;
46871
46872 /**
46873 * struct ath_spec_scan - parameters for Atheros spectral scan
46874@@ -706,7 +706,7 @@ struct ath_hw_ops {
46875 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46876 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46877 #endif
46878-};
46879+} __no_const;
46880
46881 struct ath_nf_limits {
46882 s16 max;
46883diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46884index 92190da..f3a4c4c 100644
46885--- a/drivers/net/wireless/b43/phy_lp.c
46886+++ b/drivers/net/wireless/b43/phy_lp.c
46887@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46888 {
46889 struct ssb_bus *bus = dev->dev->sdev->bus;
46890
46891- static const struct b206x_channel *chandata = NULL;
46892+ const struct b206x_channel *chandata = NULL;
46893 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46894 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46895 u16 old_comm15, scale;
46896diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46897index dc1d20c..f7a4f06 100644
46898--- a/drivers/net/wireless/iwlegacy/3945-mac.c
46899+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46900@@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46901 */
46902 if (il3945_mod_params.disable_hw_scan) {
46903 D_INFO("Disabling hw_scan\n");
46904- il3945_mac_ops.hw_scan = NULL;
46905+ pax_open_kernel();
46906+ *(void **)&il3945_mac_ops.hw_scan = NULL;
46907+ pax_close_kernel();
46908 }
46909
46910 D_INFO("*** LOAD DRIVER ***\n");
46911diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46912index d2fe259..0c4c682 100644
46913--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46914+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46915@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46916 {
46917 struct iwl_priv *priv = file->private_data;
46918 char buf[64];
46919- int buf_size;
46920+ size_t buf_size;
46921 u32 offset, len;
46922
46923 memset(buf, 0, sizeof(buf));
46924@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46925 struct iwl_priv *priv = file->private_data;
46926
46927 char buf[8];
46928- int buf_size;
46929+ size_t buf_size;
46930 u32 reset_flag;
46931
46932 memset(buf, 0, sizeof(buf));
46933@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46934 {
46935 struct iwl_priv *priv = file->private_data;
46936 char buf[8];
46937- int buf_size;
46938+ size_t buf_size;
46939 int ht40;
46940
46941 memset(buf, 0, sizeof(buf));
46942@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46943 {
46944 struct iwl_priv *priv = file->private_data;
46945 char buf[8];
46946- int buf_size;
46947+ size_t buf_size;
46948 int value;
46949
46950 memset(buf, 0, sizeof(buf));
46951@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46952 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46953 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46954
46955-static const char *fmt_value = " %-30s %10u\n";
46956-static const char *fmt_hex = " %-30s 0x%02X\n";
46957-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46958-static const char *fmt_header =
46959+static const char fmt_value[] = " %-30s %10u\n";
46960+static const char fmt_hex[] = " %-30s 0x%02X\n";
46961+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46962+static const char fmt_header[] =
46963 "%-32s current cumulative delta max\n";
46964
46965 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46966@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46967 {
46968 struct iwl_priv *priv = file->private_data;
46969 char buf[8];
46970- int buf_size;
46971+ size_t buf_size;
46972 int clear;
46973
46974 memset(buf, 0, sizeof(buf));
46975@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46976 {
46977 struct iwl_priv *priv = file->private_data;
46978 char buf[8];
46979- int buf_size;
46980+ size_t buf_size;
46981 int trace;
46982
46983 memset(buf, 0, sizeof(buf));
46984@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
46985 {
46986 struct iwl_priv *priv = file->private_data;
46987 char buf[8];
46988- int buf_size;
46989+ size_t buf_size;
46990 int missed;
46991
46992 memset(buf, 0, sizeof(buf));
46993@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
46994
46995 struct iwl_priv *priv = file->private_data;
46996 char buf[8];
46997- int buf_size;
46998+ size_t buf_size;
46999 int plcp;
47000
47001 memset(buf, 0, sizeof(buf));
47002@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47003
47004 struct iwl_priv *priv = file->private_data;
47005 char buf[8];
47006- int buf_size;
47007+ size_t buf_size;
47008 int flush;
47009
47010 memset(buf, 0, sizeof(buf));
47011@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47012
47013 struct iwl_priv *priv = file->private_data;
47014 char buf[8];
47015- int buf_size;
47016+ size_t buf_size;
47017 int rts;
47018
47019 if (!priv->cfg->ht_params)
47020@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47021 {
47022 struct iwl_priv *priv = file->private_data;
47023 char buf[8];
47024- int buf_size;
47025+ size_t buf_size;
47026
47027 memset(buf, 0, sizeof(buf));
47028 buf_size = min(count, sizeof(buf) - 1);
47029@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47030 struct iwl_priv *priv = file->private_data;
47031 u32 event_log_flag;
47032 char buf[8];
47033- int buf_size;
47034+ size_t buf_size;
47035
47036 /* check that the interface is up */
47037 if (!iwl_is_ready(priv))
47038@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47039 struct iwl_priv *priv = file->private_data;
47040 char buf[8];
47041 u32 calib_disabled;
47042- int buf_size;
47043+ size_t buf_size;
47044
47045 memset(buf, 0, sizeof(buf));
47046 buf_size = min(count, sizeof(buf) - 1);
47047diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47048index 6a6df71..eb5c93a 100644
47049--- a/drivers/net/wireless/iwlwifi/dvm/main.c
47050+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47051@@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47052 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47053 {
47054 struct iwl_nvm_data *data = priv->nvm_data;
47055- char *debug_msg;
47056+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47057
47058 if (data->sku_cap_11n_enable &&
47059 !priv->cfg->ht_params) {
47060@@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47061 return -EINVAL;
47062 }
47063
47064- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47065 IWL_DEBUG_INFO(priv, debug_msg,
47066 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47067 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47068diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47069index 2365553..97126d8 100644
47070--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47071+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47072@@ -1552,7 +1552,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47073 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47074
47075 char buf[8];
47076- int buf_size;
47077+ size_t buf_size;
47078 u32 reset_flag;
47079
47080 memset(buf, 0, sizeof(buf));
47081@@ -1573,7 +1573,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47082 {
47083 struct iwl_trans *trans = file->private_data;
47084 char buf[8];
47085- int buf_size;
47086+ size_t buf_size;
47087 int csr;
47088
47089 memset(buf, 0, sizeof(buf));
47090diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47091index 9d7a52f..2729a99 100644
47092--- a/drivers/net/wireless/mac80211_hwsim.c
47093+++ b/drivers/net/wireless/mac80211_hwsim.c
47094@@ -2570,20 +2570,20 @@ static int __init init_mac80211_hwsim(void)
47095 if (channels < 1)
47096 return -EINVAL;
47097
47098- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47099- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47100- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47101- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47102- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47103- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47104- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47105- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47106- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47107- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47108- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47109- mac80211_hwsim_assign_vif_chanctx;
47110- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47111- mac80211_hwsim_unassign_vif_chanctx;
47112+ pax_open_kernel();
47113+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47114+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47115+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47116+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47117+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47118+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47119+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47120+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47121+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47122+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47123+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47124+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47125+ pax_close_kernel();
47126
47127 spin_lock_init(&hwsim_radio_lock);
47128 INIT_LIST_HEAD(&hwsim_radios);
47129diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47130index 39d22a1..4ec8612 100644
47131--- a/drivers/net/wireless/rndis_wlan.c
47132+++ b/drivers/net/wireless/rndis_wlan.c
47133@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47134
47135 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47136
47137- if (rts_threshold < 0 || rts_threshold > 2347)
47138+ if (rts_threshold > 2347)
47139 rts_threshold = 2347;
47140
47141 tmp = cpu_to_le32(rts_threshold);
47142diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47143index e3b885d..7a7de2f 100644
47144--- a/drivers/net/wireless/rt2x00/rt2x00.h
47145+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47146@@ -375,7 +375,7 @@ struct rt2x00_intf {
47147 * for hardware which doesn't support hardware
47148 * sequence counting.
47149 */
47150- atomic_t seqno;
47151+ atomic_unchecked_t seqno;
47152 };
47153
47154 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47155diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47156index 5642ccc..01f03eb 100644
47157--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47158+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47159@@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47160 * sequence counter given by mac80211.
47161 */
47162 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47163- seqno = atomic_add_return(0x10, &intf->seqno);
47164+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47165 else
47166- seqno = atomic_read(&intf->seqno);
47167+ seqno = atomic_read_unchecked(&intf->seqno);
47168
47169 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47170 hdr->seq_ctrl |= cpu_to_le16(seqno);
47171diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47172index b661f896..ddf7d2b 100644
47173--- a/drivers/net/wireless/ti/wl1251/sdio.c
47174+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47175@@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47176
47177 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47178
47179- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47180- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47181+ pax_open_kernel();
47182+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47183+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47184+ pax_close_kernel();
47185
47186 wl1251_info("using dedicated interrupt line");
47187 } else {
47188- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47189- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47190+ pax_open_kernel();
47191+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47192+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47193+ pax_close_kernel();
47194
47195 wl1251_info("using SDIO interrupt");
47196 }
47197diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47198index d50dfac..0a6f5be3 100644
47199--- a/drivers/net/wireless/ti/wl12xx/main.c
47200+++ b/drivers/net/wireless/ti/wl12xx/main.c
47201@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47202 sizeof(wl->conf.mem));
47203
47204 /* read data preparation is only needed by wl127x */
47205- wl->ops->prepare_read = wl127x_prepare_read;
47206+ pax_open_kernel();
47207+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47208+ pax_close_kernel();
47209
47210 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47211 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47212@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47213 sizeof(wl->conf.mem));
47214
47215 /* read data preparation is only needed by wl127x */
47216- wl->ops->prepare_read = wl127x_prepare_read;
47217+ pax_open_kernel();
47218+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47219+ pax_close_kernel();
47220
47221 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47222 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47223diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47224index de5b4fa..7996ec6 100644
47225--- a/drivers/net/wireless/ti/wl18xx/main.c
47226+++ b/drivers/net/wireless/ti/wl18xx/main.c
47227@@ -1900,8 +1900,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47228 }
47229
47230 if (!checksum_param) {
47231- wl18xx_ops.set_rx_csum = NULL;
47232- wl18xx_ops.init_vif = NULL;
47233+ pax_open_kernel();
47234+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47235+ *(void **)&wl18xx_ops.init_vif = NULL;
47236+ pax_close_kernel();
47237 }
47238
47239 /* Enable 11a Band only if we have 5G antennas */
47240diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47241index a912dc0..a8225ba 100644
47242--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47243+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47244@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47245 {
47246 struct zd_usb *usb = urb->context;
47247 struct zd_usb_interrupt *intr = &usb->intr;
47248- int len;
47249+ unsigned int len;
47250 u16 int_num;
47251
47252 ZD_ASSERT(in_interrupt());
47253diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47254index 683671a..4519fc2 100644
47255--- a/drivers/nfc/nfcwilink.c
47256+++ b/drivers/nfc/nfcwilink.c
47257@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47258
47259 static int nfcwilink_probe(struct platform_device *pdev)
47260 {
47261- static struct nfcwilink *drv;
47262+ struct nfcwilink *drv;
47263 int rc;
47264 __u32 protocols;
47265
47266diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47267index d93b2b6..ae50401 100644
47268--- a/drivers/oprofile/buffer_sync.c
47269+++ b/drivers/oprofile/buffer_sync.c
47270@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47271 if (cookie == NO_COOKIE)
47272 offset = pc;
47273 if (cookie == INVALID_COOKIE) {
47274- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47275+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47276 offset = pc;
47277 }
47278 if (cookie != last_cookie) {
47279@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47280 /* add userspace sample */
47281
47282 if (!mm) {
47283- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47284+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47285 return 0;
47286 }
47287
47288 cookie = lookup_dcookie(mm, s->eip, &offset);
47289
47290 if (cookie == INVALID_COOKIE) {
47291- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47292+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47293 return 0;
47294 }
47295
47296@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47297 /* ignore backtraces if failed to add a sample */
47298 if (state == sb_bt_start) {
47299 state = sb_bt_ignore;
47300- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47301+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47302 }
47303 }
47304 release_mm(mm);
47305diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47306index c0cc4e7..44d4e54 100644
47307--- a/drivers/oprofile/event_buffer.c
47308+++ b/drivers/oprofile/event_buffer.c
47309@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47310 }
47311
47312 if (buffer_pos == buffer_size) {
47313- atomic_inc(&oprofile_stats.event_lost_overflow);
47314+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47315 return;
47316 }
47317
47318diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47319index ed2c3ec..deda85a 100644
47320--- a/drivers/oprofile/oprof.c
47321+++ b/drivers/oprofile/oprof.c
47322@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47323 if (oprofile_ops.switch_events())
47324 return;
47325
47326- atomic_inc(&oprofile_stats.multiplex_counter);
47327+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47328 start_switch_worker();
47329 }
47330
47331diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47332index ee2cfce..7f8f699 100644
47333--- a/drivers/oprofile/oprofile_files.c
47334+++ b/drivers/oprofile/oprofile_files.c
47335@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47336
47337 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47338
47339-static ssize_t timeout_read(struct file *file, char __user *buf,
47340+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47341 size_t count, loff_t *offset)
47342 {
47343 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47344diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47345index 59659ce..6c860a0 100644
47346--- a/drivers/oprofile/oprofile_stats.c
47347+++ b/drivers/oprofile/oprofile_stats.c
47348@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47349 cpu_buf->sample_invalid_eip = 0;
47350 }
47351
47352- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47353- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47354- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47355- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47356- atomic_set(&oprofile_stats.multiplex_counter, 0);
47357+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47358+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47359+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47360+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47361+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47362 }
47363
47364
47365diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47366index 1fc622b..8c48fc3 100644
47367--- a/drivers/oprofile/oprofile_stats.h
47368+++ b/drivers/oprofile/oprofile_stats.h
47369@@ -13,11 +13,11 @@
47370 #include <linux/atomic.h>
47371
47372 struct oprofile_stat_struct {
47373- atomic_t sample_lost_no_mm;
47374- atomic_t sample_lost_no_mapping;
47375- atomic_t bt_lost_no_mapping;
47376- atomic_t event_lost_overflow;
47377- atomic_t multiplex_counter;
47378+ atomic_unchecked_t sample_lost_no_mm;
47379+ atomic_unchecked_t sample_lost_no_mapping;
47380+ atomic_unchecked_t bt_lost_no_mapping;
47381+ atomic_unchecked_t event_lost_overflow;
47382+ atomic_unchecked_t multiplex_counter;
47383 };
47384
47385 extern struct oprofile_stat_struct oprofile_stats;
47386diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47387index 3f49345..c750d0b 100644
47388--- a/drivers/oprofile/oprofilefs.c
47389+++ b/drivers/oprofile/oprofilefs.c
47390@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47391
47392 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47393 {
47394- atomic_t *val = file->private_data;
47395- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47396+ atomic_unchecked_t *val = file->private_data;
47397+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47398 }
47399
47400
47401@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47402
47403
47404 int oprofilefs_create_ro_atomic(struct dentry *root,
47405- char const *name, atomic_t *val)
47406+ char const *name, atomic_unchecked_t *val)
47407 {
47408 return __oprofilefs_create_file(root, name,
47409 &atomic_ro_fops, 0444, val);
47410diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47411index 61be1d9..dec05d7 100644
47412--- a/drivers/oprofile/timer_int.c
47413+++ b/drivers/oprofile/timer_int.c
47414@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47415 return NOTIFY_OK;
47416 }
47417
47418-static struct notifier_block __refdata oprofile_cpu_notifier = {
47419+static struct notifier_block oprofile_cpu_notifier = {
47420 .notifier_call = oprofile_cpu_notify,
47421 };
47422
47423diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47424index 92ed045..62d39bd7 100644
47425--- a/drivers/parport/procfs.c
47426+++ b/drivers/parport/procfs.c
47427@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47428
47429 *ppos += len;
47430
47431- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47432+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47433 }
47434
47435 #ifdef CONFIG_PARPORT_1284
47436@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47437
47438 *ppos += len;
47439
47440- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47441+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47442 }
47443 #endif /* IEEE1284.3 support. */
47444
47445diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47446index 8dcccff..35d701d 100644
47447--- a/drivers/pci/hotplug/acpiphp_ibm.c
47448+++ b/drivers/pci/hotplug/acpiphp_ibm.c
47449@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47450 goto init_cleanup;
47451 }
47452
47453- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47454+ pax_open_kernel();
47455+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47456+ pax_close_kernel();
47457 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47458
47459 return retval;
47460diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47461index 7536eef..52dc8fa 100644
47462--- a/drivers/pci/hotplug/cpcihp_generic.c
47463+++ b/drivers/pci/hotplug/cpcihp_generic.c
47464@@ -73,7 +73,6 @@ static u16 port;
47465 static unsigned int enum_bit;
47466 static u8 enum_mask;
47467
47468-static struct cpci_hp_controller_ops generic_hpc_ops;
47469 static struct cpci_hp_controller generic_hpc;
47470
47471 static int __init validate_parameters(void)
47472@@ -139,6 +138,10 @@ static int query_enum(void)
47473 return ((value & enum_mask) == enum_mask);
47474 }
47475
47476+static struct cpci_hp_controller_ops generic_hpc_ops = {
47477+ .query_enum = query_enum,
47478+};
47479+
47480 static int __init cpcihp_generic_init(void)
47481 {
47482 int status;
47483@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47484 pci_dev_put(dev);
47485
47486 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47487- generic_hpc_ops.query_enum = query_enum;
47488 generic_hpc.ops = &generic_hpc_ops;
47489
47490 status = cpci_hp_register_controller(&generic_hpc);
47491diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47492index e8c4a7c..7046f5c 100644
47493--- a/drivers/pci/hotplug/cpcihp_zt5550.c
47494+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47495@@ -59,7 +59,6 @@
47496 /* local variables */
47497 static bool debug;
47498 static bool poll;
47499-static struct cpci_hp_controller_ops zt5550_hpc_ops;
47500 static struct cpci_hp_controller zt5550_hpc;
47501
47502 /* Primary cPCI bus bridge device */
47503@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47504 return 0;
47505 }
47506
47507+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47508+ .query_enum = zt5550_hc_query_enum,
47509+};
47510+
47511 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47512 {
47513 int status;
47514@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47515 dbg("returned from zt5550_hc_config");
47516
47517 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47518- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47519 zt5550_hpc.ops = &zt5550_hpc_ops;
47520 if(!poll) {
47521 zt5550_hpc.irq = hc_dev->irq;
47522 zt5550_hpc.irq_flags = IRQF_SHARED;
47523 zt5550_hpc.dev_id = hc_dev;
47524
47525- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47526- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47527- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47528+ pax_open_kernel();
47529+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47530+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47531+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47532+ pax_open_kernel();
47533 } else {
47534 info("using ENUM# polling mode");
47535 }
47536diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47537index 76ba8a1..20ca857 100644
47538--- a/drivers/pci/hotplug/cpqphp_nvram.c
47539+++ b/drivers/pci/hotplug/cpqphp_nvram.c
47540@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47541
47542 void compaq_nvram_init (void __iomem *rom_start)
47543 {
47544+
47545+#ifndef CONFIG_PAX_KERNEXEC
47546 if (rom_start) {
47547 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47548 }
47549+#endif
47550+
47551 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47552
47553 /* initialize our int15 lock */
47554diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47555index cfa92a9..29539c5 100644
47556--- a/drivers/pci/hotplug/pci_hotplug_core.c
47557+++ b/drivers/pci/hotplug/pci_hotplug_core.c
47558@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47559 return -EINVAL;
47560 }
47561
47562- slot->ops->owner = owner;
47563- slot->ops->mod_name = mod_name;
47564+ pax_open_kernel();
47565+ *(struct module **)&slot->ops->owner = owner;
47566+ *(const char **)&slot->ops->mod_name = mod_name;
47567+ pax_close_kernel();
47568
47569 mutex_lock(&pci_hp_mutex);
47570 /*
47571diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47572index 0e0a2ff..29dff57 100644
47573--- a/drivers/pci/hotplug/pciehp_core.c
47574+++ b/drivers/pci/hotplug/pciehp_core.c
47575@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47576 struct slot *slot = ctrl->slot;
47577 struct hotplug_slot *hotplug = NULL;
47578 struct hotplug_slot_info *info = NULL;
47579- struct hotplug_slot_ops *ops = NULL;
47580+ hotplug_slot_ops_no_const *ops = NULL;
47581 char name[SLOT_NAME_SIZE];
47582 int retval = -ENOMEM;
47583
47584diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
47585index fb02fc2..83dc2c3 100644
47586--- a/drivers/pci/msi.c
47587+++ b/drivers/pci/msi.c
47588@@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
47589 {
47590 struct attribute **msi_attrs;
47591 struct attribute *msi_attr;
47592- struct device_attribute *msi_dev_attr;
47593- struct attribute_group *msi_irq_group;
47594+ device_attribute_no_const *msi_dev_attr;
47595+ attribute_group_no_const *msi_irq_group;
47596 const struct attribute_group **msi_irq_groups;
47597 struct msi_desc *entry;
47598 int ret = -ENOMEM;
47599@@ -589,7 +589,7 @@ error_attrs:
47600 count = 0;
47601 msi_attr = msi_attrs[count];
47602 while (msi_attr) {
47603- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
47604+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
47605 kfree(msi_attr->name);
47606 kfree(msi_dev_attr);
47607 ++count;
47608diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47609index 4e0acef..bd98e31 100644
47610--- a/drivers/pci/pci-sysfs.c
47611+++ b/drivers/pci/pci-sysfs.c
47612@@ -1101,7 +1101,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47613 {
47614 /* allocate attribute structure, piggyback attribute name */
47615 int name_len = write_combine ? 13 : 10;
47616- struct bin_attribute *res_attr;
47617+ bin_attribute_no_const *res_attr;
47618 int retval;
47619
47620 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47621@@ -1286,7 +1286,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47622 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47623 {
47624 int retval;
47625- struct bin_attribute *attr;
47626+ bin_attribute_no_const *attr;
47627
47628 /* If the device has VPD, try to expose it in sysfs. */
47629 if (dev->vpd) {
47630@@ -1333,7 +1333,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47631 {
47632 int retval;
47633 int rom_size = 0;
47634- struct bin_attribute *attr;
47635+ bin_attribute_no_const *attr;
47636
47637 if (!sysfs_initialized)
47638 return -EACCES;
47639diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47640index 6bd0822..35bc2b3 100644
47641--- a/drivers/pci/pci.h
47642+++ b/drivers/pci/pci.h
47643@@ -91,7 +91,7 @@ struct pci_vpd_ops {
47644 struct pci_vpd {
47645 unsigned int len;
47646 const struct pci_vpd_ops *ops;
47647- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47648+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47649 };
47650
47651 int pci_vpd_pci22_init(struct pci_dev *dev);
47652diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47653index e1e7026..d28dd33 100644
47654--- a/drivers/pci/pcie/aspm.c
47655+++ b/drivers/pci/pcie/aspm.c
47656@@ -27,9 +27,9 @@
47657 #define MODULE_PARAM_PREFIX "pcie_aspm."
47658
47659 /* Note: those are not register definitions */
47660-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47661-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47662-#define ASPM_STATE_L1 (4) /* L1 state */
47663+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47664+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47665+#define ASPM_STATE_L1 (4U) /* L1 state */
47666 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47667 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47668
47669diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47670index ef09f5f..49ac62f 100644
47671--- a/drivers/pci/probe.c
47672+++ b/drivers/pci/probe.c
47673@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47674 struct pci_bus_region region, inverted_region;
47675 bool bar_too_big = false, bar_disabled = false;
47676
47677- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47678+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47679
47680 /* No printks while decoding is disabled! */
47681 if (!dev->mmio_always_on) {
47682diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47683index 46d1378..30e452b 100644
47684--- a/drivers/pci/proc.c
47685+++ b/drivers/pci/proc.c
47686@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47687 static int __init pci_proc_init(void)
47688 {
47689 struct pci_dev *dev = NULL;
47690+
47691+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47692+#ifdef CONFIG_GRKERNSEC_PROC_USER
47693+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47694+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47695+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47696+#endif
47697+#else
47698 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47699+#endif
47700 proc_create("devices", 0, proc_bus_pci_dir,
47701 &proc_bus_pci_dev_operations);
47702 proc_initialized = 1;
47703diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47704index 7f3aad0..7d604bb 100644
47705--- a/drivers/platform/chrome/chromeos_laptop.c
47706+++ b/drivers/platform/chrome/chromeos_laptop.c
47707@@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
47708 .callback = chromeos_laptop_dmi_matched, \
47709 .driver_data = (void *)&board_
47710
47711-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
47712+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
47713 {
47714 .ident = "Samsung Series 5 550",
47715 .matches = {
47716diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
47717index 541f951..4dfd598 100644
47718--- a/drivers/platform/x86/alienware-wmi.c
47719+++ b/drivers/platform/x86/alienware-wmi.c
47720@@ -132,7 +132,7 @@ struct wmax_led_args {
47721 } __packed;
47722
47723 static struct platform_device *platform_device;
47724-static struct device_attribute *zone_dev_attrs;
47725+static device_attribute_no_const *zone_dev_attrs;
47726 static struct attribute **zone_attrs;
47727 static struct platform_zone *zone_data;
47728
47729@@ -143,7 +143,7 @@ static struct platform_driver platform_driver = {
47730 }
47731 };
47732
47733-static struct attribute_group zone_attribute_group = {
47734+static attribute_group_no_const zone_attribute_group = {
47735 .name = "rgb_zones",
47736 };
47737
47738diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47739index c5e082f..d6307a0 100644
47740--- a/drivers/platform/x86/asus-wmi.c
47741+++ b/drivers/platform/x86/asus-wmi.c
47742@@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
47743 int err;
47744 u32 retval = -1;
47745
47746+#ifdef CONFIG_GRKERNSEC_KMEM
47747+ return -EPERM;
47748+#endif
47749+
47750 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47751
47752 if (err < 0)
47753@@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
47754 int err;
47755 u32 retval = -1;
47756
47757+#ifdef CONFIG_GRKERNSEC_KMEM
47758+ return -EPERM;
47759+#endif
47760+
47761 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47762 &retval);
47763
47764@@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
47765 union acpi_object *obj;
47766 acpi_status status;
47767
47768+#ifdef CONFIG_GRKERNSEC_KMEM
47769+ return -EPERM;
47770+#endif
47771+
47772 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47773 1, asus->debug.method_id,
47774 &input, &output);
47775diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47776index 62f8030..c7f2a45 100644
47777--- a/drivers/platform/x86/msi-laptop.c
47778+++ b/drivers/platform/x86/msi-laptop.c
47779@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47780
47781 if (!quirks->ec_read_only) {
47782 /* allow userland write sysfs file */
47783- dev_attr_bluetooth.store = store_bluetooth;
47784- dev_attr_wlan.store = store_wlan;
47785- dev_attr_threeg.store = store_threeg;
47786- dev_attr_bluetooth.attr.mode |= S_IWUSR;
47787- dev_attr_wlan.attr.mode |= S_IWUSR;
47788- dev_attr_threeg.attr.mode |= S_IWUSR;
47789+ pax_open_kernel();
47790+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47791+ *(void **)&dev_attr_wlan.store = store_wlan;
47792+ *(void **)&dev_attr_threeg.store = store_threeg;
47793+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47794+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47795+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47796+ pax_close_kernel();
47797 }
47798
47799 /* disable hardware control by fn key */
47800diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47801index 70222f2..8c8ce66 100644
47802--- a/drivers/platform/x86/msi-wmi.c
47803+++ b/drivers/platform/x86/msi-wmi.c
47804@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47805 static void msi_wmi_notify(u32 value, void *context)
47806 {
47807 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47808- static struct key_entry *key;
47809+ struct key_entry *key;
47810 union acpi_object *obj;
47811 acpi_status status;
47812
47813diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47814index 9c5a074..06c976a 100644
47815--- a/drivers/platform/x86/sony-laptop.c
47816+++ b/drivers/platform/x86/sony-laptop.c
47817@@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47818 }
47819
47820 /* High speed charging function */
47821-static struct device_attribute *hsc_handle;
47822+static device_attribute_no_const *hsc_handle;
47823
47824 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47825 struct device_attribute *attr,
47826@@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
47827 }
47828
47829 /* low battery function */
47830-static struct device_attribute *lowbatt_handle;
47831+static device_attribute_no_const *lowbatt_handle;
47832
47833 static ssize_t sony_nc_lowbatt_store(struct device *dev,
47834 struct device_attribute *attr,
47835@@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
47836 }
47837
47838 /* fan speed function */
47839-static struct device_attribute *fan_handle, *hsf_handle;
47840+static device_attribute_no_const *fan_handle, *hsf_handle;
47841
47842 static ssize_t sony_nc_hsfan_store(struct device *dev,
47843 struct device_attribute *attr,
47844@@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
47845 }
47846
47847 /* USB charge function */
47848-static struct device_attribute *uc_handle;
47849+static device_attribute_no_const *uc_handle;
47850
47851 static ssize_t sony_nc_usb_charge_store(struct device *dev,
47852 struct device_attribute *attr,
47853@@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
47854 }
47855
47856 /* Panel ID function */
47857-static struct device_attribute *panel_handle;
47858+static device_attribute_no_const *panel_handle;
47859
47860 static ssize_t sony_nc_panelid_show(struct device *dev,
47861 struct device_attribute *attr, char *buffer)
47862@@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
47863 }
47864
47865 /* smart connect function */
47866-static struct device_attribute *sc_handle;
47867+static device_attribute_no_const *sc_handle;
47868
47869 static ssize_t sony_nc_smart_conn_store(struct device *dev,
47870 struct device_attribute *attr,
47871diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47872index 15e61c1..40a39c7 100644
47873--- a/drivers/platform/x86/thinkpad_acpi.c
47874+++ b/drivers/platform/x86/thinkpad_acpi.c
47875@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
47876 return 0;
47877 }
47878
47879-void static hotkey_mask_warn_incomplete_mask(void)
47880+static void hotkey_mask_warn_incomplete_mask(void)
47881 {
47882 /* log only what the user can fix... */
47883 const u32 wantedmask = hotkey_driver_mask &
47884@@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47885 && !tp_features.bright_unkfw)
47886 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47887 }
47888+}
47889
47890 #undef TPACPI_COMPARE_KEY
47891 #undef TPACPI_MAY_SEND_KEY
47892-}
47893
47894 /*
47895 * Polling driver
47896diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47897index 438d4c7..ca8a2fb 100644
47898--- a/drivers/pnp/pnpbios/bioscalls.c
47899+++ b/drivers/pnp/pnpbios/bioscalls.c
47900@@ -59,7 +59,7 @@ do { \
47901 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47902 } while(0)
47903
47904-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47905+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47906 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47907
47908 /*
47909@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47910
47911 cpu = get_cpu();
47912 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47913+
47914+ pax_open_kernel();
47915 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47916+ pax_close_kernel();
47917
47918 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47919 spin_lock_irqsave(&pnp_bios_lock, flags);
47920@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47921 :"memory");
47922 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47923
47924+ pax_open_kernel();
47925 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47926+ pax_close_kernel();
47927+
47928 put_cpu();
47929
47930 /* If we get here and this is set then the PnP BIOS faulted on us. */
47931@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47932 return status;
47933 }
47934
47935-void pnpbios_calls_init(union pnp_bios_install_struct *header)
47936+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47937 {
47938 int i;
47939
47940@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47941 pnp_bios_callpoint.offset = header->fields.pm16offset;
47942 pnp_bios_callpoint.segment = PNP_CS16;
47943
47944+ pax_open_kernel();
47945+
47946 for_each_possible_cpu(i) {
47947 struct desc_struct *gdt = get_cpu_gdt_table(i);
47948 if (!gdt)
47949@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47950 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47951 (unsigned long)__va(header->fields.pm16dseg));
47952 }
47953+
47954+ pax_close_kernel();
47955 }
47956diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47957index 01712cb..782e822 100644
47958--- a/drivers/pnp/resource.c
47959+++ b/drivers/pnp/resource.c
47960@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
47961 return 1;
47962
47963 /* check if the resource is valid */
47964- if (*irq < 0 || *irq > 15)
47965+ if (*irq > 15)
47966 return 0;
47967
47968 /* check if the resource is reserved */
47969@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
47970 return 1;
47971
47972 /* check if the resource is valid */
47973- if (*dma < 0 || *dma == 4 || *dma > 7)
47974+ if (*dma == 4 || *dma > 7)
47975 return 0;
47976
47977 /* check if the resource is reserved */
47978diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
47979index 0c52e2a..3421ab7 100644
47980--- a/drivers/power/pda_power.c
47981+++ b/drivers/power/pda_power.c
47982@@ -37,7 +37,11 @@ static int polling;
47983
47984 #if IS_ENABLED(CONFIG_USB_PHY)
47985 static struct usb_phy *transceiver;
47986-static struct notifier_block otg_nb;
47987+static int otg_handle_notification(struct notifier_block *nb,
47988+ unsigned long event, void *unused);
47989+static struct notifier_block otg_nb = {
47990+ .notifier_call = otg_handle_notification
47991+};
47992 #endif
47993
47994 static struct regulator *ac_draw;
47995@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
47996
47997 #if IS_ENABLED(CONFIG_USB_PHY)
47998 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
47999- otg_nb.notifier_call = otg_handle_notification;
48000 ret = usb_register_notifier(transceiver, &otg_nb);
48001 if (ret) {
48002 dev_err(dev, "failure to register otg notifier\n");
48003diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48004index cc439fd..8fa30df 100644
48005--- a/drivers/power/power_supply.h
48006+++ b/drivers/power/power_supply.h
48007@@ -16,12 +16,12 @@ struct power_supply;
48008
48009 #ifdef CONFIG_SYSFS
48010
48011-extern void power_supply_init_attrs(struct device_type *dev_type);
48012+extern void power_supply_init_attrs(void);
48013 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48014
48015 #else
48016
48017-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48018+static inline void power_supply_init_attrs(void) {}
48019 #define power_supply_uevent NULL
48020
48021 #endif /* CONFIG_SYSFS */
48022diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48023index 2660664..75fcb04 100644
48024--- a/drivers/power/power_supply_core.c
48025+++ b/drivers/power/power_supply_core.c
48026@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48027 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48028 EXPORT_SYMBOL_GPL(power_supply_notifier);
48029
48030-static struct device_type power_supply_dev_type;
48031+extern const struct attribute_group *power_supply_attr_groups[];
48032+static struct device_type power_supply_dev_type = {
48033+ .groups = power_supply_attr_groups,
48034+};
48035
48036 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48037 struct power_supply *supply)
48038@@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48039 return PTR_ERR(power_supply_class);
48040
48041 power_supply_class->dev_uevent = power_supply_uevent;
48042- power_supply_init_attrs(&power_supply_dev_type);
48043+ power_supply_init_attrs();
48044
48045 return 0;
48046 }
48047diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48048index 44420d1..967126e 100644
48049--- a/drivers/power/power_supply_sysfs.c
48050+++ b/drivers/power/power_supply_sysfs.c
48051@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48052 .is_visible = power_supply_attr_is_visible,
48053 };
48054
48055-static const struct attribute_group *power_supply_attr_groups[] = {
48056+const struct attribute_group *power_supply_attr_groups[] = {
48057 &power_supply_attr_group,
48058 NULL,
48059 };
48060
48061-void power_supply_init_attrs(struct device_type *dev_type)
48062+void power_supply_init_attrs(void)
48063 {
48064 int i;
48065
48066- dev_type->groups = power_supply_attr_groups;
48067-
48068 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48069 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48070 }
48071diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48072index 84419af..268ede8 100644
48073--- a/drivers/powercap/powercap_sys.c
48074+++ b/drivers/powercap/powercap_sys.c
48075@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48076 struct device_attribute name_attr;
48077 };
48078
48079+static ssize_t show_constraint_name(struct device *dev,
48080+ struct device_attribute *dev_attr,
48081+ char *buf);
48082+
48083 static struct powercap_constraint_attr
48084- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48085+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48086+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48087+ .power_limit_attr = {
48088+ .attr = {
48089+ .name = NULL,
48090+ .mode = S_IWUSR | S_IRUGO
48091+ },
48092+ .show = show_constraint_power_limit_uw,
48093+ .store = store_constraint_power_limit_uw
48094+ },
48095+
48096+ .time_window_attr = {
48097+ .attr = {
48098+ .name = NULL,
48099+ .mode = S_IWUSR | S_IRUGO
48100+ },
48101+ .show = show_constraint_time_window_us,
48102+ .store = store_constraint_time_window_us
48103+ },
48104+
48105+ .max_power_attr = {
48106+ .attr = {
48107+ .name = NULL,
48108+ .mode = S_IRUGO
48109+ },
48110+ .show = show_constraint_max_power_uw,
48111+ .store = NULL
48112+ },
48113+
48114+ .min_power_attr = {
48115+ .attr = {
48116+ .name = NULL,
48117+ .mode = S_IRUGO
48118+ },
48119+ .show = show_constraint_min_power_uw,
48120+ .store = NULL
48121+ },
48122+
48123+ .max_time_window_attr = {
48124+ .attr = {
48125+ .name = NULL,
48126+ .mode = S_IRUGO
48127+ },
48128+ .show = show_constraint_max_time_window_us,
48129+ .store = NULL
48130+ },
48131+
48132+ .min_time_window_attr = {
48133+ .attr = {
48134+ .name = NULL,
48135+ .mode = S_IRUGO
48136+ },
48137+ .show = show_constraint_min_time_window_us,
48138+ .store = NULL
48139+ },
48140+
48141+ .name_attr = {
48142+ .attr = {
48143+ .name = NULL,
48144+ .mode = S_IRUGO
48145+ },
48146+ .show = show_constraint_name,
48147+ .store = NULL
48148+ }
48149+ }
48150+};
48151
48152 /* A list of powercap control_types */
48153 static LIST_HEAD(powercap_cntrl_list);
48154@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48155 }
48156
48157 static int create_constraint_attribute(int id, const char *name,
48158- int mode,
48159- struct device_attribute *dev_attr,
48160- ssize_t (*show)(struct device *,
48161- struct device_attribute *, char *),
48162- ssize_t (*store)(struct device *,
48163- struct device_attribute *,
48164- const char *, size_t)
48165- )
48166+ struct device_attribute *dev_attr)
48167 {
48168+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48169
48170- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48171- id, name);
48172- if (!dev_attr->attr.name)
48173+ if (!name)
48174 return -ENOMEM;
48175- dev_attr->attr.mode = mode;
48176- dev_attr->show = show;
48177- dev_attr->store = store;
48178+
48179+ pax_open_kernel();
48180+ *(const char **)&dev_attr->attr.name = name;
48181+ pax_close_kernel();
48182
48183 return 0;
48184 }
48185@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48186
48187 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48188 ret = create_constraint_attribute(i, "power_limit_uw",
48189- S_IWUSR | S_IRUGO,
48190- &constraint_attrs[i].power_limit_attr,
48191- show_constraint_power_limit_uw,
48192- store_constraint_power_limit_uw);
48193+ &constraint_attrs[i].power_limit_attr);
48194 if (ret)
48195 goto err_alloc;
48196 ret = create_constraint_attribute(i, "time_window_us",
48197- S_IWUSR | S_IRUGO,
48198- &constraint_attrs[i].time_window_attr,
48199- show_constraint_time_window_us,
48200- store_constraint_time_window_us);
48201+ &constraint_attrs[i].time_window_attr);
48202 if (ret)
48203 goto err_alloc;
48204- ret = create_constraint_attribute(i, "name", S_IRUGO,
48205- &constraint_attrs[i].name_attr,
48206- show_constraint_name,
48207- NULL);
48208+ ret = create_constraint_attribute(i, "name",
48209+ &constraint_attrs[i].name_attr);
48210 if (ret)
48211 goto err_alloc;
48212- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48213- &constraint_attrs[i].max_power_attr,
48214- show_constraint_max_power_uw,
48215- NULL);
48216+ ret = create_constraint_attribute(i, "max_power_uw",
48217+ &constraint_attrs[i].max_power_attr);
48218 if (ret)
48219 goto err_alloc;
48220- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48221- &constraint_attrs[i].min_power_attr,
48222- show_constraint_min_power_uw,
48223- NULL);
48224+ ret = create_constraint_attribute(i, "min_power_uw",
48225+ &constraint_attrs[i].min_power_attr);
48226 if (ret)
48227 goto err_alloc;
48228 ret = create_constraint_attribute(i, "max_time_window_us",
48229- S_IRUGO,
48230- &constraint_attrs[i].max_time_window_attr,
48231- show_constraint_max_time_window_us,
48232- NULL);
48233+ &constraint_attrs[i].max_time_window_attr);
48234 if (ret)
48235 goto err_alloc;
48236 ret = create_constraint_attribute(i, "min_time_window_us",
48237- S_IRUGO,
48238- &constraint_attrs[i].min_time_window_attr,
48239- show_constraint_min_time_window_us,
48240- NULL);
48241+ &constraint_attrs[i].min_time_window_attr);
48242 if (ret)
48243 goto err_alloc;
48244
48245@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48246 power_zone->zone_dev_attrs[count++] =
48247 &dev_attr_max_energy_range_uj.attr;
48248 if (power_zone->ops->get_energy_uj) {
48249+ pax_open_kernel();
48250 if (power_zone->ops->reset_energy_uj)
48251- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48252+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48253 else
48254- dev_attr_energy_uj.attr.mode = S_IRUGO;
48255+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48256+ pax_close_kernel();
48257 power_zone->zone_dev_attrs[count++] =
48258 &dev_attr_energy_uj.attr;
48259 }
48260diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
48261index 9c5d414..c7900ce 100644
48262--- a/drivers/ptp/ptp_private.h
48263+++ b/drivers/ptp/ptp_private.h
48264@@ -51,7 +51,7 @@ struct ptp_clock {
48265 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
48266 wait_queue_head_t tsev_wq;
48267 int defunct; /* tells readers to go away when clock is being removed */
48268- struct device_attribute *pin_dev_attr;
48269+ device_attribute_no_const *pin_dev_attr;
48270 struct attribute **pin_attr;
48271 struct attribute_group pin_attr_group;
48272 };
48273diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
48274index 302e626..12579af 100644
48275--- a/drivers/ptp/ptp_sysfs.c
48276+++ b/drivers/ptp/ptp_sysfs.c
48277@@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
48278 goto no_pin_attr;
48279
48280 for (i = 0; i < n_pins; i++) {
48281- struct device_attribute *da = &ptp->pin_dev_attr[i];
48282+ device_attribute_no_const *da = &ptp->pin_dev_attr[i];
48283 sysfs_attr_init(&da->attr);
48284 da->attr.name = info->pin_config[i].name;
48285 da->attr.mode = 0644;
48286diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48287index 9a09f3c..450b523 100644
48288--- a/drivers/regulator/core.c
48289+++ b/drivers/regulator/core.c
48290@@ -3380,7 +3380,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48291 {
48292 const struct regulation_constraints *constraints = NULL;
48293 const struct regulator_init_data *init_data;
48294- static atomic_t regulator_no = ATOMIC_INIT(0);
48295+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48296 struct regulator_dev *rdev;
48297 struct device *dev;
48298 int ret, i;
48299@@ -3450,7 +3450,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48300 rdev->dev.of_node = config->of_node;
48301 rdev->dev.parent = dev;
48302 dev_set_name(&rdev->dev, "regulator.%d",
48303- atomic_inc_return(&regulator_no) - 1);
48304+ atomic_inc_return_unchecked(&regulator_no) - 1);
48305 ret = device_register(&rdev->dev);
48306 if (ret != 0) {
48307 put_device(&rdev->dev);
48308diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48309index 2fc4111..6aa88ca 100644
48310--- a/drivers/regulator/max8660.c
48311+++ b/drivers/regulator/max8660.c
48312@@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
48313 max8660->shadow_regs[MAX8660_OVER1] = 5;
48314 } else {
48315 /* Otherwise devices can be toggled via software */
48316- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48317- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48318+ pax_open_kernel();
48319+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48320+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48321+ pax_close_kernel();
48322 }
48323
48324 /*
48325diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48326index dbedf17..18ff6b7 100644
48327--- a/drivers/regulator/max8973-regulator.c
48328+++ b/drivers/regulator/max8973-regulator.c
48329@@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
48330 if (!pdata || !pdata->enable_ext_control) {
48331 max->desc.enable_reg = MAX8973_VOUT;
48332 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48333- max->ops.enable = regulator_enable_regmap;
48334- max->ops.disable = regulator_disable_regmap;
48335- max->ops.is_enabled = regulator_is_enabled_regmap;
48336+ pax_open_kernel();
48337+ *(void **)&max->ops.enable = regulator_enable_regmap;
48338+ *(void **)&max->ops.disable = regulator_disable_regmap;
48339+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48340+ pax_close_kernel();
48341 }
48342
48343 if (pdata) {
48344diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48345index f374fa5..26f0683 100644
48346--- a/drivers/regulator/mc13892-regulator.c
48347+++ b/drivers/regulator/mc13892-regulator.c
48348@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48349 }
48350 mc13xxx_unlock(mc13892);
48351
48352- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48353+ pax_open_kernel();
48354+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48355 = mc13892_vcam_set_mode;
48356- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48357+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48358 = mc13892_vcam_get_mode;
48359+ pax_close_kernel();
48360
48361 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48362 ARRAY_SIZE(mc13892_regulators));
48363diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48364index 0963c93..ea29cce 100644
48365--- a/drivers/rtc/rtc-cmos.c
48366+++ b/drivers/rtc/rtc-cmos.c
48367@@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48368 hpet_rtc_timer_init();
48369
48370 /* export at least the first block of NVRAM */
48371- nvram.size = address_space - NVRAM_OFFSET;
48372+ pax_open_kernel();
48373+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48374+ pax_close_kernel();
48375 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48376 if (retval < 0) {
48377 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48378diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48379index d049393..bb20be0 100644
48380--- a/drivers/rtc/rtc-dev.c
48381+++ b/drivers/rtc/rtc-dev.c
48382@@ -16,6 +16,7 @@
48383 #include <linux/module.h>
48384 #include <linux/rtc.h>
48385 #include <linux/sched.h>
48386+#include <linux/grsecurity.h>
48387 #include "rtc-core.h"
48388
48389 static dev_t rtc_devt;
48390@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48391 if (copy_from_user(&tm, uarg, sizeof(tm)))
48392 return -EFAULT;
48393
48394+ gr_log_timechange();
48395+
48396 return rtc_set_time(rtc, &tm);
48397
48398 case RTC_PIE_ON:
48399diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48400index f03d5ba..8325bf6 100644
48401--- a/drivers/rtc/rtc-ds1307.c
48402+++ b/drivers/rtc/rtc-ds1307.c
48403@@ -107,7 +107,7 @@ struct ds1307 {
48404 u8 offset; /* register's offset */
48405 u8 regs[11];
48406 u16 nvram_offset;
48407- struct bin_attribute *nvram;
48408+ bin_attribute_no_const *nvram;
48409 enum ds_type type;
48410 unsigned long flags;
48411 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48412diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48413index 11880c1..b823aa4 100644
48414--- a/drivers/rtc/rtc-m48t59.c
48415+++ b/drivers/rtc/rtc-m48t59.c
48416@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48417 if (IS_ERR(m48t59->rtc))
48418 return PTR_ERR(m48t59->rtc);
48419
48420- m48t59_nvram_attr.size = pdata->offset;
48421+ pax_open_kernel();
48422+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48423+ pax_close_kernel();
48424
48425 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48426 if (ret)
48427diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48428index 14b5f8d..cc9bd26 100644
48429--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48430+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48431@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48432 for (bit = 0; bit < 8; bit++) {
48433
48434 if ((pci_status[i] & (0x1 << bit)) != 0) {
48435- static const char *s;
48436+ const char *s;
48437
48438 s = pci_status_strings[bit];
48439 if (i == 7/*TARG*/ && bit == 3)
48440@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48441
48442 for (bit = 0; bit < 8; bit++) {
48443
48444- if ((split_status[i] & (0x1 << bit)) != 0) {
48445- static const char *s;
48446-
48447- s = split_status_strings[bit];
48448- printk(s, ahd_name(ahd),
48449+ if ((split_status[i] & (0x1 << bit)) != 0)
48450+ printk(split_status_strings[bit], ahd_name(ahd),
48451 split_status_source[i]);
48452- }
48453
48454 if (i > 1)
48455 continue;
48456
48457- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48458- static const char *s;
48459-
48460- s = split_status_strings[bit];
48461- printk(s, ahd_name(ahd), "SG");
48462- }
48463+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
48464+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
48465 }
48466 }
48467 /*
48468diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48469index e693af6..2e525b6 100644
48470--- a/drivers/scsi/bfa/bfa_fcpim.h
48471+++ b/drivers/scsi/bfa/bfa_fcpim.h
48472@@ -36,7 +36,7 @@ struct bfa_iotag_s {
48473
48474 struct bfa_itn_s {
48475 bfa_isr_func_t isr;
48476-};
48477+} __no_const;
48478
48479 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48480 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48481diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48482index a3ab5cc..8143622 100644
48483--- a/drivers/scsi/bfa/bfa_fcs.c
48484+++ b/drivers/scsi/bfa/bfa_fcs.c
48485@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48486 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48487
48488 static struct bfa_fcs_mod_s fcs_modules[] = {
48489- { bfa_fcs_port_attach, NULL, NULL },
48490- { bfa_fcs_uf_attach, NULL, NULL },
48491- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48492- bfa_fcs_fabric_modexit },
48493+ {
48494+ .attach = bfa_fcs_port_attach,
48495+ .modinit = NULL,
48496+ .modexit = NULL
48497+ },
48498+ {
48499+ .attach = bfa_fcs_uf_attach,
48500+ .modinit = NULL,
48501+ .modexit = NULL
48502+ },
48503+ {
48504+ .attach = bfa_fcs_fabric_attach,
48505+ .modinit = bfa_fcs_fabric_modinit,
48506+ .modexit = bfa_fcs_fabric_modexit
48507+ },
48508 };
48509
48510 /*
48511diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48512index ff75ef8..2dfe00a 100644
48513--- a/drivers/scsi/bfa/bfa_fcs_lport.c
48514+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48515@@ -89,15 +89,26 @@ static struct {
48516 void (*offline) (struct bfa_fcs_lport_s *port);
48517 } __port_action[] = {
48518 {
48519- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48520- bfa_fcs_lport_unknown_offline}, {
48521- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48522- bfa_fcs_lport_fab_offline}, {
48523- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48524- bfa_fcs_lport_n2n_offline}, {
48525- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48526- bfa_fcs_lport_loop_offline},
48527- };
48528+ .init = bfa_fcs_lport_unknown_init,
48529+ .online = bfa_fcs_lport_unknown_online,
48530+ .offline = bfa_fcs_lport_unknown_offline
48531+ },
48532+ {
48533+ .init = bfa_fcs_lport_fab_init,
48534+ .online = bfa_fcs_lport_fab_online,
48535+ .offline = bfa_fcs_lport_fab_offline
48536+ },
48537+ {
48538+ .init = bfa_fcs_lport_n2n_init,
48539+ .online = bfa_fcs_lport_n2n_online,
48540+ .offline = bfa_fcs_lport_n2n_offline
48541+ },
48542+ {
48543+ .init = bfa_fcs_lport_loop_init,
48544+ .online = bfa_fcs_lport_loop_online,
48545+ .offline = bfa_fcs_lport_loop_offline
48546+ },
48547+};
48548
48549 /*
48550 * fcs_port_sm FCS logical port state machine
48551diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48552index 2e28392..9d865b6 100644
48553--- a/drivers/scsi/bfa/bfa_ioc.h
48554+++ b/drivers/scsi/bfa/bfa_ioc.h
48555@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48556 bfa_ioc_disable_cbfn_t disable_cbfn;
48557 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48558 bfa_ioc_reset_cbfn_t reset_cbfn;
48559-};
48560+} __no_const;
48561
48562 /*
48563 * IOC event notification mechanism.
48564@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48565 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48566 enum bfi_ioc_state fwstate);
48567 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48568-};
48569+} __no_const;
48570
48571 /*
48572 * Queue element to wait for room in request queue. FIFO order is
48573diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48574index a14c784..6de6790 100644
48575--- a/drivers/scsi/bfa/bfa_modules.h
48576+++ b/drivers/scsi/bfa/bfa_modules.h
48577@@ -78,12 +78,12 @@ enum {
48578 \
48579 extern struct bfa_module_s hal_mod_ ## __mod; \
48580 struct bfa_module_s hal_mod_ ## __mod = { \
48581- bfa_ ## __mod ## _meminfo, \
48582- bfa_ ## __mod ## _attach, \
48583- bfa_ ## __mod ## _detach, \
48584- bfa_ ## __mod ## _start, \
48585- bfa_ ## __mod ## _stop, \
48586- bfa_ ## __mod ## _iocdisable, \
48587+ .meminfo = bfa_ ## __mod ## _meminfo, \
48588+ .attach = bfa_ ## __mod ## _attach, \
48589+ .detach = bfa_ ## __mod ## _detach, \
48590+ .start = bfa_ ## __mod ## _start, \
48591+ .stop = bfa_ ## __mod ## _stop, \
48592+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
48593 }
48594
48595 #define BFA_CACHELINE_SZ (256)
48596diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48597index 045c4e1..13de803 100644
48598--- a/drivers/scsi/fcoe/fcoe_sysfs.c
48599+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48600@@ -33,8 +33,8 @@
48601 */
48602 #include "libfcoe.h"
48603
48604-static atomic_t ctlr_num;
48605-static atomic_t fcf_num;
48606+static atomic_unchecked_t ctlr_num;
48607+static atomic_unchecked_t fcf_num;
48608
48609 /*
48610 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48611@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48612 if (!ctlr)
48613 goto out;
48614
48615- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48616+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48617 ctlr->f = f;
48618 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48619 INIT_LIST_HEAD(&ctlr->fcfs);
48620@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48621 fcf->dev.parent = &ctlr->dev;
48622 fcf->dev.bus = &fcoe_bus_type;
48623 fcf->dev.type = &fcoe_fcf_device_type;
48624- fcf->id = atomic_inc_return(&fcf_num) - 1;
48625+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48626 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48627
48628 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48629@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48630 {
48631 int error;
48632
48633- atomic_set(&ctlr_num, 0);
48634- atomic_set(&fcf_num, 0);
48635+ atomic_set_unchecked(&ctlr_num, 0);
48636+ atomic_set_unchecked(&fcf_num, 0);
48637
48638 error = bus_register(&fcoe_bus_type);
48639 if (error)
48640diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48641index 3cbb57a..95e47a3 100644
48642--- a/drivers/scsi/hosts.c
48643+++ b/drivers/scsi/hosts.c
48644@@ -42,7 +42,7 @@
48645 #include "scsi_logging.h"
48646
48647
48648-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48649+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48650
48651
48652 static void scsi_host_cls_release(struct device *dev)
48653@@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48654 * subtract one because we increment first then return, but we need to
48655 * know what the next host number was before increment
48656 */
48657- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48658+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48659 shost->dma_channel = 0xff;
48660
48661 /* These three are default values which can be overridden */
48662diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48663index 9a6e4a2..27843b6 100644
48664--- a/drivers/scsi/hpsa.c
48665+++ b/drivers/scsi/hpsa.c
48666@@ -687,10 +687,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48667 unsigned long flags;
48668
48669 if (h->transMethod & CFGTBL_Trans_io_accel1)
48670- return h->access.command_completed(h, q);
48671+ return h->access->command_completed(h, q);
48672
48673 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48674- return h->access.command_completed(h, q);
48675+ return h->access->command_completed(h, q);
48676
48677 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48678 a = rq->head[rq->current_entry];
48679@@ -5448,7 +5448,7 @@ static void start_io(struct ctlr_info *h)
48680 while (!list_empty(&h->reqQ)) {
48681 c = list_entry(h->reqQ.next, struct CommandList, list);
48682 /* can't do anything if fifo is full */
48683- if ((h->access.fifo_full(h))) {
48684+ if ((h->access->fifo_full(h))) {
48685 h->fifo_recently_full = 1;
48686 dev_warn(&h->pdev->dev, "fifo full\n");
48687 break;
48688@@ -5472,7 +5472,7 @@ static void start_io(struct ctlr_info *h)
48689
48690 /* Tell the controller execute command */
48691 spin_unlock_irqrestore(&h->lock, flags);
48692- h->access.submit_command(h, c);
48693+ h->access->submit_command(h, c);
48694 spin_lock_irqsave(&h->lock, flags);
48695 }
48696 spin_unlock_irqrestore(&h->lock, flags);
48697@@ -5480,17 +5480,17 @@ static void start_io(struct ctlr_info *h)
48698
48699 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48700 {
48701- return h->access.command_completed(h, q);
48702+ return h->access->command_completed(h, q);
48703 }
48704
48705 static inline bool interrupt_pending(struct ctlr_info *h)
48706 {
48707- return h->access.intr_pending(h);
48708+ return h->access->intr_pending(h);
48709 }
48710
48711 static inline long interrupt_not_for_us(struct ctlr_info *h)
48712 {
48713- return (h->access.intr_pending(h) == 0) ||
48714+ return (h->access->intr_pending(h) == 0) ||
48715 (h->interrupts_enabled == 0);
48716 }
48717
48718@@ -6444,7 +6444,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48719 if (prod_index < 0)
48720 return -ENODEV;
48721 h->product_name = products[prod_index].product_name;
48722- h->access = *(products[prod_index].access);
48723+ h->access = products[prod_index].access;
48724
48725 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48726 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48727@@ -6723,7 +6723,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48728 {
48729 unsigned long flags;
48730
48731- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48732+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48733 spin_lock_irqsave(&h->lock, flags);
48734 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48735 spin_unlock_irqrestore(&h->lock, flags);
48736@@ -6951,7 +6951,7 @@ reinit_after_soft_reset:
48737 }
48738
48739 /* make sure the board interrupts are off */
48740- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48741+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48742
48743 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48744 goto clean2;
48745@@ -6986,7 +6986,7 @@ reinit_after_soft_reset:
48746 * fake ones to scoop up any residual completions.
48747 */
48748 spin_lock_irqsave(&h->lock, flags);
48749- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48750+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48751 spin_unlock_irqrestore(&h->lock, flags);
48752 free_irqs(h);
48753 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48754@@ -7005,9 +7005,9 @@ reinit_after_soft_reset:
48755 dev_info(&h->pdev->dev, "Board READY.\n");
48756 dev_info(&h->pdev->dev,
48757 "Waiting for stale completions to drain.\n");
48758- h->access.set_intr_mask(h, HPSA_INTR_ON);
48759+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48760 msleep(10000);
48761- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48762+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48763
48764 rc = controller_reset_failed(h->cfgtable);
48765 if (rc)
48766@@ -7033,7 +7033,7 @@ reinit_after_soft_reset:
48767 h->drv_req_rescan = 0;
48768
48769 /* Turn the interrupts on so we can service requests */
48770- h->access.set_intr_mask(h, HPSA_INTR_ON);
48771+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48772
48773 hpsa_hba_inquiry(h);
48774 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48775@@ -7102,7 +7102,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48776 * To write all data in the battery backed cache to disks
48777 */
48778 hpsa_flush_cache(h);
48779- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48780+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48781 hpsa_free_irqs_and_disable_msix(h);
48782 }
48783
48784@@ -7220,7 +7220,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
48785 CFGTBL_Trans_enable_directed_msix |
48786 (trans_support & (CFGTBL_Trans_io_accel1 |
48787 CFGTBL_Trans_io_accel2));
48788- struct access_method access = SA5_performant_access;
48789+ struct access_method *access = &SA5_performant_access;
48790
48791 /* This is a bit complicated. There are 8 registers on
48792 * the controller which we write to to tell it 8 different
48793@@ -7285,12 +7285,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
48794 * enable outbound interrupt coalescing in accelerator mode;
48795 */
48796 if (trans_support & CFGTBL_Trans_io_accel1) {
48797- access = SA5_ioaccel_mode1_access;
48798+ access = &SA5_ioaccel_mode1_access;
48799 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
48800 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
48801 } else {
48802 if (trans_support & CFGTBL_Trans_io_accel2) {
48803- access = SA5_ioaccel_mode2_access;
48804+ access = &SA5_ioaccel_mode2_access;
48805 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
48806 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
48807 }
48808diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48809index 44235a2..962e91b 100644
48810--- a/drivers/scsi/hpsa.h
48811+++ b/drivers/scsi/hpsa.h
48812@@ -128,7 +128,7 @@ struct ctlr_info {
48813 unsigned int msix_vector;
48814 unsigned int msi_vector;
48815 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48816- struct access_method access;
48817+ struct access_method *access;
48818 char hba_mode_enabled;
48819
48820 /* queue and queue Info */
48821@@ -541,35 +541,35 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
48822 }
48823
48824 static struct access_method SA5_access = {
48825- SA5_submit_command,
48826- SA5_intr_mask,
48827- SA5_fifo_full,
48828- SA5_intr_pending,
48829- SA5_completed,
48830+ .submit_command = SA5_submit_command,
48831+ .set_intr_mask = SA5_intr_mask,
48832+ .fifo_full = SA5_fifo_full,
48833+ .intr_pending = SA5_intr_pending,
48834+ .command_completed = SA5_completed,
48835 };
48836
48837 static struct access_method SA5_ioaccel_mode1_access = {
48838- SA5_submit_command,
48839- SA5_performant_intr_mask,
48840- SA5_fifo_full,
48841- SA5_ioaccel_mode1_intr_pending,
48842- SA5_ioaccel_mode1_completed,
48843+ .submit_command = SA5_submit_command,
48844+ .set_intr_mask = SA5_performant_intr_mask,
48845+ .fifo_full = SA5_fifo_full,
48846+ .intr_pending = SA5_ioaccel_mode1_intr_pending,
48847+ .command_completed = SA5_ioaccel_mode1_completed,
48848 };
48849
48850 static struct access_method SA5_ioaccel_mode2_access = {
48851- SA5_submit_command_ioaccel2,
48852- SA5_performant_intr_mask,
48853- SA5_fifo_full,
48854- SA5_performant_intr_pending,
48855- SA5_performant_completed,
48856+ .submit_command = SA5_submit_command_ioaccel2,
48857+ .set_intr_mask = SA5_performant_intr_mask,
48858+ .fifo_full = SA5_fifo_full,
48859+ .intr_pending = SA5_performant_intr_pending,
48860+ .command_completed = SA5_performant_completed,
48861 };
48862
48863 static struct access_method SA5_performant_access = {
48864- SA5_submit_command,
48865- SA5_performant_intr_mask,
48866- SA5_fifo_full,
48867- SA5_performant_intr_pending,
48868- SA5_performant_completed,
48869+ .submit_command = SA5_submit_command,
48870+ .set_intr_mask = SA5_performant_intr_mask,
48871+ .fifo_full = SA5_fifo_full,
48872+ .intr_pending = SA5_performant_intr_pending,
48873+ .command_completed = SA5_performant_completed,
48874 };
48875
48876 struct board_type {
48877diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48878index 1b3a094..068e683 100644
48879--- a/drivers/scsi/libfc/fc_exch.c
48880+++ b/drivers/scsi/libfc/fc_exch.c
48881@@ -101,12 +101,12 @@ struct fc_exch_mgr {
48882 u16 pool_max_index;
48883
48884 struct {
48885- atomic_t no_free_exch;
48886- atomic_t no_free_exch_xid;
48887- atomic_t xid_not_found;
48888- atomic_t xid_busy;
48889- atomic_t seq_not_found;
48890- atomic_t non_bls_resp;
48891+ atomic_unchecked_t no_free_exch;
48892+ atomic_unchecked_t no_free_exch_xid;
48893+ atomic_unchecked_t xid_not_found;
48894+ atomic_unchecked_t xid_busy;
48895+ atomic_unchecked_t seq_not_found;
48896+ atomic_unchecked_t non_bls_resp;
48897 } stats;
48898 };
48899
48900@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48901 /* allocate memory for exchange */
48902 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48903 if (!ep) {
48904- atomic_inc(&mp->stats.no_free_exch);
48905+ atomic_inc_unchecked(&mp->stats.no_free_exch);
48906 goto out;
48907 }
48908 memset(ep, 0, sizeof(*ep));
48909@@ -874,7 +874,7 @@ out:
48910 return ep;
48911 err:
48912 spin_unlock_bh(&pool->lock);
48913- atomic_inc(&mp->stats.no_free_exch_xid);
48914+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48915 mempool_free(ep, mp->ep_pool);
48916 return NULL;
48917 }
48918@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48919 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48920 ep = fc_exch_find(mp, xid);
48921 if (!ep) {
48922- atomic_inc(&mp->stats.xid_not_found);
48923+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48924 reject = FC_RJT_OX_ID;
48925 goto out;
48926 }
48927@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48928 ep = fc_exch_find(mp, xid);
48929 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48930 if (ep) {
48931- atomic_inc(&mp->stats.xid_busy);
48932+ atomic_inc_unchecked(&mp->stats.xid_busy);
48933 reject = FC_RJT_RX_ID;
48934 goto rel;
48935 }
48936@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48937 }
48938 xid = ep->xid; /* get our XID */
48939 } else if (!ep) {
48940- atomic_inc(&mp->stats.xid_not_found);
48941+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48942 reject = FC_RJT_RX_ID; /* XID not found */
48943 goto out;
48944 }
48945@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48946 } else {
48947 sp = &ep->seq;
48948 if (sp->id != fh->fh_seq_id) {
48949- atomic_inc(&mp->stats.seq_not_found);
48950+ atomic_inc_unchecked(&mp->stats.seq_not_found);
48951 if (f_ctl & FC_FC_END_SEQ) {
48952 /*
48953 * Update sequence_id based on incoming last
48954@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48955
48956 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48957 if (!ep) {
48958- atomic_inc(&mp->stats.xid_not_found);
48959+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48960 goto out;
48961 }
48962 if (ep->esb_stat & ESB_ST_COMPLETE) {
48963- atomic_inc(&mp->stats.xid_not_found);
48964+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48965 goto rel;
48966 }
48967 if (ep->rxid == FC_XID_UNKNOWN)
48968 ep->rxid = ntohs(fh->fh_rx_id);
48969 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48970- atomic_inc(&mp->stats.xid_not_found);
48971+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48972 goto rel;
48973 }
48974 if (ep->did != ntoh24(fh->fh_s_id) &&
48975 ep->did != FC_FID_FLOGI) {
48976- atomic_inc(&mp->stats.xid_not_found);
48977+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48978 goto rel;
48979 }
48980 sof = fr_sof(fp);
48981@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48982 sp->ssb_stat |= SSB_ST_RESP;
48983 sp->id = fh->fh_seq_id;
48984 } else if (sp->id != fh->fh_seq_id) {
48985- atomic_inc(&mp->stats.seq_not_found);
48986+ atomic_inc_unchecked(&mp->stats.seq_not_found);
48987 goto rel;
48988 }
48989
48990@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48991 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
48992
48993 if (!sp)
48994- atomic_inc(&mp->stats.xid_not_found);
48995+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48996 else
48997- atomic_inc(&mp->stats.non_bls_resp);
48998+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
48999
49000 fc_frame_free(fp);
49001 }
49002@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49003
49004 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49005 mp = ema->mp;
49006- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49007+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49008 st->fc_no_free_exch_xid +=
49009- atomic_read(&mp->stats.no_free_exch_xid);
49010- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49011- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49012- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49013- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49014+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49015+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49016+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49017+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49018+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49019 }
49020 }
49021 EXPORT_SYMBOL(fc_exch_update_stats);
49022diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49023index 766098a..1c6c971 100644
49024--- a/drivers/scsi/libsas/sas_ata.c
49025+++ b/drivers/scsi/libsas/sas_ata.c
49026@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49027 .postreset = ata_std_postreset,
49028 .error_handler = ata_std_error_handler,
49029 .post_internal_cmd = sas_ata_post_internal,
49030- .qc_defer = ata_std_qc_defer,
49031+ .qc_defer = ata_std_qc_defer,
49032 .qc_prep = ata_noop_qc_prep,
49033 .qc_issue = sas_ata_qc_issue,
49034 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49035diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49036index 94a3caf..a118dec 100644
49037--- a/drivers/scsi/lpfc/lpfc.h
49038+++ b/drivers/scsi/lpfc/lpfc.h
49039@@ -430,7 +430,7 @@ struct lpfc_vport {
49040 struct dentry *debug_nodelist;
49041 struct dentry *vport_debugfs_root;
49042 struct lpfc_debugfs_trc *disc_trc;
49043- atomic_t disc_trc_cnt;
49044+ atomic_unchecked_t disc_trc_cnt;
49045 #endif
49046 uint8_t stat_data_enabled;
49047 uint8_t stat_data_blocked;
49048@@ -879,8 +879,8 @@ struct lpfc_hba {
49049 struct timer_list fabric_block_timer;
49050 unsigned long bit_flags;
49051 #define FABRIC_COMANDS_BLOCKED 0
49052- atomic_t num_rsrc_err;
49053- atomic_t num_cmd_success;
49054+ atomic_unchecked_t num_rsrc_err;
49055+ atomic_unchecked_t num_cmd_success;
49056 unsigned long last_rsrc_error_time;
49057 unsigned long last_ramp_down_time;
49058 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
49059@@ -915,7 +915,7 @@ struct lpfc_hba {
49060
49061 struct dentry *debug_slow_ring_trc;
49062 struct lpfc_debugfs_trc *slow_ring_trc;
49063- atomic_t slow_ring_trc_cnt;
49064+ atomic_unchecked_t slow_ring_trc_cnt;
49065 /* iDiag debugfs sub-directory */
49066 struct dentry *idiag_root;
49067 struct dentry *idiag_pci_cfg;
49068diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49069index 828c08e..e3378e0 100644
49070--- a/drivers/scsi/lpfc/lpfc_debugfs.c
49071+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49072@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49073
49074 #include <linux/debugfs.h>
49075
49076-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49077+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49078 static unsigned long lpfc_debugfs_start_time = 0L;
49079
49080 /* iDiag */
49081@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49082 lpfc_debugfs_enable = 0;
49083
49084 len = 0;
49085- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49086+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49087 (lpfc_debugfs_max_disc_trc - 1);
49088 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49089 dtp = vport->disc_trc + i;
49090@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49091 lpfc_debugfs_enable = 0;
49092
49093 len = 0;
49094- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49095+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49096 (lpfc_debugfs_max_slow_ring_trc - 1);
49097 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49098 dtp = phba->slow_ring_trc + i;
49099@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49100 !vport || !vport->disc_trc)
49101 return;
49102
49103- index = atomic_inc_return(&vport->disc_trc_cnt) &
49104+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49105 (lpfc_debugfs_max_disc_trc - 1);
49106 dtp = vport->disc_trc + index;
49107 dtp->fmt = fmt;
49108 dtp->data1 = data1;
49109 dtp->data2 = data2;
49110 dtp->data3 = data3;
49111- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49112+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49113 dtp->jif = jiffies;
49114 #endif
49115 return;
49116@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49117 !phba || !phba->slow_ring_trc)
49118 return;
49119
49120- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49121+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49122 (lpfc_debugfs_max_slow_ring_trc - 1);
49123 dtp = phba->slow_ring_trc + index;
49124 dtp->fmt = fmt;
49125 dtp->data1 = data1;
49126 dtp->data2 = data2;
49127 dtp->data3 = data3;
49128- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49129+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49130 dtp->jif = jiffies;
49131 #endif
49132 return;
49133@@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49134 "slow_ring buffer\n");
49135 goto debug_failed;
49136 }
49137- atomic_set(&phba->slow_ring_trc_cnt, 0);
49138+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49139 memset(phba->slow_ring_trc, 0,
49140 (sizeof(struct lpfc_debugfs_trc) *
49141 lpfc_debugfs_max_slow_ring_trc));
49142@@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49143 "buffer\n");
49144 goto debug_failed;
49145 }
49146- atomic_set(&vport->disc_trc_cnt, 0);
49147+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49148
49149 snprintf(name, sizeof(name), "discovery_trace");
49150 vport->debug_disc_trc =
49151diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49152index 635eeb3..038aef6 100644
49153--- a/drivers/scsi/lpfc/lpfc_init.c
49154+++ b/drivers/scsi/lpfc/lpfc_init.c
49155@@ -11194,8 +11194,10 @@ lpfc_init(void)
49156 "misc_register returned with status %d", error);
49157
49158 if (lpfc_enable_npiv) {
49159- lpfc_transport_functions.vport_create = lpfc_vport_create;
49160- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49161+ pax_open_kernel();
49162+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49163+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49164+ pax_close_kernel();
49165 }
49166 lpfc_transport_template =
49167 fc_attach_transport(&lpfc_transport_functions);
49168diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49169index 462453e..c0023a6 100644
49170--- a/drivers/scsi/lpfc/lpfc_scsi.c
49171+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49172@@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49173 uint32_t evt_posted;
49174
49175 spin_lock_irqsave(&phba->hbalock, flags);
49176- atomic_inc(&phba->num_rsrc_err);
49177+ atomic_inc_unchecked(&phba->num_rsrc_err);
49178 phba->last_rsrc_error_time = jiffies;
49179
49180 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49181@@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49182 unsigned long num_rsrc_err, num_cmd_success;
49183 int i;
49184
49185- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49186- num_cmd_success = atomic_read(&phba->num_cmd_success);
49187+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49188+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49189
49190 /*
49191 * The error and success command counters are global per
49192@@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49193 }
49194 }
49195 lpfc_destroy_vport_work_array(phba, vports);
49196- atomic_set(&phba->num_rsrc_err, 0);
49197- atomic_set(&phba->num_cmd_success, 0);
49198+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49199+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49200 }
49201
49202 /**
49203diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49204index 6fd7d40..b444223 100644
49205--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49206+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49207@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49208 {
49209 struct scsi_device *sdev = to_scsi_device(dev);
49210 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49211- static struct _raid_device *raid_device;
49212+ struct _raid_device *raid_device;
49213 unsigned long flags;
49214 Mpi2RaidVolPage0_t vol_pg0;
49215 Mpi2ConfigReply_t mpi_reply;
49216@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49217 {
49218 struct scsi_device *sdev = to_scsi_device(dev);
49219 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49220- static struct _raid_device *raid_device;
49221+ struct _raid_device *raid_device;
49222 unsigned long flags;
49223 Mpi2RaidVolPage0_t vol_pg0;
49224 Mpi2ConfigReply_t mpi_reply;
49225@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49226 struct fw_event_work *fw_event)
49227 {
49228 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49229- static struct _raid_device *raid_device;
49230+ struct _raid_device *raid_device;
49231 unsigned long flags;
49232 u16 handle;
49233
49234@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49235 u64 sas_address;
49236 struct _sas_device *sas_device;
49237 struct _sas_node *expander_device;
49238- static struct _raid_device *raid_device;
49239+ struct _raid_device *raid_device;
49240 u8 retry_count;
49241 unsigned long flags;
49242
49243diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49244index be8ce54..94ed33a 100644
49245--- a/drivers/scsi/pmcraid.c
49246+++ b/drivers/scsi/pmcraid.c
49247@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49248 res->scsi_dev = scsi_dev;
49249 scsi_dev->hostdata = res;
49250 res->change_detected = 0;
49251- atomic_set(&res->read_failures, 0);
49252- atomic_set(&res->write_failures, 0);
49253+ atomic_set_unchecked(&res->read_failures, 0);
49254+ atomic_set_unchecked(&res->write_failures, 0);
49255 rc = 0;
49256 }
49257 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49258@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49259
49260 /* If this was a SCSI read/write command keep count of errors */
49261 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49262- atomic_inc(&res->read_failures);
49263+ atomic_inc_unchecked(&res->read_failures);
49264 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49265- atomic_inc(&res->write_failures);
49266+ atomic_inc_unchecked(&res->write_failures);
49267
49268 if (!RES_IS_GSCSI(res->cfg_entry) &&
49269 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49270@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49271 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49272 * hrrq_id assigned here in queuecommand
49273 */
49274- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49275+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49276 pinstance->num_hrrq;
49277 cmd->cmd_done = pmcraid_io_done;
49278
49279@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49280 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49281 * hrrq_id assigned here in queuecommand
49282 */
49283- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49284+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49285 pinstance->num_hrrq;
49286
49287 if (request_size) {
49288@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49289
49290 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49291 /* add resources only after host is added into system */
49292- if (!atomic_read(&pinstance->expose_resources))
49293+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49294 return;
49295
49296 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49297@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49298 init_waitqueue_head(&pinstance->reset_wait_q);
49299
49300 atomic_set(&pinstance->outstanding_cmds, 0);
49301- atomic_set(&pinstance->last_message_id, 0);
49302- atomic_set(&pinstance->expose_resources, 0);
49303+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49304+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49305
49306 INIT_LIST_HEAD(&pinstance->free_res_q);
49307 INIT_LIST_HEAD(&pinstance->used_res_q);
49308@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49309 /* Schedule worker thread to handle CCN and take care of adding and
49310 * removing devices to OS
49311 */
49312- atomic_set(&pinstance->expose_resources, 1);
49313+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49314 schedule_work(&pinstance->worker_q);
49315 return rc;
49316
49317diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49318index e1d150f..6c6df44 100644
49319--- a/drivers/scsi/pmcraid.h
49320+++ b/drivers/scsi/pmcraid.h
49321@@ -748,7 +748,7 @@ struct pmcraid_instance {
49322 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49323
49324 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49325- atomic_t last_message_id;
49326+ atomic_unchecked_t last_message_id;
49327
49328 /* configuration table */
49329 struct pmcraid_config_table *cfg_table;
49330@@ -777,7 +777,7 @@ struct pmcraid_instance {
49331 atomic_t outstanding_cmds;
49332
49333 /* should add/delete resources to mid-layer now ?*/
49334- atomic_t expose_resources;
49335+ atomic_unchecked_t expose_resources;
49336
49337
49338
49339@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49340 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49341 };
49342 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49343- atomic_t read_failures; /* count of failed READ commands */
49344- atomic_t write_failures; /* count of failed WRITE commands */
49345+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49346+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49347
49348 /* To indicate add/delete/modify during CCN */
49349 u8 change_detected;
49350diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49351index 07befcf..c0bff13 100644
49352--- a/drivers/scsi/qla2xxx/qla_attr.c
49353+++ b/drivers/scsi/qla2xxx/qla_attr.c
49354@@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49355 return 0;
49356 }
49357
49358-struct fc_function_template qla2xxx_transport_functions = {
49359+fc_function_template_no_const qla2xxx_transport_functions = {
49360
49361 .show_host_node_name = 1,
49362 .show_host_port_name = 1,
49363@@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49364 .bsg_timeout = qla24xx_bsg_timeout,
49365 };
49366
49367-struct fc_function_template qla2xxx_transport_vport_functions = {
49368+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49369
49370 .show_host_node_name = 1,
49371 .show_host_port_name = 1,
49372diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49373index e665e81..16e84e6 100644
49374--- a/drivers/scsi/qla2xxx/qla_gbl.h
49375+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49376@@ -557,8 +557,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49377 struct device_attribute;
49378 extern struct device_attribute *qla2x00_host_attrs[];
49379 struct fc_function_template;
49380-extern struct fc_function_template qla2xxx_transport_functions;
49381-extern struct fc_function_template qla2xxx_transport_vport_functions;
49382+extern fc_function_template_no_const qla2xxx_transport_functions;
49383+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49384 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49385 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49386 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49387diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49388index 19e99cc..b3c0b7b 100644
49389--- a/drivers/scsi/qla2xxx/qla_os.c
49390+++ b/drivers/scsi/qla2xxx/qla_os.c
49391@@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49392 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49393 /* Ok, a 64bit DMA mask is applicable. */
49394 ha->flags.enable_64bit_addressing = 1;
49395- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49396- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49397+ pax_open_kernel();
49398+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49399+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49400+ pax_close_kernel();
49401 return;
49402 }
49403 }
49404diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49405index 73a5022..4e0797c 100644
49406--- a/drivers/scsi/qla4xxx/ql4_def.h
49407+++ b/drivers/scsi/qla4xxx/ql4_def.h
49408@@ -305,7 +305,7 @@ struct ddb_entry {
49409 * (4000 only) */
49410 atomic_t relogin_timer; /* Max Time to wait for
49411 * relogin to complete */
49412- atomic_t relogin_retry_count; /* Num of times relogin has been
49413+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49414 * retried */
49415 uint32_t default_time2wait; /* Default Min time between
49416 * relogins (+aens) */
49417diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49418index 459b9f7..2930a68 100644
49419--- a/drivers/scsi/qla4xxx/ql4_os.c
49420+++ b/drivers/scsi/qla4xxx/ql4_os.c
49421@@ -4499,12 +4499,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49422 */
49423 if (!iscsi_is_session_online(cls_sess)) {
49424 /* Reset retry relogin timer */
49425- atomic_inc(&ddb_entry->relogin_retry_count);
49426+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49427 DEBUG2(ql4_printk(KERN_INFO, ha,
49428 "%s: index[%d] relogin timed out-retrying"
49429 " relogin (%d), retry (%d)\n", __func__,
49430 ddb_entry->fw_ddb_index,
49431- atomic_read(&ddb_entry->relogin_retry_count),
49432+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49433 ddb_entry->default_time2wait + 4));
49434 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49435 atomic_set(&ddb_entry->retry_relogin_timer,
49436@@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49437
49438 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49439 atomic_set(&ddb_entry->relogin_timer, 0);
49440- atomic_set(&ddb_entry->relogin_retry_count, 0);
49441+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49442 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49443 ddb_entry->default_relogin_timeout =
49444 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49445diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49446index 88d46fe..7351be5 100644
49447--- a/drivers/scsi/scsi.c
49448+++ b/drivers/scsi/scsi.c
49449@@ -640,7 +640,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49450 struct Scsi_Host *host = cmd->device->host;
49451 int rtn = 0;
49452
49453- atomic_inc(&cmd->device->iorequest_cnt);
49454+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49455
49456 /* check if the device is still usable */
49457 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49458diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49459index 9db097a..ca5c291 100644
49460--- a/drivers/scsi/scsi_lib.c
49461+++ b/drivers/scsi/scsi_lib.c
49462@@ -1464,7 +1464,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49463 shost = sdev->host;
49464 scsi_init_cmd_errh(cmd);
49465 cmd->result = DID_NO_CONNECT << 16;
49466- atomic_inc(&cmd->device->iorequest_cnt);
49467+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49468
49469 /*
49470 * SCSI request completion path will do scsi_device_unbusy(),
49471@@ -1490,9 +1490,9 @@ static void scsi_softirq_done(struct request *rq)
49472
49473 INIT_LIST_HEAD(&cmd->eh_entry);
49474
49475- atomic_inc(&cmd->device->iodone_cnt);
49476+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
49477 if (cmd->result)
49478- atomic_inc(&cmd->device->ioerr_cnt);
49479+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49480
49481 disposition = scsi_decide_disposition(cmd);
49482 if (disposition != SUCCESS &&
49483diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49484index 074e8cc..f612e5c 100644
49485--- a/drivers/scsi/scsi_sysfs.c
49486+++ b/drivers/scsi/scsi_sysfs.c
49487@@ -780,7 +780,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49488 char *buf) \
49489 { \
49490 struct scsi_device *sdev = to_scsi_device(dev); \
49491- unsigned long long count = atomic_read(&sdev->field); \
49492+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
49493 return snprintf(buf, 20, "0x%llx\n", count); \
49494 } \
49495 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49496diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49497index e51add0..1e06a96 100644
49498--- a/drivers/scsi/scsi_tgt_lib.c
49499+++ b/drivers/scsi/scsi_tgt_lib.c
49500@@ -363,7 +363,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49501 int err;
49502
49503 dprintk("%lx %u\n", uaddr, len);
49504- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49505+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49506 if (err) {
49507 /*
49508 * TODO: need to fixup sg_tablesize, max_segment_size,
49509diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49510index f80908f..22aba76 100644
49511--- a/drivers/scsi/scsi_transport_fc.c
49512+++ b/drivers/scsi/scsi_transport_fc.c
49513@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49514 * Netlink Infrastructure
49515 */
49516
49517-static atomic_t fc_event_seq;
49518+static atomic_unchecked_t fc_event_seq;
49519
49520 /**
49521 * fc_get_event_number - Obtain the next sequential FC event number
49522@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
49523 u32
49524 fc_get_event_number(void)
49525 {
49526- return atomic_add_return(1, &fc_event_seq);
49527+ return atomic_add_return_unchecked(1, &fc_event_seq);
49528 }
49529 EXPORT_SYMBOL(fc_get_event_number);
49530
49531@@ -655,7 +655,7 @@ static __init int fc_transport_init(void)
49532 {
49533 int error;
49534
49535- atomic_set(&fc_event_seq, 0);
49536+ atomic_set_unchecked(&fc_event_seq, 0);
49537
49538 error = transport_class_register(&fc_host_class);
49539 if (error)
49540@@ -845,7 +845,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49541 char *cp;
49542
49543 *val = simple_strtoul(buf, &cp, 0);
49544- if ((*cp && (*cp != '\n')) || (*val < 0))
49545+ if (*cp && (*cp != '\n'))
49546 return -EINVAL;
49547 /*
49548 * Check for overflow; dev_loss_tmo is u32
49549diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49550index 0102a2d..cc3f8e9 100644
49551--- a/drivers/scsi/scsi_transport_iscsi.c
49552+++ b/drivers/scsi/scsi_transport_iscsi.c
49553@@ -79,7 +79,7 @@ struct iscsi_internal {
49554 struct transport_container session_cont;
49555 };
49556
49557-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49558+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49559 static struct workqueue_struct *iscsi_eh_timer_workq;
49560
49561 static DEFINE_IDA(iscsi_sess_ida);
49562@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49563 int err;
49564
49565 ihost = shost->shost_data;
49566- session->sid = atomic_add_return(1, &iscsi_session_nr);
49567+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49568
49569 if (target_id == ISCSI_MAX_TARGET) {
49570 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49571@@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
49572 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49573 ISCSI_TRANSPORT_VERSION);
49574
49575- atomic_set(&iscsi_session_nr, 0);
49576+ atomic_set_unchecked(&iscsi_session_nr, 0);
49577
49578 err = class_register(&iscsi_transport_class);
49579 if (err)
49580diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49581index 13e8983..d306a68 100644
49582--- a/drivers/scsi/scsi_transport_srp.c
49583+++ b/drivers/scsi/scsi_transport_srp.c
49584@@ -36,7 +36,7 @@
49585 #include "scsi_transport_srp_internal.h"
49586
49587 struct srp_host_attrs {
49588- atomic_t next_port_id;
49589+ atomic_unchecked_t next_port_id;
49590 };
49591 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49592
49593@@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49594 struct Scsi_Host *shost = dev_to_shost(dev);
49595 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49596
49597- atomic_set(&srp_host->next_port_id, 0);
49598+ atomic_set_unchecked(&srp_host->next_port_id, 0);
49599 return 0;
49600 }
49601
49602@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49603 rport_fast_io_fail_timedout);
49604 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49605
49606- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49607+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49608 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49609
49610 transport_setup_device(&rport->dev);
49611diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49612index efcbcd1..aeaf26e 100644
49613--- a/drivers/scsi/sd.c
49614+++ b/drivers/scsi/sd.c
49615@@ -2968,7 +2968,7 @@ static int sd_probe(struct device *dev)
49616 sdkp->disk = gd;
49617 sdkp->index = index;
49618 atomic_set(&sdkp->openers, 0);
49619- atomic_set(&sdkp->device->ioerr_cnt, 0);
49620+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49621
49622 if (!sdp->request_queue->rq_timeout) {
49623 if (sdp->type != TYPE_MOD)
49624diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49625index df5e961..df6b97f 100644
49626--- a/drivers/scsi/sg.c
49627+++ b/drivers/scsi/sg.c
49628@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49629 sdp->disk->disk_name,
49630 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49631 NULL,
49632- (char *)arg);
49633+ (char __user *)arg);
49634 case BLKTRACESTART:
49635 return blk_trace_startstop(sdp->device->request_queue, 1);
49636 case BLKTRACESTOP:
49637diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49638index 939edf4..3f50423 100644
49639--- a/drivers/spi/spi.c
49640+++ b/drivers/spi/spi.c
49641@@ -2204,7 +2204,7 @@ int spi_bus_unlock(struct spi_master *master)
49642 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49643
49644 /* portable code must never pass more than 32 bytes */
49645-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49646+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49647
49648 static u8 *buf;
49649
49650diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49651index 2c61783..4d49e4e 100644
49652--- a/drivers/staging/android/timed_output.c
49653+++ b/drivers/staging/android/timed_output.c
49654@@ -25,7 +25,7 @@
49655 #include "timed_output.h"
49656
49657 static struct class *timed_output_class;
49658-static atomic_t device_count;
49659+static atomic_unchecked_t device_count;
49660
49661 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49662 char *buf)
49663@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49664 timed_output_class = class_create(THIS_MODULE, "timed_output");
49665 if (IS_ERR(timed_output_class))
49666 return PTR_ERR(timed_output_class);
49667- atomic_set(&device_count, 0);
49668+ atomic_set_unchecked(&device_count, 0);
49669 timed_output_class->dev_groups = timed_output_groups;
49670 }
49671
49672@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49673 if (ret < 0)
49674 return ret;
49675
49676- tdev->index = atomic_inc_return(&device_count);
49677+ tdev->index = atomic_inc_return_unchecked(&device_count);
49678 tdev->dev = device_create(timed_output_class, NULL,
49679 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49680 if (IS_ERR(tdev->dev))
49681diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49682index fe47cd3..19a1bd1 100644
49683--- a/drivers/staging/gdm724x/gdm_tty.c
49684+++ b/drivers/staging/gdm724x/gdm_tty.c
49685@@ -44,7 +44,7 @@
49686 #define gdm_tty_send_control(n, r, v, d, l) (\
49687 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49688
49689-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49690+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49691
49692 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49693 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49694diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49695index c270c9a..94ddf82 100644
49696--- a/drivers/staging/imx-drm/imx-drm-core.c
49697+++ b/drivers/staging/imx-drm/imx-drm-core.c
49698@@ -362,7 +362,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
49699 if (imxdrm->pipes >= MAX_CRTC)
49700 return -EINVAL;
49701
49702- if (imxdrm->drm->open_count)
49703+ if (local_read(&imxdrm->drm->open_count))
49704 return -EBUSY;
49705
49706 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
49707diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49708index 3f8020c..649fded 100644
49709--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49710+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49711@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49712 return 0;
49713 }
49714
49715-sfw_test_client_ops_t brw_test_client;
49716-void brw_init_test_client(void)
49717-{
49718- brw_test_client.tso_init = brw_client_init;
49719- brw_test_client.tso_fini = brw_client_fini;
49720- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49721- brw_test_client.tso_done_rpc = brw_client_done_rpc;
49722+sfw_test_client_ops_t brw_test_client = {
49723+ .tso_init = brw_client_init,
49724+ .tso_fini = brw_client_fini,
49725+ .tso_prep_rpc = brw_client_prep_rpc,
49726+ .tso_done_rpc = brw_client_done_rpc,
49727 };
49728
49729 srpc_service_t brw_test_service;
49730diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49731index 050723a..fa6fdf1 100644
49732--- a/drivers/staging/lustre/lnet/selftest/framework.c
49733+++ b/drivers/staging/lustre/lnet/selftest/framework.c
49734@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49735
49736 extern sfw_test_client_ops_t ping_test_client;
49737 extern srpc_service_t ping_test_service;
49738-extern void ping_init_test_client(void);
49739 extern void ping_init_test_service(void);
49740
49741 extern sfw_test_client_ops_t brw_test_client;
49742 extern srpc_service_t brw_test_service;
49743-extern void brw_init_test_client(void);
49744 extern void brw_init_test_service(void);
49745
49746
49747@@ -1684,12 +1682,10 @@ sfw_startup (void)
49748 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49749 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49750
49751- brw_init_test_client();
49752 brw_init_test_service();
49753 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49754 LASSERT (rc == 0);
49755
49756- ping_init_test_client();
49757 ping_init_test_service();
49758 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49759 LASSERT (rc == 0);
49760diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49761index 750cac4..e4d751f 100644
49762--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49763+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49764@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49765 return 0;
49766 }
49767
49768-sfw_test_client_ops_t ping_test_client;
49769-void ping_init_test_client(void)
49770-{
49771- ping_test_client.tso_init = ping_client_init;
49772- ping_test_client.tso_fini = ping_client_fini;
49773- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49774- ping_test_client.tso_done_rpc = ping_client_done_rpc;
49775-}
49776+sfw_test_client_ops_t ping_test_client = {
49777+ .tso_init = ping_client_init,
49778+ .tso_fini = ping_client_fini,
49779+ .tso_prep_rpc = ping_client_prep_rpc,
49780+ .tso_done_rpc = ping_client_done_rpc,
49781+};
49782
49783 srpc_service_t ping_test_service;
49784 void ping_init_test_service(void)
49785diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49786index 3e25f00..0d59cf5 100644
49787--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49788+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49789@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49790 ldlm_completion_callback lcs_completion;
49791 ldlm_blocking_callback lcs_blocking;
49792 ldlm_glimpse_callback lcs_glimpse;
49793-};
49794+} __no_const;
49795
49796 /* ldlm_lockd.c */
49797 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49798diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49799index 72cf3fe..4beac19 100644
49800--- a/drivers/staging/lustre/lustre/include/obd.h
49801+++ b/drivers/staging/lustre/lustre/include/obd.h
49802@@ -1427,7 +1427,7 @@ struct md_ops {
49803 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49804 * wrapper function in include/linux/obd_class.h.
49805 */
49806-};
49807+} __no_const;
49808
49809 struct lsm_operations {
49810 void (*lsm_free)(struct lov_stripe_md *);
49811diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49812index 986bf38..eab2558f 100644
49813--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49814+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49815@@ -259,7 +259,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49816 int added = (mode == LCK_NL);
49817 int overlaps = 0;
49818 int splitted = 0;
49819- const struct ldlm_callback_suite null_cbs = { NULL };
49820+ const struct ldlm_callback_suite null_cbs = { };
49821
49822 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49823 LPU64" end "LPU64"\n", *flags,
49824diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49825index e947b91..f408990 100644
49826--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49827+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49828@@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49829 int LL_PROC_PROTO(proc_console_max_delay_cs)
49830 {
49831 int rc, max_delay_cs;
49832- ctl_table_t dummy = *table;
49833+ ctl_table_no_const dummy = *table;
49834 cfs_duration_t d;
49835
49836 dummy.data = &max_delay_cs;
49837@@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49838 int LL_PROC_PROTO(proc_console_min_delay_cs)
49839 {
49840 int rc, min_delay_cs;
49841- ctl_table_t dummy = *table;
49842+ ctl_table_no_const dummy = *table;
49843 cfs_duration_t d;
49844
49845 dummy.data = &min_delay_cs;
49846@@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49847 int LL_PROC_PROTO(proc_console_backoff)
49848 {
49849 int rc, backoff;
49850- ctl_table_t dummy = *table;
49851+ ctl_table_no_const dummy = *table;
49852
49853 dummy.data = &backoff;
49854 dummy.proc_handler = &proc_dointvec;
49855diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49856index 24ae26d..9d09cab 100644
49857--- a/drivers/staging/lustre/lustre/libcfs/module.c
49858+++ b/drivers/staging/lustre/lustre/libcfs/module.c
49859@@ -313,11 +313,11 @@ out:
49860
49861
49862 struct cfs_psdev_ops libcfs_psdev_ops = {
49863- libcfs_psdev_open,
49864- libcfs_psdev_release,
49865- NULL,
49866- NULL,
49867- libcfs_ioctl
49868+ .p_open = libcfs_psdev_open,
49869+ .p_close = libcfs_psdev_release,
49870+ .p_read = NULL,
49871+ .p_write = NULL,
49872+ .p_ioctl = libcfs_ioctl
49873 };
49874
49875 extern int insert_proc(void);
49876diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
49877index 7fbc18e..f982071 100644
49878--- a/drivers/staging/lustre/lustre/llite/dir.c
49879+++ b/drivers/staging/lustre/lustre/llite/dir.c
49880@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
49881 int mode;
49882 int err;
49883
49884- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
49885+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
49886 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
49887 strlen(filename), mode, LUSTRE_OPC_MKDIR,
49888 lump);
49889diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49890index f670469..03b7438 100644
49891--- a/drivers/staging/media/solo6x10/solo6x10-core.c
49892+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49893@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49894
49895 static int solo_sysfs_init(struct solo_dev *solo_dev)
49896 {
49897- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49898+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49899 struct device *dev = &solo_dev->dev;
49900 const char *driver;
49901 int i;
49902diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49903index 74f037b..5b5bb76 100644
49904--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49905+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49906@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49907
49908 int solo_g723_init(struct solo_dev *solo_dev)
49909 {
49910- static struct snd_device_ops ops = { NULL };
49911+ static struct snd_device_ops ops = { };
49912 struct snd_card *card;
49913 struct snd_kcontrol_new kctl;
49914 char name[32];
49915diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49916index 7f2f247..d999137 100644
49917--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49918+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49919@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49920
49921 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49922 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49923- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49924+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49925 if (p2m_id < 0)
49926 p2m_id = -p2m_id;
49927 }
49928diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49929index 8964f8b..36eb087 100644
49930--- a/drivers/staging/media/solo6x10/solo6x10.h
49931+++ b/drivers/staging/media/solo6x10/solo6x10.h
49932@@ -237,7 +237,7 @@ struct solo_dev {
49933
49934 /* P2M DMA Engine */
49935 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49936- atomic_t p2m_count;
49937+ atomic_unchecked_t p2m_count;
49938 int p2m_jiffies;
49939 unsigned int p2m_timeouts;
49940
49941diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49942index a0f4868..139f1fb 100644
49943--- a/drivers/staging/octeon/ethernet-rx.c
49944+++ b/drivers/staging/octeon/ethernet-rx.c
49945@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49946 /* Increment RX stats for virtual ports */
49947 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49948 #ifdef CONFIG_64BIT
49949- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49950- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49951+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49952+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49953 #else
49954- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49955- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49956+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49957+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49958 #endif
49959 }
49960 netif_receive_skb(skb);
49961@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49962 dev->name);
49963 */
49964 #ifdef CONFIG_64BIT
49965- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
49966+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49967 #else
49968- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
49969+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
49970 #endif
49971 dev_kfree_skb_irq(skb);
49972 }
49973diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
49974index ff7214a..6dd90f0 100644
49975--- a/drivers/staging/octeon/ethernet.c
49976+++ b/drivers/staging/octeon/ethernet.c
49977@@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
49978 * since the RX tasklet also increments it.
49979 */
49980 #ifdef CONFIG_64BIT
49981- atomic64_add(rx_status.dropped_packets,
49982- (atomic64_t *)&priv->stats.rx_dropped);
49983+ atomic64_add_unchecked(rx_status.dropped_packets,
49984+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49985 #else
49986- atomic_add(rx_status.dropped_packets,
49987- (atomic_t *)&priv->stats.rx_dropped);
49988+ atomic_add_unchecked(rx_status.dropped_packets,
49989+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
49990 #endif
49991 }
49992
49993diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
49994index c274b34..f84de76 100644
49995--- a/drivers/staging/rtl8188eu/include/hal_intf.h
49996+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
49997@@ -271,7 +271,7 @@ struct hal_ops {
49998 s32 (*c2h_handler)(struct adapter *padapter,
49999 struct c2h_evt_hdr *c2h_evt);
50000 c2h_id_filter c2h_id_filter_ccx;
50001-};
50002+} __no_const;
50003
50004 enum rt_eeprom_type {
50005 EEPROM_93C46,
50006diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50007index e8790f8..b4a5980 100644
50008--- a/drivers/staging/rtl8188eu/include/rtw_io.h
50009+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50010@@ -124,7 +124,7 @@ struct _io_ops {
50011 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50012 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50013 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50014-};
50015+} __no_const;
50016
50017 struct io_req {
50018 struct list_head list;
50019diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50020index dc23395..cf7e9b1 100644
50021--- a/drivers/staging/rtl8712/rtl871x_io.h
50022+++ b/drivers/staging/rtl8712/rtl871x_io.h
50023@@ -108,7 +108,7 @@ struct _io_ops {
50024 u8 *pmem);
50025 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50026 u8 *pmem);
50027-};
50028+} __no_const;
50029
50030 struct io_req {
50031 struct list_head list;
50032diff --git a/drivers/staging/rtl8723au/include/hal_intf.h b/drivers/staging/rtl8723au/include/hal_intf.h
50033index d183f4b..3f4903d 100644
50034--- a/drivers/staging/rtl8723au/include/hal_intf.h
50035+++ b/drivers/staging/rtl8723au/include/hal_intf.h
50036@@ -251,7 +251,7 @@ struct hal_ops {
50037 void (*hal_reset_security_engine)(struct rtw_adapter *adapter);
50038 s32 (*c2h_handler)(struct rtw_adapter *padapter, struct c2h_evt_hdr *c2h_evt);
50039 c2h_id_filter c2h_id_filter_ccx;
50040-};
50041+} __no_const;
50042
50043 enum rt_eeprom_type {
50044 EEPROM_93C46,
50045diff --git a/drivers/staging/rtl8723au/include/rtw_io.h b/drivers/staging/rtl8723au/include/rtw_io.h
50046index 8d39d800..3f21c0c 100644
50047--- a/drivers/staging/rtl8723au/include/rtw_io.h
50048+++ b/drivers/staging/rtl8723au/include/rtw_io.h
50049@@ -130,7 +130,7 @@ struct _io_ops
50050 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50051 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50052
50053-};
50054+} __no_const;
50055
50056 struct io_req {
50057 struct list_head list;
50058diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50059index fe6c951..72935ba 100644
50060--- a/drivers/staging/sbe-2t3e3/netdev.c
50061+++ b/drivers/staging/sbe-2t3e3/netdev.c
50062@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50063 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50064
50065 if (rlen)
50066- if (copy_to_user(data, &resp, rlen))
50067+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50068 return -EFAULT;
50069
50070 return 0;
50071diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50072index a863a98..d272795 100644
50073--- a/drivers/staging/usbip/vhci.h
50074+++ b/drivers/staging/usbip/vhci.h
50075@@ -83,7 +83,7 @@ struct vhci_hcd {
50076 unsigned resuming:1;
50077 unsigned long re_timeout;
50078
50079- atomic_t seqnum;
50080+ atomic_unchecked_t seqnum;
50081
50082 /*
50083 * NOTE:
50084diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50085index 70e1755..de41855 100644
50086--- a/drivers/staging/usbip/vhci_hcd.c
50087+++ b/drivers/staging/usbip/vhci_hcd.c
50088@@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
50089
50090 spin_lock(&vdev->priv_lock);
50091
50092- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50093+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50094 if (priv->seqnum == 0xffff)
50095 dev_info(&urb->dev->dev, "seqnum max\n");
50096
50097@@ -685,7 +685,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50098 return -ENOMEM;
50099 }
50100
50101- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50102+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50103 if (unlink->seqnum == 0xffff)
50104 pr_info("seqnum max\n");
50105
50106@@ -889,7 +889,7 @@ static int vhci_start(struct usb_hcd *hcd)
50107 vdev->rhport = rhport;
50108 }
50109
50110- atomic_set(&vhci->seqnum, 0);
50111+ atomic_set_unchecked(&vhci->seqnum, 0);
50112 spin_lock_init(&vhci->lock);
50113
50114 hcd->power_budget = 0; /* no limit */
50115diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50116index d07fcb5..358e1e1 100644
50117--- a/drivers/staging/usbip/vhci_rx.c
50118+++ b/drivers/staging/usbip/vhci_rx.c
50119@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50120 if (!urb) {
50121 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50122 pr_info("max seqnum %d\n",
50123- atomic_read(&the_controller->seqnum));
50124+ atomic_read_unchecked(&the_controller->seqnum));
50125 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50126 return;
50127 }
50128diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50129index 6eecd53..29317c6 100644
50130--- a/drivers/staging/vt6655/hostap.c
50131+++ b/drivers/staging/vt6655/hostap.c
50132@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50133 *
50134 */
50135
50136+static net_device_ops_no_const apdev_netdev_ops;
50137+
50138 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50139 {
50140 PSDevice apdev_priv;
50141 struct net_device *dev = pDevice->dev;
50142 int ret;
50143- const struct net_device_ops apdev_netdev_ops = {
50144- .ndo_start_xmit = pDevice->tx_80211,
50145- };
50146
50147 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50148
50149@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50150 *apdev_priv = *pDevice;
50151 eth_hw_addr_inherit(pDevice->apdev, dev);
50152
50153+ /* only half broken now */
50154+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50155 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50156
50157 pDevice->apdev->type = ARPHRD_IEEE80211;
50158diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50159index 67ba48b..24e602f 100644
50160--- a/drivers/staging/vt6656/hostap.c
50161+++ b/drivers/staging/vt6656/hostap.c
50162@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50163 *
50164 */
50165
50166+static net_device_ops_no_const apdev_netdev_ops;
50167+
50168 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50169 {
50170 struct vnt_private *apdev_priv;
50171 struct net_device *dev = pDevice->dev;
50172 int ret;
50173- const struct net_device_ops apdev_netdev_ops = {
50174- .ndo_start_xmit = pDevice->tx_80211,
50175- };
50176
50177 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50178
50179@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50180 *apdev_priv = *pDevice;
50181 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50182
50183+ /* only half broken now */
50184+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50185 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50186
50187 pDevice->apdev->type = ARPHRD_IEEE80211;
50188diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50189index e7e9372..161f530 100644
50190--- a/drivers/target/sbp/sbp_target.c
50191+++ b/drivers/target/sbp/sbp_target.c
50192@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50193
50194 #define SESSION_MAINTENANCE_INTERVAL HZ
50195
50196-static atomic_t login_id = ATOMIC_INIT(0);
50197+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50198
50199 static void session_maintenance_work(struct work_struct *);
50200 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50201@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50202 login->lun = se_lun;
50203 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50204 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50205- login->login_id = atomic_inc_return(&login_id);
50206+ login->login_id = atomic_inc_return_unchecked(&login_id);
50207
50208 login->tgt_agt = sbp_target_agent_register(login);
50209 if (IS_ERR(login->tgt_agt)) {
50210diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50211index 26416c1..e796a3d 100644
50212--- a/drivers/target/target_core_device.c
50213+++ b/drivers/target/target_core_device.c
50214@@ -1524,7 +1524,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50215 spin_lock_init(&dev->se_tmr_lock);
50216 spin_lock_init(&dev->qf_cmd_lock);
50217 sema_init(&dev->caw_sem, 1);
50218- atomic_set(&dev->dev_ordered_id, 0);
50219+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50220 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50221 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50222 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50223diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50224index a51dd4e..bcba20e 100644
50225--- a/drivers/target/target_core_transport.c
50226+++ b/drivers/target/target_core_transport.c
50227@@ -1148,7 +1148,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50228 * Used to determine when ORDERED commands should go from
50229 * Dormant to Active status.
50230 */
50231- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50232+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50233 smp_mb__after_atomic_inc();
50234 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50235 cmd->se_ordered_id, cmd->sam_task_attr,
50236diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50237index 04b1be7..5eff86d 100644
50238--- a/drivers/thermal/of-thermal.c
50239+++ b/drivers/thermal/of-thermal.c
50240@@ -30,6 +30,7 @@
50241 #include <linux/err.h>
50242 #include <linux/export.h>
50243 #include <linux/string.h>
50244+#include <linux/mm.h>
50245
50246 #include "thermal_core.h"
50247
50248@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50249 tz->get_trend = get_trend;
50250 tz->sensor_data = data;
50251
50252- tzd->ops->get_temp = of_thermal_get_temp;
50253- tzd->ops->get_trend = of_thermal_get_trend;
50254+ pax_open_kernel();
50255+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50256+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50257+ pax_close_kernel();
50258 mutex_unlock(&tzd->lock);
50259
50260 return tzd;
50261@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50262 return;
50263
50264 mutex_lock(&tzd->lock);
50265- tzd->ops->get_temp = NULL;
50266- tzd->ops->get_trend = NULL;
50267+ pax_open_kernel();
50268+ *(void **)&tzd->ops->get_temp = NULL;
50269+ *(void **)&tzd->ops->get_trend = NULL;
50270+ pax_close_kernel();
50271
50272 tz->get_temp = NULL;
50273 tz->get_trend = NULL;
50274diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50275index a57bb5a..1f727d33 100644
50276--- a/drivers/tty/cyclades.c
50277+++ b/drivers/tty/cyclades.c
50278@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50279 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50280 info->port.count);
50281 #endif
50282- info->port.count++;
50283+ atomic_inc(&info->port.count);
50284 #ifdef CY_DEBUG_COUNT
50285 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50286- current->pid, info->port.count);
50287+ current->pid, atomic_read(&info->port.count));
50288 #endif
50289
50290 /*
50291@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50292 for (j = 0; j < cy_card[i].nports; j++) {
50293 info = &cy_card[i].ports[j];
50294
50295- if (info->port.count) {
50296+ if (atomic_read(&info->port.count)) {
50297 /* XXX is the ldisc num worth this? */
50298 struct tty_struct *tty;
50299 struct tty_ldisc *ld;
50300diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50301index 0ff7fda..dbc7d52 100644
50302--- a/drivers/tty/hvc/hvc_console.c
50303+++ b/drivers/tty/hvc/hvc_console.c
50304@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50305
50306 spin_lock_irqsave(&hp->port.lock, flags);
50307 /* Check and then increment for fast path open. */
50308- if (hp->port.count++ > 0) {
50309+ if (atomic_inc_return(&hp->port.count) > 1) {
50310 spin_unlock_irqrestore(&hp->port.lock, flags);
50311 hvc_kick();
50312 return 0;
50313@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50314
50315 spin_lock_irqsave(&hp->port.lock, flags);
50316
50317- if (--hp->port.count == 0) {
50318+ if (atomic_dec_return(&hp->port.count) == 0) {
50319 spin_unlock_irqrestore(&hp->port.lock, flags);
50320 /* We are done with the tty pointer now. */
50321 tty_port_tty_set(&hp->port, NULL);
50322@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50323 */
50324 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50325 } else {
50326- if (hp->port.count < 0)
50327+ if (atomic_read(&hp->port.count) < 0)
50328 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50329- hp->vtermno, hp->port.count);
50330+ hp->vtermno, atomic_read(&hp->port.count));
50331 spin_unlock_irqrestore(&hp->port.lock, flags);
50332 }
50333 }
50334@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50335 * open->hangup case this can be called after the final close so prevent
50336 * that from happening for now.
50337 */
50338- if (hp->port.count <= 0) {
50339+ if (atomic_read(&hp->port.count) <= 0) {
50340 spin_unlock_irqrestore(&hp->port.lock, flags);
50341 return;
50342 }
50343
50344- hp->port.count = 0;
50345+ atomic_set(&hp->port.count, 0);
50346 spin_unlock_irqrestore(&hp->port.lock, flags);
50347 tty_port_tty_set(&hp->port, NULL);
50348
50349@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50350 return -EPIPE;
50351
50352 /* FIXME what's this (unprotected) check for? */
50353- if (hp->port.count <= 0)
50354+ if (atomic_read(&hp->port.count) <= 0)
50355 return -EIO;
50356
50357 spin_lock_irqsave(&hp->lock, flags);
50358diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50359index 81e939e..95ead10 100644
50360--- a/drivers/tty/hvc/hvcs.c
50361+++ b/drivers/tty/hvc/hvcs.c
50362@@ -83,6 +83,7 @@
50363 #include <asm/hvcserver.h>
50364 #include <asm/uaccess.h>
50365 #include <asm/vio.h>
50366+#include <asm/local.h>
50367
50368 /*
50369 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50370@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50371
50372 spin_lock_irqsave(&hvcsd->lock, flags);
50373
50374- if (hvcsd->port.count > 0) {
50375+ if (atomic_read(&hvcsd->port.count) > 0) {
50376 spin_unlock_irqrestore(&hvcsd->lock, flags);
50377 printk(KERN_INFO "HVCS: vterm state unchanged. "
50378 "The hvcs device node is still in use.\n");
50379@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50380 }
50381 }
50382
50383- hvcsd->port.count = 0;
50384+ atomic_set(&hvcsd->port.count, 0);
50385 hvcsd->port.tty = tty;
50386 tty->driver_data = hvcsd;
50387
50388@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50389 unsigned long flags;
50390
50391 spin_lock_irqsave(&hvcsd->lock, flags);
50392- hvcsd->port.count++;
50393+ atomic_inc(&hvcsd->port.count);
50394 hvcsd->todo_mask |= HVCS_SCHED_READ;
50395 spin_unlock_irqrestore(&hvcsd->lock, flags);
50396
50397@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50398 hvcsd = tty->driver_data;
50399
50400 spin_lock_irqsave(&hvcsd->lock, flags);
50401- if (--hvcsd->port.count == 0) {
50402+ if (atomic_dec_and_test(&hvcsd->port.count)) {
50403
50404 vio_disable_interrupts(hvcsd->vdev);
50405
50406@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50407
50408 free_irq(irq, hvcsd);
50409 return;
50410- } else if (hvcsd->port.count < 0) {
50411+ } else if (atomic_read(&hvcsd->port.count) < 0) {
50412 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50413 " is missmanaged.\n",
50414- hvcsd->vdev->unit_address, hvcsd->port.count);
50415+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50416 }
50417
50418 spin_unlock_irqrestore(&hvcsd->lock, flags);
50419@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50420
50421 spin_lock_irqsave(&hvcsd->lock, flags);
50422 /* Preserve this so that we know how many kref refs to put */
50423- temp_open_count = hvcsd->port.count;
50424+ temp_open_count = atomic_read(&hvcsd->port.count);
50425
50426 /*
50427 * Don't kref put inside the spinlock because the destruction
50428@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50429 tty->driver_data = NULL;
50430 hvcsd->port.tty = NULL;
50431
50432- hvcsd->port.count = 0;
50433+ atomic_set(&hvcsd->port.count, 0);
50434
50435 /* This will drop any buffered data on the floor which is OK in a hangup
50436 * scenario. */
50437@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50438 * the middle of a write operation? This is a crummy place to do this
50439 * but we want to keep it all in the spinlock.
50440 */
50441- if (hvcsd->port.count <= 0) {
50442+ if (atomic_read(&hvcsd->port.count) <= 0) {
50443 spin_unlock_irqrestore(&hvcsd->lock, flags);
50444 return -ENODEV;
50445 }
50446@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50447 {
50448 struct hvcs_struct *hvcsd = tty->driver_data;
50449
50450- if (!hvcsd || hvcsd->port.count <= 0)
50451+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50452 return 0;
50453
50454 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50455diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50456index 4190199..06d5bfa 100644
50457--- a/drivers/tty/hvc/hvsi.c
50458+++ b/drivers/tty/hvc/hvsi.c
50459@@ -85,7 +85,7 @@ struct hvsi_struct {
50460 int n_outbuf;
50461 uint32_t vtermno;
50462 uint32_t virq;
50463- atomic_t seqno; /* HVSI packet sequence number */
50464+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
50465 uint16_t mctrl;
50466 uint8_t state; /* HVSI protocol state */
50467 uint8_t flags;
50468@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50469
50470 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50471 packet.hdr.len = sizeof(struct hvsi_query_response);
50472- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50473+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50474 packet.verb = VSV_SEND_VERSION_NUMBER;
50475 packet.u.version = HVSI_VERSION;
50476 packet.query_seqno = query_seqno+1;
50477@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50478
50479 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50480 packet.hdr.len = sizeof(struct hvsi_query);
50481- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50482+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50483 packet.verb = verb;
50484
50485 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50486@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50487 int wrote;
50488
50489 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50490- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50491+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50492 packet.hdr.len = sizeof(struct hvsi_control);
50493 packet.verb = VSV_SET_MODEM_CTL;
50494 packet.mask = HVSI_TSDTR;
50495@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50496 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50497
50498 packet.hdr.type = VS_DATA_PACKET_HEADER;
50499- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50500+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50501 packet.hdr.len = count + sizeof(struct hvsi_header);
50502 memcpy(&packet.data, buf, count);
50503
50504@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50505 struct hvsi_control packet __ALIGNED__;
50506
50507 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50508- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50509+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50510 packet.hdr.len = 6;
50511 packet.verb = VSV_CLOSE_PROTOCOL;
50512
50513@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50514
50515 tty_port_tty_set(&hp->port, tty);
50516 spin_lock_irqsave(&hp->lock, flags);
50517- hp->port.count++;
50518+ atomic_inc(&hp->port.count);
50519 atomic_set(&hp->seqno, 0);
50520 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50521 spin_unlock_irqrestore(&hp->lock, flags);
50522@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50523
50524 spin_lock_irqsave(&hp->lock, flags);
50525
50526- if (--hp->port.count == 0) {
50527+ if (atomic_dec_return(&hp->port.count) == 0) {
50528 tty_port_tty_set(&hp->port, NULL);
50529 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50530
50531@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50532
50533 spin_lock_irqsave(&hp->lock, flags);
50534 }
50535- } else if (hp->port.count < 0)
50536+ } else if (atomic_read(&hp->port.count) < 0)
50537 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50538- hp - hvsi_ports, hp->port.count);
50539+ hp - hvsi_ports, atomic_read(&hp->port.count));
50540
50541 spin_unlock_irqrestore(&hp->lock, flags);
50542 }
50543@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50544 tty_port_tty_set(&hp->port, NULL);
50545
50546 spin_lock_irqsave(&hp->lock, flags);
50547- hp->port.count = 0;
50548+ atomic_set(&hp->port.count, 0);
50549 hp->n_outbuf = 0;
50550 spin_unlock_irqrestore(&hp->lock, flags);
50551 }
50552diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50553index 7ae6c29..05c6dba 100644
50554--- a/drivers/tty/hvc/hvsi_lib.c
50555+++ b/drivers/tty/hvc/hvsi_lib.c
50556@@ -8,7 +8,7 @@
50557
50558 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50559 {
50560- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50561+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50562
50563 /* Assumes that always succeeds, works in practice */
50564 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50565@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50566
50567 /* Reset state */
50568 pv->established = 0;
50569- atomic_set(&pv->seqno, 0);
50570+ atomic_set_unchecked(&pv->seqno, 0);
50571
50572 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50573
50574diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50575index 17ee3bf..8d2520d 100644
50576--- a/drivers/tty/ipwireless/tty.c
50577+++ b/drivers/tty/ipwireless/tty.c
50578@@ -28,6 +28,7 @@
50579 #include <linux/tty_driver.h>
50580 #include <linux/tty_flip.h>
50581 #include <linux/uaccess.h>
50582+#include <asm/local.h>
50583
50584 #include "tty.h"
50585 #include "network.h"
50586@@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50587 mutex_unlock(&tty->ipw_tty_mutex);
50588 return -ENODEV;
50589 }
50590- if (tty->port.count == 0)
50591+ if (atomic_read(&tty->port.count) == 0)
50592 tty->tx_bytes_queued = 0;
50593
50594- tty->port.count++;
50595+ atomic_inc(&tty->port.count);
50596
50597 tty->port.tty = linux_tty;
50598 linux_tty->driver_data = tty;
50599@@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50600
50601 static void do_ipw_close(struct ipw_tty *tty)
50602 {
50603- tty->port.count--;
50604-
50605- if (tty->port.count == 0) {
50606+ if (atomic_dec_return(&tty->port.count) == 0) {
50607 struct tty_struct *linux_tty = tty->port.tty;
50608
50609 if (linux_tty != NULL) {
50610@@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50611 return;
50612
50613 mutex_lock(&tty->ipw_tty_mutex);
50614- if (tty->port.count == 0) {
50615+ if (atomic_read(&tty->port.count) == 0) {
50616 mutex_unlock(&tty->ipw_tty_mutex);
50617 return;
50618 }
50619@@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50620
50621 mutex_lock(&tty->ipw_tty_mutex);
50622
50623- if (!tty->port.count) {
50624+ if (!atomic_read(&tty->port.count)) {
50625 mutex_unlock(&tty->ipw_tty_mutex);
50626 return;
50627 }
50628@@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50629 return -ENODEV;
50630
50631 mutex_lock(&tty->ipw_tty_mutex);
50632- if (!tty->port.count) {
50633+ if (!atomic_read(&tty->port.count)) {
50634 mutex_unlock(&tty->ipw_tty_mutex);
50635 return -EINVAL;
50636 }
50637@@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50638 if (!tty)
50639 return -ENODEV;
50640
50641- if (!tty->port.count)
50642+ if (!atomic_read(&tty->port.count))
50643 return -EINVAL;
50644
50645 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50646@@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50647 if (!tty)
50648 return 0;
50649
50650- if (!tty->port.count)
50651+ if (!atomic_read(&tty->port.count))
50652 return 0;
50653
50654 return tty->tx_bytes_queued;
50655@@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50656 if (!tty)
50657 return -ENODEV;
50658
50659- if (!tty->port.count)
50660+ if (!atomic_read(&tty->port.count))
50661 return -EINVAL;
50662
50663 return get_control_lines(tty);
50664@@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50665 if (!tty)
50666 return -ENODEV;
50667
50668- if (!tty->port.count)
50669+ if (!atomic_read(&tty->port.count))
50670 return -EINVAL;
50671
50672 return set_control_lines(tty, set, clear);
50673@@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50674 if (!tty)
50675 return -ENODEV;
50676
50677- if (!tty->port.count)
50678+ if (!atomic_read(&tty->port.count))
50679 return -EINVAL;
50680
50681 /* FIXME: Exactly how is the tty object locked here .. */
50682@@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50683 * are gone */
50684 mutex_lock(&ttyj->ipw_tty_mutex);
50685 }
50686- while (ttyj->port.count)
50687+ while (atomic_read(&ttyj->port.count))
50688 do_ipw_close(ttyj);
50689 ipwireless_disassociate_network_ttys(network,
50690 ttyj->channel_idx);
50691diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50692index 1deaca4..c8582d4 100644
50693--- a/drivers/tty/moxa.c
50694+++ b/drivers/tty/moxa.c
50695@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50696 }
50697
50698 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50699- ch->port.count++;
50700+ atomic_inc(&ch->port.count);
50701 tty->driver_data = ch;
50702 tty_port_tty_set(&ch->port, tty);
50703 mutex_lock(&ch->port.mutex);
50704diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50705index 2ebe47b..3205833 100644
50706--- a/drivers/tty/n_gsm.c
50707+++ b/drivers/tty/n_gsm.c
50708@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50709 spin_lock_init(&dlci->lock);
50710 mutex_init(&dlci->mutex);
50711 dlci->fifo = &dlci->_fifo;
50712- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50713+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50714 kfree(dlci);
50715 return NULL;
50716 }
50717@@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50718 struct gsm_dlci *dlci = tty->driver_data;
50719 struct tty_port *port = &dlci->port;
50720
50721- port->count++;
50722+ atomic_inc(&port->count);
50723 tty_port_tty_set(port, tty);
50724
50725 dlci->modem_rx = 0;
50726diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50727index fe9d129..477300f 100644
50728--- a/drivers/tty/n_tty.c
50729+++ b/drivers/tty/n_tty.c
50730@@ -115,7 +115,7 @@ struct n_tty_data {
50731 int minimum_to_wake;
50732
50733 /* consumer-published */
50734- size_t read_tail;
50735+ size_t read_tail __intentional_overflow(-1);
50736 size_t line_start;
50737
50738 /* protected by output lock */
50739@@ -2516,6 +2516,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50740 {
50741 *ops = tty_ldisc_N_TTY;
50742 ops->owner = NULL;
50743- ops->refcount = ops->flags = 0;
50744+ atomic_set(&ops->refcount, 0);
50745+ ops->flags = 0;
50746 }
50747 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50748diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50749index 25c9bc7..24077b7 100644
50750--- a/drivers/tty/pty.c
50751+++ b/drivers/tty/pty.c
50752@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50753 panic("Couldn't register Unix98 pts driver");
50754
50755 /* Now create the /dev/ptmx special device */
50756+ pax_open_kernel();
50757 tty_default_fops(&ptmx_fops);
50758- ptmx_fops.open = ptmx_open;
50759+ *(void **)&ptmx_fops.open = ptmx_open;
50760+ pax_close_kernel();
50761
50762 cdev_init(&ptmx_cdev, &ptmx_fops);
50763 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50764diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50765index 383c4c7..d408e21 100644
50766--- a/drivers/tty/rocket.c
50767+++ b/drivers/tty/rocket.c
50768@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50769 tty->driver_data = info;
50770 tty_port_tty_set(port, tty);
50771
50772- if (port->count++ == 0) {
50773+ if (atomic_inc_return(&port->count) == 1) {
50774 atomic_inc(&rp_num_ports_open);
50775
50776 #ifdef ROCKET_DEBUG_OPEN
50777@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50778 #endif
50779 }
50780 #ifdef ROCKET_DEBUG_OPEN
50781- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50782+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50783 #endif
50784
50785 /*
50786@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50787 spin_unlock_irqrestore(&info->port.lock, flags);
50788 return;
50789 }
50790- if (info->port.count)
50791+ if (atomic_read(&info->port.count))
50792 atomic_dec(&rp_num_ports_open);
50793 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50794 spin_unlock_irqrestore(&info->port.lock, flags);
50795diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50796index 1274499..f541382 100644
50797--- a/drivers/tty/serial/ioc4_serial.c
50798+++ b/drivers/tty/serial/ioc4_serial.c
50799@@ -437,7 +437,7 @@ struct ioc4_soft {
50800 } is_intr_info[MAX_IOC4_INTR_ENTS];
50801
50802 /* Number of entries active in the above array */
50803- atomic_t is_num_intrs;
50804+ atomic_unchecked_t is_num_intrs;
50805 } is_intr_type[IOC4_NUM_INTR_TYPES];
50806
50807 /* is_ir_lock must be held while
50808@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50809 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50810 || (type == IOC4_OTHER_INTR_TYPE)));
50811
50812- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50813+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50814 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50815
50816 /* Save off the lower level interrupt handler */
50817@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50818
50819 soft = arg;
50820 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50821- num_intrs = (int)atomic_read(
50822+ num_intrs = (int)atomic_read_unchecked(
50823 &soft->is_intr_type[intr_type].is_num_intrs);
50824
50825 this_mir = this_ir = pending_intrs(soft, intr_type);
50826diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50827index a260cde..6b2b5ce 100644
50828--- a/drivers/tty/serial/kgdboc.c
50829+++ b/drivers/tty/serial/kgdboc.c
50830@@ -24,8 +24,9 @@
50831 #define MAX_CONFIG_LEN 40
50832
50833 static struct kgdb_io kgdboc_io_ops;
50834+static struct kgdb_io kgdboc_io_ops_console;
50835
50836-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50837+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50838 static int configured = -1;
50839
50840 static char config[MAX_CONFIG_LEN];
50841@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50842 kgdboc_unregister_kbd();
50843 if (configured == 1)
50844 kgdb_unregister_io_module(&kgdboc_io_ops);
50845+ else if (configured == 2)
50846+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
50847 }
50848
50849 static int configure_kgdboc(void)
50850@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50851 int err;
50852 char *cptr = config;
50853 struct console *cons;
50854+ int is_console = 0;
50855
50856 err = kgdboc_option_setup(config);
50857 if (err || !strlen(config) || isspace(config[0]))
50858 goto noconfig;
50859
50860 err = -ENODEV;
50861- kgdboc_io_ops.is_console = 0;
50862 kgdb_tty_driver = NULL;
50863
50864 kgdboc_use_kms = 0;
50865@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50866 int idx;
50867 if (cons->device && cons->device(cons, &idx) == p &&
50868 idx == tty_line) {
50869- kgdboc_io_ops.is_console = 1;
50870+ is_console = 1;
50871 break;
50872 }
50873 cons = cons->next;
50874@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50875 kgdb_tty_line = tty_line;
50876
50877 do_register:
50878- err = kgdb_register_io_module(&kgdboc_io_ops);
50879+ if (is_console) {
50880+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
50881+ configured = 2;
50882+ } else {
50883+ err = kgdb_register_io_module(&kgdboc_io_ops);
50884+ configured = 1;
50885+ }
50886 if (err)
50887 goto noconfig;
50888
50889@@ -205,8 +214,6 @@ do_register:
50890 if (err)
50891 goto nmi_con_failed;
50892
50893- configured = 1;
50894-
50895 return 0;
50896
50897 nmi_con_failed:
50898@@ -223,7 +230,7 @@ noconfig:
50899 static int __init init_kgdboc(void)
50900 {
50901 /* Already configured? */
50902- if (configured == 1)
50903+ if (configured >= 1)
50904 return 0;
50905
50906 return configure_kgdboc();
50907@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50908 if (config[len - 1] == '\n')
50909 config[len - 1] = '\0';
50910
50911- if (configured == 1)
50912+ if (configured >= 1)
50913 cleanup_kgdboc();
50914
50915 /* Go and configure with the new params. */
50916@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50917 .post_exception = kgdboc_post_exp_handler,
50918 };
50919
50920+static struct kgdb_io kgdboc_io_ops_console = {
50921+ .name = "kgdboc",
50922+ .read_char = kgdboc_get_char,
50923+ .write_char = kgdboc_put_char,
50924+ .pre_exception = kgdboc_pre_exp_handler,
50925+ .post_exception = kgdboc_post_exp_handler,
50926+ .is_console = 1
50927+};
50928+
50929 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50930 /* This is only available if kgdboc is a built in for early debugging */
50931 static int __init kgdboc_early_init(char *opt)
50932diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50933index 053b98e..86742e5 100644
50934--- a/drivers/tty/serial/msm_serial.c
50935+++ b/drivers/tty/serial/msm_serial.c
50936@@ -1026,7 +1026,7 @@ static struct uart_driver msm_uart_driver = {
50937 .cons = MSM_CONSOLE,
50938 };
50939
50940-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
50941+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
50942
50943 static const struct of_device_id msm_uartdm_table[] = {
50944 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
50945@@ -1045,7 +1045,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
50946 int irq;
50947
50948 if (pdev->id == -1)
50949- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
50950+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
50951
50952 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
50953 return -ENXIO;
50954diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
50955index 1f5505e..a1a767d 100644
50956--- a/drivers/tty/serial/samsung.c
50957+++ b/drivers/tty/serial/samsung.c
50958@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
50959 }
50960 }
50961
50962+static int s3c64xx_serial_startup(struct uart_port *port);
50963 static int s3c24xx_serial_startup(struct uart_port *port)
50964 {
50965 struct s3c24xx_uart_port *ourport = to_ourport(port);
50966 int ret;
50967
50968+ /* Startup sequence is different for s3c64xx and higher SoC's */
50969+ if (s3c24xx_serial_has_interrupt_mask(port))
50970+ return s3c64xx_serial_startup(port);
50971+
50972 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
50973 port->mapbase, port->membase);
50974
50975@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
50976 /* setup info for port */
50977 port->dev = &platdev->dev;
50978
50979- /* Startup sequence is different for s3c64xx and higher SoC's */
50980- if (s3c24xx_serial_has_interrupt_mask(port))
50981- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
50982-
50983 port->uartclk = 1;
50984
50985 if (cfg->uart_flags & UPF_CONS_FLOW) {
50986diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
50987index b68550d..a62d7f8 100644
50988--- a/drivers/tty/serial/serial_core.c
50989+++ b/drivers/tty/serial/serial_core.c
50990@@ -1329,7 +1329,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
50991
50992 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
50993
50994- if (!port->count || tty_port_close_start(port, tty, filp) == 0)
50995+ if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
50996 return;
50997
50998 /*
50999@@ -1456,7 +1456,7 @@ static void uart_hangup(struct tty_struct *tty)
51000 uart_flush_buffer(tty);
51001 uart_shutdown(tty, state);
51002 spin_lock_irqsave(&port->lock, flags);
51003- port->count = 0;
51004+ atomic_set(&port->count, 0);
51005 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51006 spin_unlock_irqrestore(&port->lock, flags);
51007 tty_port_tty_set(port, NULL);
51008@@ -1554,7 +1554,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51009 goto end;
51010 }
51011
51012- port->count++;
51013+ atomic_inc(&port->count);
51014 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51015 retval = -ENXIO;
51016 goto err_dec_count;
51017@@ -1594,7 +1594,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51018 end:
51019 return retval;
51020 err_dec_count:
51021- port->count--;
51022+ atomic_inc(&port->count);
51023 mutex_unlock(&port->mutex);
51024 goto end;
51025 }
51026diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51027index d48e040..0f52764 100644
51028--- a/drivers/tty/synclink.c
51029+++ b/drivers/tty/synclink.c
51030@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51031
51032 if (debug_level >= DEBUG_LEVEL_INFO)
51033 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51034- __FILE__,__LINE__, info->device_name, info->port.count);
51035+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51036
51037 if (tty_port_close_start(&info->port, tty, filp) == 0)
51038 goto cleanup;
51039@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51040 cleanup:
51041 if (debug_level >= DEBUG_LEVEL_INFO)
51042 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51043- tty->driver->name, info->port.count);
51044+ tty->driver->name, atomic_read(&info->port.count));
51045
51046 } /* end of mgsl_close() */
51047
51048@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51049
51050 mgsl_flush_buffer(tty);
51051 shutdown(info);
51052-
51053- info->port.count = 0;
51054+
51055+ atomic_set(&info->port.count, 0);
51056 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51057 info->port.tty = NULL;
51058
51059@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51060
51061 if (debug_level >= DEBUG_LEVEL_INFO)
51062 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51063- __FILE__,__LINE__, tty->driver->name, port->count );
51064+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51065
51066 spin_lock_irqsave(&info->irq_spinlock, flags);
51067 if (!tty_hung_up_p(filp)) {
51068 extra_count = true;
51069- port->count--;
51070+ atomic_dec(&port->count);
51071 }
51072 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51073 port->blocked_open++;
51074@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51075
51076 if (debug_level >= DEBUG_LEVEL_INFO)
51077 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51078- __FILE__,__LINE__, tty->driver->name, port->count );
51079+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51080
51081 tty_unlock(tty);
51082 schedule();
51083@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51084
51085 /* FIXME: Racy on hangup during close wait */
51086 if (extra_count)
51087- port->count++;
51088+ atomic_inc(&port->count);
51089 port->blocked_open--;
51090
51091 if (debug_level >= DEBUG_LEVEL_INFO)
51092 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51093- __FILE__,__LINE__, tty->driver->name, port->count );
51094+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51095
51096 if (!retval)
51097 port->flags |= ASYNC_NORMAL_ACTIVE;
51098@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51099
51100 if (debug_level >= DEBUG_LEVEL_INFO)
51101 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51102- __FILE__,__LINE__,tty->driver->name, info->port.count);
51103+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51104
51105 /* If port is closing, signal caller to try again */
51106 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51107@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51108 spin_unlock_irqrestore(&info->netlock, flags);
51109 goto cleanup;
51110 }
51111- info->port.count++;
51112+ atomic_inc(&info->port.count);
51113 spin_unlock_irqrestore(&info->netlock, flags);
51114
51115- if (info->port.count == 1) {
51116+ if (atomic_read(&info->port.count) == 1) {
51117 /* 1st open on this device, init hardware */
51118 retval = startup(info);
51119 if (retval < 0)
51120@@ -3446,8 +3446,8 @@ cleanup:
51121 if (retval) {
51122 if (tty->count == 1)
51123 info->port.tty = NULL; /* tty layer will release tty struct */
51124- if(info->port.count)
51125- info->port.count--;
51126+ if (atomic_read(&info->port.count))
51127+ atomic_dec(&info->port.count);
51128 }
51129
51130 return retval;
51131@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51132 unsigned short new_crctype;
51133
51134 /* return error if TTY interface open */
51135- if (info->port.count)
51136+ if (atomic_read(&info->port.count))
51137 return -EBUSY;
51138
51139 switch (encoding)
51140@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51141
51142 /* arbitrate between network and tty opens */
51143 spin_lock_irqsave(&info->netlock, flags);
51144- if (info->port.count != 0 || info->netcount != 0) {
51145+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51146 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51147 spin_unlock_irqrestore(&info->netlock, flags);
51148 return -EBUSY;
51149@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51150 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51151
51152 /* return error if TTY interface open */
51153- if (info->port.count)
51154+ if (atomic_read(&info->port.count))
51155 return -EBUSY;
51156
51157 if (cmd != SIOCWANDEV)
51158diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51159index c359a91..959fc26 100644
51160--- a/drivers/tty/synclink_gt.c
51161+++ b/drivers/tty/synclink_gt.c
51162@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51163 tty->driver_data = info;
51164 info->port.tty = tty;
51165
51166- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51167+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51168
51169 /* If port is closing, signal caller to try again */
51170 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51171@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51172 mutex_unlock(&info->port.mutex);
51173 goto cleanup;
51174 }
51175- info->port.count++;
51176+ atomic_inc(&info->port.count);
51177 spin_unlock_irqrestore(&info->netlock, flags);
51178
51179- if (info->port.count == 1) {
51180+ if (atomic_read(&info->port.count) == 1) {
51181 /* 1st open on this device, init hardware */
51182 retval = startup(info);
51183 if (retval < 0) {
51184@@ -715,8 +715,8 @@ cleanup:
51185 if (retval) {
51186 if (tty->count == 1)
51187 info->port.tty = NULL; /* tty layer will release tty struct */
51188- if(info->port.count)
51189- info->port.count--;
51190+ if(atomic_read(&info->port.count))
51191+ atomic_dec(&info->port.count);
51192 }
51193
51194 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51195@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51196
51197 if (sanity_check(info, tty->name, "close"))
51198 return;
51199- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51200+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51201
51202 if (tty_port_close_start(&info->port, tty, filp) == 0)
51203 goto cleanup;
51204@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51205 tty_port_close_end(&info->port, tty);
51206 info->port.tty = NULL;
51207 cleanup:
51208- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51209+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51210 }
51211
51212 static void hangup(struct tty_struct *tty)
51213@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51214 shutdown(info);
51215
51216 spin_lock_irqsave(&info->port.lock, flags);
51217- info->port.count = 0;
51218+ atomic_set(&info->port.count, 0);
51219 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51220 info->port.tty = NULL;
51221 spin_unlock_irqrestore(&info->port.lock, flags);
51222@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51223 unsigned short new_crctype;
51224
51225 /* return error if TTY interface open */
51226- if (info->port.count)
51227+ if (atomic_read(&info->port.count))
51228 return -EBUSY;
51229
51230 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51231@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51232
51233 /* arbitrate between network and tty opens */
51234 spin_lock_irqsave(&info->netlock, flags);
51235- if (info->port.count != 0 || info->netcount != 0) {
51236+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51237 DBGINFO(("%s hdlc_open busy\n", dev->name));
51238 spin_unlock_irqrestore(&info->netlock, flags);
51239 return -EBUSY;
51240@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51241 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51242
51243 /* return error if TTY interface open */
51244- if (info->port.count)
51245+ if (atomic_read(&info->port.count))
51246 return -EBUSY;
51247
51248 if (cmd != SIOCWANDEV)
51249@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51250 if (port == NULL)
51251 continue;
51252 spin_lock(&port->lock);
51253- if ((port->port.count || port->netcount) &&
51254+ if ((atomic_read(&port->port.count) || port->netcount) &&
51255 port->pending_bh && !port->bh_running &&
51256 !port->bh_requested) {
51257 DBGISR(("%s bh queued\n", port->device_name));
51258@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51259 spin_lock_irqsave(&info->lock, flags);
51260 if (!tty_hung_up_p(filp)) {
51261 extra_count = true;
51262- port->count--;
51263+ atomic_dec(&port->count);
51264 }
51265 spin_unlock_irqrestore(&info->lock, flags);
51266 port->blocked_open++;
51267@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51268 remove_wait_queue(&port->open_wait, &wait);
51269
51270 if (extra_count)
51271- port->count++;
51272+ atomic_inc(&port->count);
51273 port->blocked_open--;
51274
51275 if (!retval)
51276diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51277index 53ba853..3c30f6d 100644
51278--- a/drivers/tty/synclinkmp.c
51279+++ b/drivers/tty/synclinkmp.c
51280@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51281
51282 if (debug_level >= DEBUG_LEVEL_INFO)
51283 printk("%s(%d):%s open(), old ref count = %d\n",
51284- __FILE__,__LINE__,tty->driver->name, info->port.count);
51285+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51286
51287 /* If port is closing, signal caller to try again */
51288 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51289@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51290 spin_unlock_irqrestore(&info->netlock, flags);
51291 goto cleanup;
51292 }
51293- info->port.count++;
51294+ atomic_inc(&info->port.count);
51295 spin_unlock_irqrestore(&info->netlock, flags);
51296
51297- if (info->port.count == 1) {
51298+ if (atomic_read(&info->port.count) == 1) {
51299 /* 1st open on this device, init hardware */
51300 retval = startup(info);
51301 if (retval < 0)
51302@@ -796,8 +796,8 @@ cleanup:
51303 if (retval) {
51304 if (tty->count == 1)
51305 info->port.tty = NULL; /* tty layer will release tty struct */
51306- if(info->port.count)
51307- info->port.count--;
51308+ if(atomic_read(&info->port.count))
51309+ atomic_dec(&info->port.count);
51310 }
51311
51312 return retval;
51313@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51314
51315 if (debug_level >= DEBUG_LEVEL_INFO)
51316 printk("%s(%d):%s close() entry, count=%d\n",
51317- __FILE__,__LINE__, info->device_name, info->port.count);
51318+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51319
51320 if (tty_port_close_start(&info->port, tty, filp) == 0)
51321 goto cleanup;
51322@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51323 cleanup:
51324 if (debug_level >= DEBUG_LEVEL_INFO)
51325 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51326- tty->driver->name, info->port.count);
51327+ tty->driver->name, atomic_read(&info->port.count));
51328 }
51329
51330 /* Called by tty_hangup() when a hangup is signaled.
51331@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51332 shutdown(info);
51333
51334 spin_lock_irqsave(&info->port.lock, flags);
51335- info->port.count = 0;
51336+ atomic_set(&info->port.count, 0);
51337 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51338 info->port.tty = NULL;
51339 spin_unlock_irqrestore(&info->port.lock, flags);
51340@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51341 unsigned short new_crctype;
51342
51343 /* return error if TTY interface open */
51344- if (info->port.count)
51345+ if (atomic_read(&info->port.count))
51346 return -EBUSY;
51347
51348 switch (encoding)
51349@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51350
51351 /* arbitrate between network and tty opens */
51352 spin_lock_irqsave(&info->netlock, flags);
51353- if (info->port.count != 0 || info->netcount != 0) {
51354+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51355 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51356 spin_unlock_irqrestore(&info->netlock, flags);
51357 return -EBUSY;
51358@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51359 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51360
51361 /* return error if TTY interface open */
51362- if (info->port.count)
51363+ if (atomic_read(&info->port.count))
51364 return -EBUSY;
51365
51366 if (cmd != SIOCWANDEV)
51367@@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51368 * do not request bottom half processing if the
51369 * device is not open in a normal mode.
51370 */
51371- if ( port && (port->port.count || port->netcount) &&
51372+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51373 port->pending_bh && !port->bh_running &&
51374 !port->bh_requested ) {
51375 if ( debug_level >= DEBUG_LEVEL_ISR )
51376@@ -3319,12 +3319,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51377
51378 if (debug_level >= DEBUG_LEVEL_INFO)
51379 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51380- __FILE__,__LINE__, tty->driver->name, port->count );
51381+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51382
51383 spin_lock_irqsave(&info->lock, flags);
51384 if (!tty_hung_up_p(filp)) {
51385 extra_count = true;
51386- port->count--;
51387+ atomic_dec(&port->count);
51388 }
51389 spin_unlock_irqrestore(&info->lock, flags);
51390 port->blocked_open++;
51391@@ -3353,7 +3353,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51392
51393 if (debug_level >= DEBUG_LEVEL_INFO)
51394 printk("%s(%d):%s block_til_ready() count=%d\n",
51395- __FILE__,__LINE__, tty->driver->name, port->count );
51396+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51397
51398 tty_unlock(tty);
51399 schedule();
51400@@ -3364,12 +3364,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51401 remove_wait_queue(&port->open_wait, &wait);
51402
51403 if (extra_count)
51404- port->count++;
51405+ atomic_inc(&port->count);
51406 port->blocked_open--;
51407
51408 if (debug_level >= DEBUG_LEVEL_INFO)
51409 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51410- __FILE__,__LINE__, tty->driver->name, port->count );
51411+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51412
51413 if (!retval)
51414 port->flags |= ASYNC_NORMAL_ACTIVE;
51415diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51416index ce396ec..04a37be 100644
51417--- a/drivers/tty/sysrq.c
51418+++ b/drivers/tty/sysrq.c
51419@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51420 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51421 size_t count, loff_t *ppos)
51422 {
51423- if (count) {
51424+ if (count && capable(CAP_SYS_ADMIN)) {
51425 char c;
51426
51427 if (get_user(c, buf))
51428diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51429index 3411071..86f2cf2 100644
51430--- a/drivers/tty/tty_io.c
51431+++ b/drivers/tty/tty_io.c
51432@@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51433
51434 void tty_default_fops(struct file_operations *fops)
51435 {
51436- *fops = tty_fops;
51437+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51438 }
51439
51440 /*
51441diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51442index 2d822aa..a566234 100644
51443--- a/drivers/tty/tty_ldisc.c
51444+++ b/drivers/tty/tty_ldisc.c
51445@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51446 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51447 tty_ldiscs[disc] = new_ldisc;
51448 new_ldisc->num = disc;
51449- new_ldisc->refcount = 0;
51450+ atomic_set(&new_ldisc->refcount, 0);
51451 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51452
51453 return ret;
51454@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51455 return -EINVAL;
51456
51457 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51458- if (tty_ldiscs[disc]->refcount)
51459+ if (atomic_read(&tty_ldiscs[disc]->refcount))
51460 ret = -EBUSY;
51461 else
51462 tty_ldiscs[disc] = NULL;
51463@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51464 if (ldops) {
51465 ret = ERR_PTR(-EAGAIN);
51466 if (try_module_get(ldops->owner)) {
51467- ldops->refcount++;
51468+ atomic_inc(&ldops->refcount);
51469 ret = ldops;
51470 }
51471 }
51472@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51473 unsigned long flags;
51474
51475 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51476- ldops->refcount--;
51477+ atomic_dec(&ldops->refcount);
51478 module_put(ldops->owner);
51479 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51480 }
51481diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51482index 3f746c8..2f2fcaa 100644
51483--- a/drivers/tty/tty_port.c
51484+++ b/drivers/tty/tty_port.c
51485@@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51486 unsigned long flags;
51487
51488 spin_lock_irqsave(&port->lock, flags);
51489- port->count = 0;
51490+ atomic_set(&port->count, 0);
51491 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51492 tty = port->tty;
51493 if (tty)
51494@@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51495 /* The port lock protects the port counts */
51496 spin_lock_irqsave(&port->lock, flags);
51497 if (!tty_hung_up_p(filp))
51498- port->count--;
51499+ atomic_dec(&port->count);
51500 port->blocked_open++;
51501 spin_unlock_irqrestore(&port->lock, flags);
51502
51503@@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51504 we must not mess that up further */
51505 spin_lock_irqsave(&port->lock, flags);
51506 if (!tty_hung_up_p(filp))
51507- port->count++;
51508+ atomic_inc(&port->count);
51509 port->blocked_open--;
51510 if (retval == 0)
51511 port->flags |= ASYNC_NORMAL_ACTIVE;
51512@@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51513 return 0;
51514 }
51515
51516- if (tty->count == 1 && port->count != 1) {
51517+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
51518 printk(KERN_WARNING
51519 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51520- port->count);
51521- port->count = 1;
51522+ atomic_read(&port->count));
51523+ atomic_set(&port->count, 1);
51524 }
51525- if (--port->count < 0) {
51526+ if (atomic_dec_return(&port->count) < 0) {
51527 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51528- port->count);
51529- port->count = 0;
51530+ atomic_read(&port->count));
51531+ atomic_set(&port->count, 0);
51532 }
51533
51534- if (port->count) {
51535+ if (atomic_read(&port->count)) {
51536 spin_unlock_irqrestore(&port->lock, flags);
51537 return 0;
51538 }
51539@@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51540 {
51541 spin_lock_irq(&port->lock);
51542 if (!tty_hung_up_p(filp))
51543- ++port->count;
51544+ atomic_inc(&port->count);
51545 spin_unlock_irq(&port->lock);
51546 tty_port_tty_set(port, tty);
51547
51548diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51549index d0e3a44..5f8b754 100644
51550--- a/drivers/tty/vt/keyboard.c
51551+++ b/drivers/tty/vt/keyboard.c
51552@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51553 kbd->kbdmode == VC_OFF) &&
51554 value != KVAL(K_SAK))
51555 return; /* SAK is allowed even in raw mode */
51556+
51557+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51558+ {
51559+ void *func = fn_handler[value];
51560+ if (func == fn_show_state || func == fn_show_ptregs ||
51561+ func == fn_show_mem)
51562+ return;
51563+ }
51564+#endif
51565+
51566 fn_handler[value](vc);
51567 }
51568
51569@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51570 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51571 return -EFAULT;
51572
51573- if (!capable(CAP_SYS_TTY_CONFIG))
51574- perm = 0;
51575-
51576 switch (cmd) {
51577 case KDGKBENT:
51578 /* Ensure another thread doesn't free it under us */
51579@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51580 spin_unlock_irqrestore(&kbd_event_lock, flags);
51581 return put_user(val, &user_kbe->kb_value);
51582 case KDSKBENT:
51583+ if (!capable(CAP_SYS_TTY_CONFIG))
51584+ perm = 0;
51585+
51586 if (!perm)
51587 return -EPERM;
51588 if (!i && v == K_NOSUCHMAP) {
51589@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51590 int i, j, k;
51591 int ret;
51592
51593- if (!capable(CAP_SYS_TTY_CONFIG))
51594- perm = 0;
51595-
51596 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51597 if (!kbs) {
51598 ret = -ENOMEM;
51599@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51600 kfree(kbs);
51601 return ((p && *p) ? -EOVERFLOW : 0);
51602 case KDSKBSENT:
51603+ if (!capable(CAP_SYS_TTY_CONFIG))
51604+ perm = 0;
51605+
51606 if (!perm) {
51607 ret = -EPERM;
51608 goto reterr;
51609diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51610index a673e5b..36e5d32 100644
51611--- a/drivers/uio/uio.c
51612+++ b/drivers/uio/uio.c
51613@@ -25,6 +25,7 @@
51614 #include <linux/kobject.h>
51615 #include <linux/cdev.h>
51616 #include <linux/uio_driver.h>
51617+#include <asm/local.h>
51618
51619 #define UIO_MAX_DEVICES (1U << MINORBITS)
51620
51621@@ -32,7 +33,7 @@ struct uio_device {
51622 struct module *owner;
51623 struct device *dev;
51624 int minor;
51625- atomic_t event;
51626+ atomic_unchecked_t event;
51627 struct fasync_struct *async_queue;
51628 wait_queue_head_t wait;
51629 struct uio_info *info;
51630@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51631 struct device_attribute *attr, char *buf)
51632 {
51633 struct uio_device *idev = dev_get_drvdata(dev);
51634- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51635+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51636 }
51637 static DEVICE_ATTR_RO(event);
51638
51639@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51640 {
51641 struct uio_device *idev = info->uio_dev;
51642
51643- atomic_inc(&idev->event);
51644+ atomic_inc_unchecked(&idev->event);
51645 wake_up_interruptible(&idev->wait);
51646 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51647 }
51648@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51649 }
51650
51651 listener->dev = idev;
51652- listener->event_count = atomic_read(&idev->event);
51653+ listener->event_count = atomic_read_unchecked(&idev->event);
51654 filep->private_data = listener;
51655
51656 if (idev->info->open) {
51657@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51658 return -EIO;
51659
51660 poll_wait(filep, &idev->wait, wait);
51661- if (listener->event_count != atomic_read(&idev->event))
51662+ if (listener->event_count != atomic_read_unchecked(&idev->event))
51663 return POLLIN | POLLRDNORM;
51664 return 0;
51665 }
51666@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51667 do {
51668 set_current_state(TASK_INTERRUPTIBLE);
51669
51670- event_count = atomic_read(&idev->event);
51671+ event_count = atomic_read_unchecked(&idev->event);
51672 if (event_count != listener->event_count) {
51673 if (copy_to_user(buf, &event_count, count))
51674 retval = -EFAULT;
51675@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51676 static int uio_find_mem_index(struct vm_area_struct *vma)
51677 {
51678 struct uio_device *idev = vma->vm_private_data;
51679+ unsigned long size;
51680
51681 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51682- if (idev->info->mem[vma->vm_pgoff].size == 0)
51683+ size = idev->info->mem[vma->vm_pgoff].size;
51684+ if (size == 0)
51685+ return -1;
51686+ if (vma->vm_end - vma->vm_start > size)
51687 return -1;
51688 return (int)vma->vm_pgoff;
51689 }
51690@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51691 idev->owner = owner;
51692 idev->info = info;
51693 init_waitqueue_head(&idev->wait);
51694- atomic_set(&idev->event, 0);
51695+ atomic_set_unchecked(&idev->event, 0);
51696
51697 ret = uio_get_minor(idev);
51698 if (ret)
51699diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51700index 813d4d3..a71934f 100644
51701--- a/drivers/usb/atm/cxacru.c
51702+++ b/drivers/usb/atm/cxacru.c
51703@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51704 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51705 if (ret < 2)
51706 return -EINVAL;
51707- if (index < 0 || index > 0x7f)
51708+ if (index > 0x7f)
51709 return -EINVAL;
51710 pos += tmp;
51711
51712diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51713index dada014..1d0d517 100644
51714--- a/drivers/usb/atm/usbatm.c
51715+++ b/drivers/usb/atm/usbatm.c
51716@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51717 if (printk_ratelimit())
51718 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51719 __func__, vpi, vci);
51720- atomic_inc(&vcc->stats->rx_err);
51721+ atomic_inc_unchecked(&vcc->stats->rx_err);
51722 return;
51723 }
51724
51725@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51726 if (length > ATM_MAX_AAL5_PDU) {
51727 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51728 __func__, length, vcc);
51729- atomic_inc(&vcc->stats->rx_err);
51730+ atomic_inc_unchecked(&vcc->stats->rx_err);
51731 goto out;
51732 }
51733
51734@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51735 if (sarb->len < pdu_length) {
51736 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51737 __func__, pdu_length, sarb->len, vcc);
51738- atomic_inc(&vcc->stats->rx_err);
51739+ atomic_inc_unchecked(&vcc->stats->rx_err);
51740 goto out;
51741 }
51742
51743 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51744 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51745 __func__, vcc);
51746- atomic_inc(&vcc->stats->rx_err);
51747+ atomic_inc_unchecked(&vcc->stats->rx_err);
51748 goto out;
51749 }
51750
51751@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51752 if (printk_ratelimit())
51753 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51754 __func__, length);
51755- atomic_inc(&vcc->stats->rx_drop);
51756+ atomic_inc_unchecked(&vcc->stats->rx_drop);
51757 goto out;
51758 }
51759
51760@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51761
51762 vcc->push(vcc, skb);
51763
51764- atomic_inc(&vcc->stats->rx);
51765+ atomic_inc_unchecked(&vcc->stats->rx);
51766 out:
51767 skb_trim(sarb, 0);
51768 }
51769@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51770 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51771
51772 usbatm_pop(vcc, skb);
51773- atomic_inc(&vcc->stats->tx);
51774+ atomic_inc_unchecked(&vcc->stats->tx);
51775
51776 skb = skb_dequeue(&instance->sndqueue);
51777 }
51778@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
51779 if (!left--)
51780 return sprintf(page,
51781 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51782- atomic_read(&atm_dev->stats.aal5.tx),
51783- atomic_read(&atm_dev->stats.aal5.tx_err),
51784- atomic_read(&atm_dev->stats.aal5.rx),
51785- atomic_read(&atm_dev->stats.aal5.rx_err),
51786- atomic_read(&atm_dev->stats.aal5.rx_drop));
51787+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51788+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51789+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51790+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51791+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51792
51793 if (!left--) {
51794 if (instance->disconnected)
51795diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51796index 2a3bbdf..91d72cf 100644
51797--- a/drivers/usb/core/devices.c
51798+++ b/drivers/usb/core/devices.c
51799@@ -126,7 +126,7 @@ static const char format_endpt[] =
51800 * time it gets called.
51801 */
51802 static struct device_connect_event {
51803- atomic_t count;
51804+ atomic_unchecked_t count;
51805 wait_queue_head_t wait;
51806 } device_event = {
51807 .count = ATOMIC_INIT(1),
51808@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51809
51810 void usbfs_conn_disc_event(void)
51811 {
51812- atomic_add(2, &device_event.count);
51813+ atomic_add_unchecked(2, &device_event.count);
51814 wake_up(&device_event.wait);
51815 }
51816
51817@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51818
51819 poll_wait(file, &device_event.wait, wait);
51820
51821- event_count = atomic_read(&device_event.count);
51822+ event_count = atomic_read_unchecked(&device_event.count);
51823 if (file->f_version != event_count) {
51824 file->f_version = event_count;
51825 return POLLIN | POLLRDNORM;
51826diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51827index 257876e..4304364 100644
51828--- a/drivers/usb/core/devio.c
51829+++ b/drivers/usb/core/devio.c
51830@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51831 struct usb_dev_state *ps = file->private_data;
51832 struct usb_device *dev = ps->dev;
51833 ssize_t ret = 0;
51834- unsigned len;
51835+ size_t len;
51836 loff_t pos;
51837 int i;
51838
51839@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51840 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51841 struct usb_config_descriptor *config =
51842 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51843- unsigned int length = le16_to_cpu(config->wTotalLength);
51844+ size_t length = le16_to_cpu(config->wTotalLength);
51845
51846 if (*ppos < pos + length) {
51847
51848 /* The descriptor may claim to be longer than it
51849 * really is. Here is the actual allocated length. */
51850- unsigned alloclen =
51851+ size_t alloclen =
51852 le16_to_cpu(dev->config[i].desc.wTotalLength);
51853
51854- len = length - (*ppos - pos);
51855+ len = length + pos - *ppos;
51856 if (len > nbytes)
51857 len = nbytes;
51858
51859 /* Simply don't write (skip over) unallocated parts */
51860 if (alloclen > (*ppos - pos)) {
51861- alloclen -= (*ppos - pos);
51862+ alloclen = alloclen + pos - *ppos;
51863 if (copy_to_user(buf,
51864 dev->rawdescriptors[i] + (*ppos - pos),
51865 min(len, alloclen))) {
51866diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51867index 9c4e292..b89877f 100644
51868--- a/drivers/usb/core/hcd.c
51869+++ b/drivers/usb/core/hcd.c
51870@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51871 */
51872 usb_get_urb(urb);
51873 atomic_inc(&urb->use_count);
51874- atomic_inc(&urb->dev->urbnum);
51875+ atomic_inc_unchecked(&urb->dev->urbnum);
51876 usbmon_urb_submit(&hcd->self, urb);
51877
51878 /* NOTE requirements on root-hub callers (usbfs and the hub
51879@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51880 urb->hcpriv = NULL;
51881 INIT_LIST_HEAD(&urb->urb_list);
51882 atomic_dec(&urb->use_count);
51883- atomic_dec(&urb->dev->urbnum);
51884+ atomic_dec_unchecked(&urb->dev->urbnum);
51885 if (atomic_read(&urb->reject))
51886 wake_up(&usb_kill_urb_queue);
51887 usb_put_urb(urb);
51888diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51889index 229a73f..ef86f98 100644
51890--- a/drivers/usb/core/hub.c
51891+++ b/drivers/usb/core/hub.c
51892@@ -27,6 +27,7 @@
51893 #include <linux/freezer.h>
51894 #include <linux/random.h>
51895 #include <linux/pm_qos.h>
51896+#include <linux/grsecurity.h>
51897
51898 #include <asm/uaccess.h>
51899 #include <asm/byteorder.h>
51900@@ -4512,6 +4513,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51901 goto done;
51902 return;
51903 }
51904+
51905+ if (gr_handle_new_usb())
51906+ goto done;
51907+
51908 if (hub_is_superspeed(hub->hdev))
51909 unit_load = 150;
51910 else
51911diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51912index 0c8a7fc..c45b40a 100644
51913--- a/drivers/usb/core/message.c
51914+++ b/drivers/usb/core/message.c
51915@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51916 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51917 * error number.
51918 */
51919-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51920+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51921 __u8 requesttype, __u16 value, __u16 index, void *data,
51922 __u16 size, int timeout)
51923 {
51924@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51925 * If successful, 0. Otherwise a negative error number. The number of actual
51926 * bytes transferred will be stored in the @actual_length parameter.
51927 */
51928-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51929+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51930 void *data, int len, int *actual_length, int timeout)
51931 {
51932 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51933@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51934 * bytes transferred will be stored in the @actual_length parameter.
51935 *
51936 */
51937-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51938+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51939 void *data, int len, int *actual_length, int timeout)
51940 {
51941 struct urb *urb;
51942diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
51943index 1236c60..d47a51c 100644
51944--- a/drivers/usb/core/sysfs.c
51945+++ b/drivers/usb/core/sysfs.c
51946@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
51947 struct usb_device *udev;
51948
51949 udev = to_usb_device(dev);
51950- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
51951+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
51952 }
51953 static DEVICE_ATTR_RO(urbnum);
51954
51955diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
51956index 4d11449..f4ccabf 100644
51957--- a/drivers/usb/core/usb.c
51958+++ b/drivers/usb/core/usb.c
51959@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
51960 set_dev_node(&dev->dev, dev_to_node(bus->controller));
51961 dev->state = USB_STATE_ATTACHED;
51962 dev->lpm_disable_count = 1;
51963- atomic_set(&dev->urbnum, 0);
51964+ atomic_set_unchecked(&dev->urbnum, 0);
51965
51966 INIT_LIST_HEAD(&dev->ep0.urb_list);
51967 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
51968diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
51969index 70715ee..07a175c 100644
51970--- a/drivers/usb/dwc3/gadget.c
51971+++ b/drivers/usb/dwc3/gadget.c
51972@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
51973 if (!usb_endpoint_xfer_isoc(desc))
51974 return 0;
51975
51976- memset(&trb_link, 0, sizeof(trb_link));
51977-
51978 /* Link TRB for ISOC. The HWO bit is never reset */
51979 trb_st_hw = &dep->trb_pool[0];
51980
51981diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
51982index 8cfc319..4868255 100644
51983--- a/drivers/usb/early/ehci-dbgp.c
51984+++ b/drivers/usb/early/ehci-dbgp.c
51985@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
51986
51987 #ifdef CONFIG_KGDB
51988 static struct kgdb_io kgdbdbgp_io_ops;
51989-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
51990+static struct kgdb_io kgdbdbgp_io_ops_console;
51991+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
51992 #else
51993 #define dbgp_kgdb_mode (0)
51994 #endif
51995@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
51996 .write_char = kgdbdbgp_write_char,
51997 };
51998
51999+static struct kgdb_io kgdbdbgp_io_ops_console = {
52000+ .name = "kgdbdbgp",
52001+ .read_char = kgdbdbgp_read_char,
52002+ .write_char = kgdbdbgp_write_char,
52003+ .is_console = 1
52004+};
52005+
52006 static int kgdbdbgp_wait_time;
52007
52008 static int __init kgdbdbgp_parse_config(char *str)
52009@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52010 ptr++;
52011 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52012 }
52013- kgdb_register_io_module(&kgdbdbgp_io_ops);
52014- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52015+ if (early_dbgp_console.index != -1)
52016+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52017+ else
52018+ kgdb_register_io_module(&kgdbdbgp_io_ops);
52019
52020 return 0;
52021 }
52022diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52023index 2b4c82d..06a8ee6 100644
52024--- a/drivers/usb/gadget/f_uac1.c
52025+++ b/drivers/usb/gadget/f_uac1.c
52026@@ -13,6 +13,7 @@
52027 #include <linux/kernel.h>
52028 #include <linux/device.h>
52029 #include <linux/atomic.h>
52030+#include <linux/module.h>
52031
52032 #include "u_uac1.h"
52033
52034diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52035index ad0aca8..8ff84865 100644
52036--- a/drivers/usb/gadget/u_serial.c
52037+++ b/drivers/usb/gadget/u_serial.c
52038@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52039 spin_lock_irq(&port->port_lock);
52040
52041 /* already open? Great. */
52042- if (port->port.count) {
52043+ if (atomic_read(&port->port.count)) {
52044 status = 0;
52045- port->port.count++;
52046+ atomic_inc(&port->port.count);
52047
52048 /* currently opening/closing? wait ... */
52049 } else if (port->openclose) {
52050@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52051 tty->driver_data = port;
52052 port->port.tty = tty;
52053
52054- port->port.count = 1;
52055+ atomic_set(&port->port.count, 1);
52056 port->openclose = false;
52057
52058 /* if connected, start the I/O stream */
52059@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52060
52061 spin_lock_irq(&port->port_lock);
52062
52063- if (port->port.count != 1) {
52064- if (port->port.count == 0)
52065+ if (atomic_read(&port->port.count) != 1) {
52066+ if (atomic_read(&port->port.count) == 0)
52067 WARN_ON(1);
52068 else
52069- --port->port.count;
52070+ atomic_dec(&port->port.count);
52071 goto exit;
52072 }
52073
52074@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52075 * and sleep if necessary
52076 */
52077 port->openclose = true;
52078- port->port.count = 0;
52079+ atomic_set(&port->port.count, 0);
52080
52081 gser = port->port_usb;
52082 if (gser && gser->disconnect)
52083@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52084 int cond;
52085
52086 spin_lock_irq(&port->port_lock);
52087- cond = (port->port.count == 0) && !port->openclose;
52088+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52089 spin_unlock_irq(&port->port_lock);
52090 return cond;
52091 }
52092@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52093 /* if it's already open, start I/O ... and notify the serial
52094 * protocol about open/close status (connect/disconnect).
52095 */
52096- if (port->port.count) {
52097+ if (atomic_read(&port->port.count)) {
52098 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52099 gs_start_io(port);
52100 if (gser->connect)
52101@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52102
52103 port->port_usb = NULL;
52104 gser->ioport = NULL;
52105- if (port->port.count > 0 || port->openclose) {
52106+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
52107 wake_up_interruptible(&port->drain_wait);
52108 if (port->port.tty)
52109 tty_hangup(port->port.tty);
52110@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52111
52112 /* finally, free any unused/unusable I/O buffers */
52113 spin_lock_irqsave(&port->port_lock, flags);
52114- if (port->port.count == 0 && !port->openclose)
52115+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
52116 gs_buf_free(&port->port_write_buf);
52117 gs_free_requests(gser->out, &port->read_pool, NULL);
52118 gs_free_requests(gser->out, &port->read_queue, NULL);
52119diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52120index 7a55fea..cc0ed4f 100644
52121--- a/drivers/usb/gadget/u_uac1.c
52122+++ b/drivers/usb/gadget/u_uac1.c
52123@@ -16,6 +16,7 @@
52124 #include <linux/ctype.h>
52125 #include <linux/random.h>
52126 #include <linux/syscalls.h>
52127+#include <linux/module.h>
52128
52129 #include "u_uac1.h"
52130
52131diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52132index 7ae0c4d..35521b7 100644
52133--- a/drivers/usb/host/ehci-hub.c
52134+++ b/drivers/usb/host/ehci-hub.c
52135@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52136 urb->transfer_flags = URB_DIR_IN;
52137 usb_get_urb(urb);
52138 atomic_inc(&urb->use_count);
52139- atomic_inc(&urb->dev->urbnum);
52140+ atomic_inc_unchecked(&urb->dev->urbnum);
52141 urb->setup_dma = dma_map_single(
52142 hcd->self.controller,
52143 urb->setup_packet,
52144@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52145 urb->status = -EINPROGRESS;
52146 usb_get_urb(urb);
52147 atomic_inc(&urb->use_count);
52148- atomic_inc(&urb->dev->urbnum);
52149+ atomic_inc_unchecked(&urb->dev->urbnum);
52150 retval = submit_single_step_set_feature(hcd, urb, 0);
52151 if (!retval && !wait_for_completion_timeout(&done,
52152 msecs_to_jiffies(2000))) {
52153diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52154index ba6a5d6..f88f7f3 100644
52155--- a/drivers/usb/misc/appledisplay.c
52156+++ b/drivers/usb/misc/appledisplay.c
52157@@ -83,7 +83,7 @@ struct appledisplay {
52158 spinlock_t lock;
52159 };
52160
52161-static atomic_t count_displays = ATOMIC_INIT(0);
52162+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52163 static struct workqueue_struct *wq;
52164
52165 static void appledisplay_complete(struct urb *urb)
52166@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52167
52168 /* Register backlight device */
52169 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52170- atomic_inc_return(&count_displays) - 1);
52171+ atomic_inc_return_unchecked(&count_displays) - 1);
52172 memset(&props, 0, sizeof(struct backlight_properties));
52173 props.type = BACKLIGHT_RAW;
52174 props.max_brightness = 0xff;
52175diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52176index 8d7fc48..01c4986 100644
52177--- a/drivers/usb/serial/console.c
52178+++ b/drivers/usb/serial/console.c
52179@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52180
52181 info->port = port;
52182
52183- ++port->port.count;
52184+ atomic_inc(&port->port.count);
52185 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52186 if (serial->type->set_termios) {
52187 /*
52188@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52189 }
52190 /* Now that any required fake tty operations are completed restore
52191 * the tty port count */
52192- --port->port.count;
52193+ atomic_dec(&port->port.count);
52194 /* The console is special in terms of closing the device so
52195 * indicate this port is now acting as a system console. */
52196 port->port.console = 1;
52197@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52198 free_tty:
52199 kfree(tty);
52200 reset_open_count:
52201- port->port.count = 0;
52202+ atomic_set(&port->port.count, 0);
52203 usb_autopm_put_interface(serial->interface);
52204 error_get_interface:
52205 usb_serial_put(serial);
52206@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52207 static void usb_console_write(struct console *co,
52208 const char *buf, unsigned count)
52209 {
52210- static struct usbcons_info *info = &usbcons_info;
52211+ struct usbcons_info *info = &usbcons_info;
52212 struct usb_serial_port *port = info->port;
52213 struct usb_serial *serial;
52214 int retval = -ENODEV;
52215diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52216index 307e339..6aa97cb 100644
52217--- a/drivers/usb/storage/usb.h
52218+++ b/drivers/usb/storage/usb.h
52219@@ -63,7 +63,7 @@ struct us_unusual_dev {
52220 __u8 useProtocol;
52221 __u8 useTransport;
52222 int (*initFunction)(struct us_data *);
52223-};
52224+} __do_const;
52225
52226
52227 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52228diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52229index f2a8d29..7bc3fe7 100644
52230--- a/drivers/usb/wusbcore/wa-hc.h
52231+++ b/drivers/usb/wusbcore/wa-hc.h
52232@@ -240,7 +240,7 @@ struct wahc {
52233 spinlock_t xfer_list_lock;
52234 struct work_struct xfer_enqueue_work;
52235 struct work_struct xfer_error_work;
52236- atomic_t xfer_id_count;
52237+ atomic_unchecked_t xfer_id_count;
52238
52239 kernel_ulong_t quirks;
52240 };
52241@@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
52242 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52243 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52244 wa->dto_in_use = 0;
52245- atomic_set(&wa->xfer_id_count, 1);
52246+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52247 /* init the buf in URBs */
52248 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
52249 usb_init_urb(&(wa->buf_in_urbs[index]));
52250diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52251index 3e2e4ed..060c9b8 100644
52252--- a/drivers/usb/wusbcore/wa-xfer.c
52253+++ b/drivers/usb/wusbcore/wa-xfer.c
52254@@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52255 */
52256 static void wa_xfer_id_init(struct wa_xfer *xfer)
52257 {
52258- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52259+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52260 }
52261
52262 /* Return the xfer's ID. */
52263diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52264index 512f479..7e041d0 100644
52265--- a/drivers/vfio/vfio.c
52266+++ b/drivers/vfio/vfio.c
52267@@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52268 return 0;
52269
52270 /* TODO Prevent device auto probing */
52271- WARN("Device %s added to live group %d!\n", dev_name(dev),
52272+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52273 iommu_group_id(group->iommu_group));
52274
52275 return 0;
52276diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52277index 5174eba..451e6bc 100644
52278--- a/drivers/vhost/vringh.c
52279+++ b/drivers/vhost/vringh.c
52280@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52281 /* Userspace access helpers: in this case, addresses are really userspace. */
52282 static inline int getu16_user(u16 *val, const u16 *p)
52283 {
52284- return get_user(*val, (__force u16 __user *)p);
52285+ return get_user(*val, (u16 __force_user *)p);
52286 }
52287
52288 static inline int putu16_user(u16 *p, u16 val)
52289 {
52290- return put_user(val, (__force u16 __user *)p);
52291+ return put_user(val, (u16 __force_user *)p);
52292 }
52293
52294 static inline int copydesc_user(void *dst, const void *src, size_t len)
52295 {
52296- return copy_from_user(dst, (__force void __user *)src, len) ?
52297+ return copy_from_user(dst, (void __force_user *)src, len) ?
52298 -EFAULT : 0;
52299 }
52300
52301@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52302 const struct vring_used_elem *src,
52303 unsigned int num)
52304 {
52305- return copy_to_user((__force void __user *)dst, src,
52306+ return copy_to_user((void __force_user *)dst, src,
52307 sizeof(*dst) * num) ? -EFAULT : 0;
52308 }
52309
52310 static inline int xfer_from_user(void *src, void *dst, size_t len)
52311 {
52312- return copy_from_user(dst, (__force void __user *)src, len) ?
52313+ return copy_from_user(dst, (void __force_user *)src, len) ?
52314 -EFAULT : 0;
52315 }
52316
52317 static inline int xfer_to_user(void *dst, void *src, size_t len)
52318 {
52319- return copy_to_user((__force void __user *)dst, src, len) ?
52320+ return copy_to_user((void __force_user *)dst, src, len) ?
52321 -EFAULT : 0;
52322 }
52323
52324@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52325 vrh->last_used_idx = 0;
52326 vrh->vring.num = num;
52327 /* vring expects kernel addresses, but only used via accessors. */
52328- vrh->vring.desc = (__force struct vring_desc *)desc;
52329- vrh->vring.avail = (__force struct vring_avail *)avail;
52330- vrh->vring.used = (__force struct vring_used *)used;
52331+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52332+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52333+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52334 return 0;
52335 }
52336 EXPORT_SYMBOL(vringh_init_user);
52337@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52338
52339 static inline int putu16_kern(u16 *p, u16 val)
52340 {
52341- ACCESS_ONCE(*p) = val;
52342+ ACCESS_ONCE_RW(*p) = val;
52343 return 0;
52344 }
52345
52346diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52347index 84a110a..96312c3 100644
52348--- a/drivers/video/backlight/kb3886_bl.c
52349+++ b/drivers/video/backlight/kb3886_bl.c
52350@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52351 static unsigned long kb3886bl_flags;
52352 #define KB3886BL_SUSPENDED 0x01
52353
52354-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52355+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52356 {
52357 .ident = "Sahara Touch-iT",
52358 .matches = {
52359diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
52360index 1b0b233..6f34c2c 100644
52361--- a/drivers/video/fbdev/arcfb.c
52362+++ b/drivers/video/fbdev/arcfb.c
52363@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52364 return -ENOSPC;
52365
52366 err = 0;
52367- if ((count + p) > fbmemlength) {
52368+ if (count > (fbmemlength - p)) {
52369 count = fbmemlength - p;
52370 err = -ENOSPC;
52371 }
52372diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
52373index 52108be..c7c110d 100644
52374--- a/drivers/video/fbdev/aty/aty128fb.c
52375+++ b/drivers/video/fbdev/aty/aty128fb.c
52376@@ -149,7 +149,7 @@ enum {
52377 };
52378
52379 /* Must match above enum */
52380-static char * const r128_family[] = {
52381+static const char * const r128_family[] = {
52382 "AGP",
52383 "PCI",
52384 "PRO AGP",
52385diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
52386index c3d0074..0b9077e 100644
52387--- a/drivers/video/fbdev/aty/atyfb_base.c
52388+++ b/drivers/video/fbdev/aty/atyfb_base.c
52389@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52390 par->accel_flags = var->accel_flags; /* hack */
52391
52392 if (var->accel_flags) {
52393- info->fbops->fb_sync = atyfb_sync;
52394+ pax_open_kernel();
52395+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52396+ pax_close_kernel();
52397 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52398 } else {
52399- info->fbops->fb_sync = NULL;
52400+ pax_open_kernel();
52401+ *(void **)&info->fbops->fb_sync = NULL;
52402+ pax_close_kernel();
52403 info->flags |= FBINFO_HWACCEL_DISABLED;
52404 }
52405
52406diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
52407index 2fa0317..4983f2a 100644
52408--- a/drivers/video/fbdev/aty/mach64_cursor.c
52409+++ b/drivers/video/fbdev/aty/mach64_cursor.c
52410@@ -8,6 +8,7 @@
52411 #include "../core/fb_draw.h"
52412
52413 #include <asm/io.h>
52414+#include <asm/pgtable.h>
52415
52416 #ifdef __sparc__
52417 #include <asm/fbio.h>
52418@@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
52419 info->sprite.buf_align = 16; /* and 64 lines tall. */
52420 info->sprite.flags = FB_PIXMAP_IO;
52421
52422- info->fbops->fb_cursor = atyfb_cursor;
52423+ pax_open_kernel();
52424+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52425+ pax_close_kernel();
52426
52427 return 0;
52428 }
52429diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
52430index 900aa4e..6d49418 100644
52431--- a/drivers/video/fbdev/core/fb_defio.c
52432+++ b/drivers/video/fbdev/core/fb_defio.c
52433@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52434
52435 BUG_ON(!fbdefio);
52436 mutex_init(&fbdefio->lock);
52437- info->fbops->fb_mmap = fb_deferred_io_mmap;
52438+ pax_open_kernel();
52439+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52440+ pax_close_kernel();
52441 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52442 INIT_LIST_HEAD(&fbdefio->pagelist);
52443 if (fbdefio->delay == 0) /* set a default of 1 s */
52444@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52445 page->mapping = NULL;
52446 }
52447
52448- info->fbops->fb_mmap = NULL;
52449+ *(void **)&info->fbops->fb_mmap = NULL;
52450 mutex_destroy(&fbdefio->lock);
52451 }
52452 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52453diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
52454index b6d5008..5bca7bf 100644
52455--- a/drivers/video/fbdev/core/fbmem.c
52456+++ b/drivers/video/fbdev/core/fbmem.c
52457@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52458 image->dx += image->width + 8;
52459 }
52460 } else if (rotate == FB_ROTATE_UD) {
52461- for (x = 0; x < num && image->dx >= 0; x++) {
52462+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52463 info->fbops->fb_imageblit(info, image);
52464 image->dx -= image->width + 8;
52465 }
52466@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52467 image->dy += image->height + 8;
52468 }
52469 } else if (rotate == FB_ROTATE_CCW) {
52470- for (x = 0; x < num && image->dy >= 0; x++) {
52471+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52472 info->fbops->fb_imageblit(info, image);
52473 image->dy -= image->height + 8;
52474 }
52475@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52476 return -EFAULT;
52477 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52478 return -EINVAL;
52479- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52480+ if (con2fb.framebuffer >= FB_MAX)
52481 return -EINVAL;
52482 if (!registered_fb[con2fb.framebuffer])
52483 request_module("fb%d", con2fb.framebuffer);
52484@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52485 __u32 data;
52486 int err;
52487
52488- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52489+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52490
52491 data = (__u32) (unsigned long) fix->smem_start;
52492 err |= put_user(data, &fix32->smem_start);
52493diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
52494index e23392e..8a77540 100644
52495--- a/drivers/video/fbdev/hyperv_fb.c
52496+++ b/drivers/video/fbdev/hyperv_fb.c
52497@@ -235,7 +235,7 @@ static uint screen_fb_size;
52498 static inline int synthvid_send(struct hv_device *hdev,
52499 struct synthvid_msg *msg)
52500 {
52501- static atomic64_t request_id = ATOMIC64_INIT(0);
52502+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52503 int ret;
52504
52505 msg->pipe_hdr.type = PIPE_MSG_DATA;
52506@@ -243,7 +243,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52507
52508 ret = vmbus_sendpacket(hdev->channel, msg,
52509 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52510- atomic64_inc_return(&request_id),
52511+ atomic64_inc_return_unchecked(&request_id),
52512 VM_PKT_DATA_INBAND, 0);
52513
52514 if (ret)
52515diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
52516index 7672d2e..b56437f 100644
52517--- a/drivers/video/fbdev/i810/i810_accel.c
52518+++ b/drivers/video/fbdev/i810/i810_accel.c
52519@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52520 }
52521 }
52522 printk("ringbuffer lockup!!!\n");
52523+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52524 i810_report_error(mmio);
52525 par->dev_flags |= LOCKUP;
52526 info->pixmap.scan_align = 1;
52527diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52528index a01147f..5d896f8 100644
52529--- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52530+++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52531@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
52532
52533 #ifdef CONFIG_FB_MATROX_MYSTIQUE
52534 struct matrox_switch matrox_mystique = {
52535- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
52536+ .preinit = MGA1064_preinit,
52537+ .reset = MGA1064_reset,
52538+ .init = MGA1064_init,
52539+ .restore = MGA1064_restore,
52540 };
52541 EXPORT_SYMBOL(matrox_mystique);
52542 #endif
52543
52544 #ifdef CONFIG_FB_MATROX_G
52545 struct matrox_switch matrox_G100 = {
52546- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
52547+ .preinit = MGAG100_preinit,
52548+ .reset = MGAG100_reset,
52549+ .init = MGAG100_init,
52550+ .restore = MGAG100_restore,
52551 };
52552 EXPORT_SYMBOL(matrox_G100);
52553 #endif
52554diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52555index 195ad7c..09743fc 100644
52556--- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52557+++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52558@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
52559 }
52560
52561 struct matrox_switch matrox_millennium = {
52562- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
52563+ .preinit = Ti3026_preinit,
52564+ .reset = Ti3026_reset,
52565+ .init = Ti3026_init,
52566+ .restore = Ti3026_restore
52567 };
52568 EXPORT_SYMBOL(matrox_millennium);
52569 #endif
52570diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52571index fe92eed..106e085 100644
52572--- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52573+++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52574@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
52575 struct mb862xxfb_par *par = info->par;
52576
52577 if (info->var.bits_per_pixel == 32) {
52578- info->fbops->fb_fillrect = cfb_fillrect;
52579- info->fbops->fb_copyarea = cfb_copyarea;
52580- info->fbops->fb_imageblit = cfb_imageblit;
52581+ pax_open_kernel();
52582+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52583+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52584+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52585+ pax_close_kernel();
52586 } else {
52587 outreg(disp, GC_L0EM, 3);
52588- info->fbops->fb_fillrect = mb86290fb_fillrect;
52589- info->fbops->fb_copyarea = mb86290fb_copyarea;
52590- info->fbops->fb_imageblit = mb86290fb_imageblit;
52591+ pax_open_kernel();
52592+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
52593+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
52594+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
52595+ pax_close_kernel();
52596 }
52597 outreg(draw, GDC_REG_DRAW_BASE, 0);
52598 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
52599diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
52600index def0412..fed6529 100644
52601--- a/drivers/video/fbdev/nvidia/nvidia.c
52602+++ b/drivers/video/fbdev/nvidia/nvidia.c
52603@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
52604 info->fix.line_length = (info->var.xres_virtual *
52605 info->var.bits_per_pixel) >> 3;
52606 if (info->var.accel_flags) {
52607- info->fbops->fb_imageblit = nvidiafb_imageblit;
52608- info->fbops->fb_fillrect = nvidiafb_fillrect;
52609- info->fbops->fb_copyarea = nvidiafb_copyarea;
52610- info->fbops->fb_sync = nvidiafb_sync;
52611+ pax_open_kernel();
52612+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
52613+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
52614+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
52615+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
52616+ pax_close_kernel();
52617 info->pixmap.scan_align = 4;
52618 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52619 info->flags |= FBINFO_READS_FAST;
52620 NVResetGraphics(info);
52621 } else {
52622- info->fbops->fb_imageblit = cfb_imageblit;
52623- info->fbops->fb_fillrect = cfb_fillrect;
52624- info->fbops->fb_copyarea = cfb_copyarea;
52625- info->fbops->fb_sync = NULL;
52626+ pax_open_kernel();
52627+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52628+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52629+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52630+ *(void **)&info->fbops->fb_sync = NULL;
52631+ pax_close_kernel();
52632 info->pixmap.scan_align = 1;
52633 info->flags |= FBINFO_HWACCEL_DISABLED;
52634 info->flags &= ~FBINFO_READS_FAST;
52635@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
52636 info->pixmap.size = 8 * 1024;
52637 info->pixmap.flags = FB_PIXMAP_SYSTEM;
52638
52639- if (!hwcur)
52640- info->fbops->fb_cursor = NULL;
52641+ if (!hwcur) {
52642+ pax_open_kernel();
52643+ *(void **)&info->fbops->fb_cursor = NULL;
52644+ pax_close_kernel();
52645+ }
52646
52647 info->var.accel_flags = (!noaccel);
52648
52649diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
52650index 2412a0d..294215b 100644
52651--- a/drivers/video/fbdev/omap2/dss/display.c
52652+++ b/drivers/video/fbdev/omap2/dss/display.c
52653@@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
52654 if (dssdev->name == NULL)
52655 dssdev->name = dssdev->alias;
52656
52657+ pax_open_kernel();
52658 if (drv && drv->get_resolution == NULL)
52659- drv->get_resolution = omapdss_default_get_resolution;
52660+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
52661 if (drv && drv->get_recommended_bpp == NULL)
52662- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
52663+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
52664 if (drv && drv->get_timings == NULL)
52665- drv->get_timings = omapdss_default_get_timings;
52666+ *(void **)&drv->get_timings = omapdss_default_get_timings;
52667+ pax_close_kernel();
52668
52669 mutex_lock(&panel_list_mutex);
52670 list_add_tail(&dssdev->panel_list, &panel_list);
52671diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
52672index 83433cb..71e9b98 100644
52673--- a/drivers/video/fbdev/s1d13xxxfb.c
52674+++ b/drivers/video/fbdev/s1d13xxxfb.c
52675@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
52676
52677 switch(prod_id) {
52678 case S1D13506_PROD_ID: /* activate acceleration */
52679- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52680- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52681+ pax_open_kernel();
52682+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52683+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52684+ pax_close_kernel();
52685 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
52686 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
52687 break;
52688diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
52689index 2bcc84a..29dd1ea 100644
52690--- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
52691+++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
52692@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
52693 }
52694
52695 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
52696- lcdc_sys_write_index,
52697- lcdc_sys_write_data,
52698- lcdc_sys_read_data,
52699+ .write_index = lcdc_sys_write_index,
52700+ .write_data = lcdc_sys_write_data,
52701+ .read_data = lcdc_sys_read_data,
52702 };
52703
52704 static int sh_mobile_lcdc_sginit(struct fb_info *info,
52705diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
52706index d513ed6..90b0de9 100644
52707--- a/drivers/video/fbdev/smscufx.c
52708+++ b/drivers/video/fbdev/smscufx.c
52709@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
52710 fb_deferred_io_cleanup(info);
52711 kfree(info->fbdefio);
52712 info->fbdefio = NULL;
52713- info->fbops->fb_mmap = ufx_ops_mmap;
52714+ pax_open_kernel();
52715+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
52716+ pax_close_kernel();
52717 }
52718
52719 pr_debug("released /dev/fb%d user=%d count=%d",
52720diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
52721index 77b890e..458e666 100644
52722--- a/drivers/video/fbdev/udlfb.c
52723+++ b/drivers/video/fbdev/udlfb.c
52724@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
52725 dlfb_urb_completion(urb);
52726
52727 error:
52728- atomic_add(bytes_sent, &dev->bytes_sent);
52729- atomic_add(bytes_identical, &dev->bytes_identical);
52730- atomic_add(width*height*2, &dev->bytes_rendered);
52731+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52732+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52733+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
52734 end_cycles = get_cycles();
52735- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52736+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52737 >> 10)), /* Kcycles */
52738 &dev->cpu_kcycles_used);
52739
52740@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
52741 dlfb_urb_completion(urb);
52742
52743 error:
52744- atomic_add(bytes_sent, &dev->bytes_sent);
52745- atomic_add(bytes_identical, &dev->bytes_identical);
52746- atomic_add(bytes_rendered, &dev->bytes_rendered);
52747+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52748+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52749+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
52750 end_cycles = get_cycles();
52751- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52752+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52753 >> 10)), /* Kcycles */
52754 &dev->cpu_kcycles_used);
52755 }
52756@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
52757 fb_deferred_io_cleanup(info);
52758 kfree(info->fbdefio);
52759 info->fbdefio = NULL;
52760- info->fbops->fb_mmap = dlfb_ops_mmap;
52761+ pax_open_kernel();
52762+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
52763+ pax_close_kernel();
52764 }
52765
52766 pr_warn("released /dev/fb%d user=%d count=%d\n",
52767@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
52768 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52769 struct dlfb_data *dev = fb_info->par;
52770 return snprintf(buf, PAGE_SIZE, "%u\n",
52771- atomic_read(&dev->bytes_rendered));
52772+ atomic_read_unchecked(&dev->bytes_rendered));
52773 }
52774
52775 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52776@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52777 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52778 struct dlfb_data *dev = fb_info->par;
52779 return snprintf(buf, PAGE_SIZE, "%u\n",
52780- atomic_read(&dev->bytes_identical));
52781+ atomic_read_unchecked(&dev->bytes_identical));
52782 }
52783
52784 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52785@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52786 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52787 struct dlfb_data *dev = fb_info->par;
52788 return snprintf(buf, PAGE_SIZE, "%u\n",
52789- atomic_read(&dev->bytes_sent));
52790+ atomic_read_unchecked(&dev->bytes_sent));
52791 }
52792
52793 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52794@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52795 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52796 struct dlfb_data *dev = fb_info->par;
52797 return snprintf(buf, PAGE_SIZE, "%u\n",
52798- atomic_read(&dev->cpu_kcycles_used));
52799+ atomic_read_unchecked(&dev->cpu_kcycles_used));
52800 }
52801
52802 static ssize_t edid_show(
52803@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
52804 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52805 struct dlfb_data *dev = fb_info->par;
52806
52807- atomic_set(&dev->bytes_rendered, 0);
52808- atomic_set(&dev->bytes_identical, 0);
52809- atomic_set(&dev->bytes_sent, 0);
52810- atomic_set(&dev->cpu_kcycles_used, 0);
52811+ atomic_set_unchecked(&dev->bytes_rendered, 0);
52812+ atomic_set_unchecked(&dev->bytes_identical, 0);
52813+ atomic_set_unchecked(&dev->bytes_sent, 0);
52814+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
52815
52816 return count;
52817 }
52818diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
52819index 509d452..7c9d2de 100644
52820--- a/drivers/video/fbdev/uvesafb.c
52821+++ b/drivers/video/fbdev/uvesafb.c
52822@@ -19,6 +19,7 @@
52823 #include <linux/io.h>
52824 #include <linux/mutex.h>
52825 #include <linux/slab.h>
52826+#include <linux/moduleloader.h>
52827 #include <video/edid.h>
52828 #include <video/uvesafb.h>
52829 #ifdef CONFIG_X86
52830@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
52831 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
52832 par->pmi_setpal = par->ypan = 0;
52833 } else {
52834+
52835+#ifdef CONFIG_PAX_KERNEXEC
52836+#ifdef CONFIG_MODULES
52837+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
52838+#endif
52839+ if (!par->pmi_code) {
52840+ par->pmi_setpal = par->ypan = 0;
52841+ return 0;
52842+ }
52843+#endif
52844+
52845 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
52846 + task->t.regs.edi);
52847+
52848+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52849+ pax_open_kernel();
52850+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
52851+ pax_close_kernel();
52852+
52853+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
52854+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
52855+#else
52856 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
52857 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
52858+#endif
52859+
52860 printk(KERN_INFO "uvesafb: protected mode interface info at "
52861 "%04x:%04x\n",
52862 (u16)task->t.regs.es, (u16)task->t.regs.edi);
52863@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
52864 par->ypan = ypan;
52865
52866 if (par->pmi_setpal || par->ypan) {
52867+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
52868 if (__supported_pte_mask & _PAGE_NX) {
52869 par->pmi_setpal = par->ypan = 0;
52870 printk(KERN_WARNING "uvesafb: NX protection is active, "
52871 "better not use the PMI.\n");
52872- } else {
52873+ } else
52874+#endif
52875 uvesafb_vbe_getpmi(task, par);
52876- }
52877 }
52878 #else
52879 /* The protected mode interface is not available on non-x86. */
52880@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52881 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
52882
52883 /* Disable blanking if the user requested so. */
52884- if (!blank)
52885- info->fbops->fb_blank = NULL;
52886+ if (!blank) {
52887+ pax_open_kernel();
52888+ *(void **)&info->fbops->fb_blank = NULL;
52889+ pax_close_kernel();
52890+ }
52891
52892 /*
52893 * Find out how much IO memory is required for the mode with
52894@@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52895 info->flags = FBINFO_FLAG_DEFAULT |
52896 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
52897
52898- if (!par->ypan)
52899- info->fbops->fb_pan_display = NULL;
52900+ if (!par->ypan) {
52901+ pax_open_kernel();
52902+ *(void **)&info->fbops->fb_pan_display = NULL;
52903+ pax_close_kernel();
52904+ }
52905 }
52906
52907 static void uvesafb_init_mtrr(struct fb_info *info)
52908@@ -1787,6 +1817,11 @@ out_mode:
52909 out:
52910 kfree(par->vbe_modes);
52911
52912+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52913+ if (par->pmi_code)
52914+ module_free_exec(NULL, par->pmi_code);
52915+#endif
52916+
52917 framebuffer_release(info);
52918 return err;
52919 }
52920@@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
52921 kfree(par->vbe_state_orig);
52922 kfree(par->vbe_state_saved);
52923
52924+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52925+ if (par->pmi_code)
52926+ module_free_exec(NULL, par->pmi_code);
52927+#endif
52928+
52929 framebuffer_release(info);
52930 }
52931 return 0;
52932diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
52933index 6170e7f..dd63031 100644
52934--- a/drivers/video/fbdev/vesafb.c
52935+++ b/drivers/video/fbdev/vesafb.c
52936@@ -9,6 +9,7 @@
52937 */
52938
52939 #include <linux/module.h>
52940+#include <linux/moduleloader.h>
52941 #include <linux/kernel.h>
52942 #include <linux/errno.h>
52943 #include <linux/string.h>
52944@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
52945 static int vram_total; /* Set total amount of memory */
52946 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
52947 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
52948-static void (*pmi_start)(void) __read_mostly;
52949-static void (*pmi_pal) (void) __read_mostly;
52950+static void (*pmi_start)(void) __read_only;
52951+static void (*pmi_pal) (void) __read_only;
52952 static int depth __read_mostly;
52953 static int vga_compat __read_mostly;
52954 /* --------------------------------------------------------------------- */
52955@@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
52956 unsigned int size_remap;
52957 unsigned int size_total;
52958 char *option = NULL;
52959+ void *pmi_code = NULL;
52960
52961 /* ignore error return of fb_get_options */
52962 fb_get_options("vesafb", &option);
52963@@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
52964 size_remap = size_total;
52965 vesafb_fix.smem_len = size_remap;
52966
52967-#ifndef __i386__
52968- screen_info.vesapm_seg = 0;
52969-#endif
52970-
52971 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
52972 printk(KERN_WARNING
52973 "vesafb: cannot reserve video memory at 0x%lx\n",
52974@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
52975 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
52976 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
52977
52978+#ifdef __i386__
52979+
52980+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52981+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
52982+ if (!pmi_code)
52983+#elif !defined(CONFIG_PAX_KERNEXEC)
52984+ if (0)
52985+#endif
52986+
52987+#endif
52988+ screen_info.vesapm_seg = 0;
52989+
52990 if (screen_info.vesapm_seg) {
52991- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
52992- screen_info.vesapm_seg,screen_info.vesapm_off);
52993+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
52994+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
52995 }
52996
52997 if (screen_info.vesapm_seg < 0xc000)
52998@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
52999
53000 if (ypan || pmi_setpal) {
53001 unsigned short *pmi_base;
53002+
53003 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
53004- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
53005- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
53006+
53007+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53008+ pax_open_kernel();
53009+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
53010+#else
53011+ pmi_code = pmi_base;
53012+#endif
53013+
53014+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
53015+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
53016+
53017+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53018+ pmi_start = ktva_ktla(pmi_start);
53019+ pmi_pal = ktva_ktla(pmi_pal);
53020+ pax_close_kernel();
53021+#endif
53022+
53023 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
53024 if (pmi_base[3]) {
53025 printk(KERN_INFO "vesafb: pmi: ports = ");
53026@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
53027 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
53028 (ypan ? FBINFO_HWACCEL_YPAN : 0);
53029
53030- if (!ypan)
53031- info->fbops->fb_pan_display = NULL;
53032+ if (!ypan) {
53033+ pax_open_kernel();
53034+ *(void **)&info->fbops->fb_pan_display = NULL;
53035+ pax_close_kernel();
53036+ }
53037
53038 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
53039 err = -ENOMEM;
53040@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
53041 fb_info(info, "%s frame buffer device\n", info->fix.id);
53042 return 0;
53043 err:
53044+
53045+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53046+ module_free_exec(NULL, pmi_code);
53047+#endif
53048+
53049 if (info->screen_base)
53050 iounmap(info->screen_base);
53051 framebuffer_release(info);
53052diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
53053index 88714ae..16c2e11 100644
53054--- a/drivers/video/fbdev/via/via_clock.h
53055+++ b/drivers/video/fbdev/via/via_clock.h
53056@@ -56,7 +56,7 @@ struct via_clock {
53057
53058 void (*set_engine_pll_state)(u8 state);
53059 void (*set_engine_pll)(struct via_pll_config config);
53060-};
53061+} __no_const;
53062
53063
53064 static inline u32 get_pll_internal_frequency(u32 ref_freq,
53065diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53066index 3c14e43..2630570 100644
53067--- a/drivers/video/logo/logo_linux_clut224.ppm
53068+++ b/drivers/video/logo/logo_linux_clut224.ppm
53069@@ -2,1603 +2,1123 @@ P3
53070 # Standard 224-color Linux logo
53071 80 80
53072 255
53073- 0 0 0 0 0 0 0 0 0 0 0 0
53074- 0 0 0 0 0 0 0 0 0 0 0 0
53075- 0 0 0 0 0 0 0 0 0 0 0 0
53076- 0 0 0 0 0 0 0 0 0 0 0 0
53077- 0 0 0 0 0 0 0 0 0 0 0 0
53078- 0 0 0 0 0 0 0 0 0 0 0 0
53079- 0 0 0 0 0 0 0 0 0 0 0 0
53080- 0 0 0 0 0 0 0 0 0 0 0 0
53081- 0 0 0 0 0 0 0 0 0 0 0 0
53082- 6 6 6 6 6 6 10 10 10 10 10 10
53083- 10 10 10 6 6 6 6 6 6 6 6 6
53084- 0 0 0 0 0 0 0 0 0 0 0 0
53085- 0 0 0 0 0 0 0 0 0 0 0 0
53086- 0 0 0 0 0 0 0 0 0 0 0 0
53087- 0 0 0 0 0 0 0 0 0 0 0 0
53088- 0 0 0 0 0 0 0 0 0 0 0 0
53089- 0 0 0 0 0 0 0 0 0 0 0 0
53090- 0 0 0 0 0 0 0 0 0 0 0 0
53091- 0 0 0 0 0 0 0 0 0 0 0 0
53092- 0 0 0 0 0 0 0 0 0 0 0 0
53093- 0 0 0 0 0 0 0 0 0 0 0 0
53094- 0 0 0 0 0 0 0 0 0 0 0 0
53095- 0 0 0 0 0 0 0 0 0 0 0 0
53096- 0 0 0 0 0 0 0 0 0 0 0 0
53097- 0 0 0 0 0 0 0 0 0 0 0 0
53098- 0 0 0 0 0 0 0 0 0 0 0 0
53099- 0 0 0 0 0 0 0 0 0 0 0 0
53100- 0 0 0 0 0 0 0 0 0 0 0 0
53101- 0 0 0 6 6 6 10 10 10 14 14 14
53102- 22 22 22 26 26 26 30 30 30 34 34 34
53103- 30 30 30 30 30 30 26 26 26 18 18 18
53104- 14 14 14 10 10 10 6 6 6 0 0 0
53105- 0 0 0 0 0 0 0 0 0 0 0 0
53106- 0 0 0 0 0 0 0 0 0 0 0 0
53107- 0 0 0 0 0 0 0 0 0 0 0 0
53108- 0 0 0 0 0 0 0 0 0 0 0 0
53109- 0 0 0 0 0 0 0 0 0 0 0 0
53110- 0 0 0 0 0 0 0 0 0 0 0 0
53111- 0 0 0 0 0 0 0 0 0 0 0 0
53112- 0 0 0 0 0 0 0 0 0 0 0 0
53113- 0 0 0 0 0 0 0 0 0 0 0 0
53114- 0 0 0 0 0 1 0 0 1 0 0 0
53115- 0 0 0 0 0 0 0 0 0 0 0 0
53116- 0 0 0 0 0 0 0 0 0 0 0 0
53117- 0 0 0 0 0 0 0 0 0 0 0 0
53118- 0 0 0 0 0 0 0 0 0 0 0 0
53119- 0 0 0 0 0 0 0 0 0 0 0 0
53120- 0 0 0 0 0 0 0 0 0 0 0 0
53121- 6 6 6 14 14 14 26 26 26 42 42 42
53122- 54 54 54 66 66 66 78 78 78 78 78 78
53123- 78 78 78 74 74 74 66 66 66 54 54 54
53124- 42 42 42 26 26 26 18 18 18 10 10 10
53125- 6 6 6 0 0 0 0 0 0 0 0 0
53126- 0 0 0 0 0 0 0 0 0 0 0 0
53127- 0 0 0 0 0 0 0 0 0 0 0 0
53128- 0 0 0 0 0 0 0 0 0 0 0 0
53129- 0 0 0 0 0 0 0 0 0 0 0 0
53130- 0 0 0 0 0 0 0 0 0 0 0 0
53131- 0 0 0 0 0 0 0 0 0 0 0 0
53132- 0 0 0 0 0 0 0 0 0 0 0 0
53133- 0 0 0 0 0 0 0 0 0 0 0 0
53134- 0 0 1 0 0 0 0 0 0 0 0 0
53135- 0 0 0 0 0 0 0 0 0 0 0 0
53136- 0 0 0 0 0 0 0 0 0 0 0 0
53137- 0 0 0 0 0 0 0 0 0 0 0 0
53138- 0 0 0 0 0 0 0 0 0 0 0 0
53139- 0 0 0 0 0 0 0 0 0 0 0 0
53140- 0 0 0 0 0 0 0 0 0 10 10 10
53141- 22 22 22 42 42 42 66 66 66 86 86 86
53142- 66 66 66 38 38 38 38 38 38 22 22 22
53143- 26 26 26 34 34 34 54 54 54 66 66 66
53144- 86 86 86 70 70 70 46 46 46 26 26 26
53145- 14 14 14 6 6 6 0 0 0 0 0 0
53146- 0 0 0 0 0 0 0 0 0 0 0 0
53147- 0 0 0 0 0 0 0 0 0 0 0 0
53148- 0 0 0 0 0 0 0 0 0 0 0 0
53149- 0 0 0 0 0 0 0 0 0 0 0 0
53150- 0 0 0 0 0 0 0 0 0 0 0 0
53151- 0 0 0 0 0 0 0 0 0 0 0 0
53152- 0 0 0 0 0 0 0 0 0 0 0 0
53153- 0 0 0 0 0 0 0 0 0 0 0 0
53154- 0 0 1 0 0 1 0 0 1 0 0 0
53155- 0 0 0 0 0 0 0 0 0 0 0 0
53156- 0 0 0 0 0 0 0 0 0 0 0 0
53157- 0 0 0 0 0 0 0 0 0 0 0 0
53158- 0 0 0 0 0 0 0 0 0 0 0 0
53159- 0 0 0 0 0 0 0 0 0 0 0 0
53160- 0 0 0 0 0 0 10 10 10 26 26 26
53161- 50 50 50 82 82 82 58 58 58 6 6 6
53162- 2 2 6 2 2 6 2 2 6 2 2 6
53163- 2 2 6 2 2 6 2 2 6 2 2 6
53164- 6 6 6 54 54 54 86 86 86 66 66 66
53165- 38 38 38 18 18 18 6 6 6 0 0 0
53166- 0 0 0 0 0 0 0 0 0 0 0 0
53167- 0 0 0 0 0 0 0 0 0 0 0 0
53168- 0 0 0 0 0 0 0 0 0 0 0 0
53169- 0 0 0 0 0 0 0 0 0 0 0 0
53170- 0 0 0 0 0 0 0 0 0 0 0 0
53171- 0 0 0 0 0 0 0 0 0 0 0 0
53172- 0 0 0 0 0 0 0 0 0 0 0 0
53173- 0 0 0 0 0 0 0 0 0 0 0 0
53174- 0 0 0 0 0 0 0 0 0 0 0 0
53175- 0 0 0 0 0 0 0 0 0 0 0 0
53176- 0 0 0 0 0 0 0 0 0 0 0 0
53177- 0 0 0 0 0 0 0 0 0 0 0 0
53178- 0 0 0 0 0 0 0 0 0 0 0 0
53179- 0 0 0 0 0 0 0 0 0 0 0 0
53180- 0 0 0 6 6 6 22 22 22 50 50 50
53181- 78 78 78 34 34 34 2 2 6 2 2 6
53182- 2 2 6 2 2 6 2 2 6 2 2 6
53183- 2 2 6 2 2 6 2 2 6 2 2 6
53184- 2 2 6 2 2 6 6 6 6 70 70 70
53185- 78 78 78 46 46 46 22 22 22 6 6 6
53186- 0 0 0 0 0 0 0 0 0 0 0 0
53187- 0 0 0 0 0 0 0 0 0 0 0 0
53188- 0 0 0 0 0 0 0 0 0 0 0 0
53189- 0 0 0 0 0 0 0 0 0 0 0 0
53190- 0 0 0 0 0 0 0 0 0 0 0 0
53191- 0 0 0 0 0 0 0 0 0 0 0 0
53192- 0 0 0 0 0 0 0 0 0 0 0 0
53193- 0 0 0 0 0 0 0 0 0 0 0 0
53194- 0 0 1 0 0 1 0 0 1 0 0 0
53195- 0 0 0 0 0 0 0 0 0 0 0 0
53196- 0 0 0 0 0 0 0 0 0 0 0 0
53197- 0 0 0 0 0 0 0 0 0 0 0 0
53198- 0 0 0 0 0 0 0 0 0 0 0 0
53199- 0 0 0 0 0 0 0 0 0 0 0 0
53200- 6 6 6 18 18 18 42 42 42 82 82 82
53201- 26 26 26 2 2 6 2 2 6 2 2 6
53202- 2 2 6 2 2 6 2 2 6 2 2 6
53203- 2 2 6 2 2 6 2 2 6 14 14 14
53204- 46 46 46 34 34 34 6 6 6 2 2 6
53205- 42 42 42 78 78 78 42 42 42 18 18 18
53206- 6 6 6 0 0 0 0 0 0 0 0 0
53207- 0 0 0 0 0 0 0 0 0 0 0 0
53208- 0 0 0 0 0 0 0 0 0 0 0 0
53209- 0 0 0 0 0 0 0 0 0 0 0 0
53210- 0 0 0 0 0 0 0 0 0 0 0 0
53211- 0 0 0 0 0 0 0 0 0 0 0 0
53212- 0 0 0 0 0 0 0 0 0 0 0 0
53213- 0 0 0 0 0 0 0 0 0 0 0 0
53214- 0 0 1 0 0 0 0 0 1 0 0 0
53215- 0 0 0 0 0 0 0 0 0 0 0 0
53216- 0 0 0 0 0 0 0 0 0 0 0 0
53217- 0 0 0 0 0 0 0 0 0 0 0 0
53218- 0 0 0 0 0 0 0 0 0 0 0 0
53219- 0 0 0 0 0 0 0 0 0 0 0 0
53220- 10 10 10 30 30 30 66 66 66 58 58 58
53221- 2 2 6 2 2 6 2 2 6 2 2 6
53222- 2 2 6 2 2 6 2 2 6 2 2 6
53223- 2 2 6 2 2 6 2 2 6 26 26 26
53224- 86 86 86 101 101 101 46 46 46 10 10 10
53225- 2 2 6 58 58 58 70 70 70 34 34 34
53226- 10 10 10 0 0 0 0 0 0 0 0 0
53227- 0 0 0 0 0 0 0 0 0 0 0 0
53228- 0 0 0 0 0 0 0 0 0 0 0 0
53229- 0 0 0 0 0 0 0 0 0 0 0 0
53230- 0 0 0 0 0 0 0 0 0 0 0 0
53231- 0 0 0 0 0 0 0 0 0 0 0 0
53232- 0 0 0 0 0 0 0 0 0 0 0 0
53233- 0 0 0 0 0 0 0 0 0 0 0 0
53234- 0 0 1 0 0 1 0 0 1 0 0 0
53235- 0 0 0 0 0 0 0 0 0 0 0 0
53236- 0 0 0 0 0 0 0 0 0 0 0 0
53237- 0 0 0 0 0 0 0 0 0 0 0 0
53238- 0 0 0 0 0 0 0 0 0 0 0 0
53239- 0 0 0 0 0 0 0 0 0 0 0 0
53240- 14 14 14 42 42 42 86 86 86 10 10 10
53241- 2 2 6 2 2 6 2 2 6 2 2 6
53242- 2 2 6 2 2 6 2 2 6 2 2 6
53243- 2 2 6 2 2 6 2 2 6 30 30 30
53244- 94 94 94 94 94 94 58 58 58 26 26 26
53245- 2 2 6 6 6 6 78 78 78 54 54 54
53246- 22 22 22 6 6 6 0 0 0 0 0 0
53247- 0 0 0 0 0 0 0 0 0 0 0 0
53248- 0 0 0 0 0 0 0 0 0 0 0 0
53249- 0 0 0 0 0 0 0 0 0 0 0 0
53250- 0 0 0 0 0 0 0 0 0 0 0 0
53251- 0 0 0 0 0 0 0 0 0 0 0 0
53252- 0 0 0 0 0 0 0 0 0 0 0 0
53253- 0 0 0 0 0 0 0 0 0 0 0 0
53254- 0 0 0 0 0 0 0 0 0 0 0 0
53255- 0 0 0 0 0 0 0 0 0 0 0 0
53256- 0 0 0 0 0 0 0 0 0 0 0 0
53257- 0 0 0 0 0 0 0 0 0 0 0 0
53258- 0 0 0 0 0 0 0 0 0 0 0 0
53259- 0 0 0 0 0 0 0 0 0 6 6 6
53260- 22 22 22 62 62 62 62 62 62 2 2 6
53261- 2 2 6 2 2 6 2 2 6 2 2 6
53262- 2 2 6 2 2 6 2 2 6 2 2 6
53263- 2 2 6 2 2 6 2 2 6 26 26 26
53264- 54 54 54 38 38 38 18 18 18 10 10 10
53265- 2 2 6 2 2 6 34 34 34 82 82 82
53266- 38 38 38 14 14 14 0 0 0 0 0 0
53267- 0 0 0 0 0 0 0 0 0 0 0 0
53268- 0 0 0 0 0 0 0 0 0 0 0 0
53269- 0 0 0 0 0 0 0 0 0 0 0 0
53270- 0 0 0 0 0 0 0 0 0 0 0 0
53271- 0 0 0 0 0 0 0 0 0 0 0 0
53272- 0 0 0 0 0 0 0 0 0 0 0 0
53273- 0 0 0 0 0 0 0 0 0 0 0 0
53274- 0 0 0 0 0 1 0 0 1 0 0 0
53275- 0 0 0 0 0 0 0 0 0 0 0 0
53276- 0 0 0 0 0 0 0 0 0 0 0 0
53277- 0 0 0 0 0 0 0 0 0 0 0 0
53278- 0 0 0 0 0 0 0 0 0 0 0 0
53279- 0 0 0 0 0 0 0 0 0 6 6 6
53280- 30 30 30 78 78 78 30 30 30 2 2 6
53281- 2 2 6 2 2 6 2 2 6 2 2 6
53282- 2 2 6 2 2 6 2 2 6 2 2 6
53283- 2 2 6 2 2 6 2 2 6 10 10 10
53284- 10 10 10 2 2 6 2 2 6 2 2 6
53285- 2 2 6 2 2 6 2 2 6 78 78 78
53286- 50 50 50 18 18 18 6 6 6 0 0 0
53287- 0 0 0 0 0 0 0 0 0 0 0 0
53288- 0 0 0 0 0 0 0 0 0 0 0 0
53289- 0 0 0 0 0 0 0 0 0 0 0 0
53290- 0 0 0 0 0 0 0 0 0 0 0 0
53291- 0 0 0 0 0 0 0 0 0 0 0 0
53292- 0 0 0 0 0 0 0 0 0 0 0 0
53293- 0 0 0 0 0 0 0 0 0 0 0 0
53294- 0 0 1 0 0 0 0 0 0 0 0 0
53295- 0 0 0 0 0 0 0 0 0 0 0 0
53296- 0 0 0 0 0 0 0 0 0 0 0 0
53297- 0 0 0 0 0 0 0 0 0 0 0 0
53298- 0 0 0 0 0 0 0 0 0 0 0 0
53299- 0 0 0 0 0 0 0 0 0 10 10 10
53300- 38 38 38 86 86 86 14 14 14 2 2 6
53301- 2 2 6 2 2 6 2 2 6 2 2 6
53302- 2 2 6 2 2 6 2 2 6 2 2 6
53303- 2 2 6 2 2 6 2 2 6 2 2 6
53304- 2 2 6 2 2 6 2 2 6 2 2 6
53305- 2 2 6 2 2 6 2 2 6 54 54 54
53306- 66 66 66 26 26 26 6 6 6 0 0 0
53307- 0 0 0 0 0 0 0 0 0 0 0 0
53308- 0 0 0 0 0 0 0 0 0 0 0 0
53309- 0 0 0 0 0 0 0 0 0 0 0 0
53310- 0 0 0 0 0 0 0 0 0 0 0 0
53311- 0 0 0 0 0 0 0 0 0 0 0 0
53312- 0 0 0 0 0 0 0 0 0 0 0 0
53313- 0 0 0 0 0 0 0 0 0 0 0 0
53314- 0 0 0 0 0 1 0 0 1 0 0 0
53315- 0 0 0 0 0 0 0 0 0 0 0 0
53316- 0 0 0 0 0 0 0 0 0 0 0 0
53317- 0 0 0 0 0 0 0 0 0 0 0 0
53318- 0 0 0 0 0 0 0 0 0 0 0 0
53319- 0 0 0 0 0 0 0 0 0 14 14 14
53320- 42 42 42 82 82 82 2 2 6 2 2 6
53321- 2 2 6 6 6 6 10 10 10 2 2 6
53322- 2 2 6 2 2 6 2 2 6 2 2 6
53323- 2 2 6 2 2 6 2 2 6 6 6 6
53324- 14 14 14 10 10 10 2 2 6 2 2 6
53325- 2 2 6 2 2 6 2 2 6 18 18 18
53326- 82 82 82 34 34 34 10 10 10 0 0 0
53327- 0 0 0 0 0 0 0 0 0 0 0 0
53328- 0 0 0 0 0 0 0 0 0 0 0 0
53329- 0 0 0 0 0 0 0 0 0 0 0 0
53330- 0 0 0 0 0 0 0 0 0 0 0 0
53331- 0 0 0 0 0 0 0 0 0 0 0 0
53332- 0 0 0 0 0 0 0 0 0 0 0 0
53333- 0 0 0 0 0 0 0 0 0 0 0 0
53334- 0 0 1 0 0 0 0 0 0 0 0 0
53335- 0 0 0 0 0 0 0 0 0 0 0 0
53336- 0 0 0 0 0 0 0 0 0 0 0 0
53337- 0 0 0 0 0 0 0 0 0 0 0 0
53338- 0 0 0 0 0 0 0 0 0 0 0 0
53339- 0 0 0 0 0 0 0 0 0 14 14 14
53340- 46 46 46 86 86 86 2 2 6 2 2 6
53341- 6 6 6 6 6 6 22 22 22 34 34 34
53342- 6 6 6 2 2 6 2 2 6 2 2 6
53343- 2 2 6 2 2 6 18 18 18 34 34 34
53344- 10 10 10 50 50 50 22 22 22 2 2 6
53345- 2 2 6 2 2 6 2 2 6 10 10 10
53346- 86 86 86 42 42 42 14 14 14 0 0 0
53347- 0 0 0 0 0 0 0 0 0 0 0 0
53348- 0 0 0 0 0 0 0 0 0 0 0 0
53349- 0 0 0 0 0 0 0 0 0 0 0 0
53350- 0 0 0 0 0 0 0 0 0 0 0 0
53351- 0 0 0 0 0 0 0 0 0 0 0 0
53352- 0 0 0 0 0 0 0 0 0 0 0 0
53353- 0 0 0 0 0 0 0 0 0 0 0 0
53354- 0 0 1 0 0 1 0 0 1 0 0 0
53355- 0 0 0 0 0 0 0 0 0 0 0 0
53356- 0 0 0 0 0 0 0 0 0 0 0 0
53357- 0 0 0 0 0 0 0 0 0 0 0 0
53358- 0 0 0 0 0 0 0 0 0 0 0 0
53359- 0 0 0 0 0 0 0 0 0 14 14 14
53360- 46 46 46 86 86 86 2 2 6 2 2 6
53361- 38 38 38 116 116 116 94 94 94 22 22 22
53362- 22 22 22 2 2 6 2 2 6 2 2 6
53363- 14 14 14 86 86 86 138 138 138 162 162 162
53364-154 154 154 38 38 38 26 26 26 6 6 6
53365- 2 2 6 2 2 6 2 2 6 2 2 6
53366- 86 86 86 46 46 46 14 14 14 0 0 0
53367- 0 0 0 0 0 0 0 0 0 0 0 0
53368- 0 0 0 0 0 0 0 0 0 0 0 0
53369- 0 0 0 0 0 0 0 0 0 0 0 0
53370- 0 0 0 0 0 0 0 0 0 0 0 0
53371- 0 0 0 0 0 0 0 0 0 0 0 0
53372- 0 0 0 0 0 0 0 0 0 0 0 0
53373- 0 0 0 0 0 0 0 0 0 0 0 0
53374- 0 0 0 0 0 0 0 0 0 0 0 0
53375- 0 0 0 0 0 0 0 0 0 0 0 0
53376- 0 0 0 0 0 0 0 0 0 0 0 0
53377- 0 0 0 0 0 0 0 0 0 0 0 0
53378- 0 0 0 0 0 0 0 0 0 0 0 0
53379- 0 0 0 0 0 0 0 0 0 14 14 14
53380- 46 46 46 86 86 86 2 2 6 14 14 14
53381-134 134 134 198 198 198 195 195 195 116 116 116
53382- 10 10 10 2 2 6 2 2 6 6 6 6
53383-101 98 89 187 187 187 210 210 210 218 218 218
53384-214 214 214 134 134 134 14 14 14 6 6 6
53385- 2 2 6 2 2 6 2 2 6 2 2 6
53386- 86 86 86 50 50 50 18 18 18 6 6 6
53387- 0 0 0 0 0 0 0 0 0 0 0 0
53388- 0 0 0 0 0 0 0 0 0 0 0 0
53389- 0 0 0 0 0 0 0 0 0 0 0 0
53390- 0 0 0 0 0 0 0 0 0 0 0 0
53391- 0 0 0 0 0 0 0 0 0 0 0 0
53392- 0 0 0 0 0 0 0 0 0 0 0 0
53393- 0 0 0 0 0 0 0 0 1 0 0 0
53394- 0 0 1 0 0 1 0 0 1 0 0 0
53395- 0 0 0 0 0 0 0 0 0 0 0 0
53396- 0 0 0 0 0 0 0 0 0 0 0 0
53397- 0 0 0 0 0 0 0 0 0 0 0 0
53398- 0 0 0 0 0 0 0 0 0 0 0 0
53399- 0 0 0 0 0 0 0 0 0 14 14 14
53400- 46 46 46 86 86 86 2 2 6 54 54 54
53401-218 218 218 195 195 195 226 226 226 246 246 246
53402- 58 58 58 2 2 6 2 2 6 30 30 30
53403-210 210 210 253 253 253 174 174 174 123 123 123
53404-221 221 221 234 234 234 74 74 74 2 2 6
53405- 2 2 6 2 2 6 2 2 6 2 2 6
53406- 70 70 70 58 58 58 22 22 22 6 6 6
53407- 0 0 0 0 0 0 0 0 0 0 0 0
53408- 0 0 0 0 0 0 0 0 0 0 0 0
53409- 0 0 0 0 0 0 0 0 0 0 0 0
53410- 0 0 0 0 0 0 0 0 0 0 0 0
53411- 0 0 0 0 0 0 0 0 0 0 0 0
53412- 0 0 0 0 0 0 0 0 0 0 0 0
53413- 0 0 0 0 0 0 0 0 0 0 0 0
53414- 0 0 0 0 0 0 0 0 0 0 0 0
53415- 0 0 0 0 0 0 0 0 0 0 0 0
53416- 0 0 0 0 0 0 0 0 0 0 0 0
53417- 0 0 0 0 0 0 0 0 0 0 0 0
53418- 0 0 0 0 0 0 0 0 0 0 0 0
53419- 0 0 0 0 0 0 0 0 0 14 14 14
53420- 46 46 46 82 82 82 2 2 6 106 106 106
53421-170 170 170 26 26 26 86 86 86 226 226 226
53422-123 123 123 10 10 10 14 14 14 46 46 46
53423-231 231 231 190 190 190 6 6 6 70 70 70
53424- 90 90 90 238 238 238 158 158 158 2 2 6
53425- 2 2 6 2 2 6 2 2 6 2 2 6
53426- 70 70 70 58 58 58 22 22 22 6 6 6
53427- 0 0 0 0 0 0 0 0 0 0 0 0
53428- 0 0 0 0 0 0 0 0 0 0 0 0
53429- 0 0 0 0 0 0 0 0 0 0 0 0
53430- 0 0 0 0 0 0 0 0 0 0 0 0
53431- 0 0 0 0 0 0 0 0 0 0 0 0
53432- 0 0 0 0 0 0 0 0 0 0 0 0
53433- 0 0 0 0 0 0 0 0 1 0 0 0
53434- 0 0 1 0 0 1 0 0 1 0 0 0
53435- 0 0 0 0 0 0 0 0 0 0 0 0
53436- 0 0 0 0 0 0 0 0 0 0 0 0
53437- 0 0 0 0 0 0 0 0 0 0 0 0
53438- 0 0 0 0 0 0 0 0 0 0 0 0
53439- 0 0 0 0 0 0 0 0 0 14 14 14
53440- 42 42 42 86 86 86 6 6 6 116 116 116
53441-106 106 106 6 6 6 70 70 70 149 149 149
53442-128 128 128 18 18 18 38 38 38 54 54 54
53443-221 221 221 106 106 106 2 2 6 14 14 14
53444- 46 46 46 190 190 190 198 198 198 2 2 6
53445- 2 2 6 2 2 6 2 2 6 2 2 6
53446- 74 74 74 62 62 62 22 22 22 6 6 6
53447- 0 0 0 0 0 0 0 0 0 0 0 0
53448- 0 0 0 0 0 0 0 0 0 0 0 0
53449- 0 0 0 0 0 0 0 0 0 0 0 0
53450- 0 0 0 0 0 0 0 0 0 0 0 0
53451- 0 0 0 0 0 0 0 0 0 0 0 0
53452- 0 0 0 0 0 0 0 0 0 0 0 0
53453- 0 0 0 0 0 0 0 0 1 0 0 0
53454- 0 0 1 0 0 0 0 0 1 0 0 0
53455- 0 0 0 0 0 0 0 0 0 0 0 0
53456- 0 0 0 0 0 0 0 0 0 0 0 0
53457- 0 0 0 0 0 0 0 0 0 0 0 0
53458- 0 0 0 0 0 0 0 0 0 0 0 0
53459- 0 0 0 0 0 0 0 0 0 14 14 14
53460- 42 42 42 94 94 94 14 14 14 101 101 101
53461-128 128 128 2 2 6 18 18 18 116 116 116
53462-118 98 46 121 92 8 121 92 8 98 78 10
53463-162 162 162 106 106 106 2 2 6 2 2 6
53464- 2 2 6 195 195 195 195 195 195 6 6 6
53465- 2 2 6 2 2 6 2 2 6 2 2 6
53466- 74 74 74 62 62 62 22 22 22 6 6 6
53467- 0 0 0 0 0 0 0 0 0 0 0 0
53468- 0 0 0 0 0 0 0 0 0 0 0 0
53469- 0 0 0 0 0 0 0 0 0 0 0 0
53470- 0 0 0 0 0 0 0 0 0 0 0 0
53471- 0 0 0 0 0 0 0 0 0 0 0 0
53472- 0 0 0 0 0 0 0 0 0 0 0 0
53473- 0 0 0 0 0 0 0 0 1 0 0 1
53474- 0 0 1 0 0 0 0 0 1 0 0 0
53475- 0 0 0 0 0 0 0 0 0 0 0 0
53476- 0 0 0 0 0 0 0 0 0 0 0 0
53477- 0 0 0 0 0 0 0 0 0 0 0 0
53478- 0 0 0 0 0 0 0 0 0 0 0 0
53479- 0 0 0 0 0 0 0 0 0 10 10 10
53480- 38 38 38 90 90 90 14 14 14 58 58 58
53481-210 210 210 26 26 26 54 38 6 154 114 10
53482-226 170 11 236 186 11 225 175 15 184 144 12
53483-215 174 15 175 146 61 37 26 9 2 2 6
53484- 70 70 70 246 246 246 138 138 138 2 2 6
53485- 2 2 6 2 2 6 2 2 6 2 2 6
53486- 70 70 70 66 66 66 26 26 26 6 6 6
53487- 0 0 0 0 0 0 0 0 0 0 0 0
53488- 0 0 0 0 0 0 0 0 0 0 0 0
53489- 0 0 0 0 0 0 0 0 0 0 0 0
53490- 0 0 0 0 0 0 0 0 0 0 0 0
53491- 0 0 0 0 0 0 0 0 0 0 0 0
53492- 0 0 0 0 0 0 0 0 0 0 0 0
53493- 0 0 0 0 0 0 0 0 0 0 0 0
53494- 0 0 0 0 0 0 0 0 0 0 0 0
53495- 0 0 0 0 0 0 0 0 0 0 0 0
53496- 0 0 0 0 0 0 0 0 0 0 0 0
53497- 0 0 0 0 0 0 0 0 0 0 0 0
53498- 0 0 0 0 0 0 0 0 0 0 0 0
53499- 0 0 0 0 0 0 0 0 0 10 10 10
53500- 38 38 38 86 86 86 14 14 14 10 10 10
53501-195 195 195 188 164 115 192 133 9 225 175 15
53502-239 182 13 234 190 10 232 195 16 232 200 30
53503-245 207 45 241 208 19 232 195 16 184 144 12
53504-218 194 134 211 206 186 42 42 42 2 2 6
53505- 2 2 6 2 2 6 2 2 6 2 2 6
53506- 50 50 50 74 74 74 30 30 30 6 6 6
53507- 0 0 0 0 0 0 0 0 0 0 0 0
53508- 0 0 0 0 0 0 0 0 0 0 0 0
53509- 0 0 0 0 0 0 0 0 0 0 0 0
53510- 0 0 0 0 0 0 0 0 0 0 0 0
53511- 0 0 0 0 0 0 0 0 0 0 0 0
53512- 0 0 0 0 0 0 0 0 0 0 0 0
53513- 0 0 0 0 0 0 0 0 0 0 0 0
53514- 0 0 0 0 0 0 0 0 0 0 0 0
53515- 0 0 0 0 0 0 0 0 0 0 0 0
53516- 0 0 0 0 0 0 0 0 0 0 0 0
53517- 0 0 0 0 0 0 0 0 0 0 0 0
53518- 0 0 0 0 0 0 0 0 0 0 0 0
53519- 0 0 0 0 0 0 0 0 0 10 10 10
53520- 34 34 34 86 86 86 14 14 14 2 2 6
53521-121 87 25 192 133 9 219 162 10 239 182 13
53522-236 186 11 232 195 16 241 208 19 244 214 54
53523-246 218 60 246 218 38 246 215 20 241 208 19
53524-241 208 19 226 184 13 121 87 25 2 2 6
53525- 2 2 6 2 2 6 2 2 6 2 2 6
53526- 50 50 50 82 82 82 34 34 34 10 10 10
53527- 0 0 0 0 0 0 0 0 0 0 0 0
53528- 0 0 0 0 0 0 0 0 0 0 0 0
53529- 0 0 0 0 0 0 0 0 0 0 0 0
53530- 0 0 0 0 0 0 0 0 0 0 0 0
53531- 0 0 0 0 0 0 0 0 0 0 0 0
53532- 0 0 0 0 0 0 0 0 0 0 0 0
53533- 0 0 0 0 0 0 0 0 0 0 0 0
53534- 0 0 0 0 0 0 0 0 0 0 0 0
53535- 0 0 0 0 0 0 0 0 0 0 0 0
53536- 0 0 0 0 0 0 0 0 0 0 0 0
53537- 0 0 0 0 0 0 0 0 0 0 0 0
53538- 0 0 0 0 0 0 0 0 0 0 0 0
53539- 0 0 0 0 0 0 0 0 0 10 10 10
53540- 34 34 34 82 82 82 30 30 30 61 42 6
53541-180 123 7 206 145 10 230 174 11 239 182 13
53542-234 190 10 238 202 15 241 208 19 246 218 74
53543-246 218 38 246 215 20 246 215 20 246 215 20
53544-226 184 13 215 174 15 184 144 12 6 6 6
53545- 2 2 6 2 2 6 2 2 6 2 2 6
53546- 26 26 26 94 94 94 42 42 42 14 14 14
53547- 0 0 0 0 0 0 0 0 0 0 0 0
53548- 0 0 0 0 0 0 0 0 0 0 0 0
53549- 0 0 0 0 0 0 0 0 0 0 0 0
53550- 0 0 0 0 0 0 0 0 0 0 0 0
53551- 0 0 0 0 0 0 0 0 0 0 0 0
53552- 0 0 0 0 0 0 0 0 0 0 0 0
53553- 0 0 0 0 0 0 0 0 0 0 0 0
53554- 0 0 0 0 0 0 0 0 0 0 0 0
53555- 0 0 0 0 0 0 0 0 0 0 0 0
53556- 0 0 0 0 0 0 0 0 0 0 0 0
53557- 0 0 0 0 0 0 0 0 0 0 0 0
53558- 0 0 0 0 0 0 0 0 0 0 0 0
53559- 0 0 0 0 0 0 0 0 0 10 10 10
53560- 30 30 30 78 78 78 50 50 50 104 69 6
53561-192 133 9 216 158 10 236 178 12 236 186 11
53562-232 195 16 241 208 19 244 214 54 245 215 43
53563-246 215 20 246 215 20 241 208 19 198 155 10
53564-200 144 11 216 158 10 156 118 10 2 2 6
53565- 2 2 6 2 2 6 2 2 6 2 2 6
53566- 6 6 6 90 90 90 54 54 54 18 18 18
53567- 6 6 6 0 0 0 0 0 0 0 0 0
53568- 0 0 0 0 0 0 0 0 0 0 0 0
53569- 0 0 0 0 0 0 0 0 0 0 0 0
53570- 0 0 0 0 0 0 0 0 0 0 0 0
53571- 0 0 0 0 0 0 0 0 0 0 0 0
53572- 0 0 0 0 0 0 0 0 0 0 0 0
53573- 0 0 0 0 0 0 0 0 0 0 0 0
53574- 0 0 0 0 0 0 0 0 0 0 0 0
53575- 0 0 0 0 0 0 0 0 0 0 0 0
53576- 0 0 0 0 0 0 0 0 0 0 0 0
53577- 0 0 0 0 0 0 0 0 0 0 0 0
53578- 0 0 0 0 0 0 0 0 0 0 0 0
53579- 0 0 0 0 0 0 0 0 0 10 10 10
53580- 30 30 30 78 78 78 46 46 46 22 22 22
53581-137 92 6 210 162 10 239 182 13 238 190 10
53582-238 202 15 241 208 19 246 215 20 246 215 20
53583-241 208 19 203 166 17 185 133 11 210 150 10
53584-216 158 10 210 150 10 102 78 10 2 2 6
53585- 6 6 6 54 54 54 14 14 14 2 2 6
53586- 2 2 6 62 62 62 74 74 74 30 30 30
53587- 10 10 10 0 0 0 0 0 0 0 0 0
53588- 0 0 0 0 0 0 0 0 0 0 0 0
53589- 0 0 0 0 0 0 0 0 0 0 0 0
53590- 0 0 0 0 0 0 0 0 0 0 0 0
53591- 0 0 0 0 0 0 0 0 0 0 0 0
53592- 0 0 0 0 0 0 0 0 0 0 0 0
53593- 0 0 0 0 0 0 0 0 0 0 0 0
53594- 0 0 0 0 0 0 0 0 0 0 0 0
53595- 0 0 0 0 0 0 0 0 0 0 0 0
53596- 0 0 0 0 0 0 0 0 0 0 0 0
53597- 0 0 0 0 0 0 0 0 0 0 0 0
53598- 0 0 0 0 0 0 0 0 0 0 0 0
53599- 0 0 0 0 0 0 0 0 0 10 10 10
53600- 34 34 34 78 78 78 50 50 50 6 6 6
53601- 94 70 30 139 102 15 190 146 13 226 184 13
53602-232 200 30 232 195 16 215 174 15 190 146 13
53603-168 122 10 192 133 9 210 150 10 213 154 11
53604-202 150 34 182 157 106 101 98 89 2 2 6
53605- 2 2 6 78 78 78 116 116 116 58 58 58
53606- 2 2 6 22 22 22 90 90 90 46 46 46
53607- 18 18 18 6 6 6 0 0 0 0 0 0
53608- 0 0 0 0 0 0 0 0 0 0 0 0
53609- 0 0 0 0 0 0 0 0 0 0 0 0
53610- 0 0 0 0 0 0 0 0 0 0 0 0
53611- 0 0 0 0 0 0 0 0 0 0 0 0
53612- 0 0 0 0 0 0 0 0 0 0 0 0
53613- 0 0 0 0 0 0 0 0 0 0 0 0
53614- 0 0 0 0 0 0 0 0 0 0 0 0
53615- 0 0 0 0 0 0 0 0 0 0 0 0
53616- 0 0 0 0 0 0 0 0 0 0 0 0
53617- 0 0 0 0 0 0 0 0 0 0 0 0
53618- 0 0 0 0 0 0 0 0 0 0 0 0
53619- 0 0 0 0 0 0 0 0 0 10 10 10
53620- 38 38 38 86 86 86 50 50 50 6 6 6
53621-128 128 128 174 154 114 156 107 11 168 122 10
53622-198 155 10 184 144 12 197 138 11 200 144 11
53623-206 145 10 206 145 10 197 138 11 188 164 115
53624-195 195 195 198 198 198 174 174 174 14 14 14
53625- 2 2 6 22 22 22 116 116 116 116 116 116
53626- 22 22 22 2 2 6 74 74 74 70 70 70
53627- 30 30 30 10 10 10 0 0 0 0 0 0
53628- 0 0 0 0 0 0 0 0 0 0 0 0
53629- 0 0 0 0 0 0 0 0 0 0 0 0
53630- 0 0 0 0 0 0 0 0 0 0 0 0
53631- 0 0 0 0 0 0 0 0 0 0 0 0
53632- 0 0 0 0 0 0 0 0 0 0 0 0
53633- 0 0 0 0 0 0 0 0 0 0 0 0
53634- 0 0 0 0 0 0 0 0 0 0 0 0
53635- 0 0 0 0 0 0 0 0 0 0 0 0
53636- 0 0 0 0 0 0 0 0 0 0 0 0
53637- 0 0 0 0 0 0 0 0 0 0 0 0
53638- 0 0 0 0 0 0 0 0 0 0 0 0
53639- 0 0 0 0 0 0 6 6 6 18 18 18
53640- 50 50 50 101 101 101 26 26 26 10 10 10
53641-138 138 138 190 190 190 174 154 114 156 107 11
53642-197 138 11 200 144 11 197 138 11 192 133 9
53643-180 123 7 190 142 34 190 178 144 187 187 187
53644-202 202 202 221 221 221 214 214 214 66 66 66
53645- 2 2 6 2 2 6 50 50 50 62 62 62
53646- 6 6 6 2 2 6 10 10 10 90 90 90
53647- 50 50 50 18 18 18 6 6 6 0 0 0
53648- 0 0 0 0 0 0 0 0 0 0 0 0
53649- 0 0 0 0 0 0 0 0 0 0 0 0
53650- 0 0 0 0 0 0 0 0 0 0 0 0
53651- 0 0 0 0 0 0 0 0 0 0 0 0
53652- 0 0 0 0 0 0 0 0 0 0 0 0
53653- 0 0 0 0 0 0 0 0 0 0 0 0
53654- 0 0 0 0 0 0 0 0 0 0 0 0
53655- 0 0 0 0 0 0 0 0 0 0 0 0
53656- 0 0 0 0 0 0 0 0 0 0 0 0
53657- 0 0 0 0 0 0 0 0 0 0 0 0
53658- 0 0 0 0 0 0 0 0 0 0 0 0
53659- 0 0 0 0 0 0 10 10 10 34 34 34
53660- 74 74 74 74 74 74 2 2 6 6 6 6
53661-144 144 144 198 198 198 190 190 190 178 166 146
53662-154 121 60 156 107 11 156 107 11 168 124 44
53663-174 154 114 187 187 187 190 190 190 210 210 210
53664-246 246 246 253 253 253 253 253 253 182 182 182
53665- 6 6 6 2 2 6 2 2 6 2 2 6
53666- 2 2 6 2 2 6 2 2 6 62 62 62
53667- 74 74 74 34 34 34 14 14 14 0 0 0
53668- 0 0 0 0 0 0 0 0 0 0 0 0
53669- 0 0 0 0 0 0 0 0 0 0 0 0
53670- 0 0 0 0 0 0 0 0 0 0 0 0
53671- 0 0 0 0 0 0 0 0 0 0 0 0
53672- 0 0 0 0 0 0 0 0 0 0 0 0
53673- 0 0 0 0 0 0 0 0 0 0 0 0
53674- 0 0 0 0 0 0 0 0 0 0 0 0
53675- 0 0 0 0 0 0 0 0 0 0 0 0
53676- 0 0 0 0 0 0 0 0 0 0 0 0
53677- 0 0 0 0 0 0 0 0 0 0 0 0
53678- 0 0 0 0 0 0 0 0 0 0 0 0
53679- 0 0 0 10 10 10 22 22 22 54 54 54
53680- 94 94 94 18 18 18 2 2 6 46 46 46
53681-234 234 234 221 221 221 190 190 190 190 190 190
53682-190 190 190 187 187 187 187 187 187 190 190 190
53683-190 190 190 195 195 195 214 214 214 242 242 242
53684-253 253 253 253 253 253 253 253 253 253 253 253
53685- 82 82 82 2 2 6 2 2 6 2 2 6
53686- 2 2 6 2 2 6 2 2 6 14 14 14
53687- 86 86 86 54 54 54 22 22 22 6 6 6
53688- 0 0 0 0 0 0 0 0 0 0 0 0
53689- 0 0 0 0 0 0 0 0 0 0 0 0
53690- 0 0 0 0 0 0 0 0 0 0 0 0
53691- 0 0 0 0 0 0 0 0 0 0 0 0
53692- 0 0 0 0 0 0 0 0 0 0 0 0
53693- 0 0 0 0 0 0 0 0 0 0 0 0
53694- 0 0 0 0 0 0 0 0 0 0 0 0
53695- 0 0 0 0 0 0 0 0 0 0 0 0
53696- 0 0 0 0 0 0 0 0 0 0 0 0
53697- 0 0 0 0 0 0 0 0 0 0 0 0
53698- 0 0 0 0 0 0 0 0 0 0 0 0
53699- 6 6 6 18 18 18 46 46 46 90 90 90
53700- 46 46 46 18 18 18 6 6 6 182 182 182
53701-253 253 253 246 246 246 206 206 206 190 190 190
53702-190 190 190 190 190 190 190 190 190 190 190 190
53703-206 206 206 231 231 231 250 250 250 253 253 253
53704-253 253 253 253 253 253 253 253 253 253 253 253
53705-202 202 202 14 14 14 2 2 6 2 2 6
53706- 2 2 6 2 2 6 2 2 6 2 2 6
53707- 42 42 42 86 86 86 42 42 42 18 18 18
53708- 6 6 6 0 0 0 0 0 0 0 0 0
53709- 0 0 0 0 0 0 0 0 0 0 0 0
53710- 0 0 0 0 0 0 0 0 0 0 0 0
53711- 0 0 0 0 0 0 0 0 0 0 0 0
53712- 0 0 0 0 0 0 0 0 0 0 0 0
53713- 0 0 0 0 0 0 0 0 0 0 0 0
53714- 0 0 0 0 0 0 0 0 0 0 0 0
53715- 0 0 0 0 0 0 0 0 0 0 0 0
53716- 0 0 0 0 0 0 0 0 0 0 0 0
53717- 0 0 0 0 0 0 0 0 0 0 0 0
53718- 0 0 0 0 0 0 0 0 0 6 6 6
53719- 14 14 14 38 38 38 74 74 74 66 66 66
53720- 2 2 6 6 6 6 90 90 90 250 250 250
53721-253 253 253 253 253 253 238 238 238 198 198 198
53722-190 190 190 190 190 190 195 195 195 221 221 221
53723-246 246 246 253 253 253 253 253 253 253 253 253
53724-253 253 253 253 253 253 253 253 253 253 253 253
53725-253 253 253 82 82 82 2 2 6 2 2 6
53726- 2 2 6 2 2 6 2 2 6 2 2 6
53727- 2 2 6 78 78 78 70 70 70 34 34 34
53728- 14 14 14 6 6 6 0 0 0 0 0 0
53729- 0 0 0 0 0 0 0 0 0 0 0 0
53730- 0 0 0 0 0 0 0 0 0 0 0 0
53731- 0 0 0 0 0 0 0 0 0 0 0 0
53732- 0 0 0 0 0 0 0 0 0 0 0 0
53733- 0 0 0 0 0 0 0 0 0 0 0 0
53734- 0 0 0 0 0 0 0 0 0 0 0 0
53735- 0 0 0 0 0 0 0 0 0 0 0 0
53736- 0 0 0 0 0 0 0 0 0 0 0 0
53737- 0 0 0 0 0 0 0 0 0 0 0 0
53738- 0 0 0 0 0 0 0 0 0 14 14 14
53739- 34 34 34 66 66 66 78 78 78 6 6 6
53740- 2 2 6 18 18 18 218 218 218 253 253 253
53741-253 253 253 253 253 253 253 253 253 246 246 246
53742-226 226 226 231 231 231 246 246 246 253 253 253
53743-253 253 253 253 253 253 253 253 253 253 253 253
53744-253 253 253 253 253 253 253 253 253 253 253 253
53745-253 253 253 178 178 178 2 2 6 2 2 6
53746- 2 2 6 2 2 6 2 2 6 2 2 6
53747- 2 2 6 18 18 18 90 90 90 62 62 62
53748- 30 30 30 10 10 10 0 0 0 0 0 0
53749- 0 0 0 0 0 0 0 0 0 0 0 0
53750- 0 0 0 0 0 0 0 0 0 0 0 0
53751- 0 0 0 0 0 0 0 0 0 0 0 0
53752- 0 0 0 0 0 0 0 0 0 0 0 0
53753- 0 0 0 0 0 0 0 0 0 0 0 0
53754- 0 0 0 0 0 0 0 0 0 0 0 0
53755- 0 0 0 0 0 0 0 0 0 0 0 0
53756- 0 0 0 0 0 0 0 0 0 0 0 0
53757- 0 0 0 0 0 0 0 0 0 0 0 0
53758- 0 0 0 0 0 0 10 10 10 26 26 26
53759- 58 58 58 90 90 90 18 18 18 2 2 6
53760- 2 2 6 110 110 110 253 253 253 253 253 253
53761-253 253 253 253 253 253 253 253 253 253 253 253
53762-250 250 250 253 253 253 253 253 253 253 253 253
53763-253 253 253 253 253 253 253 253 253 253 253 253
53764-253 253 253 253 253 253 253 253 253 253 253 253
53765-253 253 253 231 231 231 18 18 18 2 2 6
53766- 2 2 6 2 2 6 2 2 6 2 2 6
53767- 2 2 6 2 2 6 18 18 18 94 94 94
53768- 54 54 54 26 26 26 10 10 10 0 0 0
53769- 0 0 0 0 0 0 0 0 0 0 0 0
53770- 0 0 0 0 0 0 0 0 0 0 0 0
53771- 0 0 0 0 0 0 0 0 0 0 0 0
53772- 0 0 0 0 0 0 0 0 0 0 0 0
53773- 0 0 0 0 0 0 0 0 0 0 0 0
53774- 0 0 0 0 0 0 0 0 0 0 0 0
53775- 0 0 0 0 0 0 0 0 0 0 0 0
53776- 0 0 0 0 0 0 0 0 0 0 0 0
53777- 0 0 0 0 0 0 0 0 0 0 0 0
53778- 0 0 0 6 6 6 22 22 22 50 50 50
53779- 90 90 90 26 26 26 2 2 6 2 2 6
53780- 14 14 14 195 195 195 250 250 250 253 253 253
53781-253 253 253 253 253 253 253 253 253 253 253 253
53782-253 253 253 253 253 253 253 253 253 253 253 253
53783-253 253 253 253 253 253 253 253 253 253 253 253
53784-253 253 253 253 253 253 253 253 253 253 253 253
53785-250 250 250 242 242 242 54 54 54 2 2 6
53786- 2 2 6 2 2 6 2 2 6 2 2 6
53787- 2 2 6 2 2 6 2 2 6 38 38 38
53788- 86 86 86 50 50 50 22 22 22 6 6 6
53789- 0 0 0 0 0 0 0 0 0 0 0 0
53790- 0 0 0 0 0 0 0 0 0 0 0 0
53791- 0 0 0 0 0 0 0 0 0 0 0 0
53792- 0 0 0 0 0 0 0 0 0 0 0 0
53793- 0 0 0 0 0 0 0 0 0 0 0 0
53794- 0 0 0 0 0 0 0 0 0 0 0 0
53795- 0 0 0 0 0 0 0 0 0 0 0 0
53796- 0 0 0 0 0 0 0 0 0 0 0 0
53797- 0 0 0 0 0 0 0 0 0 0 0 0
53798- 6 6 6 14 14 14 38 38 38 82 82 82
53799- 34 34 34 2 2 6 2 2 6 2 2 6
53800- 42 42 42 195 195 195 246 246 246 253 253 253
53801-253 253 253 253 253 253 253 253 253 250 250 250
53802-242 242 242 242 242 242 250 250 250 253 253 253
53803-253 253 253 253 253 253 253 253 253 253 253 253
53804-253 253 253 250 250 250 246 246 246 238 238 238
53805-226 226 226 231 231 231 101 101 101 6 6 6
53806- 2 2 6 2 2 6 2 2 6 2 2 6
53807- 2 2 6 2 2 6 2 2 6 2 2 6
53808- 38 38 38 82 82 82 42 42 42 14 14 14
53809- 6 6 6 0 0 0 0 0 0 0 0 0
53810- 0 0 0 0 0 0 0 0 0 0 0 0
53811- 0 0 0 0 0 0 0 0 0 0 0 0
53812- 0 0 0 0 0 0 0 0 0 0 0 0
53813- 0 0 0 0 0 0 0 0 0 0 0 0
53814- 0 0 0 0 0 0 0 0 0 0 0 0
53815- 0 0 0 0 0 0 0 0 0 0 0 0
53816- 0 0 0 0 0 0 0 0 0 0 0 0
53817- 0 0 0 0 0 0 0 0 0 0 0 0
53818- 10 10 10 26 26 26 62 62 62 66 66 66
53819- 2 2 6 2 2 6 2 2 6 6 6 6
53820- 70 70 70 170 170 170 206 206 206 234 234 234
53821-246 246 246 250 250 250 250 250 250 238 238 238
53822-226 226 226 231 231 231 238 238 238 250 250 250
53823-250 250 250 250 250 250 246 246 246 231 231 231
53824-214 214 214 206 206 206 202 202 202 202 202 202
53825-198 198 198 202 202 202 182 182 182 18 18 18
53826- 2 2 6 2 2 6 2 2 6 2 2 6
53827- 2 2 6 2 2 6 2 2 6 2 2 6
53828- 2 2 6 62 62 62 66 66 66 30 30 30
53829- 10 10 10 0 0 0 0 0 0 0 0 0
53830- 0 0 0 0 0 0 0 0 0 0 0 0
53831- 0 0 0 0 0 0 0 0 0 0 0 0
53832- 0 0 0 0 0 0 0 0 0 0 0 0
53833- 0 0 0 0 0 0 0 0 0 0 0 0
53834- 0 0 0 0 0 0 0 0 0 0 0 0
53835- 0 0 0 0 0 0 0 0 0 0 0 0
53836- 0 0 0 0 0 0 0 0 0 0 0 0
53837- 0 0 0 0 0 0 0 0 0 0 0 0
53838- 14 14 14 42 42 42 82 82 82 18 18 18
53839- 2 2 6 2 2 6 2 2 6 10 10 10
53840- 94 94 94 182 182 182 218 218 218 242 242 242
53841-250 250 250 253 253 253 253 253 253 250 250 250
53842-234 234 234 253 253 253 253 253 253 253 253 253
53843-253 253 253 253 253 253 253 253 253 246 246 246
53844-238 238 238 226 226 226 210 210 210 202 202 202
53845-195 195 195 195 195 195 210 210 210 158 158 158
53846- 6 6 6 14 14 14 50 50 50 14 14 14
53847- 2 2 6 2 2 6 2 2 6 2 2 6
53848- 2 2 6 6 6 6 86 86 86 46 46 46
53849- 18 18 18 6 6 6 0 0 0 0 0 0
53850- 0 0 0 0 0 0 0 0 0 0 0 0
53851- 0 0 0 0 0 0 0 0 0 0 0 0
53852- 0 0 0 0 0 0 0 0 0 0 0 0
53853- 0 0 0 0 0 0 0 0 0 0 0 0
53854- 0 0 0 0 0 0 0 0 0 0 0 0
53855- 0 0 0 0 0 0 0 0 0 0 0 0
53856- 0 0 0 0 0 0 0 0 0 0 0 0
53857- 0 0 0 0 0 0 0 0 0 6 6 6
53858- 22 22 22 54 54 54 70 70 70 2 2 6
53859- 2 2 6 10 10 10 2 2 6 22 22 22
53860-166 166 166 231 231 231 250 250 250 253 253 253
53861-253 253 253 253 253 253 253 253 253 250 250 250
53862-242 242 242 253 253 253 253 253 253 253 253 253
53863-253 253 253 253 253 253 253 253 253 253 253 253
53864-253 253 253 253 253 253 253 253 253 246 246 246
53865-231 231 231 206 206 206 198 198 198 226 226 226
53866- 94 94 94 2 2 6 6 6 6 38 38 38
53867- 30 30 30 2 2 6 2 2 6 2 2 6
53868- 2 2 6 2 2 6 62 62 62 66 66 66
53869- 26 26 26 10 10 10 0 0 0 0 0 0
53870- 0 0 0 0 0 0 0 0 0 0 0 0
53871- 0 0 0 0 0 0 0 0 0 0 0 0
53872- 0 0 0 0 0 0 0 0 0 0 0 0
53873- 0 0 0 0 0 0 0 0 0 0 0 0
53874- 0 0 0 0 0 0 0 0 0 0 0 0
53875- 0 0 0 0 0 0 0 0 0 0 0 0
53876- 0 0 0 0 0 0 0 0 0 0 0 0
53877- 0 0 0 0 0 0 0 0 0 10 10 10
53878- 30 30 30 74 74 74 50 50 50 2 2 6
53879- 26 26 26 26 26 26 2 2 6 106 106 106
53880-238 238 238 253 253 253 253 253 253 253 253 253
53881-253 253 253 253 253 253 253 253 253 253 253 253
53882-253 253 253 253 253 253 253 253 253 253 253 253
53883-253 253 253 253 253 253 253 253 253 253 253 253
53884-253 253 253 253 253 253 253 253 253 253 253 253
53885-253 253 253 246 246 246 218 218 218 202 202 202
53886-210 210 210 14 14 14 2 2 6 2 2 6
53887- 30 30 30 22 22 22 2 2 6 2 2 6
53888- 2 2 6 2 2 6 18 18 18 86 86 86
53889- 42 42 42 14 14 14 0 0 0 0 0 0
53890- 0 0 0 0 0 0 0 0 0 0 0 0
53891- 0 0 0 0 0 0 0 0 0 0 0 0
53892- 0 0 0 0 0 0 0 0 0 0 0 0
53893- 0 0 0 0 0 0 0 0 0 0 0 0
53894- 0 0 0 0 0 0 0 0 0 0 0 0
53895- 0 0 0 0 0 0 0 0 0 0 0 0
53896- 0 0 0 0 0 0 0 0 0 0 0 0
53897- 0 0 0 0 0 0 0 0 0 14 14 14
53898- 42 42 42 90 90 90 22 22 22 2 2 6
53899- 42 42 42 2 2 6 18 18 18 218 218 218
53900-253 253 253 253 253 253 253 253 253 253 253 253
53901-253 253 253 253 253 253 253 253 253 253 253 253
53902-253 253 253 253 253 253 253 253 253 253 253 253
53903-253 253 253 253 253 253 253 253 253 253 253 253
53904-253 253 253 253 253 253 253 253 253 253 253 253
53905-253 253 253 253 253 253 250 250 250 221 221 221
53906-218 218 218 101 101 101 2 2 6 14 14 14
53907- 18 18 18 38 38 38 10 10 10 2 2 6
53908- 2 2 6 2 2 6 2 2 6 78 78 78
53909- 58 58 58 22 22 22 6 6 6 0 0 0
53910- 0 0 0 0 0 0 0 0 0 0 0 0
53911- 0 0 0 0 0 0 0 0 0 0 0 0
53912- 0 0 0 0 0 0 0 0 0 0 0 0
53913- 0 0 0 0 0 0 0 0 0 0 0 0
53914- 0 0 0 0 0 0 0 0 0 0 0 0
53915- 0 0 0 0 0 0 0 0 0 0 0 0
53916- 0 0 0 0 0 0 0 0 0 0 0 0
53917- 0 0 0 0 0 0 6 6 6 18 18 18
53918- 54 54 54 82 82 82 2 2 6 26 26 26
53919- 22 22 22 2 2 6 123 123 123 253 253 253
53920-253 253 253 253 253 253 253 253 253 253 253 253
53921-253 253 253 253 253 253 253 253 253 253 253 253
53922-253 253 253 253 253 253 253 253 253 253 253 253
53923-253 253 253 253 253 253 253 253 253 253 253 253
53924-253 253 253 253 253 253 253 253 253 253 253 253
53925-253 253 253 253 253 253 253 253 253 250 250 250
53926-238 238 238 198 198 198 6 6 6 38 38 38
53927- 58 58 58 26 26 26 38 38 38 2 2 6
53928- 2 2 6 2 2 6 2 2 6 46 46 46
53929- 78 78 78 30 30 30 10 10 10 0 0 0
53930- 0 0 0 0 0 0 0 0 0 0 0 0
53931- 0 0 0 0 0 0 0 0 0 0 0 0
53932- 0 0 0 0 0 0 0 0 0 0 0 0
53933- 0 0 0 0 0 0 0 0 0 0 0 0
53934- 0 0 0 0 0 0 0 0 0 0 0 0
53935- 0 0 0 0 0 0 0 0 0 0 0 0
53936- 0 0 0 0 0 0 0 0 0 0 0 0
53937- 0 0 0 0 0 0 10 10 10 30 30 30
53938- 74 74 74 58 58 58 2 2 6 42 42 42
53939- 2 2 6 22 22 22 231 231 231 253 253 253
53940-253 253 253 253 253 253 253 253 253 253 253 253
53941-253 253 253 253 253 253 253 253 253 250 250 250
53942-253 253 253 253 253 253 253 253 253 253 253 253
53943-253 253 253 253 253 253 253 253 253 253 253 253
53944-253 253 253 253 253 253 253 253 253 253 253 253
53945-253 253 253 253 253 253 253 253 253 253 253 253
53946-253 253 253 246 246 246 46 46 46 38 38 38
53947- 42 42 42 14 14 14 38 38 38 14 14 14
53948- 2 2 6 2 2 6 2 2 6 6 6 6
53949- 86 86 86 46 46 46 14 14 14 0 0 0
53950- 0 0 0 0 0 0 0 0 0 0 0 0
53951- 0 0 0 0 0 0 0 0 0 0 0 0
53952- 0 0 0 0 0 0 0 0 0 0 0 0
53953- 0 0 0 0 0 0 0 0 0 0 0 0
53954- 0 0 0 0 0 0 0 0 0 0 0 0
53955- 0 0 0 0 0 0 0 0 0 0 0 0
53956- 0 0 0 0 0 0 0 0 0 0 0 0
53957- 0 0 0 6 6 6 14 14 14 42 42 42
53958- 90 90 90 18 18 18 18 18 18 26 26 26
53959- 2 2 6 116 116 116 253 253 253 253 253 253
53960-253 253 253 253 253 253 253 253 253 253 253 253
53961-253 253 253 253 253 253 250 250 250 238 238 238
53962-253 253 253 253 253 253 253 253 253 253 253 253
53963-253 253 253 253 253 253 253 253 253 253 253 253
53964-253 253 253 253 253 253 253 253 253 253 253 253
53965-253 253 253 253 253 253 253 253 253 253 253 253
53966-253 253 253 253 253 253 94 94 94 6 6 6
53967- 2 2 6 2 2 6 10 10 10 34 34 34
53968- 2 2 6 2 2 6 2 2 6 2 2 6
53969- 74 74 74 58 58 58 22 22 22 6 6 6
53970- 0 0 0 0 0 0 0 0 0 0 0 0
53971- 0 0 0 0 0 0 0 0 0 0 0 0
53972- 0 0 0 0 0 0 0 0 0 0 0 0
53973- 0 0 0 0 0 0 0 0 0 0 0 0
53974- 0 0 0 0 0 0 0 0 0 0 0 0
53975- 0 0 0 0 0 0 0 0 0 0 0 0
53976- 0 0 0 0 0 0 0 0 0 0 0 0
53977- 0 0 0 10 10 10 26 26 26 66 66 66
53978- 82 82 82 2 2 6 38 38 38 6 6 6
53979- 14 14 14 210 210 210 253 253 253 253 253 253
53980-253 253 253 253 253 253 253 253 253 253 253 253
53981-253 253 253 253 253 253 246 246 246 242 242 242
53982-253 253 253 253 253 253 253 253 253 253 253 253
53983-253 253 253 253 253 253 253 253 253 253 253 253
53984-253 253 253 253 253 253 253 253 253 253 253 253
53985-253 253 253 253 253 253 253 253 253 253 253 253
53986-253 253 253 253 253 253 144 144 144 2 2 6
53987- 2 2 6 2 2 6 2 2 6 46 46 46
53988- 2 2 6 2 2 6 2 2 6 2 2 6
53989- 42 42 42 74 74 74 30 30 30 10 10 10
53990- 0 0 0 0 0 0 0 0 0 0 0 0
53991- 0 0 0 0 0 0 0 0 0 0 0 0
53992- 0 0 0 0 0 0 0 0 0 0 0 0
53993- 0 0 0 0 0 0 0 0 0 0 0 0
53994- 0 0 0 0 0 0 0 0 0 0 0 0
53995- 0 0 0 0 0 0 0 0 0 0 0 0
53996- 0 0 0 0 0 0 0 0 0 0 0 0
53997- 6 6 6 14 14 14 42 42 42 90 90 90
53998- 26 26 26 6 6 6 42 42 42 2 2 6
53999- 74 74 74 250 250 250 253 253 253 253 253 253
54000-253 253 253 253 253 253 253 253 253 253 253 253
54001-253 253 253 253 253 253 242 242 242 242 242 242
54002-253 253 253 253 253 253 253 253 253 253 253 253
54003-253 253 253 253 253 253 253 253 253 253 253 253
54004-253 253 253 253 253 253 253 253 253 253 253 253
54005-253 253 253 253 253 253 253 253 253 253 253 253
54006-253 253 253 253 253 253 182 182 182 2 2 6
54007- 2 2 6 2 2 6 2 2 6 46 46 46
54008- 2 2 6 2 2 6 2 2 6 2 2 6
54009- 10 10 10 86 86 86 38 38 38 10 10 10
54010- 0 0 0 0 0 0 0 0 0 0 0 0
54011- 0 0 0 0 0 0 0 0 0 0 0 0
54012- 0 0 0 0 0 0 0 0 0 0 0 0
54013- 0 0 0 0 0 0 0 0 0 0 0 0
54014- 0 0 0 0 0 0 0 0 0 0 0 0
54015- 0 0 0 0 0 0 0 0 0 0 0 0
54016- 0 0 0 0 0 0 0 0 0 0 0 0
54017- 10 10 10 26 26 26 66 66 66 82 82 82
54018- 2 2 6 22 22 22 18 18 18 2 2 6
54019-149 149 149 253 253 253 253 253 253 253 253 253
54020-253 253 253 253 253 253 253 253 253 253 253 253
54021-253 253 253 253 253 253 234 234 234 242 242 242
54022-253 253 253 253 253 253 253 253 253 253 253 253
54023-253 253 253 253 253 253 253 253 253 253 253 253
54024-253 253 253 253 253 253 253 253 253 253 253 253
54025-253 253 253 253 253 253 253 253 253 253 253 253
54026-253 253 253 253 253 253 206 206 206 2 2 6
54027- 2 2 6 2 2 6 2 2 6 38 38 38
54028- 2 2 6 2 2 6 2 2 6 2 2 6
54029- 6 6 6 86 86 86 46 46 46 14 14 14
54030- 0 0 0 0 0 0 0 0 0 0 0 0
54031- 0 0 0 0 0 0 0 0 0 0 0 0
54032- 0 0 0 0 0 0 0 0 0 0 0 0
54033- 0 0 0 0 0 0 0 0 0 0 0 0
54034- 0 0 0 0 0 0 0 0 0 0 0 0
54035- 0 0 0 0 0 0 0 0 0 0 0 0
54036- 0 0 0 0 0 0 0 0 0 6 6 6
54037- 18 18 18 46 46 46 86 86 86 18 18 18
54038- 2 2 6 34 34 34 10 10 10 6 6 6
54039-210 210 210 253 253 253 253 253 253 253 253 253
54040-253 253 253 253 253 253 253 253 253 253 253 253
54041-253 253 253 253 253 253 234 234 234 242 242 242
54042-253 253 253 253 253 253 253 253 253 253 253 253
54043-253 253 253 253 253 253 253 253 253 253 253 253
54044-253 253 253 253 253 253 253 253 253 253 253 253
54045-253 253 253 253 253 253 253 253 253 253 253 253
54046-253 253 253 253 253 253 221 221 221 6 6 6
54047- 2 2 6 2 2 6 6 6 6 30 30 30
54048- 2 2 6 2 2 6 2 2 6 2 2 6
54049- 2 2 6 82 82 82 54 54 54 18 18 18
54050- 6 6 6 0 0 0 0 0 0 0 0 0
54051- 0 0 0 0 0 0 0 0 0 0 0 0
54052- 0 0 0 0 0 0 0 0 0 0 0 0
54053- 0 0 0 0 0 0 0 0 0 0 0 0
54054- 0 0 0 0 0 0 0 0 0 0 0 0
54055- 0 0 0 0 0 0 0 0 0 0 0 0
54056- 0 0 0 0 0 0 0 0 0 10 10 10
54057- 26 26 26 66 66 66 62 62 62 2 2 6
54058- 2 2 6 38 38 38 10 10 10 26 26 26
54059-238 238 238 253 253 253 253 253 253 253 253 253
54060-253 253 253 253 253 253 253 253 253 253 253 253
54061-253 253 253 253 253 253 231 231 231 238 238 238
54062-253 253 253 253 253 253 253 253 253 253 253 253
54063-253 253 253 253 253 253 253 253 253 253 253 253
54064-253 253 253 253 253 253 253 253 253 253 253 253
54065-253 253 253 253 253 253 253 253 253 253 253 253
54066-253 253 253 253 253 253 231 231 231 6 6 6
54067- 2 2 6 2 2 6 10 10 10 30 30 30
54068- 2 2 6 2 2 6 2 2 6 2 2 6
54069- 2 2 6 66 66 66 58 58 58 22 22 22
54070- 6 6 6 0 0 0 0 0 0 0 0 0
54071- 0 0 0 0 0 0 0 0 0 0 0 0
54072- 0 0 0 0 0 0 0 0 0 0 0 0
54073- 0 0 0 0 0 0 0 0 0 0 0 0
54074- 0 0 0 0 0 0 0 0 0 0 0 0
54075- 0 0 0 0 0 0 0 0 0 0 0 0
54076- 0 0 0 0 0 0 0 0 0 10 10 10
54077- 38 38 38 78 78 78 6 6 6 2 2 6
54078- 2 2 6 46 46 46 14 14 14 42 42 42
54079-246 246 246 253 253 253 253 253 253 253 253 253
54080-253 253 253 253 253 253 253 253 253 253 253 253
54081-253 253 253 253 253 253 231 231 231 242 242 242
54082-253 253 253 253 253 253 253 253 253 253 253 253
54083-253 253 253 253 253 253 253 253 253 253 253 253
54084-253 253 253 253 253 253 253 253 253 253 253 253
54085-253 253 253 253 253 253 253 253 253 253 253 253
54086-253 253 253 253 253 253 234 234 234 10 10 10
54087- 2 2 6 2 2 6 22 22 22 14 14 14
54088- 2 2 6 2 2 6 2 2 6 2 2 6
54089- 2 2 6 66 66 66 62 62 62 22 22 22
54090- 6 6 6 0 0 0 0 0 0 0 0 0
54091- 0 0 0 0 0 0 0 0 0 0 0 0
54092- 0 0 0 0 0 0 0 0 0 0 0 0
54093- 0 0 0 0 0 0 0 0 0 0 0 0
54094- 0 0 0 0 0 0 0 0 0 0 0 0
54095- 0 0 0 0 0 0 0 0 0 0 0 0
54096- 0 0 0 0 0 0 6 6 6 18 18 18
54097- 50 50 50 74 74 74 2 2 6 2 2 6
54098- 14 14 14 70 70 70 34 34 34 62 62 62
54099-250 250 250 253 253 253 253 253 253 253 253 253
54100-253 253 253 253 253 253 253 253 253 253 253 253
54101-253 253 253 253 253 253 231 231 231 246 246 246
54102-253 253 253 253 253 253 253 253 253 253 253 253
54103-253 253 253 253 253 253 253 253 253 253 253 253
54104-253 253 253 253 253 253 253 253 253 253 253 253
54105-253 253 253 253 253 253 253 253 253 253 253 253
54106-253 253 253 253 253 253 234 234 234 14 14 14
54107- 2 2 6 2 2 6 30 30 30 2 2 6
54108- 2 2 6 2 2 6 2 2 6 2 2 6
54109- 2 2 6 66 66 66 62 62 62 22 22 22
54110- 6 6 6 0 0 0 0 0 0 0 0 0
54111- 0 0 0 0 0 0 0 0 0 0 0 0
54112- 0 0 0 0 0 0 0 0 0 0 0 0
54113- 0 0 0 0 0 0 0 0 0 0 0 0
54114- 0 0 0 0 0 0 0 0 0 0 0 0
54115- 0 0 0 0 0 0 0 0 0 0 0 0
54116- 0 0 0 0 0 0 6 6 6 18 18 18
54117- 54 54 54 62 62 62 2 2 6 2 2 6
54118- 2 2 6 30 30 30 46 46 46 70 70 70
54119-250 250 250 253 253 253 253 253 253 253 253 253
54120-253 253 253 253 253 253 253 253 253 253 253 253
54121-253 253 253 253 253 253 231 231 231 246 246 246
54122-253 253 253 253 253 253 253 253 253 253 253 253
54123-253 253 253 253 253 253 253 253 253 253 253 253
54124-253 253 253 253 253 253 253 253 253 253 253 253
54125-253 253 253 253 253 253 253 253 253 253 253 253
54126-253 253 253 253 253 253 226 226 226 10 10 10
54127- 2 2 6 6 6 6 30 30 30 2 2 6
54128- 2 2 6 2 2 6 2 2 6 2 2 6
54129- 2 2 6 66 66 66 58 58 58 22 22 22
54130- 6 6 6 0 0 0 0 0 0 0 0 0
54131- 0 0 0 0 0 0 0 0 0 0 0 0
54132- 0 0 0 0 0 0 0 0 0 0 0 0
54133- 0 0 0 0 0 0 0 0 0 0 0 0
54134- 0 0 0 0 0 0 0 0 0 0 0 0
54135- 0 0 0 0 0 0 0 0 0 0 0 0
54136- 0 0 0 0 0 0 6 6 6 22 22 22
54137- 58 58 58 62 62 62 2 2 6 2 2 6
54138- 2 2 6 2 2 6 30 30 30 78 78 78
54139-250 250 250 253 253 253 253 253 253 253 253 253
54140-253 253 253 253 253 253 253 253 253 253 253 253
54141-253 253 253 253 253 253 231 231 231 246 246 246
54142-253 253 253 253 253 253 253 253 253 253 253 253
54143-253 253 253 253 253 253 253 253 253 253 253 253
54144-253 253 253 253 253 253 253 253 253 253 253 253
54145-253 253 253 253 253 253 253 253 253 253 253 253
54146-253 253 253 253 253 253 206 206 206 2 2 6
54147- 22 22 22 34 34 34 18 14 6 22 22 22
54148- 26 26 26 18 18 18 6 6 6 2 2 6
54149- 2 2 6 82 82 82 54 54 54 18 18 18
54150- 6 6 6 0 0 0 0 0 0 0 0 0
54151- 0 0 0 0 0 0 0 0 0 0 0 0
54152- 0 0 0 0 0 0 0 0 0 0 0 0
54153- 0 0 0 0 0 0 0 0 0 0 0 0
54154- 0 0 0 0 0 0 0 0 0 0 0 0
54155- 0 0 0 0 0 0 0 0 0 0 0 0
54156- 0 0 0 0 0 0 6 6 6 26 26 26
54157- 62 62 62 106 106 106 74 54 14 185 133 11
54158-210 162 10 121 92 8 6 6 6 62 62 62
54159-238 238 238 253 253 253 253 253 253 253 253 253
54160-253 253 253 253 253 253 253 253 253 253 253 253
54161-253 253 253 253 253 253 231 231 231 246 246 246
54162-253 253 253 253 253 253 253 253 253 253 253 253
54163-253 253 253 253 253 253 253 253 253 253 253 253
54164-253 253 253 253 253 253 253 253 253 253 253 253
54165-253 253 253 253 253 253 253 253 253 253 253 253
54166-253 253 253 253 253 253 158 158 158 18 18 18
54167- 14 14 14 2 2 6 2 2 6 2 2 6
54168- 6 6 6 18 18 18 66 66 66 38 38 38
54169- 6 6 6 94 94 94 50 50 50 18 18 18
54170- 6 6 6 0 0 0 0 0 0 0 0 0
54171- 0 0 0 0 0 0 0 0 0 0 0 0
54172- 0 0 0 0 0 0 0 0 0 0 0 0
54173- 0 0 0 0 0 0 0 0 0 0 0 0
54174- 0 0 0 0 0 0 0 0 0 0 0 0
54175- 0 0 0 0 0 0 0 0 0 6 6 6
54176- 10 10 10 10 10 10 18 18 18 38 38 38
54177- 78 78 78 142 134 106 216 158 10 242 186 14
54178-246 190 14 246 190 14 156 118 10 10 10 10
54179- 90 90 90 238 238 238 253 253 253 253 253 253
54180-253 253 253 253 253 253 253 253 253 253 253 253
54181-253 253 253 253 253 253 231 231 231 250 250 250
54182-253 253 253 253 253 253 253 253 253 253 253 253
54183-253 253 253 253 253 253 253 253 253 253 253 253
54184-253 253 253 253 253 253 253 253 253 253 253 253
54185-253 253 253 253 253 253 253 253 253 246 230 190
54186-238 204 91 238 204 91 181 142 44 37 26 9
54187- 2 2 6 2 2 6 2 2 6 2 2 6
54188- 2 2 6 2 2 6 38 38 38 46 46 46
54189- 26 26 26 106 106 106 54 54 54 18 18 18
54190- 6 6 6 0 0 0 0 0 0 0 0 0
54191- 0 0 0 0 0 0 0 0 0 0 0 0
54192- 0 0 0 0 0 0 0 0 0 0 0 0
54193- 0 0 0 0 0 0 0 0 0 0 0 0
54194- 0 0 0 0 0 0 0 0 0 0 0 0
54195- 0 0 0 6 6 6 14 14 14 22 22 22
54196- 30 30 30 38 38 38 50 50 50 70 70 70
54197-106 106 106 190 142 34 226 170 11 242 186 14
54198-246 190 14 246 190 14 246 190 14 154 114 10
54199- 6 6 6 74 74 74 226 226 226 253 253 253
54200-253 253 253 253 253 253 253 253 253 253 253 253
54201-253 253 253 253 253 253 231 231 231 250 250 250
54202-253 253 253 253 253 253 253 253 253 253 253 253
54203-253 253 253 253 253 253 253 253 253 253 253 253
54204-253 253 253 253 253 253 253 253 253 253 253 253
54205-253 253 253 253 253 253 253 253 253 228 184 62
54206-241 196 14 241 208 19 232 195 16 38 30 10
54207- 2 2 6 2 2 6 2 2 6 2 2 6
54208- 2 2 6 6 6 6 30 30 30 26 26 26
54209-203 166 17 154 142 90 66 66 66 26 26 26
54210- 6 6 6 0 0 0 0 0 0 0 0 0
54211- 0 0 0 0 0 0 0 0 0 0 0 0
54212- 0 0 0 0 0 0 0 0 0 0 0 0
54213- 0 0 0 0 0 0 0 0 0 0 0 0
54214- 0 0 0 0 0 0 0 0 0 0 0 0
54215- 6 6 6 18 18 18 38 38 38 58 58 58
54216- 78 78 78 86 86 86 101 101 101 123 123 123
54217-175 146 61 210 150 10 234 174 13 246 186 14
54218-246 190 14 246 190 14 246 190 14 238 190 10
54219-102 78 10 2 2 6 46 46 46 198 198 198
54220-253 253 253 253 253 253 253 253 253 253 253 253
54221-253 253 253 253 253 253 234 234 234 242 242 242
54222-253 253 253 253 253 253 253 253 253 253 253 253
54223-253 253 253 253 253 253 253 253 253 253 253 253
54224-253 253 253 253 253 253 253 253 253 253 253 253
54225-253 253 253 253 253 253 253 253 253 224 178 62
54226-242 186 14 241 196 14 210 166 10 22 18 6
54227- 2 2 6 2 2 6 2 2 6 2 2 6
54228- 2 2 6 2 2 6 6 6 6 121 92 8
54229-238 202 15 232 195 16 82 82 82 34 34 34
54230- 10 10 10 0 0 0 0 0 0 0 0 0
54231- 0 0 0 0 0 0 0 0 0 0 0 0
54232- 0 0 0 0 0 0 0 0 0 0 0 0
54233- 0 0 0 0 0 0 0 0 0 0 0 0
54234- 0 0 0 0 0 0 0 0 0 0 0 0
54235- 14 14 14 38 38 38 70 70 70 154 122 46
54236-190 142 34 200 144 11 197 138 11 197 138 11
54237-213 154 11 226 170 11 242 186 14 246 190 14
54238-246 190 14 246 190 14 246 190 14 246 190 14
54239-225 175 15 46 32 6 2 2 6 22 22 22
54240-158 158 158 250 250 250 253 253 253 253 253 253
54241-253 253 253 253 253 253 253 253 253 253 253 253
54242-253 253 253 253 253 253 253 253 253 253 253 253
54243-253 253 253 253 253 253 253 253 253 253 253 253
54244-253 253 253 253 253 253 253 253 253 253 253 253
54245-253 253 253 250 250 250 242 242 242 224 178 62
54246-239 182 13 236 186 11 213 154 11 46 32 6
54247- 2 2 6 2 2 6 2 2 6 2 2 6
54248- 2 2 6 2 2 6 61 42 6 225 175 15
54249-238 190 10 236 186 11 112 100 78 42 42 42
54250- 14 14 14 0 0 0 0 0 0 0 0 0
54251- 0 0 0 0 0 0 0 0 0 0 0 0
54252- 0 0 0 0 0 0 0 0 0 0 0 0
54253- 0 0 0 0 0 0 0 0 0 0 0 0
54254- 0 0 0 0 0 0 0 0 0 6 6 6
54255- 22 22 22 54 54 54 154 122 46 213 154 11
54256-226 170 11 230 174 11 226 170 11 226 170 11
54257-236 178 12 242 186 14 246 190 14 246 190 14
54258-246 190 14 246 190 14 246 190 14 246 190 14
54259-241 196 14 184 144 12 10 10 10 2 2 6
54260- 6 6 6 116 116 116 242 242 242 253 253 253
54261-253 253 253 253 253 253 253 253 253 253 253 253
54262-253 253 253 253 253 253 253 253 253 253 253 253
54263-253 253 253 253 253 253 253 253 253 253 253 253
54264-253 253 253 253 253 253 253 253 253 253 253 253
54265-253 253 253 231 231 231 198 198 198 214 170 54
54266-236 178 12 236 178 12 210 150 10 137 92 6
54267- 18 14 6 2 2 6 2 2 6 2 2 6
54268- 6 6 6 70 47 6 200 144 11 236 178 12
54269-239 182 13 239 182 13 124 112 88 58 58 58
54270- 22 22 22 6 6 6 0 0 0 0 0 0
54271- 0 0 0 0 0 0 0 0 0 0 0 0
54272- 0 0 0 0 0 0 0 0 0 0 0 0
54273- 0 0 0 0 0 0 0 0 0 0 0 0
54274- 0 0 0 0 0 0 0 0 0 10 10 10
54275- 30 30 30 70 70 70 180 133 36 226 170 11
54276-239 182 13 242 186 14 242 186 14 246 186 14
54277-246 190 14 246 190 14 246 190 14 246 190 14
54278-246 190 14 246 190 14 246 190 14 246 190 14
54279-246 190 14 232 195 16 98 70 6 2 2 6
54280- 2 2 6 2 2 6 66 66 66 221 221 221
54281-253 253 253 253 253 253 253 253 253 253 253 253
54282-253 253 253 253 253 253 253 253 253 253 253 253
54283-253 253 253 253 253 253 253 253 253 253 253 253
54284-253 253 253 253 253 253 253 253 253 253 253 253
54285-253 253 253 206 206 206 198 198 198 214 166 58
54286-230 174 11 230 174 11 216 158 10 192 133 9
54287-163 110 8 116 81 8 102 78 10 116 81 8
54288-167 114 7 197 138 11 226 170 11 239 182 13
54289-242 186 14 242 186 14 162 146 94 78 78 78
54290- 34 34 34 14 14 14 6 6 6 0 0 0
54291- 0 0 0 0 0 0 0 0 0 0 0 0
54292- 0 0 0 0 0 0 0 0 0 0 0 0
54293- 0 0 0 0 0 0 0 0 0 0 0 0
54294- 0 0 0 0 0 0 0 0 0 6 6 6
54295- 30 30 30 78 78 78 190 142 34 226 170 11
54296-239 182 13 246 190 14 246 190 14 246 190 14
54297-246 190 14 246 190 14 246 190 14 246 190 14
54298-246 190 14 246 190 14 246 190 14 246 190 14
54299-246 190 14 241 196 14 203 166 17 22 18 6
54300- 2 2 6 2 2 6 2 2 6 38 38 38
54301-218 218 218 253 253 253 253 253 253 253 253 253
54302-253 253 253 253 253 253 253 253 253 253 253 253
54303-253 253 253 253 253 253 253 253 253 253 253 253
54304-253 253 253 253 253 253 253 253 253 253 253 253
54305-250 250 250 206 206 206 198 198 198 202 162 69
54306-226 170 11 236 178 12 224 166 10 210 150 10
54307-200 144 11 197 138 11 192 133 9 197 138 11
54308-210 150 10 226 170 11 242 186 14 246 190 14
54309-246 190 14 246 186 14 225 175 15 124 112 88
54310- 62 62 62 30 30 30 14 14 14 6 6 6
54311- 0 0 0 0 0 0 0 0 0 0 0 0
54312- 0 0 0 0 0 0 0 0 0 0 0 0
54313- 0 0 0 0 0 0 0 0 0 0 0 0
54314- 0 0 0 0 0 0 0 0 0 10 10 10
54315- 30 30 30 78 78 78 174 135 50 224 166 10
54316-239 182 13 246 190 14 246 190 14 246 190 14
54317-246 190 14 246 190 14 246 190 14 246 190 14
54318-246 190 14 246 190 14 246 190 14 246 190 14
54319-246 190 14 246 190 14 241 196 14 139 102 15
54320- 2 2 6 2 2 6 2 2 6 2 2 6
54321- 78 78 78 250 250 250 253 253 253 253 253 253
54322-253 253 253 253 253 253 253 253 253 253 253 253
54323-253 253 253 253 253 253 253 253 253 253 253 253
54324-253 253 253 253 253 253 253 253 253 253 253 253
54325-250 250 250 214 214 214 198 198 198 190 150 46
54326-219 162 10 236 178 12 234 174 13 224 166 10
54327-216 158 10 213 154 11 213 154 11 216 158 10
54328-226 170 11 239 182 13 246 190 14 246 190 14
54329-246 190 14 246 190 14 242 186 14 206 162 42
54330-101 101 101 58 58 58 30 30 30 14 14 14
54331- 6 6 6 0 0 0 0 0 0 0 0 0
54332- 0 0 0 0 0 0 0 0 0 0 0 0
54333- 0 0 0 0 0 0 0 0 0 0 0 0
54334- 0 0 0 0 0 0 0 0 0 10 10 10
54335- 30 30 30 74 74 74 174 135 50 216 158 10
54336-236 178 12 246 190 14 246 190 14 246 190 14
54337-246 190 14 246 190 14 246 190 14 246 190 14
54338-246 190 14 246 190 14 246 190 14 246 190 14
54339-246 190 14 246 190 14 241 196 14 226 184 13
54340- 61 42 6 2 2 6 2 2 6 2 2 6
54341- 22 22 22 238 238 238 253 253 253 253 253 253
54342-253 253 253 253 253 253 253 253 253 253 253 253
54343-253 253 253 253 253 253 253 253 253 253 253 253
54344-253 253 253 253 253 253 253 253 253 253 253 253
54345-253 253 253 226 226 226 187 187 187 180 133 36
54346-216 158 10 236 178 12 239 182 13 236 178 12
54347-230 174 11 226 170 11 226 170 11 230 174 11
54348-236 178 12 242 186 14 246 190 14 246 190 14
54349-246 190 14 246 190 14 246 186 14 239 182 13
54350-206 162 42 106 106 106 66 66 66 34 34 34
54351- 14 14 14 6 6 6 0 0 0 0 0 0
54352- 0 0 0 0 0 0 0 0 0 0 0 0
54353- 0 0 0 0 0 0 0 0 0 0 0 0
54354- 0 0 0 0 0 0 0 0 0 6 6 6
54355- 26 26 26 70 70 70 163 133 67 213 154 11
54356-236 178 12 246 190 14 246 190 14 246 190 14
54357-246 190 14 246 190 14 246 190 14 246 190 14
54358-246 190 14 246 190 14 246 190 14 246 190 14
54359-246 190 14 246 190 14 246 190 14 241 196 14
54360-190 146 13 18 14 6 2 2 6 2 2 6
54361- 46 46 46 246 246 246 253 253 253 253 253 253
54362-253 253 253 253 253 253 253 253 253 253 253 253
54363-253 253 253 253 253 253 253 253 253 253 253 253
54364-253 253 253 253 253 253 253 253 253 253 253 253
54365-253 253 253 221 221 221 86 86 86 156 107 11
54366-216 158 10 236 178 12 242 186 14 246 186 14
54367-242 186 14 239 182 13 239 182 13 242 186 14
54368-242 186 14 246 186 14 246 190 14 246 190 14
54369-246 190 14 246 190 14 246 190 14 246 190 14
54370-242 186 14 225 175 15 142 122 72 66 66 66
54371- 30 30 30 10 10 10 0 0 0 0 0 0
54372- 0 0 0 0 0 0 0 0 0 0 0 0
54373- 0 0 0 0 0 0 0 0 0 0 0 0
54374- 0 0 0 0 0 0 0 0 0 6 6 6
54375- 26 26 26 70 70 70 163 133 67 210 150 10
54376-236 178 12 246 190 14 246 190 14 246 190 14
54377-246 190 14 246 190 14 246 190 14 246 190 14
54378-246 190 14 246 190 14 246 190 14 246 190 14
54379-246 190 14 246 190 14 246 190 14 246 190 14
54380-232 195 16 121 92 8 34 34 34 106 106 106
54381-221 221 221 253 253 253 253 253 253 253 253 253
54382-253 253 253 253 253 253 253 253 253 253 253 253
54383-253 253 253 253 253 253 253 253 253 253 253 253
54384-253 253 253 253 253 253 253 253 253 253 253 253
54385-242 242 242 82 82 82 18 14 6 163 110 8
54386-216 158 10 236 178 12 242 186 14 246 190 14
54387-246 190 14 246 190 14 246 190 14 246 190 14
54388-246 190 14 246 190 14 246 190 14 246 190 14
54389-246 190 14 246 190 14 246 190 14 246 190 14
54390-246 190 14 246 190 14 242 186 14 163 133 67
54391- 46 46 46 18 18 18 6 6 6 0 0 0
54392- 0 0 0 0 0 0 0 0 0 0 0 0
54393- 0 0 0 0 0 0 0 0 0 0 0 0
54394- 0 0 0 0 0 0 0 0 0 10 10 10
54395- 30 30 30 78 78 78 163 133 67 210 150 10
54396-236 178 12 246 186 14 246 190 14 246 190 14
54397-246 190 14 246 190 14 246 190 14 246 190 14
54398-246 190 14 246 190 14 246 190 14 246 190 14
54399-246 190 14 246 190 14 246 190 14 246 190 14
54400-241 196 14 215 174 15 190 178 144 253 253 253
54401-253 253 253 253 253 253 253 253 253 253 253 253
54402-253 253 253 253 253 253 253 253 253 253 253 253
54403-253 253 253 253 253 253 253 253 253 253 253 253
54404-253 253 253 253 253 253 253 253 253 218 218 218
54405- 58 58 58 2 2 6 22 18 6 167 114 7
54406-216 158 10 236 178 12 246 186 14 246 190 14
54407-246 190 14 246 190 14 246 190 14 246 190 14
54408-246 190 14 246 190 14 246 190 14 246 190 14
54409-246 190 14 246 190 14 246 190 14 246 190 14
54410-246 190 14 246 186 14 242 186 14 190 150 46
54411- 54 54 54 22 22 22 6 6 6 0 0 0
54412- 0 0 0 0 0 0 0 0 0 0 0 0
54413- 0 0 0 0 0 0 0 0 0 0 0 0
54414- 0 0 0 0 0 0 0 0 0 14 14 14
54415- 38 38 38 86 86 86 180 133 36 213 154 11
54416-236 178 12 246 186 14 246 190 14 246 190 14
54417-246 190 14 246 190 14 246 190 14 246 190 14
54418-246 190 14 246 190 14 246 190 14 246 190 14
54419-246 190 14 246 190 14 246 190 14 246 190 14
54420-246 190 14 232 195 16 190 146 13 214 214 214
54421-253 253 253 253 253 253 253 253 253 253 253 253
54422-253 253 253 253 253 253 253 253 253 253 253 253
54423-253 253 253 253 253 253 253 253 253 253 253 253
54424-253 253 253 250 250 250 170 170 170 26 26 26
54425- 2 2 6 2 2 6 37 26 9 163 110 8
54426-219 162 10 239 182 13 246 186 14 246 190 14
54427-246 190 14 246 190 14 246 190 14 246 190 14
54428-246 190 14 246 190 14 246 190 14 246 190 14
54429-246 190 14 246 190 14 246 190 14 246 190 14
54430-246 186 14 236 178 12 224 166 10 142 122 72
54431- 46 46 46 18 18 18 6 6 6 0 0 0
54432- 0 0 0 0 0 0 0 0 0 0 0 0
54433- 0 0 0 0 0 0 0 0 0 0 0 0
54434- 0 0 0 0 0 0 6 6 6 18 18 18
54435- 50 50 50 109 106 95 192 133 9 224 166 10
54436-242 186 14 246 190 14 246 190 14 246 190 14
54437-246 190 14 246 190 14 246 190 14 246 190 14
54438-246 190 14 246 190 14 246 190 14 246 190 14
54439-246 190 14 246 190 14 246 190 14 246 190 14
54440-242 186 14 226 184 13 210 162 10 142 110 46
54441-226 226 226 253 253 253 253 253 253 253 253 253
54442-253 253 253 253 253 253 253 253 253 253 253 253
54443-253 253 253 253 253 253 253 253 253 253 253 253
54444-198 198 198 66 66 66 2 2 6 2 2 6
54445- 2 2 6 2 2 6 50 34 6 156 107 11
54446-219 162 10 239 182 13 246 186 14 246 190 14
54447-246 190 14 246 190 14 246 190 14 246 190 14
54448-246 190 14 246 190 14 246 190 14 246 190 14
54449-246 190 14 246 190 14 246 190 14 242 186 14
54450-234 174 13 213 154 11 154 122 46 66 66 66
54451- 30 30 30 10 10 10 0 0 0 0 0 0
54452- 0 0 0 0 0 0 0 0 0 0 0 0
54453- 0 0 0 0 0 0 0 0 0 0 0 0
54454- 0 0 0 0 0 0 6 6 6 22 22 22
54455- 58 58 58 154 121 60 206 145 10 234 174 13
54456-242 186 14 246 186 14 246 190 14 246 190 14
54457-246 190 14 246 190 14 246 190 14 246 190 14
54458-246 190 14 246 190 14 246 190 14 246 190 14
54459-246 190 14 246 190 14 246 190 14 246 190 14
54460-246 186 14 236 178 12 210 162 10 163 110 8
54461- 61 42 6 138 138 138 218 218 218 250 250 250
54462-253 253 253 253 253 253 253 253 253 250 250 250
54463-242 242 242 210 210 210 144 144 144 66 66 66
54464- 6 6 6 2 2 6 2 2 6 2 2 6
54465- 2 2 6 2 2 6 61 42 6 163 110 8
54466-216 158 10 236 178 12 246 190 14 246 190 14
54467-246 190 14 246 190 14 246 190 14 246 190 14
54468-246 190 14 246 190 14 246 190 14 246 190 14
54469-246 190 14 239 182 13 230 174 11 216 158 10
54470-190 142 34 124 112 88 70 70 70 38 38 38
54471- 18 18 18 6 6 6 0 0 0 0 0 0
54472- 0 0 0 0 0 0 0 0 0 0 0 0
54473- 0 0 0 0 0 0 0 0 0 0 0 0
54474- 0 0 0 0 0 0 6 6 6 22 22 22
54475- 62 62 62 168 124 44 206 145 10 224 166 10
54476-236 178 12 239 182 13 242 186 14 242 186 14
54477-246 186 14 246 190 14 246 190 14 246 190 14
54478-246 190 14 246 190 14 246 190 14 246 190 14
54479-246 190 14 246 190 14 246 190 14 246 190 14
54480-246 190 14 236 178 12 216 158 10 175 118 6
54481- 80 54 7 2 2 6 6 6 6 30 30 30
54482- 54 54 54 62 62 62 50 50 50 38 38 38
54483- 14 14 14 2 2 6 2 2 6 2 2 6
54484- 2 2 6 2 2 6 2 2 6 2 2 6
54485- 2 2 6 6 6 6 80 54 7 167 114 7
54486-213 154 11 236 178 12 246 190 14 246 190 14
54487-246 190 14 246 190 14 246 190 14 246 190 14
54488-246 190 14 242 186 14 239 182 13 239 182 13
54489-230 174 11 210 150 10 174 135 50 124 112 88
54490- 82 82 82 54 54 54 34 34 34 18 18 18
54491- 6 6 6 0 0 0 0 0 0 0 0 0
54492- 0 0 0 0 0 0 0 0 0 0 0 0
54493- 0 0 0 0 0 0 0 0 0 0 0 0
54494- 0 0 0 0 0 0 6 6 6 18 18 18
54495- 50 50 50 158 118 36 192 133 9 200 144 11
54496-216 158 10 219 162 10 224 166 10 226 170 11
54497-230 174 11 236 178 12 239 182 13 239 182 13
54498-242 186 14 246 186 14 246 190 14 246 190 14
54499-246 190 14 246 190 14 246 190 14 246 190 14
54500-246 186 14 230 174 11 210 150 10 163 110 8
54501-104 69 6 10 10 10 2 2 6 2 2 6
54502- 2 2 6 2 2 6 2 2 6 2 2 6
54503- 2 2 6 2 2 6 2 2 6 2 2 6
54504- 2 2 6 2 2 6 2 2 6 2 2 6
54505- 2 2 6 6 6 6 91 60 6 167 114 7
54506-206 145 10 230 174 11 242 186 14 246 190 14
54507-246 190 14 246 190 14 246 186 14 242 186 14
54508-239 182 13 230 174 11 224 166 10 213 154 11
54509-180 133 36 124 112 88 86 86 86 58 58 58
54510- 38 38 38 22 22 22 10 10 10 6 6 6
54511- 0 0 0 0 0 0 0 0 0 0 0 0
54512- 0 0 0 0 0 0 0 0 0 0 0 0
54513- 0 0 0 0 0 0 0 0 0 0 0 0
54514- 0 0 0 0 0 0 0 0 0 14 14 14
54515- 34 34 34 70 70 70 138 110 50 158 118 36
54516-167 114 7 180 123 7 192 133 9 197 138 11
54517-200 144 11 206 145 10 213 154 11 219 162 10
54518-224 166 10 230 174 11 239 182 13 242 186 14
54519-246 186 14 246 186 14 246 186 14 246 186 14
54520-239 182 13 216 158 10 185 133 11 152 99 6
54521-104 69 6 18 14 6 2 2 6 2 2 6
54522- 2 2 6 2 2 6 2 2 6 2 2 6
54523- 2 2 6 2 2 6 2 2 6 2 2 6
54524- 2 2 6 2 2 6 2 2 6 2 2 6
54525- 2 2 6 6 6 6 80 54 7 152 99 6
54526-192 133 9 219 162 10 236 178 12 239 182 13
54527-246 186 14 242 186 14 239 182 13 236 178 12
54528-224 166 10 206 145 10 192 133 9 154 121 60
54529- 94 94 94 62 62 62 42 42 42 22 22 22
54530- 14 14 14 6 6 6 0 0 0 0 0 0
54531- 0 0 0 0 0 0 0 0 0 0 0 0
54532- 0 0 0 0 0 0 0 0 0 0 0 0
54533- 0 0 0 0 0 0 0 0 0 0 0 0
54534- 0 0 0 0 0 0 0 0 0 6 6 6
54535- 18 18 18 34 34 34 58 58 58 78 78 78
54536-101 98 89 124 112 88 142 110 46 156 107 11
54537-163 110 8 167 114 7 175 118 6 180 123 7
54538-185 133 11 197 138 11 210 150 10 219 162 10
54539-226 170 11 236 178 12 236 178 12 234 174 13
54540-219 162 10 197 138 11 163 110 8 130 83 6
54541- 91 60 6 10 10 10 2 2 6 2 2 6
54542- 18 18 18 38 38 38 38 38 38 38 38 38
54543- 38 38 38 38 38 38 38 38 38 38 38 38
54544- 38 38 38 38 38 38 26 26 26 2 2 6
54545- 2 2 6 6 6 6 70 47 6 137 92 6
54546-175 118 6 200 144 11 219 162 10 230 174 11
54547-234 174 13 230 174 11 219 162 10 210 150 10
54548-192 133 9 163 110 8 124 112 88 82 82 82
54549- 50 50 50 30 30 30 14 14 14 6 6 6
54550- 0 0 0 0 0 0 0 0 0 0 0 0
54551- 0 0 0 0 0 0 0 0 0 0 0 0
54552- 0 0 0 0 0 0 0 0 0 0 0 0
54553- 0 0 0 0 0 0 0 0 0 0 0 0
54554- 0 0 0 0 0 0 0 0 0 0 0 0
54555- 6 6 6 14 14 14 22 22 22 34 34 34
54556- 42 42 42 58 58 58 74 74 74 86 86 86
54557-101 98 89 122 102 70 130 98 46 121 87 25
54558-137 92 6 152 99 6 163 110 8 180 123 7
54559-185 133 11 197 138 11 206 145 10 200 144 11
54560-180 123 7 156 107 11 130 83 6 104 69 6
54561- 50 34 6 54 54 54 110 110 110 101 98 89
54562- 86 86 86 82 82 82 78 78 78 78 78 78
54563- 78 78 78 78 78 78 78 78 78 78 78 78
54564- 78 78 78 82 82 82 86 86 86 94 94 94
54565-106 106 106 101 101 101 86 66 34 124 80 6
54566-156 107 11 180 123 7 192 133 9 200 144 11
54567-206 145 10 200 144 11 192 133 9 175 118 6
54568-139 102 15 109 106 95 70 70 70 42 42 42
54569- 22 22 22 10 10 10 0 0 0 0 0 0
54570- 0 0 0 0 0 0 0 0 0 0 0 0
54571- 0 0 0 0 0 0 0 0 0 0 0 0
54572- 0 0 0 0 0 0 0 0 0 0 0 0
54573- 0 0 0 0 0 0 0 0 0 0 0 0
54574- 0 0 0 0 0 0 0 0 0 0 0 0
54575- 0 0 0 0 0 0 6 6 6 10 10 10
54576- 14 14 14 22 22 22 30 30 30 38 38 38
54577- 50 50 50 62 62 62 74 74 74 90 90 90
54578-101 98 89 112 100 78 121 87 25 124 80 6
54579-137 92 6 152 99 6 152 99 6 152 99 6
54580-138 86 6 124 80 6 98 70 6 86 66 30
54581-101 98 89 82 82 82 58 58 58 46 46 46
54582- 38 38 38 34 34 34 34 34 34 34 34 34
54583- 34 34 34 34 34 34 34 34 34 34 34 34
54584- 34 34 34 34 34 34 38 38 38 42 42 42
54585- 54 54 54 82 82 82 94 86 76 91 60 6
54586-134 86 6 156 107 11 167 114 7 175 118 6
54587-175 118 6 167 114 7 152 99 6 121 87 25
54588-101 98 89 62 62 62 34 34 34 18 18 18
54589- 6 6 6 0 0 0 0 0 0 0 0 0
54590- 0 0 0 0 0 0 0 0 0 0 0 0
54591- 0 0 0 0 0 0 0 0 0 0 0 0
54592- 0 0 0 0 0 0 0 0 0 0 0 0
54593- 0 0 0 0 0 0 0 0 0 0 0 0
54594- 0 0 0 0 0 0 0 0 0 0 0 0
54595- 0 0 0 0 0 0 0 0 0 0 0 0
54596- 0 0 0 6 6 6 6 6 6 10 10 10
54597- 18 18 18 22 22 22 30 30 30 42 42 42
54598- 50 50 50 66 66 66 86 86 86 101 98 89
54599-106 86 58 98 70 6 104 69 6 104 69 6
54600-104 69 6 91 60 6 82 62 34 90 90 90
54601- 62 62 62 38 38 38 22 22 22 14 14 14
54602- 10 10 10 10 10 10 10 10 10 10 10 10
54603- 10 10 10 10 10 10 6 6 6 10 10 10
54604- 10 10 10 10 10 10 10 10 10 14 14 14
54605- 22 22 22 42 42 42 70 70 70 89 81 66
54606- 80 54 7 104 69 6 124 80 6 137 92 6
54607-134 86 6 116 81 8 100 82 52 86 86 86
54608- 58 58 58 30 30 30 14 14 14 6 6 6
54609- 0 0 0 0 0 0 0 0 0 0 0 0
54610- 0 0 0 0 0 0 0 0 0 0 0 0
54611- 0 0 0 0 0 0 0 0 0 0 0 0
54612- 0 0 0 0 0 0 0 0 0 0 0 0
54613- 0 0 0 0 0 0 0 0 0 0 0 0
54614- 0 0 0 0 0 0 0 0 0 0 0 0
54615- 0 0 0 0 0 0 0 0 0 0 0 0
54616- 0 0 0 0 0 0 0 0 0 0 0 0
54617- 0 0 0 6 6 6 10 10 10 14 14 14
54618- 18 18 18 26 26 26 38 38 38 54 54 54
54619- 70 70 70 86 86 86 94 86 76 89 81 66
54620- 89 81 66 86 86 86 74 74 74 50 50 50
54621- 30 30 30 14 14 14 6 6 6 0 0 0
54622- 0 0 0 0 0 0 0 0 0 0 0 0
54623- 0 0 0 0 0 0 0 0 0 0 0 0
54624- 0 0 0 0 0 0 0 0 0 0 0 0
54625- 6 6 6 18 18 18 34 34 34 58 58 58
54626- 82 82 82 89 81 66 89 81 66 89 81 66
54627- 94 86 66 94 86 76 74 74 74 50 50 50
54628- 26 26 26 14 14 14 6 6 6 0 0 0
54629- 0 0 0 0 0 0 0 0 0 0 0 0
54630- 0 0 0 0 0 0 0 0 0 0 0 0
54631- 0 0 0 0 0 0 0 0 0 0 0 0
54632- 0 0 0 0 0 0 0 0 0 0 0 0
54633- 0 0 0 0 0 0 0 0 0 0 0 0
54634- 0 0 0 0 0 0 0 0 0 0 0 0
54635- 0 0 0 0 0 0 0 0 0 0 0 0
54636- 0 0 0 0 0 0 0 0 0 0 0 0
54637- 0 0 0 0 0 0 0 0 0 0 0 0
54638- 6 6 6 6 6 6 14 14 14 18 18 18
54639- 30 30 30 38 38 38 46 46 46 54 54 54
54640- 50 50 50 42 42 42 30 30 30 18 18 18
54641- 10 10 10 0 0 0 0 0 0 0 0 0
54642- 0 0 0 0 0 0 0 0 0 0 0 0
54643- 0 0 0 0 0 0 0 0 0 0 0 0
54644- 0 0 0 0 0 0 0 0 0 0 0 0
54645- 0 0 0 6 6 6 14 14 14 26 26 26
54646- 38 38 38 50 50 50 58 58 58 58 58 58
54647- 54 54 54 42 42 42 30 30 30 18 18 18
54648- 10 10 10 0 0 0 0 0 0 0 0 0
54649- 0 0 0 0 0 0 0 0 0 0 0 0
54650- 0 0 0 0 0 0 0 0 0 0 0 0
54651- 0 0 0 0 0 0 0 0 0 0 0 0
54652- 0 0 0 0 0 0 0 0 0 0 0 0
54653- 0 0 0 0 0 0 0 0 0 0 0 0
54654- 0 0 0 0 0 0 0 0 0 0 0 0
54655- 0 0 0 0 0 0 0 0 0 0 0 0
54656- 0 0 0 0 0 0 0 0 0 0 0 0
54657- 0 0 0 0 0 0 0 0 0 0 0 0
54658- 0 0 0 0 0 0 0 0 0 6 6 6
54659- 6 6 6 10 10 10 14 14 14 18 18 18
54660- 18 18 18 14 14 14 10 10 10 6 6 6
54661- 0 0 0 0 0 0 0 0 0 0 0 0
54662- 0 0 0 0 0 0 0 0 0 0 0 0
54663- 0 0 0 0 0 0 0 0 0 0 0 0
54664- 0 0 0 0 0 0 0 0 0 0 0 0
54665- 0 0 0 0 0 0 0 0 0 6 6 6
54666- 14 14 14 18 18 18 22 22 22 22 22 22
54667- 18 18 18 14 14 14 10 10 10 6 6 6
54668- 0 0 0 0 0 0 0 0 0 0 0 0
54669- 0 0 0 0 0 0 0 0 0 0 0 0
54670- 0 0 0 0 0 0 0 0 0 0 0 0
54671- 0 0 0 0 0 0 0 0 0 0 0 0
54672- 0 0 0 0 0 0 0 0 0 0 0 0
54673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54686+4 4 4 4 4 4
54687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54700+4 4 4 4 4 4
54701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54714+4 4 4 4 4 4
54715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54728+4 4 4 4 4 4
54729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54742+4 4 4 4 4 4
54743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54756+4 4 4 4 4 4
54757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54761+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54762+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54766+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54767+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54768+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54770+4 4 4 4 4 4
54771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54775+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54776+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54777+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54780+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54781+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54782+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54783+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54784+4 4 4 4 4 4
54785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54789+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54790+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54791+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54794+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54795+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54796+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54797+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54798+4 4 4 4 4 4
54799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54802+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54803+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54804+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54805+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54807+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54808+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54809+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54810+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54811+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54812+4 4 4 4 4 4
54813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54816+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54817+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54818+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54819+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54820+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54821+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54822+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54823+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54824+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54825+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54826+4 4 4 4 4 4
54827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54830+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54831+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54832+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54833+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54834+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54835+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54836+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54837+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54838+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54839+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54840+4 4 4 4 4 4
54841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54843+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54844+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54845+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54846+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54847+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54848+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54849+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54850+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54851+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54852+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54853+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54854+4 4 4 4 4 4
54855+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54856+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54857+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54858+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54859+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54860+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54861+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54862+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54863+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54864+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54865+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54866+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54867+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54868+4 4 4 4 4 4
54869+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54870+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54871+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54872+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54873+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54874+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54875+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54876+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54877+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54878+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54879+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54880+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54881+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54882+4 4 4 4 4 4
54883+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54884+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54885+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54886+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54887+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54888+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54889+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54890+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54891+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54892+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54893+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54894+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54895+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54896+4 4 4 4 4 4
54897+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54898+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
54899+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54900+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54901+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54902+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54903+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54904+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54905+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54906+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54907+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54908+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54909+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54910+4 4 4 4 4 4
54911+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54912+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54913+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54914+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54915+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54916+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54917+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54918+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54919+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54920+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54921+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54922+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54923+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54924+0 0 0 4 4 4
54925+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54926+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54927+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54928+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54929+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54930+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54931+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54932+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54933+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54934+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54935+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54936+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54937+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54938+2 0 0 0 0 0
54939+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54940+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54941+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54942+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54943+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54944+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54945+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54946+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54947+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54948+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54949+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54950+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54951+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54952+37 38 37 0 0 0
54953+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54954+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54955+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54956+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54957+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54958+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54959+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54960+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54961+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54962+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54963+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54964+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54965+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54966+85 115 134 4 0 0
54967+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54968+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54969+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54970+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54971+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54972+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54973+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54974+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54975+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54976+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54977+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54978+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54979+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54980+60 73 81 4 0 0
54981+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54982+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54983+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54984+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54985+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54986+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54987+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54988+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54989+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54990+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54991+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54992+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54993+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54994+16 19 21 4 0 0
54995+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54996+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54997+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54998+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54999+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
55000+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
55001+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
55002+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
55003+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
55004+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
55005+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
55006+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
55007+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
55008+4 0 0 4 3 3
55009+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
55010+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
55011+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
55012+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
55013+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
55014+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
55015+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
55016+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
55017+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
55018+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
55019+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
55020+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
55021+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
55022+3 2 2 4 4 4
55023+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
55024+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
55025+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
55026+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55027+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
55028+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
55029+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
55030+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
55031+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
55032+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
55033+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
55034+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
55035+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
55036+4 4 4 4 4 4
55037+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
55038+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
55039+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
55040+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
55041+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
55042+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
55043+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
55044+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
55045+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
55046+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
55047+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
55048+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
55049+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
55050+4 4 4 4 4 4
55051+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
55052+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
55053+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
55054+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
55055+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
55056+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55057+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
55058+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
55059+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
55060+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
55061+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
55062+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
55063+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
55064+5 5 5 5 5 5
55065+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55066+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55067+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55068+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55069+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55070+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55071+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55072+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55073+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55074+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55075+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55076+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55077+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55078+5 5 5 4 4 4
55079+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55080+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55081+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55082+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55083+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55084+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55085+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55086+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55087+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55088+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55089+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55090+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55092+4 4 4 4 4 4
55093+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55094+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55095+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55096+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55097+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55098+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55099+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55100+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55101+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55102+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55103+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55104+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
55105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55106+4 4 4 4 4 4
55107+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
55108+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55109+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55110+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55111+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55112+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
55113+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55114+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55115+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55116+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55117+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
55118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55120+4 4 4 4 4 4
55121+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
55122+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55123+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55124+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55125+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55126+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55127+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55128+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55129+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55130+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55131+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
55132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55134+4 4 4 4 4 4
55135+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55136+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55137+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55138+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55139+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55140+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55141+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55142+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55143+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55144+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
55145+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55148+4 4 4 4 4 4
55149+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55150+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55151+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55152+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55153+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55154+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55155+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55156+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55157+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55158+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55159+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
55160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55162+4 4 4 4 4 4
55163+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55164+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55165+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55166+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55167+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55168+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55169+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55170+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55171+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55172+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55173+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
55174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55176+4 4 4 4 4 4
55177+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
55178+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55179+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55180+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55181+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55182+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55183+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55184+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55185+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55186+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55187+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55190+4 4 4 4 4 4
55191+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
55192+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55193+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55194+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55195+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55196+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55197+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55198+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55199+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55200+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55201+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55204+4 4 4 4 4 4
55205+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
55206+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55207+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55208+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55209+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55210+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55211+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55212+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55213+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55214+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55215+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55218+4 4 4 4 4 4
55219+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
55220+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55221+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55222+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55223+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55224+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55225+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55226+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
55227+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55228+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55229+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55232+4 4 4 4 4 4
55233+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55234+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55235+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55236+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55237+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55238+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55239+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55240+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55241+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55242+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55243+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55246+4 4 4 4 4 4
55247+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55248+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
55249+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55250+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55251+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55252+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55253+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55254+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55255+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55256+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55257+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55260+4 4 4 4 4 4
55261+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55262+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55263+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55264+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55265+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55266+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55267+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55268+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
55269+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55270+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55271+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55274+4 4 4 4 4 4
55275+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55276+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
55277+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55278+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55279+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55280+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55281+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55282+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55283+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55284+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55285+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55288+4 4 4 4 4 4
55289+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55290+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55291+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55292+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55293+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55294+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55295+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55296+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
55297+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55298+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55299+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55302+4 4 4 4 4 4
55303+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
55304+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55305+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55306+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55307+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55308+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55309+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55310+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55311+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
55312+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55313+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55316+4 4 4 4 4 4
55317+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55318+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55319+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55320+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55321+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55322+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55323+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55324+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55325+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55326+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55327+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55330+4 4 4 4 4 4
55331+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55332+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55333+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55334+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55335+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55336+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55337+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55338+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55339+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55340+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55341+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55344+4 4 4 4 4 4
55345+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55346+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55347+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55348+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55349+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55350+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55351+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55352+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55353+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55354+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55355+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55358+4 4 4 4 4 4
55359+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55360+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55361+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55362+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55363+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55364+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55365+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55366+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55367+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55368+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55369+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55372+4 4 4 4 4 4
55373+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55374+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55375+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55376+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55377+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55378+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55379+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55380+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55381+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55382+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55383+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55386+4 4 4 4 4 4
55387+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55388+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55389+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55390+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55391+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55392+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55393+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55394+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55395+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
55396+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55397+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55400+4 4 4 4 4 4
55401+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55402+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55403+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55404+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55405+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55406+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55407+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55408+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55409+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55410+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55411+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55413+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55414+4 4 4 4 4 4
55415+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55416+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
55417+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
55418+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
55419+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
55420+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
55421+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
55422+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
55423+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
55424+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55425+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55427+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55428+4 4 4 4 4 4
55429+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
55430+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
55431+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
55432+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
55433+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
55434+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
55435+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
55436+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
55437+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
55438+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
55439+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55441+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55442+4 4 4 4 4 4
55443+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
55444+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55445+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
55446+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
55447+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
55448+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
55449+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
55450+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
55451+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
55452+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
55453+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55455+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55456+4 4 4 4 4 4
55457+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
55458+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55459+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
55460+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
55461+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
55462+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
55463+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55464+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
55465+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
55466+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
55467+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55469+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55470+4 4 4 4 4 4
55471+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
55472+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
55473+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
55474+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
55475+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55476+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55477+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55478+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55479+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55480+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55481+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55483+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55484+4 4 4 4 4 4
55485+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55486+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55487+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55488+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55489+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55490+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55491+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55492+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55493+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55494+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
55495+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55497+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55498+4 4 4 4 4 4
55499+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55500+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55501+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55502+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55503+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
55504+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55505+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55506+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55507+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55508+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55509+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55511+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55512+4 4 4 4 4 4
55513+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55514+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55515+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55516+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55517+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55518+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55519+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55520+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55521+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55522+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55523+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55525+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55526+4 4 4 4 4 4
55527+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55528+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55529+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
55530+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
55531+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
55532+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
55533+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
55534+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
55535+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55536+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55537+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55539+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55540+4 4 4 4 4 4
55541+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
55542+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55543+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
55544+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55545+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
55546+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55547+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55548+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55549+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
55550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55553+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55554+4 4 4 4 4 4
55555+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55556+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55557+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55558+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55559+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55560+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55561+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55562+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55563+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
55564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55567+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55568+4 4 4 4 4 4
55569+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55570+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55571+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55572+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55573+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55574+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55575+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55576+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55577+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55579+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55581+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55582+4 4 4 4 4 4
55583+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55584+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55585+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55586+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55587+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55588+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55589+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55590+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55595+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55596+4 4 4 4 4 4
55597+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55598+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55599+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55600+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55601+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55602+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55603+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55604+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55609+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55610+4 4 4 4 4 4
55611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55612+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55613+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55614+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55615+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55616+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55617+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55618+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55624+4 4 4 4 4 4
55625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55626+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55627+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55628+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55629+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55630+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55631+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55632+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55638+4 4 4 4 4 4
55639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55640+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55641+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55642+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55643+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55644+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55645+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55646+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55652+4 4 4 4 4 4
55653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55655+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55656+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55657+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55658+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55659+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55660+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55666+4 4 4 4 4 4
55667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55670+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55671+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55672+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55673+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
55674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55680+4 4 4 4 4 4
55681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55684+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55685+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55686+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55687+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
55688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55694+4 4 4 4 4 4
55695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55698+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55699+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55700+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55701+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
55702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55705+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55708+4 4 4 4 4 4
55709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55712+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
55713+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55714+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55715+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
55716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55719+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55722+4 4 4 4 4 4
55723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55727+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55728+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55729+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55733+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55736+4 4 4 4 4 4
55737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55741+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55742+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55743+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55747+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55750+4 4 4 4 4 4
55751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55755+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55756+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55757+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55761+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55764+4 4 4 4 4 4
55765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55769+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55770+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55775+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55778+4 4 4 4 4 4
55779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55783+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55784+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55788+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55789+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55792+4 4 4 4 4 4
55793diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55794index fef20db..d28b1ab 100644
55795--- a/drivers/xen/xenfs/xenstored.c
55796+++ b/drivers/xen/xenfs/xenstored.c
55797@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55798 static int xsd_kva_open(struct inode *inode, struct file *file)
55799 {
55800 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55801+#ifdef CONFIG_GRKERNSEC_HIDESYM
55802+ NULL);
55803+#else
55804 xen_store_interface);
55805+#endif
55806+
55807 if (!file->private_data)
55808 return -ENOMEM;
55809 return 0;
55810diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55811index c71e886..61d3d44b 100644
55812--- a/fs/9p/vfs_addr.c
55813+++ b/fs/9p/vfs_addr.c
55814@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55815
55816 retval = v9fs_file_write_internal(inode,
55817 v9inode->writeback_fid,
55818- (__force const char __user *)buffer,
55819+ (const char __force_user *)buffer,
55820 len, &offset, 0);
55821 if (retval > 0)
55822 retval = 0;
55823diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55824index 53161ec..e261d8a 100644
55825--- a/fs/9p/vfs_inode.c
55826+++ b/fs/9p/vfs_inode.c
55827@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55828 void
55829 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55830 {
55831- char *s = nd_get_link(nd);
55832+ const char *s = nd_get_link(nd);
55833
55834 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55835 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55836diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55837index 370b24c..ff0be7b 100644
55838--- a/fs/Kconfig.binfmt
55839+++ b/fs/Kconfig.binfmt
55840@@ -103,7 +103,7 @@ config HAVE_AOUT
55841
55842 config BINFMT_AOUT
55843 tristate "Kernel support for a.out and ECOFF binaries"
55844- depends on HAVE_AOUT
55845+ depends on HAVE_AOUT && BROKEN
55846 ---help---
55847 A.out (Assembler.OUTput) is a set of formats for libraries and
55848 executables used in the earliest versions of UNIX. Linux used
55849diff --git a/fs/afs/inode.c b/fs/afs/inode.c
55850index 2946712..f737435 100644
55851--- a/fs/afs/inode.c
55852+++ b/fs/afs/inode.c
55853@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55854 struct afs_vnode *vnode;
55855 struct super_block *sb;
55856 struct inode *inode;
55857- static atomic_t afs_autocell_ino;
55858+ static atomic_unchecked_t afs_autocell_ino;
55859
55860 _enter("{%x:%u},%*.*s,",
55861 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
55862@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55863 data.fid.unique = 0;
55864 data.fid.vnode = 0;
55865
55866- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55867+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55868 afs_iget5_autocell_test, afs_iget5_set,
55869 &data);
55870 if (!inode) {
55871diff --git a/fs/aio.c b/fs/aio.c
55872index a0ed6c7..c9fcd97 100644
55873--- a/fs/aio.c
55874+++ b/fs/aio.c
55875@@ -380,7 +380,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55876 size += sizeof(struct io_event) * nr_events;
55877
55878 nr_pages = PFN_UP(size);
55879- if (nr_pages < 0)
55880+ if (nr_pages <= 0)
55881 return -EINVAL;
55882
55883 file = aio_private_file(ctx, nr_pages);
55884@@ -1021,6 +1021,7 @@ void aio_complete(struct kiocb *iocb, long res, long res2)
55885
55886 /* everything turned out well, dispose of the aiocb. */
55887 kiocb_free(iocb);
55888+ put_reqs_available(ctx, 1);
55889
55890 /*
55891 * We have to order our ring_info tail store above and test
55892@@ -1062,6 +1063,9 @@ static long aio_read_events_ring(struct kioctx *ctx,
55893 if (head == tail)
55894 goto out;
55895
55896+ head %= ctx->nr_events;
55897+ tail %= ctx->nr_events;
55898+
55899 while (ret < nr) {
55900 long avail;
55901 struct io_event *ev;
55902@@ -1100,8 +1104,6 @@ static long aio_read_events_ring(struct kioctx *ctx,
55903 flush_dcache_page(ctx->ring_pages[0]);
55904
55905 pr_debug("%li h%u t%u\n", ret, head, tail);
55906-
55907- put_reqs_available(ctx, ret);
55908 out:
55909 mutex_unlock(&ctx->ring_lock);
55910
55911diff --git a/fs/attr.c b/fs/attr.c
55912index 6530ced..4a827e2 100644
55913--- a/fs/attr.c
55914+++ b/fs/attr.c
55915@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55916 unsigned long limit;
55917
55918 limit = rlimit(RLIMIT_FSIZE);
55919+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55920 if (limit != RLIM_INFINITY && offset > limit)
55921 goto out_sig;
55922 if (offset > inode->i_sb->s_maxbytes)
55923diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55924index 116fd38..c04182da 100644
55925--- a/fs/autofs4/waitq.c
55926+++ b/fs/autofs4/waitq.c
55927@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55928 {
55929 unsigned long sigpipe, flags;
55930 mm_segment_t fs;
55931- const char *data = (const char *)addr;
55932+ const char __user *data = (const char __force_user *)addr;
55933 ssize_t wr = 0;
55934
55935 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55936@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55937 return 1;
55938 }
55939
55940+#ifdef CONFIG_GRKERNSEC_HIDESYM
55941+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
55942+#endif
55943+
55944 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55945 enum autofs_notify notify)
55946 {
55947@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55948
55949 /* If this is a direct mount request create a dummy name */
55950 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
55951+#ifdef CONFIG_GRKERNSEC_HIDESYM
55952+ /* this name does get written to userland via autofs4_write() */
55953+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
55954+#else
55955 qstr.len = sprintf(name, "%p", dentry);
55956+#endif
55957 else {
55958 qstr.len = autofs4_getpath(sbi, dentry, &name);
55959 if (!qstr.len) {
55960diff --git a/fs/befs/endian.h b/fs/befs/endian.h
55961index 2722387..56059b5 100644
55962--- a/fs/befs/endian.h
55963+++ b/fs/befs/endian.h
55964@@ -11,7 +11,7 @@
55965
55966 #include <asm/byteorder.h>
55967
55968-static inline u64
55969+static inline u64 __intentional_overflow(-1)
55970 fs64_to_cpu(const struct super_block *sb, fs64 n)
55971 {
55972 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55973@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
55974 return (__force fs64)cpu_to_be64(n);
55975 }
55976
55977-static inline u32
55978+static inline u32 __intentional_overflow(-1)
55979 fs32_to_cpu(const struct super_block *sb, fs32 n)
55980 {
55981 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55982@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
55983 return (__force fs32)cpu_to_be32(n);
55984 }
55985
55986-static inline u16
55987+static inline u16 __intentional_overflow(-1)
55988 fs16_to_cpu(const struct super_block *sb, fs16 n)
55989 {
55990 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55991diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
55992index ca0ba15..0fa3257 100644
55993--- a/fs/binfmt_aout.c
55994+++ b/fs/binfmt_aout.c
55995@@ -16,6 +16,7 @@
55996 #include <linux/string.h>
55997 #include <linux/fs.h>
55998 #include <linux/file.h>
55999+#include <linux/security.h>
56000 #include <linux/stat.h>
56001 #include <linux/fcntl.h>
56002 #include <linux/ptrace.h>
56003@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56004 #endif
56005 # define START_STACK(u) ((void __user *)u.start_stack)
56006
56007+ memset(&dump, 0, sizeof(dump));
56008+
56009 fs = get_fs();
56010 set_fs(KERNEL_DS);
56011 has_dumped = 1;
56012@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56013
56014 /* If the size of the dump file exceeds the rlimit, then see what would happen
56015 if we wrote the stack, but not the data area. */
56016+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56017 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56018 dump.u_dsize = 0;
56019
56020 /* Make sure we have enough room to write the stack and data areas. */
56021+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56022 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56023 dump.u_ssize = 0;
56024
56025@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56026 rlim = rlimit(RLIMIT_DATA);
56027 if (rlim >= RLIM_INFINITY)
56028 rlim = ~0;
56029+
56030+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56031 if (ex.a_data + ex.a_bss > rlim)
56032 return -ENOMEM;
56033
56034@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56035
56036 install_exec_creds(bprm);
56037
56038+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56039+ current->mm->pax_flags = 0UL;
56040+#endif
56041+
56042+#ifdef CONFIG_PAX_PAGEEXEC
56043+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56044+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56045+
56046+#ifdef CONFIG_PAX_EMUTRAMP
56047+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56048+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56049+#endif
56050+
56051+#ifdef CONFIG_PAX_MPROTECT
56052+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56053+ current->mm->pax_flags |= MF_PAX_MPROTECT;
56054+#endif
56055+
56056+ }
56057+#endif
56058+
56059 if (N_MAGIC(ex) == OMAGIC) {
56060 unsigned long text_addr, map_size;
56061 loff_t pos;
56062@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56063 }
56064
56065 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56066- PROT_READ | PROT_WRITE | PROT_EXEC,
56067+ PROT_READ | PROT_WRITE,
56068 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56069 fd_offset + ex.a_text);
56070 if (error != N_DATADDR(ex)) {
56071diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56072index aa3cb62..bc53934 100644
56073--- a/fs/binfmt_elf.c
56074+++ b/fs/binfmt_elf.c
56075@@ -34,6 +34,7 @@
56076 #include <linux/utsname.h>
56077 #include <linux/coredump.h>
56078 #include <linux/sched.h>
56079+#include <linux/xattr.h>
56080 #include <asm/uaccess.h>
56081 #include <asm/param.h>
56082 #include <asm/page.h>
56083@@ -47,7 +48,7 @@
56084
56085 static int load_elf_binary(struct linux_binprm *bprm);
56086 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56087- int, int, unsigned long);
56088+ int, int, unsigned long) __intentional_overflow(-1);
56089
56090 #ifdef CONFIG_USELIB
56091 static int load_elf_library(struct file *);
56092@@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56093 #define elf_core_dump NULL
56094 #endif
56095
56096+#ifdef CONFIG_PAX_MPROTECT
56097+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56098+#endif
56099+
56100+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56101+static void elf_handle_mmap(struct file *file);
56102+#endif
56103+
56104 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56105 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56106 #else
56107@@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
56108 .load_binary = load_elf_binary,
56109 .load_shlib = load_elf_library,
56110 .core_dump = elf_core_dump,
56111+
56112+#ifdef CONFIG_PAX_MPROTECT
56113+ .handle_mprotect= elf_handle_mprotect,
56114+#endif
56115+
56116+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56117+ .handle_mmap = elf_handle_mmap,
56118+#endif
56119+
56120 .min_coredump = ELF_EXEC_PAGESIZE,
56121 };
56122
56123@@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
56124
56125 static int set_brk(unsigned long start, unsigned long end)
56126 {
56127+ unsigned long e = end;
56128+
56129 start = ELF_PAGEALIGN(start);
56130 end = ELF_PAGEALIGN(end);
56131 if (end > start) {
56132@@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
56133 if (BAD_ADDR(addr))
56134 return addr;
56135 }
56136- current->mm->start_brk = current->mm->brk = end;
56137+ current->mm->start_brk = current->mm->brk = e;
56138 return 0;
56139 }
56140
56141@@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56142 elf_addr_t __user *u_rand_bytes;
56143 const char *k_platform = ELF_PLATFORM;
56144 const char *k_base_platform = ELF_BASE_PLATFORM;
56145- unsigned char k_rand_bytes[16];
56146+ u32 k_rand_bytes[4];
56147 int items;
56148 elf_addr_t *elf_info;
56149 int ei_index = 0;
56150 const struct cred *cred = current_cred();
56151 struct vm_area_struct *vma;
56152+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56153
56154 /*
56155 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56156@@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56157 * Generate 16 random bytes for userspace PRNG seeding.
56158 */
56159 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56160- u_rand_bytes = (elf_addr_t __user *)
56161- STACK_ALLOC(p, sizeof(k_rand_bytes));
56162+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56163+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56164+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56165+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56166+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56167+ u_rand_bytes = (elf_addr_t __user *) p;
56168 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56169 return -EFAULT;
56170
56171@@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56172 return -EFAULT;
56173 current->mm->env_end = p;
56174
56175+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56176+
56177 /* Put the elf_info on the stack in the right place. */
56178 sp = (elf_addr_t __user *)envp + 1;
56179- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56180+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56181 return -EFAULT;
56182 return 0;
56183 }
56184@@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56185 an ELF header */
56186
56187 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56188- struct file *interpreter, unsigned long *interp_map_addr,
56189- unsigned long no_base)
56190+ struct file *interpreter, unsigned long no_base)
56191 {
56192 struct elf_phdr *elf_phdata;
56193 struct elf_phdr *eppnt;
56194- unsigned long load_addr = 0;
56195+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56196 int load_addr_set = 0;
56197 unsigned long last_bss = 0, elf_bss = 0;
56198- unsigned long error = ~0UL;
56199+ unsigned long error = -EINVAL;
56200 unsigned long total_size;
56201 int retval, i, size;
56202
56203@@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56204 goto out_close;
56205 }
56206
56207+#ifdef CONFIG_PAX_SEGMEXEC
56208+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56209+ pax_task_size = SEGMEXEC_TASK_SIZE;
56210+#endif
56211+
56212 eppnt = elf_phdata;
56213 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56214 if (eppnt->p_type == PT_LOAD) {
56215@@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56216 map_addr = elf_map(interpreter, load_addr + vaddr,
56217 eppnt, elf_prot, elf_type, total_size);
56218 total_size = 0;
56219- if (!*interp_map_addr)
56220- *interp_map_addr = map_addr;
56221 error = map_addr;
56222 if (BAD_ADDR(map_addr))
56223 goto out_close;
56224@@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56225 k = load_addr + eppnt->p_vaddr;
56226 if (BAD_ADDR(k) ||
56227 eppnt->p_filesz > eppnt->p_memsz ||
56228- eppnt->p_memsz > TASK_SIZE ||
56229- TASK_SIZE - eppnt->p_memsz < k) {
56230+ eppnt->p_memsz > pax_task_size ||
56231+ pax_task_size - eppnt->p_memsz < k) {
56232 error = -ENOMEM;
56233 goto out_close;
56234 }
56235@@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56236 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56237
56238 /* Map the last of the bss segment */
56239- error = vm_brk(elf_bss, last_bss - elf_bss);
56240- if (BAD_ADDR(error))
56241- goto out_close;
56242+ if (last_bss > elf_bss) {
56243+ error = vm_brk(elf_bss, last_bss - elf_bss);
56244+ if (BAD_ADDR(error))
56245+ goto out_close;
56246+ }
56247 }
56248
56249 error = load_addr;
56250@@ -543,6 +574,336 @@ out:
56251 return error;
56252 }
56253
56254+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56255+#ifdef CONFIG_PAX_SOFTMODE
56256+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56257+{
56258+ unsigned long pax_flags = 0UL;
56259+
56260+#ifdef CONFIG_PAX_PAGEEXEC
56261+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56262+ pax_flags |= MF_PAX_PAGEEXEC;
56263+#endif
56264+
56265+#ifdef CONFIG_PAX_SEGMEXEC
56266+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56267+ pax_flags |= MF_PAX_SEGMEXEC;
56268+#endif
56269+
56270+#ifdef CONFIG_PAX_EMUTRAMP
56271+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56272+ pax_flags |= MF_PAX_EMUTRAMP;
56273+#endif
56274+
56275+#ifdef CONFIG_PAX_MPROTECT
56276+ if (elf_phdata->p_flags & PF_MPROTECT)
56277+ pax_flags |= MF_PAX_MPROTECT;
56278+#endif
56279+
56280+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56281+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56282+ pax_flags |= MF_PAX_RANDMMAP;
56283+#endif
56284+
56285+ return pax_flags;
56286+}
56287+#endif
56288+
56289+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56290+{
56291+ unsigned long pax_flags = 0UL;
56292+
56293+#ifdef CONFIG_PAX_PAGEEXEC
56294+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56295+ pax_flags |= MF_PAX_PAGEEXEC;
56296+#endif
56297+
56298+#ifdef CONFIG_PAX_SEGMEXEC
56299+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56300+ pax_flags |= MF_PAX_SEGMEXEC;
56301+#endif
56302+
56303+#ifdef CONFIG_PAX_EMUTRAMP
56304+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56305+ pax_flags |= MF_PAX_EMUTRAMP;
56306+#endif
56307+
56308+#ifdef CONFIG_PAX_MPROTECT
56309+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56310+ pax_flags |= MF_PAX_MPROTECT;
56311+#endif
56312+
56313+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56314+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56315+ pax_flags |= MF_PAX_RANDMMAP;
56316+#endif
56317+
56318+ return pax_flags;
56319+}
56320+#endif
56321+
56322+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56323+#ifdef CONFIG_PAX_SOFTMODE
56324+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56325+{
56326+ unsigned long pax_flags = 0UL;
56327+
56328+#ifdef CONFIG_PAX_PAGEEXEC
56329+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56330+ pax_flags |= MF_PAX_PAGEEXEC;
56331+#endif
56332+
56333+#ifdef CONFIG_PAX_SEGMEXEC
56334+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56335+ pax_flags |= MF_PAX_SEGMEXEC;
56336+#endif
56337+
56338+#ifdef CONFIG_PAX_EMUTRAMP
56339+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56340+ pax_flags |= MF_PAX_EMUTRAMP;
56341+#endif
56342+
56343+#ifdef CONFIG_PAX_MPROTECT
56344+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56345+ pax_flags |= MF_PAX_MPROTECT;
56346+#endif
56347+
56348+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56349+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56350+ pax_flags |= MF_PAX_RANDMMAP;
56351+#endif
56352+
56353+ return pax_flags;
56354+}
56355+#endif
56356+
56357+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56358+{
56359+ unsigned long pax_flags = 0UL;
56360+
56361+#ifdef CONFIG_PAX_PAGEEXEC
56362+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56363+ pax_flags |= MF_PAX_PAGEEXEC;
56364+#endif
56365+
56366+#ifdef CONFIG_PAX_SEGMEXEC
56367+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56368+ pax_flags |= MF_PAX_SEGMEXEC;
56369+#endif
56370+
56371+#ifdef CONFIG_PAX_EMUTRAMP
56372+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56373+ pax_flags |= MF_PAX_EMUTRAMP;
56374+#endif
56375+
56376+#ifdef CONFIG_PAX_MPROTECT
56377+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56378+ pax_flags |= MF_PAX_MPROTECT;
56379+#endif
56380+
56381+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56382+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56383+ pax_flags |= MF_PAX_RANDMMAP;
56384+#endif
56385+
56386+ return pax_flags;
56387+}
56388+#endif
56389+
56390+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56391+static unsigned long pax_parse_defaults(void)
56392+{
56393+ unsigned long pax_flags = 0UL;
56394+
56395+#ifdef CONFIG_PAX_SOFTMODE
56396+ if (pax_softmode)
56397+ return pax_flags;
56398+#endif
56399+
56400+#ifdef CONFIG_PAX_PAGEEXEC
56401+ pax_flags |= MF_PAX_PAGEEXEC;
56402+#endif
56403+
56404+#ifdef CONFIG_PAX_SEGMEXEC
56405+ pax_flags |= MF_PAX_SEGMEXEC;
56406+#endif
56407+
56408+#ifdef CONFIG_PAX_MPROTECT
56409+ pax_flags |= MF_PAX_MPROTECT;
56410+#endif
56411+
56412+#ifdef CONFIG_PAX_RANDMMAP
56413+ if (randomize_va_space)
56414+ pax_flags |= MF_PAX_RANDMMAP;
56415+#endif
56416+
56417+ return pax_flags;
56418+}
56419+
56420+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56421+{
56422+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56423+
56424+#ifdef CONFIG_PAX_EI_PAX
56425+
56426+#ifdef CONFIG_PAX_SOFTMODE
56427+ if (pax_softmode)
56428+ return pax_flags;
56429+#endif
56430+
56431+ pax_flags = 0UL;
56432+
56433+#ifdef CONFIG_PAX_PAGEEXEC
56434+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56435+ pax_flags |= MF_PAX_PAGEEXEC;
56436+#endif
56437+
56438+#ifdef CONFIG_PAX_SEGMEXEC
56439+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56440+ pax_flags |= MF_PAX_SEGMEXEC;
56441+#endif
56442+
56443+#ifdef CONFIG_PAX_EMUTRAMP
56444+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56445+ pax_flags |= MF_PAX_EMUTRAMP;
56446+#endif
56447+
56448+#ifdef CONFIG_PAX_MPROTECT
56449+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56450+ pax_flags |= MF_PAX_MPROTECT;
56451+#endif
56452+
56453+#ifdef CONFIG_PAX_ASLR
56454+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56455+ pax_flags |= MF_PAX_RANDMMAP;
56456+#endif
56457+
56458+#endif
56459+
56460+ return pax_flags;
56461+
56462+}
56463+
56464+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56465+{
56466+
56467+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56468+ unsigned long i;
56469+
56470+ for (i = 0UL; i < elf_ex->e_phnum; i++)
56471+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56472+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56473+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56474+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56475+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56476+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56477+ return PAX_PARSE_FLAGS_FALLBACK;
56478+
56479+#ifdef CONFIG_PAX_SOFTMODE
56480+ if (pax_softmode)
56481+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56482+ else
56483+#endif
56484+
56485+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56486+ break;
56487+ }
56488+#endif
56489+
56490+ return PAX_PARSE_FLAGS_FALLBACK;
56491+}
56492+
56493+static unsigned long pax_parse_xattr_pax(struct file * const file)
56494+{
56495+
56496+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56497+ ssize_t xattr_size, i;
56498+ unsigned char xattr_value[sizeof("pemrs") - 1];
56499+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56500+
56501+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56502+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56503+ return PAX_PARSE_FLAGS_FALLBACK;
56504+
56505+ for (i = 0; i < xattr_size; i++)
56506+ switch (xattr_value[i]) {
56507+ default:
56508+ return PAX_PARSE_FLAGS_FALLBACK;
56509+
56510+#define parse_flag(option1, option2, flag) \
56511+ case option1: \
56512+ if (pax_flags_hardmode & MF_PAX_##flag) \
56513+ return PAX_PARSE_FLAGS_FALLBACK;\
56514+ pax_flags_hardmode |= MF_PAX_##flag; \
56515+ break; \
56516+ case option2: \
56517+ if (pax_flags_softmode & MF_PAX_##flag) \
56518+ return PAX_PARSE_FLAGS_FALLBACK;\
56519+ pax_flags_softmode |= MF_PAX_##flag; \
56520+ break;
56521+
56522+ parse_flag('p', 'P', PAGEEXEC);
56523+ parse_flag('e', 'E', EMUTRAMP);
56524+ parse_flag('m', 'M', MPROTECT);
56525+ parse_flag('r', 'R', RANDMMAP);
56526+ parse_flag('s', 'S', SEGMEXEC);
56527+
56528+#undef parse_flag
56529+ }
56530+
56531+ if (pax_flags_hardmode & pax_flags_softmode)
56532+ return PAX_PARSE_FLAGS_FALLBACK;
56533+
56534+#ifdef CONFIG_PAX_SOFTMODE
56535+ if (pax_softmode)
56536+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56537+ else
56538+#endif
56539+
56540+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56541+#else
56542+ return PAX_PARSE_FLAGS_FALLBACK;
56543+#endif
56544+
56545+}
56546+
56547+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56548+{
56549+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56550+
56551+ pax_flags = pax_parse_defaults();
56552+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
56553+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56554+ xattr_pax_flags = pax_parse_xattr_pax(file);
56555+
56556+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56557+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56558+ pt_pax_flags != xattr_pax_flags)
56559+ return -EINVAL;
56560+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56561+ pax_flags = xattr_pax_flags;
56562+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56563+ pax_flags = pt_pax_flags;
56564+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56565+ pax_flags = ei_pax_flags;
56566+
56567+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56568+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56569+ if ((__supported_pte_mask & _PAGE_NX))
56570+ pax_flags &= ~MF_PAX_SEGMEXEC;
56571+ else
56572+ pax_flags &= ~MF_PAX_PAGEEXEC;
56573+ }
56574+#endif
56575+
56576+ if (0 > pax_check_flags(&pax_flags))
56577+ return -EINVAL;
56578+
56579+ current->mm->pax_flags = pax_flags;
56580+ return 0;
56581+}
56582+#endif
56583+
56584 /*
56585 * These are the functions used to load ELF style executables and shared
56586 * libraries. There is no binary dependent code anywhere else.
56587@@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56588 {
56589 unsigned int random_variable = 0;
56590
56591+#ifdef CONFIG_PAX_RANDUSTACK
56592+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56593+ return stack_top - current->mm->delta_stack;
56594+#endif
56595+
56596 if ((current->flags & PF_RANDOMIZE) &&
56597 !(current->personality & ADDR_NO_RANDOMIZE)) {
56598 random_variable = get_random_int() & STACK_RND_MASK;
56599@@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56600 unsigned long load_addr = 0, load_bias = 0;
56601 int load_addr_set = 0;
56602 char * elf_interpreter = NULL;
56603- unsigned long error;
56604+ unsigned long error = 0;
56605 struct elf_phdr *elf_ppnt, *elf_phdata;
56606 unsigned long elf_bss, elf_brk;
56607 int retval, i;
56608@@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56609 struct elfhdr elf_ex;
56610 struct elfhdr interp_elf_ex;
56611 } *loc;
56612+ unsigned long pax_task_size;
56613
56614 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56615 if (!loc) {
56616@@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
56617 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56618 may depend on the personality. */
56619 SET_PERSONALITY(loc->elf_ex);
56620+
56621+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56622+ current->mm->pax_flags = 0UL;
56623+#endif
56624+
56625+#ifdef CONFIG_PAX_DLRESOLVE
56626+ current->mm->call_dl_resolve = 0UL;
56627+#endif
56628+
56629+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56630+ current->mm->call_syscall = 0UL;
56631+#endif
56632+
56633+#ifdef CONFIG_PAX_ASLR
56634+ current->mm->delta_mmap = 0UL;
56635+ current->mm->delta_stack = 0UL;
56636+#endif
56637+
56638+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56639+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56640+ send_sig(SIGKILL, current, 0);
56641+ goto out_free_dentry;
56642+ }
56643+#endif
56644+
56645+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56646+ pax_set_initial_flags(bprm);
56647+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56648+ if (pax_set_initial_flags_func)
56649+ (pax_set_initial_flags_func)(bprm);
56650+#endif
56651+
56652+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56653+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56654+ current->mm->context.user_cs_limit = PAGE_SIZE;
56655+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56656+ }
56657+#endif
56658+
56659+#ifdef CONFIG_PAX_SEGMEXEC
56660+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56661+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56662+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56663+ pax_task_size = SEGMEXEC_TASK_SIZE;
56664+ current->mm->def_flags |= VM_NOHUGEPAGE;
56665+ } else
56666+#endif
56667+
56668+ pax_task_size = TASK_SIZE;
56669+
56670+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56671+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56672+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56673+ put_cpu();
56674+ }
56675+#endif
56676+
56677+#ifdef CONFIG_PAX_ASLR
56678+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56679+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56680+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56681+ }
56682+#endif
56683+
56684+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56685+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56686+ executable_stack = EXSTACK_DISABLE_X;
56687+ current->personality &= ~READ_IMPLIES_EXEC;
56688+ } else
56689+#endif
56690+
56691 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56692 current->personality |= READ_IMPLIES_EXEC;
56693
56694@@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56695 #else
56696 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56697 #endif
56698+
56699+#ifdef CONFIG_PAX_RANDMMAP
56700+ /* PaX: randomize base address at the default exe base if requested */
56701+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56702+#ifdef CONFIG_SPARC64
56703+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56704+#else
56705+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56706+#endif
56707+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56708+ elf_flags |= MAP_FIXED;
56709+ }
56710+#endif
56711+
56712 }
56713
56714 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56715@@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56716 * allowed task size. Note that p_filesz must always be
56717 * <= p_memsz so it is only necessary to check p_memsz.
56718 */
56719- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56720- elf_ppnt->p_memsz > TASK_SIZE ||
56721- TASK_SIZE - elf_ppnt->p_memsz < k) {
56722+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56723+ elf_ppnt->p_memsz > pax_task_size ||
56724+ pax_task_size - elf_ppnt->p_memsz < k) {
56725 /* set_brk can never work. Avoid overflows. */
56726 send_sig(SIGKILL, current, 0);
56727 retval = -EINVAL;
56728@@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56729 goto out_free_dentry;
56730 }
56731 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56732- send_sig(SIGSEGV, current, 0);
56733- retval = -EFAULT; /* Nobody gets to see this, but.. */
56734- goto out_free_dentry;
56735+ /*
56736+ * This bss-zeroing can fail if the ELF
56737+ * file specifies odd protections. So
56738+ * we don't check the return value
56739+ */
56740 }
56741
56742+#ifdef CONFIG_PAX_RANDMMAP
56743+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56744+ unsigned long start, size, flags;
56745+ vm_flags_t vm_flags;
56746+
56747+ start = ELF_PAGEALIGN(elf_brk);
56748+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56749+ flags = MAP_FIXED | MAP_PRIVATE;
56750+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56751+
56752+ down_write(&current->mm->mmap_sem);
56753+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56754+ retval = -ENOMEM;
56755+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56756+// if (current->personality & ADDR_NO_RANDOMIZE)
56757+// vm_flags |= VM_READ | VM_MAYREAD;
56758+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56759+ retval = IS_ERR_VALUE(start) ? start : 0;
56760+ }
56761+ up_write(&current->mm->mmap_sem);
56762+ if (retval == 0)
56763+ retval = set_brk(start + size, start + size + PAGE_SIZE);
56764+ if (retval < 0) {
56765+ send_sig(SIGKILL, current, 0);
56766+ goto out_free_dentry;
56767+ }
56768+ }
56769+#endif
56770+
56771 if (elf_interpreter) {
56772- unsigned long interp_map_addr = 0;
56773-
56774 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56775 interpreter,
56776- &interp_map_addr,
56777 load_bias);
56778 if (!IS_ERR((void *)elf_entry)) {
56779 /*
56780@@ -1122,7 +1602,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56781 * Decide what to dump of a segment, part, all or none.
56782 */
56783 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56784- unsigned long mm_flags)
56785+ unsigned long mm_flags, long signr)
56786 {
56787 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56788
56789@@ -1160,7 +1640,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56790 if (vma->vm_file == NULL)
56791 return 0;
56792
56793- if (FILTER(MAPPED_PRIVATE))
56794+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56795 goto whole;
56796
56797 /*
56798@@ -1367,9 +1847,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56799 {
56800 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56801 int i = 0;
56802- do
56803+ do {
56804 i += 2;
56805- while (auxv[i - 2] != AT_NULL);
56806+ } while (auxv[i - 2] != AT_NULL);
56807 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56808 }
56809
56810@@ -1378,7 +1858,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56811 {
56812 mm_segment_t old_fs = get_fs();
56813 set_fs(KERNEL_DS);
56814- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56815+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56816 set_fs(old_fs);
56817 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56818 }
56819@@ -2002,14 +2482,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56820 }
56821
56822 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56823- unsigned long mm_flags)
56824+ struct coredump_params *cprm)
56825 {
56826 struct vm_area_struct *vma;
56827 size_t size = 0;
56828
56829 for (vma = first_vma(current, gate_vma); vma != NULL;
56830 vma = next_vma(vma, gate_vma))
56831- size += vma_dump_size(vma, mm_flags);
56832+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56833 return size;
56834 }
56835
56836@@ -2100,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56837
56838 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56839
56840- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56841+ offset += elf_core_vma_data_size(gate_vma, cprm);
56842 offset += elf_core_extra_data_size();
56843 e_shoff = offset;
56844
56845@@ -2128,7 +2608,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56846 phdr.p_offset = offset;
56847 phdr.p_vaddr = vma->vm_start;
56848 phdr.p_paddr = 0;
56849- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56850+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56851 phdr.p_memsz = vma->vm_end - vma->vm_start;
56852 offset += phdr.p_filesz;
56853 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
56854@@ -2161,7 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56855 unsigned long addr;
56856 unsigned long end;
56857
56858- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
56859+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56860
56861 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
56862 struct page *page;
56863@@ -2202,6 +2682,167 @@ out:
56864
56865 #endif /* CONFIG_ELF_CORE */
56866
56867+#ifdef CONFIG_PAX_MPROTECT
56868+/* PaX: non-PIC ELF libraries need relocations on their executable segments
56869+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
56870+ * we'll remove VM_MAYWRITE for good on RELRO segments.
56871+ *
56872+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
56873+ * basis because we want to allow the common case and not the special ones.
56874+ */
56875+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
56876+{
56877+ struct elfhdr elf_h;
56878+ struct elf_phdr elf_p;
56879+ unsigned long i;
56880+ unsigned long oldflags;
56881+ bool is_textrel_rw, is_textrel_rx, is_relro;
56882+
56883+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
56884+ return;
56885+
56886+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
56887+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
56888+
56889+#ifdef CONFIG_PAX_ELFRELOCS
56890+ /* possible TEXTREL */
56891+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56892+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56893+#else
56894+ is_textrel_rw = false;
56895+ is_textrel_rx = false;
56896+#endif
56897+
56898+ /* possible RELRO */
56899+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56900+
56901+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56902+ return;
56903+
56904+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56905+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56906+
56907+#ifdef CONFIG_PAX_ETEXECRELOCS
56908+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56909+#else
56910+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56911+#endif
56912+
56913+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56914+ !elf_check_arch(&elf_h) ||
56915+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56916+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56917+ return;
56918+
56919+ for (i = 0UL; i < elf_h.e_phnum; i++) {
56920+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56921+ return;
56922+ switch (elf_p.p_type) {
56923+ case PT_DYNAMIC:
56924+ if (!is_textrel_rw && !is_textrel_rx)
56925+ continue;
56926+ i = 0UL;
56927+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
56928+ elf_dyn dyn;
56929+
56930+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
56931+ break;
56932+ if (dyn.d_tag == DT_NULL)
56933+ break;
56934+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56935+ gr_log_textrel(vma);
56936+ if (is_textrel_rw)
56937+ vma->vm_flags |= VM_MAYWRITE;
56938+ else
56939+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56940+ vma->vm_flags &= ~VM_MAYWRITE;
56941+ break;
56942+ }
56943+ i++;
56944+ }
56945+ is_textrel_rw = false;
56946+ is_textrel_rx = false;
56947+ continue;
56948+
56949+ case PT_GNU_RELRO:
56950+ if (!is_relro)
56951+ continue;
56952+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
56953+ vma->vm_flags &= ~VM_MAYWRITE;
56954+ is_relro = false;
56955+ continue;
56956+
56957+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56958+ case PT_PAX_FLAGS: {
56959+ const char *msg_mprotect = "", *msg_emutramp = "";
56960+ char *buffer_lib, *buffer_exe;
56961+
56962+ if (elf_p.p_flags & PF_NOMPROTECT)
56963+ msg_mprotect = "MPROTECT disabled";
56964+
56965+#ifdef CONFIG_PAX_EMUTRAMP
56966+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
56967+ msg_emutramp = "EMUTRAMP enabled";
56968+#endif
56969+
56970+ if (!msg_mprotect[0] && !msg_emutramp[0])
56971+ continue;
56972+
56973+ if (!printk_ratelimit())
56974+ continue;
56975+
56976+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
56977+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
56978+ if (buffer_lib && buffer_exe) {
56979+ char *path_lib, *path_exe;
56980+
56981+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
56982+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
56983+
56984+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
56985+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
56986+
56987+ }
56988+ free_page((unsigned long)buffer_exe);
56989+ free_page((unsigned long)buffer_lib);
56990+ continue;
56991+ }
56992+#endif
56993+
56994+ }
56995+ }
56996+}
56997+#endif
56998+
56999+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57000+
57001+extern int grsec_enable_log_rwxmaps;
57002+
57003+static void elf_handle_mmap(struct file *file)
57004+{
57005+ struct elfhdr elf_h;
57006+ struct elf_phdr elf_p;
57007+ unsigned long i;
57008+
57009+ if (!grsec_enable_log_rwxmaps)
57010+ return;
57011+
57012+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57013+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57014+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57015+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57016+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57017+ return;
57018+
57019+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57020+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57021+ return;
57022+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57023+ gr_log_ptgnustack(file);
57024+ }
57025+}
57026+#endif
57027+
57028 static int __init init_elf_binfmt(void)
57029 {
57030 register_binfmt(&elf_format);
57031diff --git a/fs/bio.c b/fs/bio.c
57032index 6f0362b..26a7496 100644
57033--- a/fs/bio.c
57034+++ b/fs/bio.c
57035@@ -1144,7 +1144,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57036 /*
57037 * Overflow, abort
57038 */
57039- if (end < start)
57040+ if (end < start || end - start > INT_MAX - nr_pages)
57041 return ERR_PTR(-EINVAL);
57042
57043 nr_pages += end - start;
57044@@ -1278,7 +1278,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57045 /*
57046 * Overflow, abort
57047 */
57048- if (end < start)
57049+ if (end < start || end - start > INT_MAX - nr_pages)
57050 return ERR_PTR(-EINVAL);
57051
57052 nr_pages += end - start;
57053@@ -1540,7 +1540,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57054 const int read = bio_data_dir(bio) == READ;
57055 struct bio_map_data *bmd = bio->bi_private;
57056 int i;
57057- char *p = bmd->sgvecs[0].iov_base;
57058+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57059
57060 bio_for_each_segment_all(bvec, bio, i) {
57061 char *addr = page_address(bvec->bv_page);
57062diff --git a/fs/block_dev.c b/fs/block_dev.c
57063index 552a8d1..d51ccf3 100644
57064--- a/fs/block_dev.c
57065+++ b/fs/block_dev.c
57066@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57067 else if (bdev->bd_contains == bdev)
57068 return true; /* is a whole device which isn't held */
57069
57070- else if (whole->bd_holder == bd_may_claim)
57071+ else if (whole->bd_holder == (void *)bd_may_claim)
57072 return true; /* is a partition of a device that is being partitioned */
57073 else if (whole->bd_holder != NULL)
57074 return false; /* is a partition of a held device */
57075diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57076index 1bcfcdb..e942132 100644
57077--- a/fs/btrfs/ctree.c
57078+++ b/fs/btrfs/ctree.c
57079@@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57080 free_extent_buffer(buf);
57081 add_root_to_dirty_list(root);
57082 } else {
57083- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57084- parent_start = parent->start;
57085- else
57086+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57087+ if (parent)
57088+ parent_start = parent->start;
57089+ else
57090+ parent_start = 0;
57091+ } else
57092 parent_start = 0;
57093
57094 WARN_ON(trans->transid != btrfs_header_generation(parent));
57095diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57096index 33e561a..16df7ae 100644
57097--- a/fs/btrfs/delayed-inode.c
57098+++ b/fs/btrfs/delayed-inode.c
57099@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57100
57101 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57102 {
57103- int seq = atomic_inc_return(&delayed_root->items_seq);
57104+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57105 if ((atomic_dec_return(&delayed_root->items) <
57106 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57107 waitqueue_active(&delayed_root->wait))
57108@@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57109
57110 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57111 {
57112- int val = atomic_read(&delayed_root->items_seq);
57113+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57114
57115 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57116 return 1;
57117@@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57118 int seq;
57119 int ret;
57120
57121- seq = atomic_read(&delayed_root->items_seq);
57122+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57123
57124 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57125 if (ret)
57126diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57127index f70119f..ab5894d 100644
57128--- a/fs/btrfs/delayed-inode.h
57129+++ b/fs/btrfs/delayed-inode.h
57130@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57131 */
57132 struct list_head prepare_list;
57133 atomic_t items; /* for delayed items */
57134- atomic_t items_seq; /* for delayed items */
57135+ atomic_unchecked_t items_seq; /* for delayed items */
57136 int nodes; /* for delayed nodes */
57137 wait_queue_head_t wait;
57138 };
57139@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57140 struct btrfs_delayed_root *delayed_root)
57141 {
57142 atomic_set(&delayed_root->items, 0);
57143- atomic_set(&delayed_root->items_seq, 0);
57144+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57145 delayed_root->nodes = 0;
57146 spin_lock_init(&delayed_root->lock);
57147 init_waitqueue_head(&delayed_root->wait);
57148diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57149index 2f6d7b1..f186382 100644
57150--- a/fs/btrfs/ioctl.c
57151+++ b/fs/btrfs/ioctl.c
57152@@ -3575,9 +3575,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57153 for (i = 0; i < num_types; i++) {
57154 struct btrfs_space_info *tmp;
57155
57156+ /* Don't copy in more than we allocated */
57157 if (!slot_count)
57158 break;
57159
57160+ slot_count--;
57161+
57162 info = NULL;
57163 rcu_read_lock();
57164 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57165@@ -3599,10 +3602,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57166 memcpy(dest, &space, sizeof(space));
57167 dest++;
57168 space_args.total_spaces++;
57169- slot_count--;
57170 }
57171- if (!slot_count)
57172- break;
57173 }
57174 up_read(&info->groups_sem);
57175 }
57176diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57177index 9601d25..2896d6c 100644
57178--- a/fs/btrfs/super.c
57179+++ b/fs/btrfs/super.c
57180@@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57181 function, line, errstr);
57182 return;
57183 }
57184- ACCESS_ONCE(trans->transaction->aborted) = errno;
57185+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57186 /* Wake up anybody who may be waiting on this transaction */
57187 wake_up(&root->fs_info->transaction_wait);
57188 wake_up(&root->fs_info->transaction_blocked_wait);
57189diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57190index c5eb214..218cc24 100644
57191--- a/fs/btrfs/sysfs.c
57192+++ b/fs/btrfs/sysfs.c
57193@@ -437,7 +437,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57194 for (set = 0; set < FEAT_MAX; set++) {
57195 int i;
57196 struct attribute *attrs[2];
57197- struct attribute_group agroup = {
57198+ attribute_group_no_const agroup = {
57199 .name = "features",
57200 .attrs = attrs,
57201 };
57202diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
57203index e2f45fc..b036909 100644
57204--- a/fs/btrfs/tree-log.c
57205+++ b/fs/btrfs/tree-log.c
57206@@ -2533,7 +2533,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57207 blk_finish_plug(&plug);
57208 btrfs_abort_transaction(trans, root, ret);
57209 btrfs_free_logged_extents(log, log_transid);
57210- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57211+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57212 trans->transid;
57213 mutex_unlock(&root->log_mutex);
57214 goto out;
57215@@ -2577,7 +2577,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57216 list_del_init(&root_log_ctx.list);
57217
57218 blk_finish_plug(&plug);
57219- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57220+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57221 trans->transid;
57222 if (ret != -ENOSPC) {
57223 btrfs_abort_transaction(trans, root, ret);
57224@@ -2622,7 +2622,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57225 * now that we've moved on to the tree of log tree roots,
57226 * check the full commit flag again
57227 */
57228- if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
57229+ if (ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) ==
57230 trans->transid) {
57231 blk_finish_plug(&plug);
57232 btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
57233@@ -2637,7 +2637,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57234 EXTENT_DIRTY | EXTENT_NEW);
57235 blk_finish_plug(&plug);
57236 if (ret) {
57237- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57238+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57239 trans->transid;
57240 btrfs_abort_transaction(trans, root, ret);
57241 btrfs_free_logged_extents(log, log_transid);
57242@@ -2667,7 +2667,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57243 */
57244 ret = write_ctree_super(trans, root->fs_info->tree_root, 1);
57245 if (ret) {
57246- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57247+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57248 trans->transid;
57249 btrfs_abort_transaction(trans, root, ret);
57250 goto out_wake_log_root;
57251diff --git a/fs/buffer.c b/fs/buffer.c
57252index 9ddb9fc..7aa2487 100644
57253--- a/fs/buffer.c
57254+++ b/fs/buffer.c
57255@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57256 bh_cachep = kmem_cache_create("buffer_head",
57257 sizeof(struct buffer_head), 0,
57258 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57259- SLAB_MEM_SPREAD),
57260+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57261 NULL);
57262
57263 /*
57264diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57265index 5b99baf..47fffb5 100644
57266--- a/fs/cachefiles/bind.c
57267+++ b/fs/cachefiles/bind.c
57268@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57269 args);
57270
57271 /* start by checking things over */
57272- ASSERT(cache->fstop_percent >= 0 &&
57273- cache->fstop_percent < cache->fcull_percent &&
57274+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57275 cache->fcull_percent < cache->frun_percent &&
57276 cache->frun_percent < 100);
57277
57278- ASSERT(cache->bstop_percent >= 0 &&
57279- cache->bstop_percent < cache->bcull_percent &&
57280+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57281 cache->bcull_percent < cache->brun_percent &&
57282 cache->brun_percent < 100);
57283
57284diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57285index 0a1467b..6a53245 100644
57286--- a/fs/cachefiles/daemon.c
57287+++ b/fs/cachefiles/daemon.c
57288@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57289 if (n > buflen)
57290 return -EMSGSIZE;
57291
57292- if (copy_to_user(_buffer, buffer, n) != 0)
57293+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57294 return -EFAULT;
57295
57296 return n;
57297@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57298 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57299 return -EIO;
57300
57301- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57302+ if (datalen > PAGE_SIZE - 1)
57303 return -EOPNOTSUPP;
57304
57305 /* drag the command string into the kernel so we can parse it */
57306@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57307 if (args[0] != '%' || args[1] != '\0')
57308 return -EINVAL;
57309
57310- if (fstop < 0 || fstop >= cache->fcull_percent)
57311+ if (fstop >= cache->fcull_percent)
57312 return cachefiles_daemon_range_error(cache, args);
57313
57314 cache->fstop_percent = fstop;
57315@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57316 if (args[0] != '%' || args[1] != '\0')
57317 return -EINVAL;
57318
57319- if (bstop < 0 || bstop >= cache->bcull_percent)
57320+ if (bstop >= cache->bcull_percent)
57321 return cachefiles_daemon_range_error(cache, args);
57322
57323 cache->bstop_percent = bstop;
57324diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57325index 5349473..d6c0b93 100644
57326--- a/fs/cachefiles/internal.h
57327+++ b/fs/cachefiles/internal.h
57328@@ -59,7 +59,7 @@ struct cachefiles_cache {
57329 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57330 struct rb_root active_nodes; /* active nodes (can't be culled) */
57331 rwlock_t active_lock; /* lock for active_nodes */
57332- atomic_t gravecounter; /* graveyard uniquifier */
57333+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57334 unsigned frun_percent; /* when to stop culling (% files) */
57335 unsigned fcull_percent; /* when to start culling (% files) */
57336 unsigned fstop_percent; /* when to stop allocating (% files) */
57337@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57338 * proc.c
57339 */
57340 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57341-extern atomic_t cachefiles_lookup_histogram[HZ];
57342-extern atomic_t cachefiles_mkdir_histogram[HZ];
57343-extern atomic_t cachefiles_create_histogram[HZ];
57344+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57345+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57346+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57347
57348 extern int __init cachefiles_proc_init(void);
57349 extern void cachefiles_proc_cleanup(void);
57350 static inline
57351-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57352+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57353 {
57354 unsigned long jif = jiffies - start_jif;
57355 if (jif >= HZ)
57356 jif = HZ - 1;
57357- atomic_inc(&histogram[jif]);
57358+ atomic_inc_unchecked(&histogram[jif]);
57359 }
57360
57361 #else
57362diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57363index c0a6817..ea811166 100644
57364--- a/fs/cachefiles/namei.c
57365+++ b/fs/cachefiles/namei.c
57366@@ -317,7 +317,7 @@ try_again:
57367 /* first step is to make up a grave dentry in the graveyard */
57368 sprintf(nbuffer, "%08x%08x",
57369 (uint32_t) get_seconds(),
57370- (uint32_t) atomic_inc_return(&cache->gravecounter));
57371+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57372
57373 /* do the multiway lock magic */
57374 trap = lock_rename(cache->graveyard, dir);
57375diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57376index eccd339..4c1d995 100644
57377--- a/fs/cachefiles/proc.c
57378+++ b/fs/cachefiles/proc.c
57379@@ -14,9 +14,9 @@
57380 #include <linux/seq_file.h>
57381 #include "internal.h"
57382
57383-atomic_t cachefiles_lookup_histogram[HZ];
57384-atomic_t cachefiles_mkdir_histogram[HZ];
57385-atomic_t cachefiles_create_histogram[HZ];
57386+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57387+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57388+atomic_unchecked_t cachefiles_create_histogram[HZ];
57389
57390 /*
57391 * display the latency histogram
57392@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57393 return 0;
57394 default:
57395 index = (unsigned long) v - 3;
57396- x = atomic_read(&cachefiles_lookup_histogram[index]);
57397- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57398- z = atomic_read(&cachefiles_create_histogram[index]);
57399+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57400+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57401+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57402 if (x == 0 && y == 0 && z == 0)
57403 return 0;
57404
57405diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57406index 4b1fb5c..0d2a699 100644
57407--- a/fs/cachefiles/rdwr.c
57408+++ b/fs/cachefiles/rdwr.c
57409@@ -943,7 +943,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57410 old_fs = get_fs();
57411 set_fs(KERNEL_DS);
57412 ret = file->f_op->write(
57413- file, (const void __user *) data, len, &pos);
57414+ file, (const void __force_user *) data, len, &pos);
57415 set_fs(old_fs);
57416 kunmap(page);
57417 file_end_write(file);
57418diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57419index c29d6ae..a56c4ae 100644
57420--- a/fs/ceph/dir.c
57421+++ b/fs/ceph/dir.c
57422@@ -250,7 +250,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57423 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57424 struct ceph_mds_client *mdsc = fsc->mdsc;
57425 unsigned frag = fpos_frag(ctx->pos);
57426- int off = fpos_off(ctx->pos);
57427+ unsigned int off = fpos_off(ctx->pos);
57428 int err;
57429 u32 ftype;
57430 struct ceph_mds_reply_info_parsed *rinfo;
57431diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57432index 06150fd..192061b 100644
57433--- a/fs/ceph/super.c
57434+++ b/fs/ceph/super.c
57435@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57436 /*
57437 * construct our own bdi so we can control readahead, etc.
57438 */
57439-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57440+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57441
57442 static int ceph_register_bdi(struct super_block *sb,
57443 struct ceph_fs_client *fsc)
57444@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57445 default_backing_dev_info.ra_pages;
57446
57447 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57448- atomic_long_inc_return(&bdi_seq));
57449+ atomic_long_inc_return_unchecked(&bdi_seq));
57450 if (!err)
57451 sb->s_bdi = &fsc->backing_dev_info;
57452 return err;
57453diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57454index f3ac415..3d2420c 100644
57455--- a/fs/cifs/cifs_debug.c
57456+++ b/fs/cifs/cifs_debug.c
57457@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57458
57459 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57460 #ifdef CONFIG_CIFS_STATS2
57461- atomic_set(&totBufAllocCount, 0);
57462- atomic_set(&totSmBufAllocCount, 0);
57463+ atomic_set_unchecked(&totBufAllocCount, 0);
57464+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57465 #endif /* CONFIG_CIFS_STATS2 */
57466 spin_lock(&cifs_tcp_ses_lock);
57467 list_for_each(tmp1, &cifs_tcp_ses_list) {
57468@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57469 tcon = list_entry(tmp3,
57470 struct cifs_tcon,
57471 tcon_list);
57472- atomic_set(&tcon->num_smbs_sent, 0);
57473+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57474 if (server->ops->clear_stats)
57475 server->ops->clear_stats(tcon);
57476 }
57477@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57478 smBufAllocCount.counter, cifs_min_small);
57479 #ifdef CONFIG_CIFS_STATS2
57480 seq_printf(m, "Total Large %d Small %d Allocations\n",
57481- atomic_read(&totBufAllocCount),
57482- atomic_read(&totSmBufAllocCount));
57483+ atomic_read_unchecked(&totBufAllocCount),
57484+ atomic_read_unchecked(&totSmBufAllocCount));
57485 #endif /* CONFIG_CIFS_STATS2 */
57486
57487 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57488@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57489 if (tcon->need_reconnect)
57490 seq_puts(m, "\tDISCONNECTED ");
57491 seq_printf(m, "\nSMBs: %d",
57492- atomic_read(&tcon->num_smbs_sent));
57493+ atomic_read_unchecked(&tcon->num_smbs_sent));
57494 if (server->ops->print_stats)
57495 server->ops->print_stats(m, tcon);
57496 }
57497diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57498index 5be1f997..fa1015a1 100644
57499--- a/fs/cifs/cifsfs.c
57500+++ b/fs/cifs/cifsfs.c
57501@@ -1068,7 +1068,7 @@ cifs_init_request_bufs(void)
57502 */
57503 cifs_req_cachep = kmem_cache_create("cifs_request",
57504 CIFSMaxBufSize + max_hdr_size, 0,
57505- SLAB_HWCACHE_ALIGN, NULL);
57506+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57507 if (cifs_req_cachep == NULL)
57508 return -ENOMEM;
57509
57510@@ -1095,7 +1095,7 @@ cifs_init_request_bufs(void)
57511 efficient to alloc 1 per page off the slab compared to 17K (5page)
57512 alloc of large cifs buffers even when page debugging is on */
57513 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57514- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57515+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57516 NULL);
57517 if (cifs_sm_req_cachep == NULL) {
57518 mempool_destroy(cifs_req_poolp);
57519@@ -1180,8 +1180,8 @@ init_cifs(void)
57520 atomic_set(&bufAllocCount, 0);
57521 atomic_set(&smBufAllocCount, 0);
57522 #ifdef CONFIG_CIFS_STATS2
57523- atomic_set(&totBufAllocCount, 0);
57524- atomic_set(&totSmBufAllocCount, 0);
57525+ atomic_set_unchecked(&totBufAllocCount, 0);
57526+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57527 #endif /* CONFIG_CIFS_STATS2 */
57528
57529 atomic_set(&midCount, 0);
57530diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57531index 30f6e92..e915ba5 100644
57532--- a/fs/cifs/cifsglob.h
57533+++ b/fs/cifs/cifsglob.h
57534@@ -806,35 +806,35 @@ struct cifs_tcon {
57535 __u16 Flags; /* optional support bits */
57536 enum statusEnum tidStatus;
57537 #ifdef CONFIG_CIFS_STATS
57538- atomic_t num_smbs_sent;
57539+ atomic_unchecked_t num_smbs_sent;
57540 union {
57541 struct {
57542- atomic_t num_writes;
57543- atomic_t num_reads;
57544- atomic_t num_flushes;
57545- atomic_t num_oplock_brks;
57546- atomic_t num_opens;
57547- atomic_t num_closes;
57548- atomic_t num_deletes;
57549- atomic_t num_mkdirs;
57550- atomic_t num_posixopens;
57551- atomic_t num_posixmkdirs;
57552- atomic_t num_rmdirs;
57553- atomic_t num_renames;
57554- atomic_t num_t2renames;
57555- atomic_t num_ffirst;
57556- atomic_t num_fnext;
57557- atomic_t num_fclose;
57558- atomic_t num_hardlinks;
57559- atomic_t num_symlinks;
57560- atomic_t num_locks;
57561- atomic_t num_acl_get;
57562- atomic_t num_acl_set;
57563+ atomic_unchecked_t num_writes;
57564+ atomic_unchecked_t num_reads;
57565+ atomic_unchecked_t num_flushes;
57566+ atomic_unchecked_t num_oplock_brks;
57567+ atomic_unchecked_t num_opens;
57568+ atomic_unchecked_t num_closes;
57569+ atomic_unchecked_t num_deletes;
57570+ atomic_unchecked_t num_mkdirs;
57571+ atomic_unchecked_t num_posixopens;
57572+ atomic_unchecked_t num_posixmkdirs;
57573+ atomic_unchecked_t num_rmdirs;
57574+ atomic_unchecked_t num_renames;
57575+ atomic_unchecked_t num_t2renames;
57576+ atomic_unchecked_t num_ffirst;
57577+ atomic_unchecked_t num_fnext;
57578+ atomic_unchecked_t num_fclose;
57579+ atomic_unchecked_t num_hardlinks;
57580+ atomic_unchecked_t num_symlinks;
57581+ atomic_unchecked_t num_locks;
57582+ atomic_unchecked_t num_acl_get;
57583+ atomic_unchecked_t num_acl_set;
57584 } cifs_stats;
57585 #ifdef CONFIG_CIFS_SMB2
57586 struct {
57587- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57588- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57589+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57590+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57591 } smb2_stats;
57592 #endif /* CONFIG_CIFS_SMB2 */
57593 } stats;
57594@@ -1170,7 +1170,7 @@ convert_delimiter(char *path, char delim)
57595 }
57596
57597 #ifdef CONFIG_CIFS_STATS
57598-#define cifs_stats_inc atomic_inc
57599+#define cifs_stats_inc atomic_inc_unchecked
57600
57601 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57602 unsigned int bytes)
57603@@ -1536,8 +1536,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57604 /* Various Debug counters */
57605 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57606 #ifdef CONFIG_CIFS_STATS2
57607-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57608-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57609+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57610+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57611 #endif
57612 GLOBAL_EXTERN atomic_t smBufAllocCount;
57613 GLOBAL_EXTERN atomic_t midCount;
57614diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57615index 5ed03e0..e9a3a6c 100644
57616--- a/fs/cifs/file.c
57617+++ b/fs/cifs/file.c
57618@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57619 index = mapping->writeback_index; /* Start from prev offset */
57620 end = -1;
57621 } else {
57622- index = wbc->range_start >> PAGE_CACHE_SHIFT;
57623- end = wbc->range_end >> PAGE_CACHE_SHIFT;
57624- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57625+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57626 range_whole = true;
57627+ index = 0;
57628+ end = ULONG_MAX;
57629+ } else {
57630+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
57631+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
57632+ }
57633 scanned = true;
57634 }
57635 retry:
57636diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57637index 3b0c62e..f7d090c 100644
57638--- a/fs/cifs/misc.c
57639+++ b/fs/cifs/misc.c
57640@@ -170,7 +170,7 @@ cifs_buf_get(void)
57641 memset(ret_buf, 0, buf_size + 3);
57642 atomic_inc(&bufAllocCount);
57643 #ifdef CONFIG_CIFS_STATS2
57644- atomic_inc(&totBufAllocCount);
57645+ atomic_inc_unchecked(&totBufAllocCount);
57646 #endif /* CONFIG_CIFS_STATS2 */
57647 }
57648
57649@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57650 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57651 atomic_inc(&smBufAllocCount);
57652 #ifdef CONFIG_CIFS_STATS2
57653- atomic_inc(&totSmBufAllocCount);
57654+ atomic_inc_unchecked(&totSmBufAllocCount);
57655 #endif /* CONFIG_CIFS_STATS2 */
57656
57657 }
57658diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57659index d1fdfa8..94558f8 100644
57660--- a/fs/cifs/smb1ops.c
57661+++ b/fs/cifs/smb1ops.c
57662@@ -626,27 +626,27 @@ static void
57663 cifs_clear_stats(struct cifs_tcon *tcon)
57664 {
57665 #ifdef CONFIG_CIFS_STATS
57666- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57667- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57668- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57669- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57670- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57671- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57672- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57673- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57674- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57675- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57676- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57677- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57678- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57679- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57680- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57681- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57682- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57683- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57684- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57685- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57686- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57687+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57688+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57689+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57690+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57691+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57692+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57693+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57694+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57695+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57696+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57697+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57698+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57699+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57700+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57701+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57702+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57703+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57704+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57705+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57706+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57707+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57708 #endif
57709 }
57710
57711@@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57712 {
57713 #ifdef CONFIG_CIFS_STATS
57714 seq_printf(m, " Oplocks breaks: %d",
57715- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57716+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57717 seq_printf(m, "\nReads: %d Bytes: %llu",
57718- atomic_read(&tcon->stats.cifs_stats.num_reads),
57719+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57720 (long long)(tcon->bytes_read));
57721 seq_printf(m, "\nWrites: %d Bytes: %llu",
57722- atomic_read(&tcon->stats.cifs_stats.num_writes),
57723+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57724 (long long)(tcon->bytes_written));
57725 seq_printf(m, "\nFlushes: %d",
57726- atomic_read(&tcon->stats.cifs_stats.num_flushes));
57727+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57728 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57729- atomic_read(&tcon->stats.cifs_stats.num_locks),
57730- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57731- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57732+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57733+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57734+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57735 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57736- atomic_read(&tcon->stats.cifs_stats.num_opens),
57737- atomic_read(&tcon->stats.cifs_stats.num_closes),
57738- atomic_read(&tcon->stats.cifs_stats.num_deletes));
57739+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57740+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57741+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57742 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57743- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57744- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57745+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57746+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57747 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57748- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57749- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57750+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57751+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57752 seq_printf(m, "\nRenames: %d T2 Renames %d",
57753- atomic_read(&tcon->stats.cifs_stats.num_renames),
57754- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57755+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57756+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57757 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57758- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57759- atomic_read(&tcon->stats.cifs_stats.num_fnext),
57760- atomic_read(&tcon->stats.cifs_stats.num_fclose));
57761+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57762+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57763+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57764 #endif
57765 }
57766
57767diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57768index 35ddc3e..563e809 100644
57769--- a/fs/cifs/smb2ops.c
57770+++ b/fs/cifs/smb2ops.c
57771@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57772 #ifdef CONFIG_CIFS_STATS
57773 int i;
57774 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57775- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57776- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57777+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57778+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57779 }
57780 #endif
57781 }
57782@@ -405,65 +405,65 @@ static void
57783 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57784 {
57785 #ifdef CONFIG_CIFS_STATS
57786- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57787- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57788+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57789+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57790 seq_printf(m, "\nNegotiates: %d sent %d failed",
57791- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57792- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57793+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57794+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57795 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57796- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57797- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57798+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57799+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57800 seq_printf(m, "\nLogoffs: %d sent %d failed",
57801- atomic_read(&sent[SMB2_LOGOFF_HE]),
57802- atomic_read(&failed[SMB2_LOGOFF_HE]));
57803+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57804+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57805 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57806- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57807- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57808+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57809+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57810 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57811- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57812- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57813+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57814+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57815 seq_printf(m, "\nCreates: %d sent %d failed",
57816- atomic_read(&sent[SMB2_CREATE_HE]),
57817- atomic_read(&failed[SMB2_CREATE_HE]));
57818+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57819+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57820 seq_printf(m, "\nCloses: %d sent %d failed",
57821- atomic_read(&sent[SMB2_CLOSE_HE]),
57822- atomic_read(&failed[SMB2_CLOSE_HE]));
57823+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57824+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57825 seq_printf(m, "\nFlushes: %d sent %d failed",
57826- atomic_read(&sent[SMB2_FLUSH_HE]),
57827- atomic_read(&failed[SMB2_FLUSH_HE]));
57828+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57829+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57830 seq_printf(m, "\nReads: %d sent %d failed",
57831- atomic_read(&sent[SMB2_READ_HE]),
57832- atomic_read(&failed[SMB2_READ_HE]));
57833+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
57834+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
57835 seq_printf(m, "\nWrites: %d sent %d failed",
57836- atomic_read(&sent[SMB2_WRITE_HE]),
57837- atomic_read(&failed[SMB2_WRITE_HE]));
57838+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57839+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57840 seq_printf(m, "\nLocks: %d sent %d failed",
57841- atomic_read(&sent[SMB2_LOCK_HE]),
57842- atomic_read(&failed[SMB2_LOCK_HE]));
57843+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57844+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57845 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57846- atomic_read(&sent[SMB2_IOCTL_HE]),
57847- atomic_read(&failed[SMB2_IOCTL_HE]));
57848+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57849+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57850 seq_printf(m, "\nCancels: %d sent %d failed",
57851- atomic_read(&sent[SMB2_CANCEL_HE]),
57852- atomic_read(&failed[SMB2_CANCEL_HE]));
57853+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57854+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57855 seq_printf(m, "\nEchos: %d sent %d failed",
57856- atomic_read(&sent[SMB2_ECHO_HE]),
57857- atomic_read(&failed[SMB2_ECHO_HE]));
57858+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57859+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57860 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57861- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57862- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57863+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57864+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
57865 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
57866- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
57867- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
57868+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
57869+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
57870 seq_printf(m, "\nQueryInfos: %d sent %d failed",
57871- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
57872- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
57873+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
57874+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
57875 seq_printf(m, "\nSetInfos: %d sent %d failed",
57876- atomic_read(&sent[SMB2_SET_INFO_HE]),
57877- atomic_read(&failed[SMB2_SET_INFO_HE]));
57878+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
57879+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
57880 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
57881- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
57882- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
57883+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
57884+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
57885 #endif
57886 }
57887
57888diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
57889index 3802f8c..3a98488 100644
57890--- a/fs/cifs/smb2pdu.c
57891+++ b/fs/cifs/smb2pdu.c
57892@@ -2092,8 +2092,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
57893 default:
57894 cifs_dbg(VFS, "info level %u isn't supported\n",
57895 srch_inf->info_level);
57896- rc = -EINVAL;
57897- goto qdir_exit;
57898+ return -EINVAL;
57899 }
57900
57901 req->FileIndex = cpu_to_le32(index);
57902diff --git a/fs/coda/cache.c b/fs/coda/cache.c
57903index 1da168c..8bc7ff6 100644
57904--- a/fs/coda/cache.c
57905+++ b/fs/coda/cache.c
57906@@ -24,7 +24,7 @@
57907 #include "coda_linux.h"
57908 #include "coda_cache.h"
57909
57910-static atomic_t permission_epoch = ATOMIC_INIT(0);
57911+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
57912
57913 /* replace or extend an acl cache hit */
57914 void coda_cache_enter(struct inode *inode, int mask)
57915@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
57916 struct coda_inode_info *cii = ITOC(inode);
57917
57918 spin_lock(&cii->c_lock);
57919- cii->c_cached_epoch = atomic_read(&permission_epoch);
57920+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57921 if (!uid_eq(cii->c_uid, current_fsuid())) {
57922 cii->c_uid = current_fsuid();
57923 cii->c_cached_perm = mask;
57924@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57925 {
57926 struct coda_inode_info *cii = ITOC(inode);
57927 spin_lock(&cii->c_lock);
57928- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57929+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57930 spin_unlock(&cii->c_lock);
57931 }
57932
57933 /* remove all acl caches */
57934 void coda_cache_clear_all(struct super_block *sb)
57935 {
57936- atomic_inc(&permission_epoch);
57937+ atomic_inc_unchecked(&permission_epoch);
57938 }
57939
57940
57941@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
57942 spin_lock(&cii->c_lock);
57943 hit = (mask & cii->c_cached_perm) == mask &&
57944 uid_eq(cii->c_uid, current_fsuid()) &&
57945- cii->c_cached_epoch == atomic_read(&permission_epoch);
57946+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
57947 spin_unlock(&cii->c_lock);
57948
57949 return hit;
57950diff --git a/fs/compat.c b/fs/compat.c
57951index 66d3d3c..9c10175 100644
57952--- a/fs/compat.c
57953+++ b/fs/compat.c
57954@@ -54,7 +54,7 @@
57955 #include <asm/ioctls.h>
57956 #include "internal.h"
57957
57958-int compat_log = 1;
57959+int compat_log = 0;
57960
57961 int compat_printk(const char *fmt, ...)
57962 {
57963@@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
57964
57965 set_fs(KERNEL_DS);
57966 /* The __user pointer cast is valid because of the set_fs() */
57967- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
57968+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
57969 set_fs(oldfs);
57970 /* truncating is ok because it's a user address */
57971 if (!ret)
57972@@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
57973 goto out;
57974
57975 ret = -EINVAL;
57976- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
57977+ if (nr_segs > UIO_MAXIOV)
57978 goto out;
57979 if (nr_segs > fast_segs) {
57980 ret = -ENOMEM;
57981@@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
57982 struct compat_readdir_callback {
57983 struct dir_context ctx;
57984 struct compat_old_linux_dirent __user *dirent;
57985+ struct file * file;
57986 int result;
57987 };
57988
57989@@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
57990 buf->result = -EOVERFLOW;
57991 return -EOVERFLOW;
57992 }
57993+
57994+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57995+ return 0;
57996+
57997 buf->result++;
57998 dirent = buf->dirent;
57999 if (!access_ok(VERIFY_WRITE, dirent,
58000@@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
58001 if (!f.file)
58002 return -EBADF;
58003
58004+ buf.file = f.file;
58005 error = iterate_dir(f.file, &buf.ctx);
58006 if (buf.result)
58007 error = buf.result;
58008@@ -917,6 +923,7 @@ struct compat_getdents_callback {
58009 struct dir_context ctx;
58010 struct compat_linux_dirent __user *current_dir;
58011 struct compat_linux_dirent __user *previous;
58012+ struct file * file;
58013 int count;
58014 int error;
58015 };
58016@@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58017 buf->error = -EOVERFLOW;
58018 return -EOVERFLOW;
58019 }
58020+
58021+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58022+ return 0;
58023+
58024 dirent = buf->previous;
58025 if (dirent) {
58026 if (__put_user(offset, &dirent->d_off))
58027@@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
58028 if (!f.file)
58029 return -EBADF;
58030
58031+ buf.file = f.file;
58032 error = iterate_dir(f.file, &buf.ctx);
58033 if (error >= 0)
58034 error = buf.error;
58035@@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
58036 struct dir_context ctx;
58037 struct linux_dirent64 __user *current_dir;
58038 struct linux_dirent64 __user *previous;
58039+ struct file * file;
58040 int count;
58041 int error;
58042 };
58043@@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58044 buf->error = -EINVAL; /* only used if we fail.. */
58045 if (reclen > buf->count)
58046 return -EINVAL;
58047+
58048+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58049+ return 0;
58050+
58051 dirent = buf->previous;
58052
58053 if (dirent) {
58054@@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
58055 if (!f.file)
58056 return -EBADF;
58057
58058+ buf.file = f.file;
58059 error = iterate_dir(f.file, &buf.ctx);
58060 if (error >= 0)
58061 error = buf.error;
58062diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58063index 4d24d17..4f8c09e 100644
58064--- a/fs/compat_binfmt_elf.c
58065+++ b/fs/compat_binfmt_elf.c
58066@@ -30,11 +30,13 @@
58067 #undef elf_phdr
58068 #undef elf_shdr
58069 #undef elf_note
58070+#undef elf_dyn
58071 #undef elf_addr_t
58072 #define elfhdr elf32_hdr
58073 #define elf_phdr elf32_phdr
58074 #define elf_shdr elf32_shdr
58075 #define elf_note elf32_note
58076+#define elf_dyn Elf32_Dyn
58077 #define elf_addr_t Elf32_Addr
58078
58079 /*
58080diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58081index e822890..59374d5 100644
58082--- a/fs/compat_ioctl.c
58083+++ b/fs/compat_ioctl.c
58084@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58085 return -EFAULT;
58086 if (__get_user(udata, &ss32->iomem_base))
58087 return -EFAULT;
58088- ss.iomem_base = compat_ptr(udata);
58089+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58090 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58091 __get_user(ss.port_high, &ss32->port_high))
58092 return -EFAULT;
58093@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58094 for (i = 0; i < nmsgs; i++) {
58095 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58096 return -EFAULT;
58097- if (get_user(datap, &umsgs[i].buf) ||
58098- put_user(compat_ptr(datap), &tmsgs[i].buf))
58099+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58100+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58101 return -EFAULT;
58102 }
58103 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58104@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58105 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58106 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58107 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58108- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58109+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58110 return -EFAULT;
58111
58112 return ioctl_preallocate(file, p);
58113@@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
58114 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58115 {
58116 unsigned int a, b;
58117- a = *(unsigned int *)p;
58118- b = *(unsigned int *)q;
58119+ a = *(const unsigned int *)p;
58120+ b = *(const unsigned int *)q;
58121 if (a > b)
58122 return 1;
58123 if (a < b)
58124diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58125index e081acb..911df21 100644
58126--- a/fs/configfs/dir.c
58127+++ b/fs/configfs/dir.c
58128@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58129 }
58130 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58131 struct configfs_dirent *next;
58132- const char *name;
58133+ const unsigned char * name;
58134+ char d_name[sizeof(next->s_dentry->d_iname)];
58135 int len;
58136 struct inode *inode = NULL;
58137
58138@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58139 continue;
58140
58141 name = configfs_get_name(next);
58142- len = strlen(name);
58143+ if (next->s_dentry && name == next->s_dentry->d_iname) {
58144+ len = next->s_dentry->d_name.len;
58145+ memcpy(d_name, name, len);
58146+ name = d_name;
58147+ } else
58148+ len = strlen(name);
58149
58150 /*
58151 * We'll have a dentry and an inode for
58152diff --git a/fs/coredump.c b/fs/coredump.c
58153index 0b2528f..836c55f 100644
58154--- a/fs/coredump.c
58155+++ b/fs/coredump.c
58156@@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58157 struct pipe_inode_info *pipe = file->private_data;
58158
58159 pipe_lock(pipe);
58160- pipe->readers++;
58161- pipe->writers--;
58162+ atomic_inc(&pipe->readers);
58163+ atomic_dec(&pipe->writers);
58164 wake_up_interruptible_sync(&pipe->wait);
58165 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58166 pipe_unlock(pipe);
58167@@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58168 * We actually want wait_event_freezable() but then we need
58169 * to clear TIF_SIGPENDING and improve dump_interrupted().
58170 */
58171- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58172+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58173
58174 pipe_lock(pipe);
58175- pipe->readers--;
58176- pipe->writers++;
58177+ atomic_dec(&pipe->readers);
58178+ atomic_inc(&pipe->writers);
58179 pipe_unlock(pipe);
58180 }
58181
58182@@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58183 struct files_struct *displaced;
58184 bool need_nonrelative = false;
58185 bool core_dumped = false;
58186- static atomic_t core_dump_count = ATOMIC_INIT(0);
58187+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58188+ long signr = siginfo->si_signo;
58189+ int dumpable;
58190 struct coredump_params cprm = {
58191 .siginfo = siginfo,
58192 .regs = signal_pt_regs(),
58193@@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58194 .mm_flags = mm->flags,
58195 };
58196
58197- audit_core_dumps(siginfo->si_signo);
58198+ audit_core_dumps(signr);
58199+
58200+ dumpable = __get_dumpable(cprm.mm_flags);
58201+
58202+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58203+ gr_handle_brute_attach(dumpable);
58204
58205 binfmt = mm->binfmt;
58206 if (!binfmt || !binfmt->core_dump)
58207 goto fail;
58208- if (!__get_dumpable(cprm.mm_flags))
58209+ if (!dumpable)
58210 goto fail;
58211
58212 cred = prepare_creds();
58213@@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58214 need_nonrelative = true;
58215 }
58216
58217- retval = coredump_wait(siginfo->si_signo, &core_state);
58218+ retval = coredump_wait(signr, &core_state);
58219 if (retval < 0)
58220 goto fail_creds;
58221
58222@@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58223 }
58224 cprm.limit = RLIM_INFINITY;
58225
58226- dump_count = atomic_inc_return(&core_dump_count);
58227+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58228 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58229 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58230 task_tgid_vnr(current), current->comm);
58231@@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58232 } else {
58233 struct inode *inode;
58234
58235+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58236+
58237 if (cprm.limit < binfmt->min_coredump)
58238 goto fail_unlock;
58239
58240@@ -673,7 +682,7 @@ close_fail:
58241 filp_close(cprm.file, NULL);
58242 fail_dropcount:
58243 if (ispipe)
58244- atomic_dec(&core_dump_count);
58245+ atomic_dec_unchecked(&core_dump_count);
58246 fail_unlock:
58247 kfree(cn.corename);
58248 coredump_finish(mm, core_dumped);
58249@@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58250 struct file *file = cprm->file;
58251 loff_t pos = file->f_pos;
58252 ssize_t n;
58253+
58254+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58255 if (cprm->written + nr > cprm->limit)
58256 return 0;
58257 while (nr) {
58258diff --git a/fs/dcache.c b/fs/dcache.c
58259index e99c6f5..2838bf58 100644
58260--- a/fs/dcache.c
58261+++ b/fs/dcache.c
58262@@ -1445,7 +1445,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58263 */
58264 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58265 if (name->len > DNAME_INLINE_LEN-1) {
58266- dname = kmalloc(name->len + 1, GFP_KERNEL);
58267+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58268 if (!dname) {
58269 kmem_cache_free(dentry_cache, dentry);
58270 return NULL;
58271@@ -3413,7 +3413,8 @@ void __init vfs_caches_init(unsigned long mempages)
58272 mempages -= reserve;
58273
58274 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58275- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58276+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58277+ SLAB_NO_SANITIZE, NULL);
58278
58279 dcache_init();
58280 inode_init();
58281diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58282index 8c41b52..145b1b9 100644
58283--- a/fs/debugfs/inode.c
58284+++ b/fs/debugfs/inode.c
58285@@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58286 */
58287 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58288 {
58289+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58290+ return __create_file(name, S_IFDIR | S_IRWXU,
58291+#else
58292 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58293+#endif
58294 parent, NULL, NULL);
58295 }
58296 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58297diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58298index d4a9431..77f9b2e 100644
58299--- a/fs/ecryptfs/inode.c
58300+++ b/fs/ecryptfs/inode.c
58301@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58302 old_fs = get_fs();
58303 set_fs(get_ds());
58304 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58305- (char __user *)lower_buf,
58306+ (char __force_user *)lower_buf,
58307 PATH_MAX);
58308 set_fs(old_fs);
58309 if (rc < 0)
58310diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58311index e4141f2..d8263e8 100644
58312--- a/fs/ecryptfs/miscdev.c
58313+++ b/fs/ecryptfs/miscdev.c
58314@@ -304,7 +304,7 @@ check_list:
58315 goto out_unlock_msg_ctx;
58316 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58317 if (msg_ctx->msg) {
58318- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58319+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58320 goto out_unlock_msg_ctx;
58321 i += packet_length_size;
58322 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58323diff --git a/fs/exec.c b/fs/exec.c
58324index 238b7aa..a421d91 100644
58325--- a/fs/exec.c
58326+++ b/fs/exec.c
58327@@ -56,8 +56,20 @@
58328 #include <linux/pipe_fs_i.h>
58329 #include <linux/oom.h>
58330 #include <linux/compat.h>
58331+#include <linux/random.h>
58332+#include <linux/seq_file.h>
58333+#include <linux/coredump.h>
58334+#include <linux/mman.h>
58335+
58336+#ifdef CONFIG_PAX_REFCOUNT
58337+#include <linux/kallsyms.h>
58338+#include <linux/kdebug.h>
58339+#endif
58340+
58341+#include <trace/events/fs.h>
58342
58343 #include <asm/uaccess.h>
58344+#include <asm/sections.h>
58345 #include <asm/mmu_context.h>
58346 #include <asm/tlb.h>
58347
58348@@ -66,19 +78,34 @@
58349
58350 #include <trace/events/sched.h>
58351
58352+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58353+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58354+{
58355+ 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");
58356+}
58357+#endif
58358+
58359+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58360+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58361+EXPORT_SYMBOL(pax_set_initial_flags_func);
58362+#endif
58363+
58364 int suid_dumpable = 0;
58365
58366 static LIST_HEAD(formats);
58367 static DEFINE_RWLOCK(binfmt_lock);
58368
58369+extern int gr_process_kernel_exec_ban(void);
58370+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58371+
58372 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58373 {
58374 BUG_ON(!fmt);
58375 if (WARN_ON(!fmt->load_binary))
58376 return;
58377 write_lock(&binfmt_lock);
58378- insert ? list_add(&fmt->lh, &formats) :
58379- list_add_tail(&fmt->lh, &formats);
58380+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58381+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58382 write_unlock(&binfmt_lock);
58383 }
58384
58385@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58386 void unregister_binfmt(struct linux_binfmt * fmt)
58387 {
58388 write_lock(&binfmt_lock);
58389- list_del(&fmt->lh);
58390+ pax_list_del((struct list_head *)&fmt->lh);
58391 write_unlock(&binfmt_lock);
58392 }
58393
58394@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58395 int write)
58396 {
58397 struct page *page;
58398- int ret;
58399
58400-#ifdef CONFIG_STACK_GROWSUP
58401- if (write) {
58402- ret = expand_downwards(bprm->vma, pos);
58403- if (ret < 0)
58404- return NULL;
58405- }
58406-#endif
58407- ret = get_user_pages(current, bprm->mm, pos,
58408- 1, write, 1, &page, NULL);
58409- if (ret <= 0)
58410+ if (0 > expand_downwards(bprm->vma, pos))
58411+ return NULL;
58412+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58413 return NULL;
58414
58415 if (write) {
58416@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58417 if (size <= ARG_MAX)
58418 return page;
58419
58420+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58421+ // only allow 512KB for argv+env on suid/sgid binaries
58422+ // to prevent easy ASLR exhaustion
58423+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58424+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58425+ (size > (512 * 1024))) {
58426+ put_page(page);
58427+ return NULL;
58428+ }
58429+#endif
58430+
58431 /*
58432 * Limit to 1/4-th the stack size for the argv+env strings.
58433 * This ensures that:
58434@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58435 vma->vm_end = STACK_TOP_MAX;
58436 vma->vm_start = vma->vm_end - PAGE_SIZE;
58437 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58438+
58439+#ifdef CONFIG_PAX_SEGMEXEC
58440+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58441+#endif
58442+
58443 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58444 INIT_LIST_HEAD(&vma->anon_vma_chain);
58445
58446@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58447 mm->stack_vm = mm->total_vm = 1;
58448 up_write(&mm->mmap_sem);
58449 bprm->p = vma->vm_end - sizeof(void *);
58450+
58451+#ifdef CONFIG_PAX_RANDUSTACK
58452+ if (randomize_va_space)
58453+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
58454+#endif
58455+
58456 return 0;
58457 err:
58458 up_write(&mm->mmap_sem);
58459@@ -399,7 +440,7 @@ struct user_arg_ptr {
58460 } ptr;
58461 };
58462
58463-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58464+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58465 {
58466 const char __user *native;
58467
58468@@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58469 compat_uptr_t compat;
58470
58471 if (get_user(compat, argv.ptr.compat + nr))
58472- return ERR_PTR(-EFAULT);
58473+ return (const char __force_user *)ERR_PTR(-EFAULT);
58474
58475 return compat_ptr(compat);
58476 }
58477 #endif
58478
58479 if (get_user(native, argv.ptr.native + nr))
58480- return ERR_PTR(-EFAULT);
58481+ return (const char __force_user *)ERR_PTR(-EFAULT);
58482
58483 return native;
58484 }
58485@@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
58486 if (!p)
58487 break;
58488
58489- if (IS_ERR(p))
58490+ if (IS_ERR((const char __force_kernel *)p))
58491 return -EFAULT;
58492
58493 if (i >= max)
58494@@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58495
58496 ret = -EFAULT;
58497 str = get_user_arg_ptr(argv, argc);
58498- if (IS_ERR(str))
58499+ if (IS_ERR((const char __force_kernel *)str))
58500 goto out;
58501
58502 len = strnlen_user(str, MAX_ARG_STRLEN);
58503@@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58504 int r;
58505 mm_segment_t oldfs = get_fs();
58506 struct user_arg_ptr argv = {
58507- .ptr.native = (const char __user *const __user *)__argv,
58508+ .ptr.native = (const char __user * const __force_user *)__argv,
58509 };
58510
58511 set_fs(KERNEL_DS);
58512@@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58513 unsigned long new_end = old_end - shift;
58514 struct mmu_gather tlb;
58515
58516- BUG_ON(new_start > new_end);
58517+ if (new_start >= new_end || new_start < mmap_min_addr)
58518+ return -ENOMEM;
58519
58520 /*
58521 * ensure there are no vmas between where we want to go
58522@@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58523 if (vma != find_vma(mm, new_start))
58524 return -EFAULT;
58525
58526+#ifdef CONFIG_PAX_SEGMEXEC
58527+ BUG_ON(pax_find_mirror_vma(vma));
58528+#endif
58529+
58530 /*
58531 * cover the whole range: [new_start, old_end)
58532 */
58533@@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58534 stack_top = arch_align_stack(stack_top);
58535 stack_top = PAGE_ALIGN(stack_top);
58536
58537- if (unlikely(stack_top < mmap_min_addr) ||
58538- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58539- return -ENOMEM;
58540-
58541 stack_shift = vma->vm_end - stack_top;
58542
58543 bprm->p -= stack_shift;
58544@@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58545 bprm->exec -= stack_shift;
58546
58547 down_write(&mm->mmap_sem);
58548+
58549+ /* Move stack pages down in memory. */
58550+ if (stack_shift) {
58551+ ret = shift_arg_pages(vma, stack_shift);
58552+ if (ret)
58553+ goto out_unlock;
58554+ }
58555+
58556 vm_flags = VM_STACK_FLAGS;
58557
58558+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58559+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58560+ vm_flags &= ~VM_EXEC;
58561+
58562+#ifdef CONFIG_PAX_MPROTECT
58563+ if (mm->pax_flags & MF_PAX_MPROTECT)
58564+ vm_flags &= ~VM_MAYEXEC;
58565+#endif
58566+
58567+ }
58568+#endif
58569+
58570 /*
58571 * Adjust stack execute permissions; explicitly enable for
58572 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58573@@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58574 goto out_unlock;
58575 BUG_ON(prev != vma);
58576
58577- /* Move stack pages down in memory. */
58578- if (stack_shift) {
58579- ret = shift_arg_pages(vma, stack_shift);
58580- if (ret)
58581- goto out_unlock;
58582- }
58583-
58584 /* mprotect_fixup is overkill to remove the temporary stack flags */
58585 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58586
58587@@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58588 #endif
58589 current->mm->start_stack = bprm->p;
58590 ret = expand_stack(vma, stack_base);
58591+
58592+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58593+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58594+ unsigned long size;
58595+ vm_flags_t vm_flags;
58596+
58597+ size = STACK_TOP - vma->vm_end;
58598+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58599+
58600+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58601+
58602+#ifdef CONFIG_X86
58603+ if (!ret) {
58604+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58605+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58606+ }
58607+#endif
58608+
58609+ }
58610+#endif
58611+
58612 if (ret)
58613 ret = -EFAULT;
58614
58615@@ -775,6 +851,8 @@ static struct file *do_open_exec(struct filename *name)
58616
58617 fsnotify_open(file);
58618
58619+ trace_open_exec(name->name);
58620+
58621 err = deny_write_access(file);
58622 if (err)
58623 goto exit;
58624@@ -804,7 +882,7 @@ int kernel_read(struct file *file, loff_t offset,
58625 old_fs = get_fs();
58626 set_fs(get_ds());
58627 /* The cast to a user pointer is valid due to the set_fs() */
58628- result = vfs_read(file, (void __user *)addr, count, &pos);
58629+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
58630 set_fs(old_fs);
58631 return result;
58632 }
58633@@ -849,6 +927,7 @@ static int exec_mmap(struct mm_struct *mm)
58634 tsk->mm = mm;
58635 tsk->active_mm = mm;
58636 activate_mm(active_mm, mm);
58637+ populate_stack();
58638 tsk->mm->vmacache_seqnum = 0;
58639 vmacache_flush(tsk);
58640 task_unlock(tsk);
58641@@ -1246,7 +1325,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
58642 }
58643 rcu_read_unlock();
58644
58645- if (p->fs->users > n_fs)
58646+ if (atomic_read(&p->fs->users) > n_fs)
58647 bprm->unsafe |= LSM_UNSAFE_SHARE;
58648 else
58649 p->fs->in_exec = 1;
58650@@ -1422,6 +1501,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58651 return ret;
58652 }
58653
58654+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58655+static DEFINE_PER_CPU(u64, exec_counter);
58656+static int __init init_exec_counters(void)
58657+{
58658+ unsigned int cpu;
58659+
58660+ for_each_possible_cpu(cpu) {
58661+ per_cpu(exec_counter, cpu) = (u64)cpu;
58662+ }
58663+
58664+ return 0;
58665+}
58666+early_initcall(init_exec_counters);
58667+static inline void increment_exec_counter(void)
58668+{
58669+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
58670+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58671+}
58672+#else
58673+static inline void increment_exec_counter(void) {}
58674+#endif
58675+
58676+extern void gr_handle_exec_args(struct linux_binprm *bprm,
58677+ struct user_arg_ptr argv);
58678+
58679 /*
58680 * sys_execve() executes a new program.
58681 */
58682@@ -1429,6 +1533,11 @@ static int do_execve_common(struct filename *filename,
58683 struct user_arg_ptr argv,
58684 struct user_arg_ptr envp)
58685 {
58686+#ifdef CONFIG_GRKERNSEC
58687+ struct file *old_exec_file;
58688+ struct acl_subject_label *old_acl;
58689+ struct rlimit old_rlim[RLIM_NLIMITS];
58690+#endif
58691 struct linux_binprm *bprm;
58692 struct file *file;
58693 struct files_struct *displaced;
58694@@ -1437,6 +1546,8 @@ static int do_execve_common(struct filename *filename,
58695 if (IS_ERR(filename))
58696 return PTR_ERR(filename);
58697
58698+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58699+
58700 /*
58701 * We move the actual failure in case of RLIMIT_NPROC excess from
58702 * set*uid() to execve() because too many poorly written programs
58703@@ -1474,11 +1585,21 @@ static int do_execve_common(struct filename *filename,
58704 if (IS_ERR(file))
58705 goto out_unmark;
58706
58707+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
58708+ retval = -EPERM;
58709+ goto out_unmark;
58710+ }
58711+
58712 sched_exec();
58713
58714 bprm->file = file;
58715 bprm->filename = bprm->interp = filename->name;
58716
58717+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58718+ retval = -EACCES;
58719+ goto out_unmark;
58720+ }
58721+
58722 retval = bprm_mm_init(bprm);
58723 if (retval)
58724 goto out_unmark;
58725@@ -1495,24 +1616,70 @@ static int do_execve_common(struct filename *filename,
58726 if (retval < 0)
58727 goto out;
58728
58729+#ifdef CONFIG_GRKERNSEC
58730+ old_acl = current->acl;
58731+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58732+ old_exec_file = current->exec_file;
58733+ get_file(file);
58734+ current->exec_file = file;
58735+#endif
58736+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58737+ /* limit suid stack to 8MB
58738+ * we saved the old limits above and will restore them if this exec fails
58739+ */
58740+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58741+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58742+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58743+#endif
58744+
58745+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58746+ retval = -EPERM;
58747+ goto out_fail;
58748+ }
58749+
58750+ if (!gr_tpe_allow(file)) {
58751+ retval = -EACCES;
58752+ goto out_fail;
58753+ }
58754+
58755+ if (gr_check_crash_exec(file)) {
58756+ retval = -EACCES;
58757+ goto out_fail;
58758+ }
58759+
58760+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58761+ bprm->unsafe);
58762+ if (retval < 0)
58763+ goto out_fail;
58764+
58765 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58766 if (retval < 0)
58767- goto out;
58768+ goto out_fail;
58769
58770 bprm->exec = bprm->p;
58771 retval = copy_strings(bprm->envc, envp, bprm);
58772 if (retval < 0)
58773- goto out;
58774+ goto out_fail;
58775
58776 retval = copy_strings(bprm->argc, argv, bprm);
58777 if (retval < 0)
58778- goto out;
58779+ goto out_fail;
58780+
58781+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58782+
58783+ gr_handle_exec_args(bprm, argv);
58784
58785 retval = exec_binprm(bprm);
58786 if (retval < 0)
58787- goto out;
58788+ goto out_fail;
58789+#ifdef CONFIG_GRKERNSEC
58790+ if (old_exec_file)
58791+ fput(old_exec_file);
58792+#endif
58793
58794 /* execve succeeded */
58795+
58796+ increment_exec_counter();
58797 current->fs->in_exec = 0;
58798 current->in_execve = 0;
58799 acct_update_integrals(current);
58800@@ -1523,6 +1690,14 @@ static int do_execve_common(struct filename *filename,
58801 put_files_struct(displaced);
58802 return retval;
58803
58804+out_fail:
58805+#ifdef CONFIG_GRKERNSEC
58806+ current->acl = old_acl;
58807+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58808+ fput(current->exec_file);
58809+ current->exec_file = old_exec_file;
58810+#endif
58811+
58812 out:
58813 if (bprm->mm) {
58814 acct_arg_size(bprm, 0);
58815@@ -1614,3 +1789,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
58816 return compat_do_execve(getname(filename), argv, envp);
58817 }
58818 #endif
58819+
58820+int pax_check_flags(unsigned long *flags)
58821+{
58822+ int retval = 0;
58823+
58824+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58825+ if (*flags & MF_PAX_SEGMEXEC)
58826+ {
58827+ *flags &= ~MF_PAX_SEGMEXEC;
58828+ retval = -EINVAL;
58829+ }
58830+#endif
58831+
58832+ if ((*flags & MF_PAX_PAGEEXEC)
58833+
58834+#ifdef CONFIG_PAX_PAGEEXEC
58835+ && (*flags & MF_PAX_SEGMEXEC)
58836+#endif
58837+
58838+ )
58839+ {
58840+ *flags &= ~MF_PAX_PAGEEXEC;
58841+ retval = -EINVAL;
58842+ }
58843+
58844+ if ((*flags & MF_PAX_MPROTECT)
58845+
58846+#ifdef CONFIG_PAX_MPROTECT
58847+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58848+#endif
58849+
58850+ )
58851+ {
58852+ *flags &= ~MF_PAX_MPROTECT;
58853+ retval = -EINVAL;
58854+ }
58855+
58856+ if ((*flags & MF_PAX_EMUTRAMP)
58857+
58858+#ifdef CONFIG_PAX_EMUTRAMP
58859+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58860+#endif
58861+
58862+ )
58863+ {
58864+ *flags &= ~MF_PAX_EMUTRAMP;
58865+ retval = -EINVAL;
58866+ }
58867+
58868+ return retval;
58869+}
58870+
58871+EXPORT_SYMBOL(pax_check_flags);
58872+
58873+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58874+char *pax_get_path(const struct path *path, char *buf, int buflen)
58875+{
58876+ char *pathname = d_path(path, buf, buflen);
58877+
58878+ if (IS_ERR(pathname))
58879+ goto toolong;
58880+
58881+ pathname = mangle_path(buf, pathname, "\t\n\\");
58882+ if (!pathname)
58883+ goto toolong;
58884+
58885+ *pathname = 0;
58886+ return buf;
58887+
58888+toolong:
58889+ return "<path too long>";
58890+}
58891+EXPORT_SYMBOL(pax_get_path);
58892+
58893+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
58894+{
58895+ struct task_struct *tsk = current;
58896+ struct mm_struct *mm = current->mm;
58897+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
58898+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
58899+ char *path_exec = NULL;
58900+ char *path_fault = NULL;
58901+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
58902+ siginfo_t info = { };
58903+
58904+ if (buffer_exec && buffer_fault) {
58905+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
58906+
58907+ down_read(&mm->mmap_sem);
58908+ vma = mm->mmap;
58909+ while (vma && (!vma_exec || !vma_fault)) {
58910+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
58911+ vma_exec = vma;
58912+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
58913+ vma_fault = vma;
58914+ vma = vma->vm_next;
58915+ }
58916+ if (vma_exec)
58917+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
58918+ if (vma_fault) {
58919+ start = vma_fault->vm_start;
58920+ end = vma_fault->vm_end;
58921+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
58922+ if (vma_fault->vm_file)
58923+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
58924+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58925+ path_fault = "<heap>";
58926+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58927+ path_fault = "<stack>";
58928+ else
58929+ path_fault = "<anonymous mapping>";
58930+ }
58931+ up_read(&mm->mmap_sem);
58932+ }
58933+ if (tsk->signal->curr_ip)
58934+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
58935+ else
58936+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
58937+ 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),
58938+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
58939+ free_page((unsigned long)buffer_exec);
58940+ free_page((unsigned long)buffer_fault);
58941+ pax_report_insns(regs, pc, sp);
58942+ info.si_signo = SIGKILL;
58943+ info.si_errno = 0;
58944+ info.si_code = SI_KERNEL;
58945+ info.si_pid = 0;
58946+ info.si_uid = 0;
58947+ do_coredump(&info);
58948+}
58949+#endif
58950+
58951+#ifdef CONFIG_PAX_REFCOUNT
58952+void pax_report_refcount_overflow(struct pt_regs *regs)
58953+{
58954+ if (current->signal->curr_ip)
58955+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
58956+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
58957+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58958+ else
58959+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
58960+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58961+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
58962+ preempt_disable();
58963+ show_regs(regs);
58964+ preempt_enable();
58965+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
58966+}
58967+#endif
58968+
58969+#ifdef CONFIG_PAX_USERCOPY
58970+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
58971+static noinline int check_stack_object(const void *obj, unsigned long len)
58972+{
58973+ const void * const stack = task_stack_page(current);
58974+ const void * const stackend = stack + THREAD_SIZE;
58975+
58976+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58977+ const void *frame = NULL;
58978+ const void *oldframe;
58979+#endif
58980+
58981+ if (obj + len < obj)
58982+ return -1;
58983+
58984+ if (obj + len <= stack || stackend <= obj)
58985+ return 0;
58986+
58987+ if (obj < stack || stackend < obj + len)
58988+ return -1;
58989+
58990+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58991+ oldframe = __builtin_frame_address(1);
58992+ if (oldframe)
58993+ frame = __builtin_frame_address(2);
58994+ /*
58995+ low ----------------------------------------------> high
58996+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
58997+ ^----------------^
58998+ allow copies only within here
58999+ */
59000+ while (stack <= frame && frame < stackend) {
59001+ /* if obj + len extends past the last frame, this
59002+ check won't pass and the next frame will be 0,
59003+ causing us to bail out and correctly report
59004+ the copy as invalid
59005+ */
59006+ if (obj + len <= frame)
59007+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59008+ oldframe = frame;
59009+ frame = *(const void * const *)frame;
59010+ }
59011+ return -1;
59012+#else
59013+ return 1;
59014+#endif
59015+}
59016+
59017+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59018+{
59019+ if (current->signal->curr_ip)
59020+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59021+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59022+ else
59023+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59024+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59025+ dump_stack();
59026+ gr_handle_kernel_exploit();
59027+ do_group_exit(SIGKILL);
59028+}
59029+#endif
59030+
59031+#ifdef CONFIG_PAX_USERCOPY
59032+
59033+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59034+{
59035+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59036+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
59037+#ifdef CONFIG_MODULES
59038+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59039+#else
59040+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59041+#endif
59042+
59043+#else
59044+ unsigned long textlow = (unsigned long)_stext;
59045+ unsigned long texthigh = (unsigned long)_etext;
59046+
59047+#ifdef CONFIG_X86_64
59048+ /* check against linear mapping as well */
59049+ if (high > (unsigned long)__va(__pa(textlow)) &&
59050+ low < (unsigned long)__va(__pa(texthigh)))
59051+ return true;
59052+#endif
59053+
59054+#endif
59055+
59056+ if (high <= textlow || low >= texthigh)
59057+ return false;
59058+ else
59059+ return true;
59060+}
59061+#endif
59062+
59063+void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
59064+{
59065+#ifdef CONFIG_PAX_USERCOPY
59066+ const char *type;
59067+#endif
59068+
59069+#ifndef CONFIG_STACK_GROWSUP
59070+ unsigned long stackstart = (unsigned long)task_stack_page(current);
59071+ unsigned long currentsp = (unsigned long)&stackstart;
59072+ if (unlikely((currentsp < stackstart + 512 ||
59073+ currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
59074+ BUG();
59075+#endif
59076+
59077+#ifndef CONFIG_PAX_USERCOPY_DEBUG
59078+ if (const_size)
59079+ return;
59080+#endif
59081+
59082+#ifdef CONFIG_PAX_USERCOPY
59083+ if (!n)
59084+ return;
59085+
59086+ type = check_heap_object(ptr, n);
59087+ if (!type) {
59088+ int ret = check_stack_object(ptr, n);
59089+ if (ret == 1 || ret == 2)
59090+ return;
59091+ if (ret == 0) {
59092+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59093+ type = "<kernel text>";
59094+ else
59095+ return;
59096+ } else
59097+ type = "<process stack>";
59098+ }
59099+
59100+ pax_report_usercopy(ptr, n, to_user, type);
59101+#endif
59102+
59103+}
59104+EXPORT_SYMBOL(__check_object_size);
59105+
59106+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59107+void pax_track_stack(void)
59108+{
59109+ unsigned long sp = (unsigned long)&sp;
59110+ if (sp < current_thread_info()->lowest_stack &&
59111+ sp > (unsigned long)task_stack_page(current))
59112+ current_thread_info()->lowest_stack = sp;
59113+ if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
59114+ BUG();
59115+}
59116+EXPORT_SYMBOL(pax_track_stack);
59117+#endif
59118+
59119+#ifdef CONFIG_PAX_SIZE_OVERFLOW
59120+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59121+{
59122+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59123+ dump_stack();
59124+ do_group_exit(SIGKILL);
59125+}
59126+EXPORT_SYMBOL(report_size_overflow);
59127+#endif
59128diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59129index 9f9992b..8b59411 100644
59130--- a/fs/ext2/balloc.c
59131+++ b/fs/ext2/balloc.c
59132@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59133
59134 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59135 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59136- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59137+ if (free_blocks < root_blocks + 1 &&
59138 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59139 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59140- !in_group_p (sbi->s_resgid))) {
59141+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59142 return 0;
59143 }
59144 return 1;
59145diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59146index 9142614..97484fa 100644
59147--- a/fs/ext2/xattr.c
59148+++ b/fs/ext2/xattr.c
59149@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59150 struct buffer_head *bh = NULL;
59151 struct ext2_xattr_entry *entry;
59152 char *end;
59153- size_t rest = buffer_size;
59154+ size_t rest = buffer_size, total_size = 0;
59155 int error;
59156
59157 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59158@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59159 buffer += size;
59160 }
59161 rest -= size;
59162+ total_size += size;
59163 }
59164 }
59165- error = buffer_size - rest; /* total size */
59166+ error = total_size;
59167
59168 cleanup:
59169 brelse(bh);
59170diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59171index 158b5d4..2432610 100644
59172--- a/fs/ext3/balloc.c
59173+++ b/fs/ext3/balloc.c
59174@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59175
59176 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59177 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59178- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59179+ if (free_blocks < root_blocks + 1 &&
59180 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59181 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59182- !in_group_p (sbi->s_resgid))) {
59183+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59184 return 0;
59185 }
59186 return 1;
59187diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59188index c6874be..f8a6ae8 100644
59189--- a/fs/ext3/xattr.c
59190+++ b/fs/ext3/xattr.c
59191@@ -330,7 +330,7 @@ static int
59192 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59193 char *buffer, size_t buffer_size)
59194 {
59195- size_t rest = buffer_size;
59196+ size_t rest = buffer_size, total_size = 0;
59197
59198 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59199 const struct xattr_handler *handler =
59200@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59201 buffer += size;
59202 }
59203 rest -= size;
59204+ total_size += size;
59205 }
59206 }
59207- return buffer_size - rest;
59208+ return total_size;
59209 }
59210
59211 static int
59212diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59213index 5c56785..77698a2 100644
59214--- a/fs/ext4/balloc.c
59215+++ b/fs/ext4/balloc.c
59216@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59217 /* Hm, nope. Are (enough) root reserved clusters available? */
59218 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59219 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59220- capable(CAP_SYS_RESOURCE) ||
59221- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59222+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59223+ capable_nolog(CAP_SYS_RESOURCE)) {
59224
59225 if (free_clusters >= (nclusters + dirty_clusters +
59226 resv_clusters))
59227diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59228index 66946aa..4706fa4 100644
59229--- a/fs/ext4/ext4.h
59230+++ b/fs/ext4/ext4.h
59231@@ -1274,19 +1274,19 @@ struct ext4_sb_info {
59232 unsigned long s_mb_last_start;
59233
59234 /* stats for buddy allocator */
59235- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59236- atomic_t s_bal_success; /* we found long enough chunks */
59237- atomic_t s_bal_allocated; /* in blocks */
59238- atomic_t s_bal_ex_scanned; /* total extents scanned */
59239- atomic_t s_bal_goals; /* goal hits */
59240- atomic_t s_bal_breaks; /* too long searches */
59241- atomic_t s_bal_2orders; /* 2^order hits */
59242+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59243+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59244+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59245+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59246+ atomic_unchecked_t s_bal_goals; /* goal hits */
59247+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59248+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59249 spinlock_t s_bal_lock;
59250 unsigned long s_mb_buddies_generated;
59251 unsigned long long s_mb_generation_time;
59252- atomic_t s_mb_lost_chunks;
59253- atomic_t s_mb_preallocated;
59254- atomic_t s_mb_discarded;
59255+ atomic_unchecked_t s_mb_lost_chunks;
59256+ atomic_unchecked_t s_mb_preallocated;
59257+ atomic_unchecked_t s_mb_discarded;
59258 atomic_t s_lock_busy;
59259
59260 /* locality groups */
59261diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59262index c8238a2..42c2029 100644
59263--- a/fs/ext4/mballoc.c
59264+++ b/fs/ext4/mballoc.c
59265@@ -1889,7 +1889,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59266 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59267
59268 if (EXT4_SB(sb)->s_mb_stats)
59269- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59270+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59271
59272 break;
59273 }
59274@@ -2199,7 +2199,7 @@ repeat:
59275 ac->ac_status = AC_STATUS_CONTINUE;
59276 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59277 cr = 3;
59278- atomic_inc(&sbi->s_mb_lost_chunks);
59279+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59280 goto repeat;
59281 }
59282 }
59283@@ -2707,25 +2707,25 @@ int ext4_mb_release(struct super_block *sb)
59284 if (sbi->s_mb_stats) {
59285 ext4_msg(sb, KERN_INFO,
59286 "mballoc: %u blocks %u reqs (%u success)",
59287- atomic_read(&sbi->s_bal_allocated),
59288- atomic_read(&sbi->s_bal_reqs),
59289- atomic_read(&sbi->s_bal_success));
59290+ atomic_read_unchecked(&sbi->s_bal_allocated),
59291+ atomic_read_unchecked(&sbi->s_bal_reqs),
59292+ atomic_read_unchecked(&sbi->s_bal_success));
59293 ext4_msg(sb, KERN_INFO,
59294 "mballoc: %u extents scanned, %u goal hits, "
59295 "%u 2^N hits, %u breaks, %u lost",
59296- atomic_read(&sbi->s_bal_ex_scanned),
59297- atomic_read(&sbi->s_bal_goals),
59298- atomic_read(&sbi->s_bal_2orders),
59299- atomic_read(&sbi->s_bal_breaks),
59300- atomic_read(&sbi->s_mb_lost_chunks));
59301+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59302+ atomic_read_unchecked(&sbi->s_bal_goals),
59303+ atomic_read_unchecked(&sbi->s_bal_2orders),
59304+ atomic_read_unchecked(&sbi->s_bal_breaks),
59305+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59306 ext4_msg(sb, KERN_INFO,
59307 "mballoc: %lu generated and it took %Lu",
59308 sbi->s_mb_buddies_generated,
59309 sbi->s_mb_generation_time);
59310 ext4_msg(sb, KERN_INFO,
59311 "mballoc: %u preallocated, %u discarded",
59312- atomic_read(&sbi->s_mb_preallocated),
59313- atomic_read(&sbi->s_mb_discarded));
59314+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59315+ atomic_read_unchecked(&sbi->s_mb_discarded));
59316 }
59317
59318 free_percpu(sbi->s_locality_groups);
59319@@ -3179,16 +3179,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59320 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59321
59322 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59323- atomic_inc(&sbi->s_bal_reqs);
59324- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59325+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59326+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59327 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59328- atomic_inc(&sbi->s_bal_success);
59329- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59330+ atomic_inc_unchecked(&sbi->s_bal_success);
59331+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59332 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59333 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59334- atomic_inc(&sbi->s_bal_goals);
59335+ atomic_inc_unchecked(&sbi->s_bal_goals);
59336 if (ac->ac_found > sbi->s_mb_max_to_scan)
59337- atomic_inc(&sbi->s_bal_breaks);
59338+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59339 }
59340
59341 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59342@@ -3593,7 +3593,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59343 trace_ext4_mb_new_inode_pa(ac, pa);
59344
59345 ext4_mb_use_inode_pa(ac, pa);
59346- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59347+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59348
59349 ei = EXT4_I(ac->ac_inode);
59350 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59351@@ -3653,7 +3653,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59352 trace_ext4_mb_new_group_pa(ac, pa);
59353
59354 ext4_mb_use_group_pa(ac, pa);
59355- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59356+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59357
59358 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59359 lg = ac->ac_lg;
59360@@ -3742,7 +3742,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59361 * from the bitmap and continue.
59362 */
59363 }
59364- atomic_add(free, &sbi->s_mb_discarded);
59365+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59366
59367 return err;
59368 }
59369@@ -3760,7 +3760,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59370 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59371 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59372 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59373- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59374+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59375 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59376
59377 return 0;
59378diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59379index 04434ad..6404663 100644
59380--- a/fs/ext4/mmp.c
59381+++ b/fs/ext4/mmp.c
59382@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59383 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59384 const char *function, unsigned int line, const char *msg)
59385 {
59386- __ext4_warning(sb, function, line, msg);
59387+ __ext4_warning(sb, function, line, "%s", msg);
59388 __ext4_warning(sb, function, line,
59389 "MMP failure info: last update time: %llu, last update "
59390 "node: %s, last update device: %s\n",
59391diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59392index 6f9e6fa..5431c02 100644
59393--- a/fs/ext4/super.c
59394+++ b/fs/ext4/super.c
59395@@ -1275,7 +1275,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59396 }
59397
59398 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59399-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59400+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59401 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59402
59403 #ifdef CONFIG_QUOTA
59404@@ -2455,7 +2455,7 @@ struct ext4_attr {
59405 int offset;
59406 int deprecated_val;
59407 } u;
59408-};
59409+} __do_const;
59410
59411 static int parse_strtoull(const char *buf,
59412 unsigned long long max, unsigned long long *value)
59413diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59414index 4eec399..1d9444c 100644
59415--- a/fs/ext4/xattr.c
59416+++ b/fs/ext4/xattr.c
59417@@ -383,7 +383,7 @@ static int
59418 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59419 char *buffer, size_t buffer_size)
59420 {
59421- size_t rest = buffer_size;
59422+ size_t rest = buffer_size, total_size = 0;
59423
59424 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59425 const struct xattr_handler *handler =
59426@@ -400,9 +400,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59427 buffer += size;
59428 }
59429 rest -= size;
59430+ total_size += size;
59431 }
59432 }
59433- return buffer_size - rest;
59434+ return total_size;
59435 }
59436
59437 static int
59438diff --git a/fs/fcntl.c b/fs/fcntl.c
59439index 72c82f6..a18b263 100644
59440--- a/fs/fcntl.c
59441+++ b/fs/fcntl.c
59442@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59443 if (err)
59444 return err;
59445
59446+ if (gr_handle_chroot_fowner(pid, type))
59447+ return -ENOENT;
59448+ if (gr_check_protected_task_fowner(pid, type))
59449+ return -EACCES;
59450+
59451 f_modown(filp, pid, type, force);
59452 return 0;
59453 }
59454diff --git a/fs/fhandle.c b/fs/fhandle.c
59455index 999ff5c..ac037c9 100644
59456--- a/fs/fhandle.c
59457+++ b/fs/fhandle.c
59458@@ -8,6 +8,7 @@
59459 #include <linux/fs_struct.h>
59460 #include <linux/fsnotify.h>
59461 #include <linux/personality.h>
59462+#include <linux/grsecurity.h>
59463 #include <asm/uaccess.h>
59464 #include "internal.h"
59465 #include "mount.h"
59466@@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
59467 } else
59468 retval = 0;
59469 /* copy the mount id */
59470- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59471- sizeof(*mnt_id)) ||
59472+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59473 copy_to_user(ufh, handle,
59474 sizeof(struct file_handle) + handle_bytes))
59475 retval = -EFAULT;
59476@@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
59477 * the directory. Ideally we would like CAP_DAC_SEARCH.
59478 * But we don't have that
59479 */
59480- if (!capable(CAP_DAC_READ_SEARCH)) {
59481+ if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
59482 retval = -EPERM;
59483 goto out_err;
59484 }
59485diff --git a/fs/file.c b/fs/file.c
59486index 8f294cf..d0f3872 100644
59487--- a/fs/file.c
59488+++ b/fs/file.c
59489@@ -16,6 +16,7 @@
59490 #include <linux/slab.h>
59491 #include <linux/vmalloc.h>
59492 #include <linux/file.h>
59493+#include <linux/security.h>
59494 #include <linux/fdtable.h>
59495 #include <linux/bitops.h>
59496 #include <linux/interrupt.h>
59497@@ -144,7 +145,7 @@ out:
59498 * Return <0 error code on error; 1 on successful completion.
59499 * The files->file_lock should be held on entry, and will be held on exit.
59500 */
59501-static int expand_fdtable(struct files_struct *files, int nr)
59502+static int expand_fdtable(struct files_struct *files, unsigned int nr)
59503 __releases(files->file_lock)
59504 __acquires(files->file_lock)
59505 {
59506@@ -189,7 +190,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59507 * expanded and execution may have blocked.
59508 * The files->file_lock should be held on entry, and will be held on exit.
59509 */
59510-static int expand_files(struct files_struct *files, int nr)
59511+static int expand_files(struct files_struct *files, unsigned int nr)
59512 {
59513 struct fdtable *fdt;
59514
59515@@ -804,6 +805,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59516 if (!file)
59517 return __close_fd(files, fd);
59518
59519+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59520 if (fd >= rlimit(RLIMIT_NOFILE))
59521 return -EBADF;
59522
59523@@ -830,6 +832,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59524 if (unlikely(oldfd == newfd))
59525 return -EINVAL;
59526
59527+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59528 if (newfd >= rlimit(RLIMIT_NOFILE))
59529 return -EBADF;
59530
59531@@ -885,6 +888,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59532 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59533 {
59534 int err;
59535+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59536 if (from >= rlimit(RLIMIT_NOFILE))
59537 return -EINVAL;
59538 err = alloc_fd(from, flags);
59539diff --git a/fs/filesystems.c b/fs/filesystems.c
59540index 5797d45..7d7d79a 100644
59541--- a/fs/filesystems.c
59542+++ b/fs/filesystems.c
59543@@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
59544 int len = dot ? dot - name : strlen(name);
59545
59546 fs = __get_fs_type(name, len);
59547+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59548+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59549+#else
59550 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59551+#endif
59552 fs = __get_fs_type(name, len);
59553
59554 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59555diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59556index 7dca743..543d620 100644
59557--- a/fs/fs_struct.c
59558+++ b/fs/fs_struct.c
59559@@ -4,6 +4,7 @@
59560 #include <linux/path.h>
59561 #include <linux/slab.h>
59562 #include <linux/fs_struct.h>
59563+#include <linux/grsecurity.h>
59564 #include "internal.h"
59565
59566 /*
59567@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59568 write_seqcount_begin(&fs->seq);
59569 old_root = fs->root;
59570 fs->root = *path;
59571+ gr_set_chroot_entries(current, path);
59572 write_seqcount_end(&fs->seq);
59573 spin_unlock(&fs->lock);
59574 if (old_root.dentry)
59575@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59576 int hits = 0;
59577 spin_lock(&fs->lock);
59578 write_seqcount_begin(&fs->seq);
59579+ /* this root replacement is only done by pivot_root,
59580+ leave grsec's chroot tagging alone for this task
59581+ so that a pivoted root isn't treated as a chroot
59582+ */
59583 hits += replace_path(&fs->root, old_root, new_root);
59584 hits += replace_path(&fs->pwd, old_root, new_root);
59585 write_seqcount_end(&fs->seq);
59586@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59587 task_lock(tsk);
59588 spin_lock(&fs->lock);
59589 tsk->fs = NULL;
59590- kill = !--fs->users;
59591+ gr_clear_chroot_entries(tsk);
59592+ kill = !atomic_dec_return(&fs->users);
59593 spin_unlock(&fs->lock);
59594 task_unlock(tsk);
59595 if (kill)
59596@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59597 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59598 /* We don't need to lock fs - think why ;-) */
59599 if (fs) {
59600- fs->users = 1;
59601+ atomic_set(&fs->users, 1);
59602 fs->in_exec = 0;
59603 spin_lock_init(&fs->lock);
59604 seqcount_init(&fs->seq);
59605@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59606 spin_lock(&old->lock);
59607 fs->root = old->root;
59608 path_get(&fs->root);
59609+ /* instead of calling gr_set_chroot_entries here,
59610+ we call it from every caller of this function
59611+ */
59612 fs->pwd = old->pwd;
59613 path_get(&fs->pwd);
59614 spin_unlock(&old->lock);
59615@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59616
59617 task_lock(current);
59618 spin_lock(&fs->lock);
59619- kill = !--fs->users;
59620+ kill = !atomic_dec_return(&fs->users);
59621 current->fs = new_fs;
59622+ gr_set_chroot_entries(current, &new_fs->root);
59623 spin_unlock(&fs->lock);
59624 task_unlock(current);
59625
59626@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59627
59628 int current_umask(void)
59629 {
59630- return current->fs->umask;
59631+ return current->fs->umask | gr_acl_umask();
59632 }
59633 EXPORT_SYMBOL(current_umask);
59634
59635 /* to be mentioned only in INIT_TASK */
59636 struct fs_struct init_fs = {
59637- .users = 1,
59638+ .users = ATOMIC_INIT(1),
59639 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59640 .seq = SEQCNT_ZERO(init_fs.seq),
59641 .umask = 0022,
59642diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59643index 29d7feb..303644d 100644
59644--- a/fs/fscache/cookie.c
59645+++ b/fs/fscache/cookie.c
59646@@ -19,7 +19,7 @@
59647
59648 struct kmem_cache *fscache_cookie_jar;
59649
59650-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59651+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59652
59653 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59654 static int fscache_alloc_object(struct fscache_cache *cache,
59655@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59656 parent ? (char *) parent->def->name : "<no-parent>",
59657 def->name, netfs_data, enable);
59658
59659- fscache_stat(&fscache_n_acquires);
59660+ fscache_stat_unchecked(&fscache_n_acquires);
59661
59662 /* if there's no parent cookie, then we don't create one here either */
59663 if (!parent) {
59664- fscache_stat(&fscache_n_acquires_null);
59665+ fscache_stat_unchecked(&fscache_n_acquires_null);
59666 _leave(" [no parent]");
59667 return NULL;
59668 }
59669@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59670 /* allocate and initialise a cookie */
59671 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59672 if (!cookie) {
59673- fscache_stat(&fscache_n_acquires_oom);
59674+ fscache_stat_unchecked(&fscache_n_acquires_oom);
59675 _leave(" [ENOMEM]");
59676 return NULL;
59677 }
59678@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59679
59680 switch (cookie->def->type) {
59681 case FSCACHE_COOKIE_TYPE_INDEX:
59682- fscache_stat(&fscache_n_cookie_index);
59683+ fscache_stat_unchecked(&fscache_n_cookie_index);
59684 break;
59685 case FSCACHE_COOKIE_TYPE_DATAFILE:
59686- fscache_stat(&fscache_n_cookie_data);
59687+ fscache_stat_unchecked(&fscache_n_cookie_data);
59688 break;
59689 default:
59690- fscache_stat(&fscache_n_cookie_special);
59691+ fscache_stat_unchecked(&fscache_n_cookie_special);
59692 break;
59693 }
59694
59695@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59696 } else {
59697 atomic_dec(&parent->n_children);
59698 __fscache_cookie_put(cookie);
59699- fscache_stat(&fscache_n_acquires_nobufs);
59700+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59701 _leave(" = NULL");
59702 return NULL;
59703 }
59704@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59705 }
59706 }
59707
59708- fscache_stat(&fscache_n_acquires_ok);
59709+ fscache_stat_unchecked(&fscache_n_acquires_ok);
59710 _leave(" = %p", cookie);
59711 return cookie;
59712 }
59713@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59714 cache = fscache_select_cache_for_object(cookie->parent);
59715 if (!cache) {
59716 up_read(&fscache_addremove_sem);
59717- fscache_stat(&fscache_n_acquires_no_cache);
59718+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59719 _leave(" = -ENOMEDIUM [no cache]");
59720 return -ENOMEDIUM;
59721 }
59722@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59723 object = cache->ops->alloc_object(cache, cookie);
59724 fscache_stat_d(&fscache_n_cop_alloc_object);
59725 if (IS_ERR(object)) {
59726- fscache_stat(&fscache_n_object_no_alloc);
59727+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
59728 ret = PTR_ERR(object);
59729 goto error;
59730 }
59731
59732- fscache_stat(&fscache_n_object_alloc);
59733+ fscache_stat_unchecked(&fscache_n_object_alloc);
59734
59735- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59736+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59737
59738 _debug("ALLOC OBJ%x: %s {%lx}",
59739 object->debug_id, cookie->def->name, object->events);
59740@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59741
59742 _enter("{%s}", cookie->def->name);
59743
59744- fscache_stat(&fscache_n_invalidates);
59745+ fscache_stat_unchecked(&fscache_n_invalidates);
59746
59747 /* Only permit invalidation of data files. Invalidating an index will
59748 * require the caller to release all its attachments to the tree rooted
59749@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59750 {
59751 struct fscache_object *object;
59752
59753- fscache_stat(&fscache_n_updates);
59754+ fscache_stat_unchecked(&fscache_n_updates);
59755
59756 if (!cookie) {
59757- fscache_stat(&fscache_n_updates_null);
59758+ fscache_stat_unchecked(&fscache_n_updates_null);
59759 _leave(" [no cookie]");
59760 return;
59761 }
59762@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59763 */
59764 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59765 {
59766- fscache_stat(&fscache_n_relinquishes);
59767+ fscache_stat_unchecked(&fscache_n_relinquishes);
59768 if (retire)
59769- fscache_stat(&fscache_n_relinquishes_retire);
59770+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59771
59772 if (!cookie) {
59773- fscache_stat(&fscache_n_relinquishes_null);
59774+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
59775 _leave(" [no cookie]");
59776 return;
59777 }
59778@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59779 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59780 goto inconsistent;
59781
59782- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59783+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59784
59785 __fscache_use_cookie(cookie);
59786 if (fscache_submit_op(object, op) < 0)
59787diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59788index 4226f66..0fb3f45 100644
59789--- a/fs/fscache/internal.h
59790+++ b/fs/fscache/internal.h
59791@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59792 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59793 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59794 struct fscache_operation *,
59795- atomic_t *,
59796- atomic_t *,
59797+ atomic_unchecked_t *,
59798+ atomic_unchecked_t *,
59799 void (*)(struct fscache_operation *));
59800 extern void fscache_invalidate_writes(struct fscache_cookie *);
59801
59802@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59803 * stats.c
59804 */
59805 #ifdef CONFIG_FSCACHE_STATS
59806-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59807-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59808+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59809+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59810
59811-extern atomic_t fscache_n_op_pend;
59812-extern atomic_t fscache_n_op_run;
59813-extern atomic_t fscache_n_op_enqueue;
59814-extern atomic_t fscache_n_op_deferred_release;
59815-extern atomic_t fscache_n_op_release;
59816-extern atomic_t fscache_n_op_gc;
59817-extern atomic_t fscache_n_op_cancelled;
59818-extern atomic_t fscache_n_op_rejected;
59819+extern atomic_unchecked_t fscache_n_op_pend;
59820+extern atomic_unchecked_t fscache_n_op_run;
59821+extern atomic_unchecked_t fscache_n_op_enqueue;
59822+extern atomic_unchecked_t fscache_n_op_deferred_release;
59823+extern atomic_unchecked_t fscache_n_op_release;
59824+extern atomic_unchecked_t fscache_n_op_gc;
59825+extern atomic_unchecked_t fscache_n_op_cancelled;
59826+extern atomic_unchecked_t fscache_n_op_rejected;
59827
59828-extern atomic_t fscache_n_attr_changed;
59829-extern atomic_t fscache_n_attr_changed_ok;
59830-extern atomic_t fscache_n_attr_changed_nobufs;
59831-extern atomic_t fscache_n_attr_changed_nomem;
59832-extern atomic_t fscache_n_attr_changed_calls;
59833+extern atomic_unchecked_t fscache_n_attr_changed;
59834+extern atomic_unchecked_t fscache_n_attr_changed_ok;
59835+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59836+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59837+extern atomic_unchecked_t fscache_n_attr_changed_calls;
59838
59839-extern atomic_t fscache_n_allocs;
59840-extern atomic_t fscache_n_allocs_ok;
59841-extern atomic_t fscache_n_allocs_wait;
59842-extern atomic_t fscache_n_allocs_nobufs;
59843-extern atomic_t fscache_n_allocs_intr;
59844-extern atomic_t fscache_n_allocs_object_dead;
59845-extern atomic_t fscache_n_alloc_ops;
59846-extern atomic_t fscache_n_alloc_op_waits;
59847+extern atomic_unchecked_t fscache_n_allocs;
59848+extern atomic_unchecked_t fscache_n_allocs_ok;
59849+extern atomic_unchecked_t fscache_n_allocs_wait;
59850+extern atomic_unchecked_t fscache_n_allocs_nobufs;
59851+extern atomic_unchecked_t fscache_n_allocs_intr;
59852+extern atomic_unchecked_t fscache_n_allocs_object_dead;
59853+extern atomic_unchecked_t fscache_n_alloc_ops;
59854+extern atomic_unchecked_t fscache_n_alloc_op_waits;
59855
59856-extern atomic_t fscache_n_retrievals;
59857-extern atomic_t fscache_n_retrievals_ok;
59858-extern atomic_t fscache_n_retrievals_wait;
59859-extern atomic_t fscache_n_retrievals_nodata;
59860-extern atomic_t fscache_n_retrievals_nobufs;
59861-extern atomic_t fscache_n_retrievals_intr;
59862-extern atomic_t fscache_n_retrievals_nomem;
59863-extern atomic_t fscache_n_retrievals_object_dead;
59864-extern atomic_t fscache_n_retrieval_ops;
59865-extern atomic_t fscache_n_retrieval_op_waits;
59866+extern atomic_unchecked_t fscache_n_retrievals;
59867+extern atomic_unchecked_t fscache_n_retrievals_ok;
59868+extern atomic_unchecked_t fscache_n_retrievals_wait;
59869+extern atomic_unchecked_t fscache_n_retrievals_nodata;
59870+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59871+extern atomic_unchecked_t fscache_n_retrievals_intr;
59872+extern atomic_unchecked_t fscache_n_retrievals_nomem;
59873+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59874+extern atomic_unchecked_t fscache_n_retrieval_ops;
59875+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59876
59877-extern atomic_t fscache_n_stores;
59878-extern atomic_t fscache_n_stores_ok;
59879-extern atomic_t fscache_n_stores_again;
59880-extern atomic_t fscache_n_stores_nobufs;
59881-extern atomic_t fscache_n_stores_oom;
59882-extern atomic_t fscache_n_store_ops;
59883-extern atomic_t fscache_n_store_calls;
59884-extern atomic_t fscache_n_store_pages;
59885-extern atomic_t fscache_n_store_radix_deletes;
59886-extern atomic_t fscache_n_store_pages_over_limit;
59887+extern atomic_unchecked_t fscache_n_stores;
59888+extern atomic_unchecked_t fscache_n_stores_ok;
59889+extern atomic_unchecked_t fscache_n_stores_again;
59890+extern atomic_unchecked_t fscache_n_stores_nobufs;
59891+extern atomic_unchecked_t fscache_n_stores_oom;
59892+extern atomic_unchecked_t fscache_n_store_ops;
59893+extern atomic_unchecked_t fscache_n_store_calls;
59894+extern atomic_unchecked_t fscache_n_store_pages;
59895+extern atomic_unchecked_t fscache_n_store_radix_deletes;
59896+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
59897
59898-extern atomic_t fscache_n_store_vmscan_not_storing;
59899-extern atomic_t fscache_n_store_vmscan_gone;
59900-extern atomic_t fscache_n_store_vmscan_busy;
59901-extern atomic_t fscache_n_store_vmscan_cancelled;
59902-extern atomic_t fscache_n_store_vmscan_wait;
59903+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59904+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
59905+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
59906+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59907+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
59908
59909-extern atomic_t fscache_n_marks;
59910-extern atomic_t fscache_n_uncaches;
59911+extern atomic_unchecked_t fscache_n_marks;
59912+extern atomic_unchecked_t fscache_n_uncaches;
59913
59914-extern atomic_t fscache_n_acquires;
59915-extern atomic_t fscache_n_acquires_null;
59916-extern atomic_t fscache_n_acquires_no_cache;
59917-extern atomic_t fscache_n_acquires_ok;
59918-extern atomic_t fscache_n_acquires_nobufs;
59919-extern atomic_t fscache_n_acquires_oom;
59920+extern atomic_unchecked_t fscache_n_acquires;
59921+extern atomic_unchecked_t fscache_n_acquires_null;
59922+extern atomic_unchecked_t fscache_n_acquires_no_cache;
59923+extern atomic_unchecked_t fscache_n_acquires_ok;
59924+extern atomic_unchecked_t fscache_n_acquires_nobufs;
59925+extern atomic_unchecked_t fscache_n_acquires_oom;
59926
59927-extern atomic_t fscache_n_invalidates;
59928-extern atomic_t fscache_n_invalidates_run;
59929+extern atomic_unchecked_t fscache_n_invalidates;
59930+extern atomic_unchecked_t fscache_n_invalidates_run;
59931
59932-extern atomic_t fscache_n_updates;
59933-extern atomic_t fscache_n_updates_null;
59934-extern atomic_t fscache_n_updates_run;
59935+extern atomic_unchecked_t fscache_n_updates;
59936+extern atomic_unchecked_t fscache_n_updates_null;
59937+extern atomic_unchecked_t fscache_n_updates_run;
59938
59939-extern atomic_t fscache_n_relinquishes;
59940-extern atomic_t fscache_n_relinquishes_null;
59941-extern atomic_t fscache_n_relinquishes_waitcrt;
59942-extern atomic_t fscache_n_relinquishes_retire;
59943+extern atomic_unchecked_t fscache_n_relinquishes;
59944+extern atomic_unchecked_t fscache_n_relinquishes_null;
59945+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59946+extern atomic_unchecked_t fscache_n_relinquishes_retire;
59947
59948-extern atomic_t fscache_n_cookie_index;
59949-extern atomic_t fscache_n_cookie_data;
59950-extern atomic_t fscache_n_cookie_special;
59951+extern atomic_unchecked_t fscache_n_cookie_index;
59952+extern atomic_unchecked_t fscache_n_cookie_data;
59953+extern atomic_unchecked_t fscache_n_cookie_special;
59954
59955-extern atomic_t fscache_n_object_alloc;
59956-extern atomic_t fscache_n_object_no_alloc;
59957-extern atomic_t fscache_n_object_lookups;
59958-extern atomic_t fscache_n_object_lookups_negative;
59959-extern atomic_t fscache_n_object_lookups_positive;
59960-extern atomic_t fscache_n_object_lookups_timed_out;
59961-extern atomic_t fscache_n_object_created;
59962-extern atomic_t fscache_n_object_avail;
59963-extern atomic_t fscache_n_object_dead;
59964+extern atomic_unchecked_t fscache_n_object_alloc;
59965+extern atomic_unchecked_t fscache_n_object_no_alloc;
59966+extern atomic_unchecked_t fscache_n_object_lookups;
59967+extern atomic_unchecked_t fscache_n_object_lookups_negative;
59968+extern atomic_unchecked_t fscache_n_object_lookups_positive;
59969+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
59970+extern atomic_unchecked_t fscache_n_object_created;
59971+extern atomic_unchecked_t fscache_n_object_avail;
59972+extern atomic_unchecked_t fscache_n_object_dead;
59973
59974-extern atomic_t fscache_n_checkaux_none;
59975-extern atomic_t fscache_n_checkaux_okay;
59976-extern atomic_t fscache_n_checkaux_update;
59977-extern atomic_t fscache_n_checkaux_obsolete;
59978+extern atomic_unchecked_t fscache_n_checkaux_none;
59979+extern atomic_unchecked_t fscache_n_checkaux_okay;
59980+extern atomic_unchecked_t fscache_n_checkaux_update;
59981+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
59982
59983 extern atomic_t fscache_n_cop_alloc_object;
59984 extern atomic_t fscache_n_cop_lookup_object;
59985@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
59986 atomic_inc(stat);
59987 }
59988
59989+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
59990+{
59991+ atomic_inc_unchecked(stat);
59992+}
59993+
59994 static inline void fscache_stat_d(atomic_t *stat)
59995 {
59996 atomic_dec(stat);
59997@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
59998
59999 #define __fscache_stat(stat) (NULL)
60000 #define fscache_stat(stat) do {} while (0)
60001+#define fscache_stat_unchecked(stat) do {} while (0)
60002 #define fscache_stat_d(stat) do {} while (0)
60003 #endif
60004
60005diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60006index d3b4539..ed0c659 100644
60007--- a/fs/fscache/object.c
60008+++ b/fs/fscache/object.c
60009@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60010 _debug("LOOKUP \"%s\" in \"%s\"",
60011 cookie->def->name, object->cache->tag->name);
60012
60013- fscache_stat(&fscache_n_object_lookups);
60014+ fscache_stat_unchecked(&fscache_n_object_lookups);
60015 fscache_stat(&fscache_n_cop_lookup_object);
60016 ret = object->cache->ops->lookup_object(object);
60017 fscache_stat_d(&fscache_n_cop_lookup_object);
60018@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60019 if (ret == -ETIMEDOUT) {
60020 /* probably stuck behind another object, so move this one to
60021 * the back of the queue */
60022- fscache_stat(&fscache_n_object_lookups_timed_out);
60023+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60024 _leave(" [timeout]");
60025 return NO_TRANSIT;
60026 }
60027@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60028 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60029
60030 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60031- fscache_stat(&fscache_n_object_lookups_negative);
60032+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60033
60034 /* Allow write requests to begin stacking up and read requests to begin
60035 * returning ENODATA.
60036@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60037 /* if we were still looking up, then we must have a positive lookup
60038 * result, in which case there may be data available */
60039 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60040- fscache_stat(&fscache_n_object_lookups_positive);
60041+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60042
60043 /* We do (presumably) have data */
60044 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60045@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60046 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60047 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60048 } else {
60049- fscache_stat(&fscache_n_object_created);
60050+ fscache_stat_unchecked(&fscache_n_object_created);
60051 }
60052
60053 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60054@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60055 fscache_stat_d(&fscache_n_cop_lookup_complete);
60056
60057 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60058- fscache_stat(&fscache_n_object_avail);
60059+ fscache_stat_unchecked(&fscache_n_object_avail);
60060
60061 _leave("");
60062 return transit_to(JUMPSTART_DEPS);
60063@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60064
60065 /* this just shifts the object release to the work processor */
60066 fscache_put_object(object);
60067- fscache_stat(&fscache_n_object_dead);
60068+ fscache_stat_unchecked(&fscache_n_object_dead);
60069
60070 _leave("");
60071 return transit_to(OBJECT_DEAD);
60072@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60073 enum fscache_checkaux result;
60074
60075 if (!object->cookie->def->check_aux) {
60076- fscache_stat(&fscache_n_checkaux_none);
60077+ fscache_stat_unchecked(&fscache_n_checkaux_none);
60078 return FSCACHE_CHECKAUX_OKAY;
60079 }
60080
60081@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60082 switch (result) {
60083 /* entry okay as is */
60084 case FSCACHE_CHECKAUX_OKAY:
60085- fscache_stat(&fscache_n_checkaux_okay);
60086+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
60087 break;
60088
60089 /* entry requires update */
60090 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60091- fscache_stat(&fscache_n_checkaux_update);
60092+ fscache_stat_unchecked(&fscache_n_checkaux_update);
60093 break;
60094
60095 /* entry requires deletion */
60096 case FSCACHE_CHECKAUX_OBSOLETE:
60097- fscache_stat(&fscache_n_checkaux_obsolete);
60098+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60099 break;
60100
60101 default:
60102@@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60103 {
60104 const struct fscache_state *s;
60105
60106- fscache_stat(&fscache_n_invalidates_run);
60107+ fscache_stat_unchecked(&fscache_n_invalidates_run);
60108 fscache_stat(&fscache_n_cop_invalidate_object);
60109 s = _fscache_invalidate_object(object, event);
60110 fscache_stat_d(&fscache_n_cop_invalidate_object);
60111@@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60112 {
60113 _enter("{OBJ%x},%d", object->debug_id, event);
60114
60115- fscache_stat(&fscache_n_updates_run);
60116+ fscache_stat_unchecked(&fscache_n_updates_run);
60117 fscache_stat(&fscache_n_cop_update_object);
60118 object->cache->ops->update_object(object);
60119 fscache_stat_d(&fscache_n_cop_update_object);
60120diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60121index 318071a..379938b 100644
60122--- a/fs/fscache/operation.c
60123+++ b/fs/fscache/operation.c
60124@@ -17,7 +17,7 @@
60125 #include <linux/slab.h>
60126 #include "internal.h"
60127
60128-atomic_t fscache_op_debug_id;
60129+atomic_unchecked_t fscache_op_debug_id;
60130 EXPORT_SYMBOL(fscache_op_debug_id);
60131
60132 /**
60133@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60134 ASSERTCMP(atomic_read(&op->usage), >, 0);
60135 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60136
60137- fscache_stat(&fscache_n_op_enqueue);
60138+ fscache_stat_unchecked(&fscache_n_op_enqueue);
60139 switch (op->flags & FSCACHE_OP_TYPE) {
60140 case FSCACHE_OP_ASYNC:
60141 _debug("queue async");
60142@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60143 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60144 if (op->processor)
60145 fscache_enqueue_operation(op);
60146- fscache_stat(&fscache_n_op_run);
60147+ fscache_stat_unchecked(&fscache_n_op_run);
60148 }
60149
60150 /*
60151@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60152 if (object->n_in_progress > 0) {
60153 atomic_inc(&op->usage);
60154 list_add_tail(&op->pend_link, &object->pending_ops);
60155- fscache_stat(&fscache_n_op_pend);
60156+ fscache_stat_unchecked(&fscache_n_op_pend);
60157 } else if (!list_empty(&object->pending_ops)) {
60158 atomic_inc(&op->usage);
60159 list_add_tail(&op->pend_link, &object->pending_ops);
60160- fscache_stat(&fscache_n_op_pend);
60161+ fscache_stat_unchecked(&fscache_n_op_pend);
60162 fscache_start_operations(object);
60163 } else {
60164 ASSERTCMP(object->n_in_progress, ==, 0);
60165@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60166 object->n_exclusive++; /* reads and writes must wait */
60167 atomic_inc(&op->usage);
60168 list_add_tail(&op->pend_link, &object->pending_ops);
60169- fscache_stat(&fscache_n_op_pend);
60170+ fscache_stat_unchecked(&fscache_n_op_pend);
60171 ret = 0;
60172 } else {
60173 /* If we're in any other state, there must have been an I/O
60174@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60175 if (object->n_exclusive > 0) {
60176 atomic_inc(&op->usage);
60177 list_add_tail(&op->pend_link, &object->pending_ops);
60178- fscache_stat(&fscache_n_op_pend);
60179+ fscache_stat_unchecked(&fscache_n_op_pend);
60180 } else if (!list_empty(&object->pending_ops)) {
60181 atomic_inc(&op->usage);
60182 list_add_tail(&op->pend_link, &object->pending_ops);
60183- fscache_stat(&fscache_n_op_pend);
60184+ fscache_stat_unchecked(&fscache_n_op_pend);
60185 fscache_start_operations(object);
60186 } else {
60187 ASSERTCMP(object->n_exclusive, ==, 0);
60188@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60189 object->n_ops++;
60190 atomic_inc(&op->usage);
60191 list_add_tail(&op->pend_link, &object->pending_ops);
60192- fscache_stat(&fscache_n_op_pend);
60193+ fscache_stat_unchecked(&fscache_n_op_pend);
60194 ret = 0;
60195 } else if (fscache_object_is_dying(object)) {
60196- fscache_stat(&fscache_n_op_rejected);
60197+ fscache_stat_unchecked(&fscache_n_op_rejected);
60198 op->state = FSCACHE_OP_ST_CANCELLED;
60199 ret = -ENOBUFS;
60200 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60201@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60202 ret = -EBUSY;
60203 if (op->state == FSCACHE_OP_ST_PENDING) {
60204 ASSERT(!list_empty(&op->pend_link));
60205- fscache_stat(&fscache_n_op_cancelled);
60206+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60207 list_del_init(&op->pend_link);
60208 if (do_cancel)
60209 do_cancel(op);
60210@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60211 while (!list_empty(&object->pending_ops)) {
60212 op = list_entry(object->pending_ops.next,
60213 struct fscache_operation, pend_link);
60214- fscache_stat(&fscache_n_op_cancelled);
60215+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60216 list_del_init(&op->pend_link);
60217
60218 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60219@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60220 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60221 op->state = FSCACHE_OP_ST_DEAD;
60222
60223- fscache_stat(&fscache_n_op_release);
60224+ fscache_stat_unchecked(&fscache_n_op_release);
60225
60226 if (op->release) {
60227 op->release(op);
60228@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60229 * lock, and defer it otherwise */
60230 if (!spin_trylock(&object->lock)) {
60231 _debug("defer put");
60232- fscache_stat(&fscache_n_op_deferred_release);
60233+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60234
60235 cache = object->cache;
60236 spin_lock(&cache->op_gc_list_lock);
60237@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60238
60239 _debug("GC DEFERRED REL OBJ%x OP%x",
60240 object->debug_id, op->debug_id);
60241- fscache_stat(&fscache_n_op_gc);
60242+ fscache_stat_unchecked(&fscache_n_op_gc);
60243
60244 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60245 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60246diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60247index 7f5c658..6c1e164 100644
60248--- a/fs/fscache/page.c
60249+++ b/fs/fscache/page.c
60250@@ -61,7 +61,7 @@ try_again:
60251 val = radix_tree_lookup(&cookie->stores, page->index);
60252 if (!val) {
60253 rcu_read_unlock();
60254- fscache_stat(&fscache_n_store_vmscan_not_storing);
60255+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60256 __fscache_uncache_page(cookie, page);
60257 return true;
60258 }
60259@@ -91,11 +91,11 @@ try_again:
60260 spin_unlock(&cookie->stores_lock);
60261
60262 if (xpage) {
60263- fscache_stat(&fscache_n_store_vmscan_cancelled);
60264- fscache_stat(&fscache_n_store_radix_deletes);
60265+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60266+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60267 ASSERTCMP(xpage, ==, page);
60268 } else {
60269- fscache_stat(&fscache_n_store_vmscan_gone);
60270+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60271 }
60272
60273 wake_up_bit(&cookie->flags, 0);
60274@@ -110,11 +110,11 @@ page_busy:
60275 * sleeping on memory allocation, so we may need to impose a timeout
60276 * too. */
60277 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60278- fscache_stat(&fscache_n_store_vmscan_busy);
60279+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60280 return false;
60281 }
60282
60283- fscache_stat(&fscache_n_store_vmscan_wait);
60284+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60285 __fscache_wait_on_page_write(cookie, page);
60286 gfp &= ~__GFP_WAIT;
60287 goto try_again;
60288@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60289 FSCACHE_COOKIE_STORING_TAG);
60290 if (!radix_tree_tag_get(&cookie->stores, page->index,
60291 FSCACHE_COOKIE_PENDING_TAG)) {
60292- fscache_stat(&fscache_n_store_radix_deletes);
60293+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60294 xpage = radix_tree_delete(&cookie->stores, page->index);
60295 }
60296 spin_unlock(&cookie->stores_lock);
60297@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60298
60299 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60300
60301- fscache_stat(&fscache_n_attr_changed_calls);
60302+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60303
60304 if (fscache_object_is_active(object)) {
60305 fscache_stat(&fscache_n_cop_attr_changed);
60306@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60307
60308 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60309
60310- fscache_stat(&fscache_n_attr_changed);
60311+ fscache_stat_unchecked(&fscache_n_attr_changed);
60312
60313 op = kzalloc(sizeof(*op), GFP_KERNEL);
60314 if (!op) {
60315- fscache_stat(&fscache_n_attr_changed_nomem);
60316+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60317 _leave(" = -ENOMEM");
60318 return -ENOMEM;
60319 }
60320@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60321 if (fscache_submit_exclusive_op(object, op) < 0)
60322 goto nobufs;
60323 spin_unlock(&cookie->lock);
60324- fscache_stat(&fscache_n_attr_changed_ok);
60325+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60326 fscache_put_operation(op);
60327 _leave(" = 0");
60328 return 0;
60329@@ -225,7 +225,7 @@ nobufs:
60330 kfree(op);
60331 if (wake_cookie)
60332 __fscache_wake_unused_cookie(cookie);
60333- fscache_stat(&fscache_n_attr_changed_nobufs);
60334+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60335 _leave(" = %d", -ENOBUFS);
60336 return -ENOBUFS;
60337 }
60338@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60339 /* allocate a retrieval operation and attempt to submit it */
60340 op = kzalloc(sizeof(*op), GFP_NOIO);
60341 if (!op) {
60342- fscache_stat(&fscache_n_retrievals_nomem);
60343+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60344 return NULL;
60345 }
60346
60347@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60348 return 0;
60349 }
60350
60351- fscache_stat(&fscache_n_retrievals_wait);
60352+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60353
60354 jif = jiffies;
60355 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60356 fscache_wait_bit_interruptible,
60357 TASK_INTERRUPTIBLE) != 0) {
60358- fscache_stat(&fscache_n_retrievals_intr);
60359+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60360 _leave(" = -ERESTARTSYS");
60361 return -ERESTARTSYS;
60362 }
60363@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60364 */
60365 int fscache_wait_for_operation_activation(struct fscache_object *object,
60366 struct fscache_operation *op,
60367- atomic_t *stat_op_waits,
60368- atomic_t *stat_object_dead,
60369+ atomic_unchecked_t *stat_op_waits,
60370+ atomic_unchecked_t *stat_object_dead,
60371 void (*do_cancel)(struct fscache_operation *))
60372 {
60373 int ret;
60374@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60375
60376 _debug(">>> WT");
60377 if (stat_op_waits)
60378- fscache_stat(stat_op_waits);
60379+ fscache_stat_unchecked(stat_op_waits);
60380 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60381 fscache_wait_bit_interruptible,
60382 TASK_INTERRUPTIBLE) != 0) {
60383@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60384 check_if_dead:
60385 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60386 if (stat_object_dead)
60387- fscache_stat(stat_object_dead);
60388+ fscache_stat_unchecked(stat_object_dead);
60389 _leave(" = -ENOBUFS [cancelled]");
60390 return -ENOBUFS;
60391 }
60392@@ -366,7 +366,7 @@ check_if_dead:
60393 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60394 fscache_cancel_op(op, do_cancel);
60395 if (stat_object_dead)
60396- fscache_stat(stat_object_dead);
60397+ fscache_stat_unchecked(stat_object_dead);
60398 return -ENOBUFS;
60399 }
60400 return 0;
60401@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60402
60403 _enter("%p,%p,,,", cookie, page);
60404
60405- fscache_stat(&fscache_n_retrievals);
60406+ fscache_stat_unchecked(&fscache_n_retrievals);
60407
60408 if (hlist_empty(&cookie->backing_objects))
60409 goto nobufs;
60410@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60411 goto nobufs_unlock_dec;
60412 spin_unlock(&cookie->lock);
60413
60414- fscache_stat(&fscache_n_retrieval_ops);
60415+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60416
60417 /* pin the netfs read context in case we need to do the actual netfs
60418 * read because we've encountered a cache read failure */
60419@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60420
60421 error:
60422 if (ret == -ENOMEM)
60423- fscache_stat(&fscache_n_retrievals_nomem);
60424+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60425 else if (ret == -ERESTARTSYS)
60426- fscache_stat(&fscache_n_retrievals_intr);
60427+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60428 else if (ret == -ENODATA)
60429- fscache_stat(&fscache_n_retrievals_nodata);
60430+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60431 else if (ret < 0)
60432- fscache_stat(&fscache_n_retrievals_nobufs);
60433+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60434 else
60435- fscache_stat(&fscache_n_retrievals_ok);
60436+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60437
60438 fscache_put_retrieval(op);
60439 _leave(" = %d", ret);
60440@@ -490,7 +490,7 @@ nobufs_unlock:
60441 __fscache_wake_unused_cookie(cookie);
60442 kfree(op);
60443 nobufs:
60444- fscache_stat(&fscache_n_retrievals_nobufs);
60445+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60446 _leave(" = -ENOBUFS");
60447 return -ENOBUFS;
60448 }
60449@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60450
60451 _enter("%p,,%d,,,", cookie, *nr_pages);
60452
60453- fscache_stat(&fscache_n_retrievals);
60454+ fscache_stat_unchecked(&fscache_n_retrievals);
60455
60456 if (hlist_empty(&cookie->backing_objects))
60457 goto nobufs;
60458@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60459 goto nobufs_unlock_dec;
60460 spin_unlock(&cookie->lock);
60461
60462- fscache_stat(&fscache_n_retrieval_ops);
60463+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60464
60465 /* pin the netfs read context in case we need to do the actual netfs
60466 * read because we've encountered a cache read failure */
60467@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60468
60469 error:
60470 if (ret == -ENOMEM)
60471- fscache_stat(&fscache_n_retrievals_nomem);
60472+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60473 else if (ret == -ERESTARTSYS)
60474- fscache_stat(&fscache_n_retrievals_intr);
60475+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60476 else if (ret == -ENODATA)
60477- fscache_stat(&fscache_n_retrievals_nodata);
60478+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60479 else if (ret < 0)
60480- fscache_stat(&fscache_n_retrievals_nobufs);
60481+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60482 else
60483- fscache_stat(&fscache_n_retrievals_ok);
60484+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60485
60486 fscache_put_retrieval(op);
60487 _leave(" = %d", ret);
60488@@ -621,7 +621,7 @@ nobufs_unlock:
60489 if (wake_cookie)
60490 __fscache_wake_unused_cookie(cookie);
60491 nobufs:
60492- fscache_stat(&fscache_n_retrievals_nobufs);
60493+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60494 _leave(" = -ENOBUFS");
60495 return -ENOBUFS;
60496 }
60497@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60498
60499 _enter("%p,%p,,,", cookie, page);
60500
60501- fscache_stat(&fscache_n_allocs);
60502+ fscache_stat_unchecked(&fscache_n_allocs);
60503
60504 if (hlist_empty(&cookie->backing_objects))
60505 goto nobufs;
60506@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60507 goto nobufs_unlock_dec;
60508 spin_unlock(&cookie->lock);
60509
60510- fscache_stat(&fscache_n_alloc_ops);
60511+ fscache_stat_unchecked(&fscache_n_alloc_ops);
60512
60513 ret = fscache_wait_for_operation_activation(
60514 object, &op->op,
60515@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60516
60517 error:
60518 if (ret == -ERESTARTSYS)
60519- fscache_stat(&fscache_n_allocs_intr);
60520+ fscache_stat_unchecked(&fscache_n_allocs_intr);
60521 else if (ret < 0)
60522- fscache_stat(&fscache_n_allocs_nobufs);
60523+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60524 else
60525- fscache_stat(&fscache_n_allocs_ok);
60526+ fscache_stat_unchecked(&fscache_n_allocs_ok);
60527
60528 fscache_put_retrieval(op);
60529 _leave(" = %d", ret);
60530@@ -715,7 +715,7 @@ nobufs_unlock:
60531 if (wake_cookie)
60532 __fscache_wake_unused_cookie(cookie);
60533 nobufs:
60534- fscache_stat(&fscache_n_allocs_nobufs);
60535+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60536 _leave(" = -ENOBUFS");
60537 return -ENOBUFS;
60538 }
60539@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60540
60541 spin_lock(&cookie->stores_lock);
60542
60543- fscache_stat(&fscache_n_store_calls);
60544+ fscache_stat_unchecked(&fscache_n_store_calls);
60545
60546 /* find a page to store */
60547 page = NULL;
60548@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60549 page = results[0];
60550 _debug("gang %d [%lx]", n, page->index);
60551 if (page->index > op->store_limit) {
60552- fscache_stat(&fscache_n_store_pages_over_limit);
60553+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60554 goto superseded;
60555 }
60556
60557@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60558 spin_unlock(&cookie->stores_lock);
60559 spin_unlock(&object->lock);
60560
60561- fscache_stat(&fscache_n_store_pages);
60562+ fscache_stat_unchecked(&fscache_n_store_pages);
60563 fscache_stat(&fscache_n_cop_write_page);
60564 ret = object->cache->ops->write_page(op, page);
60565 fscache_stat_d(&fscache_n_cop_write_page);
60566@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60567 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60568 ASSERT(PageFsCache(page));
60569
60570- fscache_stat(&fscache_n_stores);
60571+ fscache_stat_unchecked(&fscache_n_stores);
60572
60573 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60574 _leave(" = -ENOBUFS [invalidating]");
60575@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60576 spin_unlock(&cookie->stores_lock);
60577 spin_unlock(&object->lock);
60578
60579- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60580+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60581 op->store_limit = object->store_limit;
60582
60583 __fscache_use_cookie(cookie);
60584@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60585
60586 spin_unlock(&cookie->lock);
60587 radix_tree_preload_end();
60588- fscache_stat(&fscache_n_store_ops);
60589- fscache_stat(&fscache_n_stores_ok);
60590+ fscache_stat_unchecked(&fscache_n_store_ops);
60591+ fscache_stat_unchecked(&fscache_n_stores_ok);
60592
60593 /* the work queue now carries its own ref on the object */
60594 fscache_put_operation(&op->op);
60595@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60596 return 0;
60597
60598 already_queued:
60599- fscache_stat(&fscache_n_stores_again);
60600+ fscache_stat_unchecked(&fscache_n_stores_again);
60601 already_pending:
60602 spin_unlock(&cookie->stores_lock);
60603 spin_unlock(&object->lock);
60604 spin_unlock(&cookie->lock);
60605 radix_tree_preload_end();
60606 kfree(op);
60607- fscache_stat(&fscache_n_stores_ok);
60608+ fscache_stat_unchecked(&fscache_n_stores_ok);
60609 _leave(" = 0");
60610 return 0;
60611
60612@@ -1024,14 +1024,14 @@ nobufs:
60613 kfree(op);
60614 if (wake_cookie)
60615 __fscache_wake_unused_cookie(cookie);
60616- fscache_stat(&fscache_n_stores_nobufs);
60617+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
60618 _leave(" = -ENOBUFS");
60619 return -ENOBUFS;
60620
60621 nomem_free:
60622 kfree(op);
60623 nomem:
60624- fscache_stat(&fscache_n_stores_oom);
60625+ fscache_stat_unchecked(&fscache_n_stores_oom);
60626 _leave(" = -ENOMEM");
60627 return -ENOMEM;
60628 }
60629@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60630 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60631 ASSERTCMP(page, !=, NULL);
60632
60633- fscache_stat(&fscache_n_uncaches);
60634+ fscache_stat_unchecked(&fscache_n_uncaches);
60635
60636 /* cache withdrawal may beat us to it */
60637 if (!PageFsCache(page))
60638@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60639 struct fscache_cookie *cookie = op->op.object->cookie;
60640
60641 #ifdef CONFIG_FSCACHE_STATS
60642- atomic_inc(&fscache_n_marks);
60643+ atomic_inc_unchecked(&fscache_n_marks);
60644 #endif
60645
60646 _debug("- mark %p{%lx}", page, page->index);
60647diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60648index 40d13c7..ddf52b9 100644
60649--- a/fs/fscache/stats.c
60650+++ b/fs/fscache/stats.c
60651@@ -18,99 +18,99 @@
60652 /*
60653 * operation counters
60654 */
60655-atomic_t fscache_n_op_pend;
60656-atomic_t fscache_n_op_run;
60657-atomic_t fscache_n_op_enqueue;
60658-atomic_t fscache_n_op_requeue;
60659-atomic_t fscache_n_op_deferred_release;
60660-atomic_t fscache_n_op_release;
60661-atomic_t fscache_n_op_gc;
60662-atomic_t fscache_n_op_cancelled;
60663-atomic_t fscache_n_op_rejected;
60664+atomic_unchecked_t fscache_n_op_pend;
60665+atomic_unchecked_t fscache_n_op_run;
60666+atomic_unchecked_t fscache_n_op_enqueue;
60667+atomic_unchecked_t fscache_n_op_requeue;
60668+atomic_unchecked_t fscache_n_op_deferred_release;
60669+atomic_unchecked_t fscache_n_op_release;
60670+atomic_unchecked_t fscache_n_op_gc;
60671+atomic_unchecked_t fscache_n_op_cancelled;
60672+atomic_unchecked_t fscache_n_op_rejected;
60673
60674-atomic_t fscache_n_attr_changed;
60675-atomic_t fscache_n_attr_changed_ok;
60676-atomic_t fscache_n_attr_changed_nobufs;
60677-atomic_t fscache_n_attr_changed_nomem;
60678-atomic_t fscache_n_attr_changed_calls;
60679+atomic_unchecked_t fscache_n_attr_changed;
60680+atomic_unchecked_t fscache_n_attr_changed_ok;
60681+atomic_unchecked_t fscache_n_attr_changed_nobufs;
60682+atomic_unchecked_t fscache_n_attr_changed_nomem;
60683+atomic_unchecked_t fscache_n_attr_changed_calls;
60684
60685-atomic_t fscache_n_allocs;
60686-atomic_t fscache_n_allocs_ok;
60687-atomic_t fscache_n_allocs_wait;
60688-atomic_t fscache_n_allocs_nobufs;
60689-atomic_t fscache_n_allocs_intr;
60690-atomic_t fscache_n_allocs_object_dead;
60691-atomic_t fscache_n_alloc_ops;
60692-atomic_t fscache_n_alloc_op_waits;
60693+atomic_unchecked_t fscache_n_allocs;
60694+atomic_unchecked_t fscache_n_allocs_ok;
60695+atomic_unchecked_t fscache_n_allocs_wait;
60696+atomic_unchecked_t fscache_n_allocs_nobufs;
60697+atomic_unchecked_t fscache_n_allocs_intr;
60698+atomic_unchecked_t fscache_n_allocs_object_dead;
60699+atomic_unchecked_t fscache_n_alloc_ops;
60700+atomic_unchecked_t fscache_n_alloc_op_waits;
60701
60702-atomic_t fscache_n_retrievals;
60703-atomic_t fscache_n_retrievals_ok;
60704-atomic_t fscache_n_retrievals_wait;
60705-atomic_t fscache_n_retrievals_nodata;
60706-atomic_t fscache_n_retrievals_nobufs;
60707-atomic_t fscache_n_retrievals_intr;
60708-atomic_t fscache_n_retrievals_nomem;
60709-atomic_t fscache_n_retrievals_object_dead;
60710-atomic_t fscache_n_retrieval_ops;
60711-atomic_t fscache_n_retrieval_op_waits;
60712+atomic_unchecked_t fscache_n_retrievals;
60713+atomic_unchecked_t fscache_n_retrievals_ok;
60714+atomic_unchecked_t fscache_n_retrievals_wait;
60715+atomic_unchecked_t fscache_n_retrievals_nodata;
60716+atomic_unchecked_t fscache_n_retrievals_nobufs;
60717+atomic_unchecked_t fscache_n_retrievals_intr;
60718+atomic_unchecked_t fscache_n_retrievals_nomem;
60719+atomic_unchecked_t fscache_n_retrievals_object_dead;
60720+atomic_unchecked_t fscache_n_retrieval_ops;
60721+atomic_unchecked_t fscache_n_retrieval_op_waits;
60722
60723-atomic_t fscache_n_stores;
60724-atomic_t fscache_n_stores_ok;
60725-atomic_t fscache_n_stores_again;
60726-atomic_t fscache_n_stores_nobufs;
60727-atomic_t fscache_n_stores_oom;
60728-atomic_t fscache_n_store_ops;
60729-atomic_t fscache_n_store_calls;
60730-atomic_t fscache_n_store_pages;
60731-atomic_t fscache_n_store_radix_deletes;
60732-atomic_t fscache_n_store_pages_over_limit;
60733+atomic_unchecked_t fscache_n_stores;
60734+atomic_unchecked_t fscache_n_stores_ok;
60735+atomic_unchecked_t fscache_n_stores_again;
60736+atomic_unchecked_t fscache_n_stores_nobufs;
60737+atomic_unchecked_t fscache_n_stores_oom;
60738+atomic_unchecked_t fscache_n_store_ops;
60739+atomic_unchecked_t fscache_n_store_calls;
60740+atomic_unchecked_t fscache_n_store_pages;
60741+atomic_unchecked_t fscache_n_store_radix_deletes;
60742+atomic_unchecked_t fscache_n_store_pages_over_limit;
60743
60744-atomic_t fscache_n_store_vmscan_not_storing;
60745-atomic_t fscache_n_store_vmscan_gone;
60746-atomic_t fscache_n_store_vmscan_busy;
60747-atomic_t fscache_n_store_vmscan_cancelled;
60748-atomic_t fscache_n_store_vmscan_wait;
60749+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60750+atomic_unchecked_t fscache_n_store_vmscan_gone;
60751+atomic_unchecked_t fscache_n_store_vmscan_busy;
60752+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60753+atomic_unchecked_t fscache_n_store_vmscan_wait;
60754
60755-atomic_t fscache_n_marks;
60756-atomic_t fscache_n_uncaches;
60757+atomic_unchecked_t fscache_n_marks;
60758+atomic_unchecked_t fscache_n_uncaches;
60759
60760-atomic_t fscache_n_acquires;
60761-atomic_t fscache_n_acquires_null;
60762-atomic_t fscache_n_acquires_no_cache;
60763-atomic_t fscache_n_acquires_ok;
60764-atomic_t fscache_n_acquires_nobufs;
60765-atomic_t fscache_n_acquires_oom;
60766+atomic_unchecked_t fscache_n_acquires;
60767+atomic_unchecked_t fscache_n_acquires_null;
60768+atomic_unchecked_t fscache_n_acquires_no_cache;
60769+atomic_unchecked_t fscache_n_acquires_ok;
60770+atomic_unchecked_t fscache_n_acquires_nobufs;
60771+atomic_unchecked_t fscache_n_acquires_oom;
60772
60773-atomic_t fscache_n_invalidates;
60774-atomic_t fscache_n_invalidates_run;
60775+atomic_unchecked_t fscache_n_invalidates;
60776+atomic_unchecked_t fscache_n_invalidates_run;
60777
60778-atomic_t fscache_n_updates;
60779-atomic_t fscache_n_updates_null;
60780-atomic_t fscache_n_updates_run;
60781+atomic_unchecked_t fscache_n_updates;
60782+atomic_unchecked_t fscache_n_updates_null;
60783+atomic_unchecked_t fscache_n_updates_run;
60784
60785-atomic_t fscache_n_relinquishes;
60786-atomic_t fscache_n_relinquishes_null;
60787-atomic_t fscache_n_relinquishes_waitcrt;
60788-atomic_t fscache_n_relinquishes_retire;
60789+atomic_unchecked_t fscache_n_relinquishes;
60790+atomic_unchecked_t fscache_n_relinquishes_null;
60791+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60792+atomic_unchecked_t fscache_n_relinquishes_retire;
60793
60794-atomic_t fscache_n_cookie_index;
60795-atomic_t fscache_n_cookie_data;
60796-atomic_t fscache_n_cookie_special;
60797+atomic_unchecked_t fscache_n_cookie_index;
60798+atomic_unchecked_t fscache_n_cookie_data;
60799+atomic_unchecked_t fscache_n_cookie_special;
60800
60801-atomic_t fscache_n_object_alloc;
60802-atomic_t fscache_n_object_no_alloc;
60803-atomic_t fscache_n_object_lookups;
60804-atomic_t fscache_n_object_lookups_negative;
60805-atomic_t fscache_n_object_lookups_positive;
60806-atomic_t fscache_n_object_lookups_timed_out;
60807-atomic_t fscache_n_object_created;
60808-atomic_t fscache_n_object_avail;
60809-atomic_t fscache_n_object_dead;
60810+atomic_unchecked_t fscache_n_object_alloc;
60811+atomic_unchecked_t fscache_n_object_no_alloc;
60812+atomic_unchecked_t fscache_n_object_lookups;
60813+atomic_unchecked_t fscache_n_object_lookups_negative;
60814+atomic_unchecked_t fscache_n_object_lookups_positive;
60815+atomic_unchecked_t fscache_n_object_lookups_timed_out;
60816+atomic_unchecked_t fscache_n_object_created;
60817+atomic_unchecked_t fscache_n_object_avail;
60818+atomic_unchecked_t fscache_n_object_dead;
60819
60820-atomic_t fscache_n_checkaux_none;
60821-atomic_t fscache_n_checkaux_okay;
60822-atomic_t fscache_n_checkaux_update;
60823-atomic_t fscache_n_checkaux_obsolete;
60824+atomic_unchecked_t fscache_n_checkaux_none;
60825+atomic_unchecked_t fscache_n_checkaux_okay;
60826+atomic_unchecked_t fscache_n_checkaux_update;
60827+atomic_unchecked_t fscache_n_checkaux_obsolete;
60828
60829 atomic_t fscache_n_cop_alloc_object;
60830 atomic_t fscache_n_cop_lookup_object;
60831@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60832 seq_puts(m, "FS-Cache statistics\n");
60833
60834 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60835- atomic_read(&fscache_n_cookie_index),
60836- atomic_read(&fscache_n_cookie_data),
60837- atomic_read(&fscache_n_cookie_special));
60838+ atomic_read_unchecked(&fscache_n_cookie_index),
60839+ atomic_read_unchecked(&fscache_n_cookie_data),
60840+ atomic_read_unchecked(&fscache_n_cookie_special));
60841
60842 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60843- atomic_read(&fscache_n_object_alloc),
60844- atomic_read(&fscache_n_object_no_alloc),
60845- atomic_read(&fscache_n_object_avail),
60846- atomic_read(&fscache_n_object_dead));
60847+ atomic_read_unchecked(&fscache_n_object_alloc),
60848+ atomic_read_unchecked(&fscache_n_object_no_alloc),
60849+ atomic_read_unchecked(&fscache_n_object_avail),
60850+ atomic_read_unchecked(&fscache_n_object_dead));
60851 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60852- atomic_read(&fscache_n_checkaux_none),
60853- atomic_read(&fscache_n_checkaux_okay),
60854- atomic_read(&fscache_n_checkaux_update),
60855- atomic_read(&fscache_n_checkaux_obsolete));
60856+ atomic_read_unchecked(&fscache_n_checkaux_none),
60857+ atomic_read_unchecked(&fscache_n_checkaux_okay),
60858+ atomic_read_unchecked(&fscache_n_checkaux_update),
60859+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60860
60861 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60862- atomic_read(&fscache_n_marks),
60863- atomic_read(&fscache_n_uncaches));
60864+ atomic_read_unchecked(&fscache_n_marks),
60865+ atomic_read_unchecked(&fscache_n_uncaches));
60866
60867 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60868 " oom=%u\n",
60869- atomic_read(&fscache_n_acquires),
60870- atomic_read(&fscache_n_acquires_null),
60871- atomic_read(&fscache_n_acquires_no_cache),
60872- atomic_read(&fscache_n_acquires_ok),
60873- atomic_read(&fscache_n_acquires_nobufs),
60874- atomic_read(&fscache_n_acquires_oom));
60875+ atomic_read_unchecked(&fscache_n_acquires),
60876+ atomic_read_unchecked(&fscache_n_acquires_null),
60877+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
60878+ atomic_read_unchecked(&fscache_n_acquires_ok),
60879+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
60880+ atomic_read_unchecked(&fscache_n_acquires_oom));
60881
60882 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60883- atomic_read(&fscache_n_object_lookups),
60884- atomic_read(&fscache_n_object_lookups_negative),
60885- atomic_read(&fscache_n_object_lookups_positive),
60886- atomic_read(&fscache_n_object_created),
60887- atomic_read(&fscache_n_object_lookups_timed_out));
60888+ atomic_read_unchecked(&fscache_n_object_lookups),
60889+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
60890+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
60891+ atomic_read_unchecked(&fscache_n_object_created),
60892+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
60893
60894 seq_printf(m, "Invals : n=%u run=%u\n",
60895- atomic_read(&fscache_n_invalidates),
60896- atomic_read(&fscache_n_invalidates_run));
60897+ atomic_read_unchecked(&fscache_n_invalidates),
60898+ atomic_read_unchecked(&fscache_n_invalidates_run));
60899
60900 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
60901- atomic_read(&fscache_n_updates),
60902- atomic_read(&fscache_n_updates_null),
60903- atomic_read(&fscache_n_updates_run));
60904+ atomic_read_unchecked(&fscache_n_updates),
60905+ atomic_read_unchecked(&fscache_n_updates_null),
60906+ atomic_read_unchecked(&fscache_n_updates_run));
60907
60908 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
60909- atomic_read(&fscache_n_relinquishes),
60910- atomic_read(&fscache_n_relinquishes_null),
60911- atomic_read(&fscache_n_relinquishes_waitcrt),
60912- atomic_read(&fscache_n_relinquishes_retire));
60913+ atomic_read_unchecked(&fscache_n_relinquishes),
60914+ atomic_read_unchecked(&fscache_n_relinquishes_null),
60915+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
60916+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
60917
60918 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
60919- atomic_read(&fscache_n_attr_changed),
60920- atomic_read(&fscache_n_attr_changed_ok),
60921- atomic_read(&fscache_n_attr_changed_nobufs),
60922- atomic_read(&fscache_n_attr_changed_nomem),
60923- atomic_read(&fscache_n_attr_changed_calls));
60924+ atomic_read_unchecked(&fscache_n_attr_changed),
60925+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
60926+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
60927+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
60928+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
60929
60930 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
60931- atomic_read(&fscache_n_allocs),
60932- atomic_read(&fscache_n_allocs_ok),
60933- atomic_read(&fscache_n_allocs_wait),
60934- atomic_read(&fscache_n_allocs_nobufs),
60935- atomic_read(&fscache_n_allocs_intr));
60936+ atomic_read_unchecked(&fscache_n_allocs),
60937+ atomic_read_unchecked(&fscache_n_allocs_ok),
60938+ atomic_read_unchecked(&fscache_n_allocs_wait),
60939+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
60940+ atomic_read_unchecked(&fscache_n_allocs_intr));
60941 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
60942- atomic_read(&fscache_n_alloc_ops),
60943- atomic_read(&fscache_n_alloc_op_waits),
60944- atomic_read(&fscache_n_allocs_object_dead));
60945+ atomic_read_unchecked(&fscache_n_alloc_ops),
60946+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
60947+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
60948
60949 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
60950 " int=%u oom=%u\n",
60951- atomic_read(&fscache_n_retrievals),
60952- atomic_read(&fscache_n_retrievals_ok),
60953- atomic_read(&fscache_n_retrievals_wait),
60954- atomic_read(&fscache_n_retrievals_nodata),
60955- atomic_read(&fscache_n_retrievals_nobufs),
60956- atomic_read(&fscache_n_retrievals_intr),
60957- atomic_read(&fscache_n_retrievals_nomem));
60958+ atomic_read_unchecked(&fscache_n_retrievals),
60959+ atomic_read_unchecked(&fscache_n_retrievals_ok),
60960+ atomic_read_unchecked(&fscache_n_retrievals_wait),
60961+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
60962+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
60963+ atomic_read_unchecked(&fscache_n_retrievals_intr),
60964+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
60965 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
60966- atomic_read(&fscache_n_retrieval_ops),
60967- atomic_read(&fscache_n_retrieval_op_waits),
60968- atomic_read(&fscache_n_retrievals_object_dead));
60969+ atomic_read_unchecked(&fscache_n_retrieval_ops),
60970+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
60971+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
60972
60973 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
60974- atomic_read(&fscache_n_stores),
60975- atomic_read(&fscache_n_stores_ok),
60976- atomic_read(&fscache_n_stores_again),
60977- atomic_read(&fscache_n_stores_nobufs),
60978- atomic_read(&fscache_n_stores_oom));
60979+ atomic_read_unchecked(&fscache_n_stores),
60980+ atomic_read_unchecked(&fscache_n_stores_ok),
60981+ atomic_read_unchecked(&fscache_n_stores_again),
60982+ atomic_read_unchecked(&fscache_n_stores_nobufs),
60983+ atomic_read_unchecked(&fscache_n_stores_oom));
60984 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
60985- atomic_read(&fscache_n_store_ops),
60986- atomic_read(&fscache_n_store_calls),
60987- atomic_read(&fscache_n_store_pages),
60988- atomic_read(&fscache_n_store_radix_deletes),
60989- atomic_read(&fscache_n_store_pages_over_limit));
60990+ atomic_read_unchecked(&fscache_n_store_ops),
60991+ atomic_read_unchecked(&fscache_n_store_calls),
60992+ atomic_read_unchecked(&fscache_n_store_pages),
60993+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
60994+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
60995
60996 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
60997- atomic_read(&fscache_n_store_vmscan_not_storing),
60998- atomic_read(&fscache_n_store_vmscan_gone),
60999- atomic_read(&fscache_n_store_vmscan_busy),
61000- atomic_read(&fscache_n_store_vmscan_cancelled),
61001- atomic_read(&fscache_n_store_vmscan_wait));
61002+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61003+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61004+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61005+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61006+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61007
61008 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61009- atomic_read(&fscache_n_op_pend),
61010- atomic_read(&fscache_n_op_run),
61011- atomic_read(&fscache_n_op_enqueue),
61012- atomic_read(&fscache_n_op_cancelled),
61013- atomic_read(&fscache_n_op_rejected));
61014+ atomic_read_unchecked(&fscache_n_op_pend),
61015+ atomic_read_unchecked(&fscache_n_op_run),
61016+ atomic_read_unchecked(&fscache_n_op_enqueue),
61017+ atomic_read_unchecked(&fscache_n_op_cancelled),
61018+ atomic_read_unchecked(&fscache_n_op_rejected));
61019 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61020- atomic_read(&fscache_n_op_deferred_release),
61021- atomic_read(&fscache_n_op_release),
61022- atomic_read(&fscache_n_op_gc));
61023+ atomic_read_unchecked(&fscache_n_op_deferred_release),
61024+ atomic_read_unchecked(&fscache_n_op_release),
61025+ atomic_read_unchecked(&fscache_n_op_gc));
61026
61027 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61028 atomic_read(&fscache_n_cop_alloc_object),
61029diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61030index 13b691a..1ffca5ae 100644
61031--- a/fs/fuse/cuse.c
61032+++ b/fs/fuse/cuse.c
61033@@ -607,10 +607,12 @@ static int __init cuse_init(void)
61034 INIT_LIST_HEAD(&cuse_conntbl[i]);
61035
61036 /* inherit and extend fuse_dev_operations */
61037- cuse_channel_fops = fuse_dev_operations;
61038- cuse_channel_fops.owner = THIS_MODULE;
61039- cuse_channel_fops.open = cuse_channel_open;
61040- cuse_channel_fops.release = cuse_channel_release;
61041+ pax_open_kernel();
61042+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61043+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61044+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
61045+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
61046+ pax_close_kernel();
61047
61048 cuse_class = class_create(THIS_MODULE, "cuse");
61049 if (IS_ERR(cuse_class))
61050diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61051index aac71ce..fcd6a1b 100644
61052--- a/fs/fuse/dev.c
61053+++ b/fs/fuse/dev.c
61054@@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61055 ret = 0;
61056 pipe_lock(pipe);
61057
61058- if (!pipe->readers) {
61059+ if (!atomic_read(&pipe->readers)) {
61060 send_sig(SIGPIPE, current, 0);
61061 if (!ret)
61062 ret = -EPIPE;
61063@@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61064 page_nr++;
61065 ret += buf->len;
61066
61067- if (pipe->files)
61068+ if (atomic_read(&pipe->files))
61069 do_wakeup = 1;
61070 }
61071
61072diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61073index 4219835..3473b7e 100644
61074--- a/fs/fuse/dir.c
61075+++ b/fs/fuse/dir.c
61076@@ -1478,7 +1478,7 @@ static char *read_link(struct dentry *dentry)
61077 return link;
61078 }
61079
61080-static void free_link(char *link)
61081+static void free_link(const char *link)
61082 {
61083 if (!IS_ERR(link))
61084 free_page((unsigned long) link);
61085diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61086index 9c470fd..aae410e 100644
61087--- a/fs/hostfs/hostfs_kern.c
61088+++ b/fs/hostfs/hostfs_kern.c
61089@@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61090
61091 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61092 {
61093- char *s = nd_get_link(nd);
61094+ const char *s = nd_get_link(nd);
61095 if (!IS_ERR(s))
61096 __putname(s);
61097 }
61098diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61099index e19d4c0..8a357a9 100644
61100--- a/fs/hugetlbfs/inode.c
61101+++ b/fs/hugetlbfs/inode.c
61102@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61103 struct mm_struct *mm = current->mm;
61104 struct vm_area_struct *vma;
61105 struct hstate *h = hstate_file(file);
61106+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61107 struct vm_unmapped_area_info info;
61108
61109 if (len & ~huge_page_mask(h))
61110@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61111 return addr;
61112 }
61113
61114+#ifdef CONFIG_PAX_RANDMMAP
61115+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61116+#endif
61117+
61118 if (addr) {
61119 addr = ALIGN(addr, huge_page_size(h));
61120 vma = find_vma(mm, addr);
61121- if (TASK_SIZE - len >= addr &&
61122- (!vma || addr + len <= vma->vm_start))
61123+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61124 return addr;
61125 }
61126
61127 info.flags = 0;
61128 info.length = len;
61129 info.low_limit = TASK_UNMAPPED_BASE;
61130+
61131+#ifdef CONFIG_PAX_RANDMMAP
61132+ if (mm->pax_flags & MF_PAX_RANDMMAP)
61133+ info.low_limit += mm->delta_mmap;
61134+#endif
61135+
61136 info.high_limit = TASK_SIZE;
61137 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61138 info.align_offset = 0;
61139@@ -921,7 +931,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61140 };
61141 MODULE_ALIAS_FS("hugetlbfs");
61142
61143-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61144+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61145
61146 static int can_do_hugetlb_shm(void)
61147 {
61148diff --git a/fs/inode.c b/fs/inode.c
61149index d2fb2f2..a6444b0 100644
61150--- a/fs/inode.c
61151+++ b/fs/inode.c
61152@@ -839,16 +839,20 @@ unsigned int get_next_ino(void)
61153 unsigned int *p = &get_cpu_var(last_ino);
61154 unsigned int res = *p;
61155
61156+start:
61157+
61158 #ifdef CONFIG_SMP
61159 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61160- static atomic_t shared_last_ino;
61161- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61162+ static atomic_unchecked_t shared_last_ino;
61163+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61164
61165 res = next - LAST_INO_BATCH;
61166 }
61167 #endif
61168
61169- *p = ++res;
61170+ if (unlikely(!++res))
61171+ goto start; /* never zero */
61172+ *p = res;
61173 put_cpu_var(last_ino);
61174 return res;
61175 }
61176diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61177index 4a6cf28..d3a29d3 100644
61178--- a/fs/jffs2/erase.c
61179+++ b/fs/jffs2/erase.c
61180@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61181 struct jffs2_unknown_node marker = {
61182 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61183 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61184- .totlen = cpu_to_je32(c->cleanmarker_size)
61185+ .totlen = cpu_to_je32(c->cleanmarker_size),
61186+ .hdr_crc = cpu_to_je32(0)
61187 };
61188
61189 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61190diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61191index a6597d6..41b30ec 100644
61192--- a/fs/jffs2/wbuf.c
61193+++ b/fs/jffs2/wbuf.c
61194@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61195 {
61196 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61197 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61198- .totlen = constant_cpu_to_je32(8)
61199+ .totlen = constant_cpu_to_je32(8),
61200+ .hdr_crc = constant_cpu_to_je32(0)
61201 };
61202
61203 /*
61204diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61205index 97f7fda..09bd33d 100644
61206--- a/fs/jfs/super.c
61207+++ b/fs/jfs/super.c
61208@@ -885,7 +885,7 @@ static int __init init_jfs_fs(void)
61209
61210 jfs_inode_cachep =
61211 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61212- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61213+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61214 init_once);
61215 if (jfs_inode_cachep == NULL)
61216 return -ENOMEM;
61217diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61218index ac127cd..d8079db 100644
61219--- a/fs/kernfs/dir.c
61220+++ b/fs/kernfs/dir.c
61221@@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
61222 *
61223 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61224 */
61225-static unsigned int kernfs_name_hash(const char *name, const void *ns)
61226+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61227 {
61228 unsigned long hash = init_name_hash();
61229 unsigned int len = strlen(name);
61230diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61231index 5e9a80c..3853a24 100644
61232--- a/fs/kernfs/file.c
61233+++ b/fs/kernfs/file.c
61234@@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61235
61236 struct kernfs_open_node {
61237 atomic_t refcnt;
61238- atomic_t event;
61239+ atomic_unchecked_t event;
61240 wait_queue_head_t poll;
61241 struct list_head files; /* goes through kernfs_open_file.list */
61242 };
61243@@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61244 {
61245 struct kernfs_open_file *of = sf->private;
61246
61247- of->event = atomic_read(&of->kn->attr.open->event);
61248+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61249
61250 return of->kn->attr.ops->seq_show(sf, v);
61251 }
61252@@ -361,12 +361,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61253 return ret;
61254 }
61255
61256-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61257- void *buf, int len, int write)
61258+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61259+ void *buf, size_t len, int write)
61260 {
61261 struct file *file = vma->vm_file;
61262 struct kernfs_open_file *of = kernfs_of(file);
61263- int ret;
61264+ ssize_t ret;
61265
61266 if (!of->vm_ops)
61267 return -EINVAL;
61268@@ -567,7 +567,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61269 return -ENOMEM;
61270
61271 atomic_set(&new_on->refcnt, 0);
61272- atomic_set(&new_on->event, 1);
61273+ atomic_set_unchecked(&new_on->event, 1);
61274 init_waitqueue_head(&new_on->poll);
61275 INIT_LIST_HEAD(&new_on->files);
61276 goto retry;
61277@@ -773,7 +773,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61278
61279 kernfs_put_active(kn);
61280
61281- if (of->event != atomic_read(&on->event))
61282+ if (of->event != atomic_read_unchecked(&on->event))
61283 goto trigger;
61284
61285 return DEFAULT_POLLMASK;
61286@@ -798,7 +798,7 @@ void kernfs_notify(struct kernfs_node *kn)
61287 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61288 on = kn->attr.open;
61289 if (on) {
61290- atomic_inc(&on->event);
61291+ atomic_inc_unchecked(&on->event);
61292 wake_up_interruptible(&on->poll);
61293 }
61294 }
61295diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61296index 8a19889..4c3069a 100644
61297--- a/fs/kernfs/symlink.c
61298+++ b/fs/kernfs/symlink.c
61299@@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61300 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61301 void *cookie)
61302 {
61303- char *page = nd_get_link(nd);
61304+ const char *page = nd_get_link(nd);
61305 if (!IS_ERR(page))
61306 free_page((unsigned long)page);
61307 }
61308diff --git a/fs/libfs.c b/fs/libfs.c
61309index a184424..944ddce 100644
61310--- a/fs/libfs.c
61311+++ b/fs/libfs.c
61312@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61313
61314 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61315 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61316+ char d_name[sizeof(next->d_iname)];
61317+ const unsigned char *name;
61318+
61319 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61320 if (!simple_positive(next)) {
61321 spin_unlock(&next->d_lock);
61322@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61323
61324 spin_unlock(&next->d_lock);
61325 spin_unlock(&dentry->d_lock);
61326- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61327+ name = next->d_name.name;
61328+ if (name == next->d_iname) {
61329+ memcpy(d_name, name, next->d_name.len);
61330+ name = d_name;
61331+ }
61332+ if (!dir_emit(ctx, name, next->d_name.len,
61333 next->d_inode->i_ino, dt_type(next->d_inode)))
61334 return 0;
61335 spin_lock(&dentry->d_lock);
61336@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61337 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61338 void *cookie)
61339 {
61340- char *s = nd_get_link(nd);
61341+ const char *s = nd_get_link(nd);
61342 if (!IS_ERR(s))
61343 kfree(s);
61344 }
61345diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61346index acd3947..1f896e2 100644
61347--- a/fs/lockd/clntproc.c
61348+++ b/fs/lockd/clntproc.c
61349@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61350 /*
61351 * Cookie counter for NLM requests
61352 */
61353-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61354+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61355
61356 void nlmclnt_next_cookie(struct nlm_cookie *c)
61357 {
61358- u32 cookie = atomic_inc_return(&nlm_cookie);
61359+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61360
61361 memcpy(c->data, &cookie, 4);
61362 c->len=4;
61363diff --git a/fs/locks.c b/fs/locks.c
61364index e390bd9..c79870e 100644
61365--- a/fs/locks.c
61366+++ b/fs/locks.c
61367@@ -2315,16 +2315,16 @@ void locks_remove_file(struct file *filp)
61368 locks_remove_posix(filp, (fl_owner_t)filp);
61369
61370 if (filp->f_op->flock) {
61371- struct file_lock fl = {
61372+ struct file_lock flock = {
61373 .fl_pid = current->tgid,
61374 .fl_file = filp,
61375 .fl_flags = FL_FLOCK,
61376 .fl_type = F_UNLCK,
61377 .fl_end = OFFSET_MAX,
61378 };
61379- filp->f_op->flock(filp, F_SETLKW, &fl);
61380- if (fl.fl_ops && fl.fl_ops->fl_release_private)
61381- fl.fl_ops->fl_release_private(&fl);
61382+ filp->f_op->flock(filp, F_SETLKW, &flock);
61383+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
61384+ flock.fl_ops->fl_release_private(&flock);
61385 }
61386
61387 spin_lock(&inode->i_lock);
61388diff --git a/fs/mount.h b/fs/mount.h
61389index d55297f..f5b28c5 100644
61390--- a/fs/mount.h
61391+++ b/fs/mount.h
61392@@ -11,7 +11,7 @@ struct mnt_namespace {
61393 u64 seq; /* Sequence number to prevent loops */
61394 wait_queue_head_t poll;
61395 u64 event;
61396-};
61397+} __randomize_layout;
61398
61399 struct mnt_pcp {
61400 int mnt_count;
61401@@ -57,7 +57,7 @@ struct mount {
61402 int mnt_expiry_mark; /* true if marked for expiry */
61403 int mnt_pinned;
61404 struct path mnt_ex_mountpoint;
61405-};
61406+} __randomize_layout;
61407
61408 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61409
61410diff --git a/fs/namei.c b/fs/namei.c
61411index 985c6f3..f67a0f8 100644
61412--- a/fs/namei.c
61413+++ b/fs/namei.c
61414@@ -330,17 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61415 if (ret != -EACCES)
61416 return ret;
61417
61418+#ifdef CONFIG_GRKERNSEC
61419+ /* we'll block if we have to log due to a denied capability use */
61420+ if (mask & MAY_NOT_BLOCK)
61421+ return -ECHILD;
61422+#endif
61423+
61424 if (S_ISDIR(inode->i_mode)) {
61425 /* DACs are overridable for directories */
61426- if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61427- return 0;
61428 if (!(mask & MAY_WRITE))
61429- if (capable_wrt_inode_uidgid(inode,
61430- CAP_DAC_READ_SEARCH))
61431+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61432+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61433 return 0;
61434+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61435+ return 0;
61436 return -EACCES;
61437 }
61438 /*
61439+ * Searching includes executable on directories, else just read.
61440+ */
61441+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61442+ if (mask == MAY_READ)
61443+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61444+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61445+ return 0;
61446+
61447+ /*
61448 * Read/write DACs are always overridable.
61449 * Executable DACs are overridable when there is
61450 * at least one exec bit set.
61451@@ -349,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61452 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61453 return 0;
61454
61455- /*
61456- * Searching includes executable on directories, else just read.
61457- */
61458- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61459- if (mask == MAY_READ)
61460- if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61461- return 0;
61462-
61463 return -EACCES;
61464 }
61465 EXPORT_SYMBOL(generic_permission);
61466@@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61467 {
61468 struct dentry *dentry = link->dentry;
61469 int error;
61470- char *s;
61471+ const char *s;
61472
61473 BUG_ON(nd->flags & LOOKUP_RCU);
61474
61475@@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61476 if (error)
61477 goto out_put_nd_path;
61478
61479+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
61480+ dentry->d_inode, dentry, nd->path.mnt)) {
61481+ error = -EACCES;
61482+ goto out_put_nd_path;
61483+ }
61484+
61485 nd->last_type = LAST_BIND;
61486 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61487 error = PTR_ERR(*p);
61488@@ -1596,6 +1609,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61489 if (res)
61490 break;
61491 res = walk_component(nd, path, LOOKUP_FOLLOW);
61492+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61493+ res = -EACCES;
61494 put_link(nd, &link, cookie);
61495 } while (res > 0);
61496
61497@@ -1669,7 +1684,7 @@ EXPORT_SYMBOL(full_name_hash);
61498 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61499 {
61500 unsigned long a, b, adata, bdata, mask, hash, len;
61501- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61502+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61503
61504 hash = a = 0;
61505 len = -sizeof(unsigned long);
61506@@ -1953,6 +1968,8 @@ static int path_lookupat(int dfd, const char *name,
61507 if (err)
61508 break;
61509 err = lookup_last(nd, &path);
61510+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
61511+ err = -EACCES;
61512 put_link(nd, &link, cookie);
61513 }
61514 }
61515@@ -1960,6 +1977,13 @@ static int path_lookupat(int dfd, const char *name,
61516 if (!err)
61517 err = complete_walk(nd);
61518
61519+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
61520+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61521+ path_put(&nd->path);
61522+ err = -ENOENT;
61523+ }
61524+ }
61525+
61526 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61527 if (!d_can_lookup(nd->path.dentry)) {
61528 path_put(&nd->path);
61529@@ -1987,8 +2011,15 @@ static int filename_lookup(int dfd, struct filename *name,
61530 retval = path_lookupat(dfd, name->name,
61531 flags | LOOKUP_REVAL, nd);
61532
61533- if (likely(!retval))
61534+ if (likely(!retval)) {
61535 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61536+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61537+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61538+ path_put(&nd->path);
61539+ return -ENOENT;
61540+ }
61541+ }
61542+ }
61543 return retval;
61544 }
61545
61546@@ -2569,6 +2600,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61547 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61548 return -EPERM;
61549
61550+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61551+ return -EPERM;
61552+ if (gr_handle_rawio(inode))
61553+ return -EPERM;
61554+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61555+ return -EACCES;
61556+
61557 return 0;
61558 }
61559
61560@@ -2800,7 +2838,7 @@ looked_up:
61561 * cleared otherwise prior to returning.
61562 */
61563 static int lookup_open(struct nameidata *nd, struct path *path,
61564- struct file *file,
61565+ struct path *link, struct file *file,
61566 const struct open_flags *op,
61567 bool got_write, int *opened)
61568 {
61569@@ -2835,6 +2873,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61570 /* Negative dentry, just create the file */
61571 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61572 umode_t mode = op->mode;
61573+
61574+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61575+ error = -EACCES;
61576+ goto out_dput;
61577+ }
61578+
61579+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61580+ error = -EACCES;
61581+ goto out_dput;
61582+ }
61583+
61584 if (!IS_POSIXACL(dir->d_inode))
61585 mode &= ~current_umask();
61586 /*
61587@@ -2856,6 +2905,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61588 nd->flags & LOOKUP_EXCL);
61589 if (error)
61590 goto out_dput;
61591+ else
61592+ gr_handle_create(dentry, nd->path.mnt);
61593 }
61594 out_no_open:
61595 path->dentry = dentry;
61596@@ -2870,7 +2921,7 @@ out_dput:
61597 /*
61598 * Handle the last step of open()
61599 */
61600-static int do_last(struct nameidata *nd, struct path *path,
61601+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61602 struct file *file, const struct open_flags *op,
61603 int *opened, struct filename *name)
61604 {
61605@@ -2920,6 +2971,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61606 if (error)
61607 return error;
61608
61609+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61610+ error = -ENOENT;
61611+ goto out;
61612+ }
61613+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61614+ error = -EACCES;
61615+ goto out;
61616+ }
61617+
61618 audit_inode(name, dir, LOOKUP_PARENT);
61619 error = -EISDIR;
61620 /* trailing slashes? */
61621@@ -2939,7 +2999,7 @@ retry_lookup:
61622 */
61623 }
61624 mutex_lock(&dir->d_inode->i_mutex);
61625- error = lookup_open(nd, path, file, op, got_write, opened);
61626+ error = lookup_open(nd, path, link, file, op, got_write, opened);
61627 mutex_unlock(&dir->d_inode->i_mutex);
61628
61629 if (error <= 0) {
61630@@ -2963,11 +3023,28 @@ retry_lookup:
61631 goto finish_open_created;
61632 }
61633
61634+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61635+ error = -ENOENT;
61636+ goto exit_dput;
61637+ }
61638+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61639+ error = -EACCES;
61640+ goto exit_dput;
61641+ }
61642+
61643 /*
61644 * create/update audit record if it already exists.
61645 */
61646- if (d_is_positive(path->dentry))
61647+ if (d_is_positive(path->dentry)) {
61648+ /* only check if O_CREAT is specified, all other checks need to go
61649+ into may_open */
61650+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61651+ error = -EACCES;
61652+ goto exit_dput;
61653+ }
61654+
61655 audit_inode(name, path->dentry, 0);
61656+ }
61657
61658 /*
61659 * If atomic_open() acquired write access it is dropped now due to
61660@@ -3008,6 +3085,11 @@ finish_lookup:
61661 }
61662 }
61663 BUG_ON(inode != path->dentry->d_inode);
61664+ /* if we're resolving a symlink to another symlink */
61665+ if (link && gr_handle_symlink_owner(link, inode)) {
61666+ error = -EACCES;
61667+ goto out;
61668+ }
61669 return 1;
61670 }
61671
61672@@ -3017,7 +3099,6 @@ finish_lookup:
61673 save_parent.dentry = nd->path.dentry;
61674 save_parent.mnt = mntget(path->mnt);
61675 nd->path.dentry = path->dentry;
61676-
61677 }
61678 nd->inode = inode;
61679 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61680@@ -3027,7 +3108,18 @@ finish_open:
61681 path_put(&save_parent);
61682 return error;
61683 }
61684+
61685+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61686+ error = -ENOENT;
61687+ goto out;
61688+ }
61689+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61690+ error = -EACCES;
61691+ goto out;
61692+ }
61693+
61694 audit_inode(name, nd->path.dentry, 0);
61695+
61696 error = -EISDIR;
61697 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
61698 goto out;
61699@@ -3190,7 +3282,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61700 if (unlikely(error))
61701 goto out;
61702
61703- error = do_last(nd, &path, file, op, &opened, pathname);
61704+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61705 while (unlikely(error > 0)) { /* trailing symlink */
61706 struct path link = path;
61707 void *cookie;
61708@@ -3208,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61709 error = follow_link(&link, nd, &cookie);
61710 if (unlikely(error))
61711 break;
61712- error = do_last(nd, &path, file, op, &opened, pathname);
61713+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
61714 put_link(nd, &link, cookie);
61715 }
61716 out:
61717@@ -3308,9 +3400,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61718 goto unlock;
61719
61720 error = -EEXIST;
61721- if (d_is_positive(dentry))
61722+ if (d_is_positive(dentry)) {
61723+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61724+ error = -ENOENT;
61725 goto fail;
61726-
61727+ }
61728 /*
61729 * Special case - lookup gave negative, but... we had foo/bar/
61730 * From the vfs_mknod() POV we just have a negative dentry -
61731@@ -3362,6 +3456,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61732 }
61733 EXPORT_SYMBOL(user_path_create);
61734
61735+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61736+{
61737+ struct filename *tmp = getname(pathname);
61738+ struct dentry *res;
61739+ if (IS_ERR(tmp))
61740+ return ERR_CAST(tmp);
61741+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61742+ if (IS_ERR(res))
61743+ putname(tmp);
61744+ else
61745+ *to = tmp;
61746+ return res;
61747+}
61748+
61749 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61750 {
61751 int error = may_create(dir, dentry);
61752@@ -3425,6 +3533,17 @@ retry:
61753
61754 if (!IS_POSIXACL(path.dentry->d_inode))
61755 mode &= ~current_umask();
61756+
61757+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61758+ error = -EPERM;
61759+ goto out;
61760+ }
61761+
61762+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61763+ error = -EACCES;
61764+ goto out;
61765+ }
61766+
61767 error = security_path_mknod(&path, dentry, mode, dev);
61768 if (error)
61769 goto out;
61770@@ -3441,6 +3560,8 @@ retry:
61771 break;
61772 }
61773 out:
61774+ if (!error)
61775+ gr_handle_create(dentry, path.mnt);
61776 done_path_create(&path, dentry);
61777 if (retry_estale(error, lookup_flags)) {
61778 lookup_flags |= LOOKUP_REVAL;
61779@@ -3494,9 +3615,16 @@ retry:
61780
61781 if (!IS_POSIXACL(path.dentry->d_inode))
61782 mode &= ~current_umask();
61783+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61784+ error = -EACCES;
61785+ goto out;
61786+ }
61787 error = security_path_mkdir(&path, dentry, mode);
61788 if (!error)
61789 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61790+ if (!error)
61791+ gr_handle_create(dentry, path.mnt);
61792+out:
61793 done_path_create(&path, dentry);
61794 if (retry_estale(error, lookup_flags)) {
61795 lookup_flags |= LOOKUP_REVAL;
61796@@ -3579,6 +3707,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61797 struct filename *name;
61798 struct dentry *dentry;
61799 struct nameidata nd;
61800+ ino_t saved_ino = 0;
61801+ dev_t saved_dev = 0;
61802 unsigned int lookup_flags = 0;
61803 retry:
61804 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61805@@ -3611,10 +3741,21 @@ retry:
61806 error = -ENOENT;
61807 goto exit3;
61808 }
61809+
61810+ saved_ino = dentry->d_inode->i_ino;
61811+ saved_dev = gr_get_dev_from_dentry(dentry);
61812+
61813+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61814+ error = -EACCES;
61815+ goto exit3;
61816+ }
61817+
61818 error = security_path_rmdir(&nd.path, dentry);
61819 if (error)
61820 goto exit3;
61821 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61822+ if (!error && (saved_dev || saved_ino))
61823+ gr_handle_delete(saved_ino, saved_dev);
61824 exit3:
61825 dput(dentry);
61826 exit2:
61827@@ -3705,6 +3846,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61828 struct nameidata nd;
61829 struct inode *inode = NULL;
61830 struct inode *delegated_inode = NULL;
61831+ ino_t saved_ino = 0;
61832+ dev_t saved_dev = 0;
61833 unsigned int lookup_flags = 0;
61834 retry:
61835 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61836@@ -3731,10 +3874,22 @@ retry_deleg:
61837 if (d_is_negative(dentry))
61838 goto slashes;
61839 ihold(inode);
61840+
61841+ if (inode->i_nlink <= 1) {
61842+ saved_ino = inode->i_ino;
61843+ saved_dev = gr_get_dev_from_dentry(dentry);
61844+ }
61845+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61846+ error = -EACCES;
61847+ goto exit2;
61848+ }
61849+
61850 error = security_path_unlink(&nd.path, dentry);
61851 if (error)
61852 goto exit2;
61853 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61854+ if (!error && (saved_ino || saved_dev))
61855+ gr_handle_delete(saved_ino, saved_dev);
61856 exit2:
61857 dput(dentry);
61858 }
61859@@ -3823,9 +3978,17 @@ retry:
61860 if (IS_ERR(dentry))
61861 goto out_putname;
61862
61863+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61864+ error = -EACCES;
61865+ goto out;
61866+ }
61867+
61868 error = security_path_symlink(&path, dentry, from->name);
61869 if (!error)
61870 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61871+ if (!error)
61872+ gr_handle_create(dentry, path.mnt);
61873+out:
61874 done_path_create(&path, dentry);
61875 if (retry_estale(error, lookup_flags)) {
61876 lookup_flags |= LOOKUP_REVAL;
61877@@ -3929,6 +4092,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61878 struct dentry *new_dentry;
61879 struct path old_path, new_path;
61880 struct inode *delegated_inode = NULL;
61881+ struct filename *to = NULL;
61882 int how = 0;
61883 int error;
61884
61885@@ -3952,7 +4116,7 @@ retry:
61886 if (error)
61887 return error;
61888
61889- new_dentry = user_path_create(newdfd, newname, &new_path,
61890+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
61891 (how & LOOKUP_REVAL));
61892 error = PTR_ERR(new_dentry);
61893 if (IS_ERR(new_dentry))
61894@@ -3964,11 +4128,28 @@ retry:
61895 error = may_linkat(&old_path);
61896 if (unlikely(error))
61897 goto out_dput;
61898+
61899+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
61900+ old_path.dentry->d_inode,
61901+ old_path.dentry->d_inode->i_mode, to)) {
61902+ error = -EACCES;
61903+ goto out_dput;
61904+ }
61905+
61906+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
61907+ old_path.dentry, old_path.mnt, to)) {
61908+ error = -EACCES;
61909+ goto out_dput;
61910+ }
61911+
61912 error = security_path_link(old_path.dentry, &new_path, new_dentry);
61913 if (error)
61914 goto out_dput;
61915 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
61916+ if (!error)
61917+ gr_handle_create(new_dentry, new_path.mnt);
61918 out_dput:
61919+ putname(to);
61920 done_path_create(&new_path, new_dentry);
61921 if (delegated_inode) {
61922 error = break_deleg_wait(&delegated_inode);
61923@@ -4278,6 +4459,12 @@ retry_deleg:
61924 if (new_dentry == trap)
61925 goto exit5;
61926
61927+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
61928+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
61929+ to, flags);
61930+ if (error)
61931+ goto exit5;
61932+
61933 error = security_path_rename(&oldnd.path, old_dentry,
61934 &newnd.path, new_dentry, flags);
61935 if (error)
61936@@ -4285,6 +4472,9 @@ retry_deleg:
61937 error = vfs_rename(old_dir->d_inode, old_dentry,
61938 new_dir->d_inode, new_dentry,
61939 &delegated_inode, flags);
61940+ if (!error)
61941+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
61942+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
61943 exit5:
61944 dput(new_dentry);
61945 exit4:
61946@@ -4327,14 +4517,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
61947
61948 int readlink_copy(char __user *buffer, int buflen, const char *link)
61949 {
61950+ char tmpbuf[64];
61951+ const char *newlink;
61952 int len = PTR_ERR(link);
61953+
61954 if (IS_ERR(link))
61955 goto out;
61956
61957 len = strlen(link);
61958 if (len > (unsigned) buflen)
61959 len = buflen;
61960- if (copy_to_user(buffer, link, len))
61961+
61962+ if (len < sizeof(tmpbuf)) {
61963+ memcpy(tmpbuf, link, len);
61964+ newlink = tmpbuf;
61965+ } else
61966+ newlink = link;
61967+
61968+ if (copy_to_user(buffer, newlink, len))
61969 len = -EFAULT;
61970 out:
61971 return len;
61972diff --git a/fs/namespace.c b/fs/namespace.c
61973index 182bc41..72e3cf1 100644
61974--- a/fs/namespace.c
61975+++ b/fs/namespace.c
61976@@ -1348,6 +1348,9 @@ static int do_umount(struct mount *mnt, int flags)
61977 if (!(sb->s_flags & MS_RDONLY))
61978 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
61979 up_write(&sb->s_umount);
61980+
61981+ gr_log_remount(mnt->mnt_devname, retval);
61982+
61983 return retval;
61984 }
61985
61986@@ -1370,6 +1373,9 @@ static int do_umount(struct mount *mnt, int flags)
61987 }
61988 unlock_mount_hash();
61989 namespace_unlock();
61990+
61991+ gr_log_unmount(mnt->mnt_devname, retval);
61992+
61993 return retval;
61994 }
61995
61996@@ -1389,7 +1395,7 @@ static inline bool may_mount(void)
61997 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
61998 */
61999
62000-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62001+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62002 {
62003 struct path path;
62004 struct mount *mnt;
62005@@ -1431,7 +1437,7 @@ out:
62006 /*
62007 * The 2.0 compatible umount. No flags.
62008 */
62009-SYSCALL_DEFINE1(oldumount, char __user *, name)
62010+SYSCALL_DEFINE1(oldumount, const char __user *, name)
62011 {
62012 return sys_umount(name, 0);
62013 }
62014@@ -2440,6 +2446,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62015 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62016 MS_STRICTATIME);
62017
62018+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62019+ retval = -EPERM;
62020+ goto dput_out;
62021+ }
62022+
62023+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62024+ retval = -EPERM;
62025+ goto dput_out;
62026+ }
62027+
62028 if (flags & MS_REMOUNT)
62029 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62030 data_page);
62031@@ -2454,6 +2470,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62032 dev_name, data_page);
62033 dput_out:
62034 path_put(&path);
62035+
62036+ gr_log_mount(dev_name, dir_name, retval);
62037+
62038 return retval;
62039 }
62040
62041@@ -2471,7 +2490,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62042 * number incrementing at 10Ghz will take 12,427 years to wrap which
62043 * is effectively never, so we can ignore the possibility.
62044 */
62045-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62046+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62047
62048 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62049 {
62050@@ -2486,7 +2505,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62051 kfree(new_ns);
62052 return ERR_PTR(ret);
62053 }
62054- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62055+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62056 atomic_set(&new_ns->count, 1);
62057 new_ns->root = NULL;
62058 INIT_LIST_HEAD(&new_ns->list);
62059@@ -2496,7 +2515,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62060 return new_ns;
62061 }
62062
62063-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62064+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62065 struct user_namespace *user_ns, struct fs_struct *new_fs)
62066 {
62067 struct mnt_namespace *new_ns;
62068@@ -2617,8 +2636,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62069 }
62070 EXPORT_SYMBOL(mount_subtree);
62071
62072-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62073- char __user *, type, unsigned long, flags, void __user *, data)
62074+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62075+ const char __user *, type, unsigned long, flags, void __user *, data)
62076 {
62077 int ret;
62078 char *kernel_type;
62079@@ -2731,6 +2750,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62080 if (error)
62081 goto out2;
62082
62083+ if (gr_handle_chroot_pivot()) {
62084+ error = -EPERM;
62085+ goto out2;
62086+ }
62087+
62088 get_fs_root(current->fs, &root);
62089 old_mp = lock_mount(&old);
62090 error = PTR_ERR(old_mp);
62091@@ -2999,7 +3023,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62092 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62093 return -EPERM;
62094
62095- if (fs->users != 1)
62096+ if (atomic_read(&fs->users) != 1)
62097 return -EINVAL;
62098
62099 get_mnt_ns(mnt_ns);
62100diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62101index f4ccfe6..a5cf064 100644
62102--- a/fs/nfs/callback_xdr.c
62103+++ b/fs/nfs/callback_xdr.c
62104@@ -51,7 +51,7 @@ struct callback_op {
62105 callback_decode_arg_t decode_args;
62106 callback_encode_res_t encode_res;
62107 long res_maxsize;
62108-};
62109+} __do_const;
62110
62111 static struct callback_op callback_ops[];
62112
62113diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62114index 0c43897..0949f08 100644
62115--- a/fs/nfs/inode.c
62116+++ b/fs/nfs/inode.c
62117@@ -1209,16 +1209,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62118 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62119 }
62120
62121-static atomic_long_t nfs_attr_generation_counter;
62122+static atomic_long_unchecked_t nfs_attr_generation_counter;
62123
62124 static unsigned long nfs_read_attr_generation_counter(void)
62125 {
62126- return atomic_long_read(&nfs_attr_generation_counter);
62127+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62128 }
62129
62130 unsigned long nfs_inc_attr_generation_counter(void)
62131 {
62132- return atomic_long_inc_return(&nfs_attr_generation_counter);
62133+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62134 }
62135
62136 void nfs_fattr_init(struct nfs_fattr *fattr)
62137diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62138index d543222..2cfa2a2 100644
62139--- a/fs/nfsd/nfs4proc.c
62140+++ b/fs/nfsd/nfs4proc.c
62141@@ -1178,7 +1178,7 @@ struct nfsd4_operation {
62142 nfsd4op_rsize op_rsize_bop;
62143 stateid_getter op_get_currentstateid;
62144 stateid_setter op_set_currentstateid;
62145-};
62146+} __do_const;
62147
62148 static struct nfsd4_operation nfsd4_ops[];
62149
62150diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62151index 18881f3..40e5bef 100644
62152--- a/fs/nfsd/nfs4xdr.c
62153+++ b/fs/nfsd/nfs4xdr.c
62154@@ -1530,7 +1530,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62155
62156 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62157
62158-static nfsd4_dec nfsd4_dec_ops[] = {
62159+static const nfsd4_dec nfsd4_dec_ops[] = {
62160 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62161 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62162 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62163diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62164index f8f060f..c4ba09a 100644
62165--- a/fs/nfsd/nfscache.c
62166+++ b/fs/nfsd/nfscache.c
62167@@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62168 {
62169 struct svc_cacherep *rp = rqstp->rq_cacherep;
62170 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62171- int len;
62172+ long len;
62173 size_t bufsize = 0;
62174
62175 if (!rp)
62176 return;
62177
62178- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62179- len >>= 2;
62180+ if (statp) {
62181+ len = (char*)statp - (char*)resv->iov_base;
62182+ len = resv->iov_len - len;
62183+ len >>= 2;
62184+ }
62185
62186 /* Don't cache excessive amounts of data and XDR failures */
62187 if (!statp || len > (256 >> 2)) {
62188diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62189index 16f0673..1c2c30ab 100644
62190--- a/fs/nfsd/vfs.c
62191+++ b/fs/nfsd/vfs.c
62192@@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62193 } else {
62194 oldfs = get_fs();
62195 set_fs(KERNEL_DS);
62196- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62197+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62198 set_fs(oldfs);
62199 }
62200
62201@@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62202
62203 /* Write the data. */
62204 oldfs = get_fs(); set_fs(KERNEL_DS);
62205- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62206+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62207 set_fs(oldfs);
62208 if (host_err < 0)
62209 goto out_nfserr;
62210@@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62211 */
62212
62213 oldfs = get_fs(); set_fs(KERNEL_DS);
62214- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62215+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62216 set_fs(oldfs);
62217
62218 if (host_err < 0)
62219diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62220index 52ccd34..43a53b1 100644
62221--- a/fs/nls/nls_base.c
62222+++ b/fs/nls/nls_base.c
62223@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62224
62225 int __register_nls(struct nls_table *nls, struct module *owner)
62226 {
62227- struct nls_table ** tmp = &tables;
62228+ struct nls_table *tmp = tables;
62229
62230 if (nls->next)
62231 return -EBUSY;
62232
62233- nls->owner = owner;
62234+ pax_open_kernel();
62235+ *(void **)&nls->owner = owner;
62236+ pax_close_kernel();
62237 spin_lock(&nls_lock);
62238- while (*tmp) {
62239- if (nls == *tmp) {
62240+ while (tmp) {
62241+ if (nls == tmp) {
62242 spin_unlock(&nls_lock);
62243 return -EBUSY;
62244 }
62245- tmp = &(*tmp)->next;
62246+ tmp = tmp->next;
62247 }
62248- nls->next = tables;
62249+ pax_open_kernel();
62250+ *(struct nls_table **)&nls->next = tables;
62251+ pax_close_kernel();
62252 tables = nls;
62253 spin_unlock(&nls_lock);
62254 return 0;
62255@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62256
62257 int unregister_nls(struct nls_table * nls)
62258 {
62259- struct nls_table ** tmp = &tables;
62260+ struct nls_table * const * tmp = &tables;
62261
62262 spin_lock(&nls_lock);
62263 while (*tmp) {
62264 if (nls == *tmp) {
62265- *tmp = nls->next;
62266+ pax_open_kernel();
62267+ *(struct nls_table **)tmp = nls->next;
62268+ pax_close_kernel();
62269 spin_unlock(&nls_lock);
62270 return 0;
62271 }
62272diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62273index 162b3f1..6076a7c 100644
62274--- a/fs/nls/nls_euc-jp.c
62275+++ b/fs/nls/nls_euc-jp.c
62276@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62277 p_nls = load_nls("cp932");
62278
62279 if (p_nls) {
62280- table.charset2upper = p_nls->charset2upper;
62281- table.charset2lower = p_nls->charset2lower;
62282+ pax_open_kernel();
62283+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62284+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62285+ pax_close_kernel();
62286 return register_nls(&table);
62287 }
62288
62289diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62290index a80a741..7b96e1b 100644
62291--- a/fs/nls/nls_koi8-ru.c
62292+++ b/fs/nls/nls_koi8-ru.c
62293@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62294 p_nls = load_nls("koi8-u");
62295
62296 if (p_nls) {
62297- table.charset2upper = p_nls->charset2upper;
62298- table.charset2lower = p_nls->charset2lower;
62299+ pax_open_kernel();
62300+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62301+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62302+ pax_close_kernel();
62303 return register_nls(&table);
62304 }
62305
62306diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62307index 732648b..d3b017f 100644
62308--- a/fs/notify/fanotify/fanotify_user.c
62309+++ b/fs/notify/fanotify/fanotify_user.c
62310@@ -203,8 +203,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62311
62312 fd = fanotify_event_metadata.fd;
62313 ret = -EFAULT;
62314- if (copy_to_user(buf, &fanotify_event_metadata,
62315- fanotify_event_metadata.event_len))
62316+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62317+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62318 goto out_close_fd;
62319
62320 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62321diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62322index 1e58402..bb2d6f4 100644
62323--- a/fs/notify/notification.c
62324+++ b/fs/notify/notification.c
62325@@ -48,7 +48,7 @@
62326 #include <linux/fsnotify_backend.h>
62327 #include "fsnotify.h"
62328
62329-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62330+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62331
62332 /**
62333 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62334@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62335 */
62336 u32 fsnotify_get_cookie(void)
62337 {
62338- return atomic_inc_return(&fsnotify_sync_cookie);
62339+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62340 }
62341 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62342
62343diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62344index 9e38daf..5727cae 100644
62345--- a/fs/ntfs/dir.c
62346+++ b/fs/ntfs/dir.c
62347@@ -1310,7 +1310,7 @@ find_next_index_buffer:
62348 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62349 ~(s64)(ndir->itype.index.block_size - 1)));
62350 /* Bounds checks. */
62351- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62352+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62353 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62354 "inode 0x%lx or driver bug.", vdir->i_ino);
62355 goto err_out;
62356diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62357index db9bd8a..8338fb6 100644
62358--- a/fs/ntfs/file.c
62359+++ b/fs/ntfs/file.c
62360@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62361 char *addr;
62362 size_t total = 0;
62363 unsigned len;
62364- int left;
62365+ unsigned left;
62366
62367 do {
62368 len = PAGE_CACHE_SIZE - ofs;
62369diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62370index 9de2491..3306095 100644
62371--- a/fs/ntfs/super.c
62372+++ b/fs/ntfs/super.c
62373@@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62374 if (!silent)
62375 ntfs_error(sb, "Primary boot sector is invalid.");
62376 } else if (!silent)
62377- ntfs_error(sb, read_err_str, "primary");
62378+ ntfs_error(sb, read_err_str, "%s", "primary");
62379 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62380 if (bh_primary)
62381 brelse(bh_primary);
62382@@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62383 goto hotfix_primary_boot_sector;
62384 brelse(bh_backup);
62385 } else if (!silent)
62386- ntfs_error(sb, read_err_str, "backup");
62387+ ntfs_error(sb, read_err_str, "%s", "backup");
62388 /* Try to read NT3.51- backup boot sector. */
62389 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62390 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62391@@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62392 "sector.");
62393 brelse(bh_backup);
62394 } else if (!silent)
62395- ntfs_error(sb, read_err_str, "backup");
62396+ ntfs_error(sb, read_err_str, "%s", "backup");
62397 /* We failed. Cleanup and return. */
62398 if (bh_primary)
62399 brelse(bh_primary);
62400diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62401index 0440134..d52c93a 100644
62402--- a/fs/ocfs2/localalloc.c
62403+++ b/fs/ocfs2/localalloc.c
62404@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62405 goto bail;
62406 }
62407
62408- atomic_inc(&osb->alloc_stats.moves);
62409+ atomic_inc_unchecked(&osb->alloc_stats.moves);
62410
62411 bail:
62412 if (handle)
62413diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62414index 8d64a97..c37665d 100644
62415--- a/fs/ocfs2/ocfs2.h
62416+++ b/fs/ocfs2/ocfs2.h
62417@@ -236,11 +236,11 @@ enum ocfs2_vol_state
62418
62419 struct ocfs2_alloc_stats
62420 {
62421- atomic_t moves;
62422- atomic_t local_data;
62423- atomic_t bitmap_data;
62424- atomic_t bg_allocs;
62425- atomic_t bg_extends;
62426+ atomic_unchecked_t moves;
62427+ atomic_unchecked_t local_data;
62428+ atomic_unchecked_t bitmap_data;
62429+ atomic_unchecked_t bg_allocs;
62430+ atomic_unchecked_t bg_extends;
62431 };
62432
62433 enum ocfs2_local_alloc_state
62434diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62435index 0cb889a..6a26b24 100644
62436--- a/fs/ocfs2/suballoc.c
62437+++ b/fs/ocfs2/suballoc.c
62438@@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62439 mlog_errno(status);
62440 goto bail;
62441 }
62442- atomic_inc(&osb->alloc_stats.bg_extends);
62443+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62444
62445 /* You should never ask for this much metadata */
62446 BUG_ON(bits_wanted >
62447@@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62448 mlog_errno(status);
62449 goto bail;
62450 }
62451- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62452+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62453
62454 *suballoc_loc = res.sr_bg_blkno;
62455 *suballoc_bit_start = res.sr_bit_offset;
62456@@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62457 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62458 res->sr_bits);
62459
62460- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62461+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62462
62463 BUG_ON(res->sr_bits != 1);
62464
62465@@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62466 mlog_errno(status);
62467 goto bail;
62468 }
62469- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62470+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62471
62472 BUG_ON(res.sr_bits != 1);
62473
62474@@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62475 cluster_start,
62476 num_clusters);
62477 if (!status)
62478- atomic_inc(&osb->alloc_stats.local_data);
62479+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
62480 } else {
62481 if (min_clusters > (osb->bitmap_cpg - 1)) {
62482 /* The only paths asking for contiguousness
62483@@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62484 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62485 res.sr_bg_blkno,
62486 res.sr_bit_offset);
62487- atomic_inc(&osb->alloc_stats.bitmap_data);
62488+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62489 *num_clusters = res.sr_bits;
62490 }
62491 }
62492diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62493index a7cdd56..c583144 100644
62494--- a/fs/ocfs2/super.c
62495+++ b/fs/ocfs2/super.c
62496@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62497 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62498 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62499 "Stats",
62500- atomic_read(&osb->alloc_stats.bitmap_data),
62501- atomic_read(&osb->alloc_stats.local_data),
62502- atomic_read(&osb->alloc_stats.bg_allocs),
62503- atomic_read(&osb->alloc_stats.moves),
62504- atomic_read(&osb->alloc_stats.bg_extends));
62505+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62506+ atomic_read_unchecked(&osb->alloc_stats.local_data),
62507+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62508+ atomic_read_unchecked(&osb->alloc_stats.moves),
62509+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62510
62511 out += snprintf(buf + out, len - out,
62512 "%10s => State: %u Descriptor: %llu Size: %u bits "
62513@@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62514
62515 mutex_init(&osb->system_file_mutex);
62516
62517- atomic_set(&osb->alloc_stats.moves, 0);
62518- atomic_set(&osb->alloc_stats.local_data, 0);
62519- atomic_set(&osb->alloc_stats.bitmap_data, 0);
62520- atomic_set(&osb->alloc_stats.bg_allocs, 0);
62521- atomic_set(&osb->alloc_stats.bg_extends, 0);
62522+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62523+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62524+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62525+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62526+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62527
62528 /* Copy the blockcheck stats from the superblock probe */
62529 osb->osb_ecc_stats = *stats;
62530diff --git a/fs/open.c b/fs/open.c
62531index 9d64679..75f925c 100644
62532--- a/fs/open.c
62533+++ b/fs/open.c
62534@@ -32,6 +32,8 @@
62535 #include <linux/dnotify.h>
62536 #include <linux/compat.h>
62537
62538+#define CREATE_TRACE_POINTS
62539+#include <trace/events/fs.h>
62540 #include "internal.h"
62541
62542 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62543@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62544 error = locks_verify_truncate(inode, NULL, length);
62545 if (!error)
62546 error = security_path_truncate(path);
62547+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62548+ error = -EACCES;
62549 if (!error)
62550 error = do_truncate(path->dentry, length, 0, NULL);
62551
62552@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62553 error = locks_verify_truncate(inode, f.file, length);
62554 if (!error)
62555 error = security_path_truncate(&f.file->f_path);
62556+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62557+ error = -EACCES;
62558 if (!error)
62559 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62560 sb_end_write(inode->i_sb);
62561@@ -381,6 +387,9 @@ retry:
62562 if (__mnt_is_readonly(path.mnt))
62563 res = -EROFS;
62564
62565+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62566+ res = -EACCES;
62567+
62568 out_path_release:
62569 path_put(&path);
62570 if (retry_estale(res, lookup_flags)) {
62571@@ -412,6 +421,8 @@ retry:
62572 if (error)
62573 goto dput_and_out;
62574
62575+ gr_log_chdir(path.dentry, path.mnt);
62576+
62577 set_fs_pwd(current->fs, &path);
62578
62579 dput_and_out:
62580@@ -441,6 +452,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62581 goto out_putf;
62582
62583 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62584+
62585+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62586+ error = -EPERM;
62587+
62588+ if (!error)
62589+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62590+
62591 if (!error)
62592 set_fs_pwd(current->fs, &f.file->f_path);
62593 out_putf:
62594@@ -470,7 +488,13 @@ retry:
62595 if (error)
62596 goto dput_and_out;
62597
62598+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62599+ goto dput_and_out;
62600+
62601 set_fs_root(current->fs, &path);
62602+
62603+ gr_handle_chroot_chdir(&path);
62604+
62605 error = 0;
62606 dput_and_out:
62607 path_put(&path);
62608@@ -494,6 +518,16 @@ static int chmod_common(struct path *path, umode_t mode)
62609 return error;
62610 retry_deleg:
62611 mutex_lock(&inode->i_mutex);
62612+
62613+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62614+ error = -EACCES;
62615+ goto out_unlock;
62616+ }
62617+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62618+ error = -EACCES;
62619+ goto out_unlock;
62620+ }
62621+
62622 error = security_path_chmod(path, mode);
62623 if (error)
62624 goto out_unlock;
62625@@ -559,6 +593,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62626 uid = make_kuid(current_user_ns(), user);
62627 gid = make_kgid(current_user_ns(), group);
62628
62629+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
62630+ return -EACCES;
62631+
62632 newattrs.ia_valid = ATTR_CTIME;
62633 if (user != (uid_t) -1) {
62634 if (!uid_valid(uid))
62635@@ -978,6 +1015,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62636 } else {
62637 fsnotify_open(f);
62638 fd_install(fd, f);
62639+ trace_do_sys_open(tmp->name, flags, mode);
62640 }
62641 }
62642 putname(tmp);
62643diff --git a/fs/pipe.c b/fs/pipe.c
62644index 034bffa..6c6b522 100644
62645--- a/fs/pipe.c
62646+++ b/fs/pipe.c
62647@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62648
62649 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62650 {
62651- if (pipe->files)
62652+ if (atomic_read(&pipe->files))
62653 mutex_lock_nested(&pipe->mutex, subclass);
62654 }
62655
62656@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62657
62658 void pipe_unlock(struct pipe_inode_info *pipe)
62659 {
62660- if (pipe->files)
62661+ if (atomic_read(&pipe->files))
62662 mutex_unlock(&pipe->mutex);
62663 }
62664 EXPORT_SYMBOL(pipe_unlock);
62665@@ -342,9 +342,9 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
62666 }
62667 if (bufs) /* More to do? */
62668 continue;
62669- if (!pipe->writers)
62670+ if (!atomic_read(&pipe->writers))
62671 break;
62672- if (!pipe->waiting_writers) {
62673+ if (!atomic_read(&pipe->waiting_writers)) {
62674 /* syscall merging: Usually we must not sleep
62675 * if O_NONBLOCK is set, or if we got some data.
62676 * But if a writer sleeps in kernel space, then
62677@@ -406,7 +406,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62678 ret = 0;
62679 __pipe_lock(pipe);
62680
62681- if (!pipe->readers) {
62682+ if (!atomic_read(&pipe->readers)) {
62683 send_sig(SIGPIPE, current, 0);
62684 ret = -EPIPE;
62685 goto out;
62686@@ -461,7 +461,7 @@ redo1:
62687 for (;;) {
62688 int bufs;
62689
62690- if (!pipe->readers) {
62691+ if (!atomic_read(&pipe->readers)) {
62692 send_sig(SIGPIPE, current, 0);
62693 if (!ret)
62694 ret = -EPIPE;
62695@@ -552,9 +552,9 @@ redo2:
62696 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62697 do_wakeup = 0;
62698 }
62699- pipe->waiting_writers++;
62700+ atomic_inc(&pipe->waiting_writers);
62701 pipe_wait(pipe);
62702- pipe->waiting_writers--;
62703+ atomic_dec(&pipe->waiting_writers);
62704 }
62705 out:
62706 __pipe_unlock(pipe);
62707@@ -609,7 +609,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62708 mask = 0;
62709 if (filp->f_mode & FMODE_READ) {
62710 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62711- if (!pipe->writers && filp->f_version != pipe->w_counter)
62712+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62713 mask |= POLLHUP;
62714 }
62715
62716@@ -619,7 +619,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62717 * Most Unices do not set POLLERR for FIFOs but on Linux they
62718 * behave exactly like pipes for poll().
62719 */
62720- if (!pipe->readers)
62721+ if (!atomic_read(&pipe->readers))
62722 mask |= POLLERR;
62723 }
62724
62725@@ -631,7 +631,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62726 int kill = 0;
62727
62728 spin_lock(&inode->i_lock);
62729- if (!--pipe->files) {
62730+ if (atomic_dec_and_test(&pipe->files)) {
62731 inode->i_pipe = NULL;
62732 kill = 1;
62733 }
62734@@ -648,11 +648,11 @@ pipe_release(struct inode *inode, struct file *file)
62735
62736 __pipe_lock(pipe);
62737 if (file->f_mode & FMODE_READ)
62738- pipe->readers--;
62739+ atomic_dec(&pipe->readers);
62740 if (file->f_mode & FMODE_WRITE)
62741- pipe->writers--;
62742+ atomic_dec(&pipe->writers);
62743
62744- if (pipe->readers || pipe->writers) {
62745+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62746 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62747 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62748 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62749@@ -717,7 +717,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62750 kfree(pipe);
62751 }
62752
62753-static struct vfsmount *pipe_mnt __read_mostly;
62754+struct vfsmount *pipe_mnt __read_mostly;
62755
62756 /*
62757 * pipefs_dname() is called from d_path().
62758@@ -747,8 +747,9 @@ static struct inode * get_pipe_inode(void)
62759 goto fail_iput;
62760
62761 inode->i_pipe = pipe;
62762- pipe->files = 2;
62763- pipe->readers = pipe->writers = 1;
62764+ atomic_set(&pipe->files, 2);
62765+ atomic_set(&pipe->readers, 1);
62766+ atomic_set(&pipe->writers, 1);
62767 inode->i_fop = &pipefifo_fops;
62768
62769 /*
62770@@ -927,17 +928,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62771 spin_lock(&inode->i_lock);
62772 if (inode->i_pipe) {
62773 pipe = inode->i_pipe;
62774- pipe->files++;
62775+ atomic_inc(&pipe->files);
62776 spin_unlock(&inode->i_lock);
62777 } else {
62778 spin_unlock(&inode->i_lock);
62779 pipe = alloc_pipe_info();
62780 if (!pipe)
62781 return -ENOMEM;
62782- pipe->files = 1;
62783+ atomic_set(&pipe->files, 1);
62784 spin_lock(&inode->i_lock);
62785 if (unlikely(inode->i_pipe)) {
62786- inode->i_pipe->files++;
62787+ atomic_inc(&inode->i_pipe->files);
62788 spin_unlock(&inode->i_lock);
62789 free_pipe_info(pipe);
62790 pipe = inode->i_pipe;
62791@@ -962,10 +963,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62792 * opened, even when there is no process writing the FIFO.
62793 */
62794 pipe->r_counter++;
62795- if (pipe->readers++ == 0)
62796+ if (atomic_inc_return(&pipe->readers) == 1)
62797 wake_up_partner(pipe);
62798
62799- if (!is_pipe && !pipe->writers) {
62800+ if (!is_pipe && !atomic_read(&pipe->writers)) {
62801 if ((filp->f_flags & O_NONBLOCK)) {
62802 /* suppress POLLHUP until we have
62803 * seen a writer */
62804@@ -984,14 +985,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62805 * errno=ENXIO when there is no process reading the FIFO.
62806 */
62807 ret = -ENXIO;
62808- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62809+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62810 goto err;
62811
62812 pipe->w_counter++;
62813- if (!pipe->writers++)
62814+ if (atomic_inc_return(&pipe->writers) == 1)
62815 wake_up_partner(pipe);
62816
62817- if (!is_pipe && !pipe->readers) {
62818+ if (!is_pipe && !atomic_read(&pipe->readers)) {
62819 if (wait_for_partner(pipe, &pipe->r_counter))
62820 goto err_wr;
62821 }
62822@@ -1005,11 +1006,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62823 * the process can at least talk to itself.
62824 */
62825
62826- pipe->readers++;
62827- pipe->writers++;
62828+ atomic_inc(&pipe->readers);
62829+ atomic_inc(&pipe->writers);
62830 pipe->r_counter++;
62831 pipe->w_counter++;
62832- if (pipe->readers == 1 || pipe->writers == 1)
62833+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62834 wake_up_partner(pipe);
62835 break;
62836
62837@@ -1023,13 +1024,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62838 return 0;
62839
62840 err_rd:
62841- if (!--pipe->readers)
62842+ if (atomic_dec_and_test(&pipe->readers))
62843 wake_up_interruptible(&pipe->wait);
62844 ret = -ERESTARTSYS;
62845 goto err;
62846
62847 err_wr:
62848- if (!--pipe->writers)
62849+ if (atomic_dec_and_test(&pipe->writers))
62850 wake_up_interruptible(&pipe->wait);
62851 ret = -ERESTARTSYS;
62852 goto err;
62853diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62854index 0855f77..6787d50 100644
62855--- a/fs/posix_acl.c
62856+++ b/fs/posix_acl.c
62857@@ -20,6 +20,7 @@
62858 #include <linux/xattr.h>
62859 #include <linux/export.h>
62860 #include <linux/user_namespace.h>
62861+#include <linux/grsecurity.h>
62862
62863 struct posix_acl **acl_by_type(struct inode *inode, int type)
62864 {
62865@@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62866 }
62867 }
62868 if (mode_p)
62869- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62870+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62871 return not_equiv;
62872 }
62873 EXPORT_SYMBOL(posix_acl_equiv_mode);
62874@@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62875 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62876 }
62877
62878- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62879+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62880 return not_equiv;
62881 }
62882
62883@@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62884 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
62885 int err = -ENOMEM;
62886 if (clone) {
62887+ *mode_p &= ~gr_acl_umask();
62888+
62889 err = posix_acl_create_masq(clone, mode_p);
62890 if (err < 0) {
62891 posix_acl_release(clone);
62892@@ -659,11 +662,12 @@ struct posix_acl *
62893 posix_acl_from_xattr(struct user_namespace *user_ns,
62894 const void *value, size_t size)
62895 {
62896- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
62897- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
62898+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
62899+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
62900 int count;
62901 struct posix_acl *acl;
62902 struct posix_acl_entry *acl_e;
62903+ umode_t umask = gr_acl_umask();
62904
62905 if (!value)
62906 return NULL;
62907@@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62908
62909 switch(acl_e->e_tag) {
62910 case ACL_USER_OBJ:
62911+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62912+ break;
62913 case ACL_GROUP_OBJ:
62914 case ACL_MASK:
62915+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
62916+ break;
62917 case ACL_OTHER:
62918+ acl_e->e_perm &= ~(umask & S_IRWXO);
62919 break;
62920
62921 case ACL_USER:
62922+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62923 acl_e->e_uid =
62924 make_kuid(user_ns,
62925 le32_to_cpu(entry->e_id));
62926@@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62927 goto fail;
62928 break;
62929 case ACL_GROUP:
62930+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
62931 acl_e->e_gid =
62932 make_kgid(user_ns,
62933 le32_to_cpu(entry->e_id));
62934diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
62935index 2183fcf..3c32a98 100644
62936--- a/fs/proc/Kconfig
62937+++ b/fs/proc/Kconfig
62938@@ -30,7 +30,7 @@ config PROC_FS
62939
62940 config PROC_KCORE
62941 bool "/proc/kcore support" if !ARM
62942- depends on PROC_FS && MMU
62943+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
62944 help
62945 Provides a virtual ELF core file of the live kernel. This can
62946 be read with gdb and other ELF tools. No modifications can be
62947@@ -38,8 +38,8 @@ config PROC_KCORE
62948
62949 config PROC_VMCORE
62950 bool "/proc/vmcore support"
62951- depends on PROC_FS && CRASH_DUMP
62952- default y
62953+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
62954+ default n
62955 help
62956 Exports the dump image of crashed kernel in ELF format.
62957
62958@@ -63,8 +63,8 @@ config PROC_SYSCTL
62959 limited in memory.
62960
62961 config PROC_PAGE_MONITOR
62962- default y
62963- depends on PROC_FS && MMU
62964+ default n
62965+ depends on PROC_FS && MMU && !GRKERNSEC
62966 bool "Enable /proc page monitoring" if EXPERT
62967 help
62968 Various /proc files exist to monitor process memory utilization:
62969diff --git a/fs/proc/array.c b/fs/proc/array.c
62970index 64db2bc..a8185d6 100644
62971--- a/fs/proc/array.c
62972+++ b/fs/proc/array.c
62973@@ -60,6 +60,7 @@
62974 #include <linux/tty.h>
62975 #include <linux/string.h>
62976 #include <linux/mman.h>
62977+#include <linux/grsecurity.h>
62978 #include <linux/proc_fs.h>
62979 #include <linux/ioport.h>
62980 #include <linux/uaccess.h>
62981@@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
62982 seq_putc(m, '\n');
62983 }
62984
62985+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62986+static inline void task_pax(struct seq_file *m, struct task_struct *p)
62987+{
62988+ if (p->mm)
62989+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
62990+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
62991+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
62992+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
62993+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
62994+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
62995+ else
62996+ seq_printf(m, "PaX:\t-----\n");
62997+}
62998+#endif
62999+
63000 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63001 struct pid *pid, struct task_struct *task)
63002 {
63003@@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63004 task_cpus_allowed(m, task);
63005 cpuset_task_status_allowed(m, task);
63006 task_context_switch_counts(m, task);
63007+
63008+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63009+ task_pax(m, task);
63010+#endif
63011+
63012+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63013+ task_grsec_rbac(m, task);
63014+#endif
63015+
63016 return 0;
63017 }
63018
63019+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63020+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63021+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63022+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63023+#endif
63024+
63025 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63026 struct pid *pid, struct task_struct *task, int whole)
63027 {
63028@@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63029 char tcomm[sizeof(task->comm)];
63030 unsigned long flags;
63031
63032+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63033+ if (current->exec_id != m->exec_id) {
63034+ gr_log_badprocpid("stat");
63035+ return 0;
63036+ }
63037+#endif
63038+
63039 state = *get_task_state(task);
63040 vsize = eip = esp = 0;
63041 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63042@@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63043 gtime = task_gtime(task);
63044 }
63045
63046+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63047+ if (PAX_RAND_FLAGS(mm)) {
63048+ eip = 0;
63049+ esp = 0;
63050+ wchan = 0;
63051+ }
63052+#endif
63053+#ifdef CONFIG_GRKERNSEC_HIDESYM
63054+ wchan = 0;
63055+ eip =0;
63056+ esp =0;
63057+#endif
63058+
63059 /* scale priority and nice values from timeslices to -20..20 */
63060 /* to make it look like a "normal" Unix priority/nice value */
63061 priority = task_prio(task);
63062@@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63063 seq_put_decimal_ull(m, ' ', vsize);
63064 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63065 seq_put_decimal_ull(m, ' ', rsslim);
63066+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63067+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63068+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63069+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63070+#else
63071 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63072 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63073 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63074+#endif
63075 seq_put_decimal_ull(m, ' ', esp);
63076 seq_put_decimal_ull(m, ' ', eip);
63077 /* The signal information here is obsolete.
63078@@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63079 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63080 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63081
63082- if (mm && permitted) {
63083+ if (mm && permitted
63084+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63085+ && !PAX_RAND_FLAGS(mm)
63086+#endif
63087+ ) {
63088 seq_put_decimal_ull(m, ' ', mm->start_data);
63089 seq_put_decimal_ull(m, ' ', mm->end_data);
63090 seq_put_decimal_ull(m, ' ', mm->start_brk);
63091@@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63092 struct pid *pid, struct task_struct *task)
63093 {
63094 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63095- struct mm_struct *mm = get_task_mm(task);
63096+ struct mm_struct *mm;
63097
63098+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63099+ if (current->exec_id != m->exec_id) {
63100+ gr_log_badprocpid("statm");
63101+ return 0;
63102+ }
63103+#endif
63104+ mm = get_task_mm(task);
63105 if (mm) {
63106 size = task_statm(mm, &shared, &text, &data, &resident);
63107 mmput(mm);
63108@@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63109 return 0;
63110 }
63111
63112+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63113+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63114+{
63115+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63116+}
63117+#endif
63118+
63119 #ifdef CONFIG_CHECKPOINT_RESTORE
63120 static struct pid *
63121 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63122diff --git a/fs/proc/base.c b/fs/proc/base.c
63123index 2d696b0..b9da447 100644
63124--- a/fs/proc/base.c
63125+++ b/fs/proc/base.c
63126@@ -113,6 +113,14 @@ struct pid_entry {
63127 union proc_op op;
63128 };
63129
63130+struct getdents_callback {
63131+ struct linux_dirent __user * current_dir;
63132+ struct linux_dirent __user * previous;
63133+ struct file * file;
63134+ int count;
63135+ int error;
63136+};
63137+
63138 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63139 .name = (NAME), \
63140 .len = sizeof(NAME) - 1, \
63141@@ -205,12 +213,28 @@ static int proc_pid_cmdline(struct task_struct *task, char *buffer)
63142 return get_cmdline(task, buffer, PAGE_SIZE);
63143 }
63144
63145+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63146+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63147+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63148+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63149+#endif
63150+
63151 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63152 {
63153 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63154 int res = PTR_ERR(mm);
63155 if (mm && !IS_ERR(mm)) {
63156 unsigned int nwords = 0;
63157+
63158+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63159+ /* allow if we're currently ptracing this task */
63160+ if (PAX_RAND_FLAGS(mm) &&
63161+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63162+ mmput(mm);
63163+ return 0;
63164+ }
63165+#endif
63166+
63167 do {
63168 nwords += 2;
63169 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63170@@ -224,7 +248,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63171 }
63172
63173
63174-#ifdef CONFIG_KALLSYMS
63175+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63176 /*
63177 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63178 * Returns the resolved symbol. If that fails, simply return the address.
63179@@ -263,7 +287,7 @@ static void unlock_trace(struct task_struct *task)
63180 mutex_unlock(&task->signal->cred_guard_mutex);
63181 }
63182
63183-#ifdef CONFIG_STACKTRACE
63184+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63185
63186 #define MAX_STACK_TRACE_DEPTH 64
63187
63188@@ -486,7 +510,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63189 return count;
63190 }
63191
63192-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63193+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63194 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63195 {
63196 long nr;
63197@@ -515,7 +539,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63198 /************************************************************************/
63199
63200 /* permission checks */
63201-static int proc_fd_access_allowed(struct inode *inode)
63202+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63203 {
63204 struct task_struct *task;
63205 int allowed = 0;
63206@@ -525,7 +549,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63207 */
63208 task = get_proc_task(inode);
63209 if (task) {
63210- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63211+ if (log)
63212+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63213+ else
63214+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63215 put_task_struct(task);
63216 }
63217 return allowed;
63218@@ -556,10 +583,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63219 struct task_struct *task,
63220 int hide_pid_min)
63221 {
63222+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63223+ return false;
63224+
63225+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63226+ rcu_read_lock();
63227+ {
63228+ const struct cred *tmpcred = current_cred();
63229+ const struct cred *cred = __task_cred(task);
63230+
63231+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63232+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63233+ || in_group_p(grsec_proc_gid)
63234+#endif
63235+ ) {
63236+ rcu_read_unlock();
63237+ return true;
63238+ }
63239+ }
63240+ rcu_read_unlock();
63241+
63242+ if (!pid->hide_pid)
63243+ return false;
63244+#endif
63245+
63246 if (pid->hide_pid < hide_pid_min)
63247 return true;
63248 if (in_group_p(pid->pid_gid))
63249 return true;
63250+
63251 return ptrace_may_access(task, PTRACE_MODE_READ);
63252 }
63253
63254@@ -577,7 +629,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63255 put_task_struct(task);
63256
63257 if (!has_perms) {
63258+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63259+ {
63260+#else
63261 if (pid->hide_pid == 2) {
63262+#endif
63263 /*
63264 * Let's make getdents(), stat(), and open()
63265 * consistent with each other. If a process
63266@@ -675,6 +731,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63267 if (!task)
63268 return -ESRCH;
63269
63270+ if (gr_acl_handle_procpidmem(task)) {
63271+ put_task_struct(task);
63272+ return -EPERM;
63273+ }
63274+
63275 mm = mm_access(task, mode);
63276 put_task_struct(task);
63277
63278@@ -690,6 +751,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63279
63280 file->private_data = mm;
63281
63282+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63283+ file->f_version = current->exec_id;
63284+#endif
63285+
63286 return 0;
63287 }
63288
63289@@ -711,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63290 ssize_t copied;
63291 char *page;
63292
63293+#ifdef CONFIG_GRKERNSEC
63294+ if (write)
63295+ return -EPERM;
63296+#endif
63297+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63298+ if (file->f_version != current->exec_id) {
63299+ gr_log_badprocpid("mem");
63300+ return 0;
63301+ }
63302+#endif
63303+
63304 if (!mm)
63305 return 0;
63306
63307@@ -723,7 +799,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63308 goto free;
63309
63310 while (count > 0) {
63311- int this_len = min_t(int, count, PAGE_SIZE);
63312+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63313
63314 if (write && copy_from_user(page, buf, this_len)) {
63315 copied = -EFAULT;
63316@@ -815,6 +891,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63317 if (!mm)
63318 return 0;
63319
63320+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63321+ if (file->f_version != current->exec_id) {
63322+ gr_log_badprocpid("environ");
63323+ return 0;
63324+ }
63325+#endif
63326+
63327 page = (char *)__get_free_page(GFP_TEMPORARY);
63328 if (!page)
63329 return -ENOMEM;
63330@@ -824,7 +907,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63331 goto free;
63332 while (count > 0) {
63333 size_t this_len, max_len;
63334- int retval;
63335+ ssize_t retval;
63336
63337 if (src >= (mm->env_end - mm->env_start))
63338 break;
63339@@ -1438,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63340 int error = -EACCES;
63341
63342 /* Are we allowed to snoop on the tasks file descriptors? */
63343- if (!proc_fd_access_allowed(inode))
63344+ if (!proc_fd_access_allowed(inode, 0))
63345 goto out;
63346
63347 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63348@@ -1482,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63349 struct path path;
63350
63351 /* Are we allowed to snoop on the tasks file descriptors? */
63352- if (!proc_fd_access_allowed(inode))
63353- goto out;
63354+ /* logging this is needed for learning on chromium to work properly,
63355+ but we don't want to flood the logs from 'ps' which does a readlink
63356+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63357+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
63358+ */
63359+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63360+ if (!proc_fd_access_allowed(inode,0))
63361+ goto out;
63362+ } else {
63363+ if (!proc_fd_access_allowed(inode,1))
63364+ goto out;
63365+ }
63366
63367 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63368 if (error)
63369@@ -1533,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63370 rcu_read_lock();
63371 cred = __task_cred(task);
63372 inode->i_uid = cred->euid;
63373+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63374+ inode->i_gid = grsec_proc_gid;
63375+#else
63376 inode->i_gid = cred->egid;
63377+#endif
63378 rcu_read_unlock();
63379 }
63380 security_task_to_inode(task, inode);
63381@@ -1569,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63382 return -ENOENT;
63383 }
63384 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63385+#ifdef CONFIG_GRKERNSEC_PROC_USER
63386+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63387+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63388+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63389+#endif
63390 task_dumpable(task)) {
63391 cred = __task_cred(task);
63392 stat->uid = cred->euid;
63393+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63394+ stat->gid = grsec_proc_gid;
63395+#else
63396 stat->gid = cred->egid;
63397+#endif
63398 }
63399 }
63400 rcu_read_unlock();
63401@@ -1610,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63402
63403 if (task) {
63404 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63405+#ifdef CONFIG_GRKERNSEC_PROC_USER
63406+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63407+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63408+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63409+#endif
63410 task_dumpable(task)) {
63411 rcu_read_lock();
63412 cred = __task_cred(task);
63413 inode->i_uid = cred->euid;
63414+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63415+ inode->i_gid = grsec_proc_gid;
63416+#else
63417 inode->i_gid = cred->egid;
63418+#endif
63419 rcu_read_unlock();
63420 } else {
63421 inode->i_uid = GLOBAL_ROOT_UID;
63422@@ -2149,6 +2264,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63423 if (!task)
63424 goto out_no_task;
63425
63426+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63427+ goto out;
63428+
63429 /*
63430 * Yes, it does not scale. And it should not. Don't add
63431 * new entries into /proc/<tgid>/ without very good reasons.
63432@@ -2179,6 +2297,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63433 if (!task)
63434 return -ENOENT;
63435
63436+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63437+ goto out;
63438+
63439 if (!dir_emit_dots(file, ctx))
63440 goto out;
63441
63442@@ -2568,7 +2689,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63443 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63444 #endif
63445 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63446-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63447+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63448 INF("syscall", S_IRUSR, proc_pid_syscall),
63449 #endif
63450 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63451@@ -2593,10 +2714,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63452 #ifdef CONFIG_SECURITY
63453 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63454 #endif
63455-#ifdef CONFIG_KALLSYMS
63456+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63457 INF("wchan", S_IRUGO, proc_pid_wchan),
63458 #endif
63459-#ifdef CONFIG_STACKTRACE
63460+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63461 ONE("stack", S_IRUSR, proc_pid_stack),
63462 #endif
63463 #ifdef CONFIG_SCHEDSTATS
63464@@ -2630,6 +2751,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63465 #ifdef CONFIG_HARDWALL
63466 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63467 #endif
63468+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63469+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63470+#endif
63471 #ifdef CONFIG_USER_NS
63472 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63473 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63474@@ -2760,7 +2884,14 @@ static int proc_pid_instantiate(struct inode *dir,
63475 if (!inode)
63476 goto out;
63477
63478+#ifdef CONFIG_GRKERNSEC_PROC_USER
63479+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63480+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63481+ inode->i_gid = grsec_proc_gid;
63482+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63483+#else
63484 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63485+#endif
63486 inode->i_op = &proc_tgid_base_inode_operations;
63487 inode->i_fop = &proc_tgid_base_operations;
63488 inode->i_flags|=S_IMMUTABLE;
63489@@ -2798,7 +2929,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63490 if (!task)
63491 goto out;
63492
63493+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63494+ goto out_put_task;
63495+
63496 result = proc_pid_instantiate(dir, dentry, task, NULL);
63497+out_put_task:
63498 put_task_struct(task);
63499 out:
63500 return ERR_PTR(result);
63501@@ -2904,7 +3039,7 @@ static const struct pid_entry tid_base_stuff[] = {
63502 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63503 #endif
63504 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63505-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63506+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63507 INF("syscall", S_IRUSR, proc_pid_syscall),
63508 #endif
63509 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63510@@ -2931,10 +3066,10 @@ static const struct pid_entry tid_base_stuff[] = {
63511 #ifdef CONFIG_SECURITY
63512 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63513 #endif
63514-#ifdef CONFIG_KALLSYMS
63515+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63516 INF("wchan", S_IRUGO, proc_pid_wchan),
63517 #endif
63518-#ifdef CONFIG_STACKTRACE
63519+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63520 ONE("stack", S_IRUSR, proc_pid_stack),
63521 #endif
63522 #ifdef CONFIG_SCHEDSTATS
63523diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63524index cbd82df..c0407d2 100644
63525--- a/fs/proc/cmdline.c
63526+++ b/fs/proc/cmdline.c
63527@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63528
63529 static int __init proc_cmdline_init(void)
63530 {
63531+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63532+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63533+#else
63534 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63535+#endif
63536 return 0;
63537 }
63538 fs_initcall(proc_cmdline_init);
63539diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63540index 50493ed..248166b 100644
63541--- a/fs/proc/devices.c
63542+++ b/fs/proc/devices.c
63543@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63544
63545 static int __init proc_devices_init(void)
63546 {
63547+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63548+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63549+#else
63550 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63551+#endif
63552 return 0;
63553 }
63554 fs_initcall(proc_devices_init);
63555diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63556index 0788d09..9cc1385 100644
63557--- a/fs/proc/fd.c
63558+++ b/fs/proc/fd.c
63559@@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
63560 if (!task)
63561 return -ENOENT;
63562
63563- files = get_files_struct(task);
63564+ if (!gr_acl_handle_procpidmem(task))
63565+ files = get_files_struct(task);
63566 put_task_struct(task);
63567
63568 if (files) {
63569@@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63570 */
63571 int proc_fd_permission(struct inode *inode, int mask)
63572 {
63573+ struct task_struct *task;
63574 int rv = generic_permission(inode, mask);
63575- if (rv == 0)
63576- return 0;
63577+
63578 if (task_tgid(current) == proc_pid(inode))
63579 rv = 0;
63580+
63581+ task = get_proc_task(inode);
63582+ if (task == NULL)
63583+ return rv;
63584+
63585+ if (gr_acl_handle_procpidmem(task))
63586+ rv = -EACCES;
63587+
63588+ put_task_struct(task);
63589+
63590 return rv;
63591 }
63592
63593diff --git a/fs/proc/generic.c b/fs/proc/generic.c
63594index b7f268e..3bea6b7 100644
63595--- a/fs/proc/generic.c
63596+++ b/fs/proc/generic.c
63597@@ -23,6 +23,7 @@
63598 #include <linux/bitops.h>
63599 #include <linux/spinlock.h>
63600 #include <linux/completion.h>
63601+#include <linux/grsecurity.h>
63602 #include <asm/uaccess.h>
63603
63604 #include "internal.h"
63605@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
63606 return proc_lookup_de(PDE(dir), dir, dentry);
63607 }
63608
63609+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
63610+ unsigned int flags)
63611+{
63612+ if (gr_proc_is_restricted())
63613+ return ERR_PTR(-EACCES);
63614+
63615+ return proc_lookup_de(PDE(dir), dir, dentry);
63616+}
63617+
63618 /*
63619 * This returns non-zero if at EOF, so that the /proc
63620 * root directory can use this and check if it should
63621@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
63622 return proc_readdir_de(PDE(inode), file, ctx);
63623 }
63624
63625+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
63626+{
63627+ struct inode *inode = file_inode(file);
63628+
63629+ if (gr_proc_is_restricted())
63630+ return -EACCES;
63631+
63632+ return proc_readdir_de(PDE(inode), file, ctx);
63633+}
63634+
63635 /*
63636 * These are the generic /proc directory operations. They
63637 * use the in-memory "struct proc_dir_entry" tree to parse
63638@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
63639 .iterate = proc_readdir,
63640 };
63641
63642+static const struct file_operations proc_dir_restricted_operations = {
63643+ .llseek = generic_file_llseek,
63644+ .read = generic_read_dir,
63645+ .iterate = proc_readdir_restrict,
63646+};
63647+
63648 /*
63649 * proc directories can do almost nothing..
63650 */
63651@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
63652 .setattr = proc_notify_change,
63653 };
63654
63655+static const struct inode_operations proc_dir_restricted_inode_operations = {
63656+ .lookup = proc_lookup_restrict,
63657+ .getattr = proc_getattr,
63658+ .setattr = proc_notify_change,
63659+};
63660+
63661 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
63662 {
63663 struct proc_dir_entry *tmp;
63664@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
63665 return ret;
63666
63667 if (S_ISDIR(dp->mode)) {
63668- dp->proc_fops = &proc_dir_operations;
63669- dp->proc_iops = &proc_dir_inode_operations;
63670+ if (dp->restricted) {
63671+ dp->proc_fops = &proc_dir_restricted_operations;
63672+ dp->proc_iops = &proc_dir_restricted_inode_operations;
63673+ } else {
63674+ dp->proc_fops = &proc_dir_operations;
63675+ dp->proc_iops = &proc_dir_inode_operations;
63676+ }
63677 dir->nlink++;
63678 } else if (S_ISLNK(dp->mode)) {
63679 dp->proc_iops = &proc_link_inode_operations;
63680@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
63681 }
63682 EXPORT_SYMBOL_GPL(proc_mkdir_data);
63683
63684+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
63685+ struct proc_dir_entry *parent, void *data)
63686+{
63687+ struct proc_dir_entry *ent;
63688+
63689+ if (mode == 0)
63690+ mode = S_IRUGO | S_IXUGO;
63691+
63692+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
63693+ if (ent) {
63694+ ent->data = data;
63695+ ent->restricted = 1;
63696+ if (proc_register(parent, ent) < 0) {
63697+ kfree(ent);
63698+ ent = NULL;
63699+ }
63700+ }
63701+ return ent;
63702+}
63703+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
63704+
63705 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
63706 struct proc_dir_entry *parent)
63707 {
63708@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
63709 }
63710 EXPORT_SYMBOL(proc_mkdir);
63711
63712+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
63713+ struct proc_dir_entry *parent)
63714+{
63715+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
63716+}
63717+EXPORT_SYMBOL(proc_mkdir_restrict);
63718+
63719 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
63720 struct proc_dir_entry *parent,
63721 const struct file_operations *proc_fops,
63722diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63723index 0adbc02..bee4d0b 100644
63724--- a/fs/proc/inode.c
63725+++ b/fs/proc/inode.c
63726@@ -23,11 +23,17 @@
63727 #include <linux/slab.h>
63728 #include <linux/mount.h>
63729 #include <linux/magic.h>
63730+#include <linux/grsecurity.h>
63731
63732 #include <asm/uaccess.h>
63733
63734 #include "internal.h"
63735
63736+#ifdef CONFIG_PROC_SYSCTL
63737+extern const struct inode_operations proc_sys_inode_operations;
63738+extern const struct inode_operations proc_sys_dir_operations;
63739+#endif
63740+
63741 static void proc_evict_inode(struct inode *inode)
63742 {
63743 struct proc_dir_entry *de;
63744@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63745 ns = PROC_I(inode)->ns.ns;
63746 if (ns_ops && ns)
63747 ns_ops->put(ns);
63748+
63749+#ifdef CONFIG_PROC_SYSCTL
63750+ if (inode->i_op == &proc_sys_inode_operations ||
63751+ inode->i_op == &proc_sys_dir_operations)
63752+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63753+#endif
63754+
63755 }
63756
63757 static struct kmem_cache * proc_inode_cachep;
63758@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63759 if (de->mode) {
63760 inode->i_mode = de->mode;
63761 inode->i_uid = de->uid;
63762+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63763+ inode->i_gid = grsec_proc_gid;
63764+#else
63765 inode->i_gid = de->gid;
63766+#endif
63767 }
63768 if (de->size)
63769 inode->i_size = de->size;
63770diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63771index 3ab6d14..b26174e 100644
63772--- a/fs/proc/internal.h
63773+++ b/fs/proc/internal.h
63774@@ -46,9 +46,10 @@ struct proc_dir_entry {
63775 struct completion *pde_unload_completion;
63776 struct list_head pde_openers; /* who did ->open, but not ->release */
63777 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63778+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
63779 u8 namelen;
63780 char name[];
63781-};
63782+} __randomize_layout;
63783
63784 union proc_op {
63785 int (*proc_get_link)(struct dentry *, struct path *);
63786@@ -67,7 +68,7 @@ struct proc_inode {
63787 struct ctl_table *sysctl_entry;
63788 struct proc_ns ns;
63789 struct inode vfs_inode;
63790-};
63791+} __randomize_layout;
63792
63793 /*
63794 * General functions
63795@@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63796 struct pid *, struct task_struct *);
63797 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63798 struct pid *, struct task_struct *);
63799+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63800+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63801+#endif
63802
63803 /*
63804 * base.c
63805@@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
63806 extern spinlock_t proc_subdir_lock;
63807
63808 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
63809+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
63810 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
63811 struct dentry *);
63812 extern int proc_readdir(struct file *, struct dir_context *);
63813+extern int proc_readdir_restrict(struct file *, struct dir_context *);
63814 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
63815
63816 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
63817diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63818index a352d57..cb94a5c 100644
63819--- a/fs/proc/interrupts.c
63820+++ b/fs/proc/interrupts.c
63821@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63822
63823 static int __init proc_interrupts_init(void)
63824 {
63825+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63826+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63827+#else
63828 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63829+#endif
63830 return 0;
63831 }
63832 fs_initcall(proc_interrupts_init);
63833diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63834index 39e6ef3..2f9cb5e 100644
63835--- a/fs/proc/kcore.c
63836+++ b/fs/proc/kcore.c
63837@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63838 * the addresses in the elf_phdr on our list.
63839 */
63840 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63841- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63842+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63843+ if (tsz > buflen)
63844 tsz = buflen;
63845-
63846+
63847 while (buflen) {
63848 struct kcore_list *m;
63849
63850@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63851 kfree(elf_buf);
63852 } else {
63853 if (kern_addr_valid(start)) {
63854- unsigned long n;
63855+ char *elf_buf;
63856+ mm_segment_t oldfs;
63857
63858- n = copy_to_user(buffer, (char *)start, tsz);
63859- /*
63860- * We cannot distinguish between fault on source
63861- * and fault on destination. When this happens
63862- * we clear too and hope it will trigger the
63863- * EFAULT again.
63864- */
63865- if (n) {
63866- if (clear_user(buffer + tsz - n,
63867- n))
63868+ elf_buf = kmalloc(tsz, GFP_KERNEL);
63869+ if (!elf_buf)
63870+ return -ENOMEM;
63871+ oldfs = get_fs();
63872+ set_fs(KERNEL_DS);
63873+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63874+ set_fs(oldfs);
63875+ if (copy_to_user(buffer, elf_buf, tsz)) {
63876+ kfree(elf_buf);
63877 return -EFAULT;
63878+ }
63879 }
63880+ set_fs(oldfs);
63881+ kfree(elf_buf);
63882 } else {
63883 if (clear_user(buffer, tsz))
63884 return -EFAULT;
63885@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63886
63887 static int open_kcore(struct inode *inode, struct file *filp)
63888 {
63889+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63890+ return -EPERM;
63891+#endif
63892 if (!capable(CAP_SYS_RAWIO))
63893 return -EPERM;
63894 if (kcore_need_update)
63895diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
63896index 7445af0..7c5113c 100644
63897--- a/fs/proc/meminfo.c
63898+++ b/fs/proc/meminfo.c
63899@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
63900 vmi.used >> 10,
63901 vmi.largest_chunk >> 10
63902 #ifdef CONFIG_MEMORY_FAILURE
63903- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63904+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63905 #endif
63906 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63907 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
63908diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
63909index d4a3574..b421ce9 100644
63910--- a/fs/proc/nommu.c
63911+++ b/fs/proc/nommu.c
63912@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
63913
63914 if (file) {
63915 seq_pad(m, ' ');
63916- seq_path(m, &file->f_path, "");
63917+ seq_path(m, &file->f_path, "\n\\");
63918 }
63919
63920 seq_putc(m, '\n');
63921diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
63922index 4677bb7..94067cd 100644
63923--- a/fs/proc/proc_net.c
63924+++ b/fs/proc/proc_net.c
63925@@ -23,6 +23,7 @@
63926 #include <linux/nsproxy.h>
63927 #include <net/net_namespace.h>
63928 #include <linux/seq_file.h>
63929+#include <linux/grsecurity.h>
63930
63931 #include "internal.h"
63932
63933@@ -36,6 +37,8 @@ static struct net *get_proc_net(const struct inode *inode)
63934 return maybe_get_net(PDE_NET(PDE(inode)));
63935 }
63936
63937+extern const struct seq_operations dev_seq_ops;
63938+
63939 int seq_open_net(struct inode *ino, struct file *f,
63940 const struct seq_operations *ops, int size)
63941 {
63942@@ -44,6 +47,10 @@ int seq_open_net(struct inode *ino, struct file *f,
63943
63944 BUG_ON(size < sizeof(*p));
63945
63946+ /* only permit access to /proc/net/dev */
63947+ if (ops != &dev_seq_ops && gr_proc_is_restricted())
63948+ return -EACCES;
63949+
63950 net = get_proc_net(ino);
63951 if (net == NULL)
63952 return -ENXIO;
63953@@ -66,6 +73,9 @@ int single_open_net(struct inode *inode, struct file *file,
63954 int err;
63955 struct net *net;
63956
63957+ if (gr_proc_is_restricted())
63958+ return -EACCES;
63959+
63960 err = -ENXIO;
63961 net = get_proc_net(inode);
63962 if (net == NULL)
63963diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
63964index 7129046..6914844 100644
63965--- a/fs/proc/proc_sysctl.c
63966+++ b/fs/proc/proc_sysctl.c
63967@@ -11,13 +11,21 @@
63968 #include <linux/namei.h>
63969 #include <linux/mm.h>
63970 #include <linux/module.h>
63971+#include <linux/nsproxy.h>
63972+#ifdef CONFIG_GRKERNSEC
63973+#include <net/net_namespace.h>
63974+#endif
63975 #include "internal.h"
63976
63977+extern int gr_handle_chroot_sysctl(const int op);
63978+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
63979+ const int op);
63980+
63981 static const struct dentry_operations proc_sys_dentry_operations;
63982 static const struct file_operations proc_sys_file_operations;
63983-static const struct inode_operations proc_sys_inode_operations;
63984+const struct inode_operations proc_sys_inode_operations;
63985 static const struct file_operations proc_sys_dir_file_operations;
63986-static const struct inode_operations proc_sys_dir_operations;
63987+const struct inode_operations proc_sys_dir_operations;
63988
63989 void proc_sys_poll_notify(struct ctl_table_poll *poll)
63990 {
63991@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
63992
63993 err = NULL;
63994 d_set_d_op(dentry, &proc_sys_dentry_operations);
63995+
63996+ gr_handle_proc_create(dentry, inode);
63997+
63998 d_add(dentry, inode);
63999
64000 out:
64001@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64002 struct inode *inode = file_inode(filp);
64003 struct ctl_table_header *head = grab_header(inode);
64004 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64005+ int op = write ? MAY_WRITE : MAY_READ;
64006 ssize_t error;
64007 size_t res;
64008
64009@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64010 * and won't be until we finish.
64011 */
64012 error = -EPERM;
64013- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64014+ if (sysctl_perm(head, table, op))
64015 goto out;
64016
64017 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64018@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64019 if (!table->proc_handler)
64020 goto out;
64021
64022+#ifdef CONFIG_GRKERNSEC
64023+ error = -EPERM;
64024+ if (gr_handle_chroot_sysctl(op))
64025+ goto out;
64026+ dget(filp->f_path.dentry);
64027+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64028+ dput(filp->f_path.dentry);
64029+ goto out;
64030+ }
64031+ dput(filp->f_path.dentry);
64032+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64033+ goto out;
64034+ if (write) {
64035+ if (current->nsproxy->net_ns != table->extra2) {
64036+ if (!capable(CAP_SYS_ADMIN))
64037+ goto out;
64038+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64039+ goto out;
64040+ }
64041+#endif
64042+
64043 /* careful: calling conventions are nasty here */
64044 res = count;
64045 error = table->proc_handler(table, write, buf, &res, ppos);
64046@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64047 return false;
64048 } else {
64049 d_set_d_op(child, &proc_sys_dentry_operations);
64050+
64051+ gr_handle_proc_create(child, inode);
64052+
64053 d_add(child, inode);
64054 }
64055 } else {
64056@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64057 if ((*pos)++ < ctx->pos)
64058 return true;
64059
64060+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64061+ return 0;
64062+
64063 if (unlikely(S_ISLNK(table->mode)))
64064 res = proc_sys_link_fill_cache(file, ctx, head, table);
64065 else
64066@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64067 if (IS_ERR(head))
64068 return PTR_ERR(head);
64069
64070+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64071+ return -ENOENT;
64072+
64073 generic_fillattr(inode, stat);
64074 if (table)
64075 stat->mode = (stat->mode & S_IFMT) | table->mode;
64076@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64077 .llseek = generic_file_llseek,
64078 };
64079
64080-static const struct inode_operations proc_sys_inode_operations = {
64081+const struct inode_operations proc_sys_inode_operations = {
64082 .permission = proc_sys_permission,
64083 .setattr = proc_sys_setattr,
64084 .getattr = proc_sys_getattr,
64085 };
64086
64087-static const struct inode_operations proc_sys_dir_operations = {
64088+const struct inode_operations proc_sys_dir_operations = {
64089 .lookup = proc_sys_lookup,
64090 .permission = proc_sys_permission,
64091 .setattr = proc_sys_setattr,
64092@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64093 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64094 const char *name, int namelen)
64095 {
64096- struct ctl_table *table;
64097+ ctl_table_no_const *table;
64098 struct ctl_dir *new;
64099 struct ctl_node *node;
64100 char *new_name;
64101@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64102 return NULL;
64103
64104 node = (struct ctl_node *)(new + 1);
64105- table = (struct ctl_table *)(node + 1);
64106+ table = (ctl_table_no_const *)(node + 1);
64107 new_name = (char *)(table + 2);
64108 memcpy(new_name, name, namelen);
64109 new_name[namelen] = '\0';
64110@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64111 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64112 struct ctl_table_root *link_root)
64113 {
64114- struct ctl_table *link_table, *entry, *link;
64115+ ctl_table_no_const *link_table, *link;
64116+ struct ctl_table *entry;
64117 struct ctl_table_header *links;
64118 struct ctl_node *node;
64119 char *link_name;
64120@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64121 return NULL;
64122
64123 node = (struct ctl_node *)(links + 1);
64124- link_table = (struct ctl_table *)(node + nr_entries);
64125+ link_table = (ctl_table_no_const *)(node + nr_entries);
64126 link_name = (char *)&link_table[nr_entries + 1];
64127
64128 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64129@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64130 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64131 struct ctl_table *table)
64132 {
64133- struct ctl_table *ctl_table_arg = NULL;
64134- struct ctl_table *entry, *files;
64135+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64136+ struct ctl_table *entry;
64137 int nr_files = 0;
64138 int nr_dirs = 0;
64139 int err = -ENOMEM;
64140@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64141 nr_files++;
64142 }
64143
64144- files = table;
64145 /* If there are mixed files and directories we need a new table */
64146 if (nr_dirs && nr_files) {
64147- struct ctl_table *new;
64148+ ctl_table_no_const *new;
64149 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64150 GFP_KERNEL);
64151 if (!files)
64152@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64153 /* Register everything except a directory full of subdirectories */
64154 if (nr_files || !nr_dirs) {
64155 struct ctl_table_header *header;
64156- header = __register_sysctl_table(set, path, files);
64157+ header = __register_sysctl_table(set, path, files ? files : table);
64158 if (!header) {
64159 kfree(ctl_table_arg);
64160 goto out;
64161diff --git a/fs/proc/root.c b/fs/proc/root.c
64162index 5dbadec..473af2f 100644
64163--- a/fs/proc/root.c
64164+++ b/fs/proc/root.c
64165@@ -185,7 +185,15 @@ void __init proc_root_init(void)
64166 proc_mkdir("openprom", NULL);
64167 #endif
64168 proc_tty_init();
64169+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64170+#ifdef CONFIG_GRKERNSEC_PROC_USER
64171+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64172+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64173+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64174+#endif
64175+#else
64176 proc_mkdir("bus", NULL);
64177+#endif
64178 proc_sys_init();
64179 }
64180
64181diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64182index 9d231e9..2e1b51a 100644
64183--- a/fs/proc/stat.c
64184+++ b/fs/proc/stat.c
64185@@ -11,6 +11,7 @@
64186 #include <linux/irqnr.h>
64187 #include <linux/cputime.h>
64188 #include <linux/tick.h>
64189+#include <linux/grsecurity.h>
64190
64191 #ifndef arch_irq_stat_cpu
64192 #define arch_irq_stat_cpu(cpu) 0
64193@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64194 u64 sum_softirq = 0;
64195 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64196 struct timespec boottime;
64197+ int unrestricted = 1;
64198+
64199+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64200+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64201+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64202+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64203+ && !in_group_p(grsec_proc_gid)
64204+#endif
64205+ )
64206+ unrestricted = 0;
64207+#endif
64208+#endif
64209
64210 user = nice = system = idle = iowait =
64211 irq = softirq = steal = 0;
64212@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
64213 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64214 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64215 idle += get_idle_time(i);
64216- iowait += get_iowait_time(i);
64217- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64218- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64219- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64220- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64221- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64222- sum += kstat_cpu_irqs_sum(i);
64223- sum += arch_irq_stat_cpu(i);
64224+ if (unrestricted) {
64225+ iowait += get_iowait_time(i);
64226+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64227+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64228+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64229+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64230+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64231+ sum += kstat_cpu_irqs_sum(i);
64232+ sum += arch_irq_stat_cpu(i);
64233+ for (j = 0; j < NR_SOFTIRQS; j++) {
64234+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64235
64236- for (j = 0; j < NR_SOFTIRQS; j++) {
64237- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64238-
64239- per_softirq_sums[j] += softirq_stat;
64240- sum_softirq += softirq_stat;
64241+ per_softirq_sums[j] += softirq_stat;
64242+ sum_softirq += softirq_stat;
64243+ }
64244 }
64245 }
64246- sum += arch_irq_stat();
64247+ if (unrestricted)
64248+ sum += arch_irq_stat();
64249
64250 seq_puts(p, "cpu ");
64251 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64252@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
64253 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64254 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64255 idle = get_idle_time(i);
64256- iowait = get_iowait_time(i);
64257- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64258- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64259- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64260- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64261- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64262+ if (unrestricted) {
64263+ iowait = get_iowait_time(i);
64264+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64265+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64266+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64267+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64268+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64269+ }
64270 seq_printf(p, "cpu%d", i);
64271 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64272 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64273@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64274
64275 /* sum again ? it could be updated? */
64276 for_each_irq_nr(j)
64277- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64278+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64279
64280 seq_printf(p,
64281 "\nctxt %llu\n"
64282@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64283 "processes %lu\n"
64284 "procs_running %lu\n"
64285 "procs_blocked %lu\n",
64286- nr_context_switches(),
64287+ unrestricted ? nr_context_switches() : 0ULL,
64288 (unsigned long)jif,
64289- total_forks,
64290- nr_running(),
64291- nr_iowait());
64292+ unrestricted ? total_forks : 0UL,
64293+ unrestricted ? nr_running() : 0UL,
64294+ unrestricted ? nr_iowait() : 0UL);
64295
64296 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64297
64298diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64299index c4b2646..84f0d7b 100644
64300--- a/fs/proc/task_mmu.c
64301+++ b/fs/proc/task_mmu.c
64302@@ -13,12 +13,19 @@
64303 #include <linux/swap.h>
64304 #include <linux/swapops.h>
64305 #include <linux/mmu_notifier.h>
64306+#include <linux/grsecurity.h>
64307
64308 #include <asm/elf.h>
64309 #include <asm/uaccess.h>
64310 #include <asm/tlbflush.h>
64311 #include "internal.h"
64312
64313+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64314+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64315+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
64316+ _mm->pax_flags & MF_PAX_SEGMEXEC))
64317+#endif
64318+
64319 void task_mem(struct seq_file *m, struct mm_struct *mm)
64320 {
64321 unsigned long data, text, lib, swap;
64322@@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64323 "VmExe:\t%8lu kB\n"
64324 "VmLib:\t%8lu kB\n"
64325 "VmPTE:\t%8lu kB\n"
64326- "VmSwap:\t%8lu kB\n",
64327- hiwater_vm << (PAGE_SHIFT-10),
64328+ "VmSwap:\t%8lu kB\n"
64329+
64330+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64331+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64332+#endif
64333+
64334+ ,hiwater_vm << (PAGE_SHIFT-10),
64335 total_vm << (PAGE_SHIFT-10),
64336 mm->locked_vm << (PAGE_SHIFT-10),
64337 mm->pinned_vm << (PAGE_SHIFT-10),
64338@@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64339 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64340 (PTRS_PER_PTE * sizeof(pte_t) *
64341 atomic_long_read(&mm->nr_ptes)) >> 10,
64342- swap << (PAGE_SHIFT-10));
64343+ swap << (PAGE_SHIFT-10)
64344+
64345+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64346+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64347+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64348+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64349+#else
64350+ , mm->context.user_cs_base
64351+ , mm->context.user_cs_limit
64352+#endif
64353+#endif
64354+
64355+ );
64356 }
64357
64358 unsigned long task_vsize(struct mm_struct *mm)
64359@@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64360 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64361 }
64362
64363- /* We don't show the stack guard page in /proc/maps */
64364+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64365+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64366+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64367+#else
64368 start = vma->vm_start;
64369- if (stack_guard_page_start(vma, start))
64370- start += PAGE_SIZE;
64371 end = vma->vm_end;
64372- if (stack_guard_page_end(vma, end))
64373- end -= PAGE_SIZE;
64374+#endif
64375
64376 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64377 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64378@@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64379 flags & VM_WRITE ? 'w' : '-',
64380 flags & VM_EXEC ? 'x' : '-',
64381 flags & VM_MAYSHARE ? 's' : 'p',
64382+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64383+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64384+#else
64385 pgoff,
64386+#endif
64387 MAJOR(dev), MINOR(dev), ino);
64388
64389 /*
64390@@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64391 */
64392 if (file) {
64393 seq_pad(m, ' ');
64394- seq_path(m, &file->f_path, "\n");
64395+ seq_path(m, &file->f_path, "\n\\");
64396 goto done;
64397 }
64398
64399@@ -322,8 +350,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64400 * Thread stack in /proc/PID/task/TID/maps or
64401 * the main process stack.
64402 */
64403- if (!is_pid || (vma->vm_start <= mm->start_stack &&
64404- vma->vm_end >= mm->start_stack)) {
64405+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64406+ (vma->vm_start <= mm->start_stack &&
64407+ vma->vm_end >= mm->start_stack)) {
64408 name = "[stack]";
64409 } else {
64410 /* Thread stack in /proc/PID/maps */
64411@@ -347,6 +376,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64412 struct proc_maps_private *priv = m->private;
64413 struct task_struct *task = priv->task;
64414
64415+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64416+ if (current->exec_id != m->exec_id) {
64417+ gr_log_badprocpid("maps");
64418+ return 0;
64419+ }
64420+#endif
64421+
64422 show_map_vma(m, vma, is_pid);
64423
64424 if (m->count < m->size) /* vma is copied successfully */
64425@@ -587,12 +623,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64426 .private = &mss,
64427 };
64428
64429+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64430+ if (current->exec_id != m->exec_id) {
64431+ gr_log_badprocpid("smaps");
64432+ return 0;
64433+ }
64434+#endif
64435 memset(&mss, 0, sizeof mss);
64436- mss.vma = vma;
64437- /* mmap_sem is held in m_start */
64438- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64439- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64440-
64441+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64442+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64443+#endif
64444+ mss.vma = vma;
64445+ /* mmap_sem is held in m_start */
64446+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64447+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64448+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64449+ }
64450+#endif
64451 show_map_vma(m, vma, is_pid);
64452
64453 seq_printf(m,
64454@@ -610,7 +657,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64455 "KernelPageSize: %8lu kB\n"
64456 "MMUPageSize: %8lu kB\n"
64457 "Locked: %8lu kB\n",
64458+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64459+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64460+#else
64461 (vma->vm_end - vma->vm_start) >> 10,
64462+#endif
64463 mss.resident >> 10,
64464 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64465 mss.shared_clean >> 10,
64466@@ -1388,6 +1439,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64467 char buffer[64];
64468 int nid;
64469
64470+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64471+ if (current->exec_id != m->exec_id) {
64472+ gr_log_badprocpid("numa_maps");
64473+ return 0;
64474+ }
64475+#endif
64476+
64477 if (!mm)
64478 return 0;
64479
64480@@ -1405,11 +1463,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64481 mpol_to_str(buffer, sizeof(buffer), pol);
64482 mpol_cond_put(pol);
64483
64484+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64485+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64486+#else
64487 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64488+#endif
64489
64490 if (file) {
64491 seq_printf(m, " file=");
64492- seq_path(m, &file->f_path, "\n\t= ");
64493+ seq_path(m, &file->f_path, "\n\t\\= ");
64494 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64495 seq_printf(m, " heap");
64496 } else {
64497diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64498index 678455d..ebd3245 100644
64499--- a/fs/proc/task_nommu.c
64500+++ b/fs/proc/task_nommu.c
64501@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64502 else
64503 bytes += kobjsize(mm);
64504
64505- if (current->fs && current->fs->users > 1)
64506+ if (current->fs && atomic_read(&current->fs->users) > 1)
64507 sbytes += kobjsize(current->fs);
64508 else
64509 bytes += kobjsize(current->fs);
64510@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64511
64512 if (file) {
64513 seq_pad(m, ' ');
64514- seq_path(m, &file->f_path, "");
64515+ seq_path(m, &file->f_path, "\n\\");
64516 } else if (mm) {
64517 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64518
64519diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64520index 6a8e785..41f2a6c 100644
64521--- a/fs/proc/vmcore.c
64522+++ b/fs/proc/vmcore.c
64523@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64524 nr_bytes = count;
64525
64526 /* If pfn is not ram, return zeros for sparse dump files */
64527- if (pfn_is_ram(pfn) == 0)
64528- memset(buf, 0, nr_bytes);
64529- else {
64530+ if (pfn_is_ram(pfn) == 0) {
64531+ if (userbuf) {
64532+ if (clear_user((char __force_user *)buf, nr_bytes))
64533+ return -EFAULT;
64534+ } else
64535+ memset(buf, 0, nr_bytes);
64536+ } else {
64537 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64538 offset, userbuf);
64539 if (tmp < 0)
64540@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64541 static int copy_to(void *target, void *src, size_t size, int userbuf)
64542 {
64543 if (userbuf) {
64544- if (copy_to_user((char __user *) target, src, size))
64545+ if (copy_to_user((char __force_user *) target, src, size))
64546 return -EFAULT;
64547 } else {
64548 memcpy(target, src, size);
64549@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64550 if (*fpos < m->offset + m->size) {
64551 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64552 start = m->paddr + *fpos - m->offset;
64553- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64554+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64555 if (tmp < 0)
64556 return tmp;
64557 buflen -= tsz;
64558@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64559 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64560 size_t buflen, loff_t *fpos)
64561 {
64562- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64563+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64564 }
64565
64566 /*
64567diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64568index b00fcc9..e0c6381 100644
64569--- a/fs/qnx6/qnx6.h
64570+++ b/fs/qnx6/qnx6.h
64571@@ -74,7 +74,7 @@ enum {
64572 BYTESEX_BE,
64573 };
64574
64575-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64576+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64577 {
64578 if (sbi->s_bytesex == BYTESEX_LE)
64579 return le64_to_cpu((__force __le64)n);
64580@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64581 return (__force __fs64)cpu_to_be64(n);
64582 }
64583
64584-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64585+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64586 {
64587 if (sbi->s_bytesex == BYTESEX_LE)
64588 return le32_to_cpu((__force __le32)n);
64589diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64590index 72d2917..c917c12 100644
64591--- a/fs/quota/netlink.c
64592+++ b/fs/quota/netlink.c
64593@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64594 void quota_send_warning(struct kqid qid, dev_t dev,
64595 const char warntype)
64596 {
64597- static atomic_t seq;
64598+ static atomic_unchecked_t seq;
64599 struct sk_buff *skb;
64600 void *msg_head;
64601 int ret;
64602@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64603 "VFS: Not enough memory to send quota warning.\n");
64604 return;
64605 }
64606- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64607+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64608 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64609 if (!msg_head) {
64610 printk(KERN_ERR
64611diff --git a/fs/read_write.c b/fs/read_write.c
64612index 31c6efa..a068805 100644
64613--- a/fs/read_write.c
64614+++ b/fs/read_write.c
64615@@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64616
64617 old_fs = get_fs();
64618 set_fs(get_ds());
64619- p = (__force const char __user *)buf;
64620+ p = (const char __force_user *)buf;
64621 if (count > MAX_RW_COUNT)
64622 count = MAX_RW_COUNT;
64623 if (file->f_op->write)
64624diff --git a/fs/readdir.c b/fs/readdir.c
64625index 5b53d99..a6c3049 100644
64626--- a/fs/readdir.c
64627+++ b/fs/readdir.c
64628@@ -17,6 +17,7 @@
64629 #include <linux/security.h>
64630 #include <linux/syscalls.h>
64631 #include <linux/unistd.h>
64632+#include <linux/namei.h>
64633
64634 #include <asm/uaccess.h>
64635
64636@@ -69,6 +70,7 @@ struct old_linux_dirent {
64637 struct readdir_callback {
64638 struct dir_context ctx;
64639 struct old_linux_dirent __user * dirent;
64640+ struct file * file;
64641 int result;
64642 };
64643
64644@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64645 buf->result = -EOVERFLOW;
64646 return -EOVERFLOW;
64647 }
64648+
64649+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64650+ return 0;
64651+
64652 buf->result++;
64653 dirent = buf->dirent;
64654 if (!access_ok(VERIFY_WRITE, dirent,
64655@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64656 if (!f.file)
64657 return -EBADF;
64658
64659+ buf.file = f.file;
64660 error = iterate_dir(f.file, &buf.ctx);
64661 if (buf.result)
64662 error = buf.result;
64663@@ -142,6 +149,7 @@ struct getdents_callback {
64664 struct dir_context ctx;
64665 struct linux_dirent __user * current_dir;
64666 struct linux_dirent __user * previous;
64667+ struct file * file;
64668 int count;
64669 int error;
64670 };
64671@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64672 buf->error = -EOVERFLOW;
64673 return -EOVERFLOW;
64674 }
64675+
64676+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64677+ return 0;
64678+
64679 dirent = buf->previous;
64680 if (dirent) {
64681 if (__put_user(offset, &dirent->d_off))
64682@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64683 if (!f.file)
64684 return -EBADF;
64685
64686+ buf.file = f.file;
64687 error = iterate_dir(f.file, &buf.ctx);
64688 if (error >= 0)
64689 error = buf.error;
64690@@ -226,6 +239,7 @@ struct getdents_callback64 {
64691 struct dir_context ctx;
64692 struct linux_dirent64 __user * current_dir;
64693 struct linux_dirent64 __user * previous;
64694+ struct file *file;
64695 int count;
64696 int error;
64697 };
64698@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64699 buf->error = -EINVAL; /* only used if we fail.. */
64700 if (reclen > buf->count)
64701 return -EINVAL;
64702+
64703+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64704+ return 0;
64705+
64706 dirent = buf->previous;
64707 if (dirent) {
64708 if (__put_user(offset, &dirent->d_off))
64709@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64710 if (!f.file)
64711 return -EBADF;
64712
64713+ buf.file = f.file;
64714 error = iterate_dir(f.file, &buf.ctx);
64715 if (error >= 0)
64716 error = buf.error;
64717diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64718index 9a3c68c..767933e 100644
64719--- a/fs/reiserfs/do_balan.c
64720+++ b/fs/reiserfs/do_balan.c
64721@@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64722 return;
64723 }
64724
64725- atomic_inc(&(fs_generation(tb->tb_sb)));
64726+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64727 do_balance_starts(tb);
64728
64729 /* balance leaf returns 0 except if combining L R and S into
64730diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64731index ee382ef..f4eb6eb5 100644
64732--- a/fs/reiserfs/item_ops.c
64733+++ b/fs/reiserfs/item_ops.c
64734@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64735 }
64736
64737 static struct item_operations errcatch_ops = {
64738- errcatch_bytes_number,
64739- errcatch_decrement_key,
64740- errcatch_is_left_mergeable,
64741- errcatch_print_item,
64742- errcatch_check_item,
64743+ .bytes_number = errcatch_bytes_number,
64744+ .decrement_key = errcatch_decrement_key,
64745+ .is_left_mergeable = errcatch_is_left_mergeable,
64746+ .print_item = errcatch_print_item,
64747+ .check_item = errcatch_check_item,
64748
64749- errcatch_create_vi,
64750- errcatch_check_left,
64751- errcatch_check_right,
64752- errcatch_part_size,
64753- errcatch_unit_num,
64754- errcatch_print_vi
64755+ .create_vi = errcatch_create_vi,
64756+ .check_left = errcatch_check_left,
64757+ .check_right = errcatch_check_right,
64758+ .part_size = errcatch_part_size,
64759+ .unit_num = errcatch_unit_num,
64760+ .print_vi = errcatch_print_vi
64761 };
64762
64763 //////////////////////////////////////////////////////////////////////////////
64764diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64765index 02b0b7d..c85018b 100644
64766--- a/fs/reiserfs/procfs.c
64767+++ b/fs/reiserfs/procfs.c
64768@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64769 "SMALL_TAILS " : "NO_TAILS ",
64770 replay_only(sb) ? "REPLAY_ONLY " : "",
64771 convert_reiserfs(sb) ? "CONV " : "",
64772- atomic_read(&r->s_generation_counter),
64773+ atomic_read_unchecked(&r->s_generation_counter),
64774 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64775 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64776 SF(s_good_search_by_key_reada), SF(s_bmaps),
64777diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64778index 83d4eac..04e39a7 100644
64779--- a/fs/reiserfs/reiserfs.h
64780+++ b/fs/reiserfs/reiserfs.h
64781@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64782 /* Comment? -Hans */
64783 wait_queue_head_t s_wait;
64784 /* To be obsoleted soon by per buffer seals.. -Hans */
64785- atomic_t s_generation_counter; // increased by one every time the
64786+ atomic_unchecked_t s_generation_counter; // increased by one every time the
64787 // tree gets re-balanced
64788 unsigned long s_properties; /* File system properties. Currently holds
64789 on-disk FS format */
64790@@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64791 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64792
64793 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64794-#define get_generation(s) atomic_read (&fs_generation(s))
64795+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64796 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64797 #define __fs_changed(gen,s) (gen != get_generation (s))
64798 #define fs_changed(gen,s) \
64799diff --git a/fs/select.c b/fs/select.c
64800index 467bb1c..cf9d65a 100644
64801--- a/fs/select.c
64802+++ b/fs/select.c
64803@@ -20,6 +20,7 @@
64804 #include <linux/export.h>
64805 #include <linux/slab.h>
64806 #include <linux/poll.h>
64807+#include <linux/security.h>
64808 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64809 #include <linux/file.h>
64810 #include <linux/fdtable.h>
64811@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64812 struct poll_list *walk = head;
64813 unsigned long todo = nfds;
64814
64815+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64816 if (nfds > rlimit(RLIMIT_NOFILE))
64817 return -EINVAL;
64818
64819diff --git a/fs/seq_file.c b/fs/seq_file.c
64820index 1d641bb..c2f4743 100644
64821--- a/fs/seq_file.c
64822+++ b/fs/seq_file.c
64823@@ -10,6 +10,8 @@
64824 #include <linux/seq_file.h>
64825 #include <linux/slab.h>
64826 #include <linux/cred.h>
64827+#include <linux/sched.h>
64828+#include <linux/grsecurity.h>
64829
64830 #include <asm/uaccess.h>
64831 #include <asm/page.h>
64832@@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64833 #ifdef CONFIG_USER_NS
64834 p->user_ns = file->f_cred->user_ns;
64835 #endif
64836+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64837+ p->exec_id = current->exec_id;
64838+#endif
64839
64840 /*
64841 * Wrappers around seq_open(e.g. swaps_open) need to be
64842@@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
64843 }
64844 EXPORT_SYMBOL(seq_open);
64845
64846+
64847+int seq_open_restrict(struct file *file, const struct seq_operations *op)
64848+{
64849+ if (gr_proc_is_restricted())
64850+ return -EACCES;
64851+
64852+ return seq_open(file, op);
64853+}
64854+EXPORT_SYMBOL(seq_open_restrict);
64855+
64856 static int traverse(struct seq_file *m, loff_t offset)
64857 {
64858 loff_t pos = 0, index;
64859@@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64860 return 0;
64861 }
64862 if (!m->buf) {
64863- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64864+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64865 if (!m->buf)
64866 return -ENOMEM;
64867 }
64868@@ -137,7 +152,7 @@ Eoverflow:
64869 m->op->stop(m, p);
64870 kfree(m->buf);
64871 m->count = 0;
64872- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64873+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64874 return !m->buf ? -ENOMEM : -EAGAIN;
64875 }
64876
64877@@ -153,7 +168,7 @@ Eoverflow:
64878 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64879 {
64880 struct seq_file *m = file->private_data;
64881- size_t copied = 0;
64882+ ssize_t copied = 0;
64883 loff_t pos;
64884 size_t n;
64885 void *p;
64886@@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64887
64888 /* grab buffer if we didn't have one */
64889 if (!m->buf) {
64890- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64891+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64892 if (!m->buf)
64893 goto Enomem;
64894 }
64895@@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64896 m->op->stop(m, p);
64897 kfree(m->buf);
64898 m->count = 0;
64899- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64900+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64901 if (!m->buf)
64902 goto Enomem;
64903 m->version = 0;
64904@@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
64905 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
64906 void *data)
64907 {
64908- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
64909+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
64910 int res = -ENOMEM;
64911
64912 if (op) {
64913@@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
64914 }
64915 EXPORT_SYMBOL(single_open_size);
64916
64917+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
64918+ void *data)
64919+{
64920+ if (gr_proc_is_restricted())
64921+ return -EACCES;
64922+
64923+ return single_open(file, show, data);
64924+}
64925+EXPORT_SYMBOL(single_open_restrict);
64926+
64927+
64928 int single_release(struct inode *inode, struct file *file)
64929 {
64930 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
64931diff --git a/fs/splice.c b/fs/splice.c
64932index e246954..bd4f5b5 100644
64933--- a/fs/splice.c
64934+++ b/fs/splice.c
64935@@ -192,7 +192,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64936 pipe_lock(pipe);
64937
64938 for (;;) {
64939- if (!pipe->readers) {
64940+ if (!atomic_read(&pipe->readers)) {
64941 send_sig(SIGPIPE, current, 0);
64942 if (!ret)
64943 ret = -EPIPE;
64944@@ -215,7 +215,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64945 page_nr++;
64946 ret += buf->len;
64947
64948- if (pipe->files)
64949+ if (atomic_read(&pipe->files))
64950 do_wakeup = 1;
64951
64952 if (!--spd->nr_pages)
64953@@ -246,9 +246,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64954 do_wakeup = 0;
64955 }
64956
64957- pipe->waiting_writers++;
64958+ atomic_inc(&pipe->waiting_writers);
64959 pipe_wait(pipe);
64960- pipe->waiting_writers--;
64961+ atomic_dec(&pipe->waiting_writers);
64962 }
64963
64964 pipe_unlock(pipe);
64965@@ -575,7 +575,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
64966 old_fs = get_fs();
64967 set_fs(get_ds());
64968 /* The cast to a user pointer is valid due to the set_fs() */
64969- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
64970+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
64971 set_fs(old_fs);
64972
64973 return res;
64974@@ -590,7 +590,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
64975 old_fs = get_fs();
64976 set_fs(get_ds());
64977 /* The cast to a user pointer is valid due to the set_fs() */
64978- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
64979+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
64980 set_fs(old_fs);
64981
64982 return res;
64983@@ -643,7 +643,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
64984 goto err;
64985
64986 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
64987- vec[i].iov_base = (void __user *) page_address(page);
64988+ vec[i].iov_base = (void __force_user *) page_address(page);
64989 vec[i].iov_len = this_len;
64990 spd.pages[i] = page;
64991 spd.nr_pages++;
64992@@ -839,7 +839,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
64993 ops->release(pipe, buf);
64994 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
64995 pipe->nrbufs--;
64996- if (pipe->files)
64997+ if (atomic_read(&pipe->files))
64998 sd->need_wakeup = true;
64999 }
65000
65001@@ -864,10 +864,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65002 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65003 {
65004 while (!pipe->nrbufs) {
65005- if (!pipe->writers)
65006+ if (!atomic_read(&pipe->writers))
65007 return 0;
65008
65009- if (!pipe->waiting_writers && sd->num_spliced)
65010+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65011 return 0;
65012
65013 if (sd->flags & SPLICE_F_NONBLOCK)
65014@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65015 * out of the pipe right after the splice_to_pipe(). So set
65016 * PIPE_READERS appropriately.
65017 */
65018- pipe->readers = 1;
65019+ atomic_set(&pipe->readers, 1);
65020
65021 current->splice_pipe = pipe;
65022 }
65023@@ -1485,6 +1485,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65024
65025 partial[buffers].offset = off;
65026 partial[buffers].len = plen;
65027+ partial[buffers].private = 0;
65028
65029 off = 0;
65030 len -= plen;
65031@@ -1721,9 +1722,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65032 ret = -ERESTARTSYS;
65033 break;
65034 }
65035- if (!pipe->writers)
65036+ if (!atomic_read(&pipe->writers))
65037 break;
65038- if (!pipe->waiting_writers) {
65039+ if (!atomic_read(&pipe->waiting_writers)) {
65040 if (flags & SPLICE_F_NONBLOCK) {
65041 ret = -EAGAIN;
65042 break;
65043@@ -1755,7 +1756,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65044 pipe_lock(pipe);
65045
65046 while (pipe->nrbufs >= pipe->buffers) {
65047- if (!pipe->readers) {
65048+ if (!atomic_read(&pipe->readers)) {
65049 send_sig(SIGPIPE, current, 0);
65050 ret = -EPIPE;
65051 break;
65052@@ -1768,9 +1769,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65053 ret = -ERESTARTSYS;
65054 break;
65055 }
65056- pipe->waiting_writers++;
65057+ atomic_inc(&pipe->waiting_writers);
65058 pipe_wait(pipe);
65059- pipe->waiting_writers--;
65060+ atomic_dec(&pipe->waiting_writers);
65061 }
65062
65063 pipe_unlock(pipe);
65064@@ -1806,14 +1807,14 @@ retry:
65065 pipe_double_lock(ipipe, opipe);
65066
65067 do {
65068- if (!opipe->readers) {
65069+ if (!atomic_read(&opipe->readers)) {
65070 send_sig(SIGPIPE, current, 0);
65071 if (!ret)
65072 ret = -EPIPE;
65073 break;
65074 }
65075
65076- if (!ipipe->nrbufs && !ipipe->writers)
65077+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65078 break;
65079
65080 /*
65081@@ -1910,7 +1911,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65082 pipe_double_lock(ipipe, opipe);
65083
65084 do {
65085- if (!opipe->readers) {
65086+ if (!atomic_read(&opipe->readers)) {
65087 send_sig(SIGPIPE, current, 0);
65088 if (!ret)
65089 ret = -EPIPE;
65090@@ -1955,7 +1956,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65091 * return EAGAIN if we have the potential of some data in the
65092 * future, otherwise just return 0
65093 */
65094- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65095+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65096 ret = -EAGAIN;
65097
65098 pipe_unlock(ipipe);
65099diff --git a/fs/stat.c b/fs/stat.c
65100index ae0c3ce..9ee641c 100644
65101--- a/fs/stat.c
65102+++ b/fs/stat.c
65103@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65104 stat->gid = inode->i_gid;
65105 stat->rdev = inode->i_rdev;
65106 stat->size = i_size_read(inode);
65107- stat->atime = inode->i_atime;
65108- stat->mtime = inode->i_mtime;
65109+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65110+ stat->atime = inode->i_ctime;
65111+ stat->mtime = inode->i_ctime;
65112+ } else {
65113+ stat->atime = inode->i_atime;
65114+ stat->mtime = inode->i_mtime;
65115+ }
65116 stat->ctime = inode->i_ctime;
65117 stat->blksize = (1 << inode->i_blkbits);
65118 stat->blocks = inode->i_blocks;
65119@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65120 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65121 {
65122 struct inode *inode = path->dentry->d_inode;
65123+ int retval;
65124
65125- if (inode->i_op->getattr)
65126- return inode->i_op->getattr(path->mnt, path->dentry, stat);
65127+ if (inode->i_op->getattr) {
65128+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65129+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65130+ stat->atime = stat->ctime;
65131+ stat->mtime = stat->ctime;
65132+ }
65133+ return retval;
65134+ }
65135
65136 generic_fillattr(inode, stat);
65137 return 0;
65138diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65139index 0b45ff4..847de5b 100644
65140--- a/fs/sysfs/dir.c
65141+++ b/fs/sysfs/dir.c
65142@@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65143 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65144 {
65145 struct kernfs_node *parent, *kn;
65146+ const char *name;
65147+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65148+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65149+ const char *parent_name;
65150+#endif
65151
65152 BUG_ON(!kobj);
65153
65154+ name = kobject_name(kobj);
65155+
65156 if (kobj->parent)
65157 parent = kobj->parent->sd;
65158 else
65159@@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65160 if (!parent)
65161 return -ENOENT;
65162
65163- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65164- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65165+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65166+ parent_name = parent->name;
65167+ mode = S_IRWXU;
65168+
65169+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65170+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65171+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65172+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65173+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
65174+#endif
65175+
65176+ kn = kernfs_create_dir_ns(parent, name,
65177+ mode, kobj, ns);
65178 if (IS_ERR(kn)) {
65179 if (PTR_ERR(kn) == -EEXIST)
65180- sysfs_warn_dup(parent, kobject_name(kobj));
65181+ sysfs_warn_dup(parent, name);
65182 return PTR_ERR(kn);
65183 }
65184
65185diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65186index 69d4889..a810bd4 100644
65187--- a/fs/sysv/sysv.h
65188+++ b/fs/sysv/sysv.h
65189@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65190 #endif
65191 }
65192
65193-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65194+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65195 {
65196 if (sbi->s_bytesex == BYTESEX_PDP)
65197 return PDP_swab((__force __u32)n);
65198diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65199index e18b988..f1d4ad0f 100644
65200--- a/fs/ubifs/io.c
65201+++ b/fs/ubifs/io.c
65202@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65203 return err;
65204 }
65205
65206-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65207+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65208 {
65209 int err;
65210
65211diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65212index c175b4d..8f36a16 100644
65213--- a/fs/udf/misc.c
65214+++ b/fs/udf/misc.c
65215@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65216
65217 u8 udf_tag_checksum(const struct tag *t)
65218 {
65219- u8 *data = (u8 *)t;
65220+ const u8 *data = (const u8 *)t;
65221 u8 checksum = 0;
65222 int i;
65223 for (i = 0; i < sizeof(struct tag); ++i)
65224diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65225index 8d974c4..b82f6ec 100644
65226--- a/fs/ufs/swab.h
65227+++ b/fs/ufs/swab.h
65228@@ -22,7 +22,7 @@ enum {
65229 BYTESEX_BE
65230 };
65231
65232-static inline u64
65233+static inline u64 __intentional_overflow(-1)
65234 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65235 {
65236 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65237@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65238 return (__force __fs64)cpu_to_be64(n);
65239 }
65240
65241-static inline u32
65242+static inline u32 __intentional_overflow(-1)
65243 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65244 {
65245 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65246diff --git a/fs/utimes.c b/fs/utimes.c
65247index aa138d6..5f3a811 100644
65248--- a/fs/utimes.c
65249+++ b/fs/utimes.c
65250@@ -1,6 +1,7 @@
65251 #include <linux/compiler.h>
65252 #include <linux/file.h>
65253 #include <linux/fs.h>
65254+#include <linux/security.h>
65255 #include <linux/linkage.h>
65256 #include <linux/mount.h>
65257 #include <linux/namei.h>
65258@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65259 }
65260 }
65261 retry_deleg:
65262+
65263+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65264+ error = -EACCES;
65265+ goto mnt_drop_write_and_out;
65266+ }
65267+
65268 mutex_lock(&inode->i_mutex);
65269 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65270 mutex_unlock(&inode->i_mutex);
65271diff --git a/fs/xattr.c b/fs/xattr.c
65272index 3377dff..f394815 100644
65273--- a/fs/xattr.c
65274+++ b/fs/xattr.c
65275@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65276 return rc;
65277 }
65278
65279+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65280+ssize_t
65281+pax_getxattr(struct dentry *dentry, void *value, size_t size)
65282+{
65283+ struct inode *inode = dentry->d_inode;
65284+ ssize_t error;
65285+
65286+ error = inode_permission(inode, MAY_EXEC);
65287+ if (error)
65288+ return error;
65289+
65290+ if (inode->i_op->getxattr)
65291+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65292+ else
65293+ error = -EOPNOTSUPP;
65294+
65295+ return error;
65296+}
65297+EXPORT_SYMBOL(pax_getxattr);
65298+#endif
65299+
65300 ssize_t
65301 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65302 {
65303@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65304 * Extended attribute SET operations
65305 */
65306 static long
65307-setxattr(struct dentry *d, const char __user *name, const void __user *value,
65308+setxattr(struct path *path, const char __user *name, const void __user *value,
65309 size_t size, int flags)
65310 {
65311 int error;
65312@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65313 posix_acl_fix_xattr_from_user(kvalue, size);
65314 }
65315
65316- error = vfs_setxattr(d, kname, kvalue, size, flags);
65317+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65318+ error = -EACCES;
65319+ goto out;
65320+ }
65321+
65322+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65323 out:
65324 if (vvalue)
65325 vfree(vvalue);
65326@@ -377,7 +403,7 @@ retry:
65327 return error;
65328 error = mnt_want_write(path.mnt);
65329 if (!error) {
65330- error = setxattr(path.dentry, name, value, size, flags);
65331+ error = setxattr(&path, name, value, size, flags);
65332 mnt_drop_write(path.mnt);
65333 }
65334 path_put(&path);
65335@@ -401,7 +427,7 @@ retry:
65336 return error;
65337 error = mnt_want_write(path.mnt);
65338 if (!error) {
65339- error = setxattr(path.dentry, name, value, size, flags);
65340+ error = setxattr(&path, name, value, size, flags);
65341 mnt_drop_write(path.mnt);
65342 }
65343 path_put(&path);
65344@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65345 const void __user *,value, size_t, size, int, flags)
65346 {
65347 struct fd f = fdget(fd);
65348- struct dentry *dentry;
65349 int error = -EBADF;
65350
65351 if (!f.file)
65352 return error;
65353- dentry = f.file->f_path.dentry;
65354- audit_inode(NULL, dentry, 0);
65355+ audit_inode(NULL, f.file->f_path.dentry, 0);
65356 error = mnt_want_write_file(f.file);
65357 if (!error) {
65358- error = setxattr(dentry, name, value, size, flags);
65359+ error = setxattr(&f.file->f_path, name, value, size, flags);
65360 mnt_drop_write_file(f.file);
65361 }
65362 fdput(f);
65363@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65364 * Extended attribute REMOVE operations
65365 */
65366 static long
65367-removexattr(struct dentry *d, const char __user *name)
65368+removexattr(struct path *path, const char __user *name)
65369 {
65370 int error;
65371 char kname[XATTR_NAME_MAX + 1];
65372@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65373 if (error < 0)
65374 return error;
65375
65376- return vfs_removexattr(d, kname);
65377+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65378+ return -EACCES;
65379+
65380+ return vfs_removexattr(path->dentry, kname);
65381 }
65382
65383 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65384@@ -652,7 +679,7 @@ retry:
65385 return error;
65386 error = mnt_want_write(path.mnt);
65387 if (!error) {
65388- error = removexattr(path.dentry, name);
65389+ error = removexattr(&path, name);
65390 mnt_drop_write(path.mnt);
65391 }
65392 path_put(&path);
65393@@ -675,7 +702,7 @@ retry:
65394 return error;
65395 error = mnt_want_write(path.mnt);
65396 if (!error) {
65397- error = removexattr(path.dentry, name);
65398+ error = removexattr(&path, name);
65399 mnt_drop_write(path.mnt);
65400 }
65401 path_put(&path);
65402@@ -689,16 +716,16 @@ retry:
65403 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65404 {
65405 struct fd f = fdget(fd);
65406- struct dentry *dentry;
65407+ struct path *path;
65408 int error = -EBADF;
65409
65410 if (!f.file)
65411 return error;
65412- dentry = f.file->f_path.dentry;
65413- audit_inode(NULL, dentry, 0);
65414+ path = &f.file->f_path;
65415+ audit_inode(NULL, path->dentry, 0);
65416 error = mnt_want_write_file(f.file);
65417 if (!error) {
65418- error = removexattr(dentry, name);
65419+ error = removexattr(path, name);
65420 mnt_drop_write_file(f.file);
65421 }
65422 fdput(f);
65423diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65424index f0efc7e..ba72910 100644
65425--- a/fs/xfs/xfs_bmap.c
65426+++ b/fs/xfs/xfs_bmap.c
65427@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65428
65429 #else
65430 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65431-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65432+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65433 #endif /* DEBUG */
65434
65435 /*
65436diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65437index aead369..0dfecfd 100644
65438--- a/fs/xfs/xfs_dir2_readdir.c
65439+++ b/fs/xfs/xfs_dir2_readdir.c
65440@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65441 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65442 filetype = dp->d_ops->sf_get_ftype(sfep);
65443 ctx->pos = off & 0x7fffffff;
65444- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65445+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65446+ char name[sfep->namelen];
65447+ memcpy(name, sfep->name, sfep->namelen);
65448+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65449+ return 0;
65450+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65451 xfs_dir3_get_dtype(mp, filetype)))
65452 return 0;
65453 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65454diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65455index 6152cbe..f0f9eaa 100644
65456--- a/fs/xfs/xfs_ioctl.c
65457+++ b/fs/xfs/xfs_ioctl.c
65458@@ -122,7 +122,7 @@ xfs_find_handle(
65459 }
65460
65461 error = -EFAULT;
65462- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65463+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65464 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65465 goto out_put;
65466
65467diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65468new file mode 100644
65469index 0000000..bfd482c
65470--- /dev/null
65471+++ b/grsecurity/Kconfig
65472@@ -0,0 +1,1176 @@
65473+#
65474+# grecurity configuration
65475+#
65476+menu "Memory Protections"
65477+depends on GRKERNSEC
65478+
65479+config GRKERNSEC_KMEM
65480+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65481+ default y if GRKERNSEC_CONFIG_AUTO
65482+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65483+ help
65484+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65485+ be written to or read from to modify or leak the contents of the running
65486+ kernel. /dev/port will also not be allowed to be opened, writing to
65487+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65488+ If you have module support disabled, enabling this will close up several
65489+ ways that are currently used to insert malicious code into the running
65490+ kernel.
65491+
65492+ Even with this feature enabled, we still highly recommend that
65493+ you use the RBAC system, as it is still possible for an attacker to
65494+ modify the running kernel through other more obscure methods.
65495+
65496+ It is highly recommended that you say Y here if you meet all the
65497+ conditions above.
65498+
65499+config GRKERNSEC_VM86
65500+ bool "Restrict VM86 mode"
65501+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65502+ depends on X86_32
65503+
65504+ help
65505+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65506+ make use of a special execution mode on 32bit x86 processors called
65507+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65508+ video cards and will still work with this option enabled. The purpose
65509+ of the option is to prevent exploitation of emulation errors in
65510+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
65511+ Nearly all users should be able to enable this option.
65512+
65513+config GRKERNSEC_IO
65514+ bool "Disable privileged I/O"
65515+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65516+ depends on X86
65517+ select RTC_CLASS
65518+ select RTC_INTF_DEV
65519+ select RTC_DRV_CMOS
65520+
65521+ help
65522+ If you say Y here, all ioperm and iopl calls will return an error.
65523+ Ioperm and iopl can be used to modify the running kernel.
65524+ Unfortunately, some programs need this access to operate properly,
65525+ the most notable of which are XFree86 and hwclock. hwclock can be
65526+ remedied by having RTC support in the kernel, so real-time
65527+ clock support is enabled if this option is enabled, to ensure
65528+ that hwclock operates correctly. If hwclock still does not work,
65529+ either update udev or symlink /dev/rtc to /dev/rtc0.
65530+
65531+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
65532+ you may not be able to boot into a graphical environment with this
65533+ option enabled. In this case, you should use the RBAC system instead.
65534+
65535+config GRKERNSEC_JIT_HARDEN
65536+ bool "Harden BPF JIT against spray attacks"
65537+ default y if GRKERNSEC_CONFIG_AUTO
65538+ depends on BPF_JIT && X86
65539+ help
65540+ If you say Y here, the native code generated by the kernel's Berkeley
65541+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65542+ attacks that attempt to fit attacker-beneficial instructions in
65543+ 32bit immediate fields of JIT-generated native instructions. The
65544+ attacker will generally aim to cause an unintended instruction sequence
65545+ of JIT-generated native code to execute by jumping into the middle of
65546+ a generated instruction. This feature effectively randomizes the 32bit
65547+ immediate constants present in the generated code to thwart such attacks.
65548+
65549+ If you're using KERNEXEC, it's recommended that you enable this option
65550+ to supplement the hardening of the kernel.
65551+
65552+config GRKERNSEC_PERF_HARDEN
65553+ bool "Disable unprivileged PERF_EVENTS usage by default"
65554+ default y if GRKERNSEC_CONFIG_AUTO
65555+ depends on PERF_EVENTS
65556+ help
65557+ If you say Y here, the range of acceptable values for the
65558+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65559+ default to a new value: 3. When the sysctl is set to this value, no
65560+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65561+
65562+ Though PERF_EVENTS can be used legitimately for performance monitoring
65563+ and low-level application profiling, it is forced on regardless of
65564+ configuration, has been at fault for several vulnerabilities, and
65565+ creates new opportunities for side channels and other information leaks.
65566+
65567+ This feature puts PERF_EVENTS into a secure default state and permits
65568+ the administrator to change out of it temporarily if unprivileged
65569+ application profiling is needed.
65570+
65571+config GRKERNSEC_RAND_THREADSTACK
65572+ bool "Insert random gaps between thread stacks"
65573+ default y if GRKERNSEC_CONFIG_AUTO
65574+ depends on PAX_RANDMMAP && !PPC
65575+ help
65576+ If you say Y here, a random-sized gap will be enforced between allocated
65577+ thread stacks. Glibc's NPTL and other threading libraries that
65578+ pass MAP_STACK to the kernel for thread stack allocation are supported.
65579+ The implementation currently provides 8 bits of entropy for the gap.
65580+
65581+ Many distributions do not compile threaded remote services with the
65582+ -fstack-check argument to GCC, causing the variable-sized stack-based
65583+ allocator, alloca(), to not probe the stack on allocation. This
65584+ permits an unbounded alloca() to skip over any guard page and potentially
65585+ modify another thread's stack reliably. An enforced random gap
65586+ reduces the reliability of such an attack and increases the chance
65587+ that such a read/write to another thread's stack instead lands in
65588+ an unmapped area, causing a crash and triggering grsecurity's
65589+ anti-bruteforcing logic.
65590+
65591+config GRKERNSEC_PROC_MEMMAP
65592+ bool "Harden ASLR against information leaks and entropy reduction"
65593+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65594+ depends on PAX_NOEXEC || PAX_ASLR
65595+ help
65596+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65597+ give no information about the addresses of its mappings if
65598+ PaX features that rely on random addresses are enabled on the task.
65599+ In addition to sanitizing this information and disabling other
65600+ dangerous sources of information, this option causes reads of sensitive
65601+ /proc/<pid> entries where the file descriptor was opened in a different
65602+ task than the one performing the read. Such attempts are logged.
65603+ This option also limits argv/env strings for suid/sgid binaries
65604+ to 512KB to prevent a complete exhaustion of the stack entropy provided
65605+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65606+ binaries to prevent alternative mmap layouts from being abused.
65607+
65608+ If you use PaX it is essential that you say Y here as it closes up
65609+ several holes that make full ASLR useless locally.
65610+
65611+
65612+config GRKERNSEC_KSTACKOVERFLOW
65613+ bool "Prevent kernel stack overflows"
65614+ default y if GRKERNSEC_CONFIG_AUTO
65615+ depends on !IA64 && 64BIT
65616+ help
65617+ If you say Y here, the kernel's process stacks will be allocated
65618+ with vmalloc instead of the kernel's default allocator. This
65619+ introduces guard pages that in combination with the alloca checking
65620+ of the STACKLEAK feature prevents all forms of kernel process stack
65621+ overflow abuse. Note that this is different from kernel stack
65622+ buffer overflows.
65623+
65624+config GRKERNSEC_BRUTE
65625+ bool "Deter exploit bruteforcing"
65626+ default y if GRKERNSEC_CONFIG_AUTO
65627+ help
65628+ If you say Y here, attempts to bruteforce exploits against forking
65629+ daemons such as apache or sshd, as well as against suid/sgid binaries
65630+ will be deterred. When a child of a forking daemon is killed by PaX
65631+ or crashes due to an illegal instruction or other suspicious signal,
65632+ the parent process will be delayed 30 seconds upon every subsequent
65633+ fork until the administrator is able to assess the situation and
65634+ restart the daemon.
65635+ In the suid/sgid case, the attempt is logged, the user has all their
65636+ existing instances of the suid/sgid binary terminated and will
65637+ be unable to execute any suid/sgid binaries for 15 minutes.
65638+
65639+ It is recommended that you also enable signal logging in the auditing
65640+ section so that logs are generated when a process triggers a suspicious
65641+ signal.
65642+ If the sysctl option is enabled, a sysctl option with name
65643+ "deter_bruteforce" is created.
65644+
65645+config GRKERNSEC_MODHARDEN
65646+ bool "Harden module auto-loading"
65647+ default y if GRKERNSEC_CONFIG_AUTO
65648+ depends on MODULES
65649+ help
65650+ If you say Y here, module auto-loading in response to use of some
65651+ feature implemented by an unloaded module will be restricted to
65652+ root users. Enabling this option helps defend against attacks
65653+ by unprivileged users who abuse the auto-loading behavior to
65654+ cause a vulnerable module to load that is then exploited.
65655+
65656+ If this option prevents a legitimate use of auto-loading for a
65657+ non-root user, the administrator can execute modprobe manually
65658+ with the exact name of the module mentioned in the alert log.
65659+ Alternatively, the administrator can add the module to the list
65660+ of modules loaded at boot by modifying init scripts.
65661+
65662+ Modification of init scripts will most likely be needed on
65663+ Ubuntu servers with encrypted home directory support enabled,
65664+ as the first non-root user logging in will cause the ecb(aes),
65665+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65666+
65667+config GRKERNSEC_HIDESYM
65668+ bool "Hide kernel symbols"
65669+ default y if GRKERNSEC_CONFIG_AUTO
65670+ select PAX_USERCOPY_SLABS
65671+ help
65672+ If you say Y here, getting information on loaded modules, and
65673+ displaying all kernel symbols through a syscall will be restricted
65674+ to users with CAP_SYS_MODULE. For software compatibility reasons,
65675+ /proc/kallsyms will be restricted to the root user. The RBAC
65676+ system can hide that entry even from root.
65677+
65678+ This option also prevents leaking of kernel addresses through
65679+ several /proc entries.
65680+
65681+ Note that this option is only effective provided the following
65682+ conditions are met:
65683+ 1) The kernel using grsecurity is not precompiled by some distribution
65684+ 2) You have also enabled GRKERNSEC_DMESG
65685+ 3) You are using the RBAC system and hiding other files such as your
65686+ kernel image and System.map. Alternatively, enabling this option
65687+ causes the permissions on /boot, /lib/modules, and the kernel
65688+ source directory to change at compile time to prevent
65689+ reading by non-root users.
65690+ If the above conditions are met, this option will aid in providing a
65691+ useful protection against local kernel exploitation of overflows
65692+ and arbitrary read/write vulnerabilities.
65693+
65694+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65695+ in addition to this feature.
65696+
65697+config GRKERNSEC_RANDSTRUCT
65698+ bool "Randomize layout of sensitive kernel structures"
65699+ default y if GRKERNSEC_CONFIG_AUTO
65700+ select GRKERNSEC_HIDESYM
65701+ select MODVERSIONS if MODULES
65702+ help
65703+ If you say Y here, the layouts of a number of sensitive kernel
65704+ structures (task, fs, cred, etc) and all structures composed entirely
65705+ of function pointers (aka "ops" structs) will be randomized at compile-time.
65706+ This can introduce the requirement of an additional infoleak
65707+ vulnerability for exploits targeting these structure types.
65708+
65709+ Enabling this feature will introduce some performance impact, slightly
65710+ increase memory usage, and prevent the use of forensic tools like
65711+ Volatility against the system (unless the kernel source tree isn't
65712+ cleaned after kernel installation).
65713+
65714+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65715+ It remains after a make clean to allow for external modules to be compiled
65716+ with the existing seed and will be removed by a make mrproper or
65717+ make distclean.
65718+
65719+ Note that the implementation requires gcc 4.6.4. or newer. You may need
65720+ to install the supporting headers explicitly in addition to the normal
65721+ gcc package.
65722+
65723+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65724+ bool "Use cacheline-aware structure randomization"
65725+ depends on GRKERNSEC_RANDSTRUCT
65726+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65727+ help
65728+ If you say Y here, the RANDSTRUCT randomization will make a best effort
65729+ at restricting randomization to cacheline-sized groups of elements. It
65730+ will further not randomize bitfields in structures. This reduces the
65731+ performance hit of RANDSTRUCT at the cost of weakened randomization.
65732+
65733+config GRKERNSEC_KERN_LOCKOUT
65734+ bool "Active kernel exploit response"
65735+ default y if GRKERNSEC_CONFIG_AUTO
65736+ depends on X86 || ARM || PPC || SPARC
65737+ help
65738+ If you say Y here, when a PaX alert is triggered due to suspicious
65739+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65740+ or an OOPS occurs due to bad memory accesses, instead of just
65741+ terminating the offending process (and potentially allowing
65742+ a subsequent exploit from the same user), we will take one of two
65743+ actions:
65744+ If the user was root, we will panic the system
65745+ If the user was non-root, we will log the attempt, terminate
65746+ all processes owned by the user, then prevent them from creating
65747+ any new processes until the system is restarted
65748+ This deters repeated kernel exploitation/bruteforcing attempts
65749+ and is useful for later forensics.
65750+
65751+config GRKERNSEC_OLD_ARM_USERLAND
65752+ bool "Old ARM userland compatibility"
65753+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65754+ help
65755+ If you say Y here, stubs of executable code to perform such operations
65756+ as "compare-exchange" will be placed at fixed locations in the ARM vector
65757+ table. This is unfortunately needed for old ARM userland meant to run
65758+ across a wide range of processors. Without this option enabled,
65759+ the get_tls and data memory barrier stubs will be emulated by the kernel,
65760+ which is enough for Linaro userlands or other userlands designed for v6
65761+ and newer ARM CPUs. It's recommended that you try without this option enabled
65762+ first, and only enable it if your userland does not boot (it will likely fail
65763+ at init time).
65764+
65765+endmenu
65766+menu "Role Based Access Control Options"
65767+depends on GRKERNSEC
65768+
65769+config GRKERNSEC_RBAC_DEBUG
65770+ bool
65771+
65772+config GRKERNSEC_NO_RBAC
65773+ bool "Disable RBAC system"
65774+ help
65775+ If you say Y here, the /dev/grsec device will be removed from the kernel,
65776+ preventing the RBAC system from being enabled. You should only say Y
65777+ here if you have no intention of using the RBAC system, so as to prevent
65778+ an attacker with root access from misusing the RBAC system to hide files
65779+ and processes when loadable module support and /dev/[k]mem have been
65780+ locked down.
65781+
65782+config GRKERNSEC_ACL_HIDEKERN
65783+ bool "Hide kernel processes"
65784+ help
65785+ If you say Y here, all kernel threads will be hidden to all
65786+ processes but those whose subject has the "view hidden processes"
65787+ flag.
65788+
65789+config GRKERNSEC_ACL_MAXTRIES
65790+ int "Maximum tries before password lockout"
65791+ default 3
65792+ help
65793+ This option enforces the maximum number of times a user can attempt
65794+ to authorize themselves with the grsecurity RBAC system before being
65795+ denied the ability to attempt authorization again for a specified time.
65796+ The lower the number, the harder it will be to brute-force a password.
65797+
65798+config GRKERNSEC_ACL_TIMEOUT
65799+ int "Time to wait after max password tries, in seconds"
65800+ default 30
65801+ help
65802+ This option specifies the time the user must wait after attempting to
65803+ authorize to the RBAC system with the maximum number of invalid
65804+ passwords. The higher the number, the harder it will be to brute-force
65805+ a password.
65806+
65807+endmenu
65808+menu "Filesystem Protections"
65809+depends on GRKERNSEC
65810+
65811+config GRKERNSEC_PROC
65812+ bool "Proc restrictions"
65813+ default y if GRKERNSEC_CONFIG_AUTO
65814+ help
65815+ If you say Y here, the permissions of the /proc filesystem
65816+ will be altered to enhance system security and privacy. You MUST
65817+ choose either a user only restriction or a user and group restriction.
65818+ Depending upon the option you choose, you can either restrict users to
65819+ see only the processes they themselves run, or choose a group that can
65820+ view all processes and files normally restricted to root if you choose
65821+ the "restrict to user only" option. NOTE: If you're running identd or
65822+ ntpd as a non-root user, you will have to run it as the group you
65823+ specify here.
65824+
65825+config GRKERNSEC_PROC_USER
65826+ bool "Restrict /proc to user only"
65827+ depends on GRKERNSEC_PROC
65828+ help
65829+ If you say Y here, non-root users will only be able to view their own
65830+ processes, and restricts them from viewing network-related information,
65831+ and viewing kernel symbol and module information.
65832+
65833+config GRKERNSEC_PROC_USERGROUP
65834+ bool "Allow special group"
65835+ default y if GRKERNSEC_CONFIG_AUTO
65836+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65837+ help
65838+ If you say Y here, you will be able to select a group that will be
65839+ able to view all processes and network-related information. If you've
65840+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65841+ remain hidden. This option is useful if you want to run identd as
65842+ a non-root user. The group you select may also be chosen at boot time
65843+ via "grsec_proc_gid=" on the kernel commandline.
65844+
65845+config GRKERNSEC_PROC_GID
65846+ int "GID for special group"
65847+ depends on GRKERNSEC_PROC_USERGROUP
65848+ default 1001
65849+
65850+config GRKERNSEC_PROC_ADD
65851+ bool "Additional restrictions"
65852+ default y if GRKERNSEC_CONFIG_AUTO
65853+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65854+ help
65855+ If you say Y here, additional restrictions will be placed on
65856+ /proc that keep normal users from viewing device information and
65857+ slabinfo information that could be useful for exploits.
65858+
65859+config GRKERNSEC_LINK
65860+ bool "Linking restrictions"
65861+ default y if GRKERNSEC_CONFIG_AUTO
65862+ help
65863+ If you say Y here, /tmp race exploits will be prevented, since users
65864+ will no longer be able to follow symlinks owned by other users in
65865+ world-writable +t directories (e.g. /tmp), unless the owner of the
65866+ symlink is the owner of the directory. users will also not be
65867+ able to hardlink to files they do not own. If the sysctl option is
65868+ enabled, a sysctl option with name "linking_restrictions" is created.
65869+
65870+config GRKERNSEC_SYMLINKOWN
65871+ bool "Kernel-enforced SymlinksIfOwnerMatch"
65872+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65873+ help
65874+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
65875+ that prevents it from being used as a security feature. As Apache
65876+ verifies the symlink by performing a stat() against the target of
65877+ the symlink before it is followed, an attacker can setup a symlink
65878+ to point to a same-owned file, then replace the symlink with one
65879+ that targets another user's file just after Apache "validates" the
65880+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
65881+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65882+ will be in place for the group you specify. If the sysctl option
65883+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
65884+ created.
65885+
65886+config GRKERNSEC_SYMLINKOWN_GID
65887+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
65888+ depends on GRKERNSEC_SYMLINKOWN
65889+ default 1006
65890+ help
65891+ Setting this GID determines what group kernel-enforced
65892+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
65893+ is enabled, a sysctl option with name "symlinkown_gid" is created.
65894+
65895+config GRKERNSEC_FIFO
65896+ bool "FIFO restrictions"
65897+ default y if GRKERNSEC_CONFIG_AUTO
65898+ help
65899+ If you say Y here, users will not be able to write to FIFOs they don't
65900+ own in world-writable +t directories (e.g. /tmp), unless the owner of
65901+ the FIFO is the same owner of the directory it's held in. If the sysctl
65902+ option is enabled, a sysctl option with name "fifo_restrictions" is
65903+ created.
65904+
65905+config GRKERNSEC_SYSFS_RESTRICT
65906+ bool "Sysfs/debugfs restriction"
65907+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65908+ depends on SYSFS
65909+ help
65910+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
65911+ any filesystem normally mounted under it (e.g. debugfs) will be
65912+ mostly accessible only by root. These filesystems generally provide access
65913+ to hardware and debug information that isn't appropriate for unprivileged
65914+ users of the system. Sysfs and debugfs have also become a large source
65915+ of new vulnerabilities, ranging from infoleaks to local compromise.
65916+ There has been very little oversight with an eye toward security involved
65917+ in adding new exporters of information to these filesystems, so their
65918+ use is discouraged.
65919+ For reasons of compatibility, a few directories have been whitelisted
65920+ for access by non-root users:
65921+ /sys/fs/selinux
65922+ /sys/fs/fuse
65923+ /sys/devices/system/cpu
65924+
65925+config GRKERNSEC_ROFS
65926+ bool "Runtime read-only mount protection"
65927+ depends on SYSCTL
65928+ help
65929+ If you say Y here, a sysctl option with name "romount_protect" will
65930+ be created. By setting this option to 1 at runtime, filesystems
65931+ will be protected in the following ways:
65932+ * No new writable mounts will be allowed
65933+ * Existing read-only mounts won't be able to be remounted read/write
65934+ * Write operations will be denied on all block devices
65935+ This option acts independently of grsec_lock: once it is set to 1,
65936+ it cannot be turned off. Therefore, please be mindful of the resulting
65937+ behavior if this option is enabled in an init script on a read-only
65938+ filesystem.
65939+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
65940+ and GRKERNSEC_IO should be enabled and module loading disabled via
65941+ config or at runtime.
65942+ This feature is mainly intended for secure embedded systems.
65943+
65944+
65945+config GRKERNSEC_DEVICE_SIDECHANNEL
65946+ bool "Eliminate stat/notify-based device sidechannels"
65947+ default y if GRKERNSEC_CONFIG_AUTO
65948+ help
65949+ If you say Y here, timing analyses on block or character
65950+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
65951+ will be thwarted for unprivileged users. If a process without
65952+ CAP_MKNOD stats such a device, the last access and last modify times
65953+ will match the device's create time. No access or modify events
65954+ will be triggered through inotify/dnotify/fanotify for such devices.
65955+ This feature will prevent attacks that may at a minimum
65956+ allow an attacker to determine the administrator's password length.
65957+
65958+config GRKERNSEC_CHROOT
65959+ bool "Chroot jail restrictions"
65960+ default y if GRKERNSEC_CONFIG_AUTO
65961+ help
65962+ If you say Y here, you will be able to choose several options that will
65963+ make breaking out of a chrooted jail much more difficult. If you
65964+ encounter no software incompatibilities with the following options, it
65965+ is recommended that you enable each one.
65966+
65967+ Note that the chroot restrictions are not intended to apply to "chroots"
65968+ to directories that are simple bind mounts of the global root filesystem.
65969+ For several other reasons, a user shouldn't expect any significant
65970+ security by performing such a chroot.
65971+
65972+config GRKERNSEC_CHROOT_MOUNT
65973+ bool "Deny mounts"
65974+ default y if GRKERNSEC_CONFIG_AUTO
65975+ depends on GRKERNSEC_CHROOT
65976+ help
65977+ If you say Y here, processes inside a chroot will not be able to
65978+ mount or remount filesystems. If the sysctl option is enabled, a
65979+ sysctl option with name "chroot_deny_mount" is created.
65980+
65981+config GRKERNSEC_CHROOT_DOUBLE
65982+ bool "Deny double-chroots"
65983+ default y if GRKERNSEC_CONFIG_AUTO
65984+ depends on GRKERNSEC_CHROOT
65985+ help
65986+ If you say Y here, processes inside a chroot will not be able to chroot
65987+ again outside the chroot. This is a widely used method of breaking
65988+ out of a chroot jail and should not be allowed. If the sysctl
65989+ option is enabled, a sysctl option with name
65990+ "chroot_deny_chroot" is created.
65991+
65992+config GRKERNSEC_CHROOT_PIVOT
65993+ bool "Deny pivot_root in chroot"
65994+ default y if GRKERNSEC_CONFIG_AUTO
65995+ depends on GRKERNSEC_CHROOT
65996+ help
65997+ If you say Y here, processes inside a chroot will not be able to use
65998+ a function called pivot_root() that was introduced in Linux 2.3.41. It
65999+ works similar to chroot in that it changes the root filesystem. This
66000+ function could be misused in a chrooted process to attempt to break out
66001+ of the chroot, and therefore should not be allowed. If the sysctl
66002+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
66003+ created.
66004+
66005+config GRKERNSEC_CHROOT_CHDIR
66006+ bool "Enforce chdir(\"/\") on all chroots"
66007+ default y if GRKERNSEC_CONFIG_AUTO
66008+ depends on GRKERNSEC_CHROOT
66009+ help
66010+ If you say Y here, the current working directory of all newly-chrooted
66011+ applications will be set to the the root directory of the chroot.
66012+ The man page on chroot(2) states:
66013+ Note that this call does not change the current working
66014+ directory, so that `.' can be outside the tree rooted at
66015+ `/'. In particular, the super-user can escape from a
66016+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66017+
66018+ It is recommended that you say Y here, since it's not known to break
66019+ any software. If the sysctl option is enabled, a sysctl option with
66020+ name "chroot_enforce_chdir" is created.
66021+
66022+config GRKERNSEC_CHROOT_CHMOD
66023+ bool "Deny (f)chmod +s"
66024+ default y if GRKERNSEC_CONFIG_AUTO
66025+ depends on GRKERNSEC_CHROOT
66026+ help
66027+ If you say Y here, processes inside a chroot will not be able to chmod
66028+ or fchmod files to make them have suid or sgid bits. This protects
66029+ against another published method of breaking a chroot. If the sysctl
66030+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
66031+ created.
66032+
66033+config GRKERNSEC_CHROOT_FCHDIR
66034+ bool "Deny fchdir and fhandle out of chroot"
66035+ default y if GRKERNSEC_CONFIG_AUTO
66036+ depends on GRKERNSEC_CHROOT
66037+ help
66038+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
66039+ to a file descriptor of the chrooting process that points to a directory
66040+ outside the filesystem will be stopped. Additionally, this option prevents
66041+ use of the recently-created syscall for opening files by a guessable "file
66042+ handle" inside a chroot. If the sysctl option is enabled, a sysctl option
66043+ with name "chroot_deny_fchdir" is created.
66044+
66045+config GRKERNSEC_CHROOT_MKNOD
66046+ bool "Deny mknod"
66047+ default y if GRKERNSEC_CONFIG_AUTO
66048+ depends on GRKERNSEC_CHROOT
66049+ help
66050+ If you say Y here, processes inside a chroot will not be allowed to
66051+ mknod. The problem with using mknod inside a chroot is that it
66052+ would allow an attacker to create a device entry that is the same
66053+ as one on the physical root of your system, which could range from
66054+ anything from the console device to a device for your harddrive (which
66055+ they could then use to wipe the drive or steal data). It is recommended
66056+ that you say Y here, unless you run into software incompatibilities.
66057+ If the sysctl option is enabled, a sysctl option with name
66058+ "chroot_deny_mknod" is created.
66059+
66060+config GRKERNSEC_CHROOT_SHMAT
66061+ bool "Deny shmat() out of chroot"
66062+ default y if GRKERNSEC_CONFIG_AUTO
66063+ depends on GRKERNSEC_CHROOT
66064+ help
66065+ If you say Y here, processes inside a chroot will not be able to attach
66066+ to shared memory segments that were created outside of the chroot jail.
66067+ It is recommended that you say Y here. If the sysctl option is enabled,
66068+ a sysctl option with name "chroot_deny_shmat" is created.
66069+
66070+config GRKERNSEC_CHROOT_UNIX
66071+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
66072+ default y if GRKERNSEC_CONFIG_AUTO
66073+ depends on GRKERNSEC_CHROOT
66074+ help
66075+ If you say Y here, processes inside a chroot will not be able to
66076+ connect to abstract (meaning not belonging to a filesystem) Unix
66077+ domain sockets that were bound outside of a chroot. It is recommended
66078+ that you say Y here. If the sysctl option is enabled, a sysctl option
66079+ with name "chroot_deny_unix" is created.
66080+
66081+config GRKERNSEC_CHROOT_FINDTASK
66082+ bool "Protect outside processes"
66083+ default y if GRKERNSEC_CONFIG_AUTO
66084+ depends on GRKERNSEC_CHROOT
66085+ help
66086+ If you say Y here, processes inside a chroot will not be able to
66087+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66088+ getsid, or view any process outside of the chroot. If the sysctl
66089+ option is enabled, a sysctl option with name "chroot_findtask" is
66090+ created.
66091+
66092+config GRKERNSEC_CHROOT_NICE
66093+ bool "Restrict priority changes"
66094+ default y if GRKERNSEC_CONFIG_AUTO
66095+ depends on GRKERNSEC_CHROOT
66096+ help
66097+ If you say Y here, processes inside a chroot will not be able to raise
66098+ the priority of processes in the chroot, or alter the priority of
66099+ processes outside the chroot. This provides more security than simply
66100+ removing CAP_SYS_NICE from the process' capability set. If the
66101+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66102+ is created.
66103+
66104+config GRKERNSEC_CHROOT_SYSCTL
66105+ bool "Deny sysctl writes"
66106+ default y if GRKERNSEC_CONFIG_AUTO
66107+ depends on GRKERNSEC_CHROOT
66108+ help
66109+ If you say Y here, an attacker in a chroot will not be able to
66110+ write to sysctl entries, either by sysctl(2) or through a /proc
66111+ interface. It is strongly recommended that you say Y here. If the
66112+ sysctl option is enabled, a sysctl option with name
66113+ "chroot_deny_sysctl" is created.
66114+
66115+config GRKERNSEC_CHROOT_CAPS
66116+ bool "Capability restrictions"
66117+ default y if GRKERNSEC_CONFIG_AUTO
66118+ depends on GRKERNSEC_CHROOT
66119+ help
66120+ If you say Y here, the capabilities on all processes within a
66121+ chroot jail will be lowered to stop module insertion, raw i/o,
66122+ system and net admin tasks, rebooting the system, modifying immutable
66123+ files, modifying IPC owned by another, and changing the system time.
66124+ This is left an option because it can break some apps. Disable this
66125+ if your chrooted apps are having problems performing those kinds of
66126+ tasks. If the sysctl option is enabled, a sysctl option with
66127+ name "chroot_caps" is created.
66128+
66129+config GRKERNSEC_CHROOT_INITRD
66130+ bool "Exempt initrd tasks from restrictions"
66131+ default y if GRKERNSEC_CONFIG_AUTO
66132+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66133+ help
66134+ If you say Y here, tasks started prior to init will be exempted from
66135+ grsecurity's chroot restrictions. This option is mainly meant to
66136+ resolve Plymouth's performing privileged operations unnecessarily
66137+ in a chroot.
66138+
66139+endmenu
66140+menu "Kernel Auditing"
66141+depends on GRKERNSEC
66142+
66143+config GRKERNSEC_AUDIT_GROUP
66144+ bool "Single group for auditing"
66145+ help
66146+ If you say Y here, the exec and chdir logging features will only operate
66147+ on a group you specify. This option is recommended if you only want to
66148+ watch certain users instead of having a large amount of logs from the
66149+ entire system. If the sysctl option is enabled, a sysctl option with
66150+ name "audit_group" is created.
66151+
66152+config GRKERNSEC_AUDIT_GID
66153+ int "GID for auditing"
66154+ depends on GRKERNSEC_AUDIT_GROUP
66155+ default 1007
66156+
66157+config GRKERNSEC_EXECLOG
66158+ bool "Exec logging"
66159+ help
66160+ If you say Y here, all execve() calls will be logged (since the
66161+ other exec*() calls are frontends to execve(), all execution
66162+ will be logged). Useful for shell-servers that like to keep track
66163+ of their users. If the sysctl option is enabled, a sysctl option with
66164+ name "exec_logging" is created.
66165+ WARNING: This option when enabled will produce a LOT of logs, especially
66166+ on an active system.
66167+
66168+config GRKERNSEC_RESLOG
66169+ bool "Resource logging"
66170+ default y if GRKERNSEC_CONFIG_AUTO
66171+ help
66172+ If you say Y here, all attempts to overstep resource limits will
66173+ be logged with the resource name, the requested size, and the current
66174+ limit. It is highly recommended that you say Y here. If the sysctl
66175+ option is enabled, a sysctl option with name "resource_logging" is
66176+ created. If the RBAC system is enabled, the sysctl value is ignored.
66177+
66178+config GRKERNSEC_CHROOT_EXECLOG
66179+ bool "Log execs within chroot"
66180+ help
66181+ If you say Y here, all executions inside a chroot jail will be logged
66182+ to syslog. This can cause a large amount of logs if certain
66183+ applications (eg. djb's daemontools) are installed on the system, and
66184+ is therefore left as an option. If the sysctl option is enabled, a
66185+ sysctl option with name "chroot_execlog" is created.
66186+
66187+config GRKERNSEC_AUDIT_PTRACE
66188+ bool "Ptrace logging"
66189+ help
66190+ If you say Y here, all attempts to attach to a process via ptrace
66191+ will be logged. If the sysctl option is enabled, a sysctl option
66192+ with name "audit_ptrace" is created.
66193+
66194+config GRKERNSEC_AUDIT_CHDIR
66195+ bool "Chdir logging"
66196+ help
66197+ If you say Y here, all chdir() calls will be logged. If the sysctl
66198+ option is enabled, a sysctl option with name "audit_chdir" is created.
66199+
66200+config GRKERNSEC_AUDIT_MOUNT
66201+ bool "(Un)Mount logging"
66202+ help
66203+ If you say Y here, all mounts and unmounts will be logged. If the
66204+ sysctl option is enabled, a sysctl option with name "audit_mount" is
66205+ created.
66206+
66207+config GRKERNSEC_SIGNAL
66208+ bool "Signal logging"
66209+ default y if GRKERNSEC_CONFIG_AUTO
66210+ help
66211+ If you say Y here, certain important signals will be logged, such as
66212+ SIGSEGV, which will as a result inform you of when a error in a program
66213+ occurred, which in some cases could mean a possible exploit attempt.
66214+ If the sysctl option is enabled, a sysctl option with name
66215+ "signal_logging" is created.
66216+
66217+config GRKERNSEC_FORKFAIL
66218+ bool "Fork failure logging"
66219+ help
66220+ If you say Y here, all failed fork() attempts will be logged.
66221+ This could suggest a fork bomb, or someone attempting to overstep
66222+ their process limit. If the sysctl option is enabled, a sysctl option
66223+ with name "forkfail_logging" is created.
66224+
66225+config GRKERNSEC_TIME
66226+ bool "Time change logging"
66227+ default y if GRKERNSEC_CONFIG_AUTO
66228+ help
66229+ If you say Y here, any changes of the system clock will be logged.
66230+ If the sysctl option is enabled, a sysctl option with name
66231+ "timechange_logging" is created.
66232+
66233+config GRKERNSEC_PROC_IPADDR
66234+ bool "/proc/<pid>/ipaddr support"
66235+ default y if GRKERNSEC_CONFIG_AUTO
66236+ help
66237+ If you say Y here, a new entry will be added to each /proc/<pid>
66238+ directory that contains the IP address of the person using the task.
66239+ The IP is carried across local TCP and AF_UNIX stream sockets.
66240+ This information can be useful for IDS/IPSes to perform remote response
66241+ to a local attack. The entry is readable by only the owner of the
66242+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66243+ the RBAC system), and thus does not create privacy concerns.
66244+
66245+config GRKERNSEC_RWXMAP_LOG
66246+ bool 'Denied RWX mmap/mprotect logging'
66247+ default y if GRKERNSEC_CONFIG_AUTO
66248+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66249+ help
66250+ If you say Y here, calls to mmap() and mprotect() with explicit
66251+ usage of PROT_WRITE and PROT_EXEC together will be logged when
66252+ denied by the PAX_MPROTECT feature. This feature will also
66253+ log other problematic scenarios that can occur when PAX_MPROTECT
66254+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
66255+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66256+ is created.
66257+
66258+endmenu
66259+
66260+menu "Executable Protections"
66261+depends on GRKERNSEC
66262+
66263+config GRKERNSEC_DMESG
66264+ bool "Dmesg(8) restriction"
66265+ default y if GRKERNSEC_CONFIG_AUTO
66266+ help
66267+ If you say Y here, non-root users will not be able to use dmesg(8)
66268+ to view the contents of the kernel's circular log buffer.
66269+ The kernel's log buffer often contains kernel addresses and other
66270+ identifying information useful to an attacker in fingerprinting a
66271+ system for a targeted exploit.
66272+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
66273+ created.
66274+
66275+config GRKERNSEC_HARDEN_PTRACE
66276+ bool "Deter ptrace-based process snooping"
66277+ default y if GRKERNSEC_CONFIG_AUTO
66278+ help
66279+ If you say Y here, TTY sniffers and other malicious monitoring
66280+ programs implemented through ptrace will be defeated. If you
66281+ have been using the RBAC system, this option has already been
66282+ enabled for several years for all users, with the ability to make
66283+ fine-grained exceptions.
66284+
66285+ This option only affects the ability of non-root users to ptrace
66286+ processes that are not a descendent of the ptracing process.
66287+ This means that strace ./binary and gdb ./binary will still work,
66288+ but attaching to arbitrary processes will not. If the sysctl
66289+ option is enabled, a sysctl option with name "harden_ptrace" is
66290+ created.
66291+
66292+config GRKERNSEC_PTRACE_READEXEC
66293+ bool "Require read access to ptrace sensitive binaries"
66294+ default y if GRKERNSEC_CONFIG_AUTO
66295+ help
66296+ If you say Y here, unprivileged users will not be able to ptrace unreadable
66297+ binaries. This option is useful in environments that
66298+ remove the read bits (e.g. file mode 4711) from suid binaries to
66299+ prevent infoleaking of their contents. This option adds
66300+ consistency to the use of that file mode, as the binary could normally
66301+ be read out when run without privileges while ptracing.
66302+
66303+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66304+ is created.
66305+
66306+config GRKERNSEC_SETXID
66307+ bool "Enforce consistent multithreaded privileges"
66308+ default y if GRKERNSEC_CONFIG_AUTO
66309+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66310+ help
66311+ If you say Y here, a change from a root uid to a non-root uid
66312+ in a multithreaded application will cause the resulting uids,
66313+ gids, supplementary groups, and capabilities in that thread
66314+ to be propagated to the other threads of the process. In most
66315+ cases this is unnecessary, as glibc will emulate this behavior
66316+ on behalf of the application. Other libcs do not act in the
66317+ same way, allowing the other threads of the process to continue
66318+ running with root privileges. If the sysctl option is enabled,
66319+ a sysctl option with name "consistent_setxid" is created.
66320+
66321+config GRKERNSEC_HARDEN_IPC
66322+ bool "Disallow access to overly-permissive IPC objects"
66323+ default y if GRKERNSEC_CONFIG_AUTO
66324+ depends on SYSVIPC
66325+ help
66326+ If you say Y here, access to overly-permissive IPC objects (shared
66327+ memory, message queues, and semaphores) will be denied for processes
66328+ given the following criteria beyond normal permission checks:
66329+ 1) If the IPC object is world-accessible and the euid doesn't match
66330+ that of the creator or current uid for the IPC object
66331+ 2) If the IPC object is group-accessible and the egid doesn't
66332+ match that of the creator or current gid for the IPC object
66333+ It's a common error to grant too much permission to these objects,
66334+ with impact ranging from denial of service and information leaking to
66335+ privilege escalation. This feature was developed in response to
66336+ research by Tim Brown:
66337+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66338+ who found hundreds of such insecure usages. Processes with
66339+ CAP_IPC_OWNER are still permitted to access these IPC objects.
66340+ If the sysctl option is enabled, a sysctl option with name
66341+ "harden_ipc" is created.
66342+
66343+config GRKERNSEC_TPE
66344+ bool "Trusted Path Execution (TPE)"
66345+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66346+ help
66347+ If you say Y here, you will be able to choose a gid to add to the
66348+ supplementary groups of users you want to mark as "untrusted."
66349+ These users will not be able to execute any files that are not in
66350+ root-owned directories writable only by root. If the sysctl option
66351+ is enabled, a sysctl option with name "tpe" is created.
66352+
66353+config GRKERNSEC_TPE_ALL
66354+ bool "Partially restrict all non-root users"
66355+ depends on GRKERNSEC_TPE
66356+ help
66357+ If you say Y here, all non-root users will be covered under
66358+ a weaker TPE restriction. This is separate from, and in addition to,
66359+ the main TPE options that you have selected elsewhere. Thus, if a
66360+ "trusted" GID is chosen, this restriction applies to even that GID.
66361+ Under this restriction, all non-root users will only be allowed to
66362+ execute files in directories they own that are not group or
66363+ world-writable, or in directories owned by root and writable only by
66364+ root. If the sysctl option is enabled, a sysctl option with name
66365+ "tpe_restrict_all" is created.
66366+
66367+config GRKERNSEC_TPE_INVERT
66368+ bool "Invert GID option"
66369+ depends on GRKERNSEC_TPE
66370+ help
66371+ If you say Y here, the group you specify in the TPE configuration will
66372+ decide what group TPE restrictions will be *disabled* for. This
66373+ option is useful if you want TPE restrictions to be applied to most
66374+ users on the system. If the sysctl option is enabled, a sysctl option
66375+ with name "tpe_invert" is created. Unlike other sysctl options, this
66376+ entry will default to on for backward-compatibility.
66377+
66378+config GRKERNSEC_TPE_GID
66379+ int
66380+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66381+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66382+
66383+config GRKERNSEC_TPE_UNTRUSTED_GID
66384+ int "GID for TPE-untrusted users"
66385+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66386+ default 1005
66387+ help
66388+ Setting this GID determines what group TPE restrictions will be
66389+ *enabled* for. If the sysctl option is enabled, a sysctl option
66390+ with name "tpe_gid" is created.
66391+
66392+config GRKERNSEC_TPE_TRUSTED_GID
66393+ int "GID for TPE-trusted users"
66394+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66395+ default 1005
66396+ help
66397+ Setting this GID determines what group TPE restrictions will be
66398+ *disabled* for. If the sysctl option is enabled, a sysctl option
66399+ with name "tpe_gid" is created.
66400+
66401+endmenu
66402+menu "Network Protections"
66403+depends on GRKERNSEC
66404+
66405+config GRKERNSEC_RANDNET
66406+ bool "Larger entropy pools"
66407+ default y if GRKERNSEC_CONFIG_AUTO
66408+ help
66409+ If you say Y here, the entropy pools used for many features of Linux
66410+ and grsecurity will be doubled in size. Since several grsecurity
66411+ features use additional randomness, it is recommended that you say Y
66412+ here. Saying Y here has a similar effect as modifying
66413+ /proc/sys/kernel/random/poolsize.
66414+
66415+config GRKERNSEC_BLACKHOLE
66416+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66417+ default y if GRKERNSEC_CONFIG_AUTO
66418+ depends on NET
66419+ help
66420+ If you say Y here, neither TCP resets nor ICMP
66421+ destination-unreachable packets will be sent in response to packets
66422+ sent to ports for which no associated listening process exists.
66423+ This feature supports both IPV4 and IPV6 and exempts the
66424+ loopback interface from blackholing. Enabling this feature
66425+ makes a host more resilient to DoS attacks and reduces network
66426+ visibility against scanners.
66427+
66428+ The blackhole feature as-implemented is equivalent to the FreeBSD
66429+ blackhole feature, as it prevents RST responses to all packets, not
66430+ just SYNs. Under most application behavior this causes no
66431+ problems, but applications (like haproxy) may not close certain
66432+ connections in a way that cleanly terminates them on the remote
66433+ end, leaving the remote host in LAST_ACK state. Because of this
66434+ side-effect and to prevent intentional LAST_ACK DoSes, this
66435+ feature also adds automatic mitigation against such attacks.
66436+ The mitigation drastically reduces the amount of time a socket
66437+ can spend in LAST_ACK state. If you're using haproxy and not
66438+ all servers it connects to have this option enabled, consider
66439+ disabling this feature on the haproxy host.
66440+
66441+ If the sysctl option is enabled, two sysctl options with names
66442+ "ip_blackhole" and "lastack_retries" will be created.
66443+ While "ip_blackhole" takes the standard zero/non-zero on/off
66444+ toggle, "lastack_retries" uses the same kinds of values as
66445+ "tcp_retries1" and "tcp_retries2". The default value of 4
66446+ prevents a socket from lasting more than 45 seconds in LAST_ACK
66447+ state.
66448+
66449+config GRKERNSEC_NO_SIMULT_CONNECT
66450+ bool "Disable TCP Simultaneous Connect"
66451+ default y if GRKERNSEC_CONFIG_AUTO
66452+ depends on NET
66453+ help
66454+ If you say Y here, a feature by Willy Tarreau will be enabled that
66455+ removes a weakness in Linux's strict implementation of TCP that
66456+ allows two clients to connect to each other without either entering
66457+ a listening state. The weakness allows an attacker to easily prevent
66458+ a client from connecting to a known server provided the source port
66459+ for the connection is guessed correctly.
66460+
66461+ As the weakness could be used to prevent an antivirus or IPS from
66462+ fetching updates, or prevent an SSL gateway from fetching a CRL,
66463+ it should be eliminated by enabling this option. Though Linux is
66464+ one of few operating systems supporting simultaneous connect, it
66465+ has no legitimate use in practice and is rarely supported by firewalls.
66466+
66467+config GRKERNSEC_SOCKET
66468+ bool "Socket restrictions"
66469+ depends on NET
66470+ help
66471+ If you say Y here, you will be able to choose from several options.
66472+ If you assign a GID on your system and add it to the supplementary
66473+ groups of users you want to restrict socket access to, this patch
66474+ will perform up to three things, based on the option(s) you choose.
66475+
66476+config GRKERNSEC_SOCKET_ALL
66477+ bool "Deny any sockets to group"
66478+ depends on GRKERNSEC_SOCKET
66479+ help
66480+ If you say Y here, you will be able to choose a GID of whose users will
66481+ be unable to connect to other hosts from your machine or run server
66482+ applications from your machine. If the sysctl option is enabled, a
66483+ sysctl option with name "socket_all" is created.
66484+
66485+config GRKERNSEC_SOCKET_ALL_GID
66486+ int "GID to deny all sockets for"
66487+ depends on GRKERNSEC_SOCKET_ALL
66488+ default 1004
66489+ help
66490+ Here you can choose the GID to disable socket access for. Remember to
66491+ add the users you want socket access disabled for to the GID
66492+ specified here. If the sysctl option is enabled, a sysctl option
66493+ with name "socket_all_gid" is created.
66494+
66495+config GRKERNSEC_SOCKET_CLIENT
66496+ bool "Deny client sockets to group"
66497+ depends on GRKERNSEC_SOCKET
66498+ help
66499+ If you say Y here, you will be able to choose a GID of whose users will
66500+ be unable to connect to other hosts from your machine, but will be
66501+ able to run servers. If this option is enabled, all users in the group
66502+ you specify will have to use passive mode when initiating ftp transfers
66503+ from the shell on your machine. If the sysctl option is enabled, a
66504+ sysctl option with name "socket_client" is created.
66505+
66506+config GRKERNSEC_SOCKET_CLIENT_GID
66507+ int "GID to deny client sockets for"
66508+ depends on GRKERNSEC_SOCKET_CLIENT
66509+ default 1003
66510+ help
66511+ Here you can choose the GID to disable client socket access for.
66512+ Remember to add the users you want client socket access disabled for to
66513+ the GID specified here. If the sysctl option is enabled, a sysctl
66514+ option with name "socket_client_gid" is created.
66515+
66516+config GRKERNSEC_SOCKET_SERVER
66517+ bool "Deny server sockets to group"
66518+ depends on GRKERNSEC_SOCKET
66519+ help
66520+ If you say Y here, you will be able to choose a GID of whose users will
66521+ be unable to run server applications from your machine. If the sysctl
66522+ option is enabled, a sysctl option with name "socket_server" is created.
66523+
66524+config GRKERNSEC_SOCKET_SERVER_GID
66525+ int "GID to deny server sockets for"
66526+ depends on GRKERNSEC_SOCKET_SERVER
66527+ default 1002
66528+ help
66529+ Here you can choose the GID to disable server socket access for.
66530+ Remember to add the users you want server socket access disabled for to
66531+ the GID specified here. If the sysctl option is enabled, a sysctl
66532+ option with name "socket_server_gid" is created.
66533+
66534+endmenu
66535+
66536+menu "Physical Protections"
66537+depends on GRKERNSEC
66538+
66539+config GRKERNSEC_DENYUSB
66540+ bool "Deny new USB connections after toggle"
66541+ default y if GRKERNSEC_CONFIG_AUTO
66542+ depends on SYSCTL && USB_SUPPORT
66543+ help
66544+ If you say Y here, a new sysctl option with name "deny_new_usb"
66545+ will be created. Setting its value to 1 will prevent any new
66546+ USB devices from being recognized by the OS. Any attempted USB
66547+ device insertion will be logged. This option is intended to be
66548+ used against custom USB devices designed to exploit vulnerabilities
66549+ in various USB device drivers.
66550+
66551+ For greatest effectiveness, this sysctl should be set after any
66552+ relevant init scripts. This option is safe to enable in distros
66553+ as each user can choose whether or not to toggle the sysctl.
66554+
66555+config GRKERNSEC_DENYUSB_FORCE
66556+ bool "Reject all USB devices not connected at boot"
66557+ select USB
66558+ depends on GRKERNSEC_DENYUSB
66559+ help
66560+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66561+ that doesn't involve a sysctl entry. This option should only be
66562+ enabled if you're sure you want to deny all new USB connections
66563+ at runtime and don't want to modify init scripts. This should not
66564+ be enabled by distros. It forces the core USB code to be built
66565+ into the kernel image so that all devices connected at boot time
66566+ can be recognized and new USB device connections can be prevented
66567+ prior to init running.
66568+
66569+endmenu
66570+
66571+menu "Sysctl Support"
66572+depends on GRKERNSEC && SYSCTL
66573+
66574+config GRKERNSEC_SYSCTL
66575+ bool "Sysctl support"
66576+ default y if GRKERNSEC_CONFIG_AUTO
66577+ help
66578+ If you say Y here, you will be able to change the options that
66579+ grsecurity runs with at bootup, without having to recompile your
66580+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66581+ to enable (1) or disable (0) various features. All the sysctl entries
66582+ are mutable until the "grsec_lock" entry is set to a non-zero value.
66583+ All features enabled in the kernel configuration are disabled at boot
66584+ if you do not say Y to the "Turn on features by default" option.
66585+ All options should be set at startup, and the grsec_lock entry should
66586+ be set to a non-zero value after all the options are set.
66587+ *THIS IS EXTREMELY IMPORTANT*
66588+
66589+config GRKERNSEC_SYSCTL_DISTRO
66590+ bool "Extra sysctl support for distro makers (READ HELP)"
66591+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66592+ help
66593+ If you say Y here, additional sysctl options will be created
66594+ for features that affect processes running as root. Therefore,
66595+ it is critical when using this option that the grsec_lock entry be
66596+ enabled after boot. Only distros with prebuilt kernel packages
66597+ with this option enabled that can ensure grsec_lock is enabled
66598+ after boot should use this option.
66599+ *Failure to set grsec_lock after boot makes all grsec features
66600+ this option covers useless*
66601+
66602+ Currently this option creates the following sysctl entries:
66603+ "Disable Privileged I/O": "disable_priv_io"
66604+
66605+config GRKERNSEC_SYSCTL_ON
66606+ bool "Turn on features by default"
66607+ default y if GRKERNSEC_CONFIG_AUTO
66608+ depends on GRKERNSEC_SYSCTL
66609+ help
66610+ If you say Y here, instead of having all features enabled in the
66611+ kernel configuration disabled at boot time, the features will be
66612+ enabled at boot time. It is recommended you say Y here unless
66613+ there is some reason you would want all sysctl-tunable features to
66614+ be disabled by default. As mentioned elsewhere, it is important
66615+ to enable the grsec_lock entry once you have finished modifying
66616+ the sysctl entries.
66617+
66618+endmenu
66619+menu "Logging Options"
66620+depends on GRKERNSEC
66621+
66622+config GRKERNSEC_FLOODTIME
66623+ int "Seconds in between log messages (minimum)"
66624+ default 10
66625+ help
66626+ This option allows you to enforce the number of seconds between
66627+ grsecurity log messages. The default should be suitable for most
66628+ people, however, if you choose to change it, choose a value small enough
66629+ to allow informative logs to be produced, but large enough to
66630+ prevent flooding.
66631+
66632+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66633+ any rate limiting on grsecurity log messages.
66634+
66635+config GRKERNSEC_FLOODBURST
66636+ int "Number of messages in a burst (maximum)"
66637+ default 6
66638+ help
66639+ This option allows you to choose the maximum number of messages allowed
66640+ within the flood time interval you chose in a separate option. The
66641+ default should be suitable for most people, however if you find that
66642+ many of your logs are being interpreted as flooding, you may want to
66643+ raise this value.
66644+
66645+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66646+ any rate limiting on grsecurity log messages.
66647+
66648+endmenu
66649diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66650new file mode 100644
66651index 0000000..30ababb
66652--- /dev/null
66653+++ b/grsecurity/Makefile
66654@@ -0,0 +1,54 @@
66655+# grsecurity – access control and security hardening for Linux
66656+# All code in this directory and various hooks located throughout the Linux kernel are
66657+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66658+# http://www.grsecurity.net spender@grsecurity.net
66659+#
66660+# This program is free software; you can redistribute it and/or
66661+# modify it under the terms of the GNU General Public License version 2
66662+# as published by the Free Software Foundation.
66663+#
66664+# This program is distributed in the hope that it will be useful,
66665+# but WITHOUT ANY WARRANTY; without even the implied warranty of
66666+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66667+# GNU General Public License for more details.
66668+#
66669+# You should have received a copy of the GNU General Public License
66670+# along with this program; if not, write to the Free Software
66671+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66672+
66673+KBUILD_CFLAGS += -Werror
66674+
66675+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66676+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
66677+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66678+ grsec_usb.o grsec_ipc.o grsec_proc.o
66679+
66680+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66681+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66682+ gracl_learn.o grsec_log.o gracl_policy.o
66683+ifdef CONFIG_COMPAT
66684+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66685+endif
66686+
66687+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66688+
66689+ifdef CONFIG_NET
66690+obj-y += grsec_sock.o
66691+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66692+endif
66693+
66694+ifndef CONFIG_GRKERNSEC
66695+obj-y += grsec_disabled.o
66696+endif
66697+
66698+ifdef CONFIG_GRKERNSEC_HIDESYM
66699+extra-y := grsec_hidesym.o
66700+$(obj)/grsec_hidesym.o:
66701+ @-chmod -f 500 /boot
66702+ @-chmod -f 500 /lib/modules
66703+ @-chmod -f 500 /lib64/modules
66704+ @-chmod -f 500 /lib32/modules
66705+ @-chmod -f 700 .
66706+ @-chmod -f 700 $(objtree)
66707+ @echo ' grsec: protected kernel image paths'
66708+endif
66709diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66710new file mode 100644
66711index 0000000..58223f6
66712--- /dev/null
66713+++ b/grsecurity/gracl.c
66714@@ -0,0 +1,2702 @@
66715+#include <linux/kernel.h>
66716+#include <linux/module.h>
66717+#include <linux/sched.h>
66718+#include <linux/mm.h>
66719+#include <linux/file.h>
66720+#include <linux/fs.h>
66721+#include <linux/namei.h>
66722+#include <linux/mount.h>
66723+#include <linux/tty.h>
66724+#include <linux/proc_fs.h>
66725+#include <linux/lglock.h>
66726+#include <linux/slab.h>
66727+#include <linux/vmalloc.h>
66728+#include <linux/types.h>
66729+#include <linux/sysctl.h>
66730+#include <linux/netdevice.h>
66731+#include <linux/ptrace.h>
66732+#include <linux/gracl.h>
66733+#include <linux/gralloc.h>
66734+#include <linux/security.h>
66735+#include <linux/grinternal.h>
66736+#include <linux/pid_namespace.h>
66737+#include <linux/stop_machine.h>
66738+#include <linux/fdtable.h>
66739+#include <linux/percpu.h>
66740+#include <linux/lglock.h>
66741+#include <linux/hugetlb.h>
66742+#include <linux/posix-timers.h>
66743+#include <linux/prefetch.h>
66744+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66745+#include <linux/magic.h>
66746+#include <linux/pagemap.h>
66747+#include "../fs/btrfs/async-thread.h"
66748+#include "../fs/btrfs/ctree.h"
66749+#include "../fs/btrfs/btrfs_inode.h"
66750+#endif
66751+#include "../fs/mount.h"
66752+
66753+#include <asm/uaccess.h>
66754+#include <asm/errno.h>
66755+#include <asm/mman.h>
66756+
66757+#define FOR_EACH_ROLE_START(role) \
66758+ role = running_polstate.role_list; \
66759+ while (role) {
66760+
66761+#define FOR_EACH_ROLE_END(role) \
66762+ role = role->prev; \
66763+ }
66764+
66765+extern struct path gr_real_root;
66766+
66767+static struct gr_policy_state running_polstate;
66768+struct gr_policy_state *polstate = &running_polstate;
66769+extern struct gr_alloc_state *current_alloc_state;
66770+
66771+extern char *gr_shared_page[4];
66772+DEFINE_RWLOCK(gr_inode_lock);
66773+
66774+static unsigned int gr_status __read_only = GR_STATUS_INIT;
66775+
66776+#ifdef CONFIG_NET
66777+extern struct vfsmount *sock_mnt;
66778+#endif
66779+
66780+extern struct vfsmount *pipe_mnt;
66781+extern struct vfsmount *shm_mnt;
66782+
66783+#ifdef CONFIG_HUGETLBFS
66784+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66785+#endif
66786+
66787+extern u16 acl_sp_role_value;
66788+extern struct acl_object_label *fakefs_obj_rw;
66789+extern struct acl_object_label *fakefs_obj_rwx;
66790+
66791+int gr_acl_is_enabled(void)
66792+{
66793+ return (gr_status & GR_READY);
66794+}
66795+
66796+void gr_enable_rbac_system(void)
66797+{
66798+ pax_open_kernel();
66799+ gr_status |= GR_READY;
66800+ pax_close_kernel();
66801+}
66802+
66803+int gr_rbac_disable(void *unused)
66804+{
66805+ pax_open_kernel();
66806+ gr_status &= ~GR_READY;
66807+ pax_close_kernel();
66808+
66809+ return 0;
66810+}
66811+
66812+static inline dev_t __get_dev(const struct dentry *dentry)
66813+{
66814+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66815+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66816+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
66817+ else
66818+#endif
66819+ return dentry->d_sb->s_dev;
66820+}
66821+
66822+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66823+{
66824+ return __get_dev(dentry);
66825+}
66826+
66827+static char gr_task_roletype_to_char(struct task_struct *task)
66828+{
66829+ switch (task->role->roletype &
66830+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66831+ GR_ROLE_SPECIAL)) {
66832+ case GR_ROLE_DEFAULT:
66833+ return 'D';
66834+ case GR_ROLE_USER:
66835+ return 'U';
66836+ case GR_ROLE_GROUP:
66837+ return 'G';
66838+ case GR_ROLE_SPECIAL:
66839+ return 'S';
66840+ }
66841+
66842+ return 'X';
66843+}
66844+
66845+char gr_roletype_to_char(void)
66846+{
66847+ return gr_task_roletype_to_char(current);
66848+}
66849+
66850+__inline__ int
66851+gr_acl_tpe_check(void)
66852+{
66853+ if (unlikely(!(gr_status & GR_READY)))
66854+ return 0;
66855+ if (current->role->roletype & GR_ROLE_TPE)
66856+ return 1;
66857+ else
66858+ return 0;
66859+}
66860+
66861+int
66862+gr_handle_rawio(const struct inode *inode)
66863+{
66864+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66865+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66866+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66867+ !capable(CAP_SYS_RAWIO))
66868+ return 1;
66869+#endif
66870+ return 0;
66871+}
66872+
66873+int
66874+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66875+{
66876+ if (likely(lena != lenb))
66877+ return 0;
66878+
66879+ return !memcmp(a, b, lena);
66880+}
66881+
66882+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66883+{
66884+ *buflen -= namelen;
66885+ if (*buflen < 0)
66886+ return -ENAMETOOLONG;
66887+ *buffer -= namelen;
66888+ memcpy(*buffer, str, namelen);
66889+ return 0;
66890+}
66891+
66892+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
66893+{
66894+ return prepend(buffer, buflen, name->name, name->len);
66895+}
66896+
66897+static int prepend_path(const struct path *path, struct path *root,
66898+ char **buffer, int *buflen)
66899+{
66900+ struct dentry *dentry = path->dentry;
66901+ struct vfsmount *vfsmnt = path->mnt;
66902+ struct mount *mnt = real_mount(vfsmnt);
66903+ bool slash = false;
66904+ int error = 0;
66905+
66906+ while (dentry != root->dentry || vfsmnt != root->mnt) {
66907+ struct dentry * parent;
66908+
66909+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
66910+ /* Global root? */
66911+ if (!mnt_has_parent(mnt)) {
66912+ goto out;
66913+ }
66914+ dentry = mnt->mnt_mountpoint;
66915+ mnt = mnt->mnt_parent;
66916+ vfsmnt = &mnt->mnt;
66917+ continue;
66918+ }
66919+ parent = dentry->d_parent;
66920+ prefetch(parent);
66921+ spin_lock(&dentry->d_lock);
66922+ error = prepend_name(buffer, buflen, &dentry->d_name);
66923+ spin_unlock(&dentry->d_lock);
66924+ if (!error)
66925+ error = prepend(buffer, buflen, "/", 1);
66926+ if (error)
66927+ break;
66928+
66929+ slash = true;
66930+ dentry = parent;
66931+ }
66932+
66933+out:
66934+ if (!error && !slash)
66935+ error = prepend(buffer, buflen, "/", 1);
66936+
66937+ return error;
66938+}
66939+
66940+/* this must be called with mount_lock and rename_lock held */
66941+
66942+static char *__our_d_path(const struct path *path, struct path *root,
66943+ char *buf, int buflen)
66944+{
66945+ char *res = buf + buflen;
66946+ int error;
66947+
66948+ prepend(&res, &buflen, "\0", 1);
66949+ error = prepend_path(path, root, &res, &buflen);
66950+ if (error)
66951+ return ERR_PTR(error);
66952+
66953+ return res;
66954+}
66955+
66956+static char *
66957+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
66958+{
66959+ char *retval;
66960+
66961+ retval = __our_d_path(path, root, buf, buflen);
66962+ if (unlikely(IS_ERR(retval)))
66963+ retval = strcpy(buf, "<path too long>");
66964+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
66965+ retval[1] = '\0';
66966+
66967+ return retval;
66968+}
66969+
66970+static char *
66971+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66972+ char *buf, int buflen)
66973+{
66974+ struct path path;
66975+ char *res;
66976+
66977+ path.dentry = (struct dentry *)dentry;
66978+ path.mnt = (struct vfsmount *)vfsmnt;
66979+
66980+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
66981+ by the RBAC system */
66982+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
66983+
66984+ return res;
66985+}
66986+
66987+static char *
66988+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66989+ char *buf, int buflen)
66990+{
66991+ char *res;
66992+ struct path path;
66993+ struct path root;
66994+ struct task_struct *reaper = init_pid_ns.child_reaper;
66995+
66996+ path.dentry = (struct dentry *)dentry;
66997+ path.mnt = (struct vfsmount *)vfsmnt;
66998+
66999+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67000+ get_fs_root(reaper->fs, &root);
67001+
67002+ read_seqlock_excl(&mount_lock);
67003+ write_seqlock(&rename_lock);
67004+ res = gen_full_path(&path, &root, buf, buflen);
67005+ write_sequnlock(&rename_lock);
67006+ read_sequnlock_excl(&mount_lock);
67007+
67008+ path_put(&root);
67009+ return res;
67010+}
67011+
67012+char *
67013+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67014+{
67015+ char *ret;
67016+ read_seqlock_excl(&mount_lock);
67017+ write_seqlock(&rename_lock);
67018+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67019+ PAGE_SIZE);
67020+ write_sequnlock(&rename_lock);
67021+ read_sequnlock_excl(&mount_lock);
67022+ return ret;
67023+}
67024+
67025+static char *
67026+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67027+{
67028+ char *ret;
67029+ char *buf;
67030+ int buflen;
67031+
67032+ read_seqlock_excl(&mount_lock);
67033+ write_seqlock(&rename_lock);
67034+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67035+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67036+ buflen = (int)(ret - buf);
67037+ if (buflen >= 5)
67038+ prepend(&ret, &buflen, "/proc", 5);
67039+ else
67040+ ret = strcpy(buf, "<path too long>");
67041+ write_sequnlock(&rename_lock);
67042+ read_sequnlock_excl(&mount_lock);
67043+ return ret;
67044+}
67045+
67046+char *
67047+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67048+{
67049+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67050+ PAGE_SIZE);
67051+}
67052+
67053+char *
67054+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67055+{
67056+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67057+ PAGE_SIZE);
67058+}
67059+
67060+char *
67061+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67062+{
67063+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67064+ PAGE_SIZE);
67065+}
67066+
67067+char *
67068+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67069+{
67070+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67071+ PAGE_SIZE);
67072+}
67073+
67074+char *
67075+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67076+{
67077+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67078+ PAGE_SIZE);
67079+}
67080+
67081+__inline__ __u32
67082+to_gr_audit(const __u32 reqmode)
67083+{
67084+ /* masks off auditable permission flags, then shifts them to create
67085+ auditing flags, and adds the special case of append auditing if
67086+ we're requesting write */
67087+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67088+}
67089+
67090+struct acl_role_label *
67091+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67092+ const gid_t gid)
67093+{
67094+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67095+ struct acl_role_label *match;
67096+ struct role_allowed_ip *ipp;
67097+ unsigned int x;
67098+ u32 curr_ip = task->signal->saved_ip;
67099+
67100+ match = state->acl_role_set.r_hash[index];
67101+
67102+ while (match) {
67103+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67104+ for (x = 0; x < match->domain_child_num; x++) {
67105+ if (match->domain_children[x] == uid)
67106+ goto found;
67107+ }
67108+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67109+ break;
67110+ match = match->next;
67111+ }
67112+found:
67113+ if (match == NULL) {
67114+ try_group:
67115+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67116+ match = state->acl_role_set.r_hash[index];
67117+
67118+ while (match) {
67119+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67120+ for (x = 0; x < match->domain_child_num; x++) {
67121+ if (match->domain_children[x] == gid)
67122+ goto found2;
67123+ }
67124+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67125+ break;
67126+ match = match->next;
67127+ }
67128+found2:
67129+ if (match == NULL)
67130+ match = state->default_role;
67131+ if (match->allowed_ips == NULL)
67132+ return match;
67133+ else {
67134+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67135+ if (likely
67136+ ((ntohl(curr_ip) & ipp->netmask) ==
67137+ (ntohl(ipp->addr) & ipp->netmask)))
67138+ return match;
67139+ }
67140+ match = state->default_role;
67141+ }
67142+ } else if (match->allowed_ips == NULL) {
67143+ return match;
67144+ } else {
67145+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67146+ if (likely
67147+ ((ntohl(curr_ip) & ipp->netmask) ==
67148+ (ntohl(ipp->addr) & ipp->netmask)))
67149+ return match;
67150+ }
67151+ goto try_group;
67152+ }
67153+
67154+ return match;
67155+}
67156+
67157+static struct acl_role_label *
67158+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67159+ const gid_t gid)
67160+{
67161+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67162+}
67163+
67164+struct acl_subject_label *
67165+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67166+ const struct acl_role_label *role)
67167+{
67168+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67169+ struct acl_subject_label *match;
67170+
67171+ match = role->subj_hash[index];
67172+
67173+ while (match && (match->inode != ino || match->device != dev ||
67174+ (match->mode & GR_DELETED))) {
67175+ match = match->next;
67176+ }
67177+
67178+ if (match && !(match->mode & GR_DELETED))
67179+ return match;
67180+ else
67181+ return NULL;
67182+}
67183+
67184+struct acl_subject_label *
67185+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67186+ const struct acl_role_label *role)
67187+{
67188+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67189+ struct acl_subject_label *match;
67190+
67191+ match = role->subj_hash[index];
67192+
67193+ while (match && (match->inode != ino || match->device != dev ||
67194+ !(match->mode & GR_DELETED))) {
67195+ match = match->next;
67196+ }
67197+
67198+ if (match && (match->mode & GR_DELETED))
67199+ return match;
67200+ else
67201+ return NULL;
67202+}
67203+
67204+static struct acl_object_label *
67205+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67206+ const struct acl_subject_label *subj)
67207+{
67208+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67209+ struct acl_object_label *match;
67210+
67211+ match = subj->obj_hash[index];
67212+
67213+ while (match && (match->inode != ino || match->device != dev ||
67214+ (match->mode & GR_DELETED))) {
67215+ match = match->next;
67216+ }
67217+
67218+ if (match && !(match->mode & GR_DELETED))
67219+ return match;
67220+ else
67221+ return NULL;
67222+}
67223+
67224+static struct acl_object_label *
67225+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67226+ const struct acl_subject_label *subj)
67227+{
67228+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67229+ struct acl_object_label *match;
67230+
67231+ match = subj->obj_hash[index];
67232+
67233+ while (match && (match->inode != ino || match->device != dev ||
67234+ !(match->mode & GR_DELETED))) {
67235+ match = match->next;
67236+ }
67237+
67238+ if (match && (match->mode & GR_DELETED))
67239+ return match;
67240+
67241+ match = subj->obj_hash[index];
67242+
67243+ while (match && (match->inode != ino || match->device != dev ||
67244+ (match->mode & GR_DELETED))) {
67245+ match = match->next;
67246+ }
67247+
67248+ if (match && !(match->mode & GR_DELETED))
67249+ return match;
67250+ else
67251+ return NULL;
67252+}
67253+
67254+struct name_entry *
67255+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67256+{
67257+ unsigned int len = strlen(name);
67258+ unsigned int key = full_name_hash(name, len);
67259+ unsigned int index = key % state->name_set.n_size;
67260+ struct name_entry *match;
67261+
67262+ match = state->name_set.n_hash[index];
67263+
67264+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67265+ match = match->next;
67266+
67267+ return match;
67268+}
67269+
67270+static struct name_entry *
67271+lookup_name_entry(const char *name)
67272+{
67273+ return __lookup_name_entry(&running_polstate, name);
67274+}
67275+
67276+static struct name_entry *
67277+lookup_name_entry_create(const char *name)
67278+{
67279+ unsigned int len = strlen(name);
67280+ unsigned int key = full_name_hash(name, len);
67281+ unsigned int index = key % running_polstate.name_set.n_size;
67282+ struct name_entry *match;
67283+
67284+ match = running_polstate.name_set.n_hash[index];
67285+
67286+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67287+ !match->deleted))
67288+ match = match->next;
67289+
67290+ if (match && match->deleted)
67291+ return match;
67292+
67293+ match = running_polstate.name_set.n_hash[index];
67294+
67295+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67296+ match->deleted))
67297+ match = match->next;
67298+
67299+ if (match && !match->deleted)
67300+ return match;
67301+ else
67302+ return NULL;
67303+}
67304+
67305+static struct inodev_entry *
67306+lookup_inodev_entry(const ino_t ino, const dev_t dev)
67307+{
67308+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67309+ struct inodev_entry *match;
67310+
67311+ match = running_polstate.inodev_set.i_hash[index];
67312+
67313+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67314+ match = match->next;
67315+
67316+ return match;
67317+}
67318+
67319+void
67320+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67321+{
67322+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67323+ state->inodev_set.i_size);
67324+ struct inodev_entry **curr;
67325+
67326+ entry->prev = NULL;
67327+
67328+ curr = &state->inodev_set.i_hash[index];
67329+ if (*curr != NULL)
67330+ (*curr)->prev = entry;
67331+
67332+ entry->next = *curr;
67333+ *curr = entry;
67334+
67335+ return;
67336+}
67337+
67338+static void
67339+insert_inodev_entry(struct inodev_entry *entry)
67340+{
67341+ __insert_inodev_entry(&running_polstate, entry);
67342+}
67343+
67344+void
67345+insert_acl_obj_label(struct acl_object_label *obj,
67346+ struct acl_subject_label *subj)
67347+{
67348+ unsigned int index =
67349+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67350+ struct acl_object_label **curr;
67351+
67352+ obj->prev = NULL;
67353+
67354+ curr = &subj->obj_hash[index];
67355+ if (*curr != NULL)
67356+ (*curr)->prev = obj;
67357+
67358+ obj->next = *curr;
67359+ *curr = obj;
67360+
67361+ return;
67362+}
67363+
67364+void
67365+insert_acl_subj_label(struct acl_subject_label *obj,
67366+ struct acl_role_label *role)
67367+{
67368+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67369+ struct acl_subject_label **curr;
67370+
67371+ obj->prev = NULL;
67372+
67373+ curr = &role->subj_hash[index];
67374+ if (*curr != NULL)
67375+ (*curr)->prev = obj;
67376+
67377+ obj->next = *curr;
67378+ *curr = obj;
67379+
67380+ return;
67381+}
67382+
67383+/* derived from glibc fnmatch() 0: match, 1: no match*/
67384+
67385+static int
67386+glob_match(const char *p, const char *n)
67387+{
67388+ char c;
67389+
67390+ while ((c = *p++) != '\0') {
67391+ switch (c) {
67392+ case '?':
67393+ if (*n == '\0')
67394+ return 1;
67395+ else if (*n == '/')
67396+ return 1;
67397+ break;
67398+ case '\\':
67399+ if (*n != c)
67400+ return 1;
67401+ break;
67402+ case '*':
67403+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
67404+ if (*n == '/')
67405+ return 1;
67406+ else if (c == '?') {
67407+ if (*n == '\0')
67408+ return 1;
67409+ else
67410+ ++n;
67411+ }
67412+ }
67413+ if (c == '\0') {
67414+ return 0;
67415+ } else {
67416+ const char *endp;
67417+
67418+ if ((endp = strchr(n, '/')) == NULL)
67419+ endp = n + strlen(n);
67420+
67421+ if (c == '[') {
67422+ for (--p; n < endp; ++n)
67423+ if (!glob_match(p, n))
67424+ return 0;
67425+ } else if (c == '/') {
67426+ while (*n != '\0' && *n != '/')
67427+ ++n;
67428+ if (*n == '/' && !glob_match(p, n + 1))
67429+ return 0;
67430+ } else {
67431+ for (--p; n < endp; ++n)
67432+ if (*n == c && !glob_match(p, n))
67433+ return 0;
67434+ }
67435+
67436+ return 1;
67437+ }
67438+ case '[':
67439+ {
67440+ int not;
67441+ char cold;
67442+
67443+ if (*n == '\0' || *n == '/')
67444+ return 1;
67445+
67446+ not = (*p == '!' || *p == '^');
67447+ if (not)
67448+ ++p;
67449+
67450+ c = *p++;
67451+ for (;;) {
67452+ unsigned char fn = (unsigned char)*n;
67453+
67454+ if (c == '\0')
67455+ return 1;
67456+ else {
67457+ if (c == fn)
67458+ goto matched;
67459+ cold = c;
67460+ c = *p++;
67461+
67462+ if (c == '-' && *p != ']') {
67463+ unsigned char cend = *p++;
67464+
67465+ if (cend == '\0')
67466+ return 1;
67467+
67468+ if (cold <= fn && fn <= cend)
67469+ goto matched;
67470+
67471+ c = *p++;
67472+ }
67473+ }
67474+
67475+ if (c == ']')
67476+ break;
67477+ }
67478+ if (!not)
67479+ return 1;
67480+ break;
67481+ matched:
67482+ while (c != ']') {
67483+ if (c == '\0')
67484+ return 1;
67485+
67486+ c = *p++;
67487+ }
67488+ if (not)
67489+ return 1;
67490+ }
67491+ break;
67492+ default:
67493+ if (c != *n)
67494+ return 1;
67495+ }
67496+
67497+ ++n;
67498+ }
67499+
67500+ if (*n == '\0')
67501+ return 0;
67502+
67503+ if (*n == '/')
67504+ return 0;
67505+
67506+ return 1;
67507+}
67508+
67509+static struct acl_object_label *
67510+chk_glob_label(struct acl_object_label *globbed,
67511+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67512+{
67513+ struct acl_object_label *tmp;
67514+
67515+ if (*path == NULL)
67516+ *path = gr_to_filename_nolock(dentry, mnt);
67517+
67518+ tmp = globbed;
67519+
67520+ while (tmp) {
67521+ if (!glob_match(tmp->filename, *path))
67522+ return tmp;
67523+ tmp = tmp->next;
67524+ }
67525+
67526+ return NULL;
67527+}
67528+
67529+static struct acl_object_label *
67530+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67531+ const ino_t curr_ino, const dev_t curr_dev,
67532+ const struct acl_subject_label *subj, char **path, const int checkglob)
67533+{
67534+ struct acl_subject_label *tmpsubj;
67535+ struct acl_object_label *retval;
67536+ struct acl_object_label *retval2;
67537+
67538+ tmpsubj = (struct acl_subject_label *) subj;
67539+ read_lock(&gr_inode_lock);
67540+ do {
67541+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67542+ if (retval) {
67543+ if (checkglob && retval->globbed) {
67544+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67545+ if (retval2)
67546+ retval = retval2;
67547+ }
67548+ break;
67549+ }
67550+ } while ((tmpsubj = tmpsubj->parent_subject));
67551+ read_unlock(&gr_inode_lock);
67552+
67553+ return retval;
67554+}
67555+
67556+static __inline__ struct acl_object_label *
67557+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67558+ struct dentry *curr_dentry,
67559+ const struct acl_subject_label *subj, char **path, const int checkglob)
67560+{
67561+ int newglob = checkglob;
67562+ ino_t inode;
67563+ dev_t device;
67564+
67565+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67566+ as we don't want a / * rule to match instead of the / object
67567+ don't do this for create lookups that call this function though, since they're looking up
67568+ on the parent and thus need globbing checks on all paths
67569+ */
67570+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67571+ newglob = GR_NO_GLOB;
67572+
67573+ spin_lock(&curr_dentry->d_lock);
67574+ inode = curr_dentry->d_inode->i_ino;
67575+ device = __get_dev(curr_dentry);
67576+ spin_unlock(&curr_dentry->d_lock);
67577+
67578+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67579+}
67580+
67581+#ifdef CONFIG_HUGETLBFS
67582+static inline bool
67583+is_hugetlbfs_mnt(const struct vfsmount *mnt)
67584+{
67585+ int i;
67586+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67587+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67588+ return true;
67589+ }
67590+
67591+ return false;
67592+}
67593+#endif
67594+
67595+static struct acl_object_label *
67596+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67597+ const struct acl_subject_label *subj, char *path, const int checkglob)
67598+{
67599+ struct dentry *dentry = (struct dentry *) l_dentry;
67600+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67601+ struct mount *real_mnt = real_mount(mnt);
67602+ struct acl_object_label *retval;
67603+ struct dentry *parent;
67604+
67605+ read_seqlock_excl(&mount_lock);
67606+ write_seqlock(&rename_lock);
67607+
67608+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67609+#ifdef CONFIG_NET
67610+ mnt == sock_mnt ||
67611+#endif
67612+#ifdef CONFIG_HUGETLBFS
67613+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67614+#endif
67615+ /* ignore Eric Biederman */
67616+ IS_PRIVATE(l_dentry->d_inode))) {
67617+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67618+ goto out;
67619+ }
67620+
67621+ for (;;) {
67622+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67623+ break;
67624+
67625+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67626+ if (!mnt_has_parent(real_mnt))
67627+ break;
67628+
67629+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67630+ if (retval != NULL)
67631+ goto out;
67632+
67633+ dentry = real_mnt->mnt_mountpoint;
67634+ real_mnt = real_mnt->mnt_parent;
67635+ mnt = &real_mnt->mnt;
67636+ continue;
67637+ }
67638+
67639+ parent = dentry->d_parent;
67640+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67641+ if (retval != NULL)
67642+ goto out;
67643+
67644+ dentry = parent;
67645+ }
67646+
67647+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67648+
67649+ /* gr_real_root is pinned so we don't have to hold a reference */
67650+ if (retval == NULL)
67651+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67652+out:
67653+ write_sequnlock(&rename_lock);
67654+ read_sequnlock_excl(&mount_lock);
67655+
67656+ BUG_ON(retval == NULL);
67657+
67658+ return retval;
67659+}
67660+
67661+static __inline__ struct acl_object_label *
67662+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67663+ const struct acl_subject_label *subj)
67664+{
67665+ char *path = NULL;
67666+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67667+}
67668+
67669+static __inline__ struct acl_object_label *
67670+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67671+ const struct acl_subject_label *subj)
67672+{
67673+ char *path = NULL;
67674+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67675+}
67676+
67677+static __inline__ struct acl_object_label *
67678+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67679+ const struct acl_subject_label *subj, char *path)
67680+{
67681+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67682+}
67683+
67684+struct acl_subject_label *
67685+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67686+ const struct acl_role_label *role)
67687+{
67688+ struct dentry *dentry = (struct dentry *) l_dentry;
67689+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67690+ struct mount *real_mnt = real_mount(mnt);
67691+ struct acl_subject_label *retval;
67692+ struct dentry *parent;
67693+
67694+ read_seqlock_excl(&mount_lock);
67695+ write_seqlock(&rename_lock);
67696+
67697+ for (;;) {
67698+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67699+ break;
67700+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67701+ if (!mnt_has_parent(real_mnt))
67702+ break;
67703+
67704+ spin_lock(&dentry->d_lock);
67705+ read_lock(&gr_inode_lock);
67706+ retval =
67707+ lookup_acl_subj_label(dentry->d_inode->i_ino,
67708+ __get_dev(dentry), role);
67709+ read_unlock(&gr_inode_lock);
67710+ spin_unlock(&dentry->d_lock);
67711+ if (retval != NULL)
67712+ goto out;
67713+
67714+ dentry = real_mnt->mnt_mountpoint;
67715+ real_mnt = real_mnt->mnt_parent;
67716+ mnt = &real_mnt->mnt;
67717+ continue;
67718+ }
67719+
67720+ spin_lock(&dentry->d_lock);
67721+ read_lock(&gr_inode_lock);
67722+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67723+ __get_dev(dentry), role);
67724+ read_unlock(&gr_inode_lock);
67725+ parent = dentry->d_parent;
67726+ spin_unlock(&dentry->d_lock);
67727+
67728+ if (retval != NULL)
67729+ goto out;
67730+
67731+ dentry = parent;
67732+ }
67733+
67734+ spin_lock(&dentry->d_lock);
67735+ read_lock(&gr_inode_lock);
67736+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67737+ __get_dev(dentry), role);
67738+ read_unlock(&gr_inode_lock);
67739+ spin_unlock(&dentry->d_lock);
67740+
67741+ if (unlikely(retval == NULL)) {
67742+ /* gr_real_root is pinned, we don't need to hold a reference */
67743+ read_lock(&gr_inode_lock);
67744+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67745+ __get_dev(gr_real_root.dentry), role);
67746+ read_unlock(&gr_inode_lock);
67747+ }
67748+out:
67749+ write_sequnlock(&rename_lock);
67750+ read_sequnlock_excl(&mount_lock);
67751+
67752+ BUG_ON(retval == NULL);
67753+
67754+ return retval;
67755+}
67756+
67757+void
67758+assign_special_role(const char *rolename)
67759+{
67760+ struct acl_object_label *obj;
67761+ struct acl_role_label *r;
67762+ struct acl_role_label *assigned = NULL;
67763+ struct task_struct *tsk;
67764+ struct file *filp;
67765+
67766+ FOR_EACH_ROLE_START(r)
67767+ if (!strcmp(rolename, r->rolename) &&
67768+ (r->roletype & GR_ROLE_SPECIAL)) {
67769+ assigned = r;
67770+ break;
67771+ }
67772+ FOR_EACH_ROLE_END(r)
67773+
67774+ if (!assigned)
67775+ return;
67776+
67777+ read_lock(&tasklist_lock);
67778+ read_lock(&grsec_exec_file_lock);
67779+
67780+ tsk = current->real_parent;
67781+ if (tsk == NULL)
67782+ goto out_unlock;
67783+
67784+ filp = tsk->exec_file;
67785+ if (filp == NULL)
67786+ goto out_unlock;
67787+
67788+ tsk->is_writable = 0;
67789+ tsk->inherited = 0;
67790+
67791+ tsk->acl_sp_role = 1;
67792+ tsk->acl_role_id = ++acl_sp_role_value;
67793+ tsk->role = assigned;
67794+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67795+
67796+ /* ignore additional mmap checks for processes that are writable
67797+ by the default ACL */
67798+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67799+ if (unlikely(obj->mode & GR_WRITE))
67800+ tsk->is_writable = 1;
67801+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67802+ if (unlikely(obj->mode & GR_WRITE))
67803+ tsk->is_writable = 1;
67804+
67805+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67806+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67807+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67808+#endif
67809+
67810+out_unlock:
67811+ read_unlock(&grsec_exec_file_lock);
67812+ read_unlock(&tasklist_lock);
67813+ return;
67814+}
67815+
67816+
67817+static void
67818+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67819+{
67820+ struct task_struct *task = current;
67821+ const struct cred *cred = current_cred();
67822+
67823+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67824+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67825+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67826+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67827+
67828+ return;
67829+}
67830+
67831+static void
67832+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67833+{
67834+ struct task_struct *task = current;
67835+ const struct cred *cred = current_cred();
67836+
67837+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67838+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67839+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67840+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67841+
67842+ return;
67843+}
67844+
67845+static void
67846+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67847+{
67848+ struct task_struct *task = current;
67849+ const struct cred *cred = current_cred();
67850+
67851+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67852+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67853+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67854+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67855+
67856+ return;
67857+}
67858+
67859+static void
67860+gr_set_proc_res(struct task_struct *task)
67861+{
67862+ struct acl_subject_label *proc;
67863+ unsigned short i;
67864+
67865+ proc = task->acl;
67866+
67867+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67868+ return;
67869+
67870+ for (i = 0; i < RLIM_NLIMITS; i++) {
67871+ if (!(proc->resmask & (1U << i)))
67872+ continue;
67873+
67874+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67875+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67876+
67877+ if (i == RLIMIT_CPU)
67878+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
67879+ }
67880+
67881+ return;
67882+}
67883+
67884+/* both of the below must be called with
67885+ rcu_read_lock();
67886+ read_lock(&tasklist_lock);
67887+ read_lock(&grsec_exec_file_lock);
67888+*/
67889+
67890+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
67891+{
67892+ char *tmpname;
67893+ struct acl_subject_label *tmpsubj;
67894+ struct file *filp;
67895+ struct name_entry *nmatch;
67896+
67897+ filp = task->exec_file;
67898+ if (filp == NULL)
67899+ return NULL;
67900+
67901+ /* the following is to apply the correct subject
67902+ on binaries running when the RBAC system
67903+ is enabled, when the binaries have been
67904+ replaced or deleted since their execution
67905+ -----
67906+ when the RBAC system starts, the inode/dev
67907+ from exec_file will be one the RBAC system
67908+ is unaware of. It only knows the inode/dev
67909+ of the present file on disk, or the absence
67910+ of it.
67911+ */
67912+
67913+ if (filename)
67914+ nmatch = __lookup_name_entry(state, filename);
67915+ else {
67916+ preempt_disable();
67917+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
67918+
67919+ nmatch = __lookup_name_entry(state, tmpname);
67920+ preempt_enable();
67921+ }
67922+ tmpsubj = NULL;
67923+ if (nmatch) {
67924+ if (nmatch->deleted)
67925+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
67926+ else
67927+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
67928+ }
67929+ /* this also works for the reload case -- if we don't match a potentially inherited subject
67930+ then we fall back to a normal lookup based on the binary's ino/dev
67931+ */
67932+ if (tmpsubj == NULL)
67933+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
67934+
67935+ return tmpsubj;
67936+}
67937+
67938+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
67939+{
67940+ return __gr_get_subject_for_task(&running_polstate, task, filename);
67941+}
67942+
67943+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
67944+{
67945+ struct acl_object_label *obj;
67946+ struct file *filp;
67947+
67948+ filp = task->exec_file;
67949+
67950+ task->acl = subj;
67951+ task->is_writable = 0;
67952+ /* ignore additional mmap checks for processes that are writable
67953+ by the default ACL */
67954+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
67955+ if (unlikely(obj->mode & GR_WRITE))
67956+ task->is_writable = 1;
67957+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67958+ if (unlikely(obj->mode & GR_WRITE))
67959+ task->is_writable = 1;
67960+
67961+ gr_set_proc_res(task);
67962+
67963+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67964+ 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);
67965+#endif
67966+}
67967+
67968+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
67969+{
67970+ __gr_apply_subject_to_task(&running_polstate, task, subj);
67971+}
67972+
67973+__u32
67974+gr_search_file(const struct dentry * dentry, const __u32 mode,
67975+ const struct vfsmount * mnt)
67976+{
67977+ __u32 retval = mode;
67978+ struct acl_subject_label *curracl;
67979+ struct acl_object_label *currobj;
67980+
67981+ if (unlikely(!(gr_status & GR_READY)))
67982+ return (mode & ~GR_AUDITS);
67983+
67984+ curracl = current->acl;
67985+
67986+ currobj = chk_obj_label(dentry, mnt, curracl);
67987+ retval = currobj->mode & mode;
67988+
67989+ /* if we're opening a specified transfer file for writing
67990+ (e.g. /dev/initctl), then transfer our role to init
67991+ */
67992+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
67993+ current->role->roletype & GR_ROLE_PERSIST)) {
67994+ struct task_struct *task = init_pid_ns.child_reaper;
67995+
67996+ if (task->role != current->role) {
67997+ struct acl_subject_label *subj;
67998+
67999+ task->acl_sp_role = 0;
68000+ task->acl_role_id = current->acl_role_id;
68001+ task->role = current->role;
68002+ rcu_read_lock();
68003+ read_lock(&grsec_exec_file_lock);
68004+ subj = gr_get_subject_for_task(task, NULL);
68005+ gr_apply_subject_to_task(task, subj);
68006+ read_unlock(&grsec_exec_file_lock);
68007+ rcu_read_unlock();
68008+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68009+ }
68010+ }
68011+
68012+ if (unlikely
68013+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68014+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68015+ __u32 new_mode = mode;
68016+
68017+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68018+
68019+ retval = new_mode;
68020+
68021+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68022+ new_mode |= GR_INHERIT;
68023+
68024+ if (!(mode & GR_NOLEARN))
68025+ gr_log_learn(dentry, mnt, new_mode);
68026+ }
68027+
68028+ return retval;
68029+}
68030+
68031+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68032+ const struct dentry *parent,
68033+ const struct vfsmount *mnt)
68034+{
68035+ struct name_entry *match;
68036+ struct acl_object_label *matchpo;
68037+ struct acl_subject_label *curracl;
68038+ char *path;
68039+
68040+ if (unlikely(!(gr_status & GR_READY)))
68041+ return NULL;
68042+
68043+ preempt_disable();
68044+ path = gr_to_filename_rbac(new_dentry, mnt);
68045+ match = lookup_name_entry_create(path);
68046+
68047+ curracl = current->acl;
68048+
68049+ if (match) {
68050+ read_lock(&gr_inode_lock);
68051+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68052+ read_unlock(&gr_inode_lock);
68053+
68054+ if (matchpo) {
68055+ preempt_enable();
68056+ return matchpo;
68057+ }
68058+ }
68059+
68060+ // lookup parent
68061+
68062+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68063+
68064+ preempt_enable();
68065+ return matchpo;
68066+}
68067+
68068+__u32
68069+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68070+ const struct vfsmount * mnt, const __u32 mode)
68071+{
68072+ struct acl_object_label *matchpo;
68073+ __u32 retval;
68074+
68075+ if (unlikely(!(gr_status & GR_READY)))
68076+ return (mode & ~GR_AUDITS);
68077+
68078+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
68079+
68080+ retval = matchpo->mode & mode;
68081+
68082+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68083+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68084+ __u32 new_mode = mode;
68085+
68086+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68087+
68088+ gr_log_learn(new_dentry, mnt, new_mode);
68089+ return new_mode;
68090+ }
68091+
68092+ return retval;
68093+}
68094+
68095+__u32
68096+gr_check_link(const struct dentry * new_dentry,
68097+ const struct dentry * parent_dentry,
68098+ const struct vfsmount * parent_mnt,
68099+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68100+{
68101+ struct acl_object_label *obj;
68102+ __u32 oldmode, newmode;
68103+ __u32 needmode;
68104+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68105+ GR_DELETE | GR_INHERIT;
68106+
68107+ if (unlikely(!(gr_status & GR_READY)))
68108+ return (GR_CREATE | GR_LINK);
68109+
68110+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68111+ oldmode = obj->mode;
68112+
68113+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68114+ newmode = obj->mode;
68115+
68116+ needmode = newmode & checkmodes;
68117+
68118+ // old name for hardlink must have at least the permissions of the new name
68119+ if ((oldmode & needmode) != needmode)
68120+ goto bad;
68121+
68122+ // if old name had restrictions/auditing, make sure the new name does as well
68123+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68124+
68125+ // don't allow hardlinking of suid/sgid/fcapped files without permission
68126+ if (is_privileged_binary(old_dentry))
68127+ needmode |= GR_SETID;
68128+
68129+ if ((newmode & needmode) != needmode)
68130+ goto bad;
68131+
68132+ // enforce minimum permissions
68133+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68134+ return newmode;
68135+bad:
68136+ needmode = oldmode;
68137+ if (is_privileged_binary(old_dentry))
68138+ needmode |= GR_SETID;
68139+
68140+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68141+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68142+ return (GR_CREATE | GR_LINK);
68143+ } else if (newmode & GR_SUPPRESS)
68144+ return GR_SUPPRESS;
68145+ else
68146+ return 0;
68147+}
68148+
68149+int
68150+gr_check_hidden_task(const struct task_struct *task)
68151+{
68152+ if (unlikely(!(gr_status & GR_READY)))
68153+ return 0;
68154+
68155+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68156+ return 1;
68157+
68158+ return 0;
68159+}
68160+
68161+int
68162+gr_check_protected_task(const struct task_struct *task)
68163+{
68164+ if (unlikely(!(gr_status & GR_READY) || !task))
68165+ return 0;
68166+
68167+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68168+ task->acl != current->acl)
68169+ return 1;
68170+
68171+ return 0;
68172+}
68173+
68174+int
68175+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68176+{
68177+ struct task_struct *p;
68178+ int ret = 0;
68179+
68180+ if (unlikely(!(gr_status & GR_READY) || !pid))
68181+ return ret;
68182+
68183+ read_lock(&tasklist_lock);
68184+ do_each_pid_task(pid, type, p) {
68185+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68186+ p->acl != current->acl) {
68187+ ret = 1;
68188+ goto out;
68189+ }
68190+ } while_each_pid_task(pid, type, p);
68191+out:
68192+ read_unlock(&tasklist_lock);
68193+
68194+ return ret;
68195+}
68196+
68197+void
68198+gr_copy_label(struct task_struct *tsk)
68199+{
68200+ struct task_struct *p = current;
68201+
68202+ tsk->inherited = p->inherited;
68203+ tsk->acl_sp_role = 0;
68204+ tsk->acl_role_id = p->acl_role_id;
68205+ tsk->acl = p->acl;
68206+ tsk->role = p->role;
68207+ tsk->signal->used_accept = 0;
68208+ tsk->signal->curr_ip = p->signal->curr_ip;
68209+ tsk->signal->saved_ip = p->signal->saved_ip;
68210+ if (p->exec_file)
68211+ get_file(p->exec_file);
68212+ tsk->exec_file = p->exec_file;
68213+ tsk->is_writable = p->is_writable;
68214+ if (unlikely(p->signal->used_accept)) {
68215+ p->signal->curr_ip = 0;
68216+ p->signal->saved_ip = 0;
68217+ }
68218+
68219+ return;
68220+}
68221+
68222+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68223+
68224+int
68225+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68226+{
68227+ unsigned int i;
68228+ __u16 num;
68229+ uid_t *uidlist;
68230+ uid_t curuid;
68231+ int realok = 0;
68232+ int effectiveok = 0;
68233+ int fsok = 0;
68234+ uid_t globalreal, globaleffective, globalfs;
68235+
68236+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68237+ struct user_struct *user;
68238+
68239+ if (!uid_valid(real))
68240+ goto skipit;
68241+
68242+ /* find user based on global namespace */
68243+
68244+ globalreal = GR_GLOBAL_UID(real);
68245+
68246+ user = find_user(make_kuid(&init_user_ns, globalreal));
68247+ if (user == NULL)
68248+ goto skipit;
68249+
68250+ if (gr_process_kernel_setuid_ban(user)) {
68251+ /* for find_user */
68252+ free_uid(user);
68253+ return 1;
68254+ }
68255+
68256+ /* for find_user */
68257+ free_uid(user);
68258+
68259+skipit:
68260+#endif
68261+
68262+ if (unlikely(!(gr_status & GR_READY)))
68263+ return 0;
68264+
68265+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68266+ gr_log_learn_uid_change(real, effective, fs);
68267+
68268+ num = current->acl->user_trans_num;
68269+ uidlist = current->acl->user_transitions;
68270+
68271+ if (uidlist == NULL)
68272+ return 0;
68273+
68274+ if (!uid_valid(real)) {
68275+ realok = 1;
68276+ globalreal = (uid_t)-1;
68277+ } else {
68278+ globalreal = GR_GLOBAL_UID(real);
68279+ }
68280+ if (!uid_valid(effective)) {
68281+ effectiveok = 1;
68282+ globaleffective = (uid_t)-1;
68283+ } else {
68284+ globaleffective = GR_GLOBAL_UID(effective);
68285+ }
68286+ if (!uid_valid(fs)) {
68287+ fsok = 1;
68288+ globalfs = (uid_t)-1;
68289+ } else {
68290+ globalfs = GR_GLOBAL_UID(fs);
68291+ }
68292+
68293+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
68294+ for (i = 0; i < num; i++) {
68295+ curuid = uidlist[i];
68296+ if (globalreal == curuid)
68297+ realok = 1;
68298+ if (globaleffective == curuid)
68299+ effectiveok = 1;
68300+ if (globalfs == curuid)
68301+ fsok = 1;
68302+ }
68303+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
68304+ for (i = 0; i < num; i++) {
68305+ curuid = uidlist[i];
68306+ if (globalreal == curuid)
68307+ break;
68308+ if (globaleffective == curuid)
68309+ break;
68310+ if (globalfs == curuid)
68311+ break;
68312+ }
68313+ /* not in deny list */
68314+ if (i == num) {
68315+ realok = 1;
68316+ effectiveok = 1;
68317+ fsok = 1;
68318+ }
68319+ }
68320+
68321+ if (realok && effectiveok && fsok)
68322+ return 0;
68323+ else {
68324+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68325+ return 1;
68326+ }
68327+}
68328+
68329+int
68330+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68331+{
68332+ unsigned int i;
68333+ __u16 num;
68334+ gid_t *gidlist;
68335+ gid_t curgid;
68336+ int realok = 0;
68337+ int effectiveok = 0;
68338+ int fsok = 0;
68339+ gid_t globalreal, globaleffective, globalfs;
68340+
68341+ if (unlikely(!(gr_status & GR_READY)))
68342+ return 0;
68343+
68344+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68345+ gr_log_learn_gid_change(real, effective, fs);
68346+
68347+ num = current->acl->group_trans_num;
68348+ gidlist = current->acl->group_transitions;
68349+
68350+ if (gidlist == NULL)
68351+ return 0;
68352+
68353+ if (!gid_valid(real)) {
68354+ realok = 1;
68355+ globalreal = (gid_t)-1;
68356+ } else {
68357+ globalreal = GR_GLOBAL_GID(real);
68358+ }
68359+ if (!gid_valid(effective)) {
68360+ effectiveok = 1;
68361+ globaleffective = (gid_t)-1;
68362+ } else {
68363+ globaleffective = GR_GLOBAL_GID(effective);
68364+ }
68365+ if (!gid_valid(fs)) {
68366+ fsok = 1;
68367+ globalfs = (gid_t)-1;
68368+ } else {
68369+ globalfs = GR_GLOBAL_GID(fs);
68370+ }
68371+
68372+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
68373+ for (i = 0; i < num; i++) {
68374+ curgid = gidlist[i];
68375+ if (globalreal == curgid)
68376+ realok = 1;
68377+ if (globaleffective == curgid)
68378+ effectiveok = 1;
68379+ if (globalfs == curgid)
68380+ fsok = 1;
68381+ }
68382+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
68383+ for (i = 0; i < num; i++) {
68384+ curgid = gidlist[i];
68385+ if (globalreal == curgid)
68386+ break;
68387+ if (globaleffective == curgid)
68388+ break;
68389+ if (globalfs == curgid)
68390+ break;
68391+ }
68392+ /* not in deny list */
68393+ if (i == num) {
68394+ realok = 1;
68395+ effectiveok = 1;
68396+ fsok = 1;
68397+ }
68398+ }
68399+
68400+ if (realok && effectiveok && fsok)
68401+ return 0;
68402+ else {
68403+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68404+ return 1;
68405+ }
68406+}
68407+
68408+extern int gr_acl_is_capable(const int cap);
68409+
68410+void
68411+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68412+{
68413+ struct acl_role_label *role = task->role;
68414+ struct acl_subject_label *subj = NULL;
68415+ struct acl_object_label *obj;
68416+ struct file *filp;
68417+ uid_t uid;
68418+ gid_t gid;
68419+
68420+ if (unlikely(!(gr_status & GR_READY)))
68421+ return;
68422+
68423+ uid = GR_GLOBAL_UID(kuid);
68424+ gid = GR_GLOBAL_GID(kgid);
68425+
68426+ filp = task->exec_file;
68427+
68428+ /* kernel process, we'll give them the kernel role */
68429+ if (unlikely(!filp)) {
68430+ task->role = running_polstate.kernel_role;
68431+ task->acl = running_polstate.kernel_role->root_label;
68432+ return;
68433+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68434+ /* save the current ip at time of role lookup so that the proper
68435+ IP will be learned for role_allowed_ip */
68436+ task->signal->saved_ip = task->signal->curr_ip;
68437+ role = lookup_acl_role_label(task, uid, gid);
68438+ }
68439+
68440+ /* don't change the role if we're not a privileged process */
68441+ if (role && task->role != role &&
68442+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68443+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68444+ return;
68445+
68446+ /* perform subject lookup in possibly new role
68447+ we can use this result below in the case where role == task->role
68448+ */
68449+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68450+
68451+ /* if we changed uid/gid, but result in the same role
68452+ and are using inheritance, don't lose the inherited subject
68453+ if current subject is other than what normal lookup
68454+ would result in, we arrived via inheritance, don't
68455+ lose subject
68456+ */
68457+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68458+ (subj == task->acl)))
68459+ task->acl = subj;
68460+
68461+ /* leave task->inherited unaffected */
68462+
68463+ task->role = role;
68464+
68465+ task->is_writable = 0;
68466+
68467+ /* ignore additional mmap checks for processes that are writable
68468+ by the default ACL */
68469+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68470+ if (unlikely(obj->mode & GR_WRITE))
68471+ task->is_writable = 1;
68472+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68473+ if (unlikely(obj->mode & GR_WRITE))
68474+ task->is_writable = 1;
68475+
68476+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68477+ 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);
68478+#endif
68479+
68480+ gr_set_proc_res(task);
68481+
68482+ return;
68483+}
68484+
68485+int
68486+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68487+ const int unsafe_flags)
68488+{
68489+ struct task_struct *task = current;
68490+ struct acl_subject_label *newacl;
68491+ struct acl_object_label *obj;
68492+ __u32 retmode;
68493+
68494+ if (unlikely(!(gr_status & GR_READY)))
68495+ return 0;
68496+
68497+ newacl = chk_subj_label(dentry, mnt, task->role);
68498+
68499+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68500+ did an exec
68501+ */
68502+ rcu_read_lock();
68503+ read_lock(&tasklist_lock);
68504+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68505+ (task->parent->acl->mode & GR_POVERRIDE))) {
68506+ read_unlock(&tasklist_lock);
68507+ rcu_read_unlock();
68508+ goto skip_check;
68509+ }
68510+ read_unlock(&tasklist_lock);
68511+ rcu_read_unlock();
68512+
68513+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68514+ !(task->role->roletype & GR_ROLE_GOD) &&
68515+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68516+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68517+ if (unsafe_flags & LSM_UNSAFE_SHARE)
68518+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68519+ else
68520+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68521+ return -EACCES;
68522+ }
68523+
68524+skip_check:
68525+
68526+ obj = chk_obj_label(dentry, mnt, task->acl);
68527+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68528+
68529+ if (!(task->acl->mode & GR_INHERITLEARN) &&
68530+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68531+ if (obj->nested)
68532+ task->acl = obj->nested;
68533+ else
68534+ task->acl = newacl;
68535+ task->inherited = 0;
68536+ } else {
68537+ task->inherited = 1;
68538+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68539+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68540+ }
68541+
68542+ task->is_writable = 0;
68543+
68544+ /* ignore additional mmap checks for processes that are writable
68545+ by the default ACL */
68546+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68547+ if (unlikely(obj->mode & GR_WRITE))
68548+ task->is_writable = 1;
68549+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
68550+ if (unlikely(obj->mode & GR_WRITE))
68551+ task->is_writable = 1;
68552+
68553+ gr_set_proc_res(task);
68554+
68555+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68556+ 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);
68557+#endif
68558+ return 0;
68559+}
68560+
68561+/* always called with valid inodev ptr */
68562+static void
68563+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68564+{
68565+ struct acl_object_label *matchpo;
68566+ struct acl_subject_label *matchps;
68567+ struct acl_subject_label *subj;
68568+ struct acl_role_label *role;
68569+ unsigned int x;
68570+
68571+ FOR_EACH_ROLE_START(role)
68572+ FOR_EACH_SUBJECT_START(role, subj, x)
68573+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68574+ matchpo->mode |= GR_DELETED;
68575+ FOR_EACH_SUBJECT_END(subj,x)
68576+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68577+ /* nested subjects aren't in the role's subj_hash table */
68578+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68579+ matchpo->mode |= GR_DELETED;
68580+ FOR_EACH_NESTED_SUBJECT_END(subj)
68581+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68582+ matchps->mode |= GR_DELETED;
68583+ FOR_EACH_ROLE_END(role)
68584+
68585+ inodev->nentry->deleted = 1;
68586+
68587+ return;
68588+}
68589+
68590+void
68591+gr_handle_delete(const ino_t ino, const dev_t dev)
68592+{
68593+ struct inodev_entry *inodev;
68594+
68595+ if (unlikely(!(gr_status & GR_READY)))
68596+ return;
68597+
68598+ write_lock(&gr_inode_lock);
68599+ inodev = lookup_inodev_entry(ino, dev);
68600+ if (inodev != NULL)
68601+ do_handle_delete(inodev, ino, dev);
68602+ write_unlock(&gr_inode_lock);
68603+
68604+ return;
68605+}
68606+
68607+static void
68608+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68609+ const ino_t newinode, const dev_t newdevice,
68610+ struct acl_subject_label *subj)
68611+{
68612+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68613+ struct acl_object_label *match;
68614+
68615+ match = subj->obj_hash[index];
68616+
68617+ while (match && (match->inode != oldinode ||
68618+ match->device != olddevice ||
68619+ !(match->mode & GR_DELETED)))
68620+ match = match->next;
68621+
68622+ if (match && (match->inode == oldinode)
68623+ && (match->device == olddevice)
68624+ && (match->mode & GR_DELETED)) {
68625+ if (match->prev == NULL) {
68626+ subj->obj_hash[index] = match->next;
68627+ if (match->next != NULL)
68628+ match->next->prev = NULL;
68629+ } else {
68630+ match->prev->next = match->next;
68631+ if (match->next != NULL)
68632+ match->next->prev = match->prev;
68633+ }
68634+ match->prev = NULL;
68635+ match->next = NULL;
68636+ match->inode = newinode;
68637+ match->device = newdevice;
68638+ match->mode &= ~GR_DELETED;
68639+
68640+ insert_acl_obj_label(match, subj);
68641+ }
68642+
68643+ return;
68644+}
68645+
68646+static void
68647+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68648+ const ino_t newinode, const dev_t newdevice,
68649+ struct acl_role_label *role)
68650+{
68651+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68652+ struct acl_subject_label *match;
68653+
68654+ match = role->subj_hash[index];
68655+
68656+ while (match && (match->inode != oldinode ||
68657+ match->device != olddevice ||
68658+ !(match->mode & GR_DELETED)))
68659+ match = match->next;
68660+
68661+ if (match && (match->inode == oldinode)
68662+ && (match->device == olddevice)
68663+ && (match->mode & GR_DELETED)) {
68664+ if (match->prev == NULL) {
68665+ role->subj_hash[index] = match->next;
68666+ if (match->next != NULL)
68667+ match->next->prev = NULL;
68668+ } else {
68669+ match->prev->next = match->next;
68670+ if (match->next != NULL)
68671+ match->next->prev = match->prev;
68672+ }
68673+ match->prev = NULL;
68674+ match->next = NULL;
68675+ match->inode = newinode;
68676+ match->device = newdevice;
68677+ match->mode &= ~GR_DELETED;
68678+
68679+ insert_acl_subj_label(match, role);
68680+ }
68681+
68682+ return;
68683+}
68684+
68685+static void
68686+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68687+ const ino_t newinode, const dev_t newdevice)
68688+{
68689+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68690+ struct inodev_entry *match;
68691+
68692+ match = running_polstate.inodev_set.i_hash[index];
68693+
68694+ while (match && (match->nentry->inode != oldinode ||
68695+ match->nentry->device != olddevice || !match->nentry->deleted))
68696+ match = match->next;
68697+
68698+ if (match && (match->nentry->inode == oldinode)
68699+ && (match->nentry->device == olddevice) &&
68700+ match->nentry->deleted) {
68701+ if (match->prev == NULL) {
68702+ running_polstate.inodev_set.i_hash[index] = match->next;
68703+ if (match->next != NULL)
68704+ match->next->prev = NULL;
68705+ } else {
68706+ match->prev->next = match->next;
68707+ if (match->next != NULL)
68708+ match->next->prev = match->prev;
68709+ }
68710+ match->prev = NULL;
68711+ match->next = NULL;
68712+ match->nentry->inode = newinode;
68713+ match->nentry->device = newdevice;
68714+ match->nentry->deleted = 0;
68715+
68716+ insert_inodev_entry(match);
68717+ }
68718+
68719+ return;
68720+}
68721+
68722+static void
68723+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68724+{
68725+ struct acl_subject_label *subj;
68726+ struct acl_role_label *role;
68727+ unsigned int x;
68728+
68729+ FOR_EACH_ROLE_START(role)
68730+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68731+
68732+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68733+ if ((subj->inode == ino) && (subj->device == dev)) {
68734+ subj->inode = ino;
68735+ subj->device = dev;
68736+ }
68737+ /* nested subjects aren't in the role's subj_hash table */
68738+ update_acl_obj_label(matchn->inode, matchn->device,
68739+ ino, dev, subj);
68740+ FOR_EACH_NESTED_SUBJECT_END(subj)
68741+ FOR_EACH_SUBJECT_START(role, subj, x)
68742+ update_acl_obj_label(matchn->inode, matchn->device,
68743+ ino, dev, subj);
68744+ FOR_EACH_SUBJECT_END(subj,x)
68745+ FOR_EACH_ROLE_END(role)
68746+
68747+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68748+
68749+ return;
68750+}
68751+
68752+static void
68753+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68754+ const struct vfsmount *mnt)
68755+{
68756+ ino_t ino = dentry->d_inode->i_ino;
68757+ dev_t dev = __get_dev(dentry);
68758+
68759+ __do_handle_create(matchn, ino, dev);
68760+
68761+ return;
68762+}
68763+
68764+void
68765+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68766+{
68767+ struct name_entry *matchn;
68768+
68769+ if (unlikely(!(gr_status & GR_READY)))
68770+ return;
68771+
68772+ preempt_disable();
68773+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68774+
68775+ if (unlikely((unsigned long)matchn)) {
68776+ write_lock(&gr_inode_lock);
68777+ do_handle_create(matchn, dentry, mnt);
68778+ write_unlock(&gr_inode_lock);
68779+ }
68780+ preempt_enable();
68781+
68782+ return;
68783+}
68784+
68785+void
68786+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68787+{
68788+ struct name_entry *matchn;
68789+
68790+ if (unlikely(!(gr_status & GR_READY)))
68791+ return;
68792+
68793+ preempt_disable();
68794+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68795+
68796+ if (unlikely((unsigned long)matchn)) {
68797+ write_lock(&gr_inode_lock);
68798+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68799+ write_unlock(&gr_inode_lock);
68800+ }
68801+ preempt_enable();
68802+
68803+ return;
68804+}
68805+
68806+void
68807+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68808+ struct dentry *old_dentry,
68809+ struct dentry *new_dentry,
68810+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
68811+{
68812+ struct name_entry *matchn;
68813+ struct name_entry *matchn2 = NULL;
68814+ struct inodev_entry *inodev;
68815+ struct inode *inode = new_dentry->d_inode;
68816+ ino_t old_ino = old_dentry->d_inode->i_ino;
68817+ dev_t old_dev = __get_dev(old_dentry);
68818+ unsigned int exchange = flags & RENAME_EXCHANGE;
68819+
68820+ /* vfs_rename swaps the name and parent link for old_dentry and
68821+ new_dentry
68822+ at this point, old_dentry has the new name, parent link, and inode
68823+ for the renamed file
68824+ if a file is being replaced by a rename, new_dentry has the inode
68825+ and name for the replaced file
68826+ */
68827+
68828+ if (unlikely(!(gr_status & GR_READY)))
68829+ return;
68830+
68831+ preempt_disable();
68832+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68833+
68834+ /* exchange cases:
68835+ a filename exists for the source, but not dest
68836+ do a recreate on source
68837+ a filename exists for the dest, but not source
68838+ do a recreate on dest
68839+ a filename exists for both source and dest
68840+ delete source and dest, then create source and dest
68841+ a filename exists for neither source nor dest
68842+ no updates needed
68843+
68844+ the name entry lookups get us the old inode/dev associated with
68845+ each name, so do the deletes first (if possible) so that when
68846+ we do the create, we pick up on the right entries
68847+ */
68848+
68849+ if (exchange)
68850+ matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
68851+
68852+ /* we wouldn't have to check d_inode if it weren't for
68853+ NFS silly-renaming
68854+ */
68855+
68856+ write_lock(&gr_inode_lock);
68857+ if (unlikely((replace || exchange) && inode)) {
68858+ ino_t new_ino = inode->i_ino;
68859+ dev_t new_dev = __get_dev(new_dentry);
68860+
68861+ inodev = lookup_inodev_entry(new_ino, new_dev);
68862+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68863+ do_handle_delete(inodev, new_ino, new_dev);
68864+ }
68865+
68866+ inodev = lookup_inodev_entry(old_ino, old_dev);
68867+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68868+ do_handle_delete(inodev, old_ino, old_dev);
68869+
68870+ if (unlikely(matchn != NULL))
68871+ do_handle_create(matchn, old_dentry, mnt);
68872+
68873+ if (unlikely(matchn2 != NULL))
68874+ do_handle_create(matchn2, new_dentry, mnt);
68875+
68876+ write_unlock(&gr_inode_lock);
68877+ preempt_enable();
68878+
68879+ return;
68880+}
68881+
68882+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68883+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68884+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
68885+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
68886+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
68887+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
68888+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
68889+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
68890+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
68891+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
68892+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
68893+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
68894+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
68895+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
68896+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
68897+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
68898+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
68899+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
68900+};
68901+
68902+void
68903+gr_learn_resource(const struct task_struct *task,
68904+ const int res, const unsigned long wanted, const int gt)
68905+{
68906+ struct acl_subject_label *acl;
68907+ const struct cred *cred;
68908+
68909+ if (unlikely((gr_status & GR_READY) &&
68910+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
68911+ goto skip_reslog;
68912+
68913+ gr_log_resource(task, res, wanted, gt);
68914+skip_reslog:
68915+
68916+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
68917+ return;
68918+
68919+ acl = task->acl;
68920+
68921+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
68922+ !(acl->resmask & (1U << (unsigned short) res))))
68923+ return;
68924+
68925+ if (wanted >= acl->res[res].rlim_cur) {
68926+ unsigned long res_add;
68927+
68928+ res_add = wanted + res_learn_bumps[res];
68929+
68930+ acl->res[res].rlim_cur = res_add;
68931+
68932+ if (wanted > acl->res[res].rlim_max)
68933+ acl->res[res].rlim_max = res_add;
68934+
68935+ /* only log the subject filename, since resource logging is supported for
68936+ single-subject learning only */
68937+ rcu_read_lock();
68938+ cred = __task_cred(task);
68939+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68940+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
68941+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
68942+ "", (unsigned long) res, &task->signal->saved_ip);
68943+ rcu_read_unlock();
68944+ }
68945+
68946+ return;
68947+}
68948+EXPORT_SYMBOL_GPL(gr_learn_resource);
68949+#endif
68950+
68951+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
68952+void
68953+pax_set_initial_flags(struct linux_binprm *bprm)
68954+{
68955+ struct task_struct *task = current;
68956+ struct acl_subject_label *proc;
68957+ unsigned long flags;
68958+
68959+ if (unlikely(!(gr_status & GR_READY)))
68960+ return;
68961+
68962+ flags = pax_get_flags(task);
68963+
68964+ proc = task->acl;
68965+
68966+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
68967+ flags &= ~MF_PAX_PAGEEXEC;
68968+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
68969+ flags &= ~MF_PAX_SEGMEXEC;
68970+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
68971+ flags &= ~MF_PAX_RANDMMAP;
68972+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
68973+ flags &= ~MF_PAX_EMUTRAMP;
68974+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
68975+ flags &= ~MF_PAX_MPROTECT;
68976+
68977+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
68978+ flags |= MF_PAX_PAGEEXEC;
68979+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
68980+ flags |= MF_PAX_SEGMEXEC;
68981+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
68982+ flags |= MF_PAX_RANDMMAP;
68983+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
68984+ flags |= MF_PAX_EMUTRAMP;
68985+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
68986+ flags |= MF_PAX_MPROTECT;
68987+
68988+ pax_set_flags(task, flags);
68989+
68990+ return;
68991+}
68992+#endif
68993+
68994+int
68995+gr_handle_proc_ptrace(struct task_struct *task)
68996+{
68997+ struct file *filp;
68998+ struct task_struct *tmp = task;
68999+ struct task_struct *curtemp = current;
69000+ __u32 retmode;
69001+
69002+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69003+ if (unlikely(!(gr_status & GR_READY)))
69004+ return 0;
69005+#endif
69006+
69007+ read_lock(&tasklist_lock);
69008+ read_lock(&grsec_exec_file_lock);
69009+ filp = task->exec_file;
69010+
69011+ while (task_pid_nr(tmp) > 0) {
69012+ if (tmp == curtemp)
69013+ break;
69014+ tmp = tmp->real_parent;
69015+ }
69016+
69017+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69018+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69019+ read_unlock(&grsec_exec_file_lock);
69020+ read_unlock(&tasklist_lock);
69021+ return 1;
69022+ }
69023+
69024+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69025+ if (!(gr_status & GR_READY)) {
69026+ read_unlock(&grsec_exec_file_lock);
69027+ read_unlock(&tasklist_lock);
69028+ return 0;
69029+ }
69030+#endif
69031+
69032+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69033+ read_unlock(&grsec_exec_file_lock);
69034+ read_unlock(&tasklist_lock);
69035+
69036+ if (retmode & GR_NOPTRACE)
69037+ return 1;
69038+
69039+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69040+ && (current->acl != task->acl || (current->acl != current->role->root_label
69041+ && task_pid_nr(current) != task_pid_nr(task))))
69042+ return 1;
69043+
69044+ return 0;
69045+}
69046+
69047+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69048+{
69049+ if (unlikely(!(gr_status & GR_READY)))
69050+ return;
69051+
69052+ if (!(current->role->roletype & GR_ROLE_GOD))
69053+ return;
69054+
69055+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69056+ p->role->rolename, gr_task_roletype_to_char(p),
69057+ p->acl->filename);
69058+}
69059+
69060+int
69061+gr_handle_ptrace(struct task_struct *task, const long request)
69062+{
69063+ struct task_struct *tmp = task;
69064+ struct task_struct *curtemp = current;
69065+ __u32 retmode;
69066+
69067+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69068+ if (unlikely(!(gr_status & GR_READY)))
69069+ return 0;
69070+#endif
69071+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69072+ read_lock(&tasklist_lock);
69073+ while (task_pid_nr(tmp) > 0) {
69074+ if (tmp == curtemp)
69075+ break;
69076+ tmp = tmp->real_parent;
69077+ }
69078+
69079+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69080+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69081+ read_unlock(&tasklist_lock);
69082+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69083+ return 1;
69084+ }
69085+ read_unlock(&tasklist_lock);
69086+ }
69087+
69088+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69089+ if (!(gr_status & GR_READY))
69090+ return 0;
69091+#endif
69092+
69093+ read_lock(&grsec_exec_file_lock);
69094+ if (unlikely(!task->exec_file)) {
69095+ read_unlock(&grsec_exec_file_lock);
69096+ return 0;
69097+ }
69098+
69099+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69100+ read_unlock(&grsec_exec_file_lock);
69101+
69102+ if (retmode & GR_NOPTRACE) {
69103+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69104+ return 1;
69105+ }
69106+
69107+ if (retmode & GR_PTRACERD) {
69108+ switch (request) {
69109+ case PTRACE_SEIZE:
69110+ case PTRACE_POKETEXT:
69111+ case PTRACE_POKEDATA:
69112+ case PTRACE_POKEUSR:
69113+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69114+ case PTRACE_SETREGS:
69115+ case PTRACE_SETFPREGS:
69116+#endif
69117+#ifdef CONFIG_X86
69118+ case PTRACE_SETFPXREGS:
69119+#endif
69120+#ifdef CONFIG_ALTIVEC
69121+ case PTRACE_SETVRREGS:
69122+#endif
69123+ return 1;
69124+ default:
69125+ return 0;
69126+ }
69127+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
69128+ !(current->role->roletype & GR_ROLE_GOD) &&
69129+ (current->acl != task->acl)) {
69130+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69131+ return 1;
69132+ }
69133+
69134+ return 0;
69135+}
69136+
69137+static int is_writable_mmap(const struct file *filp)
69138+{
69139+ struct task_struct *task = current;
69140+ struct acl_object_label *obj, *obj2;
69141+
69142+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69143+ !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))) {
69144+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69145+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69146+ task->role->root_label);
69147+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69148+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69149+ return 1;
69150+ }
69151+ }
69152+ return 0;
69153+}
69154+
69155+int
69156+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69157+{
69158+ __u32 mode;
69159+
69160+ if (unlikely(!file || !(prot & PROT_EXEC)))
69161+ return 1;
69162+
69163+ if (is_writable_mmap(file))
69164+ return 0;
69165+
69166+ mode =
69167+ gr_search_file(file->f_path.dentry,
69168+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69169+ file->f_path.mnt);
69170+
69171+ if (!gr_tpe_allow(file))
69172+ return 0;
69173+
69174+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69175+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69176+ return 0;
69177+ } else if (unlikely(!(mode & GR_EXEC))) {
69178+ return 0;
69179+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69180+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69181+ return 1;
69182+ }
69183+
69184+ return 1;
69185+}
69186+
69187+int
69188+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69189+{
69190+ __u32 mode;
69191+
69192+ if (unlikely(!file || !(prot & PROT_EXEC)))
69193+ return 1;
69194+
69195+ if (is_writable_mmap(file))
69196+ return 0;
69197+
69198+ mode =
69199+ gr_search_file(file->f_path.dentry,
69200+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69201+ file->f_path.mnt);
69202+
69203+ if (!gr_tpe_allow(file))
69204+ return 0;
69205+
69206+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69207+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69208+ return 0;
69209+ } else if (unlikely(!(mode & GR_EXEC))) {
69210+ return 0;
69211+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69212+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69213+ return 1;
69214+ }
69215+
69216+ return 1;
69217+}
69218+
69219+void
69220+gr_acl_handle_psacct(struct task_struct *task, const long code)
69221+{
69222+ unsigned long runtime, cputime;
69223+ cputime_t utime, stime;
69224+ unsigned int wday, cday;
69225+ __u8 whr, chr;
69226+ __u8 wmin, cmin;
69227+ __u8 wsec, csec;
69228+ struct timespec timeval;
69229+
69230+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69231+ !(task->acl->mode & GR_PROCACCT)))
69232+ return;
69233+
69234+ do_posix_clock_monotonic_gettime(&timeval);
69235+ runtime = timeval.tv_sec - task->start_time.tv_sec;
69236+ wday = runtime / (60 * 60 * 24);
69237+ runtime -= wday * (60 * 60 * 24);
69238+ whr = runtime / (60 * 60);
69239+ runtime -= whr * (60 * 60);
69240+ wmin = runtime / 60;
69241+ runtime -= wmin * 60;
69242+ wsec = runtime;
69243+
69244+ task_cputime(task, &utime, &stime);
69245+ cputime = cputime_to_secs(utime + stime);
69246+ cday = cputime / (60 * 60 * 24);
69247+ cputime -= cday * (60 * 60 * 24);
69248+ chr = cputime / (60 * 60);
69249+ cputime -= chr * (60 * 60);
69250+ cmin = cputime / 60;
69251+ cputime -= cmin * 60;
69252+ csec = cputime;
69253+
69254+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69255+
69256+ return;
69257+}
69258+
69259+#ifdef CONFIG_TASKSTATS
69260+int gr_is_taskstats_denied(int pid)
69261+{
69262+ struct task_struct *task;
69263+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69264+ const struct cred *cred;
69265+#endif
69266+ int ret = 0;
69267+
69268+ /* restrict taskstats viewing to un-chrooted root users
69269+ who have the 'view' subject flag if the RBAC system is enabled
69270+ */
69271+
69272+ rcu_read_lock();
69273+ read_lock(&tasklist_lock);
69274+ task = find_task_by_vpid(pid);
69275+ if (task) {
69276+#ifdef CONFIG_GRKERNSEC_CHROOT
69277+ if (proc_is_chrooted(task))
69278+ ret = -EACCES;
69279+#endif
69280+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69281+ cred = __task_cred(task);
69282+#ifdef CONFIG_GRKERNSEC_PROC_USER
69283+ if (gr_is_global_nonroot(cred->uid))
69284+ ret = -EACCES;
69285+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69286+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69287+ ret = -EACCES;
69288+#endif
69289+#endif
69290+ if (gr_status & GR_READY) {
69291+ if (!(task->acl->mode & GR_VIEW))
69292+ ret = -EACCES;
69293+ }
69294+ } else
69295+ ret = -ENOENT;
69296+
69297+ read_unlock(&tasklist_lock);
69298+ rcu_read_unlock();
69299+
69300+ return ret;
69301+}
69302+#endif
69303+
69304+/* AUXV entries are filled via a descendant of search_binary_handler
69305+ after we've already applied the subject for the target
69306+*/
69307+int gr_acl_enable_at_secure(void)
69308+{
69309+ if (unlikely(!(gr_status & GR_READY)))
69310+ return 0;
69311+
69312+ if (current->acl->mode & GR_ATSECURE)
69313+ return 1;
69314+
69315+ return 0;
69316+}
69317+
69318+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69319+{
69320+ struct task_struct *task = current;
69321+ struct dentry *dentry = file->f_path.dentry;
69322+ struct vfsmount *mnt = file->f_path.mnt;
69323+ struct acl_object_label *obj, *tmp;
69324+ struct acl_subject_label *subj;
69325+ unsigned int bufsize;
69326+ int is_not_root;
69327+ char *path;
69328+ dev_t dev = __get_dev(dentry);
69329+
69330+ if (unlikely(!(gr_status & GR_READY)))
69331+ return 1;
69332+
69333+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69334+ return 1;
69335+
69336+ /* ignore Eric Biederman */
69337+ if (IS_PRIVATE(dentry->d_inode))
69338+ return 1;
69339+
69340+ subj = task->acl;
69341+ read_lock(&gr_inode_lock);
69342+ do {
69343+ obj = lookup_acl_obj_label(ino, dev, subj);
69344+ if (obj != NULL) {
69345+ read_unlock(&gr_inode_lock);
69346+ return (obj->mode & GR_FIND) ? 1 : 0;
69347+ }
69348+ } while ((subj = subj->parent_subject));
69349+ read_unlock(&gr_inode_lock);
69350+
69351+ /* this is purely an optimization since we're looking for an object
69352+ for the directory we're doing a readdir on
69353+ if it's possible for any globbed object to match the entry we're
69354+ filling into the directory, then the object we find here will be
69355+ an anchor point with attached globbed objects
69356+ */
69357+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69358+ if (obj->globbed == NULL)
69359+ return (obj->mode & GR_FIND) ? 1 : 0;
69360+
69361+ is_not_root = ((obj->filename[0] == '/') &&
69362+ (obj->filename[1] == '\0')) ? 0 : 1;
69363+ bufsize = PAGE_SIZE - namelen - is_not_root;
69364+
69365+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
69366+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69367+ return 1;
69368+
69369+ preempt_disable();
69370+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69371+ bufsize);
69372+
69373+ bufsize = strlen(path);
69374+
69375+ /* if base is "/", don't append an additional slash */
69376+ if (is_not_root)
69377+ *(path + bufsize) = '/';
69378+ memcpy(path + bufsize + is_not_root, name, namelen);
69379+ *(path + bufsize + namelen + is_not_root) = '\0';
69380+
69381+ tmp = obj->globbed;
69382+ while (tmp) {
69383+ if (!glob_match(tmp->filename, path)) {
69384+ preempt_enable();
69385+ return (tmp->mode & GR_FIND) ? 1 : 0;
69386+ }
69387+ tmp = tmp->next;
69388+ }
69389+ preempt_enable();
69390+ return (obj->mode & GR_FIND) ? 1 : 0;
69391+}
69392+
69393+void gr_put_exec_file(struct task_struct *task)
69394+{
69395+ struct file *filp;
69396+
69397+ write_lock(&grsec_exec_file_lock);
69398+ filp = task->exec_file;
69399+ task->exec_file = NULL;
69400+ write_unlock(&grsec_exec_file_lock);
69401+
69402+ if (filp)
69403+ fput(filp);
69404+
69405+ return;
69406+}
69407+
69408+
69409+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69410+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69411+#endif
69412+#ifdef CONFIG_SECURITY
69413+EXPORT_SYMBOL_GPL(gr_check_user_change);
69414+EXPORT_SYMBOL_GPL(gr_check_group_change);
69415+#endif
69416+
69417diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69418new file mode 100644
69419index 0000000..18ffbbd
69420--- /dev/null
69421+++ b/grsecurity/gracl_alloc.c
69422@@ -0,0 +1,105 @@
69423+#include <linux/kernel.h>
69424+#include <linux/mm.h>
69425+#include <linux/slab.h>
69426+#include <linux/vmalloc.h>
69427+#include <linux/gracl.h>
69428+#include <linux/grsecurity.h>
69429+
69430+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69431+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69432+
69433+static __inline__ int
69434+alloc_pop(void)
69435+{
69436+ if (current_alloc_state->alloc_stack_next == 1)
69437+ return 0;
69438+
69439+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69440+
69441+ current_alloc_state->alloc_stack_next--;
69442+
69443+ return 1;
69444+}
69445+
69446+static __inline__ int
69447+alloc_push(void *buf)
69448+{
69449+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69450+ return 1;
69451+
69452+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69453+
69454+ current_alloc_state->alloc_stack_next++;
69455+
69456+ return 0;
69457+}
69458+
69459+void *
69460+acl_alloc(unsigned long len)
69461+{
69462+ void *ret = NULL;
69463+
69464+ if (!len || len > PAGE_SIZE)
69465+ goto out;
69466+
69467+ ret = kmalloc(len, GFP_KERNEL);
69468+
69469+ if (ret) {
69470+ if (alloc_push(ret)) {
69471+ kfree(ret);
69472+ ret = NULL;
69473+ }
69474+ }
69475+
69476+out:
69477+ return ret;
69478+}
69479+
69480+void *
69481+acl_alloc_num(unsigned long num, unsigned long len)
69482+{
69483+ if (!len || (num > (PAGE_SIZE / len)))
69484+ return NULL;
69485+
69486+ return acl_alloc(num * len);
69487+}
69488+
69489+void
69490+acl_free_all(void)
69491+{
69492+ if (!current_alloc_state->alloc_stack)
69493+ return;
69494+
69495+ while (alloc_pop()) ;
69496+
69497+ if (current_alloc_state->alloc_stack) {
69498+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69499+ kfree(current_alloc_state->alloc_stack);
69500+ else
69501+ vfree(current_alloc_state->alloc_stack);
69502+ }
69503+
69504+ current_alloc_state->alloc_stack = NULL;
69505+ current_alloc_state->alloc_stack_size = 1;
69506+ current_alloc_state->alloc_stack_next = 1;
69507+
69508+ return;
69509+}
69510+
69511+int
69512+acl_alloc_stack_init(unsigned long size)
69513+{
69514+ if ((size * sizeof (void *)) <= PAGE_SIZE)
69515+ current_alloc_state->alloc_stack =
69516+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69517+ else
69518+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69519+
69520+ current_alloc_state->alloc_stack_size = size;
69521+ current_alloc_state->alloc_stack_next = 1;
69522+
69523+ if (!current_alloc_state->alloc_stack)
69524+ return 0;
69525+ else
69526+ return 1;
69527+}
69528diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69529new file mode 100644
69530index 0000000..bdd51ea
69531--- /dev/null
69532+++ b/grsecurity/gracl_cap.c
69533@@ -0,0 +1,110 @@
69534+#include <linux/kernel.h>
69535+#include <linux/module.h>
69536+#include <linux/sched.h>
69537+#include <linux/gracl.h>
69538+#include <linux/grsecurity.h>
69539+#include <linux/grinternal.h>
69540+
69541+extern const char *captab_log[];
69542+extern int captab_log_entries;
69543+
69544+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69545+{
69546+ struct acl_subject_label *curracl;
69547+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69548+ kernel_cap_t cap_audit = __cap_empty_set;
69549+
69550+ if (!gr_acl_is_enabled())
69551+ return 1;
69552+
69553+ curracl = task->acl;
69554+
69555+ cap_drop = curracl->cap_lower;
69556+ cap_mask = curracl->cap_mask;
69557+ cap_audit = curracl->cap_invert_audit;
69558+
69559+ while ((curracl = curracl->parent_subject)) {
69560+ /* if the cap isn't specified in the current computed mask but is specified in the
69561+ current level subject, and is lowered in the current level subject, then add
69562+ it to the set of dropped capabilities
69563+ otherwise, add the current level subject's mask to the current computed mask
69564+ */
69565+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69566+ cap_raise(cap_mask, cap);
69567+ if (cap_raised(curracl->cap_lower, cap))
69568+ cap_raise(cap_drop, cap);
69569+ if (cap_raised(curracl->cap_invert_audit, cap))
69570+ cap_raise(cap_audit, cap);
69571+ }
69572+ }
69573+
69574+ if (!cap_raised(cap_drop, cap)) {
69575+ if (cap_raised(cap_audit, cap))
69576+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69577+ return 1;
69578+ }
69579+
69580+ curracl = task->acl;
69581+
69582+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69583+ && cap_raised(cred->cap_effective, cap)) {
69584+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69585+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
69586+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
69587+ gr_to_filename(task->exec_file->f_path.dentry,
69588+ task->exec_file->f_path.mnt) : curracl->filename,
69589+ curracl->filename, 0UL,
69590+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69591+ return 1;
69592+ }
69593+
69594+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69595+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69596+
69597+ return 0;
69598+}
69599+
69600+int
69601+gr_acl_is_capable(const int cap)
69602+{
69603+ return gr_task_acl_is_capable(current, current_cred(), cap);
69604+}
69605+
69606+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69607+{
69608+ struct acl_subject_label *curracl;
69609+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69610+
69611+ if (!gr_acl_is_enabled())
69612+ return 1;
69613+
69614+ curracl = task->acl;
69615+
69616+ cap_drop = curracl->cap_lower;
69617+ cap_mask = curracl->cap_mask;
69618+
69619+ while ((curracl = curracl->parent_subject)) {
69620+ /* if the cap isn't specified in the current computed mask but is specified in the
69621+ current level subject, and is lowered in the current level subject, then add
69622+ it to the set of dropped capabilities
69623+ otherwise, add the current level subject's mask to the current computed mask
69624+ */
69625+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69626+ cap_raise(cap_mask, cap);
69627+ if (cap_raised(curracl->cap_lower, cap))
69628+ cap_raise(cap_drop, cap);
69629+ }
69630+ }
69631+
69632+ if (!cap_raised(cap_drop, cap))
69633+ return 1;
69634+
69635+ return 0;
69636+}
69637+
69638+int
69639+gr_acl_is_capable_nolog(const int cap)
69640+{
69641+ return gr_task_acl_is_capable_nolog(current, cap);
69642+}
69643+
69644diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69645new file mode 100644
69646index 0000000..ca25605
69647--- /dev/null
69648+++ b/grsecurity/gracl_compat.c
69649@@ -0,0 +1,270 @@
69650+#include <linux/kernel.h>
69651+#include <linux/gracl.h>
69652+#include <linux/compat.h>
69653+#include <linux/gracl_compat.h>
69654+
69655+#include <asm/uaccess.h>
69656+
69657+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69658+{
69659+ struct gr_arg_wrapper_compat uwrapcompat;
69660+
69661+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69662+ return -EFAULT;
69663+
69664+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69665+ (uwrapcompat.version != 0x2901)) ||
69666+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69667+ return -EINVAL;
69668+
69669+ uwrap->arg = compat_ptr(uwrapcompat.arg);
69670+ uwrap->version = uwrapcompat.version;
69671+ uwrap->size = sizeof(struct gr_arg);
69672+
69673+ return 0;
69674+}
69675+
69676+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69677+{
69678+ struct gr_arg_compat argcompat;
69679+
69680+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69681+ return -EFAULT;
69682+
69683+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69684+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69685+ arg->role_db.num_roles = argcompat.role_db.num_roles;
69686+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69687+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69688+ arg->role_db.num_objects = argcompat.role_db.num_objects;
69689+
69690+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69691+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69692+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69693+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69694+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69695+ arg->segv_device = argcompat.segv_device;
69696+ arg->segv_inode = argcompat.segv_inode;
69697+ arg->segv_uid = argcompat.segv_uid;
69698+ arg->num_sprole_pws = argcompat.num_sprole_pws;
69699+ arg->mode = argcompat.mode;
69700+
69701+ return 0;
69702+}
69703+
69704+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69705+{
69706+ struct acl_object_label_compat objcompat;
69707+
69708+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69709+ return -EFAULT;
69710+
69711+ obj->filename = compat_ptr(objcompat.filename);
69712+ obj->inode = objcompat.inode;
69713+ obj->device = objcompat.device;
69714+ obj->mode = objcompat.mode;
69715+
69716+ obj->nested = compat_ptr(objcompat.nested);
69717+ obj->globbed = compat_ptr(objcompat.globbed);
69718+
69719+ obj->prev = compat_ptr(objcompat.prev);
69720+ obj->next = compat_ptr(objcompat.next);
69721+
69722+ return 0;
69723+}
69724+
69725+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69726+{
69727+ unsigned int i;
69728+ struct acl_subject_label_compat subjcompat;
69729+
69730+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69731+ return -EFAULT;
69732+
69733+ subj->filename = compat_ptr(subjcompat.filename);
69734+ subj->inode = subjcompat.inode;
69735+ subj->device = subjcompat.device;
69736+ subj->mode = subjcompat.mode;
69737+ subj->cap_mask = subjcompat.cap_mask;
69738+ subj->cap_lower = subjcompat.cap_lower;
69739+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
69740+
69741+ for (i = 0; i < GR_NLIMITS; i++) {
69742+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69743+ subj->res[i].rlim_cur = RLIM_INFINITY;
69744+ else
69745+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69746+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69747+ subj->res[i].rlim_max = RLIM_INFINITY;
69748+ else
69749+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69750+ }
69751+ subj->resmask = subjcompat.resmask;
69752+
69753+ subj->user_trans_type = subjcompat.user_trans_type;
69754+ subj->group_trans_type = subjcompat.group_trans_type;
69755+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69756+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69757+ subj->user_trans_num = subjcompat.user_trans_num;
69758+ subj->group_trans_num = subjcompat.group_trans_num;
69759+
69760+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69761+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69762+ subj->ip_type = subjcompat.ip_type;
69763+ subj->ips = compat_ptr(subjcompat.ips);
69764+ subj->ip_num = subjcompat.ip_num;
69765+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
69766+
69767+ subj->crashes = subjcompat.crashes;
69768+ subj->expires = subjcompat.expires;
69769+
69770+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69771+ subj->hash = compat_ptr(subjcompat.hash);
69772+ subj->prev = compat_ptr(subjcompat.prev);
69773+ subj->next = compat_ptr(subjcompat.next);
69774+
69775+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69776+ subj->obj_hash_size = subjcompat.obj_hash_size;
69777+ subj->pax_flags = subjcompat.pax_flags;
69778+
69779+ return 0;
69780+}
69781+
69782+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69783+{
69784+ struct acl_role_label_compat rolecompat;
69785+
69786+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69787+ return -EFAULT;
69788+
69789+ role->rolename = compat_ptr(rolecompat.rolename);
69790+ role->uidgid = rolecompat.uidgid;
69791+ role->roletype = rolecompat.roletype;
69792+
69793+ role->auth_attempts = rolecompat.auth_attempts;
69794+ role->expires = rolecompat.expires;
69795+
69796+ role->root_label = compat_ptr(rolecompat.root_label);
69797+ role->hash = compat_ptr(rolecompat.hash);
69798+
69799+ role->prev = compat_ptr(rolecompat.prev);
69800+ role->next = compat_ptr(rolecompat.next);
69801+
69802+ role->transitions = compat_ptr(rolecompat.transitions);
69803+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69804+ role->domain_children = compat_ptr(rolecompat.domain_children);
69805+ role->domain_child_num = rolecompat.domain_child_num;
69806+
69807+ role->umask = rolecompat.umask;
69808+
69809+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
69810+ role->subj_hash_size = rolecompat.subj_hash_size;
69811+
69812+ return 0;
69813+}
69814+
69815+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69816+{
69817+ struct role_allowed_ip_compat roleip_compat;
69818+
69819+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69820+ return -EFAULT;
69821+
69822+ roleip->addr = roleip_compat.addr;
69823+ roleip->netmask = roleip_compat.netmask;
69824+
69825+ roleip->prev = compat_ptr(roleip_compat.prev);
69826+ roleip->next = compat_ptr(roleip_compat.next);
69827+
69828+ return 0;
69829+}
69830+
69831+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69832+{
69833+ struct role_transition_compat trans_compat;
69834+
69835+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69836+ return -EFAULT;
69837+
69838+ trans->rolename = compat_ptr(trans_compat.rolename);
69839+
69840+ trans->prev = compat_ptr(trans_compat.prev);
69841+ trans->next = compat_ptr(trans_compat.next);
69842+
69843+ return 0;
69844+
69845+}
69846+
69847+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69848+{
69849+ struct gr_hash_struct_compat hash_compat;
69850+
69851+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69852+ return -EFAULT;
69853+
69854+ hash->table = compat_ptr(hash_compat.table);
69855+ hash->nametable = compat_ptr(hash_compat.nametable);
69856+ hash->first = compat_ptr(hash_compat.first);
69857+
69858+ hash->table_size = hash_compat.table_size;
69859+ hash->used_size = hash_compat.used_size;
69860+
69861+ hash->type = hash_compat.type;
69862+
69863+ return 0;
69864+}
69865+
69866+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69867+{
69868+ compat_uptr_t ptrcompat;
69869+
69870+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69871+ return -EFAULT;
69872+
69873+ *(void **)ptr = compat_ptr(ptrcompat);
69874+
69875+ return 0;
69876+}
69877+
69878+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69879+{
69880+ struct acl_ip_label_compat ip_compat;
69881+
69882+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69883+ return -EFAULT;
69884+
69885+ ip->iface = compat_ptr(ip_compat.iface);
69886+ ip->addr = ip_compat.addr;
69887+ ip->netmask = ip_compat.netmask;
69888+ ip->low = ip_compat.low;
69889+ ip->high = ip_compat.high;
69890+ ip->mode = ip_compat.mode;
69891+ ip->type = ip_compat.type;
69892+
69893+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
69894+
69895+ ip->prev = compat_ptr(ip_compat.prev);
69896+ ip->next = compat_ptr(ip_compat.next);
69897+
69898+ return 0;
69899+}
69900+
69901+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69902+{
69903+ struct sprole_pw_compat pw_compat;
69904+
69905+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
69906+ return -EFAULT;
69907+
69908+ pw->rolename = compat_ptr(pw_compat.rolename);
69909+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
69910+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
69911+
69912+ return 0;
69913+}
69914+
69915+size_t get_gr_arg_wrapper_size_compat(void)
69916+{
69917+ return sizeof(struct gr_arg_wrapper_compat);
69918+}
69919+
69920diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
69921new file mode 100644
69922index 0000000..4008fdc
69923--- /dev/null
69924+++ b/grsecurity/gracl_fs.c
69925@@ -0,0 +1,445 @@
69926+#include <linux/kernel.h>
69927+#include <linux/sched.h>
69928+#include <linux/types.h>
69929+#include <linux/fs.h>
69930+#include <linux/file.h>
69931+#include <linux/stat.h>
69932+#include <linux/grsecurity.h>
69933+#include <linux/grinternal.h>
69934+#include <linux/gracl.h>
69935+
69936+umode_t
69937+gr_acl_umask(void)
69938+{
69939+ if (unlikely(!gr_acl_is_enabled()))
69940+ return 0;
69941+
69942+ return current->role->umask;
69943+}
69944+
69945+__u32
69946+gr_acl_handle_hidden_file(const struct dentry * dentry,
69947+ const struct vfsmount * mnt)
69948+{
69949+ __u32 mode;
69950+
69951+ if (unlikely(d_is_negative(dentry)))
69952+ return GR_FIND;
69953+
69954+ mode =
69955+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
69956+
69957+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
69958+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69959+ return mode;
69960+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
69961+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69962+ return 0;
69963+ } else if (unlikely(!(mode & GR_FIND)))
69964+ return 0;
69965+
69966+ return GR_FIND;
69967+}
69968+
69969+__u32
69970+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69971+ int acc_mode)
69972+{
69973+ __u32 reqmode = GR_FIND;
69974+ __u32 mode;
69975+
69976+ if (unlikely(d_is_negative(dentry)))
69977+ return reqmode;
69978+
69979+ if (acc_mode & MAY_APPEND)
69980+ reqmode |= GR_APPEND;
69981+ else if (acc_mode & MAY_WRITE)
69982+ reqmode |= GR_WRITE;
69983+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
69984+ reqmode |= GR_READ;
69985+
69986+ mode =
69987+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69988+ mnt);
69989+
69990+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69991+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69992+ reqmode & GR_READ ? " reading" : "",
69993+ reqmode & GR_WRITE ? " writing" : reqmode &
69994+ GR_APPEND ? " appending" : "");
69995+ return reqmode;
69996+ } else
69997+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69998+ {
69999+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70000+ reqmode & GR_READ ? " reading" : "",
70001+ reqmode & GR_WRITE ? " writing" : reqmode &
70002+ GR_APPEND ? " appending" : "");
70003+ return 0;
70004+ } else if (unlikely((mode & reqmode) != reqmode))
70005+ return 0;
70006+
70007+ return reqmode;
70008+}
70009+
70010+__u32
70011+gr_acl_handle_creat(const struct dentry * dentry,
70012+ const struct dentry * p_dentry,
70013+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70014+ const int imode)
70015+{
70016+ __u32 reqmode = GR_WRITE | GR_CREATE;
70017+ __u32 mode;
70018+
70019+ if (acc_mode & MAY_APPEND)
70020+ reqmode |= GR_APPEND;
70021+ // if a directory was required or the directory already exists, then
70022+ // don't count this open as a read
70023+ if ((acc_mode & MAY_READ) &&
70024+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70025+ reqmode |= GR_READ;
70026+ if ((open_flags & O_CREAT) &&
70027+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70028+ reqmode |= GR_SETID;
70029+
70030+ mode =
70031+ gr_check_create(dentry, p_dentry, p_mnt,
70032+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70033+
70034+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70035+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70036+ reqmode & GR_READ ? " reading" : "",
70037+ reqmode & GR_WRITE ? " writing" : reqmode &
70038+ GR_APPEND ? " appending" : "");
70039+ return reqmode;
70040+ } else
70041+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70042+ {
70043+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70044+ reqmode & GR_READ ? " reading" : "",
70045+ reqmode & GR_WRITE ? " writing" : reqmode &
70046+ GR_APPEND ? " appending" : "");
70047+ return 0;
70048+ } else if (unlikely((mode & reqmode) != reqmode))
70049+ return 0;
70050+
70051+ return reqmode;
70052+}
70053+
70054+__u32
70055+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70056+ const int fmode)
70057+{
70058+ __u32 mode, reqmode = GR_FIND;
70059+
70060+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70061+ reqmode |= GR_EXEC;
70062+ if (fmode & S_IWOTH)
70063+ reqmode |= GR_WRITE;
70064+ if (fmode & S_IROTH)
70065+ reqmode |= GR_READ;
70066+
70067+ mode =
70068+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70069+ mnt);
70070+
70071+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70072+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70073+ reqmode & GR_READ ? " reading" : "",
70074+ reqmode & GR_WRITE ? " writing" : "",
70075+ reqmode & GR_EXEC ? " executing" : "");
70076+ return reqmode;
70077+ } else
70078+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70079+ {
70080+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70081+ reqmode & GR_READ ? " reading" : "",
70082+ reqmode & GR_WRITE ? " writing" : "",
70083+ reqmode & GR_EXEC ? " executing" : "");
70084+ return 0;
70085+ } else if (unlikely((mode & reqmode) != reqmode))
70086+ return 0;
70087+
70088+ return reqmode;
70089+}
70090+
70091+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70092+{
70093+ __u32 mode;
70094+
70095+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70096+
70097+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70098+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70099+ return mode;
70100+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70101+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70102+ return 0;
70103+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70104+ return 0;
70105+
70106+ return (reqmode);
70107+}
70108+
70109+__u32
70110+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70111+{
70112+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70113+}
70114+
70115+__u32
70116+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70117+{
70118+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70119+}
70120+
70121+__u32
70122+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70123+{
70124+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70125+}
70126+
70127+__u32
70128+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70129+{
70130+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70131+}
70132+
70133+__u32
70134+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70135+ umode_t *modeptr)
70136+{
70137+ umode_t mode;
70138+
70139+ *modeptr &= ~gr_acl_umask();
70140+ mode = *modeptr;
70141+
70142+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70143+ return 1;
70144+
70145+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70146+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70147+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70148+ GR_CHMOD_ACL_MSG);
70149+ } else {
70150+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70151+ }
70152+}
70153+
70154+__u32
70155+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70156+{
70157+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70158+}
70159+
70160+__u32
70161+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70162+{
70163+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70164+}
70165+
70166+__u32
70167+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70168+{
70169+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70170+}
70171+
70172+__u32
70173+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70174+{
70175+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70176+}
70177+
70178+__u32
70179+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70180+{
70181+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70182+ GR_UNIXCONNECT_ACL_MSG);
70183+}
70184+
70185+/* hardlinks require at minimum create and link permission,
70186+ any additional privilege required is based on the
70187+ privilege of the file being linked to
70188+*/
70189+__u32
70190+gr_acl_handle_link(const struct dentry * new_dentry,
70191+ const struct dentry * parent_dentry,
70192+ const struct vfsmount * parent_mnt,
70193+ const struct dentry * old_dentry,
70194+ const struct vfsmount * old_mnt, const struct filename *to)
70195+{
70196+ __u32 mode;
70197+ __u32 needmode = GR_CREATE | GR_LINK;
70198+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70199+
70200+ mode =
70201+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70202+ old_mnt);
70203+
70204+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70205+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70206+ return mode;
70207+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70208+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70209+ return 0;
70210+ } else if (unlikely((mode & needmode) != needmode))
70211+ return 0;
70212+
70213+ return 1;
70214+}
70215+
70216+__u32
70217+gr_acl_handle_symlink(const struct dentry * new_dentry,
70218+ const struct dentry * parent_dentry,
70219+ const struct vfsmount * parent_mnt, const struct filename *from)
70220+{
70221+ __u32 needmode = GR_WRITE | GR_CREATE;
70222+ __u32 mode;
70223+
70224+ mode =
70225+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
70226+ GR_CREATE | GR_AUDIT_CREATE |
70227+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70228+
70229+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70230+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70231+ return mode;
70232+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70233+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70234+ return 0;
70235+ } else if (unlikely((mode & needmode) != needmode))
70236+ return 0;
70237+
70238+ return (GR_WRITE | GR_CREATE);
70239+}
70240+
70241+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)
70242+{
70243+ __u32 mode;
70244+
70245+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70246+
70247+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70248+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70249+ return mode;
70250+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70251+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70252+ return 0;
70253+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70254+ return 0;
70255+
70256+ return (reqmode);
70257+}
70258+
70259+__u32
70260+gr_acl_handle_mknod(const struct dentry * new_dentry,
70261+ const struct dentry * parent_dentry,
70262+ const struct vfsmount * parent_mnt,
70263+ const int mode)
70264+{
70265+ __u32 reqmode = GR_WRITE | GR_CREATE;
70266+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70267+ reqmode |= GR_SETID;
70268+
70269+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70270+ reqmode, GR_MKNOD_ACL_MSG);
70271+}
70272+
70273+__u32
70274+gr_acl_handle_mkdir(const struct dentry *new_dentry,
70275+ const struct dentry *parent_dentry,
70276+ const struct vfsmount *parent_mnt)
70277+{
70278+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70279+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70280+}
70281+
70282+#define RENAME_CHECK_SUCCESS(old, new) \
70283+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70284+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70285+
70286+int
70287+gr_acl_handle_rename(struct dentry *new_dentry,
70288+ struct dentry *parent_dentry,
70289+ const struct vfsmount *parent_mnt,
70290+ struct dentry *old_dentry,
70291+ struct inode *old_parent_inode,
70292+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
70293+{
70294+ __u32 comp1, comp2;
70295+ int error = 0;
70296+
70297+ if (unlikely(!gr_acl_is_enabled()))
70298+ return 0;
70299+
70300+ if (flags & RENAME_EXCHANGE) {
70301+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70302+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70303+ GR_SUPPRESS, parent_mnt);
70304+ comp2 =
70305+ gr_search_file(old_dentry,
70306+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70307+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70308+ } else if (d_is_negative(new_dentry)) {
70309+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70310+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70311+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70312+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70313+ GR_DELETE | GR_AUDIT_DELETE |
70314+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70315+ GR_SUPPRESS, old_mnt);
70316+ } else {
70317+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70318+ GR_CREATE | GR_DELETE |
70319+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70320+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70321+ GR_SUPPRESS, parent_mnt);
70322+ comp2 =
70323+ gr_search_file(old_dentry,
70324+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70325+ GR_DELETE | GR_AUDIT_DELETE |
70326+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70327+ }
70328+
70329+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70330+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70331+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70332+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70333+ && !(comp2 & GR_SUPPRESS)) {
70334+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70335+ error = -EACCES;
70336+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70337+ error = -EACCES;
70338+
70339+ return error;
70340+}
70341+
70342+void
70343+gr_acl_handle_exit(void)
70344+{
70345+ u16 id;
70346+ char *rolename;
70347+
70348+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70349+ !(current->role->roletype & GR_ROLE_PERSIST))) {
70350+ id = current->acl_role_id;
70351+ rolename = current->role->rolename;
70352+ gr_set_acls(1);
70353+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70354+ }
70355+
70356+ gr_put_exec_file(current);
70357+ return;
70358+}
70359+
70360+int
70361+gr_acl_handle_procpidmem(const struct task_struct *task)
70362+{
70363+ if (unlikely(!gr_acl_is_enabled()))
70364+ return 0;
70365+
70366+ if (task != current && task->acl->mode & GR_PROTPROCFD)
70367+ return -EACCES;
70368+
70369+ return 0;
70370+}
70371diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70372new file mode 100644
70373index 0000000..f056b81
70374--- /dev/null
70375+++ b/grsecurity/gracl_ip.c
70376@@ -0,0 +1,386 @@
70377+#include <linux/kernel.h>
70378+#include <asm/uaccess.h>
70379+#include <asm/errno.h>
70380+#include <net/sock.h>
70381+#include <linux/file.h>
70382+#include <linux/fs.h>
70383+#include <linux/net.h>
70384+#include <linux/in.h>
70385+#include <linux/skbuff.h>
70386+#include <linux/ip.h>
70387+#include <linux/udp.h>
70388+#include <linux/types.h>
70389+#include <linux/sched.h>
70390+#include <linux/netdevice.h>
70391+#include <linux/inetdevice.h>
70392+#include <linux/gracl.h>
70393+#include <linux/grsecurity.h>
70394+#include <linux/grinternal.h>
70395+
70396+#define GR_BIND 0x01
70397+#define GR_CONNECT 0x02
70398+#define GR_INVERT 0x04
70399+#define GR_BINDOVERRIDE 0x08
70400+#define GR_CONNECTOVERRIDE 0x10
70401+#define GR_SOCK_FAMILY 0x20
70402+
70403+static const char * gr_protocols[IPPROTO_MAX] = {
70404+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70405+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70406+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70407+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70408+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70409+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70410+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70411+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70412+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70413+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70414+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70415+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70416+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70417+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70418+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70419+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70420+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70421+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70422+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70423+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70424+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70425+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70426+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70427+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70428+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70429+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70430+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70431+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70432+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70433+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70434+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70435+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70436+ };
70437+
70438+static const char * gr_socktypes[SOCK_MAX] = {
70439+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70440+ "unknown:7", "unknown:8", "unknown:9", "packet"
70441+ };
70442+
70443+static const char * gr_sockfamilies[AF_MAX+1] = {
70444+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70445+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70446+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70447+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70448+ };
70449+
70450+const char *
70451+gr_proto_to_name(unsigned char proto)
70452+{
70453+ return gr_protocols[proto];
70454+}
70455+
70456+const char *
70457+gr_socktype_to_name(unsigned char type)
70458+{
70459+ return gr_socktypes[type];
70460+}
70461+
70462+const char *
70463+gr_sockfamily_to_name(unsigned char family)
70464+{
70465+ return gr_sockfamilies[family];
70466+}
70467+
70468+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70469+
70470+int
70471+gr_search_socket(const int domain, const int type, const int protocol)
70472+{
70473+ struct acl_subject_label *curr;
70474+ const struct cred *cred = current_cred();
70475+
70476+ if (unlikely(!gr_acl_is_enabled()))
70477+ goto exit;
70478+
70479+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
70480+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70481+ goto exit; // let the kernel handle it
70482+
70483+ curr = current->acl;
70484+
70485+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70486+ /* the family is allowed, if this is PF_INET allow it only if
70487+ the extra sock type/protocol checks pass */
70488+ if (domain == PF_INET)
70489+ goto inet_check;
70490+ goto exit;
70491+ } else {
70492+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70493+ __u32 fakeip = 0;
70494+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70495+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70496+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70497+ gr_to_filename(current->exec_file->f_path.dentry,
70498+ current->exec_file->f_path.mnt) :
70499+ curr->filename, curr->filename,
70500+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70501+ &current->signal->saved_ip);
70502+ goto exit;
70503+ }
70504+ goto exit_fail;
70505+ }
70506+
70507+inet_check:
70508+ /* the rest of this checking is for IPv4 only */
70509+ if (!curr->ips)
70510+ goto exit;
70511+
70512+ if ((curr->ip_type & (1U << type)) &&
70513+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70514+ goto exit;
70515+
70516+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70517+ /* we don't place acls on raw sockets , and sometimes
70518+ dgram/ip sockets are opened for ioctl and not
70519+ bind/connect, so we'll fake a bind learn log */
70520+ if (type == SOCK_RAW || type == SOCK_PACKET) {
70521+ __u32 fakeip = 0;
70522+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70523+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70524+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70525+ gr_to_filename(current->exec_file->f_path.dentry,
70526+ current->exec_file->f_path.mnt) :
70527+ curr->filename, curr->filename,
70528+ &fakeip, 0, type,
70529+ protocol, GR_CONNECT, &current->signal->saved_ip);
70530+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70531+ __u32 fakeip = 0;
70532+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70533+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70534+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70535+ gr_to_filename(current->exec_file->f_path.dentry,
70536+ current->exec_file->f_path.mnt) :
70537+ curr->filename, curr->filename,
70538+ &fakeip, 0, type,
70539+ protocol, GR_BIND, &current->signal->saved_ip);
70540+ }
70541+ /* we'll log when they use connect or bind */
70542+ goto exit;
70543+ }
70544+
70545+exit_fail:
70546+ if (domain == PF_INET)
70547+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70548+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
70549+ else if (rcu_access_pointer(net_families[domain]) != NULL)
70550+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70551+ gr_socktype_to_name(type), protocol);
70552+
70553+ return 0;
70554+exit:
70555+ return 1;
70556+}
70557+
70558+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)
70559+{
70560+ if ((ip->mode & mode) &&
70561+ (ip_port >= ip->low) &&
70562+ (ip_port <= ip->high) &&
70563+ ((ntohl(ip_addr) & our_netmask) ==
70564+ (ntohl(our_addr) & our_netmask))
70565+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70566+ && (ip->type & (1U << type))) {
70567+ if (ip->mode & GR_INVERT)
70568+ return 2; // specifically denied
70569+ else
70570+ return 1; // allowed
70571+ }
70572+
70573+ return 0; // not specifically allowed, may continue parsing
70574+}
70575+
70576+static int
70577+gr_search_connectbind(const int full_mode, struct sock *sk,
70578+ struct sockaddr_in *addr, const int type)
70579+{
70580+ char iface[IFNAMSIZ] = {0};
70581+ struct acl_subject_label *curr;
70582+ struct acl_ip_label *ip;
70583+ struct inet_sock *isk;
70584+ struct net_device *dev;
70585+ struct in_device *idev;
70586+ unsigned long i;
70587+ int ret;
70588+ int mode = full_mode & (GR_BIND | GR_CONNECT);
70589+ __u32 ip_addr = 0;
70590+ __u32 our_addr;
70591+ __u32 our_netmask;
70592+ char *p;
70593+ __u16 ip_port = 0;
70594+ const struct cred *cred = current_cred();
70595+
70596+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70597+ return 0;
70598+
70599+ curr = current->acl;
70600+ isk = inet_sk(sk);
70601+
70602+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70603+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70604+ addr->sin_addr.s_addr = curr->inaddr_any_override;
70605+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70606+ struct sockaddr_in saddr;
70607+ int err;
70608+
70609+ saddr.sin_family = AF_INET;
70610+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
70611+ saddr.sin_port = isk->inet_sport;
70612+
70613+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70614+ if (err)
70615+ return err;
70616+
70617+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70618+ if (err)
70619+ return err;
70620+ }
70621+
70622+ if (!curr->ips)
70623+ return 0;
70624+
70625+ ip_addr = addr->sin_addr.s_addr;
70626+ ip_port = ntohs(addr->sin_port);
70627+
70628+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70629+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70630+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70631+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70632+ gr_to_filename(current->exec_file->f_path.dentry,
70633+ current->exec_file->f_path.mnt) :
70634+ curr->filename, curr->filename,
70635+ &ip_addr, ip_port, type,
70636+ sk->sk_protocol, mode, &current->signal->saved_ip);
70637+ return 0;
70638+ }
70639+
70640+ for (i = 0; i < curr->ip_num; i++) {
70641+ ip = *(curr->ips + i);
70642+ if (ip->iface != NULL) {
70643+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
70644+ p = strchr(iface, ':');
70645+ if (p != NULL)
70646+ *p = '\0';
70647+ dev = dev_get_by_name(sock_net(sk), iface);
70648+ if (dev == NULL)
70649+ continue;
70650+ idev = in_dev_get(dev);
70651+ if (idev == NULL) {
70652+ dev_put(dev);
70653+ continue;
70654+ }
70655+ rcu_read_lock();
70656+ for_ifa(idev) {
70657+ if (!strcmp(ip->iface, ifa->ifa_label)) {
70658+ our_addr = ifa->ifa_address;
70659+ our_netmask = 0xffffffff;
70660+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70661+ if (ret == 1) {
70662+ rcu_read_unlock();
70663+ in_dev_put(idev);
70664+ dev_put(dev);
70665+ return 0;
70666+ } else if (ret == 2) {
70667+ rcu_read_unlock();
70668+ in_dev_put(idev);
70669+ dev_put(dev);
70670+ goto denied;
70671+ }
70672+ }
70673+ } endfor_ifa(idev);
70674+ rcu_read_unlock();
70675+ in_dev_put(idev);
70676+ dev_put(dev);
70677+ } else {
70678+ our_addr = ip->addr;
70679+ our_netmask = ip->netmask;
70680+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70681+ if (ret == 1)
70682+ return 0;
70683+ else if (ret == 2)
70684+ goto denied;
70685+ }
70686+ }
70687+
70688+denied:
70689+ if (mode == GR_BIND)
70690+ 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));
70691+ else if (mode == GR_CONNECT)
70692+ 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));
70693+
70694+ return -EACCES;
70695+}
70696+
70697+int
70698+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70699+{
70700+ /* always allow disconnection of dgram sockets with connect */
70701+ if (addr->sin_family == AF_UNSPEC)
70702+ return 0;
70703+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70704+}
70705+
70706+int
70707+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70708+{
70709+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70710+}
70711+
70712+int gr_search_listen(struct socket *sock)
70713+{
70714+ struct sock *sk = sock->sk;
70715+ struct sockaddr_in addr;
70716+
70717+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70718+ addr.sin_port = inet_sk(sk)->inet_sport;
70719+
70720+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70721+}
70722+
70723+int gr_search_accept(struct socket *sock)
70724+{
70725+ struct sock *sk = sock->sk;
70726+ struct sockaddr_in addr;
70727+
70728+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70729+ addr.sin_port = inet_sk(sk)->inet_sport;
70730+
70731+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70732+}
70733+
70734+int
70735+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70736+{
70737+ if (addr)
70738+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70739+ else {
70740+ struct sockaddr_in sin;
70741+ const struct inet_sock *inet = inet_sk(sk);
70742+
70743+ sin.sin_addr.s_addr = inet->inet_daddr;
70744+ sin.sin_port = inet->inet_dport;
70745+
70746+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70747+ }
70748+}
70749+
70750+int
70751+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70752+{
70753+ struct sockaddr_in sin;
70754+
70755+ if (unlikely(skb->len < sizeof (struct udphdr)))
70756+ return 0; // skip this packet
70757+
70758+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70759+ sin.sin_port = udp_hdr(skb)->source;
70760+
70761+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70762+}
70763diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70764new file mode 100644
70765index 0000000..25f54ef
70766--- /dev/null
70767+++ b/grsecurity/gracl_learn.c
70768@@ -0,0 +1,207 @@
70769+#include <linux/kernel.h>
70770+#include <linux/mm.h>
70771+#include <linux/sched.h>
70772+#include <linux/poll.h>
70773+#include <linux/string.h>
70774+#include <linux/file.h>
70775+#include <linux/types.h>
70776+#include <linux/vmalloc.h>
70777+#include <linux/grinternal.h>
70778+
70779+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70780+ size_t count, loff_t *ppos);
70781+extern int gr_acl_is_enabled(void);
70782+
70783+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70784+static int gr_learn_attached;
70785+
70786+/* use a 512k buffer */
70787+#define LEARN_BUFFER_SIZE (512 * 1024)
70788+
70789+static DEFINE_SPINLOCK(gr_learn_lock);
70790+static DEFINE_MUTEX(gr_learn_user_mutex);
70791+
70792+/* we need to maintain two buffers, so that the kernel context of grlearn
70793+ uses a semaphore around the userspace copying, and the other kernel contexts
70794+ use a spinlock when copying into the buffer, since they cannot sleep
70795+*/
70796+static char *learn_buffer;
70797+static char *learn_buffer_user;
70798+static int learn_buffer_len;
70799+static int learn_buffer_user_len;
70800+
70801+static ssize_t
70802+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70803+{
70804+ DECLARE_WAITQUEUE(wait, current);
70805+ ssize_t retval = 0;
70806+
70807+ add_wait_queue(&learn_wait, &wait);
70808+ set_current_state(TASK_INTERRUPTIBLE);
70809+ do {
70810+ mutex_lock(&gr_learn_user_mutex);
70811+ spin_lock(&gr_learn_lock);
70812+ if (learn_buffer_len)
70813+ break;
70814+ spin_unlock(&gr_learn_lock);
70815+ mutex_unlock(&gr_learn_user_mutex);
70816+ if (file->f_flags & O_NONBLOCK) {
70817+ retval = -EAGAIN;
70818+ goto out;
70819+ }
70820+ if (signal_pending(current)) {
70821+ retval = -ERESTARTSYS;
70822+ goto out;
70823+ }
70824+
70825+ schedule();
70826+ } while (1);
70827+
70828+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70829+ learn_buffer_user_len = learn_buffer_len;
70830+ retval = learn_buffer_len;
70831+ learn_buffer_len = 0;
70832+
70833+ spin_unlock(&gr_learn_lock);
70834+
70835+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70836+ retval = -EFAULT;
70837+
70838+ mutex_unlock(&gr_learn_user_mutex);
70839+out:
70840+ set_current_state(TASK_RUNNING);
70841+ remove_wait_queue(&learn_wait, &wait);
70842+ return retval;
70843+}
70844+
70845+static unsigned int
70846+poll_learn(struct file * file, poll_table * wait)
70847+{
70848+ poll_wait(file, &learn_wait, wait);
70849+
70850+ if (learn_buffer_len)
70851+ return (POLLIN | POLLRDNORM);
70852+
70853+ return 0;
70854+}
70855+
70856+void
70857+gr_clear_learn_entries(void)
70858+{
70859+ char *tmp;
70860+
70861+ mutex_lock(&gr_learn_user_mutex);
70862+ spin_lock(&gr_learn_lock);
70863+ tmp = learn_buffer;
70864+ learn_buffer = NULL;
70865+ spin_unlock(&gr_learn_lock);
70866+ if (tmp)
70867+ vfree(tmp);
70868+ if (learn_buffer_user != NULL) {
70869+ vfree(learn_buffer_user);
70870+ learn_buffer_user = NULL;
70871+ }
70872+ learn_buffer_len = 0;
70873+ mutex_unlock(&gr_learn_user_mutex);
70874+
70875+ return;
70876+}
70877+
70878+void
70879+gr_add_learn_entry(const char *fmt, ...)
70880+{
70881+ va_list args;
70882+ unsigned int len;
70883+
70884+ if (!gr_learn_attached)
70885+ return;
70886+
70887+ spin_lock(&gr_learn_lock);
70888+
70889+ /* leave a gap at the end so we know when it's "full" but don't have to
70890+ compute the exact length of the string we're trying to append
70891+ */
70892+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
70893+ spin_unlock(&gr_learn_lock);
70894+ wake_up_interruptible(&learn_wait);
70895+ return;
70896+ }
70897+ if (learn_buffer == NULL) {
70898+ spin_unlock(&gr_learn_lock);
70899+ return;
70900+ }
70901+
70902+ va_start(args, fmt);
70903+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
70904+ va_end(args);
70905+
70906+ learn_buffer_len += len + 1;
70907+
70908+ spin_unlock(&gr_learn_lock);
70909+ wake_up_interruptible(&learn_wait);
70910+
70911+ return;
70912+}
70913+
70914+static int
70915+open_learn(struct inode *inode, struct file *file)
70916+{
70917+ if (file->f_mode & FMODE_READ && gr_learn_attached)
70918+ return -EBUSY;
70919+ if (file->f_mode & FMODE_READ) {
70920+ int retval = 0;
70921+ mutex_lock(&gr_learn_user_mutex);
70922+ if (learn_buffer == NULL)
70923+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
70924+ if (learn_buffer_user == NULL)
70925+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
70926+ if (learn_buffer == NULL) {
70927+ retval = -ENOMEM;
70928+ goto out_error;
70929+ }
70930+ if (learn_buffer_user == NULL) {
70931+ retval = -ENOMEM;
70932+ goto out_error;
70933+ }
70934+ learn_buffer_len = 0;
70935+ learn_buffer_user_len = 0;
70936+ gr_learn_attached = 1;
70937+out_error:
70938+ mutex_unlock(&gr_learn_user_mutex);
70939+ return retval;
70940+ }
70941+ return 0;
70942+}
70943+
70944+static int
70945+close_learn(struct inode *inode, struct file *file)
70946+{
70947+ if (file->f_mode & FMODE_READ) {
70948+ char *tmp = NULL;
70949+ mutex_lock(&gr_learn_user_mutex);
70950+ spin_lock(&gr_learn_lock);
70951+ tmp = learn_buffer;
70952+ learn_buffer = NULL;
70953+ spin_unlock(&gr_learn_lock);
70954+ if (tmp)
70955+ vfree(tmp);
70956+ if (learn_buffer_user != NULL) {
70957+ vfree(learn_buffer_user);
70958+ learn_buffer_user = NULL;
70959+ }
70960+ learn_buffer_len = 0;
70961+ learn_buffer_user_len = 0;
70962+ gr_learn_attached = 0;
70963+ mutex_unlock(&gr_learn_user_mutex);
70964+ }
70965+
70966+ return 0;
70967+}
70968+
70969+const struct file_operations grsec_fops = {
70970+ .read = read_learn,
70971+ .write = write_grsec_handler,
70972+ .open = open_learn,
70973+ .release = close_learn,
70974+ .poll = poll_learn,
70975+};
70976diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
70977new file mode 100644
70978index 0000000..361a099
70979--- /dev/null
70980+++ b/grsecurity/gracl_policy.c
70981@@ -0,0 +1,1782 @@
70982+#include <linux/kernel.h>
70983+#include <linux/module.h>
70984+#include <linux/sched.h>
70985+#include <linux/mm.h>
70986+#include <linux/file.h>
70987+#include <linux/fs.h>
70988+#include <linux/namei.h>
70989+#include <linux/mount.h>
70990+#include <linux/tty.h>
70991+#include <linux/proc_fs.h>
70992+#include <linux/lglock.h>
70993+#include <linux/slab.h>
70994+#include <linux/vmalloc.h>
70995+#include <linux/types.h>
70996+#include <linux/sysctl.h>
70997+#include <linux/netdevice.h>
70998+#include <linux/ptrace.h>
70999+#include <linux/gracl.h>
71000+#include <linux/gralloc.h>
71001+#include <linux/security.h>
71002+#include <linux/grinternal.h>
71003+#include <linux/pid_namespace.h>
71004+#include <linux/stop_machine.h>
71005+#include <linux/fdtable.h>
71006+#include <linux/percpu.h>
71007+#include <linux/lglock.h>
71008+#include <linux/hugetlb.h>
71009+#include <linux/posix-timers.h>
71010+#include "../fs/mount.h"
71011+
71012+#include <asm/uaccess.h>
71013+#include <asm/errno.h>
71014+#include <asm/mman.h>
71015+
71016+extern struct gr_policy_state *polstate;
71017+
71018+#define FOR_EACH_ROLE_START(role) \
71019+ role = polstate->role_list; \
71020+ while (role) {
71021+
71022+#define FOR_EACH_ROLE_END(role) \
71023+ role = role->prev; \
71024+ }
71025+
71026+struct path gr_real_root;
71027+
71028+extern struct gr_alloc_state *current_alloc_state;
71029+
71030+u16 acl_sp_role_value;
71031+
71032+static DEFINE_MUTEX(gr_dev_mutex);
71033+
71034+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71035+extern void gr_clear_learn_entries(void);
71036+
71037+static struct gr_arg gr_usermode;
71038+static unsigned char gr_system_salt[GR_SALT_LEN];
71039+static unsigned char gr_system_sum[GR_SHA_LEN];
71040+
71041+static unsigned int gr_auth_attempts = 0;
71042+static unsigned long gr_auth_expires = 0UL;
71043+
71044+struct acl_object_label *fakefs_obj_rw;
71045+struct acl_object_label *fakefs_obj_rwx;
71046+
71047+extern int gr_init_uidset(void);
71048+extern void gr_free_uidset(void);
71049+extern void gr_remove_uid(uid_t uid);
71050+extern int gr_find_uid(uid_t uid);
71051+
71052+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71053+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71054+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71055+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71056+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);
71057+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71058+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71059+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71060+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71061+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71062+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71063+extern void assign_special_role(const char *rolename);
71064+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71065+extern int gr_rbac_disable(void *unused);
71066+extern void gr_enable_rbac_system(void);
71067+
71068+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71069+{
71070+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71071+ return -EFAULT;
71072+
71073+ return 0;
71074+}
71075+
71076+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71077+{
71078+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71079+ return -EFAULT;
71080+
71081+ return 0;
71082+}
71083+
71084+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71085+{
71086+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71087+ return -EFAULT;
71088+
71089+ return 0;
71090+}
71091+
71092+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71093+{
71094+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71095+ return -EFAULT;
71096+
71097+ return 0;
71098+}
71099+
71100+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71101+{
71102+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71103+ return -EFAULT;
71104+
71105+ return 0;
71106+}
71107+
71108+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71109+{
71110+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71111+ return -EFAULT;
71112+
71113+ return 0;
71114+}
71115+
71116+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71117+{
71118+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71119+ return -EFAULT;
71120+
71121+ return 0;
71122+}
71123+
71124+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71125+{
71126+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71127+ return -EFAULT;
71128+
71129+ return 0;
71130+}
71131+
71132+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71133+{
71134+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71135+ return -EFAULT;
71136+
71137+ return 0;
71138+}
71139+
71140+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71141+{
71142+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71143+ return -EFAULT;
71144+
71145+ if (((uwrap->version != GRSECURITY_VERSION) &&
71146+ (uwrap->version != 0x2901)) ||
71147+ (uwrap->size != sizeof(struct gr_arg)))
71148+ return -EINVAL;
71149+
71150+ return 0;
71151+}
71152+
71153+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71154+{
71155+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71156+ return -EFAULT;
71157+
71158+ return 0;
71159+}
71160+
71161+static size_t get_gr_arg_wrapper_size_normal(void)
71162+{
71163+ return sizeof(struct gr_arg_wrapper);
71164+}
71165+
71166+#ifdef CONFIG_COMPAT
71167+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71168+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71169+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71170+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71171+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71172+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71173+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71174+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71175+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71176+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71177+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71178+extern size_t get_gr_arg_wrapper_size_compat(void);
71179+
71180+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71181+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71182+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71183+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71184+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71185+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71186+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71187+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71188+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71189+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71190+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71191+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71192+
71193+#else
71194+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71195+#define copy_gr_arg copy_gr_arg_normal
71196+#define copy_gr_hash_struct copy_gr_hash_struct_normal
71197+#define copy_acl_object_label copy_acl_object_label_normal
71198+#define copy_acl_subject_label copy_acl_subject_label_normal
71199+#define copy_acl_role_label copy_acl_role_label_normal
71200+#define copy_acl_ip_label copy_acl_ip_label_normal
71201+#define copy_pointer_from_array copy_pointer_from_array_normal
71202+#define copy_sprole_pw copy_sprole_pw_normal
71203+#define copy_role_transition copy_role_transition_normal
71204+#define copy_role_allowed_ip copy_role_allowed_ip_normal
71205+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71206+#endif
71207+
71208+static struct acl_subject_label *
71209+lookup_subject_map(const struct acl_subject_label *userp)
71210+{
71211+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71212+ struct subject_map *match;
71213+
71214+ match = polstate->subj_map_set.s_hash[index];
71215+
71216+ while (match && match->user != userp)
71217+ match = match->next;
71218+
71219+ if (match != NULL)
71220+ return match->kernel;
71221+ else
71222+ return NULL;
71223+}
71224+
71225+static void
71226+insert_subj_map_entry(struct subject_map *subjmap)
71227+{
71228+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71229+ struct subject_map **curr;
71230+
71231+ subjmap->prev = NULL;
71232+
71233+ curr = &polstate->subj_map_set.s_hash[index];
71234+ if (*curr != NULL)
71235+ (*curr)->prev = subjmap;
71236+
71237+ subjmap->next = *curr;
71238+ *curr = subjmap;
71239+
71240+ return;
71241+}
71242+
71243+static void
71244+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71245+{
71246+ unsigned int index =
71247+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71248+ struct acl_role_label **curr;
71249+ struct acl_role_label *tmp, *tmp2;
71250+
71251+ curr = &polstate->acl_role_set.r_hash[index];
71252+
71253+ /* simple case, slot is empty, just set it to our role */
71254+ if (*curr == NULL) {
71255+ *curr = role;
71256+ } else {
71257+ /* example:
71258+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
71259+ 2 -> 3
71260+ */
71261+ /* first check to see if we can already be reached via this slot */
71262+ tmp = *curr;
71263+ while (tmp && tmp != role)
71264+ tmp = tmp->next;
71265+ if (tmp == role) {
71266+ /* we don't need to add ourselves to this slot's chain */
71267+ return;
71268+ }
71269+ /* we need to add ourselves to this chain, two cases */
71270+ if (role->next == NULL) {
71271+ /* simple case, append the current chain to our role */
71272+ role->next = *curr;
71273+ *curr = role;
71274+ } else {
71275+ /* 1 -> 2 -> 3 -> 4
71276+ 2 -> 3 -> 4
71277+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71278+ */
71279+ /* trickier case: walk our role's chain until we find
71280+ the role for the start of the current slot's chain */
71281+ tmp = role;
71282+ tmp2 = *curr;
71283+ while (tmp->next && tmp->next != tmp2)
71284+ tmp = tmp->next;
71285+ if (tmp->next == tmp2) {
71286+ /* from example above, we found 3, so just
71287+ replace this slot's chain with ours */
71288+ *curr = role;
71289+ } else {
71290+ /* we didn't find a subset of our role's chain
71291+ in the current slot's chain, so append their
71292+ chain to ours, and set us as the first role in
71293+ the slot's chain
71294+
71295+ we could fold this case with the case above,
71296+ but making it explicit for clarity
71297+ */
71298+ tmp->next = tmp2;
71299+ *curr = role;
71300+ }
71301+ }
71302+ }
71303+
71304+ return;
71305+}
71306+
71307+static void
71308+insert_acl_role_label(struct acl_role_label *role)
71309+{
71310+ int i;
71311+
71312+ if (polstate->role_list == NULL) {
71313+ polstate->role_list = role;
71314+ role->prev = NULL;
71315+ } else {
71316+ role->prev = polstate->role_list;
71317+ polstate->role_list = role;
71318+ }
71319+
71320+ /* used for hash chains */
71321+ role->next = NULL;
71322+
71323+ if (role->roletype & GR_ROLE_DOMAIN) {
71324+ for (i = 0; i < role->domain_child_num; i++)
71325+ __insert_acl_role_label(role, role->domain_children[i]);
71326+ } else
71327+ __insert_acl_role_label(role, role->uidgid);
71328+}
71329+
71330+static int
71331+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71332+{
71333+ struct name_entry **curr, *nentry;
71334+ struct inodev_entry *ientry;
71335+ unsigned int len = strlen(name);
71336+ unsigned int key = full_name_hash(name, len);
71337+ unsigned int index = key % polstate->name_set.n_size;
71338+
71339+ curr = &polstate->name_set.n_hash[index];
71340+
71341+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71342+ curr = &((*curr)->next);
71343+
71344+ if (*curr != NULL)
71345+ return 1;
71346+
71347+ nentry = acl_alloc(sizeof (struct name_entry));
71348+ if (nentry == NULL)
71349+ return 0;
71350+ ientry = acl_alloc(sizeof (struct inodev_entry));
71351+ if (ientry == NULL)
71352+ return 0;
71353+ ientry->nentry = nentry;
71354+
71355+ nentry->key = key;
71356+ nentry->name = name;
71357+ nentry->inode = inode;
71358+ nentry->device = device;
71359+ nentry->len = len;
71360+ nentry->deleted = deleted;
71361+
71362+ nentry->prev = NULL;
71363+ curr = &polstate->name_set.n_hash[index];
71364+ if (*curr != NULL)
71365+ (*curr)->prev = nentry;
71366+ nentry->next = *curr;
71367+ *curr = nentry;
71368+
71369+ /* insert us into the table searchable by inode/dev */
71370+ __insert_inodev_entry(polstate, ientry);
71371+
71372+ return 1;
71373+}
71374+
71375+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71376+
71377+static void *
71378+create_table(__u32 * len, int elementsize)
71379+{
71380+ unsigned int table_sizes[] = {
71381+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71382+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71383+ 4194301, 8388593, 16777213, 33554393, 67108859
71384+ };
71385+ void *newtable = NULL;
71386+ unsigned int pwr = 0;
71387+
71388+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71389+ table_sizes[pwr] <= *len)
71390+ pwr++;
71391+
71392+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71393+ return newtable;
71394+
71395+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71396+ newtable =
71397+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71398+ else
71399+ newtable = vmalloc(table_sizes[pwr] * elementsize);
71400+
71401+ *len = table_sizes[pwr];
71402+
71403+ return newtable;
71404+}
71405+
71406+static int
71407+init_variables(const struct gr_arg *arg, bool reload)
71408+{
71409+ struct task_struct *reaper = init_pid_ns.child_reaper;
71410+ unsigned int stacksize;
71411+
71412+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71413+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71414+ polstate->name_set.n_size = arg->role_db.num_objects;
71415+ polstate->inodev_set.i_size = arg->role_db.num_objects;
71416+
71417+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71418+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71419+ return 1;
71420+
71421+ if (!reload) {
71422+ if (!gr_init_uidset())
71423+ return 1;
71424+ }
71425+
71426+ /* set up the stack that holds allocation info */
71427+
71428+ stacksize = arg->role_db.num_pointers + 5;
71429+
71430+ if (!acl_alloc_stack_init(stacksize))
71431+ return 1;
71432+
71433+ if (!reload) {
71434+ /* grab reference for the real root dentry and vfsmount */
71435+ get_fs_root(reaper->fs, &gr_real_root);
71436+
71437+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71438+ 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);
71439+#endif
71440+
71441+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71442+ if (fakefs_obj_rw == NULL)
71443+ return 1;
71444+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71445+
71446+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71447+ if (fakefs_obj_rwx == NULL)
71448+ return 1;
71449+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71450+ }
71451+
71452+ polstate->subj_map_set.s_hash =
71453+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71454+ polstate->acl_role_set.r_hash =
71455+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71456+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71457+ polstate->inodev_set.i_hash =
71458+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71459+
71460+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71461+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71462+ return 1;
71463+
71464+ memset(polstate->subj_map_set.s_hash, 0,
71465+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71466+ memset(polstate->acl_role_set.r_hash, 0,
71467+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71468+ memset(polstate->name_set.n_hash, 0,
71469+ sizeof (struct name_entry *) * polstate->name_set.n_size);
71470+ memset(polstate->inodev_set.i_hash, 0,
71471+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71472+
71473+ return 0;
71474+}
71475+
71476+/* free information not needed after startup
71477+ currently contains user->kernel pointer mappings for subjects
71478+*/
71479+
71480+static void
71481+free_init_variables(void)
71482+{
71483+ __u32 i;
71484+
71485+ if (polstate->subj_map_set.s_hash) {
71486+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71487+ if (polstate->subj_map_set.s_hash[i]) {
71488+ kfree(polstate->subj_map_set.s_hash[i]);
71489+ polstate->subj_map_set.s_hash[i] = NULL;
71490+ }
71491+ }
71492+
71493+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71494+ PAGE_SIZE)
71495+ kfree(polstate->subj_map_set.s_hash);
71496+ else
71497+ vfree(polstate->subj_map_set.s_hash);
71498+ }
71499+
71500+ return;
71501+}
71502+
71503+static void
71504+free_variables(bool reload)
71505+{
71506+ struct acl_subject_label *s;
71507+ struct acl_role_label *r;
71508+ struct task_struct *task, *task2;
71509+ unsigned int x;
71510+
71511+ if (!reload) {
71512+ gr_clear_learn_entries();
71513+
71514+ read_lock(&tasklist_lock);
71515+ do_each_thread(task2, task) {
71516+ task->acl_sp_role = 0;
71517+ task->acl_role_id = 0;
71518+ task->inherited = 0;
71519+ task->acl = NULL;
71520+ task->role = NULL;
71521+ } while_each_thread(task2, task);
71522+ read_unlock(&tasklist_lock);
71523+
71524+ kfree(fakefs_obj_rw);
71525+ fakefs_obj_rw = NULL;
71526+ kfree(fakefs_obj_rwx);
71527+ fakefs_obj_rwx = NULL;
71528+
71529+ /* release the reference to the real root dentry and vfsmount */
71530+ path_put(&gr_real_root);
71531+ memset(&gr_real_root, 0, sizeof(gr_real_root));
71532+ }
71533+
71534+ /* free all object hash tables */
71535+
71536+ FOR_EACH_ROLE_START(r)
71537+ if (r->subj_hash == NULL)
71538+ goto next_role;
71539+ FOR_EACH_SUBJECT_START(r, s, x)
71540+ if (s->obj_hash == NULL)
71541+ break;
71542+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71543+ kfree(s->obj_hash);
71544+ else
71545+ vfree(s->obj_hash);
71546+ FOR_EACH_SUBJECT_END(s, x)
71547+ FOR_EACH_NESTED_SUBJECT_START(r, s)
71548+ if (s->obj_hash == NULL)
71549+ break;
71550+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71551+ kfree(s->obj_hash);
71552+ else
71553+ vfree(s->obj_hash);
71554+ FOR_EACH_NESTED_SUBJECT_END(s)
71555+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71556+ kfree(r->subj_hash);
71557+ else
71558+ vfree(r->subj_hash);
71559+ r->subj_hash = NULL;
71560+next_role:
71561+ FOR_EACH_ROLE_END(r)
71562+
71563+ acl_free_all();
71564+
71565+ if (polstate->acl_role_set.r_hash) {
71566+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71567+ PAGE_SIZE)
71568+ kfree(polstate->acl_role_set.r_hash);
71569+ else
71570+ vfree(polstate->acl_role_set.r_hash);
71571+ }
71572+ if (polstate->name_set.n_hash) {
71573+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71574+ PAGE_SIZE)
71575+ kfree(polstate->name_set.n_hash);
71576+ else
71577+ vfree(polstate->name_set.n_hash);
71578+ }
71579+
71580+ if (polstate->inodev_set.i_hash) {
71581+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71582+ PAGE_SIZE)
71583+ kfree(polstate->inodev_set.i_hash);
71584+ else
71585+ vfree(polstate->inodev_set.i_hash);
71586+ }
71587+
71588+ if (!reload)
71589+ gr_free_uidset();
71590+
71591+ memset(&polstate->name_set, 0, sizeof (struct name_db));
71592+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71593+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71594+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71595+
71596+ polstate->default_role = NULL;
71597+ polstate->kernel_role = NULL;
71598+ polstate->role_list = NULL;
71599+
71600+ return;
71601+}
71602+
71603+static struct acl_subject_label *
71604+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71605+
71606+static int alloc_and_copy_string(char **name, unsigned int maxlen)
71607+{
71608+ unsigned int len = strnlen_user(*name, maxlen);
71609+ char *tmp;
71610+
71611+ if (!len || len >= maxlen)
71612+ return -EINVAL;
71613+
71614+ if ((tmp = (char *) acl_alloc(len)) == NULL)
71615+ return -ENOMEM;
71616+
71617+ if (copy_from_user(tmp, *name, len))
71618+ return -EFAULT;
71619+
71620+ tmp[len-1] = '\0';
71621+ *name = tmp;
71622+
71623+ return 0;
71624+}
71625+
71626+static int
71627+copy_user_glob(struct acl_object_label *obj)
71628+{
71629+ struct acl_object_label *g_tmp, **guser;
71630+ int error;
71631+
71632+ if (obj->globbed == NULL)
71633+ return 0;
71634+
71635+ guser = &obj->globbed;
71636+ while (*guser) {
71637+ g_tmp = (struct acl_object_label *)
71638+ acl_alloc(sizeof (struct acl_object_label));
71639+ if (g_tmp == NULL)
71640+ return -ENOMEM;
71641+
71642+ if (copy_acl_object_label(g_tmp, *guser))
71643+ return -EFAULT;
71644+
71645+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71646+ if (error)
71647+ return error;
71648+
71649+ *guser = g_tmp;
71650+ guser = &(g_tmp->next);
71651+ }
71652+
71653+ return 0;
71654+}
71655+
71656+static int
71657+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71658+ struct acl_role_label *role)
71659+{
71660+ struct acl_object_label *o_tmp;
71661+ int ret;
71662+
71663+ while (userp) {
71664+ if ((o_tmp = (struct acl_object_label *)
71665+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
71666+ return -ENOMEM;
71667+
71668+ if (copy_acl_object_label(o_tmp, userp))
71669+ return -EFAULT;
71670+
71671+ userp = o_tmp->prev;
71672+
71673+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71674+ if (ret)
71675+ return ret;
71676+
71677+ insert_acl_obj_label(o_tmp, subj);
71678+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71679+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71680+ return -ENOMEM;
71681+
71682+ ret = copy_user_glob(o_tmp);
71683+ if (ret)
71684+ return ret;
71685+
71686+ if (o_tmp->nested) {
71687+ int already_copied;
71688+
71689+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71690+ if (IS_ERR(o_tmp->nested))
71691+ return PTR_ERR(o_tmp->nested);
71692+
71693+ /* insert into nested subject list if we haven't copied this one yet
71694+ to prevent duplicate entries */
71695+ if (!already_copied) {
71696+ o_tmp->nested->next = role->hash->first;
71697+ role->hash->first = o_tmp->nested;
71698+ }
71699+ }
71700+ }
71701+
71702+ return 0;
71703+}
71704+
71705+static __u32
71706+count_user_subjs(struct acl_subject_label *userp)
71707+{
71708+ struct acl_subject_label s_tmp;
71709+ __u32 num = 0;
71710+
71711+ while (userp) {
71712+ if (copy_acl_subject_label(&s_tmp, userp))
71713+ break;
71714+
71715+ userp = s_tmp.prev;
71716+ }
71717+
71718+ return num;
71719+}
71720+
71721+static int
71722+copy_user_allowedips(struct acl_role_label *rolep)
71723+{
71724+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71725+
71726+ ruserip = rolep->allowed_ips;
71727+
71728+ while (ruserip) {
71729+ rlast = rtmp;
71730+
71731+ if ((rtmp = (struct role_allowed_ip *)
71732+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71733+ return -ENOMEM;
71734+
71735+ if (copy_role_allowed_ip(rtmp, ruserip))
71736+ return -EFAULT;
71737+
71738+ ruserip = rtmp->prev;
71739+
71740+ if (!rlast) {
71741+ rtmp->prev = NULL;
71742+ rolep->allowed_ips = rtmp;
71743+ } else {
71744+ rlast->next = rtmp;
71745+ rtmp->prev = rlast;
71746+ }
71747+
71748+ if (!ruserip)
71749+ rtmp->next = NULL;
71750+ }
71751+
71752+ return 0;
71753+}
71754+
71755+static int
71756+copy_user_transitions(struct acl_role_label *rolep)
71757+{
71758+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
71759+ int error;
71760+
71761+ rusertp = rolep->transitions;
71762+
71763+ while (rusertp) {
71764+ rlast = rtmp;
71765+
71766+ if ((rtmp = (struct role_transition *)
71767+ acl_alloc(sizeof (struct role_transition))) == NULL)
71768+ return -ENOMEM;
71769+
71770+ if (copy_role_transition(rtmp, rusertp))
71771+ return -EFAULT;
71772+
71773+ rusertp = rtmp->prev;
71774+
71775+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71776+ if (error)
71777+ return error;
71778+
71779+ if (!rlast) {
71780+ rtmp->prev = NULL;
71781+ rolep->transitions = rtmp;
71782+ } else {
71783+ rlast->next = rtmp;
71784+ rtmp->prev = rlast;
71785+ }
71786+
71787+ if (!rusertp)
71788+ rtmp->next = NULL;
71789+ }
71790+
71791+ return 0;
71792+}
71793+
71794+static __u32 count_user_objs(const struct acl_object_label __user *userp)
71795+{
71796+ struct acl_object_label o_tmp;
71797+ __u32 num = 0;
71798+
71799+ while (userp) {
71800+ if (copy_acl_object_label(&o_tmp, userp))
71801+ break;
71802+
71803+ userp = o_tmp.prev;
71804+ num++;
71805+ }
71806+
71807+ return num;
71808+}
71809+
71810+static struct acl_subject_label *
71811+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71812+{
71813+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71814+ __u32 num_objs;
71815+ struct acl_ip_label **i_tmp, *i_utmp2;
71816+ struct gr_hash_struct ghash;
71817+ struct subject_map *subjmap;
71818+ unsigned int i_num;
71819+ int err;
71820+
71821+ if (already_copied != NULL)
71822+ *already_copied = 0;
71823+
71824+ s_tmp = lookup_subject_map(userp);
71825+
71826+ /* we've already copied this subject into the kernel, just return
71827+ the reference to it, and don't copy it over again
71828+ */
71829+ if (s_tmp) {
71830+ if (already_copied != NULL)
71831+ *already_copied = 1;
71832+ return(s_tmp);
71833+ }
71834+
71835+ if ((s_tmp = (struct acl_subject_label *)
71836+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71837+ return ERR_PTR(-ENOMEM);
71838+
71839+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71840+ if (subjmap == NULL)
71841+ return ERR_PTR(-ENOMEM);
71842+
71843+ subjmap->user = userp;
71844+ subjmap->kernel = s_tmp;
71845+ insert_subj_map_entry(subjmap);
71846+
71847+ if (copy_acl_subject_label(s_tmp, userp))
71848+ return ERR_PTR(-EFAULT);
71849+
71850+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71851+ if (err)
71852+ return ERR_PTR(err);
71853+
71854+ if (!strcmp(s_tmp->filename, "/"))
71855+ role->root_label = s_tmp;
71856+
71857+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71858+ return ERR_PTR(-EFAULT);
71859+
71860+ /* copy user and group transition tables */
71861+
71862+ if (s_tmp->user_trans_num) {
71863+ uid_t *uidlist;
71864+
71865+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71866+ if (uidlist == NULL)
71867+ return ERR_PTR(-ENOMEM);
71868+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71869+ return ERR_PTR(-EFAULT);
71870+
71871+ s_tmp->user_transitions = uidlist;
71872+ }
71873+
71874+ if (s_tmp->group_trans_num) {
71875+ gid_t *gidlist;
71876+
71877+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71878+ if (gidlist == NULL)
71879+ return ERR_PTR(-ENOMEM);
71880+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71881+ return ERR_PTR(-EFAULT);
71882+
71883+ s_tmp->group_transitions = gidlist;
71884+ }
71885+
71886+ /* set up object hash table */
71887+ num_objs = count_user_objs(ghash.first);
71888+
71889+ s_tmp->obj_hash_size = num_objs;
71890+ s_tmp->obj_hash =
71891+ (struct acl_object_label **)
71892+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
71893+
71894+ if (!s_tmp->obj_hash)
71895+ return ERR_PTR(-ENOMEM);
71896+
71897+ memset(s_tmp->obj_hash, 0,
71898+ s_tmp->obj_hash_size *
71899+ sizeof (struct acl_object_label *));
71900+
71901+ /* add in objects */
71902+ err = copy_user_objs(ghash.first, s_tmp, role);
71903+
71904+ if (err)
71905+ return ERR_PTR(err);
71906+
71907+ /* set pointer for parent subject */
71908+ if (s_tmp->parent_subject) {
71909+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
71910+
71911+ if (IS_ERR(s_tmp2))
71912+ return s_tmp2;
71913+
71914+ s_tmp->parent_subject = s_tmp2;
71915+ }
71916+
71917+ /* add in ip acls */
71918+
71919+ if (!s_tmp->ip_num) {
71920+ s_tmp->ips = NULL;
71921+ goto insert;
71922+ }
71923+
71924+ i_tmp =
71925+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
71926+ sizeof (struct acl_ip_label *));
71927+
71928+ if (!i_tmp)
71929+ return ERR_PTR(-ENOMEM);
71930+
71931+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
71932+ *(i_tmp + i_num) =
71933+ (struct acl_ip_label *)
71934+ acl_alloc(sizeof (struct acl_ip_label));
71935+ if (!*(i_tmp + i_num))
71936+ return ERR_PTR(-ENOMEM);
71937+
71938+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
71939+ return ERR_PTR(-EFAULT);
71940+
71941+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
71942+ return ERR_PTR(-EFAULT);
71943+
71944+ if ((*(i_tmp + i_num))->iface == NULL)
71945+ continue;
71946+
71947+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
71948+ if (err)
71949+ return ERR_PTR(err);
71950+ }
71951+
71952+ s_tmp->ips = i_tmp;
71953+
71954+insert:
71955+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
71956+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
71957+ return ERR_PTR(-ENOMEM);
71958+
71959+ return s_tmp;
71960+}
71961+
71962+static int
71963+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
71964+{
71965+ struct acl_subject_label s_pre;
71966+ struct acl_subject_label * ret;
71967+ int err;
71968+
71969+ while (userp) {
71970+ if (copy_acl_subject_label(&s_pre, userp))
71971+ return -EFAULT;
71972+
71973+ ret = do_copy_user_subj(userp, role, NULL);
71974+
71975+ err = PTR_ERR(ret);
71976+ if (IS_ERR(ret))
71977+ return err;
71978+
71979+ insert_acl_subj_label(ret, role);
71980+
71981+ userp = s_pre.prev;
71982+ }
71983+
71984+ return 0;
71985+}
71986+
71987+static int
71988+copy_user_acl(struct gr_arg *arg)
71989+{
71990+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
71991+ struct acl_subject_label *subj_list;
71992+ struct sprole_pw *sptmp;
71993+ struct gr_hash_struct *ghash;
71994+ uid_t *domainlist;
71995+ unsigned int r_num;
71996+ int err = 0;
71997+ __u16 i;
71998+ __u32 num_subjs;
71999+
72000+ /* we need a default and kernel role */
72001+ if (arg->role_db.num_roles < 2)
72002+ return -EINVAL;
72003+
72004+ /* copy special role authentication info from userspace */
72005+
72006+ polstate->num_sprole_pws = arg->num_sprole_pws;
72007+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72008+
72009+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72010+ return -ENOMEM;
72011+
72012+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72013+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72014+ if (!sptmp)
72015+ return -ENOMEM;
72016+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72017+ return -EFAULT;
72018+
72019+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72020+ if (err)
72021+ return err;
72022+
72023+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72024+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72025+#endif
72026+
72027+ polstate->acl_special_roles[i] = sptmp;
72028+ }
72029+
72030+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72031+
72032+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72033+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
72034+
72035+ if (!r_tmp)
72036+ return -ENOMEM;
72037+
72038+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72039+ return -EFAULT;
72040+
72041+ if (copy_acl_role_label(r_tmp, r_utmp2))
72042+ return -EFAULT;
72043+
72044+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72045+ if (err)
72046+ return err;
72047+
72048+ if (!strcmp(r_tmp->rolename, "default")
72049+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72050+ polstate->default_role = r_tmp;
72051+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72052+ polstate->kernel_role = r_tmp;
72053+ }
72054+
72055+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72056+ return -ENOMEM;
72057+
72058+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
72059+ return -EFAULT;
72060+
72061+ r_tmp->hash = ghash;
72062+
72063+ num_subjs = count_user_subjs(r_tmp->hash->first);
72064+
72065+ r_tmp->subj_hash_size = num_subjs;
72066+ r_tmp->subj_hash =
72067+ (struct acl_subject_label **)
72068+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72069+
72070+ if (!r_tmp->subj_hash)
72071+ return -ENOMEM;
72072+
72073+ err = copy_user_allowedips(r_tmp);
72074+ if (err)
72075+ return err;
72076+
72077+ /* copy domain info */
72078+ if (r_tmp->domain_children != NULL) {
72079+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72080+ if (domainlist == NULL)
72081+ return -ENOMEM;
72082+
72083+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72084+ return -EFAULT;
72085+
72086+ r_tmp->domain_children = domainlist;
72087+ }
72088+
72089+ err = copy_user_transitions(r_tmp);
72090+ if (err)
72091+ return err;
72092+
72093+ memset(r_tmp->subj_hash, 0,
72094+ r_tmp->subj_hash_size *
72095+ sizeof (struct acl_subject_label *));
72096+
72097+ /* acquire the list of subjects, then NULL out
72098+ the list prior to parsing the subjects for this role,
72099+ as during this parsing the list is replaced with a list
72100+ of *nested* subjects for the role
72101+ */
72102+ subj_list = r_tmp->hash->first;
72103+
72104+ /* set nested subject list to null */
72105+ r_tmp->hash->first = NULL;
72106+
72107+ err = copy_user_subjs(subj_list, r_tmp);
72108+
72109+ if (err)
72110+ return err;
72111+
72112+ insert_acl_role_label(r_tmp);
72113+ }
72114+
72115+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72116+ return -EINVAL;
72117+
72118+ return err;
72119+}
72120+
72121+static int gracl_reload_apply_policies(void *reload)
72122+{
72123+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72124+ struct task_struct *task, *task2;
72125+ struct acl_role_label *role, *rtmp;
72126+ struct acl_subject_label *subj;
72127+ const struct cred *cred;
72128+ int role_applied;
72129+ int ret = 0;
72130+
72131+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72132+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72133+
72134+ /* first make sure we'll be able to apply the new policy cleanly */
72135+ do_each_thread(task2, task) {
72136+ if (task->exec_file == NULL)
72137+ continue;
72138+ role_applied = 0;
72139+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72140+ /* preserve special roles */
72141+ FOR_EACH_ROLE_START(role)
72142+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72143+ rtmp = task->role;
72144+ task->role = role;
72145+ role_applied = 1;
72146+ break;
72147+ }
72148+ FOR_EACH_ROLE_END(role)
72149+ }
72150+ if (!role_applied) {
72151+ cred = __task_cred(task);
72152+ rtmp = task->role;
72153+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72154+ }
72155+ /* this handles non-nested inherited subjects, nested subjects will still
72156+ be dropped currently */
72157+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72158+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72159+ /* change the role back so that we've made no modifications to the policy */
72160+ task->role = rtmp;
72161+
72162+ if (subj == NULL || task->tmpacl == NULL) {
72163+ ret = -EINVAL;
72164+ goto out;
72165+ }
72166+ } while_each_thread(task2, task);
72167+
72168+ /* now actually apply the policy */
72169+
72170+ do_each_thread(task2, task) {
72171+ if (task->exec_file) {
72172+ role_applied = 0;
72173+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72174+ /* preserve special roles */
72175+ FOR_EACH_ROLE_START(role)
72176+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72177+ task->role = role;
72178+ role_applied = 1;
72179+ break;
72180+ }
72181+ FOR_EACH_ROLE_END(role)
72182+ }
72183+ if (!role_applied) {
72184+ cred = __task_cred(task);
72185+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72186+ }
72187+ /* this handles non-nested inherited subjects, nested subjects will still
72188+ be dropped currently */
72189+ if (!reload_state->oldmode && task->inherited)
72190+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72191+ else {
72192+ /* looked up and tagged to the task previously */
72193+ subj = task->tmpacl;
72194+ }
72195+ /* subj will be non-null */
72196+ __gr_apply_subject_to_task(polstate, task, subj);
72197+ if (reload_state->oldmode) {
72198+ task->acl_role_id = 0;
72199+ task->acl_sp_role = 0;
72200+ task->inherited = 0;
72201+ }
72202+ } else {
72203+ // it's a kernel process
72204+ task->role = polstate->kernel_role;
72205+ task->acl = polstate->kernel_role->root_label;
72206+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72207+ task->acl->mode &= ~GR_PROCFIND;
72208+#endif
72209+ }
72210+ } while_each_thread(task2, task);
72211+
72212+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72213+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72214+
72215+out:
72216+
72217+ return ret;
72218+}
72219+
72220+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72221+{
72222+ struct gr_reload_state new_reload_state = { };
72223+ int err;
72224+
72225+ new_reload_state.oldpolicy_ptr = polstate;
72226+ new_reload_state.oldalloc_ptr = current_alloc_state;
72227+ new_reload_state.oldmode = oldmode;
72228+
72229+ current_alloc_state = &new_reload_state.newalloc;
72230+ polstate = &new_reload_state.newpolicy;
72231+
72232+ /* everything relevant is now saved off, copy in the new policy */
72233+ if (init_variables(args, true)) {
72234+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72235+ err = -ENOMEM;
72236+ goto error;
72237+ }
72238+
72239+ err = copy_user_acl(args);
72240+ free_init_variables();
72241+ if (err)
72242+ goto error;
72243+ /* the new policy is copied in, with the old policy available via saved_state
72244+ first go through applying roles, making sure to preserve special roles
72245+ then apply new subjects, making sure to preserve inherited and nested subjects,
72246+ though currently only inherited subjects will be preserved
72247+ */
72248+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72249+ if (err)
72250+ goto error;
72251+
72252+ /* we've now applied the new policy, so restore the old policy state to free it */
72253+ polstate = &new_reload_state.oldpolicy;
72254+ current_alloc_state = &new_reload_state.oldalloc;
72255+ free_variables(true);
72256+
72257+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72258+ to running_polstate/current_alloc_state inside stop_machine
72259+ */
72260+ err = 0;
72261+ goto out;
72262+error:
72263+ /* on error of loading the new policy, we'll just keep the previous
72264+ policy set around
72265+ */
72266+ free_variables(true);
72267+
72268+ /* doesn't affect runtime, but maintains consistent state */
72269+out:
72270+ polstate = new_reload_state.oldpolicy_ptr;
72271+ current_alloc_state = new_reload_state.oldalloc_ptr;
72272+
72273+ return err;
72274+}
72275+
72276+static int
72277+gracl_init(struct gr_arg *args)
72278+{
72279+ int error = 0;
72280+
72281+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72282+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72283+
72284+ if (init_variables(args, false)) {
72285+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72286+ error = -ENOMEM;
72287+ goto out;
72288+ }
72289+
72290+ error = copy_user_acl(args);
72291+ free_init_variables();
72292+ if (error)
72293+ goto out;
72294+
72295+ error = gr_set_acls(0);
72296+ if (error)
72297+ goto out;
72298+
72299+ gr_enable_rbac_system();
72300+
72301+ return 0;
72302+
72303+out:
72304+ free_variables(false);
72305+ return error;
72306+}
72307+
72308+static int
72309+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72310+ unsigned char **sum)
72311+{
72312+ struct acl_role_label *r;
72313+ struct role_allowed_ip *ipp;
72314+ struct role_transition *trans;
72315+ unsigned int i;
72316+ int found = 0;
72317+ u32 curr_ip = current->signal->curr_ip;
72318+
72319+ current->signal->saved_ip = curr_ip;
72320+
72321+ /* check transition table */
72322+
72323+ for (trans = current->role->transitions; trans; trans = trans->next) {
72324+ if (!strcmp(rolename, trans->rolename)) {
72325+ found = 1;
72326+ break;
72327+ }
72328+ }
72329+
72330+ if (!found)
72331+ return 0;
72332+
72333+ /* handle special roles that do not require authentication
72334+ and check ip */
72335+
72336+ FOR_EACH_ROLE_START(r)
72337+ if (!strcmp(rolename, r->rolename) &&
72338+ (r->roletype & GR_ROLE_SPECIAL)) {
72339+ found = 0;
72340+ if (r->allowed_ips != NULL) {
72341+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72342+ if ((ntohl(curr_ip) & ipp->netmask) ==
72343+ (ntohl(ipp->addr) & ipp->netmask))
72344+ found = 1;
72345+ }
72346+ } else
72347+ found = 2;
72348+ if (!found)
72349+ return 0;
72350+
72351+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72352+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72353+ *salt = NULL;
72354+ *sum = NULL;
72355+ return 1;
72356+ }
72357+ }
72358+ FOR_EACH_ROLE_END(r)
72359+
72360+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72361+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72362+ *salt = polstate->acl_special_roles[i]->salt;
72363+ *sum = polstate->acl_special_roles[i]->sum;
72364+ return 1;
72365+ }
72366+ }
72367+
72368+ return 0;
72369+}
72370+
72371+int gr_check_secure_terminal(struct task_struct *task)
72372+{
72373+ struct task_struct *p, *p2, *p3;
72374+ struct files_struct *files;
72375+ struct fdtable *fdt;
72376+ struct file *our_file = NULL, *file;
72377+ int i;
72378+
72379+ if (task->signal->tty == NULL)
72380+ return 1;
72381+
72382+ files = get_files_struct(task);
72383+ if (files != NULL) {
72384+ rcu_read_lock();
72385+ fdt = files_fdtable(files);
72386+ for (i=0; i < fdt->max_fds; i++) {
72387+ file = fcheck_files(files, i);
72388+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72389+ get_file(file);
72390+ our_file = file;
72391+ }
72392+ }
72393+ rcu_read_unlock();
72394+ put_files_struct(files);
72395+ }
72396+
72397+ if (our_file == NULL)
72398+ return 1;
72399+
72400+ read_lock(&tasklist_lock);
72401+ do_each_thread(p2, p) {
72402+ files = get_files_struct(p);
72403+ if (files == NULL ||
72404+ (p->signal && p->signal->tty == task->signal->tty)) {
72405+ if (files != NULL)
72406+ put_files_struct(files);
72407+ continue;
72408+ }
72409+ rcu_read_lock();
72410+ fdt = files_fdtable(files);
72411+ for (i=0; i < fdt->max_fds; i++) {
72412+ file = fcheck_files(files, i);
72413+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72414+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72415+ p3 = task;
72416+ while (task_pid_nr(p3) > 0) {
72417+ if (p3 == p)
72418+ break;
72419+ p3 = p3->real_parent;
72420+ }
72421+ if (p3 == p)
72422+ break;
72423+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72424+ gr_handle_alertkill(p);
72425+ rcu_read_unlock();
72426+ put_files_struct(files);
72427+ read_unlock(&tasklist_lock);
72428+ fput(our_file);
72429+ return 0;
72430+ }
72431+ }
72432+ rcu_read_unlock();
72433+ put_files_struct(files);
72434+ } while_each_thread(p2, p);
72435+ read_unlock(&tasklist_lock);
72436+
72437+ fput(our_file);
72438+ return 1;
72439+}
72440+
72441+ssize_t
72442+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72443+{
72444+ struct gr_arg_wrapper uwrap;
72445+ unsigned char *sprole_salt = NULL;
72446+ unsigned char *sprole_sum = NULL;
72447+ int error = 0;
72448+ int error2 = 0;
72449+ size_t req_count = 0;
72450+ unsigned char oldmode = 0;
72451+
72452+ mutex_lock(&gr_dev_mutex);
72453+
72454+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72455+ error = -EPERM;
72456+ goto out;
72457+ }
72458+
72459+#ifdef CONFIG_COMPAT
72460+ pax_open_kernel();
72461+ if (is_compat_task()) {
72462+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72463+ copy_gr_arg = &copy_gr_arg_compat;
72464+ copy_acl_object_label = &copy_acl_object_label_compat;
72465+ copy_acl_subject_label = &copy_acl_subject_label_compat;
72466+ copy_acl_role_label = &copy_acl_role_label_compat;
72467+ copy_acl_ip_label = &copy_acl_ip_label_compat;
72468+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72469+ copy_role_transition = &copy_role_transition_compat;
72470+ copy_sprole_pw = &copy_sprole_pw_compat;
72471+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72472+ copy_pointer_from_array = &copy_pointer_from_array_compat;
72473+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72474+ } else {
72475+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72476+ copy_gr_arg = &copy_gr_arg_normal;
72477+ copy_acl_object_label = &copy_acl_object_label_normal;
72478+ copy_acl_subject_label = &copy_acl_subject_label_normal;
72479+ copy_acl_role_label = &copy_acl_role_label_normal;
72480+ copy_acl_ip_label = &copy_acl_ip_label_normal;
72481+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72482+ copy_role_transition = &copy_role_transition_normal;
72483+ copy_sprole_pw = &copy_sprole_pw_normal;
72484+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72485+ copy_pointer_from_array = &copy_pointer_from_array_normal;
72486+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72487+ }
72488+ pax_close_kernel();
72489+#endif
72490+
72491+ req_count = get_gr_arg_wrapper_size();
72492+
72493+ if (count != req_count) {
72494+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72495+ error = -EINVAL;
72496+ goto out;
72497+ }
72498+
72499+
72500+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72501+ gr_auth_expires = 0;
72502+ gr_auth_attempts = 0;
72503+ }
72504+
72505+ error = copy_gr_arg_wrapper(buf, &uwrap);
72506+ if (error)
72507+ goto out;
72508+
72509+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
72510+ if (error)
72511+ goto out;
72512+
72513+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72514+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72515+ time_after(gr_auth_expires, get_seconds())) {
72516+ error = -EBUSY;
72517+ goto out;
72518+ }
72519+
72520+ /* if non-root trying to do anything other than use a special role,
72521+ do not attempt authentication, do not count towards authentication
72522+ locking
72523+ */
72524+
72525+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72526+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72527+ gr_is_global_nonroot(current_uid())) {
72528+ error = -EPERM;
72529+ goto out;
72530+ }
72531+
72532+ /* ensure pw and special role name are null terminated */
72533+
72534+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72535+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72536+
72537+ /* Okay.
72538+ * We have our enough of the argument structure..(we have yet
72539+ * to copy_from_user the tables themselves) . Copy the tables
72540+ * only if we need them, i.e. for loading operations. */
72541+
72542+ switch (gr_usermode.mode) {
72543+ case GR_STATUS:
72544+ if (gr_acl_is_enabled()) {
72545+ error = 1;
72546+ if (!gr_check_secure_terminal(current))
72547+ error = 3;
72548+ } else
72549+ error = 2;
72550+ goto out;
72551+ case GR_SHUTDOWN:
72552+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72553+ stop_machine(gr_rbac_disable, NULL, NULL);
72554+ free_variables(false);
72555+ memset(&gr_usermode, 0, sizeof(gr_usermode));
72556+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72557+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72558+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72559+ } else if (gr_acl_is_enabled()) {
72560+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72561+ error = -EPERM;
72562+ } else {
72563+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72564+ error = -EAGAIN;
72565+ }
72566+ break;
72567+ case GR_ENABLE:
72568+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72569+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72570+ else {
72571+ if (gr_acl_is_enabled())
72572+ error = -EAGAIN;
72573+ else
72574+ error = error2;
72575+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72576+ }
72577+ break;
72578+ case GR_OLDRELOAD:
72579+ oldmode = 1;
72580+ case GR_RELOAD:
72581+ if (!gr_acl_is_enabled()) {
72582+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72583+ error = -EAGAIN;
72584+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72585+ error2 = gracl_reload(&gr_usermode, oldmode);
72586+ if (!error2)
72587+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72588+ else {
72589+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72590+ error = error2;
72591+ }
72592+ } else {
72593+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72594+ error = -EPERM;
72595+ }
72596+ break;
72597+ case GR_SEGVMOD:
72598+ if (unlikely(!gr_acl_is_enabled())) {
72599+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72600+ error = -EAGAIN;
72601+ break;
72602+ }
72603+
72604+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72605+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72606+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72607+ struct acl_subject_label *segvacl;
72608+ segvacl =
72609+ lookup_acl_subj_label(gr_usermode.segv_inode,
72610+ gr_usermode.segv_device,
72611+ current->role);
72612+ if (segvacl) {
72613+ segvacl->crashes = 0;
72614+ segvacl->expires = 0;
72615+ }
72616+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72617+ gr_remove_uid(gr_usermode.segv_uid);
72618+ }
72619+ } else {
72620+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72621+ error = -EPERM;
72622+ }
72623+ break;
72624+ case GR_SPROLE:
72625+ case GR_SPROLEPAM:
72626+ if (unlikely(!gr_acl_is_enabled())) {
72627+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72628+ error = -EAGAIN;
72629+ break;
72630+ }
72631+
72632+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72633+ current->role->expires = 0;
72634+ current->role->auth_attempts = 0;
72635+ }
72636+
72637+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72638+ time_after(current->role->expires, get_seconds())) {
72639+ error = -EBUSY;
72640+ goto out;
72641+ }
72642+
72643+ if (lookup_special_role_auth
72644+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72645+ && ((!sprole_salt && !sprole_sum)
72646+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72647+ char *p = "";
72648+ assign_special_role(gr_usermode.sp_role);
72649+ read_lock(&tasklist_lock);
72650+ if (current->real_parent)
72651+ p = current->real_parent->role->rolename;
72652+ read_unlock(&tasklist_lock);
72653+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72654+ p, acl_sp_role_value);
72655+ } else {
72656+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72657+ error = -EPERM;
72658+ if(!(current->role->auth_attempts++))
72659+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72660+
72661+ goto out;
72662+ }
72663+ break;
72664+ case GR_UNSPROLE:
72665+ if (unlikely(!gr_acl_is_enabled())) {
72666+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72667+ error = -EAGAIN;
72668+ break;
72669+ }
72670+
72671+ if (current->role->roletype & GR_ROLE_SPECIAL) {
72672+ char *p = "";
72673+ int i = 0;
72674+
72675+ read_lock(&tasklist_lock);
72676+ if (current->real_parent) {
72677+ p = current->real_parent->role->rolename;
72678+ i = current->real_parent->acl_role_id;
72679+ }
72680+ read_unlock(&tasklist_lock);
72681+
72682+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72683+ gr_set_acls(1);
72684+ } else {
72685+ error = -EPERM;
72686+ goto out;
72687+ }
72688+ break;
72689+ default:
72690+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72691+ error = -EINVAL;
72692+ break;
72693+ }
72694+
72695+ if (error != -EPERM)
72696+ goto out;
72697+
72698+ if(!(gr_auth_attempts++))
72699+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72700+
72701+ out:
72702+ mutex_unlock(&gr_dev_mutex);
72703+
72704+ if (!error)
72705+ error = req_count;
72706+
72707+ return error;
72708+}
72709+
72710+int
72711+gr_set_acls(const int type)
72712+{
72713+ struct task_struct *task, *task2;
72714+ struct acl_role_label *role = current->role;
72715+ struct acl_subject_label *subj;
72716+ __u16 acl_role_id = current->acl_role_id;
72717+ const struct cred *cred;
72718+ int ret;
72719+
72720+ rcu_read_lock();
72721+ read_lock(&tasklist_lock);
72722+ read_lock(&grsec_exec_file_lock);
72723+ do_each_thread(task2, task) {
72724+ /* check to see if we're called from the exit handler,
72725+ if so, only replace ACLs that have inherited the admin
72726+ ACL */
72727+
72728+ if (type && (task->role != role ||
72729+ task->acl_role_id != acl_role_id))
72730+ continue;
72731+
72732+ task->acl_role_id = 0;
72733+ task->acl_sp_role = 0;
72734+ task->inherited = 0;
72735+
72736+ if (task->exec_file) {
72737+ cred = __task_cred(task);
72738+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72739+ subj = __gr_get_subject_for_task(polstate, task, NULL);
72740+ if (subj == NULL) {
72741+ ret = -EINVAL;
72742+ read_unlock(&grsec_exec_file_lock);
72743+ read_unlock(&tasklist_lock);
72744+ rcu_read_unlock();
72745+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72746+ return ret;
72747+ }
72748+ __gr_apply_subject_to_task(polstate, task, subj);
72749+ } else {
72750+ // it's a kernel process
72751+ task->role = polstate->kernel_role;
72752+ task->acl = polstate->kernel_role->root_label;
72753+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72754+ task->acl->mode &= ~GR_PROCFIND;
72755+#endif
72756+ }
72757+ } while_each_thread(task2, task);
72758+ read_unlock(&grsec_exec_file_lock);
72759+ read_unlock(&tasklist_lock);
72760+ rcu_read_unlock();
72761+
72762+ return 0;
72763+}
72764diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72765new file mode 100644
72766index 0000000..39645c9
72767--- /dev/null
72768+++ b/grsecurity/gracl_res.c
72769@@ -0,0 +1,68 @@
72770+#include <linux/kernel.h>
72771+#include <linux/sched.h>
72772+#include <linux/gracl.h>
72773+#include <linux/grinternal.h>
72774+
72775+static const char *restab_log[] = {
72776+ [RLIMIT_CPU] = "RLIMIT_CPU",
72777+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72778+ [RLIMIT_DATA] = "RLIMIT_DATA",
72779+ [RLIMIT_STACK] = "RLIMIT_STACK",
72780+ [RLIMIT_CORE] = "RLIMIT_CORE",
72781+ [RLIMIT_RSS] = "RLIMIT_RSS",
72782+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
72783+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72784+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72785+ [RLIMIT_AS] = "RLIMIT_AS",
72786+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72787+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72788+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72789+ [RLIMIT_NICE] = "RLIMIT_NICE",
72790+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72791+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72792+ [GR_CRASH_RES] = "RLIMIT_CRASH"
72793+};
72794+
72795+void
72796+gr_log_resource(const struct task_struct *task,
72797+ const int res, const unsigned long wanted, const int gt)
72798+{
72799+ const struct cred *cred;
72800+ unsigned long rlim;
72801+
72802+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
72803+ return;
72804+
72805+ // not yet supported resource
72806+ if (unlikely(!restab_log[res]))
72807+ return;
72808+
72809+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72810+ rlim = task_rlimit_max(task, res);
72811+ else
72812+ rlim = task_rlimit(task, res);
72813+
72814+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72815+ return;
72816+
72817+ rcu_read_lock();
72818+ cred = __task_cred(task);
72819+
72820+ if (res == RLIMIT_NPROC &&
72821+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72822+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72823+ goto out_rcu_unlock;
72824+ else if (res == RLIMIT_MEMLOCK &&
72825+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72826+ goto out_rcu_unlock;
72827+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72828+ goto out_rcu_unlock;
72829+ rcu_read_unlock();
72830+
72831+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72832+
72833+ return;
72834+out_rcu_unlock:
72835+ rcu_read_unlock();
72836+ return;
72837+}
72838diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72839new file mode 100644
72840index 0000000..2040e61
72841--- /dev/null
72842+++ b/grsecurity/gracl_segv.c
72843@@ -0,0 +1,313 @@
72844+#include <linux/kernel.h>
72845+#include <linux/mm.h>
72846+#include <asm/uaccess.h>
72847+#include <asm/errno.h>
72848+#include <asm/mman.h>
72849+#include <net/sock.h>
72850+#include <linux/file.h>
72851+#include <linux/fs.h>
72852+#include <linux/net.h>
72853+#include <linux/in.h>
72854+#include <linux/slab.h>
72855+#include <linux/types.h>
72856+#include <linux/sched.h>
72857+#include <linux/timer.h>
72858+#include <linux/gracl.h>
72859+#include <linux/grsecurity.h>
72860+#include <linux/grinternal.h>
72861+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72862+#include <linux/magic.h>
72863+#include <linux/pagemap.h>
72864+#include "../fs/btrfs/async-thread.h"
72865+#include "../fs/btrfs/ctree.h"
72866+#include "../fs/btrfs/btrfs_inode.h"
72867+#endif
72868+
72869+static struct crash_uid *uid_set;
72870+static unsigned short uid_used;
72871+static DEFINE_SPINLOCK(gr_uid_lock);
72872+extern rwlock_t gr_inode_lock;
72873+extern struct acl_subject_label *
72874+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72875+ struct acl_role_label *role);
72876+
72877+static inline dev_t __get_dev(const struct dentry *dentry)
72878+{
72879+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72880+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72881+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
72882+ else
72883+#endif
72884+ return dentry->d_sb->s_dev;
72885+}
72886+
72887+int
72888+gr_init_uidset(void)
72889+{
72890+ uid_set =
72891+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
72892+ uid_used = 0;
72893+
72894+ return uid_set ? 1 : 0;
72895+}
72896+
72897+void
72898+gr_free_uidset(void)
72899+{
72900+ if (uid_set) {
72901+ struct crash_uid *tmpset;
72902+ spin_lock(&gr_uid_lock);
72903+ tmpset = uid_set;
72904+ uid_set = NULL;
72905+ uid_used = 0;
72906+ spin_unlock(&gr_uid_lock);
72907+ if (tmpset)
72908+ kfree(tmpset);
72909+ }
72910+
72911+ return;
72912+}
72913+
72914+int
72915+gr_find_uid(const uid_t uid)
72916+{
72917+ struct crash_uid *tmp = uid_set;
72918+ uid_t buid;
72919+ int low = 0, high = uid_used - 1, mid;
72920+
72921+ while (high >= low) {
72922+ mid = (low + high) >> 1;
72923+ buid = tmp[mid].uid;
72924+ if (buid == uid)
72925+ return mid;
72926+ if (buid > uid)
72927+ high = mid - 1;
72928+ if (buid < uid)
72929+ low = mid + 1;
72930+ }
72931+
72932+ return -1;
72933+}
72934+
72935+static __inline__ void
72936+gr_insertsort(void)
72937+{
72938+ unsigned short i, j;
72939+ struct crash_uid index;
72940+
72941+ for (i = 1; i < uid_used; i++) {
72942+ index = uid_set[i];
72943+ j = i;
72944+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
72945+ uid_set[j] = uid_set[j - 1];
72946+ j--;
72947+ }
72948+ uid_set[j] = index;
72949+ }
72950+
72951+ return;
72952+}
72953+
72954+static __inline__ void
72955+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
72956+{
72957+ int loc;
72958+ uid_t uid = GR_GLOBAL_UID(kuid);
72959+
72960+ if (uid_used == GR_UIDTABLE_MAX)
72961+ return;
72962+
72963+ loc = gr_find_uid(uid);
72964+
72965+ if (loc >= 0) {
72966+ uid_set[loc].expires = expires;
72967+ return;
72968+ }
72969+
72970+ uid_set[uid_used].uid = uid;
72971+ uid_set[uid_used].expires = expires;
72972+ uid_used++;
72973+
72974+ gr_insertsort();
72975+
72976+ return;
72977+}
72978+
72979+void
72980+gr_remove_uid(const unsigned short loc)
72981+{
72982+ unsigned short i;
72983+
72984+ for (i = loc + 1; i < uid_used; i++)
72985+ uid_set[i - 1] = uid_set[i];
72986+
72987+ uid_used--;
72988+
72989+ return;
72990+}
72991+
72992+int
72993+gr_check_crash_uid(const kuid_t kuid)
72994+{
72995+ int loc;
72996+ int ret = 0;
72997+ uid_t uid;
72998+
72999+ if (unlikely(!gr_acl_is_enabled()))
73000+ return 0;
73001+
73002+ uid = GR_GLOBAL_UID(kuid);
73003+
73004+ spin_lock(&gr_uid_lock);
73005+ loc = gr_find_uid(uid);
73006+
73007+ if (loc < 0)
73008+ goto out_unlock;
73009+
73010+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
73011+ gr_remove_uid(loc);
73012+ else
73013+ ret = 1;
73014+
73015+out_unlock:
73016+ spin_unlock(&gr_uid_lock);
73017+ return ret;
73018+}
73019+
73020+static __inline__ int
73021+proc_is_setxid(const struct cred *cred)
73022+{
73023+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73024+ !uid_eq(cred->uid, cred->fsuid))
73025+ return 1;
73026+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73027+ !gid_eq(cred->gid, cred->fsgid))
73028+ return 1;
73029+
73030+ return 0;
73031+}
73032+
73033+extern int gr_fake_force_sig(int sig, struct task_struct *t);
73034+
73035+void
73036+gr_handle_crash(struct task_struct *task, const int sig)
73037+{
73038+ struct acl_subject_label *curr;
73039+ struct task_struct *tsk, *tsk2;
73040+ const struct cred *cred;
73041+ const struct cred *cred2;
73042+
73043+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73044+ return;
73045+
73046+ if (unlikely(!gr_acl_is_enabled()))
73047+ return;
73048+
73049+ curr = task->acl;
73050+
73051+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
73052+ return;
73053+
73054+ if (time_before_eq(curr->expires, get_seconds())) {
73055+ curr->expires = 0;
73056+ curr->crashes = 0;
73057+ }
73058+
73059+ curr->crashes++;
73060+
73061+ if (!curr->expires)
73062+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73063+
73064+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73065+ time_after(curr->expires, get_seconds())) {
73066+ rcu_read_lock();
73067+ cred = __task_cred(task);
73068+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73069+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73070+ spin_lock(&gr_uid_lock);
73071+ gr_insert_uid(cred->uid, curr->expires);
73072+ spin_unlock(&gr_uid_lock);
73073+ curr->expires = 0;
73074+ curr->crashes = 0;
73075+ read_lock(&tasklist_lock);
73076+ do_each_thread(tsk2, tsk) {
73077+ cred2 = __task_cred(tsk);
73078+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
73079+ gr_fake_force_sig(SIGKILL, tsk);
73080+ } while_each_thread(tsk2, tsk);
73081+ read_unlock(&tasklist_lock);
73082+ } else {
73083+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73084+ read_lock(&tasklist_lock);
73085+ read_lock(&grsec_exec_file_lock);
73086+ do_each_thread(tsk2, tsk) {
73087+ if (likely(tsk != task)) {
73088+ // if this thread has the same subject as the one that triggered
73089+ // RES_CRASH and it's the same binary, kill it
73090+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73091+ gr_fake_force_sig(SIGKILL, tsk);
73092+ }
73093+ } while_each_thread(tsk2, tsk);
73094+ read_unlock(&grsec_exec_file_lock);
73095+ read_unlock(&tasklist_lock);
73096+ }
73097+ rcu_read_unlock();
73098+ }
73099+
73100+ return;
73101+}
73102+
73103+int
73104+gr_check_crash_exec(const struct file *filp)
73105+{
73106+ struct acl_subject_label *curr;
73107+
73108+ if (unlikely(!gr_acl_is_enabled()))
73109+ return 0;
73110+
73111+ read_lock(&gr_inode_lock);
73112+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73113+ __get_dev(filp->f_path.dentry),
73114+ current->role);
73115+ read_unlock(&gr_inode_lock);
73116+
73117+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73118+ (!curr->crashes && !curr->expires))
73119+ return 0;
73120+
73121+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73122+ time_after(curr->expires, get_seconds()))
73123+ return 1;
73124+ else if (time_before_eq(curr->expires, get_seconds())) {
73125+ curr->crashes = 0;
73126+ curr->expires = 0;
73127+ }
73128+
73129+ return 0;
73130+}
73131+
73132+void
73133+gr_handle_alertkill(struct task_struct *task)
73134+{
73135+ struct acl_subject_label *curracl;
73136+ __u32 curr_ip;
73137+ struct task_struct *p, *p2;
73138+
73139+ if (unlikely(!gr_acl_is_enabled()))
73140+ return;
73141+
73142+ curracl = task->acl;
73143+ curr_ip = task->signal->curr_ip;
73144+
73145+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73146+ read_lock(&tasklist_lock);
73147+ do_each_thread(p2, p) {
73148+ if (p->signal->curr_ip == curr_ip)
73149+ gr_fake_force_sig(SIGKILL, p);
73150+ } while_each_thread(p2, p);
73151+ read_unlock(&tasklist_lock);
73152+ } else if (curracl->mode & GR_KILLPROC)
73153+ gr_fake_force_sig(SIGKILL, task);
73154+
73155+ return;
73156+}
73157diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73158new file mode 100644
73159index 0000000..98011b0
73160--- /dev/null
73161+++ b/grsecurity/gracl_shm.c
73162@@ -0,0 +1,40 @@
73163+#include <linux/kernel.h>
73164+#include <linux/mm.h>
73165+#include <linux/sched.h>
73166+#include <linux/file.h>
73167+#include <linux/ipc.h>
73168+#include <linux/gracl.h>
73169+#include <linux/grsecurity.h>
73170+#include <linux/grinternal.h>
73171+
73172+int
73173+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73174+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73175+{
73176+ struct task_struct *task;
73177+
73178+ if (!gr_acl_is_enabled())
73179+ return 1;
73180+
73181+ rcu_read_lock();
73182+ read_lock(&tasklist_lock);
73183+
73184+ task = find_task_by_vpid(shm_cprid);
73185+
73186+ if (unlikely(!task))
73187+ task = find_task_by_vpid(shm_lapid);
73188+
73189+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73190+ (task_pid_nr(task) == shm_lapid)) &&
73191+ (task->acl->mode & GR_PROTSHM) &&
73192+ (task->acl != current->acl))) {
73193+ read_unlock(&tasklist_lock);
73194+ rcu_read_unlock();
73195+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73196+ return 0;
73197+ }
73198+ read_unlock(&tasklist_lock);
73199+ rcu_read_unlock();
73200+
73201+ return 1;
73202+}
73203diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73204new file mode 100644
73205index 0000000..bc0be01
73206--- /dev/null
73207+++ b/grsecurity/grsec_chdir.c
73208@@ -0,0 +1,19 @@
73209+#include <linux/kernel.h>
73210+#include <linux/sched.h>
73211+#include <linux/fs.h>
73212+#include <linux/file.h>
73213+#include <linux/grsecurity.h>
73214+#include <linux/grinternal.h>
73215+
73216+void
73217+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73218+{
73219+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73220+ if ((grsec_enable_chdir && grsec_enable_group &&
73221+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73222+ !grsec_enable_group)) {
73223+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73224+ }
73225+#endif
73226+ return;
73227+}
73228diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73229new file mode 100644
73230index 0000000..baa635c
73231--- /dev/null
73232+++ b/grsecurity/grsec_chroot.c
73233@@ -0,0 +1,387 @@
73234+#include <linux/kernel.h>
73235+#include <linux/module.h>
73236+#include <linux/sched.h>
73237+#include <linux/file.h>
73238+#include <linux/fs.h>
73239+#include <linux/mount.h>
73240+#include <linux/types.h>
73241+#include "../fs/mount.h"
73242+#include <linux/grsecurity.h>
73243+#include <linux/grinternal.h>
73244+
73245+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73246+int gr_init_ran;
73247+#endif
73248+
73249+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73250+{
73251+#ifdef CONFIG_GRKERNSEC
73252+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73253+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73254+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73255+ && gr_init_ran
73256+#endif
73257+ )
73258+ task->gr_is_chrooted = 1;
73259+ else {
73260+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73261+ if (task_pid_nr(task) == 1 && !gr_init_ran)
73262+ gr_init_ran = 1;
73263+#endif
73264+ task->gr_is_chrooted = 0;
73265+ }
73266+
73267+ task->gr_chroot_dentry = path->dentry;
73268+#endif
73269+ return;
73270+}
73271+
73272+void gr_clear_chroot_entries(struct task_struct *task)
73273+{
73274+#ifdef CONFIG_GRKERNSEC
73275+ task->gr_is_chrooted = 0;
73276+ task->gr_chroot_dentry = NULL;
73277+#endif
73278+ return;
73279+}
73280+
73281+int
73282+gr_handle_chroot_unix(const pid_t pid)
73283+{
73284+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73285+ struct task_struct *p;
73286+
73287+ if (unlikely(!grsec_enable_chroot_unix))
73288+ return 1;
73289+
73290+ if (likely(!proc_is_chrooted(current)))
73291+ return 1;
73292+
73293+ rcu_read_lock();
73294+ read_lock(&tasklist_lock);
73295+ p = find_task_by_vpid_unrestricted(pid);
73296+ if (unlikely(p && !have_same_root(current, p))) {
73297+ read_unlock(&tasklist_lock);
73298+ rcu_read_unlock();
73299+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73300+ return 0;
73301+ }
73302+ read_unlock(&tasklist_lock);
73303+ rcu_read_unlock();
73304+#endif
73305+ return 1;
73306+}
73307+
73308+int
73309+gr_handle_chroot_nice(void)
73310+{
73311+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73312+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73313+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73314+ return -EPERM;
73315+ }
73316+#endif
73317+ return 0;
73318+}
73319+
73320+int
73321+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73322+{
73323+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73324+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73325+ && proc_is_chrooted(current)) {
73326+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73327+ return -EACCES;
73328+ }
73329+#endif
73330+ return 0;
73331+}
73332+
73333+int
73334+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73335+{
73336+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73337+ struct task_struct *p;
73338+ int ret = 0;
73339+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73340+ return ret;
73341+
73342+ read_lock(&tasklist_lock);
73343+ do_each_pid_task(pid, type, p) {
73344+ if (!have_same_root(current, p)) {
73345+ ret = 1;
73346+ goto out;
73347+ }
73348+ } while_each_pid_task(pid, type, p);
73349+out:
73350+ read_unlock(&tasklist_lock);
73351+ return ret;
73352+#endif
73353+ return 0;
73354+}
73355+
73356+int
73357+gr_pid_is_chrooted(struct task_struct *p)
73358+{
73359+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73360+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73361+ return 0;
73362+
73363+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73364+ !have_same_root(current, p)) {
73365+ return 1;
73366+ }
73367+#endif
73368+ return 0;
73369+}
73370+
73371+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73372+
73373+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73374+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73375+{
73376+ struct path path, currentroot;
73377+ int ret = 0;
73378+
73379+ path.dentry = (struct dentry *)u_dentry;
73380+ path.mnt = (struct vfsmount *)u_mnt;
73381+ get_fs_root(current->fs, &currentroot);
73382+ if (path_is_under(&path, &currentroot))
73383+ ret = 1;
73384+ path_put(&currentroot);
73385+
73386+ return ret;
73387+}
73388+#endif
73389+
73390+int
73391+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73392+{
73393+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73394+ if (!grsec_enable_chroot_fchdir)
73395+ return 1;
73396+
73397+ if (!proc_is_chrooted(current))
73398+ return 1;
73399+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73400+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73401+ return 0;
73402+ }
73403+#endif
73404+ return 1;
73405+}
73406+
73407+int
73408+gr_chroot_fhandle(void)
73409+{
73410+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73411+ if (!grsec_enable_chroot_fchdir)
73412+ return 1;
73413+
73414+ if (!proc_is_chrooted(current))
73415+ return 1;
73416+ else {
73417+ gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
73418+ return 0;
73419+ }
73420+#endif
73421+ return 1;
73422+}
73423+
73424+int
73425+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73426+ const time_t shm_createtime)
73427+{
73428+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73429+ struct task_struct *p;
73430+ time_t starttime;
73431+
73432+ if (unlikely(!grsec_enable_chroot_shmat))
73433+ return 1;
73434+
73435+ if (likely(!proc_is_chrooted(current)))
73436+ return 1;
73437+
73438+ rcu_read_lock();
73439+ read_lock(&tasklist_lock);
73440+
73441+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73442+ starttime = p->start_time.tv_sec;
73443+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73444+ if (have_same_root(current, p)) {
73445+ goto allow;
73446+ } else {
73447+ read_unlock(&tasklist_lock);
73448+ rcu_read_unlock();
73449+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73450+ return 0;
73451+ }
73452+ }
73453+ /* creator exited, pid reuse, fall through to next check */
73454+ }
73455+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73456+ if (unlikely(!have_same_root(current, p))) {
73457+ read_unlock(&tasklist_lock);
73458+ rcu_read_unlock();
73459+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73460+ return 0;
73461+ }
73462+ }
73463+
73464+allow:
73465+ read_unlock(&tasklist_lock);
73466+ rcu_read_unlock();
73467+#endif
73468+ return 1;
73469+}
73470+
73471+void
73472+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73473+{
73474+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73475+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73476+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73477+#endif
73478+ return;
73479+}
73480+
73481+int
73482+gr_handle_chroot_mknod(const struct dentry *dentry,
73483+ const struct vfsmount *mnt, const int mode)
73484+{
73485+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73486+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73487+ proc_is_chrooted(current)) {
73488+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73489+ return -EPERM;
73490+ }
73491+#endif
73492+ return 0;
73493+}
73494+
73495+int
73496+gr_handle_chroot_mount(const struct dentry *dentry,
73497+ const struct vfsmount *mnt, const char *dev_name)
73498+{
73499+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73500+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73501+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73502+ return -EPERM;
73503+ }
73504+#endif
73505+ return 0;
73506+}
73507+
73508+int
73509+gr_handle_chroot_pivot(void)
73510+{
73511+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73512+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73513+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73514+ return -EPERM;
73515+ }
73516+#endif
73517+ return 0;
73518+}
73519+
73520+int
73521+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73522+{
73523+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73524+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73525+ !gr_is_outside_chroot(dentry, mnt)) {
73526+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73527+ return -EPERM;
73528+ }
73529+#endif
73530+ return 0;
73531+}
73532+
73533+extern const char *captab_log[];
73534+extern int captab_log_entries;
73535+
73536+int
73537+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73538+{
73539+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73540+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73541+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73542+ if (cap_raised(chroot_caps, cap)) {
73543+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73544+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73545+ }
73546+ return 0;
73547+ }
73548+ }
73549+#endif
73550+ return 1;
73551+}
73552+
73553+int
73554+gr_chroot_is_capable(const int cap)
73555+{
73556+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73557+ return gr_task_chroot_is_capable(current, current_cred(), cap);
73558+#endif
73559+ return 1;
73560+}
73561+
73562+int
73563+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73564+{
73565+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73566+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73567+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73568+ if (cap_raised(chroot_caps, cap)) {
73569+ return 0;
73570+ }
73571+ }
73572+#endif
73573+ return 1;
73574+}
73575+
73576+int
73577+gr_chroot_is_capable_nolog(const int cap)
73578+{
73579+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73580+ return gr_task_chroot_is_capable_nolog(current, cap);
73581+#endif
73582+ return 1;
73583+}
73584+
73585+int
73586+gr_handle_chroot_sysctl(const int op)
73587+{
73588+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73589+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73590+ proc_is_chrooted(current))
73591+ return -EACCES;
73592+#endif
73593+ return 0;
73594+}
73595+
73596+void
73597+gr_handle_chroot_chdir(const struct path *path)
73598+{
73599+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73600+ if (grsec_enable_chroot_chdir)
73601+ set_fs_pwd(current->fs, path);
73602+#endif
73603+ return;
73604+}
73605+
73606+int
73607+gr_handle_chroot_chmod(const struct dentry *dentry,
73608+ const struct vfsmount *mnt, const int mode)
73609+{
73610+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73611+ /* allow chmod +s on directories, but not files */
73612+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73613+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73614+ proc_is_chrooted(current)) {
73615+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73616+ return -EPERM;
73617+ }
73618+#endif
73619+ return 0;
73620+}
73621diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73622new file mode 100644
73623index 0000000..de31e65
73624--- /dev/null
73625+++ b/grsecurity/grsec_disabled.c
73626@@ -0,0 +1,434 @@
73627+#include <linux/kernel.h>
73628+#include <linux/module.h>
73629+#include <linux/sched.h>
73630+#include <linux/file.h>
73631+#include <linux/fs.h>
73632+#include <linux/kdev_t.h>
73633+#include <linux/net.h>
73634+#include <linux/in.h>
73635+#include <linux/ip.h>
73636+#include <linux/skbuff.h>
73637+#include <linux/sysctl.h>
73638+
73639+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73640+void
73641+pax_set_initial_flags(struct linux_binprm *bprm)
73642+{
73643+ return;
73644+}
73645+#endif
73646+
73647+#ifdef CONFIG_SYSCTL
73648+__u32
73649+gr_handle_sysctl(const struct ctl_table * table, const int op)
73650+{
73651+ return 0;
73652+}
73653+#endif
73654+
73655+#ifdef CONFIG_TASKSTATS
73656+int gr_is_taskstats_denied(int pid)
73657+{
73658+ return 0;
73659+}
73660+#endif
73661+
73662+int
73663+gr_acl_is_enabled(void)
73664+{
73665+ return 0;
73666+}
73667+
73668+void
73669+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73670+{
73671+ return;
73672+}
73673+
73674+int
73675+gr_handle_rawio(const struct inode *inode)
73676+{
73677+ return 0;
73678+}
73679+
73680+void
73681+gr_acl_handle_psacct(struct task_struct *task, const long code)
73682+{
73683+ return;
73684+}
73685+
73686+int
73687+gr_handle_ptrace(struct task_struct *task, const long request)
73688+{
73689+ return 0;
73690+}
73691+
73692+int
73693+gr_handle_proc_ptrace(struct task_struct *task)
73694+{
73695+ return 0;
73696+}
73697+
73698+int
73699+gr_set_acls(const int type)
73700+{
73701+ return 0;
73702+}
73703+
73704+int
73705+gr_check_hidden_task(const struct task_struct *tsk)
73706+{
73707+ return 0;
73708+}
73709+
73710+int
73711+gr_check_protected_task(const struct task_struct *task)
73712+{
73713+ return 0;
73714+}
73715+
73716+int
73717+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73718+{
73719+ return 0;
73720+}
73721+
73722+void
73723+gr_copy_label(struct task_struct *tsk)
73724+{
73725+ return;
73726+}
73727+
73728+void
73729+gr_set_pax_flags(struct task_struct *task)
73730+{
73731+ return;
73732+}
73733+
73734+int
73735+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73736+ const int unsafe_share)
73737+{
73738+ return 0;
73739+}
73740+
73741+void
73742+gr_handle_delete(const ino_t ino, const dev_t dev)
73743+{
73744+ return;
73745+}
73746+
73747+void
73748+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73749+{
73750+ return;
73751+}
73752+
73753+void
73754+gr_handle_crash(struct task_struct *task, const int sig)
73755+{
73756+ return;
73757+}
73758+
73759+int
73760+gr_check_crash_exec(const struct file *filp)
73761+{
73762+ return 0;
73763+}
73764+
73765+int
73766+gr_check_crash_uid(const kuid_t uid)
73767+{
73768+ return 0;
73769+}
73770+
73771+void
73772+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73773+ struct dentry *old_dentry,
73774+ struct dentry *new_dentry,
73775+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
73776+{
73777+ return;
73778+}
73779+
73780+int
73781+gr_search_socket(const int family, const int type, const int protocol)
73782+{
73783+ return 1;
73784+}
73785+
73786+int
73787+gr_search_connectbind(const int mode, const struct socket *sock,
73788+ const struct sockaddr_in *addr)
73789+{
73790+ return 0;
73791+}
73792+
73793+void
73794+gr_handle_alertkill(struct task_struct *task)
73795+{
73796+ return;
73797+}
73798+
73799+__u32
73800+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73801+{
73802+ return 1;
73803+}
73804+
73805+__u32
73806+gr_acl_handle_hidden_file(const struct dentry * dentry,
73807+ const struct vfsmount * mnt)
73808+{
73809+ return 1;
73810+}
73811+
73812+__u32
73813+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73814+ int acc_mode)
73815+{
73816+ return 1;
73817+}
73818+
73819+__u32
73820+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73821+{
73822+ return 1;
73823+}
73824+
73825+__u32
73826+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73827+{
73828+ return 1;
73829+}
73830+
73831+int
73832+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73833+ unsigned int *vm_flags)
73834+{
73835+ return 1;
73836+}
73837+
73838+__u32
73839+gr_acl_handle_truncate(const struct dentry * dentry,
73840+ const struct vfsmount * mnt)
73841+{
73842+ return 1;
73843+}
73844+
73845+__u32
73846+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73847+{
73848+ return 1;
73849+}
73850+
73851+__u32
73852+gr_acl_handle_access(const struct dentry * dentry,
73853+ const struct vfsmount * mnt, const int fmode)
73854+{
73855+ return 1;
73856+}
73857+
73858+__u32
73859+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73860+ umode_t *mode)
73861+{
73862+ return 1;
73863+}
73864+
73865+__u32
73866+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73867+{
73868+ return 1;
73869+}
73870+
73871+__u32
73872+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73873+{
73874+ return 1;
73875+}
73876+
73877+__u32
73878+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73879+{
73880+ return 1;
73881+}
73882+
73883+void
73884+grsecurity_init(void)
73885+{
73886+ return;
73887+}
73888+
73889+umode_t gr_acl_umask(void)
73890+{
73891+ return 0;
73892+}
73893+
73894+__u32
73895+gr_acl_handle_mknod(const struct dentry * new_dentry,
73896+ const struct dentry * parent_dentry,
73897+ const struct vfsmount * parent_mnt,
73898+ const int mode)
73899+{
73900+ return 1;
73901+}
73902+
73903+__u32
73904+gr_acl_handle_mkdir(const struct dentry * new_dentry,
73905+ const struct dentry * parent_dentry,
73906+ const struct vfsmount * parent_mnt)
73907+{
73908+ return 1;
73909+}
73910+
73911+__u32
73912+gr_acl_handle_symlink(const struct dentry * new_dentry,
73913+ const struct dentry * parent_dentry,
73914+ const struct vfsmount * parent_mnt, const struct filename *from)
73915+{
73916+ return 1;
73917+}
73918+
73919+__u32
73920+gr_acl_handle_link(const struct dentry * new_dentry,
73921+ const struct dentry * parent_dentry,
73922+ const struct vfsmount * parent_mnt,
73923+ const struct dentry * old_dentry,
73924+ const struct vfsmount * old_mnt, const struct filename *to)
73925+{
73926+ return 1;
73927+}
73928+
73929+int
73930+gr_acl_handle_rename(const struct dentry *new_dentry,
73931+ const struct dentry *parent_dentry,
73932+ const struct vfsmount *parent_mnt,
73933+ const struct dentry *old_dentry,
73934+ const struct inode *old_parent_inode,
73935+ const struct vfsmount *old_mnt, const struct filename *newname,
73936+ unsigned int flags)
73937+{
73938+ return 0;
73939+}
73940+
73941+int
73942+gr_acl_handle_filldir(const struct file *file, const char *name,
73943+ const int namelen, const ino_t ino)
73944+{
73945+ return 1;
73946+}
73947+
73948+int
73949+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73950+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73951+{
73952+ return 1;
73953+}
73954+
73955+int
73956+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
73957+{
73958+ return 0;
73959+}
73960+
73961+int
73962+gr_search_accept(const struct socket *sock)
73963+{
73964+ return 0;
73965+}
73966+
73967+int
73968+gr_search_listen(const struct socket *sock)
73969+{
73970+ return 0;
73971+}
73972+
73973+int
73974+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
73975+{
73976+ return 0;
73977+}
73978+
73979+__u32
73980+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
73981+{
73982+ return 1;
73983+}
73984+
73985+__u32
73986+gr_acl_handle_creat(const struct dentry * dentry,
73987+ const struct dentry * p_dentry,
73988+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73989+ const int imode)
73990+{
73991+ return 1;
73992+}
73993+
73994+void
73995+gr_acl_handle_exit(void)
73996+{
73997+ return;
73998+}
73999+
74000+int
74001+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74002+{
74003+ return 1;
74004+}
74005+
74006+void
74007+gr_set_role_label(const kuid_t uid, const kgid_t gid)
74008+{
74009+ return;
74010+}
74011+
74012+int
74013+gr_acl_handle_procpidmem(const struct task_struct *task)
74014+{
74015+ return 0;
74016+}
74017+
74018+int
74019+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74020+{
74021+ return 0;
74022+}
74023+
74024+int
74025+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74026+{
74027+ return 0;
74028+}
74029+
74030+int
74031+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74032+{
74033+ return 0;
74034+}
74035+
74036+int
74037+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74038+{
74039+ return 0;
74040+}
74041+
74042+int gr_acl_enable_at_secure(void)
74043+{
74044+ return 0;
74045+}
74046+
74047+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74048+{
74049+ return dentry->d_sb->s_dev;
74050+}
74051+
74052+void gr_put_exec_file(struct task_struct *task)
74053+{
74054+ return;
74055+}
74056+
74057+#ifdef CONFIG_SECURITY
74058+EXPORT_SYMBOL_GPL(gr_check_user_change);
74059+EXPORT_SYMBOL_GPL(gr_check_group_change);
74060+#endif
74061diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74062new file mode 100644
74063index 0000000..f35f454
74064--- /dev/null
74065+++ b/grsecurity/grsec_exec.c
74066@@ -0,0 +1,187 @@
74067+#include <linux/kernel.h>
74068+#include <linux/sched.h>
74069+#include <linux/file.h>
74070+#include <linux/binfmts.h>
74071+#include <linux/fs.h>
74072+#include <linux/types.h>
74073+#include <linux/grdefs.h>
74074+#include <linux/grsecurity.h>
74075+#include <linux/grinternal.h>
74076+#include <linux/capability.h>
74077+#include <linux/module.h>
74078+#include <linux/compat.h>
74079+
74080+#include <asm/uaccess.h>
74081+
74082+#ifdef CONFIG_GRKERNSEC_EXECLOG
74083+static char gr_exec_arg_buf[132];
74084+static DEFINE_MUTEX(gr_exec_arg_mutex);
74085+#endif
74086+
74087+struct user_arg_ptr {
74088+#ifdef CONFIG_COMPAT
74089+ bool is_compat;
74090+#endif
74091+ union {
74092+ const char __user *const __user *native;
74093+#ifdef CONFIG_COMPAT
74094+ const compat_uptr_t __user *compat;
74095+#endif
74096+ } ptr;
74097+};
74098+
74099+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74100+
74101+void
74102+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74103+{
74104+#ifdef CONFIG_GRKERNSEC_EXECLOG
74105+ char *grarg = gr_exec_arg_buf;
74106+ unsigned int i, x, execlen = 0;
74107+ char c;
74108+
74109+ if (!((grsec_enable_execlog && grsec_enable_group &&
74110+ in_group_p(grsec_audit_gid))
74111+ || (grsec_enable_execlog && !grsec_enable_group)))
74112+ return;
74113+
74114+ mutex_lock(&gr_exec_arg_mutex);
74115+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
74116+
74117+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
74118+ const char __user *p;
74119+ unsigned int len;
74120+
74121+ p = get_user_arg_ptr(argv, i);
74122+ if (IS_ERR(p))
74123+ goto log;
74124+
74125+ len = strnlen_user(p, 128 - execlen);
74126+ if (len > 128 - execlen)
74127+ len = 128 - execlen;
74128+ else if (len > 0)
74129+ len--;
74130+ if (copy_from_user(grarg + execlen, p, len))
74131+ goto log;
74132+
74133+ /* rewrite unprintable characters */
74134+ for (x = 0; x < len; x++) {
74135+ c = *(grarg + execlen + x);
74136+ if (c < 32 || c > 126)
74137+ *(grarg + execlen + x) = ' ';
74138+ }
74139+
74140+ execlen += len;
74141+ *(grarg + execlen) = ' ';
74142+ *(grarg + execlen + 1) = '\0';
74143+ execlen++;
74144+ }
74145+
74146+ log:
74147+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74148+ bprm->file->f_path.mnt, grarg);
74149+ mutex_unlock(&gr_exec_arg_mutex);
74150+#endif
74151+ return;
74152+}
74153+
74154+#ifdef CONFIG_GRKERNSEC
74155+extern int gr_acl_is_capable(const int cap);
74156+extern int gr_acl_is_capable_nolog(const int cap);
74157+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74158+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74159+extern int gr_chroot_is_capable(const int cap);
74160+extern int gr_chroot_is_capable_nolog(const int cap);
74161+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74162+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74163+#endif
74164+
74165+const char *captab_log[] = {
74166+ "CAP_CHOWN",
74167+ "CAP_DAC_OVERRIDE",
74168+ "CAP_DAC_READ_SEARCH",
74169+ "CAP_FOWNER",
74170+ "CAP_FSETID",
74171+ "CAP_KILL",
74172+ "CAP_SETGID",
74173+ "CAP_SETUID",
74174+ "CAP_SETPCAP",
74175+ "CAP_LINUX_IMMUTABLE",
74176+ "CAP_NET_BIND_SERVICE",
74177+ "CAP_NET_BROADCAST",
74178+ "CAP_NET_ADMIN",
74179+ "CAP_NET_RAW",
74180+ "CAP_IPC_LOCK",
74181+ "CAP_IPC_OWNER",
74182+ "CAP_SYS_MODULE",
74183+ "CAP_SYS_RAWIO",
74184+ "CAP_SYS_CHROOT",
74185+ "CAP_SYS_PTRACE",
74186+ "CAP_SYS_PACCT",
74187+ "CAP_SYS_ADMIN",
74188+ "CAP_SYS_BOOT",
74189+ "CAP_SYS_NICE",
74190+ "CAP_SYS_RESOURCE",
74191+ "CAP_SYS_TIME",
74192+ "CAP_SYS_TTY_CONFIG",
74193+ "CAP_MKNOD",
74194+ "CAP_LEASE",
74195+ "CAP_AUDIT_WRITE",
74196+ "CAP_AUDIT_CONTROL",
74197+ "CAP_SETFCAP",
74198+ "CAP_MAC_OVERRIDE",
74199+ "CAP_MAC_ADMIN",
74200+ "CAP_SYSLOG",
74201+ "CAP_WAKE_ALARM"
74202+};
74203+
74204+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74205+
74206+int gr_is_capable(const int cap)
74207+{
74208+#ifdef CONFIG_GRKERNSEC
74209+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74210+ return 1;
74211+ return 0;
74212+#else
74213+ return 1;
74214+#endif
74215+}
74216+
74217+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74218+{
74219+#ifdef CONFIG_GRKERNSEC
74220+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74221+ return 1;
74222+ return 0;
74223+#else
74224+ return 1;
74225+#endif
74226+}
74227+
74228+int gr_is_capable_nolog(const int cap)
74229+{
74230+#ifdef CONFIG_GRKERNSEC
74231+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74232+ return 1;
74233+ return 0;
74234+#else
74235+ return 1;
74236+#endif
74237+}
74238+
74239+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74240+{
74241+#ifdef CONFIG_GRKERNSEC
74242+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74243+ return 1;
74244+ return 0;
74245+#else
74246+ return 1;
74247+#endif
74248+}
74249+
74250+EXPORT_SYMBOL_GPL(gr_is_capable);
74251+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74252+EXPORT_SYMBOL_GPL(gr_task_is_capable);
74253+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74254diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74255new file mode 100644
74256index 0000000..06cc6ea
74257--- /dev/null
74258+++ b/grsecurity/grsec_fifo.c
74259@@ -0,0 +1,24 @@
74260+#include <linux/kernel.h>
74261+#include <linux/sched.h>
74262+#include <linux/fs.h>
74263+#include <linux/file.h>
74264+#include <linux/grinternal.h>
74265+
74266+int
74267+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74268+ const struct dentry *dir, const int flag, const int acc_mode)
74269+{
74270+#ifdef CONFIG_GRKERNSEC_FIFO
74271+ const struct cred *cred = current_cred();
74272+
74273+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74274+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74275+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74276+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74277+ if (!inode_permission(dentry->d_inode, acc_mode))
74278+ 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));
74279+ return -EACCES;
74280+ }
74281+#endif
74282+ return 0;
74283+}
74284diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74285new file mode 100644
74286index 0000000..8ca18bf
74287--- /dev/null
74288+++ b/grsecurity/grsec_fork.c
74289@@ -0,0 +1,23 @@
74290+#include <linux/kernel.h>
74291+#include <linux/sched.h>
74292+#include <linux/grsecurity.h>
74293+#include <linux/grinternal.h>
74294+#include <linux/errno.h>
74295+
74296+void
74297+gr_log_forkfail(const int retval)
74298+{
74299+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74300+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74301+ switch (retval) {
74302+ case -EAGAIN:
74303+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74304+ break;
74305+ case -ENOMEM:
74306+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74307+ break;
74308+ }
74309+ }
74310+#endif
74311+ return;
74312+}
74313diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74314new file mode 100644
74315index 0000000..ae6c028
74316--- /dev/null
74317+++ b/grsecurity/grsec_init.c
74318@@ -0,0 +1,272 @@
74319+#include <linux/kernel.h>
74320+#include <linux/sched.h>
74321+#include <linux/mm.h>
74322+#include <linux/gracl.h>
74323+#include <linux/slab.h>
74324+#include <linux/vmalloc.h>
74325+#include <linux/percpu.h>
74326+#include <linux/module.h>
74327+
74328+int grsec_enable_ptrace_readexec;
74329+int grsec_enable_setxid;
74330+int grsec_enable_symlinkown;
74331+kgid_t grsec_symlinkown_gid;
74332+int grsec_enable_brute;
74333+int grsec_enable_link;
74334+int grsec_enable_dmesg;
74335+int grsec_enable_harden_ptrace;
74336+int grsec_enable_harden_ipc;
74337+int grsec_enable_fifo;
74338+int grsec_enable_execlog;
74339+int grsec_enable_signal;
74340+int grsec_enable_forkfail;
74341+int grsec_enable_audit_ptrace;
74342+int grsec_enable_time;
74343+int grsec_enable_group;
74344+kgid_t grsec_audit_gid;
74345+int grsec_enable_chdir;
74346+int grsec_enable_mount;
74347+int grsec_enable_rofs;
74348+int grsec_deny_new_usb;
74349+int grsec_enable_chroot_findtask;
74350+int grsec_enable_chroot_mount;
74351+int grsec_enable_chroot_shmat;
74352+int grsec_enable_chroot_fchdir;
74353+int grsec_enable_chroot_double;
74354+int grsec_enable_chroot_pivot;
74355+int grsec_enable_chroot_chdir;
74356+int grsec_enable_chroot_chmod;
74357+int grsec_enable_chroot_mknod;
74358+int grsec_enable_chroot_nice;
74359+int grsec_enable_chroot_execlog;
74360+int grsec_enable_chroot_caps;
74361+int grsec_enable_chroot_sysctl;
74362+int grsec_enable_chroot_unix;
74363+int grsec_enable_tpe;
74364+kgid_t grsec_tpe_gid;
74365+int grsec_enable_blackhole;
74366+#ifdef CONFIG_IPV6_MODULE
74367+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74368+#endif
74369+int grsec_lastack_retries;
74370+int grsec_enable_tpe_all;
74371+int grsec_enable_tpe_invert;
74372+int grsec_enable_socket_all;
74373+kgid_t grsec_socket_all_gid;
74374+int grsec_enable_socket_client;
74375+kgid_t grsec_socket_client_gid;
74376+int grsec_enable_socket_server;
74377+kgid_t grsec_socket_server_gid;
74378+int grsec_resource_logging;
74379+int grsec_disable_privio;
74380+int grsec_enable_log_rwxmaps;
74381+int grsec_lock;
74382+
74383+DEFINE_SPINLOCK(grsec_alert_lock);
74384+unsigned long grsec_alert_wtime = 0;
74385+unsigned long grsec_alert_fyet = 0;
74386+
74387+DEFINE_SPINLOCK(grsec_audit_lock);
74388+
74389+DEFINE_RWLOCK(grsec_exec_file_lock);
74390+
74391+char *gr_shared_page[4];
74392+
74393+char *gr_alert_log_fmt;
74394+char *gr_audit_log_fmt;
74395+char *gr_alert_log_buf;
74396+char *gr_audit_log_buf;
74397+
74398+void __init
74399+grsecurity_init(void)
74400+{
74401+ int j;
74402+ /* create the per-cpu shared pages */
74403+
74404+#ifdef CONFIG_X86
74405+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74406+#endif
74407+
74408+ for (j = 0; j < 4; j++) {
74409+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74410+ if (gr_shared_page[j] == NULL) {
74411+ panic("Unable to allocate grsecurity shared page");
74412+ return;
74413+ }
74414+ }
74415+
74416+ /* allocate log buffers */
74417+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74418+ if (!gr_alert_log_fmt) {
74419+ panic("Unable to allocate grsecurity alert log format buffer");
74420+ return;
74421+ }
74422+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74423+ if (!gr_audit_log_fmt) {
74424+ panic("Unable to allocate grsecurity audit log format buffer");
74425+ return;
74426+ }
74427+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74428+ if (!gr_alert_log_buf) {
74429+ panic("Unable to allocate grsecurity alert log buffer");
74430+ return;
74431+ }
74432+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74433+ if (!gr_audit_log_buf) {
74434+ panic("Unable to allocate grsecurity audit log buffer");
74435+ return;
74436+ }
74437+
74438+#ifdef CONFIG_GRKERNSEC_IO
74439+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74440+ grsec_disable_privio = 1;
74441+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74442+ grsec_disable_privio = 1;
74443+#else
74444+ grsec_disable_privio = 0;
74445+#endif
74446+#endif
74447+
74448+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74449+ /* for backward compatibility, tpe_invert always defaults to on if
74450+ enabled in the kernel
74451+ */
74452+ grsec_enable_tpe_invert = 1;
74453+#endif
74454+
74455+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74456+#ifndef CONFIG_GRKERNSEC_SYSCTL
74457+ grsec_lock = 1;
74458+#endif
74459+
74460+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74461+ grsec_enable_log_rwxmaps = 1;
74462+#endif
74463+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74464+ grsec_enable_group = 1;
74465+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74466+#endif
74467+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74468+ grsec_enable_ptrace_readexec = 1;
74469+#endif
74470+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74471+ grsec_enable_chdir = 1;
74472+#endif
74473+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74474+ grsec_enable_harden_ptrace = 1;
74475+#endif
74476+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74477+ grsec_enable_harden_ipc = 1;
74478+#endif
74479+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74480+ grsec_enable_mount = 1;
74481+#endif
74482+#ifdef CONFIG_GRKERNSEC_LINK
74483+ grsec_enable_link = 1;
74484+#endif
74485+#ifdef CONFIG_GRKERNSEC_BRUTE
74486+ grsec_enable_brute = 1;
74487+#endif
74488+#ifdef CONFIG_GRKERNSEC_DMESG
74489+ grsec_enable_dmesg = 1;
74490+#endif
74491+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74492+ grsec_enable_blackhole = 1;
74493+ grsec_lastack_retries = 4;
74494+#endif
74495+#ifdef CONFIG_GRKERNSEC_FIFO
74496+ grsec_enable_fifo = 1;
74497+#endif
74498+#ifdef CONFIG_GRKERNSEC_EXECLOG
74499+ grsec_enable_execlog = 1;
74500+#endif
74501+#ifdef CONFIG_GRKERNSEC_SETXID
74502+ grsec_enable_setxid = 1;
74503+#endif
74504+#ifdef CONFIG_GRKERNSEC_SIGNAL
74505+ grsec_enable_signal = 1;
74506+#endif
74507+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74508+ grsec_enable_forkfail = 1;
74509+#endif
74510+#ifdef CONFIG_GRKERNSEC_TIME
74511+ grsec_enable_time = 1;
74512+#endif
74513+#ifdef CONFIG_GRKERNSEC_RESLOG
74514+ grsec_resource_logging = 1;
74515+#endif
74516+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74517+ grsec_enable_chroot_findtask = 1;
74518+#endif
74519+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74520+ grsec_enable_chroot_unix = 1;
74521+#endif
74522+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74523+ grsec_enable_chroot_mount = 1;
74524+#endif
74525+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74526+ grsec_enable_chroot_fchdir = 1;
74527+#endif
74528+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74529+ grsec_enable_chroot_shmat = 1;
74530+#endif
74531+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74532+ grsec_enable_audit_ptrace = 1;
74533+#endif
74534+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74535+ grsec_enable_chroot_double = 1;
74536+#endif
74537+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74538+ grsec_enable_chroot_pivot = 1;
74539+#endif
74540+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74541+ grsec_enable_chroot_chdir = 1;
74542+#endif
74543+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74544+ grsec_enable_chroot_chmod = 1;
74545+#endif
74546+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74547+ grsec_enable_chroot_mknod = 1;
74548+#endif
74549+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74550+ grsec_enable_chroot_nice = 1;
74551+#endif
74552+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74553+ grsec_enable_chroot_execlog = 1;
74554+#endif
74555+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74556+ grsec_enable_chroot_caps = 1;
74557+#endif
74558+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74559+ grsec_enable_chroot_sysctl = 1;
74560+#endif
74561+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74562+ grsec_enable_symlinkown = 1;
74563+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74564+#endif
74565+#ifdef CONFIG_GRKERNSEC_TPE
74566+ grsec_enable_tpe = 1;
74567+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74568+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74569+ grsec_enable_tpe_all = 1;
74570+#endif
74571+#endif
74572+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74573+ grsec_enable_socket_all = 1;
74574+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74575+#endif
74576+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74577+ grsec_enable_socket_client = 1;
74578+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74579+#endif
74580+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74581+ grsec_enable_socket_server = 1;
74582+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74583+#endif
74584+#endif
74585+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74586+ grsec_deny_new_usb = 1;
74587+#endif
74588+
74589+ return;
74590+}
74591diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74592new file mode 100644
74593index 0000000..1773300
74594--- /dev/null
74595+++ b/grsecurity/grsec_ipc.c
74596@@ -0,0 +1,48 @@
74597+#include <linux/kernel.h>
74598+#include <linux/mm.h>
74599+#include <linux/sched.h>
74600+#include <linux/file.h>
74601+#include <linux/ipc.h>
74602+#include <linux/ipc_namespace.h>
74603+#include <linux/grsecurity.h>
74604+#include <linux/grinternal.h>
74605+
74606+int
74607+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74608+{
74609+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74610+ int write;
74611+ int orig_granted_mode;
74612+ kuid_t euid;
74613+ kgid_t egid;
74614+
74615+ if (!grsec_enable_harden_ipc)
74616+ return 1;
74617+
74618+ euid = current_euid();
74619+ egid = current_egid();
74620+
74621+ write = requested_mode & 00002;
74622+ orig_granted_mode = ipcp->mode;
74623+
74624+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74625+ orig_granted_mode >>= 6;
74626+ else {
74627+ /* if likely wrong permissions, lock to user */
74628+ if (orig_granted_mode & 0007)
74629+ orig_granted_mode = 0;
74630+ /* otherwise do a egid-only check */
74631+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74632+ orig_granted_mode >>= 3;
74633+ /* otherwise, no access */
74634+ else
74635+ orig_granted_mode = 0;
74636+ }
74637+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74638+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74639+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74640+ return 0;
74641+ }
74642+#endif
74643+ return 1;
74644+}
74645diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74646new file mode 100644
74647index 0000000..5e05e20
74648--- /dev/null
74649+++ b/grsecurity/grsec_link.c
74650@@ -0,0 +1,58 @@
74651+#include <linux/kernel.h>
74652+#include <linux/sched.h>
74653+#include <linux/fs.h>
74654+#include <linux/file.h>
74655+#include <linux/grinternal.h>
74656+
74657+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74658+{
74659+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74660+ const struct inode *link_inode = link->dentry->d_inode;
74661+
74662+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74663+ /* ignore root-owned links, e.g. /proc/self */
74664+ gr_is_global_nonroot(link_inode->i_uid) && target &&
74665+ !uid_eq(link_inode->i_uid, target->i_uid)) {
74666+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74667+ return 1;
74668+ }
74669+#endif
74670+ return 0;
74671+}
74672+
74673+int
74674+gr_handle_follow_link(const struct inode *parent,
74675+ const struct inode *inode,
74676+ const struct dentry *dentry, const struct vfsmount *mnt)
74677+{
74678+#ifdef CONFIG_GRKERNSEC_LINK
74679+ const struct cred *cred = current_cred();
74680+
74681+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74682+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74683+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74684+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74685+ return -EACCES;
74686+ }
74687+#endif
74688+ return 0;
74689+}
74690+
74691+int
74692+gr_handle_hardlink(const struct dentry *dentry,
74693+ const struct vfsmount *mnt,
74694+ struct inode *inode, const int mode, const struct filename *to)
74695+{
74696+#ifdef CONFIG_GRKERNSEC_LINK
74697+ const struct cred *cred = current_cred();
74698+
74699+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74700+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74701+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74702+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74703+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74704+ return -EPERM;
74705+ }
74706+#endif
74707+ return 0;
74708+}
74709diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74710new file mode 100644
74711index 0000000..dbe0a6b
74712--- /dev/null
74713+++ b/grsecurity/grsec_log.c
74714@@ -0,0 +1,341 @@
74715+#include <linux/kernel.h>
74716+#include <linux/sched.h>
74717+#include <linux/file.h>
74718+#include <linux/tty.h>
74719+#include <linux/fs.h>
74720+#include <linux/mm.h>
74721+#include <linux/grinternal.h>
74722+
74723+#ifdef CONFIG_TREE_PREEMPT_RCU
74724+#define DISABLE_PREEMPT() preempt_disable()
74725+#define ENABLE_PREEMPT() preempt_enable()
74726+#else
74727+#define DISABLE_PREEMPT()
74728+#define ENABLE_PREEMPT()
74729+#endif
74730+
74731+#define BEGIN_LOCKS(x) \
74732+ DISABLE_PREEMPT(); \
74733+ rcu_read_lock(); \
74734+ read_lock(&tasklist_lock); \
74735+ read_lock(&grsec_exec_file_lock); \
74736+ if (x != GR_DO_AUDIT) \
74737+ spin_lock(&grsec_alert_lock); \
74738+ else \
74739+ spin_lock(&grsec_audit_lock)
74740+
74741+#define END_LOCKS(x) \
74742+ if (x != GR_DO_AUDIT) \
74743+ spin_unlock(&grsec_alert_lock); \
74744+ else \
74745+ spin_unlock(&grsec_audit_lock); \
74746+ read_unlock(&grsec_exec_file_lock); \
74747+ read_unlock(&tasklist_lock); \
74748+ rcu_read_unlock(); \
74749+ ENABLE_PREEMPT(); \
74750+ if (x == GR_DONT_AUDIT) \
74751+ gr_handle_alertkill(current)
74752+
74753+enum {
74754+ FLOODING,
74755+ NO_FLOODING
74756+};
74757+
74758+extern char *gr_alert_log_fmt;
74759+extern char *gr_audit_log_fmt;
74760+extern char *gr_alert_log_buf;
74761+extern char *gr_audit_log_buf;
74762+
74763+static int gr_log_start(int audit)
74764+{
74765+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74766+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74767+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74768+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74769+ unsigned long curr_secs = get_seconds();
74770+
74771+ if (audit == GR_DO_AUDIT)
74772+ goto set_fmt;
74773+
74774+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74775+ grsec_alert_wtime = curr_secs;
74776+ grsec_alert_fyet = 0;
74777+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74778+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74779+ grsec_alert_fyet++;
74780+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74781+ grsec_alert_wtime = curr_secs;
74782+ grsec_alert_fyet++;
74783+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74784+ return FLOODING;
74785+ }
74786+ else return FLOODING;
74787+
74788+set_fmt:
74789+#endif
74790+ memset(buf, 0, PAGE_SIZE);
74791+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
74792+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74793+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74794+ } else if (current->signal->curr_ip) {
74795+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74796+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74797+ } else if (gr_acl_is_enabled()) {
74798+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74799+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74800+ } else {
74801+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
74802+ strcpy(buf, fmt);
74803+ }
74804+
74805+ return NO_FLOODING;
74806+}
74807+
74808+static void gr_log_middle(int audit, const char *msg, va_list ap)
74809+ __attribute__ ((format (printf, 2, 0)));
74810+
74811+static void gr_log_middle(int audit, const char *msg, va_list ap)
74812+{
74813+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74814+ unsigned int len = strlen(buf);
74815+
74816+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74817+
74818+ return;
74819+}
74820+
74821+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74822+ __attribute__ ((format (printf, 2, 3)));
74823+
74824+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74825+{
74826+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74827+ unsigned int len = strlen(buf);
74828+ va_list ap;
74829+
74830+ va_start(ap, msg);
74831+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74832+ va_end(ap);
74833+
74834+ return;
74835+}
74836+
74837+static void gr_log_end(int audit, int append_default)
74838+{
74839+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74840+ if (append_default) {
74841+ struct task_struct *task = current;
74842+ struct task_struct *parent = task->real_parent;
74843+ const struct cred *cred = __task_cred(task);
74844+ const struct cred *pcred = __task_cred(parent);
74845+ unsigned int len = strlen(buf);
74846+
74847+ 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));
74848+ }
74849+
74850+ printk("%s\n", buf);
74851+
74852+ return;
74853+}
74854+
74855+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74856+{
74857+ int logtype;
74858+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74859+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74860+ void *voidptr = NULL;
74861+ int num1 = 0, num2 = 0;
74862+ unsigned long ulong1 = 0, ulong2 = 0;
74863+ struct dentry *dentry = NULL;
74864+ struct vfsmount *mnt = NULL;
74865+ struct file *file = NULL;
74866+ struct task_struct *task = NULL;
74867+ struct vm_area_struct *vma = NULL;
74868+ const struct cred *cred, *pcred;
74869+ va_list ap;
74870+
74871+ BEGIN_LOCKS(audit);
74872+ logtype = gr_log_start(audit);
74873+ if (logtype == FLOODING) {
74874+ END_LOCKS(audit);
74875+ return;
74876+ }
74877+ va_start(ap, argtypes);
74878+ switch (argtypes) {
74879+ case GR_TTYSNIFF:
74880+ task = va_arg(ap, struct task_struct *);
74881+ 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));
74882+ break;
74883+ case GR_SYSCTL_HIDDEN:
74884+ str1 = va_arg(ap, char *);
74885+ gr_log_middle_varargs(audit, msg, result, str1);
74886+ break;
74887+ case GR_RBAC:
74888+ dentry = va_arg(ap, struct dentry *);
74889+ mnt = va_arg(ap, struct vfsmount *);
74890+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
74891+ break;
74892+ case GR_RBAC_STR:
74893+ dentry = va_arg(ap, struct dentry *);
74894+ mnt = va_arg(ap, struct vfsmount *);
74895+ str1 = va_arg(ap, char *);
74896+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
74897+ break;
74898+ case GR_STR_RBAC:
74899+ str1 = va_arg(ap, char *);
74900+ dentry = va_arg(ap, struct dentry *);
74901+ mnt = va_arg(ap, struct vfsmount *);
74902+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
74903+ break;
74904+ case GR_RBAC_MODE2:
74905+ dentry = va_arg(ap, struct dentry *);
74906+ mnt = va_arg(ap, struct vfsmount *);
74907+ str1 = va_arg(ap, char *);
74908+ str2 = va_arg(ap, char *);
74909+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
74910+ break;
74911+ case GR_RBAC_MODE3:
74912+ dentry = va_arg(ap, struct dentry *);
74913+ mnt = va_arg(ap, struct vfsmount *);
74914+ str1 = va_arg(ap, char *);
74915+ str2 = va_arg(ap, char *);
74916+ str3 = va_arg(ap, char *);
74917+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
74918+ break;
74919+ case GR_FILENAME:
74920+ dentry = va_arg(ap, struct dentry *);
74921+ mnt = va_arg(ap, struct vfsmount *);
74922+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
74923+ break;
74924+ case GR_STR_FILENAME:
74925+ str1 = va_arg(ap, char *);
74926+ dentry = va_arg(ap, struct dentry *);
74927+ mnt = va_arg(ap, struct vfsmount *);
74928+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
74929+ break;
74930+ case GR_FILENAME_STR:
74931+ dentry = va_arg(ap, struct dentry *);
74932+ mnt = va_arg(ap, struct vfsmount *);
74933+ str1 = va_arg(ap, char *);
74934+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
74935+ break;
74936+ case GR_FILENAME_TWO_INT:
74937+ dentry = va_arg(ap, struct dentry *);
74938+ mnt = va_arg(ap, struct vfsmount *);
74939+ num1 = va_arg(ap, int);
74940+ num2 = va_arg(ap, int);
74941+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
74942+ break;
74943+ case GR_FILENAME_TWO_INT_STR:
74944+ dentry = va_arg(ap, struct dentry *);
74945+ mnt = va_arg(ap, struct vfsmount *);
74946+ num1 = va_arg(ap, int);
74947+ num2 = va_arg(ap, int);
74948+ str1 = va_arg(ap, char *);
74949+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
74950+ break;
74951+ case GR_TEXTREL:
74952+ file = va_arg(ap, struct file *);
74953+ ulong1 = va_arg(ap, unsigned long);
74954+ ulong2 = va_arg(ap, unsigned long);
74955+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
74956+ break;
74957+ case GR_PTRACE:
74958+ task = va_arg(ap, struct task_struct *);
74959+ 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));
74960+ break;
74961+ case GR_RESOURCE:
74962+ task = va_arg(ap, struct task_struct *);
74963+ cred = __task_cred(task);
74964+ pcred = __task_cred(task->real_parent);
74965+ ulong1 = va_arg(ap, unsigned long);
74966+ str1 = va_arg(ap, char *);
74967+ ulong2 = va_arg(ap, unsigned long);
74968+ 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));
74969+ break;
74970+ case GR_CAP:
74971+ task = va_arg(ap, struct task_struct *);
74972+ cred = __task_cred(task);
74973+ pcred = __task_cred(task->real_parent);
74974+ str1 = va_arg(ap, char *);
74975+ 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));
74976+ break;
74977+ case GR_SIG:
74978+ str1 = va_arg(ap, char *);
74979+ voidptr = va_arg(ap, void *);
74980+ gr_log_middle_varargs(audit, msg, str1, voidptr);
74981+ break;
74982+ case GR_SIG2:
74983+ task = va_arg(ap, struct task_struct *);
74984+ cred = __task_cred(task);
74985+ pcred = __task_cred(task->real_parent);
74986+ num1 = va_arg(ap, int);
74987+ 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));
74988+ break;
74989+ case GR_CRASH1:
74990+ task = va_arg(ap, struct task_struct *);
74991+ cred = __task_cred(task);
74992+ pcred = __task_cred(task->real_parent);
74993+ ulong1 = va_arg(ap, unsigned long);
74994+ 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);
74995+ break;
74996+ case GR_CRASH2:
74997+ task = va_arg(ap, struct task_struct *);
74998+ cred = __task_cred(task);
74999+ pcred = __task_cred(task->real_parent);
75000+ ulong1 = va_arg(ap, unsigned long);
75001+ 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);
75002+ break;
75003+ case GR_RWXMAP:
75004+ file = va_arg(ap, struct file *);
75005+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75006+ break;
75007+ case GR_RWXMAPVMA:
75008+ vma = va_arg(ap, struct vm_area_struct *);
75009+ if (vma->vm_file)
75010+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75011+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75012+ str1 = "<stack>";
75013+ else if (vma->vm_start <= current->mm->brk &&
75014+ vma->vm_end >= current->mm->start_brk)
75015+ str1 = "<heap>";
75016+ else
75017+ str1 = "<anonymous mapping>";
75018+ gr_log_middle_varargs(audit, msg, str1);
75019+ break;
75020+ case GR_PSACCT:
75021+ {
75022+ unsigned int wday, cday;
75023+ __u8 whr, chr;
75024+ __u8 wmin, cmin;
75025+ __u8 wsec, csec;
75026+ char cur_tty[64] = { 0 };
75027+ char parent_tty[64] = { 0 };
75028+
75029+ task = va_arg(ap, struct task_struct *);
75030+ wday = va_arg(ap, unsigned int);
75031+ cday = va_arg(ap, unsigned int);
75032+ whr = va_arg(ap, int);
75033+ chr = va_arg(ap, int);
75034+ wmin = va_arg(ap, int);
75035+ cmin = va_arg(ap, int);
75036+ wsec = va_arg(ap, int);
75037+ csec = va_arg(ap, int);
75038+ ulong1 = va_arg(ap, unsigned long);
75039+ cred = __task_cred(task);
75040+ pcred = __task_cred(task->real_parent);
75041+
75042+ 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));
75043+ }
75044+ break;
75045+ default:
75046+ gr_log_middle(audit, msg, ap);
75047+ }
75048+ va_end(ap);
75049+ // these don't need DEFAULTSECARGS printed on the end
75050+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75051+ gr_log_end(audit, 0);
75052+ else
75053+ gr_log_end(audit, 1);
75054+ END_LOCKS(audit);
75055+}
75056diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75057new file mode 100644
75058index 0000000..0e39d8c
75059--- /dev/null
75060+++ b/grsecurity/grsec_mem.c
75061@@ -0,0 +1,48 @@
75062+#include <linux/kernel.h>
75063+#include <linux/sched.h>
75064+#include <linux/mm.h>
75065+#include <linux/mman.h>
75066+#include <linux/module.h>
75067+#include <linux/grinternal.h>
75068+
75069+void gr_handle_msr_write(void)
75070+{
75071+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75072+ return;
75073+}
75074+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75075+
75076+void
75077+gr_handle_ioperm(void)
75078+{
75079+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75080+ return;
75081+}
75082+
75083+void
75084+gr_handle_iopl(void)
75085+{
75086+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75087+ return;
75088+}
75089+
75090+void
75091+gr_handle_mem_readwrite(u64 from, u64 to)
75092+{
75093+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75094+ return;
75095+}
75096+
75097+void
75098+gr_handle_vm86(void)
75099+{
75100+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75101+ return;
75102+}
75103+
75104+void
75105+gr_log_badprocpid(const char *entry)
75106+{
75107+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75108+ return;
75109+}
75110diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75111new file mode 100644
75112index 0000000..cd9e124
75113--- /dev/null
75114+++ b/grsecurity/grsec_mount.c
75115@@ -0,0 +1,65 @@
75116+#include <linux/kernel.h>
75117+#include <linux/sched.h>
75118+#include <linux/mount.h>
75119+#include <linux/major.h>
75120+#include <linux/grsecurity.h>
75121+#include <linux/grinternal.h>
75122+
75123+void
75124+gr_log_remount(const char *devname, const int retval)
75125+{
75126+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75127+ if (grsec_enable_mount && (retval >= 0))
75128+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75129+#endif
75130+ return;
75131+}
75132+
75133+void
75134+gr_log_unmount(const char *devname, const int retval)
75135+{
75136+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75137+ if (grsec_enable_mount && (retval >= 0))
75138+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75139+#endif
75140+ return;
75141+}
75142+
75143+void
75144+gr_log_mount(const char *from, const char *to, const int retval)
75145+{
75146+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75147+ if (grsec_enable_mount && (retval >= 0))
75148+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75149+#endif
75150+ return;
75151+}
75152+
75153+int
75154+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75155+{
75156+#ifdef CONFIG_GRKERNSEC_ROFS
75157+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75158+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75159+ return -EPERM;
75160+ } else
75161+ return 0;
75162+#endif
75163+ return 0;
75164+}
75165+
75166+int
75167+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75168+{
75169+#ifdef CONFIG_GRKERNSEC_ROFS
75170+ struct inode *inode = dentry->d_inode;
75171+
75172+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75173+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75174+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75175+ return -EPERM;
75176+ } else
75177+ return 0;
75178+#endif
75179+ return 0;
75180+}
75181diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75182new file mode 100644
75183index 0000000..6ee9d50
75184--- /dev/null
75185+++ b/grsecurity/grsec_pax.c
75186@@ -0,0 +1,45 @@
75187+#include <linux/kernel.h>
75188+#include <linux/sched.h>
75189+#include <linux/mm.h>
75190+#include <linux/file.h>
75191+#include <linux/grinternal.h>
75192+#include <linux/grsecurity.h>
75193+
75194+void
75195+gr_log_textrel(struct vm_area_struct * vma)
75196+{
75197+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75198+ if (grsec_enable_log_rwxmaps)
75199+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75200+#endif
75201+ return;
75202+}
75203+
75204+void gr_log_ptgnustack(struct file *file)
75205+{
75206+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75207+ if (grsec_enable_log_rwxmaps)
75208+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75209+#endif
75210+ return;
75211+}
75212+
75213+void
75214+gr_log_rwxmmap(struct file *file)
75215+{
75216+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75217+ if (grsec_enable_log_rwxmaps)
75218+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75219+#endif
75220+ return;
75221+}
75222+
75223+void
75224+gr_log_rwxmprotect(struct vm_area_struct *vma)
75225+{
75226+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75227+ if (grsec_enable_log_rwxmaps)
75228+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75229+#endif
75230+ return;
75231+}
75232diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75233new file mode 100644
75234index 0000000..2005a3a
75235--- /dev/null
75236+++ b/grsecurity/grsec_proc.c
75237@@ -0,0 +1,20 @@
75238+#include <linux/kernel.h>
75239+#include <linux/sched.h>
75240+#include <linux/grsecurity.h>
75241+#include <linux/grinternal.h>
75242+
75243+int gr_proc_is_restricted(void)
75244+{
75245+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75246+ const struct cred *cred = current_cred();
75247+#endif
75248+
75249+#ifdef CONFIG_GRKERNSEC_PROC_USER
75250+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75251+ return -EACCES;
75252+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75253+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75254+ return -EACCES;
75255+#endif
75256+ return 0;
75257+}
75258diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75259new file mode 100644
75260index 0000000..f7f29aa
75261--- /dev/null
75262+++ b/grsecurity/grsec_ptrace.c
75263@@ -0,0 +1,30 @@
75264+#include <linux/kernel.h>
75265+#include <linux/sched.h>
75266+#include <linux/grinternal.h>
75267+#include <linux/security.h>
75268+
75269+void
75270+gr_audit_ptrace(struct task_struct *task)
75271+{
75272+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75273+ if (grsec_enable_audit_ptrace)
75274+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75275+#endif
75276+ return;
75277+}
75278+
75279+int
75280+gr_ptrace_readexec(struct file *file, int unsafe_flags)
75281+{
75282+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75283+ const struct dentry *dentry = file->f_path.dentry;
75284+ const struct vfsmount *mnt = file->f_path.mnt;
75285+
75286+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75287+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75288+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75289+ return -EACCES;
75290+ }
75291+#endif
75292+ return 0;
75293+}
75294diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75295new file mode 100644
75296index 0000000..3860c7e
75297--- /dev/null
75298+++ b/grsecurity/grsec_sig.c
75299@@ -0,0 +1,236 @@
75300+#include <linux/kernel.h>
75301+#include <linux/sched.h>
75302+#include <linux/fs.h>
75303+#include <linux/delay.h>
75304+#include <linux/grsecurity.h>
75305+#include <linux/grinternal.h>
75306+#include <linux/hardirq.h>
75307+
75308+char *signames[] = {
75309+ [SIGSEGV] = "Segmentation fault",
75310+ [SIGILL] = "Illegal instruction",
75311+ [SIGABRT] = "Abort",
75312+ [SIGBUS] = "Invalid alignment/Bus error"
75313+};
75314+
75315+void
75316+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75317+{
75318+#ifdef CONFIG_GRKERNSEC_SIGNAL
75319+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75320+ (sig == SIGABRT) || (sig == SIGBUS))) {
75321+ if (task_pid_nr(t) == task_pid_nr(current)) {
75322+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75323+ } else {
75324+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75325+ }
75326+ }
75327+#endif
75328+ return;
75329+}
75330+
75331+int
75332+gr_handle_signal(const struct task_struct *p, const int sig)
75333+{
75334+#ifdef CONFIG_GRKERNSEC
75335+ /* ignore the 0 signal for protected task checks */
75336+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75337+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75338+ return -EPERM;
75339+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75340+ return -EPERM;
75341+ }
75342+#endif
75343+ return 0;
75344+}
75345+
75346+#ifdef CONFIG_GRKERNSEC
75347+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75348+
75349+int gr_fake_force_sig(int sig, struct task_struct *t)
75350+{
75351+ unsigned long int flags;
75352+ int ret, blocked, ignored;
75353+ struct k_sigaction *action;
75354+
75355+ spin_lock_irqsave(&t->sighand->siglock, flags);
75356+ action = &t->sighand->action[sig-1];
75357+ ignored = action->sa.sa_handler == SIG_IGN;
75358+ blocked = sigismember(&t->blocked, sig);
75359+ if (blocked || ignored) {
75360+ action->sa.sa_handler = SIG_DFL;
75361+ if (blocked) {
75362+ sigdelset(&t->blocked, sig);
75363+ recalc_sigpending_and_wake(t);
75364+ }
75365+ }
75366+ if (action->sa.sa_handler == SIG_DFL)
75367+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
75368+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75369+
75370+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
75371+
75372+ return ret;
75373+}
75374+#endif
75375+
75376+#define GR_USER_BAN_TIME (15 * 60)
75377+#define GR_DAEMON_BRUTE_TIME (30 * 60)
75378+
75379+void gr_handle_brute_attach(int dumpable)
75380+{
75381+#ifdef CONFIG_GRKERNSEC_BRUTE
75382+ struct task_struct *p = current;
75383+ kuid_t uid = GLOBAL_ROOT_UID;
75384+ int daemon = 0;
75385+
75386+ if (!grsec_enable_brute)
75387+ return;
75388+
75389+ rcu_read_lock();
75390+ read_lock(&tasklist_lock);
75391+ read_lock(&grsec_exec_file_lock);
75392+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75393+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75394+ p->real_parent->brute = 1;
75395+ daemon = 1;
75396+ } else {
75397+ const struct cred *cred = __task_cred(p), *cred2;
75398+ struct task_struct *tsk, *tsk2;
75399+
75400+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75401+ struct user_struct *user;
75402+
75403+ uid = cred->uid;
75404+
75405+ /* this is put upon execution past expiration */
75406+ user = find_user(uid);
75407+ if (user == NULL)
75408+ goto unlock;
75409+ user->suid_banned = 1;
75410+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75411+ if (user->suid_ban_expires == ~0UL)
75412+ user->suid_ban_expires--;
75413+
75414+ /* only kill other threads of the same binary, from the same user */
75415+ do_each_thread(tsk2, tsk) {
75416+ cred2 = __task_cred(tsk);
75417+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75418+ gr_fake_force_sig(SIGKILL, tsk);
75419+ } while_each_thread(tsk2, tsk);
75420+ }
75421+ }
75422+unlock:
75423+ read_unlock(&grsec_exec_file_lock);
75424+ read_unlock(&tasklist_lock);
75425+ rcu_read_unlock();
75426+
75427+ if (gr_is_global_nonroot(uid))
75428+ 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);
75429+ else if (daemon)
75430+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75431+
75432+#endif
75433+ return;
75434+}
75435+
75436+void gr_handle_brute_check(void)
75437+{
75438+#ifdef CONFIG_GRKERNSEC_BRUTE
75439+ struct task_struct *p = current;
75440+
75441+ if (unlikely(p->brute)) {
75442+ if (!grsec_enable_brute)
75443+ p->brute = 0;
75444+ else if (time_before(get_seconds(), p->brute_expires))
75445+ msleep(30 * 1000);
75446+ }
75447+#endif
75448+ return;
75449+}
75450+
75451+void gr_handle_kernel_exploit(void)
75452+{
75453+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75454+ const struct cred *cred;
75455+ struct task_struct *tsk, *tsk2;
75456+ struct user_struct *user;
75457+ kuid_t uid;
75458+
75459+ if (in_irq() || in_serving_softirq() || in_nmi())
75460+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75461+
75462+ uid = current_uid();
75463+
75464+ if (gr_is_global_root(uid))
75465+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
75466+ else {
75467+ /* kill all the processes of this user, hold a reference
75468+ to their creds struct, and prevent them from creating
75469+ another process until system reset
75470+ */
75471+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75472+ GR_GLOBAL_UID(uid));
75473+ /* we intentionally leak this ref */
75474+ user = get_uid(current->cred->user);
75475+ if (user)
75476+ user->kernel_banned = 1;
75477+
75478+ /* kill all processes of this user */
75479+ read_lock(&tasklist_lock);
75480+ do_each_thread(tsk2, tsk) {
75481+ cred = __task_cred(tsk);
75482+ if (uid_eq(cred->uid, uid))
75483+ gr_fake_force_sig(SIGKILL, tsk);
75484+ } while_each_thread(tsk2, tsk);
75485+ read_unlock(&tasklist_lock);
75486+ }
75487+#endif
75488+}
75489+
75490+#ifdef CONFIG_GRKERNSEC_BRUTE
75491+static bool suid_ban_expired(struct user_struct *user)
75492+{
75493+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75494+ user->suid_banned = 0;
75495+ user->suid_ban_expires = 0;
75496+ free_uid(user);
75497+ return true;
75498+ }
75499+
75500+ return false;
75501+}
75502+#endif
75503+
75504+int gr_process_kernel_exec_ban(void)
75505+{
75506+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75507+ if (unlikely(current->cred->user->kernel_banned))
75508+ return -EPERM;
75509+#endif
75510+ return 0;
75511+}
75512+
75513+int gr_process_kernel_setuid_ban(struct user_struct *user)
75514+{
75515+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75516+ if (unlikely(user->kernel_banned))
75517+ gr_fake_force_sig(SIGKILL, current);
75518+#endif
75519+ return 0;
75520+}
75521+
75522+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75523+{
75524+#ifdef CONFIG_GRKERNSEC_BRUTE
75525+ struct user_struct *user = current->cred->user;
75526+ if (unlikely(user->suid_banned)) {
75527+ if (suid_ban_expired(user))
75528+ return 0;
75529+ /* disallow execution of suid binaries only */
75530+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75531+ return -EPERM;
75532+ }
75533+#endif
75534+ return 0;
75535+}
75536diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75537new file mode 100644
75538index 0000000..c0aef3a
75539--- /dev/null
75540+++ b/grsecurity/grsec_sock.c
75541@@ -0,0 +1,244 @@
75542+#include <linux/kernel.h>
75543+#include <linux/module.h>
75544+#include <linux/sched.h>
75545+#include <linux/file.h>
75546+#include <linux/net.h>
75547+#include <linux/in.h>
75548+#include <linux/ip.h>
75549+#include <net/sock.h>
75550+#include <net/inet_sock.h>
75551+#include <linux/grsecurity.h>
75552+#include <linux/grinternal.h>
75553+#include <linux/gracl.h>
75554+
75555+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75556+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75557+
75558+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75559+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75560+
75561+#ifdef CONFIG_UNIX_MODULE
75562+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75563+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75564+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75565+EXPORT_SYMBOL_GPL(gr_handle_create);
75566+#endif
75567+
75568+#ifdef CONFIG_GRKERNSEC
75569+#define gr_conn_table_size 32749
75570+struct conn_table_entry {
75571+ struct conn_table_entry *next;
75572+ struct signal_struct *sig;
75573+};
75574+
75575+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75576+DEFINE_SPINLOCK(gr_conn_table_lock);
75577+
75578+extern const char * gr_socktype_to_name(unsigned char type);
75579+extern const char * gr_proto_to_name(unsigned char proto);
75580+extern const char * gr_sockfamily_to_name(unsigned char family);
75581+
75582+static __inline__ int
75583+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75584+{
75585+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75586+}
75587+
75588+static __inline__ int
75589+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75590+ __u16 sport, __u16 dport)
75591+{
75592+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75593+ sig->gr_sport == sport && sig->gr_dport == dport))
75594+ return 1;
75595+ else
75596+ return 0;
75597+}
75598+
75599+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75600+{
75601+ struct conn_table_entry **match;
75602+ unsigned int index;
75603+
75604+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75605+ sig->gr_sport, sig->gr_dport,
75606+ gr_conn_table_size);
75607+
75608+ newent->sig = sig;
75609+
75610+ match = &gr_conn_table[index];
75611+ newent->next = *match;
75612+ *match = newent;
75613+
75614+ return;
75615+}
75616+
75617+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75618+{
75619+ struct conn_table_entry *match, *last = NULL;
75620+ unsigned int index;
75621+
75622+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75623+ sig->gr_sport, sig->gr_dport,
75624+ gr_conn_table_size);
75625+
75626+ match = gr_conn_table[index];
75627+ while (match && !conn_match(match->sig,
75628+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75629+ sig->gr_dport)) {
75630+ last = match;
75631+ match = match->next;
75632+ }
75633+
75634+ if (match) {
75635+ if (last)
75636+ last->next = match->next;
75637+ else
75638+ gr_conn_table[index] = NULL;
75639+ kfree(match);
75640+ }
75641+
75642+ return;
75643+}
75644+
75645+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75646+ __u16 sport, __u16 dport)
75647+{
75648+ struct conn_table_entry *match;
75649+ unsigned int index;
75650+
75651+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75652+
75653+ match = gr_conn_table[index];
75654+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75655+ match = match->next;
75656+
75657+ if (match)
75658+ return match->sig;
75659+ else
75660+ return NULL;
75661+}
75662+
75663+#endif
75664+
75665+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75666+{
75667+#ifdef CONFIG_GRKERNSEC
75668+ struct signal_struct *sig = task->signal;
75669+ struct conn_table_entry *newent;
75670+
75671+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75672+ if (newent == NULL)
75673+ return;
75674+ /* no bh lock needed since we are called with bh disabled */
75675+ spin_lock(&gr_conn_table_lock);
75676+ gr_del_task_from_ip_table_nolock(sig);
75677+ sig->gr_saddr = inet->inet_rcv_saddr;
75678+ sig->gr_daddr = inet->inet_daddr;
75679+ sig->gr_sport = inet->inet_sport;
75680+ sig->gr_dport = inet->inet_dport;
75681+ gr_add_to_task_ip_table_nolock(sig, newent);
75682+ spin_unlock(&gr_conn_table_lock);
75683+#endif
75684+ return;
75685+}
75686+
75687+void gr_del_task_from_ip_table(struct task_struct *task)
75688+{
75689+#ifdef CONFIG_GRKERNSEC
75690+ spin_lock_bh(&gr_conn_table_lock);
75691+ gr_del_task_from_ip_table_nolock(task->signal);
75692+ spin_unlock_bh(&gr_conn_table_lock);
75693+#endif
75694+ return;
75695+}
75696+
75697+void
75698+gr_attach_curr_ip(const struct sock *sk)
75699+{
75700+#ifdef CONFIG_GRKERNSEC
75701+ struct signal_struct *p, *set;
75702+ const struct inet_sock *inet = inet_sk(sk);
75703+
75704+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75705+ return;
75706+
75707+ set = current->signal;
75708+
75709+ spin_lock_bh(&gr_conn_table_lock);
75710+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75711+ inet->inet_dport, inet->inet_sport);
75712+ if (unlikely(p != NULL)) {
75713+ set->curr_ip = p->curr_ip;
75714+ set->used_accept = 1;
75715+ gr_del_task_from_ip_table_nolock(p);
75716+ spin_unlock_bh(&gr_conn_table_lock);
75717+ return;
75718+ }
75719+ spin_unlock_bh(&gr_conn_table_lock);
75720+
75721+ set->curr_ip = inet->inet_daddr;
75722+ set->used_accept = 1;
75723+#endif
75724+ return;
75725+}
75726+
75727+int
75728+gr_handle_sock_all(const int family, const int type, const int protocol)
75729+{
75730+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75731+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75732+ (family != AF_UNIX)) {
75733+ if (family == AF_INET)
75734+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75735+ else
75736+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75737+ return -EACCES;
75738+ }
75739+#endif
75740+ return 0;
75741+}
75742+
75743+int
75744+gr_handle_sock_server(const struct sockaddr *sck)
75745+{
75746+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75747+ if (grsec_enable_socket_server &&
75748+ in_group_p(grsec_socket_server_gid) &&
75749+ sck && (sck->sa_family != AF_UNIX) &&
75750+ (sck->sa_family != AF_LOCAL)) {
75751+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75752+ return -EACCES;
75753+ }
75754+#endif
75755+ return 0;
75756+}
75757+
75758+int
75759+gr_handle_sock_server_other(const struct sock *sck)
75760+{
75761+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75762+ if (grsec_enable_socket_server &&
75763+ in_group_p(grsec_socket_server_gid) &&
75764+ sck && (sck->sk_family != AF_UNIX) &&
75765+ (sck->sk_family != AF_LOCAL)) {
75766+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75767+ return -EACCES;
75768+ }
75769+#endif
75770+ return 0;
75771+}
75772+
75773+int
75774+gr_handle_sock_client(const struct sockaddr *sck)
75775+{
75776+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75777+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75778+ sck && (sck->sa_family != AF_UNIX) &&
75779+ (sck->sa_family != AF_LOCAL)) {
75780+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75781+ return -EACCES;
75782+ }
75783+#endif
75784+ return 0;
75785+}
75786diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75787new file mode 100644
75788index 0000000..8159888
75789--- /dev/null
75790+++ b/grsecurity/grsec_sysctl.c
75791@@ -0,0 +1,479 @@
75792+#include <linux/kernel.h>
75793+#include <linux/sched.h>
75794+#include <linux/sysctl.h>
75795+#include <linux/grsecurity.h>
75796+#include <linux/grinternal.h>
75797+
75798+int
75799+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75800+{
75801+#ifdef CONFIG_GRKERNSEC_SYSCTL
75802+ if (dirname == NULL || name == NULL)
75803+ return 0;
75804+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75805+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75806+ return -EACCES;
75807+ }
75808+#endif
75809+ return 0;
75810+}
75811+
75812+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75813+static int __maybe_unused __read_only one = 1;
75814+#endif
75815+
75816+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75817+ defined(CONFIG_GRKERNSEC_DENYUSB)
75818+struct ctl_table grsecurity_table[] = {
75819+#ifdef CONFIG_GRKERNSEC_SYSCTL
75820+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75821+#ifdef CONFIG_GRKERNSEC_IO
75822+ {
75823+ .procname = "disable_priv_io",
75824+ .data = &grsec_disable_privio,
75825+ .maxlen = sizeof(int),
75826+ .mode = 0600,
75827+ .proc_handler = &proc_dointvec,
75828+ },
75829+#endif
75830+#endif
75831+#ifdef CONFIG_GRKERNSEC_LINK
75832+ {
75833+ .procname = "linking_restrictions",
75834+ .data = &grsec_enable_link,
75835+ .maxlen = sizeof(int),
75836+ .mode = 0600,
75837+ .proc_handler = &proc_dointvec,
75838+ },
75839+#endif
75840+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75841+ {
75842+ .procname = "enforce_symlinksifowner",
75843+ .data = &grsec_enable_symlinkown,
75844+ .maxlen = sizeof(int),
75845+ .mode = 0600,
75846+ .proc_handler = &proc_dointvec,
75847+ },
75848+ {
75849+ .procname = "symlinkown_gid",
75850+ .data = &grsec_symlinkown_gid,
75851+ .maxlen = sizeof(int),
75852+ .mode = 0600,
75853+ .proc_handler = &proc_dointvec,
75854+ },
75855+#endif
75856+#ifdef CONFIG_GRKERNSEC_BRUTE
75857+ {
75858+ .procname = "deter_bruteforce",
75859+ .data = &grsec_enable_brute,
75860+ .maxlen = sizeof(int),
75861+ .mode = 0600,
75862+ .proc_handler = &proc_dointvec,
75863+ },
75864+#endif
75865+#ifdef CONFIG_GRKERNSEC_FIFO
75866+ {
75867+ .procname = "fifo_restrictions",
75868+ .data = &grsec_enable_fifo,
75869+ .maxlen = sizeof(int),
75870+ .mode = 0600,
75871+ .proc_handler = &proc_dointvec,
75872+ },
75873+#endif
75874+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75875+ {
75876+ .procname = "ptrace_readexec",
75877+ .data = &grsec_enable_ptrace_readexec,
75878+ .maxlen = sizeof(int),
75879+ .mode = 0600,
75880+ .proc_handler = &proc_dointvec,
75881+ },
75882+#endif
75883+#ifdef CONFIG_GRKERNSEC_SETXID
75884+ {
75885+ .procname = "consistent_setxid",
75886+ .data = &grsec_enable_setxid,
75887+ .maxlen = sizeof(int),
75888+ .mode = 0600,
75889+ .proc_handler = &proc_dointvec,
75890+ },
75891+#endif
75892+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75893+ {
75894+ .procname = "ip_blackhole",
75895+ .data = &grsec_enable_blackhole,
75896+ .maxlen = sizeof(int),
75897+ .mode = 0600,
75898+ .proc_handler = &proc_dointvec,
75899+ },
75900+ {
75901+ .procname = "lastack_retries",
75902+ .data = &grsec_lastack_retries,
75903+ .maxlen = sizeof(int),
75904+ .mode = 0600,
75905+ .proc_handler = &proc_dointvec,
75906+ },
75907+#endif
75908+#ifdef CONFIG_GRKERNSEC_EXECLOG
75909+ {
75910+ .procname = "exec_logging",
75911+ .data = &grsec_enable_execlog,
75912+ .maxlen = sizeof(int),
75913+ .mode = 0600,
75914+ .proc_handler = &proc_dointvec,
75915+ },
75916+#endif
75917+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75918+ {
75919+ .procname = "rwxmap_logging",
75920+ .data = &grsec_enable_log_rwxmaps,
75921+ .maxlen = sizeof(int),
75922+ .mode = 0600,
75923+ .proc_handler = &proc_dointvec,
75924+ },
75925+#endif
75926+#ifdef CONFIG_GRKERNSEC_SIGNAL
75927+ {
75928+ .procname = "signal_logging",
75929+ .data = &grsec_enable_signal,
75930+ .maxlen = sizeof(int),
75931+ .mode = 0600,
75932+ .proc_handler = &proc_dointvec,
75933+ },
75934+#endif
75935+#ifdef CONFIG_GRKERNSEC_FORKFAIL
75936+ {
75937+ .procname = "forkfail_logging",
75938+ .data = &grsec_enable_forkfail,
75939+ .maxlen = sizeof(int),
75940+ .mode = 0600,
75941+ .proc_handler = &proc_dointvec,
75942+ },
75943+#endif
75944+#ifdef CONFIG_GRKERNSEC_TIME
75945+ {
75946+ .procname = "timechange_logging",
75947+ .data = &grsec_enable_time,
75948+ .maxlen = sizeof(int),
75949+ .mode = 0600,
75950+ .proc_handler = &proc_dointvec,
75951+ },
75952+#endif
75953+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75954+ {
75955+ .procname = "chroot_deny_shmat",
75956+ .data = &grsec_enable_chroot_shmat,
75957+ .maxlen = sizeof(int),
75958+ .mode = 0600,
75959+ .proc_handler = &proc_dointvec,
75960+ },
75961+#endif
75962+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75963+ {
75964+ .procname = "chroot_deny_unix",
75965+ .data = &grsec_enable_chroot_unix,
75966+ .maxlen = sizeof(int),
75967+ .mode = 0600,
75968+ .proc_handler = &proc_dointvec,
75969+ },
75970+#endif
75971+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75972+ {
75973+ .procname = "chroot_deny_mount",
75974+ .data = &grsec_enable_chroot_mount,
75975+ .maxlen = sizeof(int),
75976+ .mode = 0600,
75977+ .proc_handler = &proc_dointvec,
75978+ },
75979+#endif
75980+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75981+ {
75982+ .procname = "chroot_deny_fchdir",
75983+ .data = &grsec_enable_chroot_fchdir,
75984+ .maxlen = sizeof(int),
75985+ .mode = 0600,
75986+ .proc_handler = &proc_dointvec,
75987+ },
75988+#endif
75989+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75990+ {
75991+ .procname = "chroot_deny_chroot",
75992+ .data = &grsec_enable_chroot_double,
75993+ .maxlen = sizeof(int),
75994+ .mode = 0600,
75995+ .proc_handler = &proc_dointvec,
75996+ },
75997+#endif
75998+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75999+ {
76000+ .procname = "chroot_deny_pivot",
76001+ .data = &grsec_enable_chroot_pivot,
76002+ .maxlen = sizeof(int),
76003+ .mode = 0600,
76004+ .proc_handler = &proc_dointvec,
76005+ },
76006+#endif
76007+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76008+ {
76009+ .procname = "chroot_enforce_chdir",
76010+ .data = &grsec_enable_chroot_chdir,
76011+ .maxlen = sizeof(int),
76012+ .mode = 0600,
76013+ .proc_handler = &proc_dointvec,
76014+ },
76015+#endif
76016+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76017+ {
76018+ .procname = "chroot_deny_chmod",
76019+ .data = &grsec_enable_chroot_chmod,
76020+ .maxlen = sizeof(int),
76021+ .mode = 0600,
76022+ .proc_handler = &proc_dointvec,
76023+ },
76024+#endif
76025+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76026+ {
76027+ .procname = "chroot_deny_mknod",
76028+ .data = &grsec_enable_chroot_mknod,
76029+ .maxlen = sizeof(int),
76030+ .mode = 0600,
76031+ .proc_handler = &proc_dointvec,
76032+ },
76033+#endif
76034+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76035+ {
76036+ .procname = "chroot_restrict_nice",
76037+ .data = &grsec_enable_chroot_nice,
76038+ .maxlen = sizeof(int),
76039+ .mode = 0600,
76040+ .proc_handler = &proc_dointvec,
76041+ },
76042+#endif
76043+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76044+ {
76045+ .procname = "chroot_execlog",
76046+ .data = &grsec_enable_chroot_execlog,
76047+ .maxlen = sizeof(int),
76048+ .mode = 0600,
76049+ .proc_handler = &proc_dointvec,
76050+ },
76051+#endif
76052+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76053+ {
76054+ .procname = "chroot_caps",
76055+ .data = &grsec_enable_chroot_caps,
76056+ .maxlen = sizeof(int),
76057+ .mode = 0600,
76058+ .proc_handler = &proc_dointvec,
76059+ },
76060+#endif
76061+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76062+ {
76063+ .procname = "chroot_deny_sysctl",
76064+ .data = &grsec_enable_chroot_sysctl,
76065+ .maxlen = sizeof(int),
76066+ .mode = 0600,
76067+ .proc_handler = &proc_dointvec,
76068+ },
76069+#endif
76070+#ifdef CONFIG_GRKERNSEC_TPE
76071+ {
76072+ .procname = "tpe",
76073+ .data = &grsec_enable_tpe,
76074+ .maxlen = sizeof(int),
76075+ .mode = 0600,
76076+ .proc_handler = &proc_dointvec,
76077+ },
76078+ {
76079+ .procname = "tpe_gid",
76080+ .data = &grsec_tpe_gid,
76081+ .maxlen = sizeof(int),
76082+ .mode = 0600,
76083+ .proc_handler = &proc_dointvec,
76084+ },
76085+#endif
76086+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76087+ {
76088+ .procname = "tpe_invert",
76089+ .data = &grsec_enable_tpe_invert,
76090+ .maxlen = sizeof(int),
76091+ .mode = 0600,
76092+ .proc_handler = &proc_dointvec,
76093+ },
76094+#endif
76095+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76096+ {
76097+ .procname = "tpe_restrict_all",
76098+ .data = &grsec_enable_tpe_all,
76099+ .maxlen = sizeof(int),
76100+ .mode = 0600,
76101+ .proc_handler = &proc_dointvec,
76102+ },
76103+#endif
76104+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76105+ {
76106+ .procname = "socket_all",
76107+ .data = &grsec_enable_socket_all,
76108+ .maxlen = sizeof(int),
76109+ .mode = 0600,
76110+ .proc_handler = &proc_dointvec,
76111+ },
76112+ {
76113+ .procname = "socket_all_gid",
76114+ .data = &grsec_socket_all_gid,
76115+ .maxlen = sizeof(int),
76116+ .mode = 0600,
76117+ .proc_handler = &proc_dointvec,
76118+ },
76119+#endif
76120+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76121+ {
76122+ .procname = "socket_client",
76123+ .data = &grsec_enable_socket_client,
76124+ .maxlen = sizeof(int),
76125+ .mode = 0600,
76126+ .proc_handler = &proc_dointvec,
76127+ },
76128+ {
76129+ .procname = "socket_client_gid",
76130+ .data = &grsec_socket_client_gid,
76131+ .maxlen = sizeof(int),
76132+ .mode = 0600,
76133+ .proc_handler = &proc_dointvec,
76134+ },
76135+#endif
76136+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76137+ {
76138+ .procname = "socket_server",
76139+ .data = &grsec_enable_socket_server,
76140+ .maxlen = sizeof(int),
76141+ .mode = 0600,
76142+ .proc_handler = &proc_dointvec,
76143+ },
76144+ {
76145+ .procname = "socket_server_gid",
76146+ .data = &grsec_socket_server_gid,
76147+ .maxlen = sizeof(int),
76148+ .mode = 0600,
76149+ .proc_handler = &proc_dointvec,
76150+ },
76151+#endif
76152+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76153+ {
76154+ .procname = "audit_group",
76155+ .data = &grsec_enable_group,
76156+ .maxlen = sizeof(int),
76157+ .mode = 0600,
76158+ .proc_handler = &proc_dointvec,
76159+ },
76160+ {
76161+ .procname = "audit_gid",
76162+ .data = &grsec_audit_gid,
76163+ .maxlen = sizeof(int),
76164+ .mode = 0600,
76165+ .proc_handler = &proc_dointvec,
76166+ },
76167+#endif
76168+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76169+ {
76170+ .procname = "audit_chdir",
76171+ .data = &grsec_enable_chdir,
76172+ .maxlen = sizeof(int),
76173+ .mode = 0600,
76174+ .proc_handler = &proc_dointvec,
76175+ },
76176+#endif
76177+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76178+ {
76179+ .procname = "audit_mount",
76180+ .data = &grsec_enable_mount,
76181+ .maxlen = sizeof(int),
76182+ .mode = 0600,
76183+ .proc_handler = &proc_dointvec,
76184+ },
76185+#endif
76186+#ifdef CONFIG_GRKERNSEC_DMESG
76187+ {
76188+ .procname = "dmesg",
76189+ .data = &grsec_enable_dmesg,
76190+ .maxlen = sizeof(int),
76191+ .mode = 0600,
76192+ .proc_handler = &proc_dointvec,
76193+ },
76194+#endif
76195+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76196+ {
76197+ .procname = "chroot_findtask",
76198+ .data = &grsec_enable_chroot_findtask,
76199+ .maxlen = sizeof(int),
76200+ .mode = 0600,
76201+ .proc_handler = &proc_dointvec,
76202+ },
76203+#endif
76204+#ifdef CONFIG_GRKERNSEC_RESLOG
76205+ {
76206+ .procname = "resource_logging",
76207+ .data = &grsec_resource_logging,
76208+ .maxlen = sizeof(int),
76209+ .mode = 0600,
76210+ .proc_handler = &proc_dointvec,
76211+ },
76212+#endif
76213+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76214+ {
76215+ .procname = "audit_ptrace",
76216+ .data = &grsec_enable_audit_ptrace,
76217+ .maxlen = sizeof(int),
76218+ .mode = 0600,
76219+ .proc_handler = &proc_dointvec,
76220+ },
76221+#endif
76222+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76223+ {
76224+ .procname = "harden_ptrace",
76225+ .data = &grsec_enable_harden_ptrace,
76226+ .maxlen = sizeof(int),
76227+ .mode = 0600,
76228+ .proc_handler = &proc_dointvec,
76229+ },
76230+#endif
76231+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76232+ {
76233+ .procname = "harden_ipc",
76234+ .data = &grsec_enable_harden_ipc,
76235+ .maxlen = sizeof(int),
76236+ .mode = 0600,
76237+ .proc_handler = &proc_dointvec,
76238+ },
76239+#endif
76240+ {
76241+ .procname = "grsec_lock",
76242+ .data = &grsec_lock,
76243+ .maxlen = sizeof(int),
76244+ .mode = 0600,
76245+ .proc_handler = &proc_dointvec,
76246+ },
76247+#endif
76248+#ifdef CONFIG_GRKERNSEC_ROFS
76249+ {
76250+ .procname = "romount_protect",
76251+ .data = &grsec_enable_rofs,
76252+ .maxlen = sizeof(int),
76253+ .mode = 0600,
76254+ .proc_handler = &proc_dointvec_minmax,
76255+ .extra1 = &one,
76256+ .extra2 = &one,
76257+ },
76258+#endif
76259+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76260+ {
76261+ .procname = "deny_new_usb",
76262+ .data = &grsec_deny_new_usb,
76263+ .maxlen = sizeof(int),
76264+ .mode = 0600,
76265+ .proc_handler = &proc_dointvec,
76266+ },
76267+#endif
76268+ { }
76269+};
76270+#endif
76271diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76272new file mode 100644
76273index 0000000..61b514e
76274--- /dev/null
76275+++ b/grsecurity/grsec_time.c
76276@@ -0,0 +1,16 @@
76277+#include <linux/kernel.h>
76278+#include <linux/sched.h>
76279+#include <linux/grinternal.h>
76280+#include <linux/module.h>
76281+
76282+void
76283+gr_log_timechange(void)
76284+{
76285+#ifdef CONFIG_GRKERNSEC_TIME
76286+ if (grsec_enable_time)
76287+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76288+#endif
76289+ return;
76290+}
76291+
76292+EXPORT_SYMBOL_GPL(gr_log_timechange);
76293diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76294new file mode 100644
76295index 0000000..d1953de
76296--- /dev/null
76297+++ b/grsecurity/grsec_tpe.c
76298@@ -0,0 +1,78 @@
76299+#include <linux/kernel.h>
76300+#include <linux/sched.h>
76301+#include <linux/file.h>
76302+#include <linux/fs.h>
76303+#include <linux/grinternal.h>
76304+
76305+extern int gr_acl_tpe_check(void);
76306+
76307+int
76308+gr_tpe_allow(const struct file *file)
76309+{
76310+#ifdef CONFIG_GRKERNSEC
76311+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76312+ struct inode *file_inode = file->f_path.dentry->d_inode;
76313+ const struct cred *cred = current_cred();
76314+ char *msg = NULL;
76315+ char *msg2 = NULL;
76316+
76317+ // never restrict root
76318+ if (gr_is_global_root(cred->uid))
76319+ return 1;
76320+
76321+ if (grsec_enable_tpe) {
76322+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76323+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76324+ msg = "not being in trusted group";
76325+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76326+ msg = "being in untrusted group";
76327+#else
76328+ if (in_group_p(grsec_tpe_gid))
76329+ msg = "being in untrusted group";
76330+#endif
76331+ }
76332+ if (!msg && gr_acl_tpe_check())
76333+ msg = "being in untrusted role";
76334+
76335+ // not in any affected group/role
76336+ if (!msg)
76337+ goto next_check;
76338+
76339+ if (gr_is_global_nonroot(inode->i_uid))
76340+ msg2 = "file in non-root-owned directory";
76341+ else if (inode->i_mode & S_IWOTH)
76342+ msg2 = "file in world-writable directory";
76343+ else if (inode->i_mode & S_IWGRP)
76344+ msg2 = "file in group-writable directory";
76345+ else if (file_inode->i_mode & S_IWOTH)
76346+ msg2 = "file is world-writable";
76347+
76348+ if (msg && msg2) {
76349+ char fullmsg[70] = {0};
76350+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76351+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76352+ return 0;
76353+ }
76354+ msg = NULL;
76355+next_check:
76356+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76357+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76358+ return 1;
76359+
76360+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76361+ msg = "directory not owned by user";
76362+ else if (inode->i_mode & S_IWOTH)
76363+ msg = "file in world-writable directory";
76364+ else if (inode->i_mode & S_IWGRP)
76365+ msg = "file in group-writable directory";
76366+ else if (file_inode->i_mode & S_IWOTH)
76367+ msg = "file is world-writable";
76368+
76369+ if (msg) {
76370+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76371+ return 0;
76372+ }
76373+#endif
76374+#endif
76375+ return 1;
76376+}
76377diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76378new file mode 100644
76379index 0000000..ae02d8e
76380--- /dev/null
76381+++ b/grsecurity/grsec_usb.c
76382@@ -0,0 +1,15 @@
76383+#include <linux/kernel.h>
76384+#include <linux/grinternal.h>
76385+#include <linux/module.h>
76386+
76387+int gr_handle_new_usb(void)
76388+{
76389+#ifdef CONFIG_GRKERNSEC_DENYUSB
76390+ if (grsec_deny_new_usb) {
76391+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76392+ return 1;
76393+ }
76394+#endif
76395+ return 0;
76396+}
76397+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76398diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76399new file mode 100644
76400index 0000000..9f7b1ac
76401--- /dev/null
76402+++ b/grsecurity/grsum.c
76403@@ -0,0 +1,61 @@
76404+#include <linux/err.h>
76405+#include <linux/kernel.h>
76406+#include <linux/sched.h>
76407+#include <linux/mm.h>
76408+#include <linux/scatterlist.h>
76409+#include <linux/crypto.h>
76410+#include <linux/gracl.h>
76411+
76412+
76413+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76414+#error "crypto and sha256 must be built into the kernel"
76415+#endif
76416+
76417+int
76418+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76419+{
76420+ char *p;
76421+ struct crypto_hash *tfm;
76422+ struct hash_desc desc;
76423+ struct scatterlist sg;
76424+ unsigned char temp_sum[GR_SHA_LEN];
76425+ volatile int retval = 0;
76426+ volatile int dummy = 0;
76427+ unsigned int i;
76428+
76429+ sg_init_table(&sg, 1);
76430+
76431+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76432+ if (IS_ERR(tfm)) {
76433+ /* should never happen, since sha256 should be built in */
76434+ return 1;
76435+ }
76436+
76437+ desc.tfm = tfm;
76438+ desc.flags = 0;
76439+
76440+ crypto_hash_init(&desc);
76441+
76442+ p = salt;
76443+ sg_set_buf(&sg, p, GR_SALT_LEN);
76444+ crypto_hash_update(&desc, &sg, sg.length);
76445+
76446+ p = entry->pw;
76447+ sg_set_buf(&sg, p, strlen(p));
76448+
76449+ crypto_hash_update(&desc, &sg, sg.length);
76450+
76451+ crypto_hash_final(&desc, temp_sum);
76452+
76453+ memset(entry->pw, 0, GR_PW_LEN);
76454+
76455+ for (i = 0; i < GR_SHA_LEN; i++)
76456+ if (sum[i] != temp_sum[i])
76457+ retval = 1;
76458+ else
76459+ dummy = 1; // waste a cycle
76460+
76461+ crypto_free_hash(tfm);
76462+
76463+ return retval;
76464+}
76465diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76466index 77ff547..181834f 100644
76467--- a/include/asm-generic/4level-fixup.h
76468+++ b/include/asm-generic/4level-fixup.h
76469@@ -13,8 +13,10 @@
76470 #define pmd_alloc(mm, pud, address) \
76471 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76472 NULL: pmd_offset(pud, address))
76473+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76474
76475 #define pud_alloc(mm, pgd, address) (pgd)
76476+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76477 #define pud_offset(pgd, start) (pgd)
76478 #define pud_none(pud) 0
76479 #define pud_bad(pud) 0
76480diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76481index b7babf0..97f4c4f 100644
76482--- a/include/asm-generic/atomic-long.h
76483+++ b/include/asm-generic/atomic-long.h
76484@@ -22,6 +22,12 @@
76485
76486 typedef atomic64_t atomic_long_t;
76487
76488+#ifdef CONFIG_PAX_REFCOUNT
76489+typedef atomic64_unchecked_t atomic_long_unchecked_t;
76490+#else
76491+typedef atomic64_t atomic_long_unchecked_t;
76492+#endif
76493+
76494 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76495
76496 static inline long atomic_long_read(atomic_long_t *l)
76497@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76498 return (long)atomic64_read(v);
76499 }
76500
76501+#ifdef CONFIG_PAX_REFCOUNT
76502+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76503+{
76504+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76505+
76506+ return (long)atomic64_read_unchecked(v);
76507+}
76508+#endif
76509+
76510 static inline void atomic_long_set(atomic_long_t *l, long i)
76511 {
76512 atomic64_t *v = (atomic64_t *)l;
76513@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76514 atomic64_set(v, i);
76515 }
76516
76517+#ifdef CONFIG_PAX_REFCOUNT
76518+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76519+{
76520+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76521+
76522+ atomic64_set_unchecked(v, i);
76523+}
76524+#endif
76525+
76526 static inline void atomic_long_inc(atomic_long_t *l)
76527 {
76528 atomic64_t *v = (atomic64_t *)l;
76529@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76530 atomic64_inc(v);
76531 }
76532
76533+#ifdef CONFIG_PAX_REFCOUNT
76534+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76535+{
76536+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76537+
76538+ atomic64_inc_unchecked(v);
76539+}
76540+#endif
76541+
76542 static inline void atomic_long_dec(atomic_long_t *l)
76543 {
76544 atomic64_t *v = (atomic64_t *)l;
76545@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76546 atomic64_dec(v);
76547 }
76548
76549+#ifdef CONFIG_PAX_REFCOUNT
76550+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76551+{
76552+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76553+
76554+ atomic64_dec_unchecked(v);
76555+}
76556+#endif
76557+
76558 static inline void atomic_long_add(long i, atomic_long_t *l)
76559 {
76560 atomic64_t *v = (atomic64_t *)l;
76561@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76562 atomic64_add(i, v);
76563 }
76564
76565+#ifdef CONFIG_PAX_REFCOUNT
76566+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76567+{
76568+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76569+
76570+ atomic64_add_unchecked(i, v);
76571+}
76572+#endif
76573+
76574 static inline void atomic_long_sub(long i, atomic_long_t *l)
76575 {
76576 atomic64_t *v = (atomic64_t *)l;
76577@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76578 atomic64_sub(i, v);
76579 }
76580
76581+#ifdef CONFIG_PAX_REFCOUNT
76582+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76583+{
76584+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76585+
76586+ atomic64_sub_unchecked(i, v);
76587+}
76588+#endif
76589+
76590 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76591 {
76592 atomic64_t *v = (atomic64_t *)l;
76593@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76594 return atomic64_add_negative(i, v);
76595 }
76596
76597-static inline long atomic_long_add_return(long i, atomic_long_t *l)
76598+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76599 {
76600 atomic64_t *v = (atomic64_t *)l;
76601
76602 return (long)atomic64_add_return(i, v);
76603 }
76604
76605+#ifdef CONFIG_PAX_REFCOUNT
76606+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76607+{
76608+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76609+
76610+ return (long)atomic64_add_return_unchecked(i, v);
76611+}
76612+#endif
76613+
76614 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76615 {
76616 atomic64_t *v = (atomic64_t *)l;
76617@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76618 return (long)atomic64_inc_return(v);
76619 }
76620
76621+#ifdef CONFIG_PAX_REFCOUNT
76622+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76623+{
76624+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76625+
76626+ return (long)atomic64_inc_return_unchecked(v);
76627+}
76628+#endif
76629+
76630 static inline long atomic_long_dec_return(atomic_long_t *l)
76631 {
76632 atomic64_t *v = (atomic64_t *)l;
76633@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76634
76635 typedef atomic_t atomic_long_t;
76636
76637+#ifdef CONFIG_PAX_REFCOUNT
76638+typedef atomic_unchecked_t atomic_long_unchecked_t;
76639+#else
76640+typedef atomic_t atomic_long_unchecked_t;
76641+#endif
76642+
76643 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76644 static inline long atomic_long_read(atomic_long_t *l)
76645 {
76646@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76647 return (long)atomic_read(v);
76648 }
76649
76650+#ifdef CONFIG_PAX_REFCOUNT
76651+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76652+{
76653+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76654+
76655+ return (long)atomic_read_unchecked(v);
76656+}
76657+#endif
76658+
76659 static inline void atomic_long_set(atomic_long_t *l, long i)
76660 {
76661 atomic_t *v = (atomic_t *)l;
76662@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76663 atomic_set(v, i);
76664 }
76665
76666+#ifdef CONFIG_PAX_REFCOUNT
76667+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76668+{
76669+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76670+
76671+ atomic_set_unchecked(v, i);
76672+}
76673+#endif
76674+
76675 static inline void atomic_long_inc(atomic_long_t *l)
76676 {
76677 atomic_t *v = (atomic_t *)l;
76678@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76679 atomic_inc(v);
76680 }
76681
76682+#ifdef CONFIG_PAX_REFCOUNT
76683+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76684+{
76685+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76686+
76687+ atomic_inc_unchecked(v);
76688+}
76689+#endif
76690+
76691 static inline void atomic_long_dec(atomic_long_t *l)
76692 {
76693 atomic_t *v = (atomic_t *)l;
76694@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76695 atomic_dec(v);
76696 }
76697
76698+#ifdef CONFIG_PAX_REFCOUNT
76699+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76700+{
76701+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76702+
76703+ atomic_dec_unchecked(v);
76704+}
76705+#endif
76706+
76707 static inline void atomic_long_add(long i, atomic_long_t *l)
76708 {
76709 atomic_t *v = (atomic_t *)l;
76710@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76711 atomic_add(i, v);
76712 }
76713
76714+#ifdef CONFIG_PAX_REFCOUNT
76715+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76716+{
76717+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76718+
76719+ atomic_add_unchecked(i, v);
76720+}
76721+#endif
76722+
76723 static inline void atomic_long_sub(long i, atomic_long_t *l)
76724 {
76725 atomic_t *v = (atomic_t *)l;
76726@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76727 atomic_sub(i, v);
76728 }
76729
76730+#ifdef CONFIG_PAX_REFCOUNT
76731+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76732+{
76733+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76734+
76735+ atomic_sub_unchecked(i, v);
76736+}
76737+#endif
76738+
76739 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76740 {
76741 atomic_t *v = (atomic_t *)l;
76742@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76743 return (long)atomic_add_return(i, v);
76744 }
76745
76746+#ifdef CONFIG_PAX_REFCOUNT
76747+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76748+{
76749+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76750+
76751+ return (long)atomic_add_return_unchecked(i, v);
76752+}
76753+
76754+#endif
76755+
76756 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76757 {
76758 atomic_t *v = (atomic_t *)l;
76759@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76760 return (long)atomic_inc_return(v);
76761 }
76762
76763+#ifdef CONFIG_PAX_REFCOUNT
76764+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76765+{
76766+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76767+
76768+ return (long)atomic_inc_return_unchecked(v);
76769+}
76770+#endif
76771+
76772 static inline long atomic_long_dec_return(atomic_long_t *l)
76773 {
76774 atomic_t *v = (atomic_t *)l;
76775@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76776
76777 #endif /* BITS_PER_LONG == 64 */
76778
76779+#ifdef CONFIG_PAX_REFCOUNT
76780+static inline void pax_refcount_needs_these_functions(void)
76781+{
76782+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
76783+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76784+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76785+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76786+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76787+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76788+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76789+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76790+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76791+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76792+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76793+#ifdef CONFIG_X86
76794+ atomic_clear_mask_unchecked(0, NULL);
76795+ atomic_set_mask_unchecked(0, NULL);
76796+#endif
76797+
76798+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76799+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76800+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76801+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76802+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76803+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76804+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76805+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76806+}
76807+#else
76808+#define atomic_read_unchecked(v) atomic_read(v)
76809+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76810+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76811+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76812+#define atomic_inc_unchecked(v) atomic_inc(v)
76813+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76814+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76815+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76816+#define atomic_dec_unchecked(v) atomic_dec(v)
76817+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76818+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76819+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76820+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76821+
76822+#define atomic_long_read_unchecked(v) atomic_long_read(v)
76823+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76824+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76825+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76826+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76827+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76828+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76829+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76830+#endif
76831+
76832 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76833diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76834index 33bd2de..f31bff97 100644
76835--- a/include/asm-generic/atomic.h
76836+++ b/include/asm-generic/atomic.h
76837@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76838 * Atomically clears the bits set in @mask from @v
76839 */
76840 #ifndef atomic_clear_mask
76841-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76842+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76843 {
76844 unsigned long flags;
76845
76846diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76847index b18ce4f..2ee2843 100644
76848--- a/include/asm-generic/atomic64.h
76849+++ b/include/asm-generic/atomic64.h
76850@@ -16,6 +16,8 @@ typedef struct {
76851 long long counter;
76852 } atomic64_t;
76853
76854+typedef atomic64_t atomic64_unchecked_t;
76855+
76856 #define ATOMIC64_INIT(i) { (i) }
76857
76858 extern long long atomic64_read(const atomic64_t *v);
76859@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76860 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76861 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76862
76863+#define atomic64_read_unchecked(v) atomic64_read(v)
76864+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76865+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76866+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76867+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76868+#define atomic64_inc_unchecked(v) atomic64_inc(v)
76869+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76870+#define atomic64_dec_unchecked(v) atomic64_dec(v)
76871+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76872+
76873 #endif /* _ASM_GENERIC_ATOMIC64_H */
76874diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
76875index 6f692f8..2ad9dd2 100644
76876--- a/include/asm-generic/barrier.h
76877+++ b/include/asm-generic/barrier.h
76878@@ -66,7 +66,7 @@
76879 do { \
76880 compiletime_assert_atomic_type(*p); \
76881 smp_mb(); \
76882- ACCESS_ONCE(*p) = (v); \
76883+ ACCESS_ONCE_RW(*p) = (v); \
76884 } while (0)
76885
76886 #define smp_load_acquire(p) \
76887diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
76888index a60a7cc..0fe12f2 100644
76889--- a/include/asm-generic/bitops/__fls.h
76890+++ b/include/asm-generic/bitops/__fls.h
76891@@ -9,7 +9,7 @@
76892 *
76893 * Undefined if no set bit exists, so code should check against 0 first.
76894 */
76895-static __always_inline unsigned long __fls(unsigned long word)
76896+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
76897 {
76898 int num = BITS_PER_LONG - 1;
76899
76900diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
76901index 0576d1f..dad6c71 100644
76902--- a/include/asm-generic/bitops/fls.h
76903+++ b/include/asm-generic/bitops/fls.h
76904@@ -9,7 +9,7 @@
76905 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
76906 */
76907
76908-static __always_inline int fls(int x)
76909+static __always_inline int __intentional_overflow(-1) fls(int x)
76910 {
76911 int r = 32;
76912
76913diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
76914index b097cf8..3d40e14 100644
76915--- a/include/asm-generic/bitops/fls64.h
76916+++ b/include/asm-generic/bitops/fls64.h
76917@@ -15,7 +15,7 @@
76918 * at position 64.
76919 */
76920 #if BITS_PER_LONG == 32
76921-static __always_inline int fls64(__u64 x)
76922+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76923 {
76924 __u32 h = x >> 32;
76925 if (h)
76926@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
76927 return fls(x);
76928 }
76929 #elif BITS_PER_LONG == 64
76930-static __always_inline int fls64(__u64 x)
76931+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76932 {
76933 if (x == 0)
76934 return 0;
76935diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
76936index 1bfcfe5..e04c5c9 100644
76937--- a/include/asm-generic/cache.h
76938+++ b/include/asm-generic/cache.h
76939@@ -6,7 +6,7 @@
76940 * cache lines need to provide their own cache.h.
76941 */
76942
76943-#define L1_CACHE_SHIFT 5
76944-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
76945+#define L1_CACHE_SHIFT 5UL
76946+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
76947
76948 #endif /* __ASM_GENERIC_CACHE_H */
76949diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
76950index 0d68a1e..b74a761 100644
76951--- a/include/asm-generic/emergency-restart.h
76952+++ b/include/asm-generic/emergency-restart.h
76953@@ -1,7 +1,7 @@
76954 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
76955 #define _ASM_GENERIC_EMERGENCY_RESTART_H
76956
76957-static inline void machine_emergency_restart(void)
76958+static inline __noreturn void machine_emergency_restart(void)
76959 {
76960 machine_restart(NULL);
76961 }
76962diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
76963index 975e1cc..0b8a083 100644
76964--- a/include/asm-generic/io.h
76965+++ b/include/asm-generic/io.h
76966@@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
76967 * These are pretty trivial
76968 */
76969 #ifndef virt_to_phys
76970-static inline unsigned long virt_to_phys(volatile void *address)
76971+static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
76972 {
76973 return __pa((unsigned long)address);
76974 }
76975diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
76976index 90f99c7..00ce236 100644
76977--- a/include/asm-generic/kmap_types.h
76978+++ b/include/asm-generic/kmap_types.h
76979@@ -2,9 +2,9 @@
76980 #define _ASM_GENERIC_KMAP_TYPES_H
76981
76982 #ifdef __WITH_KM_FENCE
76983-# define KM_TYPE_NR 41
76984+# define KM_TYPE_NR 42
76985 #else
76986-# define KM_TYPE_NR 20
76987+# define KM_TYPE_NR 21
76988 #endif
76989
76990 #endif
76991diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
76992index 9ceb03b..62b0b8f 100644
76993--- a/include/asm-generic/local.h
76994+++ b/include/asm-generic/local.h
76995@@ -23,24 +23,37 @@ typedef struct
76996 atomic_long_t a;
76997 } local_t;
76998
76999+typedef struct {
77000+ atomic_long_unchecked_t a;
77001+} local_unchecked_t;
77002+
77003 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77004
77005 #define local_read(l) atomic_long_read(&(l)->a)
77006+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77007 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77008+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77009 #define local_inc(l) atomic_long_inc(&(l)->a)
77010+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77011 #define local_dec(l) atomic_long_dec(&(l)->a)
77012+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77013 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77014+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77015 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77016+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77017
77018 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77019 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77020 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77021 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77022 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77023+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77024 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77025 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77026+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77027
77028 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77029+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77030 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77031 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77032 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77033diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77034index 725612b..9cc513a 100644
77035--- a/include/asm-generic/pgtable-nopmd.h
77036+++ b/include/asm-generic/pgtable-nopmd.h
77037@@ -1,14 +1,19 @@
77038 #ifndef _PGTABLE_NOPMD_H
77039 #define _PGTABLE_NOPMD_H
77040
77041-#ifndef __ASSEMBLY__
77042-
77043 #include <asm-generic/pgtable-nopud.h>
77044
77045-struct mm_struct;
77046-
77047 #define __PAGETABLE_PMD_FOLDED
77048
77049+#define PMD_SHIFT PUD_SHIFT
77050+#define PTRS_PER_PMD 1
77051+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77052+#define PMD_MASK (~(PMD_SIZE-1))
77053+
77054+#ifndef __ASSEMBLY__
77055+
77056+struct mm_struct;
77057+
77058 /*
77059 * Having the pmd type consist of a pud gets the size right, and allows
77060 * us to conceptually access the pud entry that this pmd is folded into
77061@@ -16,11 +21,6 @@ struct mm_struct;
77062 */
77063 typedef struct { pud_t pud; } pmd_t;
77064
77065-#define PMD_SHIFT PUD_SHIFT
77066-#define PTRS_PER_PMD 1
77067-#define PMD_SIZE (1UL << PMD_SHIFT)
77068-#define PMD_MASK (~(PMD_SIZE-1))
77069-
77070 /*
77071 * The "pud_xxx()" functions here are trivial for a folded two-level
77072 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77073diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77074index 810431d..0ec4804f 100644
77075--- a/include/asm-generic/pgtable-nopud.h
77076+++ b/include/asm-generic/pgtable-nopud.h
77077@@ -1,10 +1,15 @@
77078 #ifndef _PGTABLE_NOPUD_H
77079 #define _PGTABLE_NOPUD_H
77080
77081-#ifndef __ASSEMBLY__
77082-
77083 #define __PAGETABLE_PUD_FOLDED
77084
77085+#define PUD_SHIFT PGDIR_SHIFT
77086+#define PTRS_PER_PUD 1
77087+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77088+#define PUD_MASK (~(PUD_SIZE-1))
77089+
77090+#ifndef __ASSEMBLY__
77091+
77092 /*
77093 * Having the pud type consist of a pgd gets the size right, and allows
77094 * us to conceptually access the pgd entry that this pud is folded into
77095@@ -12,11 +17,6 @@
77096 */
77097 typedef struct { pgd_t pgd; } pud_t;
77098
77099-#define PUD_SHIFT PGDIR_SHIFT
77100-#define PTRS_PER_PUD 1
77101-#define PUD_SIZE (1UL << PUD_SHIFT)
77102-#define PUD_MASK (~(PUD_SIZE-1))
77103-
77104 /*
77105 * The "pgd_xxx()" functions here are trivial for a folded two-level
77106 * setup: the pud is never bad, and a pud always exists (as it's folded
77107@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77108 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77109
77110 #define pgd_populate(mm, pgd, pud) do { } while (0)
77111+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77112 /*
77113 * (puds are folded into pgds so this doesn't get actually called,
77114 * but the define is needed for a generic inline function.)
77115diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77116index a8015a7..7a4407b 100644
77117--- a/include/asm-generic/pgtable.h
77118+++ b/include/asm-generic/pgtable.h
77119@@ -815,6 +815,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77120 }
77121 #endif /* CONFIG_NUMA_BALANCING */
77122
77123+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77124+#ifdef CONFIG_PAX_KERNEXEC
77125+#error KERNEXEC requires pax_open_kernel
77126+#else
77127+static inline unsigned long pax_open_kernel(void) { return 0; }
77128+#endif
77129+#endif
77130+
77131+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77132+#ifdef CONFIG_PAX_KERNEXEC
77133+#error KERNEXEC requires pax_close_kernel
77134+#else
77135+static inline unsigned long pax_close_kernel(void) { return 0; }
77136+#endif
77137+#endif
77138+
77139 #endif /* CONFIG_MMU */
77140
77141 #endif /* !__ASSEMBLY__ */
77142diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77143index 72d8803..cb9749c 100644
77144--- a/include/asm-generic/uaccess.h
77145+++ b/include/asm-generic/uaccess.h
77146@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77147 return __clear_user(to, n);
77148 }
77149
77150+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77151+#ifdef CONFIG_PAX_MEMORY_UDEREF
77152+#error UDEREF requires pax_open_userland
77153+#else
77154+static inline unsigned long pax_open_userland(void) { return 0; }
77155+#endif
77156+#endif
77157+
77158+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77159+#ifdef CONFIG_PAX_MEMORY_UDEREF
77160+#error UDEREF requires pax_close_userland
77161+#else
77162+static inline unsigned long pax_close_userland(void) { return 0; }
77163+#endif
77164+#endif
77165+
77166 #endif /* __ASM_GENERIC_UACCESS_H */
77167diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77168index 146e4ff..f4f9609 100644
77169--- a/include/asm-generic/vmlinux.lds.h
77170+++ b/include/asm-generic/vmlinux.lds.h
77171@@ -251,6 +251,7 @@
77172 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77173 VMLINUX_SYMBOL(__start_rodata) = .; \
77174 *(.rodata) *(.rodata.*) \
77175+ *(.data..read_only) \
77176 *(__vermagic) /* Kernel version magic */ \
77177 . = ALIGN(8); \
77178 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77179@@ -737,17 +738,18 @@
77180 * section in the linker script will go there too. @phdr should have
77181 * a leading colon.
77182 *
77183- * Note that this macros defines __per_cpu_load as an absolute symbol.
77184+ * Note that this macros defines per_cpu_load as an absolute symbol.
77185 * If there is no need to put the percpu section at a predetermined
77186 * address, use PERCPU_SECTION.
77187 */
77188 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77189- VMLINUX_SYMBOL(__per_cpu_load) = .; \
77190- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77191+ per_cpu_load = .; \
77192+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77193 - LOAD_OFFSET) { \
77194+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77195 PERCPU_INPUT(cacheline) \
77196 } phdr \
77197- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77198+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77199
77200 /**
77201 * PERCPU_SECTION - define output section for percpu area, simple version
77202diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77203index 016c2f1..c4baa98 100644
77204--- a/include/crypto/algapi.h
77205+++ b/include/crypto/algapi.h
77206@@ -34,7 +34,7 @@ struct crypto_type {
77207 unsigned int maskclear;
77208 unsigned int maskset;
77209 unsigned int tfmsize;
77210-};
77211+} __do_const;
77212
77213 struct crypto_instance {
77214 struct crypto_alg alg;
77215diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77216index a7c2a86..078f1b6 100644
77217--- a/include/drm/drmP.h
77218+++ b/include/drm/drmP.h
77219@@ -68,6 +68,7 @@
77220 #include <linux/workqueue.h>
77221 #include <linux/poll.h>
77222 #include <asm/pgalloc.h>
77223+#include <asm/local.h>
77224 #include <drm/drm.h>
77225 #include <drm/drm_sarea.h>
77226 #include <drm/drm_vma_manager.h>
77227@@ -268,10 +269,12 @@ do { \
77228 * \param cmd command.
77229 * \param arg argument.
77230 */
77231-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77232+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77233+ struct drm_file *file_priv);
77234+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77235 struct drm_file *file_priv);
77236
77237-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77238+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77239 unsigned long arg);
77240
77241 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77242@@ -287,10 +290,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77243 struct drm_ioctl_desc {
77244 unsigned int cmd;
77245 int flags;
77246- drm_ioctl_t *func;
77247+ drm_ioctl_t func;
77248 unsigned int cmd_drv;
77249 const char *name;
77250-};
77251+} __do_const;
77252
77253 /**
77254 * Creates a driver or general drm_ioctl_desc array entry for the given
77255@@ -1001,7 +1004,8 @@ struct drm_info_list {
77256 int (*show)(struct seq_file*, void*); /** show callback */
77257 u32 driver_features; /**< Required driver features for this entry */
77258 void *data;
77259-};
77260+} __do_const;
77261+typedef struct drm_info_list __no_const drm_info_list_no_const;
77262
77263 /**
77264 * debugfs node structure. This structure represents a debugfs file.
77265@@ -1083,7 +1087,7 @@ struct drm_device {
77266
77267 /** \name Usage Counters */
77268 /*@{ */
77269- int open_count; /**< Outstanding files open */
77270+ local_t open_count; /**< Outstanding files open */
77271 int buf_use; /**< Buffers in use -- cannot alloc */
77272 atomic_t buf_alloc; /**< Buffer allocation in progress */
77273 /*@} */
77274diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77275index 36a5feb..d9f01aa 100644
77276--- a/include/drm/drm_crtc_helper.h
77277+++ b/include/drm/drm_crtc_helper.h
77278@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77279 struct drm_connector *connector);
77280 /* disable encoder when not in use - more explicit than dpms off */
77281 void (*disable)(struct drm_encoder *encoder);
77282-};
77283+} __no_const;
77284
77285 /**
77286 * drm_connector_helper_funcs - helper operations for connectors
77287diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77288index 012d58f..d0a0642 100644
77289--- a/include/drm/i915_pciids.h
77290+++ b/include/drm/i915_pciids.h
77291@@ -37,7 +37,7 @@
77292 */
77293 #define INTEL_VGA_DEVICE(id, info) { \
77294 0x8086, id, \
77295- ~0, ~0, \
77296+ PCI_ANY_ID, PCI_ANY_ID, \
77297 0x030000, 0xff0000, \
77298 (unsigned long) info }
77299
77300diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77301index 72dcbe8..8db58d7 100644
77302--- a/include/drm/ttm/ttm_memory.h
77303+++ b/include/drm/ttm/ttm_memory.h
77304@@ -48,7 +48,7 @@
77305
77306 struct ttm_mem_shrink {
77307 int (*do_shrink) (struct ttm_mem_shrink *);
77308-};
77309+} __no_const;
77310
77311 /**
77312 * struct ttm_mem_global - Global memory accounting structure.
77313diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77314index 49a8284..9643967 100644
77315--- a/include/drm/ttm/ttm_page_alloc.h
77316+++ b/include/drm/ttm/ttm_page_alloc.h
77317@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77318 */
77319 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77320
77321+struct device;
77322 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77323 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77324
77325diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77326index 4b840e8..155d235 100644
77327--- a/include/keys/asymmetric-subtype.h
77328+++ b/include/keys/asymmetric-subtype.h
77329@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77330 /* Verify the signature on a key of this subtype (optional) */
77331 int (*verify_signature)(const struct key *key,
77332 const struct public_key_signature *sig);
77333-};
77334+} __do_const;
77335
77336 /**
77337 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77338diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77339index c1da539..1dcec55 100644
77340--- a/include/linux/atmdev.h
77341+++ b/include/linux/atmdev.h
77342@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77343 #endif
77344
77345 struct k_atm_aal_stats {
77346-#define __HANDLE_ITEM(i) atomic_t i
77347+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77348 __AAL_STAT_ITEMS
77349 #undef __HANDLE_ITEM
77350 };
77351@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77352 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77353 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77354 struct module *owner;
77355-};
77356+} __do_const ;
77357
77358 struct atmphy_ops {
77359 int (*start)(struct atm_dev *dev);
77360diff --git a/include/linux/audit.h b/include/linux/audit.h
77361index 22cfddb..ab759e8 100644
77362--- a/include/linux/audit.h
77363+++ b/include/linux/audit.h
77364@@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
77365 extern unsigned int audit_serial(void);
77366 extern int auditsc_get_stamp(struct audit_context *ctx,
77367 struct timespec *t, unsigned int *serial);
77368-extern int audit_set_loginuid(kuid_t loginuid);
77369+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77370
77371 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77372 {
77373diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77374index 61f29e5..e67c658 100644
77375--- a/include/linux/binfmts.h
77376+++ b/include/linux/binfmts.h
77377@@ -44,7 +44,7 @@ struct linux_binprm {
77378 unsigned interp_flags;
77379 unsigned interp_data;
77380 unsigned long loader, exec;
77381-};
77382+} __randomize_layout;
77383
77384 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77385 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77386@@ -73,8 +73,10 @@ struct linux_binfmt {
77387 int (*load_binary)(struct linux_binprm *);
77388 int (*load_shlib)(struct file *);
77389 int (*core_dump)(struct coredump_params *cprm);
77390+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77391+ void (*handle_mmap)(struct file *);
77392 unsigned long min_coredump; /* minimal dump size */
77393-};
77394+} __do_const __randomize_layout;
77395
77396 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77397
77398diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77399index be5fd38..d71192a 100644
77400--- a/include/linux/bitops.h
77401+++ b/include/linux/bitops.h
77402@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77403 * @word: value to rotate
77404 * @shift: bits to roll
77405 */
77406-static inline __u32 rol32(__u32 word, unsigned int shift)
77407+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77408 {
77409 return (word << shift) | (word >> (32 - shift));
77410 }
77411@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77412 * @word: value to rotate
77413 * @shift: bits to roll
77414 */
77415-static inline __u32 ror32(__u32 word, unsigned int shift)
77416+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77417 {
77418 return (word >> shift) | (word << (32 - shift));
77419 }
77420@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77421 return (__s32)(value << shift) >> shift;
77422 }
77423
77424-static inline unsigned fls_long(unsigned long l)
77425+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77426 {
77427 if (sizeof(l) == 4)
77428 return fls(l);
77429diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77430index 0d84981..bb741c0 100644
77431--- a/include/linux/blkdev.h
77432+++ b/include/linux/blkdev.h
77433@@ -1584,7 +1584,7 @@ struct block_device_operations {
77434 /* this callback is with swap_lock and sometimes page table lock held */
77435 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77436 struct module *owner;
77437-};
77438+} __do_const;
77439
77440 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77441 unsigned long);
77442diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77443index afc1343..9735539 100644
77444--- a/include/linux/blktrace_api.h
77445+++ b/include/linux/blktrace_api.h
77446@@ -25,7 +25,7 @@ struct blk_trace {
77447 struct dentry *dropped_file;
77448 struct dentry *msg_file;
77449 struct list_head running_list;
77450- atomic_t dropped;
77451+ atomic_unchecked_t dropped;
77452 };
77453
77454 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77455diff --git a/include/linux/cache.h b/include/linux/cache.h
77456index 17e7e82..1d7da26 100644
77457--- a/include/linux/cache.h
77458+++ b/include/linux/cache.h
77459@@ -16,6 +16,14 @@
77460 #define __read_mostly
77461 #endif
77462
77463+#ifndef __read_only
77464+#ifdef CONFIG_PAX_KERNEXEC
77465+#error KERNEXEC requires __read_only
77466+#else
77467+#define __read_only __read_mostly
77468+#endif
77469+#endif
77470+
77471 #ifndef ____cacheline_aligned
77472 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77473 #endif
77474diff --git a/include/linux/capability.h b/include/linux/capability.h
77475index 84b13ad..172cdee 100644
77476--- a/include/linux/capability.h
77477+++ b/include/linux/capability.h
77478@@ -211,9 +211,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
77479 extern bool capable(int cap);
77480 extern bool ns_capable(struct user_namespace *ns, int cap);
77481 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
77482+extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
77483 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77484+extern bool capable_nolog(int cap);
77485+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77486
77487 /* audit system wants to get cap info from files as well */
77488 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77489
77490+extern int is_privileged_binary(const struct dentry *dentry);
77491+
77492 #endif /* !_LINUX_CAPABILITY_H */
77493diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77494index 8609d57..86e4d79 100644
77495--- a/include/linux/cdrom.h
77496+++ b/include/linux/cdrom.h
77497@@ -87,7 +87,6 @@ struct cdrom_device_ops {
77498
77499 /* driver specifications */
77500 const int capability; /* capability flags */
77501- int n_minors; /* number of active minor devices */
77502 /* handle uniform packets for scsi type devices (scsi,atapi) */
77503 int (*generic_packet) (struct cdrom_device_info *,
77504 struct packet_command *);
77505diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77506index 4ce9056..86caac6 100644
77507--- a/include/linux/cleancache.h
77508+++ b/include/linux/cleancache.h
77509@@ -31,7 +31,7 @@ struct cleancache_ops {
77510 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77511 void (*invalidate_inode)(int, struct cleancache_filekey);
77512 void (*invalidate_fs)(int);
77513-};
77514+} __no_const;
77515
77516 extern struct cleancache_ops *
77517 cleancache_register_ops(struct cleancache_ops *ops);
77518diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77519index 5119174..8e264f8 100644
77520--- a/include/linux/clk-provider.h
77521+++ b/include/linux/clk-provider.h
77522@@ -174,6 +174,7 @@ struct clk_ops {
77523 void (*init)(struct clk_hw *hw);
77524 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
77525 };
77526+typedef struct clk_ops __no_const clk_ops_no_const;
77527
77528 /**
77529 * struct clk_init_data - holds init data that's common to all clocks and is
77530diff --git a/include/linux/compat.h b/include/linux/compat.h
77531index e649426..a74047b 100644
77532--- a/include/linux/compat.h
77533+++ b/include/linux/compat.h
77534@@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77535 compat_size_t __user *len_ptr);
77536
77537 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77538-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77539+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77540 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77541 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77542 compat_ssize_t msgsz, int msgflg);
77543@@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77544 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77545 compat_ulong_t addr, compat_ulong_t data);
77546 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77547- compat_long_t addr, compat_long_t data);
77548+ compat_ulong_t addr, compat_ulong_t data);
77549
77550 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77551 /*
77552diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77553index 2507fd2..55203f8 100644
77554--- a/include/linux/compiler-gcc4.h
77555+++ b/include/linux/compiler-gcc4.h
77556@@ -39,9 +39,34 @@
77557 # define __compiletime_warning(message) __attribute__((warning(message)))
77558 # define __compiletime_error(message) __attribute__((error(message)))
77559 #endif /* __CHECKER__ */
77560+
77561+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77562+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77563+#define __bos0(ptr) __bos((ptr), 0)
77564+#define __bos1(ptr) __bos((ptr), 1)
77565 #endif /* GCC_VERSION >= 40300 */
77566
77567 #if GCC_VERSION >= 40500
77568+
77569+#ifdef RANDSTRUCT_PLUGIN
77570+#define __randomize_layout __attribute__((randomize_layout))
77571+#define __no_randomize_layout __attribute__((no_randomize_layout))
77572+#endif
77573+
77574+#ifdef CONSTIFY_PLUGIN
77575+#define __no_const __attribute__((no_const))
77576+#define __do_const __attribute__((do_const))
77577+#endif
77578+
77579+#ifdef SIZE_OVERFLOW_PLUGIN
77580+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77581+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77582+#endif
77583+
77584+#ifdef LATENT_ENTROPY_PLUGIN
77585+#define __latent_entropy __attribute__((latent_entropy))
77586+#endif
77587+
77588 /*
77589 * Mark a position in code as unreachable. This can be used to
77590 * suppress control flow warnings after asm blocks that transfer
77591diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77592index ee7239e..7c11769 100644
77593--- a/include/linux/compiler.h
77594+++ b/include/linux/compiler.h
77595@@ -5,11 +5,14 @@
77596
77597 #ifdef __CHECKER__
77598 # define __user __attribute__((noderef, address_space(1)))
77599+# define __force_user __force __user
77600 # define __kernel __attribute__((address_space(0)))
77601+# define __force_kernel __force __kernel
77602 # define __safe __attribute__((safe))
77603 # define __force __attribute__((force))
77604 # define __nocast __attribute__((nocast))
77605 # define __iomem __attribute__((noderef, address_space(2)))
77606+# define __force_iomem __force __iomem
77607 # define __must_hold(x) __attribute__((context(x,1,1)))
77608 # define __acquires(x) __attribute__((context(x,0,1)))
77609 # define __releases(x) __attribute__((context(x,1,0)))
77610@@ -17,20 +20,37 @@
77611 # define __release(x) __context__(x,-1)
77612 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77613 # define __percpu __attribute__((noderef, address_space(3)))
77614+# define __force_percpu __force __percpu
77615 #ifdef CONFIG_SPARSE_RCU_POINTER
77616 # define __rcu __attribute__((noderef, address_space(4)))
77617+# define __force_rcu __force __rcu
77618 #else
77619 # define __rcu
77620+# define __force_rcu
77621 #endif
77622 extern void __chk_user_ptr(const volatile void __user *);
77623 extern void __chk_io_ptr(const volatile void __iomem *);
77624 #else
77625-# define __user
77626-# define __kernel
77627+# ifdef CHECKER_PLUGIN
77628+//# define __user
77629+//# define __force_user
77630+//# define __kernel
77631+//# define __force_kernel
77632+# else
77633+# ifdef STRUCTLEAK_PLUGIN
77634+# define __user __attribute__((user))
77635+# else
77636+# define __user
77637+# endif
77638+# define __force_user
77639+# define __kernel
77640+# define __force_kernel
77641+# endif
77642 # define __safe
77643 # define __force
77644 # define __nocast
77645 # define __iomem
77646+# define __force_iomem
77647 # define __chk_user_ptr(x) (void)0
77648 # define __chk_io_ptr(x) (void)0
77649 # define __builtin_warning(x, y...) (1)
77650@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77651 # define __release(x) (void)0
77652 # define __cond_lock(x,c) (c)
77653 # define __percpu
77654+# define __force_percpu
77655 # define __rcu
77656+# define __force_rcu
77657 #endif
77658
77659 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77660@@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77661 # define __attribute_const__ /* unimplemented */
77662 #endif
77663
77664+#ifndef __randomize_layout
77665+# define __randomize_layout
77666+#endif
77667+
77668+#ifndef __no_randomize_layout
77669+# define __no_randomize_layout
77670+#endif
77671+
77672+#ifndef __no_const
77673+# define __no_const
77674+#endif
77675+
77676+#ifndef __do_const
77677+# define __do_const
77678+#endif
77679+
77680+#ifndef __size_overflow
77681+# define __size_overflow(...)
77682+#endif
77683+
77684+#ifndef __intentional_overflow
77685+# define __intentional_overflow(...)
77686+#endif
77687+
77688+#ifndef __latent_entropy
77689+# define __latent_entropy
77690+#endif
77691+
77692 /*
77693 * Tell gcc if a function is cold. The compiler will assume any path
77694 * directly leading to the call is unlikely.
77695@@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77696 #define __cold
77697 #endif
77698
77699+#ifndef __alloc_size
77700+#define __alloc_size(...)
77701+#endif
77702+
77703+#ifndef __bos
77704+#define __bos(ptr, arg)
77705+#endif
77706+
77707+#ifndef __bos0
77708+#define __bos0(ptr)
77709+#endif
77710+
77711+#ifndef __bos1
77712+#define __bos1(ptr)
77713+#endif
77714+
77715 /* Simple shorthand for a section definition */
77716 #ifndef __section
77717 # define __section(S) __attribute__ ((__section__(#S)))
77718@@ -369,7 +435,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77719 * use is to mediate communication between process-level code and irq/NMI
77720 * handlers, all running on the same CPU.
77721 */
77722-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77723+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77724+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77725
77726 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77727 #ifdef CONFIG_KPROBES
77728diff --git a/include/linux/completion.h b/include/linux/completion.h
77729index 5d5aaae..0ea9b84 100644
77730--- a/include/linux/completion.h
77731+++ b/include/linux/completion.h
77732@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77733
77734 extern void wait_for_completion(struct completion *);
77735 extern void wait_for_completion_io(struct completion *);
77736-extern int wait_for_completion_interruptible(struct completion *x);
77737-extern int wait_for_completion_killable(struct completion *x);
77738+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77739+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77740 extern unsigned long wait_for_completion_timeout(struct completion *x,
77741- unsigned long timeout);
77742+ unsigned long timeout) __intentional_overflow(-1);
77743 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77744- unsigned long timeout);
77745+ unsigned long timeout) __intentional_overflow(-1);
77746 extern long wait_for_completion_interruptible_timeout(
77747- struct completion *x, unsigned long timeout);
77748+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77749 extern long wait_for_completion_killable_timeout(
77750- struct completion *x, unsigned long timeout);
77751+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77752 extern bool try_wait_for_completion(struct completion *x);
77753 extern bool completion_done(struct completion *x);
77754
77755diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77756index 34025df..d94bbbc 100644
77757--- a/include/linux/configfs.h
77758+++ b/include/linux/configfs.h
77759@@ -125,7 +125,7 @@ struct configfs_attribute {
77760 const char *ca_name;
77761 struct module *ca_owner;
77762 umode_t ca_mode;
77763-};
77764+} __do_const;
77765
77766 /*
77767 * Users often need to create attribute structures for their configurable
77768diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77769index 5ae5100..b809662 100644
77770--- a/include/linux/cpufreq.h
77771+++ b/include/linux/cpufreq.h
77772@@ -200,6 +200,7 @@ struct global_attr {
77773 ssize_t (*store)(struct kobject *a, struct attribute *b,
77774 const char *c, size_t count);
77775 };
77776+typedef struct global_attr __no_const global_attr_no_const;
77777
77778 #define define_one_global_ro(_name) \
77779 static struct global_attr _name = \
77780@@ -242,7 +243,7 @@ struct cpufreq_driver {
77781 bool boost_supported;
77782 bool boost_enabled;
77783 int (*set_boost) (int state);
77784-};
77785+} __do_const;
77786
77787 /* flags */
77788 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77789diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77790index b0238cb..db89e1e 100644
77791--- a/include/linux/cpuidle.h
77792+++ b/include/linux/cpuidle.h
77793@@ -50,7 +50,8 @@ struct cpuidle_state {
77794 int index);
77795
77796 int (*enter_dead) (struct cpuidle_device *dev, int index);
77797-};
77798+} __do_const;
77799+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77800
77801 /* Idle State Flags */
77802 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77803@@ -211,7 +212,7 @@ struct cpuidle_governor {
77804 void (*reflect) (struct cpuidle_device *dev, int index);
77805
77806 struct module *owner;
77807-};
77808+} __do_const;
77809
77810 #ifdef CONFIG_CPU_IDLE
77811 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77812diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77813index d08e4d2..95fad61 100644
77814--- a/include/linux/cpumask.h
77815+++ b/include/linux/cpumask.h
77816@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77817 }
77818
77819 /* Valid inputs for n are -1 and 0. */
77820-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77821+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77822 {
77823 return n+1;
77824 }
77825
77826-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77827+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77828 {
77829 return n+1;
77830 }
77831
77832-static inline unsigned int cpumask_next_and(int n,
77833+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77834 const struct cpumask *srcp,
77835 const struct cpumask *andp)
77836 {
77837@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77838 *
77839 * Returns >= nr_cpu_ids if no further cpus set.
77840 */
77841-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77842+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77843 {
77844 /* -1 is a legal arg here. */
77845 if (n != -1)
77846@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77847 *
77848 * Returns >= nr_cpu_ids if no further cpus unset.
77849 */
77850-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77851+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77852 {
77853 /* -1 is a legal arg here. */
77854 if (n != -1)
77855@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77856 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77857 }
77858
77859-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77860+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77861 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77862
77863 /**
77864diff --git a/include/linux/cred.h b/include/linux/cred.h
77865index f61d6c8..d372d95 100644
77866--- a/include/linux/cred.h
77867+++ b/include/linux/cred.h
77868@@ -35,7 +35,7 @@ struct group_info {
77869 int nblocks;
77870 kgid_t small_block[NGROUPS_SMALL];
77871 kgid_t *blocks[0];
77872-};
77873+} __randomize_layout;
77874
77875 /**
77876 * get_group_info - Get a reference to a group info structure
77877@@ -136,7 +136,7 @@ struct cred {
77878 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77879 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77880 struct rcu_head rcu; /* RCU deletion hook */
77881-};
77882+} __randomize_layout;
77883
77884 extern void __put_cred(struct cred *);
77885 extern void exit_creds(struct task_struct *);
77886@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
77887 static inline void validate_process_creds(void)
77888 {
77889 }
77890+static inline void validate_task_creds(struct task_struct *task)
77891+{
77892+}
77893 #endif
77894
77895 /**
77896@@ -322,6 +325,7 @@ static inline void put_cred(const struct cred *_cred)
77897
77898 #define task_uid(task) (task_cred_xxx((task), uid))
77899 #define task_euid(task) (task_cred_xxx((task), euid))
77900+#define task_securebits(task) (task_cred_xxx((task), securebits))
77901
77902 #define current_cred_xxx(xxx) \
77903 ({ \
77904diff --git a/include/linux/crypto.h b/include/linux/crypto.h
77905index b92eadf..b4ecdc1 100644
77906--- a/include/linux/crypto.h
77907+++ b/include/linux/crypto.h
77908@@ -373,7 +373,7 @@ struct cipher_tfm {
77909 const u8 *key, unsigned int keylen);
77910 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77911 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77912-};
77913+} __no_const;
77914
77915 struct hash_tfm {
77916 int (*init)(struct hash_desc *desc);
77917@@ -394,13 +394,13 @@ struct compress_tfm {
77918 int (*cot_decompress)(struct crypto_tfm *tfm,
77919 const u8 *src, unsigned int slen,
77920 u8 *dst, unsigned int *dlen);
77921-};
77922+} __no_const;
77923
77924 struct rng_tfm {
77925 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
77926 unsigned int dlen);
77927 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
77928-};
77929+} __no_const;
77930
77931 #define crt_ablkcipher crt_u.ablkcipher
77932 #define crt_aead crt_u.aead
77933diff --git a/include/linux/ctype.h b/include/linux/ctype.h
77934index 653589e..4ef254a 100644
77935--- a/include/linux/ctype.h
77936+++ b/include/linux/ctype.h
77937@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
77938 * Fast implementation of tolower() for internal usage. Do not use in your
77939 * code.
77940 */
77941-static inline char _tolower(const char c)
77942+static inline unsigned char _tolower(const unsigned char c)
77943 {
77944 return c | 0x20;
77945 }
77946diff --git a/include/linux/dcache.h b/include/linux/dcache.h
77947index 3c7ec32..4ca97cc 100644
77948--- a/include/linux/dcache.h
77949+++ b/include/linux/dcache.h
77950@@ -133,7 +133,7 @@ struct dentry {
77951 } d_u;
77952 struct list_head d_subdirs; /* our children */
77953 struct hlist_node d_alias; /* inode alias list */
77954-};
77955+} __randomize_layout;
77956
77957 /*
77958 * dentry->d_lock spinlock nesting subclasses:
77959diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
77960index 7925bf0..d5143d2 100644
77961--- a/include/linux/decompress/mm.h
77962+++ b/include/linux/decompress/mm.h
77963@@ -77,7 +77,7 @@ static void free(void *where)
77964 * warnings when not needed (indeed large_malloc / large_free are not
77965 * needed by inflate */
77966
77967-#define malloc(a) kmalloc(a, GFP_KERNEL)
77968+#define malloc(a) kmalloc((a), GFP_KERNEL)
77969 #define free(a) kfree(a)
77970
77971 #define large_malloc(a) vmalloc(a)
77972diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
77973index d48dc00..211ee54 100644
77974--- a/include/linux/devfreq.h
77975+++ b/include/linux/devfreq.h
77976@@ -114,7 +114,7 @@ struct devfreq_governor {
77977 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
77978 int (*event_handler)(struct devfreq *devfreq,
77979 unsigned int event, void *data);
77980-};
77981+} __do_const;
77982
77983 /**
77984 * struct devfreq - Device devfreq structure
77985diff --git a/include/linux/device.h b/include/linux/device.h
77986index d1d1c05..a90fdb0 100644
77987--- a/include/linux/device.h
77988+++ b/include/linux/device.h
77989@@ -310,7 +310,7 @@ struct subsys_interface {
77990 struct list_head node;
77991 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
77992 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
77993-};
77994+} __do_const;
77995
77996 int subsys_interface_register(struct subsys_interface *sif);
77997 void subsys_interface_unregister(struct subsys_interface *sif);
77998@@ -506,7 +506,7 @@ struct device_type {
77999 void (*release)(struct device *dev);
78000
78001 const struct dev_pm_ops *pm;
78002-};
78003+} __do_const;
78004
78005 /* interface for exporting device attributes */
78006 struct device_attribute {
78007@@ -516,11 +516,12 @@ struct device_attribute {
78008 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78009 const char *buf, size_t count);
78010 };
78011+typedef struct device_attribute __no_const device_attribute_no_const;
78012
78013 struct dev_ext_attribute {
78014 struct device_attribute attr;
78015 void *var;
78016-};
78017+} __do_const;
78018
78019 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78020 char *buf);
78021diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78022index fd4aee2..1f28db9 100644
78023--- a/include/linux/dma-mapping.h
78024+++ b/include/linux/dma-mapping.h
78025@@ -54,7 +54,7 @@ struct dma_map_ops {
78026 u64 (*get_required_mask)(struct device *dev);
78027 #endif
78028 int is_phys;
78029-};
78030+} __do_const;
78031
78032 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78033
78034diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78035index 72cb0dd..7fe9a4b 100644
78036--- a/include/linux/dmaengine.h
78037+++ b/include/linux/dmaengine.h
78038@@ -1147,9 +1147,9 @@ struct dma_pinned_list {
78039 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78040 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78041
78042-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78043+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78044 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78045-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78046+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78047 struct dma_pinned_list *pinned_list, struct page *page,
78048 unsigned int offset, size_t len);
78049
78050diff --git a/include/linux/efi.h b/include/linux/efi.h
78051index 6c100ff..e3289b4 100644
78052--- a/include/linux/efi.h
78053+++ b/include/linux/efi.h
78054@@ -1009,6 +1009,7 @@ struct efivar_operations {
78055 efi_set_variable_t *set_variable;
78056 efi_query_variable_store_t *query_variable_store;
78057 };
78058+typedef struct efivar_operations __no_const efivar_operations_no_const;
78059
78060 struct efivars {
78061 /*
78062diff --git a/include/linux/elf.h b/include/linux/elf.h
78063index 67a5fa7..b817372 100644
78064--- a/include/linux/elf.h
78065+++ b/include/linux/elf.h
78066@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78067 #define elf_note elf32_note
78068 #define elf_addr_t Elf32_Off
78069 #define Elf_Half Elf32_Half
78070+#define elf_dyn Elf32_Dyn
78071
78072 #else
78073
78074@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78075 #define elf_note elf64_note
78076 #define elf_addr_t Elf64_Off
78077 #define Elf_Half Elf64_Half
78078+#define elf_dyn Elf64_Dyn
78079
78080 #endif
78081
78082diff --git a/include/linux/err.h b/include/linux/err.h
78083index a729120..6ede2c9 100644
78084--- a/include/linux/err.h
78085+++ b/include/linux/err.h
78086@@ -20,12 +20,12 @@
78087
78088 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78089
78090-static inline void * __must_check ERR_PTR(long error)
78091+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78092 {
78093 return (void *) error;
78094 }
78095
78096-static inline long __must_check PTR_ERR(__force const void *ptr)
78097+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78098 {
78099 return (long) ptr;
78100 }
78101diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78102index f488145..3b6b04e 100644
78103--- a/include/linux/extcon.h
78104+++ b/include/linux/extcon.h
78105@@ -135,7 +135,7 @@ struct extcon_dev {
78106 /* /sys/class/extcon/.../mutually_exclusive/... */
78107 struct attribute_group attr_g_muex;
78108 struct attribute **attrs_muex;
78109- struct device_attribute *d_attrs_muex;
78110+ device_attribute_no_const *d_attrs_muex;
78111 };
78112
78113 /**
78114diff --git a/include/linux/fb.h b/include/linux/fb.h
78115index fe6ac95..898d41d 100644
78116--- a/include/linux/fb.h
78117+++ b/include/linux/fb.h
78118@@ -304,7 +304,7 @@ struct fb_ops {
78119 /* called at KDB enter and leave time to prepare the console */
78120 int (*fb_debug_enter)(struct fb_info *info);
78121 int (*fb_debug_leave)(struct fb_info *info);
78122-};
78123+} __do_const;
78124
78125 #ifdef CONFIG_FB_TILEBLITTING
78126 #define FB_TILE_CURSOR_NONE 0
78127diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78128index 230f87b..1fd0485 100644
78129--- a/include/linux/fdtable.h
78130+++ b/include/linux/fdtable.h
78131@@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78132 void put_files_struct(struct files_struct *fs);
78133 void reset_files_struct(struct files_struct *);
78134 int unshare_files(struct files_struct **);
78135-struct files_struct *dup_fd(struct files_struct *, int *);
78136+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78137 void do_close_on_exec(struct files_struct *);
78138 int iterate_fd(struct files_struct *, unsigned,
78139 int (*)(const void *, struct file *, unsigned),
78140diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78141index 8293262..2b3b8bd 100644
78142--- a/include/linux/frontswap.h
78143+++ b/include/linux/frontswap.h
78144@@ -11,7 +11,7 @@ struct frontswap_ops {
78145 int (*load)(unsigned, pgoff_t, struct page *);
78146 void (*invalidate_page)(unsigned, pgoff_t);
78147 void (*invalidate_area)(unsigned);
78148-};
78149+} __no_const;
78150
78151 extern bool frontswap_enabled;
78152 extern struct frontswap_ops *
78153diff --git a/include/linux/fs.h b/include/linux/fs.h
78154index 8780312..425cc22 100644
78155--- a/include/linux/fs.h
78156+++ b/include/linux/fs.h
78157@@ -398,7 +398,7 @@ struct address_space {
78158 spinlock_t private_lock; /* for use by the address_space */
78159 struct list_head private_list; /* ditto */
78160 void *private_data; /* ditto */
78161-} __attribute__((aligned(sizeof(long))));
78162+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78163 /*
78164 * On most architectures that alignment is already the case; but
78165 * must be enforced here for CRIS, to let the least significant bit
78166@@ -441,7 +441,7 @@ struct block_device {
78167 int bd_fsfreeze_count;
78168 /* Mutex for freeze */
78169 struct mutex bd_fsfreeze_mutex;
78170-};
78171+} __randomize_layout;
78172
78173 /*
78174 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78175@@ -585,7 +585,7 @@ struct inode {
78176 #endif
78177
78178 void *i_private; /* fs or device private pointer */
78179-};
78180+} __randomize_layout;
78181
78182 static inline int inode_unhashed(struct inode *inode)
78183 {
78184@@ -778,7 +778,7 @@ struct file {
78185 struct list_head f_tfile_llink;
78186 #endif /* #ifdef CONFIG_EPOLL */
78187 struct address_space *f_mapping;
78188-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78189+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78190
78191 struct file_handle {
78192 __u32 handle_bytes;
78193@@ -906,7 +906,7 @@ struct file_lock {
78194 int state; /* state of grant or error if -ve */
78195 } afs;
78196 } fl_u;
78197-};
78198+} __randomize_layout;
78199
78200 /* The following constant reflects the upper bound of the file/locking space */
78201 #ifndef OFFSET_MAX
78202@@ -1255,7 +1255,7 @@ struct super_block {
78203 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78204 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78205 struct rcu_head rcu;
78206-};
78207+} __randomize_layout;
78208
78209 extern struct timespec current_fs_time(struct super_block *sb);
78210
78211@@ -1477,7 +1477,8 @@ struct file_operations {
78212 long (*fallocate)(struct file *file, int mode, loff_t offset,
78213 loff_t len);
78214 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78215-};
78216+} __do_const __randomize_layout;
78217+typedef struct file_operations __no_const file_operations_no_const;
78218
78219 struct inode_operations {
78220 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78221@@ -2757,4 +2758,14 @@ static inline bool dir_relax(struct inode *inode)
78222 return !IS_DEADDIR(inode);
78223 }
78224
78225+static inline bool is_sidechannel_device(const struct inode *inode)
78226+{
78227+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78228+ umode_t mode = inode->i_mode;
78229+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78230+#else
78231+ return false;
78232+#endif
78233+}
78234+
78235 #endif /* _LINUX_FS_H */
78236diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78237index 0efc3e6..fd23610 100644
78238--- a/include/linux/fs_struct.h
78239+++ b/include/linux/fs_struct.h
78240@@ -6,13 +6,13 @@
78241 #include <linux/seqlock.h>
78242
78243 struct fs_struct {
78244- int users;
78245+ atomic_t users;
78246 spinlock_t lock;
78247 seqcount_t seq;
78248 int umask;
78249 int in_exec;
78250 struct path root, pwd;
78251-};
78252+} __randomize_layout;
78253
78254 extern struct kmem_cache *fs_cachep;
78255
78256diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78257index 7714849..a4a5c7a 100644
78258--- a/include/linux/fscache-cache.h
78259+++ b/include/linux/fscache-cache.h
78260@@ -113,7 +113,7 @@ struct fscache_operation {
78261 fscache_operation_release_t release;
78262 };
78263
78264-extern atomic_t fscache_op_debug_id;
78265+extern atomic_unchecked_t fscache_op_debug_id;
78266 extern void fscache_op_work_func(struct work_struct *work);
78267
78268 extern void fscache_enqueue_operation(struct fscache_operation *);
78269@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78270 INIT_WORK(&op->work, fscache_op_work_func);
78271 atomic_set(&op->usage, 1);
78272 op->state = FSCACHE_OP_ST_INITIALISED;
78273- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78274+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78275 op->processor = processor;
78276 op->release = release;
78277 INIT_LIST_HEAD(&op->pend_link);
78278diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78279index 115bb81..e7b812b 100644
78280--- a/include/linux/fscache.h
78281+++ b/include/linux/fscache.h
78282@@ -152,7 +152,7 @@ struct fscache_cookie_def {
78283 * - this is mandatory for any object that may have data
78284 */
78285 void (*now_uncached)(void *cookie_netfs_data);
78286-};
78287+} __do_const;
78288
78289 /*
78290 * fscache cached network filesystem type
78291diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78292index 1c804b0..1432c2b 100644
78293--- a/include/linux/fsnotify.h
78294+++ b/include/linux/fsnotify.h
78295@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78296 struct inode *inode = file_inode(file);
78297 __u32 mask = FS_ACCESS;
78298
78299+ if (is_sidechannel_device(inode))
78300+ return;
78301+
78302 if (S_ISDIR(inode->i_mode))
78303 mask |= FS_ISDIR;
78304
78305@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78306 struct inode *inode = file_inode(file);
78307 __u32 mask = FS_MODIFY;
78308
78309+ if (is_sidechannel_device(inode))
78310+ return;
78311+
78312 if (S_ISDIR(inode->i_mode))
78313 mask |= FS_ISDIR;
78314
78315@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78316 */
78317 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78318 {
78319- return kstrdup(name, GFP_KERNEL);
78320+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78321 }
78322
78323 /*
78324diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78325index 9f3c275..8bdff5d 100644
78326--- a/include/linux/genhd.h
78327+++ b/include/linux/genhd.h
78328@@ -194,7 +194,7 @@ struct gendisk {
78329 struct kobject *slave_dir;
78330
78331 struct timer_rand_state *random;
78332- atomic_t sync_io; /* RAID */
78333+ atomic_unchecked_t sync_io; /* RAID */
78334 struct disk_events *ev;
78335 #ifdef CONFIG_BLK_DEV_INTEGRITY
78336 struct blk_integrity *integrity;
78337@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78338 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78339
78340 /* drivers/char/random.c */
78341-extern void add_disk_randomness(struct gendisk *disk);
78342+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78343 extern void rand_initialize_disk(struct gendisk *disk);
78344
78345 static inline sector_t get_start_sect(struct block_device *bdev)
78346diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78347index c0894dd..2fbf10c 100644
78348--- a/include/linux/genl_magic_func.h
78349+++ b/include/linux/genl_magic_func.h
78350@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78351 },
78352
78353 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78354-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78355+static struct genl_ops ZZZ_genl_ops[] = {
78356 #include GENL_MAGIC_INCLUDE_FILE
78357 };
78358
78359diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78360index 39b81dc..819dc51 100644
78361--- a/include/linux/gfp.h
78362+++ b/include/linux/gfp.h
78363@@ -36,6 +36,13 @@ struct vm_area_struct;
78364 #define ___GFP_NO_KSWAPD 0x400000u
78365 #define ___GFP_OTHER_NODE 0x800000u
78366 #define ___GFP_WRITE 0x1000000u
78367+
78368+#ifdef CONFIG_PAX_USERCOPY_SLABS
78369+#define ___GFP_USERCOPY 0x2000000u
78370+#else
78371+#define ___GFP_USERCOPY 0
78372+#endif
78373+
78374 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78375
78376 /*
78377@@ -93,6 +100,7 @@ struct vm_area_struct;
78378 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78379 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78380 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78381+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78382
78383 /*
78384 * This may seem redundant, but it's a way of annotating false positives vs.
78385@@ -100,7 +108,7 @@ struct vm_area_struct;
78386 */
78387 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78388
78389-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78390+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78391 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78392
78393 /* This equals 0, but use constants in case they ever change */
78394@@ -158,6 +166,8 @@ struct vm_area_struct;
78395 /* 4GB DMA on some platforms */
78396 #define GFP_DMA32 __GFP_DMA32
78397
78398+#define GFP_USERCOPY __GFP_USERCOPY
78399+
78400 /* Convert GFP flags to their corresponding migrate type */
78401 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78402 {
78403diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78404new file mode 100644
78405index 0000000..edb2cb6
78406--- /dev/null
78407+++ b/include/linux/gracl.h
78408@@ -0,0 +1,340 @@
78409+#ifndef GR_ACL_H
78410+#define GR_ACL_H
78411+
78412+#include <linux/grdefs.h>
78413+#include <linux/resource.h>
78414+#include <linux/capability.h>
78415+#include <linux/dcache.h>
78416+#include <asm/resource.h>
78417+
78418+/* Major status information */
78419+
78420+#define GR_VERSION "grsecurity 3.0"
78421+#define GRSECURITY_VERSION 0x3000
78422+
78423+enum {
78424+ GR_SHUTDOWN = 0,
78425+ GR_ENABLE = 1,
78426+ GR_SPROLE = 2,
78427+ GR_OLDRELOAD = 3,
78428+ GR_SEGVMOD = 4,
78429+ GR_STATUS = 5,
78430+ GR_UNSPROLE = 6,
78431+ GR_PASSSET = 7,
78432+ GR_SPROLEPAM = 8,
78433+ GR_RELOAD = 9,
78434+};
78435+
78436+/* Password setup definitions
78437+ * kernel/grhash.c */
78438+enum {
78439+ GR_PW_LEN = 128,
78440+ GR_SALT_LEN = 16,
78441+ GR_SHA_LEN = 32,
78442+};
78443+
78444+enum {
78445+ GR_SPROLE_LEN = 64,
78446+};
78447+
78448+enum {
78449+ GR_NO_GLOB = 0,
78450+ GR_REG_GLOB,
78451+ GR_CREATE_GLOB
78452+};
78453+
78454+#define GR_NLIMITS 32
78455+
78456+/* Begin Data Structures */
78457+
78458+struct sprole_pw {
78459+ unsigned char *rolename;
78460+ unsigned char salt[GR_SALT_LEN];
78461+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78462+};
78463+
78464+struct name_entry {
78465+ __u32 key;
78466+ ino_t inode;
78467+ dev_t device;
78468+ char *name;
78469+ __u16 len;
78470+ __u8 deleted;
78471+ struct name_entry *prev;
78472+ struct name_entry *next;
78473+};
78474+
78475+struct inodev_entry {
78476+ struct name_entry *nentry;
78477+ struct inodev_entry *prev;
78478+ struct inodev_entry *next;
78479+};
78480+
78481+struct acl_role_db {
78482+ struct acl_role_label **r_hash;
78483+ __u32 r_size;
78484+};
78485+
78486+struct inodev_db {
78487+ struct inodev_entry **i_hash;
78488+ __u32 i_size;
78489+};
78490+
78491+struct name_db {
78492+ struct name_entry **n_hash;
78493+ __u32 n_size;
78494+};
78495+
78496+struct crash_uid {
78497+ uid_t uid;
78498+ unsigned long expires;
78499+};
78500+
78501+struct gr_hash_struct {
78502+ void **table;
78503+ void **nametable;
78504+ void *first;
78505+ __u32 table_size;
78506+ __u32 used_size;
78507+ int type;
78508+};
78509+
78510+/* Userspace Grsecurity ACL data structures */
78511+
78512+struct acl_subject_label {
78513+ char *filename;
78514+ ino_t inode;
78515+ dev_t device;
78516+ __u32 mode;
78517+ kernel_cap_t cap_mask;
78518+ kernel_cap_t cap_lower;
78519+ kernel_cap_t cap_invert_audit;
78520+
78521+ struct rlimit res[GR_NLIMITS];
78522+ __u32 resmask;
78523+
78524+ __u8 user_trans_type;
78525+ __u8 group_trans_type;
78526+ uid_t *user_transitions;
78527+ gid_t *group_transitions;
78528+ __u16 user_trans_num;
78529+ __u16 group_trans_num;
78530+
78531+ __u32 sock_families[2];
78532+ __u32 ip_proto[8];
78533+ __u32 ip_type;
78534+ struct acl_ip_label **ips;
78535+ __u32 ip_num;
78536+ __u32 inaddr_any_override;
78537+
78538+ __u32 crashes;
78539+ unsigned long expires;
78540+
78541+ struct acl_subject_label *parent_subject;
78542+ struct gr_hash_struct *hash;
78543+ struct acl_subject_label *prev;
78544+ struct acl_subject_label *next;
78545+
78546+ struct acl_object_label **obj_hash;
78547+ __u32 obj_hash_size;
78548+ __u16 pax_flags;
78549+};
78550+
78551+struct role_allowed_ip {
78552+ __u32 addr;
78553+ __u32 netmask;
78554+
78555+ struct role_allowed_ip *prev;
78556+ struct role_allowed_ip *next;
78557+};
78558+
78559+struct role_transition {
78560+ char *rolename;
78561+
78562+ struct role_transition *prev;
78563+ struct role_transition *next;
78564+};
78565+
78566+struct acl_role_label {
78567+ char *rolename;
78568+ uid_t uidgid;
78569+ __u16 roletype;
78570+
78571+ __u16 auth_attempts;
78572+ unsigned long expires;
78573+
78574+ struct acl_subject_label *root_label;
78575+ struct gr_hash_struct *hash;
78576+
78577+ struct acl_role_label *prev;
78578+ struct acl_role_label *next;
78579+
78580+ struct role_transition *transitions;
78581+ struct role_allowed_ip *allowed_ips;
78582+ uid_t *domain_children;
78583+ __u16 domain_child_num;
78584+
78585+ umode_t umask;
78586+
78587+ struct acl_subject_label **subj_hash;
78588+ __u32 subj_hash_size;
78589+};
78590+
78591+struct user_acl_role_db {
78592+ struct acl_role_label **r_table;
78593+ __u32 num_pointers; /* Number of allocations to track */
78594+ __u32 num_roles; /* Number of roles */
78595+ __u32 num_domain_children; /* Number of domain children */
78596+ __u32 num_subjects; /* Number of subjects */
78597+ __u32 num_objects; /* Number of objects */
78598+};
78599+
78600+struct acl_object_label {
78601+ char *filename;
78602+ ino_t inode;
78603+ dev_t device;
78604+ __u32 mode;
78605+
78606+ struct acl_subject_label *nested;
78607+ struct acl_object_label *globbed;
78608+
78609+ /* next two structures not used */
78610+
78611+ struct acl_object_label *prev;
78612+ struct acl_object_label *next;
78613+};
78614+
78615+struct acl_ip_label {
78616+ char *iface;
78617+ __u32 addr;
78618+ __u32 netmask;
78619+ __u16 low, high;
78620+ __u8 mode;
78621+ __u32 type;
78622+ __u32 proto[8];
78623+
78624+ /* next two structures not used */
78625+
78626+ struct acl_ip_label *prev;
78627+ struct acl_ip_label *next;
78628+};
78629+
78630+struct gr_arg {
78631+ struct user_acl_role_db role_db;
78632+ unsigned char pw[GR_PW_LEN];
78633+ unsigned char salt[GR_SALT_LEN];
78634+ unsigned char sum[GR_SHA_LEN];
78635+ unsigned char sp_role[GR_SPROLE_LEN];
78636+ struct sprole_pw *sprole_pws;
78637+ dev_t segv_device;
78638+ ino_t segv_inode;
78639+ uid_t segv_uid;
78640+ __u16 num_sprole_pws;
78641+ __u16 mode;
78642+};
78643+
78644+struct gr_arg_wrapper {
78645+ struct gr_arg *arg;
78646+ __u32 version;
78647+ __u32 size;
78648+};
78649+
78650+struct subject_map {
78651+ struct acl_subject_label *user;
78652+ struct acl_subject_label *kernel;
78653+ struct subject_map *prev;
78654+ struct subject_map *next;
78655+};
78656+
78657+struct acl_subj_map_db {
78658+ struct subject_map **s_hash;
78659+ __u32 s_size;
78660+};
78661+
78662+struct gr_policy_state {
78663+ struct sprole_pw **acl_special_roles;
78664+ __u16 num_sprole_pws;
78665+ struct acl_role_label *kernel_role;
78666+ struct acl_role_label *role_list;
78667+ struct acl_role_label *default_role;
78668+ struct acl_role_db acl_role_set;
78669+ struct acl_subj_map_db subj_map_set;
78670+ struct name_db name_set;
78671+ struct inodev_db inodev_set;
78672+};
78673+
78674+struct gr_alloc_state {
78675+ unsigned long alloc_stack_next;
78676+ unsigned long alloc_stack_size;
78677+ void **alloc_stack;
78678+};
78679+
78680+struct gr_reload_state {
78681+ struct gr_policy_state oldpolicy;
78682+ struct gr_alloc_state oldalloc;
78683+ struct gr_policy_state newpolicy;
78684+ struct gr_alloc_state newalloc;
78685+ struct gr_policy_state *oldpolicy_ptr;
78686+ struct gr_alloc_state *oldalloc_ptr;
78687+ unsigned char oldmode;
78688+};
78689+
78690+/* End Data Structures Section */
78691+
78692+/* Hash functions generated by empirical testing by Brad Spengler
78693+ Makes good use of the low bits of the inode. Generally 0-1 times
78694+ in loop for successful match. 0-3 for unsuccessful match.
78695+ Shift/add algorithm with modulus of table size and an XOR*/
78696+
78697+static __inline__ unsigned int
78698+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78699+{
78700+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
78701+}
78702+
78703+ static __inline__ unsigned int
78704+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78705+{
78706+ return ((const unsigned long)userp % sz);
78707+}
78708+
78709+static __inline__ unsigned int
78710+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78711+{
78712+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78713+}
78714+
78715+static __inline__ unsigned int
78716+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78717+{
78718+ return full_name_hash((const unsigned char *)name, len) % sz;
78719+}
78720+
78721+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78722+ subj = NULL; \
78723+ iter = 0; \
78724+ while (iter < role->subj_hash_size) { \
78725+ if (subj == NULL) \
78726+ subj = role->subj_hash[iter]; \
78727+ if (subj == NULL) { \
78728+ iter++; \
78729+ continue; \
78730+ }
78731+
78732+#define FOR_EACH_SUBJECT_END(subj,iter) \
78733+ subj = subj->next; \
78734+ if (subj == NULL) \
78735+ iter++; \
78736+ }
78737+
78738+
78739+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78740+ subj = role->hash->first; \
78741+ while (subj != NULL) {
78742+
78743+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78744+ subj = subj->next; \
78745+ }
78746+
78747+#endif
78748+
78749diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78750new file mode 100644
78751index 0000000..33ebd1f
78752--- /dev/null
78753+++ b/include/linux/gracl_compat.h
78754@@ -0,0 +1,156 @@
78755+#ifndef GR_ACL_COMPAT_H
78756+#define GR_ACL_COMPAT_H
78757+
78758+#include <linux/resource.h>
78759+#include <asm/resource.h>
78760+
78761+struct sprole_pw_compat {
78762+ compat_uptr_t rolename;
78763+ unsigned char salt[GR_SALT_LEN];
78764+ unsigned char sum[GR_SHA_LEN];
78765+};
78766+
78767+struct gr_hash_struct_compat {
78768+ compat_uptr_t table;
78769+ compat_uptr_t nametable;
78770+ compat_uptr_t first;
78771+ __u32 table_size;
78772+ __u32 used_size;
78773+ int type;
78774+};
78775+
78776+struct acl_subject_label_compat {
78777+ compat_uptr_t filename;
78778+ compat_ino_t inode;
78779+ __u32 device;
78780+ __u32 mode;
78781+ kernel_cap_t cap_mask;
78782+ kernel_cap_t cap_lower;
78783+ kernel_cap_t cap_invert_audit;
78784+
78785+ struct compat_rlimit res[GR_NLIMITS];
78786+ __u32 resmask;
78787+
78788+ __u8 user_trans_type;
78789+ __u8 group_trans_type;
78790+ compat_uptr_t user_transitions;
78791+ compat_uptr_t group_transitions;
78792+ __u16 user_trans_num;
78793+ __u16 group_trans_num;
78794+
78795+ __u32 sock_families[2];
78796+ __u32 ip_proto[8];
78797+ __u32 ip_type;
78798+ compat_uptr_t ips;
78799+ __u32 ip_num;
78800+ __u32 inaddr_any_override;
78801+
78802+ __u32 crashes;
78803+ compat_ulong_t expires;
78804+
78805+ compat_uptr_t parent_subject;
78806+ compat_uptr_t hash;
78807+ compat_uptr_t prev;
78808+ compat_uptr_t next;
78809+
78810+ compat_uptr_t obj_hash;
78811+ __u32 obj_hash_size;
78812+ __u16 pax_flags;
78813+};
78814+
78815+struct role_allowed_ip_compat {
78816+ __u32 addr;
78817+ __u32 netmask;
78818+
78819+ compat_uptr_t prev;
78820+ compat_uptr_t next;
78821+};
78822+
78823+struct role_transition_compat {
78824+ compat_uptr_t rolename;
78825+
78826+ compat_uptr_t prev;
78827+ compat_uptr_t next;
78828+};
78829+
78830+struct acl_role_label_compat {
78831+ compat_uptr_t rolename;
78832+ uid_t uidgid;
78833+ __u16 roletype;
78834+
78835+ __u16 auth_attempts;
78836+ compat_ulong_t expires;
78837+
78838+ compat_uptr_t root_label;
78839+ compat_uptr_t hash;
78840+
78841+ compat_uptr_t prev;
78842+ compat_uptr_t next;
78843+
78844+ compat_uptr_t transitions;
78845+ compat_uptr_t allowed_ips;
78846+ compat_uptr_t domain_children;
78847+ __u16 domain_child_num;
78848+
78849+ umode_t umask;
78850+
78851+ compat_uptr_t subj_hash;
78852+ __u32 subj_hash_size;
78853+};
78854+
78855+struct user_acl_role_db_compat {
78856+ compat_uptr_t r_table;
78857+ __u32 num_pointers;
78858+ __u32 num_roles;
78859+ __u32 num_domain_children;
78860+ __u32 num_subjects;
78861+ __u32 num_objects;
78862+};
78863+
78864+struct acl_object_label_compat {
78865+ compat_uptr_t filename;
78866+ compat_ino_t inode;
78867+ __u32 device;
78868+ __u32 mode;
78869+
78870+ compat_uptr_t nested;
78871+ compat_uptr_t globbed;
78872+
78873+ compat_uptr_t prev;
78874+ compat_uptr_t next;
78875+};
78876+
78877+struct acl_ip_label_compat {
78878+ compat_uptr_t iface;
78879+ __u32 addr;
78880+ __u32 netmask;
78881+ __u16 low, high;
78882+ __u8 mode;
78883+ __u32 type;
78884+ __u32 proto[8];
78885+
78886+ compat_uptr_t prev;
78887+ compat_uptr_t next;
78888+};
78889+
78890+struct gr_arg_compat {
78891+ struct user_acl_role_db_compat role_db;
78892+ unsigned char pw[GR_PW_LEN];
78893+ unsigned char salt[GR_SALT_LEN];
78894+ unsigned char sum[GR_SHA_LEN];
78895+ unsigned char sp_role[GR_SPROLE_LEN];
78896+ compat_uptr_t sprole_pws;
78897+ __u32 segv_device;
78898+ compat_ino_t segv_inode;
78899+ uid_t segv_uid;
78900+ __u16 num_sprole_pws;
78901+ __u16 mode;
78902+};
78903+
78904+struct gr_arg_wrapper_compat {
78905+ compat_uptr_t arg;
78906+ __u32 version;
78907+ __u32 size;
78908+};
78909+
78910+#endif
78911diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
78912new file mode 100644
78913index 0000000..323ecf2
78914--- /dev/null
78915+++ b/include/linux/gralloc.h
78916@@ -0,0 +1,9 @@
78917+#ifndef __GRALLOC_H
78918+#define __GRALLOC_H
78919+
78920+void acl_free_all(void);
78921+int acl_alloc_stack_init(unsigned long size);
78922+void *acl_alloc(unsigned long len);
78923+void *acl_alloc_num(unsigned long num, unsigned long len);
78924+
78925+#endif
78926diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
78927new file mode 100644
78928index 0000000..be66033
78929--- /dev/null
78930+++ b/include/linux/grdefs.h
78931@@ -0,0 +1,140 @@
78932+#ifndef GRDEFS_H
78933+#define GRDEFS_H
78934+
78935+/* Begin grsecurity status declarations */
78936+
78937+enum {
78938+ GR_READY = 0x01,
78939+ GR_STATUS_INIT = 0x00 // disabled state
78940+};
78941+
78942+/* Begin ACL declarations */
78943+
78944+/* Role flags */
78945+
78946+enum {
78947+ GR_ROLE_USER = 0x0001,
78948+ GR_ROLE_GROUP = 0x0002,
78949+ GR_ROLE_DEFAULT = 0x0004,
78950+ GR_ROLE_SPECIAL = 0x0008,
78951+ GR_ROLE_AUTH = 0x0010,
78952+ GR_ROLE_NOPW = 0x0020,
78953+ GR_ROLE_GOD = 0x0040,
78954+ GR_ROLE_LEARN = 0x0080,
78955+ GR_ROLE_TPE = 0x0100,
78956+ GR_ROLE_DOMAIN = 0x0200,
78957+ GR_ROLE_PAM = 0x0400,
78958+ GR_ROLE_PERSIST = 0x0800
78959+};
78960+
78961+/* ACL Subject and Object mode flags */
78962+enum {
78963+ GR_DELETED = 0x80000000
78964+};
78965+
78966+/* ACL Object-only mode flags */
78967+enum {
78968+ GR_READ = 0x00000001,
78969+ GR_APPEND = 0x00000002,
78970+ GR_WRITE = 0x00000004,
78971+ GR_EXEC = 0x00000008,
78972+ GR_FIND = 0x00000010,
78973+ GR_INHERIT = 0x00000020,
78974+ GR_SETID = 0x00000040,
78975+ GR_CREATE = 0x00000080,
78976+ GR_DELETE = 0x00000100,
78977+ GR_LINK = 0x00000200,
78978+ GR_AUDIT_READ = 0x00000400,
78979+ GR_AUDIT_APPEND = 0x00000800,
78980+ GR_AUDIT_WRITE = 0x00001000,
78981+ GR_AUDIT_EXEC = 0x00002000,
78982+ GR_AUDIT_FIND = 0x00004000,
78983+ GR_AUDIT_INHERIT= 0x00008000,
78984+ GR_AUDIT_SETID = 0x00010000,
78985+ GR_AUDIT_CREATE = 0x00020000,
78986+ GR_AUDIT_DELETE = 0x00040000,
78987+ GR_AUDIT_LINK = 0x00080000,
78988+ GR_PTRACERD = 0x00100000,
78989+ GR_NOPTRACE = 0x00200000,
78990+ GR_SUPPRESS = 0x00400000,
78991+ GR_NOLEARN = 0x00800000,
78992+ GR_INIT_TRANSFER= 0x01000000
78993+};
78994+
78995+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
78996+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
78997+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
78998+
78999+/* ACL subject-only mode flags */
79000+enum {
79001+ GR_KILL = 0x00000001,
79002+ GR_VIEW = 0x00000002,
79003+ GR_PROTECTED = 0x00000004,
79004+ GR_LEARN = 0x00000008,
79005+ GR_OVERRIDE = 0x00000010,
79006+ /* just a placeholder, this mode is only used in userspace */
79007+ GR_DUMMY = 0x00000020,
79008+ GR_PROTSHM = 0x00000040,
79009+ GR_KILLPROC = 0x00000080,
79010+ GR_KILLIPPROC = 0x00000100,
79011+ /* just a placeholder, this mode is only used in userspace */
79012+ GR_NOTROJAN = 0x00000200,
79013+ GR_PROTPROCFD = 0x00000400,
79014+ GR_PROCACCT = 0x00000800,
79015+ GR_RELAXPTRACE = 0x00001000,
79016+ //GR_NESTED = 0x00002000,
79017+ GR_INHERITLEARN = 0x00004000,
79018+ GR_PROCFIND = 0x00008000,
79019+ GR_POVERRIDE = 0x00010000,
79020+ GR_KERNELAUTH = 0x00020000,
79021+ GR_ATSECURE = 0x00040000,
79022+ GR_SHMEXEC = 0x00080000
79023+};
79024+
79025+enum {
79026+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79027+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79028+ GR_PAX_ENABLE_MPROTECT = 0x0004,
79029+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
79030+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79031+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79032+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79033+ GR_PAX_DISABLE_MPROTECT = 0x0400,
79034+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
79035+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79036+};
79037+
79038+enum {
79039+ GR_ID_USER = 0x01,
79040+ GR_ID_GROUP = 0x02,
79041+};
79042+
79043+enum {
79044+ GR_ID_ALLOW = 0x01,
79045+ GR_ID_DENY = 0x02,
79046+};
79047+
79048+#define GR_CRASH_RES 31
79049+#define GR_UIDTABLE_MAX 500
79050+
79051+/* begin resource learning section */
79052+enum {
79053+ GR_RLIM_CPU_BUMP = 60,
79054+ GR_RLIM_FSIZE_BUMP = 50000,
79055+ GR_RLIM_DATA_BUMP = 10000,
79056+ GR_RLIM_STACK_BUMP = 1000,
79057+ GR_RLIM_CORE_BUMP = 10000,
79058+ GR_RLIM_RSS_BUMP = 500000,
79059+ GR_RLIM_NPROC_BUMP = 1,
79060+ GR_RLIM_NOFILE_BUMP = 5,
79061+ GR_RLIM_MEMLOCK_BUMP = 50000,
79062+ GR_RLIM_AS_BUMP = 500000,
79063+ GR_RLIM_LOCKS_BUMP = 2,
79064+ GR_RLIM_SIGPENDING_BUMP = 5,
79065+ GR_RLIM_MSGQUEUE_BUMP = 10000,
79066+ GR_RLIM_NICE_BUMP = 1,
79067+ GR_RLIM_RTPRIO_BUMP = 1,
79068+ GR_RLIM_RTTIME_BUMP = 1000000
79069+};
79070+
79071+#endif
79072diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79073new file mode 100644
79074index 0000000..d25522e
79075--- /dev/null
79076+++ b/include/linux/grinternal.h
79077@@ -0,0 +1,229 @@
79078+#ifndef __GRINTERNAL_H
79079+#define __GRINTERNAL_H
79080+
79081+#ifdef CONFIG_GRKERNSEC
79082+
79083+#include <linux/fs.h>
79084+#include <linux/mnt_namespace.h>
79085+#include <linux/nsproxy.h>
79086+#include <linux/gracl.h>
79087+#include <linux/grdefs.h>
79088+#include <linux/grmsg.h>
79089+
79090+void gr_add_learn_entry(const char *fmt, ...)
79091+ __attribute__ ((format (printf, 1, 2)));
79092+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79093+ const struct vfsmount *mnt);
79094+__u32 gr_check_create(const struct dentry *new_dentry,
79095+ const struct dentry *parent,
79096+ const struct vfsmount *mnt, const __u32 mode);
79097+int gr_check_protected_task(const struct task_struct *task);
79098+__u32 to_gr_audit(const __u32 reqmode);
79099+int gr_set_acls(const int type);
79100+int gr_acl_is_enabled(void);
79101+char gr_roletype_to_char(void);
79102+
79103+void gr_handle_alertkill(struct task_struct *task);
79104+char *gr_to_filename(const struct dentry *dentry,
79105+ const struct vfsmount *mnt);
79106+char *gr_to_filename1(const struct dentry *dentry,
79107+ const struct vfsmount *mnt);
79108+char *gr_to_filename2(const struct dentry *dentry,
79109+ const struct vfsmount *mnt);
79110+char *gr_to_filename3(const struct dentry *dentry,
79111+ const struct vfsmount *mnt);
79112+
79113+extern int grsec_enable_ptrace_readexec;
79114+extern int grsec_enable_harden_ptrace;
79115+extern int grsec_enable_link;
79116+extern int grsec_enable_fifo;
79117+extern int grsec_enable_execve;
79118+extern int grsec_enable_shm;
79119+extern int grsec_enable_execlog;
79120+extern int grsec_enable_signal;
79121+extern int grsec_enable_audit_ptrace;
79122+extern int grsec_enable_forkfail;
79123+extern int grsec_enable_time;
79124+extern int grsec_enable_rofs;
79125+extern int grsec_deny_new_usb;
79126+extern int grsec_enable_chroot_shmat;
79127+extern int grsec_enable_chroot_mount;
79128+extern int grsec_enable_chroot_double;
79129+extern int grsec_enable_chroot_pivot;
79130+extern int grsec_enable_chroot_chdir;
79131+extern int grsec_enable_chroot_chmod;
79132+extern int grsec_enable_chroot_mknod;
79133+extern int grsec_enable_chroot_fchdir;
79134+extern int grsec_enable_chroot_nice;
79135+extern int grsec_enable_chroot_execlog;
79136+extern int grsec_enable_chroot_caps;
79137+extern int grsec_enable_chroot_sysctl;
79138+extern int grsec_enable_chroot_unix;
79139+extern int grsec_enable_symlinkown;
79140+extern kgid_t grsec_symlinkown_gid;
79141+extern int grsec_enable_tpe;
79142+extern kgid_t grsec_tpe_gid;
79143+extern int grsec_enable_tpe_all;
79144+extern int grsec_enable_tpe_invert;
79145+extern int grsec_enable_socket_all;
79146+extern kgid_t grsec_socket_all_gid;
79147+extern int grsec_enable_socket_client;
79148+extern kgid_t grsec_socket_client_gid;
79149+extern int grsec_enable_socket_server;
79150+extern kgid_t grsec_socket_server_gid;
79151+extern kgid_t grsec_audit_gid;
79152+extern int grsec_enable_group;
79153+extern int grsec_enable_log_rwxmaps;
79154+extern int grsec_enable_mount;
79155+extern int grsec_enable_chdir;
79156+extern int grsec_resource_logging;
79157+extern int grsec_enable_blackhole;
79158+extern int grsec_lastack_retries;
79159+extern int grsec_enable_brute;
79160+extern int grsec_enable_harden_ipc;
79161+extern int grsec_lock;
79162+
79163+extern spinlock_t grsec_alert_lock;
79164+extern unsigned long grsec_alert_wtime;
79165+extern unsigned long grsec_alert_fyet;
79166+
79167+extern spinlock_t grsec_audit_lock;
79168+
79169+extern rwlock_t grsec_exec_file_lock;
79170+
79171+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79172+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79173+ (tsk)->exec_file->f_path.mnt) : "/")
79174+
79175+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79176+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79177+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79178+
79179+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79180+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
79181+ (tsk)->exec_file->f_path.mnt) : "/")
79182+
79183+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79184+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79185+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79186+
79187+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79188+
79189+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79190+
79191+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79192+{
79193+ if (file1 && file2) {
79194+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
79195+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
79196+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79197+ return true;
79198+ }
79199+
79200+ return false;
79201+}
79202+
79203+#define GR_CHROOT_CAPS {{ \
79204+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79205+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79206+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79207+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79208+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79209+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79210+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79211+
79212+#define security_learn(normal_msg,args...) \
79213+({ \
79214+ read_lock(&grsec_exec_file_lock); \
79215+ gr_add_learn_entry(normal_msg "\n", ## args); \
79216+ read_unlock(&grsec_exec_file_lock); \
79217+})
79218+
79219+enum {
79220+ GR_DO_AUDIT,
79221+ GR_DONT_AUDIT,
79222+ /* used for non-audit messages that we shouldn't kill the task on */
79223+ GR_DONT_AUDIT_GOOD
79224+};
79225+
79226+enum {
79227+ GR_TTYSNIFF,
79228+ GR_RBAC,
79229+ GR_RBAC_STR,
79230+ GR_STR_RBAC,
79231+ GR_RBAC_MODE2,
79232+ GR_RBAC_MODE3,
79233+ GR_FILENAME,
79234+ GR_SYSCTL_HIDDEN,
79235+ GR_NOARGS,
79236+ GR_ONE_INT,
79237+ GR_ONE_INT_TWO_STR,
79238+ GR_ONE_STR,
79239+ GR_STR_INT,
79240+ GR_TWO_STR_INT,
79241+ GR_TWO_INT,
79242+ GR_TWO_U64,
79243+ GR_THREE_INT,
79244+ GR_FIVE_INT_TWO_STR,
79245+ GR_TWO_STR,
79246+ GR_THREE_STR,
79247+ GR_FOUR_STR,
79248+ GR_STR_FILENAME,
79249+ GR_FILENAME_STR,
79250+ GR_FILENAME_TWO_INT,
79251+ GR_FILENAME_TWO_INT_STR,
79252+ GR_TEXTREL,
79253+ GR_PTRACE,
79254+ GR_RESOURCE,
79255+ GR_CAP,
79256+ GR_SIG,
79257+ GR_SIG2,
79258+ GR_CRASH1,
79259+ GR_CRASH2,
79260+ GR_PSACCT,
79261+ GR_RWXMAP,
79262+ GR_RWXMAPVMA
79263+};
79264+
79265+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79266+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79267+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79268+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79269+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79270+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79271+#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)
79272+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79273+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79274+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79275+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79276+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79277+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79278+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79279+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79280+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79281+#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)
79282+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79283+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79284+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79285+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79286+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79287+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79288+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79289+#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)
79290+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79291+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79292+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79293+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79294+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79295+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79296+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79297+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79298+#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)
79299+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79300+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79301+
79302+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79303+
79304+#endif
79305+
79306+#endif
79307diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79308new file mode 100644
79309index 0000000..b02ba9d
79310--- /dev/null
79311+++ b/include/linux/grmsg.h
79312@@ -0,0 +1,117 @@
79313+#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"
79314+#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"
79315+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79316+#define GR_STOPMOD_MSG "denied modification of module state by "
79317+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79318+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79319+#define GR_IOPERM_MSG "denied use of ioperm() by "
79320+#define GR_IOPL_MSG "denied use of iopl() by "
79321+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79322+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79323+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79324+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79325+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79326+#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"
79327+#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"
79328+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79329+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79330+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79331+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79332+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79333+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79334+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79335+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79336+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79337+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79338+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79339+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79340+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79341+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79342+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79343+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79344+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79345+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79346+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79347+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79348+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79349+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79350+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79351+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79352+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79353+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79354+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79355+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79356+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79357+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79358+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79359+#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
79360+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79361+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79362+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79363+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79364+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79365+#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"
79366+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79367+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79368+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79369+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79370+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79371+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79372+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79373+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79374+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79375+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79376+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79377+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79378+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79379+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79380+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79381+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79382+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79383+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79384+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79385+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79386+#define GR_FAILFORK_MSG "failed fork with errno %s by "
79387+#define GR_NICE_CHROOT_MSG "denied priority change by "
79388+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79389+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79390+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79391+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79392+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79393+#define GR_TIME_MSG "time set by "
79394+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79395+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79396+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79397+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79398+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79399+#define GR_BIND_MSG "denied bind() by "
79400+#define GR_CONNECT_MSG "denied connect() by "
79401+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79402+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79403+#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"
79404+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79405+#define GR_CAP_ACL_MSG "use of %s denied for "
79406+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79407+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79408+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79409+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79410+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79411+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79412+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79413+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79414+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79415+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79416+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79417+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79418+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79419+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79420+#define GR_VM86_MSG "denied use of vm86 by "
79421+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79422+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79423+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79424+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79425+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79426+#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 "
79427+#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 "
79428+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79429+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79430diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79431new file mode 100644
79432index 0000000..13ac2e2
79433--- /dev/null
79434+++ b/include/linux/grsecurity.h
79435@@ -0,0 +1,249 @@
79436+#ifndef GR_SECURITY_H
79437+#define GR_SECURITY_H
79438+#include <linux/fs.h>
79439+#include <linux/fs_struct.h>
79440+#include <linux/binfmts.h>
79441+#include <linux/gracl.h>
79442+
79443+/* notify of brain-dead configs */
79444+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79445+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79446+#endif
79447+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79448+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79449+#endif
79450+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79451+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79452+#endif
79453+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79454+#error "CONFIG_PAX enabled, but no PaX options are enabled."
79455+#endif
79456+
79457+int gr_handle_new_usb(void);
79458+
79459+void gr_handle_brute_attach(int dumpable);
79460+void gr_handle_brute_check(void);
79461+void gr_handle_kernel_exploit(void);
79462+
79463+char gr_roletype_to_char(void);
79464+
79465+int gr_proc_is_restricted(void);
79466+
79467+int gr_acl_enable_at_secure(void);
79468+
79469+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79470+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79471+
79472+void gr_del_task_from_ip_table(struct task_struct *p);
79473+
79474+int gr_pid_is_chrooted(struct task_struct *p);
79475+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79476+int gr_handle_chroot_nice(void);
79477+int gr_handle_chroot_sysctl(const int op);
79478+int gr_handle_chroot_setpriority(struct task_struct *p,
79479+ const int niceval);
79480+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79481+int gr_chroot_fhandle(void);
79482+int gr_handle_chroot_chroot(const struct dentry *dentry,
79483+ const struct vfsmount *mnt);
79484+void gr_handle_chroot_chdir(const struct path *path);
79485+int gr_handle_chroot_chmod(const struct dentry *dentry,
79486+ const struct vfsmount *mnt, const int mode);
79487+int gr_handle_chroot_mknod(const struct dentry *dentry,
79488+ const struct vfsmount *mnt, const int mode);
79489+int gr_handle_chroot_mount(const struct dentry *dentry,
79490+ const struct vfsmount *mnt,
79491+ const char *dev_name);
79492+int gr_handle_chroot_pivot(void);
79493+int gr_handle_chroot_unix(const pid_t pid);
79494+
79495+int gr_handle_rawio(const struct inode *inode);
79496+
79497+void gr_handle_ioperm(void);
79498+void gr_handle_iopl(void);
79499+void gr_handle_msr_write(void);
79500+
79501+umode_t gr_acl_umask(void);
79502+
79503+int gr_tpe_allow(const struct file *file);
79504+
79505+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79506+void gr_clear_chroot_entries(struct task_struct *task);
79507+
79508+void gr_log_forkfail(const int retval);
79509+void gr_log_timechange(void);
79510+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79511+void gr_log_chdir(const struct dentry *dentry,
79512+ const struct vfsmount *mnt);
79513+void gr_log_chroot_exec(const struct dentry *dentry,
79514+ const struct vfsmount *mnt);
79515+void gr_log_remount(const char *devname, const int retval);
79516+void gr_log_unmount(const char *devname, const int retval);
79517+void gr_log_mount(const char *from, const char *to, const int retval);
79518+void gr_log_textrel(struct vm_area_struct *vma);
79519+void gr_log_ptgnustack(struct file *file);
79520+void gr_log_rwxmmap(struct file *file);
79521+void gr_log_rwxmprotect(struct vm_area_struct *vma);
79522+
79523+int gr_handle_follow_link(const struct inode *parent,
79524+ const struct inode *inode,
79525+ const struct dentry *dentry,
79526+ const struct vfsmount *mnt);
79527+int gr_handle_fifo(const struct dentry *dentry,
79528+ const struct vfsmount *mnt,
79529+ const struct dentry *dir, const int flag,
79530+ const int acc_mode);
79531+int gr_handle_hardlink(const struct dentry *dentry,
79532+ const struct vfsmount *mnt,
79533+ struct inode *inode,
79534+ const int mode, const struct filename *to);
79535+
79536+int gr_is_capable(const int cap);
79537+int gr_is_capable_nolog(const int cap);
79538+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79539+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79540+
79541+void gr_copy_label(struct task_struct *tsk);
79542+void gr_handle_crash(struct task_struct *task, const int sig);
79543+int gr_handle_signal(const struct task_struct *p, const int sig);
79544+int gr_check_crash_uid(const kuid_t uid);
79545+int gr_check_protected_task(const struct task_struct *task);
79546+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79547+int gr_acl_handle_mmap(const struct file *file,
79548+ const unsigned long prot);
79549+int gr_acl_handle_mprotect(const struct file *file,
79550+ const unsigned long prot);
79551+int gr_check_hidden_task(const struct task_struct *tsk);
79552+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79553+ const struct vfsmount *mnt);
79554+__u32 gr_acl_handle_utime(const struct dentry *dentry,
79555+ const struct vfsmount *mnt);
79556+__u32 gr_acl_handle_access(const struct dentry *dentry,
79557+ const struct vfsmount *mnt, const int fmode);
79558+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79559+ const struct vfsmount *mnt, umode_t *mode);
79560+__u32 gr_acl_handle_chown(const struct dentry *dentry,
79561+ const struct vfsmount *mnt);
79562+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79563+ const struct vfsmount *mnt);
79564+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79565+ const struct vfsmount *mnt);
79566+int gr_handle_ptrace(struct task_struct *task, const long request);
79567+int gr_handle_proc_ptrace(struct task_struct *task);
79568+__u32 gr_acl_handle_execve(const struct dentry *dentry,
79569+ const struct vfsmount *mnt);
79570+int gr_check_crash_exec(const struct file *filp);
79571+int gr_acl_is_enabled(void);
79572+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79573+ const kgid_t gid);
79574+int gr_set_proc_label(const struct dentry *dentry,
79575+ const struct vfsmount *mnt,
79576+ const int unsafe_flags);
79577+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79578+ const struct vfsmount *mnt);
79579+__u32 gr_acl_handle_open(const struct dentry *dentry,
79580+ const struct vfsmount *mnt, int acc_mode);
79581+__u32 gr_acl_handle_creat(const struct dentry *dentry,
79582+ const struct dentry *p_dentry,
79583+ const struct vfsmount *p_mnt,
79584+ int open_flags, int acc_mode, const int imode);
79585+void gr_handle_create(const struct dentry *dentry,
79586+ const struct vfsmount *mnt);
79587+void gr_handle_proc_create(const struct dentry *dentry,
79588+ const struct inode *inode);
79589+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79590+ const struct dentry *parent_dentry,
79591+ const struct vfsmount *parent_mnt,
79592+ const int mode);
79593+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79594+ const struct dentry *parent_dentry,
79595+ const struct vfsmount *parent_mnt);
79596+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79597+ const struct vfsmount *mnt);
79598+void gr_handle_delete(const ino_t ino, const dev_t dev);
79599+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79600+ const struct vfsmount *mnt);
79601+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79602+ const struct dentry *parent_dentry,
79603+ const struct vfsmount *parent_mnt,
79604+ const struct filename *from);
79605+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79606+ const struct dentry *parent_dentry,
79607+ const struct vfsmount *parent_mnt,
79608+ const struct dentry *old_dentry,
79609+ const struct vfsmount *old_mnt, const struct filename *to);
79610+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79611+int gr_acl_handle_rename(struct dentry *new_dentry,
79612+ struct dentry *parent_dentry,
79613+ const struct vfsmount *parent_mnt,
79614+ struct dentry *old_dentry,
79615+ struct inode *old_parent_inode,
79616+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
79617+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79618+ struct dentry *old_dentry,
79619+ struct dentry *new_dentry,
79620+ struct vfsmount *mnt, const __u8 replace, unsigned int flags);
79621+__u32 gr_check_link(const struct dentry *new_dentry,
79622+ const struct dentry *parent_dentry,
79623+ const struct vfsmount *parent_mnt,
79624+ const struct dentry *old_dentry,
79625+ const struct vfsmount *old_mnt);
79626+int gr_acl_handle_filldir(const struct file *file, const char *name,
79627+ const unsigned int namelen, const ino_t ino);
79628+
79629+__u32 gr_acl_handle_unix(const struct dentry *dentry,
79630+ const struct vfsmount *mnt);
79631+void gr_acl_handle_exit(void);
79632+void gr_acl_handle_psacct(struct task_struct *task, const long code);
79633+int gr_acl_handle_procpidmem(const struct task_struct *task);
79634+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79635+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79636+void gr_audit_ptrace(struct task_struct *task);
79637+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79638+void gr_put_exec_file(struct task_struct *task);
79639+
79640+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79641+
79642+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79643+extern void gr_learn_resource(const struct task_struct *task, const int res,
79644+ const unsigned long wanted, const int gt);
79645+#else
79646+static inline void gr_learn_resource(const struct task_struct *task, const int res,
79647+ const unsigned long wanted, const int gt)
79648+{
79649+}
79650+#endif
79651+
79652+#ifdef CONFIG_GRKERNSEC_RESLOG
79653+extern void gr_log_resource(const struct task_struct *task, const int res,
79654+ const unsigned long wanted, const int gt);
79655+#else
79656+static inline void gr_log_resource(const struct task_struct *task, const int res,
79657+ const unsigned long wanted, const int gt)
79658+{
79659+}
79660+#endif
79661+
79662+#ifdef CONFIG_GRKERNSEC
79663+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79664+void gr_handle_vm86(void);
79665+void gr_handle_mem_readwrite(u64 from, u64 to);
79666+
79667+void gr_log_badprocpid(const char *entry);
79668+
79669+extern int grsec_enable_dmesg;
79670+extern int grsec_disable_privio;
79671+
79672+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79673+extern kgid_t grsec_proc_gid;
79674+#endif
79675+
79676+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79677+extern int grsec_enable_chroot_findtask;
79678+#endif
79679+#ifdef CONFIG_GRKERNSEC_SETXID
79680+extern int grsec_enable_setxid;
79681+#endif
79682+#endif
79683+
79684+#endif
79685diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79686new file mode 100644
79687index 0000000..e7ffaaf
79688--- /dev/null
79689+++ b/include/linux/grsock.h
79690@@ -0,0 +1,19 @@
79691+#ifndef __GRSOCK_H
79692+#define __GRSOCK_H
79693+
79694+extern void gr_attach_curr_ip(const struct sock *sk);
79695+extern int gr_handle_sock_all(const int family, const int type,
79696+ const int protocol);
79697+extern int gr_handle_sock_server(const struct sockaddr *sck);
79698+extern int gr_handle_sock_server_other(const struct sock *sck);
79699+extern int gr_handle_sock_client(const struct sockaddr *sck);
79700+extern int gr_search_connect(struct socket * sock,
79701+ struct sockaddr_in * addr);
79702+extern int gr_search_bind(struct socket * sock,
79703+ struct sockaddr_in * addr);
79704+extern int gr_search_listen(struct socket * sock);
79705+extern int gr_search_accept(struct socket * sock);
79706+extern int gr_search_socket(const int domain, const int type,
79707+ const int protocol);
79708+
79709+#endif
79710diff --git a/include/linux/hash.h b/include/linux/hash.h
79711index bd1754c..8240892 100644
79712--- a/include/linux/hash.h
79713+++ b/include/linux/hash.h
79714@@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
79715 struct fast_hash_ops {
79716 u32 (*hash)(const void *data, u32 len, u32 seed);
79717 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
79718-};
79719+} __no_const;
79720
79721 /**
79722 * arch_fast_hash - Caclulates a hash over a given buffer that can have
79723diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79724index 7fb31da..08b5114 100644
79725--- a/include/linux/highmem.h
79726+++ b/include/linux/highmem.h
79727@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79728 kunmap_atomic(kaddr);
79729 }
79730
79731+static inline void sanitize_highpage(struct page *page)
79732+{
79733+ void *kaddr;
79734+ unsigned long flags;
79735+
79736+ local_irq_save(flags);
79737+ kaddr = kmap_atomic(page);
79738+ clear_page(kaddr);
79739+ kunmap_atomic(kaddr);
79740+ local_irq_restore(flags);
79741+}
79742+
79743 static inline void zero_user_segments(struct page *page,
79744 unsigned start1, unsigned end1,
79745 unsigned start2, unsigned end2)
79746diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79747index 1c7b89a..7dda400 100644
79748--- a/include/linux/hwmon-sysfs.h
79749+++ b/include/linux/hwmon-sysfs.h
79750@@ -25,7 +25,8 @@
79751 struct sensor_device_attribute{
79752 struct device_attribute dev_attr;
79753 int index;
79754-};
79755+} __do_const;
79756+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79757 #define to_sensor_dev_attr(_dev_attr) \
79758 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79759
79760@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79761 struct device_attribute dev_attr;
79762 u8 index;
79763 u8 nr;
79764-};
79765+} __do_const;
79766+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79767 #define to_sensor_dev_attr_2(_dev_attr) \
79768 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79769
79770diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79771index b556e0a..c10a515 100644
79772--- a/include/linux/i2c.h
79773+++ b/include/linux/i2c.h
79774@@ -378,6 +378,7 @@ struct i2c_algorithm {
79775 /* To determine what the adapter supports */
79776 u32 (*functionality) (struct i2c_adapter *);
79777 };
79778+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79779
79780 /**
79781 * struct i2c_bus_recovery_info - I2C bus recovery information
79782diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79783index d23c3c2..eb63c81 100644
79784--- a/include/linux/i2o.h
79785+++ b/include/linux/i2o.h
79786@@ -565,7 +565,7 @@ struct i2o_controller {
79787 struct i2o_device *exec; /* Executive */
79788 #if BITS_PER_LONG == 64
79789 spinlock_t context_list_lock; /* lock for context_list */
79790- atomic_t context_list_counter; /* needed for unique contexts */
79791+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79792 struct list_head context_list; /* list of context id's
79793 and pointers */
79794 #endif
79795diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79796index aff7ad8..3942bbd 100644
79797--- a/include/linux/if_pppox.h
79798+++ b/include/linux/if_pppox.h
79799@@ -76,7 +76,7 @@ struct pppox_proto {
79800 int (*ioctl)(struct socket *sock, unsigned int cmd,
79801 unsigned long arg);
79802 struct module *owner;
79803-};
79804+} __do_const;
79805
79806 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79807 extern void unregister_pppox_proto(int proto_num);
79808diff --git a/include/linux/init.h b/include/linux/init.h
79809index a3ba270..a1b6604 100644
79810--- a/include/linux/init.h
79811+++ b/include/linux/init.h
79812@@ -37,9 +37,17 @@
79813 * section.
79814 */
79815
79816+#define add_init_latent_entropy __latent_entropy
79817+
79818+#ifdef CONFIG_MEMORY_HOTPLUG
79819+#define add_meminit_latent_entropy
79820+#else
79821+#define add_meminit_latent_entropy __latent_entropy
79822+#endif
79823+
79824 /* These are for everybody (although not all archs will actually
79825 discard it in modules) */
79826-#define __init __section(.init.text) __cold notrace
79827+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79828 #define __initdata __section(.init.data)
79829 #define __initconst __constsection(.init.rodata)
79830 #define __exitdata __section(.exit.data)
79831@@ -100,7 +108,7 @@
79832 #define __cpuexitconst
79833
79834 /* Used for MEMORY_HOTPLUG */
79835-#define __meminit __section(.meminit.text) __cold notrace
79836+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79837 #define __meminitdata __section(.meminit.data)
79838 #define __meminitconst __constsection(.meminit.rodata)
79839 #define __memexit __section(.memexit.text) __exitused __cold notrace
79840diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79841index 6df7f9f..d0bf699 100644
79842--- a/include/linux/init_task.h
79843+++ b/include/linux/init_task.h
79844@@ -156,6 +156,12 @@ extern struct task_group root_task_group;
79845
79846 #define INIT_TASK_COMM "swapper"
79847
79848+#ifdef CONFIG_X86
79849+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79850+#else
79851+#define INIT_TASK_THREAD_INFO
79852+#endif
79853+
79854 #ifdef CONFIG_RT_MUTEXES
79855 # define INIT_RT_MUTEXES(tsk) \
79856 .pi_waiters = RB_ROOT, \
79857@@ -203,6 +209,7 @@ extern struct task_group root_task_group;
79858 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79859 .comm = INIT_TASK_COMM, \
79860 .thread = INIT_THREAD, \
79861+ INIT_TASK_THREAD_INFO \
79862 .fs = &init_fs, \
79863 .files = &init_files, \
79864 .signal = &init_signals, \
79865diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79866index 051c850..431f83a 100644
79867--- a/include/linux/interrupt.h
79868+++ b/include/linux/interrupt.h
79869@@ -412,8 +412,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
79870
79871 struct softirq_action
79872 {
79873- void (*action)(struct softirq_action *);
79874-};
79875+ void (*action)(void);
79876+} __no_const;
79877
79878 asmlinkage void do_softirq(void);
79879 asmlinkage void __do_softirq(void);
79880@@ -427,7 +427,7 @@ static inline void do_softirq_own_stack(void)
79881 }
79882 #endif
79883
79884-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
79885+extern void open_softirq(int nr, void (*action)(void));
79886 extern void softirq_init(void);
79887 extern void __raise_softirq_irqoff(unsigned int nr);
79888
79889diff --git a/include/linux/iommu.h b/include/linux/iommu.h
79890index b96a5b2..2732d1c 100644
79891--- a/include/linux/iommu.h
79892+++ b/include/linux/iommu.h
79893@@ -131,7 +131,7 @@ struct iommu_ops {
79894 u32 (*domain_get_windows)(struct iommu_domain *domain);
79895
79896 unsigned long pgsize_bitmap;
79897-};
79898+} __do_const;
79899
79900 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
79901 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
79902diff --git a/include/linux/ioport.h b/include/linux/ioport.h
79903index 5e3a906..3131d0f 100644
79904--- a/include/linux/ioport.h
79905+++ b/include/linux/ioport.h
79906@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
79907 int adjust_resource(struct resource *res, resource_size_t start,
79908 resource_size_t size);
79909 resource_size_t resource_alignment(struct resource *res);
79910-static inline resource_size_t resource_size(const struct resource *res)
79911+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
79912 {
79913 return res->end - res->start + 1;
79914 }
79915diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
79916index 35e7eca..6afb7ad 100644
79917--- a/include/linux/ipc_namespace.h
79918+++ b/include/linux/ipc_namespace.h
79919@@ -69,7 +69,7 @@ struct ipc_namespace {
79920 struct user_namespace *user_ns;
79921
79922 unsigned int proc_inum;
79923-};
79924+} __randomize_layout;
79925
79926 extern struct ipc_namespace init_ipc_ns;
79927 extern atomic_t nr_ipc_ns;
79928diff --git a/include/linux/irq.h b/include/linux/irq.h
79929index 5c57efb..965a62b 100644
79930--- a/include/linux/irq.h
79931+++ b/include/linux/irq.h
79932@@ -344,7 +344,8 @@ struct irq_chip {
79933 void (*irq_release_resources)(struct irq_data *data);
79934
79935 unsigned long flags;
79936-};
79937+} __do_const;
79938+typedef struct irq_chip __no_const irq_chip_no_const;
79939
79940 /*
79941 * irq_chip specific flags
79942diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
79943index 7ed92d0..589abf5 100644
79944--- a/include/linux/irqchip/arm-gic.h
79945+++ b/include/linux/irqchip/arm-gic.h
79946@@ -73,9 +73,11 @@
79947
79948 #ifndef __ASSEMBLY__
79949
79950+#include <linux/irq.h>
79951+
79952 struct device_node;
79953
79954-extern struct irq_chip gic_arch_extn;
79955+extern irq_chip_no_const gic_arch_extn;
79956
79957 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
79958 u32 offset, struct device_node *);
79959diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
79960index 1f44466..b481806 100644
79961--- a/include/linux/jiffies.h
79962+++ b/include/linux/jiffies.h
79963@@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
79964 /*
79965 * Convert various time units to each other:
79966 */
79967-extern unsigned int jiffies_to_msecs(const unsigned long j);
79968-extern unsigned int jiffies_to_usecs(const unsigned long j);
79969+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
79970+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
79971
79972-static inline u64 jiffies_to_nsecs(const unsigned long j)
79973+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
79974 {
79975 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
79976 }
79977
79978-extern unsigned long msecs_to_jiffies(const unsigned int m);
79979-extern unsigned long usecs_to_jiffies(const unsigned int u);
79980+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
79981+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
79982 extern unsigned long timespec_to_jiffies(const struct timespec *value);
79983 extern void jiffies_to_timespec(const unsigned long jiffies,
79984- struct timespec *value);
79985-extern unsigned long timeval_to_jiffies(const struct timeval *value);
79986+ struct timespec *value) __intentional_overflow(-1);
79987+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
79988 extern void jiffies_to_timeval(const unsigned long jiffies,
79989 struct timeval *value);
79990
79991diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
79992index 6883e19..e854fcb 100644
79993--- a/include/linux/kallsyms.h
79994+++ b/include/linux/kallsyms.h
79995@@ -15,7 +15,8 @@
79996
79997 struct module;
79998
79999-#ifdef CONFIG_KALLSYMS
80000+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80001+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80002 /* Lookup the address for a symbol. Returns 0 if not found. */
80003 unsigned long kallsyms_lookup_name(const char *name);
80004
80005@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80006 /* Stupid that this does nothing, but I didn't create this mess. */
80007 #define __print_symbol(fmt, addr)
80008 #endif /*CONFIG_KALLSYMS*/
80009+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80010+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80011+extern unsigned long kallsyms_lookup_name(const char *name);
80012+extern void __print_symbol(const char *fmt, unsigned long address);
80013+extern int sprint_backtrace(char *buffer, unsigned long address);
80014+extern int sprint_symbol(char *buffer, unsigned long address);
80015+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80016+const char *kallsyms_lookup(unsigned long addr,
80017+ unsigned long *symbolsize,
80018+ unsigned long *offset,
80019+ char **modname, char *namebuf);
80020+extern int kallsyms_lookup_size_offset(unsigned long addr,
80021+ unsigned long *symbolsize,
80022+ unsigned long *offset);
80023+#endif
80024
80025 /* This macro allows us to keep printk typechecking */
80026 static __printf(1, 2)
80027diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80028index a74c3a8..28d3f21 100644
80029--- a/include/linux/key-type.h
80030+++ b/include/linux/key-type.h
80031@@ -131,7 +131,7 @@ struct key_type {
80032 /* internal fields */
80033 struct list_head link; /* link in types list */
80034 struct lock_class_key lock_class; /* key->sem lock class */
80035-};
80036+} __do_const;
80037
80038 extern struct key_type key_type_keyring;
80039
80040diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80041index 6b06d37..c134867 100644
80042--- a/include/linux/kgdb.h
80043+++ b/include/linux/kgdb.h
80044@@ -52,7 +52,7 @@ extern int kgdb_connected;
80045 extern int kgdb_io_module_registered;
80046
80047 extern atomic_t kgdb_setting_breakpoint;
80048-extern atomic_t kgdb_cpu_doing_single_step;
80049+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80050
80051 extern struct task_struct *kgdb_usethread;
80052 extern struct task_struct *kgdb_contthread;
80053@@ -254,7 +254,7 @@ struct kgdb_arch {
80054 void (*correct_hw_break)(void);
80055
80056 void (*enable_nmi)(bool on);
80057-};
80058+} __do_const;
80059
80060 /**
80061 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80062@@ -279,7 +279,7 @@ struct kgdb_io {
80063 void (*pre_exception) (void);
80064 void (*post_exception) (void);
80065 int is_console;
80066-};
80067+} __do_const;
80068
80069 extern struct kgdb_arch arch_kgdb_ops;
80070
80071diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80072index 0555cc6..40116ce 100644
80073--- a/include/linux/kmod.h
80074+++ b/include/linux/kmod.h
80075@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80076 * usually useless though. */
80077 extern __printf(2, 3)
80078 int __request_module(bool wait, const char *name, ...);
80079+extern __printf(3, 4)
80080+int ___request_module(bool wait, char *param_name, const char *name, ...);
80081 #define request_module(mod...) __request_module(true, mod)
80082 #define request_module_nowait(mod...) __request_module(false, mod)
80083 #define try_then_request_module(x, mod...) \
80084@@ -57,6 +59,9 @@ struct subprocess_info {
80085 struct work_struct work;
80086 struct completion *complete;
80087 char *path;
80088+#ifdef CONFIG_GRKERNSEC
80089+ char *origpath;
80090+#endif
80091 char **argv;
80092 char **envp;
80093 int wait;
80094diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80095index f896a33..f2eb10f 100644
80096--- a/include/linux/kobject.h
80097+++ b/include/linux/kobject.h
80098@@ -116,7 +116,7 @@ struct kobj_type {
80099 struct attribute **default_attrs;
80100 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80101 const void *(*namespace)(struct kobject *kobj);
80102-};
80103+} __do_const;
80104
80105 struct kobj_uevent_env {
80106 char *argv[3];
80107@@ -140,6 +140,7 @@ struct kobj_attribute {
80108 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80109 const char *buf, size_t count);
80110 };
80111+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80112
80113 extern const struct sysfs_ops kobj_sysfs_ops;
80114
80115@@ -167,7 +168,7 @@ struct kset {
80116 spinlock_t list_lock;
80117 struct kobject kobj;
80118 const struct kset_uevent_ops *uevent_ops;
80119-};
80120+} __randomize_layout;
80121
80122 extern void kset_init(struct kset *kset);
80123 extern int __must_check kset_register(struct kset *kset);
80124diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80125index df32d25..fb52e27 100644
80126--- a/include/linux/kobject_ns.h
80127+++ b/include/linux/kobject_ns.h
80128@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80129 const void *(*netlink_ns)(struct sock *sk);
80130 const void *(*initial_ns)(void);
80131 void (*drop_ns)(void *);
80132-};
80133+} __do_const;
80134
80135 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80136 int kobj_ns_type_registered(enum kobj_ns_type type);
80137diff --git a/include/linux/kref.h b/include/linux/kref.h
80138index 484604d..0f6c5b6 100644
80139--- a/include/linux/kref.h
80140+++ b/include/linux/kref.h
80141@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80142 static inline int kref_sub(struct kref *kref, unsigned int count,
80143 void (*release)(struct kref *kref))
80144 {
80145- WARN_ON(release == NULL);
80146+ BUG_ON(release == NULL);
80147
80148 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80149 release(kref);
80150diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80151index 7d21cf9..bc0c81f 100644
80152--- a/include/linux/kvm_host.h
80153+++ b/include/linux/kvm_host.h
80154@@ -466,7 +466,7 @@ static inline void kvm_irqfd_exit(void)
80155 {
80156 }
80157 #endif
80158-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80159+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80160 struct module *module);
80161 void kvm_exit(void);
80162
80163@@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80164 struct kvm_guest_debug *dbg);
80165 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80166
80167-int kvm_arch_init(void *opaque);
80168+int kvm_arch_init(const void *opaque);
80169 void kvm_arch_exit(void);
80170
80171 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80172diff --git a/include/linux/libata.h b/include/linux/libata.h
80173index 5ab4e3a..2fe237b 100644
80174--- a/include/linux/libata.h
80175+++ b/include/linux/libata.h
80176@@ -975,7 +975,7 @@ struct ata_port_operations {
80177 * fields must be pointers.
80178 */
80179 const struct ata_port_operations *inherits;
80180-};
80181+} __do_const;
80182
80183 struct ata_port_info {
80184 unsigned long flags;
80185diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80186index a6a42dd..6c5ebce 100644
80187--- a/include/linux/linkage.h
80188+++ b/include/linux/linkage.h
80189@@ -36,6 +36,7 @@
80190 #endif
80191
80192 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80193+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80194 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80195
80196 /*
80197diff --git a/include/linux/list.h b/include/linux/list.h
80198index ef95941..82db65a 100644
80199--- a/include/linux/list.h
80200+++ b/include/linux/list.h
80201@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80202 extern void list_del(struct list_head *entry);
80203 #endif
80204
80205+extern void __pax_list_add(struct list_head *new,
80206+ struct list_head *prev,
80207+ struct list_head *next);
80208+static inline void pax_list_add(struct list_head *new, struct list_head *head)
80209+{
80210+ __pax_list_add(new, head, head->next);
80211+}
80212+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80213+{
80214+ __pax_list_add(new, head->prev, head);
80215+}
80216+extern void pax_list_del(struct list_head *entry);
80217+
80218 /**
80219 * list_replace - replace old entry by new one
80220 * @old : the element to be replaced
80221@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80222 INIT_LIST_HEAD(entry);
80223 }
80224
80225+extern void pax_list_del_init(struct list_head *entry);
80226+
80227 /**
80228 * list_move - delete from one list and add as another's head
80229 * @list: the entry to move
80230diff --git a/include/linux/math64.h b/include/linux/math64.h
80231index c45c089..298841c 100644
80232--- a/include/linux/math64.h
80233+++ b/include/linux/math64.h
80234@@ -15,7 +15,7 @@
80235 * This is commonly provided by 32bit archs to provide an optimized 64bit
80236 * divide.
80237 */
80238-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80239+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80240 {
80241 *remainder = dividend % divisor;
80242 return dividend / divisor;
80243@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80244 /**
80245 * div64_u64 - unsigned 64bit divide with 64bit divisor
80246 */
80247-static inline u64 div64_u64(u64 dividend, u64 divisor)
80248+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80249 {
80250 return dividend / divisor;
80251 }
80252@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80253 #define div64_ul(x, y) div_u64((x), (y))
80254
80255 #ifndef div_u64_rem
80256-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80257+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80258 {
80259 *remainder = do_div(dividend, divisor);
80260 return dividend;
80261@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80262 #endif
80263
80264 #ifndef div64_u64
80265-extern u64 div64_u64(u64 dividend, u64 divisor);
80266+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80267 #endif
80268
80269 #ifndef div64_s64
80270@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80271 * divide.
80272 */
80273 #ifndef div_u64
80274-static inline u64 div_u64(u64 dividend, u32 divisor)
80275+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80276 {
80277 u32 remainder;
80278 return div_u64_rem(dividend, divisor, &remainder);
80279diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80280index 3c1b968..d5b5683 100644
80281--- a/include/linux/mempolicy.h
80282+++ b/include/linux/mempolicy.h
80283@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80284 }
80285
80286 #define vma_policy(vma) ((vma)->vm_policy)
80287+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80288+{
80289+ vma->vm_policy = pol;
80290+}
80291
80292 static inline void mpol_get(struct mempolicy *pol)
80293 {
80294@@ -222,6 +226,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80295 }
80296
80297 #define vma_policy(vma) NULL
80298+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80299+{
80300+}
80301
80302 static inline int
80303 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80304diff --git a/include/linux/mm.h b/include/linux/mm.h
80305index d677706..673408c 100644
80306--- a/include/linux/mm.h
80307+++ b/include/linux/mm.h
80308@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80309 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80310 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80311 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80312+
80313+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80314+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80315+#endif
80316+
80317 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80318
80319 #ifdef CONFIG_MEM_SOFT_DIRTY
80320@@ -237,8 +242,8 @@ struct vm_operations_struct {
80321 /* called by access_process_vm when get_user_pages() fails, typically
80322 * for use by special VMAs that can switch between memory and hardware
80323 */
80324- int (*access)(struct vm_area_struct *vma, unsigned long addr,
80325- void *buf, int len, int write);
80326+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80327+ void *buf, size_t len, int write);
80328 #ifdef CONFIG_NUMA
80329 /*
80330 * set_policy() op must add a reference to any non-NULL @new mempolicy
80331@@ -268,6 +273,7 @@ struct vm_operations_struct {
80332 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80333 unsigned long size, pgoff_t pgoff);
80334 };
80335+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80336
80337 struct mmu_gather;
80338 struct inode;
80339@@ -1133,8 +1139,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80340 unsigned long *pfn);
80341 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80342 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80343-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80344- void *buf, int len, int write);
80345+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80346+ void *buf, size_t len, int write);
80347
80348 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80349 loff_t const holebegin, loff_t const holelen)
80350@@ -1173,9 +1179,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80351 }
80352 #endif
80353
80354-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80355-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80356- void *buf, int len, int write);
80357+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80358+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80359+ void *buf, size_t len, int write);
80360
80361 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80362 unsigned long start, unsigned long nr_pages,
80363@@ -1208,34 +1214,6 @@ int set_page_dirty_lock(struct page *page);
80364 int clear_page_dirty_for_io(struct page *page);
80365 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
80366
80367-/* Is the vma a continuation of the stack vma above it? */
80368-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80369-{
80370- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80371-}
80372-
80373-static inline int stack_guard_page_start(struct vm_area_struct *vma,
80374- unsigned long addr)
80375-{
80376- return (vma->vm_flags & VM_GROWSDOWN) &&
80377- (vma->vm_start == addr) &&
80378- !vma_growsdown(vma->vm_prev, addr);
80379-}
80380-
80381-/* Is the vma a continuation of the stack vma below it? */
80382-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80383-{
80384- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80385-}
80386-
80387-static inline int stack_guard_page_end(struct vm_area_struct *vma,
80388- unsigned long addr)
80389-{
80390- return (vma->vm_flags & VM_GROWSUP) &&
80391- (vma->vm_end == addr) &&
80392- !vma_growsup(vma->vm_next, addr);
80393-}
80394-
80395 extern pid_t
80396 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80397
80398@@ -1335,6 +1313,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80399 }
80400 #endif
80401
80402+#ifdef CONFIG_MMU
80403+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80404+#else
80405+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80406+{
80407+ return __pgprot(0);
80408+}
80409+#endif
80410+
80411 int vma_wants_writenotify(struct vm_area_struct *vma);
80412
80413 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80414@@ -1353,8 +1340,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80415 {
80416 return 0;
80417 }
80418+
80419+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80420+ unsigned long address)
80421+{
80422+ return 0;
80423+}
80424 #else
80425 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80426+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80427 #endif
80428
80429 #ifdef __PAGETABLE_PMD_FOLDED
80430@@ -1363,8 +1357,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80431 {
80432 return 0;
80433 }
80434+
80435+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80436+ unsigned long address)
80437+{
80438+ return 0;
80439+}
80440 #else
80441 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80442+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80443 #endif
80444
80445 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80446@@ -1382,11 +1383,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80447 NULL: pud_offset(pgd, address);
80448 }
80449
80450+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80451+{
80452+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80453+ NULL: pud_offset(pgd, address);
80454+}
80455+
80456 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80457 {
80458 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80459 NULL: pmd_offset(pud, address);
80460 }
80461+
80462+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80463+{
80464+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80465+ NULL: pmd_offset(pud, address);
80466+}
80467 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80468
80469 #if USE_SPLIT_PTE_PTLOCKS
80470@@ -1783,7 +1796,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80471 unsigned long addr, unsigned long len,
80472 unsigned long flags, struct page **pages);
80473
80474-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80475+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80476
80477 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80478 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80479@@ -1791,6 +1804,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80480 unsigned long len, unsigned long prot, unsigned long flags,
80481 unsigned long pgoff, unsigned long *populate);
80482 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80483+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80484
80485 #ifdef CONFIG_MMU
80486 extern int __mm_populate(unsigned long addr, unsigned long len,
80487@@ -1819,10 +1833,11 @@ struct vm_unmapped_area_info {
80488 unsigned long high_limit;
80489 unsigned long align_mask;
80490 unsigned long align_offset;
80491+ unsigned long threadstack_offset;
80492 };
80493
80494-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80495-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80496+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80497+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80498
80499 /*
80500 * Search for an unmapped address range.
80501@@ -1834,7 +1849,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80502 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80503 */
80504 static inline unsigned long
80505-vm_unmapped_area(struct vm_unmapped_area_info *info)
80506+vm_unmapped_area(const struct vm_unmapped_area_info *info)
80507 {
80508 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80509 return unmapped_area(info);
80510@@ -1896,6 +1911,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80511 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80512 struct vm_area_struct **pprev);
80513
80514+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80515+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80516+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80517+
80518 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80519 NULL if none. Assume start_addr < end_addr. */
80520 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80521@@ -1924,15 +1943,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80522 return vma;
80523 }
80524
80525-#ifdef CONFIG_MMU
80526-pgprot_t vm_get_page_prot(unsigned long vm_flags);
80527-#else
80528-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80529-{
80530- return __pgprot(0);
80531-}
80532-#endif
80533-
80534 #ifdef CONFIG_NUMA_BALANCING
80535 unsigned long change_prot_numa(struct vm_area_struct *vma,
80536 unsigned long start, unsigned long end);
80537@@ -1984,6 +1994,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80538 static inline void vm_stat_account(struct mm_struct *mm,
80539 unsigned long flags, struct file *file, long pages)
80540 {
80541+
80542+#ifdef CONFIG_PAX_RANDMMAP
80543+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80544+#endif
80545+
80546 mm->total_vm += pages;
80547 }
80548 #endif /* CONFIG_PROC_FS */
80549@@ -2065,7 +2080,7 @@ extern int unpoison_memory(unsigned long pfn);
80550 extern int sysctl_memory_failure_early_kill;
80551 extern int sysctl_memory_failure_recovery;
80552 extern void shake_page(struct page *p, int access);
80553-extern atomic_long_t num_poisoned_pages;
80554+extern atomic_long_unchecked_t num_poisoned_pages;
80555 extern int soft_offline_page(struct page *page, int flags);
80556
80557 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
80558@@ -2100,5 +2115,11 @@ void __init setup_nr_node_ids(void);
80559 static inline void setup_nr_node_ids(void) {}
80560 #endif
80561
80562+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80563+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80564+#else
80565+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80566+#endif
80567+
80568 #endif /* __KERNEL__ */
80569 #endif /* _LINUX_MM_H */
80570diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80571index 8967e20..61f7900 100644
80572--- a/include/linux/mm_types.h
80573+++ b/include/linux/mm_types.h
80574@@ -308,7 +308,9 @@ struct vm_area_struct {
80575 #ifdef CONFIG_NUMA
80576 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80577 #endif
80578-};
80579+
80580+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80581+} __randomize_layout;
80582
80583 struct core_thread {
80584 struct task_struct *task;
80585@@ -454,7 +456,25 @@ struct mm_struct {
80586 bool tlb_flush_pending;
80587 #endif
80588 struct uprobes_state uprobes_state;
80589-};
80590+
80591+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80592+ unsigned long pax_flags;
80593+#endif
80594+
80595+#ifdef CONFIG_PAX_DLRESOLVE
80596+ unsigned long call_dl_resolve;
80597+#endif
80598+
80599+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80600+ unsigned long call_syscall;
80601+#endif
80602+
80603+#ifdef CONFIG_PAX_ASLR
80604+ unsigned long delta_mmap; /* randomized offset */
80605+ unsigned long delta_stack; /* randomized offset */
80606+#endif
80607+
80608+} __randomize_layout;
80609
80610 static inline void mm_init_cpumask(struct mm_struct *mm)
80611 {
80612diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80613index c5d5278..f0b68c8 100644
80614--- a/include/linux/mmiotrace.h
80615+++ b/include/linux/mmiotrace.h
80616@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80617 /* Called from ioremap.c */
80618 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80619 void __iomem *addr);
80620-extern void mmiotrace_iounmap(volatile void __iomem *addr);
80621+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80622
80623 /* For anyone to insert markers. Remember trailing newline. */
80624 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80625@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80626 {
80627 }
80628
80629-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80630+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80631 {
80632 }
80633
80634diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80635index fac5509..22a7710 100644
80636--- a/include/linux/mmzone.h
80637+++ b/include/linux/mmzone.h
80638@@ -402,7 +402,7 @@ struct zone {
80639 unsigned long flags; /* zone flags, see below */
80640
80641 /* Zone statistics */
80642- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80643+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80644
80645 /*
80646 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80647diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80648index 44eeef0..67ad116 100644
80649--- a/include/linux/mod_devicetable.h
80650+++ b/include/linux/mod_devicetable.h
80651@@ -13,7 +13,7 @@
80652 typedef unsigned long kernel_ulong_t;
80653 #endif
80654
80655-#define PCI_ANY_ID (~0)
80656+#define PCI_ANY_ID ((__u16)~0)
80657
80658 struct pci_device_id {
80659 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
80660@@ -139,7 +139,7 @@ struct usb_device_id {
80661 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80662 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80663
80664-#define HID_ANY_ID (~0)
80665+#define HID_ANY_ID (~0U)
80666 #define HID_BUS_ANY 0xffff
80667 #define HID_GROUP_ANY 0x0000
80668
80669@@ -475,7 +475,7 @@ struct dmi_system_id {
80670 const char *ident;
80671 struct dmi_strmatch matches[4];
80672 void *driver_data;
80673-};
80674+} __do_const;
80675 /*
80676 * struct dmi_device_id appears during expansion of
80677 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80678diff --git a/include/linux/module.h b/include/linux/module.h
80679index f520a76..5f898ef 100644
80680--- a/include/linux/module.h
80681+++ b/include/linux/module.h
80682@@ -17,9 +17,11 @@
80683 #include <linux/moduleparam.h>
80684 #include <linux/jump_label.h>
80685 #include <linux/export.h>
80686+#include <linux/fs.h>
80687
80688 #include <linux/percpu.h>
80689 #include <asm/module.h>
80690+#include <asm/pgtable.h>
80691
80692 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80693 #define MODULE_SIG_STRING "~Module signature appended~\n"
80694@@ -42,7 +44,7 @@ struct module_kobject {
80695 struct kobject *drivers_dir;
80696 struct module_param_attrs *mp;
80697 struct completion *kobj_completion;
80698-};
80699+} __randomize_layout;
80700
80701 struct module_attribute {
80702 struct attribute attr;
80703@@ -54,12 +56,13 @@ struct module_attribute {
80704 int (*test)(struct module *);
80705 void (*free)(struct module *);
80706 };
80707+typedef struct module_attribute __no_const module_attribute_no_const;
80708
80709 struct module_version_attribute {
80710 struct module_attribute mattr;
80711 const char *module_name;
80712 const char *version;
80713-} __attribute__ ((__aligned__(sizeof(void *))));
80714+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80715
80716 extern ssize_t __modver_version_show(struct module_attribute *,
80717 struct module_kobject *, char *);
80718@@ -235,7 +238,7 @@ struct module {
80719
80720 /* Sysfs stuff. */
80721 struct module_kobject mkobj;
80722- struct module_attribute *modinfo_attrs;
80723+ module_attribute_no_const *modinfo_attrs;
80724 const char *version;
80725 const char *srcversion;
80726 struct kobject *holders_dir;
80727@@ -284,19 +287,16 @@ struct module {
80728 int (*init)(void);
80729
80730 /* If this is non-NULL, vfree after init() returns */
80731- void *module_init;
80732+ void *module_init_rx, *module_init_rw;
80733
80734 /* Here is the actual code + data, vfree'd on unload. */
80735- void *module_core;
80736+ void *module_core_rx, *module_core_rw;
80737
80738 /* Here are the sizes of the init and core sections */
80739- unsigned int init_size, core_size;
80740+ unsigned int init_size_rw, core_size_rw;
80741
80742 /* The size of the executable code in each section. */
80743- unsigned int init_text_size, core_text_size;
80744-
80745- /* Size of RO sections of the module (text+rodata) */
80746- unsigned int init_ro_size, core_ro_size;
80747+ unsigned int init_size_rx, core_size_rx;
80748
80749 /* Arch-specific module values */
80750 struct mod_arch_specific arch;
80751@@ -352,6 +352,10 @@ struct module {
80752 #ifdef CONFIG_EVENT_TRACING
80753 struct ftrace_event_call **trace_events;
80754 unsigned int num_trace_events;
80755+ struct file_operations trace_id;
80756+ struct file_operations trace_enable;
80757+ struct file_operations trace_format;
80758+ struct file_operations trace_filter;
80759 #endif
80760 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80761 unsigned int num_ftrace_callsites;
80762@@ -375,7 +379,7 @@ struct module {
80763 ctor_fn_t *ctors;
80764 unsigned int num_ctors;
80765 #endif
80766-};
80767+} __randomize_layout;
80768 #ifndef MODULE_ARCH_INIT
80769 #define MODULE_ARCH_INIT {}
80770 #endif
80771@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
80772 bool is_module_percpu_address(unsigned long addr);
80773 bool is_module_text_address(unsigned long addr);
80774
80775+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80776+{
80777+
80778+#ifdef CONFIG_PAX_KERNEXEC
80779+ if (ktla_ktva(addr) >= (unsigned long)start &&
80780+ ktla_ktva(addr) < (unsigned long)start + size)
80781+ return 1;
80782+#endif
80783+
80784+ return ((void *)addr >= start && (void *)addr < start + size);
80785+}
80786+
80787+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80788+{
80789+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80790+}
80791+
80792+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80793+{
80794+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80795+}
80796+
80797+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80798+{
80799+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80800+}
80801+
80802+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80803+{
80804+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80805+}
80806+
80807 static inline int within_module_core(unsigned long addr, const struct module *mod)
80808 {
80809- return (unsigned long)mod->module_core <= addr &&
80810- addr < (unsigned long)mod->module_core + mod->core_size;
80811+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80812 }
80813
80814 static inline int within_module_init(unsigned long addr, const struct module *mod)
80815 {
80816- return (unsigned long)mod->module_init <= addr &&
80817- addr < (unsigned long)mod->module_init + mod->init_size;
80818+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80819 }
80820
80821 /* Search for module by name: must hold module_mutex. */
80822diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80823index 560ca53..ef621ef 100644
80824--- a/include/linux/moduleloader.h
80825+++ b/include/linux/moduleloader.h
80826@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80827 sections. Returns NULL on failure. */
80828 void *module_alloc(unsigned long size);
80829
80830+#ifdef CONFIG_PAX_KERNEXEC
80831+void *module_alloc_exec(unsigned long size);
80832+#else
80833+#define module_alloc_exec(x) module_alloc(x)
80834+#endif
80835+
80836 /* Free memory returned from module_alloc. */
80837 void module_free(struct module *mod, void *module_region);
80838
80839+#ifdef CONFIG_PAX_KERNEXEC
80840+void module_free_exec(struct module *mod, void *module_region);
80841+#else
80842+#define module_free_exec(x, y) module_free((x), (y))
80843+#endif
80844+
80845 /*
80846 * Apply the given relocation to the (simplified) ELF. Return -error
80847 * or 0.
80848@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80849 unsigned int relsec,
80850 struct module *me)
80851 {
80852+#ifdef CONFIG_MODULES
80853 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80854+#endif
80855 return -ENOEXEC;
80856 }
80857 #endif
80858@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80859 unsigned int relsec,
80860 struct module *me)
80861 {
80862+#ifdef CONFIG_MODULES
80863 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80864+#endif
80865 return -ENOEXEC;
80866 }
80867 #endif
80868diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80869index 204a677..e9b486a 100644
80870--- a/include/linux/moduleparam.h
80871+++ b/include/linux/moduleparam.h
80872@@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
80873 * @len is usually just sizeof(string).
80874 */
80875 #define module_param_string(name, string, len, perm) \
80876- static const struct kparam_string __param_string_##name \
80877+ static const struct kparam_string __param_string_##name __used \
80878 = { len, string }; \
80879 __module_param_call(MODULE_PARAM_PREFIX, name, \
80880 &param_ops_string, \
80881@@ -432,7 +432,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80882 */
80883 #define module_param_array_named(name, array, type, nump, perm) \
80884 param_check_##type(name, &(array)[0]); \
80885- static const struct kparam_array __param_arr_##name \
80886+ static const struct kparam_array __param_arr_##name __used \
80887 = { .max = ARRAY_SIZE(array), .num = nump, \
80888 .ops = &param_ops_##type, \
80889 .elemsize = sizeof(array[0]), .elem = array }; \
80890diff --git a/include/linux/mount.h b/include/linux/mount.h
80891index 839bac2..a96b37c 100644
80892--- a/include/linux/mount.h
80893+++ b/include/linux/mount.h
80894@@ -59,7 +59,7 @@ struct vfsmount {
80895 struct dentry *mnt_root; /* root of the mounted tree */
80896 struct super_block *mnt_sb; /* pointer to superblock */
80897 int mnt_flags;
80898-};
80899+} __randomize_layout;
80900
80901 struct file; /* forward dec */
80902
80903diff --git a/include/linux/namei.h b/include/linux/namei.h
80904index 492de72..1bddcd4 100644
80905--- a/include/linux/namei.h
80906+++ b/include/linux/namei.h
80907@@ -19,7 +19,7 @@ struct nameidata {
80908 unsigned seq, m_seq;
80909 int last_type;
80910 unsigned depth;
80911- char *saved_names[MAX_NESTED_LINKS + 1];
80912+ const char *saved_names[MAX_NESTED_LINKS + 1];
80913 };
80914
80915 /*
80916@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
80917
80918 extern void nd_jump_link(struct nameidata *nd, struct path *path);
80919
80920-static inline void nd_set_link(struct nameidata *nd, char *path)
80921+static inline void nd_set_link(struct nameidata *nd, const char *path)
80922 {
80923 nd->saved_names[nd->depth] = path;
80924 }
80925
80926-static inline char *nd_get_link(struct nameidata *nd)
80927+static inline const char *nd_get_link(const struct nameidata *nd)
80928 {
80929 return nd->saved_names[nd->depth];
80930 }
80931diff --git a/include/linux/net.h b/include/linux/net.h
80932index 17d8339..81656c0 100644
80933--- a/include/linux/net.h
80934+++ b/include/linux/net.h
80935@@ -192,7 +192,7 @@ struct net_proto_family {
80936 int (*create)(struct net *net, struct socket *sock,
80937 int protocol, int kern);
80938 struct module *owner;
80939-};
80940+} __do_const;
80941
80942 struct iovec;
80943 struct kvec;
80944diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
80945index b42d07b..7f45ae2 100644
80946--- a/include/linux/netdevice.h
80947+++ b/include/linux/netdevice.h
80948@@ -1146,6 +1146,7 @@ struct net_device_ops {
80949 void *priv);
80950 int (*ndo_get_lock_subclass)(struct net_device *dev);
80951 };
80952+typedef struct net_device_ops __no_const net_device_ops_no_const;
80953
80954 /**
80955 * enum net_device_priv_flags - &struct net_device priv_flags
80956@@ -1313,11 +1314,11 @@ struct net_device {
80957 struct net_device_stats stats;
80958
80959 /* dropped packets by core network, Do not use this in drivers */
80960- atomic_long_t rx_dropped;
80961- atomic_long_t tx_dropped;
80962+ atomic_long_unchecked_t rx_dropped;
80963+ atomic_long_unchecked_t tx_dropped;
80964
80965 /* Stats to monitor carrier on<->off transitions */
80966- atomic_t carrier_changes;
80967+ atomic_unchecked_t carrier_changes;
80968
80969 #ifdef CONFIG_WIRELESS_EXT
80970 /* List of functions to handle Wireless Extensions (instead of ioctl).
80971diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
80972index 2077489..a15e561 100644
80973--- a/include/linux/netfilter.h
80974+++ b/include/linux/netfilter.h
80975@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
80976 #endif
80977 /* Use the module struct to lock set/get code in place */
80978 struct module *owner;
80979-};
80980+} __do_const;
80981
80982 /* Function to register/unregister hook points. */
80983 int nf_register_hook(struct nf_hook_ops *reg);
80984diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
80985index e955d47..04a5338 100644
80986--- a/include/linux/netfilter/nfnetlink.h
80987+++ b/include/linux/netfilter/nfnetlink.h
80988@@ -19,7 +19,7 @@ struct nfnl_callback {
80989 const struct nlattr * const cda[]);
80990 const struct nla_policy *policy; /* netlink attribute policy */
80991 const u_int16_t attr_count; /* number of nlattr's */
80992-};
80993+} __do_const;
80994
80995 struct nfnetlink_subsystem {
80996 const char *name;
80997diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
80998new file mode 100644
80999index 0000000..33f4af8
81000--- /dev/null
81001+++ b/include/linux/netfilter/xt_gradm.h
81002@@ -0,0 +1,9 @@
81003+#ifndef _LINUX_NETFILTER_XT_GRADM_H
81004+#define _LINUX_NETFILTER_XT_GRADM_H 1
81005+
81006+struct xt_gradm_mtinfo {
81007+ __u16 flags;
81008+ __u16 invflags;
81009+};
81010+
81011+#endif
81012diff --git a/include/linux/nls.h b/include/linux/nls.h
81013index 520681b..1d67ed2 100644
81014--- a/include/linux/nls.h
81015+++ b/include/linux/nls.h
81016@@ -31,7 +31,7 @@ struct nls_table {
81017 const unsigned char *charset2upper;
81018 struct module *owner;
81019 struct nls_table *next;
81020-};
81021+} __do_const;
81022
81023 /* this value hold the maximum octet of charset */
81024 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81025diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81026index d14a4c3..a078786 100644
81027--- a/include/linux/notifier.h
81028+++ b/include/linux/notifier.h
81029@@ -54,7 +54,8 @@ struct notifier_block {
81030 notifier_fn_t notifier_call;
81031 struct notifier_block __rcu *next;
81032 int priority;
81033-};
81034+} __do_const;
81035+typedef struct notifier_block __no_const notifier_block_no_const;
81036
81037 struct atomic_notifier_head {
81038 spinlock_t lock;
81039diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81040index b2a0f15..4d7da32 100644
81041--- a/include/linux/oprofile.h
81042+++ b/include/linux/oprofile.h
81043@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81044 int oprofilefs_create_ro_ulong(struct dentry * root,
81045 char const * name, ulong * val);
81046
81047-/** Create a file for read-only access to an atomic_t. */
81048+/** Create a file for read-only access to an atomic_unchecked_t. */
81049 int oprofilefs_create_ro_atomic(struct dentry * root,
81050- char const * name, atomic_t * val);
81051+ char const * name, atomic_unchecked_t * val);
81052
81053 /** create a directory */
81054 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81055diff --git a/include/linux/padata.h b/include/linux/padata.h
81056index 4386946..f50c615 100644
81057--- a/include/linux/padata.h
81058+++ b/include/linux/padata.h
81059@@ -129,7 +129,7 @@ struct parallel_data {
81060 struct padata_serial_queue __percpu *squeue;
81061 atomic_t reorder_objects;
81062 atomic_t refcnt;
81063- atomic_t seq_nr;
81064+ atomic_unchecked_t seq_nr;
81065 struct padata_cpumask cpumask;
81066 spinlock_t lock ____cacheline_aligned;
81067 unsigned int processed;
81068diff --git a/include/linux/path.h b/include/linux/path.h
81069index d137218..be0c176 100644
81070--- a/include/linux/path.h
81071+++ b/include/linux/path.h
81072@@ -1,13 +1,15 @@
81073 #ifndef _LINUX_PATH_H
81074 #define _LINUX_PATH_H
81075
81076+#include <linux/compiler.h>
81077+
81078 struct dentry;
81079 struct vfsmount;
81080
81081 struct path {
81082 struct vfsmount *mnt;
81083 struct dentry *dentry;
81084-};
81085+} __randomize_layout;
81086
81087 extern void path_get(const struct path *);
81088 extern void path_put(const struct path *);
81089diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81090index 5f2e559..7d59314 100644
81091--- a/include/linux/pci_hotplug.h
81092+++ b/include/linux/pci_hotplug.h
81093@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81094 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81095 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81096 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81097-};
81098+} __do_const;
81099+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81100
81101 /**
81102 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81103diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81104index 3ef6ea1..ed1a248 100644
81105--- a/include/linux/perf_event.h
81106+++ b/include/linux/perf_event.h
81107@@ -328,8 +328,8 @@ struct perf_event {
81108
81109 enum perf_event_active_state state;
81110 unsigned int attach_state;
81111- local64_t count;
81112- atomic64_t child_count;
81113+ local64_t count; /* PaX: fix it one day */
81114+ atomic64_unchecked_t child_count;
81115
81116 /*
81117 * These are the total time in nanoseconds that the event
81118@@ -380,8 +380,8 @@ struct perf_event {
81119 * These accumulate total time (in nanoseconds) that children
81120 * events have been enabled and running, respectively.
81121 */
81122- atomic64_t child_total_time_enabled;
81123- atomic64_t child_total_time_running;
81124+ atomic64_unchecked_t child_total_time_enabled;
81125+ atomic64_unchecked_t child_total_time_running;
81126
81127 /*
81128 * Protect attach/detach and child_list:
81129@@ -710,7 +710,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81130 entry->ip[entry->nr++] = ip;
81131 }
81132
81133-extern int sysctl_perf_event_paranoid;
81134+extern int sysctl_perf_event_legitimately_concerned;
81135 extern int sysctl_perf_event_mlock;
81136 extern int sysctl_perf_event_sample_rate;
81137 extern int sysctl_perf_cpu_time_max_percent;
81138@@ -725,19 +725,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81139 loff_t *ppos);
81140
81141
81142+static inline bool perf_paranoid_any(void)
81143+{
81144+ return sysctl_perf_event_legitimately_concerned > 2;
81145+}
81146+
81147 static inline bool perf_paranoid_tracepoint_raw(void)
81148 {
81149- return sysctl_perf_event_paranoid > -1;
81150+ return sysctl_perf_event_legitimately_concerned > -1;
81151 }
81152
81153 static inline bool perf_paranoid_cpu(void)
81154 {
81155- return sysctl_perf_event_paranoid > 0;
81156+ return sysctl_perf_event_legitimately_concerned > 0;
81157 }
81158
81159 static inline bool perf_paranoid_kernel(void)
81160 {
81161- return sysctl_perf_event_paranoid > 1;
81162+ return sysctl_perf_event_legitimately_concerned > 1;
81163 }
81164
81165 extern void perf_event_init(void);
81166@@ -867,7 +872,7 @@ struct perf_pmu_events_attr {
81167 struct device_attribute attr;
81168 u64 id;
81169 const char *event_str;
81170-};
81171+} __do_const;
81172
81173 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81174 static struct perf_pmu_events_attr _var = { \
81175diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81176index 7246ef3..1539ea4 100644
81177--- a/include/linux/pid_namespace.h
81178+++ b/include/linux/pid_namespace.h
81179@@ -43,7 +43,7 @@ struct pid_namespace {
81180 int hide_pid;
81181 int reboot; /* group exit code if this pidns was rebooted */
81182 unsigned int proc_inum;
81183-};
81184+} __randomize_layout;
81185
81186 extern struct pid_namespace init_pid_ns;
81187
81188diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81189index eb8b8ac..62649e1 100644
81190--- a/include/linux/pipe_fs_i.h
81191+++ b/include/linux/pipe_fs_i.h
81192@@ -47,10 +47,10 @@ struct pipe_inode_info {
81193 struct mutex mutex;
81194 wait_queue_head_t wait;
81195 unsigned int nrbufs, curbuf, buffers;
81196- unsigned int readers;
81197- unsigned int writers;
81198- unsigned int files;
81199- unsigned int waiting_writers;
81200+ atomic_t readers;
81201+ atomic_t writers;
81202+ atomic_t files;
81203+ atomic_t waiting_writers;
81204 unsigned int r_counter;
81205 unsigned int w_counter;
81206 struct page *tmp_page;
81207diff --git a/include/linux/pm.h b/include/linux/pm.h
81208index d915d03..0531037 100644
81209--- a/include/linux/pm.h
81210+++ b/include/linux/pm.h
81211@@ -600,6 +600,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81212 struct dev_pm_domain {
81213 struct dev_pm_ops ops;
81214 };
81215+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81216
81217 /*
81218 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81219diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81220index 7c1d252..0e7061d 100644
81221--- a/include/linux/pm_domain.h
81222+++ b/include/linux/pm_domain.h
81223@@ -44,11 +44,11 @@ struct gpd_dev_ops {
81224 int (*thaw_early)(struct device *dev);
81225 int (*thaw)(struct device *dev);
81226 bool (*active_wakeup)(struct device *dev);
81227-};
81228+} __no_const;
81229
81230 struct gpd_cpu_data {
81231 unsigned int saved_exit_latency;
81232- struct cpuidle_state *idle_state;
81233+ cpuidle_state_no_const *idle_state;
81234 };
81235
81236 struct generic_pm_domain {
81237diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81238index 2a5897a..4f9af63 100644
81239--- a/include/linux/pm_runtime.h
81240+++ b/include/linux/pm_runtime.h
81241@@ -113,7 +113,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81242
81243 static inline void pm_runtime_mark_last_busy(struct device *dev)
81244 {
81245- ACCESS_ONCE(dev->power.last_busy) = jiffies;
81246+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81247 }
81248
81249 #else /* !CONFIG_PM_RUNTIME */
81250diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81251index 195aafc..49a7bc2 100644
81252--- a/include/linux/pnp.h
81253+++ b/include/linux/pnp.h
81254@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81255 struct pnp_fixup {
81256 char id[7];
81257 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81258-};
81259+} __do_const;
81260
81261 /* config parameters */
81262 #define PNP_CONFIG_NORMAL 0x0001
81263diff --git a/include/linux/poison.h b/include/linux/poison.h
81264index 2110a81..13a11bb 100644
81265--- a/include/linux/poison.h
81266+++ b/include/linux/poison.h
81267@@ -19,8 +19,8 @@
81268 * under normal circumstances, used to verify that nobody uses
81269 * non-initialized list entries.
81270 */
81271-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81272-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81273+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81274+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81275
81276 /********** include/linux/timer.h **********/
81277 /*
81278diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81279index d8b187c3..9a9257a 100644
81280--- a/include/linux/power/smartreflex.h
81281+++ b/include/linux/power/smartreflex.h
81282@@ -238,7 +238,7 @@ struct omap_sr_class_data {
81283 int (*notify)(struct omap_sr *sr, u32 status);
81284 u8 notify_flags;
81285 u8 class_type;
81286-};
81287+} __do_const;
81288
81289 /**
81290 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81291diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81292index 4ea1d37..80f4b33 100644
81293--- a/include/linux/ppp-comp.h
81294+++ b/include/linux/ppp-comp.h
81295@@ -84,7 +84,7 @@ struct compressor {
81296 struct module *owner;
81297 /* Extra skb space needed by the compressor algorithm */
81298 unsigned int comp_extra;
81299-};
81300+} __do_const;
81301
81302 /*
81303 * The return value from decompress routine is the length of the
81304diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81305index de83b4e..c4b997d 100644
81306--- a/include/linux/preempt.h
81307+++ b/include/linux/preempt.h
81308@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81309 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81310 #endif
81311
81312+#define raw_preempt_count_add(val) __preempt_count_add(val)
81313+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81314+
81315 #define __preempt_count_inc() __preempt_count_add(1)
81316 #define __preempt_count_dec() __preempt_count_sub(1)
81317
81318 #define preempt_count_inc() preempt_count_add(1)
81319+#define raw_preempt_count_inc() raw_preempt_count_add(1)
81320 #define preempt_count_dec() preempt_count_sub(1)
81321+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81322
81323 #ifdef CONFIG_PREEMPT_COUNT
81324
81325@@ -41,6 +46,12 @@ do { \
81326 barrier(); \
81327 } while (0)
81328
81329+#define raw_preempt_disable() \
81330+do { \
81331+ raw_preempt_count_inc(); \
81332+ barrier(); \
81333+} while (0)
81334+
81335 #define sched_preempt_enable_no_resched() \
81336 do { \
81337 barrier(); \
81338@@ -49,6 +60,12 @@ do { \
81339
81340 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81341
81342+#define raw_preempt_enable_no_resched() \
81343+do { \
81344+ barrier(); \
81345+ raw_preempt_count_dec(); \
81346+} while (0)
81347+
81348 #ifdef CONFIG_PREEMPT
81349 #define preempt_enable() \
81350 do { \
81351@@ -113,8 +130,10 @@ do { \
81352 * region.
81353 */
81354 #define preempt_disable() barrier()
81355+#define raw_preempt_disable() barrier()
81356 #define sched_preempt_enable_no_resched() barrier()
81357 #define preempt_enable_no_resched() barrier()
81358+#define raw_preempt_enable_no_resched() barrier()
81359 #define preempt_enable() barrier()
81360 #define preempt_check_resched() do { } while (0)
81361
81362@@ -128,11 +147,13 @@ do { \
81363 /*
81364 * Modules have no business playing preemption tricks.
81365 */
81366+#ifndef CONFIG_PAX_KERNEXEC
81367 #undef sched_preempt_enable_no_resched
81368 #undef preempt_enable_no_resched
81369 #undef preempt_enable_no_resched_notrace
81370 #undef preempt_check_resched
81371 #endif
81372+#endif
81373
81374 #define preempt_set_need_resched() \
81375 do { \
81376diff --git a/include/linux/printk.h b/include/linux/printk.h
81377index 8752f75..2b80c0f 100644
81378--- a/include/linux/printk.h
81379+++ b/include/linux/printk.h
81380@@ -110,6 +110,8 @@ static inline __printf(1, 2) __cold
81381 void early_printk(const char *s, ...) { }
81382 #endif
81383
81384+extern int kptr_restrict;
81385+
81386 #ifdef CONFIG_PRINTK
81387 asmlinkage __printf(5, 0)
81388 int vprintk_emit(int facility, int level,
81389@@ -144,7 +146,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81390
81391 extern int printk_delay_msec;
81392 extern int dmesg_restrict;
81393-extern int kptr_restrict;
81394
81395 extern void wake_up_klogd(void);
81396
81397diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81398index 608e60a..79cfb18 100644
81399--- a/include/linux/proc_fs.h
81400+++ b/include/linux/proc_fs.h
81401@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81402 extern struct proc_dir_entry *proc_symlink(const char *,
81403 struct proc_dir_entry *, const char *);
81404 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81405+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81406 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81407 struct proc_dir_entry *, void *);
81408+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81409+ struct proc_dir_entry *, void *);
81410 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81411 struct proc_dir_entry *);
81412
81413@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81414 return proc_create_data(name, mode, parent, proc_fops, NULL);
81415 }
81416
81417+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81418+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81419+{
81420+#ifdef CONFIG_GRKERNSEC_PROC_USER
81421+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81422+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81423+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81424+#else
81425+ return proc_create_data(name, mode, parent, proc_fops, NULL);
81426+#endif
81427+}
81428+
81429+
81430 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81431 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81432 extern void *PDE_DATA(const struct inode *);
81433@@ -52,8 +68,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
81434 struct proc_dir_entry *parent,const char *dest) { return NULL;}
81435 static inline struct proc_dir_entry *proc_mkdir(const char *name,
81436 struct proc_dir_entry *parent) {return NULL;}
81437+static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
81438+ struct proc_dir_entry *parent) { return NULL; }
81439 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
81440 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81441+static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
81442+ umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81443 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
81444 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
81445 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
81446@@ -73,7 +93,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81447 static inline struct proc_dir_entry *proc_net_mkdir(
81448 struct net *net, const char *name, struct proc_dir_entry *parent)
81449 {
81450- return proc_mkdir_data(name, 0, parent, net);
81451+ return proc_mkdir_data_restrict(name, 0, parent, net);
81452 }
81453
81454 #endif /* _LINUX_PROC_FS_H */
81455diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81456index 34a1e10..70f6bde 100644
81457--- a/include/linux/proc_ns.h
81458+++ b/include/linux/proc_ns.h
81459@@ -14,7 +14,7 @@ struct proc_ns_operations {
81460 void (*put)(void *ns);
81461 int (*install)(struct nsproxy *nsproxy, void *ns);
81462 unsigned int (*inum)(void *ns);
81463-};
81464+} __do_const __randomize_layout;
81465
81466 struct proc_ns {
81467 void *ns;
81468diff --git a/include/linux/quota.h b/include/linux/quota.h
81469index cc7494a..1e27036 100644
81470--- a/include/linux/quota.h
81471+++ b/include/linux/quota.h
81472@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81473
81474 extern bool qid_eq(struct kqid left, struct kqid right);
81475 extern bool qid_lt(struct kqid left, struct kqid right);
81476-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81477+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81478 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81479 extern bool qid_valid(struct kqid qid);
81480
81481diff --git a/include/linux/random.h b/include/linux/random.h
81482index 57fbbff..2331f3f 100644
81483--- a/include/linux/random.h
81484+++ b/include/linux/random.h
81485@@ -9,9 +9,19 @@
81486 #include <uapi/linux/random.h>
81487
81488 extern void add_device_randomness(const void *, unsigned int);
81489+
81490+static inline void add_latent_entropy(void)
81491+{
81492+
81493+#ifdef LATENT_ENTROPY_PLUGIN
81494+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81495+#endif
81496+
81497+}
81498+
81499 extern void add_input_randomness(unsigned int type, unsigned int code,
81500- unsigned int value);
81501-extern void add_interrupt_randomness(int irq, int irq_flags);
81502+ unsigned int value) __latent_entropy;
81503+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81504
81505 extern void get_random_bytes(void *buf, int nbytes);
81506 extern void get_random_bytes_arch(void *buf, int nbytes);
81507@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
81508 extern const struct file_operations random_fops, urandom_fops;
81509 #endif
81510
81511-unsigned int get_random_int(void);
81512+unsigned int __intentional_overflow(-1) get_random_int(void);
81513 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81514
81515-u32 prandom_u32(void);
81516+u32 prandom_u32(void) __intentional_overflow(-1);
81517 void prandom_bytes(void *buf, int nbytes);
81518 void prandom_seed(u32 seed);
81519 void prandom_reseed_late(void);
81520@@ -37,6 +47,11 @@ struct rnd_state {
81521 u32 prandom_u32_state(struct rnd_state *state);
81522 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81523
81524+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81525+{
81526+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81527+}
81528+
81529 /**
81530 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
81531 * @ep_ro: right open interval endpoint
81532diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81533index fea49b5..2ac22bb 100644
81534--- a/include/linux/rbtree_augmented.h
81535+++ b/include/linux/rbtree_augmented.h
81536@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81537 old->rbaugmented = rbcompute(old); \
81538 } \
81539 rbstatic const struct rb_augment_callbacks rbname = { \
81540- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81541+ .propagate = rbname ## _propagate, \
81542+ .copy = rbname ## _copy, \
81543+ .rotate = rbname ## _rotate \
81544 };
81545
81546
81547diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81548index 8183b46..a388711 100644
81549--- a/include/linux/rculist.h
81550+++ b/include/linux/rculist.h
81551@@ -29,8 +29,8 @@
81552 */
81553 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81554 {
81555- ACCESS_ONCE(list->next) = list;
81556- ACCESS_ONCE(list->prev) = list;
81557+ ACCESS_ONCE_RW(list->next) = list;
81558+ ACCESS_ONCE_RW(list->prev) = list;
81559 }
81560
81561 /*
81562@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
81563 struct list_head *prev, struct list_head *next);
81564 #endif
81565
81566+void __pax_list_add_rcu(struct list_head *new,
81567+ struct list_head *prev, struct list_head *next);
81568+
81569 /**
81570 * list_add_rcu - add a new entry to rcu-protected list
81571 * @new: new entry to be added
81572@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81573 __list_add_rcu(new, head, head->next);
81574 }
81575
81576+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81577+{
81578+ __pax_list_add_rcu(new, head, head->next);
81579+}
81580+
81581 /**
81582 * list_add_tail_rcu - add a new entry to rcu-protected list
81583 * @new: new entry to be added
81584@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81585 __list_add_rcu(new, head->prev, head);
81586 }
81587
81588+static inline void pax_list_add_tail_rcu(struct list_head *new,
81589+ struct list_head *head)
81590+{
81591+ __pax_list_add_rcu(new, head->prev, head);
81592+}
81593+
81594 /**
81595 * list_del_rcu - deletes entry from list without re-initialization
81596 * @entry: the element to delete from the list.
81597@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81598 entry->prev = LIST_POISON2;
81599 }
81600
81601+extern void pax_list_del_rcu(struct list_head *entry);
81602+
81603 /**
81604 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81605 * @n: the element to delete from the hash list.
81606diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81607index 48bf152..d38b785 100644
81608--- a/include/linux/reboot.h
81609+++ b/include/linux/reboot.h
81610@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81611 */
81612
81613 extern void migrate_to_reboot_cpu(void);
81614-extern void machine_restart(char *cmd);
81615-extern void machine_halt(void);
81616-extern void machine_power_off(void);
81617+extern void machine_restart(char *cmd) __noreturn;
81618+extern void machine_halt(void) __noreturn;
81619+extern void machine_power_off(void) __noreturn;
81620
81621 extern void machine_shutdown(void);
81622 struct pt_regs;
81623@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81624 */
81625
81626 extern void kernel_restart_prepare(char *cmd);
81627-extern void kernel_restart(char *cmd);
81628-extern void kernel_halt(void);
81629-extern void kernel_power_off(void);
81630+extern void kernel_restart(char *cmd) __noreturn;
81631+extern void kernel_halt(void) __noreturn;
81632+extern void kernel_power_off(void) __noreturn;
81633
81634 extern int C_A_D; /* for sysctl */
81635 void ctrl_alt_del(void);
81636@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81637 * Emergency restart, callable from an interrupt handler.
81638 */
81639
81640-extern void emergency_restart(void);
81641+extern void emergency_restart(void) __noreturn;
81642 #include <asm/emergency-restart.h>
81643
81644 #endif /* _LINUX_REBOOT_H */
81645diff --git a/include/linux/regset.h b/include/linux/regset.h
81646index 8e0c9fe..ac4d221 100644
81647--- a/include/linux/regset.h
81648+++ b/include/linux/regset.h
81649@@ -161,7 +161,8 @@ struct user_regset {
81650 unsigned int align;
81651 unsigned int bias;
81652 unsigned int core_note_type;
81653-};
81654+} __do_const;
81655+typedef struct user_regset __no_const user_regset_no_const;
81656
81657 /**
81658 * struct user_regset_view - available regsets
81659diff --git a/include/linux/relay.h b/include/linux/relay.h
81660index d7c8359..818daf5 100644
81661--- a/include/linux/relay.h
81662+++ b/include/linux/relay.h
81663@@ -157,7 +157,7 @@ struct rchan_callbacks
81664 * The callback should return 0 if successful, negative if not.
81665 */
81666 int (*remove_buf_file)(struct dentry *dentry);
81667-};
81668+} __no_const;
81669
81670 /*
81671 * CONFIG_RELAY kernel API, kernel/relay.c
81672diff --git a/include/linux/rio.h b/include/linux/rio.h
81673index 6bda06f..bf39a9b 100644
81674--- a/include/linux/rio.h
81675+++ b/include/linux/rio.h
81676@@ -358,7 +358,7 @@ struct rio_ops {
81677 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81678 u64 rstart, u32 size, u32 flags);
81679 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81680-};
81681+} __no_const;
81682
81683 #define RIO_RESOURCE_MEM 0x00000100
81684 #define RIO_RESOURCE_DOORBELL 0x00000200
81685diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81686index b66c211..13d2915 100644
81687--- a/include/linux/rmap.h
81688+++ b/include/linux/rmap.h
81689@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81690 void anon_vma_init(void); /* create anon_vma_cachep */
81691 int anon_vma_prepare(struct vm_area_struct *);
81692 void unlink_anon_vmas(struct vm_area_struct *);
81693-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81694-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81695+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81696+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81697
81698 static inline void anon_vma_merge(struct vm_area_struct *vma,
81699 struct vm_area_struct *next)
81700diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
81701index a964f72..b475afb 100644
81702--- a/include/linux/scatterlist.h
81703+++ b/include/linux/scatterlist.h
81704@@ -1,6 +1,7 @@
81705 #ifndef _LINUX_SCATTERLIST_H
81706 #define _LINUX_SCATTERLIST_H
81707
81708+#include <linux/sched.h>
81709 #include <linux/string.h>
81710 #include <linux/bug.h>
81711 #include <linux/mm.h>
81712@@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
81713 #ifdef CONFIG_DEBUG_SG
81714 BUG_ON(!virt_addr_valid(buf));
81715 #endif
81716+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
81717+ if (object_starts_on_stack(buf)) {
81718+ void *adjbuf = buf - current->stack + current->lowmem_stack;
81719+ sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
81720+ } else
81721+#endif
81722 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
81723 }
81724
81725diff --git a/include/linux/sched.h b/include/linux/sched.h
81726index 221b2bd..e2e5f82 100644
81727--- a/include/linux/sched.h
81728+++ b/include/linux/sched.h
81729@@ -131,6 +131,7 @@ struct fs_struct;
81730 struct perf_event_context;
81731 struct blk_plug;
81732 struct filename;
81733+struct linux_binprm;
81734
81735 #define VMACACHE_BITS 2
81736 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
81737@@ -380,7 +381,7 @@ extern char __sched_text_start[], __sched_text_end[];
81738 extern int in_sched_functions(unsigned long addr);
81739
81740 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81741-extern signed long schedule_timeout(signed long timeout);
81742+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81743 extern signed long schedule_timeout_interruptible(signed long timeout);
81744 extern signed long schedule_timeout_killable(signed long timeout);
81745 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81746@@ -391,6 +392,19 @@ struct nsproxy;
81747 struct user_namespace;
81748
81749 #ifdef CONFIG_MMU
81750+
81751+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81752+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81753+#else
81754+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81755+{
81756+ return 0;
81757+}
81758+#endif
81759+
81760+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81761+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81762+
81763 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81764 extern unsigned long
81765 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81766@@ -688,6 +702,17 @@ struct signal_struct {
81767 #ifdef CONFIG_TASKSTATS
81768 struct taskstats *stats;
81769 #endif
81770+
81771+#ifdef CONFIG_GRKERNSEC
81772+ u32 curr_ip;
81773+ u32 saved_ip;
81774+ u32 gr_saddr;
81775+ u32 gr_daddr;
81776+ u16 gr_sport;
81777+ u16 gr_dport;
81778+ u8 used_accept:1;
81779+#endif
81780+
81781 #ifdef CONFIG_AUDIT
81782 unsigned audit_tty;
81783 unsigned audit_tty_log_passwd;
81784@@ -714,7 +739,7 @@ struct signal_struct {
81785 struct mutex cred_guard_mutex; /* guard against foreign influences on
81786 * credential calculations
81787 * (notably. ptrace) */
81788-};
81789+} __randomize_layout;
81790
81791 /*
81792 * Bits in flags field of signal_struct.
81793@@ -768,6 +793,14 @@ struct user_struct {
81794 struct key *session_keyring; /* UID's default session keyring */
81795 #endif
81796
81797+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81798+ unsigned char kernel_banned;
81799+#endif
81800+#ifdef CONFIG_GRKERNSEC_BRUTE
81801+ unsigned char suid_banned;
81802+ unsigned long suid_ban_expires;
81803+#endif
81804+
81805 /* Hash table maintenance information */
81806 struct hlist_node uidhash_node;
81807 kuid_t uid;
81808@@ -775,7 +808,7 @@ struct user_struct {
81809 #ifdef CONFIG_PERF_EVENTS
81810 atomic_long_t locked_vm;
81811 #endif
81812-};
81813+} __randomize_layout;
81814
81815 extern int uids_sysfs_init(void);
81816
81817@@ -1179,6 +1212,9 @@ enum perf_event_task_context {
81818 struct task_struct {
81819 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
81820 void *stack;
81821+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
81822+ void *lowmem_stack;
81823+#endif
81824 atomic_t usage;
81825 unsigned int flags; /* per process flags, defined below */
81826 unsigned int ptrace;
81827@@ -1304,8 +1340,8 @@ struct task_struct {
81828 struct list_head thread_node;
81829
81830 struct completion *vfork_done; /* for vfork() */
81831- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81832- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81833+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81834+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81835
81836 cputime_t utime, stime, utimescaled, stimescaled;
81837 cputime_t gtime;
81838@@ -1330,11 +1366,6 @@ struct task_struct {
81839 struct task_cputime cputime_expires;
81840 struct list_head cpu_timers[3];
81841
81842-/* process credentials */
81843- const struct cred __rcu *real_cred; /* objective and real subjective task
81844- * credentials (COW) */
81845- const struct cred __rcu *cred; /* effective (overridable) subjective task
81846- * credentials (COW) */
81847 char comm[TASK_COMM_LEN]; /* executable name excluding path
81848 - access with [gs]et_task_comm (which lock
81849 it with task_lock())
81850@@ -1351,6 +1382,10 @@ struct task_struct {
81851 #endif
81852 /* CPU-specific state of this task */
81853 struct thread_struct thread;
81854+/* thread_info moved to task_struct */
81855+#ifdef CONFIG_X86
81856+ struct thread_info tinfo;
81857+#endif
81858 /* filesystem information */
81859 struct fs_struct *fs;
81860 /* open file information */
81861@@ -1427,6 +1462,10 @@ struct task_struct {
81862 gfp_t lockdep_reclaim_gfp;
81863 #endif
81864
81865+/* process credentials */
81866+ const struct cred __rcu *real_cred; /* objective and real subjective task
81867+ * credentials (COW) */
81868+
81869 /* journalling filesystem info */
81870 void *journal_info;
81871
81872@@ -1465,6 +1504,10 @@ struct task_struct {
81873 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81874 struct list_head cg_list;
81875 #endif
81876+
81877+ const struct cred __rcu *cred; /* effective (overridable) subjective task
81878+ * credentials (COW) */
81879+
81880 #ifdef CONFIG_FUTEX
81881 struct robust_list_head __user *robust_list;
81882 #ifdef CONFIG_COMPAT
81883@@ -1610,7 +1653,78 @@ struct task_struct {
81884 unsigned int sequential_io;
81885 unsigned int sequential_io_avg;
81886 #endif
81887-};
81888+
81889+#ifdef CONFIG_GRKERNSEC
81890+ /* grsecurity */
81891+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81892+ u64 exec_id;
81893+#endif
81894+#ifdef CONFIG_GRKERNSEC_SETXID
81895+ const struct cred *delayed_cred;
81896+#endif
81897+ struct dentry *gr_chroot_dentry;
81898+ struct acl_subject_label *acl;
81899+ struct acl_subject_label *tmpacl;
81900+ struct acl_role_label *role;
81901+ struct file *exec_file;
81902+ unsigned long brute_expires;
81903+ u16 acl_role_id;
81904+ u8 inherited;
81905+ /* is this the task that authenticated to the special role */
81906+ u8 acl_sp_role;
81907+ u8 is_writable;
81908+ u8 brute;
81909+ u8 gr_is_chrooted;
81910+#endif
81911+
81912+} __randomize_layout;
81913+
81914+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
81915+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
81916+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
81917+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
81918+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
81919+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
81920+
81921+#ifdef CONFIG_PAX_SOFTMODE
81922+extern int pax_softmode;
81923+#endif
81924+
81925+extern int pax_check_flags(unsigned long *);
81926+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
81927+
81928+/* if tsk != current then task_lock must be held on it */
81929+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81930+static inline unsigned long pax_get_flags(struct task_struct *tsk)
81931+{
81932+ if (likely(tsk->mm))
81933+ return tsk->mm->pax_flags;
81934+ else
81935+ return 0UL;
81936+}
81937+
81938+/* if tsk != current then task_lock must be held on it */
81939+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
81940+{
81941+ if (likely(tsk->mm)) {
81942+ tsk->mm->pax_flags = flags;
81943+ return 0;
81944+ }
81945+ return -EINVAL;
81946+}
81947+#endif
81948+
81949+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
81950+extern void pax_set_initial_flags(struct linux_binprm *bprm);
81951+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
81952+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
81953+#endif
81954+
81955+struct path;
81956+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
81957+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
81958+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
81959+extern void pax_report_refcount_overflow(struct pt_regs *regs);
81960
81961 /* Future-safe accessor for struct task_struct's cpus_allowed. */
81962 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
81963@@ -1692,7 +1806,7 @@ struct pid_namespace;
81964 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
81965 struct pid_namespace *ns);
81966
81967-static inline pid_t task_pid_nr(struct task_struct *tsk)
81968+static inline pid_t task_pid_nr(const struct task_struct *tsk)
81969 {
81970 return tsk->pid;
81971 }
81972@@ -2039,6 +2153,25 @@ extern u64 sched_clock_cpu(int cpu);
81973
81974 extern void sched_clock_init(void);
81975
81976+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
81977+static inline void populate_stack(void)
81978+{
81979+ struct task_struct *curtask = current;
81980+ int c;
81981+ int *ptr = curtask->stack;
81982+ int *end = curtask->stack + THREAD_SIZE;
81983+
81984+ while (ptr < end) {
81985+ c = *(volatile int *)ptr;
81986+ ptr += PAGE_SIZE/sizeof(int);
81987+ }
81988+}
81989+#else
81990+static inline void populate_stack(void)
81991+{
81992+}
81993+#endif
81994+
81995 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
81996 static inline void sched_clock_tick(void)
81997 {
81998@@ -2172,7 +2305,9 @@ void yield(void);
81999 extern struct exec_domain default_exec_domain;
82000
82001 union thread_union {
82002+#ifndef CONFIG_X86
82003 struct thread_info thread_info;
82004+#endif
82005 unsigned long stack[THREAD_SIZE/sizeof(long)];
82006 };
82007
82008@@ -2205,6 +2340,7 @@ extern struct pid_namespace init_pid_ns;
82009 */
82010
82011 extern struct task_struct *find_task_by_vpid(pid_t nr);
82012+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82013 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82014 struct pid_namespace *ns);
82015
82016@@ -2367,7 +2503,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82017 extern void exit_itimers(struct signal_struct *);
82018 extern void flush_itimer_signals(void);
82019
82020-extern void do_group_exit(int);
82021+extern __noreturn void do_group_exit(int);
82022
82023 extern int allow_signal(int);
82024 extern int disallow_signal(int);
82025@@ -2568,9 +2704,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82026
82027 #endif
82028
82029-static inline int object_is_on_stack(void *obj)
82030+static inline int object_starts_on_stack(const void *obj)
82031 {
82032- void *stack = task_stack_page(current);
82033+ const void *stack = task_stack_page(current);
82034
82035 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82036 }
82037diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82038index 8045a55..c959cd5 100644
82039--- a/include/linux/sched/sysctl.h
82040+++ b/include/linux/sched/sysctl.h
82041@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82042 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82043
82044 extern int sysctl_max_map_count;
82045+extern unsigned long sysctl_heap_stack_gap;
82046
82047 extern unsigned int sysctl_sched_latency;
82048 extern unsigned int sysctl_sched_min_granularity;
82049diff --git a/include/linux/security.h b/include/linux/security.h
82050index 6478ce3..5e6ad6e 100644
82051--- a/include/linux/security.h
82052+++ b/include/linux/security.h
82053@@ -27,6 +27,7 @@
82054 #include <linux/slab.h>
82055 #include <linux/err.h>
82056 #include <linux/string.h>
82057+#include <linux/grsecurity.h>
82058
82059 struct linux_binprm;
82060 struct cred;
82061@@ -116,8 +117,6 @@ struct seq_file;
82062
82063 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82064
82065-void reset_security_ops(void);
82066-
82067 #ifdef CONFIG_MMU
82068 extern unsigned long mmap_min_addr;
82069 extern unsigned long dac_mmap_min_addr;
82070@@ -1719,7 +1718,7 @@ struct security_operations {
82071 struct audit_context *actx);
82072 void (*audit_rule_free) (void *lsmrule);
82073 #endif /* CONFIG_AUDIT */
82074-};
82075+} __randomize_layout;
82076
82077 /* prototypes */
82078 extern int security_init(void);
82079diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82080index dc368b8..e895209 100644
82081--- a/include/linux/semaphore.h
82082+++ b/include/linux/semaphore.h
82083@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82084 }
82085
82086 extern void down(struct semaphore *sem);
82087-extern int __must_check down_interruptible(struct semaphore *sem);
82088+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82089 extern int __must_check down_killable(struct semaphore *sem);
82090 extern int __must_check down_trylock(struct semaphore *sem);
82091 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82092diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82093index 52e0097..383f21d 100644
82094--- a/include/linux/seq_file.h
82095+++ b/include/linux/seq_file.h
82096@@ -27,6 +27,9 @@ struct seq_file {
82097 struct mutex lock;
82098 const struct seq_operations *op;
82099 int poll_event;
82100+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82101+ u64 exec_id;
82102+#endif
82103 #ifdef CONFIG_USER_NS
82104 struct user_namespace *user_ns;
82105 #endif
82106@@ -39,6 +42,7 @@ struct seq_operations {
82107 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82108 int (*show) (struct seq_file *m, void *v);
82109 };
82110+typedef struct seq_operations __no_const seq_operations_no_const;
82111
82112 #define SEQ_SKIP 1
82113
82114@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82115
82116 char *mangle_path(char *s, const char *p, const char *esc);
82117 int seq_open(struct file *, const struct seq_operations *);
82118+int seq_open_restrict(struct file *, const struct seq_operations *);
82119 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82120 loff_t seq_lseek(struct file *, loff_t, int);
82121 int seq_release(struct inode *, struct file *);
82122@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82123 }
82124
82125 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82126+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82127 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82128 int single_release(struct inode *, struct file *);
82129 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82130diff --git a/include/linux/shm.h b/include/linux/shm.h
82131index 1e2cd2e..0288750 100644
82132--- a/include/linux/shm.h
82133+++ b/include/linux/shm.h
82134@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82135
82136 /* The task created the shm object. NULL if the task is dead. */
82137 struct task_struct *shm_creator;
82138+#ifdef CONFIG_GRKERNSEC
82139+ time_t shm_createtime;
82140+ pid_t shm_lapid;
82141+#endif
82142 };
82143
82144 /* shm_mode upper byte flags */
82145diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82146index 08074a8..e2ae280 100644
82147--- a/include/linux/skbuff.h
82148+++ b/include/linux/skbuff.h
82149@@ -717,7 +717,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82150 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82151 int node);
82152 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82153-static inline struct sk_buff *alloc_skb(unsigned int size,
82154+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82155 gfp_t priority)
82156 {
82157 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82158@@ -1825,7 +1825,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82159 return skb->inner_transport_header - skb->inner_network_header;
82160 }
82161
82162-static inline int skb_network_offset(const struct sk_buff *skb)
82163+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82164 {
82165 return skb_network_header(skb) - skb->data;
82166 }
82167@@ -1885,7 +1885,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82168 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82169 */
82170 #ifndef NET_SKB_PAD
82171-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82172+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82173 #endif
82174
82175 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82176@@ -2484,7 +2484,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82177 int *err);
82178 unsigned int datagram_poll(struct file *file, struct socket *sock,
82179 struct poll_table_struct *wait);
82180-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82181+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82182 struct iovec *to, int size);
82183 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82184 struct iovec *iov);
82185@@ -2776,6 +2776,9 @@ static inline void nf_reset(struct sk_buff *skb)
82186 nf_bridge_put(skb->nf_bridge);
82187 skb->nf_bridge = NULL;
82188 #endif
82189+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82190+ skb->nf_trace = 0;
82191+#endif
82192 }
82193
82194 static inline void nf_reset_trace(struct sk_buff *skb)
82195diff --git a/include/linux/slab.h b/include/linux/slab.h
82196index 307bfbe..a999cf3 100644
82197--- a/include/linux/slab.h
82198+++ b/include/linux/slab.h
82199@@ -14,15 +14,29 @@
82200 #include <linux/gfp.h>
82201 #include <linux/types.h>
82202 #include <linux/workqueue.h>
82203-
82204+#include <linux/err.h>
82205
82206 /*
82207 * Flags to pass to kmem_cache_create().
82208 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82209 */
82210 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82211+
82212+#ifdef CONFIG_PAX_USERCOPY_SLABS
82213+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82214+#else
82215+#define SLAB_USERCOPY 0x00000000UL
82216+#endif
82217+
82218 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82219 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82220+
82221+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82222+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82223+#else
82224+#define SLAB_NO_SANITIZE 0x00000000UL
82225+#endif
82226+
82227 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82228 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82229 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82230@@ -98,10 +112,13 @@
82231 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82232 * Both make kfree a no-op.
82233 */
82234-#define ZERO_SIZE_PTR ((void *)16)
82235+#define ZERO_SIZE_PTR \
82236+({ \
82237+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82238+ (void *)(-MAX_ERRNO-1L); \
82239+})
82240
82241-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82242- (unsigned long)ZERO_SIZE_PTR)
82243+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82244
82245 #include <linux/kmemleak.h>
82246
82247@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82248 void kfree(const void *);
82249 void kzfree(const void *);
82250 size_t ksize(const void *);
82251+const char *check_heap_object(const void *ptr, unsigned long n);
82252+bool is_usercopy_object(const void *ptr);
82253
82254 /*
82255 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82256@@ -174,7 +193,7 @@ struct kmem_cache {
82257 unsigned int align; /* Alignment as calculated */
82258 unsigned long flags; /* Active flags on the slab */
82259 const char *name; /* Slab name for sysfs */
82260- int refcount; /* Use counter */
82261+ atomic_t refcount; /* Use counter */
82262 void (*ctor)(void *); /* Called on object slot creation */
82263 struct list_head list; /* List of all slab caches on the system */
82264 };
82265@@ -259,6 +278,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82266 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82267 #endif
82268
82269+#ifdef CONFIG_PAX_USERCOPY_SLABS
82270+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82271+#endif
82272+
82273 /*
82274 * Figure out which kmalloc slab an allocation of a certain size
82275 * belongs to.
82276@@ -267,7 +290,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82277 * 2 = 120 .. 192 bytes
82278 * n = 2^(n-1) .. 2^n -1
82279 */
82280-static __always_inline int kmalloc_index(size_t size)
82281+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82282 {
82283 if (!size)
82284 return 0;
82285@@ -310,11 +333,11 @@ static __always_inline int kmalloc_index(size_t size)
82286 }
82287 #endif /* !CONFIG_SLOB */
82288
82289-void *__kmalloc(size_t size, gfp_t flags);
82290+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82291 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82292
82293 #ifdef CONFIG_NUMA
82294-void *__kmalloc_node(size_t size, gfp_t flags, int node);
82295+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82296 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82297 #else
82298 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82299diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82300index 8235dfb..47ce586 100644
82301--- a/include/linux/slab_def.h
82302+++ b/include/linux/slab_def.h
82303@@ -38,7 +38,7 @@ struct kmem_cache {
82304 /* 4) cache creation/removal */
82305 const char *name;
82306 struct list_head list;
82307- int refcount;
82308+ atomic_t refcount;
82309 int object_size;
82310 int align;
82311
82312@@ -54,10 +54,14 @@ struct kmem_cache {
82313 unsigned long node_allocs;
82314 unsigned long node_frees;
82315 unsigned long node_overflow;
82316- atomic_t allochit;
82317- atomic_t allocmiss;
82318- atomic_t freehit;
82319- atomic_t freemiss;
82320+ atomic_unchecked_t allochit;
82321+ atomic_unchecked_t allocmiss;
82322+ atomic_unchecked_t freehit;
82323+ atomic_unchecked_t freemiss;
82324+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82325+ atomic_unchecked_t sanitized;
82326+ atomic_unchecked_t not_sanitized;
82327+#endif
82328
82329 /*
82330 * If debugging is enabled, then the allocator can add additional
82331diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82332index d82abd4..408c3a0 100644
82333--- a/include/linux/slub_def.h
82334+++ b/include/linux/slub_def.h
82335@@ -74,7 +74,7 @@ struct kmem_cache {
82336 struct kmem_cache_order_objects max;
82337 struct kmem_cache_order_objects min;
82338 gfp_t allocflags; /* gfp flags to use on each alloc */
82339- int refcount; /* Refcount for slab cache destroy */
82340+ atomic_t refcount; /* Refcount for slab cache destroy */
82341 void (*ctor)(void *);
82342 int inuse; /* Offset to metadata */
82343 int align; /* Alignment */
82344diff --git a/include/linux/smp.h b/include/linux/smp.h
82345index 633f5ed..6c3dc3f 100644
82346--- a/include/linux/smp.h
82347+++ b/include/linux/smp.h
82348@@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
82349 #endif
82350
82351 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82352+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82353 #define put_cpu() preempt_enable()
82354+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82355
82356 /*
82357 * Callback to arch code if there's nosmp or maxcpus=0 on the
82358diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82359index 46cca4c..3323536 100644
82360--- a/include/linux/sock_diag.h
82361+++ b/include/linux/sock_diag.h
82362@@ -11,7 +11,7 @@ struct sock;
82363 struct sock_diag_handler {
82364 __u8 family;
82365 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82366-};
82367+} __do_const;
82368
82369 int sock_diag_register(const struct sock_diag_handler *h);
82370 void sock_diag_unregister(const struct sock_diag_handler *h);
82371diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82372index 680f9a3..f13aeb0 100644
82373--- a/include/linux/sonet.h
82374+++ b/include/linux/sonet.h
82375@@ -7,7 +7,7 @@
82376 #include <uapi/linux/sonet.h>
82377
82378 struct k_sonet_stats {
82379-#define __HANDLE_ITEM(i) atomic_t i
82380+#define __HANDLE_ITEM(i) atomic_unchecked_t i
82381 __SONET_ITEMS
82382 #undef __HANDLE_ITEM
82383 };
82384diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82385index 07d8e53..dc934c9 100644
82386--- a/include/linux/sunrpc/addr.h
82387+++ b/include/linux/sunrpc/addr.h
82388@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82389 {
82390 switch (sap->sa_family) {
82391 case AF_INET:
82392- return ntohs(((struct sockaddr_in *)sap)->sin_port);
82393+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82394 case AF_INET6:
82395- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82396+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82397 }
82398 return 0;
82399 }
82400@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82401 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82402 const struct sockaddr *src)
82403 {
82404- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82405+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82406 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82407
82408 dsin->sin_family = ssin->sin_family;
82409@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82410 if (sa->sa_family != AF_INET6)
82411 return 0;
82412
82413- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82414+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82415 }
82416
82417 #endif /* _LINUX_SUNRPC_ADDR_H */
82418diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82419index 70736b9..37f33db 100644
82420--- a/include/linux/sunrpc/clnt.h
82421+++ b/include/linux/sunrpc/clnt.h
82422@@ -97,7 +97,7 @@ struct rpc_procinfo {
82423 unsigned int p_timer; /* Which RTT timer to use */
82424 u32 p_statidx; /* Which procedure to account */
82425 const char * p_name; /* name of procedure */
82426-};
82427+} __do_const;
82428
82429 #ifdef __KERNEL__
82430
82431diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82432index 04e7632..2e2a8a3 100644
82433--- a/include/linux/sunrpc/svc.h
82434+++ b/include/linux/sunrpc/svc.h
82435@@ -412,7 +412,7 @@ struct svc_procedure {
82436 unsigned int pc_count; /* call count */
82437 unsigned int pc_cachetype; /* cache info (NFS) */
82438 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82439-};
82440+} __do_const;
82441
82442 /*
82443 * Function prototypes.
82444diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82445index 0b8e3e6..33e0a01 100644
82446--- a/include/linux/sunrpc/svc_rdma.h
82447+++ b/include/linux/sunrpc/svc_rdma.h
82448@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82449 extern unsigned int svcrdma_max_requests;
82450 extern unsigned int svcrdma_max_req_size;
82451
82452-extern atomic_t rdma_stat_recv;
82453-extern atomic_t rdma_stat_read;
82454-extern atomic_t rdma_stat_write;
82455-extern atomic_t rdma_stat_sq_starve;
82456-extern atomic_t rdma_stat_rq_starve;
82457-extern atomic_t rdma_stat_rq_poll;
82458-extern atomic_t rdma_stat_rq_prod;
82459-extern atomic_t rdma_stat_sq_poll;
82460-extern atomic_t rdma_stat_sq_prod;
82461+extern atomic_unchecked_t rdma_stat_recv;
82462+extern atomic_unchecked_t rdma_stat_read;
82463+extern atomic_unchecked_t rdma_stat_write;
82464+extern atomic_unchecked_t rdma_stat_sq_starve;
82465+extern atomic_unchecked_t rdma_stat_rq_starve;
82466+extern atomic_unchecked_t rdma_stat_rq_poll;
82467+extern atomic_unchecked_t rdma_stat_rq_prod;
82468+extern atomic_unchecked_t rdma_stat_sq_poll;
82469+extern atomic_unchecked_t rdma_stat_sq_prod;
82470
82471 #define RPCRDMA_VERSION 1
82472
82473diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82474index 8d71d65..f79586e 100644
82475--- a/include/linux/sunrpc/svcauth.h
82476+++ b/include/linux/sunrpc/svcauth.h
82477@@ -120,7 +120,7 @@ struct auth_ops {
82478 int (*release)(struct svc_rqst *rq);
82479 void (*domain_release)(struct auth_domain *);
82480 int (*set_client)(struct svc_rqst *rq);
82481-};
82482+} __do_const;
82483
82484 #define SVC_GARBAGE 1
82485 #define SVC_SYSERR 2
82486diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82487index a5ffd32..0935dea 100644
82488--- a/include/linux/swiotlb.h
82489+++ b/include/linux/swiotlb.h
82490@@ -60,7 +60,8 @@ extern void
82491
82492 extern void
82493 swiotlb_free_coherent(struct device *hwdev, size_t size,
82494- void *vaddr, dma_addr_t dma_handle);
82495+ void *vaddr, dma_addr_t dma_handle,
82496+ struct dma_attrs *attrs);
82497
82498 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82499 unsigned long offset, size_t size,
82500diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82501index a4a0588..752870e 100644
82502--- a/include/linux/syscalls.h
82503+++ b/include/linux/syscalls.h
82504@@ -98,10 +98,16 @@ struct sigaltstack;
82505 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82506
82507 #define __SC_DECL(t, a) t a
82508+#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))
82509 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
82510 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
82511 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82512-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82513+#define __SC_LONG(t, a) __typeof( \
82514+ __builtin_choose_expr( \
82515+ sizeof(t) > sizeof(int), \
82516+ (t) 0, \
82517+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82518+ )) a
82519 #define __SC_CAST(t, a) (t) a
82520 #define __SC_ARGS(t, a) a
82521 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82522@@ -379,11 +385,11 @@ asmlinkage long sys_sync(void);
82523 asmlinkage long sys_fsync(unsigned int fd);
82524 asmlinkage long sys_fdatasync(unsigned int fd);
82525 asmlinkage long sys_bdflush(int func, long data);
82526-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82527- char __user *type, unsigned long flags,
82528+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82529+ const char __user *type, unsigned long flags,
82530 void __user *data);
82531-asmlinkage long sys_umount(char __user *name, int flags);
82532-asmlinkage long sys_oldumount(char __user *name);
82533+asmlinkage long sys_umount(const char __user *name, int flags);
82534+asmlinkage long sys_oldumount(const char __user *name);
82535 asmlinkage long sys_truncate(const char __user *path, long length);
82536 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82537 asmlinkage long sys_stat(const char __user *filename,
82538@@ -595,7 +601,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82539 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82540 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82541 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82542- struct sockaddr __user *, int);
82543+ struct sockaddr __user *, int) __intentional_overflow(0);
82544 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82545 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82546 unsigned int vlen, unsigned flags);
82547diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82548index 27b3b0b..e093dd9 100644
82549--- a/include/linux/syscore_ops.h
82550+++ b/include/linux/syscore_ops.h
82551@@ -16,7 +16,7 @@ struct syscore_ops {
82552 int (*suspend)(void);
82553 void (*resume)(void);
82554 void (*shutdown)(void);
82555-};
82556+} __do_const;
82557
82558 extern void register_syscore_ops(struct syscore_ops *ops);
82559 extern void unregister_syscore_ops(struct syscore_ops *ops);
82560diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82561index 14a8ff2..fa95f3a 100644
82562--- a/include/linux/sysctl.h
82563+++ b/include/linux/sysctl.h
82564@@ -34,13 +34,13 @@ struct ctl_table_root;
82565 struct ctl_table_header;
82566 struct ctl_dir;
82567
82568-typedef struct ctl_table ctl_table;
82569-
82570 typedef int proc_handler (struct ctl_table *ctl, int write,
82571 void __user *buffer, size_t *lenp, loff_t *ppos);
82572
82573 extern int proc_dostring(struct ctl_table *, int,
82574 void __user *, size_t *, loff_t *);
82575+extern int proc_dostring_modpriv(struct ctl_table *, int,
82576+ void __user *, size_t *, loff_t *);
82577 extern int proc_dointvec(struct ctl_table *, int,
82578 void __user *, size_t *, loff_t *);
82579 extern int proc_dointvec_minmax(struct ctl_table *, int,
82580@@ -115,7 +115,9 @@ struct ctl_table
82581 struct ctl_table_poll *poll;
82582 void *extra1;
82583 void *extra2;
82584-};
82585+} __do_const __randomize_layout;
82586+typedef struct ctl_table __no_const ctl_table_no_const;
82587+typedef struct ctl_table ctl_table;
82588
82589 struct ctl_node {
82590 struct rb_node node;
82591diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82592index 5ffaa34..fe3e31c 100644
82593--- a/include/linux/sysfs.h
82594+++ b/include/linux/sysfs.h
82595@@ -34,7 +34,8 @@ struct attribute {
82596 struct lock_class_key *key;
82597 struct lock_class_key skey;
82598 #endif
82599-};
82600+} __do_const;
82601+typedef struct attribute __no_const attribute_no_const;
82602
82603 /**
82604 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82605@@ -63,7 +64,8 @@ struct attribute_group {
82606 struct attribute *, int);
82607 struct attribute **attrs;
82608 struct bin_attribute **bin_attrs;
82609-};
82610+} __do_const;
82611+typedef struct attribute_group __no_const attribute_group_no_const;
82612
82613 /**
82614 * Use these macros to make defining attributes easier. See include/linux/device.h
82615@@ -128,7 +130,8 @@ struct bin_attribute {
82616 char *, loff_t, size_t);
82617 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82618 struct vm_area_struct *vma);
82619-};
82620+} __do_const;
82621+typedef struct bin_attribute __no_const bin_attribute_no_const;
82622
82623 /**
82624 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82625diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82626index 387fa7d..3fcde6b 100644
82627--- a/include/linux/sysrq.h
82628+++ b/include/linux/sysrq.h
82629@@ -16,6 +16,7 @@
82630
82631 #include <linux/errno.h>
82632 #include <linux/types.h>
82633+#include <linux/compiler.h>
82634
82635 /* Possible values of bitmask for enabling sysrq functions */
82636 /* 0x0001 is reserved for enable everything */
82637@@ -33,7 +34,7 @@ struct sysrq_key_op {
82638 char *help_msg;
82639 char *action_msg;
82640 int enable_mask;
82641-};
82642+} __do_const;
82643
82644 #ifdef CONFIG_MAGIC_SYSRQ
82645
82646diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82647index fddbe20..a0e76ab 100644
82648--- a/include/linux/thread_info.h
82649+++ b/include/linux/thread_info.h
82650@@ -161,6 +161,13 @@ static inline bool test_and_clear_restore_sigmask(void)
82651 #error "no set_restore_sigmask() provided and default one won't work"
82652 #endif
82653
82654+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
82655+
82656+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82657+{
82658+ __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
82659+}
82660+
82661 #endif /* __KERNEL__ */
82662
82663 #endif /* _LINUX_THREAD_INFO_H */
82664diff --git a/include/linux/tty.h b/include/linux/tty.h
82665index 1c3316a..ae83b9f 100644
82666--- a/include/linux/tty.h
82667+++ b/include/linux/tty.h
82668@@ -202,7 +202,7 @@ struct tty_port {
82669 const struct tty_port_operations *ops; /* Port operations */
82670 spinlock_t lock; /* Lock protecting tty field */
82671 int blocked_open; /* Waiting to open */
82672- int count; /* Usage count */
82673+ atomic_t count; /* Usage count */
82674 wait_queue_head_t open_wait; /* Open waiters */
82675 wait_queue_head_t close_wait; /* Close waiters */
82676 wait_queue_head_t delta_msr_wait; /* Modem status change */
82677@@ -284,7 +284,7 @@ struct tty_struct {
82678 /* If the tty has a pending do_SAK, queue it here - akpm */
82679 struct work_struct SAK_work;
82680 struct tty_port *port;
82681-};
82682+} __randomize_layout;
82683
82684 /* Each of a tty's open files has private_data pointing to tty_file_private */
82685 struct tty_file_private {
82686@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
82687 struct tty_struct *tty, struct file *filp);
82688 static inline int tty_port_users(struct tty_port *port)
82689 {
82690- return port->count + port->blocked_open;
82691+ return atomic_read(&port->count) + port->blocked_open;
82692 }
82693
82694 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82695diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82696index 756a609..89db85e 100644
82697--- a/include/linux/tty_driver.h
82698+++ b/include/linux/tty_driver.h
82699@@ -285,7 +285,7 @@ struct tty_operations {
82700 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82701 #endif
82702 const struct file_operations *proc_fops;
82703-};
82704+} __do_const __randomize_layout;
82705
82706 struct tty_driver {
82707 int magic; /* magic number for this structure */
82708@@ -319,7 +319,7 @@ struct tty_driver {
82709
82710 const struct tty_operations *ops;
82711 struct list_head tty_drivers;
82712-};
82713+} __randomize_layout;
82714
82715 extern struct list_head tty_drivers;
82716
82717diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82718index add26da..22c00bef 100644
82719--- a/include/linux/tty_ldisc.h
82720+++ b/include/linux/tty_ldisc.h
82721@@ -212,7 +212,7 @@ struct tty_ldisc_ops {
82722
82723 struct module *owner;
82724
82725- int refcount;
82726+ atomic_t refcount;
82727 };
82728
82729 struct tty_ldisc {
82730diff --git a/include/linux/types.h b/include/linux/types.h
82731index 4d118ba..c3ee9bf 100644
82732--- a/include/linux/types.h
82733+++ b/include/linux/types.h
82734@@ -176,10 +176,26 @@ typedef struct {
82735 int counter;
82736 } atomic_t;
82737
82738+#ifdef CONFIG_PAX_REFCOUNT
82739+typedef struct {
82740+ int counter;
82741+} atomic_unchecked_t;
82742+#else
82743+typedef atomic_t atomic_unchecked_t;
82744+#endif
82745+
82746 #ifdef CONFIG_64BIT
82747 typedef struct {
82748 long counter;
82749 } atomic64_t;
82750+
82751+#ifdef CONFIG_PAX_REFCOUNT
82752+typedef struct {
82753+ long counter;
82754+} atomic64_unchecked_t;
82755+#else
82756+typedef atomic64_t atomic64_unchecked_t;
82757+#endif
82758 #endif
82759
82760 struct list_head {
82761diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
82762index ecd3319..8a36ded 100644
82763--- a/include/linux/uaccess.h
82764+++ b/include/linux/uaccess.h
82765@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
82766 long ret; \
82767 mm_segment_t old_fs = get_fs(); \
82768 \
82769- set_fs(KERNEL_DS); \
82770 pagefault_disable(); \
82771- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
82772- pagefault_enable(); \
82773+ set_fs(KERNEL_DS); \
82774+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
82775 set_fs(old_fs); \
82776+ pagefault_enable(); \
82777 ret; \
82778 })
82779
82780diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
82781index 2d1f9b6..d7a9fce 100644
82782--- a/include/linux/uidgid.h
82783+++ b/include/linux/uidgid.h
82784@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
82785
82786 #endif /* CONFIG_USER_NS */
82787
82788+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
82789+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
82790+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
82791+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
82792+
82793 #endif /* _LINUX_UIDGID_H */
82794diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82795index 99c1b4d..562e6f3 100644
82796--- a/include/linux/unaligned/access_ok.h
82797+++ b/include/linux/unaligned/access_ok.h
82798@@ -4,34 +4,34 @@
82799 #include <linux/kernel.h>
82800 #include <asm/byteorder.h>
82801
82802-static inline u16 get_unaligned_le16(const void *p)
82803+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82804 {
82805- return le16_to_cpup((__le16 *)p);
82806+ return le16_to_cpup((const __le16 *)p);
82807 }
82808
82809-static inline u32 get_unaligned_le32(const void *p)
82810+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82811 {
82812- return le32_to_cpup((__le32 *)p);
82813+ return le32_to_cpup((const __le32 *)p);
82814 }
82815
82816-static inline u64 get_unaligned_le64(const void *p)
82817+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82818 {
82819- return le64_to_cpup((__le64 *)p);
82820+ return le64_to_cpup((const __le64 *)p);
82821 }
82822
82823-static inline u16 get_unaligned_be16(const void *p)
82824+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82825 {
82826- return be16_to_cpup((__be16 *)p);
82827+ return be16_to_cpup((const __be16 *)p);
82828 }
82829
82830-static inline u32 get_unaligned_be32(const void *p)
82831+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82832 {
82833- return be32_to_cpup((__be32 *)p);
82834+ return be32_to_cpup((const __be32 *)p);
82835 }
82836
82837-static inline u64 get_unaligned_be64(const void *p)
82838+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82839 {
82840- return be64_to_cpup((__be64 *)p);
82841+ return be64_to_cpup((const __be64 *)p);
82842 }
82843
82844 static inline void put_unaligned_le16(u16 val, void *p)
82845diff --git a/include/linux/usb.h b/include/linux/usb.h
82846index 6b7ec37..4428419 100644
82847--- a/include/linux/usb.h
82848+++ b/include/linux/usb.h
82849@@ -569,7 +569,7 @@ struct usb_device {
82850 int maxchild;
82851
82852 u32 quirks;
82853- atomic_t urbnum;
82854+ atomic_unchecked_t urbnum;
82855
82856 unsigned long active_duration;
82857
82858@@ -1653,7 +1653,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82859
82860 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82861 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82862- void *data, __u16 size, int timeout);
82863+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
82864 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82865 void *data, int len, int *actual_length, int timeout);
82866 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82867diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82868index e452ba6..78f8e80 100644
82869--- a/include/linux/usb/renesas_usbhs.h
82870+++ b/include/linux/usb/renesas_usbhs.h
82871@@ -39,7 +39,7 @@ enum {
82872 */
82873 struct renesas_usbhs_driver_callback {
82874 int (*notify_hotplug)(struct platform_device *pdev);
82875-};
82876+} __no_const;
82877
82878 /*
82879 * callback functions for platform
82880diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
82881index 4836ba3..603f6ee 100644
82882--- a/include/linux/user_namespace.h
82883+++ b/include/linux/user_namespace.h
82884@@ -33,7 +33,7 @@ struct user_namespace {
82885 struct key *persistent_keyring_register;
82886 struct rw_semaphore persistent_keyring_register_sem;
82887 #endif
82888-};
82889+} __randomize_layout;
82890
82891 extern struct user_namespace init_user_ns;
82892
82893diff --git a/include/linux/utsname.h b/include/linux/utsname.h
82894index 239e277..22a5cf5 100644
82895--- a/include/linux/utsname.h
82896+++ b/include/linux/utsname.h
82897@@ -24,7 +24,7 @@ struct uts_namespace {
82898 struct new_utsname name;
82899 struct user_namespace *user_ns;
82900 unsigned int proc_inum;
82901-};
82902+} __randomize_layout;
82903 extern struct uts_namespace init_uts_ns;
82904
82905 #ifdef CONFIG_UTS_NS
82906diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
82907index 6f8fbcf..4efc177 100644
82908--- a/include/linux/vermagic.h
82909+++ b/include/linux/vermagic.h
82910@@ -25,9 +25,42 @@
82911 #define MODULE_ARCH_VERMAGIC ""
82912 #endif
82913
82914+#ifdef CONFIG_PAX_REFCOUNT
82915+#define MODULE_PAX_REFCOUNT "REFCOUNT "
82916+#else
82917+#define MODULE_PAX_REFCOUNT ""
82918+#endif
82919+
82920+#ifdef CONSTIFY_PLUGIN
82921+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
82922+#else
82923+#define MODULE_CONSTIFY_PLUGIN ""
82924+#endif
82925+
82926+#ifdef STACKLEAK_PLUGIN
82927+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
82928+#else
82929+#define MODULE_STACKLEAK_PLUGIN ""
82930+#endif
82931+
82932+#ifdef RANDSTRUCT_PLUGIN
82933+#include <generated/randomize_layout_hash.h>
82934+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
82935+#else
82936+#define MODULE_RANDSTRUCT_PLUGIN
82937+#endif
82938+
82939+#ifdef CONFIG_GRKERNSEC
82940+#define MODULE_GRSEC "GRSEC "
82941+#else
82942+#define MODULE_GRSEC ""
82943+#endif
82944+
82945 #define VERMAGIC_STRING \
82946 UTS_RELEASE " " \
82947 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
82948 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
82949- MODULE_ARCH_VERMAGIC
82950+ MODULE_ARCH_VERMAGIC \
82951+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
82952+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
82953
82954diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
82955index 502073a..a7de024 100644
82956--- a/include/linux/vga_switcheroo.h
82957+++ b/include/linux/vga_switcheroo.h
82958@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
82959
82960 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
82961
82962-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
82963-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
82964+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
82965+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
82966 #else
82967
82968 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
82969@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
82970
82971 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
82972
82973-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82974-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82975+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82976+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82977
82978 #endif
82979 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
82980diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
82981index 4b8a891..e9a2863 100644
82982--- a/include/linux/vmalloc.h
82983+++ b/include/linux/vmalloc.h
82984@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
82985 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
82986 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
82987 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
82988+
82989+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
82990+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
82991+#endif
82992+
82993 /* bits [20..32] reserved for arch specific ioremap internals */
82994
82995 /*
82996@@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
82997 unsigned long flags, pgprot_t prot);
82998 extern void vunmap(const void *addr);
82999
83000+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
83001+extern void unmap_process_stacks(struct task_struct *task);
83002+#endif
83003+
83004 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
83005 unsigned long uaddr, void *kaddr,
83006 unsigned long size);
83007@@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
83008
83009 /* for /dev/kmem */
83010 extern long vread(char *buf, char *addr, unsigned long count);
83011-extern long vwrite(char *buf, char *addr, unsigned long count);
83012+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83013
83014 /*
83015 * Internals. Dont't use..
83016diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83017index 45c9cd1..20bd0bf 100644
83018--- a/include/linux/vmstat.h
83019+++ b/include/linux/vmstat.h
83020@@ -102,18 +102,18 @@ static inline void vm_events_fold_cpu(int cpu)
83021 /*
83022 * Zone based page accounting with per cpu differentials.
83023 */
83024-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83025+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83026
83027 static inline void zone_page_state_add(long x, struct zone *zone,
83028 enum zone_stat_item item)
83029 {
83030- atomic_long_add(x, &zone->vm_stat[item]);
83031- atomic_long_add(x, &vm_stat[item]);
83032+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83033+ atomic_long_add_unchecked(x, &vm_stat[item]);
83034 }
83035
83036-static inline unsigned long global_page_state(enum zone_stat_item item)
83037+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83038 {
83039- long x = atomic_long_read(&vm_stat[item]);
83040+ long x = atomic_long_read_unchecked(&vm_stat[item]);
83041 #ifdef CONFIG_SMP
83042 if (x < 0)
83043 x = 0;
83044@@ -121,10 +121,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83045 return x;
83046 }
83047
83048-static inline unsigned long zone_page_state(struct zone *zone,
83049+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83050 enum zone_stat_item item)
83051 {
83052- long x = atomic_long_read(&zone->vm_stat[item]);
83053+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83054 #ifdef CONFIG_SMP
83055 if (x < 0)
83056 x = 0;
83057@@ -141,7 +141,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83058 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83059 enum zone_stat_item item)
83060 {
83061- long x = atomic_long_read(&zone->vm_stat[item]);
83062+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83063
83064 #ifdef CONFIG_SMP
83065 int cpu;
83066@@ -228,14 +228,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
83067
83068 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83069 {
83070- atomic_long_inc(&zone->vm_stat[item]);
83071- atomic_long_inc(&vm_stat[item]);
83072+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
83073+ atomic_long_inc_unchecked(&vm_stat[item]);
83074 }
83075
83076 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83077 {
83078- atomic_long_dec(&zone->vm_stat[item]);
83079- atomic_long_dec(&vm_stat[item]);
83080+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
83081+ atomic_long_dec_unchecked(&vm_stat[item]);
83082 }
83083
83084 static inline void __inc_zone_page_state(struct page *page,
83085diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83086index 91b0a68..0e9adf6 100644
83087--- a/include/linux/xattr.h
83088+++ b/include/linux/xattr.h
83089@@ -28,7 +28,7 @@ struct xattr_handler {
83090 size_t size, int handler_flags);
83091 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83092 size_t size, int flags, int handler_flags);
83093-};
83094+} __do_const;
83095
83096 struct xattr {
83097 const char *name;
83098@@ -37,6 +37,9 @@ struct xattr {
83099 };
83100
83101 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83102+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83103+ssize_t pax_getxattr(struct dentry *, void *, size_t);
83104+#endif
83105 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83106 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83107 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83108diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83109index 9c5a6b4..09c9438 100644
83110--- a/include/linux/zlib.h
83111+++ b/include/linux/zlib.h
83112@@ -31,6 +31,7 @@
83113 #define _ZLIB_H
83114
83115 #include <linux/zconf.h>
83116+#include <linux/compiler.h>
83117
83118 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83119 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83120@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83121
83122 /* basic functions */
83123
83124-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83125+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83126 /*
83127 Returns the number of bytes that needs to be allocated for a per-
83128 stream workspace with the specified parameters. A pointer to this
83129diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83130index eec6e46..82d5641 100644
83131--- a/include/media/v4l2-dev.h
83132+++ b/include/media/v4l2-dev.h
83133@@ -77,7 +77,7 @@ struct v4l2_file_operations {
83134 int (*mmap) (struct file *, struct vm_area_struct *);
83135 int (*open) (struct file *);
83136 int (*release) (struct file *);
83137-};
83138+} __do_const;
83139
83140 /*
83141 * Newer version of video_device, handled by videodev2.c
83142diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83143index c9b1593..a572459 100644
83144--- a/include/media/v4l2-device.h
83145+++ b/include/media/v4l2-device.h
83146@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83147 this function returns 0. If the name ends with a digit (e.g. cx18),
83148 then the name will be set to cx18-0 since cx180 looks really odd. */
83149 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83150- atomic_t *instance);
83151+ atomic_unchecked_t *instance);
83152
83153 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83154 Since the parent disappears this ensures that v4l2_dev doesn't have an
83155diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83156index d9fa68f..45c88d1 100644
83157--- a/include/net/9p/transport.h
83158+++ b/include/net/9p/transport.h
83159@@ -63,7 +63,7 @@ struct p9_trans_module {
83160 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
83161 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83162 char *, char *, int , int, int, int);
83163-};
83164+} __do_const;
83165
83166 void v9fs_register_trans(struct p9_trans_module *m);
83167 void v9fs_unregister_trans(struct p9_trans_module *m);
83168diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83169index a175ba4..196eb82 100644
83170--- a/include/net/af_unix.h
83171+++ b/include/net/af_unix.h
83172@@ -36,7 +36,7 @@ struct unix_skb_parms {
83173 u32 secid; /* Security ID */
83174 #endif
83175 u32 consumed;
83176-};
83177+} __randomize_layout;
83178
83179 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83180 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83181diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83182index 4abdcb2..945c5cc 100644
83183--- a/include/net/bluetooth/l2cap.h
83184+++ b/include/net/bluetooth/l2cap.h
83185@@ -601,7 +601,7 @@ struct l2cap_ops {
83186 long (*get_sndtimeo) (struct l2cap_chan *chan);
83187 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83188 unsigned long len, int nb);
83189-};
83190+} __do_const;
83191
83192 struct l2cap_conn {
83193 struct hci_conn *hcon;
83194diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83195index f2ae33d..c457cf0 100644
83196--- a/include/net/caif/cfctrl.h
83197+++ b/include/net/caif/cfctrl.h
83198@@ -52,7 +52,7 @@ struct cfctrl_rsp {
83199 void (*radioset_rsp)(void);
83200 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83201 struct cflayer *client_layer);
83202-};
83203+} __no_const;
83204
83205 /* Link Setup Parameters for CAIF-Links. */
83206 struct cfctrl_link_param {
83207@@ -101,8 +101,8 @@ struct cfctrl_request_info {
83208 struct cfctrl {
83209 struct cfsrvl serv;
83210 struct cfctrl_rsp res;
83211- atomic_t req_seq_no;
83212- atomic_t rsp_seq_no;
83213+ atomic_unchecked_t req_seq_no;
83214+ atomic_unchecked_t rsp_seq_no;
83215 struct list_head list;
83216 /* Protects from simultaneous access to first_req list */
83217 spinlock_t info_list_lock;
83218diff --git a/include/net/flow.h b/include/net/flow.h
83219index 8109a15..504466d 100644
83220--- a/include/net/flow.h
83221+++ b/include/net/flow.h
83222@@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
83223
83224 void flow_cache_flush(struct net *net);
83225 void flow_cache_flush_deferred(struct net *net);
83226-extern atomic_t flow_cache_genid;
83227+extern atomic_unchecked_t flow_cache_genid;
83228
83229 #endif
83230diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83231index 93695f0..766d71c 100644
83232--- a/include/net/genetlink.h
83233+++ b/include/net/genetlink.h
83234@@ -120,7 +120,7 @@ struct genl_ops {
83235 u8 cmd;
83236 u8 internal_flags;
83237 u8 flags;
83238-};
83239+} __do_const;
83240
83241 int __genl_register_family(struct genl_family *family);
83242
83243diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83244index 734d9b5..48a9a4b 100644
83245--- a/include/net/gro_cells.h
83246+++ b/include/net/gro_cells.h
83247@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83248 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83249
83250 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83251- atomic_long_inc(&dev->rx_dropped);
83252+ atomic_long_inc_unchecked(&dev->rx_dropped);
83253 kfree_skb(skb);
83254 return;
83255 }
83256diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83257index 7a43138..bc76865 100644
83258--- a/include/net/inet_connection_sock.h
83259+++ b/include/net/inet_connection_sock.h
83260@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83261 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83262 int (*bind_conflict)(const struct sock *sk,
83263 const struct inet_bind_bucket *tb, bool relax);
83264-};
83265+} __do_const;
83266
83267 /** inet_connection_sock - INET connection oriented sock
83268 *
83269diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83270index 058271b..1a44af7 100644
83271--- a/include/net/inetpeer.h
83272+++ b/include/net/inetpeer.h
83273@@ -47,8 +47,8 @@ struct inet_peer {
83274 */
83275 union {
83276 struct {
83277- atomic_t rid; /* Frag reception counter */
83278- atomic_t ip_id_count; /* IP ID for the next packet */
83279+ atomic_unchecked_t rid; /* Frag reception counter */
83280+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
83281 };
83282 struct rcu_head rcu;
83283 struct inet_peer *gc_next;
83284@@ -179,7 +179,7 @@ static inline int inet_getid(struct inet_peer *p, int more)
83285 {
83286 more++;
83287 inet_peer_refcheck(p);
83288- return atomic_add_return(more, &p->ip_id_count) - more;
83289+ return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
83290 }
83291
83292 #endif /* _NET_INETPEER_H */
83293diff --git a/include/net/ip.h b/include/net/ip.h
83294index 3ec2b0f..72435b6 100644
83295--- a/include/net/ip.h
83296+++ b/include/net/ip.h
83297@@ -220,7 +220,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83298
83299 void inet_get_local_port_range(struct net *net, int *low, int *high);
83300
83301-extern unsigned long *sysctl_local_reserved_ports;
83302+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83303 static inline int inet_is_reserved_local_port(int port)
83304 {
83305 return test_bit(port, sysctl_local_reserved_ports);
83306diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83307index 9922093..a1755d6 100644
83308--- a/include/net/ip_fib.h
83309+++ b/include/net/ip_fib.h
83310@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83311
83312 #define FIB_RES_SADDR(net, res) \
83313 ((FIB_RES_NH(res).nh_saddr_genid == \
83314- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83315+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83316 FIB_RES_NH(res).nh_saddr : \
83317 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83318 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83319diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83320index 5679d92..2e7a690 100644
83321--- a/include/net/ip_vs.h
83322+++ b/include/net/ip_vs.h
83323@@ -558,7 +558,7 @@ struct ip_vs_conn {
83324 struct ip_vs_conn *control; /* Master control connection */
83325 atomic_t n_control; /* Number of controlled ones */
83326 struct ip_vs_dest *dest; /* real server */
83327- atomic_t in_pkts; /* incoming packet counter */
83328+ atomic_unchecked_t in_pkts; /* incoming packet counter */
83329
83330 /* packet transmitter for different forwarding methods. If it
83331 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83332@@ -705,7 +705,7 @@ struct ip_vs_dest {
83333 __be16 port; /* port number of the server */
83334 union nf_inet_addr addr; /* IP address of the server */
83335 volatile unsigned int flags; /* dest status flags */
83336- atomic_t conn_flags; /* flags to copy to conn */
83337+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
83338 atomic_t weight; /* server weight */
83339
83340 atomic_t refcnt; /* reference counter */
83341@@ -960,11 +960,11 @@ struct netns_ipvs {
83342 /* ip_vs_lblc */
83343 int sysctl_lblc_expiration;
83344 struct ctl_table_header *lblc_ctl_header;
83345- struct ctl_table *lblc_ctl_table;
83346+ ctl_table_no_const *lblc_ctl_table;
83347 /* ip_vs_lblcr */
83348 int sysctl_lblcr_expiration;
83349 struct ctl_table_header *lblcr_ctl_header;
83350- struct ctl_table *lblcr_ctl_table;
83351+ ctl_table_no_const *lblcr_ctl_table;
83352 /* ip_vs_est */
83353 struct list_head est_list; /* estimator list */
83354 spinlock_t est_lock;
83355diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83356index 8d4f588..2e37ad2 100644
83357--- a/include/net/irda/ircomm_tty.h
83358+++ b/include/net/irda/ircomm_tty.h
83359@@ -33,6 +33,7 @@
83360 #include <linux/termios.h>
83361 #include <linux/timer.h>
83362 #include <linux/tty.h> /* struct tty_struct */
83363+#include <asm/local.h>
83364
83365 #include <net/irda/irias_object.h>
83366 #include <net/irda/ircomm_core.h>
83367diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83368index 714cc9a..ea05f3e 100644
83369--- a/include/net/iucv/af_iucv.h
83370+++ b/include/net/iucv/af_iucv.h
83371@@ -149,7 +149,7 @@ struct iucv_skb_cb {
83372 struct iucv_sock_list {
83373 struct hlist_head head;
83374 rwlock_t lock;
83375- atomic_t autobind_name;
83376+ atomic_unchecked_t autobind_name;
83377 };
83378
83379 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83380diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83381index f3be818..bf46196 100644
83382--- a/include/net/llc_c_ac.h
83383+++ b/include/net/llc_c_ac.h
83384@@ -87,7 +87,7 @@
83385 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83386 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83387
83388-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83389+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83390
83391 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83392 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83393diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83394index 3948cf1..83b28c4 100644
83395--- a/include/net/llc_c_ev.h
83396+++ b/include/net/llc_c_ev.h
83397@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83398 return (struct llc_conn_state_ev *)skb->cb;
83399 }
83400
83401-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83402-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83403+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83404+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83405
83406 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83407 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83408diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83409index 0e79cfb..f46db31 100644
83410--- a/include/net/llc_c_st.h
83411+++ b/include/net/llc_c_st.h
83412@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83413 u8 next_state;
83414 llc_conn_ev_qfyr_t *ev_qualifiers;
83415 llc_conn_action_t *ev_actions;
83416-};
83417+} __do_const;
83418
83419 struct llc_conn_state {
83420 u8 current_state;
83421diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83422index a61b98c..aade1eb 100644
83423--- a/include/net/llc_s_ac.h
83424+++ b/include/net/llc_s_ac.h
83425@@ -23,7 +23,7 @@
83426 #define SAP_ACT_TEST_IND 9
83427
83428 /* All action functions must look like this */
83429-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83430+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83431
83432 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83433 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83434diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83435index 567c681..cd73ac02 100644
83436--- a/include/net/llc_s_st.h
83437+++ b/include/net/llc_s_st.h
83438@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83439 llc_sap_ev_t ev;
83440 u8 next_state;
83441 llc_sap_action_t *ev_actions;
83442-};
83443+} __do_const;
83444
83445 struct llc_sap_state {
83446 u8 curr_state;
83447diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83448index 8248e39..7610eec 100644
83449--- a/include/net/mac80211.h
83450+++ b/include/net/mac80211.h
83451@@ -4467,7 +4467,7 @@ struct rate_control_ops {
83452 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83453 struct dentry *dir);
83454 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83455-};
83456+} __do_const;
83457
83458 static inline int rate_supported(struct ieee80211_sta *sta,
83459 enum ieee80211_band band,
83460diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83461index 7277caf..fd095bc 100644
83462--- a/include/net/neighbour.h
83463+++ b/include/net/neighbour.h
83464@@ -163,7 +163,7 @@ struct neigh_ops {
83465 void (*error_report)(struct neighbour *, struct sk_buff *);
83466 int (*output)(struct neighbour *, struct sk_buff *);
83467 int (*connected_output)(struct neighbour *, struct sk_buff *);
83468-};
83469+} __do_const;
83470
83471 struct pneigh_entry {
83472 struct pneigh_entry *next;
83473@@ -203,7 +203,6 @@ struct neigh_table {
83474 void (*proxy_redo)(struct sk_buff *skb);
83475 char *id;
83476 struct neigh_parms parms;
83477- /* HACK. gc_* should follow parms without a gap! */
83478 int gc_interval;
83479 int gc_thresh1;
83480 int gc_thresh2;
83481@@ -218,7 +217,7 @@ struct neigh_table {
83482 struct neigh_statistics __percpu *stats;
83483 struct neigh_hash_table __rcu *nht;
83484 struct pneigh_entry **phash_buckets;
83485-};
83486+} __randomize_layout;
83487
83488 static inline int neigh_parms_family(struct neigh_parms *p)
83489 {
83490diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83491index 5f9eb26..85699c4 100644
83492--- a/include/net/net_namespace.h
83493+++ b/include/net/net_namespace.h
83494@@ -129,8 +129,8 @@ struct net {
83495 struct netns_ipvs *ipvs;
83496 #endif
83497 struct sock *diag_nlsk;
83498- atomic_t fnhe_genid;
83499-};
83500+ atomic_unchecked_t fnhe_genid;
83501+} __randomize_layout;
83502
83503 #include <linux/seq_file_net.h>
83504
83505@@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83506 #define __net_init __init
83507 #define __net_exit __exit_refok
83508 #define __net_initdata __initdata
83509+#ifdef CONSTIFY_PLUGIN
83510 #define __net_initconst __initconst
83511+#else
83512+#define __net_initconst __initdata
83513+#endif
83514 #endif
83515
83516 struct pernet_operations {
83517@@ -296,7 +300,7 @@ struct pernet_operations {
83518 void (*exit_batch)(struct list_head *net_exit_list);
83519 int *id;
83520 size_t size;
83521-};
83522+} __do_const;
83523
83524 /*
83525 * Use these carefully. If you implement a network device and it
83526@@ -344,23 +348,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83527
83528 static inline int rt_genid_ipv4(struct net *net)
83529 {
83530- return atomic_read(&net->ipv4.rt_genid);
83531+ return atomic_read_unchecked(&net->ipv4.rt_genid);
83532 }
83533
83534 static inline void rt_genid_bump_ipv4(struct net *net)
83535 {
83536- atomic_inc(&net->ipv4.rt_genid);
83537+ atomic_inc_unchecked(&net->ipv4.rt_genid);
83538 }
83539
83540 #if IS_ENABLED(CONFIG_IPV6)
83541 static inline int rt_genid_ipv6(struct net *net)
83542 {
83543- return atomic_read(&net->ipv6.rt_genid);
83544+ return atomic_read_unchecked(&net->ipv6.rt_genid);
83545 }
83546
83547 static inline void rt_genid_bump_ipv6(struct net *net)
83548 {
83549- atomic_inc(&net->ipv6.rt_genid);
83550+ atomic_inc_unchecked(&net->ipv6.rt_genid);
83551 }
83552 #else
83553 static inline int rt_genid_ipv6(struct net *net)
83554@@ -382,12 +386,12 @@ static inline void rt_genid_bump_all(struct net *net)
83555
83556 static inline int fnhe_genid(struct net *net)
83557 {
83558- return atomic_read(&net->fnhe_genid);
83559+ return atomic_read_unchecked(&net->fnhe_genid);
83560 }
83561
83562 static inline void fnhe_genid_bump(struct net *net)
83563 {
83564- atomic_inc(&net->fnhe_genid);
83565+ atomic_inc_unchecked(&net->fnhe_genid);
83566 }
83567
83568 #endif /* __NET_NET_NAMESPACE_H */
83569diff --git a/include/net/netdma.h b/include/net/netdma.h
83570index 8ba8ce2..99b7fff 100644
83571--- a/include/net/netdma.h
83572+++ b/include/net/netdma.h
83573@@ -24,7 +24,7 @@
83574 #include <linux/dmaengine.h>
83575 #include <linux/skbuff.h>
83576
83577-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83578+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83579 struct sk_buff *skb, int offset, struct iovec *to,
83580 size_t len, struct dma_pinned_list *pinned_list);
83581
83582diff --git a/include/net/netlink.h b/include/net/netlink.h
83583index 2b47eaa..6d5bcc2 100644
83584--- a/include/net/netlink.h
83585+++ b/include/net/netlink.h
83586@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83587 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83588 {
83589 if (mark)
83590- skb_trim(skb, (unsigned char *) mark - skb->data);
83591+ skb_trim(skb, (const unsigned char *) mark - skb->data);
83592 }
83593
83594 /**
83595diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
83596index 773cce3..6a11852 100644
83597--- a/include/net/netns/conntrack.h
83598+++ b/include/net/netns/conntrack.h
83599@@ -13,10 +13,10 @@ struct nf_conntrack_ecache;
83600 struct nf_proto_net {
83601 #ifdef CONFIG_SYSCTL
83602 struct ctl_table_header *ctl_table_header;
83603- struct ctl_table *ctl_table;
83604+ ctl_table_no_const *ctl_table;
83605 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83606 struct ctl_table_header *ctl_compat_header;
83607- struct ctl_table *ctl_compat_table;
83608+ ctl_table_no_const *ctl_compat_table;
83609 #endif
83610 #endif
83611 unsigned int users;
83612@@ -59,7 +59,7 @@ struct nf_ip_net {
83613 struct nf_icmp_net icmpv6;
83614 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83615 struct ctl_table_header *ctl_table_header;
83616- struct ctl_table *ctl_table;
83617+ ctl_table_no_const *ctl_table;
83618 #endif
83619 };
83620
83621diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83622index b2704fd0..421d717 100644
83623--- a/include/net/netns/ipv4.h
83624+++ b/include/net/netns/ipv4.h
83625@@ -79,7 +79,7 @@ struct netns_ipv4 {
83626
83627 struct ping_group_range ping_group_range;
83628
83629- atomic_t dev_addr_genid;
83630+ atomic_unchecked_t dev_addr_genid;
83631
83632 #ifdef CONFIG_IP_MROUTE
83633 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83634@@ -89,6 +89,6 @@ struct netns_ipv4 {
83635 struct fib_rules_ops *mr_rules_ops;
83636 #endif
83637 #endif
83638- atomic_t rt_genid;
83639+ atomic_unchecked_t rt_genid;
83640 };
83641 #endif
83642diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83643index 21edaf1..4c5faae 100644
83644--- a/include/net/netns/ipv6.h
83645+++ b/include/net/netns/ipv6.h
83646@@ -73,8 +73,8 @@ struct netns_ipv6 {
83647 struct fib_rules_ops *mr6_rules_ops;
83648 #endif
83649 #endif
83650- atomic_t dev_addr_genid;
83651- atomic_t rt_genid;
83652+ atomic_unchecked_t dev_addr_genid;
83653+ atomic_unchecked_t rt_genid;
83654 };
83655
83656 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83657diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
83658index 3492434..209f58c 100644
83659--- a/include/net/netns/xfrm.h
83660+++ b/include/net/netns/xfrm.h
83661@@ -64,7 +64,7 @@ struct netns_xfrm {
83662
83663 /* flow cache part */
83664 struct flow_cache flow_cache_global;
83665- atomic_t flow_cache_genid;
83666+ atomic_unchecked_t flow_cache_genid;
83667 struct list_head flow_cache_gc_list;
83668 spinlock_t flow_cache_gc_lock;
83669 struct work_struct flow_cache_gc_work;
83670diff --git a/include/net/ping.h b/include/net/ping.h
83671index 026479b..d9b2829 100644
83672--- a/include/net/ping.h
83673+++ b/include/net/ping.h
83674@@ -54,7 +54,7 @@ struct ping_iter_state {
83675
83676 extern struct proto ping_prot;
83677 #if IS_ENABLED(CONFIG_IPV6)
83678-extern struct pingv6_ops pingv6_ops;
83679+extern struct pingv6_ops *pingv6_ops;
83680 #endif
83681
83682 struct pingfakehdr {
83683diff --git a/include/net/protocol.h b/include/net/protocol.h
83684index a7e986b..dc67bce 100644
83685--- a/include/net/protocol.h
83686+++ b/include/net/protocol.h
83687@@ -49,7 +49,7 @@ struct net_protocol {
83688 * socket lookup?
83689 */
83690 icmp_strict_tag_validation:1;
83691-};
83692+} __do_const;
83693
83694 #if IS_ENABLED(CONFIG_IPV6)
83695 struct inet6_protocol {
83696@@ -62,7 +62,7 @@ struct inet6_protocol {
83697 u8 type, u8 code, int offset,
83698 __be32 info);
83699 unsigned int flags; /* INET6_PROTO_xxx */
83700-};
83701+} __do_const;
83702
83703 #define INET6_PROTO_NOPOLICY 0x1
83704 #define INET6_PROTO_FINAL 0x2
83705diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83706index 72240e5..8c14bef 100644
83707--- a/include/net/rtnetlink.h
83708+++ b/include/net/rtnetlink.h
83709@@ -93,7 +93,7 @@ struct rtnl_link_ops {
83710 int (*fill_slave_info)(struct sk_buff *skb,
83711 const struct net_device *dev,
83712 const struct net_device *slave_dev);
83713-};
83714+} __do_const;
83715
83716 int __rtnl_link_register(struct rtnl_link_ops *ops);
83717 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83718diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83719index 4a5b9a3..ca27d73 100644
83720--- a/include/net/sctp/checksum.h
83721+++ b/include/net/sctp/checksum.h
83722@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83723 unsigned int offset)
83724 {
83725 struct sctphdr *sh = sctp_hdr(skb);
83726- __le32 ret, old = sh->checksum;
83727- const struct skb_checksum_ops ops = {
83728+ __le32 ret, old = sh->checksum;
83729+ static const struct skb_checksum_ops ops = {
83730 .update = sctp_csum_update,
83731 .combine = sctp_csum_combine,
83732 };
83733diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83734index 7f4eeb3..37e8fe1 100644
83735--- a/include/net/sctp/sm.h
83736+++ b/include/net/sctp/sm.h
83737@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83738 typedef struct {
83739 sctp_state_fn_t *fn;
83740 const char *name;
83741-} sctp_sm_table_entry_t;
83742+} __do_const sctp_sm_table_entry_t;
83743
83744 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83745 * currently in use.
83746@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83747 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83748
83749 /* Extern declarations for major data structures. */
83750-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83751+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83752
83753
83754 /* Get the size of a DATA chunk payload. */
83755diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83756index 0dfcc92..7967849 100644
83757--- a/include/net/sctp/structs.h
83758+++ b/include/net/sctp/structs.h
83759@@ -507,7 +507,7 @@ struct sctp_pf {
83760 struct sctp_association *asoc);
83761 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
83762 struct sctp_af *af;
83763-};
83764+} __do_const;
83765
83766
83767 /* Structure to track chunk fragments that have been acked, but peer
83768diff --git a/include/net/sock.h b/include/net/sock.h
83769index 21569cf..dd60300 100644
83770--- a/include/net/sock.h
83771+++ b/include/net/sock.h
83772@@ -348,7 +348,7 @@ struct sock {
83773 unsigned int sk_napi_id;
83774 unsigned int sk_ll_usec;
83775 #endif
83776- atomic_t sk_drops;
83777+ atomic_unchecked_t sk_drops;
83778 int sk_rcvbuf;
83779
83780 struct sk_filter __rcu *sk_filter;
83781@@ -1036,7 +1036,7 @@ struct proto {
83782 void (*destroy_cgroup)(struct mem_cgroup *memcg);
83783 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
83784 #endif
83785-};
83786+} __randomize_layout;
83787
83788 /*
83789 * Bits in struct cg_proto.flags
83790@@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
83791 return ret >> PAGE_SHIFT;
83792 }
83793
83794-static inline long
83795+static inline long __intentional_overflow(-1)
83796 sk_memory_allocated(const struct sock *sk)
83797 {
83798 struct proto *prot = sk->sk_prot;
83799@@ -1368,7 +1368,7 @@ struct sock_iocb {
83800 struct scm_cookie *scm;
83801 struct msghdr *msg, async_msg;
83802 struct kiocb *kiocb;
83803-};
83804+} __randomize_layout;
83805
83806 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
83807 {
83808@@ -1728,8 +1728,8 @@ sk_dst_get(struct sock *sk)
83809
83810 rcu_read_lock();
83811 dst = rcu_dereference(sk->sk_dst_cache);
83812- if (dst)
83813- dst_hold(dst);
83814+ if (dst && !atomic_inc_not_zero(&dst->__refcnt))
83815+ dst = NULL;
83816 rcu_read_unlock();
83817 return dst;
83818 }
83819@@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
83820 }
83821
83822 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
83823- char __user *from, char *to,
83824+ char __user *from, unsigned char *to,
83825 int copy, int offset)
83826 {
83827 if (skb->ip_summed == CHECKSUM_NONE) {
83828@@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
83829 }
83830 }
83831
83832-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83833+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83834
83835 /**
83836 * sk_page_frag - return an appropriate page_frag
83837diff --git a/include/net/tcp.h b/include/net/tcp.h
83838index 87d8774..cf214f8 100644
83839--- a/include/net/tcp.h
83840+++ b/include/net/tcp.h
83841@@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
83842 void tcp_xmit_retransmit_queue(struct sock *);
83843 void tcp_simple_retransmit(struct sock *);
83844 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83845-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83846+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83847
83848 void tcp_send_probe0(struct sock *);
83849 void tcp_send_partial(struct sock *);
83850@@ -715,8 +715,8 @@ struct tcp_skb_cb {
83851 struct inet6_skb_parm h6;
83852 #endif
83853 } header; /* For incoming frames */
83854- __u32 seq; /* Starting sequence number */
83855- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83856+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
83857+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83858 __u32 when; /* used to compute rtt's */
83859 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83860
83861@@ -730,7 +730,7 @@ struct tcp_skb_cb {
83862
83863 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83864 /* 1 byte hole */
83865- __u32 ack_seq; /* Sequence number ACK'd */
83866+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83867 };
83868
83869 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83870diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83871index 116e9c7..3070537 100644
83872--- a/include/net/xfrm.h
83873+++ b/include/net/xfrm.h
83874@@ -285,7 +285,6 @@ struct xfrm_dst;
83875 struct xfrm_policy_afinfo {
83876 unsigned short family;
83877 struct dst_ops *dst_ops;
83878- void (*garbage_collect)(struct net *net);
83879 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
83880 const xfrm_address_t *saddr,
83881 const xfrm_address_t *daddr);
83882@@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
83883 struct net_device *dev,
83884 const struct flowi *fl);
83885 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
83886-};
83887+} __do_const;
83888
83889 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
83890 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
83891@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
83892 int (*transport_finish)(struct sk_buff *skb,
83893 int async);
83894 void (*local_error)(struct sk_buff *skb, u32 mtu);
83895-};
83896+} __do_const;
83897
83898 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
83899 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
83900@@ -437,7 +436,7 @@ struct xfrm_mode {
83901 struct module *owner;
83902 unsigned int encap;
83903 int flags;
83904-};
83905+} __do_const;
83906
83907 /* Flags for xfrm_mode. */
83908 enum {
83909@@ -534,7 +533,7 @@ struct xfrm_policy {
83910 struct timer_list timer;
83911
83912 struct flow_cache_object flo;
83913- atomic_t genid;
83914+ atomic_unchecked_t genid;
83915 u32 priority;
83916 u32 index;
83917 struct xfrm_mark mark;
83918@@ -1180,6 +1179,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
83919 }
83920
83921 void xfrm_garbage_collect(struct net *net);
83922+void xfrm_garbage_collect_deferred(struct net *net);
83923
83924 #else
83925
83926@@ -1218,6 +1218,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
83927 static inline void xfrm_garbage_collect(struct net *net)
83928 {
83929 }
83930+static inline void xfrm_garbage_collect_deferred(struct net *net)
83931+{
83932+}
83933 #endif
83934
83935 static __inline__
83936diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
83937index 1017e0b..227aa4d 100644
83938--- a/include/rdma/iw_cm.h
83939+++ b/include/rdma/iw_cm.h
83940@@ -122,7 +122,7 @@ struct iw_cm_verbs {
83941 int backlog);
83942
83943 int (*destroy_listen)(struct iw_cm_id *cm_id);
83944-};
83945+} __no_const;
83946
83947 /**
83948 * iw_create_cm_id - Create an IW CM identifier.
83949diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
83950index 52beadf..598734c 100644
83951--- a/include/scsi/libfc.h
83952+++ b/include/scsi/libfc.h
83953@@ -771,6 +771,7 @@ struct libfc_function_template {
83954 */
83955 void (*disc_stop_final) (struct fc_lport *);
83956 };
83957+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
83958
83959 /**
83960 * struct fc_disc - Discovery context
83961@@ -875,7 +876,7 @@ struct fc_lport {
83962 struct fc_vport *vport;
83963
83964 /* Operational Information */
83965- struct libfc_function_template tt;
83966+ libfc_function_template_no_const tt;
83967 u8 link_up;
83968 u8 qfull;
83969 enum fc_lport_state state;
83970diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
83971index 5853c91..1e355a8 100644
83972--- a/include/scsi/scsi_device.h
83973+++ b/include/scsi/scsi_device.h
83974@@ -186,9 +186,9 @@ struct scsi_device {
83975 unsigned int max_device_blocked; /* what device_blocked counts down from */
83976 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
83977
83978- atomic_t iorequest_cnt;
83979- atomic_t iodone_cnt;
83980- atomic_t ioerr_cnt;
83981+ atomic_unchecked_t iorequest_cnt;
83982+ atomic_unchecked_t iodone_cnt;
83983+ atomic_unchecked_t ioerr_cnt;
83984
83985 struct device sdev_gendev,
83986 sdev_dev;
83987diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
83988index 8c79980..723f6f9 100644
83989--- a/include/scsi/scsi_transport_fc.h
83990+++ b/include/scsi/scsi_transport_fc.h
83991@@ -752,7 +752,8 @@ struct fc_function_template {
83992 unsigned long show_host_system_hostname:1;
83993
83994 unsigned long disable_target_scan:1;
83995-};
83996+} __do_const;
83997+typedef struct fc_function_template __no_const fc_function_template_no_const;
83998
83999
84000 /**
84001diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84002index ae6c3b8..fd748ac 100644
84003--- a/include/sound/compress_driver.h
84004+++ b/include/sound/compress_driver.h
84005@@ -128,7 +128,7 @@ struct snd_compr_ops {
84006 struct snd_compr_caps *caps);
84007 int (*get_codec_caps) (struct snd_compr_stream *stream,
84008 struct snd_compr_codec_caps *codec);
84009-};
84010+} __no_const;
84011
84012 /**
84013 * struct snd_compr: Compressed device
84014diff --git a/include/sound/soc.h b/include/sound/soc.h
84015index 0b83168..d67280a 100644
84016--- a/include/sound/soc.h
84017+++ b/include/sound/soc.h
84018@@ -782,7 +782,7 @@ struct snd_soc_codec_driver {
84019 /* probe ordering - for components with runtime dependencies */
84020 int probe_order;
84021 int remove_order;
84022-};
84023+} __do_const;
84024
84025 /* SoC platform interface */
84026 struct snd_soc_platform_driver {
84027@@ -828,7 +828,7 @@ struct snd_soc_platform_driver {
84028 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84029 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84030 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84031-};
84032+} __do_const;
84033
84034 struct snd_soc_platform {
84035 const char *name;
84036diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84037index 9ec9864..e2ee1ee 100644
84038--- a/include/target/target_core_base.h
84039+++ b/include/target/target_core_base.h
84040@@ -761,7 +761,7 @@ struct se_device {
84041 atomic_long_t write_bytes;
84042 /* Active commands on this virtual SE device */
84043 atomic_t simple_cmds;
84044- atomic_t dev_ordered_id;
84045+ atomic_unchecked_t dev_ordered_id;
84046 atomic_t dev_ordered_sync;
84047 atomic_t dev_qf_count;
84048 int export_count;
84049diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84050new file mode 100644
84051index 0000000..fb634b7
84052--- /dev/null
84053+++ b/include/trace/events/fs.h
84054@@ -0,0 +1,53 @@
84055+#undef TRACE_SYSTEM
84056+#define TRACE_SYSTEM fs
84057+
84058+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84059+#define _TRACE_FS_H
84060+
84061+#include <linux/fs.h>
84062+#include <linux/tracepoint.h>
84063+
84064+TRACE_EVENT(do_sys_open,
84065+
84066+ TP_PROTO(const char *filename, int flags, int mode),
84067+
84068+ TP_ARGS(filename, flags, mode),
84069+
84070+ TP_STRUCT__entry(
84071+ __string( filename, filename )
84072+ __field( int, flags )
84073+ __field( int, mode )
84074+ ),
84075+
84076+ TP_fast_assign(
84077+ __assign_str(filename, filename);
84078+ __entry->flags = flags;
84079+ __entry->mode = mode;
84080+ ),
84081+
84082+ TP_printk("\"%s\" %x %o",
84083+ __get_str(filename), __entry->flags, __entry->mode)
84084+);
84085+
84086+TRACE_EVENT(open_exec,
84087+
84088+ TP_PROTO(const char *filename),
84089+
84090+ TP_ARGS(filename),
84091+
84092+ TP_STRUCT__entry(
84093+ __string( filename, filename )
84094+ ),
84095+
84096+ TP_fast_assign(
84097+ __assign_str(filename, filename);
84098+ ),
84099+
84100+ TP_printk("\"%s\"",
84101+ __get_str(filename))
84102+);
84103+
84104+#endif /* _TRACE_FS_H */
84105+
84106+/* This part must be outside protection */
84107+#include <trace/define_trace.h>
84108diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84109index 1c09820..7f5ec79 100644
84110--- a/include/trace/events/irq.h
84111+++ b/include/trace/events/irq.h
84112@@ -36,7 +36,7 @@ struct softirq_action;
84113 */
84114 TRACE_EVENT(irq_handler_entry,
84115
84116- TP_PROTO(int irq, struct irqaction *action),
84117+ TP_PROTO(int irq, const struct irqaction *action),
84118
84119 TP_ARGS(irq, action),
84120
84121@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84122 */
84123 TRACE_EVENT(irq_handler_exit,
84124
84125- TP_PROTO(int irq, struct irqaction *action, int ret),
84126+ TP_PROTO(int irq, const struct irqaction *action, int ret),
84127
84128 TP_ARGS(irq, action, ret),
84129
84130diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84131index 7caf44c..23c6f27 100644
84132--- a/include/uapi/linux/a.out.h
84133+++ b/include/uapi/linux/a.out.h
84134@@ -39,6 +39,14 @@ enum machine_type {
84135 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84136 };
84137
84138+/* Constants for the N_FLAGS field */
84139+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84140+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84141+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84142+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84143+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84144+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84145+
84146 #if !defined (N_MAGIC)
84147 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84148 #endif
84149diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84150index 22b6ad3..aeba37e 100644
84151--- a/include/uapi/linux/bcache.h
84152+++ b/include/uapi/linux/bcache.h
84153@@ -5,6 +5,7 @@
84154 * Bcache on disk data structures
84155 */
84156
84157+#include <linux/compiler.h>
84158 #include <asm/types.h>
84159
84160 #define BITMASK(name, type, field, offset, size) \
84161@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84162 /* Btree keys - all units are in sectors */
84163
84164 struct bkey {
84165- __u64 high;
84166- __u64 low;
84167+ __u64 high __intentional_overflow(-1);
84168+ __u64 low __intentional_overflow(-1);
84169 __u64 ptr[];
84170 };
84171
84172diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84173index d876736..ccce5c0 100644
84174--- a/include/uapi/linux/byteorder/little_endian.h
84175+++ b/include/uapi/linux/byteorder/little_endian.h
84176@@ -42,51 +42,51 @@
84177
84178 static inline __le64 __cpu_to_le64p(const __u64 *p)
84179 {
84180- return (__force __le64)*p;
84181+ return (__force const __le64)*p;
84182 }
84183-static inline __u64 __le64_to_cpup(const __le64 *p)
84184+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84185 {
84186- return (__force __u64)*p;
84187+ return (__force const __u64)*p;
84188 }
84189 static inline __le32 __cpu_to_le32p(const __u32 *p)
84190 {
84191- return (__force __le32)*p;
84192+ return (__force const __le32)*p;
84193 }
84194 static inline __u32 __le32_to_cpup(const __le32 *p)
84195 {
84196- return (__force __u32)*p;
84197+ return (__force const __u32)*p;
84198 }
84199 static inline __le16 __cpu_to_le16p(const __u16 *p)
84200 {
84201- return (__force __le16)*p;
84202+ return (__force const __le16)*p;
84203 }
84204 static inline __u16 __le16_to_cpup(const __le16 *p)
84205 {
84206- return (__force __u16)*p;
84207+ return (__force const __u16)*p;
84208 }
84209 static inline __be64 __cpu_to_be64p(const __u64 *p)
84210 {
84211- return (__force __be64)__swab64p(p);
84212+ return (__force const __be64)__swab64p(p);
84213 }
84214 static inline __u64 __be64_to_cpup(const __be64 *p)
84215 {
84216- return __swab64p((__u64 *)p);
84217+ return __swab64p((const __u64 *)p);
84218 }
84219 static inline __be32 __cpu_to_be32p(const __u32 *p)
84220 {
84221- return (__force __be32)__swab32p(p);
84222+ return (__force const __be32)__swab32p(p);
84223 }
84224-static inline __u32 __be32_to_cpup(const __be32 *p)
84225+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84226 {
84227- return __swab32p((__u32 *)p);
84228+ return __swab32p((const __u32 *)p);
84229 }
84230 static inline __be16 __cpu_to_be16p(const __u16 *p)
84231 {
84232- return (__force __be16)__swab16p(p);
84233+ return (__force const __be16)__swab16p(p);
84234 }
84235 static inline __u16 __be16_to_cpup(const __be16 *p)
84236 {
84237- return __swab16p((__u16 *)p);
84238+ return __swab16p((const __u16 *)p);
84239 }
84240 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84241 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84242diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84243index ef6103b..d4e65dd 100644
84244--- a/include/uapi/linux/elf.h
84245+++ b/include/uapi/linux/elf.h
84246@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84247 #define PT_GNU_EH_FRAME 0x6474e550
84248
84249 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84250+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84251+
84252+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84253+
84254+/* Constants for the e_flags field */
84255+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84256+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84257+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84258+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84259+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84260+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84261
84262 /*
84263 * Extended Numbering
84264@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84265 #define DT_DEBUG 21
84266 #define DT_TEXTREL 22
84267 #define DT_JMPREL 23
84268+#define DT_FLAGS 30
84269+ #define DF_TEXTREL 0x00000004
84270 #define DT_ENCODING 32
84271 #define OLD_DT_LOOS 0x60000000
84272 #define DT_LOOS 0x6000000d
84273@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84274 #define PF_W 0x2
84275 #define PF_X 0x1
84276
84277+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84278+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84279+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84280+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84281+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84282+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84283+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84284+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84285+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84286+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84287+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84288+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84289+
84290 typedef struct elf32_phdr{
84291 Elf32_Word p_type;
84292 Elf32_Off p_offset;
84293@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84294 #define EI_OSABI 7
84295 #define EI_PAD 8
84296
84297+#define EI_PAX 14
84298+
84299 #define ELFMAG0 0x7f /* EI_MAG */
84300 #define ELFMAG1 'E'
84301 #define ELFMAG2 'L'
84302diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84303index aa169c4..6a2771d 100644
84304--- a/include/uapi/linux/personality.h
84305+++ b/include/uapi/linux/personality.h
84306@@ -30,6 +30,7 @@ enum {
84307 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84308 ADDR_NO_RANDOMIZE | \
84309 ADDR_COMPAT_LAYOUT | \
84310+ ADDR_LIMIT_3GB | \
84311 MMAP_PAGE_ZERO)
84312
84313 /*
84314diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84315index 7530e74..e714828 100644
84316--- a/include/uapi/linux/screen_info.h
84317+++ b/include/uapi/linux/screen_info.h
84318@@ -43,7 +43,8 @@ struct screen_info {
84319 __u16 pages; /* 0x32 */
84320 __u16 vesa_attributes; /* 0x34 */
84321 __u32 capabilities; /* 0x36 */
84322- __u8 _reserved[6]; /* 0x3a */
84323+ __u16 vesapm_size; /* 0x3a */
84324+ __u8 _reserved[4]; /* 0x3c */
84325 } __attribute__((packed));
84326
84327 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84328diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84329index 0e011eb..82681b1 100644
84330--- a/include/uapi/linux/swab.h
84331+++ b/include/uapi/linux/swab.h
84332@@ -43,7 +43,7 @@
84333 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84334 */
84335
84336-static inline __attribute_const__ __u16 __fswab16(__u16 val)
84337+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84338 {
84339 #ifdef __HAVE_BUILTIN_BSWAP16__
84340 return __builtin_bswap16(val);
84341@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84342 #endif
84343 }
84344
84345-static inline __attribute_const__ __u32 __fswab32(__u32 val)
84346+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84347 {
84348 #ifdef __HAVE_BUILTIN_BSWAP32__
84349 return __builtin_bswap32(val);
84350@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84351 #endif
84352 }
84353
84354-static inline __attribute_const__ __u64 __fswab64(__u64 val)
84355+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84356 {
84357 #ifdef __HAVE_BUILTIN_BSWAP64__
84358 return __builtin_bswap64(val);
84359diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84360index 6d67213..552fdd9 100644
84361--- a/include/uapi/linux/sysctl.h
84362+++ b/include/uapi/linux/sysctl.h
84363@@ -155,8 +155,6 @@ enum
84364 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84365 };
84366
84367-
84368-
84369 /* CTL_VM names: */
84370 enum
84371 {
84372diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84373index ea468ee..4d367a5 100644
84374--- a/include/uapi/linux/videodev2.h
84375+++ b/include/uapi/linux/videodev2.h
84376@@ -1248,7 +1248,7 @@ struct v4l2_ext_control {
84377 union {
84378 __s32 value;
84379 __s64 value64;
84380- char *string;
84381+ char __user *string;
84382 };
84383 } __attribute__ ((packed));
84384
84385diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84386index c38355c..17a57bc 100644
84387--- a/include/uapi/linux/xattr.h
84388+++ b/include/uapi/linux/xattr.h
84389@@ -73,5 +73,9 @@
84390 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84391 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84392
84393+/* User namespace */
84394+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84395+#define XATTR_PAX_FLAGS_SUFFIX "flags"
84396+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84397
84398 #endif /* _UAPI_LINUX_XATTR_H */
84399diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84400index f9466fa..f4e2b81 100644
84401--- a/include/video/udlfb.h
84402+++ b/include/video/udlfb.h
84403@@ -53,10 +53,10 @@ struct dlfb_data {
84404 u32 pseudo_palette[256];
84405 int blank_mode; /*one of FB_BLANK_ */
84406 /* blit-only rendering path metrics, exposed through sysfs */
84407- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84408- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84409- atomic_t bytes_sent; /* to usb, after compression including overhead */
84410- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84411+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84412+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84413+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84414+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84415 };
84416
84417 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84418diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84419index 30f5362..8ed8ac9 100644
84420--- a/include/video/uvesafb.h
84421+++ b/include/video/uvesafb.h
84422@@ -122,6 +122,7 @@ struct uvesafb_par {
84423 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84424 u8 pmi_setpal; /* PMI for palette changes */
84425 u16 *pmi_base; /* protected mode interface location */
84426+ u8 *pmi_code; /* protected mode code location */
84427 void *pmi_start;
84428 void *pmi_pal;
84429 u8 *vbe_state_orig; /*
84430diff --git a/init/Kconfig b/init/Kconfig
84431index 9d3585b..ad45d34 100644
84432--- a/init/Kconfig
84433+++ b/init/Kconfig
84434@@ -1093,6 +1093,7 @@ endif # CGROUPS
84435
84436 config CHECKPOINT_RESTORE
84437 bool "Checkpoint/restore support" if EXPERT
84438+ depends on !GRKERNSEC
84439 default n
84440 help
84441 Enables additional kernel features in a sake of checkpoint/restore.
84442@@ -1570,7 +1571,7 @@ config SLUB_DEBUG
84443
84444 config COMPAT_BRK
84445 bool "Disable heap randomization"
84446- default y
84447+ default n
84448 help
84449 Randomizing heap placement makes heap exploits harder, but it
84450 also breaks ancient binaries (including anything libc5 based).
84451@@ -1858,7 +1859,7 @@ config INIT_ALL_POSSIBLE
84452 config STOP_MACHINE
84453 bool
84454 default y
84455- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84456+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84457 help
84458 Need stop_machine() primitive.
84459
84460diff --git a/init/Makefile b/init/Makefile
84461index 7bc47ee..6da2dc7 100644
84462--- a/init/Makefile
84463+++ b/init/Makefile
84464@@ -2,6 +2,9 @@
84465 # Makefile for the linux kernel.
84466 #
84467
84468+ccflags-y := $(GCC_PLUGINS_CFLAGS)
84469+asflags-y := $(GCC_PLUGINS_AFLAGS)
84470+
84471 obj-y := main.o version.o mounts.o
84472 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84473 obj-y += noinitramfs.o
84474diff --git a/init/do_mounts.c b/init/do_mounts.c
84475index 82f2288..ea1430a 100644
84476--- a/init/do_mounts.c
84477+++ b/init/do_mounts.c
84478@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84479 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84480 {
84481 struct super_block *s;
84482- int err = sys_mount(name, "/root", fs, flags, data);
84483+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84484 if (err)
84485 return err;
84486
84487- sys_chdir("/root");
84488+ sys_chdir((const char __force_user *)"/root");
84489 s = current->fs->pwd.dentry->d_sb;
84490 ROOT_DEV = s->s_dev;
84491 printk(KERN_INFO
84492@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84493 va_start(args, fmt);
84494 vsprintf(buf, fmt, args);
84495 va_end(args);
84496- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84497+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84498 if (fd >= 0) {
84499 sys_ioctl(fd, FDEJECT, 0);
84500 sys_close(fd);
84501 }
84502 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84503- fd = sys_open("/dev/console", O_RDWR, 0);
84504+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84505 if (fd >= 0) {
84506 sys_ioctl(fd, TCGETS, (long)&termios);
84507 termios.c_lflag &= ~ICANON;
84508 sys_ioctl(fd, TCSETSF, (long)&termios);
84509- sys_read(fd, &c, 1);
84510+ sys_read(fd, (char __user *)&c, 1);
84511 termios.c_lflag |= ICANON;
84512 sys_ioctl(fd, TCSETSF, (long)&termios);
84513 sys_close(fd);
84514@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84515 mount_root();
84516 out:
84517 devtmpfs_mount("dev");
84518- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84519- sys_chroot(".");
84520+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84521+ sys_chroot((const char __force_user *)".");
84522 }
84523
84524 static bool is_tmpfs;
84525diff --git a/init/do_mounts.h b/init/do_mounts.h
84526index f5b978a..69dbfe8 100644
84527--- a/init/do_mounts.h
84528+++ b/init/do_mounts.h
84529@@ -15,15 +15,15 @@ extern int root_mountflags;
84530
84531 static inline int create_dev(char *name, dev_t dev)
84532 {
84533- sys_unlink(name);
84534- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84535+ sys_unlink((char __force_user *)name);
84536+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84537 }
84538
84539 #if BITS_PER_LONG == 32
84540 static inline u32 bstat(char *name)
84541 {
84542 struct stat64 stat;
84543- if (sys_stat64(name, &stat) != 0)
84544+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84545 return 0;
84546 if (!S_ISBLK(stat.st_mode))
84547 return 0;
84548@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84549 static inline u32 bstat(char *name)
84550 {
84551 struct stat stat;
84552- if (sys_newstat(name, &stat) != 0)
84553+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84554 return 0;
84555 if (!S_ISBLK(stat.st_mode))
84556 return 0;
84557diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84558index 3e0878e..8a9d7a0 100644
84559--- a/init/do_mounts_initrd.c
84560+++ b/init/do_mounts_initrd.c
84561@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84562 {
84563 sys_unshare(CLONE_FS | CLONE_FILES);
84564 /* stdin/stdout/stderr for /linuxrc */
84565- sys_open("/dev/console", O_RDWR, 0);
84566+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84567 sys_dup(0);
84568 sys_dup(0);
84569 /* move initrd over / and chdir/chroot in initrd root */
84570- sys_chdir("/root");
84571- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84572- sys_chroot(".");
84573+ sys_chdir((const char __force_user *)"/root");
84574+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84575+ sys_chroot((const char __force_user *)".");
84576 sys_setsid();
84577 return 0;
84578 }
84579@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84580 create_dev("/dev/root.old", Root_RAM0);
84581 /* mount initrd on rootfs' /root */
84582 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84583- sys_mkdir("/old", 0700);
84584- sys_chdir("/old");
84585+ sys_mkdir((const char __force_user *)"/old", 0700);
84586+ sys_chdir((const char __force_user *)"/old");
84587
84588 /* try loading default modules from initrd */
84589 load_default_modules();
84590@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84591 current->flags &= ~PF_FREEZER_SKIP;
84592
84593 /* move initrd to rootfs' /old */
84594- sys_mount("..", ".", NULL, MS_MOVE, NULL);
84595+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84596 /* switch root and cwd back to / of rootfs */
84597- sys_chroot("..");
84598+ sys_chroot((const char __force_user *)"..");
84599
84600 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84601- sys_chdir("/old");
84602+ sys_chdir((const char __force_user *)"/old");
84603 return;
84604 }
84605
84606- sys_chdir("/");
84607+ sys_chdir((const char __force_user *)"/");
84608 ROOT_DEV = new_decode_dev(real_root_dev);
84609 mount_root();
84610
84611 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84612- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
84613+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
84614 if (!error)
84615 printk("okay\n");
84616 else {
84617- int fd = sys_open("/dev/root.old", O_RDWR, 0);
84618+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
84619 if (error == -ENOENT)
84620 printk("/initrd does not exist. Ignored.\n");
84621 else
84622 printk("failed\n");
84623 printk(KERN_NOTICE "Unmounting old root\n");
84624- sys_umount("/old", MNT_DETACH);
84625+ sys_umount((char __force_user *)"/old", MNT_DETACH);
84626 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
84627 if (fd < 0) {
84628 error = fd;
84629@@ -127,11 +127,11 @@ int __init initrd_load(void)
84630 * mounted in the normal path.
84631 */
84632 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
84633- sys_unlink("/initrd.image");
84634+ sys_unlink((const char __force_user *)"/initrd.image");
84635 handle_initrd();
84636 return 1;
84637 }
84638 }
84639- sys_unlink("/initrd.image");
84640+ sys_unlink((const char __force_user *)"/initrd.image");
84641 return 0;
84642 }
84643diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84644index 8cb6db5..d729f50 100644
84645--- a/init/do_mounts_md.c
84646+++ b/init/do_mounts_md.c
84647@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84648 partitioned ? "_d" : "", minor,
84649 md_setup_args[ent].device_names);
84650
84651- fd = sys_open(name, 0, 0);
84652+ fd = sys_open((char __force_user *)name, 0, 0);
84653 if (fd < 0) {
84654 printk(KERN_ERR "md: open failed - cannot start "
84655 "array %s\n", name);
84656@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84657 * array without it
84658 */
84659 sys_close(fd);
84660- fd = sys_open(name, 0, 0);
84661+ fd = sys_open((char __force_user *)name, 0, 0);
84662 sys_ioctl(fd, BLKRRPART, 0);
84663 }
84664 sys_close(fd);
84665@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84666
84667 wait_for_device_probe();
84668
84669- fd = sys_open("/dev/md0", 0, 0);
84670+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84671 if (fd >= 0) {
84672 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84673 sys_close(fd);
84674diff --git a/init/init_task.c b/init/init_task.c
84675index ba0a7f36..2bcf1d5 100644
84676--- a/init/init_task.c
84677+++ b/init/init_task.c
84678@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84679 * Initial thread structure. Alignment of this is handled by a special
84680 * linker map entry.
84681 */
84682+#ifdef CONFIG_X86
84683+union thread_union init_thread_union __init_task_data;
84684+#else
84685 union thread_union init_thread_union __init_task_data =
84686 { INIT_THREAD_INFO(init_task) };
84687+#endif
84688diff --git a/init/initramfs.c b/init/initramfs.c
84689index a8497fa..35b3c90 100644
84690--- a/init/initramfs.c
84691+++ b/init/initramfs.c
84692@@ -84,7 +84,7 @@ static void __init free_hash(void)
84693 }
84694 }
84695
84696-static long __init do_utime(char *filename, time_t mtime)
84697+static long __init do_utime(char __force_user *filename, time_t mtime)
84698 {
84699 struct timespec t[2];
84700
84701@@ -119,7 +119,7 @@ static void __init dir_utime(void)
84702 struct dir_entry *de, *tmp;
84703 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84704 list_del(&de->list);
84705- do_utime(de->name, de->mtime);
84706+ do_utime((char __force_user *)de->name, de->mtime);
84707 kfree(de->name);
84708 kfree(de);
84709 }
84710@@ -281,7 +281,7 @@ static int __init maybe_link(void)
84711 if (nlink >= 2) {
84712 char *old = find_link(major, minor, ino, mode, collected);
84713 if (old)
84714- return (sys_link(old, collected) < 0) ? -1 : 1;
84715+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84716 }
84717 return 0;
84718 }
84719@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84720 {
84721 struct stat st;
84722
84723- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84724+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84725 if (S_ISDIR(st.st_mode))
84726- sys_rmdir(path);
84727+ sys_rmdir((char __force_user *)path);
84728 else
84729- sys_unlink(path);
84730+ sys_unlink((char __force_user *)path);
84731 }
84732 }
84733
84734@@ -315,7 +315,7 @@ static int __init do_name(void)
84735 int openflags = O_WRONLY|O_CREAT;
84736 if (ml != 1)
84737 openflags |= O_TRUNC;
84738- wfd = sys_open(collected, openflags, mode);
84739+ wfd = sys_open((char __force_user *)collected, openflags, mode);
84740
84741 if (wfd >= 0) {
84742 sys_fchown(wfd, uid, gid);
84743@@ -327,17 +327,17 @@ static int __init do_name(void)
84744 }
84745 }
84746 } else if (S_ISDIR(mode)) {
84747- sys_mkdir(collected, mode);
84748- sys_chown(collected, uid, gid);
84749- sys_chmod(collected, mode);
84750+ sys_mkdir((char __force_user *)collected, mode);
84751+ sys_chown((char __force_user *)collected, uid, gid);
84752+ sys_chmod((char __force_user *)collected, mode);
84753 dir_add(collected, mtime);
84754 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84755 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84756 if (maybe_link() == 0) {
84757- sys_mknod(collected, mode, rdev);
84758- sys_chown(collected, uid, gid);
84759- sys_chmod(collected, mode);
84760- do_utime(collected, mtime);
84761+ sys_mknod((char __force_user *)collected, mode, rdev);
84762+ sys_chown((char __force_user *)collected, uid, gid);
84763+ sys_chmod((char __force_user *)collected, mode);
84764+ do_utime((char __force_user *)collected, mtime);
84765 }
84766 }
84767 return 0;
84768@@ -346,15 +346,15 @@ static int __init do_name(void)
84769 static int __init do_copy(void)
84770 {
84771 if (count >= body_len) {
84772- sys_write(wfd, victim, body_len);
84773+ sys_write(wfd, (char __force_user *)victim, body_len);
84774 sys_close(wfd);
84775- do_utime(vcollected, mtime);
84776+ do_utime((char __force_user *)vcollected, mtime);
84777 kfree(vcollected);
84778 eat(body_len);
84779 state = SkipIt;
84780 return 0;
84781 } else {
84782- sys_write(wfd, victim, count);
84783+ sys_write(wfd, (char __force_user *)victim, count);
84784 body_len -= count;
84785 eat(count);
84786 return 1;
84787@@ -365,9 +365,9 @@ static int __init do_symlink(void)
84788 {
84789 collected[N_ALIGN(name_len) + body_len] = '\0';
84790 clean_path(collected, 0);
84791- sys_symlink(collected + N_ALIGN(name_len), collected);
84792- sys_lchown(collected, uid, gid);
84793- do_utime(collected, mtime);
84794+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
84795+ sys_lchown((char __force_user *)collected, uid, gid);
84796+ do_utime((char __force_user *)collected, mtime);
84797 state = SkipIt;
84798 next_state = Reset;
84799 return 0;
84800diff --git a/init/main.c b/init/main.c
84801index 48655ce..d0113e4 100644
84802--- a/init/main.c
84803+++ b/init/main.c
84804@@ -97,6 +97,8 @@ extern void radix_tree_init(void);
84805 static inline void mark_rodata_ro(void) { }
84806 #endif
84807
84808+extern void grsecurity_init(void);
84809+
84810 /*
84811 * Debug helper: via this flag we know that we are in 'early bootup code'
84812 * where only the boot processor is running with IRQ disabled. This means
84813@@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
84814
84815 __setup("reset_devices", set_reset_devices);
84816
84817+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84818+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
84819+static int __init setup_grsec_proc_gid(char *str)
84820+{
84821+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
84822+ return 1;
84823+}
84824+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
84825+#endif
84826+
84827+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
84828+unsigned long pax_user_shadow_base __read_only;
84829+EXPORT_SYMBOL(pax_user_shadow_base);
84830+extern char pax_enter_kernel_user[];
84831+extern char pax_exit_kernel_user[];
84832+#endif
84833+
84834+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
84835+static int __init setup_pax_nouderef(char *str)
84836+{
84837+#ifdef CONFIG_X86_32
84838+ unsigned int cpu;
84839+ struct desc_struct *gdt;
84840+
84841+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
84842+ gdt = get_cpu_gdt_table(cpu);
84843+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
84844+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
84845+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
84846+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
84847+ }
84848+ loadsegment(ds, __KERNEL_DS);
84849+ loadsegment(es, __KERNEL_DS);
84850+ loadsegment(ss, __KERNEL_DS);
84851+#else
84852+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
84853+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
84854+ clone_pgd_mask = ~(pgdval_t)0UL;
84855+ pax_user_shadow_base = 0UL;
84856+ setup_clear_cpu_cap(X86_FEATURE_PCID);
84857+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
84858+#endif
84859+
84860+ return 0;
84861+}
84862+early_param("pax_nouderef", setup_pax_nouderef);
84863+
84864+#ifdef CONFIG_X86_64
84865+static int __init setup_pax_weakuderef(char *str)
84866+{
84867+ if (clone_pgd_mask != ~(pgdval_t)0UL)
84868+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84869+ return 1;
84870+}
84871+__setup("pax_weakuderef", setup_pax_weakuderef);
84872+#endif
84873+#endif
84874+
84875+#ifdef CONFIG_PAX_SOFTMODE
84876+int pax_softmode;
84877+
84878+static int __init setup_pax_softmode(char *str)
84879+{
84880+ get_option(&str, &pax_softmode);
84881+ return 1;
84882+}
84883+__setup("pax_softmode=", setup_pax_softmode);
84884+#endif
84885+
84886 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
84887 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
84888 static const char *panic_later, *panic_param;
84889@@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
84890 {
84891 int count = preempt_count();
84892 int ret;
84893- char msgbuf[64];
84894+ const char *msg1 = "", *msg2 = "";
84895
84896 if (initcall_debug)
84897 ret = do_one_initcall_debug(fn);
84898 else
84899 ret = fn();
84900
84901- msgbuf[0] = 0;
84902-
84903 if (preempt_count() != count) {
84904- sprintf(msgbuf, "preemption imbalance ");
84905+ msg1 = " preemption imbalance";
84906 preempt_count_set(count);
84907 }
84908 if (irqs_disabled()) {
84909- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
84910+ msg2 = " disabled interrupts";
84911 local_irq_enable();
84912 }
84913- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
84914+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
84915
84916+ add_latent_entropy();
84917 return ret;
84918 }
84919
84920@@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
84921 {
84922 argv_init[0] = init_filename;
84923 return do_execve(getname_kernel(init_filename),
84924- (const char __user *const __user *)argv_init,
84925- (const char __user *const __user *)envp_init);
84926+ (const char __user *const __force_user *)argv_init,
84927+ (const char __user *const __force_user *)envp_init);
84928 }
84929
84930 static int try_to_run_init_process(const char *init_filename)
84931@@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
84932 return ret;
84933 }
84934
84935+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84936+extern int gr_init_ran;
84937+#endif
84938+
84939 static noinline void __init kernel_init_freeable(void);
84940
84941 static int __ref kernel_init(void *unused)
84942@@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
84943 ramdisk_execute_command, ret);
84944 }
84945
84946+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84947+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
84948+ gr_init_ran = 1;
84949+#endif
84950+
84951 /*
84952 * We try each of these until one succeeds.
84953 *
84954@@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
84955 do_basic_setup();
84956
84957 /* Open the /dev/console on the rootfs, this should never fail */
84958- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
84959+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
84960 pr_err("Warning: unable to open an initial console.\n");
84961
84962 (void) sys_dup(0);
84963@@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
84964 if (!ramdisk_execute_command)
84965 ramdisk_execute_command = "/init";
84966
84967- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
84968+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
84969 ramdisk_execute_command = NULL;
84970 prepare_namespace();
84971 }
84972
84973+ grsecurity_init();
84974+
84975 /*
84976 * Ok, we have completed the initial bootup, and
84977 * we're essentially up and running. Get rid of the
84978diff --git a/ipc/compat.c b/ipc/compat.c
84979index 45d035d..e4a7f99 100644
84980--- a/ipc/compat.c
84981+++ b/ipc/compat.c
84982@@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
84983 COMPAT_SHMLBA);
84984 if (err < 0)
84985 return err;
84986- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
84987+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
84988 }
84989 case SHMDT:
84990 return sys_shmdt(compat_ptr(ptr));
84991diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
84992index 998d31b..30c24df 100644
84993--- a/ipc/ipc_sysctl.c
84994+++ b/ipc/ipc_sysctl.c
84995@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
84996 static int proc_ipc_dointvec(ctl_table *table, int write,
84997 void __user *buffer, size_t *lenp, loff_t *ppos)
84998 {
84999- struct ctl_table ipc_table;
85000+ ctl_table_no_const ipc_table;
85001
85002 memcpy(&ipc_table, table, sizeof(ipc_table));
85003 ipc_table.data = get_ipc(table);
85004@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85005 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85006 void __user *buffer, size_t *lenp, loff_t *ppos)
85007 {
85008- struct ctl_table ipc_table;
85009+ ctl_table_no_const ipc_table;
85010
85011 memcpy(&ipc_table, table, sizeof(ipc_table));
85012 ipc_table.data = get_ipc(table);
85013@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85014 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85015 void __user *buffer, size_t *lenp, loff_t *ppos)
85016 {
85017- struct ctl_table ipc_table;
85018+ ctl_table_no_const ipc_table;
85019 size_t lenp_bef = *lenp;
85020 int rc;
85021
85022@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85023 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85024 void __user *buffer, size_t *lenp, loff_t *ppos)
85025 {
85026- struct ctl_table ipc_table;
85027+ ctl_table_no_const ipc_table;
85028 memcpy(&ipc_table, table, sizeof(ipc_table));
85029 ipc_table.data = get_ipc(table);
85030
85031@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85032 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85033 void __user *buffer, size_t *lenp, loff_t *ppos)
85034 {
85035- struct ctl_table ipc_table;
85036+ ctl_table_no_const ipc_table;
85037 size_t lenp_bef = *lenp;
85038 int oldval;
85039 int rc;
85040diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85041index 5bb8bfe..a38ec05 100644
85042--- a/ipc/mq_sysctl.c
85043+++ b/ipc/mq_sysctl.c
85044@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85045 static int proc_mq_dointvec(ctl_table *table, int write,
85046 void __user *buffer, size_t *lenp, loff_t *ppos)
85047 {
85048- struct ctl_table mq_table;
85049+ ctl_table_no_const mq_table;
85050 memcpy(&mq_table, table, sizeof(mq_table));
85051 mq_table.data = get_mq(table);
85052
85053@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85054 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85055 void __user *buffer, size_t *lenp, loff_t *ppos)
85056 {
85057- struct ctl_table mq_table;
85058+ ctl_table_no_const mq_table;
85059 memcpy(&mq_table, table, sizeof(mq_table));
85060 mq_table.data = get_mq(table);
85061
85062diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85063index 4fcf39a..d3cc2ec 100644
85064--- a/ipc/mqueue.c
85065+++ b/ipc/mqueue.c
85066@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85067 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85068 info->attr.mq_msgsize);
85069
85070+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85071 spin_lock(&mq_lock);
85072 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85073 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85074diff --git a/ipc/msg.c b/ipc/msg.c
85075index 6498531..b0ff3c8 100644
85076--- a/ipc/msg.c
85077+++ b/ipc/msg.c
85078@@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85079 return security_msg_queue_associate(msq, msgflg);
85080 }
85081
85082+static struct ipc_ops msg_ops = {
85083+ .getnew = newque,
85084+ .associate = msg_security,
85085+ .more_checks = NULL
85086+};
85087+
85088 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85089 {
85090 struct ipc_namespace *ns;
85091- struct ipc_ops msg_ops;
85092 struct ipc_params msg_params;
85093
85094 ns = current->nsproxy->ipc_ns;
85095
85096- msg_ops.getnew = newque;
85097- msg_ops.associate = msg_security;
85098- msg_ops.more_checks = NULL;
85099-
85100 msg_params.key = key;
85101 msg_params.flg = msgflg;
85102
85103diff --git a/ipc/sem.c b/ipc/sem.c
85104index bee5554..e9af81dd 100644
85105--- a/ipc/sem.c
85106+++ b/ipc/sem.c
85107@@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85108 return 0;
85109 }
85110
85111+static struct ipc_ops sem_ops = {
85112+ .getnew = newary,
85113+ .associate = sem_security,
85114+ .more_checks = sem_more_checks
85115+};
85116+
85117 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85118 {
85119 struct ipc_namespace *ns;
85120- struct ipc_ops sem_ops;
85121 struct ipc_params sem_params;
85122
85123 ns = current->nsproxy->ipc_ns;
85124@@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85125 if (nsems < 0 || nsems > ns->sc_semmsl)
85126 return -EINVAL;
85127
85128- sem_ops.getnew = newary;
85129- sem_ops.associate = sem_security;
85130- sem_ops.more_checks = sem_more_checks;
85131-
85132 sem_params.key = key;
85133 sem_params.flg = semflg;
85134 sem_params.u.nsems = nsems;
85135diff --git a/ipc/shm.c b/ipc/shm.c
85136index 7645961..afc7f02 100644
85137--- a/ipc/shm.c
85138+++ b/ipc/shm.c
85139@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85140 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85141 #endif
85142
85143+#ifdef CONFIG_GRKERNSEC
85144+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85145+ const time_t shm_createtime, const kuid_t cuid,
85146+ const int shmid);
85147+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85148+ const time_t shm_createtime);
85149+#endif
85150+
85151 void shm_init_ns(struct ipc_namespace *ns)
85152 {
85153 ns->shm_ctlmax = SHMMAX;
85154@@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85155 shp->shm_lprid = 0;
85156 shp->shm_atim = shp->shm_dtim = 0;
85157 shp->shm_ctim = get_seconds();
85158+#ifdef CONFIG_GRKERNSEC
85159+ {
85160+ struct timespec timeval;
85161+ do_posix_clock_monotonic_gettime(&timeval);
85162+
85163+ shp->shm_createtime = timeval.tv_sec;
85164+ }
85165+#endif
85166 shp->shm_segsz = size;
85167 shp->shm_nattch = 0;
85168 shp->shm_file = file;
85169@@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85170 return 0;
85171 }
85172
85173+static struct ipc_ops shm_ops = {
85174+ .getnew = newseg,
85175+ .associate = shm_security,
85176+ .more_checks = shm_more_checks
85177+};
85178+
85179 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85180 {
85181 struct ipc_namespace *ns;
85182- struct ipc_ops shm_ops;
85183 struct ipc_params shm_params;
85184
85185 ns = current->nsproxy->ipc_ns;
85186
85187- shm_ops.getnew = newseg;
85188- shm_ops.associate = shm_security;
85189- shm_ops.more_checks = shm_more_checks;
85190-
85191 shm_params.key = key;
85192 shm_params.flg = shmflg;
85193 shm_params.u.size = size;
85194@@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85195 f_mode = FMODE_READ | FMODE_WRITE;
85196 }
85197 if (shmflg & SHM_EXEC) {
85198+
85199+#ifdef CONFIG_PAX_MPROTECT
85200+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
85201+ goto out;
85202+#endif
85203+
85204 prot |= PROT_EXEC;
85205 acc_mode |= S_IXUGO;
85206 }
85207@@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85208 if (err)
85209 goto out_unlock;
85210
85211+#ifdef CONFIG_GRKERNSEC
85212+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85213+ shp->shm_perm.cuid, shmid) ||
85214+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85215+ err = -EACCES;
85216+ goto out_unlock;
85217+ }
85218+#endif
85219+
85220 ipc_lock_object(&shp->shm_perm);
85221
85222 /* check if shm_destroy() is tearing down shp */
85223@@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85224 path = shp->shm_file->f_path;
85225 path_get(&path);
85226 shp->shm_nattch++;
85227+#ifdef CONFIG_GRKERNSEC
85228+ shp->shm_lapid = current->pid;
85229+#endif
85230 size = i_size_read(path.dentry->d_inode);
85231 ipc_unlock_object(&shp->shm_perm);
85232 rcu_read_unlock();
85233diff --git a/ipc/util.c b/ipc/util.c
85234index 2eb0d1e..0308564 100644
85235--- a/ipc/util.c
85236+++ b/ipc/util.c
85237@@ -71,6 +71,8 @@ struct ipc_proc_iface {
85238 int (*show)(struct seq_file *, void *);
85239 };
85240
85241+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85242+
85243 static void ipc_memory_notifier(struct work_struct *work)
85244 {
85245 ipcns_notify(IPCNS_MEMCHANGED);
85246@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85247 granted_mode >>= 6;
85248 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85249 granted_mode >>= 3;
85250+
85251+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85252+ return -1;
85253+
85254 /* is there some bit set in requested_mode but not in granted_mode? */
85255 if ((requested_mode & ~granted_mode & 0007) &&
85256 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85257diff --git a/kernel/acct.c b/kernel/acct.c
85258index 8d6e145..33e0b1e 100644
85259--- a/kernel/acct.c
85260+++ b/kernel/acct.c
85261@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85262 */
85263 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85264 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85265- file->f_op->write(file, (char *)&ac,
85266+ file->f_op->write(file, (char __force_user *)&ac,
85267 sizeof(acct_t), &file->f_pos);
85268 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85269 set_fs(fs);
85270diff --git a/kernel/audit.c b/kernel/audit.c
85271index 47845c5..bd9dd5b 100644
85272--- a/kernel/audit.c
85273+++ b/kernel/audit.c
85274@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85275 3) suppressed due to audit_rate_limit
85276 4) suppressed due to audit_backlog_limit
85277 */
85278-static atomic_t audit_lost = ATOMIC_INIT(0);
85279+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85280
85281 /* The netlink socket. */
85282 static struct sock *audit_sock;
85283@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85284 unsigned long now;
85285 int print;
85286
85287- atomic_inc(&audit_lost);
85288+ atomic_inc_unchecked(&audit_lost);
85289
85290 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85291
85292@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85293 if (print) {
85294 if (printk_ratelimit())
85295 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85296- atomic_read(&audit_lost),
85297+ atomic_read_unchecked(&audit_lost),
85298 audit_rate_limit,
85299 audit_backlog_limit);
85300 audit_panic(message);
85301@@ -808,7 +808,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85302 s.pid = audit_pid;
85303 s.rate_limit = audit_rate_limit;
85304 s.backlog_limit = audit_backlog_limit;
85305- s.lost = atomic_read(&audit_lost);
85306+ s.lost = atomic_read_unchecked(&audit_lost);
85307 s.backlog = skb_queue_len(&audit_skb_queue);
85308 s.version = AUDIT_VERSION_LATEST;
85309 s.backlog_wait_time = audit_backlog_wait_time;
85310diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85311index 21eae3c..66db239 100644
85312--- a/kernel/auditsc.c
85313+++ b/kernel/auditsc.c
85314@@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85315 }
85316
85317 /* global counter which is incremented every time something logs in */
85318-static atomic_t session_id = ATOMIC_INIT(0);
85319+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85320
85321 static int audit_set_loginuid_perm(kuid_t loginuid)
85322 {
85323@@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
85324
85325 /* are we setting or clearing? */
85326 if (uid_valid(loginuid))
85327- sessionid = (unsigned int)atomic_inc_return(&session_id);
85328+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85329
85330 task->sessionid = sessionid;
85331 task->loginuid = loginuid;
85332diff --git a/kernel/capability.c b/kernel/capability.c
85333index 24663b3..b926ae1 100644
85334--- a/kernel/capability.c
85335+++ b/kernel/capability.c
85336@@ -193,6 +193,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85337 * before modification is attempted and the application
85338 * fails.
85339 */
85340+ if (tocopy > ARRAY_SIZE(kdata))
85341+ return -EFAULT;
85342+
85343 if (copy_to_user(dataptr, kdata, tocopy
85344 * sizeof(struct __user_cap_data_struct))) {
85345 return -EFAULT;
85346@@ -294,10 +297,11 @@ bool has_ns_capability(struct task_struct *t,
85347 int ret;
85348
85349 rcu_read_lock();
85350- ret = security_capable(__task_cred(t), ns, cap);
85351+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85352+ gr_task_is_capable(t, __task_cred(t), cap);
85353 rcu_read_unlock();
85354
85355- return (ret == 0);
85356+ return ret;
85357 }
85358
85359 /**
85360@@ -334,10 +338,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85361 int ret;
85362
85363 rcu_read_lock();
85364- ret = security_capable_noaudit(__task_cred(t), ns, cap);
85365+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85366 rcu_read_unlock();
85367
85368- return (ret == 0);
85369+ return ret;
85370 }
85371
85372 /**
85373@@ -375,7 +379,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85374 BUG();
85375 }
85376
85377- if (security_capable(current_cred(), ns, cap) == 0) {
85378+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85379 current->flags |= PF_SUPERPRIV;
85380 return true;
85381 }
85382@@ -383,6 +387,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85383 }
85384 EXPORT_SYMBOL(ns_capable);
85385
85386+bool ns_capable_nolog(struct user_namespace *ns, int cap)
85387+{
85388+ if (unlikely(!cap_valid(cap))) {
85389+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85390+ BUG();
85391+ }
85392+
85393+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85394+ current->flags |= PF_SUPERPRIV;
85395+ return true;
85396+ }
85397+ return false;
85398+}
85399+EXPORT_SYMBOL(ns_capable_nolog);
85400+
85401 /**
85402 * file_ns_capable - Determine if the file's opener had a capability in effect
85403 * @file: The file we want to check
85404@@ -423,6 +442,12 @@ bool capable(int cap)
85405 }
85406 EXPORT_SYMBOL(capable);
85407
85408+bool capable_nolog(int cap)
85409+{
85410+ return ns_capable_nolog(&init_user_ns, cap);
85411+}
85412+EXPORT_SYMBOL(capable_nolog);
85413+
85414 /**
85415 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
85416 * @inode: The inode in question
85417@@ -440,3 +465,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
85418 kgid_has_mapping(ns, inode->i_gid);
85419 }
85420 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
85421+
85422+bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
85423+{
85424+ struct user_namespace *ns = current_user_ns();
85425+
85426+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
85427+ kgid_has_mapping(ns, inode->i_gid);
85428+}
85429+EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
85430diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85431index ceee0c5..d6f81dd 100644
85432--- a/kernel/cgroup.c
85433+++ b/kernel/cgroup.c
85434@@ -4757,7 +4757,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85435 struct task_struct *task;
85436 int count = 0;
85437
85438- seq_printf(seq, "css_set %p\n", cset);
85439+ seq_printf(seq, "css_set %pK\n", cset);
85440
85441 list_for_each_entry(task, &cset->tasks, cg_list) {
85442 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
85443diff --git a/kernel/compat.c b/kernel/compat.c
85444index e40b043..3da8f51 100644
85445--- a/kernel/compat.c
85446+++ b/kernel/compat.c
85447@@ -13,6 +13,7 @@
85448
85449 #include <linux/linkage.h>
85450 #include <linux/compat.h>
85451+#include <linux/module.h>
85452 #include <linux/errno.h>
85453 #include <linux/time.h>
85454 #include <linux/signal.h>
85455@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85456 mm_segment_t oldfs;
85457 long ret;
85458
85459- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85460+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85461 oldfs = get_fs();
85462 set_fs(KERNEL_DS);
85463 ret = hrtimer_nanosleep_restart(restart);
85464@@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
85465 oldfs = get_fs();
85466 set_fs(KERNEL_DS);
85467 ret = hrtimer_nanosleep(&tu,
85468- rmtp ? (struct timespec __user *)&rmt : NULL,
85469+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
85470 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85471 set_fs(oldfs);
85472
85473@@ -361,7 +362,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
85474 mm_segment_t old_fs = get_fs();
85475
85476 set_fs(KERNEL_DS);
85477- ret = sys_sigpending((old_sigset_t __user *) &s);
85478+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
85479 set_fs(old_fs);
85480 if (ret == 0)
85481 ret = put_user(s, set);
85482@@ -451,7 +452,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
85483 mm_segment_t old_fs = get_fs();
85484
85485 set_fs(KERNEL_DS);
85486- ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
85487+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85488 set_fs(old_fs);
85489
85490 if (!ret) {
85491@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85492 set_fs (KERNEL_DS);
85493 ret = sys_wait4(pid,
85494 (stat_addr ?
85495- (unsigned int __user *) &status : NULL),
85496- options, (struct rusage __user *) &r);
85497+ (unsigned int __force_user *) &status : NULL),
85498+ options, (struct rusage __force_user *) &r);
85499 set_fs (old_fs);
85500
85501 if (ret > 0) {
85502@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85503 memset(&info, 0, sizeof(info));
85504
85505 set_fs(KERNEL_DS);
85506- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85507- uru ? (struct rusage __user *)&ru : NULL);
85508+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85509+ uru ? (struct rusage __force_user *)&ru : NULL);
85510 set_fs(old_fs);
85511
85512 if ((ret < 0) || (info.si_signo == 0))
85513@@ -695,8 +696,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
85514 oldfs = get_fs();
85515 set_fs(KERNEL_DS);
85516 err = sys_timer_settime(timer_id, flags,
85517- (struct itimerspec __user *) &newts,
85518- (struct itimerspec __user *) &oldts);
85519+ (struct itimerspec __force_user *) &newts,
85520+ (struct itimerspec __force_user *) &oldts);
85521 set_fs(oldfs);
85522 if (!err && old && put_compat_itimerspec(old, &oldts))
85523 return -EFAULT;
85524@@ -713,7 +714,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
85525 oldfs = get_fs();
85526 set_fs(KERNEL_DS);
85527 err = sys_timer_gettime(timer_id,
85528- (struct itimerspec __user *) &ts);
85529+ (struct itimerspec __force_user *) &ts);
85530 set_fs(oldfs);
85531 if (!err && put_compat_itimerspec(setting, &ts))
85532 return -EFAULT;
85533@@ -732,7 +733,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
85534 oldfs = get_fs();
85535 set_fs(KERNEL_DS);
85536 err = sys_clock_settime(which_clock,
85537- (struct timespec __user *) &ts);
85538+ (struct timespec __force_user *) &ts);
85539 set_fs(oldfs);
85540 return err;
85541 }
85542@@ -747,7 +748,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
85543 oldfs = get_fs();
85544 set_fs(KERNEL_DS);
85545 err = sys_clock_gettime(which_clock,
85546- (struct timespec __user *) &ts);
85547+ (struct timespec __force_user *) &ts);
85548 set_fs(oldfs);
85549 if (!err && compat_put_timespec(&ts, tp))
85550 return -EFAULT;
85551@@ -767,7 +768,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
85552
85553 oldfs = get_fs();
85554 set_fs(KERNEL_DS);
85555- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85556+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85557 set_fs(oldfs);
85558
85559 err = compat_put_timex(utp, &txc);
85560@@ -787,7 +788,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
85561 oldfs = get_fs();
85562 set_fs(KERNEL_DS);
85563 err = sys_clock_getres(which_clock,
85564- (struct timespec __user *) &ts);
85565+ (struct timespec __force_user *) &ts);
85566 set_fs(oldfs);
85567 if (!err && tp && compat_put_timespec(&ts, tp))
85568 return -EFAULT;
85569@@ -801,7 +802,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85570 struct timespec tu;
85571 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85572
85573- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85574+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85575 oldfs = get_fs();
85576 set_fs(KERNEL_DS);
85577 err = clock_nanosleep_restart(restart);
85578@@ -833,8 +834,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
85579 oldfs = get_fs();
85580 set_fs(KERNEL_DS);
85581 err = sys_clock_nanosleep(which_clock, flags,
85582- (struct timespec __user *) &in,
85583- (struct timespec __user *) &out);
85584+ (struct timespec __force_user *) &in,
85585+ (struct timespec __force_user *) &out);
85586 set_fs(oldfs);
85587
85588 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85589@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85590 mm_segment_t old_fs = get_fs();
85591
85592 set_fs(KERNEL_DS);
85593- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85594+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85595 set_fs(old_fs);
85596 if (compat_put_timespec(&t, interval))
85597 return -EFAULT;
85598diff --git a/kernel/configs.c b/kernel/configs.c
85599index c18b1f1..b9a0132 100644
85600--- a/kernel/configs.c
85601+++ b/kernel/configs.c
85602@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85603 struct proc_dir_entry *entry;
85604
85605 /* create the current config file */
85606+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85607+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85608+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85609+ &ikconfig_file_ops);
85610+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85611+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
85612+ &ikconfig_file_ops);
85613+#endif
85614+#else
85615 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
85616 &ikconfig_file_ops);
85617+#endif
85618+
85619 if (!entry)
85620 return -ENOMEM;
85621
85622diff --git a/kernel/cred.c b/kernel/cred.c
85623index e0573a4..26c0fd3 100644
85624--- a/kernel/cred.c
85625+++ b/kernel/cred.c
85626@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85627 validate_creds(cred);
85628 alter_cred_subscribers(cred, -1);
85629 put_cred(cred);
85630+
85631+#ifdef CONFIG_GRKERNSEC_SETXID
85632+ cred = (struct cred *) tsk->delayed_cred;
85633+ if (cred != NULL) {
85634+ tsk->delayed_cred = NULL;
85635+ validate_creds(cred);
85636+ alter_cred_subscribers(cred, -1);
85637+ put_cred(cred);
85638+ }
85639+#endif
85640 }
85641
85642 /**
85643@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85644 * Always returns 0 thus allowing this function to be tail-called at the end
85645 * of, say, sys_setgid().
85646 */
85647-int commit_creds(struct cred *new)
85648+static int __commit_creds(struct cred *new)
85649 {
85650 struct task_struct *task = current;
85651 const struct cred *old = task->real_cred;
85652@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85653
85654 get_cred(new); /* we will require a ref for the subj creds too */
85655
85656+ gr_set_role_label(task, new->uid, new->gid);
85657+
85658 /* dumpability changes */
85659 if (!uid_eq(old->euid, new->euid) ||
85660 !gid_eq(old->egid, new->egid) ||
85661@@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
85662 put_cred(old);
85663 return 0;
85664 }
85665+#ifdef CONFIG_GRKERNSEC_SETXID
85666+extern int set_user(struct cred *new);
85667+
85668+void gr_delayed_cred_worker(void)
85669+{
85670+ const struct cred *new = current->delayed_cred;
85671+ struct cred *ncred;
85672+
85673+ current->delayed_cred = NULL;
85674+
85675+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85676+ // from doing get_cred on it when queueing this
85677+ put_cred(new);
85678+ return;
85679+ } else if (new == NULL)
85680+ return;
85681+
85682+ ncred = prepare_creds();
85683+ if (!ncred)
85684+ goto die;
85685+ // uids
85686+ ncred->uid = new->uid;
85687+ ncred->euid = new->euid;
85688+ ncred->suid = new->suid;
85689+ ncred->fsuid = new->fsuid;
85690+ // gids
85691+ ncred->gid = new->gid;
85692+ ncred->egid = new->egid;
85693+ ncred->sgid = new->sgid;
85694+ ncred->fsgid = new->fsgid;
85695+ // groups
85696+ set_groups(ncred, new->group_info);
85697+ // caps
85698+ ncred->securebits = new->securebits;
85699+ ncred->cap_inheritable = new->cap_inheritable;
85700+ ncred->cap_permitted = new->cap_permitted;
85701+ ncred->cap_effective = new->cap_effective;
85702+ ncred->cap_bset = new->cap_bset;
85703+
85704+ if (set_user(ncred)) {
85705+ abort_creds(ncred);
85706+ goto die;
85707+ }
85708+
85709+ // from doing get_cred on it when queueing this
85710+ put_cred(new);
85711+
85712+ __commit_creds(ncred);
85713+ return;
85714+die:
85715+ // from doing get_cred on it when queueing this
85716+ put_cred(new);
85717+ do_group_exit(SIGKILL);
85718+}
85719+#endif
85720+
85721+int commit_creds(struct cred *new)
85722+{
85723+#ifdef CONFIG_GRKERNSEC_SETXID
85724+ int ret;
85725+ int schedule_it = 0;
85726+ struct task_struct *t;
85727+ unsigned oldsecurebits = current_cred()->securebits;
85728+
85729+ /* we won't get called with tasklist_lock held for writing
85730+ and interrupts disabled as the cred struct in that case is
85731+ init_cred
85732+ */
85733+ if (grsec_enable_setxid && !current_is_single_threaded() &&
85734+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85735+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85736+ schedule_it = 1;
85737+ }
85738+ ret = __commit_creds(new);
85739+ if (schedule_it) {
85740+ rcu_read_lock();
85741+ read_lock(&tasklist_lock);
85742+ for (t = next_thread(current); t != current;
85743+ t = next_thread(t)) {
85744+ /* we'll check if the thread has uid 0 in
85745+ * the delayed worker routine
85746+ */
85747+ if (task_securebits(t) == oldsecurebits &&
85748+ t->delayed_cred == NULL) {
85749+ t->delayed_cred = get_cred(new);
85750+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85751+ set_tsk_need_resched(t);
85752+ }
85753+ }
85754+ read_unlock(&tasklist_lock);
85755+ rcu_read_unlock();
85756+ }
85757+
85758+ return ret;
85759+#else
85760+ return __commit_creds(new);
85761+#endif
85762+}
85763+
85764 EXPORT_SYMBOL(commit_creds);
85765
85766 /**
85767diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
85768index 2956c8d..cfe1e2e 100644
85769--- a/kernel/debug/debug_core.c
85770+++ b/kernel/debug/debug_core.c
85771@@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
85772 */
85773 static atomic_t masters_in_kgdb;
85774 static atomic_t slaves_in_kgdb;
85775-static atomic_t kgdb_break_tasklet_var;
85776+static atomic_unchecked_t kgdb_break_tasklet_var;
85777 atomic_t kgdb_setting_breakpoint;
85778
85779 struct task_struct *kgdb_usethread;
85780@@ -134,7 +134,7 @@ int kgdb_single_step;
85781 static pid_t kgdb_sstep_pid;
85782
85783 /* to keep track of the CPU which is doing the single stepping*/
85784-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85785+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85786
85787 /*
85788 * If you are debugging a problem where roundup (the collection of
85789@@ -549,7 +549,7 @@ return_normal:
85790 * kernel will only try for the value of sstep_tries before
85791 * giving up and continuing on.
85792 */
85793- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
85794+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
85795 (kgdb_info[cpu].task &&
85796 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
85797 atomic_set(&kgdb_active, -1);
85798@@ -647,8 +647,8 @@ cpu_master_loop:
85799 }
85800
85801 kgdb_restore:
85802- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
85803- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
85804+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
85805+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
85806 if (kgdb_info[sstep_cpu].task)
85807 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
85808 else
85809@@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
85810 static void kgdb_tasklet_bpt(unsigned long ing)
85811 {
85812 kgdb_breakpoint();
85813- atomic_set(&kgdb_break_tasklet_var, 0);
85814+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
85815 }
85816
85817 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
85818
85819 void kgdb_schedule_breakpoint(void)
85820 {
85821- if (atomic_read(&kgdb_break_tasklet_var) ||
85822+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
85823 atomic_read(&kgdb_active) != -1 ||
85824 atomic_read(&kgdb_setting_breakpoint))
85825 return;
85826- atomic_inc(&kgdb_break_tasklet_var);
85827+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
85828 tasklet_schedule(&kgdb_tasklet_breakpoint);
85829 }
85830 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
85831diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
85832index 0b097c8..11dd5c5 100644
85833--- a/kernel/debug/kdb/kdb_main.c
85834+++ b/kernel/debug/kdb/kdb_main.c
85835@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
85836 continue;
85837
85838 kdb_printf("%-20s%8u 0x%p ", mod->name,
85839- mod->core_size, (void *)mod);
85840+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
85841 #ifdef CONFIG_MODULE_UNLOAD
85842 kdb_printf("%4ld ", module_refcount(mod));
85843 #endif
85844@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
85845 kdb_printf(" (Loading)");
85846 else
85847 kdb_printf(" (Live)");
85848- kdb_printf(" 0x%p", mod->module_core);
85849+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
85850
85851 #ifdef CONFIG_MODULE_UNLOAD
85852 {
85853diff --git a/kernel/events/core.c b/kernel/events/core.c
85854index 440eefc..0909f02 100644
85855--- a/kernel/events/core.c
85856+++ b/kernel/events/core.c
85857@@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
85858 * 0 - disallow raw tracepoint access for unpriv
85859 * 1 - disallow cpu events for unpriv
85860 * 2 - disallow kernel profiling for unpriv
85861+ * 3 - disallow all unpriv perf event use
85862 */
85863-int sysctl_perf_event_paranoid __read_mostly = 1;
85864+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85865+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85866+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85867+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85868+#else
85869+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85870+#endif
85871
85872 /* Minimum for 512 kiB + 1 user control page */
85873 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85874@@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
85875
85876 tmp *= sysctl_perf_cpu_time_max_percent;
85877 do_div(tmp, 100);
85878- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85879+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
85880 }
85881
85882 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
85883@@ -291,7 +298,7 @@ void perf_sample_event_took(u64 sample_len_ns)
85884 }
85885 }
85886
85887-static atomic64_t perf_event_id;
85888+static atomic64_unchecked_t perf_event_id;
85889
85890 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
85891 enum event_type_t event_type);
85892@@ -3002,7 +3009,7 @@ static void __perf_event_read(void *info)
85893
85894 static inline u64 perf_event_count(struct perf_event *event)
85895 {
85896- return local64_read(&event->count) + atomic64_read(&event->child_count);
85897+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
85898 }
85899
85900 static u64 perf_event_read(struct perf_event *event)
85901@@ -3361,9 +3368,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
85902 mutex_lock(&event->child_mutex);
85903 total += perf_event_read(event);
85904 *enabled += event->total_time_enabled +
85905- atomic64_read(&event->child_total_time_enabled);
85906+ atomic64_read_unchecked(&event->child_total_time_enabled);
85907 *running += event->total_time_running +
85908- atomic64_read(&event->child_total_time_running);
85909+ atomic64_read_unchecked(&event->child_total_time_running);
85910
85911 list_for_each_entry(child, &event->child_list, child_list) {
85912 total += perf_event_read(child);
85913@@ -3792,10 +3799,10 @@ void perf_event_update_userpage(struct perf_event *event)
85914 userpg->offset -= local64_read(&event->hw.prev_count);
85915
85916 userpg->time_enabled = enabled +
85917- atomic64_read(&event->child_total_time_enabled);
85918+ atomic64_read_unchecked(&event->child_total_time_enabled);
85919
85920 userpg->time_running = running +
85921- atomic64_read(&event->child_total_time_running);
85922+ atomic64_read_unchecked(&event->child_total_time_running);
85923
85924 arch_perf_update_userpage(userpg, now);
85925
85926@@ -4359,7 +4366,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
85927
85928 /* Data. */
85929 sp = perf_user_stack_pointer(regs);
85930- rem = __output_copy_user(handle, (void *) sp, dump_size);
85931+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
85932 dyn_size = dump_size - rem;
85933
85934 perf_output_skip(handle, rem);
85935@@ -4450,11 +4457,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
85936 values[n++] = perf_event_count(event);
85937 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
85938 values[n++] = enabled +
85939- atomic64_read(&event->child_total_time_enabled);
85940+ atomic64_read_unchecked(&event->child_total_time_enabled);
85941 }
85942 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
85943 values[n++] = running +
85944- atomic64_read(&event->child_total_time_running);
85945+ atomic64_read_unchecked(&event->child_total_time_running);
85946 }
85947 if (read_format & PERF_FORMAT_ID)
85948 values[n++] = primary_event_id(event);
85949@@ -6733,7 +6740,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
85950 event->parent = parent_event;
85951
85952 event->ns = get_pid_ns(task_active_pid_ns(current));
85953- event->id = atomic64_inc_return(&perf_event_id);
85954+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
85955
85956 event->state = PERF_EVENT_STATE_INACTIVE;
85957
85958@@ -7015,6 +7022,11 @@ SYSCALL_DEFINE5(perf_event_open,
85959 if (flags & ~PERF_FLAG_ALL)
85960 return -EINVAL;
85961
85962+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85963+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
85964+ return -EACCES;
85965+#endif
85966+
85967 err = perf_copy_attr(attr_uptr, &attr);
85968 if (err)
85969 return err;
85970@@ -7353,10 +7365,10 @@ static void sync_child_event(struct perf_event *child_event,
85971 /*
85972 * Add back the child's count to the parent's count:
85973 */
85974- atomic64_add(child_val, &parent_event->child_count);
85975- atomic64_add(child_event->total_time_enabled,
85976+ atomic64_add_unchecked(child_val, &parent_event->child_count);
85977+ atomic64_add_unchecked(child_event->total_time_enabled,
85978 &parent_event->child_total_time_enabled);
85979- atomic64_add(child_event->total_time_running,
85980+ atomic64_add_unchecked(child_event->total_time_running,
85981 &parent_event->child_total_time_running);
85982
85983 /*
85984diff --git a/kernel/events/internal.h b/kernel/events/internal.h
85985index 569b2187..19940d9 100644
85986--- a/kernel/events/internal.h
85987+++ b/kernel/events/internal.h
85988@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
85989 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
85990 }
85991
85992-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
85993+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
85994 static inline unsigned long \
85995 func_name(struct perf_output_handle *handle, \
85996- const void *buf, unsigned long len) \
85997+ const void user *buf, unsigned long len) \
85998 { \
85999 unsigned long size, written; \
86000 \
86001@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86002 return 0;
86003 }
86004
86005-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86006+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86007
86008 static inline unsigned long
86009 memcpy_skip(void *dst, const void *src, unsigned long n)
86010@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86011 return 0;
86012 }
86013
86014-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86015+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86016
86017 #ifndef arch_perf_out_copy_user
86018 #define arch_perf_out_copy_user arch_perf_out_copy_user
86019@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86020 }
86021 #endif
86022
86023-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86024+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86025
86026 /* Callchain handling */
86027 extern struct perf_callchain_entry *
86028diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86029index 04709b6..d330828 100644
86030--- a/kernel/events/uprobes.c
86031+++ b/kernel/events/uprobes.c
86032@@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86033 {
86034 struct page *page;
86035 uprobe_opcode_t opcode;
86036- int result;
86037+ long result;
86038
86039 pagefault_disable();
86040 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86041diff --git a/kernel/exit.c b/kernel/exit.c
86042index 6ed6a1d..edecb0e 100644
86043--- a/kernel/exit.c
86044+++ b/kernel/exit.c
86045@@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86046 struct task_struct *leader;
86047 int zap_leader;
86048 repeat:
86049+#ifdef CONFIG_NET
86050+ gr_del_task_from_ip_table(p);
86051+#endif
86052+
86053 /* don't need to get the RCU readlock here - the process is dead and
86054 * can't be modifying its own credentials. But shut RCU-lockdep up */
86055 rcu_read_lock();
86056@@ -330,7 +334,7 @@ int allow_signal(int sig)
86057 * know it'll be handled, so that they don't get converted to
86058 * SIGKILL or just silently dropped.
86059 */
86060- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86061+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86062 recalc_sigpending();
86063 spin_unlock_irq(&current->sighand->siglock);
86064 return 0;
86065@@ -699,6 +703,8 @@ void do_exit(long code)
86066 struct task_struct *tsk = current;
86067 int group_dead;
86068
86069+ set_fs(USER_DS);
86070+
86071 profile_task_exit(tsk);
86072
86073 WARN_ON(blk_needs_flush_plug(tsk));
86074@@ -715,7 +721,6 @@ void do_exit(long code)
86075 * mm_release()->clear_child_tid() from writing to a user-controlled
86076 * kernel address.
86077 */
86078- set_fs(USER_DS);
86079
86080 ptrace_event(PTRACE_EVENT_EXIT, code);
86081
86082@@ -774,6 +779,9 @@ void do_exit(long code)
86083 tsk->exit_code = code;
86084 taskstats_exit(tsk, group_dead);
86085
86086+ gr_acl_handle_psacct(tsk, code);
86087+ gr_acl_handle_exit();
86088+
86089 exit_mm(tsk);
86090
86091 if (group_dead)
86092@@ -893,7 +901,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86093 * Take down every thread in the group. This is called by fatal signals
86094 * as well as by sys_exit_group (below).
86095 */
86096-void
86097+__noreturn void
86098 do_group_exit(int exit_code)
86099 {
86100 struct signal_struct *sig = current->signal;
86101diff --git a/kernel/fork.c b/kernel/fork.c
86102index 54a8d26..9a24446 100644
86103--- a/kernel/fork.c
86104+++ b/kernel/fork.c
86105@@ -183,6 +183,48 @@ void thread_info_cache_init(void)
86106 # endif
86107 #endif
86108
86109+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86110+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86111+ int node, void **lowmem_stack)
86112+{
86113+ struct page *pages[THREAD_SIZE / PAGE_SIZE];
86114+ void *ret = NULL;
86115+ unsigned int i;
86116+
86117+ *lowmem_stack = alloc_thread_info_node(tsk, node);
86118+ if (*lowmem_stack == NULL)
86119+ goto out;
86120+
86121+ for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
86122+ pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
86123+
86124+ /* use VM_IOREMAP to gain THREAD_SIZE alignment */
86125+ ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
86126+ if (ret == NULL) {
86127+ free_thread_info(*lowmem_stack);
86128+ *lowmem_stack = NULL;
86129+ }
86130+
86131+out:
86132+ return ret;
86133+}
86134+
86135+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86136+{
86137+ unmap_process_stacks(tsk);
86138+}
86139+#else
86140+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86141+ int node, void **lowmem_stack)
86142+{
86143+ return alloc_thread_info_node(tsk, node);
86144+}
86145+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86146+{
86147+ free_thread_info(ti);
86148+}
86149+#endif
86150+
86151 /* SLAB cache for signal_struct structures (tsk->signal) */
86152 static struct kmem_cache *signal_cachep;
86153
86154@@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
86155 /* SLAB cache for mm_struct structures (tsk->mm) */
86156 static struct kmem_cache *mm_cachep;
86157
86158-static void account_kernel_stack(struct thread_info *ti, int account)
86159+static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
86160 {
86161+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86162+ struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
86163+#else
86164 struct zone *zone = page_zone(virt_to_page(ti));
86165+#endif
86166
86167 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
86168 }
86169
86170 void free_task(struct task_struct *tsk)
86171 {
86172- account_kernel_stack(tsk->stack, -1);
86173+ account_kernel_stack(tsk, tsk->stack, -1);
86174 arch_release_thread_info(tsk->stack);
86175- free_thread_info(tsk->stack);
86176+ gr_free_thread_info(tsk, tsk->stack);
86177 rt_mutex_debug_task_free(tsk);
86178 ftrace_graph_exit_task(tsk);
86179 put_seccomp_filter(tsk);
86180@@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86181 struct task_struct *tsk;
86182 struct thread_info *ti;
86183 unsigned long *stackend;
86184+ void *lowmem_stack;
86185 int node = tsk_fork_get_node(orig);
86186 int err;
86187
86188@@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86189 if (!tsk)
86190 return NULL;
86191
86192- ti = alloc_thread_info_node(tsk, node);
86193+ ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
86194 if (!ti)
86195 goto free_tsk;
86196
86197@@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86198 goto free_ti;
86199
86200 tsk->stack = ti;
86201+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86202+ tsk->lowmem_stack = lowmem_stack;
86203+#endif
86204
86205 setup_thread_stack(tsk, orig);
86206 clear_user_return_notifier(tsk);
86207@@ -323,7 +373,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86208 *stackend = STACK_END_MAGIC; /* for overflow detection */
86209
86210 #ifdef CONFIG_CC_STACKPROTECTOR
86211- tsk->stack_canary = get_random_int();
86212+ tsk->stack_canary = pax_get_random_long();
86213 #endif
86214
86215 /*
86216@@ -337,24 +387,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86217 tsk->splice_pipe = NULL;
86218 tsk->task_frag.page = NULL;
86219
86220- account_kernel_stack(ti, 1);
86221+ account_kernel_stack(tsk, ti, 1);
86222
86223 return tsk;
86224
86225 free_ti:
86226- free_thread_info(ti);
86227+ gr_free_thread_info(tsk, ti);
86228 free_tsk:
86229 free_task_struct(tsk);
86230 return NULL;
86231 }
86232
86233 #ifdef CONFIG_MMU
86234-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86235+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
86236+{
86237+ struct vm_area_struct *tmp;
86238+ unsigned long charge;
86239+ struct file *file;
86240+ int retval;
86241+
86242+ charge = 0;
86243+ if (mpnt->vm_flags & VM_ACCOUNT) {
86244+ unsigned long len = vma_pages(mpnt);
86245+
86246+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86247+ goto fail_nomem;
86248+ charge = len;
86249+ }
86250+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86251+ if (!tmp)
86252+ goto fail_nomem;
86253+ *tmp = *mpnt;
86254+ tmp->vm_mm = mm;
86255+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
86256+ retval = vma_dup_policy(mpnt, tmp);
86257+ if (retval)
86258+ goto fail_nomem_policy;
86259+ if (anon_vma_fork(tmp, mpnt))
86260+ goto fail_nomem_anon_vma_fork;
86261+ tmp->vm_flags &= ~VM_LOCKED;
86262+ tmp->vm_next = tmp->vm_prev = NULL;
86263+ tmp->vm_mirror = NULL;
86264+ file = tmp->vm_file;
86265+ if (file) {
86266+ struct inode *inode = file_inode(file);
86267+ struct address_space *mapping = file->f_mapping;
86268+
86269+ get_file(file);
86270+ if (tmp->vm_flags & VM_DENYWRITE)
86271+ atomic_dec(&inode->i_writecount);
86272+ mutex_lock(&mapping->i_mmap_mutex);
86273+ if (tmp->vm_flags & VM_SHARED)
86274+ mapping->i_mmap_writable++;
86275+ flush_dcache_mmap_lock(mapping);
86276+ /* insert tmp into the share list, just after mpnt */
86277+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86278+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
86279+ else
86280+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
86281+ flush_dcache_mmap_unlock(mapping);
86282+ mutex_unlock(&mapping->i_mmap_mutex);
86283+ }
86284+
86285+ /*
86286+ * Clear hugetlb-related page reserves for children. This only
86287+ * affects MAP_PRIVATE mappings. Faults generated by the child
86288+ * are not guaranteed to succeed, even if read-only
86289+ */
86290+ if (is_vm_hugetlb_page(tmp))
86291+ reset_vma_resv_huge_pages(tmp);
86292+
86293+ return tmp;
86294+
86295+fail_nomem_anon_vma_fork:
86296+ mpol_put(vma_policy(tmp));
86297+fail_nomem_policy:
86298+ kmem_cache_free(vm_area_cachep, tmp);
86299+fail_nomem:
86300+ vm_unacct_memory(charge);
86301+ return NULL;
86302+}
86303+
86304+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86305 {
86306 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86307 struct rb_node **rb_link, *rb_parent;
86308 int retval;
86309- unsigned long charge;
86310
86311 uprobe_start_dup_mmap();
86312 down_write(&oldmm->mmap_sem);
86313@@ -383,55 +501,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86314
86315 prev = NULL;
86316 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86317- struct file *file;
86318-
86319 if (mpnt->vm_flags & VM_DONTCOPY) {
86320 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86321 -vma_pages(mpnt));
86322 continue;
86323 }
86324- charge = 0;
86325- if (mpnt->vm_flags & VM_ACCOUNT) {
86326- unsigned long len = vma_pages(mpnt);
86327-
86328- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86329- goto fail_nomem;
86330- charge = len;
86331- }
86332- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86333- if (!tmp)
86334- goto fail_nomem;
86335- *tmp = *mpnt;
86336- INIT_LIST_HEAD(&tmp->anon_vma_chain);
86337- retval = vma_dup_policy(mpnt, tmp);
86338- if (retval)
86339- goto fail_nomem_policy;
86340- tmp->vm_mm = mm;
86341- if (anon_vma_fork(tmp, mpnt))
86342- goto fail_nomem_anon_vma_fork;
86343- tmp->vm_flags &= ~VM_LOCKED;
86344- tmp->vm_next = tmp->vm_prev = NULL;
86345- file = tmp->vm_file;
86346- if (file) {
86347- struct inode *inode = file_inode(file);
86348- struct address_space *mapping = file->f_mapping;
86349-
86350- get_file(file);
86351- if (tmp->vm_flags & VM_DENYWRITE)
86352- atomic_dec(&inode->i_writecount);
86353- mutex_lock(&mapping->i_mmap_mutex);
86354- if (tmp->vm_flags & VM_SHARED)
86355- mapping->i_mmap_writable++;
86356- flush_dcache_mmap_lock(mapping);
86357- /* insert tmp into the share list, just after mpnt */
86358- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86359- vma_nonlinear_insert(tmp,
86360- &mapping->i_mmap_nonlinear);
86361- else
86362- vma_interval_tree_insert_after(tmp, mpnt,
86363- &mapping->i_mmap);
86364- flush_dcache_mmap_unlock(mapping);
86365- mutex_unlock(&mapping->i_mmap_mutex);
86366+ tmp = dup_vma(mm, oldmm, mpnt);
86367+ if (!tmp) {
86368+ retval = -ENOMEM;
86369+ goto out;
86370 }
86371
86372 /*
86373@@ -463,6 +541,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86374 if (retval)
86375 goto out;
86376 }
86377+
86378+#ifdef CONFIG_PAX_SEGMEXEC
86379+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86380+ struct vm_area_struct *mpnt_m;
86381+
86382+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86383+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86384+
86385+ if (!mpnt->vm_mirror)
86386+ continue;
86387+
86388+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86389+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86390+ mpnt->vm_mirror = mpnt_m;
86391+ } else {
86392+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86393+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86394+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86395+ mpnt->vm_mirror->vm_mirror = mpnt;
86396+ }
86397+ }
86398+ BUG_ON(mpnt_m);
86399+ }
86400+#endif
86401+
86402 /* a new mm has just been created */
86403 arch_dup_mmap(oldmm, mm);
86404 retval = 0;
86405@@ -472,14 +575,6 @@ out:
86406 up_write(&oldmm->mmap_sem);
86407 uprobe_end_dup_mmap();
86408 return retval;
86409-fail_nomem_anon_vma_fork:
86410- mpol_put(vma_policy(tmp));
86411-fail_nomem_policy:
86412- kmem_cache_free(vm_area_cachep, tmp);
86413-fail_nomem:
86414- retval = -ENOMEM;
86415- vm_unacct_memory(charge);
86416- goto out;
86417 }
86418
86419 static inline int mm_alloc_pgd(struct mm_struct *mm)
86420@@ -698,8 +793,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86421 return ERR_PTR(err);
86422
86423 mm = get_task_mm(task);
86424- if (mm && mm != current->mm &&
86425- !ptrace_may_access(task, mode)) {
86426+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86427+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86428 mmput(mm);
86429 mm = ERR_PTR(-EACCES);
86430 }
86431@@ -918,13 +1013,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86432 spin_unlock(&fs->lock);
86433 return -EAGAIN;
86434 }
86435- fs->users++;
86436+ atomic_inc(&fs->users);
86437 spin_unlock(&fs->lock);
86438 return 0;
86439 }
86440 tsk->fs = copy_fs_struct(fs);
86441 if (!tsk->fs)
86442 return -ENOMEM;
86443+ /* Carry through gr_chroot_dentry and is_chrooted instead
86444+ of recomputing it here. Already copied when the task struct
86445+ is duplicated. This allows pivot_root to not be treated as
86446+ a chroot
86447+ */
86448+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
86449+
86450 return 0;
86451 }
86452
86453@@ -1133,7 +1235,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86454 * parts of the process environment (as per the clone
86455 * flags). The actual kick-off is left to the caller.
86456 */
86457-static struct task_struct *copy_process(unsigned long clone_flags,
86458+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86459 unsigned long stack_start,
86460 unsigned long stack_size,
86461 int __user *child_tidptr,
86462@@ -1205,6 +1307,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86463 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86464 #endif
86465 retval = -EAGAIN;
86466+
86467+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86468+
86469 if (atomic_read(&p->real_cred->user->processes) >=
86470 task_rlimit(p, RLIMIT_NPROC)) {
86471 if (p->real_cred->user != INIT_USER &&
86472@@ -1452,6 +1557,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86473 goto bad_fork_free_pid;
86474 }
86475
86476+ /* synchronizes with gr_set_acls()
86477+ we need to call this past the point of no return for fork()
86478+ */
86479+ gr_copy_label(p);
86480+
86481 if (likely(p->pid)) {
86482 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86483
86484@@ -1539,6 +1649,8 @@ bad_fork_cleanup_count:
86485 bad_fork_free:
86486 free_task(p);
86487 fork_out:
86488+ gr_log_forkfail(retval);
86489+
86490 return ERR_PTR(retval);
86491 }
86492
86493@@ -1600,6 +1712,7 @@ long do_fork(unsigned long clone_flags,
86494
86495 p = copy_process(clone_flags, stack_start, stack_size,
86496 child_tidptr, NULL, trace);
86497+ add_latent_entropy();
86498 /*
86499 * Do this prior waking up the new thread - the thread pointer
86500 * might get invalid after that point, if the thread exits quickly.
86501@@ -1614,6 +1727,8 @@ long do_fork(unsigned long clone_flags,
86502 if (clone_flags & CLONE_PARENT_SETTID)
86503 put_user(nr, parent_tidptr);
86504
86505+ gr_handle_brute_check();
86506+
86507 if (clone_flags & CLONE_VFORK) {
86508 p->vfork_done = &vfork;
86509 init_completion(&vfork);
86510@@ -1730,7 +1845,7 @@ void __init proc_caches_init(void)
86511 mm_cachep = kmem_cache_create("mm_struct",
86512 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
86513 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
86514- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
86515+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
86516 mmap_init();
86517 nsproxy_cache_init();
86518 }
86519@@ -1770,7 +1885,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
86520 return 0;
86521
86522 /* don't need lock here; in the worst case we'll do useless copy */
86523- if (fs->users == 1)
86524+ if (atomic_read(&fs->users) == 1)
86525 return 0;
86526
86527 *new_fsp = copy_fs_struct(fs);
86528@@ -1877,7 +1992,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
86529 fs = current->fs;
86530 spin_lock(&fs->lock);
86531 current->fs = new_fs;
86532- if (--fs->users)
86533+ gr_set_chroot_entries(current, &current->fs->root);
86534+ if (atomic_dec_return(&fs->users))
86535 new_fs = NULL;
86536 else
86537 new_fs = fs;
86538diff --git a/kernel/futex.c b/kernel/futex.c
86539index de938d2..c566038 100644
86540--- a/kernel/futex.c
86541+++ b/kernel/futex.c
86542@@ -202,7 +202,7 @@ struct futex_pi_state {
86543 atomic_t refcount;
86544
86545 union futex_key key;
86546-};
86547+} __randomize_layout;
86548
86549 /**
86550 * struct futex_q - The hashed futex queue entry, one per waiting task
86551@@ -236,7 +236,7 @@ struct futex_q {
86552 struct rt_mutex_waiter *rt_waiter;
86553 union futex_key *requeue_pi_key;
86554 u32 bitset;
86555-};
86556+} __randomize_layout;
86557
86558 static const struct futex_q futex_q_init = {
86559 /* list gets initialized in queue_me()*/
86560@@ -394,6 +394,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86561 struct page *page, *page_head;
86562 int err, ro = 0;
86563
86564+#ifdef CONFIG_PAX_SEGMEXEC
86565+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86566+ return -EFAULT;
86567+#endif
86568+
86569 /*
86570 * The futex address must be "naturally" aligned.
86571 */
86572@@ -593,7 +598,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
86573
86574 static int get_futex_value_locked(u32 *dest, u32 __user *from)
86575 {
86576- int ret;
86577+ unsigned long ret;
86578
86579 pagefault_disable();
86580 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
86581@@ -3033,6 +3038,7 @@ static void __init futex_detect_cmpxchg(void)
86582 {
86583 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
86584 u32 curval;
86585+ mm_segment_t oldfs;
86586
86587 /*
86588 * This will fail and we want it. Some arch implementations do
86589@@ -3044,8 +3050,11 @@ static void __init futex_detect_cmpxchg(void)
86590 * implementation, the non-functional ones will return
86591 * -ENOSYS.
86592 */
86593+ oldfs = get_fs();
86594+ set_fs(USER_DS);
86595 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
86596 futex_cmpxchg_enabled = 1;
86597+ set_fs(oldfs);
86598 #endif
86599 }
86600
86601diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
86602index 55c8c93..9ba7ad6 100644
86603--- a/kernel/futex_compat.c
86604+++ b/kernel/futex_compat.c
86605@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
86606 return 0;
86607 }
86608
86609-static void __user *futex_uaddr(struct robust_list __user *entry,
86610+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
86611 compat_long_t futex_offset)
86612 {
86613 compat_uptr_t base = ptr_to_compat(entry);
86614diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
86615index f45b75b..bfac6d5 100644
86616--- a/kernel/gcov/base.c
86617+++ b/kernel/gcov/base.c
86618@@ -108,11 +108,6 @@ void gcov_enable_events(void)
86619 }
86620
86621 #ifdef CONFIG_MODULES
86622-static inline int within(void *addr, void *start, unsigned long size)
86623-{
86624- return ((addr >= start) && (addr < start + size));
86625-}
86626-
86627 /* Update list and generate events when modules are unloaded. */
86628 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86629 void *data)
86630@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86631
86632 /* Remove entries located in module from linked list. */
86633 while ((info = gcov_info_next(info))) {
86634- if (within(info, mod->module_core, mod->core_size)) {
86635+ if (within_module_core_rw((unsigned long)info, mod)) {
86636 gcov_info_unlink(prev, info);
86637 if (gcov_events_enabled)
86638 gcov_event(GCOV_REMOVE, info);
86639diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
86640index e0501fe..312edd6 100644
86641--- a/kernel/hrtimer.c
86642+++ b/kernel/hrtimer.c
86643@@ -1448,7 +1448,7 @@ void hrtimer_peek_ahead_timers(void)
86644 local_irq_restore(flags);
86645 }
86646
86647-static void run_hrtimer_softirq(struct softirq_action *h)
86648+static __latent_entropy void run_hrtimer_softirq(void)
86649 {
86650 hrtimer_peek_ahead_timers();
86651 }
86652diff --git a/kernel/irq_work.c b/kernel/irq_work.c
86653index a82170e..5b01e7f 100644
86654--- a/kernel/irq_work.c
86655+++ b/kernel/irq_work.c
86656@@ -191,12 +191,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
86657 return NOTIFY_OK;
86658 }
86659
86660-static struct notifier_block cpu_notify;
86661+static struct notifier_block cpu_notify = {
86662+ .notifier_call = irq_work_cpu_notify,
86663+ .priority = 0,
86664+};
86665
86666 static __init int irq_work_init_cpu_notifier(void)
86667 {
86668- cpu_notify.notifier_call = irq_work_cpu_notify;
86669- cpu_notify.priority = 0;
86670 register_cpu_notifier(&cpu_notify);
86671 return 0;
86672 }
86673diff --git a/kernel/jump_label.c b/kernel/jump_label.c
86674index 9019f15..9a3c42e 100644
86675--- a/kernel/jump_label.c
86676+++ b/kernel/jump_label.c
86677@@ -14,6 +14,7 @@
86678 #include <linux/err.h>
86679 #include <linux/static_key.h>
86680 #include <linux/jump_label_ratelimit.h>
86681+#include <linux/mm.h>
86682
86683 #ifdef HAVE_JUMP_LABEL
86684
86685@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86686
86687 size = (((unsigned long)stop - (unsigned long)start)
86688 / sizeof(struct jump_entry));
86689+ pax_open_kernel();
86690 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86691+ pax_close_kernel();
86692 }
86693
86694 static void jump_label_update(struct static_key *key, int enable);
86695@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86696 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86697 struct jump_entry *iter;
86698
86699+ pax_open_kernel();
86700 for (iter = iter_start; iter < iter_stop; iter++) {
86701 if (within_module_init(iter->code, mod))
86702 iter->code = 0;
86703 }
86704+ pax_close_kernel();
86705 }
86706
86707 static int
86708diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
86709index cb0cf37..b69e161 100644
86710--- a/kernel/kallsyms.c
86711+++ b/kernel/kallsyms.c
86712@@ -11,6 +11,9 @@
86713 * Changed the compression method from stem compression to "table lookup"
86714 * compression (see scripts/kallsyms.c for a more complete description)
86715 */
86716+#ifdef CONFIG_GRKERNSEC_HIDESYM
86717+#define __INCLUDED_BY_HIDESYM 1
86718+#endif
86719 #include <linux/kallsyms.h>
86720 #include <linux/module.h>
86721 #include <linux/init.h>
86722@@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
86723
86724 static inline int is_kernel_inittext(unsigned long addr)
86725 {
86726+ if (system_state != SYSTEM_BOOTING)
86727+ return 0;
86728+
86729 if (addr >= (unsigned long)_sinittext
86730 && addr <= (unsigned long)_einittext)
86731 return 1;
86732 return 0;
86733 }
86734
86735+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86736+#ifdef CONFIG_MODULES
86737+static inline int is_module_text(unsigned long addr)
86738+{
86739+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
86740+ return 1;
86741+
86742+ addr = ktla_ktva(addr);
86743+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
86744+}
86745+#else
86746+static inline int is_module_text(unsigned long addr)
86747+{
86748+ return 0;
86749+}
86750+#endif
86751+#endif
86752+
86753 static inline int is_kernel_text(unsigned long addr)
86754 {
86755 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86756@@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
86757
86758 static inline int is_kernel(unsigned long addr)
86759 {
86760+
86761+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86762+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
86763+ return 1;
86764+
86765+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86766+#else
86767 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86768+#endif
86769+
86770 return 1;
86771 return in_gate_area_no_mm(addr);
86772 }
86773
86774 static int is_ksym_addr(unsigned long addr)
86775 {
86776+
86777+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86778+ if (is_module_text(addr))
86779+ return 0;
86780+#endif
86781+
86782 if (all_var)
86783 return is_kernel(addr);
86784
86785@@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86786
86787 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86788 {
86789- iter->name[0] = '\0';
86790 iter->nameoff = get_symbol_offset(new_pos);
86791 iter->pos = new_pos;
86792 }
86793@@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
86794 {
86795 struct kallsym_iter *iter = m->private;
86796
86797+#ifdef CONFIG_GRKERNSEC_HIDESYM
86798+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86799+ return 0;
86800+#endif
86801+
86802 /* Some debugging symbols have no name. Ignore them. */
86803 if (!iter->name[0])
86804 return 0;
86805@@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
86806 */
86807 type = iter->exported ? toupper(iter->type) :
86808 tolower(iter->type);
86809+
86810 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
86811 type, iter->name, iter->module_name);
86812 } else
86813@@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
86814 struct kallsym_iter *iter;
86815 int ret;
86816
86817- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86818+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86819 if (!iter)
86820 return -ENOMEM;
86821 reset_iter(iter, 0);
86822diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86823index e30ac0f..3528cac 100644
86824--- a/kernel/kcmp.c
86825+++ b/kernel/kcmp.c
86826@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86827 struct task_struct *task1, *task2;
86828 int ret;
86829
86830+#ifdef CONFIG_GRKERNSEC
86831+ return -ENOSYS;
86832+#endif
86833+
86834 rcu_read_lock();
86835
86836 /*
86837diff --git a/kernel/kexec.c b/kernel/kexec.c
86838index 28c5706..bfc8388 100644
86839--- a/kernel/kexec.c
86840+++ b/kernel/kexec.c
86841@@ -1046,7 +1046,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
86842 compat_ulong_t, flags)
86843 {
86844 struct compat_kexec_segment in;
86845- struct kexec_segment out, __user *ksegments;
86846+ struct kexec_segment out;
86847+ struct kexec_segment __user *ksegments;
86848 unsigned long i, result;
86849
86850 /* Don't allow clients that don't understand the native
86851diff --git a/kernel/kmod.c b/kernel/kmod.c
86852index 6b375af..eaff670 100644
86853--- a/kernel/kmod.c
86854+++ b/kernel/kmod.c
86855@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86856 kfree(info->argv);
86857 }
86858
86859-static int call_modprobe(char *module_name, int wait)
86860+static int call_modprobe(char *module_name, char *module_param, int wait)
86861 {
86862 struct subprocess_info *info;
86863 static char *envp[] = {
86864@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86865 NULL
86866 };
86867
86868- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86869+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86870 if (!argv)
86871 goto out;
86872
86873@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86874 argv[1] = "-q";
86875 argv[2] = "--";
86876 argv[3] = module_name; /* check free_modprobe_argv() */
86877- argv[4] = NULL;
86878+ argv[4] = module_param;
86879+ argv[5] = NULL;
86880
86881 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
86882 NULL, free_modprobe_argv, NULL);
86883@@ -129,9 +130,8 @@ out:
86884 * If module auto-loading support is disabled then this function
86885 * becomes a no-operation.
86886 */
86887-int __request_module(bool wait, const char *fmt, ...)
86888+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
86889 {
86890- va_list args;
86891 char module_name[MODULE_NAME_LEN];
86892 unsigned int max_modprobes;
86893 int ret;
86894@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
86895 if (!modprobe_path[0])
86896 return 0;
86897
86898- va_start(args, fmt);
86899- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
86900- va_end(args);
86901+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
86902 if (ret >= MODULE_NAME_LEN)
86903 return -ENAMETOOLONG;
86904
86905@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
86906 if (ret)
86907 return ret;
86908
86909+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86910+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86911+ /* hack to workaround consolekit/udisks stupidity */
86912+ read_lock(&tasklist_lock);
86913+ if (!strcmp(current->comm, "mount") &&
86914+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
86915+ read_unlock(&tasklist_lock);
86916+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
86917+ return -EPERM;
86918+ }
86919+ read_unlock(&tasklist_lock);
86920+ }
86921+#endif
86922+
86923 /* If modprobe needs a service that is in a module, we get a recursive
86924 * loop. Limit the number of running kmod threads to max_threads/2 or
86925 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
86926@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
86927
86928 trace_module_request(module_name, wait, _RET_IP_);
86929
86930- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86931+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86932
86933 atomic_dec(&kmod_concurrent);
86934 return ret;
86935 }
86936+
86937+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
86938+{
86939+ va_list args;
86940+ int ret;
86941+
86942+ va_start(args, fmt);
86943+ ret = ____request_module(wait, module_param, fmt, args);
86944+ va_end(args);
86945+
86946+ return ret;
86947+}
86948+
86949+int __request_module(bool wait, const char *fmt, ...)
86950+{
86951+ va_list args;
86952+ int ret;
86953+
86954+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86955+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86956+ char module_param[MODULE_NAME_LEN];
86957+
86958+ memset(module_param, 0, sizeof(module_param));
86959+
86960+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
86961+
86962+ va_start(args, fmt);
86963+ ret = ____request_module(wait, module_param, fmt, args);
86964+ va_end(args);
86965+
86966+ return ret;
86967+ }
86968+#endif
86969+
86970+ va_start(args, fmt);
86971+ ret = ____request_module(wait, NULL, fmt, args);
86972+ va_end(args);
86973+
86974+ return ret;
86975+}
86976+
86977 EXPORT_SYMBOL(__request_module);
86978 #endif /* CONFIG_MODULES */
86979
86980@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
86981 */
86982 set_user_nice(current, 0);
86983
86984+#ifdef CONFIG_GRKERNSEC
86985+ /* this is race-free as far as userland is concerned as we copied
86986+ out the path to be used prior to this point and are now operating
86987+ on that copy
86988+ */
86989+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
86990+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
86991+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
86992+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
86993+ retval = -EPERM;
86994+ goto fail;
86995+ }
86996+#endif
86997+
86998 retval = -ENOMEM;
86999 new = prepare_kernel_cred(current);
87000 if (!new)
87001@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87002 commit_creds(new);
87003
87004 retval = do_execve(getname_kernel(sub_info->path),
87005- (const char __user *const __user *)sub_info->argv,
87006- (const char __user *const __user *)sub_info->envp);
87007+ (const char __user *const __force_user *)sub_info->argv,
87008+ (const char __user *const __force_user *)sub_info->envp);
87009 if (!retval)
87010 return 0;
87011
87012@@ -260,6 +327,10 @@ static int call_helper(void *data)
87013
87014 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87015 {
87016+#ifdef CONFIG_GRKERNSEC
87017+ kfree(info->path);
87018+ info->path = info->origpath;
87019+#endif
87020 if (info->cleanup)
87021 (*info->cleanup)(info);
87022 kfree(info);
87023@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87024 *
87025 * Thus the __user pointer cast is valid here.
87026 */
87027- sys_wait4(pid, (int __user *)&ret, 0, NULL);
87028+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87029
87030 /*
87031 * If ret is 0, either ____call_usermodehelper failed and the
87032@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87033 goto out;
87034
87035 INIT_WORK(&sub_info->work, __call_usermodehelper);
87036+#ifdef CONFIG_GRKERNSEC
87037+ sub_info->origpath = path;
87038+ sub_info->path = kstrdup(path, gfp_mask);
87039+#else
87040 sub_info->path = path;
87041+#endif
87042 sub_info->argv = argv;
87043 sub_info->envp = envp;
87044
87045@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87046 static int proc_cap_handler(struct ctl_table *table, int write,
87047 void __user *buffer, size_t *lenp, loff_t *ppos)
87048 {
87049- struct ctl_table t;
87050+ ctl_table_no_const t;
87051 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87052 kernel_cap_t new_cap;
87053 int err, i;
87054diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87055index ceeadfc..11c18b6 100644
87056--- a/kernel/kprobes.c
87057+++ b/kernel/kprobes.c
87058@@ -31,6 +31,9 @@
87059 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87060 * <prasanna@in.ibm.com> added function-return probes.
87061 */
87062+#ifdef CONFIG_GRKERNSEC_HIDESYM
87063+#define __INCLUDED_BY_HIDESYM 1
87064+#endif
87065 #include <linux/kprobes.h>
87066 #include <linux/hash.h>
87067 #include <linux/init.h>
87068@@ -135,12 +138,12 @@ enum kprobe_slot_state {
87069
87070 static void *alloc_insn_page(void)
87071 {
87072- return module_alloc(PAGE_SIZE);
87073+ return module_alloc_exec(PAGE_SIZE);
87074 }
87075
87076 static void free_insn_page(void *page)
87077 {
87078- module_free(NULL, page);
87079+ module_free_exec(NULL, page);
87080 }
87081
87082 struct kprobe_insn_cache kprobe_insn_slots = {
87083@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87084 kprobe_type = "k";
87085
87086 if (sym)
87087- seq_printf(pi, "%p %s %s+0x%x %s ",
87088+ seq_printf(pi, "%pK %s %s+0x%x %s ",
87089 p->addr, kprobe_type, sym, offset,
87090 (modname ? modname : " "));
87091 else
87092- seq_printf(pi, "%p %s %p ",
87093+ seq_printf(pi, "%pK %s %pK ",
87094 p->addr, kprobe_type, p->addr);
87095
87096 if (!pp)
87097diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87098index 2495a9b..071b906 100644
87099--- a/kernel/ksysfs.c
87100+++ b/kernel/ksysfs.c
87101@@ -49,6 +49,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87102 {
87103 if (count+1 > UEVENT_HELPER_PATH_LEN)
87104 return -ENOENT;
87105+ if (!capable(CAP_SYS_ADMIN))
87106+ return -EPERM;
87107 memcpy(uevent_helper, buf, count);
87108 uevent_helper[count] = '\0';
87109 if (count && uevent_helper[count-1] == '\n')
87110@@ -175,7 +177,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87111 return count;
87112 }
87113
87114-static struct bin_attribute notes_attr = {
87115+static bin_attribute_no_const notes_attr __read_only = {
87116 .attr = {
87117 .name = "notes",
87118 .mode = S_IRUGO,
87119diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87120index d24e433..fa04fb8 100644
87121--- a/kernel/locking/lockdep.c
87122+++ b/kernel/locking/lockdep.c
87123@@ -597,6 +597,10 @@ static int static_obj(void *obj)
87124 end = (unsigned long) &_end,
87125 addr = (unsigned long) obj;
87126
87127+#ifdef CONFIG_PAX_KERNEXEC
87128+ start = ktla_ktva(start);
87129+#endif
87130+
87131 /*
87132 * static variable?
87133 */
87134@@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87135 if (!static_obj(lock->key)) {
87136 debug_locks_off();
87137 printk("INFO: trying to register non-static key.\n");
87138+ printk("lock:%pS key:%pS.\n", lock, lock->key);
87139 printk("the code is fine but needs lockdep annotation.\n");
87140 printk("turning off the locking correctness validator.\n");
87141 dump_stack();
87142@@ -3079,7 +3084,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87143 if (!class)
87144 return 0;
87145 }
87146- atomic_inc((atomic_t *)&class->ops);
87147+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87148 if (very_verbose(class)) {
87149 printk("\nacquire class [%p] %s", class->key, class->name);
87150 if (class->name_version > 1)
87151diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87152index ef43ac4..2720dfa 100644
87153--- a/kernel/locking/lockdep_proc.c
87154+++ b/kernel/locking/lockdep_proc.c
87155@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87156 return 0;
87157 }
87158
87159- seq_printf(m, "%p", class->key);
87160+ seq_printf(m, "%pK", class->key);
87161 #ifdef CONFIG_DEBUG_LOCKDEP
87162 seq_printf(m, " OPS:%8ld", class->ops);
87163 #endif
87164@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87165
87166 list_for_each_entry(entry, &class->locks_after, entry) {
87167 if (entry->distance == 1) {
87168- seq_printf(m, " -> [%p] ", entry->class->key);
87169+ seq_printf(m, " -> [%pK] ", entry->class->key);
87170 print_name(m, entry->class);
87171 seq_puts(m, "\n");
87172 }
87173@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87174 if (!class->key)
87175 continue;
87176
87177- seq_printf(m, "[%p] ", class->key);
87178+ seq_printf(m, "[%pK] ", class->key);
87179 print_name(m, class);
87180 seq_puts(m, "\n");
87181 }
87182@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87183 if (!i)
87184 seq_line(m, '-', 40-namelen, namelen);
87185
87186- snprintf(ip, sizeof(ip), "[<%p>]",
87187+ snprintf(ip, sizeof(ip), "[<%pK>]",
87188 (void *)class->contention_point[i]);
87189 seq_printf(m, "%40s %14lu %29s %pS\n",
87190 name, stats->contention_point[i],
87191@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87192 if (!i)
87193 seq_line(m, '-', 40-namelen, namelen);
87194
87195- snprintf(ip, sizeof(ip), "[<%p>]",
87196+ snprintf(ip, sizeof(ip), "[<%pK>]",
87197 (void *)class->contending_point[i]);
87198 seq_printf(m, "%40s %14lu %29s %pS\n",
87199 name, stats->contending_point[i],
87200diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
87201index 838dc9e..760e158 100644
87202--- a/kernel/locking/mcs_spinlock.c
87203+++ b/kernel/locking/mcs_spinlock.c
87204@@ -71,7 +71,7 @@ bool osq_lock(struct optimistic_spin_queue **lock)
87205 if (likely(prev == NULL))
87206 return true;
87207
87208- ACCESS_ONCE(prev->next) = node;
87209+ ACCESS_ONCE_RW(prev->next) = node;
87210
87211 /*
87212 * Normally @prev is untouchable after the above store; because at that
87213@@ -143,8 +143,8 @@ unqueue:
87214 * it will wait in Step-A.
87215 */
87216
87217- ACCESS_ONCE(next->prev) = prev;
87218- ACCESS_ONCE(prev->next) = next;
87219+ ACCESS_ONCE_RW(next->prev) = prev;
87220+ ACCESS_ONCE_RW(prev->next) = next;
87221
87222 return false;
87223 }
87224@@ -165,13 +165,13 @@ void osq_unlock(struct optimistic_spin_queue **lock)
87225 */
87226 next = xchg(&node->next, NULL);
87227 if (next) {
87228- ACCESS_ONCE(next->locked) = 1;
87229+ ACCESS_ONCE_RW(next->locked) = 1;
87230 return;
87231 }
87232
87233 next = osq_wait_next(lock, node, NULL);
87234 if (next)
87235- ACCESS_ONCE(next->locked) = 1;
87236+ ACCESS_ONCE_RW(next->locked) = 1;
87237 }
87238
87239 #endif
87240diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
87241index a2dbac4..e02a34a 100644
87242--- a/kernel/locking/mcs_spinlock.h
87243+++ b/kernel/locking/mcs_spinlock.h
87244@@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
87245 */
87246 return;
87247 }
87248- ACCESS_ONCE(prev->next) = node;
87249+ ACCESS_ONCE_RW(prev->next) = node;
87250
87251 /* Wait until the lock holder passes the lock down. */
87252 arch_mcs_spin_lock_contended(&node->locked);
87253diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
87254index 5cf6731..ce3bc5a 100644
87255--- a/kernel/locking/mutex-debug.c
87256+++ b/kernel/locking/mutex-debug.c
87257@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
87258 }
87259
87260 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87261- struct thread_info *ti)
87262+ struct task_struct *task)
87263 {
87264 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
87265
87266 /* Mark the current thread as blocked on the lock: */
87267- ti->task->blocked_on = waiter;
87268+ task->blocked_on = waiter;
87269 }
87270
87271 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87272- struct thread_info *ti)
87273+ struct task_struct *task)
87274 {
87275 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
87276- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
87277- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
87278- ti->task->blocked_on = NULL;
87279+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
87280+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
87281+ task->blocked_on = NULL;
87282
87283 list_del_init(&waiter->list);
87284 waiter->task = NULL;
87285diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
87286index 0799fd3..d06ae3b 100644
87287--- a/kernel/locking/mutex-debug.h
87288+++ b/kernel/locking/mutex-debug.h
87289@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
87290 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
87291 extern void debug_mutex_add_waiter(struct mutex *lock,
87292 struct mutex_waiter *waiter,
87293- struct thread_info *ti);
87294+ struct task_struct *task);
87295 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87296- struct thread_info *ti);
87297+ struct task_struct *task);
87298 extern void debug_mutex_unlock(struct mutex *lock);
87299 extern void debug_mutex_init(struct mutex *lock, const char *name,
87300 struct lock_class_key *key);
87301diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
87302index bc73d33..6f308aa 100644
87303--- a/kernel/locking/mutex.c
87304+++ b/kernel/locking/mutex.c
87305@@ -490,7 +490,7 @@ slowpath:
87306 goto skip_wait;
87307
87308 debug_mutex_lock_common(lock, &waiter);
87309- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
87310+ debug_mutex_add_waiter(lock, &waiter, task);
87311
87312 /* add waiting tasks to the end of the waitqueue (FIFO): */
87313 list_add_tail(&waiter.list, &lock->wait_list);
87314@@ -534,7 +534,7 @@ slowpath:
87315 schedule_preempt_disabled();
87316 spin_lock_mutex(&lock->wait_lock, flags);
87317 }
87318- mutex_remove_waiter(lock, &waiter, current_thread_info());
87319+ mutex_remove_waiter(lock, &waiter, task);
87320 /* set it to 0 if there are no waiters left: */
87321 if (likely(list_empty(&lock->wait_list)))
87322 atomic_set(&lock->count, 0);
87323@@ -571,7 +571,7 @@ skip_wait:
87324 return 0;
87325
87326 err:
87327- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87328+ mutex_remove_waiter(lock, &waiter, task);
87329 spin_unlock_mutex(&lock->wait_lock, flags);
87330 debug_mutex_free_waiter(&waiter);
87331 mutex_release(&lock->dep_map, 1, ip);
87332diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87333index 1d96dd0..994ff19 100644
87334--- a/kernel/locking/rtmutex-tester.c
87335+++ b/kernel/locking/rtmutex-tester.c
87336@@ -22,7 +22,7 @@
87337 #define MAX_RT_TEST_MUTEXES 8
87338
87339 static spinlock_t rttest_lock;
87340-static atomic_t rttest_event;
87341+static atomic_unchecked_t rttest_event;
87342
87343 struct test_thread_data {
87344 int opcode;
87345@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87346
87347 case RTTEST_LOCKCONT:
87348 td->mutexes[td->opdata] = 1;
87349- td->event = atomic_add_return(1, &rttest_event);
87350+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87351 return 0;
87352
87353 case RTTEST_RESET:
87354@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87355 return 0;
87356
87357 case RTTEST_RESETEVENT:
87358- atomic_set(&rttest_event, 0);
87359+ atomic_set_unchecked(&rttest_event, 0);
87360 return 0;
87361
87362 default:
87363@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87364 return ret;
87365
87366 td->mutexes[id] = 1;
87367- td->event = atomic_add_return(1, &rttest_event);
87368+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87369 rt_mutex_lock(&mutexes[id]);
87370- td->event = atomic_add_return(1, &rttest_event);
87371+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87372 td->mutexes[id] = 4;
87373 return 0;
87374
87375@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87376 return ret;
87377
87378 td->mutexes[id] = 1;
87379- td->event = atomic_add_return(1, &rttest_event);
87380+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87381 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87382- td->event = atomic_add_return(1, &rttest_event);
87383+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87384 td->mutexes[id] = ret ? 0 : 4;
87385 return ret ? -EINTR : 0;
87386
87387@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87388 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87389 return ret;
87390
87391- td->event = atomic_add_return(1, &rttest_event);
87392+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87393 rt_mutex_unlock(&mutexes[id]);
87394- td->event = atomic_add_return(1, &rttest_event);
87395+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87396 td->mutexes[id] = 0;
87397 return 0;
87398
87399@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87400 break;
87401
87402 td->mutexes[dat] = 2;
87403- td->event = atomic_add_return(1, &rttest_event);
87404+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87405 break;
87406
87407 default:
87408@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87409 return;
87410
87411 td->mutexes[dat] = 3;
87412- td->event = atomic_add_return(1, &rttest_event);
87413+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87414 break;
87415
87416 case RTTEST_LOCKNOWAIT:
87417@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87418 return;
87419
87420 td->mutexes[dat] = 1;
87421- td->event = atomic_add_return(1, &rttest_event);
87422+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87423 return;
87424
87425 default:
87426diff --git a/kernel/module.c b/kernel/module.c
87427index 079c461..741f79c 100644
87428--- a/kernel/module.c
87429+++ b/kernel/module.c
87430@@ -61,6 +61,7 @@
87431 #include <linux/pfn.h>
87432 #include <linux/bsearch.h>
87433 #include <linux/fips.h>
87434+#include <linux/grsecurity.h>
87435 #include <uapi/linux/module.h>
87436 #include "module-internal.h"
87437
87438@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87439
87440 /* Bounds of module allocation, for speeding __module_address.
87441 * Protected by module_mutex. */
87442-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87443+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87444+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87445
87446 int register_module_notifier(struct notifier_block * nb)
87447 {
87448@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87449 return true;
87450
87451 list_for_each_entry_rcu(mod, &modules, list) {
87452- struct symsearch arr[] = {
87453+ struct symsearch modarr[] = {
87454 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87455 NOT_GPL_ONLY, false },
87456 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87457@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87458 if (mod->state == MODULE_STATE_UNFORMED)
87459 continue;
87460
87461- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87462+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87463 return true;
87464 }
87465 return false;
87466@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87467 if (!pcpusec->sh_size)
87468 return 0;
87469
87470- if (align > PAGE_SIZE) {
87471+ if (align-1 >= PAGE_SIZE) {
87472 pr_warn("%s: per-cpu alignment %li > %li\n",
87473 mod->name, align, PAGE_SIZE);
87474 align = PAGE_SIZE;
87475@@ -1061,7 +1063,7 @@ struct module_attribute module_uevent =
87476 static ssize_t show_coresize(struct module_attribute *mattr,
87477 struct module_kobject *mk, char *buffer)
87478 {
87479- return sprintf(buffer, "%u\n", mk->mod->core_size);
87480+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87481 }
87482
87483 static struct module_attribute modinfo_coresize =
87484@@ -1070,7 +1072,7 @@ static struct module_attribute modinfo_coresize =
87485 static ssize_t show_initsize(struct module_attribute *mattr,
87486 struct module_kobject *mk, char *buffer)
87487 {
87488- return sprintf(buffer, "%u\n", mk->mod->init_size);
87489+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87490 }
87491
87492 static struct module_attribute modinfo_initsize =
87493@@ -1162,12 +1164,29 @@ static int check_version(Elf_Shdr *sechdrs,
87494 goto bad_version;
87495 }
87496
87497+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87498+ /*
87499+ * avoid potentially printing jibberish on attempted load
87500+ * of a module randomized with a different seed
87501+ */
87502+ pr_warn("no symbol version for %s\n", symname);
87503+#else
87504 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
87505+#endif
87506 return 0;
87507
87508 bad_version:
87509+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87510+ /*
87511+ * avoid potentially printing jibberish on attempted load
87512+ * of a module randomized with a different seed
87513+ */
87514+ printk("attempted module disagrees about version of symbol %s\n",
87515+ symname);
87516+#else
87517 printk("%s: disagrees about version of symbol %s\n",
87518 mod->name, symname);
87519+#endif
87520 return 0;
87521 }
87522
87523@@ -1283,7 +1302,7 @@ resolve_symbol_wait(struct module *mod,
87524 */
87525 #ifdef CONFIG_SYSFS
87526
87527-#ifdef CONFIG_KALLSYMS
87528+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
87529 static inline bool sect_empty(const Elf_Shdr *sect)
87530 {
87531 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
87532@@ -1423,7 +1442,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
87533 {
87534 unsigned int notes, loaded, i;
87535 struct module_notes_attrs *notes_attrs;
87536- struct bin_attribute *nattr;
87537+ bin_attribute_no_const *nattr;
87538
87539 /* failed to create section attributes, so can't create notes */
87540 if (!mod->sect_attrs)
87541@@ -1535,7 +1554,7 @@ static void del_usage_links(struct module *mod)
87542 static int module_add_modinfo_attrs(struct module *mod)
87543 {
87544 struct module_attribute *attr;
87545- struct module_attribute *temp_attr;
87546+ module_attribute_no_const *temp_attr;
87547 int error = 0;
87548 int i;
87549
87550@@ -1756,21 +1775,21 @@ static void set_section_ro_nx(void *base,
87551
87552 static void unset_module_core_ro_nx(struct module *mod)
87553 {
87554- set_page_attributes(mod->module_core + mod->core_text_size,
87555- mod->module_core + mod->core_size,
87556+ set_page_attributes(mod->module_core_rw,
87557+ mod->module_core_rw + mod->core_size_rw,
87558 set_memory_x);
87559- set_page_attributes(mod->module_core,
87560- mod->module_core + mod->core_ro_size,
87561+ set_page_attributes(mod->module_core_rx,
87562+ mod->module_core_rx + mod->core_size_rx,
87563 set_memory_rw);
87564 }
87565
87566 static void unset_module_init_ro_nx(struct module *mod)
87567 {
87568- set_page_attributes(mod->module_init + mod->init_text_size,
87569- mod->module_init + mod->init_size,
87570+ set_page_attributes(mod->module_init_rw,
87571+ mod->module_init_rw + mod->init_size_rw,
87572 set_memory_x);
87573- set_page_attributes(mod->module_init,
87574- mod->module_init + mod->init_ro_size,
87575+ set_page_attributes(mod->module_init_rx,
87576+ mod->module_init_rx + mod->init_size_rx,
87577 set_memory_rw);
87578 }
87579
87580@@ -1783,14 +1802,14 @@ void set_all_modules_text_rw(void)
87581 list_for_each_entry_rcu(mod, &modules, list) {
87582 if (mod->state == MODULE_STATE_UNFORMED)
87583 continue;
87584- if ((mod->module_core) && (mod->core_text_size)) {
87585- set_page_attributes(mod->module_core,
87586- mod->module_core + mod->core_text_size,
87587+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87588+ set_page_attributes(mod->module_core_rx,
87589+ mod->module_core_rx + mod->core_size_rx,
87590 set_memory_rw);
87591 }
87592- if ((mod->module_init) && (mod->init_text_size)) {
87593- set_page_attributes(mod->module_init,
87594- mod->module_init + mod->init_text_size,
87595+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87596+ set_page_attributes(mod->module_init_rx,
87597+ mod->module_init_rx + mod->init_size_rx,
87598 set_memory_rw);
87599 }
87600 }
87601@@ -1806,14 +1825,14 @@ void set_all_modules_text_ro(void)
87602 list_for_each_entry_rcu(mod, &modules, list) {
87603 if (mod->state == MODULE_STATE_UNFORMED)
87604 continue;
87605- if ((mod->module_core) && (mod->core_text_size)) {
87606- set_page_attributes(mod->module_core,
87607- mod->module_core + mod->core_text_size,
87608+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87609+ set_page_attributes(mod->module_core_rx,
87610+ mod->module_core_rx + mod->core_size_rx,
87611 set_memory_ro);
87612 }
87613- if ((mod->module_init) && (mod->init_text_size)) {
87614- set_page_attributes(mod->module_init,
87615- mod->module_init + mod->init_text_size,
87616+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87617+ set_page_attributes(mod->module_init_rx,
87618+ mod->module_init_rx + mod->init_size_rx,
87619 set_memory_ro);
87620 }
87621 }
87622@@ -1864,16 +1883,19 @@ static void free_module(struct module *mod)
87623
87624 /* This may be NULL, but that's OK */
87625 unset_module_init_ro_nx(mod);
87626- module_free(mod, mod->module_init);
87627+ module_free(mod, mod->module_init_rw);
87628+ module_free_exec(mod, mod->module_init_rx);
87629 kfree(mod->args);
87630 percpu_modfree(mod);
87631
87632 /* Free lock-classes: */
87633- lockdep_free_key_range(mod->module_core, mod->core_size);
87634+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
87635+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
87636
87637 /* Finally, free the core (containing the module structure) */
87638 unset_module_core_ro_nx(mod);
87639- module_free(mod, mod->module_core);
87640+ module_free_exec(mod, mod->module_core_rx);
87641+ module_free(mod, mod->module_core_rw);
87642
87643 #ifdef CONFIG_MPU
87644 update_protections(current->mm);
87645@@ -1942,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87646 int ret = 0;
87647 const struct kernel_symbol *ksym;
87648
87649+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87650+ int is_fs_load = 0;
87651+ int register_filesystem_found = 0;
87652+ char *p;
87653+
87654+ p = strstr(mod->args, "grsec_modharden_fs");
87655+ if (p) {
87656+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
87657+ /* copy \0 as well */
87658+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
87659+ is_fs_load = 1;
87660+ }
87661+#endif
87662+
87663 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
87664 const char *name = info->strtab + sym[i].st_name;
87665
87666+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87667+ /* it's a real shame this will never get ripped and copied
87668+ upstream! ;(
87669+ */
87670+ if (is_fs_load && !strcmp(name, "register_filesystem"))
87671+ register_filesystem_found = 1;
87672+#endif
87673+
87674 switch (sym[i].st_shndx) {
87675 case SHN_COMMON:
87676 /* Ignore common symbols */
87677@@ -1969,7 +2013,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87678 ksym = resolve_symbol_wait(mod, info, name);
87679 /* Ok if resolved. */
87680 if (ksym && !IS_ERR(ksym)) {
87681+ pax_open_kernel();
87682 sym[i].st_value = ksym->value;
87683+ pax_close_kernel();
87684 break;
87685 }
87686
87687@@ -1988,11 +2034,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87688 secbase = (unsigned long)mod_percpu(mod);
87689 else
87690 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
87691+ pax_open_kernel();
87692 sym[i].st_value += secbase;
87693+ pax_close_kernel();
87694 break;
87695 }
87696 }
87697
87698+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87699+ if (is_fs_load && !register_filesystem_found) {
87700+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
87701+ ret = -EPERM;
87702+ }
87703+#endif
87704+
87705 return ret;
87706 }
87707
87708@@ -2076,22 +2131,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
87709 || s->sh_entsize != ~0UL
87710 || strstarts(sname, ".init"))
87711 continue;
87712- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
87713+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87714+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
87715+ else
87716+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87717 pr_debug("\t%s\n", sname);
87718 }
87719- switch (m) {
87720- case 0: /* executable */
87721- mod->core_size = debug_align(mod->core_size);
87722- mod->core_text_size = mod->core_size;
87723- break;
87724- case 1: /* RO: text and ro-data */
87725- mod->core_size = debug_align(mod->core_size);
87726- mod->core_ro_size = mod->core_size;
87727- break;
87728- case 3: /* whole core */
87729- mod->core_size = debug_align(mod->core_size);
87730- break;
87731- }
87732 }
87733
87734 pr_debug("Init section allocation order:\n");
87735@@ -2105,23 +2150,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
87736 || s->sh_entsize != ~0UL
87737 || !strstarts(sname, ".init"))
87738 continue;
87739- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
87740- | INIT_OFFSET_MASK);
87741+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87742+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
87743+ else
87744+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
87745+ s->sh_entsize |= INIT_OFFSET_MASK;
87746 pr_debug("\t%s\n", sname);
87747 }
87748- switch (m) {
87749- case 0: /* executable */
87750- mod->init_size = debug_align(mod->init_size);
87751- mod->init_text_size = mod->init_size;
87752- break;
87753- case 1: /* RO: text and ro-data */
87754- mod->init_size = debug_align(mod->init_size);
87755- mod->init_ro_size = mod->init_size;
87756- break;
87757- case 3: /* whole init */
87758- mod->init_size = debug_align(mod->init_size);
87759- break;
87760- }
87761 }
87762 }
87763
87764@@ -2294,7 +2329,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87765
87766 /* Put symbol section at end of init part of module. */
87767 symsect->sh_flags |= SHF_ALLOC;
87768- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
87769+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
87770 info->index.sym) | INIT_OFFSET_MASK;
87771 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
87772
87773@@ -2311,13 +2346,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87774 }
87775
87776 /* Append room for core symbols at end of core part. */
87777- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
87778- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
87779- mod->core_size += strtab_size;
87780+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
87781+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
87782+ mod->core_size_rx += strtab_size;
87783
87784 /* Put string table section at end of init part of module. */
87785 strsect->sh_flags |= SHF_ALLOC;
87786- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87787+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87788 info->index.str) | INIT_OFFSET_MASK;
87789 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87790 }
87791@@ -2335,12 +2370,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87792 /* Make sure we get permanent strtab: don't use info->strtab. */
87793 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87794
87795+ pax_open_kernel();
87796+
87797 /* Set types up while we still have access to sections. */
87798 for (i = 0; i < mod->num_symtab; i++)
87799 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87800
87801- mod->core_symtab = dst = mod->module_core + info->symoffs;
87802- mod->core_strtab = s = mod->module_core + info->stroffs;
87803+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87804+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87805 src = mod->symtab;
87806 for (ndst = i = 0; i < mod->num_symtab; i++) {
87807 if (i == 0 ||
87808@@ -2352,6 +2389,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87809 }
87810 }
87811 mod->core_num_syms = ndst;
87812+
87813+ pax_close_kernel();
87814 }
87815 #else
87816 static inline void layout_symtab(struct module *mod, struct load_info *info)
87817@@ -2385,17 +2424,33 @@ void * __weak module_alloc(unsigned long size)
87818 return vmalloc_exec(size);
87819 }
87820
87821-static void *module_alloc_update_bounds(unsigned long size)
87822+static void *module_alloc_update_bounds_rw(unsigned long size)
87823 {
87824 void *ret = module_alloc(size);
87825
87826 if (ret) {
87827 mutex_lock(&module_mutex);
87828 /* Update module bounds. */
87829- if ((unsigned long)ret < module_addr_min)
87830- module_addr_min = (unsigned long)ret;
87831- if ((unsigned long)ret + size > module_addr_max)
87832- module_addr_max = (unsigned long)ret + size;
87833+ if ((unsigned long)ret < module_addr_min_rw)
87834+ module_addr_min_rw = (unsigned long)ret;
87835+ if ((unsigned long)ret + size > module_addr_max_rw)
87836+ module_addr_max_rw = (unsigned long)ret + size;
87837+ mutex_unlock(&module_mutex);
87838+ }
87839+ return ret;
87840+}
87841+
87842+static void *module_alloc_update_bounds_rx(unsigned long size)
87843+{
87844+ void *ret = module_alloc_exec(size);
87845+
87846+ if (ret) {
87847+ mutex_lock(&module_mutex);
87848+ /* Update module bounds. */
87849+ if ((unsigned long)ret < module_addr_min_rx)
87850+ module_addr_min_rx = (unsigned long)ret;
87851+ if ((unsigned long)ret + size > module_addr_max_rx)
87852+ module_addr_max_rx = (unsigned long)ret + size;
87853 mutex_unlock(&module_mutex);
87854 }
87855 return ret;
87856@@ -2652,7 +2707,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87857 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87858
87859 if (info->index.sym == 0) {
87860+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87861+ /*
87862+ * avoid potentially printing jibberish on attempted load
87863+ * of a module randomized with a different seed
87864+ */
87865+ pr_warn("module has no symbols (stripped?)\n");
87866+#else
87867 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87868+#endif
87869 return ERR_PTR(-ENOEXEC);
87870 }
87871
87872@@ -2668,8 +2731,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87873 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87874 {
87875 const char *modmagic = get_modinfo(info, "vermagic");
87876+ const char *license = get_modinfo(info, "license");
87877 int err;
87878
87879+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
87880+ if (!license || !license_is_gpl_compatible(license))
87881+ return -ENOEXEC;
87882+#endif
87883+
87884 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
87885 modmagic = NULL;
87886
87887@@ -2694,7 +2763,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87888 }
87889
87890 /* Set up license info based on the info section */
87891- set_license(mod, get_modinfo(info, "license"));
87892+ set_license(mod, license);
87893
87894 return 0;
87895 }
87896@@ -2788,7 +2857,7 @@ static int move_module(struct module *mod, struct load_info *info)
87897 void *ptr;
87898
87899 /* Do the allocs. */
87900- ptr = module_alloc_update_bounds(mod->core_size);
87901+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87902 /*
87903 * The pointer to this block is stored in the module structure
87904 * which is inside the block. Just mark it as not being a
87905@@ -2798,11 +2867,11 @@ static int move_module(struct module *mod, struct load_info *info)
87906 if (!ptr)
87907 return -ENOMEM;
87908
87909- memset(ptr, 0, mod->core_size);
87910- mod->module_core = ptr;
87911+ memset(ptr, 0, mod->core_size_rw);
87912+ mod->module_core_rw = ptr;
87913
87914- if (mod->init_size) {
87915- ptr = module_alloc_update_bounds(mod->init_size);
87916+ if (mod->init_size_rw) {
87917+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
87918 /*
87919 * The pointer to this block is stored in the module structure
87920 * which is inside the block. This block doesn't need to be
87921@@ -2811,13 +2880,45 @@ static int move_module(struct module *mod, struct load_info *info)
87922 */
87923 kmemleak_ignore(ptr);
87924 if (!ptr) {
87925- module_free(mod, mod->module_core);
87926+ module_free(mod, mod->module_core_rw);
87927 return -ENOMEM;
87928 }
87929- memset(ptr, 0, mod->init_size);
87930- mod->module_init = ptr;
87931+ memset(ptr, 0, mod->init_size_rw);
87932+ mod->module_init_rw = ptr;
87933 } else
87934- mod->module_init = NULL;
87935+ mod->module_init_rw = NULL;
87936+
87937+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
87938+ kmemleak_not_leak(ptr);
87939+ if (!ptr) {
87940+ if (mod->module_init_rw)
87941+ module_free(mod, mod->module_init_rw);
87942+ module_free(mod, mod->module_core_rw);
87943+ return -ENOMEM;
87944+ }
87945+
87946+ pax_open_kernel();
87947+ memset(ptr, 0, mod->core_size_rx);
87948+ pax_close_kernel();
87949+ mod->module_core_rx = ptr;
87950+
87951+ if (mod->init_size_rx) {
87952+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
87953+ kmemleak_ignore(ptr);
87954+ if (!ptr && mod->init_size_rx) {
87955+ module_free_exec(mod, mod->module_core_rx);
87956+ if (mod->module_init_rw)
87957+ module_free(mod, mod->module_init_rw);
87958+ module_free(mod, mod->module_core_rw);
87959+ return -ENOMEM;
87960+ }
87961+
87962+ pax_open_kernel();
87963+ memset(ptr, 0, mod->init_size_rx);
87964+ pax_close_kernel();
87965+ mod->module_init_rx = ptr;
87966+ } else
87967+ mod->module_init_rx = NULL;
87968
87969 /* Transfer each section which specifies SHF_ALLOC */
87970 pr_debug("final section addresses:\n");
87971@@ -2828,16 +2929,45 @@ static int move_module(struct module *mod, struct load_info *info)
87972 if (!(shdr->sh_flags & SHF_ALLOC))
87973 continue;
87974
87975- if (shdr->sh_entsize & INIT_OFFSET_MASK)
87976- dest = mod->module_init
87977- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87978- else
87979- dest = mod->module_core + shdr->sh_entsize;
87980+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
87981+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87982+ dest = mod->module_init_rw
87983+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87984+ else
87985+ dest = mod->module_init_rx
87986+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87987+ } else {
87988+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87989+ dest = mod->module_core_rw + shdr->sh_entsize;
87990+ else
87991+ dest = mod->module_core_rx + shdr->sh_entsize;
87992+ }
87993+
87994+ if (shdr->sh_type != SHT_NOBITS) {
87995+
87996+#ifdef CONFIG_PAX_KERNEXEC
87997+#ifdef CONFIG_X86_64
87998+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
87999+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88000+#endif
88001+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88002+ pax_open_kernel();
88003+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88004+ pax_close_kernel();
88005+ } else
88006+#endif
88007
88008- if (shdr->sh_type != SHT_NOBITS)
88009 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88010+ }
88011 /* Update sh_addr to point to copy in image. */
88012- shdr->sh_addr = (unsigned long)dest;
88013+
88014+#ifdef CONFIG_PAX_KERNEXEC
88015+ if (shdr->sh_flags & SHF_EXECINSTR)
88016+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
88017+ else
88018+#endif
88019+
88020+ shdr->sh_addr = (unsigned long)dest;
88021 pr_debug("\t0x%lx %s\n",
88022 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88023 }
88024@@ -2894,12 +3024,12 @@ static void flush_module_icache(const struct module *mod)
88025 * Do it before processing of module parameters, so the module
88026 * can provide parameter accessor functions of its own.
88027 */
88028- if (mod->module_init)
88029- flush_icache_range((unsigned long)mod->module_init,
88030- (unsigned long)mod->module_init
88031- + mod->init_size);
88032- flush_icache_range((unsigned long)mod->module_core,
88033- (unsigned long)mod->module_core + mod->core_size);
88034+ if (mod->module_init_rx)
88035+ flush_icache_range((unsigned long)mod->module_init_rx,
88036+ (unsigned long)mod->module_init_rx
88037+ + mod->init_size_rx);
88038+ flush_icache_range((unsigned long)mod->module_core_rx,
88039+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
88040
88041 set_fs(old_fs);
88042 }
88043@@ -2956,8 +3086,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88044 static void module_deallocate(struct module *mod, struct load_info *info)
88045 {
88046 percpu_modfree(mod);
88047- module_free(mod, mod->module_init);
88048- module_free(mod, mod->module_core);
88049+ module_free_exec(mod, mod->module_init_rx);
88050+ module_free_exec(mod, mod->module_core_rx);
88051+ module_free(mod, mod->module_init_rw);
88052+ module_free(mod, mod->module_core_rw);
88053 }
88054
88055 int __weak module_finalize(const Elf_Ehdr *hdr,
88056@@ -2970,7 +3102,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88057 static int post_relocation(struct module *mod, const struct load_info *info)
88058 {
88059 /* Sort exception table now relocations are done. */
88060+ pax_open_kernel();
88061 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88062+ pax_close_kernel();
88063
88064 /* Copy relocated percpu area over. */
88065 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88066@@ -3024,16 +3158,16 @@ static int do_init_module(struct module *mod)
88067 MODULE_STATE_COMING, mod);
88068
88069 /* Set RO and NX regions for core */
88070- set_section_ro_nx(mod->module_core,
88071- mod->core_text_size,
88072- mod->core_ro_size,
88073- mod->core_size);
88074+ set_section_ro_nx(mod->module_core_rx,
88075+ mod->core_size_rx,
88076+ mod->core_size_rx,
88077+ mod->core_size_rx);
88078
88079 /* Set RO and NX regions for init */
88080- set_section_ro_nx(mod->module_init,
88081- mod->init_text_size,
88082- mod->init_ro_size,
88083- mod->init_size);
88084+ set_section_ro_nx(mod->module_init_rx,
88085+ mod->init_size_rx,
88086+ mod->init_size_rx,
88087+ mod->init_size_rx);
88088
88089 do_mod_ctors(mod);
88090 /* Start the module */
88091@@ -3094,11 +3228,12 @@ static int do_init_module(struct module *mod)
88092 mod->strtab = mod->core_strtab;
88093 #endif
88094 unset_module_init_ro_nx(mod);
88095- module_free(mod, mod->module_init);
88096- mod->module_init = NULL;
88097- mod->init_size = 0;
88098- mod->init_ro_size = 0;
88099- mod->init_text_size = 0;
88100+ module_free(mod, mod->module_init_rw);
88101+ module_free_exec(mod, mod->module_init_rx);
88102+ mod->module_init_rw = NULL;
88103+ mod->module_init_rx = NULL;
88104+ mod->init_size_rw = 0;
88105+ mod->init_size_rx = 0;
88106 mutex_unlock(&module_mutex);
88107 wake_up_all(&module_wq);
88108
88109@@ -3241,9 +3376,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88110 if (err)
88111 goto free_unload;
88112
88113+ /* Now copy in args */
88114+ mod->args = strndup_user(uargs, ~0UL >> 1);
88115+ if (IS_ERR(mod->args)) {
88116+ err = PTR_ERR(mod->args);
88117+ goto free_unload;
88118+ }
88119+
88120 /* Set up MODINFO_ATTR fields */
88121 setup_modinfo(mod, info);
88122
88123+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88124+ {
88125+ char *p, *p2;
88126+
88127+ if (strstr(mod->args, "grsec_modharden_netdev")) {
88128+ 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);
88129+ err = -EPERM;
88130+ goto free_modinfo;
88131+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88132+ p += sizeof("grsec_modharden_normal") - 1;
88133+ p2 = strstr(p, "_");
88134+ if (p2) {
88135+ *p2 = '\0';
88136+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88137+ *p2 = '_';
88138+ }
88139+ err = -EPERM;
88140+ goto free_modinfo;
88141+ }
88142+ }
88143+#endif
88144+
88145 /* Fix up syms, so that st_value is a pointer to location. */
88146 err = simplify_symbols(mod, info);
88147 if (err < 0)
88148@@ -3259,13 +3423,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88149
88150 flush_module_icache(mod);
88151
88152- /* Now copy in args */
88153- mod->args = strndup_user(uargs, ~0UL >> 1);
88154- if (IS_ERR(mod->args)) {
88155- err = PTR_ERR(mod->args);
88156- goto free_arch_cleanup;
88157- }
88158-
88159 dynamic_debug_setup(info->debug, info->num_debug);
88160
88161 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
88162@@ -3303,11 +3460,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88163 ddebug_cleanup:
88164 dynamic_debug_remove(info->debug);
88165 synchronize_sched();
88166- kfree(mod->args);
88167- free_arch_cleanup:
88168 module_arch_cleanup(mod);
88169 free_modinfo:
88170 free_modinfo(mod);
88171+ kfree(mod->args);
88172 free_unload:
88173 module_unload_free(mod);
88174 unlink_mod:
88175@@ -3390,10 +3546,16 @@ static const char *get_ksymbol(struct module *mod,
88176 unsigned long nextval;
88177
88178 /* At worse, next value is at end of module */
88179- if (within_module_init(addr, mod))
88180- nextval = (unsigned long)mod->module_init+mod->init_text_size;
88181+ if (within_module_init_rx(addr, mod))
88182+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88183+ else if (within_module_init_rw(addr, mod))
88184+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88185+ else if (within_module_core_rx(addr, mod))
88186+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88187+ else if (within_module_core_rw(addr, mod))
88188+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88189 else
88190- nextval = (unsigned long)mod->module_core+mod->core_text_size;
88191+ return NULL;
88192
88193 /* Scan for closest preceding symbol, and next symbol. (ELF
88194 starts real symbols at 1). */
88195@@ -3644,7 +3806,7 @@ static int m_show(struct seq_file *m, void *p)
88196 return 0;
88197
88198 seq_printf(m, "%s %u",
88199- mod->name, mod->init_size + mod->core_size);
88200+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88201 print_unload_info(m, mod);
88202
88203 /* Informative for users. */
88204@@ -3653,7 +3815,7 @@ static int m_show(struct seq_file *m, void *p)
88205 mod->state == MODULE_STATE_COMING ? "Loading":
88206 "Live");
88207 /* Used by oprofile and other similar tools. */
88208- seq_printf(m, " 0x%pK", mod->module_core);
88209+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88210
88211 /* Taints info */
88212 if (mod->taints)
88213@@ -3689,7 +3851,17 @@ static const struct file_operations proc_modules_operations = {
88214
88215 static int __init proc_modules_init(void)
88216 {
88217+#ifndef CONFIG_GRKERNSEC_HIDESYM
88218+#ifdef CONFIG_GRKERNSEC_PROC_USER
88219+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88220+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88221+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
88222+#else
88223 proc_create("modules", 0, NULL, &proc_modules_operations);
88224+#endif
88225+#else
88226+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88227+#endif
88228 return 0;
88229 }
88230 module_init(proc_modules_init);
88231@@ -3750,14 +3922,14 @@ struct module *__module_address(unsigned long addr)
88232 {
88233 struct module *mod;
88234
88235- if (addr < module_addr_min || addr > module_addr_max)
88236+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
88237+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
88238 return NULL;
88239
88240 list_for_each_entry_rcu(mod, &modules, list) {
88241 if (mod->state == MODULE_STATE_UNFORMED)
88242 continue;
88243- if (within_module_core(addr, mod)
88244- || within_module_init(addr, mod))
88245+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
88246 return mod;
88247 }
88248 return NULL;
88249@@ -3792,11 +3964,20 @@ bool is_module_text_address(unsigned long addr)
88250 */
88251 struct module *__module_text_address(unsigned long addr)
88252 {
88253- struct module *mod = __module_address(addr);
88254+ struct module *mod;
88255+
88256+#ifdef CONFIG_X86_32
88257+ addr = ktla_ktva(addr);
88258+#endif
88259+
88260+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
88261+ return NULL;
88262+
88263+ mod = __module_address(addr);
88264+
88265 if (mod) {
88266 /* Make sure it's within the text section. */
88267- if (!within(addr, mod->module_init, mod->init_text_size)
88268- && !within(addr, mod->module_core, mod->core_text_size))
88269+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
88270 mod = NULL;
88271 }
88272 return mod;
88273diff --git a/kernel/notifier.c b/kernel/notifier.c
88274index db4c8b0..ad011c5 100644
88275--- a/kernel/notifier.c
88276+++ b/kernel/notifier.c
88277@@ -5,6 +5,7 @@
88278 #include <linux/rcupdate.h>
88279 #include <linux/vmalloc.h>
88280 #include <linux/reboot.h>
88281+#include <linux/mm.h>
88282
88283 /*
88284 * Notifier list for kernel code which wants to be called
88285@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
88286 while ((*nl) != NULL) {
88287 if (n->priority > (*nl)->priority)
88288 break;
88289- nl = &((*nl)->next);
88290+ nl = (struct notifier_block **)&((*nl)->next);
88291 }
88292- n->next = *nl;
88293+ pax_open_kernel();
88294+ *(const void **)&n->next = *nl;
88295 rcu_assign_pointer(*nl, n);
88296+ pax_close_kernel();
88297 return 0;
88298 }
88299
88300@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
88301 return 0;
88302 if (n->priority > (*nl)->priority)
88303 break;
88304- nl = &((*nl)->next);
88305+ nl = (struct notifier_block **)&((*nl)->next);
88306 }
88307- n->next = *nl;
88308+ pax_open_kernel();
88309+ *(const void **)&n->next = *nl;
88310 rcu_assign_pointer(*nl, n);
88311+ pax_close_kernel();
88312 return 0;
88313 }
88314
88315@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
88316 {
88317 while ((*nl) != NULL) {
88318 if ((*nl) == n) {
88319+ pax_open_kernel();
88320 rcu_assign_pointer(*nl, n->next);
88321+ pax_close_kernel();
88322 return 0;
88323 }
88324- nl = &((*nl)->next);
88325+ nl = (struct notifier_block **)&((*nl)->next);
88326 }
88327 return -ENOENT;
88328 }
88329diff --git a/kernel/padata.c b/kernel/padata.c
88330index 161402f..598814c 100644
88331--- a/kernel/padata.c
88332+++ b/kernel/padata.c
88333@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88334 * seq_nr mod. number of cpus in use.
88335 */
88336
88337- seq_nr = atomic_inc_return(&pd->seq_nr);
88338+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88339 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88340
88341 return padata_index_to_cpu(pd, cpu_index);
88342@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88343 padata_init_pqueues(pd);
88344 padata_init_squeues(pd);
88345 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88346- atomic_set(&pd->seq_nr, -1);
88347+ atomic_set_unchecked(&pd->seq_nr, -1);
88348 atomic_set(&pd->reorder_objects, 0);
88349 atomic_set(&pd->refcnt, 0);
88350 pd->pinst = pinst;
88351diff --git a/kernel/panic.c b/kernel/panic.c
88352index d02fa9f..9faec0a 100644
88353--- a/kernel/panic.c
88354+++ b/kernel/panic.c
88355@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88356 /*
88357 * Stop ourself in panic -- architecture code may override this
88358 */
88359-void __weak panic_smp_self_stop(void)
88360+void __weak __noreturn panic_smp_self_stop(void)
88361 {
88362 while (1)
88363 cpu_relax();
88364@@ -408,7 +408,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88365 disable_trace_on_warning();
88366
88367 pr_warn("------------[ cut here ]------------\n");
88368- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88369+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88370 raw_smp_processor_id(), current->pid, file, line, caller);
88371
88372 if (args)
88373@@ -462,7 +462,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88374 */
88375 __visible void __stack_chk_fail(void)
88376 {
88377- panic("stack-protector: Kernel stack is corrupted in: %p\n",
88378+ dump_stack();
88379+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88380 __builtin_return_address(0));
88381 }
88382 EXPORT_SYMBOL(__stack_chk_fail);
88383diff --git a/kernel/pid.c b/kernel/pid.c
88384index 9b9a266..c20ef80 100644
88385--- a/kernel/pid.c
88386+++ b/kernel/pid.c
88387@@ -33,6 +33,7 @@
88388 #include <linux/rculist.h>
88389 #include <linux/bootmem.h>
88390 #include <linux/hash.h>
88391+#include <linux/security.h>
88392 #include <linux/pid_namespace.h>
88393 #include <linux/init_task.h>
88394 #include <linux/syscalls.h>
88395@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88396
88397 int pid_max = PID_MAX_DEFAULT;
88398
88399-#define RESERVED_PIDS 300
88400+#define RESERVED_PIDS 500
88401
88402 int pid_max_min = RESERVED_PIDS + 1;
88403 int pid_max_max = PID_MAX_LIMIT;
88404@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88405 */
88406 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88407 {
88408+ struct task_struct *task;
88409+
88410 rcu_lockdep_assert(rcu_read_lock_held(),
88411 "find_task_by_pid_ns() needs rcu_read_lock()"
88412 " protection");
88413- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88414+
88415+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88416+
88417+ if (gr_pid_is_chrooted(task))
88418+ return NULL;
88419+
88420+ return task;
88421 }
88422
88423 struct task_struct *find_task_by_vpid(pid_t vnr)
88424@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88425 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88426 }
88427
88428+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88429+{
88430+ rcu_lockdep_assert(rcu_read_lock_held(),
88431+ "find_task_by_pid_ns() needs rcu_read_lock()"
88432+ " protection");
88433+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88434+}
88435+
88436 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88437 {
88438 struct pid *pid;
88439diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88440index db95d8e..a0ca23f 100644
88441--- a/kernel/pid_namespace.c
88442+++ b/kernel/pid_namespace.c
88443@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88444 void __user *buffer, size_t *lenp, loff_t *ppos)
88445 {
88446 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88447- struct ctl_table tmp = *table;
88448+ ctl_table_no_const tmp = *table;
88449
88450 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88451 return -EPERM;
88452diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88453index 3b89464..5e38379 100644
88454--- a/kernel/posix-cpu-timers.c
88455+++ b/kernel/posix-cpu-timers.c
88456@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88457
88458 static __init int init_posix_cpu_timers(void)
88459 {
88460- struct k_clock process = {
88461+ static struct k_clock process = {
88462 .clock_getres = process_cpu_clock_getres,
88463 .clock_get = process_cpu_clock_get,
88464 .timer_create = process_cpu_timer_create,
88465 .nsleep = process_cpu_nsleep,
88466 .nsleep_restart = process_cpu_nsleep_restart,
88467 };
88468- struct k_clock thread = {
88469+ static struct k_clock thread = {
88470 .clock_getres = thread_cpu_clock_getres,
88471 .clock_get = thread_cpu_clock_get,
88472 .timer_create = thread_cpu_timer_create,
88473diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88474index 424c2d4..679242f 100644
88475--- a/kernel/posix-timers.c
88476+++ b/kernel/posix-timers.c
88477@@ -43,6 +43,7 @@
88478 #include <linux/hash.h>
88479 #include <linux/posix-clock.h>
88480 #include <linux/posix-timers.h>
88481+#include <linux/grsecurity.h>
88482 #include <linux/syscalls.h>
88483 #include <linux/wait.h>
88484 #include <linux/workqueue.h>
88485@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88486 * which we beg off on and pass to do_sys_settimeofday().
88487 */
88488
88489-static struct k_clock posix_clocks[MAX_CLOCKS];
88490+static struct k_clock *posix_clocks[MAX_CLOCKS];
88491
88492 /*
88493 * These ones are defined below.
88494@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88495 */
88496 static __init int init_posix_timers(void)
88497 {
88498- struct k_clock clock_realtime = {
88499+ static struct k_clock clock_realtime = {
88500 .clock_getres = hrtimer_get_res,
88501 .clock_get = posix_clock_realtime_get,
88502 .clock_set = posix_clock_realtime_set,
88503@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
88504 .timer_get = common_timer_get,
88505 .timer_del = common_timer_del,
88506 };
88507- struct k_clock clock_monotonic = {
88508+ static struct k_clock clock_monotonic = {
88509 .clock_getres = hrtimer_get_res,
88510 .clock_get = posix_ktime_get_ts,
88511 .nsleep = common_nsleep,
88512@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
88513 .timer_get = common_timer_get,
88514 .timer_del = common_timer_del,
88515 };
88516- struct k_clock clock_monotonic_raw = {
88517+ static struct k_clock clock_monotonic_raw = {
88518 .clock_getres = hrtimer_get_res,
88519 .clock_get = posix_get_monotonic_raw,
88520 };
88521- struct k_clock clock_realtime_coarse = {
88522+ static struct k_clock clock_realtime_coarse = {
88523 .clock_getres = posix_get_coarse_res,
88524 .clock_get = posix_get_realtime_coarse,
88525 };
88526- struct k_clock clock_monotonic_coarse = {
88527+ static struct k_clock clock_monotonic_coarse = {
88528 .clock_getres = posix_get_coarse_res,
88529 .clock_get = posix_get_monotonic_coarse,
88530 };
88531- struct k_clock clock_tai = {
88532+ static struct k_clock clock_tai = {
88533 .clock_getres = hrtimer_get_res,
88534 .clock_get = posix_get_tai,
88535 .nsleep = common_nsleep,
88536@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
88537 .timer_get = common_timer_get,
88538 .timer_del = common_timer_del,
88539 };
88540- struct k_clock clock_boottime = {
88541+ static struct k_clock clock_boottime = {
88542 .clock_getres = hrtimer_get_res,
88543 .clock_get = posix_get_boottime,
88544 .nsleep = common_nsleep,
88545@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
88546 return;
88547 }
88548
88549- posix_clocks[clock_id] = *new_clock;
88550+ posix_clocks[clock_id] = new_clock;
88551 }
88552 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
88553
88554@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
88555 return (id & CLOCKFD_MASK) == CLOCKFD ?
88556 &clock_posix_dynamic : &clock_posix_cpu;
88557
88558- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
88559+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
88560 return NULL;
88561- return &posix_clocks[id];
88562+ return posix_clocks[id];
88563 }
88564
88565 static int common_timer_create(struct k_itimer *new_timer)
88566@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
88567 struct k_clock *kc = clockid_to_kclock(which_clock);
88568 struct k_itimer *new_timer;
88569 int error, new_timer_id;
88570- sigevent_t event;
88571+ sigevent_t event = { };
88572 int it_id_set = IT_ID_NOT_SET;
88573
88574 if (!kc)
88575@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
88576 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
88577 return -EFAULT;
88578
88579+ /* only the CLOCK_REALTIME clock can be set, all other clocks
88580+ have their clock_set fptr set to a nosettime dummy function
88581+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
88582+ call common_clock_set, which calls do_sys_settimeofday, which
88583+ we hook
88584+ */
88585+
88586 return kc->clock_set(which_clock, &new_tp);
88587 }
88588
88589diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
88590index 2fac9cc..56fef29 100644
88591--- a/kernel/power/Kconfig
88592+++ b/kernel/power/Kconfig
88593@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
88594 config HIBERNATION
88595 bool "Hibernation (aka 'suspend to disk')"
88596 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
88597+ depends on !GRKERNSEC_KMEM
88598+ depends on !PAX_MEMORY_SANITIZE
88599 select HIBERNATE_CALLBACKS
88600 select LZO_COMPRESS
88601 select LZO_DECOMPRESS
88602diff --git a/kernel/power/process.c b/kernel/power/process.c
88603index 06ec886..9dba35e 100644
88604--- a/kernel/power/process.c
88605+++ b/kernel/power/process.c
88606@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
88607 unsigned int elapsed_msecs;
88608 bool wakeup = false;
88609 int sleep_usecs = USEC_PER_MSEC;
88610+ bool timedout = false;
88611
88612 do_gettimeofday(&start);
88613
88614@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
88615
88616 while (true) {
88617 todo = 0;
88618+ if (time_after(jiffies, end_time))
88619+ timedout = true;
88620 read_lock(&tasklist_lock);
88621 do_each_thread(g, p) {
88622 if (p == current || !freeze_task(p))
88623 continue;
88624
88625- if (!freezer_should_skip(p))
88626+ if (!freezer_should_skip(p)) {
88627 todo++;
88628+ if (timedout) {
88629+ printk(KERN_ERR "Task refusing to freeze:\n");
88630+ sched_show_task(p);
88631+ }
88632+ }
88633 } while_each_thread(g, p);
88634 read_unlock(&tasklist_lock);
88635
88636@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
88637 todo += wq_busy;
88638 }
88639
88640- if (!todo || time_after(jiffies, end_time))
88641+ if (!todo || timedout)
88642 break;
88643
88644 if (pm_wakeup_pending()) {
88645diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
88646index 7228258..e8ae7c9 100644
88647--- a/kernel/printk/printk.c
88648+++ b/kernel/printk/printk.c
88649@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
88650 if (from_file && type != SYSLOG_ACTION_OPEN)
88651 return 0;
88652
88653+#ifdef CONFIG_GRKERNSEC_DMESG
88654+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
88655+ return -EPERM;
88656+#endif
88657+
88658 if (syslog_action_restricted(type)) {
88659 if (capable(CAP_SYSLOG))
88660 return 0;
88661diff --git a/kernel/profile.c b/kernel/profile.c
88662index cb980f0..ccd8782 100644
88663--- a/kernel/profile.c
88664+++ b/kernel/profile.c
88665@@ -37,7 +37,7 @@ struct profile_hit {
88666 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
88667 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
88668
88669-static atomic_t *prof_buffer;
88670+static atomic_unchecked_t *prof_buffer;
88671 static unsigned long prof_len, prof_shift;
88672
88673 int prof_on __read_mostly;
88674@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
88675 hits[i].pc = 0;
88676 continue;
88677 }
88678- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88679+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88680 hits[i].hits = hits[i].pc = 0;
88681 }
88682 }
88683@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88684 * Add the current hit(s) and flush the write-queue out
88685 * to the global buffer:
88686 */
88687- atomic_add(nr_hits, &prof_buffer[pc]);
88688+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
88689 for (i = 0; i < NR_PROFILE_HIT; ++i) {
88690- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88691+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88692 hits[i].pc = hits[i].hits = 0;
88693 }
88694 out:
88695@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88696 {
88697 unsigned long pc;
88698 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
88699- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88700+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88701 }
88702 #endif /* !CONFIG_SMP */
88703
88704@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
88705 return -EFAULT;
88706 buf++; p++; count--; read++;
88707 }
88708- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88709+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88710 if (copy_to_user(buf, (void *)pnt, count))
88711 return -EFAULT;
88712 read += count;
88713@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88714 }
88715 #endif
88716 profile_discard_flip_buffers();
88717- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88718+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88719 return count;
88720 }
88721
88722diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88723index adf9862..9d86345 100644
88724--- a/kernel/ptrace.c
88725+++ b/kernel/ptrace.c
88726@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88727 if (seize)
88728 flags |= PT_SEIZED;
88729 rcu_read_lock();
88730- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88731+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88732 flags |= PT_PTRACE_CAP;
88733 rcu_read_unlock();
88734 task->ptrace = flags;
88735@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
88736 break;
88737 return -EIO;
88738 }
88739- if (copy_to_user(dst, buf, retval))
88740+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
88741 return -EFAULT;
88742 copied += retval;
88743 src += retval;
88744@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
88745 bool seized = child->ptrace & PT_SEIZED;
88746 int ret = -EIO;
88747 siginfo_t siginfo, *si;
88748- void __user *datavp = (void __user *) data;
88749+ void __user *datavp = (__force void __user *) data;
88750 unsigned long __user *datalp = datavp;
88751 unsigned long flags;
88752
88753@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
88754 goto out;
88755 }
88756
88757+ if (gr_handle_ptrace(child, request)) {
88758+ ret = -EPERM;
88759+ goto out_put_task_struct;
88760+ }
88761+
88762 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88763 ret = ptrace_attach(child, request, addr, data);
88764 /*
88765 * Some architectures need to do book-keeping after
88766 * a ptrace attach.
88767 */
88768- if (!ret)
88769+ if (!ret) {
88770 arch_ptrace_attach(child);
88771+ gr_audit_ptrace(child);
88772+ }
88773 goto out_put_task_struct;
88774 }
88775
88776@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
88777 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
88778 if (copied != sizeof(tmp))
88779 return -EIO;
88780- return put_user(tmp, (unsigned long __user *)data);
88781+ return put_user(tmp, (__force unsigned long __user *)data);
88782 }
88783
88784 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88785@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88786 }
88787
88788 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
88789- compat_long_t, addr, compat_long_t, data)
88790+ compat_ulong_t, addr, compat_ulong_t, data)
88791 {
88792 struct task_struct *child;
88793 long ret;
88794@@ -1197,14 +1204,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
88795 goto out;
88796 }
88797
88798+ if (gr_handle_ptrace(child, request)) {
88799+ ret = -EPERM;
88800+ goto out_put_task_struct;
88801+ }
88802+
88803 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88804 ret = ptrace_attach(child, request, addr, data);
88805 /*
88806 * Some architectures need to do book-keeping after
88807 * a ptrace attach.
88808 */
88809- if (!ret)
88810+ if (!ret) {
88811 arch_ptrace_attach(child);
88812+ gr_audit_ptrace(child);
88813+ }
88814 goto out_put_task_struct;
88815 }
88816
88817diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
88818index bd30bc6..dce23da 100644
88819--- a/kernel/rcu/rcutorture.c
88820+++ b/kernel/rcu/rcutorture.c
88821@@ -122,12 +122,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
88822 rcu_torture_count) = { 0 };
88823 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
88824 rcu_torture_batch) = { 0 };
88825-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88826-static atomic_t n_rcu_torture_alloc;
88827-static atomic_t n_rcu_torture_alloc_fail;
88828-static atomic_t n_rcu_torture_free;
88829-static atomic_t n_rcu_torture_mberror;
88830-static atomic_t n_rcu_torture_error;
88831+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88832+static atomic_unchecked_t n_rcu_torture_alloc;
88833+static atomic_unchecked_t n_rcu_torture_alloc_fail;
88834+static atomic_unchecked_t n_rcu_torture_free;
88835+static atomic_unchecked_t n_rcu_torture_mberror;
88836+static atomic_unchecked_t n_rcu_torture_error;
88837 static long n_rcu_torture_barrier_error;
88838 static long n_rcu_torture_boost_ktrerror;
88839 static long n_rcu_torture_boost_rterror;
88840@@ -186,11 +186,11 @@ rcu_torture_alloc(void)
88841
88842 spin_lock_bh(&rcu_torture_lock);
88843 if (list_empty(&rcu_torture_freelist)) {
88844- atomic_inc(&n_rcu_torture_alloc_fail);
88845+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88846 spin_unlock_bh(&rcu_torture_lock);
88847 return NULL;
88848 }
88849- atomic_inc(&n_rcu_torture_alloc);
88850+ atomic_inc_unchecked(&n_rcu_torture_alloc);
88851 p = rcu_torture_freelist.next;
88852 list_del_init(p);
88853 spin_unlock_bh(&rcu_torture_lock);
88854@@ -203,7 +203,7 @@ rcu_torture_alloc(void)
88855 static void
88856 rcu_torture_free(struct rcu_torture *p)
88857 {
88858- atomic_inc(&n_rcu_torture_free);
88859+ atomic_inc_unchecked(&n_rcu_torture_free);
88860 spin_lock_bh(&rcu_torture_lock);
88861 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88862 spin_unlock_bh(&rcu_torture_lock);
88863@@ -287,7 +287,7 @@ rcu_torture_cb(struct rcu_head *p)
88864 i = rp->rtort_pipe_count;
88865 if (i > RCU_TORTURE_PIPE_LEN)
88866 i = RCU_TORTURE_PIPE_LEN;
88867- atomic_inc(&rcu_torture_wcount[i]);
88868+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88869 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88870 rp->rtort_mbtest = 0;
88871 rcu_torture_free(rp);
88872@@ -714,7 +714,7 @@ rcu_torture_writer(void *arg)
88873 i = old_rp->rtort_pipe_count;
88874 if (i > RCU_TORTURE_PIPE_LEN)
88875 i = RCU_TORTURE_PIPE_LEN;
88876- atomic_inc(&rcu_torture_wcount[i]);
88877+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88878 old_rp->rtort_pipe_count++;
88879 if (gp_normal == gp_exp)
88880 exp = !!(torture_random(&rand) & 0x80);
88881@@ -732,7 +732,7 @@ rcu_torture_writer(void *arg)
88882 i = rp->rtort_pipe_count;
88883 if (i > RCU_TORTURE_PIPE_LEN)
88884 i = RCU_TORTURE_PIPE_LEN;
88885- atomic_inc(&rcu_torture_wcount[i]);
88886+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88887 if (++rp->rtort_pipe_count >=
88888 RCU_TORTURE_PIPE_LEN) {
88889 rp->rtort_mbtest = 0;
88890@@ -825,7 +825,7 @@ static void rcu_torture_timer(unsigned long unused)
88891 return;
88892 }
88893 if (p->rtort_mbtest == 0)
88894- atomic_inc(&n_rcu_torture_mberror);
88895+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88896 spin_lock(&rand_lock);
88897 cur_ops->read_delay(&rand);
88898 n_rcu_torture_timers++;
88899@@ -895,7 +895,7 @@ rcu_torture_reader(void *arg)
88900 continue;
88901 }
88902 if (p->rtort_mbtest == 0)
88903- atomic_inc(&n_rcu_torture_mberror);
88904+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88905 cur_ops->read_delay(&rand);
88906 preempt_disable();
88907 pipe_count = p->rtort_pipe_count;
88908@@ -950,15 +950,15 @@ rcu_torture_printk(char *page)
88909 }
88910 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
88911 page += sprintf(page,
88912- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
88913+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
88914 rcu_torture_current,
88915 rcu_torture_current_version,
88916 list_empty(&rcu_torture_freelist),
88917- atomic_read(&n_rcu_torture_alloc),
88918- atomic_read(&n_rcu_torture_alloc_fail),
88919- atomic_read(&n_rcu_torture_free));
88920+ atomic_read_unchecked(&n_rcu_torture_alloc),
88921+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
88922+ atomic_read_unchecked(&n_rcu_torture_free));
88923 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
88924- atomic_read(&n_rcu_torture_mberror),
88925+ atomic_read_unchecked(&n_rcu_torture_mberror),
88926 n_rcu_torture_boost_ktrerror,
88927 n_rcu_torture_boost_rterror);
88928 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
88929@@ -971,14 +971,14 @@ rcu_torture_printk(char *page)
88930 n_barrier_attempts,
88931 n_rcu_torture_barrier_error);
88932 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
88933- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
88934+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
88935 n_rcu_torture_barrier_error != 0 ||
88936 n_rcu_torture_boost_ktrerror != 0 ||
88937 n_rcu_torture_boost_rterror != 0 ||
88938 n_rcu_torture_boost_failure != 0 ||
88939 i > 1) {
88940 page += sprintf(page, "!!! ");
88941- atomic_inc(&n_rcu_torture_error);
88942+ atomic_inc_unchecked(&n_rcu_torture_error);
88943 WARN_ON_ONCE(1);
88944 }
88945 page += sprintf(page, "Reader Pipe: ");
88946@@ -992,7 +992,7 @@ rcu_torture_printk(char *page)
88947 page += sprintf(page, "Free-Block Circulation: ");
88948 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88949 page += sprintf(page, " %d",
88950- atomic_read(&rcu_torture_wcount[i]));
88951+ atomic_read_unchecked(&rcu_torture_wcount[i]));
88952 }
88953 page += sprintf(page, "\n");
88954 if (cur_ops->stats)
88955@@ -1341,7 +1341,7 @@ rcu_torture_cleanup(void)
88956
88957 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
88958
88959- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88960+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88961 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
88962 else if (torture_onoff_failures())
88963 rcu_torture_print_module_parms(cur_ops,
88964@@ -1460,18 +1460,18 @@ rcu_torture_init(void)
88965
88966 rcu_torture_current = NULL;
88967 rcu_torture_current_version = 0;
88968- atomic_set(&n_rcu_torture_alloc, 0);
88969- atomic_set(&n_rcu_torture_alloc_fail, 0);
88970- atomic_set(&n_rcu_torture_free, 0);
88971- atomic_set(&n_rcu_torture_mberror, 0);
88972- atomic_set(&n_rcu_torture_error, 0);
88973+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
88974+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
88975+ atomic_set_unchecked(&n_rcu_torture_free, 0);
88976+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
88977+ atomic_set_unchecked(&n_rcu_torture_error, 0);
88978 n_rcu_torture_barrier_error = 0;
88979 n_rcu_torture_boost_ktrerror = 0;
88980 n_rcu_torture_boost_rterror = 0;
88981 n_rcu_torture_boost_failure = 0;
88982 n_rcu_torture_boosts = 0;
88983 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
88984- atomic_set(&rcu_torture_wcount[i], 0);
88985+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
88986 for_each_possible_cpu(cpu) {
88987 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88988 per_cpu(rcu_torture_count, cpu)[i] = 0;
88989diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
88990index c639556..cf0a0d5 100644
88991--- a/kernel/rcu/srcu.c
88992+++ b/kernel/rcu/srcu.c
88993@@ -298,9 +298,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
88994
88995 idx = ACCESS_ONCE(sp->completed) & 0x1;
88996 preempt_disable();
88997- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88998+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88999 smp_mb(); /* B */ /* Avoid leaking the critical section. */
89000- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89001+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89002 preempt_enable();
89003 return idx;
89004 }
89005diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
89006index d9efcc1..ea543e9 100644
89007--- a/kernel/rcu/tiny.c
89008+++ b/kernel/rcu/tiny.c
89009@@ -42,7 +42,7 @@
89010 /* Forward declarations for tiny_plugin.h. */
89011 struct rcu_ctrlblk;
89012 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
89013-static void rcu_process_callbacks(struct softirq_action *unused);
89014+static void rcu_process_callbacks(void);
89015 static void __call_rcu(struct rcu_head *head,
89016 void (*func)(struct rcu_head *rcu),
89017 struct rcu_ctrlblk *rcp);
89018@@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
89019 false));
89020 }
89021
89022-static void rcu_process_callbacks(struct softirq_action *unused)
89023+static __latent_entropy void rcu_process_callbacks(void)
89024 {
89025 __rcu_process_callbacks(&rcu_sched_ctrlblk);
89026 __rcu_process_callbacks(&rcu_bh_ctrlblk);
89027diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89028index 0c47e30..a084591 100644
89029--- a/kernel/rcu/tree.c
89030+++ b/kernel/rcu/tree.c
89031@@ -388,9 +388,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89032 rcu_prepare_for_idle(smp_processor_id());
89033 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89034 smp_mb__before_atomic_inc(); /* See above. */
89035- atomic_inc(&rdtp->dynticks);
89036+ atomic_inc_unchecked(&rdtp->dynticks);
89037 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89038- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89039+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89040
89041 /*
89042 * It is illegal to enter an extended quiescent state while
89043@@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89044 int user)
89045 {
89046 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89047- atomic_inc(&rdtp->dynticks);
89048+ atomic_inc_unchecked(&rdtp->dynticks);
89049 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89050 smp_mb__after_atomic_inc(); /* See above. */
89051- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89052+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89053 rcu_cleanup_after_idle(smp_processor_id());
89054 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89055 if (!user && !is_idle_task(current)) {
89056@@ -632,14 +632,14 @@ void rcu_nmi_enter(void)
89057 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89058
89059 if (rdtp->dynticks_nmi_nesting == 0 &&
89060- (atomic_read(&rdtp->dynticks) & 0x1))
89061+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89062 return;
89063 rdtp->dynticks_nmi_nesting++;
89064 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89065- atomic_inc(&rdtp->dynticks);
89066+ atomic_inc_unchecked(&rdtp->dynticks);
89067 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89068 smp_mb__after_atomic_inc(); /* See above. */
89069- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89070+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89071 }
89072
89073 /**
89074@@ -658,9 +658,9 @@ void rcu_nmi_exit(void)
89075 return;
89076 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89077 smp_mb__before_atomic_inc(); /* See above. */
89078- atomic_inc(&rdtp->dynticks);
89079+ atomic_inc_unchecked(&rdtp->dynticks);
89080 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89081- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89082+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89083 }
89084
89085 /**
89086@@ -673,7 +673,7 @@ void rcu_nmi_exit(void)
89087 */
89088 bool notrace __rcu_is_watching(void)
89089 {
89090- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89091+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89092 }
89093
89094 /**
89095@@ -756,7 +756,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89096 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89097 bool *isidle, unsigned long *maxj)
89098 {
89099- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89100+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89101 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89102 return (rdp->dynticks_snap & 0x1) == 0;
89103 }
89104@@ -779,7 +779,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89105 unsigned int curr;
89106 unsigned int snap;
89107
89108- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89109+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89110 snap = (unsigned int)rdp->dynticks_snap;
89111
89112 /*
89113@@ -1449,9 +1449,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89114 rdp = this_cpu_ptr(rsp->rda);
89115 rcu_preempt_check_blocked_tasks(rnp);
89116 rnp->qsmask = rnp->qsmaskinit;
89117- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89118+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89119 WARN_ON_ONCE(rnp->completed != rsp->completed);
89120- ACCESS_ONCE(rnp->completed) = rsp->completed;
89121+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89122 if (rnp == rdp->mynode)
89123 __note_gp_changes(rsp, rnp, rdp);
89124 rcu_preempt_boost_start_gp(rnp);
89125@@ -1545,7 +1545,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89126 rcu_for_each_node_breadth_first(rsp, rnp) {
89127 raw_spin_lock_irq(&rnp->lock);
89128 smp_mb__after_unlock_lock();
89129- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89130+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89131 rdp = this_cpu_ptr(rsp->rda);
89132 if (rnp == rdp->mynode)
89133 __note_gp_changes(rsp, rnp, rdp);
89134@@ -1560,7 +1560,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89135 rcu_nocb_gp_set(rnp, nocb);
89136
89137 /* Declare grace period done. */
89138- ACCESS_ONCE(rsp->completed) = rsp->gpnum;
89139+ ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
89140 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
89141 rsp->fqs_state = RCU_GP_IDLE;
89142 rdp = this_cpu_ptr(rsp->rda);
89143@@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89144 rsp->qlen += rdp->qlen;
89145 rdp->n_cbs_orphaned += rdp->qlen;
89146 rdp->qlen_lazy = 0;
89147- ACCESS_ONCE(rdp->qlen) = 0;
89148+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89149 }
89150
89151 /*
89152@@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89153 }
89154 smp_mb(); /* List handling before counting for rcu_barrier(). */
89155 rdp->qlen_lazy -= count_lazy;
89156- ACCESS_ONCE(rdp->qlen) -= count;
89157+ ACCESS_ONCE_RW(rdp->qlen) -= count;
89158 rdp->n_cbs_invoked += count;
89159
89160 /* Reinstate batch limit if we have worked down the excess. */
89161@@ -2304,7 +2304,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89162 if (rnp_old != NULL)
89163 raw_spin_unlock(&rnp_old->fqslock);
89164 if (ret) {
89165- ACCESS_ONCE(rsp->n_force_qs_lh)++;
89166+ ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89167 return;
89168 }
89169 rnp_old = rnp;
89170@@ -2316,7 +2316,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89171 smp_mb__after_unlock_lock();
89172 raw_spin_unlock(&rnp_old->fqslock);
89173 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
89174- ACCESS_ONCE(rsp->n_force_qs_lh)++;
89175+ ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89176 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
89177 return; /* Someone beat us to it. */
89178 }
89179@@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89180 /*
89181 * Do RCU core processing for the current CPU.
89182 */
89183-static void rcu_process_callbacks(struct softirq_action *unused)
89184+static void rcu_process_callbacks(void)
89185 {
89186 struct rcu_state *rsp;
89187
89188@@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89189 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89190 if (debug_rcu_head_queue(head)) {
89191 /* Probable double call_rcu(), so leak the callback. */
89192- ACCESS_ONCE(head->func) = rcu_leak_callback;
89193+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89194 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89195 return;
89196 }
89197@@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89198 local_irq_restore(flags);
89199 return;
89200 }
89201- ACCESS_ONCE(rdp->qlen)++;
89202+ ACCESS_ONCE_RW(rdp->qlen)++;
89203 if (lazy)
89204 rdp->qlen_lazy++;
89205 else
89206@@ -2759,11 +2759,11 @@ void synchronize_sched_expedited(void)
89207 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89208 * course be required on a 64-bit system.
89209 */
89210- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89211+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89212 (ulong)atomic_long_read(&rsp->expedited_done) +
89213 ULONG_MAX / 8)) {
89214 synchronize_sched();
89215- atomic_long_inc(&rsp->expedited_wrap);
89216+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
89217 return;
89218 }
89219
89220@@ -2771,7 +2771,7 @@ void synchronize_sched_expedited(void)
89221 * Take a ticket. Note that atomic_inc_return() implies a
89222 * full memory barrier.
89223 */
89224- snap = atomic_long_inc_return(&rsp->expedited_start);
89225+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
89226 firstsnap = snap;
89227 get_online_cpus();
89228 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
89229@@ -2784,14 +2784,14 @@ void synchronize_sched_expedited(void)
89230 synchronize_sched_expedited_cpu_stop,
89231 NULL) == -EAGAIN) {
89232 put_online_cpus();
89233- atomic_long_inc(&rsp->expedited_tryfail);
89234+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
89235
89236 /* Check to see if someone else did our work for us. */
89237 s = atomic_long_read(&rsp->expedited_done);
89238 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89239 /* ensure test happens before caller kfree */
89240 smp_mb__before_atomic_inc(); /* ^^^ */
89241- atomic_long_inc(&rsp->expedited_workdone1);
89242+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
89243 return;
89244 }
89245
89246@@ -2800,7 +2800,7 @@ void synchronize_sched_expedited(void)
89247 udelay(trycount * num_online_cpus());
89248 } else {
89249 wait_rcu_gp(call_rcu_sched);
89250- atomic_long_inc(&rsp->expedited_normal);
89251+ atomic_long_inc_unchecked(&rsp->expedited_normal);
89252 return;
89253 }
89254
89255@@ -2809,7 +2809,7 @@ void synchronize_sched_expedited(void)
89256 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89257 /* ensure test happens before caller kfree */
89258 smp_mb__before_atomic_inc(); /* ^^^ */
89259- atomic_long_inc(&rsp->expedited_workdone2);
89260+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
89261 return;
89262 }
89263
89264@@ -2821,10 +2821,10 @@ void synchronize_sched_expedited(void)
89265 * period works for us.
89266 */
89267 get_online_cpus();
89268- snap = atomic_long_read(&rsp->expedited_start);
89269+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
89270 smp_mb(); /* ensure read is before try_stop_cpus(). */
89271 }
89272- atomic_long_inc(&rsp->expedited_stoppedcpus);
89273+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
89274
89275 /*
89276 * Everyone up to our most recent fetch is covered by our grace
89277@@ -2833,16 +2833,16 @@ void synchronize_sched_expedited(void)
89278 * than we did already did their update.
89279 */
89280 do {
89281- atomic_long_inc(&rsp->expedited_done_tries);
89282+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
89283 s = atomic_long_read(&rsp->expedited_done);
89284 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
89285 /* ensure test happens before caller kfree */
89286 smp_mb__before_atomic_inc(); /* ^^^ */
89287- atomic_long_inc(&rsp->expedited_done_lost);
89288+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
89289 break;
89290 }
89291 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
89292- atomic_long_inc(&rsp->expedited_done_exit);
89293+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
89294
89295 put_online_cpus();
89296 }
89297@@ -3048,7 +3048,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89298 * ACCESS_ONCE() to prevent the compiler from speculating
89299 * the increment to precede the early-exit check.
89300 */
89301- ACCESS_ONCE(rsp->n_barrier_done)++;
89302+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89303 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
89304 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
89305 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
89306@@ -3098,7 +3098,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89307
89308 /* Increment ->n_barrier_done to prevent duplicate work. */
89309 smp_mb(); /* Keep increment after above mechanism. */
89310- ACCESS_ONCE(rsp->n_barrier_done)++;
89311+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89312 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
89313 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
89314 smp_mb(); /* Keep increment before caller's subsequent code. */
89315@@ -3143,10 +3143,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
89316 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
89317 init_callback_list(rdp);
89318 rdp->qlen_lazy = 0;
89319- ACCESS_ONCE(rdp->qlen) = 0;
89320+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89321 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
89322 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
89323- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
89324+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
89325 rdp->cpu = cpu;
89326 rdp->rsp = rsp;
89327 rcu_boot_init_nocb_percpu_data(rdp);
89328@@ -3180,8 +3180,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
89329 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
89330 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
89331 rcu_sysidle_init_percpu_data(rdp->dynticks);
89332- atomic_set(&rdp->dynticks->dynticks,
89333- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
89334+ atomic_set_unchecked(&rdp->dynticks->dynticks,
89335+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
89336 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
89337
89338 /* Add CPU to rcu_node bitmasks. */
89339diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
89340index 75dc3c3..b95d624 100644
89341--- a/kernel/rcu/tree.h
89342+++ b/kernel/rcu/tree.h
89343@@ -87,11 +87,11 @@ struct rcu_dynticks {
89344 long long dynticks_nesting; /* Track irq/process nesting level. */
89345 /* Process level is worth LLONG_MAX/2. */
89346 int dynticks_nmi_nesting; /* Track NMI nesting level. */
89347- atomic_t dynticks; /* Even value for idle, else odd. */
89348+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
89349 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
89350 long long dynticks_idle_nesting;
89351 /* irq/process nesting level from idle. */
89352- atomic_t dynticks_idle; /* Even value for idle, else odd. */
89353+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
89354 /* "Idle" excludes userspace execution. */
89355 unsigned long dynticks_idle_jiffies;
89356 /* End of last non-NMI non-idle period. */
89357@@ -431,17 +431,17 @@ struct rcu_state {
89358 /* _rcu_barrier(). */
89359 /* End of fields guarded by barrier_mutex. */
89360
89361- atomic_long_t expedited_start; /* Starting ticket. */
89362- atomic_long_t expedited_done; /* Done ticket. */
89363- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89364- atomic_long_t expedited_tryfail; /* # acquisition failures. */
89365- atomic_long_t expedited_workdone1; /* # done by others #1. */
89366- atomic_long_t expedited_workdone2; /* # done by others #2. */
89367- atomic_long_t expedited_normal; /* # fallbacks to normal. */
89368- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89369- atomic_long_t expedited_done_tries; /* # tries to update _done. */
89370- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89371- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89372+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89373+ atomic_long_t expedited_done; /* Done ticket. */
89374+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89375+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89376+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89377+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89378+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89379+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89380+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89381+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89382+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89383
89384 unsigned long jiffies_force_qs; /* Time at which to invoke */
89385 /* force_quiescent_state(). */
89386diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89387index 962d1d5..c6c62d12d 100644
89388--- a/kernel/rcu/tree_plugin.h
89389+++ b/kernel/rcu/tree_plugin.h
89390@@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89391 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89392 {
89393 return !rcu_preempted_readers_exp(rnp) &&
89394- ACCESS_ONCE(rnp->expmask) == 0;
89395+ ACCESS_ONCE_RW(rnp->expmask) == 0;
89396 }
89397
89398 /*
89399@@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89400
89401 /* Clean up and exit. */
89402 smp_mb(); /* ensure expedited GP seen before counter increment. */
89403- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89404+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89405 unlock_mb_ret:
89406 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89407 mb_ret:
89408@@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89409 free_cpumask_var(cm);
89410 }
89411
89412-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89413+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89414 .store = &rcu_cpu_kthread_task,
89415 .thread_should_run = rcu_cpu_kthread_should_run,
89416 .thread_fn = rcu_cpu_kthread,
89417@@ -1972,7 +1972,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89418 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89419 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89420 cpu, ticks_value, ticks_title,
89421- atomic_read(&rdtp->dynticks) & 0xfff,
89422+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89423 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89424 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89425 fast_no_hz);
89426@@ -2138,7 +2138,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89427
89428 /* Enqueue the callback on the nocb list and update counts. */
89429 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89430- ACCESS_ONCE(*old_rhpp) = rhp;
89431+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
89432 atomic_long_add(rhcount, &rdp->nocb_q_count);
89433 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89434
89435@@ -2311,12 +2311,12 @@ static int rcu_nocb_kthread(void *arg)
89436 * Extract queued callbacks, update counts, and wait
89437 * for a grace period to elapse.
89438 */
89439- ACCESS_ONCE(rdp->nocb_head) = NULL;
89440+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89441 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89442 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89443 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89444- ACCESS_ONCE(rdp->nocb_p_count) += c;
89445- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89446+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89447+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89448 rcu_nocb_wait_gp(rdp);
89449
89450 /* Each pass through the following loop invokes a callback. */
89451@@ -2342,8 +2342,8 @@ static int rcu_nocb_kthread(void *arg)
89452 list = next;
89453 }
89454 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89455- ACCESS_ONCE(rdp->nocb_p_count) -= c;
89456- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89457+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89458+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89459 rdp->n_nocbs_invoked += c;
89460 }
89461 return 0;
89462@@ -2360,7 +2360,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89463 {
89464 if (!rcu_nocb_need_deferred_wakeup(rdp))
89465 return;
89466- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89467+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89468 wake_up(&rdp->nocb_wq);
89469 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89470 }
89471@@ -2386,7 +2386,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89472 t = kthread_run(rcu_nocb_kthread, rdp,
89473 "rcuo%c/%d", rsp->abbr, cpu);
89474 BUG_ON(IS_ERR(t));
89475- ACCESS_ONCE(rdp->nocb_kthread) = t;
89476+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89477 }
89478 }
89479
89480@@ -2522,11 +2522,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89481
89482 /* Record start of fully idle period. */
89483 j = jiffies;
89484- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89485+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89486 smp_mb__before_atomic_inc();
89487- atomic_inc(&rdtp->dynticks_idle);
89488+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89489 smp_mb__after_atomic_inc();
89490- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89491+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89492 }
89493
89494 /*
89495@@ -2591,9 +2591,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89496
89497 /* Record end of idle period. */
89498 smp_mb__before_atomic_inc();
89499- atomic_inc(&rdtp->dynticks_idle);
89500+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89501 smp_mb__after_atomic_inc();
89502- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
89503+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
89504
89505 /*
89506 * If we are the timekeeping CPU, we are permitted to be non-idle
89507@@ -2634,7 +2634,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
89508 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
89509
89510 /* Pick up current idle and NMI-nesting counter and check. */
89511- cur = atomic_read(&rdtp->dynticks_idle);
89512+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
89513 if (cur & 0x1) {
89514 *isidle = false; /* We are not idle! */
89515 return;
89516@@ -2697,7 +2697,7 @@ static void rcu_sysidle(unsigned long j)
89517 case RCU_SYSIDLE_NOT:
89518
89519 /* First time all are idle, so note a short idle period. */
89520- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89521+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89522 break;
89523
89524 case RCU_SYSIDLE_SHORT:
89525@@ -2734,7 +2734,7 @@ static void rcu_sysidle(unsigned long j)
89526 static void rcu_sysidle_cancel(void)
89527 {
89528 smp_mb();
89529- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
89530+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
89531 }
89532
89533 /*
89534@@ -2782,7 +2782,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
89535 smp_mb(); /* grace period precedes setting inuse. */
89536
89537 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
89538- ACCESS_ONCE(rshp->inuse) = 0;
89539+ ACCESS_ONCE_RW(rshp->inuse) = 0;
89540 }
89541
89542 /*
89543diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
89544index 5cdc62e..cc52e88 100644
89545--- a/kernel/rcu/tree_trace.c
89546+++ b/kernel/rcu/tree_trace.c
89547@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
89548 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
89549 rdp->passed_quiesce, rdp->qs_pending);
89550 seq_printf(m, " dt=%d/%llx/%d df=%lu",
89551- atomic_read(&rdp->dynticks->dynticks),
89552+ atomic_read_unchecked(&rdp->dynticks->dynticks),
89553 rdp->dynticks->dynticks_nesting,
89554 rdp->dynticks->dynticks_nmi_nesting,
89555 rdp->dynticks_fqs);
89556@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
89557 struct rcu_state *rsp = (struct rcu_state *)m->private;
89558
89559 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",
89560- atomic_long_read(&rsp->expedited_start),
89561+ atomic_long_read_unchecked(&rsp->expedited_start),
89562 atomic_long_read(&rsp->expedited_done),
89563- atomic_long_read(&rsp->expedited_wrap),
89564- atomic_long_read(&rsp->expedited_tryfail),
89565- atomic_long_read(&rsp->expedited_workdone1),
89566- atomic_long_read(&rsp->expedited_workdone2),
89567- atomic_long_read(&rsp->expedited_normal),
89568- atomic_long_read(&rsp->expedited_stoppedcpus),
89569- atomic_long_read(&rsp->expedited_done_tries),
89570- atomic_long_read(&rsp->expedited_done_lost),
89571- atomic_long_read(&rsp->expedited_done_exit));
89572+ atomic_long_read_unchecked(&rsp->expedited_wrap),
89573+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
89574+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
89575+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
89576+ atomic_long_read_unchecked(&rsp->expedited_normal),
89577+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
89578+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
89579+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
89580+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
89581 return 0;
89582 }
89583
89584diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
89585index 4c0a9b0..7e81362 100644
89586--- a/kernel/rcu/update.c
89587+++ b/kernel/rcu/update.c
89588@@ -311,10 +311,10 @@ int rcu_jiffies_till_stall_check(void)
89589 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
89590 */
89591 if (till_stall_check < 3) {
89592- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
89593+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
89594 till_stall_check = 3;
89595 } else if (till_stall_check > 300) {
89596- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
89597+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
89598 till_stall_check = 300;
89599 }
89600 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
89601diff --git a/kernel/resource.c b/kernel/resource.c
89602index 8957d68..770cbe4 100644
89603--- a/kernel/resource.c
89604+++ b/kernel/resource.c
89605@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
89606
89607 static int __init ioresources_init(void)
89608 {
89609+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89610+#ifdef CONFIG_GRKERNSEC_PROC_USER
89611+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
89612+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
89613+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89614+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
89615+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
89616+#endif
89617+#else
89618 proc_create("ioports", 0, NULL, &proc_ioports_operations);
89619 proc_create("iomem", 0, NULL, &proc_iomem_operations);
89620+#endif
89621 return 0;
89622 }
89623 __initcall(ioresources_init);
89624diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
89625index e73efba..c9bfbd4 100644
89626--- a/kernel/sched/auto_group.c
89627+++ b/kernel/sched/auto_group.c
89628@@ -11,7 +11,7 @@
89629
89630 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
89631 static struct autogroup autogroup_default;
89632-static atomic_t autogroup_seq_nr;
89633+static atomic_unchecked_t autogroup_seq_nr;
89634
89635 void __init autogroup_init(struct task_struct *init_task)
89636 {
89637@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
89638
89639 kref_init(&ag->kref);
89640 init_rwsem(&ag->lock);
89641- ag->id = atomic_inc_return(&autogroup_seq_nr);
89642+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
89643 ag->tg = tg;
89644 #ifdef CONFIG_RT_GROUP_SCHED
89645 /*
89646diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
89647index a63f4dc..349bbb0 100644
89648--- a/kernel/sched/completion.c
89649+++ b/kernel/sched/completion.c
89650@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
89651 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89652 * or number of jiffies left till timeout) if completed.
89653 */
89654-long __sched
89655+long __sched __intentional_overflow(-1)
89656 wait_for_completion_interruptible_timeout(struct completion *x,
89657 unsigned long timeout)
89658 {
89659@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
89660 *
89661 * Return: -ERESTARTSYS if interrupted, 0 if completed.
89662 */
89663-int __sched wait_for_completion_killable(struct completion *x)
89664+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
89665 {
89666 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
89667 if (t == -ERESTARTSYS)
89668@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
89669 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89670 * or number of jiffies left till timeout) if completed.
89671 */
89672-long __sched
89673+long __sched __intentional_overflow(-1)
89674 wait_for_completion_killable_timeout(struct completion *x,
89675 unsigned long timeout)
89676 {
89677diff --git a/kernel/sched/core.c b/kernel/sched/core.c
89678index 084d17f..e416b9f 100644
89679--- a/kernel/sched/core.c
89680+++ b/kernel/sched/core.c
89681@@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
89682 int sysctl_numa_balancing(struct ctl_table *table, int write,
89683 void __user *buffer, size_t *lenp, loff_t *ppos)
89684 {
89685- struct ctl_table t;
89686+ ctl_table_no_const t;
89687 int err;
89688 int state = numabalancing_enabled;
89689
89690@@ -2238,8 +2238,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
89691 next->active_mm = oldmm;
89692 atomic_inc(&oldmm->mm_count);
89693 enter_lazy_tlb(oldmm, next);
89694- } else
89695+ } else {
89696 switch_mm(oldmm, mm, next);
89697+ populate_stack();
89698+ }
89699
89700 if (!prev->mm) {
89701 prev->active_mm = NULL;
89702@@ -3004,6 +3006,8 @@ int can_nice(const struct task_struct *p, const int nice)
89703 /* convert nice value [19,-20] to rlimit style value [1,40] */
89704 int nice_rlim = 20 - nice;
89705
89706+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
89707+
89708 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
89709 capable(CAP_SYS_NICE));
89710 }
89711@@ -3037,7 +3041,8 @@ SYSCALL_DEFINE1(nice, int, increment)
89712 if (nice > MAX_NICE)
89713 nice = MAX_NICE;
89714
89715- if (increment < 0 && !can_nice(current, nice))
89716+ if (increment < 0 && (!can_nice(current, nice) ||
89717+ gr_handle_chroot_nice()))
89718 return -EPERM;
89719
89720 retval = security_task_setnice(current, nice);
89721@@ -3310,6 +3315,7 @@ recheck:
89722 if (policy != p->policy && !rlim_rtprio)
89723 return -EPERM;
89724
89725+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
89726 /* can't increase priority */
89727 if (attr->sched_priority > p->rt_priority &&
89728 attr->sched_priority > rlim_rtprio)
89729@@ -4708,6 +4714,7 @@ void idle_task_exit(void)
89730
89731 if (mm != &init_mm) {
89732 switch_mm(mm, &init_mm, current);
89733+ populate_stack();
89734 finish_arch_post_lock_switch();
89735 }
89736 mmdrop(mm);
89737@@ -4803,7 +4810,7 @@ static void migrate_tasks(unsigned int dead_cpu)
89738
89739 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
89740
89741-static struct ctl_table sd_ctl_dir[] = {
89742+static ctl_table_no_const sd_ctl_dir[] __read_only = {
89743 {
89744 .procname = "sched_domain",
89745 .mode = 0555,
89746@@ -4820,17 +4827,17 @@ static struct ctl_table sd_ctl_root[] = {
89747 {}
89748 };
89749
89750-static struct ctl_table *sd_alloc_ctl_entry(int n)
89751+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
89752 {
89753- struct ctl_table *entry =
89754+ ctl_table_no_const *entry =
89755 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
89756
89757 return entry;
89758 }
89759
89760-static void sd_free_ctl_entry(struct ctl_table **tablep)
89761+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
89762 {
89763- struct ctl_table *entry;
89764+ ctl_table_no_const *entry;
89765
89766 /*
89767 * In the intermediate directories, both the child directory and
89768@@ -4838,22 +4845,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
89769 * will always be set. In the lowest directory the names are
89770 * static strings and all have proc handlers.
89771 */
89772- for (entry = *tablep; entry->mode; entry++) {
89773- if (entry->child)
89774- sd_free_ctl_entry(&entry->child);
89775+ for (entry = tablep; entry->mode; entry++) {
89776+ if (entry->child) {
89777+ sd_free_ctl_entry(entry->child);
89778+ pax_open_kernel();
89779+ entry->child = NULL;
89780+ pax_close_kernel();
89781+ }
89782 if (entry->proc_handler == NULL)
89783 kfree(entry->procname);
89784 }
89785
89786- kfree(*tablep);
89787- *tablep = NULL;
89788+ kfree(tablep);
89789 }
89790
89791 static int min_load_idx = 0;
89792 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
89793
89794 static void
89795-set_table_entry(struct ctl_table *entry,
89796+set_table_entry(ctl_table_no_const *entry,
89797 const char *procname, void *data, int maxlen,
89798 umode_t mode, proc_handler *proc_handler,
89799 bool load_idx)
89800@@ -4873,7 +4883,7 @@ set_table_entry(struct ctl_table *entry,
89801 static struct ctl_table *
89802 sd_alloc_ctl_domain_table(struct sched_domain *sd)
89803 {
89804- struct ctl_table *table = sd_alloc_ctl_entry(14);
89805+ ctl_table_no_const *table = sd_alloc_ctl_entry(14);
89806
89807 if (table == NULL)
89808 return NULL;
89809@@ -4911,9 +4921,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
89810 return table;
89811 }
89812
89813-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
89814+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
89815 {
89816- struct ctl_table *entry, *table;
89817+ ctl_table_no_const *entry, *table;
89818 struct sched_domain *sd;
89819 int domain_num = 0, i;
89820 char buf[32];
89821@@ -4940,11 +4950,13 @@ static struct ctl_table_header *sd_sysctl_header;
89822 static void register_sched_domain_sysctl(void)
89823 {
89824 int i, cpu_num = num_possible_cpus();
89825- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
89826+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
89827 char buf[32];
89828
89829 WARN_ON(sd_ctl_dir[0].child);
89830+ pax_open_kernel();
89831 sd_ctl_dir[0].child = entry;
89832+ pax_close_kernel();
89833
89834 if (entry == NULL)
89835 return;
89836@@ -4967,8 +4979,12 @@ static void unregister_sched_domain_sysctl(void)
89837 if (sd_sysctl_header)
89838 unregister_sysctl_table(sd_sysctl_header);
89839 sd_sysctl_header = NULL;
89840- if (sd_ctl_dir[0].child)
89841- sd_free_ctl_entry(&sd_ctl_dir[0].child);
89842+ if (sd_ctl_dir[0].child) {
89843+ sd_free_ctl_entry(sd_ctl_dir[0].child);
89844+ pax_open_kernel();
89845+ sd_ctl_dir[0].child = NULL;
89846+ pax_close_kernel();
89847+ }
89848 }
89849 #else
89850 static void register_sched_domain_sysctl(void)
89851diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89852index 8cbe2d2..61f20a1 100644
89853--- a/kernel/sched/fair.c
89854+++ b/kernel/sched/fair.c
89855@@ -1806,7 +1806,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
89856
89857 static void reset_ptenuma_scan(struct task_struct *p)
89858 {
89859- ACCESS_ONCE(p->mm->numa_scan_seq)++;
89860+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89861 p->mm->numa_scan_offset = 0;
89862 }
89863
89864@@ -7181,7 +7181,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
89865 * run_rebalance_domains is triggered when needed from the scheduler tick.
89866 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89867 */
89868-static void run_rebalance_domains(struct softirq_action *h)
89869+static __latent_entropy void run_rebalance_domains(void)
89870 {
89871 struct rq *this_rq = this_rq();
89872 enum cpu_idle_type idle = this_rq->idle_balance ?
89873diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89874index 369b4d6..fa4eb3b 100644
89875--- a/kernel/sched/sched.h
89876+++ b/kernel/sched/sched.h
89877@@ -1157,7 +1157,7 @@ struct sched_class {
89878 #ifdef CONFIG_FAIR_GROUP_SCHED
89879 void (*task_move_group) (struct task_struct *p, int on_rq);
89880 #endif
89881-};
89882+} __do_const;
89883
89884 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
89885 {
89886diff --git a/kernel/signal.c b/kernel/signal.c
89887index 6ea13c0..31e3b25 100644
89888--- a/kernel/signal.c
89889+++ b/kernel/signal.c
89890@@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
89891
89892 int print_fatal_signals __read_mostly;
89893
89894-static void __user *sig_handler(struct task_struct *t, int sig)
89895+static __sighandler_t sig_handler(struct task_struct *t, int sig)
89896 {
89897 return t->sighand->action[sig - 1].sa.sa_handler;
89898 }
89899
89900-static int sig_handler_ignored(void __user *handler, int sig)
89901+static int sig_handler_ignored(__sighandler_t handler, int sig)
89902 {
89903 /* Is it explicitly or implicitly ignored? */
89904 return handler == SIG_IGN ||
89905@@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
89906
89907 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
89908 {
89909- void __user *handler;
89910+ __sighandler_t handler;
89911
89912 handler = sig_handler(t, sig);
89913
89914@@ -371,6 +371,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
89915 atomic_inc(&user->sigpending);
89916 rcu_read_unlock();
89917
89918+ if (!override_rlimit)
89919+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
89920+
89921 if (override_rlimit ||
89922 atomic_read(&user->sigpending) <=
89923 task_rlimit(t, RLIMIT_SIGPENDING)) {
89924@@ -498,7 +501,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
89925
89926 int unhandled_signal(struct task_struct *tsk, int sig)
89927 {
89928- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
89929+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
89930 if (is_global_init(tsk))
89931 return 1;
89932 if (handler != SIG_IGN && handler != SIG_DFL)
89933@@ -818,6 +821,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89934 }
89935 }
89936
89937+ /* allow glibc communication via tgkill to other threads in our
89938+ thread group */
89939+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
89940+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
89941+ && gr_handle_signal(t, sig))
89942+ return -EPERM;
89943+
89944 return security_task_kill(t, info, sig, 0);
89945 }
89946
89947@@ -1201,7 +1211,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89948 return send_signal(sig, info, p, 1);
89949 }
89950
89951-static int
89952+int
89953 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89954 {
89955 return send_signal(sig, info, t, 0);
89956@@ -1238,6 +1248,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89957 unsigned long int flags;
89958 int ret, blocked, ignored;
89959 struct k_sigaction *action;
89960+ int is_unhandled = 0;
89961
89962 spin_lock_irqsave(&t->sighand->siglock, flags);
89963 action = &t->sighand->action[sig-1];
89964@@ -1252,9 +1263,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89965 }
89966 if (action->sa.sa_handler == SIG_DFL)
89967 t->signal->flags &= ~SIGNAL_UNKILLABLE;
89968+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
89969+ is_unhandled = 1;
89970 ret = specific_send_sig_info(sig, info, t);
89971 spin_unlock_irqrestore(&t->sighand->siglock, flags);
89972
89973+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
89974+ normal operation */
89975+ if (is_unhandled) {
89976+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
89977+ gr_handle_crash(t, sig);
89978+ }
89979+
89980 return ret;
89981 }
89982
89983@@ -1321,8 +1341,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89984 ret = check_kill_permission(sig, info, p);
89985 rcu_read_unlock();
89986
89987- if (!ret && sig)
89988+ if (!ret && sig) {
89989 ret = do_send_sig_info(sig, info, p, true);
89990+ if (!ret)
89991+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
89992+ }
89993
89994 return ret;
89995 }
89996@@ -2928,7 +2951,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
89997 int error = -ESRCH;
89998
89999 rcu_read_lock();
90000- p = find_task_by_vpid(pid);
90001+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90002+ /* allow glibc communication via tgkill to other threads in our
90003+ thread group */
90004+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90005+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
90006+ p = find_task_by_vpid_unrestricted(pid);
90007+ else
90008+#endif
90009+ p = find_task_by_vpid(pid);
90010 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90011 error = check_kill_permission(sig, info, p);
90012 /*
90013@@ -3241,8 +3272,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90014 }
90015 seg = get_fs();
90016 set_fs(KERNEL_DS);
90017- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90018- (stack_t __force __user *) &uoss,
90019+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90020+ (stack_t __force_user *) &uoss,
90021 compat_user_stack_pointer());
90022 set_fs(seg);
90023 if (ret >= 0 && uoss_ptr) {
90024diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90025index eb89e18..a4e6792 100644
90026--- a/kernel/smpboot.c
90027+++ b/kernel/smpboot.c
90028@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90029 }
90030 smpboot_unpark_thread(plug_thread, cpu);
90031 }
90032- list_add(&plug_thread->list, &hotplug_threads);
90033+ pax_list_add(&plug_thread->list, &hotplug_threads);
90034 out:
90035 mutex_unlock(&smpboot_threads_lock);
90036 return ret;
90037@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90038 {
90039 get_online_cpus();
90040 mutex_lock(&smpboot_threads_lock);
90041- list_del(&plug_thread->list);
90042+ pax_list_del(&plug_thread->list);
90043 smpboot_destroy_threads(plug_thread);
90044 mutex_unlock(&smpboot_threads_lock);
90045 put_online_cpus();
90046diff --git a/kernel/softirq.c b/kernel/softirq.c
90047index 92f24f5..db41501 100644
90048--- a/kernel/softirq.c
90049+++ b/kernel/softirq.c
90050@@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90051 EXPORT_SYMBOL(irq_stat);
90052 #endif
90053
90054-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90055+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90056
90057 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90058
90059@@ -268,7 +268,7 @@ restart:
90060 kstat_incr_softirqs_this_cpu(vec_nr);
90061
90062 trace_softirq_entry(vec_nr);
90063- h->action(h);
90064+ h->action();
90065 trace_softirq_exit(vec_nr);
90066 if (unlikely(prev_count != preempt_count())) {
90067 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90068@@ -428,7 +428,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90069 or_softirq_pending(1UL << nr);
90070 }
90071
90072-void open_softirq(int nr, void (*action)(struct softirq_action *))
90073+void __init open_softirq(int nr, void (*action)(void))
90074 {
90075 softirq_vec[nr].action = action;
90076 }
90077@@ -480,7 +480,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90078 }
90079 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90080
90081-static void tasklet_action(struct softirq_action *a)
90082+static void tasklet_action(void)
90083 {
90084 struct tasklet_struct *list;
90085
90086@@ -516,7 +516,7 @@ static void tasklet_action(struct softirq_action *a)
90087 }
90088 }
90089
90090-static void tasklet_hi_action(struct softirq_action *a)
90091+static __latent_entropy void tasklet_hi_action(void)
90092 {
90093 struct tasklet_struct *list;
90094
90095@@ -743,7 +743,7 @@ static struct notifier_block cpu_nfb = {
90096 .notifier_call = cpu_callback
90097 };
90098
90099-static struct smp_hotplug_thread softirq_threads = {
90100+static struct smp_hotplug_thread softirq_threads __read_only = {
90101 .store = &ksoftirqd,
90102 .thread_should_run = ksoftirqd_should_run,
90103 .thread_fn = run_ksoftirqd,
90104diff --git a/kernel/sys.c b/kernel/sys.c
90105index fba0f29..84400e2 100644
90106--- a/kernel/sys.c
90107+++ b/kernel/sys.c
90108@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90109 error = -EACCES;
90110 goto out;
90111 }
90112+
90113+ if (gr_handle_chroot_setpriority(p, niceval)) {
90114+ error = -EACCES;
90115+ goto out;
90116+ }
90117+
90118 no_nice = security_task_setnice(p, niceval);
90119 if (no_nice) {
90120 error = no_nice;
90121@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90122 goto error;
90123 }
90124
90125+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90126+ goto error;
90127+
90128 if (rgid != (gid_t) -1 ||
90129 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90130 new->sgid = new->egid;
90131@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90132 old = current_cred();
90133
90134 retval = -EPERM;
90135+
90136+ if (gr_check_group_change(kgid, kgid, kgid))
90137+ goto error;
90138+
90139 if (ns_capable(old->user_ns, CAP_SETGID))
90140 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90141 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90142@@ -403,7 +416,7 @@ error:
90143 /*
90144 * change the user struct in a credentials set to match the new UID
90145 */
90146-static int set_user(struct cred *new)
90147+int set_user(struct cred *new)
90148 {
90149 struct user_struct *new_user;
90150
90151@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90152 goto error;
90153 }
90154
90155+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90156+ goto error;
90157+
90158 if (!uid_eq(new->uid, old->uid)) {
90159 retval = set_user(new);
90160 if (retval < 0)
90161@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90162 old = current_cred();
90163
90164 retval = -EPERM;
90165+
90166+ if (gr_check_crash_uid(kuid))
90167+ goto error;
90168+ if (gr_check_user_change(kuid, kuid, kuid))
90169+ goto error;
90170+
90171 if (ns_capable(old->user_ns, CAP_SETUID)) {
90172 new->suid = new->uid = kuid;
90173 if (!uid_eq(kuid, old->uid)) {
90174@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90175 goto error;
90176 }
90177
90178+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
90179+ goto error;
90180+
90181 if (ruid != (uid_t) -1) {
90182 new->uid = kruid;
90183 if (!uid_eq(kruid, old->uid)) {
90184@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90185 goto error;
90186 }
90187
90188+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
90189+ goto error;
90190+
90191 if (rgid != (gid_t) -1)
90192 new->gid = krgid;
90193 if (egid != (gid_t) -1)
90194@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90195 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90196 ns_capable(old->user_ns, CAP_SETUID)) {
90197 if (!uid_eq(kuid, old->fsuid)) {
90198+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90199+ goto error;
90200+
90201 new->fsuid = kuid;
90202 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90203 goto change_okay;
90204 }
90205 }
90206
90207+error:
90208 abort_creds(new);
90209 return old_fsuid;
90210
90211@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90212 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90213 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
90214 ns_capable(old->user_ns, CAP_SETGID)) {
90215+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
90216+ goto error;
90217+
90218 if (!gid_eq(kgid, old->fsgid)) {
90219 new->fsgid = kgid;
90220 goto change_okay;
90221 }
90222 }
90223
90224+error:
90225 abort_creds(new);
90226 return old_fsgid;
90227
90228@@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
90229 return -EFAULT;
90230
90231 down_read(&uts_sem);
90232- error = __copy_to_user(&name->sysname, &utsname()->sysname,
90233+ error = __copy_to_user(name->sysname, &utsname()->sysname,
90234 __OLD_UTS_LEN);
90235 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
90236- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
90237+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
90238 __OLD_UTS_LEN);
90239 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
90240- error |= __copy_to_user(&name->release, &utsname()->release,
90241+ error |= __copy_to_user(name->release, &utsname()->release,
90242 __OLD_UTS_LEN);
90243 error |= __put_user(0, name->release + __OLD_UTS_LEN);
90244- error |= __copy_to_user(&name->version, &utsname()->version,
90245+ error |= __copy_to_user(name->version, &utsname()->version,
90246 __OLD_UTS_LEN);
90247 error |= __put_user(0, name->version + __OLD_UTS_LEN);
90248- error |= __copy_to_user(&name->machine, &utsname()->machine,
90249+ error |= __copy_to_user(name->machine, &utsname()->machine,
90250 __OLD_UTS_LEN);
90251 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
90252 up_read(&uts_sem);
90253@@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
90254 */
90255 new_rlim->rlim_cur = 1;
90256 }
90257+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
90258+ is changed to a lower value. Since tasks can be created by the same
90259+ user in between this limit change and an execve by this task, force
90260+ a recheck only for this task by setting PF_NPROC_EXCEEDED
90261+ */
90262+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
90263+ tsk->flags |= PF_NPROC_EXCEEDED;
90264 }
90265 if (!retval) {
90266 if (old_rlim)
90267diff --git a/kernel/sysctl.c b/kernel/sysctl.c
90268index 74f5b58..65ba165 100644
90269--- a/kernel/sysctl.c
90270+++ b/kernel/sysctl.c
90271@@ -94,7 +94,6 @@
90272
90273
90274 #if defined(CONFIG_SYSCTL)
90275-
90276 /* External variables not in a header file. */
90277 extern int max_threads;
90278 extern int suid_dumpable;
90279@@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
90280
90281 /* Constants used for minimum and maximum */
90282 #ifdef CONFIG_LOCKUP_DETECTOR
90283-static int sixty = 60;
90284+static int sixty __read_only = 60;
90285 #endif
90286
90287-static int __maybe_unused neg_one = -1;
90288+static int __maybe_unused neg_one __read_only = -1;
90289
90290-static int zero;
90291-static int __maybe_unused one = 1;
90292-static int __maybe_unused two = 2;
90293-static int __maybe_unused four = 4;
90294-static unsigned long one_ul = 1;
90295-static int one_hundred = 100;
90296+static int zero __read_only = 0;
90297+static int __maybe_unused one __read_only = 1;
90298+static int __maybe_unused two __read_only = 2;
90299+static int __maybe_unused three __read_only = 3;
90300+static int __maybe_unused four __read_only = 4;
90301+static unsigned long one_ul __read_only = 1;
90302+static int one_hundred __read_only = 100;
90303 #ifdef CONFIG_PRINTK
90304-static int ten_thousand = 10000;
90305+static int ten_thousand __read_only = 10000;
90306 #endif
90307
90308 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
90309@@ -179,10 +179,8 @@ static int proc_taint(struct ctl_table *table, int write,
90310 void __user *buffer, size_t *lenp, loff_t *ppos);
90311 #endif
90312
90313-#ifdef CONFIG_PRINTK
90314 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90315 void __user *buffer, size_t *lenp, loff_t *ppos);
90316-#endif
90317
90318 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
90319 void __user *buffer, size_t *lenp, loff_t *ppos);
90320@@ -213,6 +211,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
90321
90322 #endif
90323
90324+extern struct ctl_table grsecurity_table[];
90325+
90326 static struct ctl_table kern_table[];
90327 static struct ctl_table vm_table[];
90328 static struct ctl_table fs_table[];
90329@@ -227,6 +227,20 @@ extern struct ctl_table epoll_table[];
90330 int sysctl_legacy_va_layout;
90331 #endif
90332
90333+#ifdef CONFIG_PAX_SOFTMODE
90334+static ctl_table pax_table[] = {
90335+ {
90336+ .procname = "softmode",
90337+ .data = &pax_softmode,
90338+ .maxlen = sizeof(unsigned int),
90339+ .mode = 0600,
90340+ .proc_handler = &proc_dointvec,
90341+ },
90342+
90343+ { }
90344+};
90345+#endif
90346+
90347 /* The default sysctl tables: */
90348
90349 static struct ctl_table sysctl_base_table[] = {
90350@@ -275,6 +289,22 @@ static int max_extfrag_threshold = 1000;
90351 #endif
90352
90353 static struct ctl_table kern_table[] = {
90354+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
90355+ {
90356+ .procname = "grsecurity",
90357+ .mode = 0500,
90358+ .child = grsecurity_table,
90359+ },
90360+#endif
90361+
90362+#ifdef CONFIG_PAX_SOFTMODE
90363+ {
90364+ .procname = "pax",
90365+ .mode = 0500,
90366+ .child = pax_table,
90367+ },
90368+#endif
90369+
90370 {
90371 .procname = "sched_child_runs_first",
90372 .data = &sysctl_sched_child_runs_first,
90373@@ -630,7 +660,7 @@ static struct ctl_table kern_table[] = {
90374 .data = &modprobe_path,
90375 .maxlen = KMOD_PATH_LEN,
90376 .mode = 0644,
90377- .proc_handler = proc_dostring,
90378+ .proc_handler = proc_dostring_modpriv,
90379 },
90380 {
90381 .procname = "modules_disabled",
90382@@ -797,16 +827,20 @@ static struct ctl_table kern_table[] = {
90383 .extra1 = &zero,
90384 .extra2 = &one,
90385 },
90386+#endif
90387 {
90388 .procname = "kptr_restrict",
90389 .data = &kptr_restrict,
90390 .maxlen = sizeof(int),
90391 .mode = 0644,
90392 .proc_handler = proc_dointvec_minmax_sysadmin,
90393+#ifdef CONFIG_GRKERNSEC_HIDESYM
90394+ .extra1 = &two,
90395+#else
90396 .extra1 = &zero,
90397+#endif
90398 .extra2 = &two,
90399 },
90400-#endif
90401 {
90402 .procname = "ngroups_max",
90403 .data = &ngroups_max,
90404@@ -1051,10 +1085,17 @@ static struct ctl_table kern_table[] = {
90405 */
90406 {
90407 .procname = "perf_event_paranoid",
90408- .data = &sysctl_perf_event_paranoid,
90409- .maxlen = sizeof(sysctl_perf_event_paranoid),
90410+ .data = &sysctl_perf_event_legitimately_concerned,
90411+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90412 .mode = 0644,
90413- .proc_handler = proc_dointvec,
90414+ /* go ahead, be a hero */
90415+ .proc_handler = proc_dointvec_minmax_sysadmin,
90416+ .extra1 = &neg_one,
90417+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90418+ .extra2 = &three,
90419+#else
90420+ .extra2 = &two,
90421+#endif
90422 },
90423 {
90424 .procname = "perf_event_mlock_kb",
90425@@ -1316,6 +1357,13 @@ static struct ctl_table vm_table[] = {
90426 .proc_handler = proc_dointvec_minmax,
90427 .extra1 = &zero,
90428 },
90429+ {
90430+ .procname = "heap_stack_gap",
90431+ .data = &sysctl_heap_stack_gap,
90432+ .maxlen = sizeof(sysctl_heap_stack_gap),
90433+ .mode = 0644,
90434+ .proc_handler = proc_doulongvec_minmax,
90435+ },
90436 #else
90437 {
90438 .procname = "nr_trim_pages",
90439@@ -1780,6 +1828,16 @@ int proc_dostring(struct ctl_table *table, int write,
90440 buffer, lenp, ppos);
90441 }
90442
90443+int proc_dostring_modpriv(struct ctl_table *table, int write,
90444+ void __user *buffer, size_t *lenp, loff_t *ppos)
90445+{
90446+ if (write && !capable(CAP_SYS_MODULE))
90447+ return -EPERM;
90448+
90449+ return _proc_do_string(table->data, table->maxlen, write,
90450+ buffer, lenp, ppos);
90451+}
90452+
90453 static size_t proc_skip_spaces(char **buf)
90454 {
90455 size_t ret;
90456@@ -1885,6 +1943,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90457 len = strlen(tmp);
90458 if (len > *size)
90459 len = *size;
90460+ if (len > sizeof(tmp))
90461+ len = sizeof(tmp);
90462 if (copy_to_user(*buf, tmp, len))
90463 return -EFAULT;
90464 *size -= len;
90465@@ -2049,7 +2109,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90466 static int proc_taint(struct ctl_table *table, int write,
90467 void __user *buffer, size_t *lenp, loff_t *ppos)
90468 {
90469- struct ctl_table t;
90470+ ctl_table_no_const t;
90471 unsigned long tmptaint = get_taint();
90472 int err;
90473
90474@@ -2077,7 +2137,6 @@ static int proc_taint(struct ctl_table *table, int write,
90475 return err;
90476 }
90477
90478-#ifdef CONFIG_PRINTK
90479 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90480 void __user *buffer, size_t *lenp, loff_t *ppos)
90481 {
90482@@ -2086,7 +2145,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90483
90484 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90485 }
90486-#endif
90487
90488 struct do_proc_dointvec_minmax_conv_param {
90489 int *min;
90490@@ -2633,6 +2691,12 @@ int proc_dostring(struct ctl_table *table, int write,
90491 return -ENOSYS;
90492 }
90493
90494+int proc_dostring_modpriv(struct ctl_table *table, int write,
90495+ void __user *buffer, size_t *lenp, loff_t *ppos)
90496+{
90497+ return -ENOSYS;
90498+}
90499+
90500 int proc_dointvec(struct ctl_table *table, int write,
90501 void __user *buffer, size_t *lenp, loff_t *ppos)
90502 {
90503@@ -2689,5 +2753,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
90504 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
90505 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
90506 EXPORT_SYMBOL(proc_dostring);
90507+EXPORT_SYMBOL(proc_dostring_modpriv);
90508 EXPORT_SYMBOL(proc_doulongvec_minmax);
90509 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
90510diff --git a/kernel/taskstats.c b/kernel/taskstats.c
90511index 13d2f7c..c93d0b0 100644
90512--- a/kernel/taskstats.c
90513+++ b/kernel/taskstats.c
90514@@ -28,9 +28,12 @@
90515 #include <linux/fs.h>
90516 #include <linux/file.h>
90517 #include <linux/pid_namespace.h>
90518+#include <linux/grsecurity.h>
90519 #include <net/genetlink.h>
90520 #include <linux/atomic.h>
90521
90522+extern int gr_is_taskstats_denied(int pid);
90523+
90524 /*
90525 * Maximum length of a cpumask that can be specified in
90526 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
90527@@ -576,6 +579,9 @@ err:
90528
90529 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
90530 {
90531+ if (gr_is_taskstats_denied(current->pid))
90532+ return -EACCES;
90533+
90534 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
90535 return cmd_attr_register_cpumask(info);
90536 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
90537diff --git a/kernel/time.c b/kernel/time.c
90538index 7c7964c..2a0d412 100644
90539--- a/kernel/time.c
90540+++ b/kernel/time.c
90541@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
90542 return error;
90543
90544 if (tz) {
90545+ /* we log in do_settimeofday called below, so don't log twice
90546+ */
90547+ if (!tv)
90548+ gr_log_timechange();
90549+
90550 sys_tz = *tz;
90551 update_vsyscall_tz();
90552 if (firsttime) {
90553diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
90554index 88c9c65..7497ebc 100644
90555--- a/kernel/time/alarmtimer.c
90556+++ b/kernel/time/alarmtimer.c
90557@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
90558 struct platform_device *pdev;
90559 int error = 0;
90560 int i;
90561- struct k_clock alarm_clock = {
90562+ static struct k_clock alarm_clock = {
90563 .clock_getres = alarm_clock_getres,
90564 .clock_get = alarm_clock_get,
90565 .timer_create = alarm_timer_create,
90566diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
90567index f7df8ea..0810193 100644
90568--- a/kernel/time/timekeeping.c
90569+++ b/kernel/time/timekeeping.c
90570@@ -15,6 +15,7 @@
90571 #include <linux/init.h>
90572 #include <linux/mm.h>
90573 #include <linux/sched.h>
90574+#include <linux/grsecurity.h>
90575 #include <linux/syscore_ops.h>
90576 #include <linux/clocksource.h>
90577 #include <linux/jiffies.h>
90578@@ -502,6 +503,8 @@ int do_settimeofday(const struct timespec *tv)
90579 if (!timespec_valid_strict(tv))
90580 return -EINVAL;
90581
90582+ gr_log_timechange();
90583+
90584 raw_spin_lock_irqsave(&timekeeper_lock, flags);
90585 write_seqcount_begin(&timekeeper_seq);
90586
90587diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
90588index 61ed862..3b52c65 100644
90589--- a/kernel/time/timer_list.c
90590+++ b/kernel/time/timer_list.c
90591@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
90592
90593 static void print_name_offset(struct seq_file *m, void *sym)
90594 {
90595+#ifdef CONFIG_GRKERNSEC_HIDESYM
90596+ SEQ_printf(m, "<%p>", NULL);
90597+#else
90598 char symname[KSYM_NAME_LEN];
90599
90600 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
90601 SEQ_printf(m, "<%pK>", sym);
90602 else
90603 SEQ_printf(m, "%s", symname);
90604+#endif
90605 }
90606
90607 static void
90608@@ -119,7 +123,11 @@ next_one:
90609 static void
90610 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
90611 {
90612+#ifdef CONFIG_GRKERNSEC_HIDESYM
90613+ SEQ_printf(m, " .base: %p\n", NULL);
90614+#else
90615 SEQ_printf(m, " .base: %pK\n", base);
90616+#endif
90617 SEQ_printf(m, " .index: %d\n",
90618 base->index);
90619 SEQ_printf(m, " .resolution: %Lu nsecs\n",
90620@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
90621 {
90622 struct proc_dir_entry *pe;
90623
90624+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90625+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
90626+#else
90627 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
90628+#endif
90629 if (!pe)
90630 return -ENOMEM;
90631 return 0;
90632diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
90633index 1fb08f2..ca4bb1e 100644
90634--- a/kernel/time/timer_stats.c
90635+++ b/kernel/time/timer_stats.c
90636@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
90637 static unsigned long nr_entries;
90638 static struct entry entries[MAX_ENTRIES];
90639
90640-static atomic_t overflow_count;
90641+static atomic_unchecked_t overflow_count;
90642
90643 /*
90644 * The entries are in a hash-table, for fast lookup:
90645@@ -140,7 +140,7 @@ static void reset_entries(void)
90646 nr_entries = 0;
90647 memset(entries, 0, sizeof(entries));
90648 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
90649- atomic_set(&overflow_count, 0);
90650+ atomic_set_unchecked(&overflow_count, 0);
90651 }
90652
90653 static struct entry *alloc_entry(void)
90654@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90655 if (likely(entry))
90656 entry->count++;
90657 else
90658- atomic_inc(&overflow_count);
90659+ atomic_inc_unchecked(&overflow_count);
90660
90661 out_unlock:
90662 raw_spin_unlock_irqrestore(lock, flags);
90663@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90664
90665 static void print_name_offset(struct seq_file *m, unsigned long addr)
90666 {
90667+#ifdef CONFIG_GRKERNSEC_HIDESYM
90668+ seq_printf(m, "<%p>", NULL);
90669+#else
90670 char symname[KSYM_NAME_LEN];
90671
90672 if (lookup_symbol_name(addr, symname) < 0)
90673- seq_printf(m, "<%p>", (void *)addr);
90674+ seq_printf(m, "<%pK>", (void *)addr);
90675 else
90676 seq_printf(m, "%s", symname);
90677+#endif
90678 }
90679
90680 static int tstats_show(struct seq_file *m, void *v)
90681@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
90682
90683 seq_puts(m, "Timer Stats Version: v0.3\n");
90684 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
90685- if (atomic_read(&overflow_count))
90686- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
90687+ if (atomic_read_unchecked(&overflow_count))
90688+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
90689 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
90690
90691 for (i = 0; i < nr_entries; i++) {
90692@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
90693 {
90694 struct proc_dir_entry *pe;
90695
90696+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90697+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
90698+#else
90699 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
90700+#endif
90701 if (!pe)
90702 return -ENOMEM;
90703 return 0;
90704diff --git a/kernel/timer.c b/kernel/timer.c
90705index 3bb01a3..0e7760e 100644
90706--- a/kernel/timer.c
90707+++ b/kernel/timer.c
90708@@ -1393,7 +1393,7 @@ void update_process_times(int user_tick)
90709 /*
90710 * This function runs timers and the timer-tq in bottom half context.
90711 */
90712-static void run_timer_softirq(struct softirq_action *h)
90713+static __latent_entropy void run_timer_softirq(void)
90714 {
90715 struct tvec_base *base = __this_cpu_read(tvec_bases);
90716
90717@@ -1456,7 +1456,7 @@ static void process_timeout(unsigned long __data)
90718 *
90719 * In all cases the return value is guaranteed to be non-negative.
90720 */
90721-signed long __sched schedule_timeout(signed long timeout)
90722+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
90723 {
90724 struct timer_list timer;
90725 unsigned long expire;
90726diff --git a/kernel/torture.c b/kernel/torture.c
90727index acc9afc..4f9eb49 100644
90728--- a/kernel/torture.c
90729+++ b/kernel/torture.c
90730@@ -489,7 +489,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
90731 mutex_lock(&fullstop_mutex);
90732 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
90733 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
90734- ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
90735+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
90736 } else {
90737 pr_warn("Concurrent rmmod and shutdown illegal!\n");
90738 }
90739@@ -551,11 +551,11 @@ static int torture_stutter(void *arg)
90740 do {
90741 if (!torture_must_stop()) {
90742 schedule_timeout_interruptible(stutter);
90743- ACCESS_ONCE(stutter_pause_test) = 1;
90744+ ACCESS_ONCE_RW(stutter_pause_test) = 1;
90745 }
90746 if (!torture_must_stop())
90747 schedule_timeout_interruptible(stutter);
90748- ACCESS_ONCE(stutter_pause_test) = 0;
90749+ ACCESS_ONCE_RW(stutter_pause_test) = 0;
90750 torture_shutdown_absorb("torture_stutter");
90751 } while (!torture_must_stop());
90752 torture_kthread_stopping("torture_stutter");
90753@@ -636,7 +636,7 @@ bool torture_cleanup(void)
90754 schedule_timeout_uninterruptible(10);
90755 return true;
90756 }
90757- ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
90758+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
90759 mutex_unlock(&fullstop_mutex);
90760 torture_shutdown_cleanup();
90761 torture_shuffle_cleanup();
90762diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
90763index c1bd4ad..4b861dc 100644
90764--- a/kernel/trace/blktrace.c
90765+++ b/kernel/trace/blktrace.c
90766@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
90767 struct blk_trace *bt = filp->private_data;
90768 char buf[16];
90769
90770- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
90771+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
90772
90773 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
90774 }
90775@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
90776 return 1;
90777
90778 bt = buf->chan->private_data;
90779- atomic_inc(&bt->dropped);
90780+ atomic_inc_unchecked(&bt->dropped);
90781 return 0;
90782 }
90783
90784@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
90785
90786 bt->dir = dir;
90787 bt->dev = dev;
90788- atomic_set(&bt->dropped, 0);
90789+ atomic_set_unchecked(&bt->dropped, 0);
90790 INIT_LIST_HEAD(&bt->running_list);
90791
90792 ret = -EIO;
90793diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
90794index 4a54a25..7ca9c89 100644
90795--- a/kernel/trace/ftrace.c
90796+++ b/kernel/trace/ftrace.c
90797@@ -1960,12 +1960,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
90798 if (unlikely(ftrace_disabled))
90799 return 0;
90800
90801+ ret = ftrace_arch_code_modify_prepare();
90802+ FTRACE_WARN_ON(ret);
90803+ if (ret)
90804+ return 0;
90805+
90806 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
90807+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
90808 if (ret) {
90809 ftrace_bug(ret, ip);
90810- return 0;
90811 }
90812- return 1;
90813+ return ret ? 0 : 1;
90814 }
90815
90816 /*
90817@@ -4195,8 +4200,10 @@ static int ftrace_process_locs(struct module *mod,
90818 if (!count)
90819 return 0;
90820
90821+ pax_open_kernel();
90822 sort(start, count, sizeof(*start),
90823 ftrace_cmp_ips, ftrace_swap_ips);
90824+ pax_close_kernel();
90825
90826 start_pg = ftrace_allocate_pages(count);
90827 if (!start_pg)
90828@@ -4908,8 +4915,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
90829 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
90830
90831 static int ftrace_graph_active;
90832-static struct notifier_block ftrace_suspend_notifier;
90833-
90834 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
90835 {
90836 return 0;
90837@@ -5085,6 +5090,10 @@ static void update_function_graph_func(void)
90838 ftrace_graph_entry = ftrace_graph_entry_test;
90839 }
90840
90841+static struct notifier_block ftrace_suspend_notifier = {
90842+ .notifier_call = ftrace_suspend_notifier_call
90843+};
90844+
90845 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90846 trace_func_graph_ent_t entryfunc)
90847 {
90848@@ -5098,7 +5107,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90849 goto out;
90850 }
90851
90852- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
90853 register_pm_notifier(&ftrace_suspend_notifier);
90854
90855 ftrace_graph_active++;
90856diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
90857index c634868..00d0d19 100644
90858--- a/kernel/trace/ring_buffer.c
90859+++ b/kernel/trace/ring_buffer.c
90860@@ -352,9 +352,9 @@ struct buffer_data_page {
90861 */
90862 struct buffer_page {
90863 struct list_head list; /* list of buffer pages */
90864- local_t write; /* index for next write */
90865+ local_unchecked_t write; /* index for next write */
90866 unsigned read; /* index for next read */
90867- local_t entries; /* entries on this page */
90868+ local_unchecked_t entries; /* entries on this page */
90869 unsigned long real_end; /* real end of data */
90870 struct buffer_data_page *page; /* Actual data page */
90871 };
90872@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
90873 unsigned long last_overrun;
90874 local_t entries_bytes;
90875 local_t entries;
90876- local_t overrun;
90877- local_t commit_overrun;
90878+ local_unchecked_t overrun;
90879+ local_unchecked_t commit_overrun;
90880 local_t dropped_events;
90881 local_t committing;
90882 local_t commits;
90883@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90884 *
90885 * We add a counter to the write field to denote this.
90886 */
90887- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
90888- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
90889+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
90890+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
90891
90892 /*
90893 * Just make sure we have seen our old_write and synchronize
90894@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90895 * cmpxchg to only update if an interrupt did not already
90896 * do it for us. If the cmpxchg fails, we don't care.
90897 */
90898- (void)local_cmpxchg(&next_page->write, old_write, val);
90899- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90900+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90901+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90902
90903 /*
90904 * No need to worry about races with clearing out the commit.
90905@@ -1389,12 +1389,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90906
90907 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90908 {
90909- return local_read(&bpage->entries) & RB_WRITE_MASK;
90910+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90911 }
90912
90913 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90914 {
90915- return local_read(&bpage->write) & RB_WRITE_MASK;
90916+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90917 }
90918
90919 static int
90920@@ -1489,7 +1489,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90921 * bytes consumed in ring buffer from here.
90922 * Increment overrun to account for the lost events.
90923 */
90924- local_add(page_entries, &cpu_buffer->overrun);
90925+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
90926 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90927 }
90928
90929@@ -2067,7 +2067,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
90930 * it is our responsibility to update
90931 * the counters.
90932 */
90933- local_add(entries, &cpu_buffer->overrun);
90934+ local_add_unchecked(entries, &cpu_buffer->overrun);
90935 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90936
90937 /*
90938@@ -2217,7 +2217,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90939 if (tail == BUF_PAGE_SIZE)
90940 tail_page->real_end = 0;
90941
90942- local_sub(length, &tail_page->write);
90943+ local_sub_unchecked(length, &tail_page->write);
90944 return;
90945 }
90946
90947@@ -2252,7 +2252,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90948 rb_event_set_padding(event);
90949
90950 /* Set the write back to the previous setting */
90951- local_sub(length, &tail_page->write);
90952+ local_sub_unchecked(length, &tail_page->write);
90953 return;
90954 }
90955
90956@@ -2264,7 +2264,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90957
90958 /* Set write to end of buffer */
90959 length = (tail + length) - BUF_PAGE_SIZE;
90960- local_sub(length, &tail_page->write);
90961+ local_sub_unchecked(length, &tail_page->write);
90962 }
90963
90964 /*
90965@@ -2290,7 +2290,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90966 * about it.
90967 */
90968 if (unlikely(next_page == commit_page)) {
90969- local_inc(&cpu_buffer->commit_overrun);
90970+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90971 goto out_reset;
90972 }
90973
90974@@ -2346,7 +2346,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90975 cpu_buffer->tail_page) &&
90976 (cpu_buffer->commit_page ==
90977 cpu_buffer->reader_page))) {
90978- local_inc(&cpu_buffer->commit_overrun);
90979+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90980 goto out_reset;
90981 }
90982 }
90983@@ -2394,7 +2394,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90984 length += RB_LEN_TIME_EXTEND;
90985
90986 tail_page = cpu_buffer->tail_page;
90987- write = local_add_return(length, &tail_page->write);
90988+ write = local_add_return_unchecked(length, &tail_page->write);
90989
90990 /* set write to only the index of the write */
90991 write &= RB_WRITE_MASK;
90992@@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90993 kmemcheck_annotate_bitfield(event, bitfield);
90994 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
90995
90996- local_inc(&tail_page->entries);
90997+ local_inc_unchecked(&tail_page->entries);
90998
90999 /*
91000 * If this is the first commit on the page, then update
91001@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91002
91003 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91004 unsigned long write_mask =
91005- local_read(&bpage->write) & ~RB_WRITE_MASK;
91006+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91007 unsigned long event_length = rb_event_length(event);
91008 /*
91009 * This is on the tail page. It is possible that
91010@@ -2461,7 +2461,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91011 */
91012 old_index += write_mask;
91013 new_index += write_mask;
91014- index = local_cmpxchg(&bpage->write, old_index, new_index);
91015+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91016 if (index == old_index) {
91017 /* update counters */
91018 local_sub(event_length, &cpu_buffer->entries_bytes);
91019@@ -2853,7 +2853,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91020
91021 /* Do the likely case first */
91022 if (likely(bpage->page == (void *)addr)) {
91023- local_dec(&bpage->entries);
91024+ local_dec_unchecked(&bpage->entries);
91025 return;
91026 }
91027
91028@@ -2865,7 +2865,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91029 start = bpage;
91030 do {
91031 if (bpage->page == (void *)addr) {
91032- local_dec(&bpage->entries);
91033+ local_dec_unchecked(&bpage->entries);
91034 return;
91035 }
91036 rb_inc_page(cpu_buffer, &bpage);
91037@@ -3149,7 +3149,7 @@ static inline unsigned long
91038 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91039 {
91040 return local_read(&cpu_buffer->entries) -
91041- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91042+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91043 }
91044
91045 /**
91046@@ -3238,7 +3238,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91047 return 0;
91048
91049 cpu_buffer = buffer->buffers[cpu];
91050- ret = local_read(&cpu_buffer->overrun);
91051+ ret = local_read_unchecked(&cpu_buffer->overrun);
91052
91053 return ret;
91054 }
91055@@ -3261,7 +3261,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91056 return 0;
91057
91058 cpu_buffer = buffer->buffers[cpu];
91059- ret = local_read(&cpu_buffer->commit_overrun);
91060+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91061
91062 return ret;
91063 }
91064@@ -3346,7 +3346,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91065 /* if you care about this being correct, lock the buffer */
91066 for_each_buffer_cpu(buffer, cpu) {
91067 cpu_buffer = buffer->buffers[cpu];
91068- overruns += local_read(&cpu_buffer->overrun);
91069+ overruns += local_read_unchecked(&cpu_buffer->overrun);
91070 }
91071
91072 return overruns;
91073@@ -3522,8 +3522,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91074 /*
91075 * Reset the reader page to size zero.
91076 */
91077- local_set(&cpu_buffer->reader_page->write, 0);
91078- local_set(&cpu_buffer->reader_page->entries, 0);
91079+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91080+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91081 local_set(&cpu_buffer->reader_page->page->commit, 0);
91082 cpu_buffer->reader_page->real_end = 0;
91083
91084@@ -3557,7 +3557,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91085 * want to compare with the last_overrun.
91086 */
91087 smp_mb();
91088- overwrite = local_read(&(cpu_buffer->overrun));
91089+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91090
91091 /*
91092 * Here's the tricky part.
91093@@ -4127,8 +4127,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91094
91095 cpu_buffer->head_page
91096 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91097- local_set(&cpu_buffer->head_page->write, 0);
91098- local_set(&cpu_buffer->head_page->entries, 0);
91099+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
91100+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91101 local_set(&cpu_buffer->head_page->page->commit, 0);
91102
91103 cpu_buffer->head_page->read = 0;
91104@@ -4138,14 +4138,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91105
91106 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91107 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91108- local_set(&cpu_buffer->reader_page->write, 0);
91109- local_set(&cpu_buffer->reader_page->entries, 0);
91110+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91111+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91112 local_set(&cpu_buffer->reader_page->page->commit, 0);
91113 cpu_buffer->reader_page->read = 0;
91114
91115 local_set(&cpu_buffer->entries_bytes, 0);
91116- local_set(&cpu_buffer->overrun, 0);
91117- local_set(&cpu_buffer->commit_overrun, 0);
91118+ local_set_unchecked(&cpu_buffer->overrun, 0);
91119+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91120 local_set(&cpu_buffer->dropped_events, 0);
91121 local_set(&cpu_buffer->entries, 0);
91122 local_set(&cpu_buffer->committing, 0);
91123@@ -4550,8 +4550,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91124 rb_init_page(bpage);
91125 bpage = reader->page;
91126 reader->page = *data_page;
91127- local_set(&reader->write, 0);
91128- local_set(&reader->entries, 0);
91129+ local_set_unchecked(&reader->write, 0);
91130+ local_set_unchecked(&reader->entries, 0);
91131 reader->read = 0;
91132 *data_page = bpage;
91133
91134diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91135index 737b0ef..bd21ea6 100644
91136--- a/kernel/trace/trace.c
91137+++ b/kernel/trace/trace.c
91138@@ -3448,7 +3448,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91139 return 0;
91140 }
91141
91142-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91143+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91144 {
91145 /* do nothing if flag is already set */
91146 if (!!(trace_flags & mask) == !!enabled)
91147diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91148index 2e29d7b..61367d7 100644
91149--- a/kernel/trace/trace.h
91150+++ b/kernel/trace/trace.h
91151@@ -1264,7 +1264,7 @@ extern const char *__stop___tracepoint_str[];
91152 void trace_printk_init_buffers(void);
91153 void trace_printk_start_comm(void);
91154 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91155-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91156+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91157
91158 /*
91159 * Normal trace_printk() and friends allocates special buffers
91160diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91161index 26dc348..8708ca7 100644
91162--- a/kernel/trace/trace_clock.c
91163+++ b/kernel/trace/trace_clock.c
91164@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
91165 return now;
91166 }
91167
91168-static atomic64_t trace_counter;
91169+static atomic64_unchecked_t trace_counter;
91170
91171 /*
91172 * trace_clock_counter(): simply an atomic counter.
91173@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
91174 */
91175 u64 notrace trace_clock_counter(void)
91176 {
91177- return atomic64_add_return(1, &trace_counter);
91178+ return atomic64_inc_return_unchecked(&trace_counter);
91179 }
91180diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91181index 3ddfd8f..41a10fe 100644
91182--- a/kernel/trace/trace_events.c
91183+++ b/kernel/trace/trace_events.c
91184@@ -1718,7 +1718,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91185 return 0;
91186 }
91187
91188-struct ftrace_module_file_ops;
91189 static void __add_event_to_tracers(struct ftrace_event_call *call);
91190
91191 /* Add an additional event_call dynamically */
91192diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91193index 0abd9b8..6a663a2 100644
91194--- a/kernel/trace/trace_mmiotrace.c
91195+++ b/kernel/trace/trace_mmiotrace.c
91196@@ -24,7 +24,7 @@ struct header_iter {
91197 static struct trace_array *mmio_trace_array;
91198 static bool overrun_detected;
91199 static unsigned long prev_overruns;
91200-static atomic_t dropped_count;
91201+static atomic_unchecked_t dropped_count;
91202
91203 static void mmio_reset_data(struct trace_array *tr)
91204 {
91205@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91206
91207 static unsigned long count_overruns(struct trace_iterator *iter)
91208 {
91209- unsigned long cnt = atomic_xchg(&dropped_count, 0);
91210+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91211 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91212
91213 if (over > prev_overruns)
91214@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
91215 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
91216 sizeof(*entry), 0, pc);
91217 if (!event) {
91218- atomic_inc(&dropped_count);
91219+ atomic_inc_unchecked(&dropped_count);
91220 return;
91221 }
91222 entry = ring_buffer_event_data(event);
91223@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
91224 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
91225 sizeof(*entry), 0, pc);
91226 if (!event) {
91227- atomic_inc(&dropped_count);
91228+ atomic_inc_unchecked(&dropped_count);
91229 return;
91230 }
91231 entry = ring_buffer_event_data(event);
91232diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
91233index a436de1..f64dde2 100644
91234--- a/kernel/trace/trace_output.c
91235+++ b/kernel/trace/trace_output.c
91236@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
91237
91238 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
91239 if (!IS_ERR(p)) {
91240- p = mangle_path(s->buffer + s->len, p, "\n");
91241+ p = mangle_path(s->buffer + s->len, p, "\n\\");
91242 if (p) {
91243 s->len = p - s->buffer;
91244 return 1;
91245@@ -939,14 +939,16 @@ int register_ftrace_event(struct trace_event *event)
91246 goto out;
91247 }
91248
91249+ pax_open_kernel();
91250 if (event->funcs->trace == NULL)
91251- event->funcs->trace = trace_nop_print;
91252+ *(void **)&event->funcs->trace = trace_nop_print;
91253 if (event->funcs->raw == NULL)
91254- event->funcs->raw = trace_nop_print;
91255+ *(void **)&event->funcs->raw = trace_nop_print;
91256 if (event->funcs->hex == NULL)
91257- event->funcs->hex = trace_nop_print;
91258+ *(void **)&event->funcs->hex = trace_nop_print;
91259 if (event->funcs->binary == NULL)
91260- event->funcs->binary = trace_nop_print;
91261+ *(void **)&event->funcs->binary = trace_nop_print;
91262+ pax_close_kernel();
91263
91264 key = event->type & (EVENT_HASHSIZE - 1);
91265
91266diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
91267index 21b320e..40607bc 100644
91268--- a/kernel/trace/trace_stack.c
91269+++ b/kernel/trace/trace_stack.c
91270@@ -69,7 +69,7 @@ check_stack(unsigned long ip, unsigned long *stack)
91271 return;
91272
91273 /* we do not handle interrupt stacks yet */
91274- if (!object_is_on_stack(stack))
91275+ if (!object_starts_on_stack(stack))
91276 return;
91277
91278 local_irq_save(flags);
91279diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
91280index bf71b4b..04dee68 100644
91281--- a/kernel/user_namespace.c
91282+++ b/kernel/user_namespace.c
91283@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
91284 !kgid_has_mapping(parent_ns, group))
91285 return -EPERM;
91286
91287+#ifdef CONFIG_GRKERNSEC
91288+ /*
91289+ * This doesn't really inspire confidence:
91290+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
91291+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
91292+ * Increases kernel attack surface in areas developers
91293+ * previously cared little about ("low importance due
91294+ * to requiring "root" capability")
91295+ * To be removed when this code receives *proper* review
91296+ */
91297+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
91298+ !capable(CAP_SETGID))
91299+ return -EPERM;
91300+#endif
91301+
91302 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
91303 if (!ns)
91304 return -ENOMEM;
91305@@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
91306 if (atomic_read(&current->mm->mm_users) > 1)
91307 return -EINVAL;
91308
91309- if (current->fs->users != 1)
91310+ if (atomic_read(&current->fs->users) != 1)
91311 return -EINVAL;
91312
91313 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
91314diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
91315index 4f69f9a..7c6f8f8 100644
91316--- a/kernel/utsname_sysctl.c
91317+++ b/kernel/utsname_sysctl.c
91318@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
91319 static int proc_do_uts_string(ctl_table *table, int write,
91320 void __user *buffer, size_t *lenp, loff_t *ppos)
91321 {
91322- struct ctl_table uts_table;
91323+ ctl_table_no_const uts_table;
91324 int r;
91325 memcpy(&uts_table, table, sizeof(uts_table));
91326 uts_table.data = get_uts(table, write);
91327diff --git a/kernel/watchdog.c b/kernel/watchdog.c
91328index 516203e..ecc58d1 100644
91329--- a/kernel/watchdog.c
91330+++ b/kernel/watchdog.c
91331@@ -479,7 +479,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
91332 static void watchdog_nmi_disable(unsigned int cpu) { return; }
91333 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
91334
91335-static struct smp_hotplug_thread watchdog_threads = {
91336+static struct smp_hotplug_thread watchdog_threads __read_only = {
91337 .store = &softlockup_watchdog,
91338 .thread_should_run = watchdog_should_run,
91339 .thread_fn = watchdog,
91340diff --git a/kernel/workqueue.c b/kernel/workqueue.c
91341index 8edc8718..b6a70b9 100644
91342--- a/kernel/workqueue.c
91343+++ b/kernel/workqueue.c
91344@@ -4709,7 +4709,7 @@ static void rebind_workers(struct worker_pool *pool)
91345 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
91346 worker_flags |= WORKER_REBOUND;
91347 worker_flags &= ~WORKER_UNBOUND;
91348- ACCESS_ONCE(worker->flags) = worker_flags;
91349+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
91350 }
91351
91352 spin_unlock_irq(&pool->lock);
91353diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
91354index 819ac51..1c8a65e 100644
91355--- a/lib/Kconfig.debug
91356+++ b/lib/Kconfig.debug
91357@@ -853,7 +853,7 @@ config DEBUG_MUTEXES
91358
91359 config DEBUG_WW_MUTEX_SLOWPATH
91360 bool "Wait/wound mutex debugging: Slowpath testing"
91361- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91362+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91363 select DEBUG_LOCK_ALLOC
91364 select DEBUG_SPINLOCK
91365 select DEBUG_MUTEXES
91366@@ -866,7 +866,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
91367
91368 config DEBUG_LOCK_ALLOC
91369 bool "Lock debugging: detect incorrect freeing of live locks"
91370- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91371+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91372 select DEBUG_SPINLOCK
91373 select DEBUG_MUTEXES
91374 select LOCKDEP
91375@@ -880,7 +880,7 @@ config DEBUG_LOCK_ALLOC
91376
91377 config PROVE_LOCKING
91378 bool "Lock debugging: prove locking correctness"
91379- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91380+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91381 select LOCKDEP
91382 select DEBUG_SPINLOCK
91383 select DEBUG_MUTEXES
91384@@ -931,7 +931,7 @@ config LOCKDEP
91385
91386 config LOCK_STAT
91387 bool "Lock usage statistics"
91388- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91389+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91390 select LOCKDEP
91391 select DEBUG_SPINLOCK
91392 select DEBUG_MUTEXES
91393@@ -1403,6 +1403,7 @@ config LATENCYTOP
91394 depends on DEBUG_KERNEL
91395 depends on STACKTRACE_SUPPORT
91396 depends on PROC_FS
91397+ depends on !GRKERNSEC_HIDESYM
91398 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
91399 select KALLSYMS
91400 select KALLSYMS_ALL
91401@@ -1419,7 +1420,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91402 config DEBUG_STRICT_USER_COPY_CHECKS
91403 bool "Strict user copy size checks"
91404 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91405- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
91406+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
91407 help
91408 Enabling this option turns a certain set of sanity checks for user
91409 copy operations into compile time failures.
91410@@ -1538,7 +1539,7 @@ endmenu # runtime tests
91411
91412 config PROVIDE_OHCI1394_DMA_INIT
91413 bool "Remote debugging over FireWire early on boot"
91414- depends on PCI && X86
91415+ depends on PCI && X86 && !GRKERNSEC
91416 help
91417 If you want to debug problems which hang or crash the kernel early
91418 on boot and the crashing machine has a FireWire port, you can use
91419diff --git a/lib/Makefile b/lib/Makefile
91420index 0cd7b68..e149e37 100644
91421--- a/lib/Makefile
91422+++ b/lib/Makefile
91423@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91424 obj-$(CONFIG_BTREE) += btree.o
91425 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91426 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91427-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91428+obj-y += list_debug.o
91429 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91430
91431 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91432diff --git a/lib/average.c b/lib/average.c
91433index 114d1be..ab0350c 100644
91434--- a/lib/average.c
91435+++ b/lib/average.c
91436@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91437 {
91438 unsigned long internal = ACCESS_ONCE(avg->internal);
91439
91440- ACCESS_ONCE(avg->internal) = internal ?
91441+ ACCESS_ONCE_RW(avg->internal) = internal ?
91442 (((internal << avg->weight) - internal) +
91443 (val << avg->factor)) >> avg->weight :
91444 (val << avg->factor);
91445diff --git a/lib/bitmap.c b/lib/bitmap.c
91446index 06f7e4f..f3cf2b0 100644
91447--- a/lib/bitmap.c
91448+++ b/lib/bitmap.c
91449@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91450 {
91451 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91452 u32 chunk;
91453- const char __user __force *ubuf = (const char __user __force *)buf;
91454+ const char __user *ubuf = (const char __force_user *)buf;
91455
91456 bitmap_zero(maskp, nmaskbits);
91457
91458@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91459 {
91460 if (!access_ok(VERIFY_READ, ubuf, ulen))
91461 return -EFAULT;
91462- return __bitmap_parse((const char __force *)ubuf,
91463+ return __bitmap_parse((const char __force_kernel *)ubuf,
91464 ulen, 1, maskp, nmaskbits);
91465
91466 }
91467@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91468 {
91469 unsigned a, b;
91470 int c, old_c, totaldigits;
91471- const char __user __force *ubuf = (const char __user __force *)buf;
91472+ const char __user *ubuf = (const char __force_user *)buf;
91473 int exp_digit, in_range;
91474
91475 totaldigits = c = 0;
91476@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
91477 {
91478 if (!access_ok(VERIFY_READ, ubuf, ulen))
91479 return -EFAULT;
91480- return __bitmap_parselist((const char __force *)ubuf,
91481+ return __bitmap_parselist((const char __force_kernel *)ubuf,
91482 ulen, 1, maskp, nmaskbits);
91483 }
91484 EXPORT_SYMBOL(bitmap_parselist_user);
91485diff --git a/lib/bug.c b/lib/bug.c
91486index 1686034..a9c00c8 100644
91487--- a/lib/bug.c
91488+++ b/lib/bug.c
91489@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
91490 return BUG_TRAP_TYPE_NONE;
91491
91492 bug = find_bug(bugaddr);
91493+ if (!bug)
91494+ return BUG_TRAP_TYPE_NONE;
91495
91496 file = NULL;
91497 line = 0;
91498diff --git a/lib/debugobjects.c b/lib/debugobjects.c
91499index e0731c3..ad66444 100644
91500--- a/lib/debugobjects.c
91501+++ b/lib/debugobjects.c
91502@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
91503 if (limit > 4)
91504 return;
91505
91506- is_on_stack = object_is_on_stack(addr);
91507+ is_on_stack = object_starts_on_stack(addr);
91508 if (is_on_stack == onstack)
91509 return;
91510
91511diff --git a/lib/div64.c b/lib/div64.c
91512index 4382ad7..08aa558 100644
91513--- a/lib/div64.c
91514+++ b/lib/div64.c
91515@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
91516 EXPORT_SYMBOL(__div64_32);
91517
91518 #ifndef div_s64_rem
91519-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91520+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91521 {
91522 u64 quotient;
91523
91524@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
91525 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
91526 */
91527 #ifndef div64_u64
91528-u64 div64_u64(u64 dividend, u64 divisor)
91529+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
91530 {
91531 u32 high = divisor >> 32;
91532 u64 quot;
91533diff --git a/lib/dma-debug.c b/lib/dma-debug.c
91534index 98f2d7e..899da5c 100644
91535--- a/lib/dma-debug.c
91536+++ b/lib/dma-debug.c
91537@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
91538
91539 void dma_debug_add_bus(struct bus_type *bus)
91540 {
91541- struct notifier_block *nb;
91542+ notifier_block_no_const *nb;
91543
91544 if (global_disable)
91545 return;
91546@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
91547
91548 static void check_for_stack(struct device *dev, void *addr)
91549 {
91550- if (object_is_on_stack(addr))
91551+ if (object_starts_on_stack(addr))
91552 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
91553 "stack [addr=%p]\n", addr);
91554 }
91555diff --git a/lib/hash.c b/lib/hash.c
91556index fea973f..386626f 100644
91557--- a/lib/hash.c
91558+++ b/lib/hash.c
91559@@ -14,7 +14,7 @@
91560 #include <linux/hash.h>
91561 #include <linux/cache.h>
91562
91563-static struct fast_hash_ops arch_hash_ops __read_mostly = {
91564+static struct fast_hash_ops arch_hash_ops __read_only = {
91565 .hash = jhash,
91566 .hash2 = jhash2,
91567 };
91568diff --git a/lib/inflate.c b/lib/inflate.c
91569index 013a761..c28f3fc 100644
91570--- a/lib/inflate.c
91571+++ b/lib/inflate.c
91572@@ -269,7 +269,7 @@ static void free(void *where)
91573 malloc_ptr = free_mem_ptr;
91574 }
91575 #else
91576-#define malloc(a) kmalloc(a, GFP_KERNEL)
91577+#define malloc(a) kmalloc((a), GFP_KERNEL)
91578 #define free(a) kfree(a)
91579 #endif
91580
91581diff --git a/lib/ioremap.c b/lib/ioremap.c
91582index 0c9216c..863bd89 100644
91583--- a/lib/ioremap.c
91584+++ b/lib/ioremap.c
91585@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
91586 unsigned long next;
91587
91588 phys_addr -= addr;
91589- pmd = pmd_alloc(&init_mm, pud, addr);
91590+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91591 if (!pmd)
91592 return -ENOMEM;
91593 do {
91594@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
91595 unsigned long next;
91596
91597 phys_addr -= addr;
91598- pud = pud_alloc(&init_mm, pgd, addr);
91599+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
91600 if (!pud)
91601 return -ENOMEM;
91602 do {
91603diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
91604index bd2bea9..6b3c95e 100644
91605--- a/lib/is_single_threaded.c
91606+++ b/lib/is_single_threaded.c
91607@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
91608 struct task_struct *p, *t;
91609 bool ret;
91610
91611+ if (!mm)
91612+ return true;
91613+
91614 if (atomic_read(&task->signal->live) != 1)
91615 return false;
91616
91617diff --git a/lib/kobject.c b/lib/kobject.c
91618index 58751bb..93a1853 100644
91619--- a/lib/kobject.c
91620+++ b/lib/kobject.c
91621@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
91622
91623
91624 static DEFINE_SPINLOCK(kobj_ns_type_lock);
91625-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
91626+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
91627
91628-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91629+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91630 {
91631 enum kobj_ns_type type = ops->type;
91632 int error;
91633diff --git a/lib/list_debug.c b/lib/list_debug.c
91634index c24c2f7..f0296f4 100644
91635--- a/lib/list_debug.c
91636+++ b/lib/list_debug.c
91637@@ -11,7 +11,9 @@
91638 #include <linux/bug.h>
91639 #include <linux/kernel.h>
91640 #include <linux/rculist.h>
91641+#include <linux/mm.h>
91642
91643+#ifdef CONFIG_DEBUG_LIST
91644 /*
91645 * Insert a new entry between two known consecutive entries.
91646 *
91647@@ -19,21 +21,40 @@
91648 * the prev/next entries already!
91649 */
91650
91651+static bool __list_add_debug(struct list_head *new,
91652+ struct list_head *prev,
91653+ struct list_head *next)
91654+{
91655+ if (unlikely(next->prev != prev)) {
91656+ printk(KERN_ERR "list_add corruption. next->prev should be "
91657+ "prev (%p), but was %p. (next=%p).\n",
91658+ prev, next->prev, next);
91659+ BUG();
91660+ return false;
91661+ }
91662+ if (unlikely(prev->next != next)) {
91663+ printk(KERN_ERR "list_add corruption. prev->next should be "
91664+ "next (%p), but was %p. (prev=%p).\n",
91665+ next, prev->next, prev);
91666+ BUG();
91667+ return false;
91668+ }
91669+ if (unlikely(new == prev || new == next)) {
91670+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
91671+ new, prev, next);
91672+ BUG();
91673+ return false;
91674+ }
91675+ return true;
91676+}
91677+
91678 void __list_add(struct list_head *new,
91679- struct list_head *prev,
91680- struct list_head *next)
91681+ struct list_head *prev,
91682+ struct list_head *next)
91683 {
91684- WARN(next->prev != prev,
91685- "list_add corruption. next->prev should be "
91686- "prev (%p), but was %p. (next=%p).\n",
91687- prev, next->prev, next);
91688- WARN(prev->next != next,
91689- "list_add corruption. prev->next should be "
91690- "next (%p), but was %p. (prev=%p).\n",
91691- next, prev->next, prev);
91692- WARN(new == prev || new == next,
91693- "list_add double add: new=%p, prev=%p, next=%p.\n",
91694- new, prev, next);
91695+ if (!__list_add_debug(new, prev, next))
91696+ return;
91697+
91698 next->prev = new;
91699 new->next = next;
91700 new->prev = prev;
91701@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
91702 }
91703 EXPORT_SYMBOL(__list_add);
91704
91705-void __list_del_entry(struct list_head *entry)
91706+static bool __list_del_entry_debug(struct list_head *entry)
91707 {
91708 struct list_head *prev, *next;
91709
91710 prev = entry->prev;
91711 next = entry->next;
91712
91713- if (WARN(next == LIST_POISON1,
91714- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91715- entry, LIST_POISON1) ||
91716- WARN(prev == LIST_POISON2,
91717- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91718- entry, LIST_POISON2) ||
91719- WARN(prev->next != entry,
91720- "list_del corruption. prev->next should be %p, "
91721- "but was %p\n", entry, prev->next) ||
91722- WARN(next->prev != entry,
91723- "list_del corruption. next->prev should be %p, "
91724- "but was %p\n", entry, next->prev))
91725+ if (unlikely(next == LIST_POISON1)) {
91726+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91727+ entry, LIST_POISON1);
91728+ BUG();
91729+ return false;
91730+ }
91731+ if (unlikely(prev == LIST_POISON2)) {
91732+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91733+ entry, LIST_POISON2);
91734+ BUG();
91735+ return false;
91736+ }
91737+ if (unlikely(entry->prev->next != entry)) {
91738+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
91739+ "but was %p\n", entry, prev->next);
91740+ BUG();
91741+ return false;
91742+ }
91743+ if (unlikely(entry->next->prev != entry)) {
91744+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
91745+ "but was %p\n", entry, next->prev);
91746+ BUG();
91747+ return false;
91748+ }
91749+ return true;
91750+}
91751+
91752+void __list_del_entry(struct list_head *entry)
91753+{
91754+ if (!__list_del_entry_debug(entry))
91755 return;
91756
91757- __list_del(prev, next);
91758+ __list_del(entry->prev, entry->next);
91759 }
91760 EXPORT_SYMBOL(__list_del_entry);
91761
91762@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
91763 void __list_add_rcu(struct list_head *new,
91764 struct list_head *prev, struct list_head *next)
91765 {
91766- WARN(next->prev != prev,
91767- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
91768- prev, next->prev, next);
91769- WARN(prev->next != next,
91770- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
91771- next, prev->next, prev);
91772+ if (!__list_add_debug(new, prev, next))
91773+ return;
91774+
91775 new->next = next;
91776 new->prev = prev;
91777 rcu_assign_pointer(list_next_rcu(prev), new);
91778 next->prev = new;
91779 }
91780 EXPORT_SYMBOL(__list_add_rcu);
91781+#endif
91782+
91783+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
91784+{
91785+#ifdef CONFIG_DEBUG_LIST
91786+ if (!__list_add_debug(new, prev, next))
91787+ return;
91788+#endif
91789+
91790+ pax_open_kernel();
91791+ next->prev = new;
91792+ new->next = next;
91793+ new->prev = prev;
91794+ prev->next = new;
91795+ pax_close_kernel();
91796+}
91797+EXPORT_SYMBOL(__pax_list_add);
91798+
91799+void pax_list_del(struct list_head *entry)
91800+{
91801+#ifdef CONFIG_DEBUG_LIST
91802+ if (!__list_del_entry_debug(entry))
91803+ return;
91804+#endif
91805+
91806+ pax_open_kernel();
91807+ __list_del(entry->prev, entry->next);
91808+ entry->next = LIST_POISON1;
91809+ entry->prev = LIST_POISON2;
91810+ pax_close_kernel();
91811+}
91812+EXPORT_SYMBOL(pax_list_del);
91813+
91814+void pax_list_del_init(struct list_head *entry)
91815+{
91816+ pax_open_kernel();
91817+ __list_del(entry->prev, entry->next);
91818+ INIT_LIST_HEAD(entry);
91819+ pax_close_kernel();
91820+}
91821+EXPORT_SYMBOL(pax_list_del_init);
91822+
91823+void __pax_list_add_rcu(struct list_head *new,
91824+ struct list_head *prev, struct list_head *next)
91825+{
91826+#ifdef CONFIG_DEBUG_LIST
91827+ if (!__list_add_debug(new, prev, next))
91828+ return;
91829+#endif
91830+
91831+ pax_open_kernel();
91832+ new->next = next;
91833+ new->prev = prev;
91834+ rcu_assign_pointer(list_next_rcu(prev), new);
91835+ next->prev = new;
91836+ pax_close_kernel();
91837+}
91838+EXPORT_SYMBOL(__pax_list_add_rcu);
91839+
91840+void pax_list_del_rcu(struct list_head *entry)
91841+{
91842+#ifdef CONFIG_DEBUG_LIST
91843+ if (!__list_del_entry_debug(entry))
91844+ return;
91845+#endif
91846+
91847+ pax_open_kernel();
91848+ __list_del(entry->prev, entry->next);
91849+ entry->next = LIST_POISON1;
91850+ entry->prev = LIST_POISON2;
91851+ pax_close_kernel();
91852+}
91853+EXPORT_SYMBOL(pax_list_del_rcu);
91854diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
91855index 963b703..438bc51 100644
91856--- a/lib/percpu-refcount.c
91857+++ b/lib/percpu-refcount.c
91858@@ -29,7 +29,7 @@
91859 * can't hit 0 before we've added up all the percpu refs.
91860 */
91861
91862-#define PCPU_COUNT_BIAS (1U << 31)
91863+#define PCPU_COUNT_BIAS (1U << 30)
91864
91865 /**
91866 * percpu_ref_init - initialize a percpu refcount
91867diff --git a/lib/radix-tree.c b/lib/radix-tree.c
91868index 9599aa7..9cf6c72 100644
91869--- a/lib/radix-tree.c
91870+++ b/lib/radix-tree.c
91871@@ -66,7 +66,7 @@ struct radix_tree_preload {
91872 int nr;
91873 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
91874 };
91875-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
91876+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
91877
91878 static inline void *ptr_to_indirect(void *ptr)
91879 {
91880diff --git a/lib/random32.c b/lib/random32.c
91881index fa5da61..35fe9af 100644
91882--- a/lib/random32.c
91883+++ b/lib/random32.c
91884@@ -42,7 +42,7 @@
91885 static void __init prandom_state_selftest(void);
91886 #endif
91887
91888-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91889+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91890
91891 /**
91892 * prandom_u32_state - seeded pseudo-random number generator.
91893diff --git a/lib/rbtree.c b/lib/rbtree.c
91894index 65f4eff..2cfa167 100644
91895--- a/lib/rbtree.c
91896+++ b/lib/rbtree.c
91897@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91898 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91899
91900 static const struct rb_augment_callbacks dummy_callbacks = {
91901- dummy_propagate, dummy_copy, dummy_rotate
91902+ .propagate = dummy_propagate,
91903+ .copy = dummy_copy,
91904+ .rotate = dummy_rotate
91905 };
91906
91907 void rb_insert_color(struct rb_node *node, struct rb_root *root)
91908diff --git a/lib/show_mem.c b/lib/show_mem.c
91909index 0922579..9d7adb9 100644
91910--- a/lib/show_mem.c
91911+++ b/lib/show_mem.c
91912@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
91913 quicklist_total_size());
91914 #endif
91915 #ifdef CONFIG_MEMORY_FAILURE
91916- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
91917+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
91918 #endif
91919 }
91920diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
91921index bb2b201..46abaf9 100644
91922--- a/lib/strncpy_from_user.c
91923+++ b/lib/strncpy_from_user.c
91924@@ -21,7 +21,7 @@
91925 */
91926 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
91927 {
91928- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91929+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91930 long res = 0;
91931
91932 /*
91933diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
91934index a28df52..3d55877 100644
91935--- a/lib/strnlen_user.c
91936+++ b/lib/strnlen_user.c
91937@@ -26,7 +26,7 @@
91938 */
91939 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
91940 {
91941- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91942+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91943 long align, res = 0;
91944 unsigned long c;
91945
91946diff --git a/lib/swiotlb.c b/lib/swiotlb.c
91947index b604b83..c0547f6 100644
91948--- a/lib/swiotlb.c
91949+++ b/lib/swiotlb.c
91950@@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
91951
91952 void
91953 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
91954- dma_addr_t dev_addr)
91955+ dma_addr_t dev_addr, struct dma_attrs *attrs)
91956 {
91957 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
91958
91959diff --git a/lib/usercopy.c b/lib/usercopy.c
91960index 4f5b1dd..7cab418 100644
91961--- a/lib/usercopy.c
91962+++ b/lib/usercopy.c
91963@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
91964 WARN(1, "Buffer overflow detected!\n");
91965 }
91966 EXPORT_SYMBOL(copy_from_user_overflow);
91967+
91968+void copy_to_user_overflow(void)
91969+{
91970+ WARN(1, "Buffer overflow detected!\n");
91971+}
91972+EXPORT_SYMBOL(copy_to_user_overflow);
91973diff --git a/lib/vsprintf.c b/lib/vsprintf.c
91974index 0648291..42bf42b 100644
91975--- a/lib/vsprintf.c
91976+++ b/lib/vsprintf.c
91977@@ -16,6 +16,9 @@
91978 * - scnprintf and vscnprintf
91979 */
91980
91981+#ifdef CONFIG_GRKERNSEC_HIDESYM
91982+#define __INCLUDED_BY_HIDESYM 1
91983+#endif
91984 #include <stdarg.h>
91985 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
91986 #include <linux/types.h>
91987@@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
91988 return number(buf, end, num, spec);
91989 }
91990
91991+#ifdef CONFIG_GRKERNSEC_HIDESYM
91992+int kptr_restrict __read_mostly = 2;
91993+#else
91994 int kptr_restrict __read_mostly;
91995+#endif
91996
91997 /*
91998 * Show a '%p' thing. A kernel extension is that the '%p' is followed
91999@@ -1196,6 +1203,7 @@ int kptr_restrict __read_mostly;
92000 * - 'f' For simple symbolic function names without offset
92001 * - 'S' For symbolic direct pointers with offset
92002 * - 's' For symbolic direct pointers without offset
92003+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92004 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92005 * - 'B' For backtraced symbolic direct pointers with offset
92006 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92007@@ -1263,12 +1271,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92008
92009 if (!ptr && *fmt != 'K') {
92010 /*
92011- * Print (null) with the same width as a pointer so it makes
92012+ * Print (nil) with the same width as a pointer so it makes
92013 * tabular output look nice.
92014 */
92015 if (spec.field_width == -1)
92016 spec.field_width = default_width;
92017- return string(buf, end, "(null)", spec);
92018+ return string(buf, end, "(nil)", spec);
92019 }
92020
92021 switch (*fmt) {
92022@@ -1278,6 +1286,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92023 /* Fallthrough */
92024 case 'S':
92025 case 's':
92026+#ifdef CONFIG_GRKERNSEC_HIDESYM
92027+ break;
92028+#else
92029+ return symbol_string(buf, end, ptr, spec, fmt);
92030+#endif
92031+ case 'A':
92032 case 'B':
92033 return symbol_string(buf, end, ptr, spec, fmt);
92034 case 'R':
92035@@ -1333,6 +1347,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92036 va_end(va);
92037 return buf;
92038 }
92039+ case 'P':
92040+ break;
92041 case 'K':
92042 /*
92043 * %pK cannot be used in IRQ context because its test
92044@@ -1390,6 +1406,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92045 ((const struct file *)ptr)->f_path.dentry,
92046 spec, fmt);
92047 }
92048+
92049+#ifdef CONFIG_GRKERNSEC_HIDESYM
92050+ /* 'P' = approved pointers to copy to userland,
92051+ as in the /proc/kallsyms case, as we make it display nothing
92052+ for non-root users, and the real contents for root users
92053+ Also ignore 'K' pointers, since we force their NULLing for non-root users
92054+ above
92055+ */
92056+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92057+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92058+ dump_stack();
92059+ ptr = NULL;
92060+ }
92061+#endif
92062+
92063 spec.flags |= SMALL;
92064 if (spec.field_width == -1) {
92065 spec.field_width = default_width;
92066@@ -2089,11 +2120,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92067 typeof(type) value; \
92068 if (sizeof(type) == 8) { \
92069 args = PTR_ALIGN(args, sizeof(u32)); \
92070- *(u32 *)&value = *(u32 *)args; \
92071- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92072+ *(u32 *)&value = *(const u32 *)args; \
92073+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92074 } else { \
92075 args = PTR_ALIGN(args, sizeof(type)); \
92076- value = *(typeof(type) *)args; \
92077+ value = *(const typeof(type) *)args; \
92078 } \
92079 args += sizeof(type); \
92080 value; \
92081@@ -2156,7 +2187,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92082 case FORMAT_TYPE_STR: {
92083 const char *str_arg = args;
92084 args += strlen(str_arg) + 1;
92085- str = string(str, end, (char *)str_arg, spec);
92086+ str = string(str, end, str_arg, spec);
92087 break;
92088 }
92089
92090diff --git a/localversion-grsec b/localversion-grsec
92091new file mode 100644
92092index 0000000..7cd6065
92093--- /dev/null
92094+++ b/localversion-grsec
92095@@ -0,0 +1 @@
92096+-grsec
92097diff --git a/mm/Kconfig b/mm/Kconfig
92098index 1b5a95f..e8068bf 100644
92099--- a/mm/Kconfig
92100+++ b/mm/Kconfig
92101@@ -327,10 +327,11 @@ config KSM
92102 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92103
92104 config DEFAULT_MMAP_MIN_ADDR
92105- int "Low address space to protect from user allocation"
92106+ int "Low address space to protect from user allocation"
92107 depends on MMU
92108- default 4096
92109- help
92110+ default 32768 if ALPHA || ARM || PARISC || SPARC32
92111+ default 65536
92112+ help
92113 This is the portion of low virtual memory which should be protected
92114 from userspace allocation. Keeping a user from writing to low pages
92115 can help reduce the impact of kernel NULL pointer bugs.
92116@@ -361,7 +362,7 @@ config MEMORY_FAILURE
92117
92118 config HWPOISON_INJECT
92119 tristate "HWPoison pages injector"
92120- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92121+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92122 select PROC_PAGE_MONITOR
92123
92124 config NOMMU_INITIAL_TRIM_EXCESS
92125diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92126index 09d9591..165bb75 100644
92127--- a/mm/backing-dev.c
92128+++ b/mm/backing-dev.c
92129@@ -12,7 +12,7 @@
92130 #include <linux/device.h>
92131 #include <trace/events/writeback.h>
92132
92133-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92134+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92135
92136 struct backing_dev_info default_backing_dev_info = {
92137 .name = "default",
92138@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92139 return err;
92140
92141 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92142- atomic_long_inc_return(&bdi_seq));
92143+ atomic_long_inc_return_unchecked(&bdi_seq));
92144 if (err) {
92145 bdi_destroy(bdi);
92146 return err;
92147diff --git a/mm/filemap.c b/mm/filemap.c
92148index 088358c..bb415bf 100644
92149--- a/mm/filemap.c
92150+++ b/mm/filemap.c
92151@@ -2125,7 +2125,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92152 struct address_space *mapping = file->f_mapping;
92153
92154 if (!mapping->a_ops->readpage)
92155- return -ENOEXEC;
92156+ return -ENODEV;
92157 file_accessed(file);
92158 vma->vm_ops = &generic_file_vm_ops;
92159 return 0;
92160@@ -2303,6 +2303,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92161 *pos = i_size_read(inode);
92162
92163 if (limit != RLIM_INFINITY) {
92164+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92165 if (*pos >= limit) {
92166 send_sig(SIGXFSZ, current, 0);
92167 return -EFBIG;
92168diff --git a/mm/fremap.c b/mm/fremap.c
92169index 34feba6..315fe78 100644
92170--- a/mm/fremap.c
92171+++ b/mm/fremap.c
92172@@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92173 retry:
92174 vma = find_vma(mm, start);
92175
92176+#ifdef CONFIG_PAX_SEGMEXEC
92177+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92178+ goto out;
92179+#endif
92180+
92181 /*
92182 * Make sure the vma is shared, that it supports prefaulting,
92183 * and that the remapped range is valid and fully within
92184diff --git a/mm/highmem.c b/mm/highmem.c
92185index b32b70c..e512eb0 100644
92186--- a/mm/highmem.c
92187+++ b/mm/highmem.c
92188@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92189 * So no dangers, even with speculative execution.
92190 */
92191 page = pte_page(pkmap_page_table[i]);
92192+ pax_open_kernel();
92193 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92194-
92195+ pax_close_kernel();
92196 set_page_address(page, NULL);
92197 need_flush = 1;
92198 }
92199@@ -198,9 +199,11 @@ start:
92200 }
92201 }
92202 vaddr = PKMAP_ADDR(last_pkmap_nr);
92203+
92204+ pax_open_kernel();
92205 set_pte_at(&init_mm, vaddr,
92206 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92207-
92208+ pax_close_kernel();
92209 pkmap_count[last_pkmap_nr] = 1;
92210 set_page_address(page, (void *)vaddr);
92211
92212diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92213index c82290b..863d466 100644
92214--- a/mm/hugetlb.c
92215+++ b/mm/hugetlb.c
92216@@ -2107,6 +2107,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92217 struct hstate *h = &default_hstate;
92218 unsigned long tmp;
92219 int ret;
92220+ ctl_table_no_const hugetlb_table;
92221
92222 if (!hugepages_supported())
92223 return -ENOTSUPP;
92224@@ -2116,9 +2117,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92225 if (write && h->order >= MAX_ORDER)
92226 return -EINVAL;
92227
92228- table->data = &tmp;
92229- table->maxlen = sizeof(unsigned long);
92230- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92231+ hugetlb_table = *table;
92232+ hugetlb_table.data = &tmp;
92233+ hugetlb_table.maxlen = sizeof(unsigned long);
92234+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92235 if (ret)
92236 goto out;
92237
92238@@ -2163,6 +2165,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92239 struct hstate *h = &default_hstate;
92240 unsigned long tmp;
92241 int ret;
92242+ ctl_table_no_const hugetlb_table;
92243
92244 if (!hugepages_supported())
92245 return -ENOTSUPP;
92246@@ -2172,9 +2175,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92247 if (write && h->order >= MAX_ORDER)
92248 return -EINVAL;
92249
92250- table->data = &tmp;
92251- table->maxlen = sizeof(unsigned long);
92252- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92253+ hugetlb_table = *table;
92254+ hugetlb_table.data = &tmp;
92255+ hugetlb_table.maxlen = sizeof(unsigned long);
92256+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92257 if (ret)
92258 goto out;
92259
92260@@ -2639,6 +2643,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
92261 return 1;
92262 }
92263
92264+#ifdef CONFIG_PAX_SEGMEXEC
92265+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
92266+{
92267+ struct mm_struct *mm = vma->vm_mm;
92268+ struct vm_area_struct *vma_m;
92269+ unsigned long address_m;
92270+ pte_t *ptep_m;
92271+
92272+ vma_m = pax_find_mirror_vma(vma);
92273+ if (!vma_m)
92274+ return;
92275+
92276+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92277+ address_m = address + SEGMEXEC_TASK_SIZE;
92278+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
92279+ get_page(page_m);
92280+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
92281+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
92282+}
92283+#endif
92284+
92285 /*
92286 * Hugetlb_cow() should be called with page lock of the original hugepage held.
92287 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
92288@@ -2756,6 +2781,11 @@ retry_avoidcopy:
92289 make_huge_pte(vma, new_page, 1));
92290 page_remove_rmap(old_page);
92291 hugepage_add_new_anon_rmap(new_page, vma, address);
92292+
92293+#ifdef CONFIG_PAX_SEGMEXEC
92294+ pax_mirror_huge_pte(vma, address, new_page);
92295+#endif
92296+
92297 /* Make the old page be freed below */
92298 new_page = old_page;
92299 }
92300@@ -2915,6 +2945,10 @@ retry:
92301 && (vma->vm_flags & VM_SHARED)));
92302 set_huge_pte_at(mm, address, ptep, new_pte);
92303
92304+#ifdef CONFIG_PAX_SEGMEXEC
92305+ pax_mirror_huge_pte(vma, address, page);
92306+#endif
92307+
92308 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
92309 /* Optimization, do the COW without a second fault */
92310 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
92311@@ -2981,6 +3015,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92312 struct hstate *h = hstate_vma(vma);
92313 struct address_space *mapping;
92314
92315+#ifdef CONFIG_PAX_SEGMEXEC
92316+ struct vm_area_struct *vma_m;
92317+#endif
92318+
92319 address &= huge_page_mask(h);
92320
92321 ptep = huge_pte_offset(mm, address);
92322@@ -2994,6 +3032,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92323 VM_FAULT_SET_HINDEX(hstate_index(h));
92324 }
92325
92326+#ifdef CONFIG_PAX_SEGMEXEC
92327+ vma_m = pax_find_mirror_vma(vma);
92328+ if (vma_m) {
92329+ unsigned long address_m;
92330+
92331+ if (vma->vm_start > vma_m->vm_start) {
92332+ address_m = address;
92333+ address -= SEGMEXEC_TASK_SIZE;
92334+ vma = vma_m;
92335+ h = hstate_vma(vma);
92336+ } else
92337+ address_m = address + SEGMEXEC_TASK_SIZE;
92338+
92339+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
92340+ return VM_FAULT_OOM;
92341+ address_m &= HPAGE_MASK;
92342+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
92343+ }
92344+#endif
92345+
92346 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
92347 if (!ptep)
92348 return VM_FAULT_OOM;
92349diff --git a/mm/internal.h b/mm/internal.h
92350index 07b6736..ae8da20 100644
92351--- a/mm/internal.h
92352+++ b/mm/internal.h
92353@@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
92354 * in mm/page_alloc.c
92355 */
92356 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92357+extern void free_compound_page(struct page *page);
92358 extern void prep_compound_page(struct page *page, unsigned long order);
92359 #ifdef CONFIG_MEMORY_FAILURE
92360 extern bool is_free_buddy_page(struct page *page);
92361@@ -367,7 +368,7 @@ extern u32 hwpoison_filter_enable;
92362
92363 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92364 unsigned long, unsigned long,
92365- unsigned long, unsigned long);
92366+ unsigned long, unsigned long) __intentional_overflow(-1);
92367
92368 extern void set_pageblock_order(void);
92369 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92370diff --git a/mm/iov_iter.c b/mm/iov_iter.c
92371index 10e46cd..e3052f6 100644
92372--- a/mm/iov_iter.c
92373+++ b/mm/iov_iter.c
92374@@ -87,7 +87,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
92375
92376 while (bytes) {
92377 char __user *buf = iov->iov_base + base;
92378- int copy = min(bytes, iov->iov_len - base);
92379+ size_t copy = min(bytes, iov->iov_len - base);
92380
92381 base = 0;
92382 left = __copy_from_user_inatomic(vaddr, buf, copy);
92383@@ -115,7 +115,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
92384
92385 kaddr = kmap_atomic(page);
92386 if (likely(i->nr_segs == 1)) {
92387- int left;
92388+ size_t left;
92389 char __user *buf = i->iov->iov_base + i->iov_offset;
92390 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
92391 copied = bytes - left;
92392@@ -143,7 +143,7 @@ size_t iov_iter_copy_from_user(struct page *page,
92393
92394 kaddr = kmap(page);
92395 if (likely(i->nr_segs == 1)) {
92396- int left;
92397+ size_t left;
92398 char __user *buf = i->iov->iov_base + i->iov_offset;
92399 left = __copy_from_user(kaddr + offset, buf, bytes);
92400 copied = bytes - left;
92401@@ -173,7 +173,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
92402 * zero-length segments (without overruning the iovec).
92403 */
92404 while (bytes || unlikely(i->count && !iov->iov_len)) {
92405- int copy;
92406+ size_t copy;
92407
92408 copy = min(bytes, iov->iov_len - base);
92409 BUG_ON(!i->count || i->count < copy);
92410diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92411index 8d2fcdf..6dd9f1a 100644
92412--- a/mm/kmemleak.c
92413+++ b/mm/kmemleak.c
92414@@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
92415
92416 for (i = 0; i < object->trace_len; i++) {
92417 void *ptr = (void *)object->trace[i];
92418- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92419+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92420 }
92421 }
92422
92423@@ -1871,7 +1871,7 @@ static int __init kmemleak_late_init(void)
92424 return -ENOMEM;
92425 }
92426
92427- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92428+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92429 &kmemleak_fops);
92430 if (!dentry)
92431 pr_warning("Failed to create the debugfs kmemleak file\n");
92432diff --git a/mm/maccess.c b/mm/maccess.c
92433index d53adf9..03a24bf 100644
92434--- a/mm/maccess.c
92435+++ b/mm/maccess.c
92436@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92437 set_fs(KERNEL_DS);
92438 pagefault_disable();
92439 ret = __copy_from_user_inatomic(dst,
92440- (__force const void __user *)src, size);
92441+ (const void __force_user *)src, size);
92442 pagefault_enable();
92443 set_fs(old_fs);
92444
92445@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92446
92447 set_fs(KERNEL_DS);
92448 pagefault_disable();
92449- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92450+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92451 pagefault_enable();
92452 set_fs(old_fs);
92453
92454diff --git a/mm/madvise.c b/mm/madvise.c
92455index a402f8f..f5e5daa 100644
92456--- a/mm/madvise.c
92457+++ b/mm/madvise.c
92458@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92459 pgoff_t pgoff;
92460 unsigned long new_flags = vma->vm_flags;
92461
92462+#ifdef CONFIG_PAX_SEGMEXEC
92463+ struct vm_area_struct *vma_m;
92464+#endif
92465+
92466 switch (behavior) {
92467 case MADV_NORMAL:
92468 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92469@@ -126,6 +130,13 @@ success:
92470 /*
92471 * vm_flags is protected by the mmap_sem held in write mode.
92472 */
92473+
92474+#ifdef CONFIG_PAX_SEGMEXEC
92475+ vma_m = pax_find_mirror_vma(vma);
92476+ if (vma_m)
92477+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
92478+#endif
92479+
92480 vma->vm_flags = new_flags;
92481
92482 out:
92483@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92484 struct vm_area_struct **prev,
92485 unsigned long start, unsigned long end)
92486 {
92487+
92488+#ifdef CONFIG_PAX_SEGMEXEC
92489+ struct vm_area_struct *vma_m;
92490+#endif
92491+
92492 *prev = vma;
92493 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
92494 return -EINVAL;
92495@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92496 zap_page_range(vma, start, end - start, &details);
92497 } else
92498 zap_page_range(vma, start, end - start, NULL);
92499+
92500+#ifdef CONFIG_PAX_SEGMEXEC
92501+ vma_m = pax_find_mirror_vma(vma);
92502+ if (vma_m) {
92503+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
92504+ struct zap_details details = {
92505+ .nonlinear_vma = vma_m,
92506+ .last_index = ULONG_MAX,
92507+ };
92508+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
92509+ } else
92510+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
92511+ }
92512+#endif
92513+
92514 return 0;
92515 }
92516
92517@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
92518 if (end < start)
92519 return error;
92520
92521+#ifdef CONFIG_PAX_SEGMEXEC
92522+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92523+ if (end > SEGMEXEC_TASK_SIZE)
92524+ return error;
92525+ } else
92526+#endif
92527+
92528+ if (end > TASK_SIZE)
92529+ return error;
92530+
92531 error = 0;
92532 if (end == start)
92533 return error;
92534diff --git a/mm/memory-failure.c b/mm/memory-failure.c
92535index 9ccef39..d3320da 100644
92536--- a/mm/memory-failure.c
92537+++ b/mm/memory-failure.c
92538@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
92539
92540 int sysctl_memory_failure_recovery __read_mostly = 1;
92541
92542-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92543+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92544
92545 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
92546
92547@@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
92548 pfn, t->comm, t->pid);
92549 si.si_signo = SIGBUS;
92550 si.si_errno = 0;
92551- si.si_addr = (void *)addr;
92552+ si.si_addr = (void __user *)addr;
92553 #ifdef __ARCH_SI_TRAPNO
92554 si.si_trapno = trapno;
92555 #endif
92556@@ -758,7 +758,7 @@ static struct page_state {
92557 unsigned long res;
92558 char *msg;
92559 int (*action)(struct page *p, unsigned long pfn);
92560-} error_states[] = {
92561+} __do_const error_states[] = {
92562 { reserved, reserved, "reserved kernel", me_kernel },
92563 /*
92564 * free pages are specially detected outside this table:
92565@@ -1058,7 +1058,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92566 nr_pages = 1 << compound_order(hpage);
92567 else /* normal page or thp */
92568 nr_pages = 1;
92569- atomic_long_add(nr_pages, &num_poisoned_pages);
92570+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
92571
92572 /*
92573 * We need/can do nothing about count=0 pages.
92574@@ -1087,7 +1087,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92575 if (PageHWPoison(hpage)) {
92576 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
92577 || (p != hpage && TestSetPageHWPoison(hpage))) {
92578- atomic_long_sub(nr_pages, &num_poisoned_pages);
92579+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92580 unlock_page(hpage);
92581 return 0;
92582 }
92583@@ -1153,14 +1153,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92584 */
92585 if (!PageHWPoison(p)) {
92586 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
92587- atomic_long_sub(nr_pages, &num_poisoned_pages);
92588+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92589 put_page(hpage);
92590 res = 0;
92591 goto out;
92592 }
92593 if (hwpoison_filter(p)) {
92594 if (TestClearPageHWPoison(p))
92595- atomic_long_sub(nr_pages, &num_poisoned_pages);
92596+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92597 unlock_page(hpage);
92598 put_page(hpage);
92599 return 0;
92600@@ -1382,7 +1382,7 @@ int unpoison_memory(unsigned long pfn)
92601 return 0;
92602 }
92603 if (TestClearPageHWPoison(p))
92604- atomic_long_dec(&num_poisoned_pages);
92605+ atomic_long_dec_unchecked(&num_poisoned_pages);
92606 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
92607 return 0;
92608 }
92609@@ -1396,7 +1396,7 @@ int unpoison_memory(unsigned long pfn)
92610 */
92611 if (TestClearPageHWPoison(page)) {
92612 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
92613- atomic_long_sub(nr_pages, &num_poisoned_pages);
92614+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92615 freeit = 1;
92616 if (PageHuge(page))
92617 clear_page_hwpoison_huge_page(page);
92618@@ -1521,11 +1521,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
92619 if (PageHuge(page)) {
92620 set_page_hwpoison_huge_page(hpage);
92621 dequeue_hwpoisoned_huge_page(hpage);
92622- atomic_long_add(1 << compound_order(hpage),
92623+ atomic_long_add_unchecked(1 << compound_order(hpage),
92624 &num_poisoned_pages);
92625 } else {
92626 SetPageHWPoison(page);
92627- atomic_long_inc(&num_poisoned_pages);
92628+ atomic_long_inc_unchecked(&num_poisoned_pages);
92629 }
92630 }
92631 return ret;
92632@@ -1564,7 +1564,7 @@ static int __soft_offline_page(struct page *page, int flags)
92633 put_page(page);
92634 pr_info("soft_offline: %#lx: invalidated\n", pfn);
92635 SetPageHWPoison(page);
92636- atomic_long_inc(&num_poisoned_pages);
92637+ atomic_long_inc_unchecked(&num_poisoned_pages);
92638 return 0;
92639 }
92640
92641@@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
92642 if (!is_free_buddy_page(page))
92643 pr_info("soft offline: %#lx: page leaked\n",
92644 pfn);
92645- atomic_long_inc(&num_poisoned_pages);
92646+ atomic_long_inc_unchecked(&num_poisoned_pages);
92647 }
92648 } else {
92649 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
92650@@ -1689,11 +1689,11 @@ int soft_offline_page(struct page *page, int flags)
92651 if (PageHuge(page)) {
92652 set_page_hwpoison_huge_page(hpage);
92653 dequeue_hwpoisoned_huge_page(hpage);
92654- atomic_long_add(1 << compound_order(hpage),
92655+ atomic_long_add_unchecked(1 << compound_order(hpage),
92656 &num_poisoned_pages);
92657 } else {
92658 SetPageHWPoison(page);
92659- atomic_long_inc(&num_poisoned_pages);
92660+ atomic_long_inc_unchecked(&num_poisoned_pages);
92661 }
92662 }
92663 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
92664diff --git a/mm/memory.c b/mm/memory.c
92665index 037b812..948123c 100644
92666--- a/mm/memory.c
92667+++ b/mm/memory.c
92668@@ -413,6 +413,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92669 free_pte_range(tlb, pmd, addr);
92670 } while (pmd++, addr = next, addr != end);
92671
92672+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
92673 start &= PUD_MASK;
92674 if (start < floor)
92675 return;
92676@@ -427,6 +428,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92677 pmd = pmd_offset(pud, start);
92678 pud_clear(pud);
92679 pmd_free_tlb(tlb, pmd, start);
92680+#endif
92681+
92682 }
92683
92684 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92685@@ -446,6 +449,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92686 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
92687 } while (pud++, addr = next, addr != end);
92688
92689+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
92690 start &= PGDIR_MASK;
92691 if (start < floor)
92692 return;
92693@@ -460,6 +464,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92694 pud = pud_offset(pgd, start);
92695 pgd_clear(pgd);
92696 pud_free_tlb(tlb, pud, start);
92697+#endif
92698+
92699 }
92700
92701 /*
92702@@ -1652,12 +1658,6 @@ no_page_table:
92703 return page;
92704 }
92705
92706-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
92707-{
92708- return stack_guard_page_start(vma, addr) ||
92709- stack_guard_page_end(vma, addr+PAGE_SIZE);
92710-}
92711-
92712 /**
92713 * __get_user_pages() - pin user pages in memory
92714 * @tsk: task_struct of target task
92715@@ -1735,10 +1735,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92716
92717 i = 0;
92718
92719- do {
92720+ while (nr_pages) {
92721 struct vm_area_struct *vma;
92722
92723- vma = find_extend_vma(mm, start);
92724+ vma = find_vma(mm, start);
92725 if (!vma && in_gate_area(mm, start)) {
92726 unsigned long pg = start & PAGE_MASK;
92727 pgd_t *pgd;
92728@@ -1787,7 +1787,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92729 goto next_page;
92730 }
92731
92732- if (!vma)
92733+ if (!vma || start < vma->vm_start)
92734 goto efault;
92735 vm_flags = vma->vm_flags;
92736 if (vm_flags & (VM_IO | VM_PFNMAP))
92737@@ -1848,11 +1848,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92738 int ret;
92739 unsigned int fault_flags = 0;
92740
92741- /* For mlock, just skip the stack guard page. */
92742- if (foll_flags & FOLL_MLOCK) {
92743- if (stack_guard_page(vma, start))
92744- goto next_page;
92745- }
92746 if (foll_flags & FOLL_WRITE)
92747 fault_flags |= FAULT_FLAG_WRITE;
92748 if (nonblocking)
92749@@ -1932,7 +1927,7 @@ next_page:
92750 start += page_increm * PAGE_SIZE;
92751 nr_pages -= page_increm;
92752 } while (nr_pages && start < vma->vm_end);
92753- } while (nr_pages);
92754+ }
92755 return i;
92756 efault:
92757 return i ? : -EFAULT;
92758@@ -2145,6 +2140,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
92759 page_add_file_rmap(page);
92760 set_pte_at(mm, addr, pte, mk_pte(page, prot));
92761
92762+#ifdef CONFIG_PAX_SEGMEXEC
92763+ pax_mirror_file_pte(vma, addr, page, ptl);
92764+#endif
92765+
92766 retval = 0;
92767 pte_unmap_unlock(pte, ptl);
92768 return retval;
92769@@ -2189,9 +2188,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
92770 if (!page_count(page))
92771 return -EINVAL;
92772 if (!(vma->vm_flags & VM_MIXEDMAP)) {
92773+
92774+#ifdef CONFIG_PAX_SEGMEXEC
92775+ struct vm_area_struct *vma_m;
92776+#endif
92777+
92778 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
92779 BUG_ON(vma->vm_flags & VM_PFNMAP);
92780 vma->vm_flags |= VM_MIXEDMAP;
92781+
92782+#ifdef CONFIG_PAX_SEGMEXEC
92783+ vma_m = pax_find_mirror_vma(vma);
92784+ if (vma_m)
92785+ vma_m->vm_flags |= VM_MIXEDMAP;
92786+#endif
92787+
92788 }
92789 return insert_page(vma, addr, page, vma->vm_page_prot);
92790 }
92791@@ -2274,6 +2285,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
92792 unsigned long pfn)
92793 {
92794 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
92795+ BUG_ON(vma->vm_mirror);
92796
92797 if (addr < vma->vm_start || addr >= vma->vm_end)
92798 return -EFAULT;
92799@@ -2521,7 +2533,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
92800
92801 BUG_ON(pud_huge(*pud));
92802
92803- pmd = pmd_alloc(mm, pud, addr);
92804+ pmd = (mm == &init_mm) ?
92805+ pmd_alloc_kernel(mm, pud, addr) :
92806+ pmd_alloc(mm, pud, addr);
92807 if (!pmd)
92808 return -ENOMEM;
92809 do {
92810@@ -2541,7 +2555,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
92811 unsigned long next;
92812 int err;
92813
92814- pud = pud_alloc(mm, pgd, addr);
92815+ pud = (mm == &init_mm) ?
92816+ pud_alloc_kernel(mm, pgd, addr) :
92817+ pud_alloc(mm, pgd, addr);
92818 if (!pud)
92819 return -ENOMEM;
92820 do {
92821@@ -2663,6 +2679,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
92822 return ret;
92823 }
92824
92825+#ifdef CONFIG_PAX_SEGMEXEC
92826+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
92827+{
92828+ struct mm_struct *mm = vma->vm_mm;
92829+ spinlock_t *ptl;
92830+ pte_t *pte, entry;
92831+
92832+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
92833+ entry = *pte;
92834+ if (!pte_present(entry)) {
92835+ if (!pte_none(entry)) {
92836+ BUG_ON(pte_file(entry));
92837+ free_swap_and_cache(pte_to_swp_entry(entry));
92838+ pte_clear_not_present_full(mm, address, pte, 0);
92839+ }
92840+ } else {
92841+ struct page *page;
92842+
92843+ flush_cache_page(vma, address, pte_pfn(entry));
92844+ entry = ptep_clear_flush(vma, address, pte);
92845+ BUG_ON(pte_dirty(entry));
92846+ page = vm_normal_page(vma, address, entry);
92847+ if (page) {
92848+ update_hiwater_rss(mm);
92849+ if (PageAnon(page))
92850+ dec_mm_counter_fast(mm, MM_ANONPAGES);
92851+ else
92852+ dec_mm_counter_fast(mm, MM_FILEPAGES);
92853+ page_remove_rmap(page);
92854+ page_cache_release(page);
92855+ }
92856+ }
92857+ pte_unmap_unlock(pte, ptl);
92858+}
92859+
92860+/* PaX: if vma is mirrored, synchronize the mirror's PTE
92861+ *
92862+ * the ptl of the lower mapped page is held on entry and is not released on exit
92863+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
92864+ */
92865+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92866+{
92867+ struct mm_struct *mm = vma->vm_mm;
92868+ unsigned long address_m;
92869+ spinlock_t *ptl_m;
92870+ struct vm_area_struct *vma_m;
92871+ pmd_t *pmd_m;
92872+ pte_t *pte_m, entry_m;
92873+
92874+ BUG_ON(!page_m || !PageAnon(page_m));
92875+
92876+ vma_m = pax_find_mirror_vma(vma);
92877+ if (!vma_m)
92878+ return;
92879+
92880+ BUG_ON(!PageLocked(page_m));
92881+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92882+ address_m = address + SEGMEXEC_TASK_SIZE;
92883+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92884+ pte_m = pte_offset_map(pmd_m, address_m);
92885+ ptl_m = pte_lockptr(mm, pmd_m);
92886+ if (ptl != ptl_m) {
92887+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92888+ if (!pte_none(*pte_m))
92889+ goto out;
92890+ }
92891+
92892+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92893+ page_cache_get(page_m);
92894+ page_add_anon_rmap(page_m, vma_m, address_m);
92895+ inc_mm_counter_fast(mm, MM_ANONPAGES);
92896+ set_pte_at(mm, address_m, pte_m, entry_m);
92897+ update_mmu_cache(vma_m, address_m, pte_m);
92898+out:
92899+ if (ptl != ptl_m)
92900+ spin_unlock(ptl_m);
92901+ pte_unmap(pte_m);
92902+ unlock_page(page_m);
92903+}
92904+
92905+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92906+{
92907+ struct mm_struct *mm = vma->vm_mm;
92908+ unsigned long address_m;
92909+ spinlock_t *ptl_m;
92910+ struct vm_area_struct *vma_m;
92911+ pmd_t *pmd_m;
92912+ pte_t *pte_m, entry_m;
92913+
92914+ BUG_ON(!page_m || PageAnon(page_m));
92915+
92916+ vma_m = pax_find_mirror_vma(vma);
92917+ if (!vma_m)
92918+ return;
92919+
92920+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92921+ address_m = address + SEGMEXEC_TASK_SIZE;
92922+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92923+ pte_m = pte_offset_map(pmd_m, address_m);
92924+ ptl_m = pte_lockptr(mm, pmd_m);
92925+ if (ptl != ptl_m) {
92926+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92927+ if (!pte_none(*pte_m))
92928+ goto out;
92929+ }
92930+
92931+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92932+ page_cache_get(page_m);
92933+ page_add_file_rmap(page_m);
92934+ inc_mm_counter_fast(mm, MM_FILEPAGES);
92935+ set_pte_at(mm, address_m, pte_m, entry_m);
92936+ update_mmu_cache(vma_m, address_m, pte_m);
92937+out:
92938+ if (ptl != ptl_m)
92939+ spin_unlock(ptl_m);
92940+ pte_unmap(pte_m);
92941+}
92942+
92943+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
92944+{
92945+ struct mm_struct *mm = vma->vm_mm;
92946+ unsigned long address_m;
92947+ spinlock_t *ptl_m;
92948+ struct vm_area_struct *vma_m;
92949+ pmd_t *pmd_m;
92950+ pte_t *pte_m, entry_m;
92951+
92952+ vma_m = pax_find_mirror_vma(vma);
92953+ if (!vma_m)
92954+ return;
92955+
92956+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92957+ address_m = address + SEGMEXEC_TASK_SIZE;
92958+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92959+ pte_m = pte_offset_map(pmd_m, address_m);
92960+ ptl_m = pte_lockptr(mm, pmd_m);
92961+ if (ptl != ptl_m) {
92962+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92963+ if (!pte_none(*pte_m))
92964+ goto out;
92965+ }
92966+
92967+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
92968+ set_pte_at(mm, address_m, pte_m, entry_m);
92969+out:
92970+ if (ptl != ptl_m)
92971+ spin_unlock(ptl_m);
92972+ pte_unmap(pte_m);
92973+}
92974+
92975+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
92976+{
92977+ struct page *page_m;
92978+ pte_t entry;
92979+
92980+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
92981+ goto out;
92982+
92983+ entry = *pte;
92984+ page_m = vm_normal_page(vma, address, entry);
92985+ if (!page_m)
92986+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
92987+ else if (PageAnon(page_m)) {
92988+ if (pax_find_mirror_vma(vma)) {
92989+ pte_unmap_unlock(pte, ptl);
92990+ lock_page(page_m);
92991+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
92992+ if (pte_same(entry, *pte))
92993+ pax_mirror_anon_pte(vma, address, page_m, ptl);
92994+ else
92995+ unlock_page(page_m);
92996+ }
92997+ } else
92998+ pax_mirror_file_pte(vma, address, page_m, ptl);
92999+
93000+out:
93001+ pte_unmap_unlock(pte, ptl);
93002+}
93003+#endif
93004+
93005 /*
93006 * This routine handles present pages, when users try to write
93007 * to a shared page. It is done by copying the page to a new address
93008@@ -2860,6 +3056,12 @@ gotten:
93009 */
93010 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93011 if (likely(pte_same(*page_table, orig_pte))) {
93012+
93013+#ifdef CONFIG_PAX_SEGMEXEC
93014+ if (pax_find_mirror_vma(vma))
93015+ BUG_ON(!trylock_page(new_page));
93016+#endif
93017+
93018 if (old_page) {
93019 if (!PageAnon(old_page)) {
93020 dec_mm_counter_fast(mm, MM_FILEPAGES);
93021@@ -2911,6 +3113,10 @@ gotten:
93022 page_remove_rmap(old_page);
93023 }
93024
93025+#ifdef CONFIG_PAX_SEGMEXEC
93026+ pax_mirror_anon_pte(vma, address, new_page, ptl);
93027+#endif
93028+
93029 /* Free the old page.. */
93030 new_page = old_page;
93031 ret |= VM_FAULT_WRITE;
93032@@ -3184,6 +3390,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93033 swap_free(entry);
93034 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93035 try_to_free_swap(page);
93036+
93037+#ifdef CONFIG_PAX_SEGMEXEC
93038+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93039+#endif
93040+
93041 unlock_page(page);
93042 if (page != swapcache) {
93043 /*
93044@@ -3207,6 +3418,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93045
93046 /* No need to invalidate - it was non-present before */
93047 update_mmu_cache(vma, address, page_table);
93048+
93049+#ifdef CONFIG_PAX_SEGMEXEC
93050+ pax_mirror_anon_pte(vma, address, page, ptl);
93051+#endif
93052+
93053 unlock:
93054 pte_unmap_unlock(page_table, ptl);
93055 out:
93056@@ -3226,40 +3442,6 @@ out_release:
93057 }
93058
93059 /*
93060- * This is like a special single-page "expand_{down|up}wards()",
93061- * except we must first make sure that 'address{-|+}PAGE_SIZE'
93062- * doesn't hit another vma.
93063- */
93064-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93065-{
93066- address &= PAGE_MASK;
93067- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93068- struct vm_area_struct *prev = vma->vm_prev;
93069-
93070- /*
93071- * Is there a mapping abutting this one below?
93072- *
93073- * That's only ok if it's the same stack mapping
93074- * that has gotten split..
93075- */
93076- if (prev && prev->vm_end == address)
93077- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93078-
93079- expand_downwards(vma, address - PAGE_SIZE);
93080- }
93081- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93082- struct vm_area_struct *next = vma->vm_next;
93083-
93084- /* As VM_GROWSDOWN but s/below/above/ */
93085- if (next && next->vm_start == address + PAGE_SIZE)
93086- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93087-
93088- expand_upwards(vma, address + PAGE_SIZE);
93089- }
93090- return 0;
93091-}
93092-
93093-/*
93094 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93095 * but allow concurrent faults), and pte mapped but not yet locked.
93096 * We return with mmap_sem still held, but pte unmapped and unlocked.
93097@@ -3268,27 +3450,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93098 unsigned long address, pte_t *page_table, pmd_t *pmd,
93099 unsigned int flags)
93100 {
93101- struct page *page;
93102+ struct page *page = NULL;
93103 spinlock_t *ptl;
93104 pte_t entry;
93105
93106- pte_unmap(page_table);
93107-
93108- /* Check if we need to add a guard page to the stack */
93109- if (check_stack_guard_page(vma, address) < 0)
93110- return VM_FAULT_SIGBUS;
93111-
93112- /* Use the zero-page for reads */
93113 if (!(flags & FAULT_FLAG_WRITE)) {
93114 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93115 vma->vm_page_prot));
93116- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93117+ ptl = pte_lockptr(mm, pmd);
93118+ spin_lock(ptl);
93119 if (!pte_none(*page_table))
93120 goto unlock;
93121 goto setpte;
93122 }
93123
93124 /* Allocate our own private page. */
93125+ pte_unmap(page_table);
93126+
93127 if (unlikely(anon_vma_prepare(vma)))
93128 goto oom;
93129 page = alloc_zeroed_user_highpage_movable(vma, address);
93130@@ -3312,6 +3490,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93131 if (!pte_none(*page_table))
93132 goto release;
93133
93134+#ifdef CONFIG_PAX_SEGMEXEC
93135+ if (pax_find_mirror_vma(vma))
93136+ BUG_ON(!trylock_page(page));
93137+#endif
93138+
93139 inc_mm_counter_fast(mm, MM_ANONPAGES);
93140 page_add_new_anon_rmap(page, vma, address);
93141 setpte:
93142@@ -3319,6 +3502,12 @@ setpte:
93143
93144 /* No need to invalidate - it was non-present before */
93145 update_mmu_cache(vma, address, page_table);
93146+
93147+#ifdef CONFIG_PAX_SEGMEXEC
93148+ if (page)
93149+ pax_mirror_anon_pte(vma, address, page, ptl);
93150+#endif
93151+
93152 unlock:
93153 pte_unmap_unlock(page_table, ptl);
93154 return 0;
93155@@ -3535,6 +3724,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93156 return ret;
93157 }
93158 do_set_pte(vma, address, fault_page, pte, false, false);
93159+
93160+#ifdef CONFIG_PAX_SEGMEXEC
93161+ pax_mirror_file_pte(vma, address, fault_page, ptl);
93162+#endif
93163+
93164 unlock_page(fault_page);
93165 unlock_out:
93166 pte_unmap_unlock(pte, ptl);
93167@@ -3576,7 +3770,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93168 page_cache_release(fault_page);
93169 goto uncharge_out;
93170 }
93171+
93172+#ifdef CONFIG_PAX_SEGMEXEC
93173+ if (pax_find_mirror_vma(vma))
93174+ BUG_ON(!trylock_page(new_page));
93175+#endif
93176+
93177 do_set_pte(vma, address, new_page, pte, true, true);
93178+
93179+#ifdef CONFIG_PAX_SEGMEXEC
93180+ pax_mirror_anon_pte(vma, address, new_page, ptl);
93181+#endif
93182+
93183 pte_unmap_unlock(pte, ptl);
93184 unlock_page(fault_page);
93185 page_cache_release(fault_page);
93186@@ -3624,6 +3829,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93187 return ret;
93188 }
93189 do_set_pte(vma, address, fault_page, pte, true, false);
93190+
93191+#ifdef CONFIG_PAX_SEGMEXEC
93192+ pax_mirror_file_pte(vma, address, fault_page, ptl);
93193+#endif
93194+
93195 pte_unmap_unlock(pte, ptl);
93196
93197 if (set_page_dirty(fault_page))
93198@@ -3854,6 +4064,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93199 if (flags & FAULT_FLAG_WRITE)
93200 flush_tlb_fix_spurious_fault(vma, address);
93201 }
93202+
93203+#ifdef CONFIG_PAX_SEGMEXEC
93204+ pax_mirror_pte(vma, address, pte, pmd, ptl);
93205+ return 0;
93206+#endif
93207+
93208 unlock:
93209 pte_unmap_unlock(pte, ptl);
93210 return 0;
93211@@ -3870,9 +4086,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93212 pmd_t *pmd;
93213 pte_t *pte;
93214
93215+#ifdef CONFIG_PAX_SEGMEXEC
93216+ struct vm_area_struct *vma_m;
93217+#endif
93218+
93219 if (unlikely(is_vm_hugetlb_page(vma)))
93220 return hugetlb_fault(mm, vma, address, flags);
93221
93222+#ifdef CONFIG_PAX_SEGMEXEC
93223+ vma_m = pax_find_mirror_vma(vma);
93224+ if (vma_m) {
93225+ unsigned long address_m;
93226+ pgd_t *pgd_m;
93227+ pud_t *pud_m;
93228+ pmd_t *pmd_m;
93229+
93230+ if (vma->vm_start > vma_m->vm_start) {
93231+ address_m = address;
93232+ address -= SEGMEXEC_TASK_SIZE;
93233+ vma = vma_m;
93234+ } else
93235+ address_m = address + SEGMEXEC_TASK_SIZE;
93236+
93237+ pgd_m = pgd_offset(mm, address_m);
93238+ pud_m = pud_alloc(mm, pgd_m, address_m);
93239+ if (!pud_m)
93240+ return VM_FAULT_OOM;
93241+ pmd_m = pmd_alloc(mm, pud_m, address_m);
93242+ if (!pmd_m)
93243+ return VM_FAULT_OOM;
93244+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
93245+ return VM_FAULT_OOM;
93246+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
93247+ }
93248+#endif
93249+
93250 pgd = pgd_offset(mm, address);
93251 pud = pud_alloc(mm, pgd, address);
93252 if (!pud)
93253@@ -4003,6 +4251,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93254 spin_unlock(&mm->page_table_lock);
93255 return 0;
93256 }
93257+
93258+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93259+{
93260+ pud_t *new = pud_alloc_one(mm, address);
93261+ if (!new)
93262+ return -ENOMEM;
93263+
93264+ smp_wmb(); /* See comment in __pte_alloc */
93265+
93266+ spin_lock(&mm->page_table_lock);
93267+ if (pgd_present(*pgd)) /* Another has populated it */
93268+ pud_free(mm, new);
93269+ else
93270+ pgd_populate_kernel(mm, pgd, new);
93271+ spin_unlock(&mm->page_table_lock);
93272+ return 0;
93273+}
93274 #endif /* __PAGETABLE_PUD_FOLDED */
93275
93276 #ifndef __PAGETABLE_PMD_FOLDED
93277@@ -4033,6 +4298,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
93278 spin_unlock(&mm->page_table_lock);
93279 return 0;
93280 }
93281+
93282+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
93283+{
93284+ pmd_t *new = pmd_alloc_one(mm, address);
93285+ if (!new)
93286+ return -ENOMEM;
93287+
93288+ smp_wmb(); /* See comment in __pte_alloc */
93289+
93290+ spin_lock(&mm->page_table_lock);
93291+#ifndef __ARCH_HAS_4LEVEL_HACK
93292+ if (pud_present(*pud)) /* Another has populated it */
93293+ pmd_free(mm, new);
93294+ else
93295+ pud_populate_kernel(mm, pud, new);
93296+#else
93297+ if (pgd_present(*pud)) /* Another has populated it */
93298+ pmd_free(mm, new);
93299+ else
93300+ pgd_populate_kernel(mm, pud, new);
93301+#endif /* __ARCH_HAS_4LEVEL_HACK */
93302+ spin_unlock(&mm->page_table_lock);
93303+ return 0;
93304+}
93305 #endif /* __PAGETABLE_PMD_FOLDED */
93306
93307 #if !defined(__HAVE_ARCH_GATE_AREA)
93308@@ -4046,7 +4335,7 @@ static int __init gate_vma_init(void)
93309 gate_vma.vm_start = FIXADDR_USER_START;
93310 gate_vma.vm_end = FIXADDR_USER_END;
93311 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
93312- gate_vma.vm_page_prot = __P101;
93313+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
93314
93315 return 0;
93316 }
93317@@ -4180,8 +4469,8 @@ out:
93318 return ret;
93319 }
93320
93321-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93322- void *buf, int len, int write)
93323+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93324+ void *buf, size_t len, int write)
93325 {
93326 resource_size_t phys_addr;
93327 unsigned long prot = 0;
93328@@ -4207,8 +4496,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
93329 * Access another process' address space as given in mm. If non-NULL, use the
93330 * given task for page fault accounting.
93331 */
93332-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93333- unsigned long addr, void *buf, int len, int write)
93334+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93335+ unsigned long addr, void *buf, size_t len, int write)
93336 {
93337 struct vm_area_struct *vma;
93338 void *old_buf = buf;
93339@@ -4216,7 +4505,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93340 down_read(&mm->mmap_sem);
93341 /* ignore errors, just check how much was successfully transferred */
93342 while (len) {
93343- int bytes, ret, offset;
93344+ ssize_t bytes, ret, offset;
93345 void *maddr;
93346 struct page *page = NULL;
93347
93348@@ -4275,8 +4564,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93349 *
93350 * The caller must hold a reference on @mm.
93351 */
93352-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93353- void *buf, int len, int write)
93354+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93355+ void *buf, size_t len, int write)
93356 {
93357 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93358 }
93359@@ -4286,11 +4575,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93360 * Source/target buffer must be kernel space,
93361 * Do not walk the page table directly, use get_user_pages
93362 */
93363-int access_process_vm(struct task_struct *tsk, unsigned long addr,
93364- void *buf, int len, int write)
93365+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
93366+ void *buf, size_t len, int write)
93367 {
93368 struct mm_struct *mm;
93369- int ret;
93370+ ssize_t ret;
93371
93372 mm = get_task_mm(tsk);
93373 if (!mm)
93374diff --git a/mm/mempolicy.c b/mm/mempolicy.c
93375index 30cc47f8..c12ef34 100644
93376--- a/mm/mempolicy.c
93377+++ b/mm/mempolicy.c
93378@@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93379 unsigned long vmstart;
93380 unsigned long vmend;
93381
93382+#ifdef CONFIG_PAX_SEGMEXEC
93383+ struct vm_area_struct *vma_m;
93384+#endif
93385+
93386 vma = find_vma(mm, start);
93387 if (!vma || vma->vm_start > start)
93388 return -EFAULT;
93389@@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93390 err = vma_replace_policy(vma, new_pol);
93391 if (err)
93392 goto out;
93393+
93394+#ifdef CONFIG_PAX_SEGMEXEC
93395+ vma_m = pax_find_mirror_vma(vma);
93396+ if (vma_m) {
93397+ err = vma_replace_policy(vma_m, new_pol);
93398+ if (err)
93399+ goto out;
93400+ }
93401+#endif
93402+
93403 }
93404
93405 out:
93406@@ -1225,6 +1239,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93407
93408 if (end < start)
93409 return -EINVAL;
93410+
93411+#ifdef CONFIG_PAX_SEGMEXEC
93412+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93413+ if (end > SEGMEXEC_TASK_SIZE)
93414+ return -EINVAL;
93415+ } else
93416+#endif
93417+
93418+ if (end > TASK_SIZE)
93419+ return -EINVAL;
93420+
93421 if (end == start)
93422 return 0;
93423
93424@@ -1453,8 +1478,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93425 */
93426 tcred = __task_cred(task);
93427 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93428- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93429- !capable(CAP_SYS_NICE)) {
93430+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93431 rcu_read_unlock();
93432 err = -EPERM;
93433 goto out_put;
93434@@ -1485,6 +1509,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93435 goto out;
93436 }
93437
93438+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93439+ if (mm != current->mm &&
93440+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93441+ mmput(mm);
93442+ err = -EPERM;
93443+ goto out;
93444+ }
93445+#endif
93446+
93447 err = do_migrate_pages(mm, old, new,
93448 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93449
93450diff --git a/mm/migrate.c b/mm/migrate.c
93451index bed4880..a493f67 100644
93452--- a/mm/migrate.c
93453+++ b/mm/migrate.c
93454@@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93455 */
93456 tcred = __task_cred(task);
93457 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93458- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93459- !capable(CAP_SYS_NICE)) {
93460+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93461 rcu_read_unlock();
93462 err = -EPERM;
93463 goto out;
93464diff --git a/mm/mlock.c b/mm/mlock.c
93465index b1eb536..091d154 100644
93466--- a/mm/mlock.c
93467+++ b/mm/mlock.c
93468@@ -14,6 +14,7 @@
93469 #include <linux/pagevec.h>
93470 #include <linux/mempolicy.h>
93471 #include <linux/syscalls.h>
93472+#include <linux/security.h>
93473 #include <linux/sched.h>
93474 #include <linux/export.h>
93475 #include <linux/rmap.h>
93476@@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
93477 {
93478 unsigned long nstart, end, tmp;
93479 struct vm_area_struct * vma, * prev;
93480- int error;
93481+ int error = 0;
93482
93483 VM_BUG_ON(start & ~PAGE_MASK);
93484 VM_BUG_ON(len != PAGE_ALIGN(len));
93485@@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
93486 return -EINVAL;
93487 if (end == start)
93488 return 0;
93489+ if (end > TASK_SIZE)
93490+ return -EINVAL;
93491+
93492 vma = find_vma(current->mm, start);
93493 if (!vma || vma->vm_start > start)
93494 return -ENOMEM;
93495@@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
93496 for (nstart = start ; ; ) {
93497 vm_flags_t newflags;
93498
93499+#ifdef CONFIG_PAX_SEGMEXEC
93500+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93501+ break;
93502+#endif
93503+
93504 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
93505
93506 newflags = vma->vm_flags & ~VM_LOCKED;
93507@@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
93508 locked += current->mm->locked_vm;
93509
93510 /* check against resource limits */
93511+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
93512 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
93513 error = do_mlock(start, len, 1);
93514
93515@@ -776,6 +786,11 @@ static int do_mlockall(int flags)
93516 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
93517 vm_flags_t newflags;
93518
93519+#ifdef CONFIG_PAX_SEGMEXEC
93520+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93521+ break;
93522+#endif
93523+
93524 newflags = vma->vm_flags & ~VM_LOCKED;
93525 if (flags & MCL_CURRENT)
93526 newflags |= VM_LOCKED;
93527@@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
93528 lock_limit >>= PAGE_SHIFT;
93529
93530 ret = -ENOMEM;
93531+
93532+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
93533+
93534 down_write(&current->mm->mmap_sem);
93535-
93536 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
93537 capable(CAP_IPC_LOCK))
93538 ret = do_mlockall(flags);
93539diff --git a/mm/mmap.c b/mm/mmap.c
93540index b1202cf..ee487f8 100644
93541--- a/mm/mmap.c
93542+++ b/mm/mmap.c
93543@@ -37,6 +37,7 @@
93544 #include <linux/sched/sysctl.h>
93545 #include <linux/notifier.h>
93546 #include <linux/memory.h>
93547+#include <linux/random.h>
93548
93549 #include <asm/uaccess.h>
93550 #include <asm/cacheflush.h>
93551@@ -53,6 +54,16 @@
93552 #define arch_rebalance_pgtables(addr, len) (addr)
93553 #endif
93554
93555+static inline void verify_mm_writelocked(struct mm_struct *mm)
93556+{
93557+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
93558+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93559+ up_read(&mm->mmap_sem);
93560+ BUG();
93561+ }
93562+#endif
93563+}
93564+
93565 static void unmap_region(struct mm_struct *mm,
93566 struct vm_area_struct *vma, struct vm_area_struct *prev,
93567 unsigned long start, unsigned long end);
93568@@ -72,16 +83,25 @@ static void unmap_region(struct mm_struct *mm,
93569 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
93570 *
93571 */
93572-pgprot_t protection_map[16] = {
93573+pgprot_t protection_map[16] __read_only = {
93574 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
93575 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
93576 };
93577
93578-pgprot_t vm_get_page_prot(unsigned long vm_flags)
93579+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
93580 {
93581- return __pgprot(pgprot_val(protection_map[vm_flags &
93582+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
93583 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
93584 pgprot_val(arch_vm_get_page_prot(vm_flags)));
93585+
93586+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93587+ if (!(__supported_pte_mask & _PAGE_NX) &&
93588+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
93589+ (vm_flags & (VM_READ | VM_WRITE)))
93590+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
93591+#endif
93592+
93593+ return prot;
93594 }
93595 EXPORT_SYMBOL(vm_get_page_prot);
93596
93597@@ -91,6 +111,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
93598 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
93599 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93600 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93601+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
93602 /*
93603 * Make sure vm_committed_as in one cacheline and not cacheline shared with
93604 * other variables. It can be updated by several CPUs frequently.
93605@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
93606 struct vm_area_struct *next = vma->vm_next;
93607
93608 might_sleep();
93609+ BUG_ON(vma->vm_mirror);
93610 if (vma->vm_ops && vma->vm_ops->close)
93611 vma->vm_ops->close(vma);
93612 if (vma->vm_file)
93613@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
93614 * not page aligned -Ram Gupta
93615 */
93616 rlim = rlimit(RLIMIT_DATA);
93617+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
93618 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
93619 (mm->end_data - mm->start_data) > rlim)
93620 goto out;
93621@@ -942,6 +965,12 @@ static int
93622 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
93623 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93624 {
93625+
93626+#ifdef CONFIG_PAX_SEGMEXEC
93627+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
93628+ return 0;
93629+#endif
93630+
93631 if (is_mergeable_vma(vma, file, vm_flags) &&
93632 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93633 if (vma->vm_pgoff == vm_pgoff)
93634@@ -961,6 +990,12 @@ static int
93635 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93636 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93637 {
93638+
93639+#ifdef CONFIG_PAX_SEGMEXEC
93640+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
93641+ return 0;
93642+#endif
93643+
93644 if (is_mergeable_vma(vma, file, vm_flags) &&
93645 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93646 pgoff_t vm_pglen;
93647@@ -1003,13 +1038,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93648 struct vm_area_struct *vma_merge(struct mm_struct *mm,
93649 struct vm_area_struct *prev, unsigned long addr,
93650 unsigned long end, unsigned long vm_flags,
93651- struct anon_vma *anon_vma, struct file *file,
93652+ struct anon_vma *anon_vma, struct file *file,
93653 pgoff_t pgoff, struct mempolicy *policy)
93654 {
93655 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
93656 struct vm_area_struct *area, *next;
93657 int err;
93658
93659+#ifdef CONFIG_PAX_SEGMEXEC
93660+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
93661+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
93662+
93663+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
93664+#endif
93665+
93666 /*
93667 * We later require that vma->vm_flags == vm_flags,
93668 * so this tests vma->vm_flags & VM_SPECIAL, too.
93669@@ -1025,6 +1067,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93670 if (next && next->vm_end == end) /* cases 6, 7, 8 */
93671 next = next->vm_next;
93672
93673+#ifdef CONFIG_PAX_SEGMEXEC
93674+ if (prev)
93675+ prev_m = pax_find_mirror_vma(prev);
93676+ if (area)
93677+ area_m = pax_find_mirror_vma(area);
93678+ if (next)
93679+ next_m = pax_find_mirror_vma(next);
93680+#endif
93681+
93682 /*
93683 * Can it merge with the predecessor?
93684 */
93685@@ -1044,9 +1095,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93686 /* cases 1, 6 */
93687 err = vma_adjust(prev, prev->vm_start,
93688 next->vm_end, prev->vm_pgoff, NULL);
93689- } else /* cases 2, 5, 7 */
93690+
93691+#ifdef CONFIG_PAX_SEGMEXEC
93692+ if (!err && prev_m)
93693+ err = vma_adjust(prev_m, prev_m->vm_start,
93694+ next_m->vm_end, prev_m->vm_pgoff, NULL);
93695+#endif
93696+
93697+ } else { /* cases 2, 5, 7 */
93698 err = vma_adjust(prev, prev->vm_start,
93699 end, prev->vm_pgoff, NULL);
93700+
93701+#ifdef CONFIG_PAX_SEGMEXEC
93702+ if (!err && prev_m)
93703+ err = vma_adjust(prev_m, prev_m->vm_start,
93704+ end_m, prev_m->vm_pgoff, NULL);
93705+#endif
93706+
93707+ }
93708 if (err)
93709 return NULL;
93710 khugepaged_enter_vma_merge(prev);
93711@@ -1060,12 +1126,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93712 mpol_equal(policy, vma_policy(next)) &&
93713 can_vma_merge_before(next, vm_flags,
93714 anon_vma, file, pgoff+pglen)) {
93715- if (prev && addr < prev->vm_end) /* case 4 */
93716+ if (prev && addr < prev->vm_end) { /* case 4 */
93717 err = vma_adjust(prev, prev->vm_start,
93718 addr, prev->vm_pgoff, NULL);
93719- else /* cases 3, 8 */
93720+
93721+#ifdef CONFIG_PAX_SEGMEXEC
93722+ if (!err && prev_m)
93723+ err = vma_adjust(prev_m, prev_m->vm_start,
93724+ addr_m, prev_m->vm_pgoff, NULL);
93725+#endif
93726+
93727+ } else { /* cases 3, 8 */
93728 err = vma_adjust(area, addr, next->vm_end,
93729 next->vm_pgoff - pglen, NULL);
93730+
93731+#ifdef CONFIG_PAX_SEGMEXEC
93732+ if (!err && area_m)
93733+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
93734+ next_m->vm_pgoff - pglen, NULL);
93735+#endif
93736+
93737+ }
93738 if (err)
93739 return NULL;
93740 khugepaged_enter_vma_merge(area);
93741@@ -1174,8 +1255,10 @@ none:
93742 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93743 struct file *file, long pages)
93744 {
93745- const unsigned long stack_flags
93746- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
93747+
93748+#ifdef CONFIG_PAX_RANDMMAP
93749+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93750+#endif
93751
93752 mm->total_vm += pages;
93753
93754@@ -1183,7 +1266,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93755 mm->shared_vm += pages;
93756 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
93757 mm->exec_vm += pages;
93758- } else if (flags & stack_flags)
93759+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
93760 mm->stack_vm += pages;
93761 }
93762 #endif /* CONFIG_PROC_FS */
93763@@ -1213,6 +1296,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
93764 locked += mm->locked_vm;
93765 lock_limit = rlimit(RLIMIT_MEMLOCK);
93766 lock_limit >>= PAGE_SHIFT;
93767+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93768 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
93769 return -EAGAIN;
93770 }
93771@@ -1239,7 +1323,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93772 * (the exception is when the underlying filesystem is noexec
93773 * mounted, in which case we dont add PROT_EXEC.)
93774 */
93775- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93776+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93777 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
93778 prot |= PROT_EXEC;
93779
93780@@ -1265,7 +1349,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93781 /* Obtain the address to map to. we verify (or select) it and ensure
93782 * that it represents a valid section of the address space.
93783 */
93784- addr = get_unmapped_area(file, addr, len, pgoff, flags);
93785+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
93786 if (addr & ~PAGE_MASK)
93787 return addr;
93788
93789@@ -1276,6 +1360,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93790 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
93791 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
93792
93793+#ifdef CONFIG_PAX_MPROTECT
93794+ if (mm->pax_flags & MF_PAX_MPROTECT) {
93795+
93796+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
93797+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
93798+ mm->binfmt->handle_mmap)
93799+ mm->binfmt->handle_mmap(file);
93800+#endif
93801+
93802+#ifndef CONFIG_PAX_MPROTECT_COMPAT
93803+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
93804+ gr_log_rwxmmap(file);
93805+
93806+#ifdef CONFIG_PAX_EMUPLT
93807+ vm_flags &= ~VM_EXEC;
93808+#else
93809+ return -EPERM;
93810+#endif
93811+
93812+ }
93813+
93814+ if (!(vm_flags & VM_EXEC))
93815+ vm_flags &= ~VM_MAYEXEC;
93816+#else
93817+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93818+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93819+#endif
93820+ else
93821+ vm_flags &= ~VM_MAYWRITE;
93822+ }
93823+#endif
93824+
93825+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93826+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
93827+ vm_flags &= ~VM_PAGEEXEC;
93828+#endif
93829+
93830 if (flags & MAP_LOCKED)
93831 if (!can_do_mlock())
93832 return -EPERM;
93833@@ -1363,6 +1484,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93834 vm_flags |= VM_NORESERVE;
93835 }
93836
93837+ if (!gr_acl_handle_mmap(file, prot))
93838+ return -EACCES;
93839+
93840 addr = mmap_region(file, addr, len, vm_flags, pgoff);
93841 if (!IS_ERR_VALUE(addr) &&
93842 ((vm_flags & VM_LOCKED) ||
93843@@ -1456,7 +1580,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
93844 vm_flags_t vm_flags = vma->vm_flags;
93845
93846 /* If it was private or non-writable, the write bit is already clear */
93847- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
93848+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
93849 return 0;
93850
93851 /* The backer wishes to know when pages are first written to? */
93852@@ -1502,7 +1626,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93853 struct rb_node **rb_link, *rb_parent;
93854 unsigned long charged = 0;
93855
93856+#ifdef CONFIG_PAX_SEGMEXEC
93857+ struct vm_area_struct *vma_m = NULL;
93858+#endif
93859+
93860+ /*
93861+ * mm->mmap_sem is required to protect against another thread
93862+ * changing the mappings in case we sleep.
93863+ */
93864+ verify_mm_writelocked(mm);
93865+
93866 /* Check against address space limit. */
93867+
93868+#ifdef CONFIG_PAX_RANDMMAP
93869+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93870+#endif
93871+
93872 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
93873 unsigned long nr_pages;
93874
93875@@ -1521,11 +1660,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93876
93877 /* Clear old maps */
93878 error = -ENOMEM;
93879-munmap_back:
93880 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93881 if (do_munmap(mm, addr, len))
93882 return -ENOMEM;
93883- goto munmap_back;
93884+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93885 }
93886
93887 /*
93888@@ -1556,6 +1694,16 @@ munmap_back:
93889 goto unacct_error;
93890 }
93891
93892+#ifdef CONFIG_PAX_SEGMEXEC
93893+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
93894+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93895+ if (!vma_m) {
93896+ error = -ENOMEM;
93897+ goto free_vma;
93898+ }
93899+ }
93900+#endif
93901+
93902 vma->vm_mm = mm;
93903 vma->vm_start = addr;
93904 vma->vm_end = addr + len;
93905@@ -1575,6 +1723,13 @@ munmap_back:
93906 if (error)
93907 goto unmap_and_free_vma;
93908
93909+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93910+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
93911+ vma->vm_flags |= VM_PAGEEXEC;
93912+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93913+ }
93914+#endif
93915+
93916 /* Can addr have changed??
93917 *
93918 * Answer: Yes, several device drivers can do it in their
93919@@ -1608,6 +1763,12 @@ munmap_back:
93920 }
93921
93922 vma_link(mm, vma, prev, rb_link, rb_parent);
93923+
93924+#ifdef CONFIG_PAX_SEGMEXEC
93925+ if (vma_m)
93926+ BUG_ON(pax_mirror_vma(vma_m, vma));
93927+#endif
93928+
93929 /* Once vma denies write, undo our temporary denial count */
93930 if (vm_flags & VM_DENYWRITE)
93931 allow_write_access(file);
93932@@ -1616,6 +1777,7 @@ out:
93933 perf_event_mmap(vma);
93934
93935 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
93936+ track_exec_limit(mm, addr, addr + len, vm_flags);
93937 if (vm_flags & VM_LOCKED) {
93938 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
93939 vma == get_gate_vma(current->mm)))
93940@@ -1648,6 +1810,12 @@ unmap_and_free_vma:
93941 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
93942 charged = 0;
93943 free_vma:
93944+
93945+#ifdef CONFIG_PAX_SEGMEXEC
93946+ if (vma_m)
93947+ kmem_cache_free(vm_area_cachep, vma_m);
93948+#endif
93949+
93950 kmem_cache_free(vm_area_cachep, vma);
93951 unacct_error:
93952 if (charged)
93953@@ -1655,7 +1823,63 @@ unacct_error:
93954 return error;
93955 }
93956
93957-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93958+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
93959+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
93960+{
93961+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
93962+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
93963+
93964+ return 0;
93965+}
93966+#endif
93967+
93968+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
93969+{
93970+ if (!vma) {
93971+#ifdef CONFIG_STACK_GROWSUP
93972+ if (addr > sysctl_heap_stack_gap)
93973+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
93974+ else
93975+ vma = find_vma(current->mm, 0);
93976+ if (vma && (vma->vm_flags & VM_GROWSUP))
93977+ return false;
93978+#endif
93979+ return true;
93980+ }
93981+
93982+ if (addr + len > vma->vm_start)
93983+ return false;
93984+
93985+ if (vma->vm_flags & VM_GROWSDOWN)
93986+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
93987+#ifdef CONFIG_STACK_GROWSUP
93988+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
93989+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
93990+#endif
93991+ else if (offset)
93992+ return offset <= vma->vm_start - addr - len;
93993+
93994+ return true;
93995+}
93996+
93997+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
93998+{
93999+ if (vma->vm_start < len)
94000+ return -ENOMEM;
94001+
94002+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
94003+ if (offset <= vma->vm_start - len)
94004+ return vma->vm_start - len - offset;
94005+ else
94006+ return -ENOMEM;
94007+ }
94008+
94009+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
94010+ return vma->vm_start - len - sysctl_heap_stack_gap;
94011+ return -ENOMEM;
94012+}
94013+
94014+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94015 {
94016 /*
94017 * We implement the search by looking for an rbtree node that
94018@@ -1703,11 +1927,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94019 }
94020 }
94021
94022- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94023+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94024 check_current:
94025 /* Check if current node has a suitable gap */
94026 if (gap_start > high_limit)
94027 return -ENOMEM;
94028+
94029+ if (gap_end - gap_start > info->threadstack_offset)
94030+ gap_start += info->threadstack_offset;
94031+ else
94032+ gap_start = gap_end;
94033+
94034+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94035+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94036+ gap_start += sysctl_heap_stack_gap;
94037+ else
94038+ gap_start = gap_end;
94039+ }
94040+ if (vma->vm_flags & VM_GROWSDOWN) {
94041+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94042+ gap_end -= sysctl_heap_stack_gap;
94043+ else
94044+ gap_end = gap_start;
94045+ }
94046 if (gap_end >= low_limit && gap_end - gap_start >= length)
94047 goto found;
94048
94049@@ -1757,7 +1999,7 @@ found:
94050 return gap_start;
94051 }
94052
94053-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94054+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94055 {
94056 struct mm_struct *mm = current->mm;
94057 struct vm_area_struct *vma;
94058@@ -1811,6 +2053,24 @@ check_current:
94059 gap_end = vma->vm_start;
94060 if (gap_end < low_limit)
94061 return -ENOMEM;
94062+
94063+ if (gap_end - gap_start > info->threadstack_offset)
94064+ gap_end -= info->threadstack_offset;
94065+ else
94066+ gap_end = gap_start;
94067+
94068+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94069+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94070+ gap_start += sysctl_heap_stack_gap;
94071+ else
94072+ gap_start = gap_end;
94073+ }
94074+ if (vma->vm_flags & VM_GROWSDOWN) {
94075+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94076+ gap_end -= sysctl_heap_stack_gap;
94077+ else
94078+ gap_end = gap_start;
94079+ }
94080 if (gap_start <= high_limit && gap_end - gap_start >= length)
94081 goto found;
94082
94083@@ -1874,6 +2134,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94084 struct mm_struct *mm = current->mm;
94085 struct vm_area_struct *vma;
94086 struct vm_unmapped_area_info info;
94087+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94088
94089 if (len > TASK_SIZE - mmap_min_addr)
94090 return -ENOMEM;
94091@@ -1881,11 +2142,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94092 if (flags & MAP_FIXED)
94093 return addr;
94094
94095+#ifdef CONFIG_PAX_RANDMMAP
94096+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94097+#endif
94098+
94099 if (addr) {
94100 addr = PAGE_ALIGN(addr);
94101 vma = find_vma(mm, addr);
94102 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94103- (!vma || addr + len <= vma->vm_start))
94104+ check_heap_stack_gap(vma, addr, len, offset))
94105 return addr;
94106 }
94107
94108@@ -1894,6 +2159,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94109 info.low_limit = mm->mmap_base;
94110 info.high_limit = TASK_SIZE;
94111 info.align_mask = 0;
94112+ info.threadstack_offset = offset;
94113 return vm_unmapped_area(&info);
94114 }
94115 #endif
94116@@ -1912,6 +2178,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94117 struct mm_struct *mm = current->mm;
94118 unsigned long addr = addr0;
94119 struct vm_unmapped_area_info info;
94120+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94121
94122 /* requested length too big for entire address space */
94123 if (len > TASK_SIZE - mmap_min_addr)
94124@@ -1920,12 +2187,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94125 if (flags & MAP_FIXED)
94126 return addr;
94127
94128+#ifdef CONFIG_PAX_RANDMMAP
94129+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94130+#endif
94131+
94132 /* requesting a specific address */
94133 if (addr) {
94134 addr = PAGE_ALIGN(addr);
94135 vma = find_vma(mm, addr);
94136 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94137- (!vma || addr + len <= vma->vm_start))
94138+ check_heap_stack_gap(vma, addr, len, offset))
94139 return addr;
94140 }
94141
94142@@ -1934,6 +2205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94143 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94144 info.high_limit = mm->mmap_base;
94145 info.align_mask = 0;
94146+ info.threadstack_offset = offset;
94147 addr = vm_unmapped_area(&info);
94148
94149 /*
94150@@ -1946,6 +2218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94151 VM_BUG_ON(addr != -ENOMEM);
94152 info.flags = 0;
94153 info.low_limit = TASK_UNMAPPED_BASE;
94154+
94155+#ifdef CONFIG_PAX_RANDMMAP
94156+ if (mm->pax_flags & MF_PAX_RANDMMAP)
94157+ info.low_limit += mm->delta_mmap;
94158+#endif
94159+
94160 info.high_limit = TASK_SIZE;
94161 addr = vm_unmapped_area(&info);
94162 }
94163@@ -2046,6 +2324,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94164 return vma;
94165 }
94166
94167+#ifdef CONFIG_PAX_SEGMEXEC
94168+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94169+{
94170+ struct vm_area_struct *vma_m;
94171+
94172+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94173+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94174+ BUG_ON(vma->vm_mirror);
94175+ return NULL;
94176+ }
94177+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94178+ vma_m = vma->vm_mirror;
94179+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94180+ BUG_ON(vma->vm_file != vma_m->vm_file);
94181+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94182+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94183+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94184+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94185+ return vma_m;
94186+}
94187+#endif
94188+
94189 /*
94190 * Verify that the stack growth is acceptable and
94191 * update accounting. This is shared with both the
94192@@ -2062,6 +2362,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94193 return -ENOMEM;
94194
94195 /* Stack limit test */
94196+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
94197 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94198 return -ENOMEM;
94199
94200@@ -2072,6 +2373,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94201 locked = mm->locked_vm + grow;
94202 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94203 limit >>= PAGE_SHIFT;
94204+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94205 if (locked > limit && !capable(CAP_IPC_LOCK))
94206 return -ENOMEM;
94207 }
94208@@ -2101,37 +2403,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94209 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
94210 * vma is the last one with address > vma->vm_end. Have to extend vma.
94211 */
94212+#ifndef CONFIG_IA64
94213+static
94214+#endif
94215 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94216 {
94217 int error;
94218+ bool locknext;
94219
94220 if (!(vma->vm_flags & VM_GROWSUP))
94221 return -EFAULT;
94222
94223+ /* Also guard against wrapping around to address 0. */
94224+ if (address < PAGE_ALIGN(address+1))
94225+ address = PAGE_ALIGN(address+1);
94226+ else
94227+ return -ENOMEM;
94228+
94229 /*
94230 * We must make sure the anon_vma is allocated
94231 * so that the anon_vma locking is not a noop.
94232 */
94233 if (unlikely(anon_vma_prepare(vma)))
94234 return -ENOMEM;
94235+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
94236+ if (locknext && anon_vma_prepare(vma->vm_next))
94237+ return -ENOMEM;
94238 vma_lock_anon_vma(vma);
94239+ if (locknext)
94240+ vma_lock_anon_vma(vma->vm_next);
94241
94242 /*
94243 * vma->vm_start/vm_end cannot change under us because the caller
94244 * is required to hold the mmap_sem in read mode. We need the
94245- * anon_vma lock to serialize against concurrent expand_stacks.
94246- * Also guard against wrapping around to address 0.
94247+ * anon_vma locks to serialize against concurrent expand_stacks
94248+ * and expand_upwards.
94249 */
94250- if (address < PAGE_ALIGN(address+4))
94251- address = PAGE_ALIGN(address+4);
94252- else {
94253- vma_unlock_anon_vma(vma);
94254- return -ENOMEM;
94255- }
94256 error = 0;
94257
94258 /* Somebody else might have raced and expanded it already */
94259- if (address > vma->vm_end) {
94260+ 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)
94261+ error = -ENOMEM;
94262+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
94263 unsigned long size, grow;
94264
94265 size = address - vma->vm_start;
94266@@ -2166,6 +2479,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94267 }
94268 }
94269 }
94270+ if (locknext)
94271+ vma_unlock_anon_vma(vma->vm_next);
94272 vma_unlock_anon_vma(vma);
94273 khugepaged_enter_vma_merge(vma);
94274 validate_mm(vma->vm_mm);
94275@@ -2180,6 +2495,8 @@ int expand_downwards(struct vm_area_struct *vma,
94276 unsigned long address)
94277 {
94278 int error;
94279+ bool lockprev = false;
94280+ struct vm_area_struct *prev;
94281
94282 /*
94283 * We must make sure the anon_vma is allocated
94284@@ -2193,6 +2510,15 @@ int expand_downwards(struct vm_area_struct *vma,
94285 if (error)
94286 return error;
94287
94288+ prev = vma->vm_prev;
94289+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
94290+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
94291+#endif
94292+ if (lockprev && anon_vma_prepare(prev))
94293+ return -ENOMEM;
94294+ if (lockprev)
94295+ vma_lock_anon_vma(prev);
94296+
94297 vma_lock_anon_vma(vma);
94298
94299 /*
94300@@ -2202,9 +2528,17 @@ int expand_downwards(struct vm_area_struct *vma,
94301 */
94302
94303 /* Somebody else might have raced and expanded it already */
94304- if (address < vma->vm_start) {
94305+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
94306+ error = -ENOMEM;
94307+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
94308 unsigned long size, grow;
94309
94310+#ifdef CONFIG_PAX_SEGMEXEC
94311+ struct vm_area_struct *vma_m;
94312+
94313+ vma_m = pax_find_mirror_vma(vma);
94314+#endif
94315+
94316 size = vma->vm_end - address;
94317 grow = (vma->vm_start - address) >> PAGE_SHIFT;
94318
94319@@ -2229,13 +2563,27 @@ int expand_downwards(struct vm_area_struct *vma,
94320 vma->vm_pgoff -= grow;
94321 anon_vma_interval_tree_post_update_vma(vma);
94322 vma_gap_update(vma);
94323+
94324+#ifdef CONFIG_PAX_SEGMEXEC
94325+ if (vma_m) {
94326+ anon_vma_interval_tree_pre_update_vma(vma_m);
94327+ vma_m->vm_start -= grow << PAGE_SHIFT;
94328+ vma_m->vm_pgoff -= grow;
94329+ anon_vma_interval_tree_post_update_vma(vma_m);
94330+ vma_gap_update(vma_m);
94331+ }
94332+#endif
94333+
94334 spin_unlock(&vma->vm_mm->page_table_lock);
94335
94336+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
94337 perf_event_mmap(vma);
94338 }
94339 }
94340 }
94341 vma_unlock_anon_vma(vma);
94342+ if (lockprev)
94343+ vma_unlock_anon_vma(prev);
94344 khugepaged_enter_vma_merge(vma);
94345 validate_mm(vma->vm_mm);
94346 return error;
94347@@ -2333,6 +2681,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
94348 do {
94349 long nrpages = vma_pages(vma);
94350
94351+#ifdef CONFIG_PAX_SEGMEXEC
94352+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
94353+ vma = remove_vma(vma);
94354+ continue;
94355+ }
94356+#endif
94357+
94358 if (vma->vm_flags & VM_ACCOUNT)
94359 nr_accounted += nrpages;
94360 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
94361@@ -2377,6 +2732,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
94362 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
94363 vma->vm_prev = NULL;
94364 do {
94365+
94366+#ifdef CONFIG_PAX_SEGMEXEC
94367+ if (vma->vm_mirror) {
94368+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
94369+ vma->vm_mirror->vm_mirror = NULL;
94370+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
94371+ vma->vm_mirror = NULL;
94372+ }
94373+#endif
94374+
94375 vma_rb_erase(vma, &mm->mm_rb);
94376 mm->map_count--;
94377 tail_vma = vma;
94378@@ -2404,14 +2769,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94379 struct vm_area_struct *new;
94380 int err = -ENOMEM;
94381
94382+#ifdef CONFIG_PAX_SEGMEXEC
94383+ struct vm_area_struct *vma_m, *new_m = NULL;
94384+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
94385+#endif
94386+
94387 if (is_vm_hugetlb_page(vma) && (addr &
94388 ~(huge_page_mask(hstate_vma(vma)))))
94389 return -EINVAL;
94390
94391+#ifdef CONFIG_PAX_SEGMEXEC
94392+ vma_m = pax_find_mirror_vma(vma);
94393+#endif
94394+
94395 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94396 if (!new)
94397 goto out_err;
94398
94399+#ifdef CONFIG_PAX_SEGMEXEC
94400+ if (vma_m) {
94401+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94402+ if (!new_m) {
94403+ kmem_cache_free(vm_area_cachep, new);
94404+ goto out_err;
94405+ }
94406+ }
94407+#endif
94408+
94409 /* most fields are the same, copy all, and then fixup */
94410 *new = *vma;
94411
94412@@ -2424,6 +2808,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94413 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94414 }
94415
94416+#ifdef CONFIG_PAX_SEGMEXEC
94417+ if (vma_m) {
94418+ *new_m = *vma_m;
94419+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
94420+ new_m->vm_mirror = new;
94421+ new->vm_mirror = new_m;
94422+
94423+ if (new_below)
94424+ new_m->vm_end = addr_m;
94425+ else {
94426+ new_m->vm_start = addr_m;
94427+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94428+ }
94429+ }
94430+#endif
94431+
94432 err = vma_dup_policy(vma, new);
94433 if (err)
94434 goto out_free_vma;
94435@@ -2443,6 +2843,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94436 else
94437 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94438
94439+#ifdef CONFIG_PAX_SEGMEXEC
94440+ if (!err && vma_m) {
94441+ struct mempolicy *pol = vma_policy(new);
94442+
94443+ if (anon_vma_clone(new_m, vma_m))
94444+ goto out_free_mpol;
94445+
94446+ mpol_get(pol);
94447+ set_vma_policy(new_m, pol);
94448+
94449+ if (new_m->vm_file)
94450+ get_file(new_m->vm_file);
94451+
94452+ if (new_m->vm_ops && new_m->vm_ops->open)
94453+ new_m->vm_ops->open(new_m);
94454+
94455+ if (new_below)
94456+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94457+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94458+ else
94459+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94460+
94461+ if (err) {
94462+ if (new_m->vm_ops && new_m->vm_ops->close)
94463+ new_m->vm_ops->close(new_m);
94464+ if (new_m->vm_file)
94465+ fput(new_m->vm_file);
94466+ mpol_put(pol);
94467+ }
94468+ }
94469+#endif
94470+
94471 /* Success. */
94472 if (!err)
94473 return 0;
94474@@ -2452,10 +2884,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94475 new->vm_ops->close(new);
94476 if (new->vm_file)
94477 fput(new->vm_file);
94478- unlink_anon_vmas(new);
94479 out_free_mpol:
94480 mpol_put(vma_policy(new));
94481 out_free_vma:
94482+
94483+#ifdef CONFIG_PAX_SEGMEXEC
94484+ if (new_m) {
94485+ unlink_anon_vmas(new_m);
94486+ kmem_cache_free(vm_area_cachep, new_m);
94487+ }
94488+#endif
94489+
94490+ unlink_anon_vmas(new);
94491 kmem_cache_free(vm_area_cachep, new);
94492 out_err:
94493 return err;
94494@@ -2468,6 +2908,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94495 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94496 unsigned long addr, int new_below)
94497 {
94498+
94499+#ifdef CONFIG_PAX_SEGMEXEC
94500+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94501+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
94502+ if (mm->map_count >= sysctl_max_map_count-1)
94503+ return -ENOMEM;
94504+ } else
94505+#endif
94506+
94507 if (mm->map_count >= sysctl_max_map_count)
94508 return -ENOMEM;
94509
94510@@ -2479,11 +2928,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94511 * work. This now handles partial unmappings.
94512 * Jeremy Fitzhardinge <jeremy@goop.org>
94513 */
94514+#ifdef CONFIG_PAX_SEGMEXEC
94515 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94516 {
94517+ int ret = __do_munmap(mm, start, len);
94518+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
94519+ return ret;
94520+
94521+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
94522+}
94523+
94524+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94525+#else
94526+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94527+#endif
94528+{
94529 unsigned long end;
94530 struct vm_area_struct *vma, *prev, *last;
94531
94532+ /*
94533+ * mm->mmap_sem is required to protect against another thread
94534+ * changing the mappings in case we sleep.
94535+ */
94536+ verify_mm_writelocked(mm);
94537+
94538 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
94539 return -EINVAL;
94540
94541@@ -2558,6 +3026,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94542 /* Fix up all other VM information */
94543 remove_vma_list(mm, vma);
94544
94545+ track_exec_limit(mm, start, end, 0UL);
94546+
94547 return 0;
94548 }
94549
94550@@ -2566,6 +3036,13 @@ int vm_munmap(unsigned long start, size_t len)
94551 int ret;
94552 struct mm_struct *mm = current->mm;
94553
94554+
94555+#ifdef CONFIG_PAX_SEGMEXEC
94556+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
94557+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
94558+ return -EINVAL;
94559+#endif
94560+
94561 down_write(&mm->mmap_sem);
94562 ret = do_munmap(mm, start, len);
94563 up_write(&mm->mmap_sem);
94564@@ -2579,16 +3056,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
94565 return vm_munmap(addr, len);
94566 }
94567
94568-static inline void verify_mm_writelocked(struct mm_struct *mm)
94569-{
94570-#ifdef CONFIG_DEBUG_VM
94571- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94572- WARN_ON(1);
94573- up_read(&mm->mmap_sem);
94574- }
94575-#endif
94576-}
94577-
94578 /*
94579 * this is really a simplified "do_mmap". it only handles
94580 * anonymous maps. eventually we may be able to do some
94581@@ -2602,6 +3069,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94582 struct rb_node ** rb_link, * rb_parent;
94583 pgoff_t pgoff = addr >> PAGE_SHIFT;
94584 int error;
94585+ unsigned long charged;
94586
94587 len = PAGE_ALIGN(len);
94588 if (!len)
94589@@ -2609,10 +3077,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94590
94591 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
94592
94593+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
94594+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
94595+ flags &= ~VM_EXEC;
94596+
94597+#ifdef CONFIG_PAX_MPROTECT
94598+ if (mm->pax_flags & MF_PAX_MPROTECT)
94599+ flags &= ~VM_MAYEXEC;
94600+#endif
94601+
94602+ }
94603+#endif
94604+
94605 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
94606 if (error & ~PAGE_MASK)
94607 return error;
94608
94609+ charged = len >> PAGE_SHIFT;
94610+
94611 error = mlock_future_check(mm, mm->def_flags, len);
94612 if (error)
94613 return error;
94614@@ -2626,21 +3108,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94615 /*
94616 * Clear old maps. this also does some error checking for us
94617 */
94618- munmap_back:
94619 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94620 if (do_munmap(mm, addr, len))
94621 return -ENOMEM;
94622- goto munmap_back;
94623+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94624 }
94625
94626 /* Check against address space limits *after* clearing old maps... */
94627- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
94628+ if (!may_expand_vm(mm, charged))
94629 return -ENOMEM;
94630
94631 if (mm->map_count > sysctl_max_map_count)
94632 return -ENOMEM;
94633
94634- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
94635+ if (security_vm_enough_memory_mm(mm, charged))
94636 return -ENOMEM;
94637
94638 /* Can we just expand an old private anonymous mapping? */
94639@@ -2654,7 +3135,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94640 */
94641 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94642 if (!vma) {
94643- vm_unacct_memory(len >> PAGE_SHIFT);
94644+ vm_unacct_memory(charged);
94645 return -ENOMEM;
94646 }
94647
94648@@ -2668,10 +3149,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94649 vma_link(mm, vma, prev, rb_link, rb_parent);
94650 out:
94651 perf_event_mmap(vma);
94652- mm->total_vm += len >> PAGE_SHIFT;
94653+ mm->total_vm += charged;
94654 if (flags & VM_LOCKED)
94655- mm->locked_vm += (len >> PAGE_SHIFT);
94656+ mm->locked_vm += charged;
94657 vma->vm_flags |= VM_SOFTDIRTY;
94658+ track_exec_limit(mm, addr, addr + len, flags);
94659 return addr;
94660 }
94661
94662@@ -2733,6 +3215,7 @@ void exit_mmap(struct mm_struct *mm)
94663 while (vma) {
94664 if (vma->vm_flags & VM_ACCOUNT)
94665 nr_accounted += vma_pages(vma);
94666+ vma->vm_mirror = NULL;
94667 vma = remove_vma(vma);
94668 }
94669 vm_unacct_memory(nr_accounted);
94670@@ -2750,6 +3233,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94671 struct vm_area_struct *prev;
94672 struct rb_node **rb_link, *rb_parent;
94673
94674+#ifdef CONFIG_PAX_SEGMEXEC
94675+ struct vm_area_struct *vma_m = NULL;
94676+#endif
94677+
94678+ if (security_mmap_addr(vma->vm_start))
94679+ return -EPERM;
94680+
94681 /*
94682 * The vm_pgoff of a purely anonymous vma should be irrelevant
94683 * until its first write fault, when page's anon_vma and index
94684@@ -2773,7 +3263,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94685 security_vm_enough_memory_mm(mm, vma_pages(vma)))
94686 return -ENOMEM;
94687
94688+#ifdef CONFIG_PAX_SEGMEXEC
94689+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
94690+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94691+ if (!vma_m)
94692+ return -ENOMEM;
94693+ }
94694+#endif
94695+
94696 vma_link(mm, vma, prev, rb_link, rb_parent);
94697+
94698+#ifdef CONFIG_PAX_SEGMEXEC
94699+ if (vma_m)
94700+ BUG_ON(pax_mirror_vma(vma_m, vma));
94701+#endif
94702+
94703 return 0;
94704 }
94705
94706@@ -2792,6 +3296,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94707 struct rb_node **rb_link, *rb_parent;
94708 bool faulted_in_anon_vma = true;
94709
94710+ BUG_ON(vma->vm_mirror);
94711+
94712 /*
94713 * If anonymous vma has not yet been faulted, update new pgoff
94714 * to match new location, to increase its chance of merging.
94715@@ -2856,6 +3362,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94716 return NULL;
94717 }
94718
94719+#ifdef CONFIG_PAX_SEGMEXEC
94720+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
94721+{
94722+ struct vm_area_struct *prev_m;
94723+ struct rb_node **rb_link_m, *rb_parent_m;
94724+ struct mempolicy *pol_m;
94725+
94726+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
94727+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
94728+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
94729+ *vma_m = *vma;
94730+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
94731+ if (anon_vma_clone(vma_m, vma))
94732+ return -ENOMEM;
94733+ pol_m = vma_policy(vma_m);
94734+ mpol_get(pol_m);
94735+ set_vma_policy(vma_m, pol_m);
94736+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
94737+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
94738+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
94739+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
94740+ if (vma_m->vm_file)
94741+ get_file(vma_m->vm_file);
94742+ if (vma_m->vm_ops && vma_m->vm_ops->open)
94743+ vma_m->vm_ops->open(vma_m);
94744+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
94745+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
94746+ vma_m->vm_mirror = vma;
94747+ vma->vm_mirror = vma_m;
94748+ return 0;
94749+}
94750+#endif
94751+
94752 /*
94753 * Return true if the calling process may expand its vm space by the passed
94754 * number of pages
94755@@ -2867,6 +3406,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
94756
94757 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
94758
94759+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
94760 if (cur + npages > lim)
94761 return 0;
94762 return 1;
94763@@ -2937,6 +3477,22 @@ struct vm_area_struct *_install_special_mapping(struct mm_struct *mm,
94764 vma->vm_start = addr;
94765 vma->vm_end = addr + len;
94766
94767+#ifdef CONFIG_PAX_MPROTECT
94768+ if (mm->pax_flags & MF_PAX_MPROTECT) {
94769+#ifndef CONFIG_PAX_MPROTECT_COMPAT
94770+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
94771+ return ERR_PTR(-EPERM);
94772+ if (!(vm_flags & VM_EXEC))
94773+ vm_flags &= ~VM_MAYEXEC;
94774+#else
94775+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94776+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94777+#endif
94778+ else
94779+ vm_flags &= ~VM_MAYWRITE;
94780+ }
94781+#endif
94782+
94783 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
94784 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94785
94786diff --git a/mm/mprotect.c b/mm/mprotect.c
94787index c43d557..0b7ccd2 100644
94788--- a/mm/mprotect.c
94789+++ b/mm/mprotect.c
94790@@ -24,10 +24,18 @@
94791 #include <linux/migrate.h>
94792 #include <linux/perf_event.h>
94793 #include <linux/ksm.h>
94794+#include <linux/sched/sysctl.h>
94795+
94796+#ifdef CONFIG_PAX_MPROTECT
94797+#include <linux/elf.h>
94798+#include <linux/binfmts.h>
94799+#endif
94800+
94801 #include <asm/uaccess.h>
94802 #include <asm/pgtable.h>
94803 #include <asm/cacheflush.h>
94804 #include <asm/tlbflush.h>
94805+#include <asm/mmu_context.h>
94806
94807 #ifndef pgprot_modify
94808 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
94809@@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
94810 return pages;
94811 }
94812
94813+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94814+/* called while holding the mmap semaphor for writing except stack expansion */
94815+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
94816+{
94817+ unsigned long oldlimit, newlimit = 0UL;
94818+
94819+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
94820+ return;
94821+
94822+ spin_lock(&mm->page_table_lock);
94823+ oldlimit = mm->context.user_cs_limit;
94824+ if ((prot & VM_EXEC) && oldlimit < end)
94825+ /* USER_CS limit moved up */
94826+ newlimit = end;
94827+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
94828+ /* USER_CS limit moved down */
94829+ newlimit = start;
94830+
94831+ if (newlimit) {
94832+ mm->context.user_cs_limit = newlimit;
94833+
94834+#ifdef CONFIG_SMP
94835+ wmb();
94836+ cpus_clear(mm->context.cpu_user_cs_mask);
94837+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
94838+#endif
94839+
94840+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
94841+ }
94842+ spin_unlock(&mm->page_table_lock);
94843+ if (newlimit == end) {
94844+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
94845+
94846+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
94847+ if (is_vm_hugetlb_page(vma))
94848+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
94849+ else
94850+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
94851+ }
94852+}
94853+#endif
94854+
94855 int
94856 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94857 unsigned long start, unsigned long end, unsigned long newflags)
94858@@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94859 int error;
94860 int dirty_accountable = 0;
94861
94862+#ifdef CONFIG_PAX_SEGMEXEC
94863+ struct vm_area_struct *vma_m = NULL;
94864+ unsigned long start_m, end_m;
94865+
94866+ start_m = start + SEGMEXEC_TASK_SIZE;
94867+ end_m = end + SEGMEXEC_TASK_SIZE;
94868+#endif
94869+
94870 if (newflags == oldflags) {
94871 *pprev = vma;
94872 return 0;
94873 }
94874
94875+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
94876+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
94877+
94878+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
94879+ return -ENOMEM;
94880+
94881+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
94882+ return -ENOMEM;
94883+ }
94884+
94885 /*
94886 * If we make a private mapping writable we increase our commit;
94887 * but (without finer accounting) cannot reduce our commit if we
94888@@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94889 }
94890 }
94891
94892+#ifdef CONFIG_PAX_SEGMEXEC
94893+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
94894+ if (start != vma->vm_start) {
94895+ error = split_vma(mm, vma, start, 1);
94896+ if (error)
94897+ goto fail;
94898+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
94899+ *pprev = (*pprev)->vm_next;
94900+ }
94901+
94902+ if (end != vma->vm_end) {
94903+ error = split_vma(mm, vma, end, 0);
94904+ if (error)
94905+ goto fail;
94906+ }
94907+
94908+ if (pax_find_mirror_vma(vma)) {
94909+ error = __do_munmap(mm, start_m, end_m - start_m);
94910+ if (error)
94911+ goto fail;
94912+ } else {
94913+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94914+ if (!vma_m) {
94915+ error = -ENOMEM;
94916+ goto fail;
94917+ }
94918+ vma->vm_flags = newflags;
94919+ error = pax_mirror_vma(vma_m, vma);
94920+ if (error) {
94921+ vma->vm_flags = oldflags;
94922+ goto fail;
94923+ }
94924+ }
94925+ }
94926+#endif
94927+
94928 /*
94929 * First try to merge with previous and/or next vma.
94930 */
94931@@ -319,9 +423,21 @@ success:
94932 * vm_flags and vm_page_prot are protected by the mmap_sem
94933 * held in write mode.
94934 */
94935+
94936+#ifdef CONFIG_PAX_SEGMEXEC
94937+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
94938+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
94939+#endif
94940+
94941 vma->vm_flags = newflags;
94942+
94943+#ifdef CONFIG_PAX_MPROTECT
94944+ if (mm->binfmt && mm->binfmt->handle_mprotect)
94945+ mm->binfmt->handle_mprotect(vma, newflags);
94946+#endif
94947+
94948 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
94949- vm_get_page_prot(newflags));
94950+ vm_get_page_prot(vma->vm_flags));
94951
94952 if (vma_wants_writenotify(vma)) {
94953 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
94954@@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94955 end = start + len;
94956 if (end <= start)
94957 return -ENOMEM;
94958+
94959+#ifdef CONFIG_PAX_SEGMEXEC
94960+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
94961+ if (end > SEGMEXEC_TASK_SIZE)
94962+ return -EINVAL;
94963+ } else
94964+#endif
94965+
94966+ if (end > TASK_SIZE)
94967+ return -EINVAL;
94968+
94969 if (!arch_validate_prot(prot))
94970 return -EINVAL;
94971
94972@@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94973 /*
94974 * Does the application expect PROT_READ to imply PROT_EXEC:
94975 */
94976- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94977+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94978 prot |= PROT_EXEC;
94979
94980 vm_flags = calc_vm_prot_bits(prot);
94981@@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94982 if (start > vma->vm_start)
94983 prev = vma;
94984
94985+#ifdef CONFIG_PAX_MPROTECT
94986+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
94987+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
94988+#endif
94989+
94990 for (nstart = start ; ; ) {
94991 unsigned long newflags;
94992
94993@@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94994
94995 /* newflags >> 4 shift VM_MAY% in place of VM_% */
94996 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
94997+ if (prot & (PROT_WRITE | PROT_EXEC))
94998+ gr_log_rwxmprotect(vma);
94999+
95000+ error = -EACCES;
95001+ goto out;
95002+ }
95003+
95004+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95005 error = -EACCES;
95006 goto out;
95007 }
95008@@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95009 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95010 if (error)
95011 goto out;
95012+
95013+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
95014+
95015 nstart = tmp;
95016
95017 if (nstart < prev->vm_end)
95018diff --git a/mm/mremap.c b/mm/mremap.c
95019index 05f1180..c3cde48 100644
95020--- a/mm/mremap.c
95021+++ b/mm/mremap.c
95022@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95023 continue;
95024 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95025 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95026+
95027+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95028+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95029+ pte = pte_exprotect(pte);
95030+#endif
95031+
95032 pte = move_soft_dirty_pte(pte);
95033 set_pte_at(mm, new_addr, new_pte, pte);
95034 }
95035@@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95036 if (is_vm_hugetlb_page(vma))
95037 goto Einval;
95038
95039+#ifdef CONFIG_PAX_SEGMEXEC
95040+ if (pax_find_mirror_vma(vma))
95041+ goto Einval;
95042+#endif
95043+
95044 /* We can't remap across vm area boundaries */
95045 if (old_len > vma->vm_end - addr)
95046 goto Efault;
95047@@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95048 unsigned long ret = -EINVAL;
95049 unsigned long charged = 0;
95050 unsigned long map_flags;
95051+ unsigned long pax_task_size = TASK_SIZE;
95052
95053 if (new_addr & ~PAGE_MASK)
95054 goto out;
95055
95056- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95057+#ifdef CONFIG_PAX_SEGMEXEC
95058+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95059+ pax_task_size = SEGMEXEC_TASK_SIZE;
95060+#endif
95061+
95062+ pax_task_size -= PAGE_SIZE;
95063+
95064+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95065 goto out;
95066
95067 /* Check if the location we're moving into overlaps the
95068 * old location at all, and fail if it does.
95069 */
95070- if ((new_addr <= addr) && (new_addr+new_len) > addr)
95071- goto out;
95072-
95073- if ((addr <= new_addr) && (addr+old_len) > new_addr)
95074+ if (addr + old_len > new_addr && new_addr + new_len > addr)
95075 goto out;
95076
95077 ret = do_munmap(mm, new_addr, new_len);
95078@@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95079 unsigned long ret = -EINVAL;
95080 unsigned long charged = 0;
95081 bool locked = false;
95082+ unsigned long pax_task_size = TASK_SIZE;
95083
95084 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95085 return ret;
95086@@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95087 if (!new_len)
95088 return ret;
95089
95090+#ifdef CONFIG_PAX_SEGMEXEC
95091+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95092+ pax_task_size = SEGMEXEC_TASK_SIZE;
95093+#endif
95094+
95095+ pax_task_size -= PAGE_SIZE;
95096+
95097+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95098+ old_len > pax_task_size || addr > pax_task_size-old_len)
95099+ return ret;
95100+
95101 down_write(&current->mm->mmap_sem);
95102
95103 if (flags & MREMAP_FIXED) {
95104@@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95105 new_addr = addr;
95106 }
95107 ret = addr;
95108+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95109 goto out;
95110 }
95111 }
95112@@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95113 goto out;
95114 }
95115
95116+ map_flags = vma->vm_flags;
95117 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95118+ if (!(ret & ~PAGE_MASK)) {
95119+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95120+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95121+ }
95122 }
95123 out:
95124 if (ret & ~PAGE_MASK)
95125diff --git a/mm/nommu.c b/mm/nommu.c
95126index 85f8d66..b3375fa 100644
95127--- a/mm/nommu.c
95128+++ b/mm/nommu.c
95129@@ -67,7 +67,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95130 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95131 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95132 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95133-int heap_stack_gap = 0;
95134
95135 atomic_long_t mmap_pages_allocated;
95136
95137@@ -854,15 +853,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95138 EXPORT_SYMBOL(find_vma);
95139
95140 /*
95141- * find a VMA
95142- * - we don't extend stack VMAs under NOMMU conditions
95143- */
95144-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95145-{
95146- return find_vma(mm, addr);
95147-}
95148-
95149-/*
95150 * expand a stack to a given address
95151 * - not supported under NOMMU conditions
95152 */
95153@@ -1569,6 +1559,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95154
95155 /* most fields are the same, copy all, and then fixup */
95156 *new = *vma;
95157+ INIT_LIST_HEAD(&new->anon_vma_chain);
95158 *region = *vma->vm_region;
95159 new->vm_region = region;
95160
95161@@ -2004,8 +1995,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95162 }
95163 EXPORT_SYMBOL(generic_file_remap_pages);
95164
95165-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95166- unsigned long addr, void *buf, int len, int write)
95167+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95168+ unsigned long addr, void *buf, size_t len, int write)
95169 {
95170 struct vm_area_struct *vma;
95171
95172@@ -2046,8 +2037,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95173 *
95174 * The caller must hold a reference on @mm.
95175 */
95176-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95177- void *buf, int len, int write)
95178+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95179+ void *buf, size_t len, int write)
95180 {
95181 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95182 }
95183@@ -2056,7 +2047,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95184 * Access another process' address space.
95185 * - source/target buffer must be kernel space
95186 */
95187-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95188+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95189 {
95190 struct mm_struct *mm;
95191
95192diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95193index a4317da..0198e48 100644
95194--- a/mm/page-writeback.c
95195+++ b/mm/page-writeback.c
95196@@ -685,7 +685,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
95197 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95198 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95199 */
95200-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95201+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95202 unsigned long thresh,
95203 unsigned long bg_thresh,
95204 unsigned long dirty,
95205diff --git a/mm/page_alloc.c b/mm/page_alloc.c
95206index 5dba293..1aca350 100644
95207--- a/mm/page_alloc.c
95208+++ b/mm/page_alloc.c
95209@@ -61,6 +61,7 @@
95210 #include <linux/page-debug-flags.h>
95211 #include <linux/hugetlb.h>
95212 #include <linux/sched/rt.h>
95213+#include <linux/random.h>
95214
95215 #include <asm/sections.h>
95216 #include <asm/tlbflush.h>
95217@@ -355,7 +356,7 @@ out:
95218 * This usage means that zero-order pages may not be compound.
95219 */
95220
95221-static void free_compound_page(struct page *page)
95222+void free_compound_page(struct page *page)
95223 {
95224 __free_pages_ok(page, compound_order(page));
95225 }
95226@@ -729,6 +730,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95227 int i;
95228 int bad = 0;
95229
95230+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95231+ unsigned long index = 1UL << order;
95232+#endif
95233+
95234 trace_mm_page_free(page, order);
95235 kmemcheck_free_shadow(page, order);
95236
95237@@ -745,6 +750,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95238 debug_check_no_obj_freed(page_address(page),
95239 PAGE_SIZE << order);
95240 }
95241+
95242+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95243+ for (; index; --index)
95244+ sanitize_highpage(page + index - 1);
95245+#endif
95246+
95247 arch_free_page(page, order);
95248 kernel_map_pages(page, 1 << order, 0);
95249
95250@@ -767,6 +778,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
95251 local_irq_restore(flags);
95252 }
95253
95254+#ifdef CONFIG_PAX_LATENT_ENTROPY
95255+bool __meminitdata extra_latent_entropy;
95256+
95257+static int __init setup_pax_extra_latent_entropy(char *str)
95258+{
95259+ extra_latent_entropy = true;
95260+ return 0;
95261+}
95262+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
95263+
95264+volatile u64 latent_entropy __latent_entropy;
95265+EXPORT_SYMBOL(latent_entropy);
95266+#endif
95267+
95268 void __init __free_pages_bootmem(struct page *page, unsigned int order)
95269 {
95270 unsigned int nr_pages = 1 << order;
95271@@ -782,6 +807,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
95272 __ClearPageReserved(p);
95273 set_page_count(p, 0);
95274
95275+#ifdef CONFIG_PAX_LATENT_ENTROPY
95276+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
95277+ u64 hash = 0;
95278+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
95279+ const u64 *data = lowmem_page_address(page);
95280+
95281+ for (index = 0; index < end; index++)
95282+ hash ^= hash + data[index];
95283+ latent_entropy ^= hash;
95284+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
95285+ }
95286+#endif
95287+
95288 page_zone(page)->managed_pages += nr_pages;
95289 set_page_refcounted(page);
95290 __free_pages(page, order);
95291@@ -898,8 +936,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
95292 arch_alloc_page(page, order);
95293 kernel_map_pages(page, 1 << order, 1);
95294
95295+#ifndef CONFIG_PAX_MEMORY_SANITIZE
95296 if (gfp_flags & __GFP_ZERO)
95297 prep_zero_page(page, order, gfp_flags);
95298+#endif
95299
95300 if (order && (gfp_flags & __GFP_COMP))
95301 prep_compound_page(page, order);
95302@@ -2402,7 +2442,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
95303 continue;
95304 mod_zone_page_state(zone, NR_ALLOC_BATCH,
95305 high_wmark_pages(zone) - low_wmark_pages(zone) -
95306- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
95307+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
95308 }
95309 }
95310
95311diff --git a/mm/page_io.c b/mm/page_io.c
95312index 7c59ef6..1358905 100644
95313--- a/mm/page_io.c
95314+++ b/mm/page_io.c
95315@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
95316 struct file *swap_file = sis->swap_file;
95317 struct address_space *mapping = swap_file->f_mapping;
95318 struct iovec iov = {
95319- .iov_base = kmap(page),
95320+ .iov_base = (void __force_user *)kmap(page),
95321 .iov_len = PAGE_SIZE,
95322 };
95323
95324diff --git a/mm/percpu.c b/mm/percpu.c
95325index 2ddf9a9..f8fc075 100644
95326--- a/mm/percpu.c
95327+++ b/mm/percpu.c
95328@@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
95329 static unsigned int pcpu_high_unit_cpu __read_mostly;
95330
95331 /* the address of the first chunk which starts with the kernel static area */
95332-void *pcpu_base_addr __read_mostly;
95333+void *pcpu_base_addr __read_only;
95334 EXPORT_SYMBOL_GPL(pcpu_base_addr);
95335
95336 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
95337diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
95338index 8505c92..946bfc9 100644
95339--- a/mm/process_vm_access.c
95340+++ b/mm/process_vm_access.c
95341@@ -13,6 +13,7 @@
95342 #include <linux/uio.h>
95343 #include <linux/sched.h>
95344 #include <linux/highmem.h>
95345+#include <linux/security.h>
95346 #include <linux/ptrace.h>
95347 #include <linux/slab.h>
95348 #include <linux/syscalls.h>
95349@@ -161,19 +162,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95350 ssize_t iov_len;
95351 size_t total_len = iov_iter_count(iter);
95352
95353+ return -ENOSYS; // PaX: until properly audited
95354+
95355 /*
95356 * Work out how many pages of struct pages we're going to need
95357 * when eventually calling get_user_pages
95358 */
95359 for (i = 0; i < riovcnt; i++) {
95360 iov_len = rvec[i].iov_len;
95361- if (iov_len > 0) {
95362- nr_pages_iov = ((unsigned long)rvec[i].iov_base
95363- + iov_len)
95364- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
95365- / PAGE_SIZE + 1;
95366- nr_pages = max(nr_pages, nr_pages_iov);
95367- }
95368+ if (iov_len <= 0)
95369+ continue;
95370+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
95371+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
95372+ nr_pages = max(nr_pages, nr_pages_iov);
95373 }
95374
95375 if (nr_pages == 0)
95376@@ -201,6 +202,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95377 goto free_proc_pages;
95378 }
95379
95380+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
95381+ rc = -EPERM;
95382+ goto put_task_struct;
95383+ }
95384+
95385 mm = mm_access(task, PTRACE_MODE_ATTACH);
95386 if (!mm || IS_ERR(mm)) {
95387 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
95388diff --git a/mm/rmap.c b/mm/rmap.c
95389index 83bfafa..660f059 100644
95390--- a/mm/rmap.c
95391+++ b/mm/rmap.c
95392@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95393 struct anon_vma *anon_vma = vma->anon_vma;
95394 struct anon_vma_chain *avc;
95395
95396+#ifdef CONFIG_PAX_SEGMEXEC
95397+ struct anon_vma_chain *avc_m = NULL;
95398+#endif
95399+
95400 might_sleep();
95401 if (unlikely(!anon_vma)) {
95402 struct mm_struct *mm = vma->vm_mm;
95403@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95404 if (!avc)
95405 goto out_enomem;
95406
95407+#ifdef CONFIG_PAX_SEGMEXEC
95408+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
95409+ if (!avc_m)
95410+ goto out_enomem_free_avc;
95411+#endif
95412+
95413 anon_vma = find_mergeable_anon_vma(vma);
95414 allocated = NULL;
95415 if (!anon_vma) {
95416@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95417 /* page_table_lock to protect against threads */
95418 spin_lock(&mm->page_table_lock);
95419 if (likely(!vma->anon_vma)) {
95420+
95421+#ifdef CONFIG_PAX_SEGMEXEC
95422+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95423+
95424+ if (vma_m) {
95425+ BUG_ON(vma_m->anon_vma);
95426+ vma_m->anon_vma = anon_vma;
95427+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
95428+ avc_m = NULL;
95429+ }
95430+#endif
95431+
95432 vma->anon_vma = anon_vma;
95433 anon_vma_chain_link(vma, avc, anon_vma);
95434 allocated = NULL;
95435@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95436
95437 if (unlikely(allocated))
95438 put_anon_vma(allocated);
95439+
95440+#ifdef CONFIG_PAX_SEGMEXEC
95441+ if (unlikely(avc_m))
95442+ anon_vma_chain_free(avc_m);
95443+#endif
95444+
95445 if (unlikely(avc))
95446 anon_vma_chain_free(avc);
95447 }
95448 return 0;
95449
95450 out_enomem_free_avc:
95451+
95452+#ifdef CONFIG_PAX_SEGMEXEC
95453+ if (avc_m)
95454+ anon_vma_chain_free(avc_m);
95455+#endif
95456+
95457 anon_vma_chain_free(avc);
95458 out_enomem:
95459 return -ENOMEM;
95460@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
95461 * Attach the anon_vmas from src to dst.
95462 * Returns 0 on success, -ENOMEM on failure.
95463 */
95464-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95465+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
95466 {
95467 struct anon_vma_chain *avc, *pavc;
95468 struct anon_vma *root = NULL;
95469@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95470 * the corresponding VMA in the parent process is attached to.
95471 * Returns 0 on success, non-zero on failure.
95472 */
95473-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
95474+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
95475 {
95476 struct anon_vma_chain *avc;
95477 struct anon_vma *anon_vma;
95478@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
95479 void __init anon_vma_init(void)
95480 {
95481 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
95482- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
95483- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
95484+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
95485+ anon_vma_ctor);
95486+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
95487+ SLAB_PANIC|SLAB_NO_SANITIZE);
95488 }
95489
95490 /*
95491diff --git a/mm/shmem.c b/mm/shmem.c
95492index a2801ba..b8651e6 100644
95493--- a/mm/shmem.c
95494+++ b/mm/shmem.c
95495@@ -33,7 +33,7 @@
95496 #include <linux/swap.h>
95497 #include <linux/aio.h>
95498
95499-static struct vfsmount *shm_mnt;
95500+struct vfsmount *shm_mnt;
95501
95502 #ifdef CONFIG_SHMEM
95503 /*
95504@@ -77,14 +77,15 @@ static struct vfsmount *shm_mnt;
95505 #define BOGO_DIRENT_SIZE 20
95506
95507 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
95508-#define SHORT_SYMLINK_LEN 128
95509+#define SHORT_SYMLINK_LEN 64
95510
95511 /*
95512- * shmem_fallocate and shmem_writepage communicate via inode->i_private
95513- * (with i_mutex making sure that it has only one user at a time):
95514- * we would prefer not to enlarge the shmem inode just for that.
95515+ * shmem_fallocate communicates with shmem_fault or shmem_writepage via
95516+ * inode->i_private (with i_mutex making sure that it has only one user at
95517+ * a time): we would prefer not to enlarge the shmem inode just for that.
95518 */
95519 struct shmem_falloc {
95520+ int mode; /* FALLOC_FL mode currently operating */
95521 pgoff_t start; /* start of range currently being fallocated */
95522 pgoff_t next; /* the next page offset to be fallocated */
95523 pgoff_t nr_falloced; /* how many new pages have been fallocated */
95524@@ -759,6 +760,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
95525 spin_lock(&inode->i_lock);
95526 shmem_falloc = inode->i_private;
95527 if (shmem_falloc &&
95528+ !shmem_falloc->mode &&
95529 index >= shmem_falloc->start &&
95530 index < shmem_falloc->next)
95531 shmem_falloc->nr_unswapped++;
95532@@ -1233,6 +1235,43 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
95533 int error;
95534 int ret = VM_FAULT_LOCKED;
95535
95536+ /*
95537+ * Trinity finds that probing a hole which tmpfs is punching can
95538+ * prevent the hole-punch from ever completing: which in turn
95539+ * locks writers out with its hold on i_mutex. So refrain from
95540+ * faulting pages into the hole while it's being punched, and
95541+ * wait on i_mutex to be released if vmf->flags permits,
95542+ */
95543+ if (unlikely(inode->i_private)) {
95544+ struct shmem_falloc *shmem_falloc;
95545+ spin_lock(&inode->i_lock);
95546+ shmem_falloc = inode->i_private;
95547+ if (!shmem_falloc ||
95548+ shmem_falloc->mode != FALLOC_FL_PUNCH_HOLE ||
95549+ vmf->pgoff < shmem_falloc->start ||
95550+ vmf->pgoff >= shmem_falloc->next)
95551+ shmem_falloc = NULL;
95552+ spin_unlock(&inode->i_lock);
95553+ /*
95554+ * i_lock has protected us from taking shmem_falloc seriously
95555+ * once return from shmem_fallocate() went back up that stack.
95556+ * i_lock does not serialize with i_mutex at all, but it does
95557+ * not matter if sometimes we wait unnecessarily, or sometimes
95558+ * miss out on waiting: we just need to make those cases rare.
95559+ */
95560+ if (shmem_falloc) {
95561+ if ((vmf->flags & FAULT_FLAG_ALLOW_RETRY) &&
95562+ !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
95563+ up_read(&vma->vm_mm->mmap_sem);
95564+ mutex_lock(&inode->i_mutex);
95565+ mutex_unlock(&inode->i_mutex);
95566+ return VM_FAULT_RETRY;
95567+ }
95568+ /* cond_resched? Leave that to GUP or return to user */
95569+ return VM_FAULT_NOPAGE;
95570+ }
95571+ }
95572+
95573 error = shmem_getpage(inode, vmf->pgoff, &vmf->page, SGP_CACHE, &ret);
95574 if (error)
95575 return ((error == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS);
95576@@ -1733,18 +1772,26 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset,
95577
95578 mutex_lock(&inode->i_mutex);
95579
95580+ shmem_falloc.mode = mode & ~FALLOC_FL_KEEP_SIZE;
95581+
95582 if (mode & FALLOC_FL_PUNCH_HOLE) {
95583 struct address_space *mapping = file->f_mapping;
95584 loff_t unmap_start = round_up(offset, PAGE_SIZE);
95585 loff_t unmap_end = round_down(offset + len, PAGE_SIZE) - 1;
95586
95587+ shmem_falloc.start = unmap_start >> PAGE_SHIFT;
95588+ shmem_falloc.next = (unmap_end + 1) >> PAGE_SHIFT;
95589+ spin_lock(&inode->i_lock);
95590+ inode->i_private = &shmem_falloc;
95591+ spin_unlock(&inode->i_lock);
95592+
95593 if ((u64)unmap_end > (u64)unmap_start)
95594 unmap_mapping_range(mapping, unmap_start,
95595 1 + unmap_end - unmap_start, 0);
95596 shmem_truncate_range(inode, offset, offset + len - 1);
95597 /* No need to unmap again: hole-punching leaves COWed pages */
95598 error = 0;
95599- goto out;
95600+ goto undone;
95601 }
95602
95603 /* We need to check rlimit even when FALLOC_FL_KEEP_SIZE */
95604@@ -2138,6 +2185,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
95605 static int shmem_xattr_validate(const char *name)
95606 {
95607 struct { const char *prefix; size_t len; } arr[] = {
95608+
95609+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95610+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
95611+#endif
95612+
95613 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
95614 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
95615 };
95616@@ -2193,6 +2245,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
95617 if (err)
95618 return err;
95619
95620+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95621+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
95622+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
95623+ return -EOPNOTSUPP;
95624+ if (size > 8)
95625+ return -EINVAL;
95626+ }
95627+#endif
95628+
95629 return simple_xattr_set(&info->xattrs, name, value, size, flags);
95630 }
95631
95632@@ -2505,8 +2566,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
95633 int err = -ENOMEM;
95634
95635 /* Round up to L1_CACHE_BYTES to resist false sharing */
95636- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
95637- L1_CACHE_BYTES), GFP_KERNEL);
95638+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
95639 if (!sbinfo)
95640 return -ENOMEM;
95641
95642diff --git a/mm/slab.c b/mm/slab.c
95643index 9432556..e0dc685 100644
95644--- a/mm/slab.c
95645+++ b/mm/slab.c
95646@@ -311,10 +311,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95647 if ((x)->max_freeable < i) \
95648 (x)->max_freeable = i; \
95649 } while (0)
95650-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
95651-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
95652-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
95653-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
95654+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
95655+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
95656+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
95657+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
95658+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
95659+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
95660 #else
95661 #define STATS_INC_ACTIVE(x) do { } while (0)
95662 #define STATS_DEC_ACTIVE(x) do { } while (0)
95663@@ -331,6 +333,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95664 #define STATS_INC_ALLOCMISS(x) do { } while (0)
95665 #define STATS_INC_FREEHIT(x) do { } while (0)
95666 #define STATS_INC_FREEMISS(x) do { } while (0)
95667+#define STATS_INC_SANITIZED(x) do { } while (0)
95668+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
95669 #endif
95670
95671 #if DEBUG
95672@@ -447,7 +451,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
95673 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
95674 */
95675 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
95676- const struct page *page, void *obj)
95677+ const struct page *page, const void *obj)
95678 {
95679 u32 offset = (obj - page->s_mem);
95680 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
95681@@ -1558,12 +1562,12 @@ void __init kmem_cache_init(void)
95682 */
95683
95684 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
95685- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
95686+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95687
95688 if (INDEX_AC != INDEX_NODE)
95689 kmalloc_caches[INDEX_NODE] =
95690 create_kmalloc_cache("kmalloc-node",
95691- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
95692+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95693
95694 slab_early_init = 0;
95695
95696@@ -3525,6 +3529,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
95697 struct array_cache *ac = cpu_cache_get(cachep);
95698
95699 check_irq_off();
95700+
95701+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95702+ if (pax_sanitize_slab) {
95703+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
95704+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
95705+
95706+ if (cachep->ctor)
95707+ cachep->ctor(objp);
95708+
95709+ STATS_INC_SANITIZED(cachep);
95710+ } else
95711+ STATS_INC_NOT_SANITIZED(cachep);
95712+ }
95713+#endif
95714+
95715 kmemleak_free_recursive(objp, cachep->flags);
95716 objp = cache_free_debugcheck(cachep, objp, caller);
95717
95718@@ -3748,6 +3767,7 @@ void kfree(const void *objp)
95719
95720 if (unlikely(ZERO_OR_NULL_PTR(objp)))
95721 return;
95722+ VM_BUG_ON(!virt_addr_valid(objp));
95723 local_irq_save(flags);
95724 kfree_debugcheck(objp);
95725 c = virt_to_cache(objp);
95726@@ -4189,14 +4209,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
95727 }
95728 /* cpu stats */
95729 {
95730- unsigned long allochit = atomic_read(&cachep->allochit);
95731- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
95732- unsigned long freehit = atomic_read(&cachep->freehit);
95733- unsigned long freemiss = atomic_read(&cachep->freemiss);
95734+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
95735+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
95736+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
95737+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
95738
95739 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
95740 allochit, allocmiss, freehit, freemiss);
95741 }
95742+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95743+ {
95744+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
95745+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
95746+
95747+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
95748+ }
95749+#endif
95750 #endif
95751 }
95752
95753@@ -4417,13 +4445,69 @@ static const struct file_operations proc_slabstats_operations = {
95754 static int __init slab_proc_init(void)
95755 {
95756 #ifdef CONFIG_DEBUG_SLAB_LEAK
95757- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
95758+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
95759 #endif
95760 return 0;
95761 }
95762 module_init(slab_proc_init);
95763 #endif
95764
95765+bool is_usercopy_object(const void *ptr)
95766+{
95767+ struct page *page;
95768+ struct kmem_cache *cachep;
95769+
95770+ if (ZERO_OR_NULL_PTR(ptr))
95771+ return false;
95772+
95773+ if (!slab_is_available())
95774+ return false;
95775+
95776+ if (!virt_addr_valid(ptr))
95777+ return false;
95778+
95779+ page = virt_to_head_page(ptr);
95780+
95781+ if (!PageSlab(page))
95782+ return false;
95783+
95784+ cachep = page->slab_cache;
95785+ return cachep->flags & SLAB_USERCOPY;
95786+}
95787+
95788+#ifdef CONFIG_PAX_USERCOPY
95789+const char *check_heap_object(const void *ptr, unsigned long n)
95790+{
95791+ struct page *page;
95792+ struct kmem_cache *cachep;
95793+ unsigned int objnr;
95794+ unsigned long offset;
95795+
95796+ if (ZERO_OR_NULL_PTR(ptr))
95797+ return "<null>";
95798+
95799+ if (!virt_addr_valid(ptr))
95800+ return NULL;
95801+
95802+ page = virt_to_head_page(ptr);
95803+
95804+ if (!PageSlab(page))
95805+ return NULL;
95806+
95807+ cachep = page->slab_cache;
95808+ if (!(cachep->flags & SLAB_USERCOPY))
95809+ return cachep->name;
95810+
95811+ objnr = obj_to_index(cachep, page, ptr);
95812+ BUG_ON(objnr >= cachep->num);
95813+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
95814+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
95815+ return NULL;
95816+
95817+ return cachep->name;
95818+}
95819+#endif
95820+
95821 /**
95822 * ksize - get the actual amount of memory allocated for a given object
95823 * @objp: Pointer to the object
95824diff --git a/mm/slab.h b/mm/slab.h
95825index 6bd4c35..97565a1 100644
95826--- a/mm/slab.h
95827+++ b/mm/slab.h
95828@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
95829 /* The slab cache that manages slab cache information */
95830 extern struct kmem_cache *kmem_cache;
95831
95832+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95833+#ifdef CONFIG_X86_64
95834+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
95835+#else
95836+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
95837+#endif
95838+extern bool pax_sanitize_slab;
95839+#endif
95840+
95841 unsigned long calculate_alignment(unsigned long flags,
95842 unsigned long align, unsigned long size);
95843
95844@@ -67,7 +76,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
95845
95846 /* Legal flag mask for kmem_cache_create(), for various configurations */
95847 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
95848- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
95849+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
95850+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
95851
95852 #if defined(CONFIG_DEBUG_SLAB)
95853 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
95854@@ -245,6 +255,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
95855 return s;
95856
95857 page = virt_to_head_page(x);
95858+
95859+ BUG_ON(!PageSlab(page));
95860+
95861 cachep = page->slab_cache;
95862 if (slab_equal_or_root(cachep, s))
95863 return cachep;
95864diff --git a/mm/slab_common.c b/mm/slab_common.c
95865index 102cc6f..c7aab3d 100644
95866--- a/mm/slab_common.c
95867+++ b/mm/slab_common.c
95868@@ -23,11 +23,22 @@
95869
95870 #include "slab.h"
95871
95872-enum slab_state slab_state;
95873+enum slab_state slab_state __read_only;
95874 LIST_HEAD(slab_caches);
95875 DEFINE_MUTEX(slab_mutex);
95876 struct kmem_cache *kmem_cache;
95877
95878+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95879+bool pax_sanitize_slab __read_only = true;
95880+static int __init pax_sanitize_slab_setup(char *str)
95881+{
95882+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
95883+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
95884+ return 1;
95885+}
95886+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
95887+#endif
95888+
95889 #ifdef CONFIG_DEBUG_VM
95890 static int kmem_cache_sanity_check(const char *name, size_t size)
95891 {
95892@@ -158,7 +169,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
95893 if (err)
95894 goto out_free_cache;
95895
95896- s->refcount = 1;
95897+ atomic_set(&s->refcount, 1);
95898 list_add(&s->list, &slab_caches);
95899 memcg_register_cache(s);
95900 out:
95901@@ -334,8 +345,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
95902 get_online_cpus();
95903 mutex_lock(&slab_mutex);
95904
95905- s->refcount--;
95906- if (s->refcount)
95907+ if (!atomic_dec_and_test(&s->refcount))
95908 goto out_unlock;
95909
95910 if (kmem_cache_destroy_memcg_children(s) != 0)
95911@@ -358,7 +368,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
95912 rcu_barrier();
95913
95914 memcg_free_cache_params(s);
95915-#ifdef SLAB_SUPPORTS_SYSFS
95916+#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95917 sysfs_slab_remove(s);
95918 #else
95919 slab_kmem_cache_release(s);
95920@@ -393,7 +403,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
95921 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
95922 name, size, err);
95923
95924- s->refcount = -1; /* Exempt from merging for now */
95925+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
95926 }
95927
95928 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95929@@ -406,7 +416,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95930
95931 create_boot_cache(s, name, size, flags);
95932 list_add(&s->list, &slab_caches);
95933- s->refcount = 1;
95934+ atomic_set(&s->refcount, 1);
95935 return s;
95936 }
95937
95938@@ -418,6 +428,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
95939 EXPORT_SYMBOL(kmalloc_dma_caches);
95940 #endif
95941
95942+#ifdef CONFIG_PAX_USERCOPY_SLABS
95943+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
95944+EXPORT_SYMBOL(kmalloc_usercopy_caches);
95945+#endif
95946+
95947 /*
95948 * Conversion table for small slabs sizes / 8 to the index in the
95949 * kmalloc array. This is necessary for slabs < 192 since we have non power
95950@@ -482,6 +497,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
95951 return kmalloc_dma_caches[index];
95952
95953 #endif
95954+
95955+#ifdef CONFIG_PAX_USERCOPY_SLABS
95956+ if (unlikely((flags & GFP_USERCOPY)))
95957+ return kmalloc_usercopy_caches[index];
95958+
95959+#endif
95960+
95961 return kmalloc_caches[index];
95962 }
95963
95964@@ -538,7 +560,7 @@ void __init create_kmalloc_caches(unsigned long flags)
95965 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
95966 if (!kmalloc_caches[i]) {
95967 kmalloc_caches[i] = create_kmalloc_cache(NULL,
95968- 1 << i, flags);
95969+ 1 << i, SLAB_USERCOPY | flags);
95970 }
95971
95972 /*
95973@@ -547,10 +569,10 @@ void __init create_kmalloc_caches(unsigned long flags)
95974 * earlier power of two caches
95975 */
95976 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
95977- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
95978+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
95979
95980 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
95981- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
95982+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
95983 }
95984
95985 /* Kmalloc array is now usable */
95986@@ -583,6 +605,23 @@ void __init create_kmalloc_caches(unsigned long flags)
95987 }
95988 }
95989 #endif
95990+
95991+#ifdef CONFIG_PAX_USERCOPY_SLABS
95992+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
95993+ struct kmem_cache *s = kmalloc_caches[i];
95994+
95995+ if (s) {
95996+ int size = kmalloc_size(i);
95997+ char *n = kasprintf(GFP_NOWAIT,
95998+ "usercopy-kmalloc-%d", size);
95999+
96000+ BUG_ON(!n);
96001+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
96002+ size, SLAB_USERCOPY | flags);
96003+ }
96004+ }
96005+#endif
96006+
96007 }
96008 #endif /* !CONFIG_SLOB */
96009
96010@@ -623,6 +662,9 @@ void print_slabinfo_header(struct seq_file *m)
96011 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
96012 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
96013 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
96014+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96015+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
96016+#endif
96017 #endif
96018 seq_putc(m, '\n');
96019 }
96020diff --git a/mm/slob.c b/mm/slob.c
96021index 730cad4..8cfd442 100644
96022--- a/mm/slob.c
96023+++ b/mm/slob.c
96024@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
96025 /*
96026 * Return the size of a slob block.
96027 */
96028-static slobidx_t slob_units(slob_t *s)
96029+static slobidx_t slob_units(const slob_t *s)
96030 {
96031 if (s->units > 0)
96032 return s->units;
96033@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
96034 /*
96035 * Return the next free slob block pointer after this one.
96036 */
96037-static slob_t *slob_next(slob_t *s)
96038+static slob_t *slob_next(const slob_t *s)
96039 {
96040 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
96041 slobidx_t next;
96042@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
96043 /*
96044 * Returns true if s is the last free block in its page.
96045 */
96046-static int slob_last(slob_t *s)
96047+static int slob_last(const slob_t *s)
96048 {
96049 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
96050 }
96051
96052-static void *slob_new_pages(gfp_t gfp, int order, int node)
96053+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
96054 {
96055- void *page;
96056+ struct page *page;
96057
96058 #ifdef CONFIG_NUMA
96059 if (node != NUMA_NO_NODE)
96060@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96061 if (!page)
96062 return NULL;
96063
96064- return page_address(page);
96065+ __SetPageSlab(page);
96066+ return page;
96067 }
96068
96069-static void slob_free_pages(void *b, int order)
96070+static void slob_free_pages(struct page *sp, int order)
96071 {
96072 if (current->reclaim_state)
96073 current->reclaim_state->reclaimed_slab += 1 << order;
96074- free_pages((unsigned long)b, order);
96075+ __ClearPageSlab(sp);
96076+ page_mapcount_reset(sp);
96077+ sp->private = 0;
96078+ __free_pages(sp, order);
96079 }
96080
96081 /*
96082@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96083
96084 /* Not enough space: must allocate a new page */
96085 if (!b) {
96086- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96087- if (!b)
96088+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96089+ if (!sp)
96090 return NULL;
96091- sp = virt_to_page(b);
96092- __SetPageSlab(sp);
96093+ b = page_address(sp);
96094
96095 spin_lock_irqsave(&slob_lock, flags);
96096 sp->units = SLOB_UNITS(PAGE_SIZE);
96097 sp->freelist = b;
96098+ sp->private = 0;
96099 INIT_LIST_HEAD(&sp->lru);
96100 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96101 set_slob_page_free(sp, slob_list);
96102@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96103 if (slob_page_free(sp))
96104 clear_slob_page_free(sp);
96105 spin_unlock_irqrestore(&slob_lock, flags);
96106- __ClearPageSlab(sp);
96107- page_mapcount_reset(sp);
96108- slob_free_pages(b, 0);
96109+ slob_free_pages(sp, 0);
96110 return;
96111 }
96112
96113+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96114+ if (pax_sanitize_slab)
96115+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96116+#endif
96117+
96118 if (!slob_page_free(sp)) {
96119 /* This slob page is about to become partially free. Easy! */
96120 sp->units = units;
96121@@ -424,11 +431,10 @@ out:
96122 */
96123
96124 static __always_inline void *
96125-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96126+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96127 {
96128- unsigned int *m;
96129- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96130- void *ret;
96131+ slob_t *m;
96132+ void *ret = NULL;
96133
96134 gfp &= gfp_allowed_mask;
96135
96136@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96137
96138 if (!m)
96139 return NULL;
96140- *m = size;
96141+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96142+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96143+ m[0].units = size;
96144+ m[1].units = align;
96145 ret = (void *)m + align;
96146
96147 trace_kmalloc_node(caller, ret,
96148 size, size + align, gfp, node);
96149 } else {
96150 unsigned int order = get_order(size);
96151+ struct page *page;
96152
96153 if (likely(order))
96154 gfp |= __GFP_COMP;
96155- ret = slob_new_pages(gfp, order, node);
96156+ page = slob_new_pages(gfp, order, node);
96157+ if (page) {
96158+ ret = page_address(page);
96159+ page->private = size;
96160+ }
96161
96162 trace_kmalloc_node(caller, ret,
96163 size, PAGE_SIZE << order, gfp, node);
96164 }
96165
96166- kmemleak_alloc(ret, size, 1, gfp);
96167+ return ret;
96168+}
96169+
96170+static __always_inline void *
96171+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96172+{
96173+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96174+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96175+
96176+ if (!ZERO_OR_NULL_PTR(ret))
96177+ kmemleak_alloc(ret, size, 1, gfp);
96178 return ret;
96179 }
96180
96181@@ -493,34 +517,112 @@ void kfree(const void *block)
96182 return;
96183 kmemleak_free(block);
96184
96185+ VM_BUG_ON(!virt_addr_valid(block));
96186 sp = virt_to_page(block);
96187- if (PageSlab(sp)) {
96188+ VM_BUG_ON(!PageSlab(sp));
96189+ if (!sp->private) {
96190 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96191- unsigned int *m = (unsigned int *)(block - align);
96192- slob_free(m, *m + align);
96193- } else
96194+ slob_t *m = (slob_t *)(block - align);
96195+ slob_free(m, m[0].units + align);
96196+ } else {
96197+ __ClearPageSlab(sp);
96198+ page_mapcount_reset(sp);
96199+ sp->private = 0;
96200 __free_pages(sp, compound_order(sp));
96201+ }
96202 }
96203 EXPORT_SYMBOL(kfree);
96204
96205+bool is_usercopy_object(const void *ptr)
96206+{
96207+ if (!slab_is_available())
96208+ return false;
96209+
96210+ // PAX: TODO
96211+
96212+ return false;
96213+}
96214+
96215+#ifdef CONFIG_PAX_USERCOPY
96216+const char *check_heap_object(const void *ptr, unsigned long n)
96217+{
96218+ struct page *page;
96219+ const slob_t *free;
96220+ const void *base;
96221+ unsigned long flags;
96222+
96223+ if (ZERO_OR_NULL_PTR(ptr))
96224+ return "<null>";
96225+
96226+ if (!virt_addr_valid(ptr))
96227+ return NULL;
96228+
96229+ page = virt_to_head_page(ptr);
96230+ if (!PageSlab(page))
96231+ return NULL;
96232+
96233+ if (page->private) {
96234+ base = page;
96235+ if (base <= ptr && n <= page->private - (ptr - base))
96236+ return NULL;
96237+ return "<slob>";
96238+ }
96239+
96240+ /* some tricky double walking to find the chunk */
96241+ spin_lock_irqsave(&slob_lock, flags);
96242+ base = (void *)((unsigned long)ptr & PAGE_MASK);
96243+ free = page->freelist;
96244+
96245+ while (!slob_last(free) && (void *)free <= ptr) {
96246+ base = free + slob_units(free);
96247+ free = slob_next(free);
96248+ }
96249+
96250+ while (base < (void *)free) {
96251+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96252+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
96253+ int offset;
96254+
96255+ if (ptr < base + align)
96256+ break;
96257+
96258+ offset = ptr - base - align;
96259+ if (offset >= m) {
96260+ base += size;
96261+ continue;
96262+ }
96263+
96264+ if (n > m - offset)
96265+ break;
96266+
96267+ spin_unlock_irqrestore(&slob_lock, flags);
96268+ return NULL;
96269+ }
96270+
96271+ spin_unlock_irqrestore(&slob_lock, flags);
96272+ return "<slob>";
96273+}
96274+#endif
96275+
96276 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96277 size_t ksize(const void *block)
96278 {
96279 struct page *sp;
96280 int align;
96281- unsigned int *m;
96282+ slob_t *m;
96283
96284 BUG_ON(!block);
96285 if (unlikely(block == ZERO_SIZE_PTR))
96286 return 0;
96287
96288 sp = virt_to_page(block);
96289- if (unlikely(!PageSlab(sp)))
96290- return PAGE_SIZE << compound_order(sp);
96291+ VM_BUG_ON(!PageSlab(sp));
96292+ if (sp->private)
96293+ return sp->private;
96294
96295 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96296- m = (unsigned int *)(block - align);
96297- return SLOB_UNITS(*m) * SLOB_UNIT;
96298+ m = (slob_t *)(block - align);
96299+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
96300 }
96301 EXPORT_SYMBOL(ksize);
96302
96303@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
96304
96305 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
96306 {
96307- void *b;
96308+ void *b = NULL;
96309
96310 flags &= gfp_allowed_mask;
96311
96312 lockdep_trace_alloc(flags);
96313
96314+#ifdef CONFIG_PAX_USERCOPY_SLABS
96315+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
96316+#else
96317 if (c->size < PAGE_SIZE) {
96318 b = slob_alloc(c->size, flags, c->align, node);
96319 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96320 SLOB_UNITS(c->size) * SLOB_UNIT,
96321 flags, node);
96322 } else {
96323- b = slob_new_pages(flags, get_order(c->size), node);
96324+ struct page *sp;
96325+
96326+ sp = slob_new_pages(flags, get_order(c->size), node);
96327+ if (sp) {
96328+ b = page_address(sp);
96329+ sp->private = c->size;
96330+ }
96331 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96332 PAGE_SIZE << get_order(c->size),
96333 flags, node);
96334 }
96335+#endif
96336
96337 if (b && c->ctor)
96338 c->ctor(b);
96339@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
96340
96341 static void __kmem_cache_free(void *b, int size)
96342 {
96343- if (size < PAGE_SIZE)
96344+ struct page *sp;
96345+
96346+ sp = virt_to_page(b);
96347+ BUG_ON(!PageSlab(sp));
96348+ if (!sp->private)
96349 slob_free(b, size);
96350 else
96351- slob_free_pages(b, get_order(size));
96352+ slob_free_pages(sp, get_order(size));
96353 }
96354
96355 static void kmem_rcu_free(struct rcu_head *head)
96356@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
96357
96358 void kmem_cache_free(struct kmem_cache *c, void *b)
96359 {
96360+ int size = c->size;
96361+
96362+#ifdef CONFIG_PAX_USERCOPY_SLABS
96363+ if (size + c->align < PAGE_SIZE) {
96364+ size += c->align;
96365+ b -= c->align;
96366+ }
96367+#endif
96368+
96369 kmemleak_free_recursive(b, c->flags);
96370 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
96371 struct slob_rcu *slob_rcu;
96372- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
96373- slob_rcu->size = c->size;
96374+ slob_rcu = b + (size - sizeof(struct slob_rcu));
96375+ slob_rcu->size = size;
96376 call_rcu(&slob_rcu->head, kmem_rcu_free);
96377 } else {
96378- __kmem_cache_free(b, c->size);
96379+ __kmem_cache_free(b, size);
96380 }
96381
96382+#ifdef CONFIG_PAX_USERCOPY_SLABS
96383+ trace_kfree(_RET_IP_, b);
96384+#else
96385 trace_kmem_cache_free(_RET_IP_, b);
96386+#endif
96387+
96388 }
96389 EXPORT_SYMBOL(kmem_cache_free);
96390
96391diff --git a/mm/slub.c b/mm/slub.c
96392index 2b1ce69..4a2193f 100644
96393--- a/mm/slub.c
96394+++ b/mm/slub.c
96395@@ -207,7 +207,7 @@ struct track {
96396
96397 enum track_item { TRACK_ALLOC, TRACK_FREE };
96398
96399-#ifdef CONFIG_SYSFS
96400+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96401 static int sysfs_slab_add(struct kmem_cache *);
96402 static int sysfs_slab_alias(struct kmem_cache *, const char *);
96403 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
96404@@ -546,7 +546,7 @@ static void print_track(const char *s, struct track *t)
96405 if (!t->addr)
96406 return;
96407
96408- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
96409+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
96410 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
96411 #ifdef CONFIG_STACKTRACE
96412 {
96413@@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
96414
96415 slab_free_hook(s, x);
96416
96417+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96418+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
96419+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
96420+ if (s->ctor)
96421+ s->ctor(x);
96422+ }
96423+#endif
96424+
96425 redo:
96426 /*
96427 * Determine the currently cpus per cpu slab.
96428@@ -2733,7 +2741,7 @@ static int slub_min_objects;
96429 * Merge control. If this is set then no merging of slab caches will occur.
96430 * (Could be removed. This was introduced to pacify the merge skeptics.)
96431 */
96432-static int slub_nomerge;
96433+static int slub_nomerge = 1;
96434
96435 /*
96436 * Calculate the order of allocation given an slab object size.
96437@@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
96438 s->inuse = size;
96439
96440 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
96441+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96442+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
96443+#endif
96444 s->ctor)) {
96445 /*
96446 * Relocate free pointer after the object if it is not
96447@@ -3343,6 +3354,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
96448 EXPORT_SYMBOL(__kmalloc_node);
96449 #endif
96450
96451+bool is_usercopy_object(const void *ptr)
96452+{
96453+ struct page *page;
96454+ struct kmem_cache *s;
96455+
96456+ if (ZERO_OR_NULL_PTR(ptr))
96457+ return false;
96458+
96459+ if (!slab_is_available())
96460+ return false;
96461+
96462+ if (!virt_addr_valid(ptr))
96463+ return false;
96464+
96465+ page = virt_to_head_page(ptr);
96466+
96467+ if (!PageSlab(page))
96468+ return false;
96469+
96470+ s = page->slab_cache;
96471+ return s->flags & SLAB_USERCOPY;
96472+}
96473+
96474+#ifdef CONFIG_PAX_USERCOPY
96475+const char *check_heap_object(const void *ptr, unsigned long n)
96476+{
96477+ struct page *page;
96478+ struct kmem_cache *s;
96479+ unsigned long offset;
96480+
96481+ if (ZERO_OR_NULL_PTR(ptr))
96482+ return "<null>";
96483+
96484+ if (!virt_addr_valid(ptr))
96485+ return NULL;
96486+
96487+ page = virt_to_head_page(ptr);
96488+
96489+ if (!PageSlab(page))
96490+ return NULL;
96491+
96492+ s = page->slab_cache;
96493+ if (!(s->flags & SLAB_USERCOPY))
96494+ return s->name;
96495+
96496+ offset = (ptr - page_address(page)) % s->size;
96497+ if (offset <= s->object_size && n <= s->object_size - offset)
96498+ return NULL;
96499+
96500+ return s->name;
96501+}
96502+#endif
96503+
96504 size_t ksize(const void *object)
96505 {
96506 struct page *page;
96507@@ -3371,6 +3435,7 @@ void kfree(const void *x)
96508 if (unlikely(ZERO_OR_NULL_PTR(x)))
96509 return;
96510
96511+ VM_BUG_ON(!virt_addr_valid(x));
96512 page = virt_to_head_page(x);
96513 if (unlikely(!PageSlab(page))) {
96514 BUG_ON(!PageCompound(page));
96515@@ -3679,7 +3744,7 @@ static int slab_unmergeable(struct kmem_cache *s)
96516 /*
96517 * We may have set a slab to be unmergeable during bootstrap.
96518 */
96519- if (s->refcount < 0)
96520+ if (atomic_read(&s->refcount) < 0)
96521 return 1;
96522
96523 return 0;
96524@@ -3736,7 +3801,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96525 int i;
96526 struct kmem_cache *c;
96527
96528- s->refcount++;
96529+ atomic_inc(&s->refcount);
96530
96531 /*
96532 * Adjust the object sizes so that we clear
96533@@ -3755,7 +3820,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96534 }
96535
96536 if (sysfs_slab_alias(s, name)) {
96537- s->refcount--;
96538+ atomic_dec(&s->refcount);
96539 s = NULL;
96540 }
96541 }
96542@@ -3872,7 +3937,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
96543 }
96544 #endif
96545
96546-#ifdef CONFIG_SYSFS
96547+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96548 static int count_inuse(struct page *page)
96549 {
96550 return page->inuse;
96551@@ -4156,7 +4221,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
96552 len += sprintf(buf + len, "%7ld ", l->count);
96553
96554 if (l->addr)
96555+#ifdef CONFIG_GRKERNSEC_HIDESYM
96556+ len += sprintf(buf + len, "%pS", NULL);
96557+#else
96558 len += sprintf(buf + len, "%pS", (void *)l->addr);
96559+#endif
96560 else
96561 len += sprintf(buf + len, "<not-available>");
96562
96563@@ -4261,12 +4330,12 @@ static void resiliency_test(void)
96564 validate_slab_cache(kmalloc_caches[9]);
96565 }
96566 #else
96567-#ifdef CONFIG_SYSFS
96568+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96569 static void resiliency_test(void) {};
96570 #endif
96571 #endif
96572
96573-#ifdef CONFIG_SYSFS
96574+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96575 enum slab_stat_type {
96576 SL_ALL, /* All slabs */
96577 SL_PARTIAL, /* Only partially allocated slabs */
96578@@ -4506,13 +4575,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
96579 {
96580 if (!s->ctor)
96581 return 0;
96582+#ifdef CONFIG_GRKERNSEC_HIDESYM
96583+ return sprintf(buf, "%pS\n", NULL);
96584+#else
96585 return sprintf(buf, "%pS\n", s->ctor);
96586+#endif
96587 }
96588 SLAB_ATTR_RO(ctor);
96589
96590 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
96591 {
96592- return sprintf(buf, "%d\n", s->refcount - 1);
96593+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
96594 }
96595 SLAB_ATTR_RO(aliases);
96596
96597@@ -4600,6 +4673,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
96598 SLAB_ATTR_RO(cache_dma);
96599 #endif
96600
96601+#ifdef CONFIG_PAX_USERCOPY_SLABS
96602+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
96603+{
96604+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
96605+}
96606+SLAB_ATTR_RO(usercopy);
96607+#endif
96608+
96609 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
96610 {
96611 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
96612@@ -4934,6 +5015,9 @@ static struct attribute *slab_attrs[] = {
96613 #ifdef CONFIG_ZONE_DMA
96614 &cache_dma_attr.attr,
96615 #endif
96616+#ifdef CONFIG_PAX_USERCOPY_SLABS
96617+ &usercopy_attr.attr,
96618+#endif
96619 #ifdef CONFIG_NUMA
96620 &remote_node_defrag_ratio_attr.attr,
96621 #endif
96622@@ -5184,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
96623 return name;
96624 }
96625
96626+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96627 static int sysfs_slab_add(struct kmem_cache *s)
96628 {
96629 int err;
96630@@ -5257,6 +5342,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
96631 kobject_del(&s->kobj);
96632 kobject_put(&s->kobj);
96633 }
96634+#endif
96635
96636 /*
96637 * Need to buffer aliases during bootup until sysfs becomes
96638@@ -5270,6 +5356,7 @@ struct saved_alias {
96639
96640 static struct saved_alias *alias_list;
96641
96642+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96643 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96644 {
96645 struct saved_alias *al;
96646@@ -5292,6 +5379,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96647 alias_list = al;
96648 return 0;
96649 }
96650+#endif
96651
96652 static int __init slab_sysfs_init(void)
96653 {
96654diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
96655index 4cba9c2..b4f9fcc 100644
96656--- a/mm/sparse-vmemmap.c
96657+++ b/mm/sparse-vmemmap.c
96658@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
96659 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96660 if (!p)
96661 return NULL;
96662- pud_populate(&init_mm, pud, p);
96663+ pud_populate_kernel(&init_mm, pud, p);
96664 }
96665 return pud;
96666 }
96667@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
96668 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96669 if (!p)
96670 return NULL;
96671- pgd_populate(&init_mm, pgd, p);
96672+ pgd_populate_kernel(&init_mm, pgd, p);
96673 }
96674 return pgd;
96675 }
96676diff --git a/mm/sparse.c b/mm/sparse.c
96677index d1b48b6..6e8590e 100644
96678--- a/mm/sparse.c
96679+++ b/mm/sparse.c
96680@@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
96681
96682 for (i = 0; i < PAGES_PER_SECTION; i++) {
96683 if (PageHWPoison(&memmap[i])) {
96684- atomic_long_sub(1, &num_poisoned_pages);
96685+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
96686 ClearPageHWPoison(&memmap[i]);
96687 }
96688 }
96689diff --git a/mm/swap.c b/mm/swap.c
96690index 9ce43ba..43bdc4c 100644
96691--- a/mm/swap.c
96692+++ b/mm/swap.c
96693@@ -31,6 +31,7 @@
96694 #include <linux/memcontrol.h>
96695 #include <linux/gfp.h>
96696 #include <linux/uio.h>
96697+#include <linux/hugetlb.h>
96698
96699 #include "internal.h"
96700
96701@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
96702
96703 __page_cache_release(page);
96704 dtor = get_compound_page_dtor(page);
96705+ if (!PageHuge(page))
96706+ BUG_ON(dtor != free_compound_page);
96707 (*dtor)(page);
96708 }
96709
96710diff --git a/mm/swapfile.c b/mm/swapfile.c
96711index 4a7f7e6..22cddf5 100644
96712--- a/mm/swapfile.c
96713+++ b/mm/swapfile.c
96714@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
96715
96716 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
96717 /* Activity counter to indicate that a swapon or swapoff has occurred */
96718-static atomic_t proc_poll_event = ATOMIC_INIT(0);
96719+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
96720
96721 static inline unsigned char swap_count(unsigned char ent)
96722 {
96723@@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
96724 spin_unlock(&swap_lock);
96725
96726 err = 0;
96727- atomic_inc(&proc_poll_event);
96728+ atomic_inc_unchecked(&proc_poll_event);
96729 wake_up_interruptible(&proc_poll_wait);
96730
96731 out_dput:
96732@@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
96733
96734 poll_wait(file, &proc_poll_wait, wait);
96735
96736- if (seq->poll_event != atomic_read(&proc_poll_event)) {
96737- seq->poll_event = atomic_read(&proc_poll_event);
96738+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
96739+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96740 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
96741 }
96742
96743@@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
96744 return ret;
96745
96746 seq = file->private_data;
96747- seq->poll_event = atomic_read(&proc_poll_event);
96748+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96749 return 0;
96750 }
96751
96752@@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
96753 (frontswap_map) ? "FS" : "");
96754
96755 mutex_unlock(&swapon_mutex);
96756- atomic_inc(&proc_poll_event);
96757+ atomic_inc_unchecked(&proc_poll_event);
96758 wake_up_interruptible(&proc_poll_wait);
96759
96760 if (S_ISREG(inode->i_mode))
96761diff --git a/mm/util.c b/mm/util.c
96762index d5ea733..e8953f9 100644
96763--- a/mm/util.c
96764+++ b/mm/util.c
96765@@ -299,6 +299,12 @@ done:
96766 void arch_pick_mmap_layout(struct mm_struct *mm)
96767 {
96768 mm->mmap_base = TASK_UNMAPPED_BASE;
96769+
96770+#ifdef CONFIG_PAX_RANDMMAP
96771+ if (mm->pax_flags & MF_PAX_RANDMMAP)
96772+ mm->mmap_base += mm->delta_mmap;
96773+#endif
96774+
96775 mm->get_unmapped_area = arch_get_unmapped_area;
96776 }
96777 #endif
96778@@ -475,6 +481,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
96779 if (!mm->arg_end)
96780 goto out_mm; /* Shh! No looking before we're done */
96781
96782+ if (gr_acl_handle_procpidmem(task))
96783+ goto out_mm;
96784+
96785 len = mm->arg_end - mm->arg_start;
96786
96787 if (len > buflen)
96788diff --git a/mm/vmalloc.c b/mm/vmalloc.c
96789index bf233b2..1dfa1bc 100644
96790--- a/mm/vmalloc.c
96791+++ b/mm/vmalloc.c
96792@@ -40,6 +40,21 @@ struct vfree_deferred {
96793 };
96794 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
96795
96796+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
96797+struct stack_deferred_llist {
96798+ struct llist_head list;
96799+ void *stack;
96800+ void *lowmem_stack;
96801+};
96802+
96803+struct stack_deferred {
96804+ struct stack_deferred_llist list;
96805+ struct work_struct wq;
96806+};
96807+
96808+static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
96809+#endif
96810+
96811 static void __vunmap(const void *, int);
96812
96813 static void free_work(struct work_struct *w)
96814@@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
96815 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
96816 struct llist_node *llnode = llist_del_all(&p->list);
96817 while (llnode) {
96818- void *p = llnode;
96819+ void *x = llnode;
96820 llnode = llist_next(llnode);
96821- __vunmap(p, 1);
96822+ __vunmap(x, 1);
96823 }
96824 }
96825
96826+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
96827+static void unmap_work(struct work_struct *w)
96828+{
96829+ struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
96830+ struct llist_node *llnode = llist_del_all(&p->list.list);
96831+ while (llnode) {
96832+ struct stack_deferred_llist *x =
96833+ llist_entry((struct llist_head *)llnode,
96834+ struct stack_deferred_llist, list);
96835+ void *stack = ACCESS_ONCE(x->stack);
96836+ void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
96837+ llnode = llist_next(llnode);
96838+ __vunmap(stack, 0);
96839+ free_memcg_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
96840+ }
96841+}
96842+#endif
96843+
96844 /*** Page table manipulation functions ***/
96845
96846 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96847@@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96848
96849 pte = pte_offset_kernel(pmd, addr);
96850 do {
96851- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96852- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96853+
96854+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96855+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
96856+ BUG_ON(!pte_exec(*pte));
96857+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
96858+ continue;
96859+ }
96860+#endif
96861+
96862+ {
96863+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96864+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96865+ }
96866 } while (pte++, addr += PAGE_SIZE, addr != end);
96867 }
96868
96869@@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
96870 pte = pte_alloc_kernel(pmd, addr);
96871 if (!pte)
96872 return -ENOMEM;
96873+
96874+ pax_open_kernel();
96875 do {
96876 struct page *page = pages[*nr];
96877
96878- if (WARN_ON(!pte_none(*pte)))
96879+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96880+ if (pgprot_val(prot) & _PAGE_NX)
96881+#endif
96882+
96883+ if (!pte_none(*pte)) {
96884+ pax_close_kernel();
96885+ WARN_ON(1);
96886 return -EBUSY;
96887- if (WARN_ON(!page))
96888+ }
96889+ if (!page) {
96890+ pax_close_kernel();
96891+ WARN_ON(1);
96892 return -ENOMEM;
96893+ }
96894 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
96895 (*nr)++;
96896 } while (pte++, addr += PAGE_SIZE, addr != end);
96897+ pax_close_kernel();
96898 return 0;
96899 }
96900
96901@@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
96902 pmd_t *pmd;
96903 unsigned long next;
96904
96905- pmd = pmd_alloc(&init_mm, pud, addr);
96906+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
96907 if (!pmd)
96908 return -ENOMEM;
96909 do {
96910@@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
96911 pud_t *pud;
96912 unsigned long next;
96913
96914- pud = pud_alloc(&init_mm, pgd, addr);
96915+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
96916 if (!pud)
96917 return -ENOMEM;
96918 do {
96919@@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
96920 if (addr >= MODULES_VADDR && addr < MODULES_END)
96921 return 1;
96922 #endif
96923+
96924+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96925+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
96926+ return 1;
96927+#endif
96928+
96929 return is_vmalloc_addr(x);
96930 }
96931
96932@@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
96933
96934 if (!pgd_none(*pgd)) {
96935 pud_t *pud = pud_offset(pgd, addr);
96936+#ifdef CONFIG_X86
96937+ if (!pud_large(*pud))
96938+#endif
96939 if (!pud_none(*pud)) {
96940 pmd_t *pmd = pmd_offset(pud, addr);
96941+#ifdef CONFIG_X86
96942+ if (!pmd_large(*pmd))
96943+#endif
96944 if (!pmd_none(*pmd)) {
96945 pte_t *ptep, pte;
96946
96947@@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
96948 for_each_possible_cpu(i) {
96949 struct vmap_block_queue *vbq;
96950 struct vfree_deferred *p;
96951+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
96952+ struct stack_deferred *p2;
96953+#endif
96954
96955 vbq = &per_cpu(vmap_block_queue, i);
96956 spin_lock_init(&vbq->lock);
96957 INIT_LIST_HEAD(&vbq->free);
96958+
96959 p = &per_cpu(vfree_deferred, i);
96960 init_llist_head(&p->list);
96961 INIT_WORK(&p->wq, free_work);
96962+
96963+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
96964+ p2 = &per_cpu(stack_deferred, i);
96965+ init_llist_head(&p2->list.list);
96966+ INIT_WORK(&p2->wq, unmap_work);
96967+#endif
96968 }
96969
96970 /* Import existing vmlist entries. */
96971@@ -1317,6 +1396,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
96972 struct vm_struct *area;
96973
96974 BUG_ON(in_interrupt());
96975+
96976+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
96977+ if (flags & VM_KERNEXEC) {
96978+ if (start != VMALLOC_START || end != VMALLOC_END)
96979+ return NULL;
96980+ start = (unsigned long)MODULES_EXEC_VADDR;
96981+ end = (unsigned long)MODULES_EXEC_END;
96982+ }
96983+#endif
96984+
96985 if (flags & VM_IOREMAP)
96986 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
96987
96988@@ -1522,6 +1611,23 @@ void vunmap(const void *addr)
96989 }
96990 EXPORT_SYMBOL(vunmap);
96991
96992+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
96993+void unmap_process_stacks(struct task_struct *task)
96994+{
96995+ if (unlikely(in_interrupt())) {
96996+ struct stack_deferred *p = &__get_cpu_var(stack_deferred);
96997+ struct stack_deferred_llist *list = task->stack;
96998+ list->stack = task->stack;
96999+ list->lowmem_stack = task->lowmem_stack;
97000+ if (llist_add((struct llist_node *)&list->list, &p->list.list))
97001+ schedule_work(&p->wq);
97002+ } else {
97003+ __vunmap(task->stack, 0);
97004+ free_memcg_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
97005+ }
97006+}
97007+#endif
97008+
97009 /**
97010 * vmap - map an array of pages into virtually contiguous space
97011 * @pages: array of page pointers
97012@@ -1542,6 +1648,11 @@ void *vmap(struct page **pages, unsigned int count,
97013 if (count > totalram_pages)
97014 return NULL;
97015
97016+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97017+ if (!(pgprot_val(prot) & _PAGE_NX))
97018+ flags |= VM_KERNEXEC;
97019+#endif
97020+
97021 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
97022 __builtin_return_address(0));
97023 if (!area)
97024@@ -1642,6 +1753,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
97025 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
97026 goto fail;
97027
97028+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97029+ if (!(pgprot_val(prot) & _PAGE_NX))
97030+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
97031+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
97032+ else
97033+#endif
97034+
97035 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
97036 start, end, node, gfp_mask, caller);
97037 if (!area)
97038@@ -1818,10 +1936,9 @@ EXPORT_SYMBOL(vzalloc_node);
97039 * For tight control over page level allocator and protection flags
97040 * use __vmalloc() instead.
97041 */
97042-
97043 void *vmalloc_exec(unsigned long size)
97044 {
97045- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
97046+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
97047 NUMA_NO_NODE, __builtin_return_address(0));
97048 }
97049
97050@@ -2128,6 +2245,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
97051 {
97052 struct vm_struct *area;
97053
97054+ BUG_ON(vma->vm_mirror);
97055+
97056 size = PAGE_ALIGN(size);
97057
97058 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
97059@@ -2610,7 +2729,11 @@ static int s_show(struct seq_file *m, void *p)
97060 v->addr, v->addr + v->size, v->size);
97061
97062 if (v->caller)
97063+#ifdef CONFIG_GRKERNSEC_HIDESYM
97064+ seq_printf(m, " %pK", v->caller);
97065+#else
97066 seq_printf(m, " %pS", v->caller);
97067+#endif
97068
97069 if (v->nr_pages)
97070 seq_printf(m, " pages=%d", v->nr_pages);
97071diff --git a/mm/vmstat.c b/mm/vmstat.c
97072index 302dd07..3841f1c 100644
97073--- a/mm/vmstat.c
97074+++ b/mm/vmstat.c
97075@@ -20,6 +20,7 @@
97076 #include <linux/writeback.h>
97077 #include <linux/compaction.h>
97078 #include <linux/mm_inline.h>
97079+#include <linux/grsecurity.h>
97080
97081 #include "internal.h"
97082
97083@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
97084 *
97085 * vm_stat contains the global counters
97086 */
97087-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97088+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97089 EXPORT_SYMBOL(vm_stat);
97090
97091 #ifdef CONFIG_SMP
97092@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
97093
97094 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97095 if (diff[i])
97096- atomic_long_add(diff[i], &vm_stat[i]);
97097+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
97098 }
97099
97100 /*
97101@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
97102 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
97103 if (v) {
97104
97105- atomic_long_add(v, &zone->vm_stat[i]);
97106+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97107 global_diff[i] += v;
97108 #ifdef CONFIG_NUMA
97109 /* 3 seconds idle till flush */
97110@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
97111
97112 v = p->vm_stat_diff[i];
97113 p->vm_stat_diff[i] = 0;
97114- atomic_long_add(v, &zone->vm_stat[i]);
97115+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97116 global_diff[i] += v;
97117 }
97118 }
97119@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
97120 if (pset->vm_stat_diff[i]) {
97121 int v = pset->vm_stat_diff[i];
97122 pset->vm_stat_diff[i] = 0;
97123- atomic_long_add(v, &zone->vm_stat[i]);
97124- atomic_long_add(v, &vm_stat[i]);
97125+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97126+ atomic_long_add_unchecked(v, &vm_stat[i]);
97127 }
97128 }
97129 #endif
97130@@ -1156,10 +1157,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
97131 stat_items_size += sizeof(struct vm_event_state);
97132 #endif
97133
97134- v = kmalloc(stat_items_size, GFP_KERNEL);
97135+ v = kzalloc(stat_items_size, GFP_KERNEL);
97136 m->private = v;
97137 if (!v)
97138 return ERR_PTR(-ENOMEM);
97139+
97140+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97141+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
97142+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
97143+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
97144+ && !in_group_p(grsec_proc_gid)
97145+#endif
97146+ )
97147+ return (unsigned long *)m->private + *pos;
97148+#endif
97149+#endif
97150+
97151 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97152 v[i] = global_page_state(i);
97153 v += NR_VM_ZONE_STAT_ITEMS;
97154@@ -1308,10 +1321,16 @@ static int __init setup_vmstat(void)
97155 cpu_notifier_register_done();
97156 #endif
97157 #ifdef CONFIG_PROC_FS
97158- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
97159- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
97160- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97161- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
97162+ {
97163+ mode_t gr_mode = S_IRUGO;
97164+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97165+ gr_mode = S_IRUSR;
97166+#endif
97167+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
97168+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
97169+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97170+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
97171+ }
97172 #endif
97173 return 0;
97174 }
97175diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
97176index 44ebd5c..1f732bae 100644
97177--- a/net/8021q/vlan.c
97178+++ b/net/8021q/vlan.c
97179@@ -475,7 +475,7 @@ out:
97180 return NOTIFY_DONE;
97181 }
97182
97183-static struct notifier_block vlan_notifier_block __read_mostly = {
97184+static struct notifier_block vlan_notifier_block = {
97185 .notifier_call = vlan_device_event,
97186 };
97187
97188@@ -550,8 +550,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
97189 err = -EPERM;
97190 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
97191 break;
97192- if ((args.u.name_type >= 0) &&
97193- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
97194+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
97195 struct vlan_net *vn;
97196
97197 vn = net_generic(net, vlan_net_id);
97198diff --git a/net/9p/client.c b/net/9p/client.c
97199index 0004cba..feba240 100644
97200--- a/net/9p/client.c
97201+++ b/net/9p/client.c
97202@@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97203 len - inline_len);
97204 } else {
97205 err = copy_from_user(ename + inline_len,
97206- uidata, len - inline_len);
97207+ (char __force_user *)uidata, len - inline_len);
97208 if (err) {
97209 err = -EFAULT;
97210 goto out_err;
97211@@ -1571,7 +1571,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97212 kernel_buf = 1;
97213 indata = data;
97214 } else
97215- indata = (__force char *)udata;
97216+ indata = (__force_kernel char *)udata;
97217 /*
97218 * response header len is 11
97219 * PDU Header(7) + IO Size (4)
97220@@ -1646,7 +1646,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97221 kernel_buf = 1;
97222 odata = data;
97223 } else
97224- odata = (char *)udata;
97225+ odata = (char __force_kernel *)udata;
97226 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97227 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97228 fid->fid, offset, rsize);
97229diff --git a/net/9p/mod.c b/net/9p/mod.c
97230index 6ab36ae..6f1841b 100644
97231--- a/net/9p/mod.c
97232+++ b/net/9p/mod.c
97233@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97234 void v9fs_register_trans(struct p9_trans_module *m)
97235 {
97236 spin_lock(&v9fs_trans_lock);
97237- list_add_tail(&m->list, &v9fs_trans_list);
97238+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97239 spin_unlock(&v9fs_trans_lock);
97240 }
97241 EXPORT_SYMBOL(v9fs_register_trans);
97242@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97243 void v9fs_unregister_trans(struct p9_trans_module *m)
97244 {
97245 spin_lock(&v9fs_trans_lock);
97246- list_del_init(&m->list);
97247+ pax_list_del_init((struct list_head *)&m->list);
97248 spin_unlock(&v9fs_trans_lock);
97249 }
97250 EXPORT_SYMBOL(v9fs_unregister_trans);
97251diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97252index 80d08f6..de63fd1 100644
97253--- a/net/9p/trans_fd.c
97254+++ b/net/9p/trans_fd.c
97255@@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97256 oldfs = get_fs();
97257 set_fs(get_ds());
97258 /* The cast to a user pointer is valid due to the set_fs() */
97259- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97260+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97261 set_fs(oldfs);
97262
97263 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97264diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97265index af46bc4..f9adfcd 100644
97266--- a/net/appletalk/atalk_proc.c
97267+++ b/net/appletalk/atalk_proc.c
97268@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97269 struct proc_dir_entry *p;
97270 int rc = -ENOMEM;
97271
97272- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97273+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97274 if (!atalk_proc_dir)
97275 goto out;
97276
97277diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97278index 876fbe8..8bbea9f 100644
97279--- a/net/atm/atm_misc.c
97280+++ b/net/atm/atm_misc.c
97281@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97282 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97283 return 1;
97284 atm_return(vcc, truesize);
97285- atomic_inc(&vcc->stats->rx_drop);
97286+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97287 return 0;
97288 }
97289 EXPORT_SYMBOL(atm_charge);
97290@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97291 }
97292 }
97293 atm_return(vcc, guess);
97294- atomic_inc(&vcc->stats->rx_drop);
97295+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97296 return NULL;
97297 }
97298 EXPORT_SYMBOL(atm_alloc_charge);
97299@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
97300
97301 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97302 {
97303-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97304+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97305 __SONET_ITEMS
97306 #undef __HANDLE_ITEM
97307 }
97308@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
97309
97310 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97311 {
97312-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97313+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
97314 __SONET_ITEMS
97315 #undef __HANDLE_ITEM
97316 }
97317diff --git a/net/atm/lec.c b/net/atm/lec.c
97318index 4c5b8ba..95f7005 100644
97319--- a/net/atm/lec.c
97320+++ b/net/atm/lec.c
97321@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
97322 }
97323
97324 static struct lane2_ops lane2_ops = {
97325- lane2_resolve, /* resolve, spec 3.1.3 */
97326- lane2_associate_req, /* associate_req, spec 3.1.4 */
97327- NULL /* associate indicator, spec 3.1.5 */
97328+ .resolve = lane2_resolve,
97329+ .associate_req = lane2_associate_req,
97330+ .associate_indicator = NULL
97331 };
97332
97333 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
97334diff --git a/net/atm/lec.h b/net/atm/lec.h
97335index 4149db1..f2ab682 100644
97336--- a/net/atm/lec.h
97337+++ b/net/atm/lec.h
97338@@ -48,7 +48,7 @@ struct lane2_ops {
97339 const u8 *tlvs, u32 sizeoftlvs);
97340 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
97341 const u8 *tlvs, u32 sizeoftlvs);
97342-};
97343+} __no_const;
97344
97345 /*
97346 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
97347diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
97348index d1b2d9a..d549f7f 100644
97349--- a/net/atm/mpoa_caches.c
97350+++ b/net/atm/mpoa_caches.c
97351@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
97352
97353
97354 static struct in_cache_ops ingress_ops = {
97355- in_cache_add_entry, /* add_entry */
97356- in_cache_get, /* get */
97357- in_cache_get_with_mask, /* get_with_mask */
97358- in_cache_get_by_vcc, /* get_by_vcc */
97359- in_cache_put, /* put */
97360- in_cache_remove_entry, /* remove_entry */
97361- cache_hit, /* cache_hit */
97362- clear_count_and_expired, /* clear_count */
97363- check_resolving_entries, /* check_resolving */
97364- refresh_entries, /* refresh */
97365- in_destroy_cache /* destroy_cache */
97366+ .add_entry = in_cache_add_entry,
97367+ .get = in_cache_get,
97368+ .get_with_mask = in_cache_get_with_mask,
97369+ .get_by_vcc = in_cache_get_by_vcc,
97370+ .put = in_cache_put,
97371+ .remove_entry = in_cache_remove_entry,
97372+ .cache_hit = cache_hit,
97373+ .clear_count = clear_count_and_expired,
97374+ .check_resolving = check_resolving_entries,
97375+ .refresh = refresh_entries,
97376+ .destroy_cache = in_destroy_cache
97377 };
97378
97379 static struct eg_cache_ops egress_ops = {
97380- eg_cache_add_entry, /* add_entry */
97381- eg_cache_get_by_cache_id, /* get_by_cache_id */
97382- eg_cache_get_by_tag, /* get_by_tag */
97383- eg_cache_get_by_vcc, /* get_by_vcc */
97384- eg_cache_get_by_src_ip, /* get_by_src_ip */
97385- eg_cache_put, /* put */
97386- eg_cache_remove_entry, /* remove_entry */
97387- update_eg_cache_entry, /* update */
97388- clear_expired, /* clear_expired */
97389- eg_destroy_cache /* destroy_cache */
97390+ .add_entry = eg_cache_add_entry,
97391+ .get_by_cache_id = eg_cache_get_by_cache_id,
97392+ .get_by_tag = eg_cache_get_by_tag,
97393+ .get_by_vcc = eg_cache_get_by_vcc,
97394+ .get_by_src_ip = eg_cache_get_by_src_ip,
97395+ .put = eg_cache_put,
97396+ .remove_entry = eg_cache_remove_entry,
97397+ .update = update_eg_cache_entry,
97398+ .clear_expired = clear_expired,
97399+ .destroy_cache = eg_destroy_cache
97400 };
97401
97402
97403diff --git a/net/atm/proc.c b/net/atm/proc.c
97404index bbb6461..cf04016 100644
97405--- a/net/atm/proc.c
97406+++ b/net/atm/proc.c
97407@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
97408 const struct k_atm_aal_stats *stats)
97409 {
97410 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
97411- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
97412- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
97413- atomic_read(&stats->rx_drop));
97414+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
97415+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
97416+ atomic_read_unchecked(&stats->rx_drop));
97417 }
97418
97419 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
97420diff --git a/net/atm/resources.c b/net/atm/resources.c
97421index 0447d5d..3cf4728 100644
97422--- a/net/atm/resources.c
97423+++ b/net/atm/resources.c
97424@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
97425 static void copy_aal_stats(struct k_atm_aal_stats *from,
97426 struct atm_aal_stats *to)
97427 {
97428-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97429+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97430 __AAL_STAT_ITEMS
97431 #undef __HANDLE_ITEM
97432 }
97433@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
97434 static void subtract_aal_stats(struct k_atm_aal_stats *from,
97435 struct atm_aal_stats *to)
97436 {
97437-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97438+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
97439 __AAL_STAT_ITEMS
97440 #undef __HANDLE_ITEM
97441 }
97442diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
97443index 919a5ce..cc6b444 100644
97444--- a/net/ax25/sysctl_net_ax25.c
97445+++ b/net/ax25/sysctl_net_ax25.c
97446@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
97447 {
97448 char path[sizeof("net/ax25/") + IFNAMSIZ];
97449 int k;
97450- struct ctl_table *table;
97451+ ctl_table_no_const *table;
97452
97453 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
97454 if (!table)
97455diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
97456index f04224c..f326579 100644
97457--- a/net/batman-adv/bat_iv_ogm.c
97458+++ b/net/batman-adv/bat_iv_ogm.c
97459@@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
97460
97461 /* randomize initial seqno to avoid collision */
97462 get_random_bytes(&random_seqno, sizeof(random_seqno));
97463- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97464+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97465
97466 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
97467 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
97468@@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
97469 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
97470
97471 /* change sequence number to network order */
97472- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
97473+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
97474 batadv_ogm_packet->seqno = htonl(seqno);
97475- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
97476+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
97477
97478 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
97479
97480@@ -1596,7 +1596,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
97481 return;
97482
97483 /* could be changed by schedule_own_packet() */
97484- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
97485+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
97486
97487 if (ogm_packet->flags & BATADV_DIRECTLINK)
97488 has_directlink_flag = true;
97489diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
97490index f14e54a..66f3e2e 100644
97491--- a/net/batman-adv/fragmentation.c
97492+++ b/net/batman-adv/fragmentation.c
97493@@ -446,7 +446,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
97494 frag_header.packet_type = BATADV_UNICAST_FRAG;
97495 frag_header.version = BATADV_COMPAT_VERSION;
97496 frag_header.ttl = BATADV_TTL;
97497- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
97498+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
97499 frag_header.reserved = 0;
97500 frag_header.no = 0;
97501 frag_header.total_size = htons(skb->len);
97502diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
97503index 744a59b..8fd037c 100644
97504--- a/net/batman-adv/soft-interface.c
97505+++ b/net/batman-adv/soft-interface.c
97506@@ -296,7 +296,7 @@ send:
97507 primary_if->net_dev->dev_addr);
97508
97509 /* set broadcast sequence number */
97510- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
97511+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
97512 bcast_packet->seqno = htonl(seqno);
97513
97514 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
97515@@ -729,7 +729,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97516 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
97517
97518 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
97519- atomic_set(&bat_priv->bcast_seqno, 1);
97520+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
97521 atomic_set(&bat_priv->tt.vn, 0);
97522 atomic_set(&bat_priv->tt.local_changes, 0);
97523 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
97524@@ -743,7 +743,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97525
97526 /* randomize initial seqno to avoid collision */
97527 get_random_bytes(&random_seqno, sizeof(random_seqno));
97528- atomic_set(&bat_priv->frag_seqno, random_seqno);
97529+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
97530
97531 bat_priv->primary_if = NULL;
97532 bat_priv->num_ifaces = 0;
97533diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
97534index 34891a5..3cfece0 100644
97535--- a/net/batman-adv/types.h
97536+++ b/net/batman-adv/types.h
97537@@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
97538 struct batadv_hard_iface_bat_iv {
97539 unsigned char *ogm_buff;
97540 int ogm_buff_len;
97541- atomic_t ogm_seqno;
97542+ atomic_unchecked_t ogm_seqno;
97543 };
97544
97545 /**
97546@@ -766,7 +766,7 @@ struct batadv_priv {
97547 atomic_t bonding;
97548 atomic_t fragmentation;
97549 atomic_t packet_size_max;
97550- atomic_t frag_seqno;
97551+ atomic_unchecked_t frag_seqno;
97552 #ifdef CONFIG_BATMAN_ADV_BLA
97553 atomic_t bridge_loop_avoidance;
97554 #endif
97555@@ -785,7 +785,7 @@ struct batadv_priv {
97556 #endif
97557 uint32_t isolation_mark;
97558 uint32_t isolation_mark_mask;
97559- atomic_t bcast_seqno;
97560+ atomic_unchecked_t bcast_seqno;
97561 atomic_t bcast_queue_left;
97562 atomic_t batman_queue_left;
97563 char num_ifaces;
97564diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
97565index b9a418e..2af862a 100644
97566--- a/net/bluetooth/hci_sock.c
97567+++ b/net/bluetooth/hci_sock.c
97568@@ -1053,7 +1053,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
97569 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
97570 }
97571
97572- len = min_t(unsigned int, len, sizeof(uf));
97573+ len = min((size_t)len, sizeof(uf));
97574 if (copy_from_user(&uf, optval, len)) {
97575 err = -EFAULT;
97576 break;
97577diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
97578index dc4d301..4975bac 100644
97579--- a/net/bluetooth/l2cap_core.c
97580+++ b/net/bluetooth/l2cap_core.c
97581@@ -3536,8 +3536,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
97582 break;
97583
97584 case L2CAP_CONF_RFC:
97585- if (olen == sizeof(rfc))
97586- memcpy(&rfc, (void *)val, olen);
97587+ if (olen != sizeof(rfc))
97588+ break;
97589+
97590+ memcpy(&rfc, (void *)val, olen);
97591
97592 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
97593 rfc.mode != chan->mode)
97594diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
97595index ef5e5b0..7d904ad 100644
97596--- a/net/bluetooth/l2cap_sock.c
97597+++ b/net/bluetooth/l2cap_sock.c
97598@@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97599 struct sock *sk = sock->sk;
97600 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
97601 struct l2cap_options opts;
97602- int len, err = 0;
97603+ int err = 0;
97604+ size_t len = optlen;
97605 u32 opt;
97606
97607 BT_DBG("sk %p", sk);
97608@@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97609 opts.max_tx = chan->max_tx;
97610 opts.txwin_size = chan->tx_win;
97611
97612- len = min_t(unsigned int, sizeof(opts), optlen);
97613+ len = min(sizeof(opts), len);
97614 if (copy_from_user((char *) &opts, optval, len)) {
97615 err = -EFAULT;
97616 break;
97617@@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97618 struct bt_security sec;
97619 struct bt_power pwr;
97620 struct l2cap_conn *conn;
97621- int len, err = 0;
97622+ int err = 0;
97623+ size_t len = optlen;
97624 u32 opt;
97625
97626 BT_DBG("sk %p", sk);
97627@@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97628
97629 sec.level = BT_SECURITY_LOW;
97630
97631- len = min_t(unsigned int, sizeof(sec), optlen);
97632+ len = min(sizeof(sec), len);
97633 if (copy_from_user((char *) &sec, optval, len)) {
97634 err = -EFAULT;
97635 break;
97636@@ -866,7 +868,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97637
97638 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
97639
97640- len = min_t(unsigned int, sizeof(pwr), optlen);
97641+ len = min(sizeof(pwr), len);
97642 if (copy_from_user((char *) &pwr, optval, len)) {
97643 err = -EFAULT;
97644 break;
97645diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
97646index c603a5e..7f08991 100644
97647--- a/net/bluetooth/rfcomm/sock.c
97648+++ b/net/bluetooth/rfcomm/sock.c
97649@@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97650 struct sock *sk = sock->sk;
97651 struct bt_security sec;
97652 int err = 0;
97653- size_t len;
97654+ size_t len = optlen;
97655 u32 opt;
97656
97657 BT_DBG("sk %p", sk);
97658@@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97659
97660 sec.level = BT_SECURITY_LOW;
97661
97662- len = min_t(unsigned int, sizeof(sec), optlen);
97663+ len = min(sizeof(sec), len);
97664 if (copy_from_user((char *) &sec, optval, len)) {
97665 err = -EFAULT;
97666 break;
97667diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
97668index 403ec09..a21a003 100644
97669--- a/net/bluetooth/rfcomm/tty.c
97670+++ b/net/bluetooth/rfcomm/tty.c
97671@@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
97672 BT_DBG("tty %p id %d", tty, tty->index);
97673
97674 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
97675- dev->channel, dev->port.count);
97676+ dev->channel, atomic_read(&dev->port.count));
97677
97678 err = tty_port_open(&dev->port, tty, filp);
97679 if (err)
97680@@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
97681 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
97682
97683 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
97684- dev->port.count);
97685+ atomic_read(&dev->port.count));
97686
97687 tty_port_close(&dev->port, tty, filp);
97688 }
97689diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
97690index 1059ed3..d70846a 100644
97691--- a/net/bridge/netfilter/ebtables.c
97692+++ b/net/bridge/netfilter/ebtables.c
97693@@ -1524,7 +1524,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97694 tmp.valid_hooks = t->table->valid_hooks;
97695 }
97696 mutex_unlock(&ebt_mutex);
97697- if (copy_to_user(user, &tmp, *len) != 0) {
97698+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97699 BUGPRINT("c2u Didn't work\n");
97700 ret = -EFAULT;
97701 break;
97702@@ -2330,7 +2330,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97703 goto out;
97704 tmp.valid_hooks = t->valid_hooks;
97705
97706- if (copy_to_user(user, &tmp, *len) != 0) {
97707+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97708 ret = -EFAULT;
97709 break;
97710 }
97711@@ -2341,7 +2341,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97712 tmp.entries_size = t->table->entries_size;
97713 tmp.valid_hooks = t->table->valid_hooks;
97714
97715- if (copy_to_user(user, &tmp, *len) != 0) {
97716+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97717 ret = -EFAULT;
97718 break;
97719 }
97720diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
97721index 0f45522..dab651f 100644
97722--- a/net/caif/cfctrl.c
97723+++ b/net/caif/cfctrl.c
97724@@ -10,6 +10,7 @@
97725 #include <linux/spinlock.h>
97726 #include <linux/slab.h>
97727 #include <linux/pkt_sched.h>
97728+#include <linux/sched.h>
97729 #include <net/caif/caif_layer.h>
97730 #include <net/caif/cfpkt.h>
97731 #include <net/caif/cfctrl.h>
97732@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
97733 memset(&dev_info, 0, sizeof(dev_info));
97734 dev_info.id = 0xff;
97735 cfsrvl_init(&this->serv, 0, &dev_info, false);
97736- atomic_set(&this->req_seq_no, 1);
97737- atomic_set(&this->rsp_seq_no, 1);
97738+ atomic_set_unchecked(&this->req_seq_no, 1);
97739+ atomic_set_unchecked(&this->rsp_seq_no, 1);
97740 this->serv.layer.receive = cfctrl_recv;
97741 sprintf(this->serv.layer.name, "ctrl");
97742 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
97743@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
97744 struct cfctrl_request_info *req)
97745 {
97746 spin_lock_bh(&ctrl->info_list_lock);
97747- atomic_inc(&ctrl->req_seq_no);
97748- req->sequence_no = atomic_read(&ctrl->req_seq_no);
97749+ atomic_inc_unchecked(&ctrl->req_seq_no);
97750+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
97751 list_add_tail(&req->list, &ctrl->list);
97752 spin_unlock_bh(&ctrl->info_list_lock);
97753 }
97754@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
97755 if (p != first)
97756 pr_warn("Requests are not received in order\n");
97757
97758- atomic_set(&ctrl->rsp_seq_no,
97759+ atomic_set_unchecked(&ctrl->rsp_seq_no,
97760 p->sequence_no);
97761 list_del(&p->list);
97762 goto out;
97763diff --git a/net/can/af_can.c b/net/can/af_can.c
97764index a27f8aa..67174a3 100644
97765--- a/net/can/af_can.c
97766+++ b/net/can/af_can.c
97767@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
97768 };
97769
97770 /* notifier block for netdevice event */
97771-static struct notifier_block can_netdev_notifier __read_mostly = {
97772+static struct notifier_block can_netdev_notifier = {
97773 .notifier_call = can_notifier,
97774 };
97775
97776diff --git a/net/can/bcm.c b/net/can/bcm.c
97777index dcb75c0..24b1b43 100644
97778--- a/net/can/bcm.c
97779+++ b/net/can/bcm.c
97780@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
97781 }
97782
97783 /* create /proc/net/can-bcm directory */
97784- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
97785+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
97786 return 0;
97787 }
97788
97789diff --git a/net/can/gw.c b/net/can/gw.c
97790index 050a211..bb9fe33 100644
97791--- a/net/can/gw.c
97792+++ b/net/can/gw.c
97793@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
97794 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
97795
97796 static HLIST_HEAD(cgw_list);
97797-static struct notifier_block notifier;
97798
97799 static struct kmem_cache *cgw_cache __read_mostly;
97800
97801@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
97802 return err;
97803 }
97804
97805+static struct notifier_block notifier = {
97806+ .notifier_call = cgw_notifier
97807+};
97808+
97809 static __init int cgw_module_init(void)
97810 {
97811 /* sanitize given module parameter */
97812@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
97813 return -ENOMEM;
97814
97815 /* set notifier */
97816- notifier.notifier_call = cgw_notifier;
97817 register_netdevice_notifier(&notifier);
97818
97819 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
97820diff --git a/net/can/proc.c b/net/can/proc.c
97821index b543470..d2ddae2 100644
97822--- a/net/can/proc.c
97823+++ b/net/can/proc.c
97824@@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
97825 void can_init_proc(void)
97826 {
97827 /* create /proc/net/can directory */
97828- can_dir = proc_mkdir("can", init_net.proc_net);
97829+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
97830
97831 if (!can_dir) {
97832 printk(KERN_INFO "can: failed to create /proc/net/can . "
97833diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
97834index 1948d59..9e854d5 100644
97835--- a/net/ceph/messenger.c
97836+++ b/net/ceph/messenger.c
97837@@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
97838 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
97839
97840 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
97841-static atomic_t addr_str_seq = ATOMIC_INIT(0);
97842+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
97843
97844 static struct page *zero_page; /* used in certain error cases */
97845
97846@@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
97847 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
97848 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
97849
97850- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97851+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97852 s = addr_str[i];
97853
97854 switch (ss->ss_family) {
97855diff --git a/net/compat.c b/net/compat.c
97856index 9a76eaf..5b8ccfd 100644
97857--- a/net/compat.c
97858+++ b/net/compat.c
97859@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
97860 return -EFAULT;
97861 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
97862 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
97863- kmsg->msg_name = compat_ptr(tmp1);
97864- kmsg->msg_iov = compat_ptr(tmp2);
97865- kmsg->msg_control = compat_ptr(tmp3);
97866+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
97867+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
97868+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
97869 return 0;
97870 }
97871
97872@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97873
97874 if (kern_msg->msg_namelen) {
97875 if (mode == VERIFY_READ) {
97876- int err = move_addr_to_kernel(kern_msg->msg_name,
97877+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
97878 kern_msg->msg_namelen,
97879 kern_address);
97880 if (err < 0)
97881@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97882 kern_msg->msg_name = NULL;
97883
97884 tot_len = iov_from_user_compat_to_kern(kern_iov,
97885- (struct compat_iovec __user *)kern_msg->msg_iov,
97886+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
97887 kern_msg->msg_iovlen);
97888 if (tot_len >= 0)
97889 kern_msg->msg_iov = kern_iov;
97890@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97891
97892 #define CMSG_COMPAT_FIRSTHDR(msg) \
97893 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
97894- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
97895+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
97896 (struct compat_cmsghdr __user *)NULL)
97897
97898 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
97899 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
97900 (ucmlen) <= (unsigned long) \
97901 ((mhdr)->msg_controllen - \
97902- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
97903+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
97904
97905 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
97906 struct compat_cmsghdr __user *cmsg, int cmsg_len)
97907 {
97908 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
97909- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
97910+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
97911 msg->msg_controllen)
97912 return NULL;
97913 return (struct compat_cmsghdr __user *)ptr;
97914@@ -222,7 +222,7 @@ Efault:
97915
97916 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
97917 {
97918- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97919+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97920 struct compat_cmsghdr cmhdr;
97921 struct compat_timeval ctv;
97922 struct compat_timespec cts[3];
97923@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
97924
97925 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
97926 {
97927- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97928+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97929 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
97930 int fdnum = scm->fp->count;
97931 struct file **fp = scm->fp->fp;
97932@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
97933 return -EFAULT;
97934 old_fs = get_fs();
97935 set_fs(KERNEL_DS);
97936- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
97937+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
97938 set_fs(old_fs);
97939
97940 return err;
97941@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
97942 len = sizeof(ktime);
97943 old_fs = get_fs();
97944 set_fs(KERNEL_DS);
97945- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
97946+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
97947 set_fs(old_fs);
97948
97949 if (!err) {
97950@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97951 case MCAST_JOIN_GROUP:
97952 case MCAST_LEAVE_GROUP:
97953 {
97954- struct compat_group_req __user *gr32 = (void *)optval;
97955+ struct compat_group_req __user *gr32 = (void __user *)optval;
97956 struct group_req __user *kgr =
97957 compat_alloc_user_space(sizeof(struct group_req));
97958 u32 interface;
97959@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97960 case MCAST_BLOCK_SOURCE:
97961 case MCAST_UNBLOCK_SOURCE:
97962 {
97963- struct compat_group_source_req __user *gsr32 = (void *)optval;
97964+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
97965 struct group_source_req __user *kgsr = compat_alloc_user_space(
97966 sizeof(struct group_source_req));
97967 u32 interface;
97968@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
97969 }
97970 case MCAST_MSFILTER:
97971 {
97972- struct compat_group_filter __user *gf32 = (void *)optval;
97973+ struct compat_group_filter __user *gf32 = (void __user *)optval;
97974 struct group_filter __user *kgf;
97975 u32 interface, fmode, numsrc;
97976
97977@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
97978 char __user *optval, int __user *optlen,
97979 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
97980 {
97981- struct compat_group_filter __user *gf32 = (void *)optval;
97982+ struct compat_group_filter __user *gf32 = (void __user *)optval;
97983 struct group_filter __user *kgf;
97984 int __user *koptlen;
97985 u32 interface, fmode, numsrc;
97986@@ -803,7 +803,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
97987
97988 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
97989 return -EINVAL;
97990- if (copy_from_user(a, args, nas[call]))
97991+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
97992 return -EFAULT;
97993 a0 = a[0];
97994 a1 = a[1];
97995diff --git a/net/core/datagram.c b/net/core/datagram.c
97996index a16ed7b..eb44d17 100644
97997--- a/net/core/datagram.c
97998+++ b/net/core/datagram.c
97999@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
98000 }
98001
98002 kfree_skb(skb);
98003- atomic_inc(&sk->sk_drops);
98004+ atomic_inc_unchecked(&sk->sk_drops);
98005 sk_mem_reclaim_partial(sk);
98006
98007 return err;
98008diff --git a/net/core/dev.c b/net/core/dev.c
98009index a30bef1..51d3e33 100644
98010--- a/net/core/dev.c
98011+++ b/net/core/dev.c
98012@@ -1683,14 +1683,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
98013 {
98014 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
98015 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
98016- atomic_long_inc(&dev->rx_dropped);
98017+ atomic_long_inc_unchecked(&dev->rx_dropped);
98018 kfree_skb(skb);
98019 return NET_RX_DROP;
98020 }
98021 }
98022
98023 if (unlikely(!is_skb_forwardable(dev, skb))) {
98024- atomic_long_inc(&dev->rx_dropped);
98025+ atomic_long_inc_unchecked(&dev->rx_dropped);
98026 kfree_skb(skb);
98027 return NET_RX_DROP;
98028 }
98029@@ -2463,7 +2463,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
98030
98031 struct dev_gso_cb {
98032 void (*destructor)(struct sk_buff *skb);
98033-};
98034+} __no_const;
98035
98036 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
98037
98038@@ -2893,7 +2893,7 @@ recursion_alert:
98039 rc = -ENETDOWN;
98040 rcu_read_unlock_bh();
98041
98042- atomic_long_inc(&dev->tx_dropped);
98043+ atomic_long_inc_unchecked(&dev->tx_dropped);
98044 kfree_skb(skb);
98045 return rc;
98046 out:
98047@@ -3237,7 +3237,7 @@ enqueue:
98048
98049 local_irq_restore(flags);
98050
98051- atomic_long_inc(&skb->dev->rx_dropped);
98052+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98053 kfree_skb(skb);
98054 return NET_RX_DROP;
98055 }
98056@@ -3314,7 +3314,7 @@ int netif_rx_ni(struct sk_buff *skb)
98057 }
98058 EXPORT_SYMBOL(netif_rx_ni);
98059
98060-static void net_tx_action(struct softirq_action *h)
98061+static __latent_entropy void net_tx_action(void)
98062 {
98063 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98064
98065@@ -3647,7 +3647,7 @@ ncls:
98066 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
98067 } else {
98068 drop:
98069- atomic_long_inc(&skb->dev->rx_dropped);
98070+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98071 kfree_skb(skb);
98072 /* Jamal, now you will not able to escape explaining
98073 * me how you were going to use this. :-)
98074@@ -4366,7 +4366,7 @@ void netif_napi_del(struct napi_struct *napi)
98075 }
98076 EXPORT_SYMBOL(netif_napi_del);
98077
98078-static void net_rx_action(struct softirq_action *h)
98079+static __latent_entropy void net_rx_action(void)
98080 {
98081 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98082 unsigned long time_limit = jiffies + 2;
98083@@ -6366,8 +6366,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
98084 } else {
98085 netdev_stats_to_stats64(storage, &dev->stats);
98086 }
98087- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
98088- storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
98089+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
98090+ storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
98091 return storage;
98092 }
98093 EXPORT_SYMBOL(dev_get_stats);
98094diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
98095index cf999e0..c59a975 100644
98096--- a/net/core/dev_ioctl.c
98097+++ b/net/core/dev_ioctl.c
98098@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
98099 if (no_module && capable(CAP_NET_ADMIN))
98100 no_module = request_module("netdev-%s", name);
98101 if (no_module && capable(CAP_SYS_MODULE)) {
98102+#ifdef CONFIG_GRKERNSEC_MODHARDEN
98103+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
98104+#else
98105 if (!request_module("%s", name))
98106 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
98107 name);
98108+#endif
98109 }
98110 }
98111 EXPORT_SYMBOL(dev_load);
98112diff --git a/net/core/dst.c b/net/core/dst.c
98113index 80d6286..a028409 100644
98114--- a/net/core/dst.c
98115+++ b/net/core/dst.c
98116@@ -269,6 +269,15 @@ again:
98117 }
98118 EXPORT_SYMBOL(dst_destroy);
98119
98120+static void dst_destroy_rcu(struct rcu_head *head)
98121+{
98122+ struct dst_entry *dst = container_of(head, struct dst_entry, rcu_head);
98123+
98124+ dst = dst_destroy(dst);
98125+ if (dst)
98126+ __dst_free(dst);
98127+}
98128+
98129 void dst_release(struct dst_entry *dst)
98130 {
98131 if (dst) {
98132@@ -276,11 +285,8 @@ void dst_release(struct dst_entry *dst)
98133
98134 newrefcnt = atomic_dec_return(&dst->__refcnt);
98135 WARN_ON(newrefcnt < 0);
98136- if (unlikely(dst->flags & DST_NOCACHE) && !newrefcnt) {
98137- dst = dst_destroy(dst);
98138- if (dst)
98139- __dst_free(dst);
98140- }
98141+ if (unlikely(dst->flags & DST_NOCACHE) && !newrefcnt)
98142+ call_rcu(&dst->rcu_head, dst_destroy_rcu);
98143 }
98144 }
98145 EXPORT_SYMBOL(dst_release);
98146diff --git a/net/core/filter.c b/net/core/filter.c
98147index 4aec7b9..5cf605c 100644
98148--- a/net/core/filter.c
98149+++ b/net/core/filter.c
98150@@ -1121,7 +1121,11 @@ do_pass:
98151 break;
98152
98153 default:
98154- goto err;
98155+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
98156+ fp->code, fp->jt, fp->jf, fp->k);
98157+ kfree(addrs);
98158+ BUG();
98159+ return -EINVAL;
98160 }
98161
98162 insn++;
98163@@ -1170,7 +1174,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
98164 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
98165 int pc, ret = 0;
98166
98167- BUILD_BUG_ON(BPF_MEMWORDS > 16);
98168+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
98169 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
98170 if (!masks)
98171 return -ENOMEM;
98172@@ -1605,7 +1609,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
98173 if (!fp)
98174 return -ENOMEM;
98175
98176- memcpy(fp->insns, fprog->filter, fsize);
98177+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
98178
98179 atomic_set(&fp->refcnt, 1);
98180 fp->len = fprog->len;
98181diff --git a/net/core/flow.c b/net/core/flow.c
98182index a0348fd..6951c76 100644
98183--- a/net/core/flow.c
98184+++ b/net/core/flow.c
98185@@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98186 static int flow_entry_valid(struct flow_cache_entry *fle,
98187 struct netns_xfrm *xfrm)
98188 {
98189- if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
98190+ if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
98191 return 0;
98192 if (fle->object && !fle->object->ops->check(fle->object))
98193 return 0;
98194@@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98195 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98196 fcp->hash_count++;
98197 }
98198- } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
98199+ } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
98200 flo = fle->object;
98201 if (!flo)
98202 goto ret_object;
98203@@ -263,7 +263,7 @@ nocache:
98204 }
98205 flo = resolver(net, key, family, dir, flo, ctx);
98206 if (fle) {
98207- fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
98208+ fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
98209 if (!IS_ERR(flo))
98210 fle->object = flo;
98211 else
98212diff --git a/net/core/iovec.c b/net/core/iovec.c
98213index b618694..192bbba 100644
98214--- a/net/core/iovec.c
98215+++ b/net/core/iovec.c
98216@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98217 if (m->msg_namelen) {
98218 if (mode == VERIFY_READ) {
98219 void __user *namep;
98220- namep = (void __user __force *) m->msg_name;
98221+ namep = (void __force_user *) m->msg_name;
98222 err = move_addr_to_kernel(namep, m->msg_namelen,
98223 address);
98224 if (err < 0)
98225@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98226 }
98227
98228 size = m->msg_iovlen * sizeof(struct iovec);
98229- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98230+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98231 return -EFAULT;
98232
98233 m->msg_iov = iov;
98234diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98235index 32d872e..487e769 100644
98236--- a/net/core/neighbour.c
98237+++ b/net/core/neighbour.c
98238@@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98239 void __user *buffer, size_t *lenp, loff_t *ppos)
98240 {
98241 int size, ret;
98242- struct ctl_table tmp = *ctl;
98243+ ctl_table_no_const tmp = *ctl;
98244
98245 tmp.extra1 = &zero;
98246 tmp.extra2 = &unres_qlen_max;
98247@@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98248 void __user *buffer,
98249 size_t *lenp, loff_t *ppos)
98250 {
98251- struct ctl_table tmp = *ctl;
98252+ ctl_table_no_const tmp = *ctl;
98253 int ret;
98254
98255 tmp.extra1 = &zero;
98256@@ -3059,11 +3059,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98257 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98258 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98259 } else {
98260+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98261 dev_name_source = "default";
98262- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98263- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98264- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98265- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98266+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98267+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98268+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98269+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98270 }
98271
98272 if (handler) {
98273diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98274index 2bf8329..2eb1423 100644
98275--- a/net/core/net-procfs.c
98276+++ b/net/core/net-procfs.c
98277@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98278 struct rtnl_link_stats64 temp;
98279 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98280
98281- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98282+ if (gr_proc_is_restricted())
98283+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98284+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98285+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98286+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98287+ else
98288+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98289 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98290 dev->name, stats->rx_bytes, stats->rx_packets,
98291 stats->rx_errors,
98292@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98293 return 0;
98294 }
98295
98296-static const struct seq_operations dev_seq_ops = {
98297+const struct seq_operations dev_seq_ops = {
98298 .start = dev_seq_start,
98299 .next = dev_seq_next,
98300 .stop = dev_seq_stop,
98301@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98302
98303 static int softnet_seq_open(struct inode *inode, struct file *file)
98304 {
98305- return seq_open(file, &softnet_seq_ops);
98306+ return seq_open_restrict(file, &softnet_seq_ops);
98307 }
98308
98309 static const struct file_operations softnet_seq_fops = {
98310@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98311 else
98312 seq_printf(seq, "%04x", ntohs(pt->type));
98313
98314+#ifdef CONFIG_GRKERNSEC_HIDESYM
98315+ seq_printf(seq, " %-8s %pf\n",
98316+ pt->dev ? pt->dev->name : "", NULL);
98317+#else
98318 seq_printf(seq, " %-8s %pf\n",
98319 pt->dev ? pt->dev->name : "", pt->func);
98320+#endif
98321 }
98322
98323 return 0;
98324diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
98325index 1cac29e..fb482f3 100644
98326--- a/net/core/net-sysfs.c
98327+++ b/net/core/net-sysfs.c
98328@@ -259,7 +259,7 @@ static ssize_t carrier_changes_show(struct device *dev,
98329 {
98330 struct net_device *netdev = to_net_dev(dev);
98331 return sprintf(buf, fmt_dec,
98332- atomic_read(&netdev->carrier_changes));
98333+ atomic_read_unchecked(&netdev->carrier_changes));
98334 }
98335 static DEVICE_ATTR_RO(carrier_changes);
98336
98337diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
98338index 7c8ffd9..0cb3687 100644
98339--- a/net/core/net_namespace.c
98340+++ b/net/core/net_namespace.c
98341@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
98342 int error;
98343 LIST_HEAD(net_exit_list);
98344
98345- list_add_tail(&ops->list, list);
98346+ pax_list_add_tail((struct list_head *)&ops->list, list);
98347 if (ops->init || (ops->id && ops->size)) {
98348 for_each_net(net) {
98349 error = ops_init(ops, net);
98350@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
98351
98352 out_undo:
98353 /* If I have an error cleanup all namespaces I initialized */
98354- list_del(&ops->list);
98355+ pax_list_del((struct list_head *)&ops->list);
98356 ops_exit_list(ops, &net_exit_list);
98357 ops_free_list(ops, &net_exit_list);
98358 return error;
98359@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
98360 struct net *net;
98361 LIST_HEAD(net_exit_list);
98362
98363- list_del(&ops->list);
98364+ pax_list_del((struct list_head *)&ops->list);
98365 for_each_net(net)
98366 list_add_tail(&net->exit_list, &net_exit_list);
98367 ops_exit_list(ops, &net_exit_list);
98368@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
98369 mutex_lock(&net_mutex);
98370 error = register_pernet_operations(&pernet_list, ops);
98371 if (!error && (first_device == &pernet_list))
98372- first_device = &ops->list;
98373+ first_device = (struct list_head *)&ops->list;
98374 mutex_unlock(&net_mutex);
98375 return error;
98376 }
98377diff --git a/net/core/netpoll.c b/net/core/netpoll.c
98378index e33937f..b2b4981 100644
98379--- a/net/core/netpoll.c
98380+++ b/net/core/netpoll.c
98381@@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98382 struct udphdr *udph;
98383 struct iphdr *iph;
98384 struct ethhdr *eth;
98385- static atomic_t ip_ident;
98386+ static atomic_unchecked_t ip_ident;
98387 struct ipv6hdr *ip6h;
98388
98389 udp_len = len + sizeof(*udph);
98390@@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98391 put_unaligned(0x45, (unsigned char *)iph);
98392 iph->tos = 0;
98393 put_unaligned(htons(ip_len), &(iph->tot_len));
98394- iph->id = htons(atomic_inc_return(&ip_ident));
98395+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
98396 iph->frag_off = 0;
98397 iph->ttl = 64;
98398 iph->protocol = IPPROTO_UDP;
98399diff --git a/net/core/pktgen.c b/net/core/pktgen.c
98400index 0304f98..ddfead6 100644
98401--- a/net/core/pktgen.c
98402+++ b/net/core/pktgen.c
98403@@ -3725,7 +3725,7 @@ static int __net_init pg_net_init(struct net *net)
98404 pn->net = net;
98405 INIT_LIST_HEAD(&pn->pktgen_threads);
98406 pn->pktgen_exiting = false;
98407- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
98408+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
98409 if (!pn->proc_dir) {
98410 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
98411 return -ENODEV;
98412diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
98413index 1999ed8..1e6e58a 100644
98414--- a/net/core/rtnetlink.c
98415+++ b/net/core/rtnetlink.c
98416@@ -58,7 +58,7 @@ struct rtnl_link {
98417 rtnl_doit_func doit;
98418 rtnl_dumpit_func dumpit;
98419 rtnl_calcit_func calcit;
98420-};
98421+} __no_const;
98422
98423 static DEFINE_MUTEX(rtnl_mutex);
98424
98425@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
98426 if (rtnl_link_ops_get(ops->kind))
98427 return -EEXIST;
98428
98429- if (!ops->dellink)
98430- ops->dellink = unregister_netdevice_queue;
98431+ if (!ops->dellink) {
98432+ pax_open_kernel();
98433+ *(void **)&ops->dellink = unregister_netdevice_queue;
98434+ pax_close_kernel();
98435+ }
98436
98437- list_add_tail(&ops->list, &link_ops);
98438+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
98439 return 0;
98440 }
98441 EXPORT_SYMBOL_GPL(__rtnl_link_register);
98442@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
98443 for_each_net(net) {
98444 __rtnl_kill_links(net, ops);
98445 }
98446- list_del(&ops->list);
98447+ pax_list_del((struct list_head *)&ops->list);
98448 }
98449 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
98450
98451@@ -1008,7 +1011,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
98452 (dev->ifalias &&
98453 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
98454 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
98455- atomic_read(&dev->carrier_changes)))
98456+ atomic_read_unchecked(&dev->carrier_changes)))
98457 goto nla_put_failure;
98458
98459 if (1) {
98460diff --git a/net/core/scm.c b/net/core/scm.c
98461index b442e7e..6f5b5a2 100644
98462--- a/net/core/scm.c
98463+++ b/net/core/scm.c
98464@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
98465 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98466 {
98467 struct cmsghdr __user *cm
98468- = (__force struct cmsghdr __user *)msg->msg_control;
98469+ = (struct cmsghdr __force_user *)msg->msg_control;
98470 struct cmsghdr cmhdr;
98471 int cmlen = CMSG_LEN(len);
98472 int err;
98473@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98474 err = -EFAULT;
98475 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
98476 goto out;
98477- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
98478+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
98479 goto out;
98480 cmlen = CMSG_SPACE(len);
98481 if (msg->msg_controllen < cmlen)
98482@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
98483 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98484 {
98485 struct cmsghdr __user *cm
98486- = (__force struct cmsghdr __user*)msg->msg_control;
98487+ = (struct cmsghdr __force_user *)msg->msg_control;
98488
98489 int fdmax = 0;
98490 int fdnum = scm->fp->count;
98491@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98492 if (fdnum < fdmax)
98493 fdmax = fdnum;
98494
98495- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
98496+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
98497 i++, cmfptr++)
98498 {
98499 struct socket *sock;
98500diff --git a/net/core/skbuff.c b/net/core/skbuff.c
98501index 8383b2b..6397efb 100644
98502--- a/net/core/skbuff.c
98503+++ b/net/core/skbuff.c
98504@@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
98505 __wsum skb_checksum(const struct sk_buff *skb, int offset,
98506 int len, __wsum csum)
98507 {
98508- const struct skb_checksum_ops ops = {
98509+ static const struct skb_checksum_ops ops = {
98510 .update = csum_partial_ext,
98511 .combine = csum_block_add_ext,
98512 };
98513@@ -3220,13 +3220,15 @@ void __init skb_init(void)
98514 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
98515 sizeof(struct sk_buff),
98516 0,
98517- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98518+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98519+ SLAB_NO_SANITIZE,
98520 NULL);
98521 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
98522 (2*sizeof(struct sk_buff)) +
98523 sizeof(atomic_t),
98524 0,
98525- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98526+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98527+ SLAB_NO_SANITIZE,
98528 NULL);
98529 }
98530
98531diff --git a/net/core/sock.c b/net/core/sock.c
98532index 664ee42..aaf9e6e 100644
98533--- a/net/core/sock.c
98534+++ b/net/core/sock.c
98535@@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98536 struct sk_buff_head *list = &sk->sk_receive_queue;
98537
98538 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
98539- atomic_inc(&sk->sk_drops);
98540+ atomic_inc_unchecked(&sk->sk_drops);
98541 trace_sock_rcvqueue_full(sk, skb);
98542 return -ENOMEM;
98543 }
98544@@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98545 return err;
98546
98547 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
98548- atomic_inc(&sk->sk_drops);
98549+ atomic_inc_unchecked(&sk->sk_drops);
98550 return -ENOBUFS;
98551 }
98552
98553@@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98554 skb_dst_force(skb);
98555
98556 spin_lock_irqsave(&list->lock, flags);
98557- skb->dropcount = atomic_read(&sk->sk_drops);
98558+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
98559 __skb_queue_tail(list, skb);
98560 spin_unlock_irqrestore(&list->lock, flags);
98561
98562@@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98563 skb->dev = NULL;
98564
98565 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
98566- atomic_inc(&sk->sk_drops);
98567+ atomic_inc_unchecked(&sk->sk_drops);
98568 goto discard_and_relse;
98569 }
98570 if (nested)
98571@@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98572 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
98573 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
98574 bh_unlock_sock(sk);
98575- atomic_inc(&sk->sk_drops);
98576+ atomic_inc_unchecked(&sk->sk_drops);
98577 goto discard_and_relse;
98578 }
98579
98580@@ -998,12 +998,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98581 struct timeval tm;
98582 } v;
98583
98584- int lv = sizeof(int);
98585- int len;
98586+ unsigned int lv = sizeof(int);
98587+ unsigned int len;
98588
98589 if (get_user(len, optlen))
98590 return -EFAULT;
98591- if (len < 0)
98592+ if (len > INT_MAX)
98593 return -EINVAL;
98594
98595 memset(&v, 0, sizeof(v));
98596@@ -1155,11 +1155,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98597
98598 case SO_PEERNAME:
98599 {
98600- char address[128];
98601+ char address[_K_SS_MAXSIZE];
98602
98603 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
98604 return -ENOTCONN;
98605- if (lv < len)
98606+ if (lv < len || sizeof address < len)
98607 return -EINVAL;
98608 if (copy_to_user(optval, address, len))
98609 return -EFAULT;
98610@@ -1240,7 +1240,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98611
98612 if (len > lv)
98613 len = lv;
98614- if (copy_to_user(optval, &v, len))
98615+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
98616 return -EFAULT;
98617 lenout:
98618 if (put_user(len, optlen))
98619@@ -2375,7 +2375,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
98620 */
98621 smp_wmb();
98622 atomic_set(&sk->sk_refcnt, 1);
98623- atomic_set(&sk->sk_drops, 0);
98624+ atomic_set_unchecked(&sk->sk_drops, 0);
98625 }
98626 EXPORT_SYMBOL(sock_init_data);
98627
98628@@ -2503,6 +2503,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
98629 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98630 int level, int type)
98631 {
98632+ struct sock_extended_err ee;
98633 struct sock_exterr_skb *serr;
98634 struct sk_buff *skb, *skb2;
98635 int copied, err;
98636@@ -2524,7 +2525,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98637 sock_recv_timestamp(msg, sk, skb);
98638
98639 serr = SKB_EXT_ERR(skb);
98640- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
98641+ ee = serr->ee;
98642+ put_cmsg(msg, level, type, sizeof ee, &ee);
98643
98644 msg->msg_flags |= MSG_ERRQUEUE;
98645 err = copied;
98646diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
98647index a4216a4..1c07687 100644
98648--- a/net/core/sock_diag.c
98649+++ b/net/core/sock_diag.c
98650@@ -9,26 +9,33 @@
98651 #include <linux/inet_diag.h>
98652 #include <linux/sock_diag.h>
98653
98654-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
98655+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
98656 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
98657 static DEFINE_MUTEX(sock_diag_table_mutex);
98658
98659 int sock_diag_check_cookie(void *sk, __u32 *cookie)
98660 {
98661+#ifndef CONFIG_GRKERNSEC_HIDESYM
98662 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
98663 cookie[1] != INET_DIAG_NOCOOKIE) &&
98664 ((u32)(unsigned long)sk != cookie[0] ||
98665 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
98666 return -ESTALE;
98667 else
98668+#endif
98669 return 0;
98670 }
98671 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
98672
98673 void sock_diag_save_cookie(void *sk, __u32 *cookie)
98674 {
98675+#ifdef CONFIG_GRKERNSEC_HIDESYM
98676+ cookie[0] = 0;
98677+ cookie[1] = 0;
98678+#else
98679 cookie[0] = (u32)(unsigned long)sk;
98680 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
98681+#endif
98682 }
98683 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
98684
98685@@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
98686 mutex_lock(&sock_diag_table_mutex);
98687 if (sock_diag_handlers[hndl->family])
98688 err = -EBUSY;
98689- else
98690+ else {
98691+ pax_open_kernel();
98692 sock_diag_handlers[hndl->family] = hndl;
98693+ pax_close_kernel();
98694+ }
98695 mutex_unlock(&sock_diag_table_mutex);
98696
98697 return err;
98698@@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
98699
98700 mutex_lock(&sock_diag_table_mutex);
98701 BUG_ON(sock_diag_handlers[family] != hnld);
98702+ pax_open_kernel();
98703 sock_diag_handlers[family] = NULL;
98704+ pax_close_kernel();
98705 mutex_unlock(&sock_diag_table_mutex);
98706 }
98707 EXPORT_SYMBOL_GPL(sock_diag_unregister);
98708diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
98709index cf9cd13..8b56af3 100644
98710--- a/net/core/sysctl_net_core.c
98711+++ b/net/core/sysctl_net_core.c
98712@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
98713 {
98714 unsigned int orig_size, size;
98715 int ret, i;
98716- struct ctl_table tmp = {
98717+ ctl_table_no_const tmp = {
98718 .data = &size,
98719 .maxlen = sizeof(size),
98720 .mode = table->mode
98721@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
98722 void __user *buffer, size_t *lenp, loff_t *ppos)
98723 {
98724 char id[IFNAMSIZ];
98725- struct ctl_table tbl = {
98726+ ctl_table_no_const tbl = {
98727 .data = id,
98728 .maxlen = IFNAMSIZ,
98729 };
98730@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
98731
98732 static __net_init int sysctl_core_net_init(struct net *net)
98733 {
98734- struct ctl_table *tbl;
98735+ ctl_table_no_const *tbl = NULL;
98736
98737 net->core.sysctl_somaxconn = SOMAXCONN;
98738
98739- tbl = netns_core_table;
98740 if (!net_eq(net, &init_net)) {
98741- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
98742+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
98743 if (tbl == NULL)
98744 goto err_dup;
98745
98746@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
98747 if (net->user_ns != &init_user_ns) {
98748 tbl[0].procname = NULL;
98749 }
98750- }
98751-
98752- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98753+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98754+ } else
98755+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
98756 if (net->core.sysctl_hdr == NULL)
98757 goto err_reg;
98758
98759 return 0;
98760
98761 err_reg:
98762- if (tbl != netns_core_table)
98763- kfree(tbl);
98764+ kfree(tbl);
98765 err_dup:
98766 return -ENOMEM;
98767 }
98768@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
98769 kfree(tbl);
98770 }
98771
98772-static __net_initdata struct pernet_operations sysctl_core_ops = {
98773+static __net_initconst struct pernet_operations sysctl_core_ops = {
98774 .init = sysctl_core_net_init,
98775 .exit = sysctl_core_net_exit,
98776 };
98777diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
98778index 4c04848..f575934 100644
98779--- a/net/decnet/af_decnet.c
98780+++ b/net/decnet/af_decnet.c
98781@@ -465,6 +465,7 @@ static struct proto dn_proto = {
98782 .sysctl_rmem = sysctl_decnet_rmem,
98783 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
98784 .obj_size = sizeof(struct dn_sock),
98785+ .slab_flags = SLAB_USERCOPY,
98786 };
98787
98788 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
98789diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
98790index 3b726f3..1af6368 100644
98791--- a/net/decnet/dn_dev.c
98792+++ b/net/decnet/dn_dev.c
98793@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
98794 .extra1 = &min_t3,
98795 .extra2 = &max_t3
98796 },
98797- {0}
98798+ { }
98799 },
98800 };
98801
98802diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
98803index 5325b54..a0d4d69 100644
98804--- a/net/decnet/sysctl_net_decnet.c
98805+++ b/net/decnet/sysctl_net_decnet.c
98806@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
98807
98808 if (len > *lenp) len = *lenp;
98809
98810- if (copy_to_user(buffer, addr, len))
98811+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
98812 return -EFAULT;
98813
98814 *lenp = len;
98815@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
98816
98817 if (len > *lenp) len = *lenp;
98818
98819- if (copy_to_user(buffer, devname, len))
98820+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
98821 return -EFAULT;
98822
98823 *lenp = len;
98824diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
98825index ef2d543..5b9b73f 100644
98826--- a/net/ieee802154/reassembly.c
98827+++ b/net/ieee802154/reassembly.c
98828@@ -434,12 +434,11 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
98829
98830 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
98831 {
98832- struct ctl_table *table;
98833+ ctl_table_no_const *table = NULL;
98834 struct ctl_table_header *hdr;
98835
98836- table = lowpan_frags_ns_ctl_table;
98837 if (!net_eq(net, &init_net)) {
98838- table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
98839+ table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
98840 GFP_KERNEL);
98841 if (table == NULL)
98842 goto err_alloc;
98843@@ -452,9 +451,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
98844 /* Don't export sysctls to unprivileged users */
98845 if (net->user_ns != &init_user_ns)
98846 table[0].procname = NULL;
98847- }
98848-
98849- hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
98850+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
98851+ } else
98852+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
98853 if (hdr == NULL)
98854 goto err_reg;
98855
98856@@ -462,8 +461,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
98857 return 0;
98858
98859 err_reg:
98860- if (!net_eq(net, &init_net))
98861- kfree(table);
98862+ kfree(table);
98863 err_alloc:
98864 return -ENOMEM;
98865 }
98866diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
98867index 6d6dd34..e5c9bec 100644
98868--- a/net/ipv4/af_inet.c
98869+++ b/net/ipv4/af_inet.c
98870@@ -1736,13 +1736,9 @@ static int __init inet_init(void)
98871
98872 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
98873
98874- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
98875- if (!sysctl_local_reserved_ports)
98876- goto out;
98877-
98878 rc = proto_register(&tcp_prot, 1);
98879 if (rc)
98880- goto out_free_reserved_ports;
98881+ goto out;
98882
98883 rc = proto_register(&udp_prot, 1);
98884 if (rc)
98885@@ -1852,8 +1848,6 @@ out_unregister_udp_proto:
98886 proto_unregister(&udp_prot);
98887 out_unregister_tcp_proto:
98888 proto_unregister(&tcp_prot);
98889-out_free_reserved_ports:
98890- kfree(sysctl_local_reserved_ports);
98891 goto out;
98892 }
98893
98894diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
98895index bdbf68b..deb4759 100644
98896--- a/net/ipv4/devinet.c
98897+++ b/net/ipv4/devinet.c
98898@@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
98899 idx = 0;
98900 head = &net->dev_index_head[h];
98901 rcu_read_lock();
98902- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98903+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98904 net->dev_base_seq;
98905 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98906 if (idx < s_idx)
98907@@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
98908 idx = 0;
98909 head = &net->dev_index_head[h];
98910 rcu_read_lock();
98911- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98912+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98913 net->dev_base_seq;
98914 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98915 if (idx < s_idx)
98916@@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
98917 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
98918 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
98919
98920-static struct devinet_sysctl_table {
98921+static const struct devinet_sysctl_table {
98922 struct ctl_table_header *sysctl_header;
98923 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
98924 } devinet_sysctl = {
98925@@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
98926 int err;
98927 struct ipv4_devconf *all, *dflt;
98928 #ifdef CONFIG_SYSCTL
98929- struct ctl_table *tbl = ctl_forward_entry;
98930+ ctl_table_no_const *tbl = NULL;
98931 struct ctl_table_header *forw_hdr;
98932 #endif
98933
98934@@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
98935 goto err_alloc_dflt;
98936
98937 #ifdef CONFIG_SYSCTL
98938- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
98939+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
98940 if (tbl == NULL)
98941 goto err_alloc_ctl;
98942
98943@@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
98944 goto err_reg_dflt;
98945
98946 err = -ENOMEM;
98947- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98948+ if (!net_eq(net, &init_net))
98949+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
98950+ else
98951+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
98952 if (forw_hdr == NULL)
98953 goto err_reg_ctl;
98954 net->ipv4.forw_hdr = forw_hdr;
98955@@ -2272,8 +2275,7 @@ err_reg_ctl:
98956 err_reg_dflt:
98957 __devinet_sysctl_unregister(all);
98958 err_reg_all:
98959- if (tbl != ctl_forward_entry)
98960- kfree(tbl);
98961+ kfree(tbl);
98962 err_alloc_ctl:
98963 #endif
98964 if (dflt != &ipv4_devconf_dflt)
98965diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
98966index 255aa99..45c78f8 100644
98967--- a/net/ipv4/fib_frontend.c
98968+++ b/net/ipv4/fib_frontend.c
98969@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
98970 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98971 fib_sync_up(dev);
98972 #endif
98973- atomic_inc(&net->ipv4.dev_addr_genid);
98974+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98975 rt_cache_flush(dev_net(dev));
98976 break;
98977 case NETDEV_DOWN:
98978 fib_del_ifaddr(ifa, NULL);
98979- atomic_inc(&net->ipv4.dev_addr_genid);
98980+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98981 if (ifa->ifa_dev->ifa_list == NULL) {
98982 /* Last address was deleted from this interface.
98983 * Disable IP.
98984@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
98985 #ifdef CONFIG_IP_ROUTE_MULTIPATH
98986 fib_sync_up(dev);
98987 #endif
98988- atomic_inc(&net->ipv4.dev_addr_genid);
98989+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
98990 rt_cache_flush(net);
98991 break;
98992 case NETDEV_DOWN:
98993diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
98994index b10cd43a..22327f9 100644
98995--- a/net/ipv4/fib_semantics.c
98996+++ b/net/ipv4/fib_semantics.c
98997@@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
98998 nh->nh_saddr = inet_select_addr(nh->nh_dev,
98999 nh->nh_gw,
99000 nh->nh_parent->fib_scope);
99001- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
99002+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
99003
99004 return nh->nh_saddr;
99005 }
99006diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
99007index a56b8e6..5be2a30 100644
99008--- a/net/ipv4/inet_connection_sock.c
99009+++ b/net/ipv4/inet_connection_sock.c
99010@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
99011 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
99012 #endif
99013
99014-unsigned long *sysctl_local_reserved_ports;
99015+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
99016 EXPORT_SYMBOL(sysctl_local_reserved_ports);
99017
99018 void inet_get_local_port_range(struct net *net, int *low, int *high)
99019diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
99020index 8b9cf27..0d8d592 100644
99021--- a/net/ipv4/inet_hashtables.c
99022+++ b/net/ipv4/inet_hashtables.c
99023@@ -18,6 +18,7 @@
99024 #include <linux/sched.h>
99025 #include <linux/slab.h>
99026 #include <linux/wait.h>
99027+#include <linux/security.h>
99028
99029 #include <net/inet_connection_sock.h>
99030 #include <net/inet_hashtables.h>
99031@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
99032 return inet_ehashfn(net, laddr, lport, faddr, fport);
99033 }
99034
99035+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
99036+
99037 /*
99038 * Allocate and initialize a new local port bind bucket.
99039 * The bindhash mutex for snum's hash chain must be held here.
99040@@ -554,6 +557,8 @@ ok:
99041 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
99042 spin_unlock(&head->lock);
99043
99044+ gr_update_task_in_ip_table(current, inet_sk(sk));
99045+
99046 if (tw) {
99047 inet_twsk_deschedule(tw, death_row);
99048 while (twrefcnt) {
99049diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
99050index 48f4244..f56d83a 100644
99051--- a/net/ipv4/inetpeer.c
99052+++ b/net/ipv4/inetpeer.c
99053@@ -496,8 +496,8 @@ relookup:
99054 if (p) {
99055 p->daddr = *daddr;
99056 atomic_set(&p->refcnt, 1);
99057- atomic_set(&p->rid, 0);
99058- atomic_set(&p->ip_id_count,
99059+ atomic_set_unchecked(&p->rid, 0);
99060+ atomic_set_unchecked(&p->ip_id_count,
99061 (daddr->family == AF_INET) ?
99062 secure_ip_id(daddr->addr.a4) :
99063 secure_ipv6_id(daddr->addr.a6));
99064diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
99065index ed32313..3762abe 100644
99066--- a/net/ipv4/ip_fragment.c
99067+++ b/net/ipv4/ip_fragment.c
99068@@ -284,7 +284,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
99069 return 0;
99070
99071 start = qp->rid;
99072- end = atomic_inc_return(&peer->rid);
99073+ end = atomic_inc_return_unchecked(&peer->rid);
99074 qp->rid = end;
99075
99076 rc = qp->q.fragments && (end - start) > max;
99077@@ -761,12 +761,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
99078
99079 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99080 {
99081- struct ctl_table *table;
99082+ ctl_table_no_const *table = NULL;
99083 struct ctl_table_header *hdr;
99084
99085- table = ip4_frags_ns_ctl_table;
99086 if (!net_eq(net, &init_net)) {
99087- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99088+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99089 if (table == NULL)
99090 goto err_alloc;
99091
99092@@ -777,9 +776,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99093 /* Don't export sysctls to unprivileged users */
99094 if (net->user_ns != &init_user_ns)
99095 table[0].procname = NULL;
99096- }
99097+ hdr = register_net_sysctl(net, "net/ipv4", table);
99098+ } else
99099+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
99100
99101- hdr = register_net_sysctl(net, "net/ipv4", table);
99102 if (hdr == NULL)
99103 goto err_reg;
99104
99105@@ -787,8 +787,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99106 return 0;
99107
99108 err_reg:
99109- if (!net_eq(net, &init_net))
99110- kfree(table);
99111+ kfree(table);
99112 err_alloc:
99113 return -ENOMEM;
99114 }
99115diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
99116index 94213c8..8bdb342 100644
99117--- a/net/ipv4/ip_gre.c
99118+++ b/net/ipv4/ip_gre.c
99119@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
99120 module_param(log_ecn_error, bool, 0644);
99121 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99122
99123-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
99124+static struct rtnl_link_ops ipgre_link_ops;
99125 static int ipgre_tunnel_init(struct net_device *dev);
99126
99127 static int ipgre_net_id __read_mostly;
99128@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
99129 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
99130 };
99131
99132-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99133+static struct rtnl_link_ops ipgre_link_ops = {
99134 .kind = "gre",
99135 .maxtype = IFLA_GRE_MAX,
99136 .policy = ipgre_policy,
99137@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99138 .fill_info = ipgre_fill_info,
99139 };
99140
99141-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
99142+static struct rtnl_link_ops ipgre_tap_ops = {
99143 .kind = "gretap",
99144 .maxtype = IFLA_GRE_MAX,
99145 .policy = ipgre_policy,
99146diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
99147index 64741b9..6f334a2 100644
99148--- a/net/ipv4/ip_sockglue.c
99149+++ b/net/ipv4/ip_sockglue.c
99150@@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99151 len = min_t(unsigned int, len, opt->optlen);
99152 if (put_user(len, optlen))
99153 return -EFAULT;
99154- if (copy_to_user(optval, opt->__data, len))
99155+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
99156+ copy_to_user(optval, opt->__data, len))
99157 return -EFAULT;
99158 return 0;
99159 }
99160@@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99161 if (sk->sk_type != SOCK_STREAM)
99162 return -ENOPROTOOPT;
99163
99164- msg.msg_control = optval;
99165+ msg.msg_control = (void __force_kernel *)optval;
99166 msg.msg_controllen = len;
99167 msg.msg_flags = flags;
99168
99169diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
99170index 2acc233..b93143f 100644
99171--- a/net/ipv4/ip_tunnel.c
99172+++ b/net/ipv4/ip_tunnel.c
99173@@ -73,12 +73,7 @@ static void __tunnel_dst_set(struct ip_tunnel_dst *idst,
99174 {
99175 struct dst_entry *old_dst;
99176
99177- if (dst) {
99178- if (dst->flags & DST_NOCACHE)
99179- dst = NULL;
99180- else
99181- dst_clone(dst);
99182- }
99183+ dst_clone(dst);
99184 old_dst = xchg((__force struct dst_entry **)&idst->dst, dst);
99185 dst_release(old_dst);
99186 }
99187@@ -108,13 +103,14 @@ static struct rtable *tunnel_rtable_get(struct ip_tunnel *t, u32 cookie)
99188
99189 rcu_read_lock();
99190 dst = rcu_dereference(this_cpu_ptr(t->dst_cache)->dst);
99191+ if (dst && !atomic_inc_not_zero(&dst->__refcnt))
99192+ dst = NULL;
99193 if (dst) {
99194 if (dst->obsolete && dst->ops->check(dst, cookie) == NULL) {
99195- rcu_read_unlock();
99196 tunnel_dst_reset(t);
99197- return NULL;
99198+ dst_release(dst);
99199+ dst = NULL;
99200 }
99201- dst_hold(dst);
99202 }
99203 rcu_read_unlock();
99204 return (struct rtable *)dst;
99205diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
99206index 13ef00f..8ffca25 100644
99207--- a/net/ipv4/ip_vti.c
99208+++ b/net/ipv4/ip_vti.c
99209@@ -45,7 +45,7 @@
99210 #include <net/net_namespace.h>
99211 #include <net/netns/generic.h>
99212
99213-static struct rtnl_link_ops vti_link_ops __read_mostly;
99214+static struct rtnl_link_ops vti_link_ops;
99215
99216 static int vti_net_id __read_mostly;
99217 static int vti_tunnel_init(struct net_device *dev);
99218@@ -513,7 +513,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
99219 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
99220 };
99221
99222-static struct rtnl_link_ops vti_link_ops __read_mostly = {
99223+static struct rtnl_link_ops vti_link_ops = {
99224 .kind = "vti",
99225 .maxtype = IFLA_VTI_MAX,
99226 .policy = vti_policy,
99227diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
99228index b3e86ea..18ce98c 100644
99229--- a/net/ipv4/ipconfig.c
99230+++ b/net/ipv4/ipconfig.c
99231@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
99232
99233 mm_segment_t oldfs = get_fs();
99234 set_fs(get_ds());
99235- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99236+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99237 set_fs(oldfs);
99238 return res;
99239 }
99240@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
99241
99242 mm_segment_t oldfs = get_fs();
99243 set_fs(get_ds());
99244- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99245+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99246 set_fs(oldfs);
99247 return res;
99248 }
99249@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
99250
99251 mm_segment_t oldfs = get_fs();
99252 set_fs(get_ds());
99253- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
99254+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99255 set_fs(oldfs);
99256 return res;
99257 }
99258diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99259index 62eaa00..29b2dc2 100644
99260--- a/net/ipv4/ipip.c
99261+++ b/net/ipv4/ipip.c
99262@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99263 static int ipip_net_id __read_mostly;
99264
99265 static int ipip_tunnel_init(struct net_device *dev);
99266-static struct rtnl_link_ops ipip_link_ops __read_mostly;
99267+static struct rtnl_link_ops ipip_link_ops;
99268
99269 static int ipip_err(struct sk_buff *skb, u32 info)
99270 {
99271@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99272 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99273 };
99274
99275-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99276+static struct rtnl_link_ops ipip_link_ops = {
99277 .kind = "ipip",
99278 .maxtype = IFLA_IPTUN_MAX,
99279 .policy = ipip_policy,
99280diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99281index f95b6f9..2ee2097 100644
99282--- a/net/ipv4/netfilter/arp_tables.c
99283+++ b/net/ipv4/netfilter/arp_tables.c
99284@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99285 #endif
99286
99287 static int get_info(struct net *net, void __user *user,
99288- const int *len, int compat)
99289+ int len, int compat)
99290 {
99291 char name[XT_TABLE_MAXNAMELEN];
99292 struct xt_table *t;
99293 int ret;
99294
99295- if (*len != sizeof(struct arpt_getinfo)) {
99296- duprintf("length %u != %Zu\n", *len,
99297+ if (len != sizeof(struct arpt_getinfo)) {
99298+ duprintf("length %u != %Zu\n", len,
99299 sizeof(struct arpt_getinfo));
99300 return -EINVAL;
99301 }
99302@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99303 info.size = private->size;
99304 strcpy(info.name, name);
99305
99306- if (copy_to_user(user, &info, *len) != 0)
99307+ if (copy_to_user(user, &info, len) != 0)
99308 ret = -EFAULT;
99309 else
99310 ret = 0;
99311@@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99312
99313 switch (cmd) {
99314 case ARPT_SO_GET_INFO:
99315- ret = get_info(sock_net(sk), user, len, 1);
99316+ ret = get_info(sock_net(sk), user, *len, 1);
99317 break;
99318 case ARPT_SO_GET_ENTRIES:
99319 ret = compat_get_entries(sock_net(sk), user, len);
99320@@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99321
99322 switch (cmd) {
99323 case ARPT_SO_GET_INFO:
99324- ret = get_info(sock_net(sk), user, len, 0);
99325+ ret = get_info(sock_net(sk), user, *len, 0);
99326 break;
99327
99328 case ARPT_SO_GET_ENTRIES:
99329diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99330index 99e810f..3711b81 100644
99331--- a/net/ipv4/netfilter/ip_tables.c
99332+++ b/net/ipv4/netfilter/ip_tables.c
99333@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99334 #endif
99335
99336 static int get_info(struct net *net, void __user *user,
99337- const int *len, int compat)
99338+ int len, int compat)
99339 {
99340 char name[XT_TABLE_MAXNAMELEN];
99341 struct xt_table *t;
99342 int ret;
99343
99344- if (*len != sizeof(struct ipt_getinfo)) {
99345- duprintf("length %u != %zu\n", *len,
99346+ if (len != sizeof(struct ipt_getinfo)) {
99347+ duprintf("length %u != %zu\n", len,
99348 sizeof(struct ipt_getinfo));
99349 return -EINVAL;
99350 }
99351@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99352 info.size = private->size;
99353 strcpy(info.name, name);
99354
99355- if (copy_to_user(user, &info, *len) != 0)
99356+ if (copy_to_user(user, &info, len) != 0)
99357 ret = -EFAULT;
99358 else
99359 ret = 0;
99360@@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99361
99362 switch (cmd) {
99363 case IPT_SO_GET_INFO:
99364- ret = get_info(sock_net(sk), user, len, 1);
99365+ ret = get_info(sock_net(sk), user, *len, 1);
99366 break;
99367 case IPT_SO_GET_ENTRIES:
99368 ret = compat_get_entries(sock_net(sk), user, len);
99369@@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99370
99371 switch (cmd) {
99372 case IPT_SO_GET_INFO:
99373- ret = get_info(sock_net(sk), user, len, 0);
99374+ ret = get_info(sock_net(sk), user, *len, 0);
99375 break;
99376
99377 case IPT_SO_GET_ENTRIES:
99378diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99379index 2510c02..cfb34fa 100644
99380--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
99381+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99382@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
99383 spin_lock_init(&cn->lock);
99384
99385 #ifdef CONFIG_PROC_FS
99386- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
99387+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
99388 if (!cn->procdir) {
99389 pr_err("Unable to proc dir entry\n");
99390 return -ENOMEM;
99391diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
99392index 044a0dd..e0c1971 100644
99393--- a/net/ipv4/ping.c
99394+++ b/net/ipv4/ping.c
99395@@ -59,7 +59,7 @@ struct ping_table {
99396 };
99397
99398 static struct ping_table ping_table;
99399-struct pingv6_ops pingv6_ops;
99400+struct pingv6_ops *pingv6_ops;
99401 EXPORT_SYMBOL_GPL(pingv6_ops);
99402
99403 static u16 ping_port_rover;
99404@@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
99405 return -ENODEV;
99406 }
99407 }
99408- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
99409+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
99410 scoped);
99411 rcu_read_unlock();
99412
99413@@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99414 }
99415 #if IS_ENABLED(CONFIG_IPV6)
99416 } else if (skb->protocol == htons(ETH_P_IPV6)) {
99417- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
99418+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
99419 #endif
99420 }
99421
99422@@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99423 info, (u8 *)icmph);
99424 #if IS_ENABLED(CONFIG_IPV6)
99425 } else if (family == AF_INET6) {
99426- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
99427+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
99428 info, (u8 *)icmph);
99429 #endif
99430 }
99431@@ -844,6 +844,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99432 {
99433 struct inet_sock *isk = inet_sk(sk);
99434 int family = sk->sk_family;
99435+ struct sockaddr_in *sin;
99436+ struct sockaddr_in6 *sin6;
99437 struct sk_buff *skb;
99438 int copied, err;
99439
99440@@ -853,12 +855,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99441 if (flags & MSG_OOB)
99442 goto out;
99443
99444+ if (addr_len) {
99445+ if (family == AF_INET)
99446+ *addr_len = sizeof(*sin);
99447+ else if (family == AF_INET6 && addr_len)
99448+ *addr_len = sizeof(*sin6);
99449+ }
99450+
99451 if (flags & MSG_ERRQUEUE) {
99452 if (family == AF_INET) {
99453 return ip_recv_error(sk, msg, len, addr_len);
99454 #if IS_ENABLED(CONFIG_IPV6)
99455 } else if (family == AF_INET6) {
99456- return pingv6_ops.ipv6_recv_error(sk, msg, len,
99457+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
99458 addr_len);
99459 #endif
99460 }
99461@@ -890,7 +899,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99462 sin->sin_port = 0 /* skb->h.uh->source */;
99463 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99464 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99465- *addr_len = sizeof(*sin);
99466 }
99467
99468 if (isk->cmsg_flags)
99469@@ -912,14 +920,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99470 sin6->sin6_scope_id =
99471 ipv6_iface_scope_id(&sin6->sin6_addr,
99472 IP6CB(skb)->iif);
99473- *addr_len = sizeof(*sin6);
99474 }
99475
99476 if (inet6_sk(sk)->rxopt.all)
99477- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
99478+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
99479 if (skb->protocol == htons(ETH_P_IPV6) &&
99480 inet6_sk(sk)->rxopt.all)
99481- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
99482+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
99483 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
99484 ip_cmsg_recv(msg, skb);
99485 #endif
99486@@ -1111,7 +1118,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
99487 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99488 0, sock_i_ino(sp),
99489 atomic_read(&sp->sk_refcnt), sp,
99490- atomic_read(&sp->sk_drops));
99491+ atomic_read_unchecked(&sp->sk_drops));
99492 }
99493
99494 static int ping_v4_seq_show(struct seq_file *seq, void *v)
99495diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
99496index a9dbe58..46f577f 100644
99497--- a/net/ipv4/raw.c
99498+++ b/net/ipv4/raw.c
99499@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
99500 int raw_rcv(struct sock *sk, struct sk_buff *skb)
99501 {
99502 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
99503- atomic_inc(&sk->sk_drops);
99504+ atomic_inc_unchecked(&sk->sk_drops);
99505 kfree_skb(skb);
99506 return NET_RX_DROP;
99507 }
99508@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99509 if (flags & MSG_OOB)
99510 goto out;
99511
99512+ if (addr_len)
99513+ *addr_len = sizeof(*sin);
99514+
99515 if (flags & MSG_ERRQUEUE) {
99516 err = ip_recv_error(sk, msg, len, addr_len);
99517 goto out;
99518@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99519 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99520 sin->sin_port = 0;
99521 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99522- *addr_len = sizeof(*sin);
99523 }
99524 if (inet->cmsg_flags)
99525 ip_cmsg_recv(msg, skb);
99526@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
99527
99528 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
99529 {
99530+ struct icmp_filter filter;
99531+
99532 if (optlen > sizeof(struct icmp_filter))
99533 optlen = sizeof(struct icmp_filter);
99534- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
99535+ if (copy_from_user(&filter, optval, optlen))
99536 return -EFAULT;
99537+ raw_sk(sk)->filter = filter;
99538 return 0;
99539 }
99540
99541 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
99542 {
99543 int len, ret = -EFAULT;
99544+ struct icmp_filter filter;
99545
99546 if (get_user(len, optlen))
99547 goto out;
99548@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
99549 if (len > sizeof(struct icmp_filter))
99550 len = sizeof(struct icmp_filter);
99551 ret = -EFAULT;
99552- if (put_user(len, optlen) ||
99553- copy_to_user(optval, &raw_sk(sk)->filter, len))
99554+ filter = raw_sk(sk)->filter;
99555+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
99556 goto out;
99557 ret = 0;
99558 out: return ret;
99559@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
99560 0, 0L, 0,
99561 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
99562 0, sock_i_ino(sp),
99563- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
99564+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
99565 }
99566
99567 static int raw_seq_show(struct seq_file *seq, void *v)
99568diff --git a/net/ipv4/route.c b/net/ipv4/route.c
99569index 5e676be..f6c62f1 100644
99570--- a/net/ipv4/route.c
99571+++ b/net/ipv4/route.c
99572@@ -227,7 +227,7 @@ static const struct seq_operations rt_cache_seq_ops = {
99573
99574 static int rt_cache_seq_open(struct inode *inode, struct file *file)
99575 {
99576- return seq_open(file, &rt_cache_seq_ops);
99577+ return seq_open_restrict(file, &rt_cache_seq_ops);
99578 }
99579
99580 static const struct file_operations rt_cache_seq_fops = {
99581@@ -318,7 +318,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
99582
99583 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
99584 {
99585- return seq_open(file, &rt_cpu_seq_ops);
99586+ return seq_open_restrict(file, &rt_cpu_seq_ops);
99587 }
99588
99589 static const struct file_operations rt_cpu_seq_fops = {
99590@@ -356,7 +356,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
99591
99592 static int rt_acct_proc_open(struct inode *inode, struct file *file)
99593 {
99594- return single_open(file, rt_acct_proc_show, NULL);
99595+ return single_open_restrict(file, rt_acct_proc_show, NULL);
99596 }
99597
99598 static const struct file_operations rt_acct_proc_fops = {
99599@@ -2610,34 +2610,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
99600 .maxlen = sizeof(int),
99601 .mode = 0200,
99602 .proc_handler = ipv4_sysctl_rtcache_flush,
99603+ .extra1 = &init_net,
99604 },
99605 { },
99606 };
99607
99608 static __net_init int sysctl_route_net_init(struct net *net)
99609 {
99610- struct ctl_table *tbl;
99611+ ctl_table_no_const *tbl = NULL;
99612
99613- tbl = ipv4_route_flush_table;
99614 if (!net_eq(net, &init_net)) {
99615- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99616+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99617 if (tbl == NULL)
99618 goto err_dup;
99619
99620 /* Don't export sysctls to unprivileged users */
99621 if (net->user_ns != &init_user_ns)
99622 tbl[0].procname = NULL;
99623- }
99624- tbl[0].extra1 = net;
99625+ tbl[0].extra1 = net;
99626+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99627+ } else
99628+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
99629
99630- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99631 if (net->ipv4.route_hdr == NULL)
99632 goto err_reg;
99633 return 0;
99634
99635 err_reg:
99636- if (tbl != ipv4_route_flush_table)
99637- kfree(tbl);
99638+ kfree(tbl);
99639 err_dup:
99640 return -ENOMEM;
99641 }
99642@@ -2660,8 +2660,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
99643
99644 static __net_init int rt_genid_init(struct net *net)
99645 {
99646- atomic_set(&net->ipv4.rt_genid, 0);
99647- atomic_set(&net->fnhe_genid, 0);
99648+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
99649+ atomic_set_unchecked(&net->fnhe_genid, 0);
99650 get_random_bytes(&net->ipv4.dev_addr_genid,
99651 sizeof(net->ipv4.dev_addr_genid));
99652 return 0;
99653diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
99654index 5cde8f2..5f5684e 100644
99655--- a/net/ipv4/sysctl_net_ipv4.c
99656+++ b/net/ipv4/sysctl_net_ipv4.c
99657@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
99658 container_of(table->data, struct net, ipv4.ip_local_ports.range);
99659 int ret;
99660 int range[2];
99661- struct ctl_table tmp = {
99662+ ctl_table_no_const tmp = {
99663 .data = &range,
99664 .maxlen = sizeof(range),
99665 .mode = table->mode,
99666@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
99667 int ret;
99668 gid_t urange[2];
99669 kgid_t low, high;
99670- struct ctl_table tmp = {
99671+ ctl_table_no_const tmp = {
99672 .data = &urange,
99673 .maxlen = sizeof(urange),
99674 .mode = table->mode,
99675@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
99676 void __user *buffer, size_t *lenp, loff_t *ppos)
99677 {
99678 char val[TCP_CA_NAME_MAX];
99679- struct ctl_table tbl = {
99680+ ctl_table_no_const tbl = {
99681 .data = val,
99682 .maxlen = TCP_CA_NAME_MAX,
99683 };
99684@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
99685 void __user *buffer, size_t *lenp,
99686 loff_t *ppos)
99687 {
99688- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
99689+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
99690 int ret;
99691
99692 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99693@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
99694 void __user *buffer, size_t *lenp,
99695 loff_t *ppos)
99696 {
99697- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
99698+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
99699 int ret;
99700
99701 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99702@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
99703 void __user *buffer, size_t *lenp,
99704 loff_t *ppos)
99705 {
99706- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99707+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99708 struct tcp_fastopen_context *ctxt;
99709 int ret;
99710 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
99711@@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
99712 },
99713 {
99714 .procname = "ip_local_reserved_ports",
99715- .data = NULL, /* initialized in sysctl_ipv4_init */
99716+ .data = sysctl_local_reserved_ports,
99717 .maxlen = 65536,
99718 .mode = 0644,
99719 .proc_handler = proc_do_large_bitmap,
99720@@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
99721
99722 static __net_init int ipv4_sysctl_init_net(struct net *net)
99723 {
99724- struct ctl_table *table;
99725+ ctl_table_no_const *table = NULL;
99726
99727- table = ipv4_net_table;
99728 if (!net_eq(net, &init_net)) {
99729 int i;
99730
99731- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
99732+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
99733 if (table == NULL)
99734 goto err_alloc;
99735
99736@@ -858,15 +857,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
99737 table[i].data += (void *)net - (void *)&init_net;
99738 }
99739
99740- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99741+ if (!net_eq(net, &init_net))
99742+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99743+ else
99744+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
99745 if (net->ipv4.ipv4_hdr == NULL)
99746 goto err_reg;
99747
99748 return 0;
99749
99750 err_reg:
99751- if (!net_eq(net, &init_net))
99752- kfree(table);
99753+ kfree(table);
99754 err_alloc:
99755 return -ENOMEM;
99756 }
99757@@ -888,16 +889,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
99758 static __init int sysctl_ipv4_init(void)
99759 {
99760 struct ctl_table_header *hdr;
99761- struct ctl_table *i;
99762-
99763- for (i = ipv4_table; i->procname; i++) {
99764- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
99765- i->data = sysctl_local_reserved_ports;
99766- break;
99767- }
99768- }
99769- if (!i->procname)
99770- return -EINVAL;
99771
99772 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
99773 if (hdr == NULL)
99774diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
99775index 3a26b3b..8bbe4ae 100644
99776--- a/net/ipv4/tcp_input.c
99777+++ b/net/ipv4/tcp_input.c
99778@@ -754,7 +754,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
99779 * without any lock. We want to make sure compiler wont store
99780 * intermediate values in this location.
99781 */
99782- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
99783+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
99784 sk->sk_max_pacing_rate);
99785 }
99786
99787@@ -4478,7 +4478,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
99788 * simplifies code)
99789 */
99790 static void
99791-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99792+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99793 struct sk_buff *head, struct sk_buff *tail,
99794 u32 start, u32 end)
99795 {
99796@@ -5558,6 +5558,7 @@ discard:
99797 tcp_paws_reject(&tp->rx_opt, 0))
99798 goto discard_and_undo;
99799
99800+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
99801 if (th->syn) {
99802 /* We see SYN without ACK. It is attempt of
99803 * simultaneous connect with crossed SYNs.
99804@@ -5608,6 +5609,7 @@ discard:
99805 goto discard;
99806 #endif
99807 }
99808+#endif
99809 /* "fifth, if neither of the SYN or RST bits is set then
99810 * drop the segment and return."
99811 */
99812@@ -5654,7 +5656,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
99813 goto discard;
99814
99815 if (th->syn) {
99816- if (th->fin)
99817+ if (th->fin || th->urg || th->psh)
99818 goto discard;
99819 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
99820 return 1;
99821diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
99822index 438f3b9..bc9e1ad 100644
99823--- a/net/ipv4/tcp_ipv4.c
99824+++ b/net/ipv4/tcp_ipv4.c
99825@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
99826 EXPORT_SYMBOL(sysctl_tcp_low_latency);
99827
99828
99829+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99830+extern int grsec_enable_blackhole;
99831+#endif
99832+
99833 #ifdef CONFIG_TCP_MD5SIG
99834 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
99835 __be32 daddr, __be32 saddr, const struct tcphdr *th);
99836@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
99837 return 0;
99838
99839 reset:
99840+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99841+ if (!grsec_enable_blackhole)
99842+#endif
99843 tcp_v4_send_reset(rsk, skb);
99844 discard:
99845 kfree_skb(skb);
99846@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
99847 TCP_SKB_CB(skb)->sacked = 0;
99848
99849 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99850- if (!sk)
99851+ if (!sk) {
99852+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99853+ ret = 1;
99854+#endif
99855 goto no_tcp_socket;
99856-
99857+ }
99858 process:
99859- if (sk->sk_state == TCP_TIME_WAIT)
99860+ if (sk->sk_state == TCP_TIME_WAIT) {
99861+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99862+ ret = 2;
99863+#endif
99864 goto do_time_wait;
99865+ }
99866
99867 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
99868 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99869@@ -2033,6 +2047,10 @@ csum_error:
99870 bad_packet:
99871 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99872 } else {
99873+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99874+ if (!grsec_enable_blackhole || (ret == 1 &&
99875+ (skb->dev->flags & IFF_LOOPBACK)))
99876+#endif
99877 tcp_v4_send_reset(NULL, skb);
99878 }
99879
99880diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
99881index 05c1b15..3e9344b 100644
99882--- a/net/ipv4/tcp_minisocks.c
99883+++ b/net/ipv4/tcp_minisocks.c
99884@@ -27,6 +27,10 @@
99885 #include <net/inet_common.h>
99886 #include <net/xfrm.h>
99887
99888+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99889+extern int grsec_enable_blackhole;
99890+#endif
99891+
99892 int sysctl_tcp_syncookies __read_mostly = 1;
99893 EXPORT_SYMBOL(sysctl_tcp_syncookies);
99894
99895@@ -709,7 +713,10 @@ embryonic_reset:
99896 * avoid becoming vulnerable to outside attack aiming at
99897 * resetting legit local connections.
99898 */
99899- req->rsk_ops->send_reset(sk, skb);
99900+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99901+ if (!grsec_enable_blackhole)
99902+#endif
99903+ req->rsk_ops->send_reset(sk, skb);
99904 } else if (fastopen) { /* received a valid RST pkt */
99905 reqsk_fastopen_remove(sk, req, true);
99906 tcp_reset(sk);
99907diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
99908index 3b66610..bfbe23a 100644
99909--- a/net/ipv4/tcp_probe.c
99910+++ b/net/ipv4/tcp_probe.c
99911@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
99912 if (cnt + width >= len)
99913 break;
99914
99915- if (copy_to_user(buf + cnt, tbuf, width))
99916+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
99917 return -EFAULT;
99918 cnt += width;
99919 }
99920diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
99921index 286227a..c495a76 100644
99922--- a/net/ipv4/tcp_timer.c
99923+++ b/net/ipv4/tcp_timer.c
99924@@ -22,6 +22,10 @@
99925 #include <linux/gfp.h>
99926 #include <net/tcp.h>
99927
99928+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99929+extern int grsec_lastack_retries;
99930+#endif
99931+
99932 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
99933 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
99934 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
99935@@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
99936 }
99937 }
99938
99939+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99940+ if ((sk->sk_state == TCP_LAST_ACK) &&
99941+ (grsec_lastack_retries > 0) &&
99942+ (grsec_lastack_retries < retry_until))
99943+ retry_until = grsec_lastack_retries;
99944+#endif
99945+
99946 if (retransmits_timed_out(sk, retry_until,
99947 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
99948 /* Has it gone just too far? */
99949diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
99950index 54a5fe9..78fea00 100644
99951--- a/net/ipv4/udp.c
99952+++ b/net/ipv4/udp.c
99953@@ -87,6 +87,7 @@
99954 #include <linux/types.h>
99955 #include <linux/fcntl.h>
99956 #include <linux/module.h>
99957+#include <linux/security.h>
99958 #include <linux/socket.h>
99959 #include <linux/sockios.h>
99960 #include <linux/igmp.h>
99961@@ -113,6 +114,10 @@
99962 #include <net/busy_poll.h>
99963 #include "udp_impl.h"
99964
99965+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99966+extern int grsec_enable_blackhole;
99967+#endif
99968+
99969 struct udp_table udp_table __read_mostly;
99970 EXPORT_SYMBOL(udp_table);
99971
99972@@ -615,6 +620,9 @@ found:
99973 return s;
99974 }
99975
99976+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
99977+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
99978+
99979 /*
99980 * This routine is called by the ICMP module when it gets some
99981 * sort of error condition. If err < 0 then the socket should
99982@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99983 dport = usin->sin_port;
99984 if (dport == 0)
99985 return -EINVAL;
99986+
99987+ err = gr_search_udp_sendmsg(sk, usin);
99988+ if (err)
99989+ return err;
99990 } else {
99991 if (sk->sk_state != TCP_ESTABLISHED)
99992 return -EDESTADDRREQ;
99993+
99994+ err = gr_search_udp_sendmsg(sk, NULL);
99995+ if (err)
99996+ return err;
99997+
99998 daddr = inet->inet_daddr;
99999 dport = inet->inet_dport;
100000 /* Open fast path for connected socket.
100001@@ -1164,7 +1181,7 @@ static unsigned int first_packet_length(struct sock *sk)
100002 IS_UDPLITE(sk));
100003 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100004 IS_UDPLITE(sk));
100005- atomic_inc(&sk->sk_drops);
100006+ atomic_inc_unchecked(&sk->sk_drops);
100007 __skb_unlink(skb, rcvq);
100008 __skb_queue_tail(&list_kill, skb);
100009 }
100010@@ -1235,6 +1252,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100011 int is_udplite = IS_UDPLITE(sk);
100012 bool slow;
100013
100014+ /*
100015+ * Check any passed addresses
100016+ */
100017+ if (addr_len)
100018+ *addr_len = sizeof(*sin);
100019+
100020 if (flags & MSG_ERRQUEUE)
100021 return ip_recv_error(sk, msg, len, addr_len);
100022
100023@@ -1244,6 +1267,10 @@ try_again:
100024 if (!skb)
100025 goto out;
100026
100027+ err = gr_search_udp_recvmsg(sk, skb);
100028+ if (err)
100029+ goto out_free;
100030+
100031 ulen = skb->len - sizeof(struct udphdr);
100032 copied = len;
100033 if (copied > ulen)
100034@@ -1277,7 +1304,7 @@ try_again:
100035 if (unlikely(err)) {
100036 trace_kfree_skb(skb, udp_recvmsg);
100037 if (!peeked) {
100038- atomic_inc(&sk->sk_drops);
100039+ atomic_inc_unchecked(&sk->sk_drops);
100040 UDP_INC_STATS_USER(sock_net(sk),
100041 UDP_MIB_INERRORS, is_udplite);
100042 }
100043@@ -1296,7 +1323,6 @@ try_again:
100044 sin->sin_port = udp_hdr(skb)->source;
100045 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100046 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
100047- *addr_len = sizeof(*sin);
100048 }
100049 if (inet->cmsg_flags)
100050 ip_cmsg_recv(msg, skb);
100051@@ -1567,7 +1593,7 @@ csum_error:
100052 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100053 drop:
100054 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100055- atomic_inc(&sk->sk_drops);
100056+ atomic_inc_unchecked(&sk->sk_drops);
100057 kfree_skb(skb);
100058 return -1;
100059 }
100060@@ -1586,7 +1612,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100061 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100062
100063 if (!skb1) {
100064- atomic_inc(&sk->sk_drops);
100065+ atomic_inc_unchecked(&sk->sk_drops);
100066 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100067 IS_UDPLITE(sk));
100068 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100069@@ -1787,6 +1813,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100070 goto csum_error;
100071
100072 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100073+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100074+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100075+#endif
100076 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
100077
100078 /*
100079@@ -2355,7 +2384,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
100080 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
100081 0, sock_i_ino(sp),
100082 atomic_read(&sp->sk_refcnt), sp,
100083- atomic_read(&sp->sk_drops));
100084+ atomic_read_unchecked(&sp->sk_drops));
100085 }
100086
100087 int udp4_seq_show(struct seq_file *seq, void *v)
100088diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
100089index 6156f68..d6ab46d 100644
100090--- a/net/ipv4/xfrm4_policy.c
100091+++ b/net/ipv4/xfrm4_policy.c
100092@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
100093 fl4->flowi4_tos = iph->tos;
100094 }
100095
100096-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
100097+static int xfrm4_garbage_collect(struct dst_ops *ops)
100098 {
100099 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
100100
100101- xfrm4_policy_afinfo.garbage_collect(net);
100102+ xfrm_garbage_collect_deferred(net);
100103 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
100104 }
100105
100106@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
100107
100108 static int __net_init xfrm4_net_init(struct net *net)
100109 {
100110- struct ctl_table *table;
100111+ ctl_table_no_const *table = NULL;
100112 struct ctl_table_header *hdr;
100113
100114- table = xfrm4_policy_table;
100115 if (!net_eq(net, &init_net)) {
100116- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100117+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100118 if (!table)
100119 goto err_alloc;
100120
100121 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
100122- }
100123-
100124- hdr = register_net_sysctl(net, "net/ipv4", table);
100125+ hdr = register_net_sysctl(net, "net/ipv4", table);
100126+ } else
100127+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
100128 if (!hdr)
100129 goto err_reg;
100130
100131@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
100132 return 0;
100133
100134 err_reg:
100135- if (!net_eq(net, &init_net))
100136- kfree(table);
100137+ kfree(table);
100138 err_alloc:
100139 return -ENOMEM;
100140 }
100141diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
100142index 6c7fa08..285086c 100644
100143--- a/net/ipv6/addrconf.c
100144+++ b/net/ipv6/addrconf.c
100145@@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
100146 idx = 0;
100147 head = &net->dev_index_head[h];
100148 rcu_read_lock();
100149- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
100150+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
100151 net->dev_base_seq;
100152 hlist_for_each_entry_rcu(dev, head, index_hlist) {
100153 if (idx < s_idx)
100154@@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
100155 p.iph.ihl = 5;
100156 p.iph.protocol = IPPROTO_IPV6;
100157 p.iph.ttl = 64;
100158- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
100159+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
100160
100161 if (ops->ndo_do_ioctl) {
100162 mm_segment_t oldfs = get_fs();
100163@@ -4146,7 +4146,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
100164 s_ip_idx = ip_idx = cb->args[2];
100165
100166 rcu_read_lock();
100167- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100168+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100169 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
100170 idx = 0;
100171 head = &net->dev_index_head[h];
100172@@ -4758,7 +4758,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
100173 dst_free(&ifp->rt->dst);
100174 break;
100175 }
100176- atomic_inc(&net->ipv6.dev_addr_genid);
100177+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
100178 rt_genid_bump_ipv6(net);
100179 }
100180
100181@@ -4779,7 +4779,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
100182 int *valp = ctl->data;
100183 int val = *valp;
100184 loff_t pos = *ppos;
100185- struct ctl_table lctl;
100186+ ctl_table_no_const lctl;
100187 int ret;
100188
100189 /*
100190@@ -4864,7 +4864,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
100191 int *valp = ctl->data;
100192 int val = *valp;
100193 loff_t pos = *ppos;
100194- struct ctl_table lctl;
100195+ ctl_table_no_const lctl;
100196 int ret;
100197
100198 /*
100199diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
100200index d935889..2f64330 100644
100201--- a/net/ipv6/af_inet6.c
100202+++ b/net/ipv6/af_inet6.c
100203@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
100204 net->ipv6.sysctl.bindv6only = 0;
100205 net->ipv6.sysctl.icmpv6_time = 1*HZ;
100206 net->ipv6.sysctl.flowlabel_consistency = 1;
100207- atomic_set(&net->ipv6.rt_genid, 0);
100208+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
100209
100210 err = ipv6_init_mibs(net);
100211 if (err)
100212diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
100213index c3bf2d2..1f00573 100644
100214--- a/net/ipv6/datagram.c
100215+++ b/net/ipv6/datagram.c
100216@@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
100217 0,
100218 sock_i_ino(sp),
100219 atomic_read(&sp->sk_refcnt), sp,
100220- atomic_read(&sp->sk_drops));
100221+ atomic_read_unchecked(&sp->sk_drops));
100222 }
100223diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100224index 7b32652..0bc348b 100644
100225--- a/net/ipv6/icmp.c
100226+++ b/net/ipv6/icmp.c
100227@@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100228
100229 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100230 {
100231- struct ctl_table *table;
100232+ ctl_table_no_const *table;
100233
100234 table = kmemdup(ipv6_icmp_table_template,
100235 sizeof(ipv6_icmp_table_template),
100236diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100237index 9d92146..d986c6a 100644
100238--- a/net/ipv6/ip6_gre.c
100239+++ b/net/ipv6/ip6_gre.c
100240@@ -71,7 +71,7 @@ struct ip6gre_net {
100241 struct net_device *fb_tunnel_dev;
100242 };
100243
100244-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100245+static struct rtnl_link_ops ip6gre_link_ops;
100246 static int ip6gre_tunnel_init(struct net_device *dev);
100247 static void ip6gre_tunnel_setup(struct net_device *dev);
100248 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100249@@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100250 }
100251
100252
100253-static struct inet6_protocol ip6gre_protocol __read_mostly = {
100254+static struct inet6_protocol ip6gre_protocol = {
100255 .handler = ip6gre_rcv,
100256 .err_handler = ip6gre_err,
100257 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100258@@ -1636,7 +1636,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100259 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100260 };
100261
100262-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100263+static struct rtnl_link_ops ip6gre_link_ops = {
100264 .kind = "ip6gre",
100265 .maxtype = IFLA_GRE_MAX,
100266 .policy = ip6gre_policy,
100267@@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100268 .fill_info = ip6gre_fill_info,
100269 };
100270
100271-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100272+static struct rtnl_link_ops ip6gre_tap_ops = {
100273 .kind = "ip6gretap",
100274 .maxtype = IFLA_GRE_MAX,
100275 .policy = ip6gre_policy,
100276diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100277index afa0824..04ba530 100644
100278--- a/net/ipv6/ip6_tunnel.c
100279+++ b/net/ipv6/ip6_tunnel.c
100280@@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100281
100282 static int ip6_tnl_dev_init(struct net_device *dev);
100283 static void ip6_tnl_dev_setup(struct net_device *dev);
100284-static struct rtnl_link_ops ip6_link_ops __read_mostly;
100285+static struct rtnl_link_ops ip6_link_ops;
100286
100287 static int ip6_tnl_net_id __read_mostly;
100288 struct ip6_tnl_net {
100289@@ -1708,7 +1708,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100290 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100291 };
100292
100293-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100294+static struct rtnl_link_ops ip6_link_ops = {
100295 .kind = "ip6tnl",
100296 .maxtype = IFLA_IPTUN_MAX,
100297 .policy = ip6_tnl_policy,
100298diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100299index 6cc9f93..6e5bb7c 100644
100300--- a/net/ipv6/ip6_vti.c
100301+++ b/net/ipv6/ip6_vti.c
100302@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100303
100304 static int vti6_dev_init(struct net_device *dev);
100305 static void vti6_dev_setup(struct net_device *dev);
100306-static struct rtnl_link_ops vti6_link_ops __read_mostly;
100307+static struct rtnl_link_ops vti6_link_ops;
100308
100309 static int vti6_net_id __read_mostly;
100310 struct vti6_net {
100311@@ -980,7 +980,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100312 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100313 };
100314
100315-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100316+static struct rtnl_link_ops vti6_link_ops = {
100317 .kind = "vti6",
100318 .maxtype = IFLA_VTI_MAX,
100319 .policy = vti6_policy,
100320diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100321index edb58af..78de133 100644
100322--- a/net/ipv6/ipv6_sockglue.c
100323+++ b/net/ipv6/ipv6_sockglue.c
100324@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
100325 if (sk->sk_type != SOCK_STREAM)
100326 return -ENOPROTOOPT;
100327
100328- msg.msg_control = optval;
100329+ msg.msg_control = (void __force_kernel *)optval;
100330 msg.msg_controllen = len;
100331 msg.msg_flags = flags;
100332
100333diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
100334index e080fbb..412b3cf 100644
100335--- a/net/ipv6/netfilter/ip6_tables.c
100336+++ b/net/ipv6/netfilter/ip6_tables.c
100337@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
100338 #endif
100339
100340 static int get_info(struct net *net, void __user *user,
100341- const int *len, int compat)
100342+ int len, int compat)
100343 {
100344 char name[XT_TABLE_MAXNAMELEN];
100345 struct xt_table *t;
100346 int ret;
100347
100348- if (*len != sizeof(struct ip6t_getinfo)) {
100349- duprintf("length %u != %zu\n", *len,
100350+ if (len != sizeof(struct ip6t_getinfo)) {
100351+ duprintf("length %u != %zu\n", len,
100352 sizeof(struct ip6t_getinfo));
100353 return -EINVAL;
100354 }
100355@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
100356 info.size = private->size;
100357 strcpy(info.name, name);
100358
100359- if (copy_to_user(user, &info, *len) != 0)
100360+ if (copy_to_user(user, &info, len) != 0)
100361 ret = -EFAULT;
100362 else
100363 ret = 0;
100364@@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100365
100366 switch (cmd) {
100367 case IP6T_SO_GET_INFO:
100368- ret = get_info(sock_net(sk), user, len, 1);
100369+ ret = get_info(sock_net(sk), user, *len, 1);
100370 break;
100371 case IP6T_SO_GET_ENTRIES:
100372 ret = compat_get_entries(sock_net(sk), user, len);
100373@@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100374
100375 switch (cmd) {
100376 case IP6T_SO_GET_INFO:
100377- ret = get_info(sock_net(sk), user, len, 0);
100378+ ret = get_info(sock_net(sk), user, *len, 0);
100379 break;
100380
100381 case IP6T_SO_GET_ENTRIES:
100382diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
100383index 767ab8d..c5ec70a 100644
100384--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
100385+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
100386@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
100387
100388 static int nf_ct_frag6_sysctl_register(struct net *net)
100389 {
100390- struct ctl_table *table;
100391+ ctl_table_no_const *table = NULL;
100392 struct ctl_table_header *hdr;
100393
100394- table = nf_ct_frag6_sysctl_table;
100395 if (!net_eq(net, &init_net)) {
100396- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
100397+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
100398 GFP_KERNEL);
100399 if (table == NULL)
100400 goto err_alloc;
100401@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100402 table[0].data = &net->nf_frag.frags.timeout;
100403 table[1].data = &net->nf_frag.frags.low_thresh;
100404 table[2].data = &net->nf_frag.frags.high_thresh;
100405- }
100406-
100407- hdr = register_net_sysctl(net, "net/netfilter", table);
100408+ hdr = register_net_sysctl(net, "net/netfilter", table);
100409+ } else
100410+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
100411 if (hdr == NULL)
100412 goto err_reg;
100413
100414@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100415 return 0;
100416
100417 err_reg:
100418- if (!net_eq(net, &init_net))
100419- kfree(table);
100420+ kfree(table);
100421 err_alloc:
100422 return -ENOMEM;
100423 }
100424diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
100425index 56596ce..c734618 100644
100426--- a/net/ipv6/output_core.c
100427+++ b/net/ipv6/output_core.c
100428@@ -10,7 +10,7 @@
100429
100430 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100431 {
100432- static atomic_t ipv6_fragmentation_id;
100433+ static atomic_unchecked_t ipv6_fragmentation_id;
100434 struct in6_addr addr;
100435 int ident;
100436
100437@@ -26,7 +26,7 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100438 return;
100439 }
100440 #endif
100441- ident = atomic_inc_return(&ipv6_fragmentation_id);
100442+ ident = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100443
100444 addr = rt->rt6i_dst.addr;
100445 addr.s6_addr32[0] ^= (__force __be32)ident;
100446diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
100447index bda7429..469b26b 100644
100448--- a/net/ipv6/ping.c
100449+++ b/net/ipv6/ping.c
100450@@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
100451 };
100452 #endif
100453
100454+static struct pingv6_ops real_pingv6_ops = {
100455+ .ipv6_recv_error = ipv6_recv_error,
100456+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
100457+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
100458+ .icmpv6_err_convert = icmpv6_err_convert,
100459+ .ipv6_icmp_error = ipv6_icmp_error,
100460+ .ipv6_chk_addr = ipv6_chk_addr,
100461+};
100462+
100463+static struct pingv6_ops dummy_pingv6_ops = {
100464+ .ipv6_recv_error = dummy_ipv6_recv_error,
100465+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
100466+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
100467+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
100468+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
100469+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
100470+};
100471+
100472 int __init pingv6_init(void)
100473 {
100474 #ifdef CONFIG_PROC_FS
100475@@ -253,13 +271,7 @@ int __init pingv6_init(void)
100476 if (ret)
100477 return ret;
100478 #endif
100479- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
100480- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
100481- pingv6_ops.ip6_datagram_recv_specific_ctl =
100482- ip6_datagram_recv_specific_ctl;
100483- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
100484- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
100485- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
100486+ pingv6_ops = &real_pingv6_ops;
100487 return inet6_register_protosw(&pingv6_protosw);
100488 }
100489
100490@@ -268,14 +280,9 @@ int __init pingv6_init(void)
100491 */
100492 void pingv6_exit(void)
100493 {
100494- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
100495- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
100496- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
100497- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
100498- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
100499- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
100500 #ifdef CONFIG_PROC_FS
100501 unregister_pernet_subsys(&ping_v6_net_ops);
100502 #endif
100503+ pingv6_ops = &dummy_pingv6_ops;
100504 inet6_unregister_protosw(&pingv6_protosw);
100505 }
100506diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
100507index 091d066..139d410 100644
100508--- a/net/ipv6/proc.c
100509+++ b/net/ipv6/proc.c
100510@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
100511 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
100512 goto proc_snmp6_fail;
100513
100514- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
100515+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
100516 if (!net->mib.proc_net_devsnmp6)
100517 goto proc_dev_snmp6_fail;
100518 return 0;
100519diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
100520index 1f29996..46fe0c7 100644
100521--- a/net/ipv6/raw.c
100522+++ b/net/ipv6/raw.c
100523@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
100524 {
100525 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
100526 skb_checksum_complete(skb)) {
100527- atomic_inc(&sk->sk_drops);
100528+ atomic_inc_unchecked(&sk->sk_drops);
100529 kfree_skb(skb);
100530 return NET_RX_DROP;
100531 }
100532@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100533 struct raw6_sock *rp = raw6_sk(sk);
100534
100535 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
100536- atomic_inc(&sk->sk_drops);
100537+ atomic_inc_unchecked(&sk->sk_drops);
100538 kfree_skb(skb);
100539 return NET_RX_DROP;
100540 }
100541@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100542
100543 if (inet->hdrincl) {
100544 if (skb_checksum_complete(skb)) {
100545- atomic_inc(&sk->sk_drops);
100546+ atomic_inc_unchecked(&sk->sk_drops);
100547 kfree_skb(skb);
100548 return NET_RX_DROP;
100549 }
100550@@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100551 if (flags & MSG_OOB)
100552 return -EOPNOTSUPP;
100553
100554+ if (addr_len)
100555+ *addr_len=sizeof(*sin6);
100556+
100557 if (flags & MSG_ERRQUEUE)
100558 return ipv6_recv_error(sk, msg, len, addr_len);
100559
100560@@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100561 sin6->sin6_flowinfo = 0;
100562 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
100563 IP6CB(skb)->iif);
100564- *addr_len = sizeof(*sin6);
100565 }
100566
100567 sock_recv_ts_and_drops(msg, sk, skb);
100568@@ -610,7 +612,7 @@ out:
100569 return err;
100570 }
100571
100572-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
100573+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
100574 struct flowi6 *fl6, struct dst_entry **dstp,
100575 unsigned int flags)
100576 {
100577@@ -922,12 +924,15 @@ do_confirm:
100578 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
100579 char __user *optval, int optlen)
100580 {
100581+ struct icmp6_filter filter;
100582+
100583 switch (optname) {
100584 case ICMPV6_FILTER:
100585 if (optlen > sizeof(struct icmp6_filter))
100586 optlen = sizeof(struct icmp6_filter);
100587- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
100588+ if (copy_from_user(&filter, optval, optlen))
100589 return -EFAULT;
100590+ raw6_sk(sk)->filter = filter;
100591 return 0;
100592 default:
100593 return -ENOPROTOOPT;
100594@@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100595 char __user *optval, int __user *optlen)
100596 {
100597 int len;
100598+ struct icmp6_filter filter;
100599
100600 switch (optname) {
100601 case ICMPV6_FILTER:
100602@@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100603 len = sizeof(struct icmp6_filter);
100604 if (put_user(len, optlen))
100605 return -EFAULT;
100606- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
100607+ filter = raw6_sk(sk)->filter;
100608+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
100609 return -EFAULT;
100610 return 0;
100611 default:
100612diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
100613index cc85a9b..526a133 100644
100614--- a/net/ipv6/reassembly.c
100615+++ b/net/ipv6/reassembly.c
100616@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
100617
100618 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100619 {
100620- struct ctl_table *table;
100621+ ctl_table_no_const *table = NULL;
100622 struct ctl_table_header *hdr;
100623
100624- table = ip6_frags_ns_ctl_table;
100625 if (!net_eq(net, &init_net)) {
100626- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100627+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100628 if (table == NULL)
100629 goto err_alloc;
100630
100631@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100632 /* Don't export sysctls to unprivileged users */
100633 if (net->user_ns != &init_user_ns)
100634 table[0].procname = NULL;
100635- }
100636+ hdr = register_net_sysctl(net, "net/ipv6", table);
100637+ } else
100638+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
100639
100640- hdr = register_net_sysctl(net, "net/ipv6", table);
100641 if (hdr == NULL)
100642 goto err_reg;
100643
100644@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100645 return 0;
100646
100647 err_reg:
100648- if (!net_eq(net, &init_net))
100649- kfree(table);
100650+ kfree(table);
100651 err_alloc:
100652 return -ENOMEM;
100653 }
100654diff --git a/net/ipv6/route.c b/net/ipv6/route.c
100655index 6ebdb7b6..f225ab1 100644
100656--- a/net/ipv6/route.c
100657+++ b/net/ipv6/route.c
100658@@ -2971,7 +2971,7 @@ struct ctl_table ipv6_route_table_template[] = {
100659
100660 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
100661 {
100662- struct ctl_table *table;
100663+ ctl_table_no_const *table;
100664
100665 table = kmemdup(ipv6_route_table_template,
100666 sizeof(ipv6_route_table_template),
100667diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
100668index 4f40817..54dcbef 100644
100669--- a/net/ipv6/sit.c
100670+++ b/net/ipv6/sit.c
100671@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
100672 static void ipip6_dev_free(struct net_device *dev);
100673 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
100674 __be32 *v4dst);
100675-static struct rtnl_link_ops sit_link_ops __read_mostly;
100676+static struct rtnl_link_ops sit_link_ops;
100677
100678 static int sit_net_id __read_mostly;
100679 struct sit_net {
100680@@ -1661,7 +1661,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
100681 unregister_netdevice_queue(dev, head);
100682 }
100683
100684-static struct rtnl_link_ops sit_link_ops __read_mostly = {
100685+static struct rtnl_link_ops sit_link_ops = {
100686 .kind = "sit",
100687 .maxtype = IFLA_IPTUN_MAX,
100688 .policy = ipip6_policy,
100689diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
100690index 7f405a1..eabef92 100644
100691--- a/net/ipv6/sysctl_net_ipv6.c
100692+++ b/net/ipv6/sysctl_net_ipv6.c
100693@@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
100694
100695 static int __net_init ipv6_sysctl_net_init(struct net *net)
100696 {
100697- struct ctl_table *ipv6_table;
100698+ ctl_table_no_const *ipv6_table;
100699 struct ctl_table *ipv6_route_table;
100700 struct ctl_table *ipv6_icmp_table;
100701 int err;
100702diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
100703index e289830..79a5718 100644
100704--- a/net/ipv6/tcp_ipv6.c
100705+++ b/net/ipv6/tcp_ipv6.c
100706@@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
100707 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
100708 }
100709
100710+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100711+extern int grsec_enable_blackhole;
100712+#endif
100713+
100714 static void tcp_v6_hash(struct sock *sk)
100715 {
100716 if (sk->sk_state != TCP_CLOSE) {
100717@@ -1416,6 +1420,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
100718 return 0;
100719
100720 reset:
100721+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100722+ if (!grsec_enable_blackhole)
100723+#endif
100724 tcp_v6_send_reset(sk, skb);
100725 discard:
100726 if (opt_skb)
100727@@ -1500,12 +1507,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
100728 TCP_SKB_CB(skb)->sacked = 0;
100729
100730 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100731- if (!sk)
100732+ if (!sk) {
100733+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100734+ ret = 1;
100735+#endif
100736 goto no_tcp_socket;
100737+ }
100738
100739 process:
100740- if (sk->sk_state == TCP_TIME_WAIT)
100741+ if (sk->sk_state == TCP_TIME_WAIT) {
100742+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100743+ ret = 2;
100744+#endif
100745 goto do_time_wait;
100746+ }
100747
100748 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
100749 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100750@@ -1557,6 +1572,10 @@ csum_error:
100751 bad_packet:
100752 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100753 } else {
100754+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100755+ if (!grsec_enable_blackhole || (ret == 1 &&
100756+ (skb->dev->flags & IFF_LOOPBACK)))
100757+#endif
100758 tcp_v6_send_reset(NULL, skb);
100759 }
100760
100761diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
100762index 20b63d2..13be908 100644
100763--- a/net/ipv6/udp.c
100764+++ b/net/ipv6/udp.c
100765@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
100766 udp_ipv6_hash_secret + net_hash_mix(net));
100767 }
100768
100769+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100770+extern int grsec_enable_blackhole;
100771+#endif
100772+
100773 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
100774 {
100775 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
100776@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100777 int is_udp4;
100778 bool slow;
100779
100780+ if (addr_len)
100781+ *addr_len = sizeof(struct sockaddr_in6);
100782+
100783 if (flags & MSG_ERRQUEUE)
100784 return ipv6_recv_error(sk, msg, len, addr_len);
100785
100786@@ -435,7 +442,7 @@ try_again:
100787 if (unlikely(err)) {
100788 trace_kfree_skb(skb, udpv6_recvmsg);
100789 if (!peeked) {
100790- atomic_inc(&sk->sk_drops);
100791+ atomic_inc_unchecked(&sk->sk_drops);
100792 if (is_udp4)
100793 UDP_INC_STATS_USER(sock_net(sk),
100794 UDP_MIB_INERRORS,
100795@@ -475,7 +482,7 @@ try_again:
100796 ipv6_iface_scope_id(&sin6->sin6_addr,
100797 IP6CB(skb)->iif);
100798 }
100799- *addr_len = sizeof(*sin6);
100800+
100801 }
100802
100803 if (np->rxopt.all)
100804@@ -690,7 +697,7 @@ csum_error:
100805 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100806 drop:
100807 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100808- atomic_inc(&sk->sk_drops);
100809+ atomic_inc_unchecked(&sk->sk_drops);
100810 kfree_skb(skb);
100811 return -1;
100812 }
100813@@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100814 if (likely(skb1 == NULL))
100815 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100816 if (!skb1) {
100817- atomic_inc(&sk->sk_drops);
100818+ atomic_inc_unchecked(&sk->sk_drops);
100819 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100820 IS_UDPLITE(sk));
100821 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100822@@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100823 goto csum_error;
100824
100825 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100826+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100827+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100828+#endif
100829 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
100830
100831 kfree_skb(skb);
100832diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
100833index 2a0bbda..d75ca57 100644
100834--- a/net/ipv6/xfrm6_policy.c
100835+++ b/net/ipv6/xfrm6_policy.c
100836@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
100837 }
100838 }
100839
100840-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
100841+static int xfrm6_garbage_collect(struct dst_ops *ops)
100842 {
100843 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
100844
100845- xfrm6_policy_afinfo.garbage_collect(net);
100846+ xfrm_garbage_collect_deferred(net);
100847 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
100848 }
100849
100850@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
100851
100852 static int __net_init xfrm6_net_init(struct net *net)
100853 {
100854- struct ctl_table *table;
100855+ ctl_table_no_const *table = NULL;
100856 struct ctl_table_header *hdr;
100857
100858- table = xfrm6_policy_table;
100859 if (!net_eq(net, &init_net)) {
100860- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100861+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100862 if (!table)
100863 goto err_alloc;
100864
100865 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
100866- }
100867+ hdr = register_net_sysctl(net, "net/ipv6", table);
100868+ } else
100869+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
100870
100871- hdr = register_net_sysctl(net, "net/ipv6", table);
100872 if (!hdr)
100873 goto err_reg;
100874
100875@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
100876 return 0;
100877
100878 err_reg:
100879- if (!net_eq(net, &init_net))
100880- kfree(table);
100881+ kfree(table);
100882 err_alloc:
100883 return -ENOMEM;
100884 }
100885diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
100886index e15c16a..7cf07aa 100644
100887--- a/net/ipx/ipx_proc.c
100888+++ b/net/ipx/ipx_proc.c
100889@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
100890 struct proc_dir_entry *p;
100891 int rc = -ENOMEM;
100892
100893- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
100894+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
100895
100896 if (!ipx_proc_dir)
100897 goto out;
100898diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
100899index 2ba8b97..6d33010 100644
100900--- a/net/irda/ircomm/ircomm_tty.c
100901+++ b/net/irda/ircomm/ircomm_tty.c
100902@@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100903 add_wait_queue(&port->open_wait, &wait);
100904
100905 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
100906- __FILE__, __LINE__, tty->driver->name, port->count);
100907+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100908
100909 spin_lock_irqsave(&port->lock, flags);
100910 if (!tty_hung_up_p(filp))
100911- port->count--;
100912+ atomic_dec(&port->count);
100913 port->blocked_open++;
100914 spin_unlock_irqrestore(&port->lock, flags);
100915
100916@@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100917 }
100918
100919 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
100920- __FILE__, __LINE__, tty->driver->name, port->count);
100921+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100922
100923 schedule();
100924 }
100925@@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100926
100927 spin_lock_irqsave(&port->lock, flags);
100928 if (!tty_hung_up_p(filp))
100929- port->count++;
100930+ atomic_inc(&port->count);
100931 port->blocked_open--;
100932 spin_unlock_irqrestore(&port->lock, flags);
100933
100934 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
100935- __FILE__, __LINE__, tty->driver->name, port->count);
100936+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100937
100938 if (!retval)
100939 port->flags |= ASYNC_NORMAL_ACTIVE;
100940@@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
100941
100942 /* ++ is not atomic, so this should be protected - Jean II */
100943 spin_lock_irqsave(&self->port.lock, flags);
100944- self->port.count++;
100945+ atomic_inc(&self->port.count);
100946 spin_unlock_irqrestore(&self->port.lock, flags);
100947 tty_port_tty_set(&self->port, tty);
100948
100949 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
100950- self->line, self->port.count);
100951+ self->line, atomic_read(&self->port.count));
100952
100953 /* Not really used by us, but lets do it anyway */
100954 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
100955@@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
100956 tty_kref_put(port->tty);
100957 }
100958 port->tty = NULL;
100959- port->count = 0;
100960+ atomic_set(&port->count, 0);
100961 spin_unlock_irqrestore(&port->lock, flags);
100962
100963 wake_up_interruptible(&port->open_wait);
100964@@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
100965 seq_putc(m, '\n');
100966
100967 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
100968- seq_printf(m, "Open count: %d\n", self->port.count);
100969+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
100970 seq_printf(m, "Max data size: %d\n", self->max_data_size);
100971 seq_printf(m, "Max header size: %d\n", self->max_header_size);
100972
100973diff --git a/net/irda/irproc.c b/net/irda/irproc.c
100974index b9ac598..f88cc56 100644
100975--- a/net/irda/irproc.c
100976+++ b/net/irda/irproc.c
100977@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
100978 {
100979 int i;
100980
100981- proc_irda = proc_mkdir("irda", init_net.proc_net);
100982+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
100983 if (proc_irda == NULL)
100984 return;
100985
100986diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
100987index 8c9d730..66c6305 100644
100988--- a/net/iucv/af_iucv.c
100989+++ b/net/iucv/af_iucv.c
100990@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
100991
100992 write_lock_bh(&iucv_sk_list.lock);
100993
100994- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
100995+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
100996 while (__iucv_get_sock_by_name(name)) {
100997 sprintf(name, "%08x",
100998- atomic_inc_return(&iucv_sk_list.autobind_name));
100999+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101000 }
101001
101002 write_unlock_bh(&iucv_sk_list.lock);
101003diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
101004index da78793..bdd78cf 100644
101005--- a/net/iucv/iucv.c
101006+++ b/net/iucv/iucv.c
101007@@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
101008 return NOTIFY_OK;
101009 }
101010
101011-static struct notifier_block __refdata iucv_cpu_notifier = {
101012+static struct notifier_block iucv_cpu_notifier = {
101013 .notifier_call = iucv_cpu_notify,
101014 };
101015
101016diff --git a/net/key/af_key.c b/net/key/af_key.c
101017index f3c8307..7127791 100644
101018--- a/net/key/af_key.c
101019+++ b/net/key/af_key.c
101020@@ -3070,10 +3070,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
101021 static u32 get_acqseq(void)
101022 {
101023 u32 res;
101024- static atomic_t acqseq;
101025+ static atomic_unchecked_t acqseq;
101026
101027 do {
101028- res = atomic_inc_return(&acqseq);
101029+ res = atomic_inc_return_unchecked(&acqseq);
101030 } while (!res);
101031 return res;
101032 }
101033diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
101034index 76125c5..e474828 100644
101035--- a/net/l2tp/l2tp_eth.c
101036+++ b/net/l2tp/l2tp_eth.c
101037@@ -42,12 +42,12 @@ struct l2tp_eth {
101038 struct sock *tunnel_sock;
101039 struct l2tp_session *session;
101040 struct list_head list;
101041- atomic_long_t tx_bytes;
101042- atomic_long_t tx_packets;
101043- atomic_long_t tx_dropped;
101044- atomic_long_t rx_bytes;
101045- atomic_long_t rx_packets;
101046- atomic_long_t rx_errors;
101047+ atomic_long_unchecked_t tx_bytes;
101048+ atomic_long_unchecked_t tx_packets;
101049+ atomic_long_unchecked_t tx_dropped;
101050+ atomic_long_unchecked_t rx_bytes;
101051+ atomic_long_unchecked_t rx_packets;
101052+ atomic_long_unchecked_t rx_errors;
101053 };
101054
101055 /* via l2tp_session_priv() */
101056@@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
101057 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
101058
101059 if (likely(ret == NET_XMIT_SUCCESS)) {
101060- atomic_long_add(len, &priv->tx_bytes);
101061- atomic_long_inc(&priv->tx_packets);
101062+ atomic_long_add_unchecked(len, &priv->tx_bytes);
101063+ atomic_long_inc_unchecked(&priv->tx_packets);
101064 } else {
101065- atomic_long_inc(&priv->tx_dropped);
101066+ atomic_long_inc_unchecked(&priv->tx_dropped);
101067 }
101068 return NETDEV_TX_OK;
101069 }
101070@@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
101071 {
101072 struct l2tp_eth *priv = netdev_priv(dev);
101073
101074- stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
101075- stats->tx_packets = atomic_long_read(&priv->tx_packets);
101076- stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
101077- stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
101078- stats->rx_packets = atomic_long_read(&priv->rx_packets);
101079- stats->rx_errors = atomic_long_read(&priv->rx_errors);
101080+ stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
101081+ stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
101082+ stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
101083+ stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
101084+ stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
101085+ stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
101086 return stats;
101087 }
101088
101089@@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
101090 nf_reset(skb);
101091
101092 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
101093- atomic_long_inc(&priv->rx_packets);
101094- atomic_long_add(data_len, &priv->rx_bytes);
101095+ atomic_long_inc_unchecked(&priv->rx_packets);
101096+ atomic_long_add_unchecked(data_len, &priv->rx_bytes);
101097 } else {
101098- atomic_long_inc(&priv->rx_errors);
101099+ atomic_long_inc_unchecked(&priv->rx_errors);
101100 }
101101 return;
101102
101103 error:
101104- atomic_long_inc(&priv->rx_errors);
101105+ atomic_long_inc_unchecked(&priv->rx_errors);
101106 kfree_skb(skb);
101107 }
101108
101109diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
101110index 3397fe6..861fd1a 100644
101111--- a/net/l2tp/l2tp_ip.c
101112+++ b/net/l2tp/l2tp_ip.c
101113@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101114 if (flags & MSG_OOB)
101115 goto out;
101116
101117+ if (addr_len)
101118+ *addr_len = sizeof(*sin);
101119+
101120 skb = skb_recv_datagram(sk, flags, noblock, &err);
101121 if (!skb)
101122 goto out;
101123@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101124 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
101125 sin->sin_port = 0;
101126 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
101127- *addr_len = sizeof(*sin);
101128 }
101129 if (inet->cmsg_flags)
101130 ip_cmsg_recv(msg, skb);
101131diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
101132index 1a3c7e0..80f8b0c 100644
101133--- a/net/llc/llc_proc.c
101134+++ b/net/llc/llc_proc.c
101135@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
101136 int rc = -ENOMEM;
101137 struct proc_dir_entry *p;
101138
101139- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
101140+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
101141 if (!llc_proc_dir)
101142 goto out;
101143
101144diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
101145index aaa59d7..21a2c4a 100644
101146--- a/net/mac80211/cfg.c
101147+++ b/net/mac80211/cfg.c
101148@@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
101149 ret = ieee80211_vif_use_channel(sdata, chandef,
101150 IEEE80211_CHANCTX_EXCLUSIVE);
101151 }
101152- } else if (local->open_count == local->monitors) {
101153+ } else if (local_read(&local->open_count) == local->monitors) {
101154 local->_oper_chandef = *chandef;
101155 ieee80211_hw_config(local, 0);
101156 }
101157@@ -3440,7 +3440,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
101158 else
101159 local->probe_req_reg--;
101160
101161- if (!local->open_count)
101162+ if (!local_read(&local->open_count))
101163 break;
101164
101165 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
101166@@ -3903,8 +3903,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
101167 if (chanctx_conf) {
101168 *chandef = chanctx_conf->def;
101169 ret = 0;
101170- } else if (local->open_count > 0 &&
101171- local->open_count == local->monitors &&
101172+ } else if (local_read(&local->open_count) > 0 &&
101173+ local_read(&local->open_count) == local->monitors &&
101174 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
101175 if (local->use_chanctx)
101176 *chandef = local->monitor_chandef;
101177diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
101178index f169b6e..a5dc4eb 100644
101179--- a/net/mac80211/ieee80211_i.h
101180+++ b/net/mac80211/ieee80211_i.h
101181@@ -28,6 +28,7 @@
101182 #include <net/ieee80211_radiotap.h>
101183 #include <net/cfg80211.h>
101184 #include <net/mac80211.h>
101185+#include <asm/local.h>
101186 #include "key.h"
101187 #include "sta_info.h"
101188 #include "debug.h"
101189@@ -999,7 +1000,7 @@ struct ieee80211_local {
101190 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
101191 spinlock_t queue_stop_reason_lock;
101192
101193- int open_count;
101194+ local_t open_count;
101195 int monitors, cooked_mntrs;
101196 /* number of interfaces with corresponding FIF_ flags */
101197 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
101198diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
101199index 34799e0..b411290 100644
101200--- a/net/mac80211/iface.c
101201+++ b/net/mac80211/iface.c
101202@@ -524,7 +524,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101203 break;
101204 }
101205
101206- if (local->open_count == 0) {
101207+ if (local_read(&local->open_count) == 0) {
101208 res = drv_start(local);
101209 if (res)
101210 goto err_del_bss;
101211@@ -571,7 +571,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101212 res = drv_add_interface(local, sdata);
101213 if (res)
101214 goto err_stop;
101215- } else if (local->monitors == 0 && local->open_count == 0) {
101216+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
101217 res = ieee80211_add_virtual_monitor(local);
101218 if (res)
101219 goto err_stop;
101220@@ -680,7 +680,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101221 atomic_inc(&local->iff_promiscs);
101222
101223 if (coming_up)
101224- local->open_count++;
101225+ local_inc(&local->open_count);
101226
101227 if (hw_reconf_flags)
101228 ieee80211_hw_config(local, hw_reconf_flags);
101229@@ -718,7 +718,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101230 err_del_interface:
101231 drv_remove_interface(local, sdata);
101232 err_stop:
101233- if (!local->open_count)
101234+ if (!local_read(&local->open_count))
101235 drv_stop(local);
101236 err_del_bss:
101237 sdata->bss = NULL;
101238@@ -871,7 +871,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101239 }
101240
101241 if (going_down)
101242- local->open_count--;
101243+ local_dec(&local->open_count);
101244
101245 switch (sdata->vif.type) {
101246 case NL80211_IFTYPE_AP_VLAN:
101247@@ -930,7 +930,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101248 }
101249 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
101250
101251- if (local->open_count == 0)
101252+ if (local_read(&local->open_count) == 0)
101253 ieee80211_clear_tx_pending(local);
101254
101255 /*
101256@@ -970,7 +970,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101257
101258 ieee80211_recalc_ps(local, -1);
101259
101260- if (local->open_count == 0) {
101261+ if (local_read(&local->open_count) == 0) {
101262 ieee80211_stop_device(local);
101263
101264 /* no reconfiguring after stop! */
101265@@ -981,7 +981,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101266 ieee80211_configure_filter(local);
101267 ieee80211_hw_config(local, hw_reconf_flags);
101268
101269- if (local->monitors == local->open_count)
101270+ if (local->monitors == local_read(&local->open_count))
101271 ieee80211_add_virtual_monitor(local);
101272 }
101273
101274diff --git a/net/mac80211/main.c b/net/mac80211/main.c
101275index 4c1bf61..00b449b 100644
101276--- a/net/mac80211/main.c
101277+++ b/net/mac80211/main.c
101278@@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
101279 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
101280 IEEE80211_CONF_CHANGE_POWER);
101281
101282- if (changed && local->open_count) {
101283+ if (changed && local_read(&local->open_count)) {
101284 ret = drv_config(local, changed);
101285 /*
101286 * Goal:
101287diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101288index d478b88..8c8d157 100644
101289--- a/net/mac80211/pm.c
101290+++ b/net/mac80211/pm.c
101291@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101292 struct ieee80211_sub_if_data *sdata;
101293 struct sta_info *sta;
101294
101295- if (!local->open_count)
101296+ if (!local_read(&local->open_count))
101297 goto suspend;
101298
101299 ieee80211_scan_cancel(local);
101300@@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101301 cancel_work_sync(&local->dynamic_ps_enable_work);
101302 del_timer_sync(&local->dynamic_ps_timer);
101303
101304- local->wowlan = wowlan && local->open_count;
101305+ local->wowlan = wowlan && local_read(&local->open_count);
101306 if (local->wowlan) {
101307 int err = drv_suspend(local, wowlan);
101308 if (err < 0) {
101309@@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101310 WARN_ON(!list_empty(&local->chanctx_list));
101311
101312 /* stop hardware - this must stop RX */
101313- if (local->open_count)
101314+ if (local_read(&local->open_count))
101315 ieee80211_stop_device(local);
101316
101317 suspend:
101318diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101319index 8fdadfd..a4f72b8 100644
101320--- a/net/mac80211/rate.c
101321+++ b/net/mac80211/rate.c
101322@@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101323
101324 ASSERT_RTNL();
101325
101326- if (local->open_count)
101327+ if (local_read(&local->open_count))
101328 return -EBUSY;
101329
101330 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101331diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101332index 6ff1346..936ca9a 100644
101333--- a/net/mac80211/rc80211_pid_debugfs.c
101334+++ b/net/mac80211/rc80211_pid_debugfs.c
101335@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
101336
101337 spin_unlock_irqrestore(&events->lock, status);
101338
101339- if (copy_to_user(buf, pb, p))
101340+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
101341 return -EFAULT;
101342
101343 return p;
101344diff --git a/net/mac80211/util.c b/net/mac80211/util.c
101345index 3c36583..12887fe 100644
101346--- a/net/mac80211/util.c
101347+++ b/net/mac80211/util.c
101348@@ -1509,7 +1509,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101349 }
101350 #endif
101351 /* everything else happens only if HW was up & running */
101352- if (!local->open_count)
101353+ if (!local_read(&local->open_count))
101354 goto wake_up;
101355
101356 /*
101357@@ -1734,7 +1734,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101358 local->in_reconfig = false;
101359 barrier();
101360
101361- if (local->monitors == local->open_count && local->monitors > 0)
101362+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
101363 ieee80211_add_virtual_monitor(local);
101364
101365 /*
101366diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
101367index e9410d1..77b6378 100644
101368--- a/net/netfilter/Kconfig
101369+++ b/net/netfilter/Kconfig
101370@@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
101371
101372 To compile it as a module, choose M here. If unsure, say N.
101373
101374+config NETFILTER_XT_MATCH_GRADM
101375+ tristate '"gradm" match support'
101376+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
101377+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
101378+ ---help---
101379+ The gradm match allows to match on grsecurity RBAC being enabled.
101380+ It is useful when iptables rules are applied early on bootup to
101381+ prevent connections to the machine (except from a trusted host)
101382+ while the RBAC system is disabled.
101383+
101384 config NETFILTER_XT_MATCH_HASHLIMIT
101385 tristate '"hashlimit" match support'
101386 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
101387diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
101388index bffdad7..f9317d1 100644
101389--- a/net/netfilter/Makefile
101390+++ b/net/netfilter/Makefile
101391@@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
101392 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
101393 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
101394 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
101395+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
101396 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
101397 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
101398 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
101399diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
101400index 1172083..986f1c1 100644
101401--- a/net/netfilter/ipset/ip_set_core.c
101402+++ b/net/netfilter/ipset/ip_set_core.c
101403@@ -1924,7 +1924,7 @@ done:
101404 return ret;
101405 }
101406
101407-static struct nf_sockopt_ops so_set __read_mostly = {
101408+static struct nf_sockopt_ops so_set = {
101409 .pf = PF_INET,
101410 .get_optmin = SO_IP_SET,
101411 .get_optmax = SO_IP_SET + 1,
101412diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
101413index a8eb0a8..86f2de4 100644
101414--- a/net/netfilter/ipvs/ip_vs_conn.c
101415+++ b/net/netfilter/ipvs/ip_vs_conn.c
101416@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
101417 /* Increase the refcnt counter of the dest */
101418 ip_vs_dest_hold(dest);
101419
101420- conn_flags = atomic_read(&dest->conn_flags);
101421+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
101422 if (cp->protocol != IPPROTO_UDP)
101423 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
101424 flags = cp->flags;
101425@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
101426
101427 cp->control = NULL;
101428 atomic_set(&cp->n_control, 0);
101429- atomic_set(&cp->in_pkts, 0);
101430+ atomic_set_unchecked(&cp->in_pkts, 0);
101431
101432 cp->packet_xmit = NULL;
101433 cp->app = NULL;
101434@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
101435
101436 /* Don't drop the entry if its number of incoming packets is not
101437 located in [0, 8] */
101438- i = atomic_read(&cp->in_pkts);
101439+ i = atomic_read_unchecked(&cp->in_pkts);
101440 if (i > 8 || i < 0) return 0;
101441
101442 if (!todrop_rate[i]) return 0;
101443diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
101444index 3d2d2c8..c87e4d3 100644
101445--- a/net/netfilter/ipvs/ip_vs_core.c
101446+++ b/net/netfilter/ipvs/ip_vs_core.c
101447@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
101448 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
101449 /* do not touch skb anymore */
101450
101451- atomic_inc(&cp->in_pkts);
101452+ atomic_inc_unchecked(&cp->in_pkts);
101453 ip_vs_conn_put(cp);
101454 return ret;
101455 }
101456@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
101457 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
101458 pkts = sysctl_sync_threshold(ipvs);
101459 else
101460- pkts = atomic_add_return(1, &cp->in_pkts);
101461+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101462
101463 if (ipvs->sync_state & IP_VS_STATE_MASTER)
101464 ip_vs_sync_conn(net, cp, pkts);
101465diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
101466index c42e83d..a6a3f8b 100644
101467--- a/net/netfilter/ipvs/ip_vs_ctl.c
101468+++ b/net/netfilter/ipvs/ip_vs_ctl.c
101469@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
101470 */
101471 ip_vs_rs_hash(ipvs, dest);
101472 }
101473- atomic_set(&dest->conn_flags, conn_flags);
101474+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
101475
101476 /* bind the service */
101477 old_svc = rcu_dereference_protected(dest->svc, 1);
101478@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
101479 * align with netns init in ip_vs_control_net_init()
101480 */
101481
101482-static struct ctl_table vs_vars[] = {
101483+static ctl_table_no_const vs_vars[] __read_only = {
101484 {
101485 .procname = "amemthresh",
101486 .maxlen = sizeof(int),
101487@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101488 " %-7s %-6d %-10d %-10d\n",
101489 &dest->addr.in6,
101490 ntohs(dest->port),
101491- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101492+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101493 atomic_read(&dest->weight),
101494 atomic_read(&dest->activeconns),
101495 atomic_read(&dest->inactconns));
101496@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101497 "%-7s %-6d %-10d %-10d\n",
101498 ntohl(dest->addr.ip),
101499 ntohs(dest->port),
101500- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101501+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101502 atomic_read(&dest->weight),
101503 atomic_read(&dest->activeconns),
101504 atomic_read(&dest->inactconns));
101505@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
101506
101507 entry.addr = dest->addr.ip;
101508 entry.port = dest->port;
101509- entry.conn_flags = atomic_read(&dest->conn_flags);
101510+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
101511 entry.weight = atomic_read(&dest->weight);
101512 entry.u_threshold = dest->u_threshold;
101513 entry.l_threshold = dest->l_threshold;
101514@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
101515 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
101516 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
101517 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
101518- (atomic_read(&dest->conn_flags) &
101519+ (atomic_read_unchecked(&dest->conn_flags) &
101520 IP_VS_CONN_F_FWD_MASK)) ||
101521 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
101522 atomic_read(&dest->weight)) ||
101523@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
101524 {
101525 int idx;
101526 struct netns_ipvs *ipvs = net_ipvs(net);
101527- struct ctl_table *tbl;
101528+ ctl_table_no_const *tbl;
101529
101530 atomic_set(&ipvs->dropentry, 0);
101531 spin_lock_init(&ipvs->dropentry_lock);
101532diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
101533index 547ff33..c8c8117 100644
101534--- a/net/netfilter/ipvs/ip_vs_lblc.c
101535+++ b/net/netfilter/ipvs/ip_vs_lblc.c
101536@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
101537 * IPVS LBLC sysctl table
101538 */
101539 #ifdef CONFIG_SYSCTL
101540-static struct ctl_table vs_vars_table[] = {
101541+static ctl_table_no_const vs_vars_table[] __read_only = {
101542 {
101543 .procname = "lblc_expiration",
101544 .data = NULL,
101545diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
101546index 3f21a2f..a112e85 100644
101547--- a/net/netfilter/ipvs/ip_vs_lblcr.c
101548+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
101549@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
101550 * IPVS LBLCR sysctl table
101551 */
101552
101553-static struct ctl_table vs_vars_table[] = {
101554+static ctl_table_no_const vs_vars_table[] __read_only = {
101555 {
101556 .procname = "lblcr_expiration",
101557 .data = NULL,
101558diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
101559index db80126..ef7110e 100644
101560--- a/net/netfilter/ipvs/ip_vs_sync.c
101561+++ b/net/netfilter/ipvs/ip_vs_sync.c
101562@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
101563 cp = cp->control;
101564 if (cp) {
101565 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101566- pkts = atomic_add_return(1, &cp->in_pkts);
101567+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101568 else
101569 pkts = sysctl_sync_threshold(ipvs);
101570 ip_vs_sync_conn(net, cp->control, pkts);
101571@@ -771,7 +771,7 @@ control:
101572 if (!cp)
101573 return;
101574 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101575- pkts = atomic_add_return(1, &cp->in_pkts);
101576+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101577 else
101578 pkts = sysctl_sync_threshold(ipvs);
101579 goto sloop;
101580@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
101581
101582 if (opt)
101583 memcpy(&cp->in_seq, opt, sizeof(*opt));
101584- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101585+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101586 cp->state = state;
101587 cp->old_state = cp->state;
101588 /*
101589diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
101590index c47444e..b0961c6 100644
101591--- a/net/netfilter/ipvs/ip_vs_xmit.c
101592+++ b/net/netfilter/ipvs/ip_vs_xmit.c
101593@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
101594 else
101595 rc = NF_ACCEPT;
101596 /* do not touch skb anymore */
101597- atomic_inc(&cp->in_pkts);
101598+ atomic_inc_unchecked(&cp->in_pkts);
101599 goto out;
101600 }
101601
101602@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
101603 else
101604 rc = NF_ACCEPT;
101605 /* do not touch skb anymore */
101606- atomic_inc(&cp->in_pkts);
101607+ atomic_inc_unchecked(&cp->in_pkts);
101608 goto out;
101609 }
101610
101611diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
101612index a4b5e2a..13b1de3 100644
101613--- a/net/netfilter/nf_conntrack_acct.c
101614+++ b/net/netfilter/nf_conntrack_acct.c
101615@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
101616 #ifdef CONFIG_SYSCTL
101617 static int nf_conntrack_acct_init_sysctl(struct net *net)
101618 {
101619- struct ctl_table *table;
101620+ ctl_table_no_const *table;
101621
101622 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
101623 GFP_KERNEL);
101624diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
101625index 75421f2..054c1fc 100644
101626--- a/net/netfilter/nf_conntrack_core.c
101627+++ b/net/netfilter/nf_conntrack_core.c
101628@@ -1789,6 +1789,10 @@ void nf_conntrack_init_end(void)
101629 #define DYING_NULLS_VAL ((1<<30)+1)
101630 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
101631
101632+#ifdef CONFIG_GRKERNSEC_HIDESYM
101633+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
101634+#endif
101635+
101636 int nf_conntrack_init_net(struct net *net)
101637 {
101638 int ret = -ENOMEM;
101639@@ -1814,7 +1818,11 @@ int nf_conntrack_init_net(struct net *net)
101640 if (!net->ct.stat)
101641 goto err_pcpu_lists;
101642
101643+#ifdef CONFIG_GRKERNSEC_HIDESYM
101644+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
101645+#else
101646 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
101647+#endif
101648 if (!net->ct.slabname)
101649 goto err_slabname;
101650
101651diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
101652index 1df1761..ce8b88a 100644
101653--- a/net/netfilter/nf_conntrack_ecache.c
101654+++ b/net/netfilter/nf_conntrack_ecache.c
101655@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
101656 #ifdef CONFIG_SYSCTL
101657 static int nf_conntrack_event_init_sysctl(struct net *net)
101658 {
101659- struct ctl_table *table;
101660+ ctl_table_no_const *table;
101661
101662 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
101663 GFP_KERNEL);
101664diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
101665index 5b3eae7..dd4b8fe 100644
101666--- a/net/netfilter/nf_conntrack_helper.c
101667+++ b/net/netfilter/nf_conntrack_helper.c
101668@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
101669
101670 static int nf_conntrack_helper_init_sysctl(struct net *net)
101671 {
101672- struct ctl_table *table;
101673+ ctl_table_no_const *table;
101674
101675 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
101676 GFP_KERNEL);
101677diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
101678index b65d586..beec902 100644
101679--- a/net/netfilter/nf_conntrack_proto.c
101680+++ b/net/netfilter/nf_conntrack_proto.c
101681@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
101682
101683 static void
101684 nf_ct_unregister_sysctl(struct ctl_table_header **header,
101685- struct ctl_table **table,
101686+ ctl_table_no_const **table,
101687 unsigned int users)
101688 {
101689 if (users > 0)
101690diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
101691index f641751..d3c5b51 100644
101692--- a/net/netfilter/nf_conntrack_standalone.c
101693+++ b/net/netfilter/nf_conntrack_standalone.c
101694@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
101695
101696 static int nf_conntrack_standalone_init_sysctl(struct net *net)
101697 {
101698- struct ctl_table *table;
101699+ ctl_table_no_const *table;
101700
101701 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
101702 GFP_KERNEL);
101703diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
101704index 7a394df..bd91a8a 100644
101705--- a/net/netfilter/nf_conntrack_timestamp.c
101706+++ b/net/netfilter/nf_conntrack_timestamp.c
101707@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
101708 #ifdef CONFIG_SYSCTL
101709 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
101710 {
101711- struct ctl_table *table;
101712+ ctl_table_no_const *table;
101713
101714 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
101715 GFP_KERNEL);
101716diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
101717index 85296d4..8becdec 100644
101718--- a/net/netfilter/nf_log.c
101719+++ b/net/netfilter/nf_log.c
101720@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
101721
101722 #ifdef CONFIG_SYSCTL
101723 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
101724-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
101725+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
101726
101727 static int nf_log_proc_dostring(struct ctl_table *table, int write,
101728 void __user *buffer, size_t *lenp, loff_t *ppos)
101729@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
101730 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
101731 mutex_unlock(&nf_log_mutex);
101732 } else {
101733+ ctl_table_no_const nf_log_table = *table;
101734+
101735 mutex_lock(&nf_log_mutex);
101736 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
101737 lockdep_is_held(&nf_log_mutex));
101738 if (!logger)
101739- table->data = "NONE";
101740+ nf_log_table.data = "NONE";
101741 else
101742- table->data = logger->name;
101743- r = proc_dostring(table, write, buffer, lenp, ppos);
101744+ nf_log_table.data = logger->name;
101745+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
101746 mutex_unlock(&nf_log_mutex);
101747 }
101748
101749diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
101750index f042ae5..30ea486 100644
101751--- a/net/netfilter/nf_sockopt.c
101752+++ b/net/netfilter/nf_sockopt.c
101753@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
101754 }
101755 }
101756
101757- list_add(&reg->list, &nf_sockopts);
101758+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
101759 out:
101760 mutex_unlock(&nf_sockopt_mutex);
101761 return ret;
101762@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
101763 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
101764 {
101765 mutex_lock(&nf_sockopt_mutex);
101766- list_del(&reg->list);
101767+ pax_list_del((struct list_head *)&reg->list);
101768 mutex_unlock(&nf_sockopt_mutex);
101769 }
101770 EXPORT_SYMBOL(nf_unregister_sockopt);
101771diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
101772index d292c8d..9f1e166 100644
101773--- a/net/netfilter/nfnetlink_log.c
101774+++ b/net/netfilter/nfnetlink_log.c
101775@@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
101776 struct nfnl_log_net {
101777 spinlock_t instances_lock;
101778 struct hlist_head instance_table[INSTANCE_BUCKETS];
101779- atomic_t global_seq;
101780+ atomic_unchecked_t global_seq;
101781 };
101782
101783 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
101784@@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
101785 /* global sequence number */
101786 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
101787 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
101788- htonl(atomic_inc_return(&log->global_seq))))
101789+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
101790 goto nla_put_failure;
101791
101792 if (data_len) {
101793diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
101794index 8a779be..1551d4c 100644
101795--- a/net/netfilter/nft_compat.c
101796+++ b/net/netfilter/nft_compat.c
101797@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
101798 /* We want to reuse existing compat_to_user */
101799 old_fs = get_fs();
101800 set_fs(KERNEL_DS);
101801- t->compat_to_user(out, in);
101802+ t->compat_to_user((void __force_user *)out, in);
101803 set_fs(old_fs);
101804 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
101805 kfree(out);
101806@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
101807 /* We want to reuse existing compat_to_user */
101808 old_fs = get_fs();
101809 set_fs(KERNEL_DS);
101810- m->compat_to_user(out, in);
101811+ m->compat_to_user((void __force_user *)out, in);
101812 set_fs(old_fs);
101813 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
101814 kfree(out);
101815diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
101816new file mode 100644
101817index 0000000..c566332
101818--- /dev/null
101819+++ b/net/netfilter/xt_gradm.c
101820@@ -0,0 +1,51 @@
101821+/*
101822+ * gradm match for netfilter
101823