]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.15.5-201407100036.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.15.5-201407100036.patch
CommitLineData
f4d2025c
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 e6b01ed..74dbc85 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..b67388e 100644
2988--- a/arch/arm/kernel/ptrace.c
2989+++ b/arch/arm/kernel/ptrace.c
2990@@ -908,7 +908,7 @@ enum ptrace_syscall_dir {
2991 PTRACE_SYSCALL_EXIT,
2992 };
2993
2994-static int tracehook_report_syscall(struct pt_regs *regs,
2995+static void tracehook_report_syscall(struct pt_regs *regs,
2996 enum ptrace_syscall_dir dir)
2997 {
2998 unsigned long ip;
2999@@ -926,19 +926,29 @@ static int tracehook_report_syscall(struct pt_regs *regs,
3000 current_thread_info()->syscall = -1;
3001
3002 regs->ARM_ip = ip;
3003- return current_thread_info()->syscall;
3004 }
3005
3006+#ifdef CONFIG_GRKERNSEC_SETXID
3007+extern void gr_delayed_cred_worker(void);
3008+#endif
3009+
3010 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3011 {
3012 current_thread_info()->syscall = scno;
3013
3014+#ifdef CONFIG_GRKERNSEC_SETXID
3015+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3016+ gr_delayed_cred_worker();
3017+#endif
3018+
3019 /* Do the secure computing check first; failures should be fast. */
3020 if (secure_computing(scno) == -1)
3021 return -1;
3022
3023 if (test_thread_flag(TIF_SYSCALL_TRACE))
3024- scno = tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
3025+ tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
3026+
3027+ scno = current_thread_info()->syscall;
3028
3029 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
3030 trace_sys_enter(regs, scno);
3031diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3032index 50e198c..a8b5f49 100644
3033--- a/arch/arm/kernel/setup.c
3034+++ b/arch/arm/kernel/setup.c
3035@@ -103,21 +103,23 @@ EXPORT_SYMBOL(elf_hwcap);
3036 unsigned int elf_hwcap2 __read_mostly;
3037 EXPORT_SYMBOL(elf_hwcap2);
3038
3039+pteval_t __supported_pte_mask __read_only;
3040+pmdval_t __supported_pmd_mask __read_only;
3041
3042 #ifdef MULTI_CPU
3043-struct processor processor __read_mostly;
3044+struct processor processor __read_only;
3045 #endif
3046 #ifdef MULTI_TLB
3047-struct cpu_tlb_fns cpu_tlb __read_mostly;
3048+struct cpu_tlb_fns cpu_tlb __read_only;
3049 #endif
3050 #ifdef MULTI_USER
3051-struct cpu_user_fns cpu_user __read_mostly;
3052+struct cpu_user_fns cpu_user __read_only;
3053 #endif
3054 #ifdef MULTI_CACHE
3055-struct cpu_cache_fns cpu_cache __read_mostly;
3056+struct cpu_cache_fns cpu_cache __read_only;
3057 #endif
3058 #ifdef CONFIG_OUTER_CACHE
3059-struct outer_cache_fns outer_cache __read_mostly;
3060+struct outer_cache_fns outer_cache __read_only;
3061 EXPORT_SYMBOL(outer_cache);
3062 #endif
3063
3064@@ -250,9 +252,13 @@ static int __get_cpu_architecture(void)
3065 asm("mrc p15, 0, %0, c0, c1, 4"
3066 : "=r" (mmfr0));
3067 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3068- (mmfr0 & 0x000000f0) >= 0x00000030)
3069+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3070 cpu_arch = CPU_ARCH_ARMv7;
3071- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3072+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3073+ __supported_pte_mask |= L_PTE_PXN;
3074+ __supported_pmd_mask |= PMD_PXNTABLE;
3075+ }
3076+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3077 (mmfr0 & 0x000000f0) == 0x00000020)
3078 cpu_arch = CPU_ARCH_ARMv6;
3079 else
3080diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3081index bd19834..e4d8c66 100644
3082--- a/arch/arm/kernel/signal.c
3083+++ b/arch/arm/kernel/signal.c
3084@@ -24,8 +24,6 @@
3085
3086 extern const unsigned long sigreturn_codes[7];
3087
3088-static unsigned long signal_return_offset;
3089-
3090 #ifdef CONFIG_CRUNCH
3091 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3092 {
3093@@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3094 * except when the MPU has protected the vectors
3095 * page from PL0
3096 */
3097- retcode = mm->context.sigpage + signal_return_offset +
3098- (idx << 2) + thumb;
3099+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3100 } else
3101 #endif
3102 {
3103@@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3104 } while (thread_flags & _TIF_WORK_MASK);
3105 return 0;
3106 }
3107-
3108-struct page *get_signal_page(void)
3109-{
3110- unsigned long ptr;
3111- unsigned offset;
3112- struct page *page;
3113- void *addr;
3114-
3115- page = alloc_pages(GFP_KERNEL, 0);
3116-
3117- if (!page)
3118- return NULL;
3119-
3120- addr = page_address(page);
3121-
3122- /* Give the signal return code some randomness */
3123- offset = 0x200 + (get_random_int() & 0x7fc);
3124- signal_return_offset = offset;
3125-
3126- /*
3127- * Copy signal return handlers into the vector page, and
3128- * set sigreturn to be a pointer to these.
3129- */
3130- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3131-
3132- ptr = (unsigned long)addr + offset;
3133- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3134-
3135- return page;
3136-}
3137diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3138index 7c4fada..8581286 100644
3139--- a/arch/arm/kernel/smp.c
3140+++ b/arch/arm/kernel/smp.c
3141@@ -73,7 +73,7 @@ enum ipi_msg_type {
3142
3143 static DECLARE_COMPLETION(cpu_running);
3144
3145-static struct smp_operations smp_ops;
3146+static struct smp_operations smp_ops __read_only;
3147
3148 void __init smp_set_ops(struct smp_operations *ops)
3149 {
3150diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3151index 7a3be1d..b00c7de 100644
3152--- a/arch/arm/kernel/tcm.c
3153+++ b/arch/arm/kernel/tcm.c
3154@@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3155 .virtual = ITCM_OFFSET,
3156 .pfn = __phys_to_pfn(ITCM_OFFSET),
3157 .length = 0,
3158- .type = MT_MEMORY_RWX_ITCM,
3159+ .type = MT_MEMORY_RX_ITCM,
3160 }
3161 };
3162
3163@@ -267,7 +267,9 @@ no_dtcm:
3164 start = &__sitcm_text;
3165 end = &__eitcm_text;
3166 ram = &__itcm_start;
3167+ pax_open_kernel();
3168 memcpy(start, ram, itcm_code_sz);
3169+ pax_close_kernel();
3170 pr_debug("CPU ITCM: copied code from %p - %p\n",
3171 start, end);
3172 itcm_present = true;
3173diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3174index abd2fc0..895dbb6 100644
3175--- a/arch/arm/kernel/traps.c
3176+++ b/arch/arm/kernel/traps.c
3177@@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3178 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3179 {
3180 #ifdef CONFIG_KALLSYMS
3181- printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3182+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3183 #else
3184 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3185 #endif
3186@@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3187 static int die_owner = -1;
3188 static unsigned int die_nest_count;
3189
3190+extern void gr_handle_kernel_exploit(void);
3191+
3192 static unsigned long oops_begin(void)
3193 {
3194 int cpu;
3195@@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3196 panic("Fatal exception in interrupt");
3197 if (panic_on_oops)
3198 panic("Fatal exception");
3199+
3200+ gr_handle_kernel_exploit();
3201+
3202 if (signr)
3203 do_exit(signr);
3204 }
3205@@ -643,7 +648,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3206 * The user helper at 0xffff0fe0 must be used instead.
3207 * (see entry-armv.S for details)
3208 */
3209+ pax_open_kernel();
3210 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3211+ pax_close_kernel();
3212 }
3213 return 0;
3214
3215@@ -900,7 +907,11 @@ void __init early_trap_init(void *vectors_base)
3216 kuser_init(vectors_base);
3217
3218 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3219- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3220+
3221+#ifndef CONFIG_PAX_MEMORY_UDEREF
3222+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3223+#endif
3224+
3225 #else /* ifndef CONFIG_CPU_V7M */
3226 /*
3227 * on V7-M there is no need to copy the vector table to a dedicated
3228diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3229index 7bcee5c..e2f3249 100644
3230--- a/arch/arm/kernel/vmlinux.lds.S
3231+++ b/arch/arm/kernel/vmlinux.lds.S
3232@@ -8,7 +8,11 @@
3233 #include <asm/thread_info.h>
3234 #include <asm/memory.h>
3235 #include <asm/page.h>
3236-
3237+
3238+#ifdef CONFIG_PAX_KERNEXEC
3239+#include <asm/pgtable.h>
3240+#endif
3241+
3242 #define PROC_INFO \
3243 . = ALIGN(4); \
3244 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3245@@ -34,7 +38,7 @@
3246 #endif
3247
3248 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3249- defined(CONFIG_GENERIC_BUG)
3250+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3251 #define ARM_EXIT_KEEP(x) x
3252 #define ARM_EXIT_DISCARD(x)
3253 #else
3254@@ -90,6 +94,11 @@ SECTIONS
3255 _text = .;
3256 HEAD_TEXT
3257 }
3258+
3259+#ifdef CONFIG_PAX_KERNEXEC
3260+ . = ALIGN(1<<SECTION_SHIFT);
3261+#endif
3262+
3263 .text : { /* Real text segment */
3264 _stext = .; /* Text and read-only data */
3265 __exception_text_start = .;
3266@@ -112,6 +121,8 @@ SECTIONS
3267 ARM_CPU_KEEP(PROC_INFO)
3268 }
3269
3270+ _etext = .; /* End of text section */
3271+
3272 RO_DATA(PAGE_SIZE)
3273
3274 . = ALIGN(4);
3275@@ -142,7 +153,9 @@ SECTIONS
3276
3277 NOTES
3278
3279- _etext = .; /* End of text and rodata section */
3280+#ifdef CONFIG_PAX_KERNEXEC
3281+ . = ALIGN(1<<SECTION_SHIFT);
3282+#endif
3283
3284 #ifndef CONFIG_XIP_KERNEL
3285 . = ALIGN(PAGE_SIZE);
3286@@ -220,6 +233,11 @@ SECTIONS
3287 . = PAGE_OFFSET + TEXT_OFFSET;
3288 #else
3289 __init_end = .;
3290+
3291+#ifdef CONFIG_PAX_KERNEXEC
3292+ . = ALIGN(1<<SECTION_SHIFT);
3293+#endif
3294+
3295 . = ALIGN(THREAD_SIZE);
3296 __data_loc = .;
3297 #endif
3298diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3299index f0e50a0..8d5d36c 100644
3300--- a/arch/arm/kvm/arm.c
3301+++ b/arch/arm/kvm/arm.c
3302@@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3303 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3304
3305 /* The VMID used in the VTTBR */
3306-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3307+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3308 static u8 kvm_next_vmid;
3309 static DEFINE_SPINLOCK(kvm_vmid_lock);
3310
3311@@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3312 */
3313 static bool need_new_vmid_gen(struct kvm *kvm)
3314 {
3315- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3316+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3317 }
3318
3319 /**
3320@@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3321
3322 /* First user of a new VMID generation? */
3323 if (unlikely(kvm_next_vmid == 0)) {
3324- atomic64_inc(&kvm_vmid_gen);
3325+ atomic64_inc_unchecked(&kvm_vmid_gen);
3326 kvm_next_vmid = 1;
3327
3328 /*
3329@@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3330 kvm_call_hyp(__kvm_flush_vm_context);
3331 }
3332
3333- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3334+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3335 kvm->arch.vmid = kvm_next_vmid;
3336 kvm_next_vmid++;
3337
3338diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3339index 14a0d98..7771a7d 100644
3340--- a/arch/arm/lib/clear_user.S
3341+++ b/arch/arm/lib/clear_user.S
3342@@ -12,14 +12,14 @@
3343
3344 .text
3345
3346-/* Prototype: int __clear_user(void *addr, size_t sz)
3347+/* Prototype: int ___clear_user(void *addr, size_t sz)
3348 * Purpose : clear some user memory
3349 * Params : addr - user memory address to clear
3350 * : sz - number of bytes to clear
3351 * Returns : number of bytes NOT cleared
3352 */
3353 ENTRY(__clear_user_std)
3354-WEAK(__clear_user)
3355+WEAK(___clear_user)
3356 stmfd sp!, {r1, lr}
3357 mov r2, #0
3358 cmp r1, #4
3359@@ -44,7 +44,7 @@ WEAK(__clear_user)
3360 USER( strnebt r2, [r0])
3361 mov r0, #0
3362 ldmfd sp!, {r1, pc}
3363-ENDPROC(__clear_user)
3364+ENDPROC(___clear_user)
3365 ENDPROC(__clear_user_std)
3366
3367 .pushsection .fixup,"ax"
3368diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3369index 66a477a..bee61d3 100644
3370--- a/arch/arm/lib/copy_from_user.S
3371+++ b/arch/arm/lib/copy_from_user.S
3372@@ -16,7 +16,7 @@
3373 /*
3374 * Prototype:
3375 *
3376- * size_t __copy_from_user(void *to, const void *from, size_t n)
3377+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3378 *
3379 * Purpose:
3380 *
3381@@ -84,11 +84,11 @@
3382
3383 .text
3384
3385-ENTRY(__copy_from_user)
3386+ENTRY(___copy_from_user)
3387
3388 #include "copy_template.S"
3389
3390-ENDPROC(__copy_from_user)
3391+ENDPROC(___copy_from_user)
3392
3393 .pushsection .fixup,"ax"
3394 .align 0
3395diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3396index 6ee2f67..d1cce76 100644
3397--- a/arch/arm/lib/copy_page.S
3398+++ b/arch/arm/lib/copy_page.S
3399@@ -10,6 +10,7 @@
3400 * ASM optimised string functions
3401 */
3402 #include <linux/linkage.h>
3403+#include <linux/const.h>
3404 #include <asm/assembler.h>
3405 #include <asm/asm-offsets.h>
3406 #include <asm/cache.h>
3407diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3408index d066df6..df28194 100644
3409--- a/arch/arm/lib/copy_to_user.S
3410+++ b/arch/arm/lib/copy_to_user.S
3411@@ -16,7 +16,7 @@
3412 /*
3413 * Prototype:
3414 *
3415- * size_t __copy_to_user(void *to, const void *from, size_t n)
3416+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3417 *
3418 * Purpose:
3419 *
3420@@ -88,11 +88,11 @@
3421 .text
3422
3423 ENTRY(__copy_to_user_std)
3424-WEAK(__copy_to_user)
3425+WEAK(___copy_to_user)
3426
3427 #include "copy_template.S"
3428
3429-ENDPROC(__copy_to_user)
3430+ENDPROC(___copy_to_user)
3431 ENDPROC(__copy_to_user_std)
3432
3433 .pushsection .fixup,"ax"
3434diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3435index 7d08b43..f7ca7ea 100644
3436--- a/arch/arm/lib/csumpartialcopyuser.S
3437+++ b/arch/arm/lib/csumpartialcopyuser.S
3438@@ -57,8 +57,8 @@
3439 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3440 */
3441
3442-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3443-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3444+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3445+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3446
3447 #include "csumpartialcopygeneric.S"
3448
3449diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3450index 5306de3..aed6d03 100644
3451--- a/arch/arm/lib/delay.c
3452+++ b/arch/arm/lib/delay.c
3453@@ -28,7 +28,7 @@
3454 /*
3455 * Default to the loop-based delay implementation.
3456 */
3457-struct arm_delay_ops arm_delay_ops = {
3458+struct arm_delay_ops arm_delay_ops __read_only = {
3459 .delay = __loop_delay,
3460 .const_udelay = __loop_const_udelay,
3461 .udelay = __loop_udelay,
3462diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3463index 3e58d71..029817c 100644
3464--- a/arch/arm/lib/uaccess_with_memcpy.c
3465+++ b/arch/arm/lib/uaccess_with_memcpy.c
3466@@ -136,7 +136,7 @@ out:
3467 }
3468
3469 unsigned long
3470-__copy_to_user(void __user *to, const void *from, unsigned long n)
3471+___copy_to_user(void __user *to, const void *from, unsigned long n)
3472 {
3473 /*
3474 * This test is stubbed out of the main function above to keep
3475@@ -190,7 +190,7 @@ out:
3476 return n;
3477 }
3478
3479-unsigned long __clear_user(void __user *addr, unsigned long n)
3480+unsigned long ___clear_user(void __user *addr, unsigned long n)
3481 {
3482 /* See rational for this in __copy_to_user() above. */
3483 if (n < 64)
3484diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3485index f7a07a5..258e1f7 100644
3486--- a/arch/arm/mach-at91/setup.c
3487+++ b/arch/arm/mach-at91/setup.c
3488@@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3489
3490 desc->pfn = __phys_to_pfn(base);
3491 desc->length = length;
3492- desc->type = MT_MEMORY_RWX_NONCACHED;
3493+ desc->type = MT_MEMORY_RW_NONCACHED;
3494
3495 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3496 base, length, desc->virtual);
3497diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3498index 255f33a..507b157 100644
3499--- a/arch/arm/mach-kirkwood/common.c
3500+++ b/arch/arm/mach-kirkwood/common.c
3501@@ -157,7 +157,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3502 clk_gate_ops.disable(hw);
3503 }
3504
3505-static struct clk_ops clk_gate_fn_ops;
3506+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3507+{
3508+ return clk_gate_ops.is_enabled(hw);
3509+}
3510+
3511+static struct clk_ops clk_gate_fn_ops = {
3512+ .enable = clk_gate_fn_enable,
3513+ .disable = clk_gate_fn_disable,
3514+ .is_enabled = clk_gate_fn_is_enabled,
3515+};
3516
3517 static struct clk __init *clk_register_gate_fn(struct device *dev,
3518 const char *name,
3519@@ -191,14 +200,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3520 gate_fn->fn_en = fn_en;
3521 gate_fn->fn_dis = fn_dis;
3522
3523- /* ops is the gate ops, but with our enable/disable functions */
3524- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3525- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3526- clk_gate_fn_ops = clk_gate_ops;
3527- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3528- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3529- }
3530-
3531 clk = clk_register(dev, &gate_fn->gate.hw);
3532
3533 if (IS_ERR(clk))
3534diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3535index aead77a..a2253fa 100644
3536--- a/arch/arm/mach-omap2/board-n8x0.c
3537+++ b/arch/arm/mach-omap2/board-n8x0.c
3538@@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3539 }
3540 #endif
3541
3542-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3543+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3544 .late_init = n8x0_menelaus_late_init,
3545 };
3546
3547diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3548index 9fe8c94..c014a4d 100644
3549--- a/arch/arm/mach-omap2/gpmc.c
3550+++ b/arch/arm/mach-omap2/gpmc.c
3551@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3552 };
3553
3554 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3555-static struct irq_chip gpmc_irq_chip;
3556 static int gpmc_irq_start;
3557
3558 static struct resource gpmc_mem_root;
3559@@ -727,6 +726,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3560
3561 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3562
3563+static struct irq_chip gpmc_irq_chip = {
3564+ .name = "gpmc",
3565+ .irq_startup = gpmc_irq_noop_ret,
3566+ .irq_enable = gpmc_irq_enable,
3567+ .irq_disable = gpmc_irq_disable,
3568+ .irq_shutdown = gpmc_irq_noop,
3569+ .irq_ack = gpmc_irq_noop,
3570+ .irq_mask = gpmc_irq_noop,
3571+ .irq_unmask = gpmc_irq_noop,
3572+
3573+};
3574+
3575 static int gpmc_setup_irq(void)
3576 {
3577 int i;
3578@@ -741,15 +752,6 @@ static int gpmc_setup_irq(void)
3579 return gpmc_irq_start;
3580 }
3581
3582- gpmc_irq_chip.name = "gpmc";
3583- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3584- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3585- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3586- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3587- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3588- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3589- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3590-
3591 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3592 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3593
3594diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3595index 667915d..2ee1219 100644
3596--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3597+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3598@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3599 int (*finish_suspend)(unsigned long cpu_state);
3600 void (*resume)(void);
3601 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3602-};
3603+} __no_const;
3604
3605 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3606 static struct powerdomain *mpuss_pd;
3607@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3608 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3609 {}
3610
3611-struct cpu_pm_ops omap_pm_ops = {
3612+static struct cpu_pm_ops omap_pm_ops __read_only = {
3613 .finish_suspend = default_finish_suspend,
3614 .resume = dummy_cpu_resume,
3615 .scu_prepare = dummy_scu_prepare,
3616diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3617index 693fe48..c15ea73 100644
3618--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3619+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3620@@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3621 return NOTIFY_OK;
3622 }
3623
3624-static struct notifier_block __refdata irq_hotplug_notifier = {
3625+static struct notifier_block irq_hotplug_notifier = {
3626 .notifier_call = irq_cpu_hotplug_notify,
3627 };
3628
3629diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3630index 01ef59d..32ae28a8 100644
3631--- a/arch/arm/mach-omap2/omap_device.c
3632+++ b/arch/arm/mach-omap2/omap_device.c
3633@@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3634 struct platform_device __init *omap_device_build(const char *pdev_name,
3635 int pdev_id,
3636 struct omap_hwmod *oh,
3637- void *pdata, int pdata_len)
3638+ const void *pdata, int pdata_len)
3639 {
3640 struct omap_hwmod *ohs[] = { oh };
3641
3642@@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3643 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3644 int pdev_id,
3645 struct omap_hwmod **ohs,
3646- int oh_cnt, void *pdata,
3647+ int oh_cnt, const void *pdata,
3648 int pdata_len)
3649 {
3650 int ret = -ENOMEM;
3651diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3652index 78c02b3..c94109a 100644
3653--- a/arch/arm/mach-omap2/omap_device.h
3654+++ b/arch/arm/mach-omap2/omap_device.h
3655@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3656 /* Core code interface */
3657
3658 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3659- struct omap_hwmod *oh, void *pdata,
3660+ struct omap_hwmod *oh, const void *pdata,
3661 int pdata_len);
3662
3663 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3664 struct omap_hwmod **oh, int oh_cnt,
3665- void *pdata, int pdata_len);
3666+ const void *pdata, int pdata_len);
3667
3668 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3669 struct omap_hwmod **ohs, int oh_cnt);
3670diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3671index 66c60fe..c78950d 100644
3672--- a/arch/arm/mach-omap2/omap_hwmod.c
3673+++ b/arch/arm/mach-omap2/omap_hwmod.c
3674@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3675 int (*init_clkdm)(struct omap_hwmod *oh);
3676 void (*update_context_lost)(struct omap_hwmod *oh);
3677 int (*get_context_lost)(struct omap_hwmod *oh);
3678-};
3679+} __no_const;
3680
3681 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3682-static struct omap_hwmod_soc_ops soc_ops;
3683+static struct omap_hwmod_soc_ops soc_ops __read_only;
3684
3685 /* omap_hwmod_list contains all registered struct omap_hwmods */
3686 static LIST_HEAD(omap_hwmod_list);
3687diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3688index 95fee54..cfa9cf1 100644
3689--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3690+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3691@@ -10,6 +10,7 @@
3692
3693 #include <linux/kernel.h>
3694 #include <linux/init.h>
3695+#include <asm/pgtable.h>
3696
3697 #include "powerdomain.h"
3698
3699@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3700
3701 void __init am43xx_powerdomains_init(void)
3702 {
3703- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3704+ pax_open_kernel();
3705+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3706+ pax_close_kernel();
3707 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3708 pwrdm_register_pwrdms(powerdomains_am43xx);
3709 pwrdm_complete_init();
3710diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3711index d15c7bb..b2d1f0c 100644
3712--- a/arch/arm/mach-omap2/wd_timer.c
3713+++ b/arch/arm/mach-omap2/wd_timer.c
3714@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3715 struct omap_hwmod *oh;
3716 char *oh_name = "wd_timer2";
3717 char *dev_name = "omap_wdt";
3718- struct omap_wd_timer_platform_data pdata;
3719+ static struct omap_wd_timer_platform_data pdata = {
3720+ .read_reset_sources = prm_read_reset_sources
3721+ };
3722
3723 if (!cpu_class_is_omap2() || of_have_populated_dt())
3724 return 0;
3725@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3726 return -EINVAL;
3727 }
3728
3729- pdata.read_reset_sources = prm_read_reset_sources;
3730-
3731 pdev = omap_device_build(dev_name, id, oh, &pdata,
3732 sizeof(struct omap_wd_timer_platform_data));
3733 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3734diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3735index b82dcae..44ee5b6 100644
3736--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3737+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3738@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3739 bool entered_lp2 = false;
3740
3741 if (tegra_pending_sgi())
3742- ACCESS_ONCE(abort_flag) = true;
3743+ ACCESS_ONCE_RW(abort_flag) = true;
3744
3745 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3746
3747diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3748index 2dea8b5..6499da2 100644
3749--- a/arch/arm/mach-ux500/setup.h
3750+++ b/arch/arm/mach-ux500/setup.h
3751@@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3752 .type = MT_DEVICE, \
3753 }
3754
3755-#define __MEM_DEV_DESC(x, sz) { \
3756- .virtual = IO_ADDRESS(x), \
3757- .pfn = __phys_to_pfn(x), \
3758- .length = sz, \
3759- .type = MT_MEMORY_RWX, \
3760-}
3761-
3762 extern struct smp_operations ux500_smp_ops;
3763 extern void ux500_cpu_die(unsigned int cpu);
3764
3765diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3766index 5bf7c3c..571e67e 100644
3767--- a/arch/arm/mm/Kconfig
3768+++ b/arch/arm/mm/Kconfig
3769@@ -446,6 +446,7 @@ config CPU_32v5
3770
3771 config CPU_32v6
3772 bool
3773+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3774 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3775
3776 config CPU_32v6K
3777@@ -600,6 +601,7 @@ config CPU_CP15_MPU
3778
3779 config CPU_USE_DOMAINS
3780 bool
3781+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3782 help
3783 This option enables or disables the use of domain switching
3784 via the set_fs() function.
3785@@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
3786 config KUSER_HELPERS
3787 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3788 default y
3789+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3790 help
3791 Warning: disabling this option may break user programs.
3792
3793@@ -811,7 +814,7 @@ config KUSER_HELPERS
3794 See Documentation/arm/kernel_user_helpers.txt for details.
3795
3796 However, the fixed address nature of these helpers can be used
3797- by ROP (return orientated programming) authors when creating
3798+ by ROP (Return Oriented Programming) authors when creating
3799 exploits.
3800
3801 If all of the binaries and libraries which run on your platform
3802diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3803index 9240364..a2b8cf3 100644
3804--- a/arch/arm/mm/alignment.c
3805+++ b/arch/arm/mm/alignment.c
3806@@ -212,10 +212,12 @@ union offset_union {
3807 #define __get16_unaligned_check(ins,val,addr) \
3808 do { \
3809 unsigned int err = 0, v, a = addr; \
3810+ pax_open_userland(); \
3811 __get8_unaligned_check(ins,v,a,err); \
3812 val = v << ((BE) ? 8 : 0); \
3813 __get8_unaligned_check(ins,v,a,err); \
3814 val |= v << ((BE) ? 0 : 8); \
3815+ pax_close_userland(); \
3816 if (err) \
3817 goto fault; \
3818 } while (0)
3819@@ -229,6 +231,7 @@ union offset_union {
3820 #define __get32_unaligned_check(ins,val,addr) \
3821 do { \
3822 unsigned int err = 0, v, a = addr; \
3823+ pax_open_userland(); \
3824 __get8_unaligned_check(ins,v,a,err); \
3825 val = v << ((BE) ? 24 : 0); \
3826 __get8_unaligned_check(ins,v,a,err); \
3827@@ -237,6 +240,7 @@ union offset_union {
3828 val |= v << ((BE) ? 8 : 16); \
3829 __get8_unaligned_check(ins,v,a,err); \
3830 val |= v << ((BE) ? 0 : 24); \
3831+ pax_close_userland(); \
3832 if (err) \
3833 goto fault; \
3834 } while (0)
3835@@ -250,6 +254,7 @@ union offset_union {
3836 #define __put16_unaligned_check(ins,val,addr) \
3837 do { \
3838 unsigned int err = 0, v = val, a = addr; \
3839+ pax_open_userland(); \
3840 __asm__( FIRST_BYTE_16 \
3841 ARM( "1: "ins" %1, [%2], #1\n" ) \
3842 THUMB( "1: "ins" %1, [%2]\n" ) \
3843@@ -269,6 +274,7 @@ union offset_union {
3844 " .popsection\n" \
3845 : "=r" (err), "=&r" (v), "=&r" (a) \
3846 : "0" (err), "1" (v), "2" (a)); \
3847+ pax_close_userland(); \
3848 if (err) \
3849 goto fault; \
3850 } while (0)
3851@@ -282,6 +288,7 @@ union offset_union {
3852 #define __put32_unaligned_check(ins,val,addr) \
3853 do { \
3854 unsigned int err = 0, v = val, a = addr; \
3855+ pax_open_userland(); \
3856 __asm__( FIRST_BYTE_32 \
3857 ARM( "1: "ins" %1, [%2], #1\n" ) \
3858 THUMB( "1: "ins" %1, [%2]\n" ) \
3859@@ -311,6 +318,7 @@ union offset_union {
3860 " .popsection\n" \
3861 : "=r" (err), "=&r" (v), "=&r" (a) \
3862 : "0" (err), "1" (v), "2" (a)); \
3863+ pax_close_userland(); \
3864 if (err) \
3865 goto fault; \
3866 } while (0)
3867diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3868index 7abde2c..9df495f 100644
3869--- a/arch/arm/mm/cache-l2x0.c
3870+++ b/arch/arm/mm/cache-l2x0.c
3871@@ -46,7 +46,7 @@ struct l2x0_of_data {
3872 void (*setup)(const struct device_node *, u32 *, u32 *);
3873 void (*save)(void);
3874 struct outer_cache_fns outer_cache;
3875-};
3876+} __do_const;
3877
3878 static bool of_init = false;
3879
3880diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3881index 6eb97b3..ac509f6 100644
3882--- a/arch/arm/mm/context.c
3883+++ b/arch/arm/mm/context.c
3884@@ -43,7 +43,7 @@
3885 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3886
3887 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3888-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3889+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3890 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3891
3892 static DEFINE_PER_CPU(atomic64_t, active_asids);
3893@@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3894 {
3895 static u32 cur_idx = 1;
3896 u64 asid = atomic64_read(&mm->context.id);
3897- u64 generation = atomic64_read(&asid_generation);
3898+ u64 generation = atomic64_read_unchecked(&asid_generation);
3899
3900 if (asid != 0 && is_reserved_asid(asid)) {
3901 /*
3902@@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3903 */
3904 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3905 if (asid == NUM_USER_ASIDS) {
3906- generation = atomic64_add_return(ASID_FIRST_VERSION,
3907+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3908 &asid_generation);
3909 flush_context(cpu);
3910 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3911@@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3912 cpu_set_reserved_ttbr0();
3913
3914 asid = atomic64_read(&mm->context.id);
3915- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3916+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3917 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3918 goto switch_mm_fastpath;
3919
3920 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3921 /* Check that our ASID belongs to the current generation. */
3922 asid = atomic64_read(&mm->context.id);
3923- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3924+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3925 asid = new_context(mm, cpu);
3926 atomic64_set(&mm->context.id, asid);
3927 }
3928diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3929index eb8830a..5360ce7 100644
3930--- a/arch/arm/mm/fault.c
3931+++ b/arch/arm/mm/fault.c
3932@@ -25,6 +25,7 @@
3933 #include <asm/system_misc.h>
3934 #include <asm/system_info.h>
3935 #include <asm/tlbflush.h>
3936+#include <asm/sections.h>
3937
3938 #include "fault.h"
3939
3940@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3941 if (fixup_exception(regs))
3942 return;
3943
3944+#ifdef CONFIG_PAX_MEMORY_UDEREF
3945+ if (addr < TASK_SIZE) {
3946+ if (current->signal->curr_ip)
3947+ 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),
3948+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3949+ else
3950+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3951+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3952+ }
3953+#endif
3954+
3955+#ifdef CONFIG_PAX_KERNEXEC
3956+ if ((fsr & FSR_WRITE) &&
3957+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3958+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3959+ {
3960+ if (current->signal->curr_ip)
3961+ 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),
3962+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3963+ else
3964+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3965+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3966+ }
3967+#endif
3968+
3969 /*
3970 * No handler, we'll have to terminate things with extreme prejudice.
3971 */
3972@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3973 }
3974 #endif
3975
3976+#ifdef CONFIG_PAX_PAGEEXEC
3977+ if (fsr & FSR_LNX_PF) {
3978+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3979+ do_group_exit(SIGKILL);
3980+ }
3981+#endif
3982+
3983 tsk->thread.address = addr;
3984 tsk->thread.error_code = fsr;
3985 tsk->thread.trap_no = 14;
3986@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3987 }
3988 #endif /* CONFIG_MMU */
3989
3990+#ifdef CONFIG_PAX_PAGEEXEC
3991+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3992+{
3993+ long i;
3994+
3995+ printk(KERN_ERR "PAX: bytes at PC: ");
3996+ for (i = 0; i < 20; i++) {
3997+ unsigned char c;
3998+ if (get_user(c, (__force unsigned char __user *)pc+i))
3999+ printk(KERN_CONT "?? ");
4000+ else
4001+ printk(KERN_CONT "%02x ", c);
4002+ }
4003+ printk("\n");
4004+
4005+ printk(KERN_ERR "PAX: bytes at SP-4: ");
4006+ for (i = -1; i < 20; i++) {
4007+ unsigned long c;
4008+ if (get_user(c, (__force unsigned long __user *)sp+i))
4009+ printk(KERN_CONT "???????? ");
4010+ else
4011+ printk(KERN_CONT "%08lx ", c);
4012+ }
4013+ printk("\n");
4014+}
4015+#endif
4016+
4017 /*
4018 * First Level Translation Fault Handler
4019 *
4020@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4021 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4022 struct siginfo info;
4023
4024+#ifdef CONFIG_PAX_MEMORY_UDEREF
4025+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4026+ if (current->signal->curr_ip)
4027+ 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),
4028+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4029+ else
4030+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4031+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4032+ goto die;
4033+ }
4034+#endif
4035+
4036 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4037 return;
4038
4039+die:
4040 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4041 inf->name, fsr, addr);
4042
4043@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4044 ifsr_info[nr].name = name;
4045 }
4046
4047+asmlinkage int sys_sigreturn(struct pt_regs *regs);
4048+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4049+
4050 asmlinkage void __exception
4051 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4052 {
4053 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4054 struct siginfo info;
4055+ unsigned long pc = instruction_pointer(regs);
4056+
4057+ if (user_mode(regs)) {
4058+ unsigned long sigpage = current->mm->context.sigpage;
4059+
4060+ if (sigpage <= pc && pc < sigpage + 7*4) {
4061+ if (pc < sigpage + 3*4)
4062+ sys_sigreturn(regs);
4063+ else
4064+ sys_rt_sigreturn(regs);
4065+ return;
4066+ }
4067+ if (pc == 0xffff0f60UL) {
4068+ /*
4069+ * PaX: __kuser_cmpxchg64 emulation
4070+ */
4071+ // TODO
4072+ //regs->ARM_pc = regs->ARM_lr;
4073+ //return;
4074+ }
4075+ if (pc == 0xffff0fa0UL) {
4076+ /*
4077+ * PaX: __kuser_memory_barrier emulation
4078+ */
4079+ // dmb(); implied by the exception
4080+ regs->ARM_pc = regs->ARM_lr;
4081+ return;
4082+ }
4083+ if (pc == 0xffff0fc0UL) {
4084+ /*
4085+ * PaX: __kuser_cmpxchg emulation
4086+ */
4087+ // TODO
4088+ //long new;
4089+ //int op;
4090+
4091+ //op = FUTEX_OP_SET << 28;
4092+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4093+ //regs->ARM_r0 = old != new;
4094+ //regs->ARM_pc = regs->ARM_lr;
4095+ //return;
4096+ }
4097+ if (pc == 0xffff0fe0UL) {
4098+ /*
4099+ * PaX: __kuser_get_tls emulation
4100+ */
4101+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4102+ regs->ARM_pc = regs->ARM_lr;
4103+ return;
4104+ }
4105+ }
4106+
4107+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4108+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4109+ if (current->signal->curr_ip)
4110+ 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),
4111+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4112+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4113+ else
4114+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4115+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4116+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4117+ goto die;
4118+ }
4119+#endif
4120+
4121+#ifdef CONFIG_PAX_REFCOUNT
4122+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4123+ unsigned int bkpt;
4124+
4125+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4126+ current->thread.error_code = ifsr;
4127+ current->thread.trap_no = 0;
4128+ pax_report_refcount_overflow(regs);
4129+ fixup_exception(regs);
4130+ return;
4131+ }
4132+ }
4133+#endif
4134
4135 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4136 return;
4137
4138+die:
4139 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4140 inf->name, ifsr, addr);
4141
4142diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4143index cf08bdf..772656c 100644
4144--- a/arch/arm/mm/fault.h
4145+++ b/arch/arm/mm/fault.h
4146@@ -3,6 +3,7 @@
4147
4148 /*
4149 * Fault status register encodings. We steal bit 31 for our own purposes.
4150+ * Set when the FSR value is from an instruction fault.
4151 */
4152 #define FSR_LNX_PF (1 << 31)
4153 #define FSR_WRITE (1 << 11)
4154@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4155 }
4156 #endif
4157
4158+/* valid for LPAE and !LPAE */
4159+static inline int is_xn_fault(unsigned int fsr)
4160+{
4161+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4162+}
4163+
4164+static inline int is_domain_fault(unsigned int fsr)
4165+{
4166+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4167+}
4168+
4169 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4170 unsigned long search_exception_table(unsigned long addr);
4171
4172diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4173index 2a77ba8..68e6a7a 100644
4174--- a/arch/arm/mm/init.c
4175+++ b/arch/arm/mm/init.c
4176@@ -30,6 +30,8 @@
4177 #include <asm/setup.h>
4178 #include <asm/tlb.h>
4179 #include <asm/fixmap.h>
4180+#include <asm/system_info.h>
4181+#include <asm/cp15.h>
4182
4183 #include <asm/mach/arch.h>
4184 #include <asm/mach/map.h>
4185@@ -627,7 +629,46 @@ void free_initmem(void)
4186 {
4187 #ifdef CONFIG_HAVE_TCM
4188 extern char __tcm_start, __tcm_end;
4189+#endif
4190
4191+#ifdef CONFIG_PAX_KERNEXEC
4192+ unsigned long addr;
4193+ pgd_t *pgd;
4194+ pud_t *pud;
4195+ pmd_t *pmd;
4196+ int cpu_arch = cpu_architecture();
4197+ unsigned int cr = get_cr();
4198+
4199+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4200+ /* make pages tables, etc before .text NX */
4201+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4202+ pgd = pgd_offset_k(addr);
4203+ pud = pud_offset(pgd, addr);
4204+ pmd = pmd_offset(pud, addr);
4205+ __section_update(pmd, addr, PMD_SECT_XN);
4206+ }
4207+ /* make init NX */
4208+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4209+ pgd = pgd_offset_k(addr);
4210+ pud = pud_offset(pgd, addr);
4211+ pmd = pmd_offset(pud, addr);
4212+ __section_update(pmd, addr, PMD_SECT_XN);
4213+ }
4214+ /* make kernel code/rodata RX */
4215+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4216+ pgd = pgd_offset_k(addr);
4217+ pud = pud_offset(pgd, addr);
4218+ pmd = pmd_offset(pud, addr);
4219+#ifdef CONFIG_ARM_LPAE
4220+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4221+#else
4222+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4223+#endif
4224+ }
4225+ }
4226+#endif
4227+
4228+#ifdef CONFIG_HAVE_TCM
4229 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4230 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4231 #endif
4232diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4233index f9c32ba..8540068 100644
4234--- a/arch/arm/mm/ioremap.c
4235+++ b/arch/arm/mm/ioremap.c
4236@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4237 unsigned int mtype;
4238
4239 if (cached)
4240- mtype = MT_MEMORY_RWX;
4241+ mtype = MT_MEMORY_RX;
4242 else
4243- mtype = MT_MEMORY_RWX_NONCACHED;
4244+ mtype = MT_MEMORY_RX_NONCACHED;
4245
4246 return __arm_ioremap_caller(phys_addr, size, mtype,
4247 __builtin_return_address(0));
4248diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4249index 5e85ed3..b10a7ed 100644
4250--- a/arch/arm/mm/mmap.c
4251+++ b/arch/arm/mm/mmap.c
4252@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4253 struct vm_area_struct *vma;
4254 int do_align = 0;
4255 int aliasing = cache_is_vipt_aliasing();
4256+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4257 struct vm_unmapped_area_info info;
4258
4259 /*
4260@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4261 if (len > TASK_SIZE)
4262 return -ENOMEM;
4263
4264+#ifdef CONFIG_PAX_RANDMMAP
4265+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4266+#endif
4267+
4268 if (addr) {
4269 if (do_align)
4270 addr = COLOUR_ALIGN(addr, pgoff);
4271@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4272 addr = PAGE_ALIGN(addr);
4273
4274 vma = find_vma(mm, addr);
4275- if (TASK_SIZE - len >= addr &&
4276- (!vma || addr + len <= vma->vm_start))
4277+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4278 return addr;
4279 }
4280
4281@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4282 info.high_limit = TASK_SIZE;
4283 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4284 info.align_offset = pgoff << PAGE_SHIFT;
4285+ info.threadstack_offset = offset;
4286 return vm_unmapped_area(&info);
4287 }
4288
4289@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4290 unsigned long addr = addr0;
4291 int do_align = 0;
4292 int aliasing = cache_is_vipt_aliasing();
4293+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4294 struct vm_unmapped_area_info info;
4295
4296 /*
4297@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4298 return addr;
4299 }
4300
4301+#ifdef CONFIG_PAX_RANDMMAP
4302+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4303+#endif
4304+
4305 /* requesting a specific address */
4306 if (addr) {
4307 if (do_align)
4308@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4309 else
4310 addr = PAGE_ALIGN(addr);
4311 vma = find_vma(mm, addr);
4312- if (TASK_SIZE - len >= addr &&
4313- (!vma || addr + len <= vma->vm_start))
4314+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4315 return addr;
4316 }
4317
4318@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4319 info.high_limit = mm->mmap_base;
4320 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4321 info.align_offset = pgoff << PAGE_SHIFT;
4322+ info.threadstack_offset = offset;
4323 addr = vm_unmapped_area(&info);
4324
4325 /*
4326@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4327 {
4328 unsigned long random_factor = 0UL;
4329
4330+#ifdef CONFIG_PAX_RANDMMAP
4331+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4332+#endif
4333+
4334 /* 8 bits of randomness in 20 address space bits */
4335 if ((current->flags & PF_RANDOMIZE) &&
4336 !(current->personality & ADDR_NO_RANDOMIZE))
4337@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4338
4339 if (mmap_is_legacy()) {
4340 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4341+
4342+#ifdef CONFIG_PAX_RANDMMAP
4343+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4344+ mm->mmap_base += mm->delta_mmap;
4345+#endif
4346+
4347 mm->get_unmapped_area = arch_get_unmapped_area;
4348 } else {
4349 mm->mmap_base = mmap_base(random_factor);
4350+
4351+#ifdef CONFIG_PAX_RANDMMAP
4352+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4353+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4354+#endif
4355+
4356 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4357 }
4358 }
4359diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4360index b68c6b2..f66c492 100644
4361--- a/arch/arm/mm/mmu.c
4362+++ b/arch/arm/mm/mmu.c
4363@@ -39,6 +39,22 @@
4364 #include "mm.h"
4365 #include "tcm.h"
4366
4367+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4368+void modify_domain(unsigned int dom, unsigned int type)
4369+{
4370+ struct thread_info *thread = current_thread_info();
4371+ unsigned int domain = thread->cpu_domain;
4372+ /*
4373+ * DOMAIN_MANAGER might be defined to some other value,
4374+ * use the arch-defined constant
4375+ */
4376+ domain &= ~domain_val(dom, 3);
4377+ thread->cpu_domain = domain | domain_val(dom, type);
4378+ set_domain(thread->cpu_domain);
4379+}
4380+EXPORT_SYMBOL(modify_domain);
4381+#endif
4382+
4383 /*
4384 * empty_zero_page is a special page that is used for
4385 * zero-initialized data and COW.
4386@@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4387 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4388 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4389
4390-static struct mem_type mem_types[] = {
4391+#ifdef CONFIG_PAX_KERNEXEC
4392+#define L_PTE_KERNEXEC L_PTE_RDONLY
4393+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4394+#else
4395+#define L_PTE_KERNEXEC L_PTE_DIRTY
4396+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4397+#endif
4398+
4399+static struct mem_type mem_types[] __read_only = {
4400 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4401 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4402 L_PTE_SHARED,
4403@@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4404 .prot_sect = PROT_SECT_DEVICE,
4405 .domain = DOMAIN_IO,
4406 },
4407- [MT_UNCACHED] = {
4408+ [MT_UNCACHED_RW] = {
4409 .prot_pte = PROT_PTE_DEVICE,
4410 .prot_l1 = PMD_TYPE_TABLE,
4411 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4412 .domain = DOMAIN_IO,
4413 },
4414- [MT_CACHECLEAN] = {
4415- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4416+ [MT_CACHECLEAN_RO] = {
4417+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4418 .domain = DOMAIN_KERNEL,
4419 },
4420 #ifndef CONFIG_ARM_LPAE
4421- [MT_MINICLEAN] = {
4422- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4423+ [MT_MINICLEAN_RO] = {
4424+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4425 .domain = DOMAIN_KERNEL,
4426 },
4427 #endif
4428@@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4429 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4430 L_PTE_RDONLY,
4431 .prot_l1 = PMD_TYPE_TABLE,
4432- .domain = DOMAIN_USER,
4433+ .domain = DOMAIN_VECTORS,
4434 },
4435 [MT_HIGH_VECTORS] = {
4436 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4437 L_PTE_USER | L_PTE_RDONLY,
4438 .prot_l1 = PMD_TYPE_TABLE,
4439- .domain = DOMAIN_USER,
4440+ .domain = DOMAIN_VECTORS,
4441 },
4442- [MT_MEMORY_RWX] = {
4443+ [__MT_MEMORY_RWX] = {
4444 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4445 .prot_l1 = PMD_TYPE_TABLE,
4446 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4447@@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4448 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4449 .domain = DOMAIN_KERNEL,
4450 },
4451- [MT_ROM] = {
4452- .prot_sect = PMD_TYPE_SECT,
4453+ [MT_MEMORY_RX] = {
4454+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4455+ .prot_l1 = PMD_TYPE_TABLE,
4456+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4457+ .domain = DOMAIN_KERNEL,
4458+ },
4459+ [MT_ROM_RX] = {
4460+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4461 .domain = DOMAIN_KERNEL,
4462 },
4463- [MT_MEMORY_RWX_NONCACHED] = {
4464+ [MT_MEMORY_RW_NONCACHED] = {
4465 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4466 L_PTE_MT_BUFFERABLE,
4467 .prot_l1 = PMD_TYPE_TABLE,
4468 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4469 .domain = DOMAIN_KERNEL,
4470 },
4471+ [MT_MEMORY_RX_NONCACHED] = {
4472+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4473+ L_PTE_MT_BUFFERABLE,
4474+ .prot_l1 = PMD_TYPE_TABLE,
4475+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4476+ .domain = DOMAIN_KERNEL,
4477+ },
4478 [MT_MEMORY_RW_DTCM] = {
4479 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4480 L_PTE_XN,
4481@@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4482 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4483 .domain = DOMAIN_KERNEL,
4484 },
4485- [MT_MEMORY_RWX_ITCM] = {
4486- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4487+ [MT_MEMORY_RX_ITCM] = {
4488+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4489 .prot_l1 = PMD_TYPE_TABLE,
4490+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4491 .domain = DOMAIN_KERNEL,
4492 },
4493 [MT_MEMORY_RW_SO] = {
4494@@ -534,9 +572,14 @@ static void __init build_mem_type_table(void)
4495 * Mark cache clean areas and XIP ROM read only
4496 * from SVC mode and no access from userspace.
4497 */
4498- mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4499- mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4500- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4501+ mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4502+#ifdef CONFIG_PAX_KERNEXEC
4503+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4504+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4505+ mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4506+#endif
4507+ mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4508+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4509 #endif
4510
4511 if (is_smp()) {
4512@@ -552,13 +595,17 @@ static void __init build_mem_type_table(void)
4513 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4514 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4515 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4516- mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4517- mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4518+ mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4519+ mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4520 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4521 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4522+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4523+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4524 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4525- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4526- mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4527+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4528+ mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4529+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4530+ mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4531 }
4532 }
4533
4534@@ -569,15 +616,20 @@ static void __init build_mem_type_table(void)
4535 if (cpu_arch >= CPU_ARCH_ARMv6) {
4536 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4537 /* Non-cacheable Normal is XCB = 001 */
4538- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4539+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4540+ PMD_SECT_BUFFERED;
4541+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4542 PMD_SECT_BUFFERED;
4543 } else {
4544 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4545- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4546+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4547+ PMD_SECT_TEX(1);
4548+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4549 PMD_SECT_TEX(1);
4550 }
4551 } else {
4552- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4553+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4554+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4555 }
4556
4557 #ifdef CONFIG_ARM_LPAE
4558@@ -593,6 +645,8 @@ static void __init build_mem_type_table(void)
4559 vecs_pgprot |= PTE_EXT_AF;
4560 #endif
4561
4562+ user_pgprot |= __supported_pte_mask;
4563+
4564 for (i = 0; i < 16; i++) {
4565 pteval_t v = pgprot_val(protection_map[i]);
4566 protection_map[i] = __pgprot(v | user_pgprot);
4567@@ -610,21 +664,24 @@ static void __init build_mem_type_table(void)
4568
4569 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4570 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4571- mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4572- mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4573+ mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4574+ mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4575 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4576 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4577+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4578+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4579 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4580- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4581- mem_types[MT_ROM].prot_sect |= cp->pmd;
4582+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4583+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4584+ mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4585
4586 switch (cp->pmd) {
4587 case PMD_SECT_WT:
4588- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4589+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4590 break;
4591 case PMD_SECT_WB:
4592 case PMD_SECT_WBWA:
4593- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4594+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4595 break;
4596 }
4597 pr_info("Memory policy: %sData cache %s\n",
4598@@ -842,7 +899,7 @@ static void __init create_mapping(struct map_desc *md)
4599 return;
4600 }
4601
4602- if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4603+ if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4604 md->virtual >= PAGE_OFFSET &&
4605 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4606 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4607@@ -1257,18 +1314,15 @@ void __init arm_mm_memblock_reserve(void)
4608 * called function. This means you can't use any function or debugging
4609 * method which may touch any device, otherwise the kernel _will_ crash.
4610 */
4611+
4612+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4613+
4614 static void __init devicemaps_init(const struct machine_desc *mdesc)
4615 {
4616 struct map_desc map;
4617 unsigned long addr;
4618- void *vectors;
4619
4620- /*
4621- * Allocate the vector page early.
4622- */
4623- vectors = early_alloc(PAGE_SIZE * 2);
4624-
4625- early_trap_init(vectors);
4626+ early_trap_init(&vectors);
4627
4628 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4629 pmd_clear(pmd_off_k(addr));
4630@@ -1281,7 +1335,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4631 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4632 map.virtual = MODULES_VADDR;
4633 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4634- map.type = MT_ROM;
4635+ map.type = MT_ROM_RX;
4636 create_mapping(&map);
4637 #endif
4638
4639@@ -1292,14 +1346,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4640 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4641 map.virtual = FLUSH_BASE;
4642 map.length = SZ_1M;
4643- map.type = MT_CACHECLEAN;
4644+ map.type = MT_CACHECLEAN_RO;
4645 create_mapping(&map);
4646 #endif
4647 #ifdef FLUSH_BASE_MINICACHE
4648 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4649 map.virtual = FLUSH_BASE_MINICACHE;
4650 map.length = SZ_1M;
4651- map.type = MT_MINICLEAN;
4652+ map.type = MT_MINICLEAN_RO;
4653 create_mapping(&map);
4654 #endif
4655
4656@@ -1308,7 +1362,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4657 * location (0xffff0000). If we aren't using high-vectors, also
4658 * create a mapping at the low-vectors virtual address.
4659 */
4660- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4661+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4662 map.virtual = 0xffff0000;
4663 map.length = PAGE_SIZE;
4664 #ifdef CONFIG_KUSER_HELPERS
4665@@ -1365,8 +1419,10 @@ static void __init kmap_init(void)
4666 static void __init map_lowmem(void)
4667 {
4668 struct memblock_region *reg;
4669+#ifndef CONFIG_PAX_KERNEXEC
4670 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4671 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4672+#endif
4673
4674 /* Map all the lowmem memory banks. */
4675 for_each_memblock(memory, reg) {
4676@@ -1379,11 +1435,48 @@ static void __init map_lowmem(void)
4677 if (start >= end)
4678 break;
4679
4680+#ifdef CONFIG_PAX_KERNEXEC
4681+ map.pfn = __phys_to_pfn(start);
4682+ map.virtual = __phys_to_virt(start);
4683+ map.length = end - start;
4684+
4685+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4686+ struct map_desc kernel;
4687+ struct map_desc initmap;
4688+
4689+ /* when freeing initmem we will make this RW */
4690+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4691+ initmap.virtual = (unsigned long)__init_begin;
4692+ initmap.length = _sdata - __init_begin;
4693+ initmap.type = __MT_MEMORY_RWX;
4694+ create_mapping(&initmap);
4695+
4696+ /* when freeing initmem we will make this RX */
4697+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4698+ kernel.virtual = (unsigned long)_stext;
4699+ kernel.length = __init_begin - _stext;
4700+ kernel.type = __MT_MEMORY_RWX;
4701+ create_mapping(&kernel);
4702+
4703+ if (map.virtual < (unsigned long)_stext) {
4704+ map.length = (unsigned long)_stext - map.virtual;
4705+ map.type = __MT_MEMORY_RWX;
4706+ create_mapping(&map);
4707+ }
4708+
4709+ map.pfn = __phys_to_pfn(__pa(_sdata));
4710+ map.virtual = (unsigned long)_sdata;
4711+ map.length = end - __pa(_sdata);
4712+ }
4713+
4714+ map.type = MT_MEMORY_RW;
4715+ create_mapping(&map);
4716+#else
4717 if (end < kernel_x_start || start >= kernel_x_end) {
4718 map.pfn = __phys_to_pfn(start);
4719 map.virtual = __phys_to_virt(start);
4720 map.length = end - start;
4721- map.type = MT_MEMORY_RWX;
4722+ map.type = __MT_MEMORY_RWX;
4723
4724 create_mapping(&map);
4725 } else {
4726@@ -1400,7 +1493,7 @@ static void __init map_lowmem(void)
4727 map.pfn = __phys_to_pfn(kernel_x_start);
4728 map.virtual = __phys_to_virt(kernel_x_start);
4729 map.length = kernel_x_end - kernel_x_start;
4730- map.type = MT_MEMORY_RWX;
4731+ map.type = __MT_MEMORY_RWX;
4732
4733 create_mapping(&map);
4734
4735@@ -1413,6 +1506,7 @@ static void __init map_lowmem(void)
4736 create_mapping(&map);
4737 }
4738 }
4739+#endif
4740 }
4741 }
4742
4743diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4744index 5b217f4..c23f40e 100644
4745--- a/arch/arm/plat-iop/setup.c
4746+++ b/arch/arm/plat-iop/setup.c
4747@@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4748 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4749 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4750 .length = IOP3XX_PERIPHERAL_SIZE,
4751- .type = MT_UNCACHED,
4752+ .type = MT_UNCACHED_RW,
4753 },
4754 };
4755
4756diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4757index a5bc92d..0bb4730 100644
4758--- a/arch/arm/plat-omap/sram.c
4759+++ b/arch/arm/plat-omap/sram.c
4760@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4761 * Looks like we need to preserve some bootloader code at the
4762 * beginning of SRAM for jumping to flash for reboot to work...
4763 */
4764+ pax_open_kernel();
4765 memset_io(omap_sram_base + omap_sram_skip, 0,
4766 omap_sram_size - omap_sram_skip);
4767+ pax_close_kernel();
4768 }
4769diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4770index ce6d763..cfea917 100644
4771--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4772+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4773@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4774 int (*started)(unsigned ch);
4775 int (*flush)(unsigned ch);
4776 int (*stop)(unsigned ch);
4777-};
4778+} __no_const;
4779
4780 extern void *samsung_dmadev_get_ops(void);
4781 extern void *s3c_dma_get_ops(void);
4782diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4783index 66eb764..b529b84 100644
4784--- a/arch/arm64/include/asm/barrier.h
4785+++ b/arch/arm64/include/asm/barrier.h
4786@@ -41,7 +41,7 @@
4787 do { \
4788 compiletime_assert_atomic_type(*p); \
4789 smp_mb(); \
4790- ACCESS_ONCE(*p) = (v); \
4791+ ACCESS_ONCE_RW(*p) = (v); \
4792 } while (0)
4793
4794 #define smp_load_acquire(p) \
4795diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4796index 3bf8f4e..5dd5491 100644
4797--- a/arch/arm64/include/asm/uaccess.h
4798+++ b/arch/arm64/include/asm/uaccess.h
4799@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4800 flag; \
4801 })
4802
4803+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4804 #define access_ok(type, addr, size) __range_ok(addr, size)
4805 #define user_addr_max get_fs
4806
4807diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4808index c3a58a1..78fbf54 100644
4809--- a/arch/avr32/include/asm/cache.h
4810+++ b/arch/avr32/include/asm/cache.h
4811@@ -1,8 +1,10 @@
4812 #ifndef __ASM_AVR32_CACHE_H
4813 #define __ASM_AVR32_CACHE_H
4814
4815+#include <linux/const.h>
4816+
4817 #define L1_CACHE_SHIFT 5
4818-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4819+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4820
4821 /*
4822 * Memory returned by kmalloc() may be used for DMA, so we must make
4823diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4824index d232888..87c8df1 100644
4825--- a/arch/avr32/include/asm/elf.h
4826+++ b/arch/avr32/include/asm/elf.h
4827@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4828 the loader. We need to make sure that it is out of the way of the program
4829 that it will "exec", and that there is sufficient room for the brk. */
4830
4831-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4832+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4833
4834+#ifdef CONFIG_PAX_ASLR
4835+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4836+
4837+#define PAX_DELTA_MMAP_LEN 15
4838+#define PAX_DELTA_STACK_LEN 15
4839+#endif
4840
4841 /* This yields a mask that user programs can use to figure out what
4842 instruction set this CPU supports. This could be done in user space,
4843diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4844index 479330b..53717a8 100644
4845--- a/arch/avr32/include/asm/kmap_types.h
4846+++ b/arch/avr32/include/asm/kmap_types.h
4847@@ -2,9 +2,9 @@
4848 #define __ASM_AVR32_KMAP_TYPES_H
4849
4850 #ifdef CONFIG_DEBUG_HIGHMEM
4851-# define KM_TYPE_NR 29
4852+# define KM_TYPE_NR 30
4853 #else
4854-# define KM_TYPE_NR 14
4855+# define KM_TYPE_NR 15
4856 #endif
4857
4858 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4859diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4860index 0eca933..eb78c7b 100644
4861--- a/arch/avr32/mm/fault.c
4862+++ b/arch/avr32/mm/fault.c
4863@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4864
4865 int exception_trace = 1;
4866
4867+#ifdef CONFIG_PAX_PAGEEXEC
4868+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4869+{
4870+ unsigned long i;
4871+
4872+ printk(KERN_ERR "PAX: bytes at PC: ");
4873+ for (i = 0; i < 20; i++) {
4874+ unsigned char c;
4875+ if (get_user(c, (unsigned char *)pc+i))
4876+ printk(KERN_CONT "???????? ");
4877+ else
4878+ printk(KERN_CONT "%02x ", c);
4879+ }
4880+ printk("\n");
4881+}
4882+#endif
4883+
4884 /*
4885 * This routine handles page faults. It determines the address and the
4886 * problem, and then passes it off to one of the appropriate routines.
4887@@ -176,6 +193,16 @@ bad_area:
4888 up_read(&mm->mmap_sem);
4889
4890 if (user_mode(regs)) {
4891+
4892+#ifdef CONFIG_PAX_PAGEEXEC
4893+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4894+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4895+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4896+ do_group_exit(SIGKILL);
4897+ }
4898+ }
4899+#endif
4900+
4901 if (exception_trace && printk_ratelimit())
4902 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4903 "sp %08lx ecr %lu\n",
4904diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4905index 568885a..f8008df 100644
4906--- a/arch/blackfin/include/asm/cache.h
4907+++ b/arch/blackfin/include/asm/cache.h
4908@@ -7,6 +7,7 @@
4909 #ifndef __ARCH_BLACKFIN_CACHE_H
4910 #define __ARCH_BLACKFIN_CACHE_H
4911
4912+#include <linux/const.h>
4913 #include <linux/linkage.h> /* for asmlinkage */
4914
4915 /*
4916@@ -14,7 +15,7 @@
4917 * Blackfin loads 32 bytes for cache
4918 */
4919 #define L1_CACHE_SHIFT 5
4920-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4921+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4922 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4923
4924 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4925diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4926index aea2718..3639a60 100644
4927--- a/arch/cris/include/arch-v10/arch/cache.h
4928+++ b/arch/cris/include/arch-v10/arch/cache.h
4929@@ -1,8 +1,9 @@
4930 #ifndef _ASM_ARCH_CACHE_H
4931 #define _ASM_ARCH_CACHE_H
4932
4933+#include <linux/const.h>
4934 /* Etrax 100LX have 32-byte cache-lines. */
4935-#define L1_CACHE_BYTES 32
4936 #define L1_CACHE_SHIFT 5
4937+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4938
4939 #endif /* _ASM_ARCH_CACHE_H */
4940diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4941index 7caf25d..ee65ac5 100644
4942--- a/arch/cris/include/arch-v32/arch/cache.h
4943+++ b/arch/cris/include/arch-v32/arch/cache.h
4944@@ -1,11 +1,12 @@
4945 #ifndef _ASM_CRIS_ARCH_CACHE_H
4946 #define _ASM_CRIS_ARCH_CACHE_H
4947
4948+#include <linux/const.h>
4949 #include <arch/hwregs/dma.h>
4950
4951 /* A cache-line is 32 bytes. */
4952-#define L1_CACHE_BYTES 32
4953 #define L1_CACHE_SHIFT 5
4954+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4955
4956 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4957
4958diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4959index b86329d..6709906 100644
4960--- a/arch/frv/include/asm/atomic.h
4961+++ b/arch/frv/include/asm/atomic.h
4962@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4963 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4964 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4965
4966+#define atomic64_read_unchecked(v) atomic64_read(v)
4967+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4968+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4969+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4970+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4971+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4972+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4973+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4974+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4975+
4976 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4977 {
4978 int c, old;
4979diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4980index 2797163..c2a401d 100644
4981--- a/arch/frv/include/asm/cache.h
4982+++ b/arch/frv/include/asm/cache.h
4983@@ -12,10 +12,11 @@
4984 #ifndef __ASM_CACHE_H
4985 #define __ASM_CACHE_H
4986
4987+#include <linux/const.h>
4988
4989 /* bytes per L1 cache line */
4990 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4991-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4992+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4993
4994 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4995 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4996diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4997index 43901f2..0d8b865 100644
4998--- a/arch/frv/include/asm/kmap_types.h
4999+++ b/arch/frv/include/asm/kmap_types.h
5000@@ -2,6 +2,6 @@
5001 #ifndef _ASM_KMAP_TYPES_H
5002 #define _ASM_KMAP_TYPES_H
5003
5004-#define KM_TYPE_NR 17
5005+#define KM_TYPE_NR 18
5006
5007 #endif
5008diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5009index 836f147..4cf23f5 100644
5010--- a/arch/frv/mm/elf-fdpic.c
5011+++ b/arch/frv/mm/elf-fdpic.c
5012@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5013 {
5014 struct vm_area_struct *vma;
5015 struct vm_unmapped_area_info info;
5016+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5017
5018 if (len > TASK_SIZE)
5019 return -ENOMEM;
5020@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5021 if (addr) {
5022 addr = PAGE_ALIGN(addr);
5023 vma = find_vma(current->mm, addr);
5024- if (TASK_SIZE - len >= addr &&
5025- (!vma || addr + len <= vma->vm_start))
5026+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5027 goto success;
5028 }
5029
5030@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5031 info.high_limit = (current->mm->start_stack - 0x00200000);
5032 info.align_mask = 0;
5033 info.align_offset = 0;
5034+ info.threadstack_offset = offset;
5035 addr = vm_unmapped_area(&info);
5036 if (!(addr & ~PAGE_MASK))
5037 goto success;
5038diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5039index f4ca594..adc72fd6 100644
5040--- a/arch/hexagon/include/asm/cache.h
5041+++ b/arch/hexagon/include/asm/cache.h
5042@@ -21,9 +21,11 @@
5043 #ifndef __ASM_CACHE_H
5044 #define __ASM_CACHE_H
5045
5046+#include <linux/const.h>
5047+
5048 /* Bytes per L1 cache line */
5049-#define L1_CACHE_SHIFT (5)
5050-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5051+#define L1_CACHE_SHIFT 5
5052+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5053
5054 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5055 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5056diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5057index 12c3afe..b1abab2 100644
5058--- a/arch/ia64/Kconfig
5059+++ b/arch/ia64/Kconfig
5060@@ -546,6 +546,7 @@ source "drivers/sn/Kconfig"
5061 config KEXEC
5062 bool "kexec system call"
5063 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5064+ depends on !GRKERNSEC_KMEM
5065 help
5066 kexec is a system call that implements the ability to shutdown your
5067 current kernel, and to start another kernel. It is like a reboot
5068diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5069index 6e6fe18..a6ae668 100644
5070--- a/arch/ia64/include/asm/atomic.h
5071+++ b/arch/ia64/include/asm/atomic.h
5072@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5073 #define atomic64_inc(v) atomic64_add(1, (v))
5074 #define atomic64_dec(v) atomic64_sub(1, (v))
5075
5076+#define atomic64_read_unchecked(v) atomic64_read(v)
5077+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5078+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5079+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5080+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5081+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5082+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5083+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5084+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5085+
5086 /* Atomic operations are already serializing */
5087 #define smp_mb__before_atomic_dec() barrier()
5088 #define smp_mb__after_atomic_dec() barrier()
5089diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5090index d0a69aa..142f878 100644
5091--- a/arch/ia64/include/asm/barrier.h
5092+++ b/arch/ia64/include/asm/barrier.h
5093@@ -64,7 +64,7 @@
5094 do { \
5095 compiletime_assert_atomic_type(*p); \
5096 barrier(); \
5097- ACCESS_ONCE(*p) = (v); \
5098+ ACCESS_ONCE_RW(*p) = (v); \
5099 } while (0)
5100
5101 #define smp_load_acquire(p) \
5102diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5103index 988254a..e1ee885 100644
5104--- a/arch/ia64/include/asm/cache.h
5105+++ b/arch/ia64/include/asm/cache.h
5106@@ -1,6 +1,7 @@
5107 #ifndef _ASM_IA64_CACHE_H
5108 #define _ASM_IA64_CACHE_H
5109
5110+#include <linux/const.h>
5111
5112 /*
5113 * Copyright (C) 1998-2000 Hewlett-Packard Co
5114@@ -9,7 +10,7 @@
5115
5116 /* Bytes per L1 (data) cache line. */
5117 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5118-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5119+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5120
5121 #ifdef CONFIG_SMP
5122 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5123diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5124index 5a83c5c..4d7f553 100644
5125--- a/arch/ia64/include/asm/elf.h
5126+++ b/arch/ia64/include/asm/elf.h
5127@@ -42,6 +42,13 @@
5128 */
5129 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5130
5131+#ifdef CONFIG_PAX_ASLR
5132+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5133+
5134+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5135+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5136+#endif
5137+
5138 #define PT_IA_64_UNWIND 0x70000001
5139
5140 /* IA-64 relocations: */
5141diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5142index 5767cdf..7462574 100644
5143--- a/arch/ia64/include/asm/pgalloc.h
5144+++ b/arch/ia64/include/asm/pgalloc.h
5145@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5146 pgd_val(*pgd_entry) = __pa(pud);
5147 }
5148
5149+static inline void
5150+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5151+{
5152+ pgd_populate(mm, pgd_entry, pud);
5153+}
5154+
5155 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5156 {
5157 return quicklist_alloc(0, GFP_KERNEL, NULL);
5158@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5159 pud_val(*pud_entry) = __pa(pmd);
5160 }
5161
5162+static inline void
5163+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5164+{
5165+ pud_populate(mm, pud_entry, pmd);
5166+}
5167+
5168 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5169 {
5170 return quicklist_alloc(0, GFP_KERNEL, NULL);
5171diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5172index 7935115..c0eca6a 100644
5173--- a/arch/ia64/include/asm/pgtable.h
5174+++ b/arch/ia64/include/asm/pgtable.h
5175@@ -12,7 +12,7 @@
5176 * David Mosberger-Tang <davidm@hpl.hp.com>
5177 */
5178
5179-
5180+#include <linux/const.h>
5181 #include <asm/mman.h>
5182 #include <asm/page.h>
5183 #include <asm/processor.h>
5184@@ -142,6 +142,17 @@
5185 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5186 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5187 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5188+
5189+#ifdef CONFIG_PAX_PAGEEXEC
5190+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5191+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5192+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5193+#else
5194+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5195+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5196+# define PAGE_COPY_NOEXEC PAGE_COPY
5197+#endif
5198+
5199 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5200 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5201 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5202diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5203index 45698cd..e8e2dbc 100644
5204--- a/arch/ia64/include/asm/spinlock.h
5205+++ b/arch/ia64/include/asm/spinlock.h
5206@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5207 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5208
5209 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5210- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5211+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5212 }
5213
5214 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5215diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5216index 449c8c0..3d4b1e9 100644
5217--- a/arch/ia64/include/asm/uaccess.h
5218+++ b/arch/ia64/include/asm/uaccess.h
5219@@ -70,6 +70,7 @@
5220 && ((segment).seg == KERNEL_DS.seg \
5221 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5222 })
5223+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5224 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5225
5226 /*
5227@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5228 static inline unsigned long
5229 __copy_to_user (void __user *to, const void *from, unsigned long count)
5230 {
5231+ if (count > INT_MAX)
5232+ return count;
5233+
5234+ if (!__builtin_constant_p(count))
5235+ check_object_size(from, count, true);
5236+
5237 return __copy_user(to, (__force void __user *) from, count);
5238 }
5239
5240 static inline unsigned long
5241 __copy_from_user (void *to, const void __user *from, unsigned long count)
5242 {
5243+ if (count > INT_MAX)
5244+ return count;
5245+
5246+ if (!__builtin_constant_p(count))
5247+ check_object_size(to, count, false);
5248+
5249 return __copy_user((__force void __user *) to, from, count);
5250 }
5251
5252@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5253 ({ \
5254 void __user *__cu_to = (to); \
5255 const void *__cu_from = (from); \
5256- long __cu_len = (n); \
5257+ unsigned long __cu_len = (n); \
5258 \
5259- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5260+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5261+ if (!__builtin_constant_p(n)) \
5262+ check_object_size(__cu_from, __cu_len, true); \
5263 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5264+ } \
5265 __cu_len; \
5266 })
5267
5268@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5269 ({ \
5270 void *__cu_to = (to); \
5271 const void __user *__cu_from = (from); \
5272- long __cu_len = (n); \
5273+ unsigned long __cu_len = (n); \
5274 \
5275 __chk_user_ptr(__cu_from); \
5276- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5277+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5278+ if (!__builtin_constant_p(n)) \
5279+ check_object_size(__cu_to, __cu_len, false); \
5280 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5281+ } \
5282 __cu_len; \
5283 })
5284
5285diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5286index 24603be..948052d 100644
5287--- a/arch/ia64/kernel/module.c
5288+++ b/arch/ia64/kernel/module.c
5289@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5290 void
5291 module_free (struct module *mod, void *module_region)
5292 {
5293- if (mod && mod->arch.init_unw_table &&
5294- module_region == mod->module_init) {
5295+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5296 unw_remove_unwind_table(mod->arch.init_unw_table);
5297 mod->arch.init_unw_table = NULL;
5298 }
5299@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5300 }
5301
5302 static inline int
5303+in_init_rx (const struct module *mod, uint64_t addr)
5304+{
5305+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5306+}
5307+
5308+static inline int
5309+in_init_rw (const struct module *mod, uint64_t addr)
5310+{
5311+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5312+}
5313+
5314+static inline int
5315 in_init (const struct module *mod, uint64_t addr)
5316 {
5317- return addr - (uint64_t) mod->module_init < mod->init_size;
5318+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5319+}
5320+
5321+static inline int
5322+in_core_rx (const struct module *mod, uint64_t addr)
5323+{
5324+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5325+}
5326+
5327+static inline int
5328+in_core_rw (const struct module *mod, uint64_t addr)
5329+{
5330+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5331 }
5332
5333 static inline int
5334 in_core (const struct module *mod, uint64_t addr)
5335 {
5336- return addr - (uint64_t) mod->module_core < mod->core_size;
5337+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5338 }
5339
5340 static inline int
5341@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5342 break;
5343
5344 case RV_BDREL:
5345- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5346+ if (in_init_rx(mod, val))
5347+ val -= (uint64_t) mod->module_init_rx;
5348+ else if (in_init_rw(mod, val))
5349+ val -= (uint64_t) mod->module_init_rw;
5350+ else if (in_core_rx(mod, val))
5351+ val -= (uint64_t) mod->module_core_rx;
5352+ else if (in_core_rw(mod, val))
5353+ val -= (uint64_t) mod->module_core_rw;
5354 break;
5355
5356 case RV_LTV:
5357@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5358 * addresses have been selected...
5359 */
5360 uint64_t gp;
5361- if (mod->core_size > MAX_LTOFF)
5362+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5363 /*
5364 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5365 * at the end of the module.
5366 */
5367- gp = mod->core_size - MAX_LTOFF / 2;
5368+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5369 else
5370- gp = mod->core_size / 2;
5371- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5372+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5373+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5374 mod->arch.gp = gp;
5375 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5376 }
5377diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5378index c39c3cd..3c77738 100644
5379--- a/arch/ia64/kernel/palinfo.c
5380+++ b/arch/ia64/kernel/palinfo.c
5381@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5382 return NOTIFY_OK;
5383 }
5384
5385-static struct notifier_block __refdata palinfo_cpu_notifier =
5386+static struct notifier_block palinfo_cpu_notifier =
5387 {
5388 .notifier_call = palinfo_cpu_callback,
5389 .priority = 0,
5390diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5391index 41e33f8..65180b2a 100644
5392--- a/arch/ia64/kernel/sys_ia64.c
5393+++ b/arch/ia64/kernel/sys_ia64.c
5394@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5395 unsigned long align_mask = 0;
5396 struct mm_struct *mm = current->mm;
5397 struct vm_unmapped_area_info info;
5398+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5399
5400 if (len > RGN_MAP_LIMIT)
5401 return -ENOMEM;
5402@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5403 if (REGION_NUMBER(addr) == RGN_HPAGE)
5404 addr = 0;
5405 #endif
5406+
5407+#ifdef CONFIG_PAX_RANDMMAP
5408+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5409+ addr = mm->free_area_cache;
5410+ else
5411+#endif
5412+
5413 if (!addr)
5414 addr = TASK_UNMAPPED_BASE;
5415
5416@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5417 info.high_limit = TASK_SIZE;
5418 info.align_mask = align_mask;
5419 info.align_offset = 0;
5420+ info.threadstack_offset = offset;
5421 return vm_unmapped_area(&info);
5422 }
5423
5424diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5425index 84f8a52..7c76178 100644
5426--- a/arch/ia64/kernel/vmlinux.lds.S
5427+++ b/arch/ia64/kernel/vmlinux.lds.S
5428@@ -192,7 +192,7 @@ SECTIONS {
5429 /* Per-cpu data: */
5430 . = ALIGN(PERCPU_PAGE_SIZE);
5431 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5432- __phys_per_cpu_start = __per_cpu_load;
5433+ __phys_per_cpu_start = per_cpu_load;
5434 /*
5435 * ensure percpu data fits
5436 * into percpu page size
5437diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5438index 7225dad..2a7c8256 100644
5439--- a/arch/ia64/mm/fault.c
5440+++ b/arch/ia64/mm/fault.c
5441@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5442 return pte_present(pte);
5443 }
5444
5445+#ifdef CONFIG_PAX_PAGEEXEC
5446+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5447+{
5448+ unsigned long i;
5449+
5450+ printk(KERN_ERR "PAX: bytes at PC: ");
5451+ for (i = 0; i < 8; i++) {
5452+ unsigned int c;
5453+ if (get_user(c, (unsigned int *)pc+i))
5454+ printk(KERN_CONT "???????? ");
5455+ else
5456+ printk(KERN_CONT "%08x ", c);
5457+ }
5458+ printk("\n");
5459+}
5460+#endif
5461+
5462 # define VM_READ_BIT 0
5463 # define VM_WRITE_BIT 1
5464 # define VM_EXEC_BIT 2
5465@@ -151,8 +168,21 @@ retry:
5466 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5467 goto bad_area;
5468
5469- if ((vma->vm_flags & mask) != mask)
5470+ if ((vma->vm_flags & mask) != mask) {
5471+
5472+#ifdef CONFIG_PAX_PAGEEXEC
5473+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5474+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5475+ goto bad_area;
5476+
5477+ up_read(&mm->mmap_sem);
5478+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5479+ do_group_exit(SIGKILL);
5480+ }
5481+#endif
5482+
5483 goto bad_area;
5484+ }
5485
5486 /*
5487 * If for any reason at all we couldn't handle the fault, make
5488diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5489index 76069c1..c2aa816 100644
5490--- a/arch/ia64/mm/hugetlbpage.c
5491+++ b/arch/ia64/mm/hugetlbpage.c
5492@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5493 unsigned long pgoff, unsigned long flags)
5494 {
5495 struct vm_unmapped_area_info info;
5496+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5497
5498 if (len > RGN_MAP_LIMIT)
5499 return -ENOMEM;
5500@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5501 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5502 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5503 info.align_offset = 0;
5504+ info.threadstack_offset = offset;
5505 return vm_unmapped_area(&info);
5506 }
5507
5508diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5509index 25c3502..560dae7 100644
5510--- a/arch/ia64/mm/init.c
5511+++ b/arch/ia64/mm/init.c
5512@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5513 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5514 vma->vm_end = vma->vm_start + PAGE_SIZE;
5515 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5516+
5517+#ifdef CONFIG_PAX_PAGEEXEC
5518+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5519+ vma->vm_flags &= ~VM_EXEC;
5520+
5521+#ifdef CONFIG_PAX_MPROTECT
5522+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5523+ vma->vm_flags &= ~VM_MAYEXEC;
5524+#endif
5525+
5526+ }
5527+#endif
5528+
5529 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5530 down_write(&current->mm->mmap_sem);
5531 if (insert_vm_struct(current->mm, vma)) {
5532diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5533index 40b3ee9..8c2c112 100644
5534--- a/arch/m32r/include/asm/cache.h
5535+++ b/arch/m32r/include/asm/cache.h
5536@@ -1,8 +1,10 @@
5537 #ifndef _ASM_M32R_CACHE_H
5538 #define _ASM_M32R_CACHE_H
5539
5540+#include <linux/const.h>
5541+
5542 /* L1 cache line size */
5543 #define L1_CACHE_SHIFT 4
5544-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5545+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5546
5547 #endif /* _ASM_M32R_CACHE_H */
5548diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5549index 82abd15..d95ae5d 100644
5550--- a/arch/m32r/lib/usercopy.c
5551+++ b/arch/m32r/lib/usercopy.c
5552@@ -14,6 +14,9 @@
5553 unsigned long
5554 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5555 {
5556+ if ((long)n < 0)
5557+ return n;
5558+
5559 prefetch(from);
5560 if (access_ok(VERIFY_WRITE, to, n))
5561 __copy_user(to,from,n);
5562@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5563 unsigned long
5564 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5565 {
5566+ if ((long)n < 0)
5567+ return n;
5568+
5569 prefetchw(to);
5570 if (access_ok(VERIFY_READ, from, n))
5571 __copy_user_zeroing(to,from,n);
5572diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5573index 0395c51..5f26031 100644
5574--- a/arch/m68k/include/asm/cache.h
5575+++ b/arch/m68k/include/asm/cache.h
5576@@ -4,9 +4,11 @@
5577 #ifndef __ARCH_M68K_CACHE_H
5578 #define __ARCH_M68K_CACHE_H
5579
5580+#include <linux/const.h>
5581+
5582 /* bytes per L1 cache line */
5583 #define L1_CACHE_SHIFT 4
5584-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5585+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5586
5587 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5588
5589diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5590index 2d6f0de..de5f5ac 100644
5591--- a/arch/metag/include/asm/barrier.h
5592+++ b/arch/metag/include/asm/barrier.h
5593@@ -89,7 +89,7 @@ static inline void fence(void)
5594 do { \
5595 compiletime_assert_atomic_type(*p); \
5596 smp_mb(); \
5597- ACCESS_ONCE(*p) = (v); \
5598+ ACCESS_ONCE_RW(*p) = (v); \
5599 } while (0)
5600
5601 #define smp_load_acquire(p) \
5602diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5603index 3c52fa6..11b2ad8 100644
5604--- a/arch/metag/mm/hugetlbpage.c
5605+++ b/arch/metag/mm/hugetlbpage.c
5606@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5607 info.high_limit = TASK_SIZE;
5608 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5609 info.align_offset = 0;
5610+ info.threadstack_offset = 0;
5611 return vm_unmapped_area(&info);
5612 }
5613
5614diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5615index 4efe96a..60e8699 100644
5616--- a/arch/microblaze/include/asm/cache.h
5617+++ b/arch/microblaze/include/asm/cache.h
5618@@ -13,11 +13,12 @@
5619 #ifndef _ASM_MICROBLAZE_CACHE_H
5620 #define _ASM_MICROBLAZE_CACHE_H
5621
5622+#include <linux/const.h>
5623 #include <asm/registers.h>
5624
5625 #define L1_CACHE_SHIFT 5
5626 /* word-granular cache in microblaze */
5627-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5628+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5629
5630 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5631
5632diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5633index 5cd695f..9a24ad0 100644
5634--- a/arch/mips/Kconfig
5635+++ b/arch/mips/Kconfig
5636@@ -2395,6 +2395,7 @@ source "kernel/Kconfig.preempt"
5637
5638 config KEXEC
5639 bool "Kexec system call"
5640+ depends on !GRKERNSEC_KMEM
5641 help
5642 kexec is a system call that implements the ability to shutdown your
5643 current kernel, and to start another kernel. It is like a reboot
5644diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5645index 02f2444..506969c 100644
5646--- a/arch/mips/cavium-octeon/dma-octeon.c
5647+++ b/arch/mips/cavium-octeon/dma-octeon.c
5648@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5649 if (dma_release_from_coherent(dev, order, vaddr))
5650 return;
5651
5652- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5653+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5654 }
5655
5656 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5657diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5658index e8eb3d5..2e665d1 100644
5659--- a/arch/mips/include/asm/atomic.h
5660+++ b/arch/mips/include/asm/atomic.h
5661@@ -21,15 +21,39 @@
5662 #include <asm/cmpxchg.h>
5663 #include <asm/war.h>
5664
5665+#ifdef CONFIG_GENERIC_ATOMIC64
5666+#include <asm-generic/atomic64.h>
5667+#endif
5668+
5669 #define ATOMIC_INIT(i) { (i) }
5670
5671+#ifdef CONFIG_64BIT
5672+#define _ASM_EXTABLE(from, to) \
5673+" .section __ex_table,\"a\"\n" \
5674+" .dword " #from ", " #to"\n" \
5675+" .previous\n"
5676+#else
5677+#define _ASM_EXTABLE(from, to) \
5678+" .section __ex_table,\"a\"\n" \
5679+" .word " #from ", " #to"\n" \
5680+" .previous\n"
5681+#endif
5682+
5683 /*
5684 * atomic_read - read atomic variable
5685 * @v: pointer of type atomic_t
5686 *
5687 * Atomically reads the value of @v.
5688 */
5689-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5690+static inline int atomic_read(const atomic_t *v)
5691+{
5692+ return (*(volatile const int *) &v->counter);
5693+}
5694+
5695+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5696+{
5697+ return (*(volatile const int *) &v->counter);
5698+}
5699
5700 /*
5701 * atomic_set - set atomic variable
5702@@ -38,7 +62,15 @@
5703 *
5704 * Atomically sets the value of @v to @i.
5705 */
5706-#define atomic_set(v, i) ((v)->counter = (i))
5707+static inline void atomic_set(atomic_t *v, int i)
5708+{
5709+ v->counter = i;
5710+}
5711+
5712+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5713+{
5714+ v->counter = i;
5715+}
5716
5717 /*
5718 * atomic_add - add integer to atomic variable
5719@@ -47,7 +79,67 @@
5720 *
5721 * Atomically adds @i to @v.
5722 */
5723-static __inline__ void atomic_add(int i, atomic_t * v)
5724+static __inline__ void atomic_add(int i, atomic_t *v)
5725+{
5726+ int temp;
5727+
5728+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5729+ __asm__ __volatile__(
5730+ " .set mips3 \n"
5731+ "1: ll %0, %1 # atomic_add \n"
5732+#ifdef CONFIG_PAX_REFCOUNT
5733+ /* Exception on overflow. */
5734+ "2: add %0, %2 \n"
5735+#else
5736+ " addu %0, %2 \n"
5737+#endif
5738+ " sc %0, %1 \n"
5739+ " beqzl %0, 1b \n"
5740+#ifdef CONFIG_PAX_REFCOUNT
5741+ "3: \n"
5742+ _ASM_EXTABLE(2b, 3b)
5743+#endif
5744+ " .set mips0 \n"
5745+ : "=&r" (temp), "+m" (v->counter)
5746+ : "Ir" (i));
5747+ } else if (kernel_uses_llsc) {
5748+ __asm__ __volatile__(
5749+ " .set mips3 \n"
5750+ "1: ll %0, %1 # atomic_add \n"
5751+#ifdef CONFIG_PAX_REFCOUNT
5752+ /* Exception on overflow. */
5753+ "2: add %0, %2 \n"
5754+#else
5755+ " addu %0, %2 \n"
5756+#endif
5757+ " sc %0, %1 \n"
5758+ " beqz %0, 1b \n"
5759+#ifdef CONFIG_PAX_REFCOUNT
5760+ "3: \n"
5761+ _ASM_EXTABLE(2b, 3b)
5762+#endif
5763+ " .set mips0 \n"
5764+ : "=&r" (temp), "+m" (v->counter)
5765+ : "Ir" (i));
5766+ } else {
5767+ unsigned long flags;
5768+
5769+ raw_local_irq_save(flags);
5770+ __asm__ __volatile__(
5771+#ifdef CONFIG_PAX_REFCOUNT
5772+ /* Exception on overflow. */
5773+ "1: add %0, %1 \n"
5774+ "2: \n"
5775+ _ASM_EXTABLE(1b, 2b)
5776+#else
5777+ " addu %0, %1 \n"
5778+#endif
5779+ : "+r" (v->counter) : "Ir" (i));
5780+ raw_local_irq_restore(flags);
5781+ }
5782+}
5783+
5784+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5785 {
5786 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5787 int temp;
5788@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5789 *
5790 * Atomically subtracts @i from @v.
5791 */
5792-static __inline__ void atomic_sub(int i, atomic_t * v)
5793+static __inline__ void atomic_sub(int i, atomic_t *v)
5794+{
5795+ int temp;
5796+
5797+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5798+ __asm__ __volatile__(
5799+ " .set mips3 \n"
5800+ "1: ll %0, %1 # atomic64_sub \n"
5801+#ifdef CONFIG_PAX_REFCOUNT
5802+ /* Exception on overflow. */
5803+ "2: sub %0, %2 \n"
5804+#else
5805+ " subu %0, %2 \n"
5806+#endif
5807+ " sc %0, %1 \n"
5808+ " beqzl %0, 1b \n"
5809+#ifdef CONFIG_PAX_REFCOUNT
5810+ "3: \n"
5811+ _ASM_EXTABLE(2b, 3b)
5812+#endif
5813+ " .set mips0 \n"
5814+ : "=&r" (temp), "+m" (v->counter)
5815+ : "Ir" (i));
5816+ } else if (kernel_uses_llsc) {
5817+ __asm__ __volatile__(
5818+ " .set mips3 \n"
5819+ "1: ll %0, %1 # atomic64_sub \n"
5820+#ifdef CONFIG_PAX_REFCOUNT
5821+ /* Exception on overflow. */
5822+ "2: sub %0, %2 \n"
5823+#else
5824+ " subu %0, %2 \n"
5825+#endif
5826+ " sc %0, %1 \n"
5827+ " beqz %0, 1b \n"
5828+#ifdef CONFIG_PAX_REFCOUNT
5829+ "3: \n"
5830+ _ASM_EXTABLE(2b, 3b)
5831+#endif
5832+ " .set mips0 \n"
5833+ : "=&r" (temp), "+m" (v->counter)
5834+ : "Ir" (i));
5835+ } else {
5836+ unsigned long flags;
5837+
5838+ raw_local_irq_save(flags);
5839+ __asm__ __volatile__(
5840+#ifdef CONFIG_PAX_REFCOUNT
5841+ /* Exception on overflow. */
5842+ "1: sub %0, %1 \n"
5843+ "2: \n"
5844+ _ASM_EXTABLE(1b, 2b)
5845+#else
5846+ " subu %0, %1 \n"
5847+#endif
5848+ : "+r" (v->counter) : "Ir" (i));
5849+ raw_local_irq_restore(flags);
5850+ }
5851+}
5852+
5853+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5854 {
5855 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5856 int temp;
5857@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5858 /*
5859 * Same as above, but return the result value
5860 */
5861-static __inline__ int atomic_add_return(int i, atomic_t * v)
5862+static __inline__ int atomic_add_return(int i, atomic_t *v)
5863+{
5864+ int result;
5865+ int temp;
5866+
5867+ smp_mb__before_llsc();
5868+
5869+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5870+ __asm__ __volatile__(
5871+ " .set mips3 \n"
5872+ "1: ll %1, %2 # atomic_add_return \n"
5873+#ifdef CONFIG_PAX_REFCOUNT
5874+ "2: add %0, %1, %3 \n"
5875+#else
5876+ " addu %0, %1, %3 \n"
5877+#endif
5878+ " sc %0, %2 \n"
5879+ " beqzl %0, 1b \n"
5880+#ifdef CONFIG_PAX_REFCOUNT
5881+ " b 4f \n"
5882+ " .set noreorder \n"
5883+ "3: b 5f \n"
5884+ " move %0, %1 \n"
5885+ " .set reorder \n"
5886+ _ASM_EXTABLE(2b, 3b)
5887+#endif
5888+ "4: addu %0, %1, %3 \n"
5889+#ifdef CONFIG_PAX_REFCOUNT
5890+ "5: \n"
5891+#endif
5892+ " .set mips0 \n"
5893+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5894+ : "Ir" (i));
5895+ } else if (kernel_uses_llsc) {
5896+ __asm__ __volatile__(
5897+ " .set mips3 \n"
5898+ "1: ll %1, %2 # atomic_add_return \n"
5899+#ifdef CONFIG_PAX_REFCOUNT
5900+ "2: add %0, %1, %3 \n"
5901+#else
5902+ " addu %0, %1, %3 \n"
5903+#endif
5904+ " sc %0, %2 \n"
5905+ " bnez %0, 4f \n"
5906+ " b 1b \n"
5907+#ifdef CONFIG_PAX_REFCOUNT
5908+ " .set noreorder \n"
5909+ "3: b 5f \n"
5910+ " move %0, %1 \n"
5911+ " .set reorder \n"
5912+ _ASM_EXTABLE(2b, 3b)
5913+#endif
5914+ "4: addu %0, %1, %3 \n"
5915+#ifdef CONFIG_PAX_REFCOUNT
5916+ "5: \n"
5917+#endif
5918+ " .set mips0 \n"
5919+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5920+ : "Ir" (i));
5921+ } else {
5922+ unsigned long flags;
5923+
5924+ raw_local_irq_save(flags);
5925+ __asm__ __volatile__(
5926+ " lw %0, %1 \n"
5927+#ifdef CONFIG_PAX_REFCOUNT
5928+ /* Exception on overflow. */
5929+ "1: add %0, %2 \n"
5930+#else
5931+ " addu %0, %2 \n"
5932+#endif
5933+ " sw %0, %1 \n"
5934+#ifdef CONFIG_PAX_REFCOUNT
5935+ /* Note: Dest reg is not modified on overflow */
5936+ "2: \n"
5937+ _ASM_EXTABLE(1b, 2b)
5938+#endif
5939+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5940+ raw_local_irq_restore(flags);
5941+ }
5942+
5943+ smp_llsc_mb();
5944+
5945+ return result;
5946+}
5947+
5948+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5949 {
5950 int result;
5951
5952@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5953 return result;
5954 }
5955
5956-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5957+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5958+{
5959+ int result;
5960+ int temp;
5961+
5962+ smp_mb__before_llsc();
5963+
5964+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5965+ __asm__ __volatile__(
5966+ " .set mips3 \n"
5967+ "1: ll %1, %2 # atomic_sub_return \n"
5968+#ifdef CONFIG_PAX_REFCOUNT
5969+ "2: sub %0, %1, %3 \n"
5970+#else
5971+ " subu %0, %1, %3 \n"
5972+#endif
5973+ " sc %0, %2 \n"
5974+ " beqzl %0, 1b \n"
5975+#ifdef CONFIG_PAX_REFCOUNT
5976+ " b 4f \n"
5977+ " .set noreorder \n"
5978+ "3: b 5f \n"
5979+ " move %0, %1 \n"
5980+ " .set reorder \n"
5981+ _ASM_EXTABLE(2b, 3b)
5982+#endif
5983+ "4: subu %0, %1, %3 \n"
5984+#ifdef CONFIG_PAX_REFCOUNT
5985+ "5: \n"
5986+#endif
5987+ " .set mips0 \n"
5988+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5989+ : "Ir" (i), "m" (v->counter)
5990+ : "memory");
5991+ } else if (kernel_uses_llsc) {
5992+ __asm__ __volatile__(
5993+ " .set mips3 \n"
5994+ "1: ll %1, %2 # atomic_sub_return \n"
5995+#ifdef CONFIG_PAX_REFCOUNT
5996+ "2: sub %0, %1, %3 \n"
5997+#else
5998+ " subu %0, %1, %3 \n"
5999+#endif
6000+ " sc %0, %2 \n"
6001+ " bnez %0, 4f \n"
6002+ " b 1b \n"
6003+#ifdef CONFIG_PAX_REFCOUNT
6004+ " .set noreorder \n"
6005+ "3: b 5f \n"
6006+ " move %0, %1 \n"
6007+ " .set reorder \n"
6008+ _ASM_EXTABLE(2b, 3b)
6009+#endif
6010+ "4: subu %0, %1, %3 \n"
6011+#ifdef CONFIG_PAX_REFCOUNT
6012+ "5: \n"
6013+#endif
6014+ " .set mips0 \n"
6015+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6016+ : "Ir" (i));
6017+ } else {
6018+ unsigned long flags;
6019+
6020+ raw_local_irq_save(flags);
6021+ __asm__ __volatile__(
6022+ " lw %0, %1 \n"
6023+#ifdef CONFIG_PAX_REFCOUNT
6024+ /* Exception on overflow. */
6025+ "1: sub %0, %2 \n"
6026+#else
6027+ " subu %0, %2 \n"
6028+#endif
6029+ " sw %0, %1 \n"
6030+#ifdef CONFIG_PAX_REFCOUNT
6031+ /* Note: Dest reg is not modified on overflow */
6032+ "2: \n"
6033+ _ASM_EXTABLE(1b, 2b)
6034+#endif
6035+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6036+ raw_local_irq_restore(flags);
6037+ }
6038+
6039+ smp_llsc_mb();
6040+
6041+ return result;
6042+}
6043+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6044 {
6045 int result;
6046
6047@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6048 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6049 * The function returns the old value of @v minus @i.
6050 */
6051-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6052+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6053 {
6054 int result;
6055
6056@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6057 return result;
6058 }
6059
6060-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6061-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6062+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6063+{
6064+ return cmpxchg(&v->counter, old, new);
6065+}
6066+
6067+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6068+ int new)
6069+{
6070+ return cmpxchg(&(v->counter), old, new);
6071+}
6072+
6073+static inline int atomic_xchg(atomic_t *v, int new)
6074+{
6075+ return xchg(&v->counter, new);
6076+}
6077+
6078+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6079+{
6080+ return xchg(&(v->counter), new);
6081+}
6082
6083 /**
6084 * __atomic_add_unless - add unless the number is a given value
6085@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6086
6087 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6088 #define atomic_inc_return(v) atomic_add_return(1, (v))
6089+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6090+{
6091+ return atomic_add_return_unchecked(1, v);
6092+}
6093
6094 /*
6095 * atomic_sub_and_test - subtract value from variable and test result
6096@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6097 * other cases.
6098 */
6099 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6100+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6101+{
6102+ return atomic_add_return_unchecked(1, v) == 0;
6103+}
6104
6105 /*
6106 * atomic_dec_and_test - decrement by 1 and test
6107@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6108 * Atomically increments @v by 1.
6109 */
6110 #define atomic_inc(v) atomic_add(1, (v))
6111+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6112+{
6113+ atomic_add_unchecked(1, v);
6114+}
6115
6116 /*
6117 * atomic_dec - decrement and test
6118@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6119 * Atomically decrements @v by 1.
6120 */
6121 #define atomic_dec(v) atomic_sub(1, (v))
6122+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6123+{
6124+ atomic_sub_unchecked(1, v);
6125+}
6126
6127 /*
6128 * atomic_add_negative - add and test if negative
6129@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6130 * @v: pointer of type atomic64_t
6131 *
6132 */
6133-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6134+static inline long atomic64_read(const atomic64_t *v)
6135+{
6136+ return (*(volatile const long *) &v->counter);
6137+}
6138+
6139+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6140+{
6141+ return (*(volatile const long *) &v->counter);
6142+}
6143
6144 /*
6145 * atomic64_set - set atomic variable
6146 * @v: pointer of type atomic64_t
6147 * @i: required value
6148 */
6149-#define atomic64_set(v, i) ((v)->counter = (i))
6150+static inline void atomic64_set(atomic64_t *v, long i)
6151+{
6152+ v->counter = i;
6153+}
6154+
6155+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6156+{
6157+ v->counter = i;
6158+}
6159
6160 /*
6161 * atomic64_add - add integer to atomic variable
6162@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6163 *
6164 * Atomically adds @i to @v.
6165 */
6166-static __inline__ void atomic64_add(long i, atomic64_t * v)
6167+static __inline__ void atomic64_add(long i, atomic64_t *v)
6168+{
6169+ long temp;
6170+
6171+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6172+ __asm__ __volatile__(
6173+ " .set mips3 \n"
6174+ "1: lld %0, %1 # atomic64_add \n"
6175+#ifdef CONFIG_PAX_REFCOUNT
6176+ /* Exception on overflow. */
6177+ "2: dadd %0, %2 \n"
6178+#else
6179+ " daddu %0, %2 \n"
6180+#endif
6181+ " scd %0, %1 \n"
6182+ " beqzl %0, 1b \n"
6183+#ifdef CONFIG_PAX_REFCOUNT
6184+ "3: \n"
6185+ _ASM_EXTABLE(2b, 3b)
6186+#endif
6187+ " .set mips0 \n"
6188+ : "=&r" (temp), "+m" (v->counter)
6189+ : "Ir" (i));
6190+ } else if (kernel_uses_llsc) {
6191+ __asm__ __volatile__(
6192+ " .set mips3 \n"
6193+ "1: lld %0, %1 # atomic64_add \n"
6194+#ifdef CONFIG_PAX_REFCOUNT
6195+ /* Exception on overflow. */
6196+ "2: dadd %0, %2 \n"
6197+#else
6198+ " daddu %0, %2 \n"
6199+#endif
6200+ " scd %0, %1 \n"
6201+ " beqz %0, 1b \n"
6202+#ifdef CONFIG_PAX_REFCOUNT
6203+ "3: \n"
6204+ _ASM_EXTABLE(2b, 3b)
6205+#endif
6206+ " .set mips0 \n"
6207+ : "=&r" (temp), "+m" (v->counter)
6208+ : "Ir" (i));
6209+ } else {
6210+ unsigned long flags;
6211+
6212+ raw_local_irq_save(flags);
6213+ __asm__ __volatile__(
6214+#ifdef CONFIG_PAX_REFCOUNT
6215+ /* Exception on overflow. */
6216+ "1: dadd %0, %1 \n"
6217+ "2: \n"
6218+ _ASM_EXTABLE(1b, 2b)
6219+#else
6220+ " daddu %0, %1 \n"
6221+#endif
6222+ : "+r" (v->counter) : "Ir" (i));
6223+ raw_local_irq_restore(flags);
6224+ }
6225+}
6226+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6227 {
6228 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6229 long temp;
6230@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6231 *
6232 * Atomically subtracts @i from @v.
6233 */
6234-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6235+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6236+{
6237+ long temp;
6238+
6239+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6240+ __asm__ __volatile__(
6241+ " .set mips3 \n"
6242+ "1: lld %0, %1 # atomic64_sub \n"
6243+#ifdef CONFIG_PAX_REFCOUNT
6244+ /* Exception on overflow. */
6245+ "2: dsub %0, %2 \n"
6246+#else
6247+ " dsubu %0, %2 \n"
6248+#endif
6249+ " scd %0, %1 \n"
6250+ " beqzl %0, 1b \n"
6251+#ifdef CONFIG_PAX_REFCOUNT
6252+ "3: \n"
6253+ _ASM_EXTABLE(2b, 3b)
6254+#endif
6255+ " .set mips0 \n"
6256+ : "=&r" (temp), "+m" (v->counter)
6257+ : "Ir" (i));
6258+ } else if (kernel_uses_llsc) {
6259+ __asm__ __volatile__(
6260+ " .set mips3 \n"
6261+ "1: lld %0, %1 # atomic64_sub \n"
6262+#ifdef CONFIG_PAX_REFCOUNT
6263+ /* Exception on overflow. */
6264+ "2: dsub %0, %2 \n"
6265+#else
6266+ " dsubu %0, %2 \n"
6267+#endif
6268+ " scd %0, %1 \n"
6269+ " beqz %0, 1b \n"
6270+#ifdef CONFIG_PAX_REFCOUNT
6271+ "3: \n"
6272+ _ASM_EXTABLE(2b, 3b)
6273+#endif
6274+ " .set mips0 \n"
6275+ : "=&r" (temp), "+m" (v->counter)
6276+ : "Ir" (i));
6277+ } else {
6278+ unsigned long flags;
6279+
6280+ raw_local_irq_save(flags);
6281+ __asm__ __volatile__(
6282+#ifdef CONFIG_PAX_REFCOUNT
6283+ /* Exception on overflow. */
6284+ "1: dsub %0, %1 \n"
6285+ "2: \n"
6286+ _ASM_EXTABLE(1b, 2b)
6287+#else
6288+ " dsubu %0, %1 \n"
6289+#endif
6290+ : "+r" (v->counter) : "Ir" (i));
6291+ raw_local_irq_restore(flags);
6292+ }
6293+}
6294+
6295+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6296 {
6297 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6298 long temp;
6299@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6300 /*
6301 * Same as above, but return the result value
6302 */
6303-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6304+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6305+{
6306+ long result;
6307+ long temp;
6308+
6309+ smp_mb__before_llsc();
6310+
6311+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6312+ __asm__ __volatile__(
6313+ " .set mips3 \n"
6314+ "1: lld %1, %2 # atomic64_add_return \n"
6315+#ifdef CONFIG_PAX_REFCOUNT
6316+ "2: dadd %0, %1, %3 \n"
6317+#else
6318+ " daddu %0, %1, %3 \n"
6319+#endif
6320+ " scd %0, %2 \n"
6321+ " beqzl %0, 1b \n"
6322+#ifdef CONFIG_PAX_REFCOUNT
6323+ " b 4f \n"
6324+ " .set noreorder \n"
6325+ "3: b 5f \n"
6326+ " move %0, %1 \n"
6327+ " .set reorder \n"
6328+ _ASM_EXTABLE(2b, 3b)
6329+#endif
6330+ "4: daddu %0, %1, %3 \n"
6331+#ifdef CONFIG_PAX_REFCOUNT
6332+ "5: \n"
6333+#endif
6334+ " .set mips0 \n"
6335+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6336+ : "Ir" (i));
6337+ } else if (kernel_uses_llsc) {
6338+ __asm__ __volatile__(
6339+ " .set mips3 \n"
6340+ "1: lld %1, %2 # atomic64_add_return \n"
6341+#ifdef CONFIG_PAX_REFCOUNT
6342+ "2: dadd %0, %1, %3 \n"
6343+#else
6344+ " daddu %0, %1, %3 \n"
6345+#endif
6346+ " scd %0, %2 \n"
6347+ " bnez %0, 4f \n"
6348+ " b 1b \n"
6349+#ifdef CONFIG_PAX_REFCOUNT
6350+ " .set noreorder \n"
6351+ "3: b 5f \n"
6352+ " move %0, %1 \n"
6353+ " .set reorder \n"
6354+ _ASM_EXTABLE(2b, 3b)
6355+#endif
6356+ "4: daddu %0, %1, %3 \n"
6357+#ifdef CONFIG_PAX_REFCOUNT
6358+ "5: \n"
6359+#endif
6360+ " .set mips0 \n"
6361+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6362+ : "Ir" (i), "m" (v->counter)
6363+ : "memory");
6364+ } else {
6365+ unsigned long flags;
6366+
6367+ raw_local_irq_save(flags);
6368+ __asm__ __volatile__(
6369+ " ld %0, %1 \n"
6370+#ifdef CONFIG_PAX_REFCOUNT
6371+ /* Exception on overflow. */
6372+ "1: dadd %0, %2 \n"
6373+#else
6374+ " daddu %0, %2 \n"
6375+#endif
6376+ " sd %0, %1 \n"
6377+#ifdef CONFIG_PAX_REFCOUNT
6378+ /* Note: Dest reg is not modified on overflow */
6379+ "2: \n"
6380+ _ASM_EXTABLE(1b, 2b)
6381+#endif
6382+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6383+ raw_local_irq_restore(flags);
6384+ }
6385+
6386+ smp_llsc_mb();
6387+
6388+ return result;
6389+}
6390+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6391 {
6392 long result;
6393
6394@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6395 return result;
6396 }
6397
6398-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6399+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6400+{
6401+ long result;
6402+ long temp;
6403+
6404+ smp_mb__before_llsc();
6405+
6406+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6407+ long temp;
6408+
6409+ __asm__ __volatile__(
6410+ " .set mips3 \n"
6411+ "1: lld %1, %2 # atomic64_sub_return \n"
6412+#ifdef CONFIG_PAX_REFCOUNT
6413+ "2: dsub %0, %1, %3 \n"
6414+#else
6415+ " dsubu %0, %1, %3 \n"
6416+#endif
6417+ " scd %0, %2 \n"
6418+ " beqzl %0, 1b \n"
6419+#ifdef CONFIG_PAX_REFCOUNT
6420+ " b 4f \n"
6421+ " .set noreorder \n"
6422+ "3: b 5f \n"
6423+ " move %0, %1 \n"
6424+ " .set reorder \n"
6425+ _ASM_EXTABLE(2b, 3b)
6426+#endif
6427+ "4: dsubu %0, %1, %3 \n"
6428+#ifdef CONFIG_PAX_REFCOUNT
6429+ "5: \n"
6430+#endif
6431+ " .set mips0 \n"
6432+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6433+ : "Ir" (i), "m" (v->counter)
6434+ : "memory");
6435+ } else if (kernel_uses_llsc) {
6436+ __asm__ __volatile__(
6437+ " .set mips3 \n"
6438+ "1: lld %1, %2 # atomic64_sub_return \n"
6439+#ifdef CONFIG_PAX_REFCOUNT
6440+ "2: dsub %0, %1, %3 \n"
6441+#else
6442+ " dsubu %0, %1, %3 \n"
6443+#endif
6444+ " scd %0, %2 \n"
6445+ " bnez %0, 4f \n"
6446+ " b 1b \n"
6447+#ifdef CONFIG_PAX_REFCOUNT
6448+ " .set noreorder \n"
6449+ "3: b 5f \n"
6450+ " move %0, %1 \n"
6451+ " .set reorder \n"
6452+ _ASM_EXTABLE(2b, 3b)
6453+#endif
6454+ "4: dsubu %0, %1, %3 \n"
6455+#ifdef CONFIG_PAX_REFCOUNT
6456+ "5: \n"
6457+#endif
6458+ " .set mips0 \n"
6459+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6460+ : "Ir" (i), "m" (v->counter)
6461+ : "memory");
6462+ } else {
6463+ unsigned long flags;
6464+
6465+ raw_local_irq_save(flags);
6466+ __asm__ __volatile__(
6467+ " ld %0, %1 \n"
6468+#ifdef CONFIG_PAX_REFCOUNT
6469+ /* Exception on overflow. */
6470+ "1: dsub %0, %2 \n"
6471+#else
6472+ " dsubu %0, %2 \n"
6473+#endif
6474+ " sd %0, %1 \n"
6475+#ifdef CONFIG_PAX_REFCOUNT
6476+ /* Note: Dest reg is not modified on overflow */
6477+ "2: \n"
6478+ _ASM_EXTABLE(1b, 2b)
6479+#endif
6480+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6481+ raw_local_irq_restore(flags);
6482+ }
6483+
6484+ smp_llsc_mb();
6485+
6486+ return result;
6487+}
6488+
6489+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6490 {
6491 long result;
6492
6493@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6494 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6495 * The function returns the old value of @v minus @i.
6496 */
6497-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6498+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6499 {
6500 long result;
6501
6502@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6503 return result;
6504 }
6505
6506-#define atomic64_cmpxchg(v, o, n) \
6507- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6508-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6509+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6510+{
6511+ return cmpxchg(&v->counter, old, new);
6512+}
6513+
6514+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6515+ long new)
6516+{
6517+ return cmpxchg(&(v->counter), old, new);
6518+}
6519+
6520+static inline long atomic64_xchg(atomic64_t *v, long new)
6521+{
6522+ return xchg(&v->counter, new);
6523+}
6524+
6525+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6526+{
6527+ return xchg(&(v->counter), new);
6528+}
6529
6530 /**
6531 * atomic64_add_unless - add unless the number is a given value
6532@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6533
6534 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6535 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6536+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6537
6538 /*
6539 * atomic64_sub_and_test - subtract value from variable and test result
6540@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6541 * other cases.
6542 */
6543 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6544+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6545
6546 /*
6547 * atomic64_dec_and_test - decrement by 1 and test
6548@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6549 * Atomically increments @v by 1.
6550 */
6551 #define atomic64_inc(v) atomic64_add(1, (v))
6552+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6553
6554 /*
6555 * atomic64_dec - decrement and test
6556@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6557 * Atomically decrements @v by 1.
6558 */
6559 #define atomic64_dec(v) atomic64_sub(1, (v))
6560+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6561
6562 /*
6563 * atomic64_add_negative - add and test if negative
6564diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6565index e1aa4e4..670b68b 100644
6566--- a/arch/mips/include/asm/barrier.h
6567+++ b/arch/mips/include/asm/barrier.h
6568@@ -184,7 +184,7 @@
6569 do { \
6570 compiletime_assert_atomic_type(*p); \
6571 smp_mb(); \
6572- ACCESS_ONCE(*p) = (v); \
6573+ ACCESS_ONCE_RW(*p) = (v); \
6574 } while (0)
6575
6576 #define smp_load_acquire(p) \
6577diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6578index b4db69f..8f3b093 100644
6579--- a/arch/mips/include/asm/cache.h
6580+++ b/arch/mips/include/asm/cache.h
6581@@ -9,10 +9,11 @@
6582 #ifndef _ASM_CACHE_H
6583 #define _ASM_CACHE_H
6584
6585+#include <linux/const.h>
6586 #include <kmalloc.h>
6587
6588 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6589-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6590+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6591
6592 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6593 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6594diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6595index d414405..6bb4ba2 100644
6596--- a/arch/mips/include/asm/elf.h
6597+++ b/arch/mips/include/asm/elf.h
6598@@ -398,13 +398,16 @@ extern const char *__elf_platform;
6599 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6600 #endif
6601
6602+#ifdef CONFIG_PAX_ASLR
6603+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6604+
6605+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6606+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6607+#endif
6608+
6609 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6610 struct linux_binprm;
6611 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6612 int uses_interp);
6613
6614-struct mm_struct;
6615-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6616-#define arch_randomize_brk arch_randomize_brk
6617-
6618 #endif /* _ASM_ELF_H */
6619diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6620index c1f6afa..38cc6e9 100644
6621--- a/arch/mips/include/asm/exec.h
6622+++ b/arch/mips/include/asm/exec.h
6623@@ -12,6 +12,6 @@
6624 #ifndef _ASM_EXEC_H
6625 #define _ASM_EXEC_H
6626
6627-extern unsigned long arch_align_stack(unsigned long sp);
6628+#define arch_align_stack(x) ((x) & ~0xfUL)
6629
6630 #endif /* _ASM_EXEC_H */
6631diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6632index 9e8ef59..1139d6b 100644
6633--- a/arch/mips/include/asm/hw_irq.h
6634+++ b/arch/mips/include/asm/hw_irq.h
6635@@ -10,7 +10,7 @@
6636
6637 #include <linux/atomic.h>
6638
6639-extern atomic_t irq_err_count;
6640+extern atomic_unchecked_t irq_err_count;
6641
6642 /*
6643 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6644diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6645index 46dfc3c..a16b13a 100644
6646--- a/arch/mips/include/asm/local.h
6647+++ b/arch/mips/include/asm/local.h
6648@@ -12,15 +12,25 @@ typedef struct
6649 atomic_long_t a;
6650 } local_t;
6651
6652+typedef struct {
6653+ atomic_long_unchecked_t a;
6654+} local_unchecked_t;
6655+
6656 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6657
6658 #define local_read(l) atomic_long_read(&(l)->a)
6659+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6660 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6661+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6662
6663 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6664+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6665 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6666+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6667 #define local_inc(l) atomic_long_inc(&(l)->a)
6668+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6669 #define local_dec(l) atomic_long_dec(&(l)->a)
6670+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6671
6672 /*
6673 * Same as above, but return the result value
6674@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6675 return result;
6676 }
6677
6678+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6679+{
6680+ unsigned long result;
6681+
6682+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6683+ unsigned long temp;
6684+
6685+ __asm__ __volatile__(
6686+ " .set mips3 \n"
6687+ "1:" __LL "%1, %2 # local_add_return \n"
6688+ " addu %0, %1, %3 \n"
6689+ __SC "%0, %2 \n"
6690+ " beqzl %0, 1b \n"
6691+ " addu %0, %1, %3 \n"
6692+ " .set mips0 \n"
6693+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6694+ : "Ir" (i), "m" (l->a.counter)
6695+ : "memory");
6696+ } else if (kernel_uses_llsc) {
6697+ unsigned long temp;
6698+
6699+ __asm__ __volatile__(
6700+ " .set mips3 \n"
6701+ "1:" __LL "%1, %2 # local_add_return \n"
6702+ " addu %0, %1, %3 \n"
6703+ __SC "%0, %2 \n"
6704+ " beqz %0, 1b \n"
6705+ " addu %0, %1, %3 \n"
6706+ " .set mips0 \n"
6707+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6708+ : "Ir" (i), "m" (l->a.counter)
6709+ : "memory");
6710+ } else {
6711+ unsigned long flags;
6712+
6713+ local_irq_save(flags);
6714+ result = l->a.counter;
6715+ result += i;
6716+ l->a.counter = result;
6717+ local_irq_restore(flags);
6718+ }
6719+
6720+ return result;
6721+}
6722+
6723 static __inline__ long local_sub_return(long i, local_t * l)
6724 {
6725 unsigned long result;
6726@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6727
6728 #define local_cmpxchg(l, o, n) \
6729 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6730+#define local_cmpxchg_unchecked(l, o, n) \
6731+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6732 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6733
6734 /**
6735diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6736index 5699ec3..95def83 100644
6737--- a/arch/mips/include/asm/page.h
6738+++ b/arch/mips/include/asm/page.h
6739@@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6740 #ifdef CONFIG_CPU_MIPS32
6741 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6742 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6743- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6744+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6745 #else
6746 typedef struct { unsigned long long pte; } pte_t;
6747 #define pte_val(x) ((x).pte)
6748diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6749index b336037..5b874cc 100644
6750--- a/arch/mips/include/asm/pgalloc.h
6751+++ b/arch/mips/include/asm/pgalloc.h
6752@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6753 {
6754 set_pud(pud, __pud((unsigned long)pmd));
6755 }
6756+
6757+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6758+{
6759+ pud_populate(mm, pud, pmd);
6760+}
6761 #endif
6762
6763 /*
6764diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6765index 008324d..f67c239 100644
6766--- a/arch/mips/include/asm/pgtable.h
6767+++ b/arch/mips/include/asm/pgtable.h
6768@@ -20,6 +20,9 @@
6769 #include <asm/io.h>
6770 #include <asm/pgtable-bits.h>
6771
6772+#define ktla_ktva(addr) (addr)
6773+#define ktva_ktla(addr) (addr)
6774+
6775 struct mm_struct;
6776 struct vm_area_struct;
6777
6778diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6779index 25da651..ae2a259 100644
6780--- a/arch/mips/include/asm/smtc_proc.h
6781+++ b/arch/mips/include/asm/smtc_proc.h
6782@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6783
6784 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6785
6786-extern atomic_t smtc_fpu_recoveries;
6787+extern atomic_unchecked_t smtc_fpu_recoveries;
6788
6789 #endif /* __ASM_SMTC_PROC_H */
6790diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6791index d2d961d..a674df0 100644
6792--- a/arch/mips/include/asm/thread_info.h
6793+++ b/arch/mips/include/asm/thread_info.h
6794@@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6795 #define TIF_SECCOMP 4 /* secure computing */
6796 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6797 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6798+/* li takes a 32bit immediate */
6799+#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6800+
6801 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6802 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6803 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6804@@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6805 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6806 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6807 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6808+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6809
6810 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6811 _TIF_SYSCALL_AUDIT | \
6812- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6813+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6814+ _TIF_GRSEC_SETXID)
6815
6816 /* work to do in syscall_trace_leave() */
6817 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6818- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6819+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6820
6821 /* work to do on interrupt/exception return */
6822 #define _TIF_WORK_MASK \
6823@@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6824 /* work to do on any return to u-space */
6825 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6826 _TIF_WORK_SYSCALL_EXIT | \
6827- _TIF_SYSCALL_TRACEPOINT)
6828+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6829
6830 /*
6831 * We stash processor id into a COP0 register to retrieve it fast
6832diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6833index a109510..94ee3f6 100644
6834--- a/arch/mips/include/asm/uaccess.h
6835+++ b/arch/mips/include/asm/uaccess.h
6836@@ -130,6 +130,7 @@ extern u64 __ua_limit;
6837 __ok == 0; \
6838 })
6839
6840+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6841 #define access_ok(type, addr, size) \
6842 likely(__access_ok((addr), (size), __access_mask))
6843
6844diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6845index 1188e00..41cf144 100644
6846--- a/arch/mips/kernel/binfmt_elfn32.c
6847+++ b/arch/mips/kernel/binfmt_elfn32.c
6848@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6849 #undef ELF_ET_DYN_BASE
6850 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6851
6852+#ifdef CONFIG_PAX_ASLR
6853+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6854+
6855+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6856+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6857+#endif
6858+
6859 #include <asm/processor.h>
6860 #include <linux/module.h>
6861 #include <linux/elfcore.h>
6862diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6863index 7faf5f2..f3d3cf4 100644
6864--- a/arch/mips/kernel/binfmt_elfo32.c
6865+++ b/arch/mips/kernel/binfmt_elfo32.c
6866@@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6867 #undef ELF_ET_DYN_BASE
6868 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6869
6870+#ifdef CONFIG_PAX_ASLR
6871+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6872+
6873+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6874+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6875+#endif
6876+
6877 #include <asm/processor.h>
6878
6879 /*
6880diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6881index 2b91fe8..fe4f6b4 100644
6882--- a/arch/mips/kernel/i8259.c
6883+++ b/arch/mips/kernel/i8259.c
6884@@ -205,7 +205,7 @@ spurious_8259A_irq:
6885 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6886 spurious_irq_mask |= irqmask;
6887 }
6888- atomic_inc(&irq_err_count);
6889+ atomic_inc_unchecked(&irq_err_count);
6890 /*
6891 * Theoretically we do not have to handle this IRQ,
6892 * but in Linux this does not cause problems and is
6893diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6894index 44a1f79..2bd6aa3 100644
6895--- a/arch/mips/kernel/irq-gt641xx.c
6896+++ b/arch/mips/kernel/irq-gt641xx.c
6897@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6898 }
6899 }
6900
6901- atomic_inc(&irq_err_count);
6902+ atomic_inc_unchecked(&irq_err_count);
6903 }
6904
6905 void __init gt641xx_irq_init(void)
6906diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6907index d1fea7a..2e591b0 100644
6908--- a/arch/mips/kernel/irq.c
6909+++ b/arch/mips/kernel/irq.c
6910@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6911 printk("unexpected IRQ # %d\n", irq);
6912 }
6913
6914-atomic_t irq_err_count;
6915+atomic_unchecked_t irq_err_count;
6916
6917 int arch_show_interrupts(struct seq_file *p, int prec)
6918 {
6919- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6920+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6921 return 0;
6922 }
6923
6924 asmlinkage void spurious_interrupt(void)
6925 {
6926- atomic_inc(&irq_err_count);
6927+ atomic_inc_unchecked(&irq_err_count);
6928 }
6929
6930 void __init init_IRQ(void)
6931@@ -110,7 +110,10 @@ void __init init_IRQ(void)
6932 #endif
6933 }
6934
6935+
6936 #ifdef DEBUG_STACKOVERFLOW
6937+extern void gr_handle_kernel_exploit(void);
6938+
6939 static inline void check_stack_overflow(void)
6940 {
6941 unsigned long sp;
6942@@ -126,6 +129,7 @@ static inline void check_stack_overflow(void)
6943 printk("do_IRQ: stack overflow: %ld\n",
6944 sp - sizeof(struct thread_info));
6945 dump_stack();
6946+ gr_handle_kernel_exploit();
6947 }
6948 }
6949 #else
6950diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6951index 60e39dc..b4829bf 100644
6952--- a/arch/mips/kernel/process.c
6953+++ b/arch/mips/kernel/process.c
6954@@ -579,15 +579,3 @@ unsigned long get_wchan(struct task_struct *task)
6955 out:
6956 return pc;
6957 }
6958-
6959-/*
6960- * Don't forget that the stack pointer must be aligned on a 8 bytes
6961- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6962- */
6963-unsigned long arch_align_stack(unsigned long sp)
6964-{
6965- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6966- sp -= get_random_int() & ~PAGE_MASK;
6967-
6968- return sp & ALMASK;
6969-}
6970diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6971index f639ccd..e4b110d 100644
6972--- a/arch/mips/kernel/ptrace.c
6973+++ b/arch/mips/kernel/ptrace.c
6974@@ -630,6 +630,10 @@ long arch_ptrace(struct task_struct *child, long request,
6975 return ret;
6976 }
6977
6978+#ifdef CONFIG_GRKERNSEC_SETXID
6979+extern void gr_delayed_cred_worker(void);
6980+#endif
6981+
6982 /*
6983 * Notification of system call entry/exit
6984 * - triggered by current->work.syscall_trace
6985@@ -646,6 +650,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
6986 tracehook_report_syscall_entry(regs))
6987 ret = -1;
6988
6989+#ifdef CONFIG_GRKERNSEC_SETXID
6990+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6991+ gr_delayed_cred_worker();
6992+#endif
6993+
6994 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6995 trace_sys_enter(regs, regs->regs[2]);
6996
6997diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6998index 07fc524..b9d7f28 100644
6999--- a/arch/mips/kernel/reset.c
7000+++ b/arch/mips/kernel/reset.c
7001@@ -13,6 +13,7 @@
7002 #include <linux/reboot.h>
7003
7004 #include <asm/reboot.h>
7005+#include <asm/bug.h>
7006
7007 /*
7008 * Urgs ... Too many MIPS machines to handle this in a generic way.
7009@@ -29,16 +30,19 @@ void machine_restart(char *command)
7010 {
7011 if (_machine_restart)
7012 _machine_restart(command);
7013+ BUG();
7014 }
7015
7016 void machine_halt(void)
7017 {
7018 if (_machine_halt)
7019 _machine_halt();
7020+ BUG();
7021 }
7022
7023 void machine_power_off(void)
7024 {
7025 if (pm_power_off)
7026 pm_power_off();
7027+ BUG();
7028 }
7029diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
7030index 38635a9..3fcd5e0 100644
7031--- a/arch/mips/kernel/smtc-proc.c
7032+++ b/arch/mips/kernel/smtc-proc.c
7033@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
7034
7035 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
7036
7037-atomic_t smtc_fpu_recoveries;
7038+atomic_unchecked_t smtc_fpu_recoveries;
7039
7040 static int smtc_proc_show(struct seq_file *m, void *v)
7041 {
7042@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
7043 for(i = 0; i < NR_CPUS; i++)
7044 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
7045 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
7046- atomic_read(&smtc_fpu_recoveries));
7047+ atomic_read_unchecked(&smtc_fpu_recoveries));
7048 return 0;
7049 }
7050
7051@@ -73,7 +73,7 @@ void init_smtc_stats(void)
7052 smtc_cpu_stats[i].selfipis = 0;
7053 }
7054
7055- atomic_set(&smtc_fpu_recoveries, 0);
7056+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
7057
7058 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
7059 }
7060diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
7061index c1681d6..9f881d1 100644
7062--- a/arch/mips/kernel/smtc.c
7063+++ b/arch/mips/kernel/smtc.c
7064@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
7065 }
7066 smtc_ipi_qdump();
7067 printk("%d Recoveries of \"stolen\" FPU\n",
7068- atomic_read(&smtc_fpu_recoveries));
7069+ atomic_read_unchecked(&smtc_fpu_recoveries));
7070 }
7071
7072
7073diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7074index c24ad5f..9983ab2 100644
7075--- a/arch/mips/kernel/sync-r4k.c
7076+++ b/arch/mips/kernel/sync-r4k.c
7077@@ -20,8 +20,8 @@
7078 #include <asm/mipsregs.h>
7079
7080 static atomic_t count_start_flag = ATOMIC_INIT(0);
7081-static atomic_t count_count_start = ATOMIC_INIT(0);
7082-static atomic_t count_count_stop = ATOMIC_INIT(0);
7083+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7084+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7085 static atomic_t count_reference = ATOMIC_INIT(0);
7086
7087 #define COUNTON 100
7088@@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
7089
7090 for (i = 0; i < NR_LOOPS; i++) {
7091 /* slaves loop on '!= 2' */
7092- while (atomic_read(&count_count_start) != 1)
7093+ while (atomic_read_unchecked(&count_count_start) != 1)
7094 mb();
7095- atomic_set(&count_count_stop, 0);
7096+ atomic_set_unchecked(&count_count_stop, 0);
7097 smp_wmb();
7098
7099 /* this lets the slaves write their count register */
7100- atomic_inc(&count_count_start);
7101+ atomic_inc_unchecked(&count_count_start);
7102
7103 /*
7104 * Everyone initialises count in the last loop:
7105@@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
7106 /*
7107 * Wait for all slaves to leave the synchronization point:
7108 */
7109- while (atomic_read(&count_count_stop) != 1)
7110+ while (atomic_read_unchecked(&count_count_stop) != 1)
7111 mb();
7112- atomic_set(&count_count_start, 0);
7113+ atomic_set_unchecked(&count_count_start, 0);
7114 smp_wmb();
7115- atomic_inc(&count_count_stop);
7116+ atomic_inc_unchecked(&count_count_stop);
7117 }
7118 /* Arrange for an interrupt in a short while */
7119 write_c0_compare(read_c0_count() + COUNTON);
7120@@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
7121 initcount = atomic_read(&count_reference);
7122
7123 for (i = 0; i < NR_LOOPS; i++) {
7124- atomic_inc(&count_count_start);
7125- while (atomic_read(&count_count_start) != 2)
7126+ atomic_inc_unchecked(&count_count_start);
7127+ while (atomic_read_unchecked(&count_count_start) != 2)
7128 mb();
7129
7130 /*
7131@@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
7132 if (i == NR_LOOPS-1)
7133 write_c0_count(initcount);
7134
7135- atomic_inc(&count_count_stop);
7136- while (atomic_read(&count_count_stop) != 2)
7137+ atomic_inc_unchecked(&count_count_stop);
7138+ while (atomic_read_unchecked(&count_count_stop) != 2)
7139 mb();
7140 }
7141 /* Arrange for an interrupt in a short while */
7142diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7143index 8119ac2..b229939 100644
7144--- a/arch/mips/kernel/traps.c
7145+++ b/arch/mips/kernel/traps.c
7146@@ -695,7 +695,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7147 siginfo_t info;
7148
7149 prev_state = exception_enter();
7150- die_if_kernel("Integer overflow", regs);
7151+ if (unlikely(!user_mode(regs))) {
7152+
7153+#ifdef CONFIG_PAX_REFCOUNT
7154+ if (fixup_exception(regs)) {
7155+ pax_report_refcount_overflow(regs);
7156+ exception_exit(prev_state);
7157+ return;
7158+ }
7159+#endif
7160+
7161+ die("Integer overflow", regs);
7162+ }
7163
7164 info.si_code = FPE_INTOVF;
7165 info.si_signo = SIGFPE;
7166diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7167index becc42b..9e43d4b 100644
7168--- a/arch/mips/mm/fault.c
7169+++ b/arch/mips/mm/fault.c
7170@@ -28,6 +28,23 @@
7171 #include <asm/highmem.h> /* For VMALLOC_END */
7172 #include <linux/kdebug.h>
7173
7174+#ifdef CONFIG_PAX_PAGEEXEC
7175+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7176+{
7177+ unsigned long i;
7178+
7179+ printk(KERN_ERR "PAX: bytes at PC: ");
7180+ for (i = 0; i < 5; i++) {
7181+ unsigned int c;
7182+ if (get_user(c, (unsigned int *)pc+i))
7183+ printk(KERN_CONT "???????? ");
7184+ else
7185+ printk(KERN_CONT "%08x ", c);
7186+ }
7187+ printk("\n");
7188+}
7189+#endif
7190+
7191 /*
7192 * This routine handles page faults. It determines the address,
7193 * and the problem, and then passes it off to one of the appropriate
7194@@ -199,6 +216,14 @@ bad_area:
7195 bad_area_nosemaphore:
7196 /* User mode accesses just cause a SIGSEGV */
7197 if (user_mode(regs)) {
7198+
7199+#ifdef CONFIG_PAX_PAGEEXEC
7200+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7201+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7202+ do_group_exit(SIGKILL);
7203+ }
7204+#endif
7205+
7206 tsk->thread.cp0_badvaddr = address;
7207 tsk->thread.error_code = write;
7208 #if 0
7209diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7210index f1baadd..5472dca 100644
7211--- a/arch/mips/mm/mmap.c
7212+++ b/arch/mips/mm/mmap.c
7213@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7214 struct vm_area_struct *vma;
7215 unsigned long addr = addr0;
7216 int do_color_align;
7217+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7218 struct vm_unmapped_area_info info;
7219
7220 if (unlikely(len > TASK_SIZE))
7221@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7222 do_color_align = 1;
7223
7224 /* requesting a specific address */
7225+
7226+#ifdef CONFIG_PAX_RANDMMAP
7227+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7228+#endif
7229+
7230 if (addr) {
7231 if (do_color_align)
7232 addr = COLOUR_ALIGN(addr, pgoff);
7233@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7234 addr = PAGE_ALIGN(addr);
7235
7236 vma = find_vma(mm, addr);
7237- if (TASK_SIZE - len >= addr &&
7238- (!vma || addr + len <= vma->vm_start))
7239+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7240 return addr;
7241 }
7242
7243 info.length = len;
7244 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7245 info.align_offset = pgoff << PAGE_SHIFT;
7246+ info.threadstack_offset = offset;
7247
7248 if (dir == DOWN) {
7249 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7250@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7251 {
7252 unsigned long random_factor = 0UL;
7253
7254+#ifdef CONFIG_PAX_RANDMMAP
7255+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7256+#endif
7257+
7258 if (current->flags & PF_RANDOMIZE) {
7259 random_factor = get_random_int();
7260 random_factor = random_factor << PAGE_SHIFT;
7261@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7262
7263 if (mmap_is_legacy()) {
7264 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7265+
7266+#ifdef CONFIG_PAX_RANDMMAP
7267+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7268+ mm->mmap_base += mm->delta_mmap;
7269+#endif
7270+
7271 mm->get_unmapped_area = arch_get_unmapped_area;
7272 } else {
7273 mm->mmap_base = mmap_base(random_factor);
7274+
7275+#ifdef CONFIG_PAX_RANDMMAP
7276+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7277+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7278+#endif
7279+
7280 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7281 }
7282 }
7283
7284-static inline unsigned long brk_rnd(void)
7285-{
7286- unsigned long rnd = get_random_int();
7287-
7288- rnd = rnd << PAGE_SHIFT;
7289- /* 8MB for 32bit, 256MB for 64bit */
7290- if (TASK_IS_32BIT_ADDR)
7291- rnd = rnd & 0x7ffffful;
7292- else
7293- rnd = rnd & 0xffffffful;
7294-
7295- return rnd;
7296-}
7297-
7298-unsigned long arch_randomize_brk(struct mm_struct *mm)
7299-{
7300- unsigned long base = mm->brk;
7301- unsigned long ret;
7302-
7303- ret = PAGE_ALIGN(base + brk_rnd());
7304-
7305- if (ret < mm->brk)
7306- return mm->brk;
7307-
7308- return ret;
7309-}
7310-
7311 int __virt_addr_valid(const volatile void *kaddr)
7312 {
7313 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7314diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7315index 59cccd9..f39ac2f 100644
7316--- a/arch/mips/pci/pci-octeon.c
7317+++ b/arch/mips/pci/pci-octeon.c
7318@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7319
7320
7321 static struct pci_ops octeon_pci_ops = {
7322- octeon_read_config,
7323- octeon_write_config,
7324+ .read = octeon_read_config,
7325+ .write = octeon_write_config,
7326 };
7327
7328 static struct resource octeon_pci_mem_resource = {
7329diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7330index 5e36c33..eb4a17b 100644
7331--- a/arch/mips/pci/pcie-octeon.c
7332+++ b/arch/mips/pci/pcie-octeon.c
7333@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7334 }
7335
7336 static struct pci_ops octeon_pcie0_ops = {
7337- octeon_pcie0_read_config,
7338- octeon_pcie0_write_config,
7339+ .read = octeon_pcie0_read_config,
7340+ .write = octeon_pcie0_write_config,
7341 };
7342
7343 static struct resource octeon_pcie0_mem_resource = {
7344@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7345 };
7346
7347 static struct pci_ops octeon_pcie1_ops = {
7348- octeon_pcie1_read_config,
7349- octeon_pcie1_write_config,
7350+ .read = octeon_pcie1_read_config,
7351+ .write = octeon_pcie1_write_config,
7352 };
7353
7354 static struct resource octeon_pcie1_mem_resource = {
7355@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7356 };
7357
7358 static struct pci_ops octeon_dummy_ops = {
7359- octeon_dummy_read_config,
7360- octeon_dummy_write_config,
7361+ .read = octeon_dummy_read_config,
7362+ .write = octeon_dummy_write_config,
7363 };
7364
7365 static struct resource octeon_dummy_mem_resource = {
7366diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7367index a2358b4..7cead4f 100644
7368--- a/arch/mips/sgi-ip27/ip27-nmi.c
7369+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7370@@ -187,9 +187,9 @@ void
7371 cont_nmi_dump(void)
7372 {
7373 #ifndef REAL_NMI_SIGNAL
7374- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7375+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7376
7377- atomic_inc(&nmied_cpus);
7378+ atomic_inc_unchecked(&nmied_cpus);
7379 #endif
7380 /*
7381 * Only allow 1 cpu to proceed
7382@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7383 udelay(10000);
7384 }
7385 #else
7386- while (atomic_read(&nmied_cpus) != num_online_cpus());
7387+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7388 #endif
7389
7390 /*
7391diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7392index a046b30..6799527 100644
7393--- a/arch/mips/sni/rm200.c
7394+++ b/arch/mips/sni/rm200.c
7395@@ -270,7 +270,7 @@ spurious_8259A_irq:
7396 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7397 spurious_irq_mask |= irqmask;
7398 }
7399- atomic_inc(&irq_err_count);
7400+ atomic_inc_unchecked(&irq_err_count);
7401 /*
7402 * Theoretically we do not have to handle this IRQ,
7403 * but in Linux this does not cause problems and is
7404diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7405index 41e873b..34d33a7 100644
7406--- a/arch/mips/vr41xx/common/icu.c
7407+++ b/arch/mips/vr41xx/common/icu.c
7408@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7409
7410 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7411
7412- atomic_inc(&irq_err_count);
7413+ atomic_inc_unchecked(&irq_err_count);
7414
7415 return -1;
7416 }
7417diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7418index ae0e4ee..e8f0692 100644
7419--- a/arch/mips/vr41xx/common/irq.c
7420+++ b/arch/mips/vr41xx/common/irq.c
7421@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7422 irq_cascade_t *cascade;
7423
7424 if (irq >= NR_IRQS) {
7425- atomic_inc(&irq_err_count);
7426+ atomic_inc_unchecked(&irq_err_count);
7427 return;
7428 }
7429
7430@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7431 ret = cascade->get_irq(irq);
7432 irq = ret;
7433 if (ret < 0)
7434- atomic_inc(&irq_err_count);
7435+ atomic_inc_unchecked(&irq_err_count);
7436 else
7437 irq_dispatch(irq);
7438 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7439diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7440index 967d144..db12197 100644
7441--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7442+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7443@@ -11,12 +11,14 @@
7444 #ifndef _ASM_PROC_CACHE_H
7445 #define _ASM_PROC_CACHE_H
7446
7447+#include <linux/const.h>
7448+
7449 /* L1 cache */
7450
7451 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7452 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7453-#define L1_CACHE_BYTES 16 /* bytes per entry */
7454 #define L1_CACHE_SHIFT 4 /* 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 /* displacement of one way from the next */
7457
7458 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7459diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7460index bcb5df2..84fabd2 100644
7461--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7462+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7463@@ -16,13 +16,15 @@
7464 #ifndef _ASM_PROC_CACHE_H
7465 #define _ASM_PROC_CACHE_H
7466
7467+#include <linux/const.h>
7468+
7469 /*
7470 * L1 cache
7471 */
7472 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7473 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7474-#define L1_CACHE_BYTES 32 /* bytes per entry */
7475 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7476+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7477 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7478
7479 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7480diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7481index 4ce7a01..449202a 100644
7482--- a/arch/openrisc/include/asm/cache.h
7483+++ b/arch/openrisc/include/asm/cache.h
7484@@ -19,11 +19,13 @@
7485 #ifndef __ASM_OPENRISC_CACHE_H
7486 #define __ASM_OPENRISC_CACHE_H
7487
7488+#include <linux/const.h>
7489+
7490 /* FIXME: How can we replace these with values from the CPU...
7491 * they shouldn't be hard-coded!
7492 */
7493
7494-#define L1_CACHE_BYTES 16
7495 #define L1_CACHE_SHIFT 4
7496+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7497
7498 #endif /* __ASM_OPENRISC_CACHE_H */
7499diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7500index 472886c..00e7df9 100644
7501--- a/arch/parisc/include/asm/atomic.h
7502+++ b/arch/parisc/include/asm/atomic.h
7503@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7504 return dec;
7505 }
7506
7507+#define atomic64_read_unchecked(v) atomic64_read(v)
7508+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7509+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7510+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7511+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7512+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7513+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7514+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7515+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7516+
7517 #endif /* !CONFIG_64BIT */
7518
7519
7520diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7521index 47f11c7..3420df2 100644
7522--- a/arch/parisc/include/asm/cache.h
7523+++ b/arch/parisc/include/asm/cache.h
7524@@ -5,6 +5,7 @@
7525 #ifndef __ARCH_PARISC_CACHE_H
7526 #define __ARCH_PARISC_CACHE_H
7527
7528+#include <linux/const.h>
7529
7530 /*
7531 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7532@@ -15,13 +16,13 @@
7533 * just ruin performance.
7534 */
7535 #ifdef CONFIG_PA20
7536-#define L1_CACHE_BYTES 64
7537 #define L1_CACHE_SHIFT 6
7538 #else
7539-#define L1_CACHE_BYTES 32
7540 #define L1_CACHE_SHIFT 5
7541 #endif
7542
7543+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7544+
7545 #ifndef __ASSEMBLY__
7546
7547 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7548diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7549index 3391d06..c23a2cc 100644
7550--- a/arch/parisc/include/asm/elf.h
7551+++ b/arch/parisc/include/asm/elf.h
7552@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7553
7554 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7555
7556+#ifdef CONFIG_PAX_ASLR
7557+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7558+
7559+#define PAX_DELTA_MMAP_LEN 16
7560+#define PAX_DELTA_STACK_LEN 16
7561+#endif
7562+
7563 /* This yields a mask that user programs can use to figure out what
7564 instruction set this CPU supports. This could be done in user space,
7565 but it's not easy, and we've already done it here. */
7566diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7567index f213f5b..0af3e8e 100644
7568--- a/arch/parisc/include/asm/pgalloc.h
7569+++ b/arch/parisc/include/asm/pgalloc.h
7570@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7571 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7572 }
7573
7574+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7575+{
7576+ pgd_populate(mm, pgd, pmd);
7577+}
7578+
7579 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7580 {
7581 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7582@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7583 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7584 #define pmd_free(mm, x) do { } while (0)
7585 #define pgd_populate(mm, pmd, pte) BUG()
7586+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7587
7588 #endif
7589
7590diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7591index 22b89d1..ce34230 100644
7592--- a/arch/parisc/include/asm/pgtable.h
7593+++ b/arch/parisc/include/asm/pgtable.h
7594@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7595 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7596 #define PAGE_COPY PAGE_EXECREAD
7597 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7598+
7599+#ifdef CONFIG_PAX_PAGEEXEC
7600+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7601+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7602+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7603+#else
7604+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7605+# define PAGE_COPY_NOEXEC PAGE_COPY
7606+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7607+#endif
7608+
7609 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7610 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7611 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7612diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7613index 4006964..fcb3cc2 100644
7614--- a/arch/parisc/include/asm/uaccess.h
7615+++ b/arch/parisc/include/asm/uaccess.h
7616@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7617 const void __user *from,
7618 unsigned long n)
7619 {
7620- int sz = __compiletime_object_size(to);
7621+ size_t sz = __compiletime_object_size(to);
7622 int ret = -EFAULT;
7623
7624- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7625+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7626 ret = __copy_from_user(to, from, n);
7627 else
7628 copy_from_user_overflow();
7629diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7630index 50dfafc..b9fc230 100644
7631--- a/arch/parisc/kernel/module.c
7632+++ b/arch/parisc/kernel/module.c
7633@@ -98,16 +98,38 @@
7634
7635 /* three functions to determine where in the module core
7636 * or init pieces the location is */
7637+static inline int in_init_rx(struct module *me, void *loc)
7638+{
7639+ return (loc >= me->module_init_rx &&
7640+ loc < (me->module_init_rx + me->init_size_rx));
7641+}
7642+
7643+static inline int in_init_rw(struct module *me, void *loc)
7644+{
7645+ return (loc >= me->module_init_rw &&
7646+ loc < (me->module_init_rw + me->init_size_rw));
7647+}
7648+
7649 static inline int in_init(struct module *me, void *loc)
7650 {
7651- return (loc >= me->module_init &&
7652- loc <= (me->module_init + me->init_size));
7653+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7654+}
7655+
7656+static inline int in_core_rx(struct module *me, void *loc)
7657+{
7658+ return (loc >= me->module_core_rx &&
7659+ loc < (me->module_core_rx + me->core_size_rx));
7660+}
7661+
7662+static inline int in_core_rw(struct module *me, void *loc)
7663+{
7664+ return (loc >= me->module_core_rw &&
7665+ loc < (me->module_core_rw + me->core_size_rw));
7666 }
7667
7668 static inline int in_core(struct module *me, void *loc)
7669 {
7670- return (loc >= me->module_core &&
7671- loc <= (me->module_core + me->core_size));
7672+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7673 }
7674
7675 static inline int in_local(struct module *me, void *loc)
7676@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7677 }
7678
7679 /* align things a bit */
7680- me->core_size = ALIGN(me->core_size, 16);
7681- me->arch.got_offset = me->core_size;
7682- me->core_size += gots * sizeof(struct got_entry);
7683+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7684+ me->arch.got_offset = me->core_size_rw;
7685+ me->core_size_rw += gots * sizeof(struct got_entry);
7686
7687- me->core_size = ALIGN(me->core_size, 16);
7688- me->arch.fdesc_offset = me->core_size;
7689- me->core_size += fdescs * sizeof(Elf_Fdesc);
7690+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7691+ me->arch.fdesc_offset = me->core_size_rw;
7692+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7693
7694 me->arch.got_max = gots;
7695 me->arch.fdesc_max = fdescs;
7696@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7697
7698 BUG_ON(value == 0);
7699
7700- got = me->module_core + me->arch.got_offset;
7701+ got = me->module_core_rw + me->arch.got_offset;
7702 for (i = 0; got[i].addr; i++)
7703 if (got[i].addr == value)
7704 goto out;
7705@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7706 #ifdef CONFIG_64BIT
7707 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7708 {
7709- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7710+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7711
7712 if (!value) {
7713 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7714@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7715
7716 /* Create new one */
7717 fdesc->addr = value;
7718- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7719+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7720 return (Elf_Addr)fdesc;
7721 }
7722 #endif /* CONFIG_64BIT */
7723@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7724
7725 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7726 end = table + sechdrs[me->arch.unwind_section].sh_size;
7727- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7728+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7729
7730 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7731 me->arch.unwind_section, table, end, gp);
7732diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7733index e1ffea2..46ed66e 100644
7734--- a/arch/parisc/kernel/sys_parisc.c
7735+++ b/arch/parisc/kernel/sys_parisc.c
7736@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7737 unsigned long task_size = TASK_SIZE;
7738 int do_color_align, last_mmap;
7739 struct vm_unmapped_area_info info;
7740+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7741
7742 if (len > task_size)
7743 return -ENOMEM;
7744@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7745 goto found_addr;
7746 }
7747
7748+#ifdef CONFIG_PAX_RANDMMAP
7749+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7750+#endif
7751+
7752 if (addr) {
7753 if (do_color_align && last_mmap)
7754 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7755@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7756 info.high_limit = mmap_upper_limit();
7757 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7758 info.align_offset = shared_align_offset(last_mmap, pgoff);
7759+ info.threadstack_offset = offset;
7760 addr = vm_unmapped_area(&info);
7761
7762 found_addr:
7763@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7764 unsigned long addr = addr0;
7765 int do_color_align, last_mmap;
7766 struct vm_unmapped_area_info info;
7767+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7768
7769 #ifdef CONFIG_64BIT
7770 /* This should only ever run for 32-bit processes. */
7771@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7772 }
7773
7774 /* requesting a specific address */
7775+#ifdef CONFIG_PAX_RANDMMAP
7776+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7777+#endif
7778+
7779 if (addr) {
7780 if (do_color_align && last_mmap)
7781 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7782@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7783 info.high_limit = mm->mmap_base;
7784 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7785 info.align_offset = shared_align_offset(last_mmap, pgoff);
7786+ info.threadstack_offset = offset;
7787 addr = vm_unmapped_area(&info);
7788 if (!(addr & ~PAGE_MASK))
7789 goto found_addr;
7790@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7791 mm->mmap_legacy_base = mmap_legacy_base();
7792 mm->mmap_base = mmap_upper_limit();
7793
7794+#ifdef CONFIG_PAX_RANDMMAP
7795+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
7796+ mm->mmap_legacy_base += mm->delta_mmap;
7797+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7798+ }
7799+#endif
7800+
7801 if (mmap_is_legacy()) {
7802 mm->mmap_base = mm->mmap_legacy_base;
7803 mm->get_unmapped_area = arch_get_unmapped_area;
7804diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7805index 47ee620..1107387 100644
7806--- a/arch/parisc/kernel/traps.c
7807+++ b/arch/parisc/kernel/traps.c
7808@@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7809
7810 down_read(&current->mm->mmap_sem);
7811 vma = find_vma(current->mm,regs->iaoq[0]);
7812- if (vma && (regs->iaoq[0] >= vma->vm_start)
7813- && (vma->vm_flags & VM_EXEC)) {
7814-
7815+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7816 fault_address = regs->iaoq[0];
7817 fault_space = regs->iasq[0];
7818
7819diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7820index 3ca9c11..d163ef7 100644
7821--- a/arch/parisc/mm/fault.c
7822+++ b/arch/parisc/mm/fault.c
7823@@ -15,6 +15,7 @@
7824 #include <linux/sched.h>
7825 #include <linux/interrupt.h>
7826 #include <linux/module.h>
7827+#include <linux/unistd.h>
7828
7829 #include <asm/uaccess.h>
7830 #include <asm/traps.h>
7831@@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7832 static unsigned long
7833 parisc_acctyp(unsigned long code, unsigned int inst)
7834 {
7835- if (code == 6 || code == 16)
7836+ if (code == 6 || code == 7 || code == 16)
7837 return VM_EXEC;
7838
7839 switch (inst & 0xf0000000) {
7840@@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7841 }
7842 #endif
7843
7844+#ifdef CONFIG_PAX_PAGEEXEC
7845+/*
7846+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7847+ *
7848+ * returns 1 when task should be killed
7849+ * 2 when rt_sigreturn trampoline was detected
7850+ * 3 when unpatched PLT trampoline was detected
7851+ */
7852+static int pax_handle_fetch_fault(struct pt_regs *regs)
7853+{
7854+
7855+#ifdef CONFIG_PAX_EMUPLT
7856+ int err;
7857+
7858+ do { /* PaX: unpatched PLT emulation */
7859+ unsigned int bl, depwi;
7860+
7861+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7862+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7863+
7864+ if (err)
7865+ break;
7866+
7867+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7868+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7869+
7870+ err = get_user(ldw, (unsigned int *)addr);
7871+ err |= get_user(bv, (unsigned int *)(addr+4));
7872+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7873+
7874+ if (err)
7875+ break;
7876+
7877+ if (ldw == 0x0E801096U &&
7878+ bv == 0xEAC0C000U &&
7879+ ldw2 == 0x0E881095U)
7880+ {
7881+ unsigned int resolver, map;
7882+
7883+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7884+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7885+ if (err)
7886+ break;
7887+
7888+ regs->gr[20] = instruction_pointer(regs)+8;
7889+ regs->gr[21] = map;
7890+ regs->gr[22] = resolver;
7891+ regs->iaoq[0] = resolver | 3UL;
7892+ regs->iaoq[1] = regs->iaoq[0] + 4;
7893+ return 3;
7894+ }
7895+ }
7896+ } while (0);
7897+#endif
7898+
7899+#ifdef CONFIG_PAX_EMUTRAMP
7900+
7901+#ifndef CONFIG_PAX_EMUSIGRT
7902+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7903+ return 1;
7904+#endif
7905+
7906+ do { /* PaX: rt_sigreturn emulation */
7907+ unsigned int ldi1, ldi2, bel, nop;
7908+
7909+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7910+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7911+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7912+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7913+
7914+ if (err)
7915+ break;
7916+
7917+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7918+ ldi2 == 0x3414015AU &&
7919+ bel == 0xE4008200U &&
7920+ nop == 0x08000240U)
7921+ {
7922+ regs->gr[25] = (ldi1 & 2) >> 1;
7923+ regs->gr[20] = __NR_rt_sigreturn;
7924+ regs->gr[31] = regs->iaoq[1] + 16;
7925+ regs->sr[0] = regs->iasq[1];
7926+ regs->iaoq[0] = 0x100UL;
7927+ regs->iaoq[1] = regs->iaoq[0] + 4;
7928+ regs->iasq[0] = regs->sr[2];
7929+ regs->iasq[1] = regs->sr[2];
7930+ return 2;
7931+ }
7932+ } while (0);
7933+#endif
7934+
7935+ return 1;
7936+}
7937+
7938+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7939+{
7940+ unsigned long i;
7941+
7942+ printk(KERN_ERR "PAX: bytes at PC: ");
7943+ for (i = 0; i < 5; i++) {
7944+ unsigned int c;
7945+ if (get_user(c, (unsigned int *)pc+i))
7946+ printk(KERN_CONT "???????? ");
7947+ else
7948+ printk(KERN_CONT "%08x ", c);
7949+ }
7950+ printk("\n");
7951+}
7952+#endif
7953+
7954 int fixup_exception(struct pt_regs *regs)
7955 {
7956 const struct exception_table_entry *fix;
7957@@ -234,8 +345,33 @@ retry:
7958
7959 good_area:
7960
7961- if ((vma->vm_flags & acc_type) != acc_type)
7962+ if ((vma->vm_flags & acc_type) != acc_type) {
7963+
7964+#ifdef CONFIG_PAX_PAGEEXEC
7965+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7966+ (address & ~3UL) == instruction_pointer(regs))
7967+ {
7968+ up_read(&mm->mmap_sem);
7969+ switch (pax_handle_fetch_fault(regs)) {
7970+
7971+#ifdef CONFIG_PAX_EMUPLT
7972+ case 3:
7973+ return;
7974+#endif
7975+
7976+#ifdef CONFIG_PAX_EMUTRAMP
7977+ case 2:
7978+ return;
7979+#endif
7980+
7981+ }
7982+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7983+ do_group_exit(SIGKILL);
7984+ }
7985+#endif
7986+
7987 goto bad_area;
7988+ }
7989
7990 /*
7991 * If for any reason at all we couldn't handle the fault, make
7992diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7993index e099899..457d6a8 100644
7994--- a/arch/powerpc/Kconfig
7995+++ b/arch/powerpc/Kconfig
7996@@ -397,6 +397,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7997 config KEXEC
7998 bool "kexec system call"
7999 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8000+ depends on !GRKERNSEC_KMEM
8001 help
8002 kexec is a system call that implements the ability to shutdown your
8003 current kernel, and to start another kernel. It is like a reboot
8004diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8005index e3b1d41..8e81edf 100644
8006--- a/arch/powerpc/include/asm/atomic.h
8007+++ b/arch/powerpc/include/asm/atomic.h
8008@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
8009 return t1;
8010 }
8011
8012+#define atomic64_read_unchecked(v) atomic64_read(v)
8013+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8014+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8015+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8016+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8017+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8018+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8019+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8020+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8021+
8022 #endif /* __powerpc64__ */
8023
8024 #endif /* __KERNEL__ */
8025diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8026index f89da80..7f5b05a 100644
8027--- a/arch/powerpc/include/asm/barrier.h
8028+++ b/arch/powerpc/include/asm/barrier.h
8029@@ -73,7 +73,7 @@
8030 do { \
8031 compiletime_assert_atomic_type(*p); \
8032 __lwsync(); \
8033- ACCESS_ONCE(*p) = (v); \
8034+ ACCESS_ONCE_RW(*p) = (v); \
8035 } while (0)
8036
8037 #define smp_load_acquire(p) \
8038diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8039index ed0afc1..0332825 100644
8040--- a/arch/powerpc/include/asm/cache.h
8041+++ b/arch/powerpc/include/asm/cache.h
8042@@ -3,6 +3,7 @@
8043
8044 #ifdef __KERNEL__
8045
8046+#include <linux/const.h>
8047
8048 /* bytes per L1 cache line */
8049 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8050@@ -22,7 +23,7 @@
8051 #define L1_CACHE_SHIFT 7
8052 #endif
8053
8054-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8055+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8056
8057 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8058
8059diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8060index 935b5e7..7001d2d 100644
8061--- a/arch/powerpc/include/asm/elf.h
8062+++ b/arch/powerpc/include/asm/elf.h
8063@@ -28,8 +28,19 @@
8064 the loader. We need to make sure that it is out of the way of the program
8065 that it will "exec", and that there is sufficient room for the brk. */
8066
8067-extern unsigned long randomize_et_dyn(unsigned long base);
8068-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8069+#define ELF_ET_DYN_BASE (0x20000000)
8070+
8071+#ifdef CONFIG_PAX_ASLR
8072+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8073+
8074+#ifdef __powerpc64__
8075+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8076+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8077+#else
8078+#define PAX_DELTA_MMAP_LEN 15
8079+#define PAX_DELTA_STACK_LEN 15
8080+#endif
8081+#endif
8082
8083 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8084
8085@@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8086 (0x7ff >> (PAGE_SHIFT - 12)) : \
8087 (0x3ffff >> (PAGE_SHIFT - 12)))
8088
8089-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8090-#define arch_randomize_brk arch_randomize_brk
8091-
8092-
8093 #ifdef CONFIG_SPU_BASE
8094 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8095 #define NT_SPU 1
8096diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8097index 8196e9c..d83a9f3 100644
8098--- a/arch/powerpc/include/asm/exec.h
8099+++ b/arch/powerpc/include/asm/exec.h
8100@@ -4,6 +4,6 @@
8101 #ifndef _ASM_POWERPC_EXEC_H
8102 #define _ASM_POWERPC_EXEC_H
8103
8104-extern unsigned long arch_align_stack(unsigned long sp);
8105+#define arch_align_stack(x) ((x) & ~0xfUL)
8106
8107 #endif /* _ASM_POWERPC_EXEC_H */
8108diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8109index 5acabbd..7ea14fa 100644
8110--- a/arch/powerpc/include/asm/kmap_types.h
8111+++ b/arch/powerpc/include/asm/kmap_types.h
8112@@ -10,7 +10,7 @@
8113 * 2 of the License, or (at your option) any later version.
8114 */
8115
8116-#define KM_TYPE_NR 16
8117+#define KM_TYPE_NR 17
8118
8119 #endif /* __KERNEL__ */
8120 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8121diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8122index b8da913..60b608a 100644
8123--- a/arch/powerpc/include/asm/local.h
8124+++ b/arch/powerpc/include/asm/local.h
8125@@ -9,15 +9,26 @@ typedef struct
8126 atomic_long_t a;
8127 } local_t;
8128
8129+typedef struct
8130+{
8131+ atomic_long_unchecked_t a;
8132+} local_unchecked_t;
8133+
8134 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8135
8136 #define local_read(l) atomic_long_read(&(l)->a)
8137+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8138 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8139+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8140
8141 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8142+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8143 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8144+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8145 #define local_inc(l) atomic_long_inc(&(l)->a)
8146+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8147 #define local_dec(l) atomic_long_dec(&(l)->a)
8148+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8149
8150 static __inline__ long local_add_return(long a, local_t *l)
8151 {
8152@@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8153
8154 return t;
8155 }
8156+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8157
8158 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8159
8160@@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8161
8162 return t;
8163 }
8164+#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8165
8166 static __inline__ long local_inc_return(local_t *l)
8167 {
8168@@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8169
8170 #define local_cmpxchg(l, o, n) \
8171 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8172+#define local_cmpxchg_unchecked(l, o, n) \
8173+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8174 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8175
8176 /**
8177diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8178index 8565c25..2865190 100644
8179--- a/arch/powerpc/include/asm/mman.h
8180+++ b/arch/powerpc/include/asm/mman.h
8181@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8182 }
8183 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8184
8185-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8186+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8187 {
8188 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8189 }
8190diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8191index 32e4e21..62afb12 100644
8192--- a/arch/powerpc/include/asm/page.h
8193+++ b/arch/powerpc/include/asm/page.h
8194@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8195 * and needs to be executable. This means the whole heap ends
8196 * up being executable.
8197 */
8198-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8199- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8200+#define VM_DATA_DEFAULT_FLAGS32 \
8201+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8202+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8203
8204 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8205 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8206@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8207 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8208 #endif
8209
8210+#define ktla_ktva(addr) (addr)
8211+#define ktva_ktla(addr) (addr)
8212+
8213 #ifndef CONFIG_PPC_BOOK3S_64
8214 /*
8215 * Use the top bit of the higher-level page table entries to indicate whether
8216diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8217index 88693ce..ac6f9ab 100644
8218--- a/arch/powerpc/include/asm/page_64.h
8219+++ b/arch/powerpc/include/asm/page_64.h
8220@@ -153,15 +153,18 @@ do { \
8221 * stack by default, so in the absence of a PT_GNU_STACK program header
8222 * we turn execute permission off.
8223 */
8224-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8225- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8226+#define VM_STACK_DEFAULT_FLAGS32 \
8227+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8228+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8229
8230 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8231 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8232
8233+#ifndef CONFIG_PAX_PAGEEXEC
8234 #define VM_STACK_DEFAULT_FLAGS \
8235 (is_32bit_task() ? \
8236 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8237+#endif
8238
8239 #include <asm-generic/getorder.h>
8240
8241diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8242index 4b0be20..c15a27d 100644
8243--- a/arch/powerpc/include/asm/pgalloc-64.h
8244+++ b/arch/powerpc/include/asm/pgalloc-64.h
8245@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8246 #ifndef CONFIG_PPC_64K_PAGES
8247
8248 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8249+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8250
8251 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8252 {
8253@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8254 pud_set(pud, (unsigned long)pmd);
8255 }
8256
8257+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8258+{
8259+ pud_populate(mm, pud, pmd);
8260+}
8261+
8262 #define pmd_populate(mm, pmd, pte_page) \
8263 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8264 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8265@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8266 #endif
8267
8268 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8269+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8270
8271 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8272 pte_t *pte)
8273diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8274index 3ebb188..e17dddf 100644
8275--- a/arch/powerpc/include/asm/pgtable.h
8276+++ b/arch/powerpc/include/asm/pgtable.h
8277@@ -2,6 +2,7 @@
8278 #define _ASM_POWERPC_PGTABLE_H
8279 #ifdef __KERNEL__
8280
8281+#include <linux/const.h>
8282 #ifndef __ASSEMBLY__
8283 #include <linux/mmdebug.h>
8284 #include <asm/processor.h> /* For TASK_SIZE */
8285diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8286index 4aad413..85d86bf 100644
8287--- a/arch/powerpc/include/asm/pte-hash32.h
8288+++ b/arch/powerpc/include/asm/pte-hash32.h
8289@@ -21,6 +21,7 @@
8290 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8291 #define _PAGE_USER 0x004 /* usermode access allowed */
8292 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8293+#define _PAGE_EXEC _PAGE_GUARDED
8294 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8295 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8296 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8297diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8298index e5d2e0b..9ac74b1 100644
8299--- a/arch/powerpc/include/asm/reg.h
8300+++ b/arch/powerpc/include/asm/reg.h
8301@@ -249,6 +249,7 @@
8302 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8303 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8304 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8305+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8306 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8307 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8308 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8309diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8310index ff51046..b982dd4 100644
8311--- a/arch/powerpc/include/asm/smp.h
8312+++ b/arch/powerpc/include/asm/smp.h
8313@@ -51,7 +51,7 @@ struct smp_ops_t {
8314 int (*cpu_disable)(void);
8315 void (*cpu_die)(unsigned int nr);
8316 int (*cpu_bootable)(unsigned int nr);
8317-};
8318+} __no_const;
8319
8320 extern void smp_send_debugger_break(void);
8321 extern void start_secondary_resume(void);
8322diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8323index b034ecd..af7e31f 100644
8324--- a/arch/powerpc/include/asm/thread_info.h
8325+++ b/arch/powerpc/include/asm/thread_info.h
8326@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8327 #if defined(CONFIG_PPC64)
8328 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8329 #endif
8330+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8331+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8332
8333 /* as above, but as bit values */
8334 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8335@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8336 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8337 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8338 #define _TIF_NOHZ (1<<TIF_NOHZ)
8339+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8340 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8341 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8342- _TIF_NOHZ)
8343+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8344
8345 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8346 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8347diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8348index 9485b43..3bd3c16 100644
8349--- a/arch/powerpc/include/asm/uaccess.h
8350+++ b/arch/powerpc/include/asm/uaccess.h
8351@@ -58,6 +58,7 @@
8352
8353 #endif
8354
8355+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8356 #define access_ok(type, addr, size) \
8357 (__chk_user_ptr(addr), \
8358 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8359@@ -318,52 +319,6 @@ do { \
8360 extern unsigned long __copy_tofrom_user(void __user *to,
8361 const void __user *from, unsigned long size);
8362
8363-#ifndef __powerpc64__
8364-
8365-static inline unsigned long copy_from_user(void *to,
8366- const void __user *from, unsigned long n)
8367-{
8368- unsigned long over;
8369-
8370- if (access_ok(VERIFY_READ, from, n))
8371- return __copy_tofrom_user((__force void __user *)to, from, n);
8372- if ((unsigned long)from < TASK_SIZE) {
8373- over = (unsigned long)from + n - TASK_SIZE;
8374- return __copy_tofrom_user((__force void __user *)to, from,
8375- n - over) + over;
8376- }
8377- return n;
8378-}
8379-
8380-static inline unsigned long copy_to_user(void __user *to,
8381- const void *from, unsigned long n)
8382-{
8383- unsigned long over;
8384-
8385- if (access_ok(VERIFY_WRITE, to, n))
8386- return __copy_tofrom_user(to, (__force void __user *)from, n);
8387- if ((unsigned long)to < TASK_SIZE) {
8388- over = (unsigned long)to + n - TASK_SIZE;
8389- return __copy_tofrom_user(to, (__force void __user *)from,
8390- n - over) + over;
8391- }
8392- return n;
8393-}
8394-
8395-#else /* __powerpc64__ */
8396-
8397-#define __copy_in_user(to, from, size) \
8398- __copy_tofrom_user((to), (from), (size))
8399-
8400-extern unsigned long copy_from_user(void *to, const void __user *from,
8401- unsigned long n);
8402-extern unsigned long copy_to_user(void __user *to, const void *from,
8403- unsigned long n);
8404-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8405- unsigned long n);
8406-
8407-#endif /* __powerpc64__ */
8408-
8409 static inline unsigned long __copy_from_user_inatomic(void *to,
8410 const void __user *from, unsigned long n)
8411 {
8412@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8413 if (ret == 0)
8414 return 0;
8415 }
8416+
8417+ if (!__builtin_constant_p(n))
8418+ check_object_size(to, n, false);
8419+
8420 return __copy_tofrom_user((__force void __user *)to, from, n);
8421 }
8422
8423@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8424 if (ret == 0)
8425 return 0;
8426 }
8427+
8428+ if (!__builtin_constant_p(n))
8429+ check_object_size(from, n, true);
8430+
8431 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8432 }
8433
8434@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8435 return __copy_to_user_inatomic(to, from, size);
8436 }
8437
8438+#ifndef __powerpc64__
8439+
8440+static inline unsigned long __must_check copy_from_user(void *to,
8441+ const void __user *from, unsigned long n)
8442+{
8443+ unsigned long over;
8444+
8445+ if ((long)n < 0)
8446+ return n;
8447+
8448+ if (access_ok(VERIFY_READ, from, n)) {
8449+ if (!__builtin_constant_p(n))
8450+ check_object_size(to, n, false);
8451+ return __copy_tofrom_user((__force void __user *)to, from, n);
8452+ }
8453+ if ((unsigned long)from < TASK_SIZE) {
8454+ over = (unsigned long)from + n - TASK_SIZE;
8455+ if (!__builtin_constant_p(n - over))
8456+ check_object_size(to, n - over, false);
8457+ return __copy_tofrom_user((__force void __user *)to, from,
8458+ n - over) + over;
8459+ }
8460+ return n;
8461+}
8462+
8463+static inline unsigned long __must_check copy_to_user(void __user *to,
8464+ const void *from, unsigned long n)
8465+{
8466+ unsigned long over;
8467+
8468+ if ((long)n < 0)
8469+ return n;
8470+
8471+ if (access_ok(VERIFY_WRITE, to, n)) {
8472+ if (!__builtin_constant_p(n))
8473+ check_object_size(from, n, true);
8474+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8475+ }
8476+ if ((unsigned long)to < TASK_SIZE) {
8477+ over = (unsigned long)to + n - TASK_SIZE;
8478+ if (!__builtin_constant_p(n))
8479+ check_object_size(from, n - over, true);
8480+ return __copy_tofrom_user(to, (__force void __user *)from,
8481+ n - over) + over;
8482+ }
8483+ return n;
8484+}
8485+
8486+#else /* __powerpc64__ */
8487+
8488+#define __copy_in_user(to, from, size) \
8489+ __copy_tofrom_user((to), (from), (size))
8490+
8491+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8492+{
8493+ if ((long)n < 0 || n > INT_MAX)
8494+ return n;
8495+
8496+ if (!__builtin_constant_p(n))
8497+ check_object_size(to, n, false);
8498+
8499+ if (likely(access_ok(VERIFY_READ, from, n)))
8500+ n = __copy_from_user(to, from, n);
8501+ else
8502+ memset(to, 0, n);
8503+ return n;
8504+}
8505+
8506+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8507+{
8508+ if ((long)n < 0 || n > INT_MAX)
8509+ return n;
8510+
8511+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8512+ if (!__builtin_constant_p(n))
8513+ check_object_size(from, n, true);
8514+ n = __copy_to_user(to, from, n);
8515+ }
8516+ return n;
8517+}
8518+
8519+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8520+ unsigned long n);
8521+
8522+#endif /* __powerpc64__ */
8523+
8524 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8525
8526 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8527diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8528index fcc9a89..07be2bb 100644
8529--- a/arch/powerpc/kernel/Makefile
8530+++ b/arch/powerpc/kernel/Makefile
8531@@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8532 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8533 endif
8534
8535+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8536+
8537 obj-y := cputable.o ptrace.o syscalls.o \
8538 irq.o align.o signal_32.o pmc.o vdso.o \
8539 process.o systbl.o idle.o \
8540diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8541index c1bee3c..5b42583 100644
8542--- a/arch/powerpc/kernel/exceptions-64e.S
8543+++ b/arch/powerpc/kernel/exceptions-64e.S
8544@@ -1010,6 +1010,7 @@ storage_fault_common:
8545 std r14,_DAR(r1)
8546 std r15,_DSISR(r1)
8547 addi r3,r1,STACK_FRAME_OVERHEAD
8548+ bl .save_nvgprs
8549 mr r4,r14
8550 mr r5,r15
8551 ld r14,PACA_EXGEN+EX_R14(r13)
8552@@ -1018,8 +1019,7 @@ storage_fault_common:
8553 cmpdi r3,0
8554 bne- 1f
8555 b .ret_from_except_lite
8556-1: bl .save_nvgprs
8557- mr r5,r3
8558+1: mr r5,r3
8559 addi r3,r1,STACK_FRAME_OVERHEAD
8560 ld r4,_DAR(r1)
8561 bl .bad_page_fault
8562diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8563index 3afd391..18f9e36 100644
8564--- a/arch/powerpc/kernel/exceptions-64s.S
8565+++ b/arch/powerpc/kernel/exceptions-64s.S
8566@@ -1587,10 +1587,10 @@ handle_page_fault:
8567 11: ld r4,_DAR(r1)
8568 ld r5,_DSISR(r1)
8569 addi r3,r1,STACK_FRAME_OVERHEAD
8570+ bl .save_nvgprs
8571 bl .do_page_fault
8572 cmpdi r3,0
8573 beq+ 12f
8574- bl .save_nvgprs
8575 mr r5,r3
8576 addi r3,r1,STACK_FRAME_OVERHEAD
8577 lwz r4,_DAR(r1)
8578diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8579index ca1cd74..6f0241a 100644
8580--- a/arch/powerpc/kernel/irq.c
8581+++ b/arch/powerpc/kernel/irq.c
8582@@ -447,6 +447,8 @@ void migrate_irqs(void)
8583 }
8584 #endif
8585
8586+extern void gr_handle_kernel_exploit(void);
8587+
8588 static inline void check_stack_overflow(void)
8589 {
8590 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8591@@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
8592 printk("do_IRQ: stack overflow: %ld\n",
8593 sp - sizeof(struct thread_info));
8594 dump_stack();
8595+ gr_handle_kernel_exploit();
8596 }
8597 #endif
8598 }
8599diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8600index 6cff040..74ac5d1 100644
8601--- a/arch/powerpc/kernel/module_32.c
8602+++ b/arch/powerpc/kernel/module_32.c
8603@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8604 me->arch.core_plt_section = i;
8605 }
8606 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8607- printk("Module doesn't contain .plt or .init.plt sections.\n");
8608+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8609 return -ENOEXEC;
8610 }
8611
8612@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8613
8614 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8615 /* Init, or core PLT? */
8616- if (location >= mod->module_core
8617- && location < mod->module_core + mod->core_size)
8618+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8619+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8620 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8621- else
8622+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8623+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8624 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8625+ else {
8626+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8627+ return ~0UL;
8628+ }
8629
8630 /* Find this entry, or if that fails, the next avail. entry */
8631 while (entry->jump[0]) {
8632@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8633 }
8634 #ifdef CONFIG_DYNAMIC_FTRACE
8635 module->arch.tramp =
8636- do_plt_call(module->module_core,
8637+ do_plt_call(module->module_core_rx,
8638 (unsigned long)ftrace_caller,
8639 sechdrs, module);
8640 #endif
8641diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8642index 31d0215..206af70 100644
8643--- a/arch/powerpc/kernel/process.c
8644+++ b/arch/powerpc/kernel/process.c
8645@@ -1031,8 +1031,8 @@ void show_regs(struct pt_regs * regs)
8646 * Lookup NIP late so we have the best change of getting the
8647 * above info out without failing
8648 */
8649- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8650- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8651+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8652+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8653 #endif
8654 show_stack(current, (unsigned long *) regs->gpr[1]);
8655 if (!user_mode(regs))
8656@@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8657 newsp = stack[0];
8658 ip = stack[STACK_FRAME_LR_SAVE];
8659 if (!firstframe || ip != lr) {
8660- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8661+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8662 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8663 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8664- printk(" (%pS)",
8665+ printk(" (%pA)",
8666 (void *)current->ret_stack[curr_frame].ret);
8667 curr_frame--;
8668 }
8669@@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8670 struct pt_regs *regs = (struct pt_regs *)
8671 (sp + STACK_FRAME_OVERHEAD);
8672 lr = regs->link;
8673- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8674+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8675 regs->trap, (void *)regs->nip, (void *)lr);
8676 firstframe = 1;
8677 }
8678@@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
8679 mtspr(SPRN_CTRLT, ctrl);
8680 }
8681 #endif /* CONFIG_PPC64 */
8682-
8683-unsigned long arch_align_stack(unsigned long sp)
8684-{
8685- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8686- sp -= get_random_int() & ~PAGE_MASK;
8687- return sp & ~0xf;
8688-}
8689-
8690-static inline unsigned long brk_rnd(void)
8691-{
8692- unsigned long rnd = 0;
8693-
8694- /* 8MB for 32bit, 1GB for 64bit */
8695- if (is_32bit_task())
8696- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8697- else
8698- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8699-
8700- return rnd << PAGE_SHIFT;
8701-}
8702-
8703-unsigned long arch_randomize_brk(struct mm_struct *mm)
8704-{
8705- unsigned long base = mm->brk;
8706- unsigned long ret;
8707-
8708-#ifdef CONFIG_PPC_STD_MMU_64
8709- /*
8710- * If we are using 1TB segments and we are allowed to randomise
8711- * the heap, we can put it above 1TB so it is backed by a 1TB
8712- * segment. Otherwise the heap will be in the bottom 1TB
8713- * which always uses 256MB segments and this may result in a
8714- * performance penalty.
8715- */
8716- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8717- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8718-#endif
8719-
8720- ret = PAGE_ALIGN(base + brk_rnd());
8721-
8722- if (ret < mm->brk)
8723- return mm->brk;
8724-
8725- return ret;
8726-}
8727-
8728-unsigned long randomize_et_dyn(unsigned long base)
8729-{
8730- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8731-
8732- if (ret < base)
8733- return base;
8734-
8735- return ret;
8736-}
8737diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8738index 2e3d2bf..35df241 100644
8739--- a/arch/powerpc/kernel/ptrace.c
8740+++ b/arch/powerpc/kernel/ptrace.c
8741@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8742 return ret;
8743 }
8744
8745+#ifdef CONFIG_GRKERNSEC_SETXID
8746+extern void gr_delayed_cred_worker(void);
8747+#endif
8748+
8749 /*
8750 * We must return the syscall number to actually look up in the table.
8751 * This can be -1L to skip running any syscall at all.
8752@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8753
8754 secure_computing_strict(regs->gpr[0]);
8755
8756+#ifdef CONFIG_GRKERNSEC_SETXID
8757+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8758+ gr_delayed_cred_worker();
8759+#endif
8760+
8761 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8762 tracehook_report_syscall_entry(regs))
8763 /*
8764@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8765 {
8766 int step;
8767
8768+#ifdef CONFIG_GRKERNSEC_SETXID
8769+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8770+ gr_delayed_cred_worker();
8771+#endif
8772+
8773 audit_syscall_exit(regs);
8774
8775 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8776diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8777index 4e47db6..6dcc96e 100644
8778--- a/arch/powerpc/kernel/signal_32.c
8779+++ b/arch/powerpc/kernel/signal_32.c
8780@@ -1013,7 +1013,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8781 /* Save user registers on the stack */
8782 frame = &rt_sf->uc.uc_mcontext;
8783 addr = frame;
8784- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8785+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8786 sigret = 0;
8787 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8788 } else {
8789diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8790index d501dc4..e5a0de0 100644
8791--- a/arch/powerpc/kernel/signal_64.c
8792+++ b/arch/powerpc/kernel/signal_64.c
8793@@ -760,7 +760,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8794 current->thread.fp_state.fpscr = 0;
8795
8796 /* Set up to return from userspace. */
8797- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8798+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8799 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8800 } else {
8801 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8802diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8803index 1bd7ca2..9b78c2f 100644
8804--- a/arch/powerpc/kernel/traps.c
8805+++ b/arch/powerpc/kernel/traps.c
8806@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8807 return flags;
8808 }
8809
8810+extern void gr_handle_kernel_exploit(void);
8811+
8812 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8813 int signr)
8814 {
8815@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8816 panic("Fatal exception in interrupt");
8817 if (panic_on_oops)
8818 panic("Fatal exception");
8819+
8820+ gr_handle_kernel_exploit();
8821+
8822 do_exit(signr);
8823 }
8824
8825diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8826index ce74c33..0803371 100644
8827--- a/arch/powerpc/kernel/vdso.c
8828+++ b/arch/powerpc/kernel/vdso.c
8829@@ -35,6 +35,7 @@
8830 #include <asm/vdso.h>
8831 #include <asm/vdso_datapage.h>
8832 #include <asm/setup.h>
8833+#include <asm/mman.h>
8834
8835 #undef DEBUG
8836
8837@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8838 vdso_base = VDSO32_MBASE;
8839 #endif
8840
8841- current->mm->context.vdso_base = 0;
8842+ current->mm->context.vdso_base = ~0UL;
8843
8844 /* vDSO has a problem and was disabled, just don't "enable" it for the
8845 * process
8846@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8847 vdso_base = get_unmapped_area(NULL, vdso_base,
8848 (vdso_pages << PAGE_SHIFT) +
8849 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8850- 0, 0);
8851+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8852 if (IS_ERR_VALUE(vdso_base)) {
8853 rc = vdso_base;
8854 goto fail_mmapsem;
8855diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8856index 3cf541a..ab2d825 100644
8857--- a/arch/powerpc/kvm/powerpc.c
8858+++ b/arch/powerpc/kvm/powerpc.c
8859@@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8860 }
8861 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8862
8863-int kvm_arch_init(void *opaque)
8864+int kvm_arch_init(const void *opaque)
8865 {
8866 return 0;
8867 }
8868diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8869index 5eea6f3..5d10396 100644
8870--- a/arch/powerpc/lib/usercopy_64.c
8871+++ b/arch/powerpc/lib/usercopy_64.c
8872@@ -9,22 +9,6 @@
8873 #include <linux/module.h>
8874 #include <asm/uaccess.h>
8875
8876-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8877-{
8878- if (likely(access_ok(VERIFY_READ, from, n)))
8879- n = __copy_from_user(to, from, n);
8880- else
8881- memset(to, 0, n);
8882- return n;
8883-}
8884-
8885-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8886-{
8887- if (likely(access_ok(VERIFY_WRITE, to, n)))
8888- n = __copy_to_user(to, from, n);
8889- return n;
8890-}
8891-
8892 unsigned long copy_in_user(void __user *to, const void __user *from,
8893 unsigned long n)
8894 {
8895@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8896 return n;
8897 }
8898
8899-EXPORT_SYMBOL(copy_from_user);
8900-EXPORT_SYMBOL(copy_to_user);
8901 EXPORT_SYMBOL(copy_in_user);
8902
8903diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8904index 51ab9e7..7d3c78b 100644
8905--- a/arch/powerpc/mm/fault.c
8906+++ b/arch/powerpc/mm/fault.c
8907@@ -33,6 +33,10 @@
8908 #include <linux/magic.h>
8909 #include <linux/ratelimit.h>
8910 #include <linux/context_tracking.h>
8911+#include <linux/slab.h>
8912+#include <linux/pagemap.h>
8913+#include <linux/compiler.h>
8914+#include <linux/unistd.h>
8915
8916 #include <asm/firmware.h>
8917 #include <asm/page.h>
8918@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8919 }
8920 #endif
8921
8922+#ifdef CONFIG_PAX_PAGEEXEC
8923+/*
8924+ * PaX: decide what to do with offenders (regs->nip = fault address)
8925+ *
8926+ * returns 1 when task should be killed
8927+ */
8928+static int pax_handle_fetch_fault(struct pt_regs *regs)
8929+{
8930+ return 1;
8931+}
8932+
8933+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8934+{
8935+ unsigned long i;
8936+
8937+ printk(KERN_ERR "PAX: bytes at PC: ");
8938+ for (i = 0; i < 5; i++) {
8939+ unsigned int c;
8940+ if (get_user(c, (unsigned int __user *)pc+i))
8941+ printk(KERN_CONT "???????? ");
8942+ else
8943+ printk(KERN_CONT "%08x ", c);
8944+ }
8945+ printk("\n");
8946+}
8947+#endif
8948+
8949 /*
8950 * Check whether the instruction at regs->nip is a store using
8951 * an update addressing form which will update r1.
8952@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8953 * indicate errors in DSISR but can validly be set in SRR1.
8954 */
8955 if (trap == 0x400)
8956- error_code &= 0x48200000;
8957+ error_code &= 0x58200000;
8958 else
8959 is_write = error_code & DSISR_ISSTORE;
8960 #else
8961@@ -378,7 +409,7 @@ good_area:
8962 * "undefined". Of those that can be set, this is the only
8963 * one which seems bad.
8964 */
8965- if (error_code & 0x10000000)
8966+ if (error_code & DSISR_GUARDED)
8967 /* Guarded storage error. */
8968 goto bad_area;
8969 #endif /* CONFIG_8xx */
8970@@ -393,7 +424,7 @@ good_area:
8971 * processors use the same I/D cache coherency mechanism
8972 * as embedded.
8973 */
8974- if (error_code & DSISR_PROTFAULT)
8975+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8976 goto bad_area;
8977 #endif /* CONFIG_PPC_STD_MMU */
8978
8979@@ -483,6 +514,23 @@ bad_area:
8980 bad_area_nosemaphore:
8981 /* User mode accesses cause a SIGSEGV */
8982 if (user_mode(regs)) {
8983+
8984+#ifdef CONFIG_PAX_PAGEEXEC
8985+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8986+#ifdef CONFIG_PPC_STD_MMU
8987+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8988+#else
8989+ if (is_exec && regs->nip == address) {
8990+#endif
8991+ switch (pax_handle_fetch_fault(regs)) {
8992+ }
8993+
8994+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8995+ do_group_exit(SIGKILL);
8996+ }
8997+ }
8998+#endif
8999+
9000 _exception(SIGSEGV, regs, code, address);
9001 goto bail;
9002 }
9003diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9004index cb8bdbe..cde4bc7 100644
9005--- a/arch/powerpc/mm/mmap.c
9006+++ b/arch/powerpc/mm/mmap.c
9007@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9008 return sysctl_legacy_va_layout;
9009 }
9010
9011-static unsigned long mmap_rnd(void)
9012+static unsigned long mmap_rnd(struct mm_struct *mm)
9013 {
9014 unsigned long rnd = 0;
9015
9016+#ifdef CONFIG_PAX_RANDMMAP
9017+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9018+#endif
9019+
9020 if (current->flags & PF_RANDOMIZE) {
9021 /* 8MB for 32bit, 1GB for 64bit */
9022 if (is_32bit_task())
9023@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9024 return rnd << PAGE_SHIFT;
9025 }
9026
9027-static inline unsigned long mmap_base(void)
9028+static inline unsigned long mmap_base(struct mm_struct *mm)
9029 {
9030 unsigned long gap = rlimit(RLIMIT_STACK);
9031
9032@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9033 else if (gap > MAX_GAP)
9034 gap = MAX_GAP;
9035
9036- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9037+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9038 }
9039
9040 /*
9041@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9042 */
9043 if (mmap_is_legacy()) {
9044 mm->mmap_base = TASK_UNMAPPED_BASE;
9045+
9046+#ifdef CONFIG_PAX_RANDMMAP
9047+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9048+ mm->mmap_base += mm->delta_mmap;
9049+#endif
9050+
9051 mm->get_unmapped_area = arch_get_unmapped_area;
9052 } else {
9053- mm->mmap_base = mmap_base();
9054+ mm->mmap_base = mmap_base(mm);
9055+
9056+#ifdef CONFIG_PAX_RANDMMAP
9057+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9058+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9059+#endif
9060+
9061 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9062 }
9063 }
9064diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9065index b0c75cc..ef7fb93 100644
9066--- a/arch/powerpc/mm/slice.c
9067+++ b/arch/powerpc/mm/slice.c
9068@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9069 if ((mm->task_size - len) < addr)
9070 return 0;
9071 vma = find_vma(mm, addr);
9072- return (!vma || (addr + len) <= vma->vm_start);
9073+ return check_heap_stack_gap(vma, addr, len, 0);
9074 }
9075
9076 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9077@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9078 info.align_offset = 0;
9079
9080 addr = TASK_UNMAPPED_BASE;
9081+
9082+#ifdef CONFIG_PAX_RANDMMAP
9083+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9084+ addr += mm->delta_mmap;
9085+#endif
9086+
9087 while (addr < TASK_SIZE) {
9088 info.low_limit = addr;
9089 if (!slice_scan_available(addr, available, 1, &addr))
9090@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9091 if (fixed && addr > (mm->task_size - len))
9092 return -ENOMEM;
9093
9094+#ifdef CONFIG_PAX_RANDMMAP
9095+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9096+ addr = 0;
9097+#endif
9098+
9099 /* If hint, make sure it matches our alignment restrictions */
9100 if (!fixed && addr) {
9101 addr = _ALIGN_UP(addr, 1ul << pshift);
9102diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9103index 4278acf..67fd0e6 100644
9104--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9105+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9106@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9107 }
9108
9109 static struct pci_ops scc_pciex_pci_ops = {
9110- scc_pciex_read_config,
9111- scc_pciex_write_config,
9112+ .read = scc_pciex_read_config,
9113+ .write = scc_pciex_write_config,
9114 };
9115
9116 static void pciex_clear_intr_all(unsigned int __iomem *base)
9117diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9118index 9098692..3d54cd1 100644
9119--- a/arch/powerpc/platforms/cell/spufs/file.c
9120+++ b/arch/powerpc/platforms/cell/spufs/file.c
9121@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9122 return VM_FAULT_NOPAGE;
9123 }
9124
9125-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9126+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9127 unsigned long address,
9128- void *buf, int len, int write)
9129+ void *buf, size_t len, int write)
9130 {
9131 struct spu_context *ctx = vma->vm_file->private_data;
9132 unsigned long offset = address - vma->vm_start;
9133diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9134index 1d47061..0714963 100644
9135--- a/arch/s390/include/asm/atomic.h
9136+++ b/arch/s390/include/asm/atomic.h
9137@@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9138 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9139 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9140
9141+#define atomic64_read_unchecked(v) atomic64_read(v)
9142+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9143+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9144+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9145+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9146+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9147+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9148+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9149+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9150+
9151 #define smp_mb__before_atomic_dec() smp_mb()
9152 #define smp_mb__after_atomic_dec() smp_mb()
9153 #define smp_mb__before_atomic_inc() smp_mb()
9154diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9155index 578680f..0eb3b11 100644
9156--- a/arch/s390/include/asm/barrier.h
9157+++ b/arch/s390/include/asm/barrier.h
9158@@ -36,7 +36,7 @@
9159 do { \
9160 compiletime_assert_atomic_type(*p); \
9161 barrier(); \
9162- ACCESS_ONCE(*p) = (v); \
9163+ ACCESS_ONCE_RW(*p) = (v); \
9164 } while (0)
9165
9166 #define smp_load_acquire(p) \
9167diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9168index 4d7ccac..d03d0ad 100644
9169--- a/arch/s390/include/asm/cache.h
9170+++ b/arch/s390/include/asm/cache.h
9171@@ -9,8 +9,10 @@
9172 #ifndef __ARCH_S390_CACHE_H
9173 #define __ARCH_S390_CACHE_H
9174
9175-#define L1_CACHE_BYTES 256
9176+#include <linux/const.h>
9177+
9178 #define L1_CACHE_SHIFT 8
9179+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9180 #define NET_SKB_PAD 32
9181
9182 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9183diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9184index 78f4f87..598ce39 100644
9185--- a/arch/s390/include/asm/elf.h
9186+++ b/arch/s390/include/asm/elf.h
9187@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9188 the loader. We need to make sure that it is out of the way of the program
9189 that it will "exec", and that there is sufficient room for the brk. */
9190
9191-extern unsigned long randomize_et_dyn(unsigned long base);
9192-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9193+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9194+
9195+#ifdef CONFIG_PAX_ASLR
9196+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9197+
9198+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9199+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9200+#endif
9201
9202 /* This yields a mask that user programs can use to figure out what
9203 instruction set this CPU supports. */
9204@@ -222,9 +228,6 @@ struct linux_binprm;
9205 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9206 int arch_setup_additional_pages(struct linux_binprm *, int);
9207
9208-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9209-#define arch_randomize_brk arch_randomize_brk
9210-
9211 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9212
9213 #endif
9214diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9215index c4a93d6..4d2a9b4 100644
9216--- a/arch/s390/include/asm/exec.h
9217+++ b/arch/s390/include/asm/exec.h
9218@@ -7,6 +7,6 @@
9219 #ifndef __ASM_EXEC_H
9220 #define __ASM_EXEC_H
9221
9222-extern unsigned long arch_align_stack(unsigned long sp);
9223+#define arch_align_stack(x) ((x) & ~0xfUL)
9224
9225 #endif /* __ASM_EXEC_H */
9226diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9227index 1be64a1..086839d1 100644
9228--- a/arch/s390/include/asm/uaccess.h
9229+++ b/arch/s390/include/asm/uaccess.h
9230@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9231 __range_ok((unsigned long)(addr), (size)); \
9232 })
9233
9234+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9235 #define access_ok(type, addr, size) __access_ok(addr, size)
9236
9237 /*
9238@@ -245,6 +246,10 @@ static inline unsigned long __must_check
9239 copy_to_user(void __user *to, const void *from, unsigned long n)
9240 {
9241 might_fault();
9242+
9243+ if ((long)n < 0)
9244+ return n;
9245+
9246 return __copy_to_user(to, from, n);
9247 }
9248
9249@@ -273,10 +278,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9250 static inline unsigned long __must_check
9251 copy_from_user(void *to, const void __user *from, unsigned long n)
9252 {
9253- unsigned int sz = __compiletime_object_size(to);
9254+ size_t sz = __compiletime_object_size(to);
9255
9256 might_fault();
9257- if (unlikely(sz != -1 && sz < n)) {
9258+
9259+ if ((long)n < 0)
9260+ return n;
9261+
9262+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9263 copy_from_user_overflow();
9264 return n;
9265 }
9266diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9267index b89b591..fd9609d 100644
9268--- a/arch/s390/kernel/module.c
9269+++ b/arch/s390/kernel/module.c
9270@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9271
9272 /* Increase core size by size of got & plt and set start
9273 offsets for got and plt. */
9274- me->core_size = ALIGN(me->core_size, 4);
9275- me->arch.got_offset = me->core_size;
9276- me->core_size += me->arch.got_size;
9277- me->arch.plt_offset = me->core_size;
9278- me->core_size += me->arch.plt_size;
9279+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9280+ me->arch.got_offset = me->core_size_rw;
9281+ me->core_size_rw += me->arch.got_size;
9282+ me->arch.plt_offset = me->core_size_rx;
9283+ me->core_size_rx += me->arch.plt_size;
9284 return 0;
9285 }
9286
9287@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9288 if (info->got_initialized == 0) {
9289 Elf_Addr *gotent;
9290
9291- gotent = me->module_core + me->arch.got_offset +
9292+ gotent = me->module_core_rw + me->arch.got_offset +
9293 info->got_offset;
9294 *gotent = val;
9295 info->got_initialized = 1;
9296@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9297 rc = apply_rela_bits(loc, val, 0, 64, 0);
9298 else if (r_type == R_390_GOTENT ||
9299 r_type == R_390_GOTPLTENT) {
9300- val += (Elf_Addr) me->module_core - loc;
9301+ val += (Elf_Addr) me->module_core_rw - loc;
9302 rc = apply_rela_bits(loc, val, 1, 32, 1);
9303 }
9304 break;
9305@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9306 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9307 if (info->plt_initialized == 0) {
9308 unsigned int *ip;
9309- ip = me->module_core + me->arch.plt_offset +
9310+ ip = me->module_core_rx + me->arch.plt_offset +
9311 info->plt_offset;
9312 #ifndef CONFIG_64BIT
9313 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9314@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9315 val - loc + 0xffffUL < 0x1ffffeUL) ||
9316 (r_type == R_390_PLT32DBL &&
9317 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9318- val = (Elf_Addr) me->module_core +
9319+ val = (Elf_Addr) me->module_core_rx +
9320 me->arch.plt_offset +
9321 info->plt_offset;
9322 val += rela->r_addend - loc;
9323@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9324 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9325 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9326 val = val + rela->r_addend -
9327- ((Elf_Addr) me->module_core + me->arch.got_offset);
9328+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9329 if (r_type == R_390_GOTOFF16)
9330 rc = apply_rela_bits(loc, val, 0, 16, 0);
9331 else if (r_type == R_390_GOTOFF32)
9332@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9333 break;
9334 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9335 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9336- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9337+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9338 rela->r_addend - loc;
9339 if (r_type == R_390_GOTPC)
9340 rc = apply_rela_bits(loc, val, 1, 32, 0);
9341diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9342index dd14532..1dfc145 100644
9343--- a/arch/s390/kernel/process.c
9344+++ b/arch/s390/kernel/process.c
9345@@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9346 }
9347 return 0;
9348 }
9349-
9350-unsigned long arch_align_stack(unsigned long sp)
9351-{
9352- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9353- sp -= get_random_int() & ~PAGE_MASK;
9354- return sp & ~0xf;
9355-}
9356-
9357-static inline unsigned long brk_rnd(void)
9358-{
9359- /* 8MB for 32bit, 1GB for 64bit */
9360- if (is_32bit_task())
9361- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9362- else
9363- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9364-}
9365-
9366-unsigned long arch_randomize_brk(struct mm_struct *mm)
9367-{
9368- unsigned long ret;
9369-
9370- ret = PAGE_ALIGN(mm->brk + brk_rnd());
9371- return (ret > mm->brk) ? ret : mm->brk;
9372-}
9373-
9374-unsigned long randomize_et_dyn(unsigned long base)
9375-{
9376- unsigned long ret;
9377-
9378- if (!(current->flags & PF_RANDOMIZE))
9379- return base;
9380- ret = PAGE_ALIGN(base + brk_rnd());
9381- return (ret > base) ? ret : base;
9382-}
9383diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9384index 9b436c2..54fbf0a 100644
9385--- a/arch/s390/mm/mmap.c
9386+++ b/arch/s390/mm/mmap.c
9387@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9388 */
9389 if (mmap_is_legacy()) {
9390 mm->mmap_base = mmap_base_legacy();
9391+
9392+#ifdef CONFIG_PAX_RANDMMAP
9393+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9394+ mm->mmap_base += mm->delta_mmap;
9395+#endif
9396+
9397 mm->get_unmapped_area = arch_get_unmapped_area;
9398 } else {
9399 mm->mmap_base = mmap_base();
9400+
9401+#ifdef CONFIG_PAX_RANDMMAP
9402+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9403+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9404+#endif
9405+
9406 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9407 }
9408 }
9409@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9410 */
9411 if (mmap_is_legacy()) {
9412 mm->mmap_base = mmap_base_legacy();
9413+
9414+#ifdef CONFIG_PAX_RANDMMAP
9415+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9416+ mm->mmap_base += mm->delta_mmap;
9417+#endif
9418+
9419 mm->get_unmapped_area = s390_get_unmapped_area;
9420 } else {
9421 mm->mmap_base = mmap_base();
9422+
9423+#ifdef CONFIG_PAX_RANDMMAP
9424+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9425+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9426+#endif
9427+
9428 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9429 }
9430 }
9431diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9432index ae3d59f..f65f075 100644
9433--- a/arch/score/include/asm/cache.h
9434+++ b/arch/score/include/asm/cache.h
9435@@ -1,7 +1,9 @@
9436 #ifndef _ASM_SCORE_CACHE_H
9437 #define _ASM_SCORE_CACHE_H
9438
9439+#include <linux/const.h>
9440+
9441 #define L1_CACHE_SHIFT 4
9442-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9443+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9444
9445 #endif /* _ASM_SCORE_CACHE_H */
9446diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9447index f9f3cd5..58ff438 100644
9448--- a/arch/score/include/asm/exec.h
9449+++ b/arch/score/include/asm/exec.h
9450@@ -1,6 +1,6 @@
9451 #ifndef _ASM_SCORE_EXEC_H
9452 #define _ASM_SCORE_EXEC_H
9453
9454-extern unsigned long arch_align_stack(unsigned long sp);
9455+#define arch_align_stack(x) (x)
9456
9457 #endif /* _ASM_SCORE_EXEC_H */
9458diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9459index a1519ad3..e8ac1ff 100644
9460--- a/arch/score/kernel/process.c
9461+++ b/arch/score/kernel/process.c
9462@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9463
9464 return task_pt_regs(task)->cp0_epc;
9465 }
9466-
9467-unsigned long arch_align_stack(unsigned long sp)
9468-{
9469- return sp;
9470-}
9471diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9472index ef9e555..331bd29 100644
9473--- a/arch/sh/include/asm/cache.h
9474+++ b/arch/sh/include/asm/cache.h
9475@@ -9,10 +9,11 @@
9476 #define __ASM_SH_CACHE_H
9477 #ifdef __KERNEL__
9478
9479+#include <linux/const.h>
9480 #include <linux/init.h>
9481 #include <cpu/cache.h>
9482
9483-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9484+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9485
9486 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9487
9488diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9489index 6777177..cb5e44f 100644
9490--- a/arch/sh/mm/mmap.c
9491+++ b/arch/sh/mm/mmap.c
9492@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9493 struct mm_struct *mm = current->mm;
9494 struct vm_area_struct *vma;
9495 int do_colour_align;
9496+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9497 struct vm_unmapped_area_info info;
9498
9499 if (flags & MAP_FIXED) {
9500@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9501 if (filp || (flags & MAP_SHARED))
9502 do_colour_align = 1;
9503
9504+#ifdef CONFIG_PAX_RANDMMAP
9505+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9506+#endif
9507+
9508 if (addr) {
9509 if (do_colour_align)
9510 addr = COLOUR_ALIGN(addr, pgoff);
9511@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9512 addr = PAGE_ALIGN(addr);
9513
9514 vma = find_vma(mm, addr);
9515- if (TASK_SIZE - len >= addr &&
9516- (!vma || addr + len <= vma->vm_start))
9517+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9518 return addr;
9519 }
9520
9521 info.flags = 0;
9522 info.length = len;
9523- info.low_limit = TASK_UNMAPPED_BASE;
9524+ info.low_limit = mm->mmap_base;
9525 info.high_limit = TASK_SIZE;
9526 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9527 info.align_offset = pgoff << PAGE_SHIFT;
9528@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9529 struct mm_struct *mm = current->mm;
9530 unsigned long addr = addr0;
9531 int do_colour_align;
9532+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9533 struct vm_unmapped_area_info info;
9534
9535 if (flags & MAP_FIXED) {
9536@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9537 if (filp || (flags & MAP_SHARED))
9538 do_colour_align = 1;
9539
9540+#ifdef CONFIG_PAX_RANDMMAP
9541+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9542+#endif
9543+
9544 /* requesting a specific address */
9545 if (addr) {
9546 if (do_colour_align)
9547@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9548 addr = PAGE_ALIGN(addr);
9549
9550 vma = find_vma(mm, addr);
9551- if (TASK_SIZE - len >= addr &&
9552- (!vma || addr + len <= vma->vm_start))
9553+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9554 return addr;
9555 }
9556
9557@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9558 VM_BUG_ON(addr != -ENOMEM);
9559 info.flags = 0;
9560 info.low_limit = TASK_UNMAPPED_BASE;
9561+
9562+#ifdef CONFIG_PAX_RANDMMAP
9563+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9564+ info.low_limit += mm->delta_mmap;
9565+#endif
9566+
9567 info.high_limit = TASK_SIZE;
9568 addr = vm_unmapped_area(&info);
9569 }
9570diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9571index be56a24..443328f 100644
9572--- a/arch/sparc/include/asm/atomic_64.h
9573+++ b/arch/sparc/include/asm/atomic_64.h
9574@@ -14,18 +14,40 @@
9575 #define ATOMIC64_INIT(i) { (i) }
9576
9577 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9578+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9579+{
9580+ return v->counter;
9581+}
9582 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9583+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9584+{
9585+ return v->counter;
9586+}
9587
9588 #define atomic_set(v, i) (((v)->counter) = i)
9589+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9590+{
9591+ v->counter = i;
9592+}
9593 #define atomic64_set(v, i) (((v)->counter) = i)
9594+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9595+{
9596+ v->counter = i;
9597+}
9598
9599 extern void atomic_add(int, atomic_t *);
9600+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9601 extern void atomic64_add(long, atomic64_t *);
9602+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9603 extern void atomic_sub(int, atomic_t *);
9604+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9605 extern void atomic64_sub(long, atomic64_t *);
9606+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9607
9608 extern int atomic_add_ret(int, atomic_t *);
9609+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9610 extern long atomic64_add_ret(long, atomic64_t *);
9611+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9612 extern int atomic_sub_ret(int, atomic_t *);
9613 extern long atomic64_sub_ret(long, atomic64_t *);
9614
9615@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9616 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9617
9618 #define atomic_inc_return(v) atomic_add_ret(1, v)
9619+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9620+{
9621+ return atomic_add_ret_unchecked(1, v);
9622+}
9623 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9624+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9625+{
9626+ return atomic64_add_ret_unchecked(1, v);
9627+}
9628
9629 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9630 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9631
9632 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9633+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9634+{
9635+ return atomic_add_ret_unchecked(i, v);
9636+}
9637 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9638+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9639+{
9640+ return atomic64_add_ret_unchecked(i, v);
9641+}
9642
9643 /*
9644 * atomic_inc_and_test - increment and test
9645@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9646 * other cases.
9647 */
9648 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9649+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9650+{
9651+ return atomic_inc_return_unchecked(v) == 0;
9652+}
9653 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9654
9655 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9656@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9657 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9658
9659 #define atomic_inc(v) atomic_add(1, v)
9660+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9661+{
9662+ atomic_add_unchecked(1, v);
9663+}
9664 #define atomic64_inc(v) atomic64_add(1, v)
9665+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9666+{
9667+ atomic64_add_unchecked(1, v);
9668+}
9669
9670 #define atomic_dec(v) atomic_sub(1, v)
9671+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9672+{
9673+ atomic_sub_unchecked(1, v);
9674+}
9675 #define atomic64_dec(v) atomic64_sub(1, v)
9676+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9677+{
9678+ atomic64_sub_unchecked(1, v);
9679+}
9680
9681 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9682 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9683
9684 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9685+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9686+{
9687+ return cmpxchg(&v->counter, old, new);
9688+}
9689 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9690+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9691+{
9692+ return xchg(&v->counter, new);
9693+}
9694
9695 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9696 {
9697- int c, old;
9698+ int c, old, new;
9699 c = atomic_read(v);
9700 for (;;) {
9701- if (unlikely(c == (u)))
9702+ if (unlikely(c == u))
9703 break;
9704- old = atomic_cmpxchg((v), c, c + (a));
9705+
9706+ asm volatile("addcc %2, %0, %0\n"
9707+
9708+#ifdef CONFIG_PAX_REFCOUNT
9709+ "tvs %%icc, 6\n"
9710+#endif
9711+
9712+ : "=r" (new)
9713+ : "0" (c), "ir" (a)
9714+ : "cc");
9715+
9716+ old = atomic_cmpxchg(v, c, new);
9717 if (likely(old == c))
9718 break;
9719 c = old;
9720@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9721 #define atomic64_cmpxchg(v, o, n) \
9722 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9723 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9724+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9725+{
9726+ return xchg(&v->counter, new);
9727+}
9728
9729 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9730 {
9731- long c, old;
9732+ long c, old, new;
9733 c = atomic64_read(v);
9734 for (;;) {
9735- if (unlikely(c == (u)))
9736+ if (unlikely(c == u))
9737 break;
9738- old = atomic64_cmpxchg((v), c, c + (a));
9739+
9740+ asm volatile("addcc %2, %0, %0\n"
9741+
9742+#ifdef CONFIG_PAX_REFCOUNT
9743+ "tvs %%xcc, 6\n"
9744+#endif
9745+
9746+ : "=r" (new)
9747+ : "0" (c), "ir" (a)
9748+ : "cc");
9749+
9750+ old = atomic64_cmpxchg(v, c, new);
9751 if (likely(old == c))
9752 break;
9753 c = old;
9754 }
9755- return c != (u);
9756+ return c != u;
9757 }
9758
9759 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9760diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
9761index b5aad96..99d7465 100644
9762--- a/arch/sparc/include/asm/barrier_64.h
9763+++ b/arch/sparc/include/asm/barrier_64.h
9764@@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
9765 do { \
9766 compiletime_assert_atomic_type(*p); \
9767 barrier(); \
9768- ACCESS_ONCE(*p) = (v); \
9769+ ACCESS_ONCE_RW(*p) = (v); \
9770 } while (0)
9771
9772 #define smp_load_acquire(p) \
9773diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9774index 5bb6991..5c2132e 100644
9775--- a/arch/sparc/include/asm/cache.h
9776+++ b/arch/sparc/include/asm/cache.h
9777@@ -7,10 +7,12 @@
9778 #ifndef _SPARC_CACHE_H
9779 #define _SPARC_CACHE_H
9780
9781+#include <linux/const.h>
9782+
9783 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9784
9785 #define L1_CACHE_SHIFT 5
9786-#define L1_CACHE_BYTES 32
9787+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9788
9789 #ifdef CONFIG_SPARC32
9790 #define SMP_CACHE_BYTES_SHIFT 5
9791diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9792index a24e41f..47677ff 100644
9793--- a/arch/sparc/include/asm/elf_32.h
9794+++ b/arch/sparc/include/asm/elf_32.h
9795@@ -114,6 +114,13 @@ typedef struct {
9796
9797 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9798
9799+#ifdef CONFIG_PAX_ASLR
9800+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9801+
9802+#define PAX_DELTA_MMAP_LEN 16
9803+#define PAX_DELTA_STACK_LEN 16
9804+#endif
9805+
9806 /* This yields a mask that user programs can use to figure out what
9807 instruction set this cpu supports. This can NOT be done in userspace
9808 on Sparc. */
9809diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9810index 370ca1e..d4f4a98 100644
9811--- a/arch/sparc/include/asm/elf_64.h
9812+++ b/arch/sparc/include/asm/elf_64.h
9813@@ -189,6 +189,13 @@ typedef struct {
9814 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9815 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9816
9817+#ifdef CONFIG_PAX_ASLR
9818+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9819+
9820+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9821+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9822+#endif
9823+
9824 extern unsigned long sparc64_elf_hwcap;
9825 #define ELF_HWCAP sparc64_elf_hwcap
9826
9827diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9828index 9b1c36d..209298b 100644
9829--- a/arch/sparc/include/asm/pgalloc_32.h
9830+++ b/arch/sparc/include/asm/pgalloc_32.h
9831@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9832 }
9833
9834 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9835+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9836
9837 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9838 unsigned long address)
9839diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9840index bcfe063..b333142 100644
9841--- a/arch/sparc/include/asm/pgalloc_64.h
9842+++ b/arch/sparc/include/asm/pgalloc_64.h
9843@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9844 }
9845
9846 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9847+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9848
9849 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9850 {
9851diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9852index 59ba6f6..4518128 100644
9853--- a/arch/sparc/include/asm/pgtable.h
9854+++ b/arch/sparc/include/asm/pgtable.h
9855@@ -5,4 +5,8 @@
9856 #else
9857 #include <asm/pgtable_32.h>
9858 #endif
9859+
9860+#define ktla_ktva(addr) (addr)
9861+#define ktva_ktla(addr) (addr)
9862+
9863 #endif
9864diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9865index 502f632..da1917f 100644
9866--- a/arch/sparc/include/asm/pgtable_32.h
9867+++ b/arch/sparc/include/asm/pgtable_32.h
9868@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9869 #define PAGE_SHARED SRMMU_PAGE_SHARED
9870 #define PAGE_COPY SRMMU_PAGE_COPY
9871 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9872+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9873+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9874+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9875 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9876
9877 /* Top-level page directory - dummy used by init-mm.
9878@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9879
9880 /* xwr */
9881 #define __P000 PAGE_NONE
9882-#define __P001 PAGE_READONLY
9883-#define __P010 PAGE_COPY
9884-#define __P011 PAGE_COPY
9885+#define __P001 PAGE_READONLY_NOEXEC
9886+#define __P010 PAGE_COPY_NOEXEC
9887+#define __P011 PAGE_COPY_NOEXEC
9888 #define __P100 PAGE_READONLY
9889 #define __P101 PAGE_READONLY
9890 #define __P110 PAGE_COPY
9891 #define __P111 PAGE_COPY
9892
9893 #define __S000 PAGE_NONE
9894-#define __S001 PAGE_READONLY
9895-#define __S010 PAGE_SHARED
9896-#define __S011 PAGE_SHARED
9897+#define __S001 PAGE_READONLY_NOEXEC
9898+#define __S010 PAGE_SHARED_NOEXEC
9899+#define __S011 PAGE_SHARED_NOEXEC
9900 #define __S100 PAGE_READONLY
9901 #define __S101 PAGE_READONLY
9902 #define __S110 PAGE_SHARED
9903diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9904index 79da178..c2eede8 100644
9905--- a/arch/sparc/include/asm/pgtsrmmu.h
9906+++ b/arch/sparc/include/asm/pgtsrmmu.h
9907@@ -115,6 +115,11 @@
9908 SRMMU_EXEC | SRMMU_REF)
9909 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9910 SRMMU_EXEC | SRMMU_REF)
9911+
9912+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9913+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9914+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9915+
9916 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9917 SRMMU_DIRTY | SRMMU_REF)
9918
9919diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9920index 9689176..63c18ea 100644
9921--- a/arch/sparc/include/asm/spinlock_64.h
9922+++ b/arch/sparc/include/asm/spinlock_64.h
9923@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9924
9925 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9926
9927-static void inline arch_read_lock(arch_rwlock_t *lock)
9928+static inline void arch_read_lock(arch_rwlock_t *lock)
9929 {
9930 unsigned long tmp1, tmp2;
9931
9932 __asm__ __volatile__ (
9933 "1: ldsw [%2], %0\n"
9934 " brlz,pn %0, 2f\n"
9935-"4: add %0, 1, %1\n"
9936+"4: addcc %0, 1, %1\n"
9937+
9938+#ifdef CONFIG_PAX_REFCOUNT
9939+" tvs %%icc, 6\n"
9940+#endif
9941+
9942 " cas [%2], %0, %1\n"
9943 " cmp %0, %1\n"
9944 " bne,pn %%icc, 1b\n"
9945@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9946 " .previous"
9947 : "=&r" (tmp1), "=&r" (tmp2)
9948 : "r" (lock)
9949- : "memory");
9950+ : "memory", "cc");
9951 }
9952
9953-static int inline arch_read_trylock(arch_rwlock_t *lock)
9954+static inline int arch_read_trylock(arch_rwlock_t *lock)
9955 {
9956 int tmp1, tmp2;
9957
9958@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9959 "1: ldsw [%2], %0\n"
9960 " brlz,a,pn %0, 2f\n"
9961 " mov 0, %0\n"
9962-" add %0, 1, %1\n"
9963+" addcc %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 %%icc, 1b\n"
9972@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9973 return tmp1;
9974 }
9975
9976-static void inline arch_read_unlock(arch_rwlock_t *lock)
9977+static inline void arch_read_unlock(arch_rwlock_t *lock)
9978 {
9979 unsigned long tmp1, tmp2;
9980
9981 __asm__ __volatile__(
9982 "1: lduw [%2], %0\n"
9983-" sub %0, 1, %1\n"
9984+" subcc %0, 1, %1\n"
9985+
9986+#ifdef CONFIG_PAX_REFCOUNT
9987+" tvs %%icc, 6\n"
9988+#endif
9989+
9990 " cas [%2], %0, %1\n"
9991 " cmp %0, %1\n"
9992 " bne,pn %%xcc, 1b\n"
9993@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9994 : "memory");
9995 }
9996
9997-static void inline arch_write_lock(arch_rwlock_t *lock)
9998+static inline void arch_write_lock(arch_rwlock_t *lock)
9999 {
10000 unsigned long mask, tmp1, tmp2;
10001
10002@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10003 : "memory");
10004 }
10005
10006-static void inline arch_write_unlock(arch_rwlock_t *lock)
10007+static inline void arch_write_unlock(arch_rwlock_t *lock)
10008 {
10009 __asm__ __volatile__(
10010 " stw %%g0, [%0]"
10011@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10012 : "memory");
10013 }
10014
10015-static int inline arch_write_trylock(arch_rwlock_t *lock)
10016+static inline int arch_write_trylock(arch_rwlock_t *lock)
10017 {
10018 unsigned long mask, tmp1, tmp2, result;
10019
10020diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10021index 96efa7a..16858bf 100644
10022--- a/arch/sparc/include/asm/thread_info_32.h
10023+++ b/arch/sparc/include/asm/thread_info_32.h
10024@@ -49,6 +49,8 @@ struct thread_info {
10025 unsigned long w_saved;
10026
10027 struct restart_block restart_block;
10028+
10029+ unsigned long lowest_stack;
10030 };
10031
10032 /*
10033diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10034index a5f01ac..703b554 100644
10035--- a/arch/sparc/include/asm/thread_info_64.h
10036+++ b/arch/sparc/include/asm/thread_info_64.h
10037@@ -63,6 +63,8 @@ struct thread_info {
10038 struct pt_regs *kern_una_regs;
10039 unsigned int kern_una_insn;
10040
10041+ unsigned long lowest_stack;
10042+
10043 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10044 };
10045
10046@@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10047 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10048 /* flag bit 4 is available */
10049 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10050-/* flag bit 6 is available */
10051+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10052 #define TIF_32BIT 7 /* 32-bit binary */
10053 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10054 #define TIF_SECCOMP 9 /* secure computing */
10055 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10056 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10057+
10058 /* NOTE: Thread flags >= 12 should be ones we have no interest
10059 * in using in assembly, else we can't use the mask as
10060 * an immediate value in instructions such as andcc.
10061@@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10062 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10063 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10064 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10065+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10066
10067 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10068 _TIF_DO_NOTIFY_RESUME_MASK | \
10069 _TIF_NEED_RESCHED)
10070 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10071
10072+#define _TIF_WORK_SYSCALL \
10073+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10074+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10075+
10076+
10077 /*
10078 * Thread-synchronous status.
10079 *
10080diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10081index 0167d26..767bb0c 100644
10082--- a/arch/sparc/include/asm/uaccess.h
10083+++ b/arch/sparc/include/asm/uaccess.h
10084@@ -1,5 +1,6 @@
10085 #ifndef ___ASM_SPARC_UACCESS_H
10086 #define ___ASM_SPARC_UACCESS_H
10087+
10088 #if defined(__sparc__) && defined(__arch64__)
10089 #include <asm/uaccess_64.h>
10090 #else
10091diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10092index 53a28dd..50c38c3 100644
10093--- a/arch/sparc/include/asm/uaccess_32.h
10094+++ b/arch/sparc/include/asm/uaccess_32.h
10095@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
10096
10097 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10098 {
10099- if (n && __access_ok((unsigned long) to, n))
10100+ if ((long)n < 0)
10101+ return n;
10102+
10103+ if (n && __access_ok((unsigned long) to, n)) {
10104+ if (!__builtin_constant_p(n))
10105+ check_object_size(from, n, true);
10106 return __copy_user(to, (__force void __user *) from, n);
10107- else
10108+ } else
10109 return n;
10110 }
10111
10112 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10113 {
10114+ if ((long)n < 0)
10115+ return n;
10116+
10117+ if (!__builtin_constant_p(n))
10118+ check_object_size(from, n, true);
10119+
10120 return __copy_user(to, (__force void __user *) from, n);
10121 }
10122
10123 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10124 {
10125- if (n && __access_ok((unsigned long) from, n))
10126+ if ((long)n < 0)
10127+ return n;
10128+
10129+ if (n && __access_ok((unsigned long) from, n)) {
10130+ if (!__builtin_constant_p(n))
10131+ check_object_size(to, n, false);
10132 return __copy_user((__force void __user *) to, from, n);
10133- else
10134+ } else
10135 return n;
10136 }
10137
10138 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10139 {
10140+ if ((long)n < 0)
10141+ return n;
10142+
10143 return __copy_user((__force void __user *) to, from, n);
10144 }
10145
10146diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10147index ad7e178..c9e7423 100644
10148--- a/arch/sparc/include/asm/uaccess_64.h
10149+++ b/arch/sparc/include/asm/uaccess_64.h
10150@@ -10,6 +10,7 @@
10151 #include <linux/compiler.h>
10152 #include <linux/string.h>
10153 #include <linux/thread_info.h>
10154+#include <linux/kernel.h>
10155 #include <asm/asi.h>
10156 #include <asm/spitfire.h>
10157 #include <asm-generic/uaccess-unaligned.h>
10158@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10159 static inline unsigned long __must_check
10160 copy_from_user(void *to, const void __user *from, unsigned long size)
10161 {
10162- unsigned long ret = ___copy_from_user(to, from, size);
10163+ unsigned long ret;
10164
10165+ if ((long)size < 0 || size > INT_MAX)
10166+ return size;
10167+
10168+ if (!__builtin_constant_p(size))
10169+ check_object_size(to, size, false);
10170+
10171+ ret = ___copy_from_user(to, from, size);
10172 if (unlikely(ret))
10173 ret = copy_from_user_fixup(to, from, size);
10174
10175@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10176 static inline unsigned long __must_check
10177 copy_to_user(void __user *to, const void *from, unsigned long size)
10178 {
10179- unsigned long ret = ___copy_to_user(to, from, size);
10180+ unsigned long ret;
10181
10182+ if ((long)size < 0 || size > INT_MAX)
10183+ return size;
10184+
10185+ if (!__builtin_constant_p(size))
10186+ check_object_size(from, size, true);
10187+
10188+ ret = ___copy_to_user(to, from, size);
10189 if (unlikely(ret))
10190 ret = copy_to_user_fixup(to, from, size);
10191 return ret;
10192diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10193index d15cc17..d0ae796 100644
10194--- a/arch/sparc/kernel/Makefile
10195+++ b/arch/sparc/kernel/Makefile
10196@@ -4,7 +4,7 @@
10197 #
10198
10199 asflags-y := -ansi
10200-ccflags-y := -Werror
10201+#ccflags-y := -Werror
10202
10203 extra-y := head_$(BITS).o
10204
10205diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10206index 510baec..9ff2607 100644
10207--- a/arch/sparc/kernel/process_32.c
10208+++ b/arch/sparc/kernel/process_32.c
10209@@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10210
10211 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10212 r->psr, r->pc, r->npc, r->y, print_tainted());
10213- printk("PC: <%pS>\n", (void *) r->pc);
10214+ printk("PC: <%pA>\n", (void *) r->pc);
10215 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10216 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10217 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10218 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10219 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10220 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10221- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10222+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10223
10224 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10225 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10226@@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10227 rw = (struct reg_window32 *) fp;
10228 pc = rw->ins[7];
10229 printk("[%08lx : ", pc);
10230- printk("%pS ] ", (void *) pc);
10231+ printk("%pA ] ", (void *) pc);
10232 fp = rw->ins[6];
10233 } while (++count < 16);
10234 printk("\n");
10235diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10236index d7b4967..2edf827 100644
10237--- a/arch/sparc/kernel/process_64.c
10238+++ b/arch/sparc/kernel/process_64.c
10239@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10240 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10241 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10242 if (regs->tstate & TSTATE_PRIV)
10243- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10244+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10245 }
10246
10247 void show_regs(struct pt_regs *regs)
10248@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10249
10250 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10251 regs->tpc, regs->tnpc, regs->y, print_tainted());
10252- printk("TPC: <%pS>\n", (void *) regs->tpc);
10253+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10254 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10255 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10256 regs->u_regs[3]);
10257@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10258 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10259 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10260 regs->u_regs[15]);
10261- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10262+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10263 show_regwindow(regs);
10264 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10265 }
10266@@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10267 ((tp && tp->task) ? tp->task->pid : -1));
10268
10269 if (gp->tstate & TSTATE_PRIV) {
10270- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10271+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10272 (void *) gp->tpc,
10273 (void *) gp->o7,
10274 (void *) gp->i7,
10275diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10276index 79cc0d1..ec62734 100644
10277--- a/arch/sparc/kernel/prom_common.c
10278+++ b/arch/sparc/kernel/prom_common.c
10279@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10280
10281 unsigned int prom_early_allocated __initdata;
10282
10283-static struct of_pdt_ops prom_sparc_ops __initdata = {
10284+static struct of_pdt_ops prom_sparc_ops __initconst = {
10285 .nextprop = prom_common_nextprop,
10286 .getproplen = prom_getproplen,
10287 .getproperty = prom_getproperty,
10288diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10289index c13c9f2..d572c34 100644
10290--- a/arch/sparc/kernel/ptrace_64.c
10291+++ b/arch/sparc/kernel/ptrace_64.c
10292@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10293 return ret;
10294 }
10295
10296+#ifdef CONFIG_GRKERNSEC_SETXID
10297+extern void gr_delayed_cred_worker(void);
10298+#endif
10299+
10300 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10301 {
10302 int ret = 0;
10303@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10304 if (test_thread_flag(TIF_NOHZ))
10305 user_exit();
10306
10307+#ifdef CONFIG_GRKERNSEC_SETXID
10308+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10309+ gr_delayed_cred_worker();
10310+#endif
10311+
10312 if (test_thread_flag(TIF_SYSCALL_TRACE))
10313 ret = tracehook_report_syscall_entry(regs);
10314
10315@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10316 if (test_thread_flag(TIF_NOHZ))
10317 user_exit();
10318
10319+#ifdef CONFIG_GRKERNSEC_SETXID
10320+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10321+ gr_delayed_cred_worker();
10322+#endif
10323+
10324 audit_syscall_exit(regs);
10325
10326 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10327diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10328index 745a363..b5566b1 100644
10329--- a/arch/sparc/kernel/smp_64.c
10330+++ b/arch/sparc/kernel/smp_64.c
10331@@ -868,8 +868,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10332 extern unsigned long xcall_flush_dcache_page_spitfire;
10333
10334 #ifdef CONFIG_DEBUG_DCFLUSH
10335-extern atomic_t dcpage_flushes;
10336-extern atomic_t dcpage_flushes_xcall;
10337+extern atomic_unchecked_t dcpage_flushes;
10338+extern atomic_unchecked_t dcpage_flushes_xcall;
10339 #endif
10340
10341 static inline void __local_flush_dcache_page(struct page *page)
10342@@ -893,7 +893,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10343 return;
10344
10345 #ifdef CONFIG_DEBUG_DCFLUSH
10346- atomic_inc(&dcpage_flushes);
10347+ atomic_inc_unchecked(&dcpage_flushes);
10348 #endif
10349
10350 this_cpu = get_cpu();
10351@@ -917,7 +917,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10352 xcall_deliver(data0, __pa(pg_addr),
10353 (u64) pg_addr, cpumask_of(cpu));
10354 #ifdef CONFIG_DEBUG_DCFLUSH
10355- atomic_inc(&dcpage_flushes_xcall);
10356+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10357 #endif
10358 }
10359 }
10360@@ -936,7 +936,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10361 preempt_disable();
10362
10363 #ifdef CONFIG_DEBUG_DCFLUSH
10364- atomic_inc(&dcpage_flushes);
10365+ atomic_inc_unchecked(&dcpage_flushes);
10366 #endif
10367 data0 = 0;
10368 pg_addr = page_address(page);
10369@@ -953,7 +953,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10370 xcall_deliver(data0, __pa(pg_addr),
10371 (u64) pg_addr, cpu_online_mask);
10372 #ifdef CONFIG_DEBUG_DCFLUSH
10373- atomic_inc(&dcpage_flushes_xcall);
10374+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10375 #endif
10376 }
10377 __local_flush_dcache_page(page);
10378diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10379index 3a8d184..49498a8 100644
10380--- a/arch/sparc/kernel/sys_sparc_32.c
10381+++ b/arch/sparc/kernel/sys_sparc_32.c
10382@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10383 if (len > TASK_SIZE - PAGE_SIZE)
10384 return -ENOMEM;
10385 if (!addr)
10386- addr = TASK_UNMAPPED_BASE;
10387+ addr = current->mm->mmap_base;
10388
10389 info.flags = 0;
10390 info.length = len;
10391diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10392index beb0b5a..5a153f7 100644
10393--- a/arch/sparc/kernel/sys_sparc_64.c
10394+++ b/arch/sparc/kernel/sys_sparc_64.c
10395@@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10396 struct vm_area_struct * vma;
10397 unsigned long task_size = TASK_SIZE;
10398 int do_color_align;
10399+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10400 struct vm_unmapped_area_info info;
10401
10402 if (flags & MAP_FIXED) {
10403 /* We do not accept a shared mapping if it would violate
10404 * cache aliasing constraints.
10405 */
10406- if ((flags & MAP_SHARED) &&
10407+ if ((filp || (flags & MAP_SHARED)) &&
10408 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10409 return -EINVAL;
10410 return addr;
10411@@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10412 if (filp || (flags & MAP_SHARED))
10413 do_color_align = 1;
10414
10415+#ifdef CONFIG_PAX_RANDMMAP
10416+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10417+#endif
10418+
10419 if (addr) {
10420 if (do_color_align)
10421 addr = COLOR_ALIGN(addr, pgoff);
10422@@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10423 addr = PAGE_ALIGN(addr);
10424
10425 vma = find_vma(mm, addr);
10426- if (task_size - len >= addr &&
10427- (!vma || addr + len <= vma->vm_start))
10428+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10429 return addr;
10430 }
10431
10432 info.flags = 0;
10433 info.length = len;
10434- info.low_limit = TASK_UNMAPPED_BASE;
10435+ info.low_limit = mm->mmap_base;
10436 info.high_limit = min(task_size, VA_EXCLUDE_START);
10437 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10438 info.align_offset = pgoff << PAGE_SHIFT;
10439+ info.threadstack_offset = offset;
10440 addr = vm_unmapped_area(&info);
10441
10442 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10443 VM_BUG_ON(addr != -ENOMEM);
10444 info.low_limit = VA_EXCLUDE_END;
10445+
10446+#ifdef CONFIG_PAX_RANDMMAP
10447+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10448+ info.low_limit += mm->delta_mmap;
10449+#endif
10450+
10451 info.high_limit = task_size;
10452 addr = vm_unmapped_area(&info);
10453 }
10454@@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10455 unsigned long task_size = STACK_TOP32;
10456 unsigned long addr = addr0;
10457 int do_color_align;
10458+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10459 struct vm_unmapped_area_info info;
10460
10461 /* This should only ever run for 32-bit processes. */
10462@@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10463 /* We do not accept a shared mapping if it would violate
10464 * cache aliasing constraints.
10465 */
10466- if ((flags & MAP_SHARED) &&
10467+ if ((filp || (flags & MAP_SHARED)) &&
10468 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10469 return -EINVAL;
10470 return addr;
10471@@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10472 if (filp || (flags & MAP_SHARED))
10473 do_color_align = 1;
10474
10475+#ifdef CONFIG_PAX_RANDMMAP
10476+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10477+#endif
10478+
10479 /* requesting a specific address */
10480 if (addr) {
10481 if (do_color_align)
10482@@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10483 addr = PAGE_ALIGN(addr);
10484
10485 vma = find_vma(mm, addr);
10486- if (task_size - len >= addr &&
10487- (!vma || addr + len <= vma->vm_start))
10488+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10489 return addr;
10490 }
10491
10492@@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10493 info.high_limit = mm->mmap_base;
10494 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10495 info.align_offset = pgoff << PAGE_SHIFT;
10496+ info.threadstack_offset = offset;
10497 addr = vm_unmapped_area(&info);
10498
10499 /*
10500@@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10501 VM_BUG_ON(addr != -ENOMEM);
10502 info.flags = 0;
10503 info.low_limit = TASK_UNMAPPED_BASE;
10504+
10505+#ifdef CONFIG_PAX_RANDMMAP
10506+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10507+ info.low_limit += mm->delta_mmap;
10508+#endif
10509+
10510 info.high_limit = STACK_TOP32;
10511 addr = vm_unmapped_area(&info);
10512 }
10513@@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10514 EXPORT_SYMBOL(get_fb_unmapped_area);
10515
10516 /* Essentially the same as PowerPC. */
10517-static unsigned long mmap_rnd(void)
10518+static unsigned long mmap_rnd(struct mm_struct *mm)
10519 {
10520 unsigned long rnd = 0UL;
10521
10522+#ifdef CONFIG_PAX_RANDMMAP
10523+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10524+#endif
10525+
10526 if (current->flags & PF_RANDOMIZE) {
10527 unsigned long val = get_random_int();
10528 if (test_thread_flag(TIF_32BIT))
10529@@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10530
10531 void arch_pick_mmap_layout(struct mm_struct *mm)
10532 {
10533- unsigned long random_factor = mmap_rnd();
10534+ unsigned long random_factor = mmap_rnd(mm);
10535 unsigned long gap;
10536
10537 /*
10538@@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10539 gap == RLIM_INFINITY ||
10540 sysctl_legacy_va_layout) {
10541 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10542+
10543+#ifdef CONFIG_PAX_RANDMMAP
10544+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10545+ mm->mmap_base += mm->delta_mmap;
10546+#endif
10547+
10548 mm->get_unmapped_area = arch_get_unmapped_area;
10549 } else {
10550 /* We know it's 32-bit */
10551@@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10552 gap = (task_size / 6 * 5);
10553
10554 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10555+
10556+#ifdef CONFIG_PAX_RANDMMAP
10557+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10558+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10559+#endif
10560+
10561 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10562 }
10563 }
10564diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10565index 33a17e7..d87fb1f 100644
10566--- a/arch/sparc/kernel/syscalls.S
10567+++ b/arch/sparc/kernel/syscalls.S
10568@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10569 #endif
10570 .align 32
10571 1: ldx [%g6 + TI_FLAGS], %l5
10572- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10573+ andcc %l5, _TIF_WORK_SYSCALL, %g0
10574 be,pt %icc, rtrap
10575 nop
10576 call syscall_trace_leave
10577@@ -184,7 +184,7 @@ linux_sparc_syscall32:
10578
10579 srl %i3, 0, %o3 ! IEU0
10580 srl %i2, 0, %o2 ! IEU0 Group
10581- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10582+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10583 bne,pn %icc, linux_syscall_trace32 ! CTI
10584 mov %i0, %l5 ! IEU1
10585 5: call %l7 ! CTI Group brk forced
10586@@ -208,7 +208,7 @@ linux_sparc_syscall:
10587
10588 mov %i3, %o3 ! IEU1
10589 mov %i4, %o4 ! IEU0 Group
10590- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10591+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10592 bne,pn %icc, linux_syscall_trace ! CTI Group
10593 mov %i0, %l5 ! IEU0
10594 2: call %l7 ! CTI Group brk forced
10595@@ -223,7 +223,7 @@ ret_sys_call:
10596
10597 cmp %o0, -ERESTART_RESTARTBLOCK
10598 bgeu,pn %xcc, 1f
10599- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10600+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10601 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10602
10603 2:
10604diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10605index 6629829..036032d 100644
10606--- a/arch/sparc/kernel/traps_32.c
10607+++ b/arch/sparc/kernel/traps_32.c
10608@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10609 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10610 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10611
10612+extern void gr_handle_kernel_exploit(void);
10613+
10614 void die_if_kernel(char *str, struct pt_regs *regs)
10615 {
10616 static int die_counter;
10617@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10618 count++ < 30 &&
10619 (((unsigned long) rw) >= PAGE_OFFSET) &&
10620 !(((unsigned long) rw) & 0x7)) {
10621- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10622+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10623 (void *) rw->ins[7]);
10624 rw = (struct reg_window32 *)rw->ins[6];
10625 }
10626 }
10627 printk("Instruction DUMP:");
10628 instruction_dump ((unsigned long *) regs->pc);
10629- if(regs->psr & PSR_PS)
10630+ if(regs->psr & PSR_PS) {
10631+ gr_handle_kernel_exploit();
10632 do_exit(SIGKILL);
10633+ }
10634 do_exit(SIGSEGV);
10635 }
10636
10637diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10638index 4ced92f..965eeed 100644
10639--- a/arch/sparc/kernel/traps_64.c
10640+++ b/arch/sparc/kernel/traps_64.c
10641@@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10642 i + 1,
10643 p->trapstack[i].tstate, p->trapstack[i].tpc,
10644 p->trapstack[i].tnpc, p->trapstack[i].tt);
10645- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10646+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10647 }
10648 }
10649
10650@@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10651
10652 lvl -= 0x100;
10653 if (regs->tstate & TSTATE_PRIV) {
10654+
10655+#ifdef CONFIG_PAX_REFCOUNT
10656+ if (lvl == 6)
10657+ pax_report_refcount_overflow(regs);
10658+#endif
10659+
10660 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10661 die_if_kernel(buffer, regs);
10662 }
10663@@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10664 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10665 {
10666 char buffer[32];
10667-
10668+
10669 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10670 0, lvl, SIGTRAP) == NOTIFY_STOP)
10671 return;
10672
10673+#ifdef CONFIG_PAX_REFCOUNT
10674+ if (lvl == 6)
10675+ pax_report_refcount_overflow(regs);
10676+#endif
10677+
10678 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10679
10680 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10681@@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10682 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10683 printk("%s" "ERROR(%d): ",
10684 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10685- printk("TPC<%pS>\n", (void *) regs->tpc);
10686+ printk("TPC<%pA>\n", (void *) regs->tpc);
10687 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10688 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10689 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10690@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10691 smp_processor_id(),
10692 (type & 0x1) ? 'I' : 'D',
10693 regs->tpc);
10694- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10695+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10696 panic("Irrecoverable Cheetah+ parity error.");
10697 }
10698
10699@@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10700 smp_processor_id(),
10701 (type & 0x1) ? 'I' : 'D',
10702 regs->tpc);
10703- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10704+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10705 }
10706
10707 struct sun4v_error_entry {
10708@@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10709 /*0x38*/u64 reserved_5;
10710 };
10711
10712-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10713-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10714+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10715+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10716
10717 static const char *sun4v_err_type_to_str(u8 type)
10718 {
10719@@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10720 }
10721
10722 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10723- int cpu, const char *pfx, atomic_t *ocnt)
10724+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10725 {
10726 u64 *raw_ptr = (u64 *) ent;
10727 u32 attrs;
10728@@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10729
10730 show_regs(regs);
10731
10732- if ((cnt = atomic_read(ocnt)) != 0) {
10733- atomic_set(ocnt, 0);
10734+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10735+ atomic_set_unchecked(ocnt, 0);
10736 wmb();
10737 printk("%s: Queue overflowed %d times.\n",
10738 pfx, cnt);
10739@@ -2046,7 +2057,7 @@ out:
10740 */
10741 void sun4v_resum_overflow(struct pt_regs *regs)
10742 {
10743- atomic_inc(&sun4v_resum_oflow_cnt);
10744+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10745 }
10746
10747 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10748@@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10749 /* XXX Actually even this can make not that much sense. Perhaps
10750 * XXX we should just pull the plug and panic directly from here?
10751 */
10752- atomic_inc(&sun4v_nonresum_oflow_cnt);
10753+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10754 }
10755
10756 unsigned long sun4v_err_itlb_vaddr;
10757@@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10758
10759 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10760 regs->tpc, tl);
10761- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10762+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10763 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10764- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10765+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10766 (void *) regs->u_regs[UREG_I7]);
10767 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10768 "pte[%lx] error[%lx]\n",
10769@@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10770
10771 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10772 regs->tpc, tl);
10773- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10774+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10775 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10776- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10777+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10778 (void *) regs->u_regs[UREG_I7]);
10779 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10780 "pte[%lx] error[%lx]\n",
10781@@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10782 fp = (unsigned long)sf->fp + STACK_BIAS;
10783 }
10784
10785- printk(" [%016lx] %pS\n", pc, (void *) pc);
10786+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10787 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10788 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10789 int index = tsk->curr_ret_stack;
10790 if (tsk->ret_stack && index >= graph) {
10791 pc = tsk->ret_stack[index - graph].ret;
10792- printk(" [%016lx] %pS\n", pc, (void *) pc);
10793+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10794 graph++;
10795 }
10796 }
10797@@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10798 return (struct reg_window *) (fp + STACK_BIAS);
10799 }
10800
10801+extern void gr_handle_kernel_exploit(void);
10802+
10803 void die_if_kernel(char *str, struct pt_regs *regs)
10804 {
10805 static int die_counter;
10806@@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10807 while (rw &&
10808 count++ < 30 &&
10809 kstack_valid(tp, (unsigned long) rw)) {
10810- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10811+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10812 (void *) rw->ins[7]);
10813
10814 rw = kernel_stack_up(rw);
10815@@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10816 }
10817 user_instruction_dump ((unsigned int __user *) regs->tpc);
10818 }
10819- if (regs->tstate & TSTATE_PRIV)
10820+ if (regs->tstate & TSTATE_PRIV) {
10821+ gr_handle_kernel_exploit();
10822 do_exit(SIGKILL);
10823+ }
10824 do_exit(SIGSEGV);
10825 }
10826 EXPORT_SYMBOL(die_if_kernel);
10827diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10828index 35ab8b6..9046547 100644
10829--- a/arch/sparc/kernel/unaligned_64.c
10830+++ b/arch/sparc/kernel/unaligned_64.c
10831@@ -295,7 +295,7 @@ static void log_unaligned(struct pt_regs *regs)
10832 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10833
10834 if (__ratelimit(&ratelimit)) {
10835- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10836+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10837 regs->tpc, (void *) regs->tpc);
10838 }
10839 }
10840diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10841index dbe119b..089c7c1 100644
10842--- a/arch/sparc/lib/Makefile
10843+++ b/arch/sparc/lib/Makefile
10844@@ -2,7 +2,7 @@
10845 #
10846
10847 asflags-y := -ansi -DST_DIV0=0x02
10848-ccflags-y := -Werror
10849+#ccflags-y := -Werror
10850
10851 lib-$(CONFIG_SPARC32) += ashrdi3.o
10852 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10853diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10854index 85c233d..68500e0 100644
10855--- a/arch/sparc/lib/atomic_64.S
10856+++ b/arch/sparc/lib/atomic_64.S
10857@@ -17,7 +17,12 @@
10858 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10859 BACKOFF_SETUP(%o2)
10860 1: lduw [%o1], %g1
10861- add %g1, %o0, %g7
10862+ addcc %g1, %o0, %g7
10863+
10864+#ifdef CONFIG_PAX_REFCOUNT
10865+ tvs %icc, 6
10866+#endif
10867+
10868 cas [%o1], %g1, %g7
10869 cmp %g1, %g7
10870 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10871@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10872 2: BACKOFF_SPIN(%o2, %o3, 1b)
10873 ENDPROC(atomic_add)
10874
10875+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10876+ BACKOFF_SETUP(%o2)
10877+1: lduw [%o1], %g1
10878+ add %g1, %o0, %g7
10879+ cas [%o1], %g1, %g7
10880+ cmp %g1, %g7
10881+ bne,pn %icc, 2f
10882+ nop
10883+ retl
10884+ nop
10885+2: BACKOFF_SPIN(%o2, %o3, 1b)
10886+ENDPROC(atomic_add_unchecked)
10887+
10888 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10889 BACKOFF_SETUP(%o2)
10890 1: lduw [%o1], %g1
10891- sub %g1, %o0, %g7
10892+ subcc %g1, %o0, %g7
10893+
10894+#ifdef CONFIG_PAX_REFCOUNT
10895+ tvs %icc, 6
10896+#endif
10897+
10898 cas [%o1], %g1, %g7
10899 cmp %g1, %g7
10900 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10901@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10902 2: BACKOFF_SPIN(%o2, %o3, 1b)
10903 ENDPROC(atomic_sub)
10904
10905+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10906+ BACKOFF_SETUP(%o2)
10907+1: lduw [%o1], %g1
10908+ sub %g1, %o0, %g7
10909+ cas [%o1], %g1, %g7
10910+ cmp %g1, %g7
10911+ bne,pn %icc, 2f
10912+ nop
10913+ retl
10914+ nop
10915+2: BACKOFF_SPIN(%o2, %o3, 1b)
10916+ENDPROC(atomic_sub_unchecked)
10917+
10918 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10919 BACKOFF_SETUP(%o2)
10920 1: lduw [%o1], %g1
10921- add %g1, %o0, %g7
10922+ addcc %g1, %o0, %g7
10923+
10924+#ifdef CONFIG_PAX_REFCOUNT
10925+ tvs %icc, 6
10926+#endif
10927+
10928 cas [%o1], %g1, %g7
10929 cmp %g1, %g7
10930 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10931@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10932 2: BACKOFF_SPIN(%o2, %o3, 1b)
10933 ENDPROC(atomic_add_ret)
10934
10935+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10936+ BACKOFF_SETUP(%o2)
10937+1: lduw [%o1], %g1
10938+ addcc %g1, %o0, %g7
10939+ cas [%o1], %g1, %g7
10940+ cmp %g1, %g7
10941+ bne,pn %icc, 2f
10942+ add %g7, %o0, %g7
10943+ sra %g7, 0, %o0
10944+ retl
10945+ nop
10946+2: BACKOFF_SPIN(%o2, %o3, 1b)
10947+ENDPROC(atomic_add_ret_unchecked)
10948+
10949 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10950 BACKOFF_SETUP(%o2)
10951 1: lduw [%o1], %g1
10952- sub %g1, %o0, %g7
10953+ subcc %g1, %o0, %g7
10954+
10955+#ifdef CONFIG_PAX_REFCOUNT
10956+ tvs %icc, 6
10957+#endif
10958+
10959 cas [%o1], %g1, %g7
10960 cmp %g1, %g7
10961 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10962@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10963 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10964 BACKOFF_SETUP(%o2)
10965 1: ldx [%o1], %g1
10966- add %g1, %o0, %g7
10967+ addcc %g1, %o0, %g7
10968+
10969+#ifdef CONFIG_PAX_REFCOUNT
10970+ tvs %xcc, 6
10971+#endif
10972+
10973 casx [%o1], %g1, %g7
10974 cmp %g1, %g7
10975 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10976@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10977 2: BACKOFF_SPIN(%o2, %o3, 1b)
10978 ENDPROC(atomic64_add)
10979
10980+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10981+ BACKOFF_SETUP(%o2)
10982+1: ldx [%o1], %g1
10983+ addcc %g1, %o0, %g7
10984+ casx [%o1], %g1, %g7
10985+ cmp %g1, %g7
10986+ bne,pn %xcc, 2f
10987+ nop
10988+ retl
10989+ nop
10990+2: BACKOFF_SPIN(%o2, %o3, 1b)
10991+ENDPROC(atomic64_add_unchecked)
10992+
10993 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10994 BACKOFF_SETUP(%o2)
10995 1: ldx [%o1], %g1
10996- sub %g1, %o0, %g7
10997+ subcc %g1, %o0, %g7
10998+
10999+#ifdef CONFIG_PAX_REFCOUNT
11000+ tvs %xcc, 6
11001+#endif
11002+
11003 casx [%o1], %g1, %g7
11004 cmp %g1, %g7
11005 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11006@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11007 2: BACKOFF_SPIN(%o2, %o3, 1b)
11008 ENDPROC(atomic64_sub)
11009
11010+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11011+ BACKOFF_SETUP(%o2)
11012+1: ldx [%o1], %g1
11013+ subcc %g1, %o0, %g7
11014+ casx [%o1], %g1, %g7
11015+ cmp %g1, %g7
11016+ bne,pn %xcc, 2f
11017+ nop
11018+ retl
11019+ nop
11020+2: BACKOFF_SPIN(%o2, %o3, 1b)
11021+ENDPROC(atomic64_sub_unchecked)
11022+
11023 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11024 BACKOFF_SETUP(%o2)
11025 1: ldx [%o1], %g1
11026- add %g1, %o0, %g7
11027+ addcc %g1, %o0, %g7
11028+
11029+#ifdef CONFIG_PAX_REFCOUNT
11030+ tvs %xcc, 6
11031+#endif
11032+
11033 casx [%o1], %g1, %g7
11034 cmp %g1, %g7
11035 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11036@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11037 2: BACKOFF_SPIN(%o2, %o3, 1b)
11038 ENDPROC(atomic64_add_ret)
11039
11040+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11041+ BACKOFF_SETUP(%o2)
11042+1: ldx [%o1], %g1
11043+ addcc %g1, %o0, %g7
11044+ casx [%o1], %g1, %g7
11045+ cmp %g1, %g7
11046+ bne,pn %xcc, 2f
11047+ add %g7, %o0, %g7
11048+ mov %g7, %o0
11049+ retl
11050+ nop
11051+2: BACKOFF_SPIN(%o2, %o3, 1b)
11052+ENDPROC(atomic64_add_ret_unchecked)
11053+
11054 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11055 BACKOFF_SETUP(%o2)
11056 1: ldx [%o1], %g1
11057- sub %g1, %o0, %g7
11058+ subcc %g1, %o0, %g7
11059+
11060+#ifdef CONFIG_PAX_REFCOUNT
11061+ tvs %xcc, 6
11062+#endif
11063+
11064 casx [%o1], %g1, %g7
11065 cmp %g1, %g7
11066 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11067diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11068index 323335b..ed85ea2 100644
11069--- a/arch/sparc/lib/ksyms.c
11070+++ b/arch/sparc/lib/ksyms.c
11071@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11072
11073 /* Atomic counter implementation. */
11074 EXPORT_SYMBOL(atomic_add);
11075+EXPORT_SYMBOL(atomic_add_unchecked);
11076 EXPORT_SYMBOL(atomic_add_ret);
11077+EXPORT_SYMBOL(atomic_add_ret_unchecked);
11078 EXPORT_SYMBOL(atomic_sub);
11079+EXPORT_SYMBOL(atomic_sub_unchecked);
11080 EXPORT_SYMBOL(atomic_sub_ret);
11081 EXPORT_SYMBOL(atomic64_add);
11082+EXPORT_SYMBOL(atomic64_add_unchecked);
11083 EXPORT_SYMBOL(atomic64_add_ret);
11084+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11085 EXPORT_SYMBOL(atomic64_sub);
11086+EXPORT_SYMBOL(atomic64_sub_unchecked);
11087 EXPORT_SYMBOL(atomic64_sub_ret);
11088 EXPORT_SYMBOL(atomic64_dec_if_positive);
11089
11090diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11091index 30c3ecc..736f015 100644
11092--- a/arch/sparc/mm/Makefile
11093+++ b/arch/sparc/mm/Makefile
11094@@ -2,7 +2,7 @@
11095 #
11096
11097 asflags-y := -ansi
11098-ccflags-y := -Werror
11099+#ccflags-y := -Werror
11100
11101 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11102 obj-y += fault_$(BITS).o
11103diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11104index 59dbd46..1dd7f5e 100644
11105--- a/arch/sparc/mm/fault_32.c
11106+++ b/arch/sparc/mm/fault_32.c
11107@@ -21,6 +21,9 @@
11108 #include <linux/perf_event.h>
11109 #include <linux/interrupt.h>
11110 #include <linux/kdebug.h>
11111+#include <linux/slab.h>
11112+#include <linux/pagemap.h>
11113+#include <linux/compiler.h>
11114
11115 #include <asm/page.h>
11116 #include <asm/pgtable.h>
11117@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11118 return safe_compute_effective_address(regs, insn);
11119 }
11120
11121+#ifdef CONFIG_PAX_PAGEEXEC
11122+#ifdef CONFIG_PAX_DLRESOLVE
11123+static void pax_emuplt_close(struct vm_area_struct *vma)
11124+{
11125+ vma->vm_mm->call_dl_resolve = 0UL;
11126+}
11127+
11128+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11129+{
11130+ unsigned int *kaddr;
11131+
11132+ vmf->page = alloc_page(GFP_HIGHUSER);
11133+ if (!vmf->page)
11134+ return VM_FAULT_OOM;
11135+
11136+ kaddr = kmap(vmf->page);
11137+ memset(kaddr, 0, PAGE_SIZE);
11138+ kaddr[0] = 0x9DE3BFA8U; /* save */
11139+ flush_dcache_page(vmf->page);
11140+ kunmap(vmf->page);
11141+ return VM_FAULT_MAJOR;
11142+}
11143+
11144+static const struct vm_operations_struct pax_vm_ops = {
11145+ .close = pax_emuplt_close,
11146+ .fault = pax_emuplt_fault
11147+};
11148+
11149+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11150+{
11151+ int ret;
11152+
11153+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11154+ vma->vm_mm = current->mm;
11155+ vma->vm_start = addr;
11156+ vma->vm_end = addr + PAGE_SIZE;
11157+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11158+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11159+ vma->vm_ops = &pax_vm_ops;
11160+
11161+ ret = insert_vm_struct(current->mm, vma);
11162+ if (ret)
11163+ return ret;
11164+
11165+ ++current->mm->total_vm;
11166+ return 0;
11167+}
11168+#endif
11169+
11170+/*
11171+ * PaX: decide what to do with offenders (regs->pc = fault address)
11172+ *
11173+ * returns 1 when task should be killed
11174+ * 2 when patched PLT trampoline was detected
11175+ * 3 when unpatched PLT trampoline was detected
11176+ */
11177+static int pax_handle_fetch_fault(struct pt_regs *regs)
11178+{
11179+
11180+#ifdef CONFIG_PAX_EMUPLT
11181+ int err;
11182+
11183+ do { /* PaX: patched PLT emulation #1 */
11184+ unsigned int sethi1, sethi2, jmpl;
11185+
11186+ err = get_user(sethi1, (unsigned int *)regs->pc);
11187+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11188+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11189+
11190+ if (err)
11191+ break;
11192+
11193+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11194+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11195+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11196+ {
11197+ unsigned int addr;
11198+
11199+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11200+ addr = regs->u_regs[UREG_G1];
11201+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11202+ regs->pc = addr;
11203+ regs->npc = addr+4;
11204+ return 2;
11205+ }
11206+ } while (0);
11207+
11208+ do { /* PaX: patched PLT emulation #2 */
11209+ unsigned int ba;
11210+
11211+ err = get_user(ba, (unsigned int *)regs->pc);
11212+
11213+ if (err)
11214+ break;
11215+
11216+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11217+ unsigned int addr;
11218+
11219+ if ((ba & 0xFFC00000U) == 0x30800000U)
11220+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11221+ else
11222+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11223+ regs->pc = addr;
11224+ regs->npc = addr+4;
11225+ return 2;
11226+ }
11227+ } while (0);
11228+
11229+ do { /* PaX: patched PLT emulation #3 */
11230+ unsigned int sethi, bajmpl, nop;
11231+
11232+ err = get_user(sethi, (unsigned int *)regs->pc);
11233+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11234+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11235+
11236+ if (err)
11237+ break;
11238+
11239+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11240+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11241+ nop == 0x01000000U)
11242+ {
11243+ unsigned int addr;
11244+
11245+ addr = (sethi & 0x003FFFFFU) << 10;
11246+ regs->u_regs[UREG_G1] = addr;
11247+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11248+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11249+ else
11250+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11251+ regs->pc = addr;
11252+ regs->npc = addr+4;
11253+ return 2;
11254+ }
11255+ } while (0);
11256+
11257+ do { /* PaX: unpatched PLT emulation step 1 */
11258+ unsigned int sethi, ba, nop;
11259+
11260+ err = get_user(sethi, (unsigned int *)regs->pc);
11261+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11262+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11263+
11264+ if (err)
11265+ break;
11266+
11267+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11268+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11269+ nop == 0x01000000U)
11270+ {
11271+ unsigned int addr, save, call;
11272+
11273+ if ((ba & 0xFFC00000U) == 0x30800000U)
11274+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11275+ else
11276+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11277+
11278+ err = get_user(save, (unsigned int *)addr);
11279+ err |= get_user(call, (unsigned int *)(addr+4));
11280+ err |= get_user(nop, (unsigned int *)(addr+8));
11281+ if (err)
11282+ break;
11283+
11284+#ifdef CONFIG_PAX_DLRESOLVE
11285+ if (save == 0x9DE3BFA8U &&
11286+ (call & 0xC0000000U) == 0x40000000U &&
11287+ nop == 0x01000000U)
11288+ {
11289+ struct vm_area_struct *vma;
11290+ unsigned long call_dl_resolve;
11291+
11292+ down_read(&current->mm->mmap_sem);
11293+ call_dl_resolve = current->mm->call_dl_resolve;
11294+ up_read(&current->mm->mmap_sem);
11295+ if (likely(call_dl_resolve))
11296+ goto emulate;
11297+
11298+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11299+
11300+ down_write(&current->mm->mmap_sem);
11301+ if (current->mm->call_dl_resolve) {
11302+ call_dl_resolve = current->mm->call_dl_resolve;
11303+ up_write(&current->mm->mmap_sem);
11304+ if (vma)
11305+ kmem_cache_free(vm_area_cachep, vma);
11306+ goto emulate;
11307+ }
11308+
11309+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11310+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11311+ up_write(&current->mm->mmap_sem);
11312+ if (vma)
11313+ kmem_cache_free(vm_area_cachep, vma);
11314+ return 1;
11315+ }
11316+
11317+ if (pax_insert_vma(vma, call_dl_resolve)) {
11318+ up_write(&current->mm->mmap_sem);
11319+ kmem_cache_free(vm_area_cachep, vma);
11320+ return 1;
11321+ }
11322+
11323+ current->mm->call_dl_resolve = call_dl_resolve;
11324+ up_write(&current->mm->mmap_sem);
11325+
11326+emulate:
11327+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11328+ regs->pc = call_dl_resolve;
11329+ regs->npc = addr+4;
11330+ return 3;
11331+ }
11332+#endif
11333+
11334+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11335+ if ((save & 0xFFC00000U) == 0x05000000U &&
11336+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11337+ nop == 0x01000000U)
11338+ {
11339+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11340+ regs->u_regs[UREG_G2] = addr + 4;
11341+ addr = (save & 0x003FFFFFU) << 10;
11342+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11343+ regs->pc = addr;
11344+ regs->npc = addr+4;
11345+ return 3;
11346+ }
11347+ }
11348+ } while (0);
11349+
11350+ do { /* PaX: unpatched PLT emulation step 2 */
11351+ unsigned int save, call, nop;
11352+
11353+ err = get_user(save, (unsigned int *)(regs->pc-4));
11354+ err |= get_user(call, (unsigned int *)regs->pc);
11355+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11356+ if (err)
11357+ break;
11358+
11359+ if (save == 0x9DE3BFA8U &&
11360+ (call & 0xC0000000U) == 0x40000000U &&
11361+ nop == 0x01000000U)
11362+ {
11363+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11364+
11365+ regs->u_regs[UREG_RETPC] = regs->pc;
11366+ regs->pc = dl_resolve;
11367+ regs->npc = dl_resolve+4;
11368+ return 3;
11369+ }
11370+ } while (0);
11371+#endif
11372+
11373+ return 1;
11374+}
11375+
11376+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11377+{
11378+ unsigned long i;
11379+
11380+ printk(KERN_ERR "PAX: bytes at PC: ");
11381+ for (i = 0; i < 8; i++) {
11382+ unsigned int c;
11383+ if (get_user(c, (unsigned int *)pc+i))
11384+ printk(KERN_CONT "???????? ");
11385+ else
11386+ printk(KERN_CONT "%08x ", c);
11387+ }
11388+ printk("\n");
11389+}
11390+#endif
11391+
11392 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11393 int text_fault)
11394 {
11395@@ -229,6 +503,24 @@ good_area:
11396 if (!(vma->vm_flags & VM_WRITE))
11397 goto bad_area;
11398 } else {
11399+
11400+#ifdef CONFIG_PAX_PAGEEXEC
11401+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11402+ up_read(&mm->mmap_sem);
11403+ switch (pax_handle_fetch_fault(regs)) {
11404+
11405+#ifdef CONFIG_PAX_EMUPLT
11406+ case 2:
11407+ case 3:
11408+ return;
11409+#endif
11410+
11411+ }
11412+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11413+ do_group_exit(SIGKILL);
11414+ }
11415+#endif
11416+
11417 /* Allow reads even for write-only mappings */
11418 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11419 goto bad_area;
11420diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11421index 4ced3fc..234f1e4 100644
11422--- a/arch/sparc/mm/fault_64.c
11423+++ b/arch/sparc/mm/fault_64.c
11424@@ -22,6 +22,9 @@
11425 #include <linux/kdebug.h>
11426 #include <linux/percpu.h>
11427 #include <linux/context_tracking.h>
11428+#include <linux/slab.h>
11429+#include <linux/pagemap.h>
11430+#include <linux/compiler.h>
11431
11432 #include <asm/page.h>
11433 #include <asm/pgtable.h>
11434@@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11435 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11436 regs->tpc);
11437 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11438- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11439+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11440 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11441 dump_stack();
11442 unhandled_fault(regs->tpc, current, regs);
11443@@ -281,6 +284,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11444 show_regs(regs);
11445 }
11446
11447+#ifdef CONFIG_PAX_PAGEEXEC
11448+#ifdef CONFIG_PAX_DLRESOLVE
11449+static void pax_emuplt_close(struct vm_area_struct *vma)
11450+{
11451+ vma->vm_mm->call_dl_resolve = 0UL;
11452+}
11453+
11454+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11455+{
11456+ unsigned int *kaddr;
11457+
11458+ vmf->page = alloc_page(GFP_HIGHUSER);
11459+ if (!vmf->page)
11460+ return VM_FAULT_OOM;
11461+
11462+ kaddr = kmap(vmf->page);
11463+ memset(kaddr, 0, PAGE_SIZE);
11464+ kaddr[0] = 0x9DE3BFA8U; /* save */
11465+ flush_dcache_page(vmf->page);
11466+ kunmap(vmf->page);
11467+ return VM_FAULT_MAJOR;
11468+}
11469+
11470+static const struct vm_operations_struct pax_vm_ops = {
11471+ .close = pax_emuplt_close,
11472+ .fault = pax_emuplt_fault
11473+};
11474+
11475+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11476+{
11477+ int ret;
11478+
11479+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11480+ vma->vm_mm = current->mm;
11481+ vma->vm_start = addr;
11482+ vma->vm_end = addr + PAGE_SIZE;
11483+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11484+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11485+ vma->vm_ops = &pax_vm_ops;
11486+
11487+ ret = insert_vm_struct(current->mm, vma);
11488+ if (ret)
11489+ return ret;
11490+
11491+ ++current->mm->total_vm;
11492+ return 0;
11493+}
11494+#endif
11495+
11496+/*
11497+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11498+ *
11499+ * returns 1 when task should be killed
11500+ * 2 when patched PLT trampoline was detected
11501+ * 3 when unpatched PLT trampoline was detected
11502+ */
11503+static int pax_handle_fetch_fault(struct pt_regs *regs)
11504+{
11505+
11506+#ifdef CONFIG_PAX_EMUPLT
11507+ int err;
11508+
11509+ do { /* PaX: patched PLT emulation #1 */
11510+ unsigned int sethi1, sethi2, jmpl;
11511+
11512+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11513+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11514+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11515+
11516+ if (err)
11517+ break;
11518+
11519+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11520+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11521+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11522+ {
11523+ unsigned long addr;
11524+
11525+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11526+ addr = regs->u_regs[UREG_G1];
11527+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11528+
11529+ if (test_thread_flag(TIF_32BIT))
11530+ addr &= 0xFFFFFFFFUL;
11531+
11532+ regs->tpc = addr;
11533+ regs->tnpc = addr+4;
11534+ return 2;
11535+ }
11536+ } while (0);
11537+
11538+ do { /* PaX: patched PLT emulation #2 */
11539+ unsigned int ba;
11540+
11541+ err = get_user(ba, (unsigned int *)regs->tpc);
11542+
11543+ if (err)
11544+ break;
11545+
11546+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11547+ unsigned long addr;
11548+
11549+ if ((ba & 0xFFC00000U) == 0x30800000U)
11550+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11551+ else
11552+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11553+
11554+ if (test_thread_flag(TIF_32BIT))
11555+ addr &= 0xFFFFFFFFUL;
11556+
11557+ regs->tpc = addr;
11558+ regs->tnpc = addr+4;
11559+ return 2;
11560+ }
11561+ } while (0);
11562+
11563+ do { /* PaX: patched PLT emulation #3 */
11564+ unsigned int sethi, bajmpl, nop;
11565+
11566+ err = get_user(sethi, (unsigned int *)regs->tpc);
11567+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11568+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11569+
11570+ if (err)
11571+ break;
11572+
11573+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11574+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11575+ nop == 0x01000000U)
11576+ {
11577+ unsigned long addr;
11578+
11579+ addr = (sethi & 0x003FFFFFU) << 10;
11580+ regs->u_regs[UREG_G1] = addr;
11581+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11582+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11583+ else
11584+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11585+
11586+ if (test_thread_flag(TIF_32BIT))
11587+ addr &= 0xFFFFFFFFUL;
11588+
11589+ regs->tpc = addr;
11590+ regs->tnpc = addr+4;
11591+ return 2;
11592+ }
11593+ } while (0);
11594+
11595+ do { /* PaX: patched PLT emulation #4 */
11596+ unsigned int sethi, mov1, call, mov2;
11597+
11598+ err = get_user(sethi, (unsigned int *)regs->tpc);
11599+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11600+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11601+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11602+
11603+ if (err)
11604+ break;
11605+
11606+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11607+ mov1 == 0x8210000FU &&
11608+ (call & 0xC0000000U) == 0x40000000U &&
11609+ mov2 == 0x9E100001U)
11610+ {
11611+ unsigned long addr;
11612+
11613+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11614+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11615+
11616+ if (test_thread_flag(TIF_32BIT))
11617+ addr &= 0xFFFFFFFFUL;
11618+
11619+ regs->tpc = addr;
11620+ regs->tnpc = addr+4;
11621+ return 2;
11622+ }
11623+ } while (0);
11624+
11625+ do { /* PaX: patched PLT emulation #5 */
11626+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11627+
11628+ err = get_user(sethi, (unsigned int *)regs->tpc);
11629+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11630+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11631+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11632+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11633+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11634+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11635+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11636+
11637+ if (err)
11638+ break;
11639+
11640+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11641+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11642+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11643+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11644+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11645+ sllx == 0x83287020U &&
11646+ jmpl == 0x81C04005U &&
11647+ nop == 0x01000000U)
11648+ {
11649+ unsigned long addr;
11650+
11651+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11652+ regs->u_regs[UREG_G1] <<= 32;
11653+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11654+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11655+ regs->tpc = addr;
11656+ regs->tnpc = addr+4;
11657+ return 2;
11658+ }
11659+ } while (0);
11660+
11661+ do { /* PaX: patched PLT emulation #6 */
11662+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11663+
11664+ err = get_user(sethi, (unsigned int *)regs->tpc);
11665+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11666+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11667+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11668+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11669+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11670+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11671+
11672+ if (err)
11673+ break;
11674+
11675+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11676+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11677+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11678+ sllx == 0x83287020U &&
11679+ (or & 0xFFFFE000U) == 0x8A116000U &&
11680+ jmpl == 0x81C04005U &&
11681+ nop == 0x01000000U)
11682+ {
11683+ unsigned long addr;
11684+
11685+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11686+ regs->u_regs[UREG_G1] <<= 32;
11687+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11688+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11689+ regs->tpc = addr;
11690+ regs->tnpc = addr+4;
11691+ return 2;
11692+ }
11693+ } while (0);
11694+
11695+ do { /* PaX: unpatched PLT emulation step 1 */
11696+ unsigned int sethi, ba, nop;
11697+
11698+ err = get_user(sethi, (unsigned int *)regs->tpc);
11699+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11700+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11701+
11702+ if (err)
11703+ break;
11704+
11705+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11706+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11707+ nop == 0x01000000U)
11708+ {
11709+ unsigned long addr;
11710+ unsigned int save, call;
11711+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11712+
11713+ if ((ba & 0xFFC00000U) == 0x30800000U)
11714+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11715+ else
11716+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11717+
11718+ if (test_thread_flag(TIF_32BIT))
11719+ addr &= 0xFFFFFFFFUL;
11720+
11721+ err = get_user(save, (unsigned int *)addr);
11722+ err |= get_user(call, (unsigned int *)(addr+4));
11723+ err |= get_user(nop, (unsigned int *)(addr+8));
11724+ if (err)
11725+ break;
11726+
11727+#ifdef CONFIG_PAX_DLRESOLVE
11728+ if (save == 0x9DE3BFA8U &&
11729+ (call & 0xC0000000U) == 0x40000000U &&
11730+ nop == 0x01000000U)
11731+ {
11732+ struct vm_area_struct *vma;
11733+ unsigned long call_dl_resolve;
11734+
11735+ down_read(&current->mm->mmap_sem);
11736+ call_dl_resolve = current->mm->call_dl_resolve;
11737+ up_read(&current->mm->mmap_sem);
11738+ if (likely(call_dl_resolve))
11739+ goto emulate;
11740+
11741+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11742+
11743+ down_write(&current->mm->mmap_sem);
11744+ if (current->mm->call_dl_resolve) {
11745+ call_dl_resolve = current->mm->call_dl_resolve;
11746+ up_write(&current->mm->mmap_sem);
11747+ if (vma)
11748+ kmem_cache_free(vm_area_cachep, vma);
11749+ goto emulate;
11750+ }
11751+
11752+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11753+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11754+ up_write(&current->mm->mmap_sem);
11755+ if (vma)
11756+ kmem_cache_free(vm_area_cachep, vma);
11757+ return 1;
11758+ }
11759+
11760+ if (pax_insert_vma(vma, call_dl_resolve)) {
11761+ up_write(&current->mm->mmap_sem);
11762+ kmem_cache_free(vm_area_cachep, vma);
11763+ return 1;
11764+ }
11765+
11766+ current->mm->call_dl_resolve = call_dl_resolve;
11767+ up_write(&current->mm->mmap_sem);
11768+
11769+emulate:
11770+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11771+ regs->tpc = call_dl_resolve;
11772+ regs->tnpc = addr+4;
11773+ return 3;
11774+ }
11775+#endif
11776+
11777+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11778+ if ((save & 0xFFC00000U) == 0x05000000U &&
11779+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11780+ nop == 0x01000000U)
11781+ {
11782+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11783+ regs->u_regs[UREG_G2] = addr + 4;
11784+ addr = (save & 0x003FFFFFU) << 10;
11785+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11786+
11787+ if (test_thread_flag(TIF_32BIT))
11788+ addr &= 0xFFFFFFFFUL;
11789+
11790+ regs->tpc = addr;
11791+ regs->tnpc = addr+4;
11792+ return 3;
11793+ }
11794+
11795+ /* PaX: 64-bit PLT stub */
11796+ err = get_user(sethi1, (unsigned int *)addr);
11797+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11798+ err |= get_user(or1, (unsigned int *)(addr+8));
11799+ err |= get_user(or2, (unsigned int *)(addr+12));
11800+ err |= get_user(sllx, (unsigned int *)(addr+16));
11801+ err |= get_user(add, (unsigned int *)(addr+20));
11802+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11803+ err |= get_user(nop, (unsigned int *)(addr+28));
11804+ if (err)
11805+ break;
11806+
11807+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11808+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11809+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11810+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11811+ sllx == 0x89293020U &&
11812+ add == 0x8A010005U &&
11813+ jmpl == 0x89C14000U &&
11814+ nop == 0x01000000U)
11815+ {
11816+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11817+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11818+ regs->u_regs[UREG_G4] <<= 32;
11819+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11820+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11821+ regs->u_regs[UREG_G4] = addr + 24;
11822+ addr = regs->u_regs[UREG_G5];
11823+ regs->tpc = addr;
11824+ regs->tnpc = addr+4;
11825+ return 3;
11826+ }
11827+ }
11828+ } while (0);
11829+
11830+#ifdef CONFIG_PAX_DLRESOLVE
11831+ do { /* PaX: unpatched PLT emulation step 2 */
11832+ unsigned int save, call, nop;
11833+
11834+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11835+ err |= get_user(call, (unsigned int *)regs->tpc);
11836+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11837+ if (err)
11838+ break;
11839+
11840+ if (save == 0x9DE3BFA8U &&
11841+ (call & 0xC0000000U) == 0x40000000U &&
11842+ nop == 0x01000000U)
11843+ {
11844+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11845+
11846+ if (test_thread_flag(TIF_32BIT))
11847+ dl_resolve &= 0xFFFFFFFFUL;
11848+
11849+ regs->u_regs[UREG_RETPC] = regs->tpc;
11850+ regs->tpc = dl_resolve;
11851+ regs->tnpc = dl_resolve+4;
11852+ return 3;
11853+ }
11854+ } while (0);
11855+#endif
11856+
11857+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11858+ unsigned int sethi, ba, nop;
11859+
11860+ err = get_user(sethi, (unsigned int *)regs->tpc);
11861+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11862+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11863+
11864+ if (err)
11865+ break;
11866+
11867+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11868+ (ba & 0xFFF00000U) == 0x30600000U &&
11869+ nop == 0x01000000U)
11870+ {
11871+ unsigned long addr;
11872+
11873+ addr = (sethi & 0x003FFFFFU) << 10;
11874+ regs->u_regs[UREG_G1] = addr;
11875+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11876+
11877+ if (test_thread_flag(TIF_32BIT))
11878+ addr &= 0xFFFFFFFFUL;
11879+
11880+ regs->tpc = addr;
11881+ regs->tnpc = addr+4;
11882+ return 2;
11883+ }
11884+ } while (0);
11885+
11886+#endif
11887+
11888+ return 1;
11889+}
11890+
11891+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11892+{
11893+ unsigned long i;
11894+
11895+ printk(KERN_ERR "PAX: bytes at PC: ");
11896+ for (i = 0; i < 8; i++) {
11897+ unsigned int c;
11898+ if (get_user(c, (unsigned int *)pc+i))
11899+ printk(KERN_CONT "???????? ");
11900+ else
11901+ printk(KERN_CONT "%08x ", c);
11902+ }
11903+ printk("\n");
11904+}
11905+#endif
11906+
11907 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11908 {
11909 enum ctx_state prev_state = exception_enter();
11910@@ -352,6 +815,29 @@ retry:
11911 if (!vma)
11912 goto bad_area;
11913
11914+#ifdef CONFIG_PAX_PAGEEXEC
11915+ /* PaX: detect ITLB misses on non-exec pages */
11916+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11917+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11918+ {
11919+ if (address != regs->tpc)
11920+ goto good_area;
11921+
11922+ up_read(&mm->mmap_sem);
11923+ switch (pax_handle_fetch_fault(regs)) {
11924+
11925+#ifdef CONFIG_PAX_EMUPLT
11926+ case 2:
11927+ case 3:
11928+ return;
11929+#endif
11930+
11931+ }
11932+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11933+ do_group_exit(SIGKILL);
11934+ }
11935+#endif
11936+
11937 /* Pure DTLB misses do not tell us whether the fault causing
11938 * load/store/atomic was a write or not, it only says that there
11939 * was no match. So in such a case we (carefully) read the
11940diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11941index d329537..2c3746a 100644
11942--- a/arch/sparc/mm/hugetlbpage.c
11943+++ b/arch/sparc/mm/hugetlbpage.c
11944@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11945 unsigned long addr,
11946 unsigned long len,
11947 unsigned long pgoff,
11948- unsigned long flags)
11949+ unsigned long flags,
11950+ unsigned long offset)
11951 {
11952+ struct mm_struct *mm = current->mm;
11953 unsigned long task_size = TASK_SIZE;
11954 struct vm_unmapped_area_info info;
11955
11956@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11957
11958 info.flags = 0;
11959 info.length = len;
11960- info.low_limit = TASK_UNMAPPED_BASE;
11961+ info.low_limit = mm->mmap_base;
11962 info.high_limit = min(task_size, VA_EXCLUDE_START);
11963 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11964 info.align_offset = 0;
11965+ info.threadstack_offset = offset;
11966 addr = vm_unmapped_area(&info);
11967
11968 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11969 VM_BUG_ON(addr != -ENOMEM);
11970 info.low_limit = VA_EXCLUDE_END;
11971+
11972+#ifdef CONFIG_PAX_RANDMMAP
11973+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11974+ info.low_limit += mm->delta_mmap;
11975+#endif
11976+
11977 info.high_limit = task_size;
11978 addr = vm_unmapped_area(&info);
11979 }
11980@@ -55,7 +64,8 @@ static unsigned long
11981 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11982 const unsigned long len,
11983 const unsigned long pgoff,
11984- const unsigned long flags)
11985+ const unsigned long flags,
11986+ const unsigned long offset)
11987 {
11988 struct mm_struct *mm = current->mm;
11989 unsigned long addr = addr0;
11990@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11991 info.high_limit = mm->mmap_base;
11992 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11993 info.align_offset = 0;
11994+ info.threadstack_offset = offset;
11995 addr = vm_unmapped_area(&info);
11996
11997 /*
11998@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11999 VM_BUG_ON(addr != -ENOMEM);
12000 info.flags = 0;
12001 info.low_limit = TASK_UNMAPPED_BASE;
12002+
12003+#ifdef CONFIG_PAX_RANDMMAP
12004+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12005+ info.low_limit += mm->delta_mmap;
12006+#endif
12007+
12008 info.high_limit = STACK_TOP32;
12009 addr = vm_unmapped_area(&info);
12010 }
12011@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12012 struct mm_struct *mm = current->mm;
12013 struct vm_area_struct *vma;
12014 unsigned long task_size = TASK_SIZE;
12015+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12016
12017 if (test_thread_flag(TIF_32BIT))
12018 task_size = STACK_TOP32;
12019@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12020 return addr;
12021 }
12022
12023+#ifdef CONFIG_PAX_RANDMMAP
12024+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12025+#endif
12026+
12027 if (addr) {
12028 addr = ALIGN(addr, HPAGE_SIZE);
12029 vma = find_vma(mm, addr);
12030- if (task_size - len >= addr &&
12031- (!vma || addr + len <= vma->vm_start))
12032+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12033 return addr;
12034 }
12035 if (mm->get_unmapped_area == arch_get_unmapped_area)
12036 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12037- pgoff, flags);
12038+ pgoff, flags, offset);
12039 else
12040 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12041- pgoff, flags);
12042+ pgoff, flags, offset);
12043 }
12044
12045 pte_t *huge_pte_alloc(struct mm_struct *mm,
12046diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12047index ed3c969..42fe48d 100644
12048--- a/arch/sparc/mm/init_64.c
12049+++ b/arch/sparc/mm/init_64.c
12050@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12051 int num_kernel_image_mappings;
12052
12053 #ifdef CONFIG_DEBUG_DCFLUSH
12054-atomic_t dcpage_flushes = ATOMIC_INIT(0);
12055+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12056 #ifdef CONFIG_SMP
12057-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12058+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12059 #endif
12060 #endif
12061
12062@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
12063 {
12064 BUG_ON(tlb_type == hypervisor);
12065 #ifdef CONFIG_DEBUG_DCFLUSH
12066- atomic_inc(&dcpage_flushes);
12067+ atomic_inc_unchecked(&dcpage_flushes);
12068 #endif
12069
12070 #ifdef DCACHE_ALIASING_POSSIBLE
12071@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
12072
12073 #ifdef CONFIG_DEBUG_DCFLUSH
12074 seq_printf(m, "DCPageFlushes\t: %d\n",
12075- atomic_read(&dcpage_flushes));
12076+ atomic_read_unchecked(&dcpage_flushes));
12077 #ifdef CONFIG_SMP
12078 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12079- atomic_read(&dcpage_flushes_xcall));
12080+ atomic_read_unchecked(&dcpage_flushes_xcall));
12081 #endif /* CONFIG_SMP */
12082 #endif /* CONFIG_DEBUG_DCFLUSH */
12083 }
12084diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12085index 85258ca..df97c79 100644
12086--- a/arch/tile/Kconfig
12087+++ b/arch/tile/Kconfig
12088@@ -190,6 +190,7 @@ source "kernel/Kconfig.hz"
12089
12090 config KEXEC
12091 bool "kexec system call"
12092+ depends on !GRKERNSEC_KMEM
12093 ---help---
12094 kexec is a system call that implements the ability to shutdown your
12095 current kernel, and to start another kernel. It is like a reboot
12096diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12097index ad220ee..2f537b3 100644
12098--- a/arch/tile/include/asm/atomic_64.h
12099+++ b/arch/tile/include/asm/atomic_64.h
12100@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12101
12102 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12103
12104+#define atomic64_read_unchecked(v) atomic64_read(v)
12105+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12106+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12107+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12108+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12109+#define atomic64_inc_unchecked(v) atomic64_inc(v)
12110+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12111+#define atomic64_dec_unchecked(v) atomic64_dec(v)
12112+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12113+
12114 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
12115 #define smp_mb__before_atomic_dec() smp_mb()
12116 #define smp_mb__after_atomic_dec() smp_mb()
12117diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12118index 6160761..00cac88 100644
12119--- a/arch/tile/include/asm/cache.h
12120+++ b/arch/tile/include/asm/cache.h
12121@@ -15,11 +15,12 @@
12122 #ifndef _ASM_TILE_CACHE_H
12123 #define _ASM_TILE_CACHE_H
12124
12125+#include <linux/const.h>
12126 #include <arch/chip.h>
12127
12128 /* bytes per L1 data cache line */
12129 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12130-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12131+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12132
12133 /* bytes per L2 cache line */
12134 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12135diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12136index b6cde32..c0cb736 100644
12137--- a/arch/tile/include/asm/uaccess.h
12138+++ b/arch/tile/include/asm/uaccess.h
12139@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12140 const void __user *from,
12141 unsigned long n)
12142 {
12143- int sz = __compiletime_object_size(to);
12144+ size_t sz = __compiletime_object_size(to);
12145
12146- if (likely(sz == -1 || sz >= n))
12147+ if (likely(sz == (size_t)-1 || sz >= n))
12148 n = _copy_from_user(to, from, n);
12149 else
12150 copy_from_user_overflow();
12151diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12152index e514899..f8743c4 100644
12153--- a/arch/tile/mm/hugetlbpage.c
12154+++ b/arch/tile/mm/hugetlbpage.c
12155@@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12156 info.high_limit = TASK_SIZE;
12157 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12158 info.align_offset = 0;
12159+ info.threadstack_offset = 0;
12160 return vm_unmapped_area(&info);
12161 }
12162
12163@@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12164 info.high_limit = current->mm->mmap_base;
12165 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12166 info.align_offset = 0;
12167+ info.threadstack_offset = 0;
12168 addr = vm_unmapped_area(&info);
12169
12170 /*
12171diff --git a/arch/um/Makefile b/arch/um/Makefile
12172index 36e658a..71a5c5a 100644
12173--- a/arch/um/Makefile
12174+++ b/arch/um/Makefile
12175@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12176 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12177 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12178
12179+ifdef CONSTIFY_PLUGIN
12180+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12181+endif
12182+
12183 #This will adjust *FLAGS accordingly to the platform.
12184 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12185
12186diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12187index 19e1bdd..3665b77 100644
12188--- a/arch/um/include/asm/cache.h
12189+++ b/arch/um/include/asm/cache.h
12190@@ -1,6 +1,7 @@
12191 #ifndef __UM_CACHE_H
12192 #define __UM_CACHE_H
12193
12194+#include <linux/const.h>
12195
12196 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12197 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12198@@ -12,6 +13,6 @@
12199 # define L1_CACHE_SHIFT 5
12200 #endif
12201
12202-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12203+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12204
12205 #endif
12206diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12207index 2e0a6b1..a64d0f5 100644
12208--- a/arch/um/include/asm/kmap_types.h
12209+++ b/arch/um/include/asm/kmap_types.h
12210@@ -8,6 +8,6 @@
12211
12212 /* No more #include "asm/arch/kmap_types.h" ! */
12213
12214-#define KM_TYPE_NR 14
12215+#define KM_TYPE_NR 15
12216
12217 #endif
12218diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12219index 5ff53d9..5850cdf 100644
12220--- a/arch/um/include/asm/page.h
12221+++ b/arch/um/include/asm/page.h
12222@@ -14,6 +14,9 @@
12223 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12224 #define PAGE_MASK (~(PAGE_SIZE-1))
12225
12226+#define ktla_ktva(addr) (addr)
12227+#define ktva_ktla(addr) (addr)
12228+
12229 #ifndef __ASSEMBLY__
12230
12231 struct page;
12232diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12233index 0032f92..cd151e0 100644
12234--- a/arch/um/include/asm/pgtable-3level.h
12235+++ b/arch/um/include/asm/pgtable-3level.h
12236@@ -58,6 +58,7 @@
12237 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12238 #define pud_populate(mm, pud, pmd) \
12239 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12240+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12241
12242 #ifdef CONFIG_64BIT
12243 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12244diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12245index f17bca8..48adb87 100644
12246--- a/arch/um/kernel/process.c
12247+++ b/arch/um/kernel/process.c
12248@@ -356,22 +356,6 @@ int singlestepping(void * t)
12249 return 2;
12250 }
12251
12252-/*
12253- * Only x86 and x86_64 have an arch_align_stack().
12254- * All other arches have "#define arch_align_stack(x) (x)"
12255- * in their asm/exec.h
12256- * As this is included in UML from asm-um/system-generic.h,
12257- * we can use it to behave as the subarch does.
12258- */
12259-#ifndef arch_align_stack
12260-unsigned long arch_align_stack(unsigned long sp)
12261-{
12262- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12263- sp -= get_random_int() % 8192;
12264- return sp & ~0xf;
12265-}
12266-#endif
12267-
12268 unsigned long get_wchan(struct task_struct *p)
12269 {
12270 unsigned long stack_page, sp, ip;
12271diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12272index ad8f795..2c7eec6 100644
12273--- a/arch/unicore32/include/asm/cache.h
12274+++ b/arch/unicore32/include/asm/cache.h
12275@@ -12,8 +12,10 @@
12276 #ifndef __UNICORE_CACHE_H__
12277 #define __UNICORE_CACHE_H__
12278
12279-#define L1_CACHE_SHIFT (5)
12280-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12281+#include <linux/const.h>
12282+
12283+#define L1_CACHE_SHIFT 5
12284+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12285
12286 /*
12287 * Memory returned by kmalloc() may be used for DMA, so we must make
12288diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12289index 6b8b429..7b21fe4 100644
12290--- a/arch/x86/Kconfig
12291+++ b/arch/x86/Kconfig
12292@@ -127,7 +127,7 @@ config X86
12293 select RTC_LIB
12294 select HAVE_DEBUG_STACKOVERFLOW
12295 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12296- select HAVE_CC_STACKPROTECTOR
12297+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12298 select GENERIC_CPU_AUTOPROBE
12299 select HAVE_ARCH_AUDITSYSCALL
12300
12301@@ -251,7 +251,7 @@ config X86_HT
12302
12303 config X86_32_LAZY_GS
12304 def_bool y
12305- depends on X86_32 && !CC_STACKPROTECTOR
12306+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12307
12308 config ARCH_HWEIGHT_CFLAGS
12309 string
12310@@ -545,6 +545,7 @@ config SCHED_OMIT_FRAME_POINTER
12311
12312 menuconfig HYPERVISOR_GUEST
12313 bool "Linux guest support"
12314+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12315 ---help---
12316 Say Y here to enable options for running Linux under various hyper-
12317 visors. This option enables basic hypervisor detection and platform
12318@@ -1054,6 +1055,7 @@ choice
12319
12320 config NOHIGHMEM
12321 bool "off"
12322+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12323 ---help---
12324 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12325 However, the address space of 32-bit x86 processors is only 4
12326@@ -1090,6 +1092,7 @@ config NOHIGHMEM
12327
12328 config HIGHMEM4G
12329 bool "4GB"
12330+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12331 ---help---
12332 Select this if you have a 32-bit processor and between 1 and 4
12333 gigabytes of physical RAM.
12334@@ -1142,7 +1145,7 @@ config PAGE_OFFSET
12335 hex
12336 default 0xB0000000 if VMSPLIT_3G_OPT
12337 default 0x80000000 if VMSPLIT_2G
12338- default 0x78000000 if VMSPLIT_2G_OPT
12339+ default 0x70000000 if VMSPLIT_2G_OPT
12340 default 0x40000000 if VMSPLIT_1G
12341 default 0xC0000000
12342 depends on X86_32
12343@@ -1555,6 +1558,7 @@ source kernel/Kconfig.hz
12344
12345 config KEXEC
12346 bool "kexec system call"
12347+ depends on !GRKERNSEC_KMEM
12348 ---help---
12349 kexec is a system call that implements the ability to shutdown your
12350 current kernel, and to start another kernel. It is like a reboot
12351@@ -1706,7 +1710,9 @@ config X86_NEED_RELOCS
12352
12353 config PHYSICAL_ALIGN
12354 hex "Alignment value to which kernel should be aligned"
12355- default "0x200000"
12356+ default "0x1000000"
12357+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12358+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12359 range 0x2000 0x1000000 if X86_32
12360 range 0x200000 0x1000000 if X86_64
12361 ---help---
12362@@ -1789,6 +1795,7 @@ config COMPAT_VDSO
12363 def_bool n
12364 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12365 depends on X86_32 || IA32_EMULATION
12366+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12367 ---help---
12368 Certain buggy versions of glibc will crash if they are
12369 presented with a 32-bit vDSO that is not mapped at the address
12370diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12371index 6983314..54ad7e8 100644
12372--- a/arch/x86/Kconfig.cpu
12373+++ b/arch/x86/Kconfig.cpu
12374@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12375
12376 config X86_F00F_BUG
12377 def_bool y
12378- depends on M586MMX || M586TSC || M586 || M486
12379+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12380
12381 config X86_INVD_BUG
12382 def_bool y
12383@@ -327,7 +327,7 @@ config X86_INVD_BUG
12384
12385 config X86_ALIGNMENT_16
12386 def_bool y
12387- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12388+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12389
12390 config X86_INTEL_USERCOPY
12391 def_bool y
12392@@ -369,7 +369,7 @@ config X86_CMPXCHG64
12393 # generates cmov.
12394 config X86_CMOV
12395 def_bool y
12396- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12397+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12398
12399 config X86_MINIMUM_CPU_FAMILY
12400 int
12401diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12402index 61bd2ad..50b625d 100644
12403--- a/arch/x86/Kconfig.debug
12404+++ b/arch/x86/Kconfig.debug
12405@@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12406 config DEBUG_RODATA
12407 bool "Write protect kernel read-only data structures"
12408 default y
12409- depends on DEBUG_KERNEL
12410+ depends on DEBUG_KERNEL && BROKEN
12411 ---help---
12412 Mark the kernel read-only data as write-protected in the pagetables,
12413 in order to catch accidental (and incorrect) writes to such const
12414@@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12415
12416 config DEBUG_SET_MODULE_RONX
12417 bool "Set loadable kernel module data as NX and text as RO"
12418- depends on MODULES
12419+ depends on MODULES && BROKEN
12420 ---help---
12421 This option helps catch unintended modifications to loadable
12422 kernel module's text and read-only data. It also prevents execution
12423diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12424index 33f71b0..c2cefa2 100644
12425--- a/arch/x86/Makefile
12426+++ b/arch/x86/Makefile
12427@@ -71,9 +71,6 @@ ifeq ($(CONFIG_X86_32),y)
12428 # CPU-specific tuning. Anything which can be shared with UML should go here.
12429 include $(srctree)/arch/x86/Makefile_32.cpu
12430 KBUILD_CFLAGS += $(cflags-y)
12431-
12432- # temporary until string.h is fixed
12433- KBUILD_CFLAGS += -ffreestanding
12434 else
12435 BITS := 64
12436 UTS_MACHINE := x86_64
12437@@ -114,6 +111,9 @@ else
12438 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12439 endif
12440
12441+# temporary until string.h is fixed
12442+KBUILD_CFLAGS += -ffreestanding
12443+
12444 # Make sure compiler does not have buggy stack-protector support.
12445 ifdef CONFIG_CC_STACKPROTECTOR
12446 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12447@@ -271,3 +271,12 @@ define archhelp
12448 echo ' FDINITRD=file initrd for the booted kernel'
12449 echo ' kvmconfig - Enable additional options for guest kernel support'
12450 endef
12451+
12452+define OLD_LD
12453+
12454+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12455+*** Please upgrade your binutils to 2.18 or newer
12456+endef
12457+
12458+archprepare:
12459+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12460diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12461index dbe8dd2..2f0a98f 100644
12462--- a/arch/x86/boot/Makefile
12463+++ b/arch/x86/boot/Makefile
12464@@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12465 # ---------------------------------------------------------------------------
12466
12467 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12468+ifdef CONSTIFY_PLUGIN
12469+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12470+endif
12471 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12472 GCOV_PROFILE := n
12473
12474diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12475index 878e4b9..20537ab 100644
12476--- a/arch/x86/boot/bitops.h
12477+++ b/arch/x86/boot/bitops.h
12478@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12479 u8 v;
12480 const u32 *p = (const u32 *)addr;
12481
12482- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12483+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12484 return v;
12485 }
12486
12487@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12488
12489 static inline void set_bit(int nr, void *addr)
12490 {
12491- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12492+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12493 }
12494
12495 #endif /* BOOT_BITOPS_H */
12496diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12497index bd49ec6..94c7f58 100644
12498--- a/arch/x86/boot/boot.h
12499+++ b/arch/x86/boot/boot.h
12500@@ -84,7 +84,7 @@ static inline void io_delay(void)
12501 static inline u16 ds(void)
12502 {
12503 u16 seg;
12504- asm("movw %%ds,%0" : "=rm" (seg));
12505+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12506 return seg;
12507 }
12508
12509diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12510index 0fcd913..3bb5c42 100644
12511--- a/arch/x86/boot/compressed/Makefile
12512+++ b/arch/x86/boot/compressed/Makefile
12513@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12514 KBUILD_CFLAGS += -mno-mmx -mno-sse
12515 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12516 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12517+ifdef CONSTIFY_PLUGIN
12518+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12519+endif
12520
12521 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12522 GCOV_PROFILE := n
12523diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12524index a53440e..c3dbf1e 100644
12525--- a/arch/x86/boot/compressed/efi_stub_32.S
12526+++ b/arch/x86/boot/compressed/efi_stub_32.S
12527@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12528 * parameter 2, ..., param n. To make things easy, we save the return
12529 * address of efi_call_phys in a global variable.
12530 */
12531- popl %ecx
12532- movl %ecx, saved_return_addr(%edx)
12533- /* get the function pointer into ECX*/
12534- popl %ecx
12535- movl %ecx, efi_rt_function_ptr(%edx)
12536+ popl saved_return_addr(%edx)
12537+ popl efi_rt_function_ptr(%edx)
12538
12539 /*
12540 * 3. Call the physical function.
12541 */
12542- call *%ecx
12543+ call *efi_rt_function_ptr(%edx)
12544
12545 /*
12546 * 4. Balance the stack. And because EAX contain the return value,
12547@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12548 1: popl %edx
12549 subl $1b, %edx
12550
12551- movl efi_rt_function_ptr(%edx), %ecx
12552- pushl %ecx
12553+ pushl efi_rt_function_ptr(%edx)
12554
12555 /*
12556 * 10. Push the saved return address onto the stack and return.
12557 */
12558- movl saved_return_addr(%edx), %ecx
12559- pushl %ecx
12560- ret
12561+ jmpl *saved_return_addr(%edx)
12562 ENDPROC(efi_call_phys)
12563 .previous
12564
12565diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12566index cbed140..5f2ca57 100644
12567--- a/arch/x86/boot/compressed/head_32.S
12568+++ b/arch/x86/boot/compressed/head_32.S
12569@@ -140,10 +140,10 @@ preferred_addr:
12570 addl %eax, %ebx
12571 notl %eax
12572 andl %eax, %ebx
12573- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12574+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12575 jge 1f
12576 #endif
12577- movl $LOAD_PHYSICAL_ADDR, %ebx
12578+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12579 1:
12580
12581 /* Target address to relocate to for decompression */
12582diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12583index 0d558ee..58f257e 100644
12584--- a/arch/x86/boot/compressed/head_64.S
12585+++ b/arch/x86/boot/compressed/head_64.S
12586@@ -94,10 +94,10 @@ ENTRY(startup_32)
12587 addl %eax, %ebx
12588 notl %eax
12589 andl %eax, %ebx
12590- cmpl $LOAD_PHYSICAL_ADDR, %ebx
12591+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12592 jge 1f
12593 #endif
12594- movl $LOAD_PHYSICAL_ADDR, %ebx
12595+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12596 1:
12597
12598 /* Target address to relocate to for decompression */
12599@@ -322,10 +322,10 @@ preferred_addr:
12600 addq %rax, %rbp
12601 notq %rax
12602 andq %rax, %rbp
12603- cmpq $LOAD_PHYSICAL_ADDR, %rbp
12604+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12605 jge 1f
12606 #endif
12607- movq $LOAD_PHYSICAL_ADDR, %rbp
12608+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12609 1:
12610
12611 /* Target address to relocate to for decompression */
12612@@ -431,8 +431,8 @@ gdt:
12613 .long gdt
12614 .word 0
12615 .quad 0x0000000000000000 /* NULL descriptor */
12616- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12617- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12618+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12619+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12620 .quad 0x0080890000000000 /* TS descriptor */
12621 .quad 0x0000000000000000 /* TS continued */
12622 gdt_end:
12623diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12624index 57ab74d..7c52182 100644
12625--- a/arch/x86/boot/compressed/misc.c
12626+++ b/arch/x86/boot/compressed/misc.c
12627@@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12628 * Calculate the delta between where vmlinux was linked to load
12629 * and where it was actually loaded.
12630 */
12631- delta = min_addr - LOAD_PHYSICAL_ADDR;
12632+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12633 if (!delta) {
12634 debug_putstr("No relocation needed... ");
12635 return;
12636@@ -312,7 +312,7 @@ static void parse_elf(void *output)
12637 Elf32_Ehdr ehdr;
12638 Elf32_Phdr *phdrs, *phdr;
12639 #endif
12640- void *dest;
12641+ void *dest, *prev;
12642 int i;
12643
12644 memcpy(&ehdr, output, sizeof(ehdr));
12645@@ -339,13 +339,16 @@ static void parse_elf(void *output)
12646 case PT_LOAD:
12647 #ifdef CONFIG_RELOCATABLE
12648 dest = output;
12649- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12650+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12651 #else
12652 dest = (void *)(phdr->p_paddr);
12653 #endif
12654 memcpy(dest,
12655 output + phdr->p_offset,
12656 phdr->p_filesz);
12657+ if (i)
12658+ memset(prev, 0xff, dest - prev);
12659+ prev = dest + phdr->p_filesz;
12660 break;
12661 default: /* Ignore other PT_* */ break;
12662 }
12663@@ -395,7 +398,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
12664 error("Destination address too large");
12665 #endif
12666 #ifndef CONFIG_RELOCATABLE
12667- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12668+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12669 error("Wrong destination address");
12670 #endif
12671
12672diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12673index 1fd7d57..0f7d096 100644
12674--- a/arch/x86/boot/cpucheck.c
12675+++ b/arch/x86/boot/cpucheck.c
12676@@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12677 u32 ecx = MSR_K7_HWCR;
12678 u32 eax, edx;
12679
12680- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12681+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12682 eax &= ~(1 << 15);
12683- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12684+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12685
12686 get_cpuflags(); /* Make sure it really did something */
12687 err = check_cpuflags();
12688@@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12689 u32 ecx = MSR_VIA_FCR;
12690 u32 eax, edx;
12691
12692- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12693+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12694 eax |= (1<<1)|(1<<7);
12695- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12696+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12697
12698 set_bit(X86_FEATURE_CX8, cpu.flags);
12699 err = check_cpuflags();
12700@@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12701 u32 eax, edx;
12702 u32 level = 1;
12703
12704- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12705- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12706- asm("cpuid"
12707+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12708+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12709+ asm volatile("cpuid"
12710 : "+a" (level), "=d" (cpu.flags[0])
12711 : : "ecx", "ebx");
12712- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12713+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12714
12715 err = check_cpuflags();
12716 } else if (err == 0x01 &&
12717diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12718index 84c2234..3ef6360 100644
12719--- a/arch/x86/boot/header.S
12720+++ b/arch/x86/boot/header.S
12721@@ -420,10 +420,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12722 # single linked list of
12723 # struct setup_data
12724
12725-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12726+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12727
12728 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12729+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12730+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12731+#else
12732 #define VO_INIT_SIZE (VO__end - VO__text)
12733+#endif
12734 #if ZO_INIT_SIZE > VO_INIT_SIZE
12735 #define INIT_SIZE ZO_INIT_SIZE
12736 #else
12737diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12738index db75d07..8e6d0af 100644
12739--- a/arch/x86/boot/memory.c
12740+++ b/arch/x86/boot/memory.c
12741@@ -19,7 +19,7 @@
12742
12743 static int detect_memory_e820(void)
12744 {
12745- int count = 0;
12746+ unsigned int count = 0;
12747 struct biosregs ireg, oreg;
12748 struct e820entry *desc = boot_params.e820_map;
12749 static struct e820entry buf; /* static so it is zeroed */
12750diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12751index ba3e100..6501b8f 100644
12752--- a/arch/x86/boot/video-vesa.c
12753+++ b/arch/x86/boot/video-vesa.c
12754@@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
12755
12756 boot_params.screen_info.vesapm_seg = oreg.es;
12757 boot_params.screen_info.vesapm_off = oreg.di;
12758+ boot_params.screen_info.vesapm_size = oreg.cx;
12759 }
12760
12761 /*
12762diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12763index 43eda28..5ab5fdb 100644
12764--- a/arch/x86/boot/video.c
12765+++ b/arch/x86/boot/video.c
12766@@ -96,7 +96,7 @@ static void store_mode_params(void)
12767 static unsigned int get_entry(void)
12768 {
12769 char entry_buf[4];
12770- int i, len = 0;
12771+ unsigned int i, len = 0;
12772 int key;
12773 unsigned int v;
12774
12775diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12776index 9105655..41779c1 100644
12777--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12778+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12779@@ -8,6 +8,8 @@
12780 * including this sentence is retained in full.
12781 */
12782
12783+#include <asm/alternative-asm.h>
12784+
12785 .extern crypto_ft_tab
12786 .extern crypto_it_tab
12787 .extern crypto_fl_tab
12788@@ -70,6 +72,8 @@
12789 je B192; \
12790 leaq 32(r9),r9;
12791
12792+#define ret pax_force_retaddr; ret
12793+
12794 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12795 movq r1,r2; \
12796 movq r3,r4; \
12797diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12798index 477e9d7..c92c7d8 100644
12799--- a/arch/x86/crypto/aesni-intel_asm.S
12800+++ b/arch/x86/crypto/aesni-intel_asm.S
12801@@ -31,6 +31,7 @@
12802
12803 #include <linux/linkage.h>
12804 #include <asm/inst.h>
12805+#include <asm/alternative-asm.h>
12806
12807 #ifdef __x86_64__
12808 .data
12809@@ -205,7 +206,7 @@ enc: .octa 0x2
12810 * num_initial_blocks = b mod 4
12811 * encrypt the initial num_initial_blocks blocks and apply ghash on
12812 * the ciphertext
12813-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12814+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12815 * are clobbered
12816 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12817 */
12818@@ -214,8 +215,8 @@ enc: .octa 0x2
12819 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12820 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12821 mov arg7, %r10 # %r10 = AAD
12822- mov arg8, %r12 # %r12 = aadLen
12823- mov %r12, %r11
12824+ mov arg8, %r15 # %r15 = aadLen
12825+ mov %r15, %r11
12826 pxor %xmm\i, %xmm\i
12827 _get_AAD_loop\num_initial_blocks\operation:
12828 movd (%r10), \TMP1
12829@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12830 psrldq $4, %xmm\i
12831 pxor \TMP1, %xmm\i
12832 add $4, %r10
12833- sub $4, %r12
12834+ sub $4, %r15
12835 jne _get_AAD_loop\num_initial_blocks\operation
12836 cmp $16, %r11
12837 je _get_AAD_loop2_done\num_initial_blocks\operation
12838- mov $16, %r12
12839+ mov $16, %r15
12840 _get_AAD_loop2\num_initial_blocks\operation:
12841 psrldq $4, %xmm\i
12842- sub $4, %r12
12843- cmp %r11, %r12
12844+ sub $4, %r15
12845+ cmp %r11, %r15
12846 jne _get_AAD_loop2\num_initial_blocks\operation
12847 _get_AAD_loop2_done\num_initial_blocks\operation:
12848 movdqa SHUF_MASK(%rip), %xmm14
12849@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12850 * num_initial_blocks = b mod 4
12851 * encrypt the initial num_initial_blocks blocks and apply ghash on
12852 * the ciphertext
12853-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12854+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12855 * are clobbered
12856 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12857 */
12858@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12859 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12860 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12861 mov arg7, %r10 # %r10 = AAD
12862- mov arg8, %r12 # %r12 = aadLen
12863- mov %r12, %r11
12864+ mov arg8, %r15 # %r15 = aadLen
12865+ mov %r15, %r11
12866 pxor %xmm\i, %xmm\i
12867 _get_AAD_loop\num_initial_blocks\operation:
12868 movd (%r10), \TMP1
12869@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12870 psrldq $4, %xmm\i
12871 pxor \TMP1, %xmm\i
12872 add $4, %r10
12873- sub $4, %r12
12874+ sub $4, %r15
12875 jne _get_AAD_loop\num_initial_blocks\operation
12876 cmp $16, %r11
12877 je _get_AAD_loop2_done\num_initial_blocks\operation
12878- mov $16, %r12
12879+ mov $16, %r15
12880 _get_AAD_loop2\num_initial_blocks\operation:
12881 psrldq $4, %xmm\i
12882- sub $4, %r12
12883- cmp %r11, %r12
12884+ sub $4, %r15
12885+ cmp %r11, %r15
12886 jne _get_AAD_loop2\num_initial_blocks\operation
12887 _get_AAD_loop2_done\num_initial_blocks\operation:
12888 movdqa SHUF_MASK(%rip), %xmm14
12889@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12890 *
12891 *****************************************************************************/
12892 ENTRY(aesni_gcm_dec)
12893- push %r12
12894+ push %r15
12895 push %r13
12896 push %r14
12897 mov %rsp, %r14
12898@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12899 */
12900 sub $VARIABLE_OFFSET, %rsp
12901 and $~63, %rsp # align rsp to 64 bytes
12902- mov %arg6, %r12
12903- movdqu (%r12), %xmm13 # %xmm13 = HashKey
12904+ mov %arg6, %r15
12905+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
12906 movdqa SHUF_MASK(%rip), %xmm2
12907 PSHUFB_XMM %xmm2, %xmm13
12908
12909@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12910 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12911 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12912 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12913- mov %r13, %r12
12914- and $(3<<4), %r12
12915+ mov %r13, %r15
12916+ and $(3<<4), %r15
12917 jz _initial_num_blocks_is_0_decrypt
12918- cmp $(2<<4), %r12
12919+ cmp $(2<<4), %r15
12920 jb _initial_num_blocks_is_1_decrypt
12921 je _initial_num_blocks_is_2_decrypt
12922 _initial_num_blocks_is_3_decrypt:
12923@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12924 sub $16, %r11
12925 add %r13, %r11
12926 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12927- lea SHIFT_MASK+16(%rip), %r12
12928- sub %r13, %r12
12929+ lea SHIFT_MASK+16(%rip), %r15
12930+ sub %r13, %r15
12931 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12932 # (%r13 is the number of bytes in plaintext mod 16)
12933- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12934+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12935 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12936
12937 movdqa %xmm1, %xmm2
12938 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12939- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12940+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12941 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12942 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12943 pand %xmm1, %xmm2
12944@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12945 sub $1, %r13
12946 jne _less_than_8_bytes_left_decrypt
12947 _multiple_of_16_bytes_decrypt:
12948- mov arg8, %r12 # %r13 = aadLen (number of bytes)
12949- shl $3, %r12 # convert into number of bits
12950- movd %r12d, %xmm15 # len(A) in %xmm15
12951+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
12952+ shl $3, %r15 # convert into number of bits
12953+ movd %r15d, %xmm15 # len(A) in %xmm15
12954 shl $3, %arg4 # len(C) in bits (*128)
12955 MOVQ_R64_XMM %arg4, %xmm1
12956 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12957@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12958 mov %r14, %rsp
12959 pop %r14
12960 pop %r13
12961- pop %r12
12962+ pop %r15
12963+ pax_force_retaddr
12964 ret
12965 ENDPROC(aesni_gcm_dec)
12966
12967@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12968 * poly = x^128 + x^127 + x^126 + x^121 + 1
12969 ***************************************************************************/
12970 ENTRY(aesni_gcm_enc)
12971- push %r12
12972+ push %r15
12973 push %r13
12974 push %r14
12975 mov %rsp, %r14
12976@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12977 #
12978 sub $VARIABLE_OFFSET, %rsp
12979 and $~63, %rsp
12980- mov %arg6, %r12
12981- movdqu (%r12), %xmm13
12982+ mov %arg6, %r15
12983+ movdqu (%r15), %xmm13
12984 movdqa SHUF_MASK(%rip), %xmm2
12985 PSHUFB_XMM %xmm2, %xmm13
12986
12987@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12988 movdqa %xmm13, HashKey(%rsp)
12989 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12990 and $-16, %r13
12991- mov %r13, %r12
12992+ mov %r13, %r15
12993
12994 # Encrypt first few blocks
12995
12996- and $(3<<4), %r12
12997+ and $(3<<4), %r15
12998 jz _initial_num_blocks_is_0_encrypt
12999- cmp $(2<<4), %r12
13000+ cmp $(2<<4), %r15
13001 jb _initial_num_blocks_is_1_encrypt
13002 je _initial_num_blocks_is_2_encrypt
13003 _initial_num_blocks_is_3_encrypt:
13004@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13005 sub $16, %r11
13006 add %r13, %r11
13007 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13008- lea SHIFT_MASK+16(%rip), %r12
13009- sub %r13, %r12
13010+ lea SHIFT_MASK+16(%rip), %r15
13011+ sub %r13, %r15
13012 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13013 # (%r13 is the number of bytes in plaintext mod 16)
13014- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13015+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13016 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13017 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13018- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13019+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13020 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13021 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13022 movdqa SHUF_MASK(%rip), %xmm10
13023@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13024 sub $1, %r13
13025 jne _less_than_8_bytes_left_encrypt
13026 _multiple_of_16_bytes_encrypt:
13027- mov arg8, %r12 # %r12 = addLen (number of bytes)
13028- shl $3, %r12
13029- movd %r12d, %xmm15 # len(A) in %xmm15
13030+ mov arg8, %r15 # %r15 = addLen (number of bytes)
13031+ shl $3, %r15
13032+ movd %r15d, %xmm15 # len(A) in %xmm15
13033 shl $3, %arg4 # len(C) in bits (*128)
13034 MOVQ_R64_XMM %arg4, %xmm1
13035 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13036@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13037 mov %r14, %rsp
13038 pop %r14
13039 pop %r13
13040- pop %r12
13041+ pop %r15
13042+ pax_force_retaddr
13043 ret
13044 ENDPROC(aesni_gcm_enc)
13045
13046@@ -1722,6 +1725,7 @@ _key_expansion_256a:
13047 pxor %xmm1, %xmm0
13048 movaps %xmm0, (TKEYP)
13049 add $0x10, TKEYP
13050+ pax_force_retaddr
13051 ret
13052 ENDPROC(_key_expansion_128)
13053 ENDPROC(_key_expansion_256a)
13054@@ -1748,6 +1752,7 @@ _key_expansion_192a:
13055 shufps $0b01001110, %xmm2, %xmm1
13056 movaps %xmm1, 0x10(TKEYP)
13057 add $0x20, TKEYP
13058+ pax_force_retaddr
13059 ret
13060 ENDPROC(_key_expansion_192a)
13061
13062@@ -1768,6 +1773,7 @@ _key_expansion_192b:
13063
13064 movaps %xmm0, (TKEYP)
13065 add $0x10, TKEYP
13066+ pax_force_retaddr
13067 ret
13068 ENDPROC(_key_expansion_192b)
13069
13070@@ -1781,6 +1787,7 @@ _key_expansion_256b:
13071 pxor %xmm1, %xmm2
13072 movaps %xmm2, (TKEYP)
13073 add $0x10, TKEYP
13074+ pax_force_retaddr
13075 ret
13076 ENDPROC(_key_expansion_256b)
13077
13078@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13079 #ifndef __x86_64__
13080 popl KEYP
13081 #endif
13082+ pax_force_retaddr
13083 ret
13084 ENDPROC(aesni_set_key)
13085
13086@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13087 popl KLEN
13088 popl KEYP
13089 #endif
13090+ pax_force_retaddr
13091 ret
13092 ENDPROC(aesni_enc)
13093
13094@@ -1974,6 +1983,7 @@ _aesni_enc1:
13095 AESENC KEY STATE
13096 movaps 0x70(TKEYP), KEY
13097 AESENCLAST KEY STATE
13098+ pax_force_retaddr
13099 ret
13100 ENDPROC(_aesni_enc1)
13101
13102@@ -2083,6 +2093,7 @@ _aesni_enc4:
13103 AESENCLAST KEY STATE2
13104 AESENCLAST KEY STATE3
13105 AESENCLAST KEY STATE4
13106+ pax_force_retaddr
13107 ret
13108 ENDPROC(_aesni_enc4)
13109
13110@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13111 popl KLEN
13112 popl KEYP
13113 #endif
13114+ pax_force_retaddr
13115 ret
13116 ENDPROC(aesni_dec)
13117
13118@@ -2164,6 +2176,7 @@ _aesni_dec1:
13119 AESDEC KEY STATE
13120 movaps 0x70(TKEYP), KEY
13121 AESDECLAST KEY STATE
13122+ pax_force_retaddr
13123 ret
13124 ENDPROC(_aesni_dec1)
13125
13126@@ -2273,6 +2286,7 @@ _aesni_dec4:
13127 AESDECLAST KEY STATE2
13128 AESDECLAST KEY STATE3
13129 AESDECLAST KEY STATE4
13130+ pax_force_retaddr
13131 ret
13132 ENDPROC(_aesni_dec4)
13133
13134@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13135 popl KEYP
13136 popl LEN
13137 #endif
13138+ pax_force_retaddr
13139 ret
13140 ENDPROC(aesni_ecb_enc)
13141
13142@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13143 popl KEYP
13144 popl LEN
13145 #endif
13146+ pax_force_retaddr
13147 ret
13148 ENDPROC(aesni_ecb_dec)
13149
13150@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13151 popl LEN
13152 popl IVP
13153 #endif
13154+ pax_force_retaddr
13155 ret
13156 ENDPROC(aesni_cbc_enc)
13157
13158@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13159 popl LEN
13160 popl IVP
13161 #endif
13162+ pax_force_retaddr
13163 ret
13164 ENDPROC(aesni_cbc_dec)
13165
13166@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13167 mov $1, TCTR_LOW
13168 MOVQ_R64_XMM TCTR_LOW INC
13169 MOVQ_R64_XMM CTR TCTR_LOW
13170+ pax_force_retaddr
13171 ret
13172 ENDPROC(_aesni_inc_init)
13173
13174@@ -2579,6 +2598,7 @@ _aesni_inc:
13175 .Linc_low:
13176 movaps CTR, IV
13177 PSHUFB_XMM BSWAP_MASK IV
13178+ pax_force_retaddr
13179 ret
13180 ENDPROC(_aesni_inc)
13181
13182@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13183 .Lctr_enc_ret:
13184 movups IV, (IVP)
13185 .Lctr_enc_just_ret:
13186+ pax_force_retaddr
13187 ret
13188 ENDPROC(aesni_ctr_enc)
13189
13190@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13191 pxor INC, STATE4
13192 movdqu STATE4, 0x70(OUTP)
13193
13194+ pax_force_retaddr
13195 ret
13196 ENDPROC(aesni_xts_crypt8)
13197
13198diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13199index 246c670..466e2d6 100644
13200--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13201+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13202@@ -21,6 +21,7 @@
13203 */
13204
13205 #include <linux/linkage.h>
13206+#include <asm/alternative-asm.h>
13207
13208 .file "blowfish-x86_64-asm.S"
13209 .text
13210@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13211 jnz .L__enc_xor;
13212
13213 write_block();
13214+ pax_force_retaddr
13215 ret;
13216 .L__enc_xor:
13217 xor_block();
13218+ pax_force_retaddr
13219 ret;
13220 ENDPROC(__blowfish_enc_blk)
13221
13222@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13223
13224 movq %r11, %rbp;
13225
13226+ pax_force_retaddr
13227 ret;
13228 ENDPROC(blowfish_dec_blk)
13229
13230@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13231
13232 popq %rbx;
13233 popq %rbp;
13234+ pax_force_retaddr
13235 ret;
13236
13237 .L__enc_xor4:
13238@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13239
13240 popq %rbx;
13241 popq %rbp;
13242+ pax_force_retaddr
13243 ret;
13244 ENDPROC(__blowfish_enc_blk_4way)
13245
13246@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13247 popq %rbx;
13248 popq %rbp;
13249
13250+ pax_force_retaddr
13251 ret;
13252 ENDPROC(blowfish_dec_blk_4way)
13253diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13254index ce71f92..1dce7ec 100644
13255--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13256+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13257@@ -16,6 +16,7 @@
13258 */
13259
13260 #include <linux/linkage.h>
13261+#include <asm/alternative-asm.h>
13262
13263 #define CAMELLIA_TABLE_BYTE_LEN 272
13264
13265@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13266 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13267 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13268 %rcx, (%r9));
13269+ pax_force_retaddr
13270 ret;
13271 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13272
13273@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13274 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13275 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13276 %rax, (%r9));
13277+ pax_force_retaddr
13278 ret;
13279 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13280
13281@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13282 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13283 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13284
13285+ pax_force_retaddr
13286 ret;
13287
13288 .align 8
13289@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13290 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13291 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13292
13293+ pax_force_retaddr
13294 ret;
13295
13296 .align 8
13297@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13298 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13299 %xmm8, %rsi);
13300
13301+ pax_force_retaddr
13302 ret;
13303 ENDPROC(camellia_ecb_enc_16way)
13304
13305@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13306 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13307 %xmm8, %rsi);
13308
13309+ pax_force_retaddr
13310 ret;
13311 ENDPROC(camellia_ecb_dec_16way)
13312
13313@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13314 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13315 %xmm8, %rsi);
13316
13317+ pax_force_retaddr
13318 ret;
13319 ENDPROC(camellia_cbc_dec_16way)
13320
13321@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13322 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13323 %xmm8, %rsi);
13324
13325+ pax_force_retaddr
13326 ret;
13327 ENDPROC(camellia_ctr_16way)
13328
13329@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13330 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13331 %xmm8, %rsi);
13332
13333+ pax_force_retaddr
13334 ret;
13335 ENDPROC(camellia_xts_crypt_16way)
13336
13337diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13338index 0e0b886..5a3123c 100644
13339--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13340+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13341@@ -11,6 +11,7 @@
13342 */
13343
13344 #include <linux/linkage.h>
13345+#include <asm/alternative-asm.h>
13346
13347 #define CAMELLIA_TABLE_BYTE_LEN 272
13348
13349@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13350 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13351 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13352 %rcx, (%r9));
13353+ pax_force_retaddr
13354 ret;
13355 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13356
13357@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13358 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13359 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13360 %rax, (%r9));
13361+ pax_force_retaddr
13362 ret;
13363 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13364
13365@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13366 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13367 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13368
13369+ pax_force_retaddr
13370 ret;
13371
13372 .align 8
13373@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13374 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13375 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13376
13377+ pax_force_retaddr
13378 ret;
13379
13380 .align 8
13381@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13382
13383 vzeroupper;
13384
13385+ pax_force_retaddr
13386 ret;
13387 ENDPROC(camellia_ecb_enc_32way)
13388
13389@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13390
13391 vzeroupper;
13392
13393+ pax_force_retaddr
13394 ret;
13395 ENDPROC(camellia_ecb_dec_32way)
13396
13397@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13398
13399 vzeroupper;
13400
13401+ pax_force_retaddr
13402 ret;
13403 ENDPROC(camellia_cbc_dec_32way)
13404
13405@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13406
13407 vzeroupper;
13408
13409+ pax_force_retaddr
13410 ret;
13411 ENDPROC(camellia_ctr_32way)
13412
13413@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13414
13415 vzeroupper;
13416
13417+ pax_force_retaddr
13418 ret;
13419 ENDPROC(camellia_xts_crypt_32way)
13420
13421diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13422index 310319c..db3d7b5 100644
13423--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13424+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13425@@ -21,6 +21,7 @@
13426 */
13427
13428 #include <linux/linkage.h>
13429+#include <asm/alternative-asm.h>
13430
13431 .file "camellia-x86_64-asm_64.S"
13432 .text
13433@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13434 enc_outunpack(mov, RT1);
13435
13436 movq RRBP, %rbp;
13437+ pax_force_retaddr
13438 ret;
13439
13440 .L__enc_xor:
13441 enc_outunpack(xor, RT1);
13442
13443 movq RRBP, %rbp;
13444+ pax_force_retaddr
13445 ret;
13446 ENDPROC(__camellia_enc_blk)
13447
13448@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13449 dec_outunpack();
13450
13451 movq RRBP, %rbp;
13452+ pax_force_retaddr
13453 ret;
13454 ENDPROC(camellia_dec_blk)
13455
13456@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13457
13458 movq RRBP, %rbp;
13459 popq %rbx;
13460+ pax_force_retaddr
13461 ret;
13462
13463 .L__enc2_xor:
13464@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13465
13466 movq RRBP, %rbp;
13467 popq %rbx;
13468+ pax_force_retaddr
13469 ret;
13470 ENDPROC(__camellia_enc_blk_2way)
13471
13472@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13473
13474 movq RRBP, %rbp;
13475 movq RXOR, %rbx;
13476+ pax_force_retaddr
13477 ret;
13478 ENDPROC(camellia_dec_blk_2way)
13479diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13480index c35fd5d..2d8c7db 100644
13481--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13482+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13483@@ -24,6 +24,7 @@
13484 */
13485
13486 #include <linux/linkage.h>
13487+#include <asm/alternative-asm.h>
13488
13489 .file "cast5-avx-x86_64-asm_64.S"
13490
13491@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13492 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13493 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13494
13495+ pax_force_retaddr
13496 ret;
13497 ENDPROC(__cast5_enc_blk16)
13498
13499@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13500 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13501 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13502
13503+ pax_force_retaddr
13504 ret;
13505
13506 .L__skip_dec:
13507@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13508 vmovdqu RR4, (6*4*4)(%r11);
13509 vmovdqu RL4, (7*4*4)(%r11);
13510
13511+ pax_force_retaddr
13512 ret;
13513 ENDPROC(cast5_ecb_enc_16way)
13514
13515@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13516 vmovdqu RR4, (6*4*4)(%r11);
13517 vmovdqu RL4, (7*4*4)(%r11);
13518
13519+ pax_force_retaddr
13520 ret;
13521 ENDPROC(cast5_ecb_dec_16way)
13522
13523@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13524 * %rdx: src
13525 */
13526
13527- pushq %r12;
13528+ pushq %r14;
13529
13530 movq %rsi, %r11;
13531- movq %rdx, %r12;
13532+ movq %rdx, %r14;
13533
13534 vmovdqu (0*16)(%rdx), RL1;
13535 vmovdqu (1*16)(%rdx), RR1;
13536@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13537 call __cast5_dec_blk16;
13538
13539 /* xor with src */
13540- vmovq (%r12), RX;
13541+ vmovq (%r14), RX;
13542 vpshufd $0x4f, RX, RX;
13543 vpxor RX, RR1, RR1;
13544- vpxor 0*16+8(%r12), RL1, RL1;
13545- vpxor 1*16+8(%r12), RR2, RR2;
13546- vpxor 2*16+8(%r12), RL2, RL2;
13547- vpxor 3*16+8(%r12), RR3, RR3;
13548- vpxor 4*16+8(%r12), RL3, RL3;
13549- vpxor 5*16+8(%r12), RR4, RR4;
13550- vpxor 6*16+8(%r12), RL4, RL4;
13551+ vpxor 0*16+8(%r14), RL1, RL1;
13552+ vpxor 1*16+8(%r14), RR2, RR2;
13553+ vpxor 2*16+8(%r14), RL2, RL2;
13554+ vpxor 3*16+8(%r14), RR3, RR3;
13555+ vpxor 4*16+8(%r14), RL3, RL3;
13556+ vpxor 5*16+8(%r14), RR4, RR4;
13557+ vpxor 6*16+8(%r14), RL4, RL4;
13558
13559 vmovdqu RR1, (0*16)(%r11);
13560 vmovdqu RL1, (1*16)(%r11);
13561@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13562 vmovdqu RR4, (6*16)(%r11);
13563 vmovdqu RL4, (7*16)(%r11);
13564
13565- popq %r12;
13566+ popq %r14;
13567
13568+ pax_force_retaddr
13569 ret;
13570 ENDPROC(cast5_cbc_dec_16way)
13571
13572@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13573 * %rcx: iv (big endian, 64bit)
13574 */
13575
13576- pushq %r12;
13577+ pushq %r14;
13578
13579 movq %rsi, %r11;
13580- movq %rdx, %r12;
13581+ movq %rdx, %r14;
13582
13583 vpcmpeqd RTMP, RTMP, RTMP;
13584 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13585@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13586 call __cast5_enc_blk16;
13587
13588 /* dst = src ^ iv */
13589- vpxor (0*16)(%r12), RR1, RR1;
13590- vpxor (1*16)(%r12), RL1, RL1;
13591- vpxor (2*16)(%r12), RR2, RR2;
13592- vpxor (3*16)(%r12), RL2, RL2;
13593- vpxor (4*16)(%r12), RR3, RR3;
13594- vpxor (5*16)(%r12), RL3, RL3;
13595- vpxor (6*16)(%r12), RR4, RR4;
13596- vpxor (7*16)(%r12), RL4, RL4;
13597+ vpxor (0*16)(%r14), RR1, RR1;
13598+ vpxor (1*16)(%r14), RL1, RL1;
13599+ vpxor (2*16)(%r14), RR2, RR2;
13600+ vpxor (3*16)(%r14), RL2, RL2;
13601+ vpxor (4*16)(%r14), RR3, RR3;
13602+ vpxor (5*16)(%r14), RL3, RL3;
13603+ vpxor (6*16)(%r14), RR4, RR4;
13604+ vpxor (7*16)(%r14), RL4, RL4;
13605 vmovdqu RR1, (0*16)(%r11);
13606 vmovdqu RL1, (1*16)(%r11);
13607 vmovdqu RR2, (2*16)(%r11);
13608@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13609 vmovdqu RR4, (6*16)(%r11);
13610 vmovdqu RL4, (7*16)(%r11);
13611
13612- popq %r12;
13613+ popq %r14;
13614
13615+ pax_force_retaddr
13616 ret;
13617 ENDPROC(cast5_ctr_16way)
13618diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13619index e3531f8..e123f35 100644
13620--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13621+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13622@@ -24,6 +24,7 @@
13623 */
13624
13625 #include <linux/linkage.h>
13626+#include <asm/alternative-asm.h>
13627 #include "glue_helper-asm-avx.S"
13628
13629 .file "cast6-avx-x86_64-asm_64.S"
13630@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13631 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13632 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13633
13634+ pax_force_retaddr
13635 ret;
13636 ENDPROC(__cast6_enc_blk8)
13637
13638@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13639 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13640 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13641
13642+ pax_force_retaddr
13643 ret;
13644 ENDPROC(__cast6_dec_blk8)
13645
13646@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13647
13648 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13649
13650+ pax_force_retaddr
13651 ret;
13652 ENDPROC(cast6_ecb_enc_8way)
13653
13654@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13655
13656 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13657
13658+ pax_force_retaddr
13659 ret;
13660 ENDPROC(cast6_ecb_dec_8way)
13661
13662@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13663 * %rdx: src
13664 */
13665
13666- pushq %r12;
13667+ pushq %r14;
13668
13669 movq %rsi, %r11;
13670- movq %rdx, %r12;
13671+ movq %rdx, %r14;
13672
13673 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13674
13675 call __cast6_dec_blk8;
13676
13677- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13678+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13679
13680- popq %r12;
13681+ popq %r14;
13682
13683+ pax_force_retaddr
13684 ret;
13685 ENDPROC(cast6_cbc_dec_8way)
13686
13687@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13688 * %rcx: iv (little endian, 128bit)
13689 */
13690
13691- pushq %r12;
13692+ pushq %r14;
13693
13694 movq %rsi, %r11;
13695- movq %rdx, %r12;
13696+ movq %rdx, %r14;
13697
13698 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13699 RD2, RX, RKR, RKM);
13700
13701 call __cast6_enc_blk8;
13702
13703- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13704+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13705
13706- popq %r12;
13707+ popq %r14;
13708
13709+ pax_force_retaddr
13710 ret;
13711 ENDPROC(cast6_ctr_8way)
13712
13713@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13714 /* dst <= regs xor IVs(in dst) */
13715 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13716
13717+ pax_force_retaddr
13718 ret;
13719 ENDPROC(cast6_xts_enc_8way)
13720
13721@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13722 /* dst <= regs xor IVs(in dst) */
13723 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13724
13725+ pax_force_retaddr
13726 ret;
13727 ENDPROC(cast6_xts_dec_8way)
13728diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13729index dbc4339..de6e120 100644
13730--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13731+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13732@@ -45,6 +45,7 @@
13733
13734 #include <asm/inst.h>
13735 #include <linux/linkage.h>
13736+#include <asm/alternative-asm.h>
13737
13738 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13739
13740@@ -312,6 +313,7 @@ do_return:
13741 popq %rsi
13742 popq %rdi
13743 popq %rbx
13744+ pax_force_retaddr
13745 ret
13746
13747 ################################################################
13748diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13749index 185fad4..ff4cd36 100644
13750--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13751+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13752@@ -18,6 +18,7 @@
13753
13754 #include <linux/linkage.h>
13755 #include <asm/inst.h>
13756+#include <asm/alternative-asm.h>
13757
13758 .data
13759
13760@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13761 psrlq $1, T2
13762 pxor T2, T1
13763 pxor T1, DATA
13764+ pax_force_retaddr
13765 ret
13766 ENDPROC(__clmul_gf128mul_ble)
13767
13768@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13769 call __clmul_gf128mul_ble
13770 PSHUFB_XMM BSWAP DATA
13771 movups DATA, (%rdi)
13772+ pax_force_retaddr
13773 ret
13774 ENDPROC(clmul_ghash_mul)
13775
13776@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13777 PSHUFB_XMM BSWAP DATA
13778 movups DATA, (%rdi)
13779 .Lupdate_just_ret:
13780+ pax_force_retaddr
13781 ret
13782 ENDPROC(clmul_ghash_update)
13783diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13784index 9279e0b..c4b3d2c 100644
13785--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13786+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13787@@ -1,4 +1,5 @@
13788 #include <linux/linkage.h>
13789+#include <asm/alternative-asm.h>
13790
13791 # enter salsa20_encrypt_bytes
13792 ENTRY(salsa20_encrypt_bytes)
13793@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13794 add %r11,%rsp
13795 mov %rdi,%rax
13796 mov %rsi,%rdx
13797+ pax_force_retaddr
13798 ret
13799 # bytesatleast65:
13800 ._bytesatleast65:
13801@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13802 add %r11,%rsp
13803 mov %rdi,%rax
13804 mov %rsi,%rdx
13805+ pax_force_retaddr
13806 ret
13807 ENDPROC(salsa20_keysetup)
13808
13809@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13810 add %r11,%rsp
13811 mov %rdi,%rax
13812 mov %rsi,%rdx
13813+ pax_force_retaddr
13814 ret
13815 ENDPROC(salsa20_ivsetup)
13816diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13817index 2f202f4..d9164d6 100644
13818--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13819+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13820@@ -24,6 +24,7 @@
13821 */
13822
13823 #include <linux/linkage.h>
13824+#include <asm/alternative-asm.h>
13825 #include "glue_helper-asm-avx.S"
13826
13827 .file "serpent-avx-x86_64-asm_64.S"
13828@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13829 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13830 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13831
13832+ pax_force_retaddr
13833 ret;
13834 ENDPROC(__serpent_enc_blk8_avx)
13835
13836@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13837 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13838 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13839
13840+ pax_force_retaddr
13841 ret;
13842 ENDPROC(__serpent_dec_blk8_avx)
13843
13844@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13845
13846 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13847
13848+ pax_force_retaddr
13849 ret;
13850 ENDPROC(serpent_ecb_enc_8way_avx)
13851
13852@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13853
13854 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13855
13856+ pax_force_retaddr
13857 ret;
13858 ENDPROC(serpent_ecb_dec_8way_avx)
13859
13860@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13861
13862 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13863
13864+ pax_force_retaddr
13865 ret;
13866 ENDPROC(serpent_cbc_dec_8way_avx)
13867
13868@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13869
13870 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13871
13872+ pax_force_retaddr
13873 ret;
13874 ENDPROC(serpent_ctr_8way_avx)
13875
13876@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13877 /* dst <= regs xor IVs(in dst) */
13878 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13879
13880+ pax_force_retaddr
13881 ret;
13882 ENDPROC(serpent_xts_enc_8way_avx)
13883
13884@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13885 /* dst <= regs xor IVs(in dst) */
13886 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13887
13888+ pax_force_retaddr
13889 ret;
13890 ENDPROC(serpent_xts_dec_8way_avx)
13891diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13892index b222085..abd483c 100644
13893--- a/arch/x86/crypto/serpent-avx2-asm_64.S
13894+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13895@@ -15,6 +15,7 @@
13896 */
13897
13898 #include <linux/linkage.h>
13899+#include <asm/alternative-asm.h>
13900 #include "glue_helper-asm-avx2.S"
13901
13902 .file "serpent-avx2-asm_64.S"
13903@@ -610,6 +611,7 @@ __serpent_enc_blk16:
13904 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13905 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13906
13907+ pax_force_retaddr
13908 ret;
13909 ENDPROC(__serpent_enc_blk16)
13910
13911@@ -664,6 +666,7 @@ __serpent_dec_blk16:
13912 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13913 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13914
13915+ pax_force_retaddr
13916 ret;
13917 ENDPROC(__serpent_dec_blk16)
13918
13919@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13920
13921 vzeroupper;
13922
13923+ pax_force_retaddr
13924 ret;
13925 ENDPROC(serpent_ecb_enc_16way)
13926
13927@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13928
13929 vzeroupper;
13930
13931+ pax_force_retaddr
13932 ret;
13933 ENDPROC(serpent_ecb_dec_16way)
13934
13935@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13936
13937 vzeroupper;
13938
13939+ pax_force_retaddr
13940 ret;
13941 ENDPROC(serpent_cbc_dec_16way)
13942
13943@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13944
13945 vzeroupper;
13946
13947+ pax_force_retaddr
13948 ret;
13949 ENDPROC(serpent_ctr_16way)
13950
13951@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13952
13953 vzeroupper;
13954
13955+ pax_force_retaddr
13956 ret;
13957 ENDPROC(serpent_xts_enc_16way)
13958
13959@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13960
13961 vzeroupper;
13962
13963+ pax_force_retaddr
13964 ret;
13965 ENDPROC(serpent_xts_dec_16way)
13966diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13967index acc066c..1559cc4 100644
13968--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13969+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13970@@ -25,6 +25,7 @@
13971 */
13972
13973 #include <linux/linkage.h>
13974+#include <asm/alternative-asm.h>
13975
13976 .file "serpent-sse2-x86_64-asm_64.S"
13977 .text
13978@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13979 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13980 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13981
13982+ pax_force_retaddr
13983 ret;
13984
13985 .L__enc_xor8:
13986 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13987 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13988
13989+ pax_force_retaddr
13990 ret;
13991 ENDPROC(__serpent_enc_blk_8way)
13992
13993@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13994 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13995 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13996
13997+ pax_force_retaddr
13998 ret;
13999 ENDPROC(serpent_dec_blk_8way)
14000diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14001index a410950..9dfe7ad 100644
14002--- a/arch/x86/crypto/sha1_ssse3_asm.S
14003+++ b/arch/x86/crypto/sha1_ssse3_asm.S
14004@@ -29,6 +29,7 @@
14005 */
14006
14007 #include <linux/linkage.h>
14008+#include <asm/alternative-asm.h>
14009
14010 #define CTX %rdi // arg1
14011 #define BUF %rsi // arg2
14012@@ -75,9 +76,9 @@
14013
14014 push %rbx
14015 push %rbp
14016- push %r12
14017+ push %r14
14018
14019- mov %rsp, %r12
14020+ mov %rsp, %r14
14021 sub $64, %rsp # allocate workspace
14022 and $~15, %rsp # align stack
14023
14024@@ -99,11 +100,12 @@
14025 xor %rax, %rax
14026 rep stosq
14027
14028- mov %r12, %rsp # deallocate workspace
14029+ mov %r14, %rsp # deallocate workspace
14030
14031- pop %r12
14032+ pop %r14
14033 pop %rbp
14034 pop %rbx
14035+ pax_force_retaddr
14036 ret
14037
14038 ENDPROC(\name)
14039diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14040index 642f156..51a513c 100644
14041--- a/arch/x86/crypto/sha256-avx-asm.S
14042+++ b/arch/x86/crypto/sha256-avx-asm.S
14043@@ -49,6 +49,7 @@
14044
14045 #ifdef CONFIG_AS_AVX
14046 #include <linux/linkage.h>
14047+#include <asm/alternative-asm.h>
14048
14049 ## assume buffers not aligned
14050 #define VMOVDQ vmovdqu
14051@@ -460,6 +461,7 @@ done_hash:
14052 popq %r13
14053 popq %rbp
14054 popq %rbx
14055+ pax_force_retaddr
14056 ret
14057 ENDPROC(sha256_transform_avx)
14058
14059diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14060index 9e86944..3795e6a 100644
14061--- a/arch/x86/crypto/sha256-avx2-asm.S
14062+++ b/arch/x86/crypto/sha256-avx2-asm.S
14063@@ -50,6 +50,7 @@
14064
14065 #ifdef CONFIG_AS_AVX2
14066 #include <linux/linkage.h>
14067+#include <asm/alternative-asm.h>
14068
14069 ## assume buffers not aligned
14070 #define VMOVDQ vmovdqu
14071@@ -720,6 +721,7 @@ done_hash:
14072 popq %r12
14073 popq %rbp
14074 popq %rbx
14075+ pax_force_retaddr
14076 ret
14077 ENDPROC(sha256_transform_rorx)
14078
14079diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14080index f833b74..8c62a9e 100644
14081--- a/arch/x86/crypto/sha256-ssse3-asm.S
14082+++ b/arch/x86/crypto/sha256-ssse3-asm.S
14083@@ -47,6 +47,7 @@
14084 ########################################################################
14085
14086 #include <linux/linkage.h>
14087+#include <asm/alternative-asm.h>
14088
14089 ## assume buffers not aligned
14090 #define MOVDQ movdqu
14091@@ -471,6 +472,7 @@ done_hash:
14092 popq %rbp
14093 popq %rbx
14094
14095+ pax_force_retaddr
14096 ret
14097 ENDPROC(sha256_transform_ssse3)
14098
14099diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14100index 974dde9..a823ff9 100644
14101--- a/arch/x86/crypto/sha512-avx-asm.S
14102+++ b/arch/x86/crypto/sha512-avx-asm.S
14103@@ -49,6 +49,7 @@
14104
14105 #ifdef CONFIG_AS_AVX
14106 #include <linux/linkage.h>
14107+#include <asm/alternative-asm.h>
14108
14109 .text
14110
14111@@ -364,6 +365,7 @@ updateblock:
14112 mov frame_RSPSAVE(%rsp), %rsp
14113
14114 nowork:
14115+ pax_force_retaddr
14116 ret
14117 ENDPROC(sha512_transform_avx)
14118
14119diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14120index 568b961..ed20c37 100644
14121--- a/arch/x86/crypto/sha512-avx2-asm.S
14122+++ b/arch/x86/crypto/sha512-avx2-asm.S
14123@@ -51,6 +51,7 @@
14124
14125 #ifdef CONFIG_AS_AVX2
14126 #include <linux/linkage.h>
14127+#include <asm/alternative-asm.h>
14128
14129 .text
14130
14131@@ -678,6 +679,7 @@ done_hash:
14132
14133 # Restore Stack Pointer
14134 mov frame_RSPSAVE(%rsp), %rsp
14135+ pax_force_retaddr
14136 ret
14137 ENDPROC(sha512_transform_rorx)
14138
14139diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14140index fb56855..6edd768 100644
14141--- a/arch/x86/crypto/sha512-ssse3-asm.S
14142+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14143@@ -48,6 +48,7 @@
14144 ########################################################################
14145
14146 #include <linux/linkage.h>
14147+#include <asm/alternative-asm.h>
14148
14149 .text
14150
14151@@ -363,6 +364,7 @@ updateblock:
14152 mov frame_RSPSAVE(%rsp), %rsp
14153
14154 nowork:
14155+ pax_force_retaddr
14156 ret
14157 ENDPROC(sha512_transform_ssse3)
14158
14159diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14160index 0505813..b067311 100644
14161--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14162+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14163@@ -24,6 +24,7 @@
14164 */
14165
14166 #include <linux/linkage.h>
14167+#include <asm/alternative-asm.h>
14168 #include "glue_helper-asm-avx.S"
14169
14170 .file "twofish-avx-x86_64-asm_64.S"
14171@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14172 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14173 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14174
14175+ pax_force_retaddr
14176 ret;
14177 ENDPROC(__twofish_enc_blk8)
14178
14179@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14180 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14181 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14182
14183+ pax_force_retaddr
14184 ret;
14185 ENDPROC(__twofish_dec_blk8)
14186
14187@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14188
14189 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14190
14191+ pax_force_retaddr
14192 ret;
14193 ENDPROC(twofish_ecb_enc_8way)
14194
14195@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14196
14197 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14198
14199+ pax_force_retaddr
14200 ret;
14201 ENDPROC(twofish_ecb_dec_8way)
14202
14203@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14204 * %rdx: src
14205 */
14206
14207- pushq %r12;
14208+ pushq %r14;
14209
14210 movq %rsi, %r11;
14211- movq %rdx, %r12;
14212+ movq %rdx, %r14;
14213
14214 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14215
14216 call __twofish_dec_blk8;
14217
14218- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14219+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14220
14221- popq %r12;
14222+ popq %r14;
14223
14224+ pax_force_retaddr
14225 ret;
14226 ENDPROC(twofish_cbc_dec_8way)
14227
14228@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14229 * %rcx: iv (little endian, 128bit)
14230 */
14231
14232- pushq %r12;
14233+ pushq %r14;
14234
14235 movq %rsi, %r11;
14236- movq %rdx, %r12;
14237+ movq %rdx, %r14;
14238
14239 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14240 RD2, RX0, RX1, RY0);
14241
14242 call __twofish_enc_blk8;
14243
14244- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14245+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14246
14247- popq %r12;
14248+ popq %r14;
14249
14250+ pax_force_retaddr
14251 ret;
14252 ENDPROC(twofish_ctr_8way)
14253
14254@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14255 /* dst <= regs xor IVs(in dst) */
14256 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14257
14258+ pax_force_retaddr
14259 ret;
14260 ENDPROC(twofish_xts_enc_8way)
14261
14262@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14263 /* dst <= regs xor IVs(in dst) */
14264 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14265
14266+ pax_force_retaddr
14267 ret;
14268 ENDPROC(twofish_xts_dec_8way)
14269diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14270index 1c3b7ce..02f578d 100644
14271--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14272+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14273@@ -21,6 +21,7 @@
14274 */
14275
14276 #include <linux/linkage.h>
14277+#include <asm/alternative-asm.h>
14278
14279 .file "twofish-x86_64-asm-3way.S"
14280 .text
14281@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14282 popq %r13;
14283 popq %r14;
14284 popq %r15;
14285+ pax_force_retaddr
14286 ret;
14287
14288 .L__enc_xor3:
14289@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14290 popq %r13;
14291 popq %r14;
14292 popq %r15;
14293+ pax_force_retaddr
14294 ret;
14295 ENDPROC(__twofish_enc_blk_3way)
14296
14297@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14298 popq %r13;
14299 popq %r14;
14300 popq %r15;
14301+ pax_force_retaddr
14302 ret;
14303 ENDPROC(twofish_dec_blk_3way)
14304diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14305index a039d21..524b8b2 100644
14306--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14307+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14308@@ -22,6 +22,7 @@
14309
14310 #include <linux/linkage.h>
14311 #include <asm/asm-offsets.h>
14312+#include <asm/alternative-asm.h>
14313
14314 #define a_offset 0
14315 #define b_offset 4
14316@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14317
14318 popq R1
14319 movq $1,%rax
14320+ pax_force_retaddr
14321 ret
14322 ENDPROC(twofish_enc_blk)
14323
14324@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14325
14326 popq R1
14327 movq $1,%rax
14328+ pax_force_retaddr
14329 ret
14330 ENDPROC(twofish_dec_blk)
14331diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14332index d21ff89..6da8e6e 100644
14333--- a/arch/x86/ia32/ia32_aout.c
14334+++ b/arch/x86/ia32/ia32_aout.c
14335@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14336 unsigned long dump_start, dump_size;
14337 struct user32 dump;
14338
14339+ memset(&dump, 0, sizeof(dump));
14340+
14341 fs = get_fs();
14342 set_fs(KERNEL_DS);
14343 has_dumped = 1;
14344diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14345index 2206757..85cbcfa 100644
14346--- a/arch/x86/ia32/ia32_signal.c
14347+++ b/arch/x86/ia32/ia32_signal.c
14348@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14349 if (__get_user(set.sig[0], &frame->sc.oldmask)
14350 || (_COMPAT_NSIG_WORDS > 1
14351 && __copy_from_user((((char *) &set.sig) + 4),
14352- &frame->extramask,
14353+ frame->extramask,
14354 sizeof(frame->extramask))))
14355 goto badframe;
14356
14357@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14358 sp -= frame_size;
14359 /* Align the stack pointer according to the i386 ABI,
14360 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14361- sp = ((sp + 4) & -16ul) - 4;
14362+ sp = ((sp - 12) & -16ul) - 4;
14363 return (void __user *) sp;
14364 }
14365
14366@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14367 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14368 sigreturn);
14369 else
14370- restorer = &frame->retcode;
14371+ restorer = frame->retcode;
14372 }
14373
14374 put_user_try {
14375@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14376 * These are actually not used anymore, but left because some
14377 * gdb versions depend on them as a marker.
14378 */
14379- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14380+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14381 } put_user_catch(err);
14382
14383 if (err)
14384@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14385 0xb8,
14386 __NR_ia32_rt_sigreturn,
14387 0x80cd,
14388- 0,
14389+ 0
14390 };
14391
14392 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14393@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14394
14395 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14396 restorer = ksig->ka.sa.sa_restorer;
14397+ else if (current->mm->context.vdso)
14398+ /* Return stub is in 32bit vsyscall page */
14399+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14400 else
14401- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14402- rt_sigreturn);
14403+ restorer = frame->retcode;
14404 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14405
14406 /*
14407 * Not actually used anymore, but left because some gdb
14408 * versions need it.
14409 */
14410- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14411+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14412 } put_user_catch(err);
14413
14414 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14415diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14416index 4299eb0..c0687a7 100644
14417--- a/arch/x86/ia32/ia32entry.S
14418+++ b/arch/x86/ia32/ia32entry.S
14419@@ -15,8 +15,10 @@
14420 #include <asm/irqflags.h>
14421 #include <asm/asm.h>
14422 #include <asm/smap.h>
14423+#include <asm/pgtable.h>
14424 #include <linux/linkage.h>
14425 #include <linux/err.h>
14426+#include <asm/alternative-asm.h>
14427
14428 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14429 #include <linux/elf-em.h>
14430@@ -62,12 +64,12 @@
14431 */
14432 .macro LOAD_ARGS32 offset, _r9=0
14433 .if \_r9
14434- movl \offset+16(%rsp),%r9d
14435+ movl \offset+R9(%rsp),%r9d
14436 .endif
14437- movl \offset+40(%rsp),%ecx
14438- movl \offset+48(%rsp),%edx
14439- movl \offset+56(%rsp),%esi
14440- movl \offset+64(%rsp),%edi
14441+ movl \offset+RCX(%rsp),%ecx
14442+ movl \offset+RDX(%rsp),%edx
14443+ movl \offset+RSI(%rsp),%esi
14444+ movl \offset+RDI(%rsp),%edi
14445 movl %eax,%eax /* zero extension */
14446 .endm
14447
14448@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14449 ENDPROC(native_irq_enable_sysexit)
14450 #endif
14451
14452+ .macro pax_enter_kernel_user
14453+ pax_set_fptr_mask
14454+#ifdef CONFIG_PAX_MEMORY_UDEREF
14455+ call pax_enter_kernel_user
14456+#endif
14457+ .endm
14458+
14459+ .macro pax_exit_kernel_user
14460+#ifdef CONFIG_PAX_MEMORY_UDEREF
14461+ call pax_exit_kernel_user
14462+#endif
14463+#ifdef CONFIG_PAX_RANDKSTACK
14464+ pushq %rax
14465+ pushq %r11
14466+ call pax_randomize_kstack
14467+ popq %r11
14468+ popq %rax
14469+#endif
14470+ .endm
14471+
14472+ .macro pax_erase_kstack
14473+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14474+ call pax_erase_kstack
14475+#endif
14476+ .endm
14477+
14478 /*
14479 * 32bit SYSENTER instruction entry.
14480 *
14481@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14482 CFI_REGISTER rsp,rbp
14483 SWAPGS_UNSAFE_STACK
14484 movq PER_CPU_VAR(kernel_stack), %rsp
14485- addq $(KERNEL_STACK_OFFSET),%rsp
14486- /*
14487- * No need to follow this irqs on/off section: the syscall
14488- * disabled irqs, here we enable it straight after entry:
14489- */
14490- ENABLE_INTERRUPTS(CLBR_NONE)
14491 movl %ebp,%ebp /* zero extension */
14492 pushq_cfi $__USER32_DS
14493 /*CFI_REL_OFFSET ss,0*/
14494@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14495 CFI_REL_OFFSET rsp,0
14496 pushfq_cfi
14497 /*CFI_REL_OFFSET rflags,0*/
14498- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14499- CFI_REGISTER rip,r10
14500+ orl $X86_EFLAGS_IF,(%rsp)
14501+ GET_THREAD_INFO(%r11)
14502+ movl TI_sysenter_return(%r11), %r11d
14503+ CFI_REGISTER rip,r11
14504 pushq_cfi $__USER32_CS
14505 /*CFI_REL_OFFSET cs,0*/
14506 movl %eax, %eax
14507- pushq_cfi %r10
14508+ pushq_cfi %r11
14509 CFI_REL_OFFSET rip,0
14510 pushq_cfi %rax
14511 cld
14512 SAVE_ARGS 0,1,0
14513+ pax_enter_kernel_user
14514+
14515+#ifdef CONFIG_PAX_RANDKSTACK
14516+ pax_erase_kstack
14517+#endif
14518+
14519+ /*
14520+ * No need to follow this irqs on/off section: the syscall
14521+ * disabled irqs, here we enable it straight after entry:
14522+ */
14523+ ENABLE_INTERRUPTS(CLBR_NONE)
14524 /* no need to do an access_ok check here because rbp has been
14525 32bit zero extended */
14526+
14527+#ifdef CONFIG_PAX_MEMORY_UDEREF
14528+ addq pax_user_shadow_base,%rbp
14529+ ASM_PAX_OPEN_USERLAND
14530+#endif
14531+
14532 ASM_STAC
14533 1: movl (%rbp),%ebp
14534 _ASM_EXTABLE(1b,ia32_badarg)
14535 ASM_CLAC
14536- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14537- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14538+
14539+#ifdef CONFIG_PAX_MEMORY_UDEREF
14540+ ASM_PAX_CLOSE_USERLAND
14541+#endif
14542+
14543+ GET_THREAD_INFO(%r11)
14544+ orl $TS_COMPAT,TI_status(%r11)
14545+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14546 CFI_REMEMBER_STATE
14547 jnz sysenter_tracesys
14548 cmpq $(IA32_NR_syscalls-1),%rax
14549@@ -162,15 +209,18 @@ sysenter_do_call:
14550 sysenter_dispatch:
14551 call *ia32_sys_call_table(,%rax,8)
14552 movq %rax,RAX-ARGOFFSET(%rsp)
14553+ GET_THREAD_INFO(%r11)
14554 DISABLE_INTERRUPTS(CLBR_NONE)
14555 TRACE_IRQS_OFF
14556- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14557+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14558 jnz sysexit_audit
14559 sysexit_from_sys_call:
14560- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14561+ pax_exit_kernel_user
14562+ pax_erase_kstack
14563+ andl $~TS_COMPAT,TI_status(%r11)
14564 /* clear IF, that popfq doesn't enable interrupts early */
14565- andl $~0x200,EFLAGS-R11(%rsp)
14566- movl RIP-R11(%rsp),%edx /* User %eip */
14567+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14568+ movl RIP(%rsp),%edx /* User %eip */
14569 CFI_REGISTER rip,rdx
14570 RESTORE_ARGS 0,24,0,0,0,0
14571 xorq %r8,%r8
14572@@ -193,6 +243,9 @@ sysexit_from_sys_call:
14573 movl %eax,%esi /* 2nd arg: syscall number */
14574 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14575 call __audit_syscall_entry
14576+
14577+ pax_erase_kstack
14578+
14579 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14580 cmpq $(IA32_NR_syscalls-1),%rax
14581 ja ia32_badsys
14582@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14583 .endm
14584
14585 .macro auditsys_exit exit
14586- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14587+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14588 jnz ia32_ret_from_sys_call
14589 TRACE_IRQS_ON
14590 ENABLE_INTERRUPTS(CLBR_NONE)
14591@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14592 1: setbe %al /* 1 if error, 0 if not */
14593 movzbl %al,%edi /* zero-extend that into %edi */
14594 call __audit_syscall_exit
14595+ GET_THREAD_INFO(%r11)
14596 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14597 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14598 DISABLE_INTERRUPTS(CLBR_NONE)
14599 TRACE_IRQS_OFF
14600- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14601+ testl %edi,TI_flags(%r11)
14602 jz \exit
14603 CLEAR_RREGS -ARGOFFSET
14604 jmp int_with_check
14605@@ -237,7 +291,7 @@ sysexit_audit:
14606
14607 sysenter_tracesys:
14608 #ifdef CONFIG_AUDITSYSCALL
14609- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14610+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14611 jz sysenter_auditsys
14612 #endif
14613 SAVE_REST
14614@@ -249,6 +303,9 @@ sysenter_tracesys:
14615 RESTORE_REST
14616 cmpq $(IA32_NR_syscalls-1),%rax
14617 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14618+
14619+ pax_erase_kstack
14620+
14621 jmp sysenter_do_call
14622 CFI_ENDPROC
14623 ENDPROC(ia32_sysenter_target)
14624@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14625 ENTRY(ia32_cstar_target)
14626 CFI_STARTPROC32 simple
14627 CFI_SIGNAL_FRAME
14628- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14629+ CFI_DEF_CFA rsp,0
14630 CFI_REGISTER rip,rcx
14631 /*CFI_REGISTER rflags,r11*/
14632 SWAPGS_UNSAFE_STACK
14633 movl %esp,%r8d
14634 CFI_REGISTER rsp,r8
14635 movq PER_CPU_VAR(kernel_stack),%rsp
14636+ SAVE_ARGS 8*6,0,0
14637+ pax_enter_kernel_user
14638+
14639+#ifdef CONFIG_PAX_RANDKSTACK
14640+ pax_erase_kstack
14641+#endif
14642+
14643 /*
14644 * No need to follow this irqs on/off section: the syscall
14645 * disabled irqs and here we enable it straight after entry:
14646 */
14647 ENABLE_INTERRUPTS(CLBR_NONE)
14648- SAVE_ARGS 8,0,0
14649 movl %eax,%eax /* zero extension */
14650 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14651 movq %rcx,RIP-ARGOFFSET(%rsp)
14652@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14653 /* no need to do an access_ok check here because r8 has been
14654 32bit zero extended */
14655 /* hardware stack frame is complete now */
14656+
14657+#ifdef CONFIG_PAX_MEMORY_UDEREF
14658+ ASM_PAX_OPEN_USERLAND
14659+ movq pax_user_shadow_base,%r8
14660+ addq RSP-ARGOFFSET(%rsp),%r8
14661+#endif
14662+
14663 ASM_STAC
14664 1: movl (%r8),%r9d
14665 _ASM_EXTABLE(1b,ia32_badarg)
14666 ASM_CLAC
14667- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14668- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14669+
14670+#ifdef CONFIG_PAX_MEMORY_UDEREF
14671+ ASM_PAX_CLOSE_USERLAND
14672+#endif
14673+
14674+ GET_THREAD_INFO(%r11)
14675+ orl $TS_COMPAT,TI_status(%r11)
14676+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14677 CFI_REMEMBER_STATE
14678 jnz cstar_tracesys
14679 cmpq $IA32_NR_syscalls-1,%rax
14680@@ -319,13 +395,16 @@ cstar_do_call:
14681 cstar_dispatch:
14682 call *ia32_sys_call_table(,%rax,8)
14683 movq %rax,RAX-ARGOFFSET(%rsp)
14684+ GET_THREAD_INFO(%r11)
14685 DISABLE_INTERRUPTS(CLBR_NONE)
14686 TRACE_IRQS_OFF
14687- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14688+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14689 jnz sysretl_audit
14690 sysretl_from_sys_call:
14691- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14692- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14693+ pax_exit_kernel_user
14694+ pax_erase_kstack
14695+ andl $~TS_COMPAT,TI_status(%r11)
14696+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14697 movl RIP-ARGOFFSET(%rsp),%ecx
14698 CFI_REGISTER rip,rcx
14699 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14700@@ -352,7 +431,7 @@ sysretl_audit:
14701
14702 cstar_tracesys:
14703 #ifdef CONFIG_AUDITSYSCALL
14704- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14705+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14706 jz cstar_auditsys
14707 #endif
14708 xchgl %r9d,%ebp
14709@@ -366,11 +445,19 @@ cstar_tracesys:
14710 xchgl %ebp,%r9d
14711 cmpq $(IA32_NR_syscalls-1),%rax
14712 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14713+
14714+ pax_erase_kstack
14715+
14716 jmp cstar_do_call
14717 END(ia32_cstar_target)
14718
14719 ia32_badarg:
14720 ASM_CLAC
14721+
14722+#ifdef CONFIG_PAX_MEMORY_UDEREF
14723+ ASM_PAX_CLOSE_USERLAND
14724+#endif
14725+
14726 movq $-EFAULT,%rax
14727 jmp ia32_sysret
14728 CFI_ENDPROC
14729@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14730 CFI_REL_OFFSET rip,RIP-RIP
14731 PARAVIRT_ADJUST_EXCEPTION_FRAME
14732 SWAPGS
14733- /*
14734- * No need to follow this irqs on/off section: the syscall
14735- * disabled irqs and here we enable it straight after entry:
14736- */
14737- ENABLE_INTERRUPTS(CLBR_NONE)
14738 movl %eax,%eax
14739 pushq_cfi %rax
14740 cld
14741 /* note the registers are not zero extended to the sf.
14742 this could be a problem. */
14743 SAVE_ARGS 0,1,0
14744- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14745- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14746+ pax_enter_kernel_user
14747+
14748+#ifdef CONFIG_PAX_RANDKSTACK
14749+ pax_erase_kstack
14750+#endif
14751+
14752+ /*
14753+ * No need to follow this irqs on/off section: the syscall
14754+ * disabled irqs and here we enable it straight after entry:
14755+ */
14756+ ENABLE_INTERRUPTS(CLBR_NONE)
14757+ GET_THREAD_INFO(%r11)
14758+ orl $TS_COMPAT,TI_status(%r11)
14759+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14760 jnz ia32_tracesys
14761 cmpq $(IA32_NR_syscalls-1),%rax
14762 ja ia32_badsys
14763@@ -442,6 +536,9 @@ ia32_tracesys:
14764 RESTORE_REST
14765 cmpq $(IA32_NR_syscalls-1),%rax
14766 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14767+
14768+ pax_erase_kstack
14769+
14770 jmp ia32_do_call
14771 END(ia32_syscall)
14772
14773diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14774index 8e0ceec..af13504 100644
14775--- a/arch/x86/ia32/sys_ia32.c
14776+++ b/arch/x86/ia32/sys_ia32.c
14777@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14778 */
14779 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14780 {
14781- typeof(ubuf->st_uid) uid = 0;
14782- typeof(ubuf->st_gid) gid = 0;
14783+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
14784+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
14785 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14786 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14787 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14788diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14789index 372231c..51b537d 100644
14790--- a/arch/x86/include/asm/alternative-asm.h
14791+++ b/arch/x86/include/asm/alternative-asm.h
14792@@ -18,6 +18,45 @@
14793 .endm
14794 #endif
14795
14796+#ifdef KERNEXEC_PLUGIN
14797+ .macro pax_force_retaddr_bts rip=0
14798+ btsq $63,\rip(%rsp)
14799+ .endm
14800+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14801+ .macro pax_force_retaddr rip=0, reload=0
14802+ btsq $63,\rip(%rsp)
14803+ .endm
14804+ .macro pax_force_fptr ptr
14805+ btsq $63,\ptr
14806+ .endm
14807+ .macro pax_set_fptr_mask
14808+ .endm
14809+#endif
14810+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14811+ .macro pax_force_retaddr rip=0, reload=0
14812+ .if \reload
14813+ pax_set_fptr_mask
14814+ .endif
14815+ orq %r12,\rip(%rsp)
14816+ .endm
14817+ .macro pax_force_fptr ptr
14818+ orq %r12,\ptr
14819+ .endm
14820+ .macro pax_set_fptr_mask
14821+ movabs $0x8000000000000000,%r12
14822+ .endm
14823+#endif
14824+#else
14825+ .macro pax_force_retaddr rip=0, reload=0
14826+ .endm
14827+ .macro pax_force_fptr ptr
14828+ .endm
14829+ .macro pax_force_retaddr_bts rip=0
14830+ .endm
14831+ .macro pax_set_fptr_mask
14832+ .endm
14833+#endif
14834+
14835 .macro altinstruction_entry orig alt feature orig_len alt_len
14836 .long \orig - .
14837 .long \alt - .
14838diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14839index 0a3f9c9..c9d081d 100644
14840--- a/arch/x86/include/asm/alternative.h
14841+++ b/arch/x86/include/asm/alternative.h
14842@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14843 ".pushsection .discard,\"aw\",@progbits\n" \
14844 DISCARD_ENTRY(1) \
14845 ".popsection\n" \
14846- ".pushsection .altinstr_replacement, \"ax\"\n" \
14847+ ".pushsection .altinstr_replacement, \"a\"\n" \
14848 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14849 ".popsection"
14850
14851@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14852 DISCARD_ENTRY(1) \
14853 DISCARD_ENTRY(2) \
14854 ".popsection\n" \
14855- ".pushsection .altinstr_replacement, \"ax\"\n" \
14856+ ".pushsection .altinstr_replacement, \"a\"\n" \
14857 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14858 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14859 ".popsection"
14860diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14861index 19b0eba..12254cd 100644
14862--- a/arch/x86/include/asm/apic.h
14863+++ b/arch/x86/include/asm/apic.h
14864@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14865
14866 #ifdef CONFIG_X86_LOCAL_APIC
14867
14868-extern unsigned int apic_verbosity;
14869+extern int apic_verbosity;
14870 extern int local_apic_timer_c2_ok;
14871
14872 extern int disable_apic;
14873diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14874index 20370c6..a2eb9b0 100644
14875--- a/arch/x86/include/asm/apm.h
14876+++ b/arch/x86/include/asm/apm.h
14877@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14878 __asm__ __volatile__(APM_DO_ZERO_SEGS
14879 "pushl %%edi\n\t"
14880 "pushl %%ebp\n\t"
14881- "lcall *%%cs:apm_bios_entry\n\t"
14882+ "lcall *%%ss:apm_bios_entry\n\t"
14883 "setc %%al\n\t"
14884 "popl %%ebp\n\t"
14885 "popl %%edi\n\t"
14886@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14887 __asm__ __volatile__(APM_DO_ZERO_SEGS
14888 "pushl %%edi\n\t"
14889 "pushl %%ebp\n\t"
14890- "lcall *%%cs:apm_bios_entry\n\t"
14891+ "lcall *%%ss:apm_bios_entry\n\t"
14892 "setc %%bl\n\t"
14893 "popl %%ebp\n\t"
14894 "popl %%edi\n\t"
14895diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14896index b17f4f4..9620151 100644
14897--- a/arch/x86/include/asm/atomic.h
14898+++ b/arch/x86/include/asm/atomic.h
14899@@ -23,7 +23,18 @@
14900 */
14901 static inline int atomic_read(const atomic_t *v)
14902 {
14903- return (*(volatile int *)&(v)->counter);
14904+ return (*(volatile const int *)&(v)->counter);
14905+}
14906+
14907+/**
14908+ * atomic_read_unchecked - read atomic variable
14909+ * @v: pointer of type atomic_unchecked_t
14910+ *
14911+ * Atomically reads the value of @v.
14912+ */
14913+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14914+{
14915+ return (*(volatile const int *)&(v)->counter);
14916 }
14917
14918 /**
14919@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14920 }
14921
14922 /**
14923+ * atomic_set_unchecked - set atomic variable
14924+ * @v: pointer of type atomic_unchecked_t
14925+ * @i: required value
14926+ *
14927+ * Atomically sets the value of @v to @i.
14928+ */
14929+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14930+{
14931+ v->counter = i;
14932+}
14933+
14934+/**
14935 * atomic_add - add integer to atomic variable
14936 * @i: integer value to add
14937 * @v: pointer of type atomic_t
14938@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14939 */
14940 static inline void atomic_add(int i, atomic_t *v)
14941 {
14942- asm volatile(LOCK_PREFIX "addl %1,%0"
14943+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14944+
14945+#ifdef CONFIG_PAX_REFCOUNT
14946+ "jno 0f\n"
14947+ LOCK_PREFIX "subl %1,%0\n"
14948+ "int $4\n0:\n"
14949+ _ASM_EXTABLE(0b, 0b)
14950+#endif
14951+
14952+ : "+m" (v->counter)
14953+ : "ir" (i));
14954+}
14955+
14956+/**
14957+ * atomic_add_unchecked - add integer to atomic variable
14958+ * @i: integer value to add
14959+ * @v: pointer of type atomic_unchecked_t
14960+ *
14961+ * Atomically adds @i to @v.
14962+ */
14963+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14964+{
14965+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14966 : "+m" (v->counter)
14967 : "ir" (i));
14968 }
14969@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14970 */
14971 static inline void atomic_sub(int i, atomic_t *v)
14972 {
14973- asm volatile(LOCK_PREFIX "subl %1,%0"
14974+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14975+
14976+#ifdef CONFIG_PAX_REFCOUNT
14977+ "jno 0f\n"
14978+ LOCK_PREFIX "addl %1,%0\n"
14979+ "int $4\n0:\n"
14980+ _ASM_EXTABLE(0b, 0b)
14981+#endif
14982+
14983+ : "+m" (v->counter)
14984+ : "ir" (i));
14985+}
14986+
14987+/**
14988+ * atomic_sub_unchecked - subtract integer from atomic variable
14989+ * @i: integer value to subtract
14990+ * @v: pointer of type atomic_unchecked_t
14991+ *
14992+ * Atomically subtracts @i from @v.
14993+ */
14994+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14995+{
14996+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14997 : "+m" (v->counter)
14998 : "ir" (i));
14999 }
15000@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15001 */
15002 static inline int atomic_sub_and_test(int i, atomic_t *v)
15003 {
15004- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15005+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15006 }
15007
15008 /**
15009@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15010 */
15011 static inline void atomic_inc(atomic_t *v)
15012 {
15013- asm volatile(LOCK_PREFIX "incl %0"
15014+ asm volatile(LOCK_PREFIX "incl %0\n"
15015+
15016+#ifdef CONFIG_PAX_REFCOUNT
15017+ "jno 0f\n"
15018+ LOCK_PREFIX "decl %0\n"
15019+ "int $4\n0:\n"
15020+ _ASM_EXTABLE(0b, 0b)
15021+#endif
15022+
15023+ : "+m" (v->counter));
15024+}
15025+
15026+/**
15027+ * atomic_inc_unchecked - increment atomic variable
15028+ * @v: pointer of type atomic_unchecked_t
15029+ *
15030+ * Atomically increments @v by 1.
15031+ */
15032+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15033+{
15034+ asm volatile(LOCK_PREFIX "incl %0\n"
15035 : "+m" (v->counter));
15036 }
15037
15038@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
15039 */
15040 static inline void atomic_dec(atomic_t *v)
15041 {
15042- asm volatile(LOCK_PREFIX "decl %0"
15043+ asm volatile(LOCK_PREFIX "decl %0\n"
15044+
15045+#ifdef CONFIG_PAX_REFCOUNT
15046+ "jno 0f\n"
15047+ LOCK_PREFIX "incl %0\n"
15048+ "int $4\n0:\n"
15049+ _ASM_EXTABLE(0b, 0b)
15050+#endif
15051+
15052+ : "+m" (v->counter));
15053+}
15054+
15055+/**
15056+ * atomic_dec_unchecked - decrement atomic variable
15057+ * @v: pointer of type atomic_unchecked_t
15058+ *
15059+ * Atomically decrements @v by 1.
15060+ */
15061+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15062+{
15063+ asm volatile(LOCK_PREFIX "decl %0\n"
15064 : "+m" (v->counter));
15065 }
15066
15067@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15068 */
15069 static inline int atomic_dec_and_test(atomic_t *v)
15070 {
15071- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15072+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15073 }
15074
15075 /**
15076@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15077 */
15078 static inline int atomic_inc_and_test(atomic_t *v)
15079 {
15080- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15081+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15082+}
15083+
15084+/**
15085+ * atomic_inc_and_test_unchecked - increment and test
15086+ * @v: pointer of type atomic_unchecked_t
15087+ *
15088+ * Atomically increments @v by 1
15089+ * and returns true if the result is zero, or false for all
15090+ * other cases.
15091+ */
15092+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15093+{
15094+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15095 }
15096
15097 /**
15098@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15099 */
15100 static inline int atomic_add_negative(int i, atomic_t *v)
15101 {
15102- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15103+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15104 }
15105
15106 /**
15107@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15108 */
15109 static inline int atomic_add_return(int i, atomic_t *v)
15110 {
15111+ return i + xadd_check_overflow(&v->counter, i);
15112+}
15113+
15114+/**
15115+ * atomic_add_return_unchecked - add integer and return
15116+ * @i: integer value to add
15117+ * @v: pointer of type atomic_unchecked_t
15118+ *
15119+ * Atomically adds @i to @v and returns @i + @v
15120+ */
15121+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15122+{
15123 return i + xadd(&v->counter, i);
15124 }
15125
15126@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15127 }
15128
15129 #define atomic_inc_return(v) (atomic_add_return(1, v))
15130+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15131+{
15132+ return atomic_add_return_unchecked(1, v);
15133+}
15134 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15135
15136-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15137+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15138+{
15139+ return cmpxchg(&v->counter, old, new);
15140+}
15141+
15142+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15143 {
15144 return cmpxchg(&v->counter, old, new);
15145 }
15146@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15147 return xchg(&v->counter, new);
15148 }
15149
15150+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15151+{
15152+ return xchg(&v->counter, new);
15153+}
15154+
15155 /**
15156 * __atomic_add_unless - add unless the number is already a given value
15157 * @v: pointer of type atomic_t
15158@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15159 * Atomically adds @a to @v, so long as @v was not already @u.
15160 * Returns the old value of @v.
15161 */
15162-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15163+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15164 {
15165- int c, old;
15166+ int c, old, new;
15167 c = atomic_read(v);
15168 for (;;) {
15169- if (unlikely(c == (u)))
15170+ if (unlikely(c == u))
15171 break;
15172- old = atomic_cmpxchg((v), c, c + (a));
15173+
15174+ asm volatile("addl %2,%0\n"
15175+
15176+#ifdef CONFIG_PAX_REFCOUNT
15177+ "jno 0f\n"
15178+ "subl %2,%0\n"
15179+ "int $4\n0:\n"
15180+ _ASM_EXTABLE(0b, 0b)
15181+#endif
15182+
15183+ : "=r" (new)
15184+ : "0" (c), "ir" (a));
15185+
15186+ old = atomic_cmpxchg(v, c, new);
15187 if (likely(old == c))
15188 break;
15189 c = old;
15190@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15191 }
15192
15193 /**
15194+ * atomic_inc_not_zero_hint - increment if not null
15195+ * @v: pointer of type atomic_t
15196+ * @hint: probable value of the atomic before the increment
15197+ *
15198+ * This version of atomic_inc_not_zero() gives a hint of probable
15199+ * value of the atomic. This helps processor to not read the memory
15200+ * before doing the atomic read/modify/write cycle, lowering
15201+ * number of bus transactions on some arches.
15202+ *
15203+ * Returns: 0 if increment was not done, 1 otherwise.
15204+ */
15205+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15206+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15207+{
15208+ int val, c = hint, new;
15209+
15210+ /* sanity test, should be removed by compiler if hint is a constant */
15211+ if (!hint)
15212+ return __atomic_add_unless(v, 1, 0);
15213+
15214+ do {
15215+ asm volatile("incl %0\n"
15216+
15217+#ifdef CONFIG_PAX_REFCOUNT
15218+ "jno 0f\n"
15219+ "decl %0\n"
15220+ "int $4\n0:\n"
15221+ _ASM_EXTABLE(0b, 0b)
15222+#endif
15223+
15224+ : "=r" (new)
15225+ : "0" (c));
15226+
15227+ val = atomic_cmpxchg(v, c, new);
15228+ if (val == c)
15229+ return 1;
15230+ c = val;
15231+ } while (c);
15232+
15233+ return 0;
15234+}
15235+
15236+/**
15237 * atomic_inc_short - increment of a short integer
15238 * @v: pointer to type int
15239 *
15240@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15241 #endif
15242
15243 /* These are x86-specific, used by some header files */
15244-#define atomic_clear_mask(mask, addr) \
15245- asm volatile(LOCK_PREFIX "andl %0,%1" \
15246- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15247+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15248+{
15249+ asm volatile(LOCK_PREFIX "andl %1,%0"
15250+ : "+m" (v->counter)
15251+ : "r" (~(mask))
15252+ : "memory");
15253+}
15254
15255-#define atomic_set_mask(mask, addr) \
15256- asm volatile(LOCK_PREFIX "orl %0,%1" \
15257- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15258- : "memory")
15259+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15260+{
15261+ asm volatile(LOCK_PREFIX "andl %1,%0"
15262+ : "+m" (v->counter)
15263+ : "r" (~(mask))
15264+ : "memory");
15265+}
15266+
15267+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15268+{
15269+ asm volatile(LOCK_PREFIX "orl %1,%0"
15270+ : "+m" (v->counter)
15271+ : "r" (mask)
15272+ : "memory");
15273+}
15274+
15275+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15276+{
15277+ asm volatile(LOCK_PREFIX "orl %1,%0"
15278+ : "+m" (v->counter)
15279+ : "r" (mask)
15280+ : "memory");
15281+}
15282
15283 /* Atomic operations are already serializing on x86 */
15284 #define smp_mb__before_atomic_dec() barrier()
15285diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15286index b154de7..bf18a5a 100644
15287--- a/arch/x86/include/asm/atomic64_32.h
15288+++ b/arch/x86/include/asm/atomic64_32.h
15289@@ -12,6 +12,14 @@ typedef struct {
15290 u64 __aligned(8) counter;
15291 } atomic64_t;
15292
15293+#ifdef CONFIG_PAX_REFCOUNT
15294+typedef struct {
15295+ u64 __aligned(8) counter;
15296+} atomic64_unchecked_t;
15297+#else
15298+typedef atomic64_t atomic64_unchecked_t;
15299+#endif
15300+
15301 #define ATOMIC64_INIT(val) { (val) }
15302
15303 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15304@@ -37,21 +45,31 @@ typedef struct {
15305 ATOMIC64_DECL_ONE(sym##_386)
15306
15307 ATOMIC64_DECL_ONE(add_386);
15308+ATOMIC64_DECL_ONE(add_unchecked_386);
15309 ATOMIC64_DECL_ONE(sub_386);
15310+ATOMIC64_DECL_ONE(sub_unchecked_386);
15311 ATOMIC64_DECL_ONE(inc_386);
15312+ATOMIC64_DECL_ONE(inc_unchecked_386);
15313 ATOMIC64_DECL_ONE(dec_386);
15314+ATOMIC64_DECL_ONE(dec_unchecked_386);
15315 #endif
15316
15317 #define alternative_atomic64(f, out, in...) \
15318 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15319
15320 ATOMIC64_DECL(read);
15321+ATOMIC64_DECL(read_unchecked);
15322 ATOMIC64_DECL(set);
15323+ATOMIC64_DECL(set_unchecked);
15324 ATOMIC64_DECL(xchg);
15325 ATOMIC64_DECL(add_return);
15326+ATOMIC64_DECL(add_return_unchecked);
15327 ATOMIC64_DECL(sub_return);
15328+ATOMIC64_DECL(sub_return_unchecked);
15329 ATOMIC64_DECL(inc_return);
15330+ATOMIC64_DECL(inc_return_unchecked);
15331 ATOMIC64_DECL(dec_return);
15332+ATOMIC64_DECL(dec_return_unchecked);
15333 ATOMIC64_DECL(dec_if_positive);
15334 ATOMIC64_DECL(inc_not_zero);
15335 ATOMIC64_DECL(add_unless);
15336@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15337 }
15338
15339 /**
15340+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15341+ * @p: pointer to type atomic64_unchecked_t
15342+ * @o: expected value
15343+ * @n: new value
15344+ *
15345+ * Atomically sets @v to @n if it was equal to @o and returns
15346+ * the old value.
15347+ */
15348+
15349+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15350+{
15351+ return cmpxchg64(&v->counter, o, n);
15352+}
15353+
15354+/**
15355 * atomic64_xchg - xchg atomic64 variable
15356 * @v: pointer to type atomic64_t
15357 * @n: value to assign
15358@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15359 }
15360
15361 /**
15362+ * atomic64_set_unchecked - set atomic64 variable
15363+ * @v: pointer to type atomic64_unchecked_t
15364+ * @n: value to assign
15365+ *
15366+ * Atomically sets the value of @v to @n.
15367+ */
15368+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15369+{
15370+ unsigned high = (unsigned)(i >> 32);
15371+ unsigned low = (unsigned)i;
15372+ alternative_atomic64(set, /* no output */,
15373+ "S" (v), "b" (low), "c" (high)
15374+ : "eax", "edx", "memory");
15375+}
15376+
15377+/**
15378 * atomic64_read - read atomic64 variable
15379 * @v: pointer to type atomic64_t
15380 *
15381@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15382 }
15383
15384 /**
15385+ * atomic64_read_unchecked - read atomic64 variable
15386+ * @v: pointer to type atomic64_unchecked_t
15387+ *
15388+ * Atomically reads the value of @v and returns it.
15389+ */
15390+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15391+{
15392+ long long r;
15393+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15394+ return r;
15395+ }
15396+
15397+/**
15398 * atomic64_add_return - add and return
15399 * @i: integer value to add
15400 * @v: pointer to type atomic64_t
15401@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15402 return i;
15403 }
15404
15405+/**
15406+ * atomic64_add_return_unchecked - add and return
15407+ * @i: integer value to add
15408+ * @v: pointer to type atomic64_unchecked_t
15409+ *
15410+ * Atomically adds @i to @v and returns @i + *@v
15411+ */
15412+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15413+{
15414+ alternative_atomic64(add_return_unchecked,
15415+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15416+ ASM_NO_INPUT_CLOBBER("memory"));
15417+ return i;
15418+}
15419+
15420 /*
15421 * Other variants with different arithmetic operators:
15422 */
15423@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15424 return a;
15425 }
15426
15427+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15428+{
15429+ long long a;
15430+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15431+ "S" (v) : "memory", "ecx");
15432+ return a;
15433+}
15434+
15435 static inline long long atomic64_dec_return(atomic64_t *v)
15436 {
15437 long long a;
15438@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15439 }
15440
15441 /**
15442+ * atomic64_add_unchecked - add integer to atomic64 variable
15443+ * @i: integer value to add
15444+ * @v: pointer to type atomic64_unchecked_t
15445+ *
15446+ * Atomically adds @i to @v.
15447+ */
15448+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15449+{
15450+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15451+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15452+ ASM_NO_INPUT_CLOBBER("memory"));
15453+ return i;
15454+}
15455+
15456+/**
15457 * atomic64_sub - subtract the atomic64 variable
15458 * @i: integer value to subtract
15459 * @v: pointer to type atomic64_t
15460diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15461index 46e9052..ae45136 100644
15462--- a/arch/x86/include/asm/atomic64_64.h
15463+++ b/arch/x86/include/asm/atomic64_64.h
15464@@ -18,7 +18,19 @@
15465 */
15466 static inline long atomic64_read(const atomic64_t *v)
15467 {
15468- return (*(volatile long *)&(v)->counter);
15469+ return (*(volatile const long *)&(v)->counter);
15470+}
15471+
15472+/**
15473+ * atomic64_read_unchecked - read atomic64 variable
15474+ * @v: pointer of type atomic64_unchecked_t
15475+ *
15476+ * Atomically reads the value of @v.
15477+ * Doesn't imply a read memory barrier.
15478+ */
15479+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15480+{
15481+ return (*(volatile const long *)&(v)->counter);
15482 }
15483
15484 /**
15485@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15486 }
15487
15488 /**
15489+ * atomic64_set_unchecked - set atomic64 variable
15490+ * @v: pointer to type atomic64_unchecked_t
15491+ * @i: required value
15492+ *
15493+ * Atomically sets the value of @v to @i.
15494+ */
15495+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15496+{
15497+ v->counter = i;
15498+}
15499+
15500+/**
15501 * atomic64_add - add integer to atomic64 variable
15502 * @i: integer value to add
15503 * @v: pointer to type atomic64_t
15504@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15505 */
15506 static inline void atomic64_add(long i, atomic64_t *v)
15507 {
15508+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15509+
15510+#ifdef CONFIG_PAX_REFCOUNT
15511+ "jno 0f\n"
15512+ LOCK_PREFIX "subq %1,%0\n"
15513+ "int $4\n0:\n"
15514+ _ASM_EXTABLE(0b, 0b)
15515+#endif
15516+
15517+ : "=m" (v->counter)
15518+ : "er" (i), "m" (v->counter));
15519+}
15520+
15521+/**
15522+ * atomic64_add_unchecked - add integer to atomic64 variable
15523+ * @i: integer value to add
15524+ * @v: pointer to type atomic64_unchecked_t
15525+ *
15526+ * Atomically adds @i to @v.
15527+ */
15528+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15529+{
15530 asm volatile(LOCK_PREFIX "addq %1,%0"
15531 : "=m" (v->counter)
15532 : "er" (i), "m" (v->counter));
15533@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15534 */
15535 static inline void atomic64_sub(long i, atomic64_t *v)
15536 {
15537- asm volatile(LOCK_PREFIX "subq %1,%0"
15538+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15539+
15540+#ifdef CONFIG_PAX_REFCOUNT
15541+ "jno 0f\n"
15542+ LOCK_PREFIX "addq %1,%0\n"
15543+ "int $4\n0:\n"
15544+ _ASM_EXTABLE(0b, 0b)
15545+#endif
15546+
15547+ : "=m" (v->counter)
15548+ : "er" (i), "m" (v->counter));
15549+}
15550+
15551+/**
15552+ * atomic64_sub_unchecked - subtract the atomic64 variable
15553+ * @i: integer value to subtract
15554+ * @v: pointer to type atomic64_unchecked_t
15555+ *
15556+ * Atomically subtracts @i from @v.
15557+ */
15558+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15559+{
15560+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15561 : "=m" (v->counter)
15562 : "er" (i), "m" (v->counter));
15563 }
15564@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15565 */
15566 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15567 {
15568- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15569+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15570 }
15571
15572 /**
15573@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15574 */
15575 static inline void atomic64_inc(atomic64_t *v)
15576 {
15577+ asm volatile(LOCK_PREFIX "incq %0\n"
15578+
15579+#ifdef CONFIG_PAX_REFCOUNT
15580+ "jno 0f\n"
15581+ LOCK_PREFIX "decq %0\n"
15582+ "int $4\n0:\n"
15583+ _ASM_EXTABLE(0b, 0b)
15584+#endif
15585+
15586+ : "=m" (v->counter)
15587+ : "m" (v->counter));
15588+}
15589+
15590+/**
15591+ * atomic64_inc_unchecked - increment atomic64 variable
15592+ * @v: pointer to type atomic64_unchecked_t
15593+ *
15594+ * Atomically increments @v by 1.
15595+ */
15596+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15597+{
15598 asm volatile(LOCK_PREFIX "incq %0"
15599 : "=m" (v->counter)
15600 : "m" (v->counter));
15601@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15602 */
15603 static inline void atomic64_dec(atomic64_t *v)
15604 {
15605- asm volatile(LOCK_PREFIX "decq %0"
15606+ asm volatile(LOCK_PREFIX "decq %0\n"
15607+
15608+#ifdef CONFIG_PAX_REFCOUNT
15609+ "jno 0f\n"
15610+ LOCK_PREFIX "incq %0\n"
15611+ "int $4\n0:\n"
15612+ _ASM_EXTABLE(0b, 0b)
15613+#endif
15614+
15615+ : "=m" (v->counter)
15616+ : "m" (v->counter));
15617+}
15618+
15619+/**
15620+ * atomic64_dec_unchecked - decrement atomic64 variable
15621+ * @v: pointer to type atomic64_t
15622+ *
15623+ * Atomically decrements @v by 1.
15624+ */
15625+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15626+{
15627+ asm volatile(LOCK_PREFIX "decq %0\n"
15628 : "=m" (v->counter)
15629 : "m" (v->counter));
15630 }
15631@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15632 */
15633 static inline int atomic64_dec_and_test(atomic64_t *v)
15634 {
15635- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15636+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15637 }
15638
15639 /**
15640@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15641 */
15642 static inline int atomic64_inc_and_test(atomic64_t *v)
15643 {
15644- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15645+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15646 }
15647
15648 /**
15649@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15650 */
15651 static inline int atomic64_add_negative(long i, atomic64_t *v)
15652 {
15653- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15654+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15655 }
15656
15657 /**
15658@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15659 */
15660 static inline long atomic64_add_return(long i, atomic64_t *v)
15661 {
15662+ return i + xadd_check_overflow(&v->counter, i);
15663+}
15664+
15665+/**
15666+ * atomic64_add_return_unchecked - add and return
15667+ * @i: integer value to add
15668+ * @v: pointer to type atomic64_unchecked_t
15669+ *
15670+ * Atomically adds @i to @v and returns @i + @v
15671+ */
15672+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15673+{
15674 return i + xadd(&v->counter, i);
15675 }
15676
15677@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15678 }
15679
15680 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15681+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15682+{
15683+ return atomic64_add_return_unchecked(1, v);
15684+}
15685 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15686
15687 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15688@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15689 return cmpxchg(&v->counter, old, new);
15690 }
15691
15692+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15693+{
15694+ return cmpxchg(&v->counter, old, new);
15695+}
15696+
15697 static inline long atomic64_xchg(atomic64_t *v, long new)
15698 {
15699 return xchg(&v->counter, new);
15700@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15701 */
15702 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15703 {
15704- long c, old;
15705+ long c, old, new;
15706 c = atomic64_read(v);
15707 for (;;) {
15708- if (unlikely(c == (u)))
15709+ if (unlikely(c == u))
15710 break;
15711- old = atomic64_cmpxchg((v), c, c + (a));
15712+
15713+ asm volatile("add %2,%0\n"
15714+
15715+#ifdef CONFIG_PAX_REFCOUNT
15716+ "jno 0f\n"
15717+ "sub %2,%0\n"
15718+ "int $4\n0:\n"
15719+ _ASM_EXTABLE(0b, 0b)
15720+#endif
15721+
15722+ : "=r" (new)
15723+ : "0" (c), "ir" (a));
15724+
15725+ old = atomic64_cmpxchg(v, c, new);
15726 if (likely(old == c))
15727 break;
15728 c = old;
15729 }
15730- return c != (u);
15731+ return c != u;
15732 }
15733
15734 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15735diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
15736index 69bbb48..32517fe 100644
15737--- a/arch/x86/include/asm/barrier.h
15738+++ b/arch/x86/include/asm/barrier.h
15739@@ -107,7 +107,7 @@
15740 do { \
15741 compiletime_assert_atomic_type(*p); \
15742 smp_mb(); \
15743- ACCESS_ONCE(*p) = (v); \
15744+ ACCESS_ONCE_RW(*p) = (v); \
15745 } while (0)
15746
15747 #define smp_load_acquire(p) \
15748@@ -124,7 +124,7 @@ do { \
15749 do { \
15750 compiletime_assert_atomic_type(*p); \
15751 barrier(); \
15752- ACCESS_ONCE(*p) = (v); \
15753+ ACCESS_ONCE_RW(*p) = (v); \
15754 } while (0)
15755
15756 #define smp_load_acquire(p) \
15757diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15758index 9fc1af7..776d75a 100644
15759--- a/arch/x86/include/asm/bitops.h
15760+++ b/arch/x86/include/asm/bitops.h
15761@@ -49,7 +49,7 @@
15762 * a mask operation on a byte.
15763 */
15764 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15765-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15766+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15767 #define CONST_MASK(nr) (1 << ((nr) & 7))
15768
15769 /**
15770@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15771 */
15772 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15773 {
15774- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15775+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15776 }
15777
15778 /**
15779@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15780 */
15781 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15782 {
15783- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15784+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15785 }
15786
15787 /**
15788@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15789 */
15790 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15791 {
15792- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15793+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15794 }
15795
15796 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15797@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15798 *
15799 * Undefined if no bit exists, so code should check against 0 first.
15800 */
15801-static inline unsigned long __ffs(unsigned long word)
15802+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15803 {
15804 asm("rep; bsf %1,%0"
15805 : "=r" (word)
15806@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15807 *
15808 * Undefined if no zero exists, so code should check against ~0UL first.
15809 */
15810-static inline unsigned long ffz(unsigned long word)
15811+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15812 {
15813 asm("rep; bsf %1,%0"
15814 : "=r" (word)
15815@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15816 *
15817 * Undefined if no set bit exists, so code should check against 0 first.
15818 */
15819-static inline unsigned long __fls(unsigned long word)
15820+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15821 {
15822 asm("bsr %1,%0"
15823 : "=r" (word)
15824@@ -436,7 +436,7 @@ static inline int ffs(int x)
15825 * set bit if value is nonzero. The last (most significant) bit is
15826 * at position 32.
15827 */
15828-static inline int fls(int x)
15829+static inline int __intentional_overflow(-1) fls(int x)
15830 {
15831 int r;
15832
15833@@ -478,7 +478,7 @@ static inline int fls(int x)
15834 * at position 64.
15835 */
15836 #ifdef CONFIG_X86_64
15837-static __always_inline int fls64(__u64 x)
15838+static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
15839 {
15840 int bitpos = -1;
15841 /*
15842diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15843index 4fa687a..60f2d39 100644
15844--- a/arch/x86/include/asm/boot.h
15845+++ b/arch/x86/include/asm/boot.h
15846@@ -6,10 +6,15 @@
15847 #include <uapi/asm/boot.h>
15848
15849 /* Physical address where kernel should be loaded. */
15850-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15851+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15852 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15853 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15854
15855+#ifndef __ASSEMBLY__
15856+extern unsigned char __LOAD_PHYSICAL_ADDR[];
15857+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15858+#endif
15859+
15860 /* Minimum kernel alignment, as a power of two */
15861 #ifdef CONFIG_X86_64
15862 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15863diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15864index 48f99f1..d78ebf9 100644
15865--- a/arch/x86/include/asm/cache.h
15866+++ b/arch/x86/include/asm/cache.h
15867@@ -5,12 +5,13 @@
15868
15869 /* L1 cache line size */
15870 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15871-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15872+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15873
15874 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15875+#define __read_only __attribute__((__section__(".data..read_only")))
15876
15877 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15878-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15879+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15880
15881 #ifdef CONFIG_X86_VSMP
15882 #ifdef CONFIG_SMP
15883diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15884index 9863ee3..4a1f8e1 100644
15885--- a/arch/x86/include/asm/cacheflush.h
15886+++ b/arch/x86/include/asm/cacheflush.h
15887@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15888 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15889
15890 if (pg_flags == _PGMT_DEFAULT)
15891- return -1;
15892+ return ~0UL;
15893 else if (pg_flags == _PGMT_WC)
15894 return _PAGE_CACHE_WC;
15895 else if (pg_flags == _PGMT_UC_MINUS)
15896diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15897index cb4c73b..c473c29 100644
15898--- a/arch/x86/include/asm/calling.h
15899+++ b/arch/x86/include/asm/calling.h
15900@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15901 #define RSP 152
15902 #define SS 160
15903
15904-#define ARGOFFSET R11
15905-#define SWFRAME ORIG_RAX
15906+#define ARGOFFSET R15
15907
15908 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15909- subq $9*8+\addskip, %rsp
15910- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15911- movq_cfi rdi, 8*8
15912- movq_cfi rsi, 7*8
15913- movq_cfi rdx, 6*8
15914+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15915+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15916+ movq_cfi rdi, RDI
15917+ movq_cfi rsi, RSI
15918+ movq_cfi rdx, RDX
15919
15920 .if \save_rcx
15921- movq_cfi rcx, 5*8
15922+ movq_cfi rcx, RCX
15923 .endif
15924
15925- movq_cfi rax, 4*8
15926+ movq_cfi rax, RAX
15927
15928 .if \save_r891011
15929- movq_cfi r8, 3*8
15930- movq_cfi r9, 2*8
15931- movq_cfi r10, 1*8
15932- movq_cfi r11, 0*8
15933+ movq_cfi r8, R8
15934+ movq_cfi r9, R9
15935+ movq_cfi r10, R10
15936+ movq_cfi r11, R11
15937 .endif
15938
15939+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15940+ movq_cfi r12, R12
15941+#endif
15942+
15943 .endm
15944
15945-#define ARG_SKIP (9*8)
15946+#define ARG_SKIP ORIG_RAX
15947
15948 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15949 rstor_r8910=1, rstor_rdx=1
15950+
15951+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15952+ movq_cfi_restore R12, r12
15953+#endif
15954+
15955 .if \rstor_r11
15956- movq_cfi_restore 0*8, r11
15957+ movq_cfi_restore R11, r11
15958 .endif
15959
15960 .if \rstor_r8910
15961- movq_cfi_restore 1*8, r10
15962- movq_cfi_restore 2*8, r9
15963- movq_cfi_restore 3*8, r8
15964+ movq_cfi_restore R10, r10
15965+ movq_cfi_restore R9, r9
15966+ movq_cfi_restore R8, r8
15967 .endif
15968
15969 .if \rstor_rax
15970- movq_cfi_restore 4*8, rax
15971+ movq_cfi_restore RAX, rax
15972 .endif
15973
15974 .if \rstor_rcx
15975- movq_cfi_restore 5*8, rcx
15976+ movq_cfi_restore RCX, rcx
15977 .endif
15978
15979 .if \rstor_rdx
15980- movq_cfi_restore 6*8, rdx
15981+ movq_cfi_restore RDX, rdx
15982 .endif
15983
15984- movq_cfi_restore 7*8, rsi
15985- movq_cfi_restore 8*8, rdi
15986+ movq_cfi_restore RSI, rsi
15987+ movq_cfi_restore RDI, rdi
15988
15989- .if ARG_SKIP+\addskip > 0
15990- addq $ARG_SKIP+\addskip, %rsp
15991- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15992+ .if ORIG_RAX+\addskip > 0
15993+ addq $ORIG_RAX+\addskip, %rsp
15994+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15995 .endif
15996 .endm
15997
15998- .macro LOAD_ARGS offset, skiprax=0
15999- movq \offset(%rsp), %r11
16000- movq \offset+8(%rsp), %r10
16001- movq \offset+16(%rsp), %r9
16002- movq \offset+24(%rsp), %r8
16003- movq \offset+40(%rsp), %rcx
16004- movq \offset+48(%rsp), %rdx
16005- movq \offset+56(%rsp), %rsi
16006- movq \offset+64(%rsp), %rdi
16007+ .macro LOAD_ARGS skiprax=0
16008+ movq R11(%rsp), %r11
16009+ movq R10(%rsp), %r10
16010+ movq R9(%rsp), %r9
16011+ movq R8(%rsp), %r8
16012+ movq RCX(%rsp), %rcx
16013+ movq RDX(%rsp), %rdx
16014+ movq RSI(%rsp), %rsi
16015+ movq RDI(%rsp), %rdi
16016 .if \skiprax
16017 .else
16018- movq \offset+72(%rsp), %rax
16019+ movq RAX(%rsp), %rax
16020 .endif
16021 .endm
16022
16023-#define REST_SKIP (6*8)
16024-
16025 .macro SAVE_REST
16026- subq $REST_SKIP, %rsp
16027- CFI_ADJUST_CFA_OFFSET REST_SKIP
16028- movq_cfi rbx, 5*8
16029- movq_cfi rbp, 4*8
16030- movq_cfi r12, 3*8
16031- movq_cfi r13, 2*8
16032- movq_cfi r14, 1*8
16033- movq_cfi r15, 0*8
16034+ movq_cfi rbx, RBX
16035+ movq_cfi rbp, RBP
16036+
16037+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16038+ movq_cfi r12, R12
16039+#endif
16040+
16041+ movq_cfi r13, R13
16042+ movq_cfi r14, R14
16043+ movq_cfi r15, R15
16044 .endm
16045
16046 .macro RESTORE_REST
16047- movq_cfi_restore 0*8, r15
16048- movq_cfi_restore 1*8, r14
16049- movq_cfi_restore 2*8, r13
16050- movq_cfi_restore 3*8, r12
16051- movq_cfi_restore 4*8, rbp
16052- movq_cfi_restore 5*8, rbx
16053- addq $REST_SKIP, %rsp
16054- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16055+ movq_cfi_restore R15, r15
16056+ movq_cfi_restore R14, r14
16057+ movq_cfi_restore R13, r13
16058+
16059+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16060+ movq_cfi_restore R12, r12
16061+#endif
16062+
16063+ movq_cfi_restore RBP, rbp
16064+ movq_cfi_restore RBX, rbx
16065 .endm
16066
16067 .macro SAVE_ALL
16068diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16069index f50de69..2b0a458 100644
16070--- a/arch/x86/include/asm/checksum_32.h
16071+++ b/arch/x86/include/asm/checksum_32.h
16072@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16073 int len, __wsum sum,
16074 int *src_err_ptr, int *dst_err_ptr);
16075
16076+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16077+ int len, __wsum sum,
16078+ int *src_err_ptr, int *dst_err_ptr);
16079+
16080+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16081+ int len, __wsum sum,
16082+ int *src_err_ptr, int *dst_err_ptr);
16083+
16084 /*
16085 * Note: when you get a NULL pointer exception here this means someone
16086 * passed in an incorrect kernel address to one of these functions.
16087@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16088
16089 might_sleep();
16090 stac();
16091- ret = csum_partial_copy_generic((__force void *)src, dst,
16092+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16093 len, sum, err_ptr, NULL);
16094 clac();
16095
16096@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16097 might_sleep();
16098 if (access_ok(VERIFY_WRITE, dst, len)) {
16099 stac();
16100- ret = csum_partial_copy_generic(src, (__force void *)dst,
16101+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16102 len, sum, NULL, err_ptr);
16103 clac();
16104 return ret;
16105diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16106index d47786a..2d8883e 100644
16107--- a/arch/x86/include/asm/cmpxchg.h
16108+++ b/arch/x86/include/asm/cmpxchg.h
16109@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16110 __compiletime_error("Bad argument size for cmpxchg");
16111 extern void __xadd_wrong_size(void)
16112 __compiletime_error("Bad argument size for xadd");
16113+extern void __xadd_check_overflow_wrong_size(void)
16114+ __compiletime_error("Bad argument size for xadd_check_overflow");
16115 extern void __add_wrong_size(void)
16116 __compiletime_error("Bad argument size for add");
16117+extern void __add_check_overflow_wrong_size(void)
16118+ __compiletime_error("Bad argument size for add_check_overflow");
16119
16120 /*
16121 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16122@@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16123 __ret; \
16124 })
16125
16126+#ifdef CONFIG_PAX_REFCOUNT
16127+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16128+ ({ \
16129+ __typeof__ (*(ptr)) __ret = (arg); \
16130+ switch (sizeof(*(ptr))) { \
16131+ case __X86_CASE_L: \
16132+ asm volatile (lock #op "l %0, %1\n" \
16133+ "jno 0f\n" \
16134+ "mov %0,%1\n" \
16135+ "int $4\n0:\n" \
16136+ _ASM_EXTABLE(0b, 0b) \
16137+ : "+r" (__ret), "+m" (*(ptr)) \
16138+ : : "memory", "cc"); \
16139+ break; \
16140+ case __X86_CASE_Q: \
16141+ asm volatile (lock #op "q %q0, %1\n" \
16142+ "jno 0f\n" \
16143+ "mov %0,%1\n" \
16144+ "int $4\n0:\n" \
16145+ _ASM_EXTABLE(0b, 0b) \
16146+ : "+r" (__ret), "+m" (*(ptr)) \
16147+ : : "memory", "cc"); \
16148+ break; \
16149+ default: \
16150+ __ ## op ## _check_overflow_wrong_size(); \
16151+ } \
16152+ __ret; \
16153+ })
16154+#else
16155+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16156+#endif
16157+
16158 /*
16159 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16160 * Since this is generally used to protect other memory information, we
16161@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16162 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16163 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16164
16165+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16166+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16167+
16168 #define __add(ptr, inc, lock) \
16169 ({ \
16170 __typeof__ (*(ptr)) __ret = (inc); \
16171diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16172index 59c6c40..5e0b22c 100644
16173--- a/arch/x86/include/asm/compat.h
16174+++ b/arch/x86/include/asm/compat.h
16175@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16176 typedef u32 compat_uint_t;
16177 typedef u32 compat_ulong_t;
16178 typedef u64 __attribute__((aligned(4))) compat_u64;
16179-typedef u32 compat_uptr_t;
16180+typedef u32 __user compat_uptr_t;
16181
16182 struct compat_timespec {
16183 compat_time_t tv_sec;
16184diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16185index e265ff9..72c253b 100644
16186--- a/arch/x86/include/asm/cpufeature.h
16187+++ b/arch/x86/include/asm/cpufeature.h
16188@@ -203,7 +203,7 @@
16189 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16190 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16191 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16192-
16193+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16194
16195 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16196 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16197@@ -211,7 +211,7 @@
16198 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16199 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16200 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16201-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16202+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16203 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16204 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16205 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16206@@ -359,6 +359,7 @@ extern const char * const x86_power_flags[32];
16207 #undef cpu_has_centaur_mcr
16208 #define cpu_has_centaur_mcr 0
16209
16210+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16211 #endif /* CONFIG_X86_64 */
16212
16213 #if __GNUC__ >= 4
16214@@ -411,7 +412,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16215
16216 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16217 t_warn:
16218- warn_pre_alternatives();
16219+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16220+ warn_pre_alternatives();
16221 return false;
16222 #endif
16223
16224@@ -431,7 +433,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16225 ".section .discard,\"aw\",@progbits\n"
16226 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16227 ".previous\n"
16228- ".section .altinstr_replacement,\"ax\"\n"
16229+ ".section .altinstr_replacement,\"a\"\n"
16230 "3: movb $1,%0\n"
16231 "4:\n"
16232 ".previous\n"
16233@@ -468,7 +470,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16234 " .byte 2b - 1b\n" /* src len */
16235 " .byte 4f - 3f\n" /* repl len */
16236 ".previous\n"
16237- ".section .altinstr_replacement,\"ax\"\n"
16238+ ".section .altinstr_replacement,\"a\"\n"
16239 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16240 "4:\n"
16241 ".previous\n"
16242@@ -501,7 +503,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16243 ".section .discard,\"aw\",@progbits\n"
16244 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16245 ".previous\n"
16246- ".section .altinstr_replacement,\"ax\"\n"
16247+ ".section .altinstr_replacement,\"a\"\n"
16248 "3: movb $0,%0\n"
16249 "4:\n"
16250 ".previous\n"
16251@@ -515,7 +517,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16252 ".section .discard,\"aw\",@progbits\n"
16253 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16254 ".previous\n"
16255- ".section .altinstr_replacement,\"ax\"\n"
16256+ ".section .altinstr_replacement,\"a\"\n"
16257 "5: movb $1,%0\n"
16258 "6:\n"
16259 ".previous\n"
16260diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16261index 50d033a..37deb26 100644
16262--- a/arch/x86/include/asm/desc.h
16263+++ b/arch/x86/include/asm/desc.h
16264@@ -4,6 +4,7 @@
16265 #include <asm/desc_defs.h>
16266 #include <asm/ldt.h>
16267 #include <asm/mmu.h>
16268+#include <asm/pgtable.h>
16269
16270 #include <linux/smp.h>
16271 #include <linux/percpu.h>
16272@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16273
16274 desc->type = (info->read_exec_only ^ 1) << 1;
16275 desc->type |= info->contents << 2;
16276+ desc->type |= info->seg_not_present ^ 1;
16277
16278 desc->s = 1;
16279 desc->dpl = 0x3;
16280@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16281 }
16282
16283 extern struct desc_ptr idt_descr;
16284-extern gate_desc idt_table[];
16285-extern struct desc_ptr debug_idt_descr;
16286-extern gate_desc debug_idt_table[];
16287-
16288-struct gdt_page {
16289- struct desc_struct gdt[GDT_ENTRIES];
16290-} __attribute__((aligned(PAGE_SIZE)));
16291-
16292-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16293+extern gate_desc idt_table[IDT_ENTRIES];
16294+extern const struct desc_ptr debug_idt_descr;
16295+extern gate_desc debug_idt_table[IDT_ENTRIES];
16296
16297+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16298 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16299 {
16300- return per_cpu(gdt_page, cpu).gdt;
16301+ return cpu_gdt_table[cpu];
16302 }
16303
16304 #ifdef CONFIG_X86_64
16305@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16306 unsigned long base, unsigned dpl, unsigned flags,
16307 unsigned short seg)
16308 {
16309- gate->a = (seg << 16) | (base & 0xffff);
16310- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16311+ gate->gate.offset_low = base;
16312+ gate->gate.seg = seg;
16313+ gate->gate.reserved = 0;
16314+ gate->gate.type = type;
16315+ gate->gate.s = 0;
16316+ gate->gate.dpl = dpl;
16317+ gate->gate.p = 1;
16318+ gate->gate.offset_high = base >> 16;
16319 }
16320
16321 #endif
16322@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16323
16324 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16325 {
16326+ pax_open_kernel();
16327 memcpy(&idt[entry], gate, sizeof(*gate));
16328+ pax_close_kernel();
16329 }
16330
16331 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16332 {
16333+ pax_open_kernel();
16334 memcpy(&ldt[entry], desc, 8);
16335+ pax_close_kernel();
16336 }
16337
16338 static inline void
16339@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16340 default: size = sizeof(*gdt); break;
16341 }
16342
16343+ pax_open_kernel();
16344 memcpy(&gdt[entry], desc, size);
16345+ pax_close_kernel();
16346 }
16347
16348 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16349@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16350
16351 static inline void native_load_tr_desc(void)
16352 {
16353+ pax_open_kernel();
16354 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16355+ pax_close_kernel();
16356 }
16357
16358 static inline void native_load_gdt(const struct desc_ptr *dtr)
16359@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16360 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16361 unsigned int i;
16362
16363+ pax_open_kernel();
16364 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16365 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16366+ pax_close_kernel();
16367 }
16368
16369 #define _LDT_empty(info) \
16370@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16371 preempt_enable();
16372 }
16373
16374-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16375+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16376 {
16377 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16378 }
16379@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16380 }
16381
16382 #ifdef CONFIG_X86_64
16383-static inline void set_nmi_gate(int gate, void *addr)
16384+static inline void set_nmi_gate(int gate, const void *addr)
16385 {
16386 gate_desc s;
16387
16388@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16389 #endif
16390
16391 #ifdef CONFIG_TRACING
16392-extern struct desc_ptr trace_idt_descr;
16393-extern gate_desc trace_idt_table[];
16394+extern const struct desc_ptr trace_idt_descr;
16395+extern gate_desc trace_idt_table[IDT_ENTRIES];
16396 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16397 {
16398 write_idt_entry(trace_idt_table, entry, gate);
16399 }
16400
16401-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16402+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16403 unsigned dpl, unsigned ist, unsigned seg)
16404 {
16405 gate_desc s;
16406@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16407 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16408 #endif
16409
16410-static inline void _set_gate(int gate, unsigned type, void *addr,
16411+static inline void _set_gate(int gate, unsigned type, const void *addr,
16412 unsigned dpl, unsigned ist, unsigned seg)
16413 {
16414 gate_desc s;
16415@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16416 #define set_intr_gate(n, addr) \
16417 do { \
16418 BUG_ON((unsigned)n > 0xFF); \
16419- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16420+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16421 __KERNEL_CS); \
16422- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16423+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16424 0, 0, __KERNEL_CS); \
16425 } while (0)
16426
16427@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16428 /*
16429 * This routine sets up an interrupt gate at directory privilege level 3.
16430 */
16431-static inline void set_system_intr_gate(unsigned int n, void *addr)
16432+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16433 {
16434 BUG_ON((unsigned)n > 0xFF);
16435 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16436 }
16437
16438-static inline void set_system_trap_gate(unsigned int n, void *addr)
16439+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16440 {
16441 BUG_ON((unsigned)n > 0xFF);
16442 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16443 }
16444
16445-static inline void set_trap_gate(unsigned int n, void *addr)
16446+static inline void set_trap_gate(unsigned int n, const void *addr)
16447 {
16448 BUG_ON((unsigned)n > 0xFF);
16449 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16450@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16451 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16452 {
16453 BUG_ON((unsigned)n > 0xFF);
16454- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16455+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16456 }
16457
16458-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16459+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16460 {
16461 BUG_ON((unsigned)n > 0xFF);
16462 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16463 }
16464
16465-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16466+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16467 {
16468 BUG_ON((unsigned)n > 0xFF);
16469 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16470@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16471 else
16472 load_idt((const struct desc_ptr *)&idt_descr);
16473 }
16474+
16475+#ifdef CONFIG_X86_32
16476+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16477+{
16478+ struct desc_struct d;
16479+
16480+ if (likely(limit))
16481+ limit = (limit - 1UL) >> PAGE_SHIFT;
16482+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16483+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16484+}
16485+#endif
16486+
16487 #endif /* _ASM_X86_DESC_H */
16488diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16489index 278441f..b95a174 100644
16490--- a/arch/x86/include/asm/desc_defs.h
16491+++ b/arch/x86/include/asm/desc_defs.h
16492@@ -31,6 +31,12 @@ struct desc_struct {
16493 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16494 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16495 };
16496+ struct {
16497+ u16 offset_low;
16498+ u16 seg;
16499+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16500+ unsigned offset_high: 16;
16501+ } gate;
16502 };
16503 } __attribute__((packed));
16504
16505diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16506index ced283a..ffe04cc 100644
16507--- a/arch/x86/include/asm/div64.h
16508+++ b/arch/x86/include/asm/div64.h
16509@@ -39,7 +39,7 @@
16510 __mod; \
16511 })
16512
16513-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16514+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16515 {
16516 union {
16517 u64 v64;
16518diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16519index 2c71182..731124d 100644
16520--- a/arch/x86/include/asm/elf.h
16521+++ b/arch/x86/include/asm/elf.h
16522@@ -243,7 +243,25 @@ extern int force_personality32;
16523 the loader. We need to make sure that it is out of the way of the program
16524 that it will "exec", and that there is sufficient room for the brk. */
16525
16526+#ifdef CONFIG_PAX_SEGMEXEC
16527+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16528+#else
16529 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16530+#endif
16531+
16532+#ifdef CONFIG_PAX_ASLR
16533+#ifdef CONFIG_X86_32
16534+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16535+
16536+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16537+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16538+#else
16539+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16540+
16541+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16542+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16543+#endif
16544+#endif
16545
16546 /* This yields a mask that user programs can use to figure out what
16547 instruction set this CPU supports. This could be done in user space,
16548@@ -292,16 +310,12 @@ do { \
16549
16550 #define ARCH_DLINFO \
16551 do { \
16552- if (vdso_enabled) \
16553- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16554- (unsigned long)current->mm->context.vdso); \
16555+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16556 } while (0)
16557
16558 #define ARCH_DLINFO_X32 \
16559 do { \
16560- if (vdso_enabled) \
16561- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16562- (unsigned long)current->mm->context.vdso); \
16563+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16564 } while (0)
16565
16566 #define AT_SYSINFO 32
16567@@ -316,7 +330,7 @@ else \
16568
16569 #endif /* !CONFIG_X86_32 */
16570
16571-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16572+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16573
16574 #define VDSO_ENTRY \
16575 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16576@@ -332,9 +346,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16577 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16578 #define compat_arch_setup_additional_pages syscall32_setup_pages
16579
16580-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16581-#define arch_randomize_brk arch_randomize_brk
16582-
16583 /*
16584 * True on X86_32 or when emulating IA32 on X86_64
16585 */
16586diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16587index 77a99ac..39ff7f5 100644
16588--- a/arch/x86/include/asm/emergency-restart.h
16589+++ b/arch/x86/include/asm/emergency-restart.h
16590@@ -1,6 +1,6 @@
16591 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16592 #define _ASM_X86_EMERGENCY_RESTART_H
16593
16594-extern void machine_emergency_restart(void);
16595+extern void machine_emergency_restart(void) __noreturn;
16596
16597 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16598diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16599index 1c7eefe..d0e4702 100644
16600--- a/arch/x86/include/asm/floppy.h
16601+++ b/arch/x86/include/asm/floppy.h
16602@@ -229,18 +229,18 @@ static struct fd_routine_l {
16603 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16604 } fd_routine[] = {
16605 {
16606- request_dma,
16607- free_dma,
16608- get_dma_residue,
16609- dma_mem_alloc,
16610- hard_dma_setup
16611+ ._request_dma = request_dma,
16612+ ._free_dma = free_dma,
16613+ ._get_dma_residue = get_dma_residue,
16614+ ._dma_mem_alloc = dma_mem_alloc,
16615+ ._dma_setup = hard_dma_setup
16616 },
16617 {
16618- vdma_request_dma,
16619- vdma_nop,
16620- vdma_get_dma_residue,
16621- vdma_mem_alloc,
16622- vdma_dma_setup
16623+ ._request_dma = vdma_request_dma,
16624+ ._free_dma = vdma_nop,
16625+ ._get_dma_residue = vdma_get_dma_residue,
16626+ ._dma_mem_alloc = vdma_mem_alloc,
16627+ ._dma_setup = vdma_dma_setup
16628 }
16629 };
16630
16631diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16632index cea1c76..6c0d79b 100644
16633--- a/arch/x86/include/asm/fpu-internal.h
16634+++ b/arch/x86/include/asm/fpu-internal.h
16635@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16636 #define user_insn(insn, output, input...) \
16637 ({ \
16638 int err; \
16639+ pax_open_userland(); \
16640 asm volatile(ASM_STAC "\n" \
16641- "1:" #insn "\n\t" \
16642+ "1:" \
16643+ __copyuser_seg \
16644+ #insn "\n\t" \
16645 "2: " ASM_CLAC "\n" \
16646 ".section .fixup,\"ax\"\n" \
16647 "3: movl $-1,%[err]\n" \
16648@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16649 _ASM_EXTABLE(1b, 3b) \
16650 : [err] "=r" (err), output \
16651 : "0"(0), input); \
16652+ pax_close_userland(); \
16653 err; \
16654 })
16655
16656@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16657 "fnclex\n\t"
16658 "emms\n\t"
16659 "fildl %P[addr]" /* set F?P to defined value */
16660- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16661+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16662 }
16663
16664 return fpu_restore_checking(&tsk->thread.fpu);
16665diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16666index b4c1f54..e290c08 100644
16667--- a/arch/x86/include/asm/futex.h
16668+++ b/arch/x86/include/asm/futex.h
16669@@ -12,6 +12,7 @@
16670 #include <asm/smap.h>
16671
16672 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16673+ typecheck(u32 __user *, uaddr); \
16674 asm volatile("\t" ASM_STAC "\n" \
16675 "1:\t" insn "\n" \
16676 "2:\t" ASM_CLAC "\n" \
16677@@ -20,15 +21,16 @@
16678 "\tjmp\t2b\n" \
16679 "\t.previous\n" \
16680 _ASM_EXTABLE(1b, 3b) \
16681- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16682+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16683 : "i" (-EFAULT), "0" (oparg), "1" (0))
16684
16685 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16686+ typecheck(u32 __user *, uaddr); \
16687 asm volatile("\t" ASM_STAC "\n" \
16688 "1:\tmovl %2, %0\n" \
16689 "\tmovl\t%0, %3\n" \
16690 "\t" insn "\n" \
16691- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16692+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16693 "\tjnz\t1b\n" \
16694 "3:\t" ASM_CLAC "\n" \
16695 "\t.section .fixup,\"ax\"\n" \
16696@@ -38,7 +40,7 @@
16697 _ASM_EXTABLE(1b, 4b) \
16698 _ASM_EXTABLE(2b, 4b) \
16699 : "=&a" (oldval), "=&r" (ret), \
16700- "+m" (*uaddr), "=&r" (tem) \
16701+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16702 : "r" (oparg), "i" (-EFAULT), "1" (0))
16703
16704 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16705@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16706
16707 pagefault_disable();
16708
16709+ pax_open_userland();
16710 switch (op) {
16711 case FUTEX_OP_SET:
16712- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16713+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16714 break;
16715 case FUTEX_OP_ADD:
16716- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16717+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16718 uaddr, oparg);
16719 break;
16720 case FUTEX_OP_OR:
16721@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16722 default:
16723 ret = -ENOSYS;
16724 }
16725+ pax_close_userland();
16726
16727 pagefault_enable();
16728
16729diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16730index a307b75..ec74ca2 100644
16731--- a/arch/x86/include/asm/hw_irq.h
16732+++ b/arch/x86/include/asm/hw_irq.h
16733@@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
16734 extern void enable_IO_APIC(void);
16735
16736 /* Statistics */
16737-extern atomic_t irq_err_count;
16738-extern atomic_t irq_mis_count;
16739+extern atomic_unchecked_t irq_err_count;
16740+extern atomic_unchecked_t irq_mis_count;
16741
16742 /* EISA */
16743 extern void eisa_set_level_irq(unsigned int irq);
16744diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16745index a203659..9889f1c 100644
16746--- a/arch/x86/include/asm/i8259.h
16747+++ b/arch/x86/include/asm/i8259.h
16748@@ -62,7 +62,7 @@ struct legacy_pic {
16749 void (*init)(int auto_eoi);
16750 int (*irq_pending)(unsigned int irq);
16751 void (*make_irq)(unsigned int irq);
16752-};
16753+} __do_const;
16754
16755 extern struct legacy_pic *legacy_pic;
16756 extern struct legacy_pic null_legacy_pic;
16757diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16758index b8237d8..3e8864e 100644
16759--- a/arch/x86/include/asm/io.h
16760+++ b/arch/x86/include/asm/io.h
16761@@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16762 "m" (*(volatile type __force *)addr) barrier); }
16763
16764 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16765-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16766-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16767+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16768+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16769
16770 build_mmio_read(__readb, "b", unsigned char, "=q", )
16771-build_mmio_read(__readw, "w", unsigned short, "=r", )
16772-build_mmio_read(__readl, "l", unsigned int, "=r", )
16773+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16774+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16775
16776 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16777 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16778@@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
16779 * this function
16780 */
16781
16782-static inline phys_addr_t virt_to_phys(volatile void *address)
16783+static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
16784 {
16785 return __pa(address);
16786 }
16787@@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16788 return ioremap_nocache(offset, size);
16789 }
16790
16791-extern void iounmap(volatile void __iomem *addr);
16792+extern void iounmap(const volatile void __iomem *addr);
16793
16794 extern void set_iounmap_nonlazy(void);
16795
16796@@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
16797
16798 #include <linux/vmalloc.h>
16799
16800+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16801+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16802+{
16803+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16804+}
16805+
16806+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16807+{
16808+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16809+}
16810+
16811 /*
16812 * Convert a virtual cached pointer to an uncached pointer
16813 */
16814diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16815index bba3cf8..06bc8da 100644
16816--- a/arch/x86/include/asm/irqflags.h
16817+++ b/arch/x86/include/asm/irqflags.h
16818@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16819 sti; \
16820 sysexit
16821
16822+#define GET_CR0_INTO_RDI mov %cr0, %rdi
16823+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16824+#define GET_CR3_INTO_RDI mov %cr3, %rdi
16825+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16826+
16827 #else
16828 #define INTERRUPT_RETURN iret
16829 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16830diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16831index 9454c16..e4100e3 100644
16832--- a/arch/x86/include/asm/kprobes.h
16833+++ b/arch/x86/include/asm/kprobes.h
16834@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16835 #define RELATIVEJUMP_SIZE 5
16836 #define RELATIVECALL_OPCODE 0xe8
16837 #define RELATIVE_ADDR_SIZE 4
16838-#define MAX_STACK_SIZE 64
16839-#define MIN_STACK_SIZE(ADDR) \
16840- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16841- THREAD_SIZE - (unsigned long)(ADDR))) \
16842- ? (MAX_STACK_SIZE) \
16843- : (((unsigned long)current_thread_info()) + \
16844- THREAD_SIZE - (unsigned long)(ADDR)))
16845+#define MAX_STACK_SIZE 64UL
16846+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16847
16848 #define flush_insn_slot(p) do { } while (0)
16849
16850diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16851index 4ad6560..75c7bdd 100644
16852--- a/arch/x86/include/asm/local.h
16853+++ b/arch/x86/include/asm/local.h
16854@@ -10,33 +10,97 @@ typedef struct {
16855 atomic_long_t a;
16856 } local_t;
16857
16858+typedef struct {
16859+ atomic_long_unchecked_t a;
16860+} local_unchecked_t;
16861+
16862 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16863
16864 #define local_read(l) atomic_long_read(&(l)->a)
16865+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16866 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16867+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16868
16869 static inline void local_inc(local_t *l)
16870 {
16871- asm volatile(_ASM_INC "%0"
16872+ asm volatile(_ASM_INC "%0\n"
16873+
16874+#ifdef CONFIG_PAX_REFCOUNT
16875+ "jno 0f\n"
16876+ _ASM_DEC "%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_inc_unchecked(local_unchecked_t *l)
16885+{
16886+ asm volatile(_ASM_INC "%0\n"
16887 : "+m" (l->a.counter));
16888 }
16889
16890 static inline void local_dec(local_t *l)
16891 {
16892- asm volatile(_ASM_DEC "%0"
16893+ asm volatile(_ASM_DEC "%0\n"
16894+
16895+#ifdef CONFIG_PAX_REFCOUNT
16896+ "jno 0f\n"
16897+ _ASM_INC "%0\n"
16898+ "int $4\n0:\n"
16899+ _ASM_EXTABLE(0b, 0b)
16900+#endif
16901+
16902+ : "+m" (l->a.counter));
16903+}
16904+
16905+static inline void local_dec_unchecked(local_unchecked_t *l)
16906+{
16907+ asm volatile(_ASM_DEC "%0\n"
16908 : "+m" (l->a.counter));
16909 }
16910
16911 static inline void local_add(long i, local_t *l)
16912 {
16913- asm volatile(_ASM_ADD "%1,%0"
16914+ asm volatile(_ASM_ADD "%1,%0\n"
16915+
16916+#ifdef CONFIG_PAX_REFCOUNT
16917+ "jno 0f\n"
16918+ _ASM_SUB "%1,%0\n"
16919+ "int $4\n0:\n"
16920+ _ASM_EXTABLE(0b, 0b)
16921+#endif
16922+
16923+ : "+m" (l->a.counter)
16924+ : "ir" (i));
16925+}
16926+
16927+static inline void local_add_unchecked(long i, local_unchecked_t *l)
16928+{
16929+ asm volatile(_ASM_ADD "%1,%0\n"
16930 : "+m" (l->a.counter)
16931 : "ir" (i));
16932 }
16933
16934 static inline void local_sub(long i, local_t *l)
16935 {
16936- asm volatile(_ASM_SUB "%1,%0"
16937+ asm volatile(_ASM_SUB "%1,%0\n"
16938+
16939+#ifdef CONFIG_PAX_REFCOUNT
16940+ "jno 0f\n"
16941+ _ASM_ADD "%1,%0\n"
16942+ "int $4\n0:\n"
16943+ _ASM_EXTABLE(0b, 0b)
16944+#endif
16945+
16946+ : "+m" (l->a.counter)
16947+ : "ir" (i));
16948+}
16949+
16950+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16951+{
16952+ asm volatile(_ASM_SUB "%1,%0\n"
16953 : "+m" (l->a.counter)
16954 : "ir" (i));
16955 }
16956@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16957 */
16958 static inline int local_sub_and_test(long i, local_t *l)
16959 {
16960- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16961+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16962 }
16963
16964 /**
16965@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16966 */
16967 static inline int local_dec_and_test(local_t *l)
16968 {
16969- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16970+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16971 }
16972
16973 /**
16974@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16975 */
16976 static inline int local_inc_and_test(local_t *l)
16977 {
16978- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16979+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16980 }
16981
16982 /**
16983@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16984 */
16985 static inline int local_add_negative(long i, local_t *l)
16986 {
16987- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16988+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16989 }
16990
16991 /**
16992@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16993 static inline long local_add_return(long i, local_t *l)
16994 {
16995 long __i = i;
16996+ asm volatile(_ASM_XADD "%0, %1\n"
16997+
16998+#ifdef CONFIG_PAX_REFCOUNT
16999+ "jno 0f\n"
17000+ _ASM_MOV "%0,%1\n"
17001+ "int $4\n0:\n"
17002+ _ASM_EXTABLE(0b, 0b)
17003+#endif
17004+
17005+ : "+r" (i), "+m" (l->a.counter)
17006+ : : "memory");
17007+ return i + __i;
17008+}
17009+
17010+/**
17011+ * local_add_return_unchecked - add and return
17012+ * @i: integer value to add
17013+ * @l: pointer to type local_unchecked_t
17014+ *
17015+ * Atomically adds @i to @l and returns @i + @l
17016+ */
17017+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17018+{
17019+ long __i = i;
17020 asm volatile(_ASM_XADD "%0, %1;"
17021 : "+r" (i), "+m" (l->a.counter)
17022 : : "memory");
17023@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17024
17025 #define local_cmpxchg(l, o, n) \
17026 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17027+#define local_cmpxchg_unchecked(l, o, n) \
17028+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
17029 /* Always has a lock prefix */
17030 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17031
17032diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17033new file mode 100644
17034index 0000000..2bfd3ba
17035--- /dev/null
17036+++ b/arch/x86/include/asm/mman.h
17037@@ -0,0 +1,15 @@
17038+#ifndef _X86_MMAN_H
17039+#define _X86_MMAN_H
17040+
17041+#include <uapi/asm/mman.h>
17042+
17043+#ifdef __KERNEL__
17044+#ifndef __ASSEMBLY__
17045+#ifdef CONFIG_X86_32
17046+#define arch_mmap_check i386_mmap_check
17047+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17048+#endif
17049+#endif
17050+#endif
17051+
17052+#endif /* X86_MMAN_H */
17053diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17054index 5f55e69..e20bfb1 100644
17055--- a/arch/x86/include/asm/mmu.h
17056+++ b/arch/x86/include/asm/mmu.h
17057@@ -9,7 +9,7 @@
17058 * we put the segment information here.
17059 */
17060 typedef struct {
17061- void *ldt;
17062+ struct desc_struct *ldt;
17063 int size;
17064
17065 #ifdef CONFIG_X86_64
17066@@ -18,7 +18,19 @@ typedef struct {
17067 #endif
17068
17069 struct mutex lock;
17070- void *vdso;
17071+ unsigned long vdso;
17072+
17073+#ifdef CONFIG_X86_32
17074+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17075+ unsigned long user_cs_base;
17076+ unsigned long user_cs_limit;
17077+
17078+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17079+ cpumask_t cpu_user_cs_mask;
17080+#endif
17081+
17082+#endif
17083+#endif
17084 } mm_context_t;
17085
17086 #ifdef CONFIG_SMP
17087diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17088index be12c53..4d24039 100644
17089--- a/arch/x86/include/asm/mmu_context.h
17090+++ b/arch/x86/include/asm/mmu_context.h
17091@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17092
17093 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17094 {
17095+
17096+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17097+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
17098+ unsigned int i;
17099+ pgd_t *pgd;
17100+
17101+ pax_open_kernel();
17102+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
17103+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17104+ set_pgd_batched(pgd+i, native_make_pgd(0));
17105+ pax_close_kernel();
17106+ }
17107+#endif
17108+
17109 #ifdef CONFIG_SMP
17110 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17111 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17112@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17113 struct task_struct *tsk)
17114 {
17115 unsigned cpu = smp_processor_id();
17116+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17117+ int tlbstate = TLBSTATE_OK;
17118+#endif
17119
17120 if (likely(prev != next)) {
17121 #ifdef CONFIG_SMP
17122+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17123+ tlbstate = this_cpu_read(cpu_tlbstate.state);
17124+#endif
17125 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17126 this_cpu_write(cpu_tlbstate.active_mm, next);
17127 #endif
17128 cpumask_set_cpu(cpu, mm_cpumask(next));
17129
17130 /* Re-load page tables */
17131+#ifdef CONFIG_PAX_PER_CPU_PGD
17132+ pax_open_kernel();
17133+
17134+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17135+ if (static_cpu_has(X86_FEATURE_PCID))
17136+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17137+ else
17138+#endif
17139+
17140+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17141+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17142+ pax_close_kernel();
17143+ 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));
17144+
17145+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17146+ if (static_cpu_has(X86_FEATURE_PCID)) {
17147+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17148+ u64 descriptor[2];
17149+ descriptor[0] = PCID_USER;
17150+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17151+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17152+ descriptor[0] = PCID_KERNEL;
17153+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17154+ }
17155+ } else {
17156+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17157+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17158+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17159+ else
17160+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17161+ }
17162+ } else
17163+#endif
17164+
17165+ load_cr3(get_cpu_pgd(cpu, kernel));
17166+#else
17167 load_cr3(next->pgd);
17168+#endif
17169
17170 /* Stop flush ipis for the previous mm */
17171 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17172@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17173 /* Load the LDT, if the LDT is different: */
17174 if (unlikely(prev->context.ldt != next->context.ldt))
17175 load_LDT_nolock(&next->context);
17176+
17177+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17178+ if (!(__supported_pte_mask & _PAGE_NX)) {
17179+ smp_mb__before_clear_bit();
17180+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17181+ smp_mb__after_clear_bit();
17182+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17183+ }
17184+#endif
17185+
17186+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17187+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17188+ prev->context.user_cs_limit != next->context.user_cs_limit))
17189+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17190+#ifdef CONFIG_SMP
17191+ else if (unlikely(tlbstate != TLBSTATE_OK))
17192+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17193+#endif
17194+#endif
17195+
17196 }
17197+ else {
17198+
17199+#ifdef CONFIG_PAX_PER_CPU_PGD
17200+ pax_open_kernel();
17201+
17202+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17203+ if (static_cpu_has(X86_FEATURE_PCID))
17204+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17205+ else
17206+#endif
17207+
17208+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17209+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17210+ pax_close_kernel();
17211+ 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));
17212+
17213+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17214+ if (static_cpu_has(X86_FEATURE_PCID)) {
17215+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17216+ u64 descriptor[2];
17217+ descriptor[0] = PCID_USER;
17218+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17219+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17220+ descriptor[0] = PCID_KERNEL;
17221+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17222+ }
17223+ } else {
17224+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17225+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17226+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17227+ else
17228+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17229+ }
17230+ } else
17231+#endif
17232+
17233+ load_cr3(get_cpu_pgd(cpu, kernel));
17234+#endif
17235+
17236 #ifdef CONFIG_SMP
17237- else {
17238 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17239 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17240
17241@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17242 * tlb flush IPI delivery. We must reload CR3
17243 * to make sure to use no freed page tables.
17244 */
17245+
17246+#ifndef CONFIG_PAX_PER_CPU_PGD
17247 load_cr3(next->pgd);
17248+#endif
17249+
17250 load_LDT_nolock(&next->context);
17251+
17252+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17253+ if (!(__supported_pte_mask & _PAGE_NX))
17254+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17255+#endif
17256+
17257+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17258+#ifdef CONFIG_PAX_PAGEEXEC
17259+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17260+#endif
17261+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17262+#endif
17263+
17264 }
17265+#endif
17266 }
17267-#endif
17268 }
17269
17270 #define activate_mm(prev, next) \
17271diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17272index e3b7819..b257c64 100644
17273--- a/arch/x86/include/asm/module.h
17274+++ b/arch/x86/include/asm/module.h
17275@@ -5,6 +5,7 @@
17276
17277 #ifdef CONFIG_X86_64
17278 /* X86_64 does not define MODULE_PROC_FAMILY */
17279+#define MODULE_PROC_FAMILY ""
17280 #elif defined CONFIG_M486
17281 #define MODULE_PROC_FAMILY "486 "
17282 #elif defined CONFIG_M586
17283@@ -57,8 +58,20 @@
17284 #error unknown processor family
17285 #endif
17286
17287-#ifdef CONFIG_X86_32
17288-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17289+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17290+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17291+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17292+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17293+#else
17294+#define MODULE_PAX_KERNEXEC ""
17295 #endif
17296
17297+#ifdef CONFIG_PAX_MEMORY_UDEREF
17298+#define MODULE_PAX_UDEREF "UDEREF "
17299+#else
17300+#define MODULE_PAX_UDEREF ""
17301+#endif
17302+
17303+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17304+
17305 #endif /* _ASM_X86_MODULE_H */
17306diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17307index 5f2fc44..106caa6 100644
17308--- a/arch/x86/include/asm/nmi.h
17309+++ b/arch/x86/include/asm/nmi.h
17310@@ -36,26 +36,35 @@ enum {
17311
17312 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17313
17314+struct nmiaction;
17315+
17316+struct nmiwork {
17317+ const struct nmiaction *action;
17318+ u64 max_duration;
17319+ struct irq_work irq_work;
17320+};
17321+
17322 struct nmiaction {
17323 struct list_head list;
17324 nmi_handler_t handler;
17325- u64 max_duration;
17326- struct irq_work irq_work;
17327 unsigned long flags;
17328 const char *name;
17329-};
17330+ struct nmiwork *work;
17331+} __do_const;
17332
17333 #define register_nmi_handler(t, fn, fg, n, init...) \
17334 ({ \
17335- static struct nmiaction init fn##_na = { \
17336+ static struct nmiwork fn##_nw; \
17337+ static const struct nmiaction init fn##_na = { \
17338 .handler = (fn), \
17339 .name = (n), \
17340 .flags = (fg), \
17341+ .work = &fn##_nw, \
17342 }; \
17343 __register_nmi_handler((t), &fn##_na); \
17344 })
17345
17346-int __register_nmi_handler(unsigned int, struct nmiaction *);
17347+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17348
17349 void unregister_nmi_handler(unsigned int, const char *);
17350
17351diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17352index 775873d..04cd306 100644
17353--- a/arch/x86/include/asm/page.h
17354+++ b/arch/x86/include/asm/page.h
17355@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17356 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17357
17358 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17359+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17360
17361 #define __boot_va(x) __va(x)
17362 #define __boot_pa(x) __pa(x)
17363@@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17364 * virt_to_page(kaddr) returns a valid pointer if and only if
17365 * virt_addr_valid(kaddr) returns true.
17366 */
17367-#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17368 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17369 extern bool __virt_addr_valid(unsigned long kaddr);
17370 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17371
17372+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17373+#define virt_to_page(kaddr) \
17374+ ({ \
17375+ const void *__kaddr = (const void *)(kaddr); \
17376+ BUG_ON(!virt_addr_valid(__kaddr)); \
17377+ pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17378+ })
17379+#else
17380+#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17381+#endif
17382+
17383 #endif /* __ASSEMBLY__ */
17384
17385 #include <asm-generic/memory_model.h>
17386diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17387index 0f1ddee..e2fc3d1 100644
17388--- a/arch/x86/include/asm/page_64.h
17389+++ b/arch/x86/include/asm/page_64.h
17390@@ -7,9 +7,9 @@
17391
17392 /* duplicated to the one in bootmem.h */
17393 extern unsigned long max_pfn;
17394-extern unsigned long phys_base;
17395+extern const unsigned long phys_base;
17396
17397-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17398+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17399 {
17400 unsigned long y = x - __START_KERNEL_map;
17401
17402diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17403index cd6e1610..70f4418 100644
17404--- a/arch/x86/include/asm/paravirt.h
17405+++ b/arch/x86/include/asm/paravirt.h
17406@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17407 return (pmd_t) { ret };
17408 }
17409
17410-static inline pmdval_t pmd_val(pmd_t pmd)
17411+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17412 {
17413 pmdval_t ret;
17414
17415@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17416 val);
17417 }
17418
17419+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17420+{
17421+ pgdval_t val = native_pgd_val(pgd);
17422+
17423+ if (sizeof(pgdval_t) > sizeof(long))
17424+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17425+ val, (u64)val >> 32);
17426+ else
17427+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17428+ val);
17429+}
17430+
17431 static inline void pgd_clear(pgd_t *pgdp)
17432 {
17433 set_pgd(pgdp, __pgd(0));
17434@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17435 pv_mmu_ops.set_fixmap(idx, phys, flags);
17436 }
17437
17438+#ifdef CONFIG_PAX_KERNEXEC
17439+static inline unsigned long pax_open_kernel(void)
17440+{
17441+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17442+}
17443+
17444+static inline unsigned long pax_close_kernel(void)
17445+{
17446+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17447+}
17448+#else
17449+static inline unsigned long pax_open_kernel(void) { return 0; }
17450+static inline unsigned long pax_close_kernel(void) { return 0; }
17451+#endif
17452+
17453 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17454
17455 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17456@@ -906,7 +933,7 @@ extern void default_banner(void);
17457
17458 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17459 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17460-#define PARA_INDIRECT(addr) *%cs:addr
17461+#define PARA_INDIRECT(addr) *%ss:addr
17462 #endif
17463
17464 #define INTERRUPT_RETURN \
17465@@ -981,6 +1008,21 @@ extern void default_banner(void);
17466 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17467 CLBR_NONE, \
17468 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17469+
17470+#define GET_CR0_INTO_RDI \
17471+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17472+ mov %rax,%rdi
17473+
17474+#define SET_RDI_INTO_CR0 \
17475+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17476+
17477+#define GET_CR3_INTO_RDI \
17478+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17479+ mov %rax,%rdi
17480+
17481+#define SET_RDI_INTO_CR3 \
17482+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17483+
17484 #endif /* CONFIG_X86_32 */
17485
17486 #endif /* __ASSEMBLY__ */
17487diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17488index 7549b8b..f0edfda 100644
17489--- a/arch/x86/include/asm/paravirt_types.h
17490+++ b/arch/x86/include/asm/paravirt_types.h
17491@@ -84,7 +84,7 @@ struct pv_init_ops {
17492 */
17493 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17494 unsigned long addr, unsigned len);
17495-};
17496+} __no_const __no_randomize_layout;
17497
17498
17499 struct pv_lazy_ops {
17500@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17501 void (*enter)(void);
17502 void (*leave)(void);
17503 void (*flush)(void);
17504-};
17505+} __no_randomize_layout;
17506
17507 struct pv_time_ops {
17508 unsigned long long (*sched_clock)(void);
17509 unsigned long long (*steal_clock)(int cpu);
17510 unsigned long (*get_tsc_khz)(void);
17511-};
17512+} __no_const __no_randomize_layout;
17513
17514 struct pv_cpu_ops {
17515 /* hooks for various privileged instructions */
17516@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17517
17518 void (*start_context_switch)(struct task_struct *prev);
17519 void (*end_context_switch)(struct task_struct *next);
17520-};
17521+} __no_const __no_randomize_layout;
17522
17523 struct pv_irq_ops {
17524 /*
17525@@ -215,7 +215,7 @@ struct pv_irq_ops {
17526 #ifdef CONFIG_X86_64
17527 void (*adjust_exception_frame)(void);
17528 #endif
17529-};
17530+} __no_randomize_layout;
17531
17532 struct pv_apic_ops {
17533 #ifdef CONFIG_X86_LOCAL_APIC
17534@@ -223,7 +223,7 @@ struct pv_apic_ops {
17535 unsigned long start_eip,
17536 unsigned long start_esp);
17537 #endif
17538-};
17539+} __no_const __no_randomize_layout;
17540
17541 struct pv_mmu_ops {
17542 unsigned long (*read_cr2)(void);
17543@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17544 struct paravirt_callee_save make_pud;
17545
17546 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17547+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17548 #endif /* PAGETABLE_LEVELS == 4 */
17549 #endif /* PAGETABLE_LEVELS >= 3 */
17550
17551@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17552 an mfn. We can tell which is which from the index. */
17553 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17554 phys_addr_t phys, pgprot_t flags);
17555-};
17556+
17557+#ifdef CONFIG_PAX_KERNEXEC
17558+ unsigned long (*pax_open_kernel)(void);
17559+ unsigned long (*pax_close_kernel)(void);
17560+#endif
17561+
17562+} __no_randomize_layout;
17563
17564 struct arch_spinlock;
17565 #ifdef CONFIG_SMP
17566@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17567 struct pv_lock_ops {
17568 struct paravirt_callee_save lock_spinning;
17569 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17570-};
17571+} __no_randomize_layout;
17572
17573 /* This contains all the paravirt structures: we get a convenient
17574 * number for each function using the offset which we use to indicate
17575- * what to patch. */
17576+ * what to patch.
17577+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17578+ */
17579+
17580 struct paravirt_patch_template {
17581 struct pv_init_ops pv_init_ops;
17582 struct pv_time_ops pv_time_ops;
17583@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17584 struct pv_apic_ops pv_apic_ops;
17585 struct pv_mmu_ops pv_mmu_ops;
17586 struct pv_lock_ops pv_lock_ops;
17587-};
17588+} __no_randomize_layout;
17589
17590 extern struct pv_info pv_info;
17591 extern struct pv_init_ops pv_init_ops;
17592diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17593index c4412e9..90e88c5 100644
17594--- a/arch/x86/include/asm/pgalloc.h
17595+++ b/arch/x86/include/asm/pgalloc.h
17596@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17597 pmd_t *pmd, pte_t *pte)
17598 {
17599 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17600+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17601+}
17602+
17603+static inline void pmd_populate_user(struct mm_struct *mm,
17604+ pmd_t *pmd, pte_t *pte)
17605+{
17606+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17607 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17608 }
17609
17610@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17611
17612 #ifdef CONFIG_X86_PAE
17613 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17614+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17615+{
17616+ pud_populate(mm, pudp, pmd);
17617+}
17618 #else /* !CONFIG_X86_PAE */
17619 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17620 {
17621 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17622 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17623 }
17624+
17625+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17626+{
17627+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17628+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17629+}
17630 #endif /* CONFIG_X86_PAE */
17631
17632 #if PAGETABLE_LEVELS > 3
17633@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17634 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17635 }
17636
17637+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17638+{
17639+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17640+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17641+}
17642+
17643 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17644 {
17645 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17646diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17647index 0d193e2..bf59aeb 100644
17648--- a/arch/x86/include/asm/pgtable-2level.h
17649+++ b/arch/x86/include/asm/pgtable-2level.h
17650@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17651
17652 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17653 {
17654+ pax_open_kernel();
17655 *pmdp = pmd;
17656+ pax_close_kernel();
17657 }
17658
17659 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17660diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17661index 81bb91b..9392125 100644
17662--- a/arch/x86/include/asm/pgtable-3level.h
17663+++ b/arch/x86/include/asm/pgtable-3level.h
17664@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17665
17666 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17667 {
17668+ pax_open_kernel();
17669 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17670+ pax_close_kernel();
17671 }
17672
17673 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17674 {
17675+ pax_open_kernel();
17676 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17677+ pax_close_kernel();
17678 }
17679
17680 /*
17681diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17682index b459ddf..b44081b 100644
17683--- a/arch/x86/include/asm/pgtable.h
17684+++ b/arch/x86/include/asm/pgtable.h
17685@@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17686
17687 #ifndef __PAGETABLE_PUD_FOLDED
17688 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17689+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17690 #define pgd_clear(pgd) native_pgd_clear(pgd)
17691 #endif
17692
17693@@ -83,12 +84,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17694
17695 #define arch_end_context_switch(prev) do {} while(0)
17696
17697+#define pax_open_kernel() native_pax_open_kernel()
17698+#define pax_close_kernel() native_pax_close_kernel()
17699 #endif /* CONFIG_PARAVIRT */
17700
17701+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17702+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17703+
17704+#ifdef CONFIG_PAX_KERNEXEC
17705+static inline unsigned long native_pax_open_kernel(void)
17706+{
17707+ unsigned long cr0;
17708+
17709+ preempt_disable();
17710+ barrier();
17711+ cr0 = read_cr0() ^ X86_CR0_WP;
17712+ BUG_ON(cr0 & X86_CR0_WP);
17713+ write_cr0(cr0);
17714+ return cr0 ^ X86_CR0_WP;
17715+}
17716+
17717+static inline unsigned long native_pax_close_kernel(void)
17718+{
17719+ unsigned long cr0;
17720+
17721+ cr0 = read_cr0() ^ X86_CR0_WP;
17722+ BUG_ON(!(cr0 & X86_CR0_WP));
17723+ write_cr0(cr0);
17724+ barrier();
17725+ preempt_enable_no_resched();
17726+ return cr0 ^ X86_CR0_WP;
17727+}
17728+#else
17729+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17730+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17731+#endif
17732+
17733 /*
17734 * The following only work if pte_present() is true.
17735 * Undefined behaviour if not..
17736 */
17737+static inline int pte_user(pte_t pte)
17738+{
17739+ return pte_val(pte) & _PAGE_USER;
17740+}
17741+
17742 static inline int pte_dirty(pte_t pte)
17743 {
17744 return pte_flags(pte) & _PAGE_DIRTY;
17745@@ -149,6 +189,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17746 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17747 }
17748
17749+static inline unsigned long pgd_pfn(pgd_t pgd)
17750+{
17751+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17752+}
17753+
17754 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17755
17756 static inline int pmd_large(pmd_t pte)
17757@@ -202,9 +247,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17758 return pte_clear_flags(pte, _PAGE_RW);
17759 }
17760
17761+static inline pte_t pte_mkread(pte_t pte)
17762+{
17763+ return __pte(pte_val(pte) | _PAGE_USER);
17764+}
17765+
17766 static inline pte_t pte_mkexec(pte_t pte)
17767 {
17768- return pte_clear_flags(pte, _PAGE_NX);
17769+#ifdef CONFIG_X86_PAE
17770+ if (__supported_pte_mask & _PAGE_NX)
17771+ return pte_clear_flags(pte, _PAGE_NX);
17772+ else
17773+#endif
17774+ return pte_set_flags(pte, _PAGE_USER);
17775+}
17776+
17777+static inline pte_t pte_exprotect(pte_t pte)
17778+{
17779+#ifdef CONFIG_X86_PAE
17780+ if (__supported_pte_mask & _PAGE_NX)
17781+ return pte_set_flags(pte, _PAGE_NX);
17782+ else
17783+#endif
17784+ return pte_clear_flags(pte, _PAGE_USER);
17785 }
17786
17787 static inline pte_t pte_mkdirty(pte_t pte)
17788@@ -431,6 +496,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17789 #endif
17790
17791 #ifndef __ASSEMBLY__
17792+
17793+#ifdef CONFIG_PAX_PER_CPU_PGD
17794+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17795+enum cpu_pgd_type {kernel = 0, user = 1};
17796+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17797+{
17798+ return cpu_pgd[cpu][type];
17799+}
17800+#endif
17801+
17802 #include <linux/mm_types.h>
17803 #include <linux/mmdebug.h>
17804 #include <linux/log2.h>
17805@@ -571,7 +646,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17806 * Currently stuck as a macro due to indirect forward reference to
17807 * linux/mmzone.h's __section_mem_map_addr() definition:
17808 */
17809-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17810+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17811
17812 /* Find an entry in the second-level page table.. */
17813 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17814@@ -611,7 +686,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17815 * Currently stuck as a macro due to indirect forward reference to
17816 * linux/mmzone.h's __section_mem_map_addr() definition:
17817 */
17818-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17819+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17820
17821 /* to find an entry in a page-table-directory. */
17822 static inline unsigned long pud_index(unsigned long address)
17823@@ -626,7 +701,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17824
17825 static inline int pgd_bad(pgd_t pgd)
17826 {
17827- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17828+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17829 }
17830
17831 static inline int pgd_none(pgd_t pgd)
17832@@ -649,7 +724,12 @@ static inline int pgd_none(pgd_t pgd)
17833 * pgd_offset() returns a (pgd_t *)
17834 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17835 */
17836-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17837+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17838+
17839+#ifdef CONFIG_PAX_PER_CPU_PGD
17840+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17841+#endif
17842+
17843 /*
17844 * a shortcut which implies the use of the kernel's pgd, instead
17845 * of a process's
17846@@ -660,6 +740,23 @@ static inline int pgd_none(pgd_t pgd)
17847 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17848 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17849
17850+#ifdef CONFIG_X86_32
17851+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17852+#else
17853+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17854+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17855+
17856+#ifdef CONFIG_PAX_MEMORY_UDEREF
17857+#ifdef __ASSEMBLY__
17858+#define pax_user_shadow_base pax_user_shadow_base(%rip)
17859+#else
17860+extern unsigned long pax_user_shadow_base;
17861+extern pgdval_t clone_pgd_mask;
17862+#endif
17863+#endif
17864+
17865+#endif
17866+
17867 #ifndef __ASSEMBLY__
17868
17869 extern int direct_gbpages;
17870@@ -826,11 +923,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17871 * dst and src can be on the same page, but the range must not overlap,
17872 * and must not cross a page boundary.
17873 */
17874-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17875+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17876 {
17877- memcpy(dst, src, count * sizeof(pgd_t));
17878+ pax_open_kernel();
17879+ while (count--)
17880+ *dst++ = *src++;
17881+ pax_close_kernel();
17882 }
17883
17884+#ifdef CONFIG_PAX_PER_CPU_PGD
17885+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17886+#endif
17887+
17888+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17889+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17890+#else
17891+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17892+#endif
17893+
17894 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17895 static inline int page_level_shift(enum pg_level level)
17896 {
17897diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17898index 9ee3221..b979c6b 100644
17899--- a/arch/x86/include/asm/pgtable_32.h
17900+++ b/arch/x86/include/asm/pgtable_32.h
17901@@ -25,9 +25,6 @@
17902 struct mm_struct;
17903 struct vm_area_struct;
17904
17905-extern pgd_t swapper_pg_dir[1024];
17906-extern pgd_t initial_page_table[1024];
17907-
17908 static inline void pgtable_cache_init(void) { }
17909 static inline void check_pgt_cache(void) { }
17910 void paging_init(void);
17911@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17912 # include <asm/pgtable-2level.h>
17913 #endif
17914
17915+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17916+extern pgd_t initial_page_table[PTRS_PER_PGD];
17917+#ifdef CONFIG_X86_PAE
17918+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17919+#endif
17920+
17921 #if defined(CONFIG_HIGHPTE)
17922 #define pte_offset_map(dir, address) \
17923 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17924@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17925 /* Clear a kernel PTE and flush it from the TLB */
17926 #define kpte_clear_flush(ptep, vaddr) \
17927 do { \
17928+ pax_open_kernel(); \
17929 pte_clear(&init_mm, (vaddr), (ptep)); \
17930+ pax_close_kernel(); \
17931 __flush_tlb_one((vaddr)); \
17932 } while (0)
17933
17934 #endif /* !__ASSEMBLY__ */
17935
17936+#define HAVE_ARCH_UNMAPPED_AREA
17937+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17938+
17939 /*
17940 * kern_addr_valid() is (1) for FLATMEM and (0) for
17941 * SPARSEMEM and DISCONTIGMEM
17942diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17943index ed5903b..c7fe163 100644
17944--- a/arch/x86/include/asm/pgtable_32_types.h
17945+++ b/arch/x86/include/asm/pgtable_32_types.h
17946@@ -8,7 +8,7 @@
17947 */
17948 #ifdef CONFIG_X86_PAE
17949 # include <asm/pgtable-3level_types.h>
17950-# define PMD_SIZE (1UL << PMD_SHIFT)
17951+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17952 # define PMD_MASK (~(PMD_SIZE - 1))
17953 #else
17954 # include <asm/pgtable-2level_types.h>
17955@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17956 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17957 #endif
17958
17959+#ifdef CONFIG_PAX_KERNEXEC
17960+#ifndef __ASSEMBLY__
17961+extern unsigned char MODULES_EXEC_VADDR[];
17962+extern unsigned char MODULES_EXEC_END[];
17963+#endif
17964+#include <asm/boot.h>
17965+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17966+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17967+#else
17968+#define ktla_ktva(addr) (addr)
17969+#define ktva_ktla(addr) (addr)
17970+#endif
17971+
17972 #define MODULES_VADDR VMALLOC_START
17973 #define MODULES_END VMALLOC_END
17974 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17975diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17976index e22c1db..23a625a 100644
17977--- a/arch/x86/include/asm/pgtable_64.h
17978+++ b/arch/x86/include/asm/pgtable_64.h
17979@@ -16,10 +16,14 @@
17980
17981 extern pud_t level3_kernel_pgt[512];
17982 extern pud_t level3_ident_pgt[512];
17983+extern pud_t level3_vmalloc_start_pgt[512];
17984+extern pud_t level3_vmalloc_end_pgt[512];
17985+extern pud_t level3_vmemmap_pgt[512];
17986+extern pud_t level2_vmemmap_pgt[512];
17987 extern pmd_t level2_kernel_pgt[512];
17988 extern pmd_t level2_fixmap_pgt[512];
17989-extern pmd_t level2_ident_pgt[512];
17990-extern pgd_t init_level4_pgt[];
17991+extern pmd_t level2_ident_pgt[512*2];
17992+extern pgd_t init_level4_pgt[512];
17993
17994 #define swapper_pg_dir init_level4_pgt
17995
17996@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17997
17998 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17999 {
18000+ pax_open_kernel();
18001 *pmdp = pmd;
18002+ pax_close_kernel();
18003 }
18004
18005 static inline void native_pmd_clear(pmd_t *pmd)
18006@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18007
18008 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18009 {
18010+ pax_open_kernel();
18011 *pudp = pud;
18012+ pax_close_kernel();
18013 }
18014
18015 static inline void native_pud_clear(pud_t *pud)
18016@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18017
18018 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18019 {
18020+ pax_open_kernel();
18021+ *pgdp = pgd;
18022+ pax_close_kernel();
18023+}
18024+
18025+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18026+{
18027 *pgdp = pgd;
18028 }
18029
18030diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18031index c883bf7..19970b3 100644
18032--- a/arch/x86/include/asm/pgtable_64_types.h
18033+++ b/arch/x86/include/asm/pgtable_64_types.h
18034@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
18035 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18036 #define MODULES_END _AC(0xffffffffff000000, UL)
18037 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18038+#define MODULES_EXEC_VADDR MODULES_VADDR
18039+#define MODULES_EXEC_END MODULES_END
18040+
18041+#define ktla_ktva(addr) (addr)
18042+#define ktva_ktla(addr) (addr)
18043
18044 #define EARLY_DYNAMIC_PAGE_TABLES 64
18045
18046diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18047index eb3d449..8d95316 100644
18048--- a/arch/x86/include/asm/pgtable_types.h
18049+++ b/arch/x86/include/asm/pgtable_types.h
18050@@ -16,13 +16,12 @@
18051 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
18052 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
18053 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
18054-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
18055+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
18056 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
18057 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
18058 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
18059-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
18060-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
18061-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
18062+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
18063+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
18064 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
18065
18066 /* If _PAGE_BIT_PRESENT is clear, we use these: */
18067@@ -40,7 +39,6 @@
18068 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
18069 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
18070 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
18071-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
18072 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
18073 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
18074 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
18075@@ -87,8 +85,10 @@
18076
18077 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18078 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18079-#else
18080+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18081 #define _PAGE_NX (_AT(pteval_t, 0))
18082+#else
18083+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18084 #endif
18085
18086 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18087@@ -147,6 +147,9 @@
18088 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18089 _PAGE_ACCESSED)
18090
18091+#define PAGE_READONLY_NOEXEC PAGE_READONLY
18092+#define PAGE_SHARED_NOEXEC PAGE_SHARED
18093+
18094 #define __PAGE_KERNEL_EXEC \
18095 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18096 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18097@@ -157,7 +160,7 @@
18098 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18099 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18100 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18101-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18102+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18103 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18104 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18105 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18106@@ -214,7 +217,7 @@
18107 #ifdef CONFIG_X86_64
18108 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18109 #else
18110-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18111+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18112 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18113 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18114 #endif
18115@@ -253,7 +256,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18116 {
18117 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18118 }
18119+#endif
18120
18121+#if PAGETABLE_LEVELS == 3
18122+#include <asm-generic/pgtable-nopud.h>
18123+#endif
18124+
18125+#if PAGETABLE_LEVELS == 2
18126+#include <asm-generic/pgtable-nopmd.h>
18127+#endif
18128+
18129+#ifndef __ASSEMBLY__
18130 #if PAGETABLE_LEVELS > 3
18131 typedef struct { pudval_t pud; } pud_t;
18132
18133@@ -267,8 +280,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18134 return pud.pud;
18135 }
18136 #else
18137-#include <asm-generic/pgtable-nopud.h>
18138-
18139 static inline pudval_t native_pud_val(pud_t pud)
18140 {
18141 return native_pgd_val(pud.pgd);
18142@@ -288,8 +299,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18143 return pmd.pmd;
18144 }
18145 #else
18146-#include <asm-generic/pgtable-nopmd.h>
18147-
18148 static inline pmdval_t native_pmd_val(pmd_t pmd)
18149 {
18150 return native_pgd_val(pmd.pud.pgd);
18151@@ -329,7 +338,6 @@ typedef struct page *pgtable_t;
18152
18153 extern pteval_t __supported_pte_mask;
18154 extern void set_nx(void);
18155-extern int nx_enabled;
18156
18157 #define pgprot_writecombine pgprot_writecombine
18158 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18159diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18160index 7024c12..71c46b9 100644
18161--- a/arch/x86/include/asm/preempt.h
18162+++ b/arch/x86/include/asm/preempt.h
18163@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18164 */
18165 static __always_inline bool __preempt_count_dec_and_test(void)
18166 {
18167- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18168+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18169 }
18170
18171 /*
18172diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18173index a4ea023..33aa874 100644
18174--- a/arch/x86/include/asm/processor.h
18175+++ b/arch/x86/include/asm/processor.h
18176@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18177 /* Index into per_cpu list: */
18178 u16 cpu_index;
18179 u32 microcode;
18180-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18181+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18182
18183 #define X86_VENDOR_INTEL 0
18184 #define X86_VENDOR_CYRIX 1
18185@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18186 : "memory");
18187 }
18188
18189+/* invpcid (%rdx),%rax */
18190+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18191+
18192+#define INVPCID_SINGLE_ADDRESS 0UL
18193+#define INVPCID_SINGLE_CONTEXT 1UL
18194+#define INVPCID_ALL_GLOBAL 2UL
18195+#define INVPCID_ALL_MONGLOBAL 3UL
18196+
18197+#define PCID_KERNEL 0UL
18198+#define PCID_USER 1UL
18199+#define PCID_NOFLUSH (1UL << 63)
18200+
18201 static inline void load_cr3(pgd_t *pgdir)
18202 {
18203- write_cr3(__pa(pgdir));
18204+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18205 }
18206
18207 #ifdef CONFIG_X86_32
18208@@ -283,7 +295,7 @@ struct tss_struct {
18209
18210 } ____cacheline_aligned;
18211
18212-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18213+extern struct tss_struct init_tss[NR_CPUS];
18214
18215 /*
18216 * Save the original ist values for checking stack pointers during debugging
18217@@ -479,6 +491,7 @@ struct thread_struct {
18218 unsigned short ds;
18219 unsigned short fsindex;
18220 unsigned short gsindex;
18221+ unsigned short ss;
18222 #endif
18223 #ifdef CONFIG_X86_32
18224 unsigned long ip;
18225@@ -588,29 +601,8 @@ static inline void load_sp0(struct tss_struct *tss,
18226 extern unsigned long mmu_cr4_features;
18227 extern u32 *trampoline_cr4_features;
18228
18229-static inline void set_in_cr4(unsigned long mask)
18230-{
18231- unsigned long cr4;
18232-
18233- mmu_cr4_features |= mask;
18234- if (trampoline_cr4_features)
18235- *trampoline_cr4_features = mmu_cr4_features;
18236- cr4 = read_cr4();
18237- cr4 |= mask;
18238- write_cr4(cr4);
18239-}
18240-
18241-static inline void clear_in_cr4(unsigned long mask)
18242-{
18243- unsigned long cr4;
18244-
18245- mmu_cr4_features &= ~mask;
18246- if (trampoline_cr4_features)
18247- *trampoline_cr4_features = mmu_cr4_features;
18248- cr4 = read_cr4();
18249- cr4 &= ~mask;
18250- write_cr4(cr4);
18251-}
18252+extern void set_in_cr4(unsigned long mask);
18253+extern void clear_in_cr4(unsigned long mask);
18254
18255 typedef struct {
18256 unsigned long seg;
18257@@ -836,11 +828,18 @@ static inline void spin_lock_prefetch(const void *x)
18258 */
18259 #define TASK_SIZE PAGE_OFFSET
18260 #define TASK_SIZE_MAX TASK_SIZE
18261+
18262+#ifdef CONFIG_PAX_SEGMEXEC
18263+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18264+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18265+#else
18266 #define STACK_TOP TASK_SIZE
18267-#define STACK_TOP_MAX STACK_TOP
18268+#endif
18269+
18270+#define STACK_TOP_MAX TASK_SIZE
18271
18272 #define INIT_THREAD { \
18273- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18274+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18275 .vm86_info = NULL, \
18276 .sysenter_cs = __KERNEL_CS, \
18277 .io_bitmap_ptr = NULL, \
18278@@ -854,7 +853,7 @@ static inline void spin_lock_prefetch(const void *x)
18279 */
18280 #define INIT_TSS { \
18281 .x86_tss = { \
18282- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18283+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18284 .ss0 = __KERNEL_DS, \
18285 .ss1 = __KERNEL_CS, \
18286 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18287@@ -865,11 +864,7 @@ static inline void spin_lock_prefetch(const void *x)
18288 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18289
18290 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18291-#define KSTK_TOP(info) \
18292-({ \
18293- unsigned long *__ptr = (unsigned long *)(info); \
18294- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18295-})
18296+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18297
18298 /*
18299 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18300@@ -884,7 +879,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18301 #define task_pt_regs(task) \
18302 ({ \
18303 struct pt_regs *__regs__; \
18304- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18305+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18306 __regs__ - 1; \
18307 })
18308
18309@@ -894,13 +889,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18310 /*
18311 * User space process size. 47bits minus one guard page.
18312 */
18313-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18314+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18315
18316 /* This decides where the kernel will search for a free chunk of vm
18317 * space during mmap's.
18318 */
18319 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18320- 0xc0000000 : 0xFFFFe000)
18321+ 0xc0000000 : 0xFFFFf000)
18322
18323 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18324 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18325@@ -911,11 +906,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18326 #define STACK_TOP_MAX TASK_SIZE_MAX
18327
18328 #define INIT_THREAD { \
18329- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18330+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18331 }
18332
18333 #define INIT_TSS { \
18334- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18335+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18336 }
18337
18338 /*
18339@@ -943,6 +938,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18340 */
18341 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18342
18343+#ifdef CONFIG_PAX_SEGMEXEC
18344+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18345+#endif
18346+
18347 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18348
18349 /* Get/set a process' ability to use the timestamp counter instruction */
18350@@ -969,7 +968,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18351 return 0;
18352 }
18353
18354-extern unsigned long arch_align_stack(unsigned long sp);
18355+#define arch_align_stack(x) ((x) & ~0xfUL)
18356 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18357
18358 void default_idle(void);
18359@@ -979,6 +978,6 @@ bool xen_set_default_idle(void);
18360 #define xen_set_default_idle 0
18361 #endif
18362
18363-void stop_this_cpu(void *dummy);
18364+void stop_this_cpu(void *dummy) __noreturn;
18365 void df_debug(struct pt_regs *regs, long error_code);
18366 #endif /* _ASM_X86_PROCESSOR_H */
18367diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18368index 6205f0c..b31a4a4 100644
18369--- a/arch/x86/include/asm/ptrace.h
18370+++ b/arch/x86/include/asm/ptrace.h
18371@@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18372 }
18373
18374 /*
18375- * user_mode_vm(regs) determines whether a register set came from user mode.
18376+ * user_mode(regs) determines whether a register set came from user mode.
18377 * This is true if V8086 mode was enabled OR if the register set was from
18378 * protected mode with RPL-3 CS value. This tricky test checks that with
18379 * one comparison. Many places in the kernel can bypass this full check
18380- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18381+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18382+ * be used.
18383 */
18384-static inline int user_mode(struct pt_regs *regs)
18385+static inline int user_mode_novm(struct pt_regs *regs)
18386 {
18387 #ifdef CONFIG_X86_32
18388 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18389 #else
18390- return !!(regs->cs & 3);
18391+ return !!(regs->cs & SEGMENT_RPL_MASK);
18392 #endif
18393 }
18394
18395-static inline int user_mode_vm(struct pt_regs *regs)
18396+static inline int user_mode(struct pt_regs *regs)
18397 {
18398 #ifdef CONFIG_X86_32
18399 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18400 USER_RPL;
18401 #else
18402- return user_mode(regs);
18403+ return user_mode_novm(regs);
18404 #endif
18405 }
18406
18407@@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18408 #ifdef CONFIG_X86_64
18409 static inline bool user_64bit_mode(struct pt_regs *regs)
18410 {
18411+ unsigned long cs = regs->cs & 0xffff;
18412 #ifndef CONFIG_PARAVIRT
18413 /*
18414 * On non-paravirt systems, this is the only long mode CPL 3
18415 * selector. We do not allow long mode selectors in the LDT.
18416 */
18417- return regs->cs == __USER_CS;
18418+ return cs == __USER_CS;
18419 #else
18420 /* Headers are too twisted for this to go in paravirt.h. */
18421- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18422+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18423 #endif
18424 }
18425
18426@@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18427 * Traps from the kernel do not save sp and ss.
18428 * Use the helper function to retrieve sp.
18429 */
18430- if (offset == offsetof(struct pt_regs, sp) &&
18431- regs->cs == __KERNEL_CS)
18432- return kernel_stack_pointer(regs);
18433+ if (offset == offsetof(struct pt_regs, sp)) {
18434+ unsigned long cs = regs->cs & 0xffff;
18435+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18436+ return kernel_stack_pointer(regs);
18437+ }
18438 #endif
18439 return *(unsigned long *)((unsigned long)regs + offset);
18440 }
18441diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18442index 9c6b890..5305f53 100644
18443--- a/arch/x86/include/asm/realmode.h
18444+++ b/arch/x86/include/asm/realmode.h
18445@@ -22,16 +22,14 @@ struct real_mode_header {
18446 #endif
18447 /* APM/BIOS reboot */
18448 u32 machine_real_restart_asm;
18449-#ifdef CONFIG_X86_64
18450 u32 machine_real_restart_seg;
18451-#endif
18452 };
18453
18454 /* This must match data at trampoline_32/64.S */
18455 struct trampoline_header {
18456 #ifdef CONFIG_X86_32
18457 u32 start;
18458- u16 gdt_pad;
18459+ u16 boot_cs;
18460 u16 gdt_limit;
18461 u32 gdt_base;
18462 #else
18463diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18464index a82c4f1..ac45053 100644
18465--- a/arch/x86/include/asm/reboot.h
18466+++ b/arch/x86/include/asm/reboot.h
18467@@ -6,13 +6,13 @@
18468 struct pt_regs;
18469
18470 struct machine_ops {
18471- void (*restart)(char *cmd);
18472- void (*halt)(void);
18473- void (*power_off)(void);
18474+ void (* __noreturn restart)(char *cmd);
18475+ void (* __noreturn halt)(void);
18476+ void (* __noreturn power_off)(void);
18477 void (*shutdown)(void);
18478 void (*crash_shutdown)(struct pt_regs *);
18479- void (*emergency_restart)(void);
18480-};
18481+ void (* __noreturn emergency_restart)(void);
18482+} __no_const;
18483
18484 extern struct machine_ops machine_ops;
18485
18486diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18487index 8f7866a..e442f20 100644
18488--- a/arch/x86/include/asm/rmwcc.h
18489+++ b/arch/x86/include/asm/rmwcc.h
18490@@ -3,7 +3,34 @@
18491
18492 #ifdef CC_HAVE_ASM_GOTO
18493
18494-#define __GEN_RMWcc(fullop, var, cc, ...) \
18495+#ifdef CONFIG_PAX_REFCOUNT
18496+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18497+do { \
18498+ asm_volatile_goto (fullop \
18499+ ";jno 0f\n" \
18500+ fullantiop \
18501+ ";int $4\n0:\n" \
18502+ _ASM_EXTABLE(0b, 0b) \
18503+ ";j" cc " %l[cc_label]" \
18504+ : : "m" (var), ## __VA_ARGS__ \
18505+ : "memory" : cc_label); \
18506+ return 0; \
18507+cc_label: \
18508+ return 1; \
18509+} while (0)
18510+#else
18511+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18512+do { \
18513+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18514+ : : "m" (var), ## __VA_ARGS__ \
18515+ : "memory" : cc_label); \
18516+ return 0; \
18517+cc_label: \
18518+ return 1; \
18519+} while (0)
18520+#endif
18521+
18522+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18523 do { \
18524 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18525 : : "m" (var), ## __VA_ARGS__ \
18526@@ -13,15 +40,46 @@ cc_label: \
18527 return 1; \
18528 } while (0)
18529
18530-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18531- __GEN_RMWcc(op " " arg0, var, cc)
18532+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18533+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18534
18535-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18536- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18537+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18538+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18539+
18540+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18541+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18542+
18543+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18544+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18545
18546 #else /* !CC_HAVE_ASM_GOTO */
18547
18548-#define __GEN_RMWcc(fullop, var, cc, ...) \
18549+#ifdef CONFIG_PAX_REFCOUNT
18550+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18551+do { \
18552+ char c; \
18553+ asm volatile (fullop \
18554+ ";jno 0f\n" \
18555+ fullantiop \
18556+ ";int $4\n0:\n" \
18557+ _ASM_EXTABLE(0b, 0b) \
18558+ "; set" cc " %1" \
18559+ : "+m" (var), "=qm" (c) \
18560+ : __VA_ARGS__ : "memory"); \
18561+ return c != 0; \
18562+} while (0)
18563+#else
18564+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18565+do { \
18566+ char c; \
18567+ asm volatile (fullop "; set" cc " %1" \
18568+ : "+m" (var), "=qm" (c) \
18569+ : __VA_ARGS__ : "memory"); \
18570+ return c != 0; \
18571+} while (0)
18572+#endif
18573+
18574+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18575 do { \
18576 char c; \
18577 asm volatile (fullop "; set" cc " %1" \
18578@@ -30,11 +88,17 @@ do { \
18579 return c != 0; \
18580 } while (0)
18581
18582-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18583- __GEN_RMWcc(op " " arg0, var, cc)
18584+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18585+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18586+
18587+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18588+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18589+
18590+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18591+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18592
18593-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18594- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18595+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18596+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18597
18598 #endif /* CC_HAVE_ASM_GOTO */
18599
18600diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18601index cad82c9..2e5c5c1 100644
18602--- a/arch/x86/include/asm/rwsem.h
18603+++ b/arch/x86/include/asm/rwsem.h
18604@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18605 {
18606 asm volatile("# beginning down_read\n\t"
18607 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18608+
18609+#ifdef CONFIG_PAX_REFCOUNT
18610+ "jno 0f\n"
18611+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18612+ "int $4\n0:\n"
18613+ _ASM_EXTABLE(0b, 0b)
18614+#endif
18615+
18616 /* adds 0x00000001 */
18617 " jns 1f\n"
18618 " call call_rwsem_down_read_failed\n"
18619@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18620 "1:\n\t"
18621 " mov %1,%2\n\t"
18622 " add %3,%2\n\t"
18623+
18624+#ifdef CONFIG_PAX_REFCOUNT
18625+ "jno 0f\n"
18626+ "sub %3,%2\n"
18627+ "int $4\n0:\n"
18628+ _ASM_EXTABLE(0b, 0b)
18629+#endif
18630+
18631 " jle 2f\n\t"
18632 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18633 " jnz 1b\n\t"
18634@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18635 long tmp;
18636 asm volatile("# beginning down_write\n\t"
18637 LOCK_PREFIX " xadd %1,(%2)\n\t"
18638+
18639+#ifdef CONFIG_PAX_REFCOUNT
18640+ "jno 0f\n"
18641+ "mov %1,(%2)\n"
18642+ "int $4\n0:\n"
18643+ _ASM_EXTABLE(0b, 0b)
18644+#endif
18645+
18646 /* adds 0xffff0001, returns the old value */
18647 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18648 /* was the active mask 0 before? */
18649@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18650 long tmp;
18651 asm volatile("# beginning __up_read\n\t"
18652 LOCK_PREFIX " xadd %1,(%2)\n\t"
18653+
18654+#ifdef CONFIG_PAX_REFCOUNT
18655+ "jno 0f\n"
18656+ "mov %1,(%2)\n"
18657+ "int $4\n0:\n"
18658+ _ASM_EXTABLE(0b, 0b)
18659+#endif
18660+
18661 /* subtracts 1, returns the old value */
18662 " jns 1f\n\t"
18663 " call call_rwsem_wake\n" /* expects old value in %edx */
18664@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18665 long tmp;
18666 asm volatile("# beginning __up_write\n\t"
18667 LOCK_PREFIX " xadd %1,(%2)\n\t"
18668+
18669+#ifdef CONFIG_PAX_REFCOUNT
18670+ "jno 0f\n"
18671+ "mov %1,(%2)\n"
18672+ "int $4\n0:\n"
18673+ _ASM_EXTABLE(0b, 0b)
18674+#endif
18675+
18676 /* subtracts 0xffff0001, returns the old value */
18677 " jns 1f\n\t"
18678 " call call_rwsem_wake\n" /* expects old value in %edx */
18679@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18680 {
18681 asm volatile("# beginning __downgrade_write\n\t"
18682 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18683+
18684+#ifdef CONFIG_PAX_REFCOUNT
18685+ "jno 0f\n"
18686+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18687+ "int $4\n0:\n"
18688+ _ASM_EXTABLE(0b, 0b)
18689+#endif
18690+
18691 /*
18692 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18693 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18694@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18695 */
18696 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18697 {
18698- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18699+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18700+
18701+#ifdef CONFIG_PAX_REFCOUNT
18702+ "jno 0f\n"
18703+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18704+ "int $4\n0:\n"
18705+ _ASM_EXTABLE(0b, 0b)
18706+#endif
18707+
18708 : "+m" (sem->count)
18709 : "er" (delta));
18710 }
18711@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18712 */
18713 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18714 {
18715- return delta + xadd(&sem->count, delta);
18716+ return delta + xadd_check_overflow(&sem->count, delta);
18717 }
18718
18719 #endif /* __KERNEL__ */
18720diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18721index 6f1c3a8..7744f19 100644
18722--- a/arch/x86/include/asm/segment.h
18723+++ b/arch/x86/include/asm/segment.h
18724@@ -64,10 +64,15 @@
18725 * 26 - ESPFIX small SS
18726 * 27 - per-cpu [ offset to per-cpu data area ]
18727 * 28 - stack_canary-20 [ for stack protector ]
18728- * 29 - unused
18729- * 30 - unused
18730+ * 29 - PCI BIOS CS
18731+ * 30 - PCI BIOS DS
18732 * 31 - TSS for double fault handler
18733 */
18734+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18735+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18736+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18737+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18738+
18739 #define GDT_ENTRY_TLS_MIN 6
18740 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18741
18742@@ -79,6 +84,8 @@
18743
18744 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18745
18746+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18747+
18748 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18749
18750 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18751@@ -104,6 +111,12 @@
18752 #define __KERNEL_STACK_CANARY 0
18753 #endif
18754
18755+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18756+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18757+
18758+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18759+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18760+
18761 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18762
18763 /*
18764@@ -141,7 +154,7 @@
18765 */
18766
18767 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18768-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18769+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18770
18771
18772 #else
18773@@ -165,6 +178,8 @@
18774 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18775 #define __USER32_DS __USER_DS
18776
18777+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18778+
18779 #define GDT_ENTRY_TSS 8 /* needs two entries */
18780 #define GDT_ENTRY_LDT 10 /* needs two entries */
18781 #define GDT_ENTRY_TLS_MIN 12
18782@@ -173,6 +188,8 @@
18783 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18784 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18785
18786+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18787+
18788 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18789 #define FS_TLS 0
18790 #define GS_TLS 1
18791@@ -180,12 +197,14 @@
18792 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18793 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18794
18795-#define GDT_ENTRIES 16
18796+#define GDT_ENTRIES 17
18797
18798 #endif
18799
18800 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18801+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18802 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18803+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18804 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18805 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18806 #ifndef CONFIG_PARAVIRT
18807@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18808 {
18809 unsigned long __limit;
18810 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18811- return __limit + 1;
18812+ return __limit;
18813 }
18814
18815 #endif /* !__ASSEMBLY__ */
18816diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18817index 8d3120f..352b440 100644
18818--- a/arch/x86/include/asm/smap.h
18819+++ b/arch/x86/include/asm/smap.h
18820@@ -25,11 +25,40 @@
18821
18822 #include <asm/alternative-asm.h>
18823
18824+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18825+#define ASM_PAX_OPEN_USERLAND \
18826+ 661: jmp 663f; \
18827+ .pushsection .altinstr_replacement, "a" ; \
18828+ 662: pushq %rax; nop; \
18829+ .popsection ; \
18830+ .pushsection .altinstructions, "a" ; \
18831+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18832+ .popsection ; \
18833+ call __pax_open_userland; \
18834+ popq %rax; \
18835+ 663:
18836+
18837+#define ASM_PAX_CLOSE_USERLAND \
18838+ 661: jmp 663f; \
18839+ .pushsection .altinstr_replacement, "a" ; \
18840+ 662: pushq %rax; nop; \
18841+ .popsection; \
18842+ .pushsection .altinstructions, "a" ; \
18843+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18844+ .popsection; \
18845+ call __pax_close_userland; \
18846+ popq %rax; \
18847+ 663:
18848+#else
18849+#define ASM_PAX_OPEN_USERLAND
18850+#define ASM_PAX_CLOSE_USERLAND
18851+#endif
18852+
18853 #ifdef CONFIG_X86_SMAP
18854
18855 #define ASM_CLAC \
18856 661: ASM_NOP3 ; \
18857- .pushsection .altinstr_replacement, "ax" ; \
18858+ .pushsection .altinstr_replacement, "a" ; \
18859 662: __ASM_CLAC ; \
18860 .popsection ; \
18861 .pushsection .altinstructions, "a" ; \
18862@@ -38,7 +67,7 @@
18863
18864 #define ASM_STAC \
18865 661: ASM_NOP3 ; \
18866- .pushsection .altinstr_replacement, "ax" ; \
18867+ .pushsection .altinstr_replacement, "a" ; \
18868 662: __ASM_STAC ; \
18869 .popsection ; \
18870 .pushsection .altinstructions, "a" ; \
18871@@ -56,6 +85,37 @@
18872
18873 #include <asm/alternative.h>
18874
18875+#define __HAVE_ARCH_PAX_OPEN_USERLAND
18876+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18877+
18878+extern void __pax_open_userland(void);
18879+static __always_inline unsigned long pax_open_userland(void)
18880+{
18881+
18882+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18883+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18884+ :
18885+ : [open] "i" (__pax_open_userland)
18886+ : "memory", "rax");
18887+#endif
18888+
18889+ return 0;
18890+}
18891+
18892+extern void __pax_close_userland(void);
18893+static __always_inline unsigned long pax_close_userland(void)
18894+{
18895+
18896+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18897+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18898+ :
18899+ : [close] "i" (__pax_close_userland)
18900+ : "memory", "rax");
18901+#endif
18902+
18903+ return 0;
18904+}
18905+
18906 #ifdef CONFIG_X86_SMAP
18907
18908 static __always_inline void clac(void)
18909diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18910index 8cd27e0..7f05ec8 100644
18911--- a/arch/x86/include/asm/smp.h
18912+++ b/arch/x86/include/asm/smp.h
18913@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18914 /* cpus sharing the last level cache: */
18915 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18916 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18917-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18918+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18919
18920 static inline struct cpumask *cpu_sibling_mask(int cpu)
18921 {
18922@@ -78,7 +78,7 @@ struct smp_ops {
18923
18924 void (*send_call_func_ipi)(const struct cpumask *mask);
18925 void (*send_call_func_single_ipi)(int cpu);
18926-};
18927+} __no_const;
18928
18929 /* Globals due to paravirt */
18930 extern void set_cpu_sibling_map(int cpu);
18931@@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
18932 extern int safe_smp_processor_id(void);
18933
18934 #elif defined(CONFIG_X86_64_SMP)
18935-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18936-
18937-#define stack_smp_processor_id() \
18938-({ \
18939- struct thread_info *ti; \
18940- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18941- ti->cpu; \
18942-})
18943+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18944+#define stack_smp_processor_id() raw_smp_processor_id()
18945 #define safe_smp_processor_id() smp_processor_id()
18946
18947 #endif
18948diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18949index 0f62f54..cb5d0dd 100644
18950--- a/arch/x86/include/asm/spinlock.h
18951+++ b/arch/x86/include/asm/spinlock.h
18952@@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18953 static inline void arch_read_lock(arch_rwlock_t *rw)
18954 {
18955 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18956+
18957+#ifdef CONFIG_PAX_REFCOUNT
18958+ "jno 0f\n"
18959+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18960+ "int $4\n0:\n"
18961+ _ASM_EXTABLE(0b, 0b)
18962+#endif
18963+
18964 "jns 1f\n"
18965 "call __read_lock_failed\n\t"
18966 "1:\n"
18967@@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18968 static inline void arch_write_lock(arch_rwlock_t *rw)
18969 {
18970 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18971+
18972+#ifdef CONFIG_PAX_REFCOUNT
18973+ "jno 0f\n"
18974+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18975+ "int $4\n0:\n"
18976+ _ASM_EXTABLE(0b, 0b)
18977+#endif
18978+
18979 "jz 1f\n"
18980 "call __write_lock_failed\n\t"
18981 "1:\n"
18982@@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18983
18984 static inline void arch_read_unlock(arch_rwlock_t *rw)
18985 {
18986- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18987+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18988+
18989+#ifdef CONFIG_PAX_REFCOUNT
18990+ "jno 0f\n"
18991+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18992+ "int $4\n0:\n"
18993+ _ASM_EXTABLE(0b, 0b)
18994+#endif
18995+
18996 :"+m" (rw->lock) : : "memory");
18997 }
18998
18999 static inline void arch_write_unlock(arch_rwlock_t *rw)
19000 {
19001- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19002+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19003+
19004+#ifdef CONFIG_PAX_REFCOUNT
19005+ "jno 0f\n"
19006+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19007+ "int $4\n0:\n"
19008+ _ASM_EXTABLE(0b, 0b)
19009+#endif
19010+
19011 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19012 }
19013
19014diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19015index 6a99859..03cb807 100644
19016--- a/arch/x86/include/asm/stackprotector.h
19017+++ b/arch/x86/include/asm/stackprotector.h
19018@@ -47,7 +47,7 @@
19019 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19020 */
19021 #define GDT_STACK_CANARY_INIT \
19022- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19023+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19024
19025 /*
19026 * Initialize the stackprotector canary value.
19027@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19028
19029 static inline void load_stack_canary_segment(void)
19030 {
19031-#ifdef CONFIG_X86_32
19032+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19033 asm volatile ("mov %0, %%gs" : : "r" (0));
19034 #endif
19035 }
19036diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19037index 70bbe39..4ae2bd4 100644
19038--- a/arch/x86/include/asm/stacktrace.h
19039+++ b/arch/x86/include/asm/stacktrace.h
19040@@ -11,28 +11,20 @@
19041
19042 extern int kstack_depth_to_print;
19043
19044-struct thread_info;
19045+struct task_struct;
19046 struct stacktrace_ops;
19047
19048-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19049- unsigned long *stack,
19050- unsigned long bp,
19051- const struct stacktrace_ops *ops,
19052- void *data,
19053- unsigned long *end,
19054- int *graph);
19055+typedef unsigned long walk_stack_t(struct task_struct *task,
19056+ void *stack_start,
19057+ unsigned long *stack,
19058+ unsigned long bp,
19059+ const struct stacktrace_ops *ops,
19060+ void *data,
19061+ unsigned long *end,
19062+ int *graph);
19063
19064-extern unsigned long
19065-print_context_stack(struct thread_info *tinfo,
19066- unsigned long *stack, unsigned long bp,
19067- const struct stacktrace_ops *ops, void *data,
19068- unsigned long *end, int *graph);
19069-
19070-extern unsigned long
19071-print_context_stack_bp(struct thread_info *tinfo,
19072- unsigned long *stack, unsigned long bp,
19073- const struct stacktrace_ops *ops, void *data,
19074- unsigned long *end, int *graph);
19075+extern walk_stack_t print_context_stack;
19076+extern walk_stack_t print_context_stack_bp;
19077
19078 /* Generic stack tracer with callbacks */
19079
19080@@ -40,7 +32,7 @@ struct stacktrace_ops {
19081 void (*address)(void *data, unsigned long address, int reliable);
19082 /* On negative return stop dumping */
19083 int (*stack)(void *data, char *name);
19084- walk_stack_t walk_stack;
19085+ walk_stack_t *walk_stack;
19086 };
19087
19088 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19089diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19090index d7f3b3b..3cc39f1 100644
19091--- a/arch/x86/include/asm/switch_to.h
19092+++ b/arch/x86/include/asm/switch_to.h
19093@@ -108,7 +108,7 @@ do { \
19094 "call __switch_to\n\t" \
19095 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19096 __switch_canary \
19097- "movq %P[thread_info](%%rsi),%%r8\n\t" \
19098+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19099 "movq %%rax,%%rdi\n\t" \
19100 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19101 "jnz ret_from_fork\n\t" \
19102@@ -119,7 +119,7 @@ do { \
19103 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19104 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19105 [_tif_fork] "i" (_TIF_FORK), \
19106- [thread_info] "i" (offsetof(struct task_struct, stack)), \
19107+ [thread_info] "m" (current_tinfo), \
19108 [current_task] "m" (current_task) \
19109 __switch_canary_iparam \
19110 : "memory", "cc" __EXTRA_CLOBBER)
19111diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19112index 47e5de2..d3dda54 100644
19113--- a/arch/x86/include/asm/thread_info.h
19114+++ b/arch/x86/include/asm/thread_info.h
19115@@ -24,7 +24,6 @@ struct exec_domain;
19116 #include <linux/atomic.h>
19117
19118 struct thread_info {
19119- struct task_struct *task; /* main task structure */
19120 struct exec_domain *exec_domain; /* execution domain */
19121 __u32 flags; /* low level flags */
19122 __u32 status; /* thread synchronous flags */
19123@@ -33,13 +32,13 @@ struct thread_info {
19124 mm_segment_t addr_limit;
19125 struct restart_block restart_block;
19126 void __user *sysenter_return;
19127+ unsigned long lowest_stack;
19128 unsigned int sig_on_uaccess_error:1;
19129 unsigned int uaccess_err:1; /* uaccess failed */
19130 };
19131
19132-#define INIT_THREAD_INFO(tsk) \
19133+#define INIT_THREAD_INFO \
19134 { \
19135- .task = &tsk, \
19136 .exec_domain = &default_exec_domain, \
19137 .flags = 0, \
19138 .cpu = 0, \
19139@@ -50,7 +49,7 @@ struct thread_info {
19140 }, \
19141 }
19142
19143-#define init_thread_info (init_thread_union.thread_info)
19144+#define init_thread_info (init_thread_union.stack)
19145 #define init_stack (init_thread_union.stack)
19146
19147 #else /* !__ASSEMBLY__ */
19148@@ -90,6 +89,7 @@ struct thread_info {
19149 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19150 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19151 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19152+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19153
19154 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19155 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19156@@ -113,17 +113,18 @@ struct thread_info {
19157 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19158 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19159 #define _TIF_X32 (1 << TIF_X32)
19160+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19161
19162 /* work to do in syscall_trace_enter() */
19163 #define _TIF_WORK_SYSCALL_ENTRY \
19164 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19165 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19166- _TIF_NOHZ)
19167+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19168
19169 /* work to do in syscall_trace_leave() */
19170 #define _TIF_WORK_SYSCALL_EXIT \
19171 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19172- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19173+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19174
19175 /* work to do on interrupt/exception return */
19176 #define _TIF_WORK_MASK \
19177@@ -134,7 +135,7 @@ struct thread_info {
19178 /* work to do on any return to user space */
19179 #define _TIF_ALLWORK_MASK \
19180 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19181- _TIF_NOHZ)
19182+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19183
19184 /* Only used for 64 bit */
19185 #define _TIF_DO_NOTIFY_MASK \
19186@@ -149,7 +150,6 @@ struct thread_info {
19187 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19188
19189 #define STACK_WARN (THREAD_SIZE/8)
19190-#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19191
19192 /*
19193 * macros/functions for gaining access to the thread information structure
19194@@ -160,26 +160,18 @@ struct thread_info {
19195
19196 DECLARE_PER_CPU(unsigned long, kernel_stack);
19197
19198+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19199+
19200 static inline struct thread_info *current_thread_info(void)
19201 {
19202- struct thread_info *ti;
19203- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19204- KERNEL_STACK_OFFSET - THREAD_SIZE);
19205- return ti;
19206+ return this_cpu_read_stable(current_tinfo);
19207 }
19208
19209 #else /* !__ASSEMBLY__ */
19210
19211 /* how to get the thread information struct from ASM */
19212 #define GET_THREAD_INFO(reg) \
19213- _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19214- _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19215-
19216-/*
19217- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19218- * a certain register (to be used in assembler memory operands).
19219- */
19220-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19221+ _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19222
19223 #endif
19224
19225@@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19226 extern void arch_task_cache_init(void);
19227 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19228 extern void arch_release_task_struct(struct task_struct *tsk);
19229+
19230+#define __HAVE_THREAD_FUNCTIONS
19231+#define task_thread_info(task) (&(task)->tinfo)
19232+#define task_stack_page(task) ((task)->stack)
19233+#define setup_thread_stack(p, org) do {} while (0)
19234+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19235+
19236 #endif
19237 #endif /* _ASM_X86_THREAD_INFO_H */
19238diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19239index 04905bf..49203ca 100644
19240--- a/arch/x86/include/asm/tlbflush.h
19241+++ b/arch/x86/include/asm/tlbflush.h
19242@@ -17,18 +17,44 @@
19243
19244 static inline void __native_flush_tlb(void)
19245 {
19246+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19247+ u64 descriptor[2];
19248+
19249+ descriptor[0] = PCID_KERNEL;
19250+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19251+ return;
19252+ }
19253+
19254+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19255+ if (static_cpu_has(X86_FEATURE_PCID)) {
19256+ unsigned int cpu = raw_get_cpu();
19257+
19258+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19259+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19260+ raw_put_cpu_no_resched();
19261+ return;
19262+ }
19263+#endif
19264+
19265 native_write_cr3(native_read_cr3());
19266 }
19267
19268 static inline void __native_flush_tlb_global_irq_disabled(void)
19269 {
19270- unsigned long cr4;
19271+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19272+ u64 descriptor[2];
19273
19274- cr4 = native_read_cr4();
19275- /* clear PGE */
19276- native_write_cr4(cr4 & ~X86_CR4_PGE);
19277- /* write old PGE again and flush TLBs */
19278- native_write_cr4(cr4);
19279+ descriptor[0] = PCID_KERNEL;
19280+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19281+ } else {
19282+ unsigned long cr4;
19283+
19284+ cr4 = native_read_cr4();
19285+ /* clear PGE */
19286+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19287+ /* write old PGE again and flush TLBs */
19288+ native_write_cr4(cr4);
19289+ }
19290 }
19291
19292 static inline void __native_flush_tlb_global(void)
19293@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19294
19295 static inline void __native_flush_tlb_single(unsigned long addr)
19296 {
19297+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19298+ u64 descriptor[2];
19299+
19300+ descriptor[0] = PCID_KERNEL;
19301+ descriptor[1] = addr;
19302+
19303+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19304+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19305+ if (addr < TASK_SIZE_MAX)
19306+ descriptor[1] += pax_user_shadow_base;
19307+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19308+ }
19309+
19310+ descriptor[0] = PCID_USER;
19311+ descriptor[1] = addr;
19312+#endif
19313+
19314+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19315+ return;
19316+ }
19317+
19318+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19319+ if (static_cpu_has(X86_FEATURE_PCID)) {
19320+ unsigned int cpu = raw_get_cpu();
19321+
19322+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19323+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19324+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19325+ raw_put_cpu_no_resched();
19326+
19327+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19328+ addr += pax_user_shadow_base;
19329+ }
19330+#endif
19331+
19332 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19333 }
19334
19335diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19336index 0d592e0..7437fcc 100644
19337--- a/arch/x86/include/asm/uaccess.h
19338+++ b/arch/x86/include/asm/uaccess.h
19339@@ -7,6 +7,7 @@
19340 #include <linux/compiler.h>
19341 #include <linux/thread_info.h>
19342 #include <linux/string.h>
19343+#include <linux/spinlock.h>
19344 #include <asm/asm.h>
19345 #include <asm/page.h>
19346 #include <asm/smap.h>
19347@@ -29,7 +30,12 @@
19348
19349 #define get_ds() (KERNEL_DS)
19350 #define get_fs() (current_thread_info()->addr_limit)
19351+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19352+void __set_fs(mm_segment_t x);
19353+void set_fs(mm_segment_t x);
19354+#else
19355 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19356+#endif
19357
19358 #define segment_eq(a, b) ((a).seg == (b).seg)
19359
19360@@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19361 * checks that the pointer is in the user space range - after calling
19362 * this function, memory access functions may still return -EFAULT.
19363 */
19364-#define access_ok(type, addr, size) \
19365- likely(!__range_not_ok(addr, size, user_addr_max()))
19366+extern int _cond_resched(void);
19367+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19368+#define access_ok(type, addr, size) \
19369+({ \
19370+ unsigned long __size = size; \
19371+ unsigned long __addr = (unsigned long)addr; \
19372+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19373+ if (__ret_ao && __size) { \
19374+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19375+ unsigned long __end_ao = __addr + __size - 1; \
19376+ if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19377+ while (__addr_ao <= __end_ao) { \
19378+ char __c_ao; \
19379+ __addr_ao += PAGE_SIZE; \
19380+ if (__size > PAGE_SIZE) \
19381+ _cond_resched(); \
19382+ if (__get_user(__c_ao, (char __user *)__addr)) \
19383+ break; \
19384+ if (type != VERIFY_WRITE) { \
19385+ __addr = __addr_ao; \
19386+ continue; \
19387+ } \
19388+ if (__put_user(__c_ao, (char __user *)__addr)) \
19389+ break; \
19390+ __addr = __addr_ao; \
19391+ } \
19392+ } \
19393+ } \
19394+ __ret_ao; \
19395+})
19396
19397 /*
19398 * The exception table consists of pairs of addresses relative to the
19399@@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19400 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19401 __chk_user_ptr(ptr); \
19402 might_fault(); \
19403+ pax_open_userland(); \
19404 asm volatile("call __get_user_%P3" \
19405 : "=a" (__ret_gu), "=r" (__val_gu) \
19406 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19407 (x) = (__typeof__(*(ptr))) __val_gu; \
19408+ pax_close_userland(); \
19409 __ret_gu; \
19410 })
19411
19412@@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19413 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19414 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19415
19416-
19417+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19418+#define __copyuser_seg "gs;"
19419+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19420+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19421+#else
19422+#define __copyuser_seg
19423+#define __COPYUSER_SET_ES
19424+#define __COPYUSER_RESTORE_ES
19425+#endif
19426
19427 #ifdef CONFIG_X86_32
19428 #define __put_user_asm_u64(x, addr, err, errret) \
19429 asm volatile(ASM_STAC "\n" \
19430- "1: movl %%eax,0(%2)\n" \
19431- "2: movl %%edx,4(%2)\n" \
19432+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19433+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19434 "3: " ASM_CLAC "\n" \
19435 ".section .fixup,\"ax\"\n" \
19436 "4: movl %3,%0\n" \
19437@@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19438
19439 #define __put_user_asm_ex_u64(x, addr) \
19440 asm volatile(ASM_STAC "\n" \
19441- "1: movl %%eax,0(%1)\n" \
19442- "2: movl %%edx,4(%1)\n" \
19443+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19444+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19445 "3: " ASM_CLAC "\n" \
19446 _ASM_EXTABLE_EX(1b, 2b) \
19447 _ASM_EXTABLE_EX(2b, 3b) \
19448@@ -257,7 +301,8 @@ extern void __put_user_8(void);
19449 __typeof__(*(ptr)) __pu_val; \
19450 __chk_user_ptr(ptr); \
19451 might_fault(); \
19452- __pu_val = x; \
19453+ __pu_val = (x); \
19454+ pax_open_userland(); \
19455 switch (sizeof(*(ptr))) { \
19456 case 1: \
19457 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19458@@ -275,6 +320,7 @@ extern void __put_user_8(void);
19459 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19460 break; \
19461 } \
19462+ pax_close_userland(); \
19463 __ret_pu; \
19464 })
19465
19466@@ -355,8 +401,10 @@ do { \
19467 } while (0)
19468
19469 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19470+do { \
19471+ pax_open_userland(); \
19472 asm volatile(ASM_STAC "\n" \
19473- "1: mov"itype" %2,%"rtype"1\n" \
19474+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19475 "2: " ASM_CLAC "\n" \
19476 ".section .fixup,\"ax\"\n" \
19477 "3: mov %3,%0\n" \
19478@@ -364,8 +412,10 @@ do { \
19479 " jmp 2b\n" \
19480 ".previous\n" \
19481 _ASM_EXTABLE(1b, 3b) \
19482- : "=r" (err), ltype(x) \
19483- : "m" (__m(addr)), "i" (errret), "0" (err))
19484+ : "=r" (err), ltype (x) \
19485+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19486+ pax_close_userland(); \
19487+} while (0)
19488
19489 #define __get_user_size_ex(x, ptr, size) \
19490 do { \
19491@@ -389,7 +439,7 @@ do { \
19492 } while (0)
19493
19494 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19495- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19496+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19497 "2:\n" \
19498 _ASM_EXTABLE_EX(1b, 2b) \
19499 : ltype(x) : "m" (__m(addr)))
19500@@ -406,13 +456,24 @@ do { \
19501 int __gu_err; \
19502 unsigned long __gu_val; \
19503 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19504- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19505+ (x) = (__typeof__(*(ptr)))__gu_val; \
19506 __gu_err; \
19507 })
19508
19509 /* FIXME: this hack is definitely wrong -AK */
19510 struct __large_struct { unsigned long buf[100]; };
19511-#define __m(x) (*(struct __large_struct __user *)(x))
19512+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19513+#define ____m(x) \
19514+({ \
19515+ unsigned long ____x = (unsigned long)(x); \
19516+ if (____x < pax_user_shadow_base) \
19517+ ____x += pax_user_shadow_base; \
19518+ (typeof(x))____x; \
19519+})
19520+#else
19521+#define ____m(x) (x)
19522+#endif
19523+#define __m(x) (*(struct __large_struct __user *)____m(x))
19524
19525 /*
19526 * Tell gcc we read from memory instead of writing: this is because
19527@@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19528 * aliasing issues.
19529 */
19530 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19531+do { \
19532+ pax_open_userland(); \
19533 asm volatile(ASM_STAC "\n" \
19534- "1: mov"itype" %"rtype"1,%2\n" \
19535+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19536 "2: " ASM_CLAC "\n" \
19537 ".section .fixup,\"ax\"\n" \
19538 "3: mov %3,%0\n" \
19539@@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19540 ".previous\n" \
19541 _ASM_EXTABLE(1b, 3b) \
19542 : "=r"(err) \
19543- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19544+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19545+ pax_close_userland(); \
19546+} while (0)
19547
19548 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19549- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19550+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19551 "2:\n" \
19552 _ASM_EXTABLE_EX(1b, 2b) \
19553 : : ltype(x), "m" (__m(addr)))
19554@@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19555 */
19556 #define uaccess_try do { \
19557 current_thread_info()->uaccess_err = 0; \
19558+ pax_open_userland(); \
19559 stac(); \
19560 barrier();
19561
19562 #define uaccess_catch(err) \
19563 clac(); \
19564+ pax_close_userland(); \
19565 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19566 } while (0)
19567
19568@@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19569 * On error, the variable @x is set to zero.
19570 */
19571
19572+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19573+#define __get_user(x, ptr) get_user((x), (ptr))
19574+#else
19575 #define __get_user(x, ptr) \
19576 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19577+#endif
19578
19579 /**
19580 * __put_user: - Write a simple value into user space, with less checking.
19581@@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19582 * Returns zero on success, or -EFAULT on error.
19583 */
19584
19585+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19586+#define __put_user(x, ptr) put_user((x), (ptr))
19587+#else
19588 #define __put_user(x, ptr) \
19589 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19590+#endif
19591
19592 #define __get_user_unaligned __get_user
19593 #define __put_user_unaligned __put_user
19594@@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19595 #define get_user_ex(x, ptr) do { \
19596 unsigned long __gue_val; \
19597 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19598- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19599+ (x) = (__typeof__(*(ptr)))__gue_val; \
19600 } while (0)
19601
19602 #define put_user_try uaccess_try
19603@@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19604 __typeof__(ptr) __uval = (uval); \
19605 __typeof__(*(ptr)) __old = (old); \
19606 __typeof__(*(ptr)) __new = (new); \
19607+ pax_open_userland(); \
19608 switch (size) { \
19609 case 1: \
19610 { \
19611 asm volatile("\t" ASM_STAC "\n" \
19612- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19613+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19614 "2:\t" ASM_CLAC "\n" \
19615 "\t.section .fixup, \"ax\"\n" \
19616 "3:\tmov %3, %0\n" \
19617 "\tjmp 2b\n" \
19618 "\t.previous\n" \
19619 _ASM_EXTABLE(1b, 3b) \
19620- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19621+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19622 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19623 : "memory" \
19624 ); \
19625@@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19626 case 2: \
19627 { \
19628 asm volatile("\t" ASM_STAC "\n" \
19629- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19630+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19631 "2:\t" ASM_CLAC "\n" \
19632 "\t.section .fixup, \"ax\"\n" \
19633 "3:\tmov %3, %0\n" \
19634 "\tjmp 2b\n" \
19635 "\t.previous\n" \
19636 _ASM_EXTABLE(1b, 3b) \
19637- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19638+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19639 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19640 : "memory" \
19641 ); \
19642@@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19643 case 4: \
19644 { \
19645 asm volatile("\t" ASM_STAC "\n" \
19646- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19647+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19648 "2:\t" ASM_CLAC "\n" \
19649 "\t.section .fixup, \"ax\"\n" \
19650 "3:\tmov %3, %0\n" \
19651 "\tjmp 2b\n" \
19652 "\t.previous\n" \
19653 _ASM_EXTABLE(1b, 3b) \
19654- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19655+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19656 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19657 : "memory" \
19658 ); \
19659@@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19660 __cmpxchg_wrong_size(); \
19661 \
19662 asm volatile("\t" ASM_STAC "\n" \
19663- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19664+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19665 "2:\t" ASM_CLAC "\n" \
19666 "\t.section .fixup, \"ax\"\n" \
19667 "3:\tmov %3, %0\n" \
19668 "\tjmp 2b\n" \
19669 "\t.previous\n" \
19670 _ASM_EXTABLE(1b, 3b) \
19671- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19672+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19673 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19674 : "memory" \
19675 ); \
19676@@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19677 default: \
19678 __cmpxchg_wrong_size(); \
19679 } \
19680+ pax_close_userland(); \
19681 *__uval = __old; \
19682 __ret; \
19683 })
19684@@ -636,17 +713,6 @@ extern struct movsl_mask {
19685
19686 #define ARCH_HAS_NOCACHE_UACCESS 1
19687
19688-#ifdef CONFIG_X86_32
19689-# include <asm/uaccess_32.h>
19690-#else
19691-# include <asm/uaccess_64.h>
19692-#endif
19693-
19694-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19695- unsigned n);
19696-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19697- unsigned n);
19698-
19699 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19700 # define copy_user_diag __compiletime_error
19701 #else
19702@@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19703 extern void copy_user_diag("copy_from_user() buffer size is too small")
19704 copy_from_user_overflow(void);
19705 extern void copy_user_diag("copy_to_user() buffer size is too small")
19706-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19707+copy_to_user_overflow(void);
19708
19709 #undef copy_user_diag
19710
19711@@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19712
19713 extern void
19714 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19715-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19716+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19717 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19718
19719 #else
19720@@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19721
19722 #endif
19723
19724+#ifdef CONFIG_X86_32
19725+# include <asm/uaccess_32.h>
19726+#else
19727+# include <asm/uaccess_64.h>
19728+#endif
19729+
19730 static inline unsigned long __must_check
19731 copy_from_user(void *to, const void __user *from, unsigned long n)
19732 {
19733- int sz = __compiletime_object_size(to);
19734+ size_t sz = __compiletime_object_size(to);
19735
19736 might_fault();
19737
19738@@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19739 * case, and do only runtime checking for non-constant sizes.
19740 */
19741
19742- if (likely(sz < 0 || sz >= n))
19743- n = _copy_from_user(to, from, n);
19744- else if(__builtin_constant_p(n))
19745- copy_from_user_overflow();
19746- else
19747- __copy_from_user_overflow(sz, n);
19748+ if (likely(sz != (size_t)-1 && sz < n)) {
19749+ if(__builtin_constant_p(n))
19750+ copy_from_user_overflow();
19751+ else
19752+ __copy_from_user_overflow(sz, n);
19753+ } if (access_ok(VERIFY_READ, from, n))
19754+ n = __copy_from_user(to, from, n);
19755+ else if ((long)n > 0)
19756+ memset(to, 0, n);
19757
19758 return n;
19759 }
19760@@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19761 static inline unsigned long __must_check
19762 copy_to_user(void __user *to, const void *from, unsigned long n)
19763 {
19764- int sz = __compiletime_object_size(from);
19765+ size_t sz = __compiletime_object_size(from);
19766
19767 might_fault();
19768
19769 /* See the comment in copy_from_user() above. */
19770- if (likely(sz < 0 || sz >= n))
19771- n = _copy_to_user(to, from, n);
19772- else if(__builtin_constant_p(n))
19773- copy_to_user_overflow();
19774- else
19775- __copy_to_user_overflow(sz, n);
19776+ if (likely(sz != (size_t)-1 && sz < n)) {
19777+ if(__builtin_constant_p(n))
19778+ copy_to_user_overflow();
19779+ else
19780+ __copy_to_user_overflow(sz, n);
19781+ } else if (access_ok(VERIFY_WRITE, to, n))
19782+ n = __copy_to_user(to, from, n);
19783
19784 return n;
19785 }
19786diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19787index 3c03a5d..1071638 100644
19788--- a/arch/x86/include/asm/uaccess_32.h
19789+++ b/arch/x86/include/asm/uaccess_32.h
19790@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19791 static __always_inline unsigned long __must_check
19792 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19793 {
19794+ if ((long)n < 0)
19795+ return n;
19796+
19797+ check_object_size(from, n, true);
19798+
19799 if (__builtin_constant_p(n)) {
19800 unsigned long ret;
19801
19802@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19803 __copy_to_user(void __user *to, const void *from, unsigned long n)
19804 {
19805 might_fault();
19806+
19807 return __copy_to_user_inatomic(to, from, n);
19808 }
19809
19810 static __always_inline unsigned long
19811 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19812 {
19813+ if ((long)n < 0)
19814+ return n;
19815+
19816 /* Avoid zeroing the tail if the copy fails..
19817 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19818 * but as the zeroing behaviour is only significant when n is not
19819@@ -137,6 +146,12 @@ static __always_inline unsigned long
19820 __copy_from_user(void *to, const void __user *from, unsigned long n)
19821 {
19822 might_fault();
19823+
19824+ if ((long)n < 0)
19825+ return n;
19826+
19827+ check_object_size(to, n, false);
19828+
19829 if (__builtin_constant_p(n)) {
19830 unsigned long ret;
19831
19832@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19833 const void __user *from, unsigned long n)
19834 {
19835 might_fault();
19836+
19837+ if ((long)n < 0)
19838+ return n;
19839+
19840 if (__builtin_constant_p(n)) {
19841 unsigned long ret;
19842
19843@@ -181,7 +200,10 @@ static __always_inline unsigned long
19844 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19845 unsigned long n)
19846 {
19847- return __copy_from_user_ll_nocache_nozero(to, from, n);
19848+ if ((long)n < 0)
19849+ return n;
19850+
19851+ return __copy_from_user_ll_nocache_nozero(to, from, n);
19852 }
19853
19854 #endif /* _ASM_X86_UACCESS_32_H */
19855diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19856index 12a26b9..206c200 100644
19857--- a/arch/x86/include/asm/uaccess_64.h
19858+++ b/arch/x86/include/asm/uaccess_64.h
19859@@ -10,6 +10,9 @@
19860 #include <asm/alternative.h>
19861 #include <asm/cpufeature.h>
19862 #include <asm/page.h>
19863+#include <asm/pgtable.h>
19864+
19865+#define set_fs(x) (current_thread_info()->addr_limit = (x))
19866
19867 /*
19868 * Copy To/From Userspace
19869@@ -17,14 +20,14 @@
19870
19871 /* Handles exceptions in both to and from, but doesn't do access_ok */
19872 __must_check unsigned long
19873-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19874+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19875 __must_check unsigned long
19876-copy_user_generic_string(void *to, const void *from, unsigned len);
19877+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19878 __must_check unsigned long
19879-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19880+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19881
19882 static __always_inline __must_check unsigned long
19883-copy_user_generic(void *to, const void *from, unsigned len)
19884+copy_user_generic(void *to, const void *from, unsigned long len)
19885 {
19886 unsigned ret;
19887
19888@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19889 }
19890
19891 __must_check unsigned long
19892-copy_in_user(void __user *to, const void __user *from, unsigned len);
19893+copy_in_user(void __user *to, const void __user *from, unsigned long len);
19894
19895 static __always_inline __must_check
19896-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19897+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19898 {
19899- int ret = 0;
19900+ size_t sz = __compiletime_object_size(dst);
19901+ unsigned ret = 0;
19902+
19903+ if (size > INT_MAX)
19904+ return size;
19905+
19906+ check_object_size(dst, size, false);
19907+
19908+#ifdef CONFIG_PAX_MEMORY_UDEREF
19909+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19910+ return size;
19911+#endif
19912+
19913+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19914+ if(__builtin_constant_p(size))
19915+ copy_from_user_overflow();
19916+ else
19917+ __copy_from_user_overflow(sz, size);
19918+ return size;
19919+ }
19920
19921 if (!__builtin_constant_p(size))
19922- return copy_user_generic(dst, (__force void *)src, size);
19923+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19924 switch (size) {
19925- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19926+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19927 ret, "b", "b", "=q", 1);
19928 return ret;
19929- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19930+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19931 ret, "w", "w", "=r", 2);
19932 return ret;
19933- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19934+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19935 ret, "l", "k", "=r", 4);
19936 return ret;
19937- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19938+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19939 ret, "q", "", "=r", 8);
19940 return ret;
19941 case 10:
19942- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19943+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19944 ret, "q", "", "=r", 10);
19945 if (unlikely(ret))
19946 return ret;
19947 __get_user_asm(*(u16 *)(8 + (char *)dst),
19948- (u16 __user *)(8 + (char __user *)src),
19949+ (const u16 __user *)(8 + (const char __user *)src),
19950 ret, "w", "w", "=r", 2);
19951 return ret;
19952 case 16:
19953- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19954+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19955 ret, "q", "", "=r", 16);
19956 if (unlikely(ret))
19957 return ret;
19958 __get_user_asm(*(u64 *)(8 + (char *)dst),
19959- (u64 __user *)(8 + (char __user *)src),
19960+ (const u64 __user *)(8 + (const char __user *)src),
19961 ret, "q", "", "=r", 8);
19962 return ret;
19963 default:
19964- return copy_user_generic(dst, (__force void *)src, size);
19965+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19966 }
19967 }
19968
19969 static __always_inline __must_check
19970-int __copy_from_user(void *dst, const void __user *src, unsigned size)
19971+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19972 {
19973 might_fault();
19974 return __copy_from_user_nocheck(dst, src, size);
19975 }
19976
19977 static __always_inline __must_check
19978-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19979+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19980 {
19981- int ret = 0;
19982+ size_t sz = __compiletime_object_size(src);
19983+ unsigned ret = 0;
19984+
19985+ if (size > INT_MAX)
19986+ return size;
19987+
19988+ check_object_size(src, size, true);
19989+
19990+#ifdef CONFIG_PAX_MEMORY_UDEREF
19991+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19992+ return size;
19993+#endif
19994+
19995+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19996+ if(__builtin_constant_p(size))
19997+ copy_to_user_overflow();
19998+ else
19999+ __copy_to_user_overflow(sz, size);
20000+ return size;
20001+ }
20002
20003 if (!__builtin_constant_p(size))
20004- return copy_user_generic((__force void *)dst, src, size);
20005+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20006 switch (size) {
20007- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20008+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20009 ret, "b", "b", "iq", 1);
20010 return ret;
20011- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20012+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20013 ret, "w", "w", "ir", 2);
20014 return ret;
20015- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20016+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20017 ret, "l", "k", "ir", 4);
20018 return ret;
20019- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20020+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20021 ret, "q", "", "er", 8);
20022 return ret;
20023 case 10:
20024- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20025+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20026 ret, "q", "", "er", 10);
20027 if (unlikely(ret))
20028 return ret;
20029 asm("":::"memory");
20030- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20031+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20032 ret, "w", "w", "ir", 2);
20033 return ret;
20034 case 16:
20035- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20036+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20037 ret, "q", "", "er", 16);
20038 if (unlikely(ret))
20039 return ret;
20040 asm("":::"memory");
20041- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20042+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20043 ret, "q", "", "er", 8);
20044 return ret;
20045 default:
20046- return copy_user_generic((__force void *)dst, src, size);
20047+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20048 }
20049 }
20050
20051 static __always_inline __must_check
20052-int __copy_to_user(void __user *dst, const void *src, unsigned size)
20053+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20054 {
20055 might_fault();
20056 return __copy_to_user_nocheck(dst, src, size);
20057 }
20058
20059 static __always_inline __must_check
20060-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20061+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20062 {
20063- int ret = 0;
20064+ unsigned ret = 0;
20065
20066 might_fault();
20067+
20068+ if (size > INT_MAX)
20069+ return size;
20070+
20071+#ifdef CONFIG_PAX_MEMORY_UDEREF
20072+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20073+ return size;
20074+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20075+ return size;
20076+#endif
20077+
20078 if (!__builtin_constant_p(size))
20079- return copy_user_generic((__force void *)dst,
20080- (__force void *)src, size);
20081+ return copy_user_generic((__force_kernel void *)____m(dst),
20082+ (__force_kernel const void *)____m(src), size);
20083 switch (size) {
20084 case 1: {
20085 u8 tmp;
20086- __get_user_asm(tmp, (u8 __user *)src,
20087+ __get_user_asm(tmp, (const u8 __user *)src,
20088 ret, "b", "b", "=q", 1);
20089 if (likely(!ret))
20090 __put_user_asm(tmp, (u8 __user *)dst,
20091@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20092 }
20093 case 2: {
20094 u16 tmp;
20095- __get_user_asm(tmp, (u16 __user *)src,
20096+ __get_user_asm(tmp, (const u16 __user *)src,
20097 ret, "w", "w", "=r", 2);
20098 if (likely(!ret))
20099 __put_user_asm(tmp, (u16 __user *)dst,
20100@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20101
20102 case 4: {
20103 u32 tmp;
20104- __get_user_asm(tmp, (u32 __user *)src,
20105+ __get_user_asm(tmp, (const u32 __user *)src,
20106 ret, "l", "k", "=r", 4);
20107 if (likely(!ret))
20108 __put_user_asm(tmp, (u32 __user *)dst,
20109@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20110 }
20111 case 8: {
20112 u64 tmp;
20113- __get_user_asm(tmp, (u64 __user *)src,
20114+ __get_user_asm(tmp, (const u64 __user *)src,
20115 ret, "q", "", "=r", 8);
20116 if (likely(!ret))
20117 __put_user_asm(tmp, (u64 __user *)dst,
20118@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20119 return ret;
20120 }
20121 default:
20122- return copy_user_generic((__force void *)dst,
20123- (__force void *)src, size);
20124+ return copy_user_generic((__force_kernel void *)____m(dst),
20125+ (__force_kernel const void *)____m(src), size);
20126 }
20127 }
20128
20129-static __must_check __always_inline int
20130-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20131+static __must_check __always_inline unsigned long
20132+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20133 {
20134 return __copy_from_user_nocheck(dst, src, size);
20135 }
20136
20137-static __must_check __always_inline int
20138-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20139+static __must_check __always_inline unsigned long
20140+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20141 {
20142 return __copy_to_user_nocheck(dst, src, size);
20143 }
20144
20145-extern long __copy_user_nocache(void *dst, const void __user *src,
20146- unsigned size, int zerorest);
20147+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20148+ unsigned long size, int zerorest);
20149
20150-static inline int
20151-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20152+static inline unsigned long
20153+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20154 {
20155 might_fault();
20156+
20157+ if (size > INT_MAX)
20158+ return size;
20159+
20160+#ifdef CONFIG_PAX_MEMORY_UDEREF
20161+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20162+ return size;
20163+#endif
20164+
20165 return __copy_user_nocache(dst, src, size, 1);
20166 }
20167
20168-static inline int
20169+static inline unsigned long
20170 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20171- unsigned size)
20172+ unsigned long size)
20173 {
20174+ if (size > INT_MAX)
20175+ return size;
20176+
20177+#ifdef CONFIG_PAX_MEMORY_UDEREF
20178+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20179+ return size;
20180+#endif
20181+
20182 return __copy_user_nocache(dst, src, size, 0);
20183 }
20184
20185 unsigned long
20186-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20187+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20188
20189 #endif /* _ASM_X86_UACCESS_64_H */
20190diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20191index 5b238981..77fdd78 100644
20192--- a/arch/x86/include/asm/word-at-a-time.h
20193+++ b/arch/x86/include/asm/word-at-a-time.h
20194@@ -11,7 +11,7 @@
20195 * and shift, for example.
20196 */
20197 struct word_at_a_time {
20198- const unsigned long one_bits, high_bits;
20199+ unsigned long one_bits, high_bits;
20200 };
20201
20202 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20203diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20204index e45e4da..44e8572 100644
20205--- a/arch/x86/include/asm/x86_init.h
20206+++ b/arch/x86/include/asm/x86_init.h
20207@@ -129,7 +129,7 @@ struct x86_init_ops {
20208 struct x86_init_timers timers;
20209 struct x86_init_iommu iommu;
20210 struct x86_init_pci pci;
20211-};
20212+} __no_const;
20213
20214 /**
20215 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20216@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20217 void (*setup_percpu_clockev)(void);
20218 void (*early_percpu_clock_init)(void);
20219 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20220-};
20221+} __no_const;
20222
20223 struct timespec;
20224
20225@@ -168,7 +168,7 @@ struct x86_platform_ops {
20226 void (*save_sched_clock_state)(void);
20227 void (*restore_sched_clock_state)(void);
20228 void (*apic_post_init)(void);
20229-};
20230+} __no_const;
20231
20232 struct pci_dev;
20233 struct msi_msg;
20234@@ -185,7 +185,7 @@ struct x86_msi_ops {
20235 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20236 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20237 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20238-};
20239+} __no_const;
20240
20241 struct IO_APIC_route_entry;
20242 struct io_apic_irq_attr;
20243@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20244 unsigned int destination, int vector,
20245 struct io_apic_irq_attr *attr);
20246 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20247-};
20248+} __no_const;
20249
20250 extern struct x86_init_ops x86_init;
20251 extern struct x86_cpuinit_ops x86_cpuinit;
20252diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20253index c949923..c22bfa4 100644
20254--- a/arch/x86/include/asm/xen/page.h
20255+++ b/arch/x86/include/asm/xen/page.h
20256@@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20257 extern struct page *m2p_find_override(unsigned long mfn);
20258 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20259
20260-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20261+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20262 {
20263 unsigned long mfn;
20264
20265diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20266index d949ef2..479b9d1 100644
20267--- a/arch/x86/include/asm/xsave.h
20268+++ b/arch/x86/include/asm/xsave.h
20269@@ -82,8 +82,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20270 if (unlikely(err))
20271 return -EFAULT;
20272
20273+ pax_open_userland();
20274 __asm__ __volatile__(ASM_STAC "\n"
20275- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20276+ "1:"
20277+ __copyuser_seg
20278+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20279 "2: " ASM_CLAC "\n"
20280 ".section .fixup,\"ax\"\n"
20281 "3: movl $-1,%[err]\n"
20282@@ -93,18 +96,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20283 : [err] "=r" (err)
20284 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20285 : "memory");
20286+ pax_close_userland();
20287 return err;
20288 }
20289
20290 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20291 {
20292 int err;
20293- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20294+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20295 u32 lmask = mask;
20296 u32 hmask = mask >> 32;
20297
20298+ pax_open_userland();
20299 __asm__ __volatile__(ASM_STAC "\n"
20300- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20301+ "1:"
20302+ __copyuser_seg
20303+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20304 "2: " ASM_CLAC "\n"
20305 ".section .fixup,\"ax\"\n"
20306 "3: movl $-1,%[err]\n"
20307@@ -114,6 +121,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20308 : [err] "=r" (err)
20309 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20310 : "memory"); /* memory required? */
20311+ pax_close_userland();
20312 return err;
20313 }
20314
20315diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20316index bbae024..e1528f9 100644
20317--- a/arch/x86/include/uapi/asm/e820.h
20318+++ b/arch/x86/include/uapi/asm/e820.h
20319@@ -63,7 +63,7 @@ struct e820map {
20320 #define ISA_START_ADDRESS 0xa0000
20321 #define ISA_END_ADDRESS 0x100000
20322
20323-#define BIOS_BEGIN 0x000a0000
20324+#define BIOS_BEGIN 0x000c0000
20325 #define BIOS_END 0x00100000
20326
20327 #define BIOS_ROM_BASE 0xffe00000
20328diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20329index 7b0a55a..ad115bf 100644
20330--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20331+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20332@@ -49,7 +49,6 @@
20333 #define EFLAGS 144
20334 #define RSP 152
20335 #define SS 160
20336-#define ARGOFFSET R11
20337 #endif /* __ASSEMBLY__ */
20338
20339 /* top of stack page */
20340diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20341index f4d9600..b45af01 100644
20342--- a/arch/x86/kernel/Makefile
20343+++ b/arch/x86/kernel/Makefile
20344@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20345 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20346 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20347 obj-y += probe_roms.o
20348-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20349+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20350 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20351 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20352 obj-$(CONFIG_X86_64) += vsyscall_64.o
20353diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20354index 86281ff..e046fc2 100644
20355--- a/arch/x86/kernel/acpi/boot.c
20356+++ b/arch/x86/kernel/acpi/boot.c
20357@@ -1296,7 +1296,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20358 * If your system is blacklisted here, but you find that acpi=force
20359 * works for you, please contact linux-acpi@vger.kernel.org
20360 */
20361-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20362+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20363 /*
20364 * Boxes that need ACPI disabled
20365 */
20366@@ -1371,7 +1371,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20367 };
20368
20369 /* second table for DMI checks that should run after early-quirks */
20370-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20371+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20372 /*
20373 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20374 * which includes some code which overrides all temperature
20375diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20376index 3136820..e2c6577 100644
20377--- a/arch/x86/kernel/acpi/sleep.c
20378+++ b/arch/x86/kernel/acpi/sleep.c
20379@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20380 #else /* CONFIG_64BIT */
20381 #ifdef CONFIG_SMP
20382 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20383+
20384+ pax_open_kernel();
20385 early_gdt_descr.address =
20386 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20387+ pax_close_kernel();
20388+
20389 initial_gs = per_cpu_offset(smp_processor_id());
20390 #endif
20391 initial_code = (unsigned long)wakeup_long64;
20392diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20393index 665c6b7..eae4d56 100644
20394--- a/arch/x86/kernel/acpi/wakeup_32.S
20395+++ b/arch/x86/kernel/acpi/wakeup_32.S
20396@@ -29,13 +29,11 @@ wakeup_pmode_return:
20397 # and restore the stack ... but you need gdt for this to work
20398 movl saved_context_esp, %esp
20399
20400- movl %cs:saved_magic, %eax
20401- cmpl $0x12345678, %eax
20402+ cmpl $0x12345678, saved_magic
20403 jne bogus_magic
20404
20405 # jump to place where we left off
20406- movl saved_eip, %eax
20407- jmp *%eax
20408+ jmp *(saved_eip)
20409
20410 bogus_magic:
20411 jmp bogus_magic
20412diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20413index df94598..b7162f9 100644
20414--- a/arch/x86/kernel/alternative.c
20415+++ b/arch/x86/kernel/alternative.c
20416@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20417 */
20418 for (a = start; a < end; a++) {
20419 instr = (u8 *)&a->instr_offset + a->instr_offset;
20420+
20421+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20422+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20423+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20424+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20425+#endif
20426+
20427 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20428 BUG_ON(a->replacementlen > a->instrlen);
20429 BUG_ON(a->instrlen > sizeof(insnbuf));
20430@@ -285,6 +292,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20431 add_nops(insnbuf + a->replacementlen,
20432 a->instrlen - a->replacementlen);
20433
20434+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20435+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20436+ instr = ktva_ktla(instr);
20437+#endif
20438+
20439 text_poke_early(instr, insnbuf, a->instrlen);
20440 }
20441 }
20442@@ -300,10 +312,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20443 for (poff = start; poff < end; poff++) {
20444 u8 *ptr = (u8 *)poff + *poff;
20445
20446+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20447+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20448+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20449+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20450+#endif
20451+
20452 if (!*poff || ptr < text || ptr >= text_end)
20453 continue;
20454 /* turn DS segment override prefix into lock prefix */
20455- if (*ptr == 0x3e)
20456+ if (*ktla_ktva(ptr) == 0x3e)
20457 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20458 }
20459 mutex_unlock(&text_mutex);
20460@@ -318,10 +336,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20461 for (poff = start; poff < end; poff++) {
20462 u8 *ptr = (u8 *)poff + *poff;
20463
20464+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20465+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20466+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20467+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20468+#endif
20469+
20470 if (!*poff || ptr < text || ptr >= text_end)
20471 continue;
20472 /* turn lock prefix into DS segment override prefix */
20473- if (*ptr == 0xf0)
20474+ if (*ktla_ktva(ptr) == 0xf0)
20475 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20476 }
20477 mutex_unlock(&text_mutex);
20478@@ -458,7 +482,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20479
20480 BUG_ON(p->len > MAX_PATCH_LEN);
20481 /* prep the buffer with the original instructions */
20482- memcpy(insnbuf, p->instr, p->len);
20483+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20484 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20485 (unsigned long)p->instr, p->len);
20486
20487@@ -505,7 +529,7 @@ void __init alternative_instructions(void)
20488 if (!uniproc_patched || num_possible_cpus() == 1)
20489 free_init_pages("SMP alternatives",
20490 (unsigned long)__smp_locks,
20491- (unsigned long)__smp_locks_end);
20492+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20493 #endif
20494
20495 apply_paravirt(__parainstructions, __parainstructions_end);
20496@@ -525,13 +549,17 @@ void __init alternative_instructions(void)
20497 * instructions. And on the local CPU you need to be protected again NMI or MCE
20498 * handlers seeing an inconsistent instruction while you patch.
20499 */
20500-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20501+void *__kprobes text_poke_early(void *addr, const void *opcode,
20502 size_t len)
20503 {
20504 unsigned long flags;
20505 local_irq_save(flags);
20506- memcpy(addr, opcode, len);
20507+
20508+ pax_open_kernel();
20509+ memcpy(ktla_ktva(addr), opcode, len);
20510 sync_core();
20511+ pax_close_kernel();
20512+
20513 local_irq_restore(flags);
20514 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20515 that causes hangs on some VIA CPUs. */
20516@@ -553,36 +581,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20517 */
20518 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20519 {
20520- unsigned long flags;
20521- char *vaddr;
20522+ unsigned char *vaddr = ktla_ktva(addr);
20523 struct page *pages[2];
20524- int i;
20525+ size_t i;
20526
20527 if (!core_kernel_text((unsigned long)addr)) {
20528- pages[0] = vmalloc_to_page(addr);
20529- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20530+ pages[0] = vmalloc_to_page(vaddr);
20531+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20532 } else {
20533- pages[0] = virt_to_page(addr);
20534+ pages[0] = virt_to_page(vaddr);
20535 WARN_ON(!PageReserved(pages[0]));
20536- pages[1] = virt_to_page(addr + PAGE_SIZE);
20537+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20538 }
20539 BUG_ON(!pages[0]);
20540- local_irq_save(flags);
20541- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20542- if (pages[1])
20543- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20544- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20545- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20546- clear_fixmap(FIX_TEXT_POKE0);
20547- if (pages[1])
20548- clear_fixmap(FIX_TEXT_POKE1);
20549- local_flush_tlb();
20550- sync_core();
20551- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20552- that causes hangs on some VIA CPUs. */
20553+ text_poke_early(addr, opcode, len);
20554 for (i = 0; i < len; i++)
20555- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20556- local_irq_restore(flags);
20557+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20558 return addr;
20559 }
20560
20561@@ -602,7 +616,7 @@ int poke_int3_handler(struct pt_regs *regs)
20562 if (likely(!bp_patching_in_progress))
20563 return 0;
20564
20565- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20566+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20567 return 0;
20568
20569 /* set up the specified breakpoint handler */
20570@@ -636,7 +650,7 @@ int poke_int3_handler(struct pt_regs *regs)
20571 */
20572 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20573 {
20574- unsigned char int3 = 0xcc;
20575+ const unsigned char int3 = 0xcc;
20576
20577 bp_int3_handler = handler;
20578 bp_int3_addr = (u8 *)addr + sizeof(int3);
20579diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20580index ad28db7..c538b2c 100644
20581--- a/arch/x86/kernel/apic/apic.c
20582+++ b/arch/x86/kernel/apic/apic.c
20583@@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20584 /*
20585 * Debug level, exported for io_apic.c
20586 */
20587-unsigned int apic_verbosity;
20588+int apic_verbosity;
20589
20590 int pic_mode;
20591
20592@@ -2000,7 +2000,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20593 apic_write(APIC_ESR, 0);
20594 v = apic_read(APIC_ESR);
20595 ack_APIC_irq();
20596- atomic_inc(&irq_err_count);
20597+ atomic_inc_unchecked(&irq_err_count);
20598
20599 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20600 smp_processor_id(), v);
20601diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20602index 7c1b294..e71d27f 100644
20603--- a/arch/x86/kernel/apic/apic_flat_64.c
20604+++ b/arch/x86/kernel/apic/apic_flat_64.c
20605@@ -154,7 +154,7 @@ static int flat_probe(void)
20606 return 1;
20607 }
20608
20609-static struct apic apic_flat = {
20610+static struct apic apic_flat __read_only = {
20611 .name = "flat",
20612 .probe = flat_probe,
20613 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20614@@ -268,7 +268,7 @@ static int physflat_probe(void)
20615 return 0;
20616 }
20617
20618-static struct apic apic_physflat = {
20619+static struct apic apic_physflat __read_only = {
20620
20621 .name = "physical flat",
20622 .probe = physflat_probe,
20623diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20624index 8c7c982..a225910 100644
20625--- a/arch/x86/kernel/apic/apic_noop.c
20626+++ b/arch/x86/kernel/apic/apic_noop.c
20627@@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20628 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20629 }
20630
20631-struct apic apic_noop = {
20632+struct apic apic_noop __read_only = {
20633 .name = "noop",
20634 .probe = noop_probe,
20635 .acpi_madt_oem_check = NULL,
20636diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20637index e4840aa..e7d9dac 100644
20638--- a/arch/x86/kernel/apic/bigsmp_32.c
20639+++ b/arch/x86/kernel/apic/bigsmp_32.c
20640@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20641 return dmi_bigsmp;
20642 }
20643
20644-static struct apic apic_bigsmp = {
20645+static struct apic apic_bigsmp __read_only = {
20646
20647 .name = "bigsmp",
20648 .probe = probe_bigsmp,
20649diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20650index 992060e..ecdc3b3 100644
20651--- a/arch/x86/kernel/apic/io_apic.c
20652+++ b/arch/x86/kernel/apic/io_apic.c
20653@@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20654 }
20655 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20656
20657-void lock_vector_lock(void)
20658+void lock_vector_lock(void) __acquires(vector_lock)
20659 {
20660 /* Used to the online set of cpus does not change
20661 * during assign_irq_vector.
20662@@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20663 raw_spin_lock(&vector_lock);
20664 }
20665
20666-void unlock_vector_lock(void)
20667+void unlock_vector_lock(void) __releases(vector_lock)
20668 {
20669 raw_spin_unlock(&vector_lock);
20670 }
20671@@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20672 ack_APIC_irq();
20673 }
20674
20675-atomic_t irq_mis_count;
20676+atomic_unchecked_t irq_mis_count;
20677
20678 #ifdef CONFIG_GENERIC_PENDING_IRQ
20679 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20680@@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20681 * at the cpu.
20682 */
20683 if (!(v & (1 << (i & 0x1f)))) {
20684- atomic_inc(&irq_mis_count);
20685+ atomic_inc_unchecked(&irq_mis_count);
20686
20687 eoi_ioapic_irq(irq, cfg);
20688 }
20689diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20690index cceb352..a635fd8 100644
20691--- a/arch/x86/kernel/apic/probe_32.c
20692+++ b/arch/x86/kernel/apic/probe_32.c
20693@@ -72,7 +72,7 @@ static int probe_default(void)
20694 return 1;
20695 }
20696
20697-static struct apic apic_default = {
20698+static struct apic apic_default __read_only = {
20699
20700 .name = "default",
20701 .probe = probe_default,
20702diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20703index e66766b..1c008ba 100644
20704--- a/arch/x86/kernel/apic/x2apic_cluster.c
20705+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20706@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20707 return notifier_from_errno(err);
20708 }
20709
20710-static struct notifier_block __refdata x2apic_cpu_notifier = {
20711+static struct notifier_block x2apic_cpu_notifier = {
20712 .notifier_call = update_clusterinfo,
20713 };
20714
20715@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20716 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20717 }
20718
20719-static struct apic apic_x2apic_cluster = {
20720+static struct apic apic_x2apic_cluster __read_only = {
20721
20722 .name = "cluster x2apic",
20723 .probe = x2apic_cluster_probe,
20724diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20725index 6d600eb..0300c00 100644
20726--- a/arch/x86/kernel/apic/x2apic_phys.c
20727+++ b/arch/x86/kernel/apic/x2apic_phys.c
20728@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20729 return apic == &apic_x2apic_phys;
20730 }
20731
20732-static struct apic apic_x2apic_phys = {
20733+static struct apic apic_x2apic_phys __read_only = {
20734
20735 .name = "physical x2apic",
20736 .probe = x2apic_phys_probe,
20737diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20738index 7834389..4ffc9c8 100644
20739--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20740+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20741@@ -350,7 +350,7 @@ static int uv_probe(void)
20742 return apic == &apic_x2apic_uv_x;
20743 }
20744
20745-static struct apic __refdata apic_x2apic_uv_x = {
20746+static struct apic apic_x2apic_uv_x __read_only = {
20747
20748 .name = "UV large system",
20749 .probe = uv_probe,
20750diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20751index 3ab0343..814c4787 100644
20752--- a/arch/x86/kernel/apm_32.c
20753+++ b/arch/x86/kernel/apm_32.c
20754@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20755 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20756 * even though they are called in protected mode.
20757 */
20758-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20759+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20760 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20761
20762 static const char driver_version[] = "1.16ac"; /* no spaces */
20763@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20764 BUG_ON(cpu != 0);
20765 gdt = get_cpu_gdt_table(cpu);
20766 save_desc_40 = gdt[0x40 / 8];
20767+
20768+ pax_open_kernel();
20769 gdt[0x40 / 8] = bad_bios_desc;
20770+ pax_close_kernel();
20771
20772 apm_irq_save(flags);
20773 APM_DO_SAVE_SEGS;
20774@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20775 &call->esi);
20776 APM_DO_RESTORE_SEGS;
20777 apm_irq_restore(flags);
20778+
20779+ pax_open_kernel();
20780 gdt[0x40 / 8] = save_desc_40;
20781+ pax_close_kernel();
20782+
20783 put_cpu();
20784
20785 return call->eax & 0xff;
20786@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20787 BUG_ON(cpu != 0);
20788 gdt = get_cpu_gdt_table(cpu);
20789 save_desc_40 = gdt[0x40 / 8];
20790+
20791+ pax_open_kernel();
20792 gdt[0x40 / 8] = bad_bios_desc;
20793+ pax_close_kernel();
20794
20795 apm_irq_save(flags);
20796 APM_DO_SAVE_SEGS;
20797@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20798 &call->eax);
20799 APM_DO_RESTORE_SEGS;
20800 apm_irq_restore(flags);
20801+
20802+ pax_open_kernel();
20803 gdt[0x40 / 8] = save_desc_40;
20804+ pax_close_kernel();
20805+
20806 put_cpu();
20807 return error;
20808 }
20809@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20810 * code to that CPU.
20811 */
20812 gdt = get_cpu_gdt_table(0);
20813+
20814+ pax_open_kernel();
20815 set_desc_base(&gdt[APM_CS >> 3],
20816 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20817 set_desc_base(&gdt[APM_CS_16 >> 3],
20818 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20819 set_desc_base(&gdt[APM_DS >> 3],
20820 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20821+ pax_close_kernel();
20822
20823 proc_create("apm", 0, NULL, &apm_file_ops);
20824
20825diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20826index 9f6b934..cf5ffb3 100644
20827--- a/arch/x86/kernel/asm-offsets.c
20828+++ b/arch/x86/kernel/asm-offsets.c
20829@@ -32,6 +32,8 @@ void common(void) {
20830 OFFSET(TI_flags, thread_info, flags);
20831 OFFSET(TI_status, thread_info, status);
20832 OFFSET(TI_addr_limit, thread_info, addr_limit);
20833+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20834+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20835
20836 BLANK();
20837 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20838@@ -52,8 +54,26 @@ void common(void) {
20839 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20840 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20841 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20842+
20843+#ifdef CONFIG_PAX_KERNEXEC
20844+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20845 #endif
20846
20847+#ifdef CONFIG_PAX_MEMORY_UDEREF
20848+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20849+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20850+#ifdef CONFIG_X86_64
20851+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20852+#endif
20853+#endif
20854+
20855+#endif
20856+
20857+ BLANK();
20858+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20859+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20860+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20861+
20862 #ifdef CONFIG_XEN
20863 BLANK();
20864 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20865diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20866index e7c798b..2b2019b 100644
20867--- a/arch/x86/kernel/asm-offsets_64.c
20868+++ b/arch/x86/kernel/asm-offsets_64.c
20869@@ -77,6 +77,7 @@ int main(void)
20870 BLANK();
20871 #undef ENTRY
20872
20873+ DEFINE(TSS_size, sizeof(struct tss_struct));
20874 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20875 BLANK();
20876
20877diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20878index 7fd54f0..0691410 100644
20879--- a/arch/x86/kernel/cpu/Makefile
20880+++ b/arch/x86/kernel/cpu/Makefile
20881@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20882 CFLAGS_REMOVE_perf_event.o = -pg
20883 endif
20884
20885-# Make sure load_percpu_segment has no stackprotector
20886-nostackp := $(call cc-option, -fno-stack-protector)
20887-CFLAGS_common.o := $(nostackp)
20888-
20889 obj-y := intel_cacheinfo.o scattered.o topology.o
20890 obj-y += proc.o capflags.o powerflags.o common.o
20891 obj-y += rdrand.o
20892diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20893index ce8b8ff..d7d8851 100644
20894--- a/arch/x86/kernel/cpu/amd.c
20895+++ b/arch/x86/kernel/cpu/amd.c
20896@@ -728,7 +728,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20897 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20898 {
20899 /* AMD errata T13 (order #21922) */
20900- if ((c->x86 == 6)) {
20901+ if (c->x86 == 6) {
20902 /* Duron Rev A0 */
20903 if (c->x86_model == 3 && c->x86_mask == 0)
20904 size = 64;
20905diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20906index a135239..41fb30a 100644
20907--- a/arch/x86/kernel/cpu/common.c
20908+++ b/arch/x86/kernel/cpu/common.c
20909@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20910
20911 static const struct cpu_dev *this_cpu = &default_cpu;
20912
20913-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20914-#ifdef CONFIG_X86_64
20915- /*
20916- * We need valid kernel segments for data and code in long mode too
20917- * IRET will check the segment types kkeil 2000/10/28
20918- * Also sysret mandates a special GDT layout
20919- *
20920- * TLS descriptors are currently at a different place compared to i386.
20921- * Hopefully nobody expects them at a fixed place (Wine?)
20922- */
20923- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20924- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20925- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20926- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20927- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20928- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20929-#else
20930- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20931- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20932- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20933- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20934- /*
20935- * Segments used for calling PnP BIOS have byte granularity.
20936- * They code segments and data segments have fixed 64k limits,
20937- * the transfer segment sizes are set at run time.
20938- */
20939- /* 32-bit code */
20940- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20941- /* 16-bit code */
20942- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20943- /* 16-bit data */
20944- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20945- /* 16-bit data */
20946- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20947- /* 16-bit data */
20948- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20949- /*
20950- * The APM segments have byte granularity and their bases
20951- * are set at run time. All have 64k limits.
20952- */
20953- /* 32-bit code */
20954- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20955- /* 16-bit code */
20956- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20957- /* data */
20958- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20959-
20960- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20961- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20962- GDT_STACK_CANARY_INIT
20963-#endif
20964-} };
20965-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20966-
20967 static int __init x86_xsave_setup(char *s)
20968 {
20969 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20970@@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20971 }
20972 }
20973
20974+#ifdef CONFIG_X86_64
20975+static __init int setup_disable_pcid(char *arg)
20976+{
20977+ setup_clear_cpu_cap(X86_FEATURE_PCID);
20978+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20979+
20980+#ifdef CONFIG_PAX_MEMORY_UDEREF
20981+ if (clone_pgd_mask != ~(pgdval_t)0UL)
20982+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20983+#endif
20984+
20985+ return 1;
20986+}
20987+__setup("nopcid", setup_disable_pcid);
20988+
20989+static void setup_pcid(struct cpuinfo_x86 *c)
20990+{
20991+ if (!cpu_has(c, X86_FEATURE_PCID)) {
20992+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
20993+
20994+#ifdef CONFIG_PAX_MEMORY_UDEREF
20995+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
20996+ pax_open_kernel();
20997+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20998+ pax_close_kernel();
20999+ printk("PAX: slow and weak UDEREF enabled\n");
21000+ } else
21001+ printk("PAX: UDEREF disabled\n");
21002+#endif
21003+
21004+ return;
21005+ }
21006+
21007+ printk("PAX: PCID detected\n");
21008+ set_in_cr4(X86_CR4_PCIDE);
21009+
21010+#ifdef CONFIG_PAX_MEMORY_UDEREF
21011+ pax_open_kernel();
21012+ clone_pgd_mask = ~(pgdval_t)0UL;
21013+ pax_close_kernel();
21014+ if (pax_user_shadow_base)
21015+ printk("PAX: weak UDEREF enabled\n");
21016+ else {
21017+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21018+ printk("PAX: strong UDEREF enabled\n");
21019+ }
21020+#endif
21021+
21022+ if (cpu_has(c, X86_FEATURE_INVPCID))
21023+ printk("PAX: INVPCID detected\n");
21024+}
21025+#endif
21026+
21027 /*
21028 * Some CPU features depend on higher CPUID levels, which may not always
21029 * be available due to CPUID level capping or broken virtualization
21030@@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
21031 {
21032 struct desc_ptr gdt_descr;
21033
21034- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21035+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21036 gdt_descr.size = GDT_SIZE - 1;
21037 load_gdt(&gdt_descr);
21038 /* Reload the per-cpu base */
21039@@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21040 setup_smep(c);
21041 setup_smap(c);
21042
21043+#ifdef CONFIG_X86_64
21044+ setup_pcid(c);
21045+#endif
21046+
21047 /*
21048 * The vendor-specific functions might have changed features.
21049 * Now we do "generic changes."
21050@@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21051 /* Filter out anything that depends on CPUID levels we don't have */
21052 filter_cpuid_features(c, true);
21053
21054+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21055+ setup_clear_cpu_cap(X86_FEATURE_SEP);
21056+#endif
21057+
21058 /* If the model name is still unset, do table lookup. */
21059 if (!c->x86_model_id[0]) {
21060 const char *p;
21061@@ -1079,14 +1086,16 @@ static __init int setup_disablecpuid(char *arg)
21062 }
21063 __setup("clearcpuid=", setup_disablecpuid);
21064
21065+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21066+EXPORT_PER_CPU_SYMBOL(current_tinfo);
21067+
21068 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21069- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21070+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21071 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21072
21073 #ifdef CONFIG_X86_64
21074-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21075-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21076- (unsigned long) debug_idt_table };
21077+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21078+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21079
21080 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21081 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21082@@ -1246,7 +1255,7 @@ void cpu_init(void)
21083 load_ucode_ap();
21084
21085 cpu = stack_smp_processor_id();
21086- t = &per_cpu(init_tss, cpu);
21087+ t = init_tss + cpu;
21088 oist = &per_cpu(orig_ist, cpu);
21089
21090 #ifdef CONFIG_NUMA
21091@@ -1281,7 +1290,6 @@ void cpu_init(void)
21092 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21093 barrier();
21094
21095- x86_configure_nx();
21096 enable_x2apic();
21097
21098 /*
21099@@ -1333,7 +1341,7 @@ void cpu_init(void)
21100 {
21101 int cpu = smp_processor_id();
21102 struct task_struct *curr = current;
21103- struct tss_struct *t = &per_cpu(init_tss, cpu);
21104+ struct tss_struct *t = init_tss + cpu;
21105 struct thread_struct *thread = &curr->thread;
21106
21107 show_ucode_info_early();
21108diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21109index a952e9c..58a4cbb 100644
21110--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21111+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21112@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21113 };
21114
21115 #ifdef CONFIG_AMD_NB
21116+static struct attribute *default_attrs_amd_nb[] = {
21117+ &type.attr,
21118+ &level.attr,
21119+ &coherency_line_size.attr,
21120+ &physical_line_partition.attr,
21121+ &ways_of_associativity.attr,
21122+ &number_of_sets.attr,
21123+ &size.attr,
21124+ &shared_cpu_map.attr,
21125+ &shared_cpu_list.attr,
21126+ NULL,
21127+ NULL,
21128+ NULL,
21129+ NULL
21130+};
21131+
21132 static struct attribute **amd_l3_attrs(void)
21133 {
21134 static struct attribute **attrs;
21135@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21136
21137 n = ARRAY_SIZE(default_attrs);
21138
21139- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21140- n += 2;
21141-
21142- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21143- n += 1;
21144-
21145- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21146- if (attrs == NULL)
21147- return attrs = default_attrs;
21148-
21149- for (n = 0; default_attrs[n]; n++)
21150- attrs[n] = default_attrs[n];
21151+ attrs = default_attrs_amd_nb;
21152
21153 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21154 attrs[n++] = &cache_disable_0.attr;
21155@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21156 .default_attrs = default_attrs,
21157 };
21158
21159+#ifdef CONFIG_AMD_NB
21160+static struct kobj_type ktype_cache_amd_nb = {
21161+ .sysfs_ops = &sysfs_ops,
21162+ .default_attrs = default_attrs_amd_nb,
21163+};
21164+#endif
21165+
21166 static struct kobj_type ktype_percpu_entry = {
21167 .sysfs_ops = &sysfs_ops,
21168 };
21169@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21170 return retval;
21171 }
21172
21173+#ifdef CONFIG_AMD_NB
21174+ amd_l3_attrs();
21175+#endif
21176+
21177 for (i = 0; i < num_cache_leaves; i++) {
21178+ struct kobj_type *ktype;
21179+
21180 this_object = INDEX_KOBJECT_PTR(cpu, i);
21181 this_object->cpu = cpu;
21182 this_object->index = i;
21183
21184 this_leaf = CPUID4_INFO_IDX(cpu, i);
21185
21186- ktype_cache.default_attrs = default_attrs;
21187+ ktype = &ktype_cache;
21188 #ifdef CONFIG_AMD_NB
21189 if (this_leaf->base.nb)
21190- ktype_cache.default_attrs = amd_l3_attrs();
21191+ ktype = &ktype_cache_amd_nb;
21192 #endif
21193 retval = kobject_init_and_add(&(this_object->kobj),
21194- &ktype_cache,
21195+ ktype,
21196 per_cpu(ici_cache_kobject, cpu),
21197 "index%1lu", i);
21198 if (unlikely(retval)) {
21199diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21200index 68317c8..c860d41 100644
21201--- a/arch/x86/kernel/cpu/mcheck/mce.c
21202+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21203@@ -45,6 +45,7 @@
21204 #include <asm/processor.h>
21205 #include <asm/mce.h>
21206 #include <asm/msr.h>
21207+#include <asm/local.h>
21208
21209 #include "mce-internal.h"
21210
21211@@ -261,7 +262,7 @@ static void print_mce(struct mce *m)
21212 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21213 m->cs, m->ip);
21214
21215- if (m->cs == __KERNEL_CS)
21216+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21217 print_symbol("{%s}", m->ip);
21218 pr_cont("\n");
21219 }
21220@@ -294,10 +295,10 @@ static void print_mce(struct mce *m)
21221
21222 #define PANIC_TIMEOUT 5 /* 5 seconds */
21223
21224-static atomic_t mce_paniced;
21225+static atomic_unchecked_t mce_paniced;
21226
21227 static int fake_panic;
21228-static atomic_t mce_fake_paniced;
21229+static atomic_unchecked_t mce_fake_paniced;
21230
21231 /* Panic in progress. Enable interrupts and wait for final IPI */
21232 static void wait_for_panic(void)
21233@@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21234 /*
21235 * Make sure only one CPU runs in machine check panic
21236 */
21237- if (atomic_inc_return(&mce_paniced) > 1)
21238+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21239 wait_for_panic();
21240 barrier();
21241
21242@@ -329,7 +330,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21243 console_verbose();
21244 } else {
21245 /* Don't log too much for fake panic */
21246- if (atomic_inc_return(&mce_fake_paniced) > 1)
21247+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21248 return;
21249 }
21250 /* First print corrected ones that are still unlogged */
21251@@ -368,7 +369,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21252 if (!fake_panic) {
21253 if (panic_timeout == 0)
21254 panic_timeout = mca_cfg.panic_timeout;
21255- panic(msg);
21256+ panic("%s", msg);
21257 } else
21258 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21259 }
21260@@ -699,7 +700,7 @@ static int mce_timed_out(u64 *t)
21261 * might have been modified by someone else.
21262 */
21263 rmb();
21264- if (atomic_read(&mce_paniced))
21265+ if (atomic_read_unchecked(&mce_paniced))
21266 wait_for_panic();
21267 if (!mca_cfg.monarch_timeout)
21268 goto out;
21269@@ -1680,7 +1681,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21270 }
21271
21272 /* Call the installed machine check handler for this CPU setup. */
21273-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21274+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21275 unexpected_machine_check;
21276
21277 /*
21278@@ -1703,7 +1704,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21279 return;
21280 }
21281
21282+ pax_open_kernel();
21283 machine_check_vector = do_machine_check;
21284+ pax_close_kernel();
21285
21286 __mcheck_cpu_init_generic();
21287 __mcheck_cpu_init_vendor(c);
21288@@ -1717,7 +1720,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21289 */
21290
21291 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21292-static int mce_chrdev_open_count; /* #times opened */
21293+static local_t mce_chrdev_open_count; /* #times opened */
21294 static int mce_chrdev_open_exclu; /* already open exclusive? */
21295
21296 static int mce_chrdev_open(struct inode *inode, struct file *file)
21297@@ -1725,7 +1728,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21298 spin_lock(&mce_chrdev_state_lock);
21299
21300 if (mce_chrdev_open_exclu ||
21301- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21302+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21303 spin_unlock(&mce_chrdev_state_lock);
21304
21305 return -EBUSY;
21306@@ -1733,7 +1736,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21307
21308 if (file->f_flags & O_EXCL)
21309 mce_chrdev_open_exclu = 1;
21310- mce_chrdev_open_count++;
21311+ local_inc(&mce_chrdev_open_count);
21312
21313 spin_unlock(&mce_chrdev_state_lock);
21314
21315@@ -1744,7 +1747,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21316 {
21317 spin_lock(&mce_chrdev_state_lock);
21318
21319- mce_chrdev_open_count--;
21320+ local_dec(&mce_chrdev_open_count);
21321 mce_chrdev_open_exclu = 0;
21322
21323 spin_unlock(&mce_chrdev_state_lock);
21324@@ -2420,7 +2423,7 @@ static __init void mce_init_banks(void)
21325
21326 for (i = 0; i < mca_cfg.banks; i++) {
21327 struct mce_bank *b = &mce_banks[i];
21328- struct device_attribute *a = &b->attr;
21329+ device_attribute_no_const *a = &b->attr;
21330
21331 sysfs_attr_init(&a->attr);
21332 a->attr.name = b->attrname;
21333@@ -2492,7 +2495,7 @@ struct dentry *mce_get_debugfs_dir(void)
21334 static void mce_reset(void)
21335 {
21336 cpu_missing = 0;
21337- atomic_set(&mce_fake_paniced, 0);
21338+ atomic_set_unchecked(&mce_fake_paniced, 0);
21339 atomic_set(&mce_executing, 0);
21340 atomic_set(&mce_callin, 0);
21341 atomic_set(&global_nwo, 0);
21342diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21343index a304298..49b6d06 100644
21344--- a/arch/x86/kernel/cpu/mcheck/p5.c
21345+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21346@@ -10,6 +10,7 @@
21347 #include <asm/processor.h>
21348 #include <asm/mce.h>
21349 #include <asm/msr.h>
21350+#include <asm/pgtable.h>
21351
21352 /* By default disabled */
21353 int mce_p5_enabled __read_mostly;
21354@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21355 if (!cpu_has(c, X86_FEATURE_MCE))
21356 return;
21357
21358+ pax_open_kernel();
21359 machine_check_vector = pentium_machine_check;
21360+ pax_close_kernel();
21361 /* Make sure the vector pointer is visible before we enable MCEs: */
21362 wmb();
21363
21364diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21365index 7dc5564..1273569 100644
21366--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21367+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21368@@ -9,6 +9,7 @@
21369 #include <asm/processor.h>
21370 #include <asm/mce.h>
21371 #include <asm/msr.h>
21372+#include <asm/pgtable.h>
21373
21374 /* Machine check handler for WinChip C6: */
21375 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21376@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21377 {
21378 u32 lo, hi;
21379
21380+ pax_open_kernel();
21381 machine_check_vector = winchip_machine_check;
21382+ pax_close_kernel();
21383 /* Make sure the vector pointer is visible before we enable MCEs: */
21384 wmb();
21385
21386diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21387index 15c9876..0a43909 100644
21388--- a/arch/x86/kernel/cpu/microcode/core.c
21389+++ b/arch/x86/kernel/cpu/microcode/core.c
21390@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21391 return NOTIFY_OK;
21392 }
21393
21394-static struct notifier_block __refdata mc_cpu_notifier = {
21395+static struct notifier_block mc_cpu_notifier = {
21396 .notifier_call = mc_cpu_callback,
21397 };
21398
21399diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21400index a276fa7..e66810f 100644
21401--- a/arch/x86/kernel/cpu/microcode/intel.c
21402+++ b/arch/x86/kernel/cpu/microcode/intel.c
21403@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21404
21405 static int get_ucode_user(void *to, const void *from, size_t n)
21406 {
21407- return copy_from_user(to, from, n);
21408+ return copy_from_user(to, (const void __force_user *)from, n);
21409 }
21410
21411 static enum ucode_state
21412 request_microcode_user(int cpu, const void __user *buf, size_t size)
21413 {
21414- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21415+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21416 }
21417
21418 static void microcode_fini_cpu(int cpu)
21419diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21420index f961de9..8a9d332 100644
21421--- a/arch/x86/kernel/cpu/mtrr/main.c
21422+++ b/arch/x86/kernel/cpu/mtrr/main.c
21423@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21424 u64 size_or_mask, size_and_mask;
21425 static bool mtrr_aps_delayed_init;
21426
21427-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21428+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21429
21430 const struct mtrr_ops *mtrr_if;
21431
21432diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21433index df5e41f..816c719 100644
21434--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21435+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21436@@ -25,7 +25,7 @@ struct mtrr_ops {
21437 int (*validate_add_page)(unsigned long base, unsigned long size,
21438 unsigned int type);
21439 int (*have_wrcomb)(void);
21440-};
21441+} __do_const;
21442
21443 extern int generic_get_free_region(unsigned long base, unsigned long size,
21444 int replace_reg);
21445diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21446index ae407f7..39c5b00 100644
21447--- a/arch/x86/kernel/cpu/perf_event.c
21448+++ b/arch/x86/kernel/cpu/perf_event.c
21449@@ -1367,7 +1367,7 @@ static void __init pmu_check_apic(void)
21450 pr_info("no hardware sampling interrupt available.\n");
21451 }
21452
21453-static struct attribute_group x86_pmu_format_group = {
21454+static attribute_group_no_const x86_pmu_format_group = {
21455 .name = "format",
21456 .attrs = NULL,
21457 };
21458@@ -1466,7 +1466,7 @@ static struct attribute *events_attr[] = {
21459 NULL,
21460 };
21461
21462-static struct attribute_group x86_pmu_events_group = {
21463+static attribute_group_no_const x86_pmu_events_group = {
21464 .name = "events",
21465 .attrs = events_attr,
21466 };
21467@@ -1990,7 +1990,7 @@ static unsigned long get_segment_base(unsigned int segment)
21468 if (idx > GDT_ENTRIES)
21469 return 0;
21470
21471- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21472+ desc = get_cpu_gdt_table(smp_processor_id());
21473 }
21474
21475 return get_desc_base(desc + idx);
21476@@ -2080,7 +2080,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21477 break;
21478
21479 perf_callchain_store(entry, frame.return_address);
21480- fp = frame.next_frame;
21481+ fp = (const void __force_user *)frame.next_frame;
21482 }
21483 }
21484
21485diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21486index 639d128..e92d7e5 100644
21487--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21488+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21489@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21490 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21491 {
21492 struct attribute **attrs;
21493- struct attribute_group *attr_group;
21494+ attribute_group_no_const *attr_group;
21495 int i = 0, j;
21496
21497 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21498diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21499index adb02aa..9688c02 100644
21500--- a/arch/x86/kernel/cpu/perf_event_intel.c
21501+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21502@@ -2308,10 +2308,10 @@ __init int intel_pmu_init(void)
21503 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21504
21505 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21506- u64 capabilities;
21507+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21508
21509- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21510- x86_pmu.intel_cap.capabilities = capabilities;
21511+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21512+ x86_pmu.intel_cap.capabilities = capabilities;
21513 }
21514
21515 intel_ds_init();
21516diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21517index 619f769..d510008 100644
21518--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21519+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21520@@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21521 NULL,
21522 };
21523
21524-static struct attribute_group rapl_pmu_events_group = {
21525+static attribute_group_no_const rapl_pmu_events_group __read_only = {
21526 .name = "events",
21527 .attrs = NULL, /* patched at runtime */
21528 };
21529diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21530index 65bbbea..1438d9e 100644
21531--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21532+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21533@@ -3693,7 +3693,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21534 static int __init uncore_type_init(struct intel_uncore_type *type)
21535 {
21536 struct intel_uncore_pmu *pmus;
21537- struct attribute_group *attr_group;
21538+ attribute_group_no_const *attr_group;
21539 struct attribute **attrs;
21540 int i, j;
21541
21542diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21543index 90236f0..54cb20d 100644
21544--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21545+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21546@@ -503,7 +503,7 @@ struct intel_uncore_box {
21547 struct uncore_event_desc {
21548 struct kobj_attribute attr;
21549 const char *config;
21550-};
21551+} __do_const;
21552
21553 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21554 { \
21555diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21556index 3225ae6c..ee3c6db 100644
21557--- a/arch/x86/kernel/cpuid.c
21558+++ b/arch/x86/kernel/cpuid.c
21559@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21560 return notifier_from_errno(err);
21561 }
21562
21563-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21564+static struct notifier_block cpuid_class_cpu_notifier =
21565 {
21566 .notifier_call = cpuid_class_cpu_callback,
21567 };
21568diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21569index 507de80..ebaae2a 100644
21570--- a/arch/x86/kernel/crash.c
21571+++ b/arch/x86/kernel/crash.c
21572@@ -58,7 +58,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21573 #ifdef CONFIG_X86_32
21574 struct pt_regs fixed_regs;
21575
21576- if (!user_mode_vm(regs)) {
21577+ if (!user_mode(regs)) {
21578 crash_fixup_ss_esp(&fixed_regs, regs);
21579 regs = &fixed_regs;
21580 }
21581diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21582index afa64ad..dce67dd 100644
21583--- a/arch/x86/kernel/crash_dump_64.c
21584+++ b/arch/x86/kernel/crash_dump_64.c
21585@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21586 return -ENOMEM;
21587
21588 if (userbuf) {
21589- if (copy_to_user(buf, vaddr + offset, csize)) {
21590+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21591 iounmap(vaddr);
21592 return -EFAULT;
21593 }
21594diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21595index f6dfd93..892ade4 100644
21596--- a/arch/x86/kernel/doublefault.c
21597+++ b/arch/x86/kernel/doublefault.c
21598@@ -12,7 +12,7 @@
21599
21600 #define DOUBLEFAULT_STACKSIZE (1024)
21601 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21602-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21603+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21604
21605 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21606
21607@@ -22,7 +22,7 @@ static void doublefault_fn(void)
21608 unsigned long gdt, tss;
21609
21610 native_store_gdt(&gdt_desc);
21611- gdt = gdt_desc.address;
21612+ gdt = (unsigned long)gdt_desc.address;
21613
21614 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21615
21616@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21617 /* 0x2 bit is always set */
21618 .flags = X86_EFLAGS_SF | 0x2,
21619 .sp = STACK_START,
21620- .es = __USER_DS,
21621+ .es = __KERNEL_DS,
21622 .cs = __KERNEL_CS,
21623 .ss = __KERNEL_DS,
21624- .ds = __USER_DS,
21625+ .ds = __KERNEL_DS,
21626 .fs = __KERNEL_PERCPU,
21627
21628 .__cr3 = __pa_nodebug(swapper_pg_dir),
21629diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21630index d9c12d3..7858b62 100644
21631--- a/arch/x86/kernel/dumpstack.c
21632+++ b/arch/x86/kernel/dumpstack.c
21633@@ -2,6 +2,9 @@
21634 * Copyright (C) 1991, 1992 Linus Torvalds
21635 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21636 */
21637+#ifdef CONFIG_GRKERNSEC_HIDESYM
21638+#define __INCLUDED_BY_HIDESYM 1
21639+#endif
21640 #include <linux/kallsyms.h>
21641 #include <linux/kprobes.h>
21642 #include <linux/uaccess.h>
21643@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21644 static void
21645 print_ftrace_graph_addr(unsigned long addr, void *data,
21646 const struct stacktrace_ops *ops,
21647- struct thread_info *tinfo, int *graph)
21648+ struct task_struct *task, int *graph)
21649 {
21650- struct task_struct *task;
21651 unsigned long ret_addr;
21652 int index;
21653
21654 if (addr != (unsigned long)return_to_handler)
21655 return;
21656
21657- task = tinfo->task;
21658 index = task->curr_ret_stack;
21659
21660 if (!task->ret_stack || index < *graph)
21661@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21662 static inline void
21663 print_ftrace_graph_addr(unsigned long addr, void *data,
21664 const struct stacktrace_ops *ops,
21665- struct thread_info *tinfo, int *graph)
21666+ struct task_struct *task, int *graph)
21667 { }
21668 #endif
21669
21670@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21671 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21672 */
21673
21674-static inline int valid_stack_ptr(struct thread_info *tinfo,
21675- void *p, unsigned int size, void *end)
21676+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21677 {
21678- void *t = tinfo;
21679 if (end) {
21680 if (p < end && p >= (end-THREAD_SIZE))
21681 return 1;
21682@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21683 }
21684
21685 unsigned long
21686-print_context_stack(struct thread_info *tinfo,
21687+print_context_stack(struct task_struct *task, void *stack_start,
21688 unsigned long *stack, unsigned long bp,
21689 const struct stacktrace_ops *ops, void *data,
21690 unsigned long *end, int *graph)
21691 {
21692 struct stack_frame *frame = (struct stack_frame *)bp;
21693
21694- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21695+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21696 unsigned long addr;
21697
21698 addr = *stack;
21699@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21700 } else {
21701 ops->address(data, addr, 0);
21702 }
21703- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21704+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21705 }
21706 stack++;
21707 }
21708@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21709 EXPORT_SYMBOL_GPL(print_context_stack);
21710
21711 unsigned long
21712-print_context_stack_bp(struct thread_info *tinfo,
21713+print_context_stack_bp(struct task_struct *task, void *stack_start,
21714 unsigned long *stack, unsigned long bp,
21715 const struct stacktrace_ops *ops, void *data,
21716 unsigned long *end, int *graph)
21717@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21718 struct stack_frame *frame = (struct stack_frame *)bp;
21719 unsigned long *ret_addr = &frame->return_address;
21720
21721- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21722+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21723 unsigned long addr = *ret_addr;
21724
21725 if (!__kernel_text_address(addr))
21726@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21727 ops->address(data, addr, 1);
21728 frame = frame->next_frame;
21729 ret_addr = &frame->return_address;
21730- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21731+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21732 }
21733
21734 return (unsigned long)frame;
21735@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21736 static void print_trace_address(void *data, unsigned long addr, int reliable)
21737 {
21738 touch_nmi_watchdog();
21739- printk(data);
21740+ printk("%s", (char *)data);
21741 printk_stack_address(addr, reliable);
21742 }
21743
21744@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21745 }
21746 EXPORT_SYMBOL_GPL(oops_begin);
21747
21748+extern void gr_handle_kernel_exploit(void);
21749+
21750 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21751 {
21752 if (regs && kexec_should_crash(current))
21753@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21754 panic("Fatal exception in interrupt");
21755 if (panic_on_oops)
21756 panic("Fatal exception");
21757- do_exit(signr);
21758+
21759+ gr_handle_kernel_exploit();
21760+
21761+ do_group_exit(signr);
21762 }
21763
21764 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21765@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21766 print_modules();
21767 show_regs(regs);
21768 #ifdef CONFIG_X86_32
21769- if (user_mode_vm(regs)) {
21770+ if (user_mode(regs)) {
21771 sp = regs->sp;
21772 ss = regs->ss & 0xffff;
21773 } else {
21774@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21775 unsigned long flags = oops_begin();
21776 int sig = SIGSEGV;
21777
21778- if (!user_mode_vm(regs))
21779+ if (!user_mode(regs))
21780 report_bug(regs->ip, regs);
21781
21782 if (__die(str, regs, err))
21783diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21784index 5abd4cd..c65733b 100644
21785--- a/arch/x86/kernel/dumpstack_32.c
21786+++ b/arch/x86/kernel/dumpstack_32.c
21787@@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21788 bp = stack_frame(task, regs);
21789
21790 for (;;) {
21791- struct thread_info *context;
21792+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21793 void *end_stack;
21794
21795 end_stack = is_hardirq_stack(stack, cpu);
21796 if (!end_stack)
21797 end_stack = is_softirq_stack(stack, cpu);
21798
21799- context = task_thread_info(task);
21800- bp = ops->walk_stack(context, stack, bp, ops, data,
21801+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
21802 end_stack, &graph);
21803
21804 /* Stop if not on irq stack */
21805@@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
21806 int i;
21807
21808 show_regs_print_info(KERN_EMERG);
21809- __show_regs(regs, !user_mode_vm(regs));
21810+ __show_regs(regs, !user_mode(regs));
21811
21812 /*
21813 * When in-kernel, we also print out the stack and code at the
21814 * time of the fault..
21815 */
21816- if (!user_mode_vm(regs)) {
21817+ if (!user_mode(regs)) {
21818 unsigned int code_prologue = code_bytes * 43 / 64;
21819 unsigned int code_len = code_bytes;
21820 unsigned char c;
21821 u8 *ip;
21822+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21823
21824 pr_emerg("Stack:\n");
21825 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21826
21827 pr_emerg("Code:");
21828
21829- ip = (u8 *)regs->ip - code_prologue;
21830+ ip = (u8 *)regs->ip - code_prologue + cs_base;
21831 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21832 /* try starting at IP */
21833- ip = (u8 *)regs->ip;
21834+ ip = (u8 *)regs->ip + cs_base;
21835 code_len = code_len - code_prologue + 1;
21836 }
21837 for (i = 0; i < code_len; i++, ip++) {
21838@@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
21839 pr_cont(" Bad EIP value.");
21840 break;
21841 }
21842- if (ip == (u8 *)regs->ip)
21843+ if (ip == (u8 *)regs->ip + cs_base)
21844 pr_cont(" <%02x>", c);
21845 else
21846 pr_cont(" %02x", c);
21847@@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
21848 {
21849 unsigned short ud2;
21850
21851+ ip = ktla_ktva(ip);
21852 if (ip < PAGE_OFFSET)
21853 return 0;
21854 if (probe_kernel_address((unsigned short *)ip, ud2))
21855@@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
21856
21857 return ud2 == 0x0b0f;
21858 }
21859+
21860+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21861+void pax_check_alloca(unsigned long size)
21862+{
21863+ unsigned long sp = (unsigned long)&sp, stack_left;
21864+
21865+ /* all kernel stacks are of the same size */
21866+ stack_left = sp & (THREAD_SIZE - 1);
21867+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21868+}
21869+EXPORT_SYMBOL(pax_check_alloca);
21870+#endif
21871diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21872index 1abcb50..6c8d702 100644
21873--- a/arch/x86/kernel/dumpstack_64.c
21874+++ b/arch/x86/kernel/dumpstack_64.c
21875@@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21876 const struct stacktrace_ops *ops, void *data)
21877 {
21878 const unsigned cpu = get_cpu();
21879- struct thread_info *tinfo;
21880 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21881 unsigned long dummy;
21882 unsigned used = 0;
21883 int graph = 0;
21884 int done = 0;
21885+ void *stack_start;
21886
21887 if (!task)
21888 task = current;
21889@@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21890 * current stack address. If the stacks consist of nested
21891 * exceptions
21892 */
21893- tinfo = task_thread_info(task);
21894 while (!done) {
21895 unsigned long *stack_end;
21896 enum stack_type stype;
21897@@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21898 if (ops->stack(data, id) < 0)
21899 break;
21900
21901- bp = ops->walk_stack(tinfo, stack, bp, ops,
21902+ bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
21903 data, stack_end, &graph);
21904 ops->stack(data, "<EOE>");
21905 /*
21906@@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21907 * second-to-last pointer (index -2 to end) in the
21908 * exception stack:
21909 */
21910+ if ((u16)stack_end[-1] != __KERNEL_DS)
21911+ goto out;
21912 stack = (unsigned long *) stack_end[-2];
21913 done = 0;
21914 break;
21915@@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21916
21917 if (ops->stack(data, "IRQ") < 0)
21918 break;
21919- bp = ops->walk_stack(tinfo, stack, bp,
21920+ bp = ops->walk_stack(task, irq_stack, stack, bp,
21921 ops, data, stack_end, &graph);
21922 /*
21923 * We link to the next stack (which would be
21924@@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21925 /*
21926 * This handles the process stack:
21927 */
21928- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21929+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21930+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21931+out:
21932 put_cpu();
21933 }
21934 EXPORT_SYMBOL(dump_trace);
21935@@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
21936
21937 return ud2 == 0x0b0f;
21938 }
21939+
21940+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21941+void pax_check_alloca(unsigned long size)
21942+{
21943+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21944+ unsigned cpu, used;
21945+ char *id;
21946+
21947+ /* check the process stack first */
21948+ stack_start = (unsigned long)task_stack_page(current);
21949+ stack_end = stack_start + THREAD_SIZE;
21950+ if (likely(stack_start <= sp && sp < stack_end)) {
21951+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
21952+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21953+ return;
21954+ }
21955+
21956+ cpu = get_cpu();
21957+
21958+ /* check the irq stacks */
21959+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21960+ stack_start = stack_end - IRQ_STACK_SIZE;
21961+ if (stack_start <= sp && sp < stack_end) {
21962+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21963+ put_cpu();
21964+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21965+ return;
21966+ }
21967+
21968+ /* check the exception stacks */
21969+ used = 0;
21970+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21971+ stack_start = stack_end - EXCEPTION_STKSZ;
21972+ if (stack_end && stack_start <= sp && sp < stack_end) {
21973+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21974+ put_cpu();
21975+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21976+ return;
21977+ }
21978+
21979+ put_cpu();
21980+
21981+ /* unknown stack */
21982+ BUG();
21983+}
21984+EXPORT_SYMBOL(pax_check_alloca);
21985+#endif
21986diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21987index 988c00a..4f673b6 100644
21988--- a/arch/x86/kernel/e820.c
21989+++ b/arch/x86/kernel/e820.c
21990@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21991
21992 static void early_panic(char *msg)
21993 {
21994- early_printk(msg);
21995- panic(msg);
21996+ early_printk("%s", msg);
21997+ panic("%s", msg);
21998 }
21999
22000 static int userdef __initdata;
22001diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22002index 01d1c18..8073693 100644
22003--- a/arch/x86/kernel/early_printk.c
22004+++ b/arch/x86/kernel/early_printk.c
22005@@ -7,6 +7,7 @@
22006 #include <linux/pci_regs.h>
22007 #include <linux/pci_ids.h>
22008 #include <linux/errno.h>
22009+#include <linux/sched.h>
22010 #include <asm/io.h>
22011 #include <asm/processor.h>
22012 #include <asm/fcntl.h>
22013diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22014index 6491353..a918952 100644
22015--- a/arch/x86/kernel/entry_32.S
22016+++ b/arch/x86/kernel/entry_32.S
22017@@ -177,13 +177,153 @@
22018 /*CFI_REL_OFFSET gs, PT_GS*/
22019 .endm
22020 .macro SET_KERNEL_GS reg
22021+
22022+#ifdef CONFIG_CC_STACKPROTECTOR
22023 movl $(__KERNEL_STACK_CANARY), \reg
22024+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22025+ movl $(__USER_DS), \reg
22026+#else
22027+ xorl \reg, \reg
22028+#endif
22029+
22030 movl \reg, %gs
22031 .endm
22032
22033 #endif /* CONFIG_X86_32_LAZY_GS */
22034
22035-.macro SAVE_ALL
22036+.macro pax_enter_kernel
22037+#ifdef CONFIG_PAX_KERNEXEC
22038+ call pax_enter_kernel
22039+#endif
22040+.endm
22041+
22042+.macro pax_exit_kernel
22043+#ifdef CONFIG_PAX_KERNEXEC
22044+ call pax_exit_kernel
22045+#endif
22046+.endm
22047+
22048+#ifdef CONFIG_PAX_KERNEXEC
22049+ENTRY(pax_enter_kernel)
22050+#ifdef CONFIG_PARAVIRT
22051+ pushl %eax
22052+ pushl %ecx
22053+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22054+ mov %eax, %esi
22055+#else
22056+ mov %cr0, %esi
22057+#endif
22058+ bts $16, %esi
22059+ jnc 1f
22060+ mov %cs, %esi
22061+ cmp $__KERNEL_CS, %esi
22062+ jz 3f
22063+ ljmp $__KERNEL_CS, $3f
22064+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22065+2:
22066+#ifdef CONFIG_PARAVIRT
22067+ mov %esi, %eax
22068+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22069+#else
22070+ mov %esi, %cr0
22071+#endif
22072+3:
22073+#ifdef CONFIG_PARAVIRT
22074+ popl %ecx
22075+ popl %eax
22076+#endif
22077+ ret
22078+ENDPROC(pax_enter_kernel)
22079+
22080+ENTRY(pax_exit_kernel)
22081+#ifdef CONFIG_PARAVIRT
22082+ pushl %eax
22083+ pushl %ecx
22084+#endif
22085+ mov %cs, %esi
22086+ cmp $__KERNEXEC_KERNEL_CS, %esi
22087+ jnz 2f
22088+#ifdef CONFIG_PARAVIRT
22089+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22090+ mov %eax, %esi
22091+#else
22092+ mov %cr0, %esi
22093+#endif
22094+ btr $16, %esi
22095+ ljmp $__KERNEL_CS, $1f
22096+1:
22097+#ifdef CONFIG_PARAVIRT
22098+ mov %esi, %eax
22099+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22100+#else
22101+ mov %esi, %cr0
22102+#endif
22103+2:
22104+#ifdef CONFIG_PARAVIRT
22105+ popl %ecx
22106+ popl %eax
22107+#endif
22108+ ret
22109+ENDPROC(pax_exit_kernel)
22110+#endif
22111+
22112+ .macro pax_erase_kstack
22113+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22114+ call pax_erase_kstack
22115+#endif
22116+ .endm
22117+
22118+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22119+/*
22120+ * ebp: thread_info
22121+ */
22122+ENTRY(pax_erase_kstack)
22123+ pushl %edi
22124+ pushl %ecx
22125+ pushl %eax
22126+
22127+ mov TI_lowest_stack(%ebp), %edi
22128+ mov $-0xBEEF, %eax
22129+ std
22130+
22131+1: mov %edi, %ecx
22132+ and $THREAD_SIZE_asm - 1, %ecx
22133+ shr $2, %ecx
22134+ repne scasl
22135+ jecxz 2f
22136+
22137+ cmp $2*16, %ecx
22138+ jc 2f
22139+
22140+ mov $2*16, %ecx
22141+ repe scasl
22142+ jecxz 2f
22143+ jne 1b
22144+
22145+2: cld
22146+ mov %esp, %ecx
22147+ sub %edi, %ecx
22148+
22149+ cmp $THREAD_SIZE_asm, %ecx
22150+ jb 3f
22151+ ud2
22152+3:
22153+
22154+ shr $2, %ecx
22155+ rep stosl
22156+
22157+ mov TI_task_thread_sp0(%ebp), %edi
22158+ sub $128, %edi
22159+ mov %edi, TI_lowest_stack(%ebp)
22160+
22161+ popl %eax
22162+ popl %ecx
22163+ popl %edi
22164+ ret
22165+ENDPROC(pax_erase_kstack)
22166+#endif
22167+
22168+.macro __SAVE_ALL _DS
22169 cld
22170 PUSH_GS
22171 pushl_cfi %fs
22172@@ -206,7 +346,7 @@
22173 CFI_REL_OFFSET ecx, 0
22174 pushl_cfi %ebx
22175 CFI_REL_OFFSET ebx, 0
22176- movl $(__USER_DS), %edx
22177+ movl $\_DS, %edx
22178 movl %edx, %ds
22179 movl %edx, %es
22180 movl $(__KERNEL_PERCPU), %edx
22181@@ -214,6 +354,15 @@
22182 SET_KERNEL_GS %edx
22183 .endm
22184
22185+.macro SAVE_ALL
22186+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22187+ __SAVE_ALL __KERNEL_DS
22188+ pax_enter_kernel
22189+#else
22190+ __SAVE_ALL __USER_DS
22191+#endif
22192+.endm
22193+
22194 .macro RESTORE_INT_REGS
22195 popl_cfi %ebx
22196 CFI_RESTORE ebx
22197@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22198 popfl_cfi
22199 jmp syscall_exit
22200 CFI_ENDPROC
22201-END(ret_from_fork)
22202+ENDPROC(ret_from_fork)
22203
22204 ENTRY(ret_from_kernel_thread)
22205 CFI_STARTPROC
22206@@ -344,7 +493,15 @@ ret_from_intr:
22207 andl $SEGMENT_RPL_MASK, %eax
22208 #endif
22209 cmpl $USER_RPL, %eax
22210+
22211+#ifdef CONFIG_PAX_KERNEXEC
22212+ jae resume_userspace
22213+
22214+ pax_exit_kernel
22215+ jmp resume_kernel
22216+#else
22217 jb resume_kernel # not returning to v8086 or userspace
22218+#endif
22219
22220 ENTRY(resume_userspace)
22221 LOCKDEP_SYS_EXIT
22222@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22223 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22224 # int/exception return?
22225 jne work_pending
22226- jmp restore_all
22227-END(ret_from_exception)
22228+ jmp restore_all_pax
22229+ENDPROC(ret_from_exception)
22230
22231 #ifdef CONFIG_PREEMPT
22232 ENTRY(resume_kernel)
22233@@ -369,7 +526,7 @@ need_resched:
22234 jz restore_all
22235 call preempt_schedule_irq
22236 jmp need_resched
22237-END(resume_kernel)
22238+ENDPROC(resume_kernel)
22239 #endif
22240 CFI_ENDPROC
22241 /*
22242@@ -403,30 +560,45 @@ sysenter_past_esp:
22243 /*CFI_REL_OFFSET cs, 0*/
22244 /*
22245 * Push current_thread_info()->sysenter_return to the stack.
22246- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22247- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22248 */
22249- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22250+ pushl_cfi $0
22251 CFI_REL_OFFSET eip, 0
22252
22253 pushl_cfi %eax
22254 SAVE_ALL
22255+ GET_THREAD_INFO(%ebp)
22256+ movl TI_sysenter_return(%ebp),%ebp
22257+ movl %ebp,PT_EIP(%esp)
22258 ENABLE_INTERRUPTS(CLBR_NONE)
22259
22260 /*
22261 * Load the potential sixth argument from user stack.
22262 * Careful about security.
22263 */
22264+ movl PT_OLDESP(%esp),%ebp
22265+
22266+#ifdef CONFIG_PAX_MEMORY_UDEREF
22267+ mov PT_OLDSS(%esp),%ds
22268+1: movl %ds:(%ebp),%ebp
22269+ push %ss
22270+ pop %ds
22271+#else
22272 cmpl $__PAGE_OFFSET-3,%ebp
22273 jae syscall_fault
22274 ASM_STAC
22275 1: movl (%ebp),%ebp
22276 ASM_CLAC
22277+#endif
22278+
22279 movl %ebp,PT_EBP(%esp)
22280 _ASM_EXTABLE(1b,syscall_fault)
22281
22282 GET_THREAD_INFO(%ebp)
22283
22284+#ifdef CONFIG_PAX_RANDKSTACK
22285+ pax_erase_kstack
22286+#endif
22287+
22288 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22289 jnz sysenter_audit
22290 sysenter_do_call:
22291@@ -442,12 +614,24 @@ sysenter_after_call:
22292 testl $_TIF_ALLWORK_MASK, %ecx
22293 jne sysexit_audit
22294 sysenter_exit:
22295+
22296+#ifdef CONFIG_PAX_RANDKSTACK
22297+ pushl_cfi %eax
22298+ movl %esp, %eax
22299+ call pax_randomize_kstack
22300+ popl_cfi %eax
22301+#endif
22302+
22303+ pax_erase_kstack
22304+
22305 /* if something modifies registers it must also disable sysexit */
22306 movl PT_EIP(%esp), %edx
22307 movl PT_OLDESP(%esp), %ecx
22308 xorl %ebp,%ebp
22309 TRACE_IRQS_ON
22310 1: mov PT_FS(%esp), %fs
22311+2: mov PT_DS(%esp), %ds
22312+3: mov PT_ES(%esp), %es
22313 PTGS_TO_GS
22314 ENABLE_INTERRUPTS_SYSEXIT
22315
22316@@ -464,6 +648,9 @@ sysenter_audit:
22317 movl %eax,%edx /* 2nd arg: syscall number */
22318 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22319 call __audit_syscall_entry
22320+
22321+ pax_erase_kstack
22322+
22323 pushl_cfi %ebx
22324 movl PT_EAX(%esp),%eax /* reload syscall number */
22325 jmp sysenter_do_call
22326@@ -489,10 +676,16 @@ sysexit_audit:
22327
22328 CFI_ENDPROC
22329 .pushsection .fixup,"ax"
22330-2: movl $0,PT_FS(%esp)
22331+4: movl $0,PT_FS(%esp)
22332+ jmp 1b
22333+5: movl $0,PT_DS(%esp)
22334+ jmp 1b
22335+6: movl $0,PT_ES(%esp)
22336 jmp 1b
22337 .popsection
22338- _ASM_EXTABLE(1b,2b)
22339+ _ASM_EXTABLE(1b,4b)
22340+ _ASM_EXTABLE(2b,5b)
22341+ _ASM_EXTABLE(3b,6b)
22342 PTGS_TO_GS_EX
22343 ENDPROC(ia32_sysenter_target)
22344
22345@@ -507,6 +700,11 @@ ENTRY(system_call)
22346 pushl_cfi %eax # save orig_eax
22347 SAVE_ALL
22348 GET_THREAD_INFO(%ebp)
22349+
22350+#ifdef CONFIG_PAX_RANDKSTACK
22351+ pax_erase_kstack
22352+#endif
22353+
22354 # system call tracing in operation / emulation
22355 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22356 jnz syscall_trace_entry
22357@@ -525,6 +723,15 @@ syscall_exit:
22358 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22359 jne syscall_exit_work
22360
22361+restore_all_pax:
22362+
22363+#ifdef CONFIG_PAX_RANDKSTACK
22364+ movl %esp, %eax
22365+ call pax_randomize_kstack
22366+#endif
22367+
22368+ pax_erase_kstack
22369+
22370 restore_all:
22371 TRACE_IRQS_IRET
22372 restore_all_notrace:
22373@@ -576,14 +783,34 @@ ldt_ss:
22374 * compensating for the offset by changing to the ESPFIX segment with
22375 * a base address that matches for the difference.
22376 */
22377-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22378+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22379 mov %esp, %edx /* load kernel esp */
22380 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22381 mov %dx, %ax /* eax: new kernel esp */
22382 sub %eax, %edx /* offset (low word is 0) */
22383+#ifdef CONFIG_SMP
22384+ movl PER_CPU_VAR(cpu_number), %ebx
22385+ shll $PAGE_SHIFT_asm, %ebx
22386+ addl $cpu_gdt_table, %ebx
22387+#else
22388+ movl $cpu_gdt_table, %ebx
22389+#endif
22390 shr $16, %edx
22391- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22392- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22393+
22394+#ifdef CONFIG_PAX_KERNEXEC
22395+ mov %cr0, %esi
22396+ btr $16, %esi
22397+ mov %esi, %cr0
22398+#endif
22399+
22400+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22401+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22402+
22403+#ifdef CONFIG_PAX_KERNEXEC
22404+ bts $16, %esi
22405+ mov %esi, %cr0
22406+#endif
22407+
22408 pushl_cfi $__ESPFIX_SS
22409 pushl_cfi %eax /* new kernel esp */
22410 /* Disable interrupts, but do not irqtrace this section: we
22411@@ -612,20 +839,18 @@ work_resched:
22412 movl TI_flags(%ebp), %ecx
22413 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22414 # than syscall tracing?
22415- jz restore_all
22416+ jz restore_all_pax
22417 testb $_TIF_NEED_RESCHED, %cl
22418 jnz work_resched
22419
22420 work_notifysig: # deal with pending signals and
22421 # notify-resume requests
22422+ movl %esp, %eax
22423 #ifdef CONFIG_VM86
22424 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22425- movl %esp, %eax
22426 jne work_notifysig_v86 # returning to kernel-space or
22427 # vm86-space
22428 1:
22429-#else
22430- movl %esp, %eax
22431 #endif
22432 TRACE_IRQS_ON
22433 ENABLE_INTERRUPTS(CLBR_NONE)
22434@@ -646,7 +871,7 @@ work_notifysig_v86:
22435 movl %eax, %esp
22436 jmp 1b
22437 #endif
22438-END(work_pending)
22439+ENDPROC(work_pending)
22440
22441 # perform syscall exit tracing
22442 ALIGN
22443@@ -654,11 +879,14 @@ syscall_trace_entry:
22444 movl $-ENOSYS,PT_EAX(%esp)
22445 movl %esp, %eax
22446 call syscall_trace_enter
22447+
22448+ pax_erase_kstack
22449+
22450 /* What it returned is what we'll actually use. */
22451 cmpl $(NR_syscalls), %eax
22452 jnae syscall_call
22453 jmp syscall_exit
22454-END(syscall_trace_entry)
22455+ENDPROC(syscall_trace_entry)
22456
22457 # perform syscall exit tracing
22458 ALIGN
22459@@ -671,26 +899,30 @@ syscall_exit_work:
22460 movl %esp, %eax
22461 call syscall_trace_leave
22462 jmp resume_userspace
22463-END(syscall_exit_work)
22464+ENDPROC(syscall_exit_work)
22465 CFI_ENDPROC
22466
22467 RING0_INT_FRAME # can't unwind into user space anyway
22468 syscall_fault:
22469+#ifdef CONFIG_PAX_MEMORY_UDEREF
22470+ push %ss
22471+ pop %ds
22472+#endif
22473 ASM_CLAC
22474 GET_THREAD_INFO(%ebp)
22475 movl $-EFAULT,PT_EAX(%esp)
22476 jmp resume_userspace
22477-END(syscall_fault)
22478+ENDPROC(syscall_fault)
22479
22480 syscall_badsys:
22481 movl $-ENOSYS,PT_EAX(%esp)
22482 jmp syscall_exit
22483-END(syscall_badsys)
22484+ENDPROC(syscall_badsys)
22485
22486 sysenter_badsys:
22487 movl $-ENOSYS,PT_EAX(%esp)
22488 jmp sysenter_after_call
22489-END(syscall_badsys)
22490+ENDPROC(sysenter_badsys)
22491 CFI_ENDPROC
22492 /*
22493 * End of kprobes section
22494@@ -706,8 +938,15 @@ END(syscall_badsys)
22495 * normal stack and adjusts ESP with the matching offset.
22496 */
22497 /* fixup the stack */
22498- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22499- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22500+#ifdef CONFIG_SMP
22501+ movl PER_CPU_VAR(cpu_number), %ebx
22502+ shll $PAGE_SHIFT_asm, %ebx
22503+ addl $cpu_gdt_table, %ebx
22504+#else
22505+ movl $cpu_gdt_table, %ebx
22506+#endif
22507+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22508+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22509 shl $16, %eax
22510 addl %esp, %eax /* the adjusted stack pointer */
22511 pushl_cfi $__KERNEL_DS
22512@@ -760,7 +999,7 @@ vector=vector+1
22513 .endr
22514 2: jmp common_interrupt
22515 .endr
22516-END(irq_entries_start)
22517+ENDPROC(irq_entries_start)
22518
22519 .previous
22520 END(interrupt)
22521@@ -821,7 +1060,7 @@ ENTRY(coprocessor_error)
22522 pushl_cfi $do_coprocessor_error
22523 jmp error_code
22524 CFI_ENDPROC
22525-END(coprocessor_error)
22526+ENDPROC(coprocessor_error)
22527
22528 ENTRY(simd_coprocessor_error)
22529 RING0_INT_FRAME
22530@@ -834,7 +1073,7 @@ ENTRY(simd_coprocessor_error)
22531 .section .altinstructions,"a"
22532 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22533 .previous
22534-.section .altinstr_replacement,"ax"
22535+.section .altinstr_replacement,"a"
22536 663: pushl $do_simd_coprocessor_error
22537 664:
22538 .previous
22539@@ -843,7 +1082,7 @@ ENTRY(simd_coprocessor_error)
22540 #endif
22541 jmp error_code
22542 CFI_ENDPROC
22543-END(simd_coprocessor_error)
22544+ENDPROC(simd_coprocessor_error)
22545
22546 ENTRY(device_not_available)
22547 RING0_INT_FRAME
22548@@ -852,18 +1091,18 @@ ENTRY(device_not_available)
22549 pushl_cfi $do_device_not_available
22550 jmp error_code
22551 CFI_ENDPROC
22552-END(device_not_available)
22553+ENDPROC(device_not_available)
22554
22555 #ifdef CONFIG_PARAVIRT
22556 ENTRY(native_iret)
22557 iret
22558 _ASM_EXTABLE(native_iret, iret_exc)
22559-END(native_iret)
22560+ENDPROC(native_iret)
22561
22562 ENTRY(native_irq_enable_sysexit)
22563 sti
22564 sysexit
22565-END(native_irq_enable_sysexit)
22566+ENDPROC(native_irq_enable_sysexit)
22567 #endif
22568
22569 ENTRY(overflow)
22570@@ -873,7 +1112,7 @@ ENTRY(overflow)
22571 pushl_cfi $do_overflow
22572 jmp error_code
22573 CFI_ENDPROC
22574-END(overflow)
22575+ENDPROC(overflow)
22576
22577 ENTRY(bounds)
22578 RING0_INT_FRAME
22579@@ -882,7 +1121,7 @@ ENTRY(bounds)
22580 pushl_cfi $do_bounds
22581 jmp error_code
22582 CFI_ENDPROC
22583-END(bounds)
22584+ENDPROC(bounds)
22585
22586 ENTRY(invalid_op)
22587 RING0_INT_FRAME
22588@@ -891,7 +1130,7 @@ ENTRY(invalid_op)
22589 pushl_cfi $do_invalid_op
22590 jmp error_code
22591 CFI_ENDPROC
22592-END(invalid_op)
22593+ENDPROC(invalid_op)
22594
22595 ENTRY(coprocessor_segment_overrun)
22596 RING0_INT_FRAME
22597@@ -900,7 +1139,7 @@ ENTRY(coprocessor_segment_overrun)
22598 pushl_cfi $do_coprocessor_segment_overrun
22599 jmp error_code
22600 CFI_ENDPROC
22601-END(coprocessor_segment_overrun)
22602+ENDPROC(coprocessor_segment_overrun)
22603
22604 ENTRY(invalid_TSS)
22605 RING0_EC_FRAME
22606@@ -908,7 +1147,7 @@ ENTRY(invalid_TSS)
22607 pushl_cfi $do_invalid_TSS
22608 jmp error_code
22609 CFI_ENDPROC
22610-END(invalid_TSS)
22611+ENDPROC(invalid_TSS)
22612
22613 ENTRY(segment_not_present)
22614 RING0_EC_FRAME
22615@@ -916,7 +1155,7 @@ ENTRY(segment_not_present)
22616 pushl_cfi $do_segment_not_present
22617 jmp error_code
22618 CFI_ENDPROC
22619-END(segment_not_present)
22620+ENDPROC(segment_not_present)
22621
22622 ENTRY(stack_segment)
22623 RING0_EC_FRAME
22624@@ -924,7 +1163,7 @@ ENTRY(stack_segment)
22625 pushl_cfi $do_stack_segment
22626 jmp error_code
22627 CFI_ENDPROC
22628-END(stack_segment)
22629+ENDPROC(stack_segment)
22630
22631 ENTRY(alignment_check)
22632 RING0_EC_FRAME
22633@@ -932,7 +1171,7 @@ ENTRY(alignment_check)
22634 pushl_cfi $do_alignment_check
22635 jmp error_code
22636 CFI_ENDPROC
22637-END(alignment_check)
22638+ENDPROC(alignment_check)
22639
22640 ENTRY(divide_error)
22641 RING0_INT_FRAME
22642@@ -941,7 +1180,7 @@ ENTRY(divide_error)
22643 pushl_cfi $do_divide_error
22644 jmp error_code
22645 CFI_ENDPROC
22646-END(divide_error)
22647+ENDPROC(divide_error)
22648
22649 #ifdef CONFIG_X86_MCE
22650 ENTRY(machine_check)
22651@@ -951,7 +1190,7 @@ ENTRY(machine_check)
22652 pushl_cfi machine_check_vector
22653 jmp error_code
22654 CFI_ENDPROC
22655-END(machine_check)
22656+ENDPROC(machine_check)
22657 #endif
22658
22659 ENTRY(spurious_interrupt_bug)
22660@@ -961,7 +1200,7 @@ ENTRY(spurious_interrupt_bug)
22661 pushl_cfi $do_spurious_interrupt_bug
22662 jmp error_code
22663 CFI_ENDPROC
22664-END(spurious_interrupt_bug)
22665+ENDPROC(spurious_interrupt_bug)
22666 /*
22667 * End of kprobes section
22668 */
22669@@ -1071,7 +1310,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22670
22671 ENTRY(mcount)
22672 ret
22673-END(mcount)
22674+ENDPROC(mcount)
22675
22676 ENTRY(ftrace_caller)
22677 cmpl $0, function_trace_stop
22678@@ -1104,7 +1343,7 @@ ftrace_graph_call:
22679 .globl ftrace_stub
22680 ftrace_stub:
22681 ret
22682-END(ftrace_caller)
22683+ENDPROC(ftrace_caller)
22684
22685 ENTRY(ftrace_regs_caller)
22686 pushf /* push flags before compare (in cs location) */
22687@@ -1208,7 +1447,7 @@ trace:
22688 popl %ecx
22689 popl %eax
22690 jmp ftrace_stub
22691-END(mcount)
22692+ENDPROC(mcount)
22693 #endif /* CONFIG_DYNAMIC_FTRACE */
22694 #endif /* CONFIG_FUNCTION_TRACER */
22695
22696@@ -1226,7 +1465,7 @@ ENTRY(ftrace_graph_caller)
22697 popl %ecx
22698 popl %eax
22699 ret
22700-END(ftrace_graph_caller)
22701+ENDPROC(ftrace_graph_caller)
22702
22703 .globl return_to_handler
22704 return_to_handler:
22705@@ -1292,15 +1531,18 @@ error_code:
22706 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22707 REG_TO_PTGS %ecx
22708 SET_KERNEL_GS %ecx
22709- movl $(__USER_DS), %ecx
22710+ movl $(__KERNEL_DS), %ecx
22711 movl %ecx, %ds
22712 movl %ecx, %es
22713+
22714+ pax_enter_kernel
22715+
22716 TRACE_IRQS_OFF
22717 movl %esp,%eax # pt_regs pointer
22718 call *%edi
22719 jmp ret_from_exception
22720 CFI_ENDPROC
22721-END(page_fault)
22722+ENDPROC(page_fault)
22723
22724 /*
22725 * Debug traps and NMI can happen at the one SYSENTER instruction
22726@@ -1343,7 +1585,7 @@ debug_stack_correct:
22727 call do_debug
22728 jmp ret_from_exception
22729 CFI_ENDPROC
22730-END(debug)
22731+ENDPROC(debug)
22732
22733 /*
22734 * NMI is doubly nasty. It can happen _while_ we're handling
22735@@ -1381,6 +1623,9 @@ nmi_stack_correct:
22736 xorl %edx,%edx # zero error code
22737 movl %esp,%eax # pt_regs pointer
22738 call do_nmi
22739+
22740+ pax_exit_kernel
22741+
22742 jmp restore_all_notrace
22743 CFI_ENDPROC
22744
22745@@ -1417,12 +1662,15 @@ nmi_espfix_stack:
22746 FIXUP_ESPFIX_STACK # %eax == %esp
22747 xorl %edx,%edx # zero error code
22748 call do_nmi
22749+
22750+ pax_exit_kernel
22751+
22752 RESTORE_REGS
22753 lss 12+4(%esp), %esp # back to espfix stack
22754 CFI_ADJUST_CFA_OFFSET -24
22755 jmp irq_return
22756 CFI_ENDPROC
22757-END(nmi)
22758+ENDPROC(nmi)
22759
22760 ENTRY(int3)
22761 RING0_INT_FRAME
22762@@ -1435,14 +1683,14 @@ ENTRY(int3)
22763 call do_int3
22764 jmp ret_from_exception
22765 CFI_ENDPROC
22766-END(int3)
22767+ENDPROC(int3)
22768
22769 ENTRY(general_protection)
22770 RING0_EC_FRAME
22771 pushl_cfi $do_general_protection
22772 jmp error_code
22773 CFI_ENDPROC
22774-END(general_protection)
22775+ENDPROC(general_protection)
22776
22777 #ifdef CONFIG_KVM_GUEST
22778 ENTRY(async_page_fault)
22779@@ -1451,7 +1699,7 @@ ENTRY(async_page_fault)
22780 pushl_cfi $do_async_page_fault
22781 jmp error_code
22782 CFI_ENDPROC
22783-END(async_page_fault)
22784+ENDPROC(async_page_fault)
22785 #endif
22786
22787 /*
22788diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22789index 1e96c36..3ff710a 100644
22790--- a/arch/x86/kernel/entry_64.S
22791+++ b/arch/x86/kernel/entry_64.S
22792@@ -59,6 +59,8 @@
22793 #include <asm/context_tracking.h>
22794 #include <asm/smap.h>
22795 #include <linux/err.h>
22796+#include <asm/pgtable.h>
22797+#include <asm/alternative-asm.h>
22798
22799 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22800 #include <linux/elf-em.h>
22801@@ -80,8 +82,9 @@
22802 #ifdef CONFIG_DYNAMIC_FTRACE
22803
22804 ENTRY(function_hook)
22805+ pax_force_retaddr
22806 retq
22807-END(function_hook)
22808+ENDPROC(function_hook)
22809
22810 /* skip is set if stack has been adjusted */
22811 .macro ftrace_caller_setup skip=0
22812@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22813 #endif
22814
22815 GLOBAL(ftrace_stub)
22816+ pax_force_retaddr
22817 retq
22818-END(ftrace_caller)
22819+ENDPROC(ftrace_caller)
22820
22821 ENTRY(ftrace_regs_caller)
22822 /* Save the current flags before compare (in SS location)*/
22823@@ -191,7 +195,7 @@ ftrace_restore_flags:
22824 popfq
22825 jmp ftrace_stub
22826
22827-END(ftrace_regs_caller)
22828+ENDPROC(ftrace_regs_caller)
22829
22830
22831 #else /* ! CONFIG_DYNAMIC_FTRACE */
22832@@ -212,6 +216,7 @@ ENTRY(function_hook)
22833 #endif
22834
22835 GLOBAL(ftrace_stub)
22836+ pax_force_retaddr
22837 retq
22838
22839 trace:
22840@@ -225,12 +230,13 @@ trace:
22841 #endif
22842 subq $MCOUNT_INSN_SIZE, %rdi
22843
22844+ pax_force_fptr ftrace_trace_function
22845 call *ftrace_trace_function
22846
22847 MCOUNT_RESTORE_FRAME
22848
22849 jmp ftrace_stub
22850-END(function_hook)
22851+ENDPROC(function_hook)
22852 #endif /* CONFIG_DYNAMIC_FTRACE */
22853 #endif /* CONFIG_FUNCTION_TRACER */
22854
22855@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22856
22857 MCOUNT_RESTORE_FRAME
22858
22859+ pax_force_retaddr
22860 retq
22861-END(ftrace_graph_caller)
22862+ENDPROC(ftrace_graph_caller)
22863
22864 GLOBAL(return_to_handler)
22865 subq $24, %rsp
22866@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22867 movq 8(%rsp), %rdx
22868 movq (%rsp), %rax
22869 addq $24, %rsp
22870+ pax_force_fptr %rdi
22871 jmp *%rdi
22872+ENDPROC(return_to_handler)
22873 #endif
22874
22875
22876@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22877 ENDPROC(native_usergs_sysret64)
22878 #endif /* CONFIG_PARAVIRT */
22879
22880+ .macro ljmpq sel, off
22881+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22882+ .byte 0x48; ljmp *1234f(%rip)
22883+ .pushsection .rodata
22884+ .align 16
22885+ 1234: .quad \off; .word \sel
22886+ .popsection
22887+#else
22888+ pushq $\sel
22889+ pushq $\off
22890+ lretq
22891+#endif
22892+ .endm
22893+
22894+ .macro pax_enter_kernel
22895+ pax_set_fptr_mask
22896+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22897+ call pax_enter_kernel
22898+#endif
22899+ .endm
22900+
22901+ .macro pax_exit_kernel
22902+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22903+ call pax_exit_kernel
22904+#endif
22905+
22906+ .endm
22907+
22908+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22909+ENTRY(pax_enter_kernel)
22910+ pushq %rdi
22911+
22912+#ifdef CONFIG_PARAVIRT
22913+ PV_SAVE_REGS(CLBR_RDI)
22914+#endif
22915+
22916+#ifdef CONFIG_PAX_KERNEXEC
22917+ GET_CR0_INTO_RDI
22918+ bts $16,%rdi
22919+ jnc 3f
22920+ mov %cs,%edi
22921+ cmp $__KERNEL_CS,%edi
22922+ jnz 2f
22923+1:
22924+#endif
22925+
22926+#ifdef CONFIG_PAX_MEMORY_UDEREF
22927+ 661: jmp 111f
22928+ .pushsection .altinstr_replacement, "a"
22929+ 662: ASM_NOP2
22930+ .popsection
22931+ .pushsection .altinstructions, "a"
22932+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22933+ .popsection
22934+ GET_CR3_INTO_RDI
22935+ cmp $0,%dil
22936+ jnz 112f
22937+ mov $__KERNEL_DS,%edi
22938+ mov %edi,%ss
22939+ jmp 111f
22940+112: cmp $1,%dil
22941+ jz 113f
22942+ ud2
22943+113: sub $4097,%rdi
22944+ bts $63,%rdi
22945+ SET_RDI_INTO_CR3
22946+ mov $__UDEREF_KERNEL_DS,%edi
22947+ mov %edi,%ss
22948+111:
22949+#endif
22950+
22951+#ifdef CONFIG_PARAVIRT
22952+ PV_RESTORE_REGS(CLBR_RDI)
22953+#endif
22954+
22955+ popq %rdi
22956+ pax_force_retaddr
22957+ retq
22958+
22959+#ifdef CONFIG_PAX_KERNEXEC
22960+2: ljmpq __KERNEL_CS,1b
22961+3: ljmpq __KERNEXEC_KERNEL_CS,4f
22962+4: SET_RDI_INTO_CR0
22963+ jmp 1b
22964+#endif
22965+ENDPROC(pax_enter_kernel)
22966+
22967+ENTRY(pax_exit_kernel)
22968+ pushq %rdi
22969+
22970+#ifdef CONFIG_PARAVIRT
22971+ PV_SAVE_REGS(CLBR_RDI)
22972+#endif
22973+
22974+#ifdef CONFIG_PAX_KERNEXEC
22975+ mov %cs,%rdi
22976+ cmp $__KERNEXEC_KERNEL_CS,%edi
22977+ jz 2f
22978+ GET_CR0_INTO_RDI
22979+ bts $16,%rdi
22980+ jnc 4f
22981+1:
22982+#endif
22983+
22984+#ifdef CONFIG_PAX_MEMORY_UDEREF
22985+ 661: jmp 111f
22986+ .pushsection .altinstr_replacement, "a"
22987+ 662: ASM_NOP2
22988+ .popsection
22989+ .pushsection .altinstructions, "a"
22990+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22991+ .popsection
22992+ mov %ss,%edi
22993+ cmp $__UDEREF_KERNEL_DS,%edi
22994+ jnz 111f
22995+ GET_CR3_INTO_RDI
22996+ cmp $0,%dil
22997+ jz 112f
22998+ ud2
22999+112: add $4097,%rdi
23000+ bts $63,%rdi
23001+ SET_RDI_INTO_CR3
23002+ mov $__KERNEL_DS,%edi
23003+ mov %edi,%ss
23004+111:
23005+#endif
23006+
23007+#ifdef CONFIG_PARAVIRT
23008+ PV_RESTORE_REGS(CLBR_RDI);
23009+#endif
23010+
23011+ popq %rdi
23012+ pax_force_retaddr
23013+ retq
23014+
23015+#ifdef CONFIG_PAX_KERNEXEC
23016+2: GET_CR0_INTO_RDI
23017+ btr $16,%rdi
23018+ jnc 4f
23019+ ljmpq __KERNEL_CS,3f
23020+3: SET_RDI_INTO_CR0
23021+ jmp 1b
23022+4: ud2
23023+ jmp 4b
23024+#endif
23025+ENDPROC(pax_exit_kernel)
23026+#endif
23027+
23028+ .macro pax_enter_kernel_user
23029+ pax_set_fptr_mask
23030+#ifdef CONFIG_PAX_MEMORY_UDEREF
23031+ call pax_enter_kernel_user
23032+#endif
23033+ .endm
23034+
23035+ .macro pax_exit_kernel_user
23036+#ifdef CONFIG_PAX_MEMORY_UDEREF
23037+ call pax_exit_kernel_user
23038+#endif
23039+#ifdef CONFIG_PAX_RANDKSTACK
23040+ pushq %rax
23041+ pushq %r11
23042+ call pax_randomize_kstack
23043+ popq %r11
23044+ popq %rax
23045+#endif
23046+ .endm
23047+
23048+#ifdef CONFIG_PAX_MEMORY_UDEREF
23049+ENTRY(pax_enter_kernel_user)
23050+ pushq %rdi
23051+ pushq %rbx
23052+
23053+#ifdef CONFIG_PARAVIRT
23054+ PV_SAVE_REGS(CLBR_RDI)
23055+#endif
23056+
23057+ 661: jmp 111f
23058+ .pushsection .altinstr_replacement, "a"
23059+ 662: ASM_NOP2
23060+ .popsection
23061+ .pushsection .altinstructions, "a"
23062+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23063+ .popsection
23064+ GET_CR3_INTO_RDI
23065+ cmp $1,%dil
23066+ jnz 4f
23067+ sub $4097,%rdi
23068+ bts $63,%rdi
23069+ SET_RDI_INTO_CR3
23070+ jmp 3f
23071+111:
23072+
23073+ GET_CR3_INTO_RDI
23074+ mov %rdi,%rbx
23075+ add $__START_KERNEL_map,%rbx
23076+ sub phys_base(%rip),%rbx
23077+
23078+#ifdef CONFIG_PARAVIRT
23079+ cmpl $0, pv_info+PARAVIRT_enabled
23080+ jz 1f
23081+ pushq %rdi
23082+ i = 0
23083+ .rept USER_PGD_PTRS
23084+ mov i*8(%rbx),%rsi
23085+ mov $0,%sil
23086+ lea i*8(%rbx),%rdi
23087+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23088+ i = i + 1
23089+ .endr
23090+ popq %rdi
23091+ jmp 2f
23092+1:
23093+#endif
23094+
23095+ i = 0
23096+ .rept USER_PGD_PTRS
23097+ movb $0,i*8(%rbx)
23098+ i = i + 1
23099+ .endr
23100+
23101+2: SET_RDI_INTO_CR3
23102+
23103+#ifdef CONFIG_PAX_KERNEXEC
23104+ GET_CR0_INTO_RDI
23105+ bts $16,%rdi
23106+ SET_RDI_INTO_CR0
23107+#endif
23108+
23109+3:
23110+
23111+#ifdef CONFIG_PARAVIRT
23112+ PV_RESTORE_REGS(CLBR_RDI)
23113+#endif
23114+
23115+ popq %rbx
23116+ popq %rdi
23117+ pax_force_retaddr
23118+ retq
23119+4: ud2
23120+ENDPROC(pax_enter_kernel_user)
23121+
23122+ENTRY(pax_exit_kernel_user)
23123+ pushq %rdi
23124+ pushq %rbx
23125+
23126+#ifdef CONFIG_PARAVIRT
23127+ PV_SAVE_REGS(CLBR_RDI)
23128+#endif
23129+
23130+ GET_CR3_INTO_RDI
23131+ 661: jmp 1f
23132+ .pushsection .altinstr_replacement, "a"
23133+ 662: ASM_NOP2
23134+ .popsection
23135+ .pushsection .altinstructions, "a"
23136+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23137+ .popsection
23138+ cmp $0,%dil
23139+ jnz 3f
23140+ add $4097,%rdi
23141+ bts $63,%rdi
23142+ SET_RDI_INTO_CR3
23143+ jmp 2f
23144+1:
23145+
23146+ mov %rdi,%rbx
23147+
23148+#ifdef CONFIG_PAX_KERNEXEC
23149+ GET_CR0_INTO_RDI
23150+ btr $16,%rdi
23151+ jnc 3f
23152+ SET_RDI_INTO_CR0
23153+#endif
23154+
23155+ add $__START_KERNEL_map,%rbx
23156+ sub phys_base(%rip),%rbx
23157+
23158+#ifdef CONFIG_PARAVIRT
23159+ cmpl $0, pv_info+PARAVIRT_enabled
23160+ jz 1f
23161+ i = 0
23162+ .rept USER_PGD_PTRS
23163+ mov i*8(%rbx),%rsi
23164+ mov $0x67,%sil
23165+ lea i*8(%rbx),%rdi
23166+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23167+ i = i + 1
23168+ .endr
23169+ jmp 2f
23170+1:
23171+#endif
23172+
23173+ i = 0
23174+ .rept USER_PGD_PTRS
23175+ movb $0x67,i*8(%rbx)
23176+ i = i + 1
23177+ .endr
23178+2:
23179+
23180+#ifdef CONFIG_PARAVIRT
23181+ PV_RESTORE_REGS(CLBR_RDI)
23182+#endif
23183+
23184+ popq %rbx
23185+ popq %rdi
23186+ pax_force_retaddr
23187+ retq
23188+3: ud2
23189+ENDPROC(pax_exit_kernel_user)
23190+#endif
23191+
23192+ .macro pax_enter_kernel_nmi
23193+ pax_set_fptr_mask
23194+
23195+#ifdef CONFIG_PAX_KERNEXEC
23196+ GET_CR0_INTO_RDI
23197+ bts $16,%rdi
23198+ jc 110f
23199+ SET_RDI_INTO_CR0
23200+ or $2,%ebx
23201+110:
23202+#endif
23203+
23204+#ifdef CONFIG_PAX_MEMORY_UDEREF
23205+ 661: jmp 111f
23206+ .pushsection .altinstr_replacement, "a"
23207+ 662: ASM_NOP2
23208+ .popsection
23209+ .pushsection .altinstructions, "a"
23210+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23211+ .popsection
23212+ GET_CR3_INTO_RDI
23213+ cmp $0,%dil
23214+ jz 111f
23215+ sub $4097,%rdi
23216+ or $4,%ebx
23217+ bts $63,%rdi
23218+ SET_RDI_INTO_CR3
23219+ mov $__UDEREF_KERNEL_DS,%edi
23220+ mov %edi,%ss
23221+111:
23222+#endif
23223+ .endm
23224+
23225+ .macro pax_exit_kernel_nmi
23226+#ifdef CONFIG_PAX_KERNEXEC
23227+ btr $1,%ebx
23228+ jnc 110f
23229+ GET_CR0_INTO_RDI
23230+ btr $16,%rdi
23231+ SET_RDI_INTO_CR0
23232+110:
23233+#endif
23234+
23235+#ifdef CONFIG_PAX_MEMORY_UDEREF
23236+ btr $2,%ebx
23237+ jnc 111f
23238+ GET_CR3_INTO_RDI
23239+ add $4097,%rdi
23240+ bts $63,%rdi
23241+ SET_RDI_INTO_CR3
23242+ mov $__KERNEL_DS,%edi
23243+ mov %edi,%ss
23244+111:
23245+#endif
23246+ .endm
23247+
23248+ .macro pax_erase_kstack
23249+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23250+ call pax_erase_kstack
23251+#endif
23252+ .endm
23253+
23254+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23255+ENTRY(pax_erase_kstack)
23256+ pushq %rdi
23257+ pushq %rcx
23258+ pushq %rax
23259+ pushq %r11
23260+
23261+ GET_THREAD_INFO(%r11)
23262+ mov TI_lowest_stack(%r11), %rdi
23263+ mov $-0xBEEF, %rax
23264+ std
23265+
23266+1: mov %edi, %ecx
23267+ and $THREAD_SIZE_asm - 1, %ecx
23268+ shr $3, %ecx
23269+ repne scasq
23270+ jecxz 2f
23271+
23272+ cmp $2*8, %ecx
23273+ jc 2f
23274+
23275+ mov $2*8, %ecx
23276+ repe scasq
23277+ jecxz 2f
23278+ jne 1b
23279+
23280+2: cld
23281+ mov %esp, %ecx
23282+ sub %edi, %ecx
23283+
23284+ cmp $THREAD_SIZE_asm, %rcx
23285+ jb 3f
23286+ ud2
23287+3:
23288+
23289+ shr $3, %ecx
23290+ rep stosq
23291+
23292+ mov TI_task_thread_sp0(%r11), %rdi
23293+ sub $256, %rdi
23294+ mov %rdi, TI_lowest_stack(%r11)
23295+
23296+ popq %r11
23297+ popq %rax
23298+ popq %rcx
23299+ popq %rdi
23300+ pax_force_retaddr
23301+ ret
23302+ENDPROC(pax_erase_kstack)
23303+#endif
23304
23305 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23306 #ifdef CONFIG_TRACE_IRQFLAGS
23307@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23308 .endm
23309
23310 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23311- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23312+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23313 jnc 1f
23314 TRACE_IRQS_ON_DEBUG
23315 1:
23316@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23317 movq \tmp,R11+\offset(%rsp)
23318 .endm
23319
23320- .macro FAKE_STACK_FRAME child_rip
23321- /* push in order ss, rsp, eflags, cs, rip */
23322- xorl %eax, %eax
23323- pushq_cfi $__KERNEL_DS /* ss */
23324- /*CFI_REL_OFFSET ss,0*/
23325- pushq_cfi %rax /* rsp */
23326- CFI_REL_OFFSET rsp,0
23327- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23328- /*CFI_REL_OFFSET rflags,0*/
23329- pushq_cfi $__KERNEL_CS /* cs */
23330- /*CFI_REL_OFFSET cs,0*/
23331- pushq_cfi \child_rip /* rip */
23332- CFI_REL_OFFSET rip,0
23333- pushq_cfi %rax /* orig rax */
23334- .endm
23335-
23336- .macro UNFAKE_STACK_FRAME
23337- addq $8*6, %rsp
23338- CFI_ADJUST_CFA_OFFSET -(6*8)
23339- .endm
23340-
23341 /*
23342 * initial frame state for interrupts (and exceptions without error code)
23343 */
23344@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23345 /* save partial stack frame */
23346 .macro SAVE_ARGS_IRQ
23347 cld
23348- /* start from rbp in pt_regs and jump over */
23349- movq_cfi rdi, (RDI-RBP)
23350- movq_cfi rsi, (RSI-RBP)
23351- movq_cfi rdx, (RDX-RBP)
23352- movq_cfi rcx, (RCX-RBP)
23353- movq_cfi rax, (RAX-RBP)
23354- movq_cfi r8, (R8-RBP)
23355- movq_cfi r9, (R9-RBP)
23356- movq_cfi r10, (R10-RBP)
23357- movq_cfi r11, (R11-RBP)
23358+ /* start from r15 in pt_regs and jump over */
23359+ movq_cfi rdi, RDI
23360+ movq_cfi rsi, RSI
23361+ movq_cfi rdx, RDX
23362+ movq_cfi rcx, RCX
23363+ movq_cfi rax, RAX
23364+ movq_cfi r8, R8
23365+ movq_cfi r9, R9
23366+ movq_cfi r10, R10
23367+ movq_cfi r11, R11
23368+ movq_cfi r12, R12
23369
23370 /* Save rbp so that we can unwind from get_irq_regs() */
23371- movq_cfi rbp, 0
23372+ movq_cfi rbp, RBP
23373
23374 /* Save previous stack value */
23375 movq %rsp, %rsi
23376
23377- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23378- testl $3, CS-RBP(%rsi)
23379+ movq %rsp,%rdi /* arg1 for handler */
23380+ testb $3, CS(%rsi)
23381 je 1f
23382 SWAPGS
23383 /*
23384@@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23385 0x06 /* DW_OP_deref */, \
23386 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23387 0x22 /* DW_OP_plus */
23388+
23389+#ifdef CONFIG_PAX_MEMORY_UDEREF
23390+ testb $3, CS(%rdi)
23391+ jnz 1f
23392+ pax_enter_kernel
23393+ jmp 2f
23394+1: pax_enter_kernel_user
23395+2:
23396+#else
23397+ pax_enter_kernel
23398+#endif
23399+
23400 /* We entered an interrupt context - irqs are off: */
23401 TRACE_IRQS_OFF
23402 .endm
23403@@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23404 js 1f /* negative -> in kernel */
23405 SWAPGS
23406 xorl %ebx,%ebx
23407-1: ret
23408+1:
23409+#ifdef CONFIG_PAX_MEMORY_UDEREF
23410+ testb $3, CS+8(%rsp)
23411+ jnz 1f
23412+ pax_enter_kernel
23413+ jmp 2f
23414+1: pax_enter_kernel_user
23415+2:
23416+#else
23417+ pax_enter_kernel
23418+#endif
23419+ pax_force_retaddr
23420+ ret
23421 CFI_ENDPROC
23422-END(save_paranoid)
23423+ENDPROC(save_paranoid)
23424+
23425+ENTRY(save_paranoid_nmi)
23426+ XCPT_FRAME 1 RDI+8
23427+ cld
23428+ movq_cfi rdi, RDI+8
23429+ movq_cfi rsi, RSI+8
23430+ movq_cfi rdx, RDX+8
23431+ movq_cfi rcx, RCX+8
23432+ movq_cfi rax, RAX+8
23433+ movq_cfi r8, R8+8
23434+ movq_cfi r9, R9+8
23435+ movq_cfi r10, R10+8
23436+ movq_cfi r11, R11+8
23437+ movq_cfi rbx, RBX+8
23438+ movq_cfi rbp, RBP+8
23439+ movq_cfi r12, R12+8
23440+ movq_cfi r13, R13+8
23441+ movq_cfi r14, R14+8
23442+ movq_cfi r15, R15+8
23443+ movl $1,%ebx
23444+ movl $MSR_GS_BASE,%ecx
23445+ rdmsr
23446+ testl %edx,%edx
23447+ js 1f /* negative -> in kernel */
23448+ SWAPGS
23449+ xorl %ebx,%ebx
23450+1: pax_enter_kernel_nmi
23451+ pax_force_retaddr
23452+ ret
23453+ CFI_ENDPROC
23454+ENDPROC(save_paranoid_nmi)
23455 .popsection
23456
23457 /*
23458@@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23459
23460 RESTORE_REST
23461
23462- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23463+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23464 jz 1f
23465
23466 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23467@@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23468 jmp ret_from_sys_call # go to the SYSRET fastpath
23469
23470 1:
23471- subq $REST_SKIP, %rsp # leave space for volatiles
23472- CFI_ADJUST_CFA_OFFSET REST_SKIP
23473 movq %rbp, %rdi
23474 call *%rbx
23475 movl $0, RAX(%rsp)
23476 RESTORE_REST
23477 jmp int_ret_from_sys_call
23478 CFI_ENDPROC
23479-END(ret_from_fork)
23480+ENDPROC(ret_from_fork)
23481
23482 /*
23483 * System call entry. Up to 6 arguments in registers are supported.
23484@@ -593,7 +1059,7 @@ END(ret_from_fork)
23485 ENTRY(system_call)
23486 CFI_STARTPROC simple
23487 CFI_SIGNAL_FRAME
23488- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23489+ CFI_DEF_CFA rsp,0
23490 CFI_REGISTER rip,rcx
23491 /*CFI_REGISTER rflags,r11*/
23492 SWAPGS_UNSAFE_STACK
23493@@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23494
23495 movq %rsp,PER_CPU_VAR(old_rsp)
23496 movq PER_CPU_VAR(kernel_stack),%rsp
23497+ SAVE_ARGS 8*6,0
23498+ pax_enter_kernel_user
23499+
23500+#ifdef CONFIG_PAX_RANDKSTACK
23501+ pax_erase_kstack
23502+#endif
23503+
23504 /*
23505 * No need to follow this irqs off/on section - it's straight
23506 * and short:
23507 */
23508 ENABLE_INTERRUPTS(CLBR_NONE)
23509- SAVE_ARGS 8,0
23510 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23511 movq %rcx,RIP-ARGOFFSET(%rsp)
23512 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23513- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23514+ GET_THREAD_INFO(%rcx)
23515+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23516 jnz tracesys
23517 system_call_fastpath:
23518 #if __SYSCALL_MASK == ~0
23519@@ -639,10 +1112,13 @@ sysret_check:
23520 LOCKDEP_SYS_EXIT
23521 DISABLE_INTERRUPTS(CLBR_NONE)
23522 TRACE_IRQS_OFF
23523- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23524+ GET_THREAD_INFO(%rcx)
23525+ movl TI_flags(%rcx),%edx
23526 andl %edi,%edx
23527 jnz sysret_careful
23528 CFI_REMEMBER_STATE
23529+ pax_exit_kernel_user
23530+ pax_erase_kstack
23531 /*
23532 * sysretq will re-enable interrupts:
23533 */
23534@@ -701,6 +1177,9 @@ auditsys:
23535 movq %rax,%rsi /* 2nd arg: syscall number */
23536 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23537 call __audit_syscall_entry
23538+
23539+ pax_erase_kstack
23540+
23541 LOAD_ARGS 0 /* reload call-clobbered registers */
23542 jmp system_call_fastpath
23543
23544@@ -722,7 +1201,7 @@ sysret_audit:
23545 /* Do syscall tracing */
23546 tracesys:
23547 #ifdef CONFIG_AUDITSYSCALL
23548- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23549+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23550 jz auditsys
23551 #endif
23552 SAVE_REST
23553@@ -730,12 +1209,15 @@ tracesys:
23554 FIXUP_TOP_OF_STACK %rdi
23555 movq %rsp,%rdi
23556 call syscall_trace_enter
23557+
23558+ pax_erase_kstack
23559+
23560 /*
23561 * Reload arg registers from stack in case ptrace changed them.
23562 * We don't reload %rax because syscall_trace_enter() returned
23563 * the value it wants us to use in the table lookup.
23564 */
23565- LOAD_ARGS ARGOFFSET, 1
23566+ LOAD_ARGS 1
23567 RESTORE_REST
23568 #if __SYSCALL_MASK == ~0
23569 cmpq $__NR_syscall_max,%rax
23570@@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23571 andl %edi,%edx
23572 jnz int_careful
23573 andl $~TS_COMPAT,TI_status(%rcx)
23574- jmp retint_swapgs
23575+ pax_exit_kernel_user
23576+ pax_erase_kstack
23577+ jmp retint_swapgs_pax
23578
23579 /* Either reschedule or signal or syscall exit tracking needed. */
23580 /* First do a reschedule test. */
23581@@ -811,7 +1295,7 @@ int_restore_rest:
23582 TRACE_IRQS_OFF
23583 jmp int_with_check
23584 CFI_ENDPROC
23585-END(system_call)
23586+ENDPROC(system_call)
23587
23588 .macro FORK_LIKE func
23589 ENTRY(stub_\func)
23590@@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23591 DEFAULT_FRAME 0 8 /* offset 8: return address */
23592 call sys_\func
23593 RESTORE_TOP_OF_STACK %r11, 8
23594- ret $REST_SKIP /* pop extended registers */
23595+ pax_force_retaddr
23596+ ret
23597 CFI_ENDPROC
23598-END(stub_\func)
23599+ENDPROC(stub_\func)
23600 .endm
23601
23602 .macro FIXED_FRAME label,func
23603@@ -836,9 +1321,10 @@ ENTRY(\label)
23604 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23605 call \func
23606 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23607+ pax_force_retaddr
23608 ret
23609 CFI_ENDPROC
23610-END(\label)
23611+ENDPROC(\label)
23612 .endm
23613
23614 FORK_LIKE clone
23615@@ -846,19 +1332,6 @@ END(\label)
23616 FORK_LIKE vfork
23617 FIXED_FRAME stub_iopl, sys_iopl
23618
23619-ENTRY(ptregscall_common)
23620- DEFAULT_FRAME 1 8 /* offset 8: return address */
23621- RESTORE_TOP_OF_STACK %r11, 8
23622- movq_cfi_restore R15+8, r15
23623- movq_cfi_restore R14+8, r14
23624- movq_cfi_restore R13+8, r13
23625- movq_cfi_restore R12+8, r12
23626- movq_cfi_restore RBP+8, rbp
23627- movq_cfi_restore RBX+8, rbx
23628- ret $REST_SKIP /* pop extended registers */
23629- CFI_ENDPROC
23630-END(ptregscall_common)
23631-
23632 ENTRY(stub_execve)
23633 CFI_STARTPROC
23634 addq $8, %rsp
23635@@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23636 RESTORE_REST
23637 jmp int_ret_from_sys_call
23638 CFI_ENDPROC
23639-END(stub_execve)
23640+ENDPROC(stub_execve)
23641
23642 /*
23643 * sigreturn is special because it needs to restore all registers on return.
23644@@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23645 RESTORE_REST
23646 jmp int_ret_from_sys_call
23647 CFI_ENDPROC
23648-END(stub_rt_sigreturn)
23649+ENDPROC(stub_rt_sigreturn)
23650
23651 #ifdef CONFIG_X86_X32_ABI
23652 ENTRY(stub_x32_rt_sigreturn)
23653@@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23654 RESTORE_REST
23655 jmp int_ret_from_sys_call
23656 CFI_ENDPROC
23657-END(stub_x32_rt_sigreturn)
23658+ENDPROC(stub_x32_rt_sigreturn)
23659
23660 ENTRY(stub_x32_execve)
23661 CFI_STARTPROC
23662@@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23663 RESTORE_REST
23664 jmp int_ret_from_sys_call
23665 CFI_ENDPROC
23666-END(stub_x32_execve)
23667+ENDPROC(stub_x32_execve)
23668
23669 #endif
23670
23671@@ -952,7 +1425,7 @@ vector=vector+1
23672 2: jmp common_interrupt
23673 .endr
23674 CFI_ENDPROC
23675-END(irq_entries_start)
23676+ENDPROC(irq_entries_start)
23677
23678 .previous
23679 END(interrupt)
23680@@ -969,8 +1442,8 @@ END(interrupt)
23681 /* 0(%rsp): ~(interrupt number) */
23682 .macro interrupt func
23683 /* reserve pt_regs for scratch regs and rbp */
23684- subq $ORIG_RAX-RBP, %rsp
23685- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23686+ subq $ORIG_RAX, %rsp
23687+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23688 SAVE_ARGS_IRQ
23689 call \func
23690 .endm
23691@@ -997,14 +1470,14 @@ ret_from_intr:
23692
23693 /* Restore saved previous stack */
23694 popq %rsi
23695- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23696- leaq ARGOFFSET-RBP(%rsi), %rsp
23697+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23698+ movq %rsi, %rsp
23699 CFI_DEF_CFA_REGISTER rsp
23700- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23701+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23702
23703 exit_intr:
23704 GET_THREAD_INFO(%rcx)
23705- testl $3,CS-ARGOFFSET(%rsp)
23706+ testb $3,CS-ARGOFFSET(%rsp)
23707 je retint_kernel
23708
23709 /* Interrupt came from user space */
23710@@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23711 * The iretq could re-enable interrupts:
23712 */
23713 DISABLE_INTERRUPTS(CLBR_ANY)
23714+ pax_exit_kernel_user
23715+retint_swapgs_pax:
23716 TRACE_IRQS_IRETQ
23717 SWAPGS
23718 jmp restore_args
23719
23720 retint_restore_args: /* return to kernel space */
23721 DISABLE_INTERRUPTS(CLBR_ANY)
23722+ pax_exit_kernel
23723+ pax_force_retaddr (RIP-ARGOFFSET)
23724 /*
23725 * The iretq could re-enable interrupts:
23726 */
23727@@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23728 #endif
23729
23730 CFI_ENDPROC
23731-END(common_interrupt)
23732+ENDPROC(common_interrupt)
23733 /*
23734 * End of kprobes section
23735 */
23736@@ -1130,7 +1607,7 @@ ENTRY(\sym)
23737 interrupt \do_sym
23738 jmp ret_from_intr
23739 CFI_ENDPROC
23740-END(\sym)
23741+ENDPROC(\sym)
23742 .endm
23743
23744 #ifdef CONFIG_TRACING
23745@@ -1218,7 +1695,7 @@ ENTRY(\sym)
23746 call \do_sym
23747 jmp error_exit /* %ebx: no swapgs flag */
23748 CFI_ENDPROC
23749-END(\sym)
23750+ENDPROC(\sym)
23751 .endm
23752
23753 .macro paranoidzeroentry sym do_sym
23754@@ -1236,10 +1713,10 @@ ENTRY(\sym)
23755 call \do_sym
23756 jmp paranoid_exit /* %ebx: no swapgs flag */
23757 CFI_ENDPROC
23758-END(\sym)
23759+ENDPROC(\sym)
23760 .endm
23761
23762-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23763+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23764 .macro paranoidzeroentry_ist sym do_sym ist
23765 ENTRY(\sym)
23766 INTR_FRAME
23767@@ -1252,12 +1729,18 @@ ENTRY(\sym)
23768 TRACE_IRQS_OFF_DEBUG
23769 movq %rsp,%rdi /* pt_regs pointer */
23770 xorl %esi,%esi /* no error code */
23771+#ifdef CONFIG_SMP
23772+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23773+ lea init_tss(%r13), %r13
23774+#else
23775+ lea init_tss(%rip), %r13
23776+#endif
23777 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23778 call \do_sym
23779 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23780 jmp paranoid_exit /* %ebx: no swapgs flag */
23781 CFI_ENDPROC
23782-END(\sym)
23783+ENDPROC(\sym)
23784 .endm
23785
23786 .macro errorentry sym do_sym
23787@@ -1275,7 +1758,7 @@ ENTRY(\sym)
23788 call \do_sym
23789 jmp error_exit /* %ebx: no swapgs flag */
23790 CFI_ENDPROC
23791-END(\sym)
23792+ENDPROC(\sym)
23793 .endm
23794
23795 #ifdef CONFIG_TRACING
23796@@ -1306,7 +1789,7 @@ ENTRY(\sym)
23797 call \do_sym
23798 jmp paranoid_exit /* %ebx: no swapgs flag */
23799 CFI_ENDPROC
23800-END(\sym)
23801+ENDPROC(\sym)
23802 .endm
23803
23804 zeroentry divide_error do_divide_error
23805@@ -1336,9 +1819,10 @@ gs_change:
23806 2: mfence /* workaround */
23807 SWAPGS
23808 popfq_cfi
23809+ pax_force_retaddr
23810 ret
23811 CFI_ENDPROC
23812-END(native_load_gs_index)
23813+ENDPROC(native_load_gs_index)
23814
23815 _ASM_EXTABLE(gs_change,bad_gs)
23816 .section .fixup,"ax"
23817@@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23818 CFI_DEF_CFA_REGISTER rsp
23819 CFI_ADJUST_CFA_OFFSET -8
23820 decl PER_CPU_VAR(irq_count)
23821+ pax_force_retaddr
23822 ret
23823 CFI_ENDPROC
23824-END(do_softirq_own_stack)
23825+ENDPROC(do_softirq_own_stack)
23826
23827 #ifdef CONFIG_XEN
23828 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23829@@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23830 decl PER_CPU_VAR(irq_count)
23831 jmp error_exit
23832 CFI_ENDPROC
23833-END(xen_do_hypervisor_callback)
23834+ENDPROC(xen_do_hypervisor_callback)
23835
23836 /*
23837 * Hypervisor uses this for application faults while it executes.
23838@@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23839 SAVE_ALL
23840 jmp error_exit
23841 CFI_ENDPROC
23842-END(xen_failsafe_callback)
23843+ENDPROC(xen_failsafe_callback)
23844
23845 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23846 xen_hvm_callback_vector xen_evtchn_do_upcall
23847@@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23848 DEFAULT_FRAME
23849 DISABLE_INTERRUPTS(CLBR_NONE)
23850 TRACE_IRQS_OFF_DEBUG
23851- testl %ebx,%ebx /* swapgs needed? */
23852+ testl $1,%ebx /* swapgs needed? */
23853 jnz paranoid_restore
23854- testl $3,CS(%rsp)
23855+ testb $3,CS(%rsp)
23856 jnz paranoid_userspace
23857+#ifdef CONFIG_PAX_MEMORY_UDEREF
23858+ pax_exit_kernel
23859+ TRACE_IRQS_IRETQ 0
23860+ SWAPGS_UNSAFE_STACK
23861+ RESTORE_ALL 8
23862+ pax_force_retaddr_bts
23863+ jmp irq_return
23864+#endif
23865 paranoid_swapgs:
23866+#ifdef CONFIG_PAX_MEMORY_UDEREF
23867+ pax_exit_kernel_user
23868+#else
23869+ pax_exit_kernel
23870+#endif
23871 TRACE_IRQS_IRETQ 0
23872 SWAPGS_UNSAFE_STACK
23873 RESTORE_ALL 8
23874 jmp irq_return
23875 paranoid_restore:
23876+ pax_exit_kernel
23877 TRACE_IRQS_IRETQ_DEBUG 0
23878 RESTORE_ALL 8
23879+ pax_force_retaddr_bts
23880 jmp irq_return
23881 paranoid_userspace:
23882 GET_THREAD_INFO(%rcx)
23883@@ -1557,7 +2057,7 @@ paranoid_schedule:
23884 TRACE_IRQS_OFF
23885 jmp paranoid_userspace
23886 CFI_ENDPROC
23887-END(paranoid_exit)
23888+ENDPROC(paranoid_exit)
23889
23890 /*
23891 * Exception entry point. This expects an error code/orig_rax on the stack.
23892@@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23893 movq_cfi r14, R14+8
23894 movq_cfi r15, R15+8
23895 xorl %ebx,%ebx
23896- testl $3,CS+8(%rsp)
23897+ testb $3,CS+8(%rsp)
23898 je error_kernelspace
23899 error_swapgs:
23900 SWAPGS
23901 error_sti:
23902+#ifdef CONFIG_PAX_MEMORY_UDEREF
23903+ testb $3, CS+8(%rsp)
23904+ jnz 1f
23905+ pax_enter_kernel
23906+ jmp 2f
23907+1: pax_enter_kernel_user
23908+2:
23909+#else
23910+ pax_enter_kernel
23911+#endif
23912 TRACE_IRQS_OFF
23913+ pax_force_retaddr
23914 ret
23915
23916 /*
23917@@ -1616,7 +2127,7 @@ bstep_iret:
23918 movq %rcx,RIP+8(%rsp)
23919 jmp error_swapgs
23920 CFI_ENDPROC
23921-END(error_entry)
23922+ENDPROC(error_entry)
23923
23924
23925 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23926@@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23927 DISABLE_INTERRUPTS(CLBR_NONE)
23928 TRACE_IRQS_OFF
23929 GET_THREAD_INFO(%rcx)
23930- testl %eax,%eax
23931+ testl $1,%eax
23932 jne retint_kernel
23933 LOCKDEP_SYS_EXIT_IRQ
23934 movl TI_flags(%rcx),%edx
23935@@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23936 jnz retint_careful
23937 jmp retint_swapgs
23938 CFI_ENDPROC
23939-END(error_exit)
23940+ENDPROC(error_exit)
23941
23942 /*
23943 * Test if a given stack is an NMI stack or not.
23944@@ -1694,9 +2205,11 @@ ENTRY(nmi)
23945 * If %cs was not the kernel segment, then the NMI triggered in user
23946 * space, which means it is definitely not nested.
23947 */
23948+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23949+ je 1f
23950 cmpl $__KERNEL_CS, 16(%rsp)
23951 jne first_nmi
23952-
23953+1:
23954 /*
23955 * Check the special variable on the stack to see if NMIs are
23956 * executing.
23957@@ -1730,8 +2243,7 @@ nested_nmi:
23958
23959 1:
23960 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23961- leaq -1*8(%rsp), %rdx
23962- movq %rdx, %rsp
23963+ subq $8, %rsp
23964 CFI_ADJUST_CFA_OFFSET 1*8
23965 leaq -10*8(%rsp), %rdx
23966 pushq_cfi $__KERNEL_DS
23967@@ -1749,6 +2261,7 @@ nested_nmi_out:
23968 CFI_RESTORE rdx
23969
23970 /* No need to check faults here */
23971+# pax_force_retaddr_bts
23972 INTERRUPT_RETURN
23973
23974 CFI_RESTORE_STATE
23975@@ -1845,13 +2358,13 @@ end_repeat_nmi:
23976 subq $ORIG_RAX-R15, %rsp
23977 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23978 /*
23979- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23980+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23981 * as we should not be calling schedule in NMI context.
23982 * Even with normal interrupts enabled. An NMI should not be
23983 * setting NEED_RESCHED or anything that normal interrupts and
23984 * exceptions might do.
23985 */
23986- call save_paranoid
23987+ call save_paranoid_nmi
23988 DEFAULT_FRAME 0
23989
23990 /*
23991@@ -1861,9 +2374,9 @@ end_repeat_nmi:
23992 * NMI itself takes a page fault, the page fault that was preempted
23993 * will read the information from the NMI page fault and not the
23994 * origin fault. Save it off and restore it if it changes.
23995- * Use the r12 callee-saved register.
23996+ * Use the r13 callee-saved register.
23997 */
23998- movq %cr2, %r12
23999+ movq %cr2, %r13
24000
24001 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24002 movq %rsp,%rdi
24003@@ -1872,31 +2385,36 @@ end_repeat_nmi:
24004
24005 /* Did the NMI take a page fault? Restore cr2 if it did */
24006 movq %cr2, %rcx
24007- cmpq %rcx, %r12
24008+ cmpq %rcx, %r13
24009 je 1f
24010- movq %r12, %cr2
24011+ movq %r13, %cr2
24012 1:
24013
24014- testl %ebx,%ebx /* swapgs needed? */
24015+ testl $1,%ebx /* swapgs needed? */
24016 jnz nmi_restore
24017 nmi_swapgs:
24018 SWAPGS_UNSAFE_STACK
24019 nmi_restore:
24020+ pax_exit_kernel_nmi
24021 /* Pop the extra iret frame at once */
24022 RESTORE_ALL 6*8
24023+ testb $3, 8(%rsp)
24024+ jnz 1f
24025+ pax_force_retaddr_bts
24026+1:
24027
24028 /* Clear the NMI executing stack variable */
24029 movq $0, 5*8(%rsp)
24030 jmp irq_return
24031 CFI_ENDPROC
24032-END(nmi)
24033+ENDPROC(nmi)
24034
24035 ENTRY(ignore_sysret)
24036 CFI_STARTPROC
24037 mov $-ENOSYS,%eax
24038 sysret
24039 CFI_ENDPROC
24040-END(ignore_sysret)
24041+ENDPROC(ignore_sysret)
24042
24043 /*
24044 * End of kprobes section
24045diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24046index 52819e8..b6d1dbd 100644
24047--- a/arch/x86/kernel/ftrace.c
24048+++ b/arch/x86/kernel/ftrace.c
24049@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24050 {
24051 unsigned char replaced[MCOUNT_INSN_SIZE];
24052
24053+ ip = ktla_ktva(ip);
24054+
24055 /*
24056 * Note: Due to modules and __init, code can
24057 * disappear and change, we need to protect against faulting
24058@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24059 unsigned char old[MCOUNT_INSN_SIZE];
24060 int ret;
24061
24062- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24063+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24064
24065 ftrace_update_func = ip;
24066 /* Make sure the breakpoints see the ftrace_update_func update */
24067@@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
24068 * kernel identity mapping to modify code.
24069 */
24070 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24071- ip = (unsigned long)__va(__pa_symbol(ip));
24072+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24073
24074 if (probe_kernel_write((void *)ip, val, size))
24075 return -EPERM;
24076@@ -319,7 +321,7 @@ static int add_break(unsigned long ip, const char *old)
24077 unsigned char replaced[MCOUNT_INSN_SIZE];
24078 unsigned char brk = BREAKPOINT_INSTRUCTION;
24079
24080- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24081+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24082 return -EFAULT;
24083
24084 /* Make sure it is what we expect it to be */
24085diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24086index 068054f..c248bcd 100644
24087--- a/arch/x86/kernel/head64.c
24088+++ b/arch/x86/kernel/head64.c
24089@@ -67,12 +67,12 @@ again:
24090 pgd = *pgd_p;
24091
24092 /*
24093- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24094- * critical -- __PAGE_OFFSET would point us back into the dynamic
24095+ * The use of __early_va rather than __va here is critical:
24096+ * __va would point us back into the dynamic
24097 * range and we might end up looping forever...
24098 */
24099 if (pgd)
24100- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24101+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24102 else {
24103 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24104 reset_early_page_tables();
24105@@ -82,13 +82,13 @@ again:
24106 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24107 for (i = 0; i < PTRS_PER_PUD; i++)
24108 pud_p[i] = 0;
24109- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24110+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24111 }
24112 pud_p += pud_index(address);
24113 pud = *pud_p;
24114
24115 if (pud)
24116- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24117+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24118 else {
24119 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24120 reset_early_page_tables();
24121@@ -98,7 +98,7 @@ again:
24122 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24123 for (i = 0; i < PTRS_PER_PMD; i++)
24124 pmd_p[i] = 0;
24125- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24126+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24127 }
24128 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24129 pmd_p[pmd_index(address)] = pmd;
24130@@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24131 if (console_loglevel == 10)
24132 early_printk("Kernel alive\n");
24133
24134- clear_page(init_level4_pgt);
24135 /* set init_level4_pgt kernel high mapping*/
24136 init_level4_pgt[511] = early_level4_pgt[511];
24137
24138diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24139index f36bd42..56ee1534 100644
24140--- a/arch/x86/kernel/head_32.S
24141+++ b/arch/x86/kernel/head_32.S
24142@@ -26,6 +26,12 @@
24143 /* Physical address */
24144 #define pa(X) ((X) - __PAGE_OFFSET)
24145
24146+#ifdef CONFIG_PAX_KERNEXEC
24147+#define ta(X) (X)
24148+#else
24149+#define ta(X) ((X) - __PAGE_OFFSET)
24150+#endif
24151+
24152 /*
24153 * References to members of the new_cpu_data structure.
24154 */
24155@@ -55,11 +61,7 @@
24156 * and small than max_low_pfn, otherwise will waste some page table entries
24157 */
24158
24159-#if PTRS_PER_PMD > 1
24160-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24161-#else
24162-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24163-#endif
24164+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24165
24166 /* Number of possible pages in the lowmem region */
24167 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24168@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24169 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24170
24171 /*
24172+ * Real beginning of normal "text" segment
24173+ */
24174+ENTRY(stext)
24175+ENTRY(_stext)
24176+
24177+/*
24178 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24179 * %esi points to the real-mode code as a 32-bit pointer.
24180 * CS and DS must be 4 GB flat segments, but we don't depend on
24181@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24182 * can.
24183 */
24184 __HEAD
24185+
24186+#ifdef CONFIG_PAX_KERNEXEC
24187+ jmp startup_32
24188+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24189+.fill PAGE_SIZE-5,1,0xcc
24190+#endif
24191+
24192 ENTRY(startup_32)
24193 movl pa(stack_start),%ecx
24194
24195@@ -106,6 +121,59 @@ ENTRY(startup_32)
24196 2:
24197 leal -__PAGE_OFFSET(%ecx),%esp
24198
24199+#ifdef CONFIG_SMP
24200+ movl $pa(cpu_gdt_table),%edi
24201+ movl $__per_cpu_load,%eax
24202+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24203+ rorl $16,%eax
24204+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24205+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24206+ movl $__per_cpu_end - 1,%eax
24207+ subl $__per_cpu_start,%eax
24208+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24209+#endif
24210+
24211+#ifdef CONFIG_PAX_MEMORY_UDEREF
24212+ movl $NR_CPUS,%ecx
24213+ movl $pa(cpu_gdt_table),%edi
24214+1:
24215+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24216+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24217+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24218+ addl $PAGE_SIZE_asm,%edi
24219+ loop 1b
24220+#endif
24221+
24222+#ifdef CONFIG_PAX_KERNEXEC
24223+ movl $pa(boot_gdt),%edi
24224+ movl $__LOAD_PHYSICAL_ADDR,%eax
24225+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24226+ rorl $16,%eax
24227+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24228+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24229+ rorl $16,%eax
24230+
24231+ ljmp $(__BOOT_CS),$1f
24232+1:
24233+
24234+ movl $NR_CPUS,%ecx
24235+ movl $pa(cpu_gdt_table),%edi
24236+ addl $__PAGE_OFFSET,%eax
24237+1:
24238+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24239+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24240+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24241+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24242+ rorl $16,%eax
24243+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24244+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24245+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24246+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24247+ rorl $16,%eax
24248+ addl $PAGE_SIZE_asm,%edi
24249+ loop 1b
24250+#endif
24251+
24252 /*
24253 * Clear BSS first so that there are no surprises...
24254 */
24255@@ -201,8 +269,11 @@ ENTRY(startup_32)
24256 movl %eax, pa(max_pfn_mapped)
24257
24258 /* Do early initialization of the fixmap area */
24259- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24260- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24261+#ifdef CONFIG_COMPAT_VDSO
24262+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24263+#else
24264+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24265+#endif
24266 #else /* Not PAE */
24267
24268 page_pde_offset = (__PAGE_OFFSET >> 20);
24269@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24270 movl %eax, pa(max_pfn_mapped)
24271
24272 /* Do early initialization of the fixmap area */
24273- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24274- movl %eax,pa(initial_page_table+0xffc)
24275+#ifdef CONFIG_COMPAT_VDSO
24276+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24277+#else
24278+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24279+#endif
24280 #endif
24281
24282 #ifdef CONFIG_PARAVIRT
24283@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24284 cmpl $num_subarch_entries, %eax
24285 jae bad_subarch
24286
24287- movl pa(subarch_entries)(,%eax,4), %eax
24288- subl $__PAGE_OFFSET, %eax
24289- jmp *%eax
24290+ jmp *pa(subarch_entries)(,%eax,4)
24291
24292 bad_subarch:
24293 WEAK(lguest_entry)
24294@@ -261,10 +333,10 @@ WEAK(xen_entry)
24295 __INITDATA
24296
24297 subarch_entries:
24298- .long default_entry /* normal x86/PC */
24299- .long lguest_entry /* lguest hypervisor */
24300- .long xen_entry /* Xen hypervisor */
24301- .long default_entry /* Moorestown MID */
24302+ .long ta(default_entry) /* normal x86/PC */
24303+ .long ta(lguest_entry) /* lguest hypervisor */
24304+ .long ta(xen_entry) /* Xen hypervisor */
24305+ .long ta(default_entry) /* Moorestown MID */
24306 num_subarch_entries = (. - subarch_entries) / 4
24307 .previous
24308 #else
24309@@ -354,6 +426,7 @@ default_entry:
24310 movl pa(mmu_cr4_features),%eax
24311 movl %eax,%cr4
24312
24313+#ifdef CONFIG_X86_PAE
24314 testb $X86_CR4_PAE, %al # check if PAE is enabled
24315 jz enable_paging
24316
24317@@ -382,6 +455,9 @@ default_entry:
24318 /* Make changes effective */
24319 wrmsr
24320
24321+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24322+#endif
24323+
24324 enable_paging:
24325
24326 /*
24327@@ -449,14 +525,20 @@ is486:
24328 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24329 movl %eax,%ss # after changing gdt.
24330
24331- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24332+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24333 movl %eax,%ds
24334 movl %eax,%es
24335
24336 movl $(__KERNEL_PERCPU), %eax
24337 movl %eax,%fs # set this cpu's percpu
24338
24339+#ifdef CONFIG_CC_STACKPROTECTOR
24340 movl $(__KERNEL_STACK_CANARY),%eax
24341+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24342+ movl $(__USER_DS),%eax
24343+#else
24344+ xorl %eax,%eax
24345+#endif
24346 movl %eax,%gs
24347
24348 xorl %eax,%eax # Clear LDT
24349@@ -512,8 +594,11 @@ setup_once:
24350 * relocation. Manually set base address in stack canary
24351 * segment descriptor.
24352 */
24353- movl $gdt_page,%eax
24354+ movl $cpu_gdt_table,%eax
24355 movl $stack_canary,%ecx
24356+#ifdef CONFIG_SMP
24357+ addl $__per_cpu_load,%ecx
24358+#endif
24359 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24360 shrl $16, %ecx
24361 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24362@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24363 cmpl $2,(%esp) # X86_TRAP_NMI
24364 je is_nmi # Ignore NMI
24365
24366- cmpl $2,%ss:early_recursion_flag
24367+ cmpl $1,%ss:early_recursion_flag
24368 je hlt_loop
24369 incl %ss:early_recursion_flag
24370
24371@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24372 pushl (20+6*4)(%esp) /* trapno */
24373 pushl $fault_msg
24374 call printk
24375-#endif
24376 call dump_stack
24377+#endif
24378 hlt_loop:
24379 hlt
24380 jmp hlt_loop
24381@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24382 /* This is the default interrupt "handler" :-) */
24383 ALIGN
24384 ignore_int:
24385- cld
24386 #ifdef CONFIG_PRINTK
24387+ cmpl $2,%ss:early_recursion_flag
24388+ je hlt_loop
24389+ incl %ss:early_recursion_flag
24390+ cld
24391 pushl %eax
24392 pushl %ecx
24393 pushl %edx
24394@@ -617,9 +705,6 @@ ignore_int:
24395 movl $(__KERNEL_DS),%eax
24396 movl %eax,%ds
24397 movl %eax,%es
24398- cmpl $2,early_recursion_flag
24399- je hlt_loop
24400- incl early_recursion_flag
24401 pushl 16(%esp)
24402 pushl 24(%esp)
24403 pushl 32(%esp)
24404@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24405 /*
24406 * BSS section
24407 */
24408-__PAGE_ALIGNED_BSS
24409- .align PAGE_SIZE
24410 #ifdef CONFIG_X86_PAE
24411+.section .initial_pg_pmd,"a",@progbits
24412 initial_pg_pmd:
24413 .fill 1024*KPMDS,4,0
24414 #else
24415+.section .initial_page_table,"a",@progbits
24416 ENTRY(initial_page_table)
24417 .fill 1024,4,0
24418 #endif
24419+.section .initial_pg_fixmap,"a",@progbits
24420 initial_pg_fixmap:
24421 .fill 1024,4,0
24422+.section .empty_zero_page,"a",@progbits
24423 ENTRY(empty_zero_page)
24424 .fill 4096,1,0
24425+.section .swapper_pg_dir,"a",@progbits
24426 ENTRY(swapper_pg_dir)
24427+#ifdef CONFIG_X86_PAE
24428+ .fill 4,8,0
24429+#else
24430 .fill 1024,4,0
24431+#endif
24432
24433 /*
24434 * This starts the data section.
24435 */
24436 #ifdef CONFIG_X86_PAE
24437-__PAGE_ALIGNED_DATA
24438- /* Page-aligned for the benefit of paravirt? */
24439- .align PAGE_SIZE
24440+.section .initial_page_table,"a",@progbits
24441 ENTRY(initial_page_table)
24442 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24443 # if KPMDS == 3
24444@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24445 # error "Kernel PMDs should be 1, 2 or 3"
24446 # endif
24447 .align PAGE_SIZE /* needs to be page-sized too */
24448+
24449+#ifdef CONFIG_PAX_PER_CPU_PGD
24450+ENTRY(cpu_pgd)
24451+ .rept 2*NR_CPUS
24452+ .fill 4,8,0
24453+ .endr
24454+#endif
24455+
24456 #endif
24457
24458 .data
24459 .balign 4
24460 ENTRY(stack_start)
24461- .long init_thread_union+THREAD_SIZE
24462+ .long init_thread_union+THREAD_SIZE-8
24463
24464 __INITRODATA
24465 int_msg:
24466@@ -727,7 +825,7 @@ fault_msg:
24467 * segment size, and 32-bit linear address value:
24468 */
24469
24470- .data
24471+.section .rodata,"a",@progbits
24472 .globl boot_gdt_descr
24473 .globl idt_descr
24474
24475@@ -736,7 +834,7 @@ fault_msg:
24476 .word 0 # 32 bit align gdt_desc.address
24477 boot_gdt_descr:
24478 .word __BOOT_DS+7
24479- .long boot_gdt - __PAGE_OFFSET
24480+ .long pa(boot_gdt)
24481
24482 .word 0 # 32-bit align idt_desc.address
24483 idt_descr:
24484@@ -747,7 +845,7 @@ idt_descr:
24485 .word 0 # 32 bit align gdt_desc.address
24486 ENTRY(early_gdt_descr)
24487 .word GDT_ENTRIES*8-1
24488- .long gdt_page /* Overwritten for secondary CPUs */
24489+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24490
24491 /*
24492 * The boot_gdt must mirror the equivalent in setup.S and is
24493@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24494 .align L1_CACHE_BYTES
24495 ENTRY(boot_gdt)
24496 .fill GDT_ENTRY_BOOT_CS,8,0
24497- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24498- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24499+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24500+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24501+
24502+ .align PAGE_SIZE_asm
24503+ENTRY(cpu_gdt_table)
24504+ .rept NR_CPUS
24505+ .quad 0x0000000000000000 /* NULL descriptor */
24506+ .quad 0x0000000000000000 /* 0x0b reserved */
24507+ .quad 0x0000000000000000 /* 0x13 reserved */
24508+ .quad 0x0000000000000000 /* 0x1b reserved */
24509+
24510+#ifdef CONFIG_PAX_KERNEXEC
24511+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24512+#else
24513+ .quad 0x0000000000000000 /* 0x20 unused */
24514+#endif
24515+
24516+ .quad 0x0000000000000000 /* 0x28 unused */
24517+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24518+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24519+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24520+ .quad 0x0000000000000000 /* 0x4b reserved */
24521+ .quad 0x0000000000000000 /* 0x53 reserved */
24522+ .quad 0x0000000000000000 /* 0x5b reserved */
24523+
24524+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24525+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24526+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24527+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24528+
24529+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24530+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24531+
24532+ /*
24533+ * Segments used for calling PnP BIOS have byte granularity.
24534+ * The code segments and data segments have fixed 64k limits,
24535+ * the transfer segment sizes are set at run time.
24536+ */
24537+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24538+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24539+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24540+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24541+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24542+
24543+ /*
24544+ * The APM segments have byte granularity and their bases
24545+ * are set at run time. All have 64k limits.
24546+ */
24547+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24548+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24549+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24550+
24551+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24552+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24553+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24554+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24555+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24556+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24557+
24558+ /* Be sure this is zeroed to avoid false validations in Xen */
24559+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24560+ .endr
24561diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24562index a468c0a..c7dec74 100644
24563--- a/arch/x86/kernel/head_64.S
24564+++ b/arch/x86/kernel/head_64.S
24565@@ -20,6 +20,8 @@
24566 #include <asm/processor-flags.h>
24567 #include <asm/percpu.h>
24568 #include <asm/nops.h>
24569+#include <asm/cpufeature.h>
24570+#include <asm/alternative-asm.h>
24571
24572 #ifdef CONFIG_PARAVIRT
24573 #include <asm/asm-offsets.h>
24574@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24575 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24576 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24577 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24578+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24579+L3_VMALLOC_START = pud_index(VMALLOC_START)
24580+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24581+L3_VMALLOC_END = pud_index(VMALLOC_END)
24582+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24583+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24584
24585 .text
24586 __HEAD
24587@@ -89,11 +97,24 @@ startup_64:
24588 * Fixup the physical addresses in the page table
24589 */
24590 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24591+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24592+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24593+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24594+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24595+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24596
24597- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24598- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24599+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24600+#ifndef CONFIG_XEN
24601+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24602+#endif
24603+
24604+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24605+
24606+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24607+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24608
24609 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24610+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24611
24612 /*
24613 * Set up the identity mapping for the switchover. These
24614@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24615 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24616 1:
24617
24618- /* Enable PAE mode and PGE */
24619- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24620+ /* Enable PAE mode and PSE/PGE */
24621+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24622 movq %rcx, %cr4
24623
24624 /* Setup early boot stage 4 level pagetables. */
24625@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24626 movl $MSR_EFER, %ecx
24627 rdmsr
24628 btsl $_EFER_SCE, %eax /* Enable System Call */
24629- btl $20,%edi /* No Execute supported? */
24630+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24631 jnc 1f
24632 btsl $_EFER_NX, %eax
24633 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24634+#ifndef CONFIG_EFI
24635+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24636+#endif
24637+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24638+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24639+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24640+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24641+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24642+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24643 1: wrmsr /* Make changes effective */
24644
24645 /* Setup cr0 */
24646@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24647 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24648 * address given in m16:64.
24649 */
24650+ pax_set_fptr_mask
24651 movq initial_code(%rip),%rax
24652 pushq $0 # fake return address to stop unwinder
24653 pushq $__KERNEL_CS # set correct cs
24654@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24655 .quad INIT_PER_CPU_VAR(irq_stack_union)
24656
24657 GLOBAL(stack_start)
24658- .quad init_thread_union+THREAD_SIZE-8
24659+ .quad init_thread_union+THREAD_SIZE-16
24660 .word 0
24661 __FINITDATA
24662
24663@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24664 call dump_stack
24665 #ifdef CONFIG_KALLSYMS
24666 leaq early_idt_ripmsg(%rip),%rdi
24667- movq 40(%rsp),%rsi # %rip again
24668+ movq 88(%rsp),%rsi # %rip again
24669 call __print_symbol
24670 #endif
24671 #endif /* EARLY_PRINTK */
24672@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24673 early_recursion_flag:
24674 .long 0
24675
24676+ .section .rodata,"a",@progbits
24677 #ifdef CONFIG_EARLY_PRINTK
24678 early_idt_msg:
24679 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24680@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24681 NEXT_PAGE(early_dynamic_pgts)
24682 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24683
24684- .data
24685+ .section .rodata,"a",@progbits
24686
24687-#ifndef CONFIG_XEN
24688 NEXT_PAGE(init_level4_pgt)
24689- .fill 512,8,0
24690-#else
24691-NEXT_PAGE(init_level4_pgt)
24692- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24693 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24694 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24695+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24696+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24697+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24698+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24699+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24700+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24701 .org init_level4_pgt + L4_START_KERNEL*8, 0
24702 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24703 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24704
24705+#ifdef CONFIG_PAX_PER_CPU_PGD
24706+NEXT_PAGE(cpu_pgd)
24707+ .rept 2*NR_CPUS
24708+ .fill 512,8,0
24709+ .endr
24710+#endif
24711+
24712 NEXT_PAGE(level3_ident_pgt)
24713 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24714+#ifdef CONFIG_XEN
24715 .fill 511, 8, 0
24716+#else
24717+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24718+ .fill 510,8,0
24719+#endif
24720+
24721+NEXT_PAGE(level3_vmalloc_start_pgt)
24722+ .fill 512,8,0
24723+
24724+NEXT_PAGE(level3_vmalloc_end_pgt)
24725+ .fill 512,8,0
24726+
24727+NEXT_PAGE(level3_vmemmap_pgt)
24728+ .fill L3_VMEMMAP_START,8,0
24729+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24730+
24731 NEXT_PAGE(level2_ident_pgt)
24732- /* Since I easily can, map the first 1G.
24733+ /* Since I easily can, map the first 2G.
24734 * Don't set NX because code runs from these pages.
24735 */
24736- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24737-#endif
24738+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24739
24740 NEXT_PAGE(level3_kernel_pgt)
24741 .fill L3_START_KERNEL,8,0
24742@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24743 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24744 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24745
24746+NEXT_PAGE(level2_vmemmap_pgt)
24747+ .fill 512,8,0
24748+
24749 NEXT_PAGE(level2_kernel_pgt)
24750 /*
24751 * 512 MB kernel mapping. We spend a full page on this pagetable
24752@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24753 NEXT_PAGE(level2_fixmap_pgt)
24754 .fill 506,8,0
24755 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24756- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24757- .fill 5,8,0
24758+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24759+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24760+ .fill 4,8,0
24761
24762 NEXT_PAGE(level1_fixmap_pgt)
24763 .fill 512,8,0
24764
24765+NEXT_PAGE(level1_vsyscall_pgt)
24766+ .fill 512,8,0
24767+
24768 #undef PMDS
24769
24770- .data
24771+ .align PAGE_SIZE
24772+ENTRY(cpu_gdt_table)
24773+ .rept NR_CPUS
24774+ .quad 0x0000000000000000 /* NULL descriptor */
24775+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24776+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24777+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
24778+ .quad 0x00cffb000000ffff /* __USER32_CS */
24779+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24780+ .quad 0x00affb000000ffff /* __USER_CS */
24781+
24782+#ifdef CONFIG_PAX_KERNEXEC
24783+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24784+#else
24785+ .quad 0x0 /* unused */
24786+#endif
24787+
24788+ .quad 0,0 /* TSS */
24789+ .quad 0,0 /* LDT */
24790+ .quad 0,0,0 /* three TLS descriptors */
24791+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
24792+ /* asm/segment.h:GDT_ENTRIES must match this */
24793+
24794+#ifdef CONFIG_PAX_MEMORY_UDEREF
24795+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24796+#else
24797+ .quad 0x0 /* unused */
24798+#endif
24799+
24800+ /* zero the remaining page */
24801+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24802+ .endr
24803+
24804 .align 16
24805 .globl early_gdt_descr
24806 early_gdt_descr:
24807 .word GDT_ENTRIES*8-1
24808 early_gdt_descr_base:
24809- .quad INIT_PER_CPU_VAR(gdt_page)
24810+ .quad cpu_gdt_table
24811
24812 ENTRY(phys_base)
24813 /* This must match the first entry in level2_kernel_pgt */
24814 .quad 0x0000000000000000
24815
24816 #include "../../x86/xen/xen-head.S"
24817-
24818- __PAGE_ALIGNED_BSS
24819+
24820+ .section .rodata,"a",@progbits
24821 NEXT_PAGE(empty_zero_page)
24822 .skip PAGE_SIZE
24823diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24824index 05fd74f..c3548b1 100644
24825--- a/arch/x86/kernel/i386_ksyms_32.c
24826+++ b/arch/x86/kernel/i386_ksyms_32.c
24827@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24828 EXPORT_SYMBOL(cmpxchg8b_emu);
24829 #endif
24830
24831+EXPORT_SYMBOL_GPL(cpu_gdt_table);
24832+
24833 /* Networking helper routines. */
24834 EXPORT_SYMBOL(csum_partial_copy_generic);
24835+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24836+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24837
24838 EXPORT_SYMBOL(__get_user_1);
24839 EXPORT_SYMBOL(__get_user_2);
24840@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24841 EXPORT_SYMBOL(___preempt_schedule_context);
24842 #endif
24843 #endif
24844+
24845+#ifdef CONFIG_PAX_KERNEXEC
24846+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24847+#endif
24848+
24849+#ifdef CONFIG_PAX_PER_CPU_PGD
24850+EXPORT_SYMBOL(cpu_pgd);
24851+#endif
24852diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24853index d5dd808..b6432cf 100644
24854--- a/arch/x86/kernel/i387.c
24855+++ b/arch/x86/kernel/i387.c
24856@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24857 static inline bool interrupted_user_mode(void)
24858 {
24859 struct pt_regs *regs = get_irq_regs();
24860- return regs && user_mode_vm(regs);
24861+ return regs && user_mode(regs);
24862 }
24863
24864 /*
24865diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24866index 2e977b5..5f2c273 100644
24867--- a/arch/x86/kernel/i8259.c
24868+++ b/arch/x86/kernel/i8259.c
24869@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24870 static void make_8259A_irq(unsigned int irq)
24871 {
24872 disable_irq_nosync(irq);
24873- io_apic_irqs &= ~(1<<irq);
24874+ io_apic_irqs &= ~(1UL<<irq);
24875 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24876 i8259A_chip.name);
24877 enable_irq(irq);
24878@@ -209,7 +209,7 @@ spurious_8259A_irq:
24879 "spurious 8259A interrupt: IRQ%d.\n", irq);
24880 spurious_irq_mask |= irqmask;
24881 }
24882- atomic_inc(&irq_err_count);
24883+ atomic_inc_unchecked(&irq_err_count);
24884 /*
24885 * Theoretically we do not have to handle this IRQ,
24886 * but in Linux this does not cause problems and is
24887@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24888 /* (slave's support for AEOI in flat mode is to be investigated) */
24889 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24890
24891+ pax_open_kernel();
24892 if (auto_eoi)
24893 /*
24894 * In AEOI mode we just have to mask the interrupt
24895 * when acking.
24896 */
24897- i8259A_chip.irq_mask_ack = disable_8259A_irq;
24898+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24899 else
24900- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24901+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24902+ pax_close_kernel();
24903
24904 udelay(100); /* wait for 8259A to initialize */
24905
24906diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24907index a979b5b..1d6db75 100644
24908--- a/arch/x86/kernel/io_delay.c
24909+++ b/arch/x86/kernel/io_delay.c
24910@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24911 * Quirk table for systems that misbehave (lock up, etc.) if port
24912 * 0x80 is used:
24913 */
24914-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24915+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24916 {
24917 .callback = dmi_io_delay_0xed_port,
24918 .ident = "Compaq Presario V6000",
24919diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24920index 4ddaf66..49d5c18 100644
24921--- a/arch/x86/kernel/ioport.c
24922+++ b/arch/x86/kernel/ioport.c
24923@@ -6,6 +6,7 @@
24924 #include <linux/sched.h>
24925 #include <linux/kernel.h>
24926 #include <linux/capability.h>
24927+#include <linux/security.h>
24928 #include <linux/errno.h>
24929 #include <linux/types.h>
24930 #include <linux/ioport.h>
24931@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24932 return -EINVAL;
24933 if (turn_on && !capable(CAP_SYS_RAWIO))
24934 return -EPERM;
24935+#ifdef CONFIG_GRKERNSEC_IO
24936+ if (turn_on && grsec_disable_privio) {
24937+ gr_handle_ioperm();
24938+ return -ENODEV;
24939+ }
24940+#endif
24941
24942 /*
24943 * If it's the first ioperm() call in this thread's lifetime, set the
24944@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24945 * because the ->io_bitmap_max value must match the bitmap
24946 * contents:
24947 */
24948- tss = &per_cpu(init_tss, get_cpu());
24949+ tss = init_tss + get_cpu();
24950
24951 if (turn_on)
24952 bitmap_clear(t->io_bitmap_ptr, from, num);
24953@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24954 if (level > old) {
24955 if (!capable(CAP_SYS_RAWIO))
24956 return -EPERM;
24957+#ifdef CONFIG_GRKERNSEC_IO
24958+ if (grsec_disable_privio) {
24959+ gr_handle_iopl();
24960+ return -ENODEV;
24961+ }
24962+#endif
24963 }
24964 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24965 t->iopl = level << 12;
24966diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24967index 11ccfb0..ec1e46f 100644
24968--- a/arch/x86/kernel/irq.c
24969+++ b/arch/x86/kernel/irq.c
24970@@ -22,7 +22,7 @@
24971 #define CREATE_TRACE_POINTS
24972 #include <asm/trace/irq_vectors.h>
24973
24974-atomic_t irq_err_count;
24975+atomic_unchecked_t irq_err_count;
24976
24977 /* Function pointer for generic interrupt vector handling */
24978 void (*x86_platform_ipi_callback)(void) = NULL;
24979@@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24980 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
24981 seq_printf(p, " Hypervisor callback interrupts\n");
24982 #endif
24983- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24984+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24985 #if defined(CONFIG_X86_IO_APIC)
24986- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24987+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24988 #endif
24989 return 0;
24990 }
24991@@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24992
24993 u64 arch_irq_stat(void)
24994 {
24995- u64 sum = atomic_read(&irq_err_count);
24996+ u64 sum = atomic_read_unchecked(&irq_err_count);
24997 return sum;
24998 }
24999
25000diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25001index 63ce838..2ea3e06 100644
25002--- a/arch/x86/kernel/irq_32.c
25003+++ b/arch/x86/kernel/irq_32.c
25004@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25005
25006 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25007
25008+extern void gr_handle_kernel_exploit(void);
25009+
25010 int sysctl_panic_on_stackoverflow __read_mostly;
25011
25012 /* Debugging check for stack overflow: is there less than 1KB free? */
25013@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25014 __asm__ __volatile__("andl %%esp,%0" :
25015 "=r" (sp) : "0" (THREAD_SIZE - 1));
25016
25017- return sp < (sizeof(struct thread_info) + STACK_WARN);
25018+ return sp < STACK_WARN;
25019 }
25020
25021 static void print_stack_overflow(void)
25022 {
25023 printk(KERN_WARNING "low stack detected by irq handler\n");
25024 dump_stack();
25025+ gr_handle_kernel_exploit();
25026 if (sysctl_panic_on_stackoverflow)
25027 panic("low stack detected by irq handler - check messages\n");
25028 }
25029@@ -84,10 +87,9 @@ static inline void *current_stack(void)
25030 static inline int
25031 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25032 {
25033- struct irq_stack *curstk, *irqstk;
25034+ struct irq_stack *irqstk;
25035 u32 *isp, *prev_esp, arg1, arg2;
25036
25037- curstk = (struct irq_stack *) current_stack();
25038 irqstk = __this_cpu_read(hardirq_stack);
25039
25040 /*
25041@@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25042 * handler) we can't do that and just have to keep using the
25043 * current stack (which is the irq stack already after all)
25044 */
25045- if (unlikely(curstk == irqstk))
25046+ if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25047 return 0;
25048
25049- isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25050+ isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25051
25052 /* Save the next esp at the bottom of the stack */
25053 prev_esp = (u32 *)irqstk;
25054 *prev_esp = current_stack_pointer;
25055
25056+#ifdef CONFIG_PAX_MEMORY_UDEREF
25057+ __set_fs(MAKE_MM_SEG(0));
25058+#endif
25059+
25060 if (unlikely(overflow))
25061 call_on_stack(print_stack_overflow, isp);
25062
25063@@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25064 : "0" (irq), "1" (desc), "2" (isp),
25065 "D" (desc->handle_irq)
25066 : "memory", "cc", "ecx");
25067+
25068+#ifdef CONFIG_PAX_MEMORY_UDEREF
25069+ __set_fs(current_thread_info()->addr_limit);
25070+#endif
25071+
25072 return 1;
25073 }
25074
25075@@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25076 */
25077 void irq_ctx_init(int cpu)
25078 {
25079- struct irq_stack *irqstk;
25080-
25081 if (per_cpu(hardirq_stack, cpu))
25082 return;
25083
25084- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25085- THREADINFO_GFP,
25086- THREAD_SIZE_ORDER));
25087- per_cpu(hardirq_stack, cpu) = irqstk;
25088-
25089- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25090- THREADINFO_GFP,
25091- THREAD_SIZE_ORDER));
25092- per_cpu(softirq_stack, cpu) = irqstk;
25093-
25094- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25095- cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25096+ per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25097+ per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25098 }
25099
25100 void do_softirq_own_stack(void)
25101 {
25102- struct thread_info *curstk;
25103 struct irq_stack *irqstk;
25104 u32 *isp, *prev_esp;
25105
25106- curstk = current_stack();
25107 irqstk = __this_cpu_read(softirq_stack);
25108
25109 /* build the stack frame on the softirq stack */
25110@@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25111 prev_esp = (u32 *)irqstk;
25112 *prev_esp = current_stack_pointer;
25113
25114+#ifdef CONFIG_PAX_MEMORY_UDEREF
25115+ __set_fs(MAKE_MM_SEG(0));
25116+#endif
25117+
25118 call_on_stack(__do_softirq, isp);
25119+
25120+#ifdef CONFIG_PAX_MEMORY_UDEREF
25121+ __set_fs(current_thread_info()->addr_limit);
25122+#endif
25123+
25124 }
25125
25126 bool handle_irq(unsigned irq, struct pt_regs *regs)
25127@@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25128 if (unlikely(!desc))
25129 return false;
25130
25131- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25132+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25133 if (unlikely(overflow))
25134 print_stack_overflow();
25135 desc->handle_irq(irq, desc);
25136diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25137index 4d1c746..55a22d6 100644
25138--- a/arch/x86/kernel/irq_64.c
25139+++ b/arch/x86/kernel/irq_64.c
25140@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25141 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25142 EXPORT_PER_CPU_SYMBOL(irq_regs);
25143
25144+extern void gr_handle_kernel_exploit(void);
25145+
25146 int sysctl_panic_on_stackoverflow;
25147
25148 /*
25149@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25150 u64 estack_top, estack_bottom;
25151 u64 curbase = (u64)task_stack_page(current);
25152
25153- if (user_mode_vm(regs))
25154+ if (user_mode(regs))
25155 return;
25156
25157 if (regs->sp >= curbase + sizeof(struct thread_info) +
25158@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25159 irq_stack_top, irq_stack_bottom,
25160 estack_top, estack_bottom);
25161
25162+ gr_handle_kernel_exploit();
25163+
25164 if (sysctl_panic_on_stackoverflow)
25165 panic("low stack detected by irq handler - check messages\n");
25166 #endif
25167diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25168index 26d5a55..a01160a 100644
25169--- a/arch/x86/kernel/jump_label.c
25170+++ b/arch/x86/kernel/jump_label.c
25171@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25172 * Jump label is enabled for the first time.
25173 * So we expect a default_nop...
25174 */
25175- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25176+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25177 != 0))
25178 bug_at((void *)entry->code, __LINE__);
25179 } else {
25180@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25181 * ...otherwise expect an ideal_nop. Otherwise
25182 * something went horribly wrong.
25183 */
25184- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25185+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25186 != 0))
25187 bug_at((void *)entry->code, __LINE__);
25188 }
25189@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25190 * are converting the default nop to the ideal nop.
25191 */
25192 if (init) {
25193- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25194+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25195 bug_at((void *)entry->code, __LINE__);
25196 } else {
25197 code.jump = 0xe9;
25198 code.offset = entry->target -
25199 (entry->code + JUMP_LABEL_NOP_SIZE);
25200- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25201+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25202 bug_at((void *)entry->code, __LINE__);
25203 }
25204 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25205diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25206index 7ec1d5f..5a7d130 100644
25207--- a/arch/x86/kernel/kgdb.c
25208+++ b/arch/x86/kernel/kgdb.c
25209@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25210 #ifdef CONFIG_X86_32
25211 switch (regno) {
25212 case GDB_SS:
25213- if (!user_mode_vm(regs))
25214+ if (!user_mode(regs))
25215 *(unsigned long *)mem = __KERNEL_DS;
25216 break;
25217 case GDB_SP:
25218- if (!user_mode_vm(regs))
25219+ if (!user_mode(regs))
25220 *(unsigned long *)mem = kernel_stack_pointer(regs);
25221 break;
25222 case GDB_GS:
25223@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25224 bp->attr.bp_addr = breakinfo[breakno].addr;
25225 bp->attr.bp_len = breakinfo[breakno].len;
25226 bp->attr.bp_type = breakinfo[breakno].type;
25227- info->address = breakinfo[breakno].addr;
25228+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25229+ info->address = ktla_ktva(breakinfo[breakno].addr);
25230+ else
25231+ info->address = breakinfo[breakno].addr;
25232 info->len = breakinfo[breakno].len;
25233 info->type = breakinfo[breakno].type;
25234 val = arch_install_hw_breakpoint(bp);
25235@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25236 case 'k':
25237 /* clear the trace bit */
25238 linux_regs->flags &= ~X86_EFLAGS_TF;
25239- atomic_set(&kgdb_cpu_doing_single_step, -1);
25240+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25241
25242 /* set the trace bit if we're stepping */
25243 if (remcomInBuffer[0] == 's') {
25244 linux_regs->flags |= X86_EFLAGS_TF;
25245- atomic_set(&kgdb_cpu_doing_single_step,
25246+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25247 raw_smp_processor_id());
25248 }
25249
25250@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25251
25252 switch (cmd) {
25253 case DIE_DEBUG:
25254- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25255+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25256 if (user_mode(regs))
25257 return single_step_cont(regs, args);
25258 break;
25259@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25260 #endif /* CONFIG_DEBUG_RODATA */
25261
25262 bpt->type = BP_BREAKPOINT;
25263- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25264+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25265 BREAK_INSTR_SIZE);
25266 if (err)
25267 return err;
25268- err = probe_kernel_write((char *)bpt->bpt_addr,
25269+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25270 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25271 #ifdef CONFIG_DEBUG_RODATA
25272 if (!err)
25273@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25274 return -EBUSY;
25275 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25276 BREAK_INSTR_SIZE);
25277- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25278+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25279 if (err)
25280 return err;
25281 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25282@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25283 if (mutex_is_locked(&text_mutex))
25284 goto knl_write;
25285 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25286- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25287+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25288 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25289 goto knl_write;
25290 return err;
25291 knl_write:
25292 #endif /* CONFIG_DEBUG_RODATA */
25293- return probe_kernel_write((char *)bpt->bpt_addr,
25294+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25295 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25296 }
25297
25298diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25299index 61b17dc..784bfe9 100644
25300--- a/arch/x86/kernel/kprobes/core.c
25301+++ b/arch/x86/kernel/kprobes/core.c
25302@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25303 s32 raddr;
25304 } __packed *insn;
25305
25306- insn = (struct __arch_relative_insn *)from;
25307+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25308+
25309+ pax_open_kernel();
25310 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25311 insn->op = op;
25312+ pax_close_kernel();
25313 }
25314
25315 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25316@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25317 kprobe_opcode_t opcode;
25318 kprobe_opcode_t *orig_opcodes = opcodes;
25319
25320- if (search_exception_tables((unsigned long)opcodes))
25321+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25322 return 0; /* Page fault may occur on this address. */
25323
25324 retry:
25325@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25326 * for the first byte, we can recover the original instruction
25327 * from it and kp->opcode.
25328 */
25329- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25330+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25331 buf[0] = kp->opcode;
25332- return (unsigned long)buf;
25333+ return ktva_ktla((unsigned long)buf);
25334 }
25335
25336 /*
25337@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25338 /* Another subsystem puts a breakpoint, failed to recover */
25339 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25340 return 0;
25341+ pax_open_kernel();
25342 memcpy(dest, insn.kaddr, insn.length);
25343+ pax_close_kernel();
25344
25345 #ifdef CONFIG_X86_64
25346 if (insn_rip_relative(&insn)) {
25347@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25348 return 0;
25349 }
25350 disp = (u8 *) dest + insn_offset_displacement(&insn);
25351+ pax_open_kernel();
25352 *(s32 *) disp = (s32) newdisp;
25353+ pax_close_kernel();
25354 }
25355 #endif
25356 return insn.length;
25357@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25358 * nor set current_kprobe, because it doesn't use single
25359 * stepping.
25360 */
25361- regs->ip = (unsigned long)p->ainsn.insn;
25362+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25363 preempt_enable_no_resched();
25364 return;
25365 }
25366@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25367 regs->flags &= ~X86_EFLAGS_IF;
25368 /* single step inline if the instruction is an int3 */
25369 if (p->opcode == BREAKPOINT_INSTRUCTION)
25370- regs->ip = (unsigned long)p->addr;
25371+ regs->ip = ktla_ktva((unsigned long)p->addr);
25372 else
25373- regs->ip = (unsigned long)p->ainsn.insn;
25374+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25375 }
25376
25377 /*
25378@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25379 setup_singlestep(p, regs, kcb, 0);
25380 return 1;
25381 }
25382- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25383+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25384 /*
25385 * The breakpoint instruction was removed right
25386 * after we hit it. Another cpu has removed
25387@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25388 " movq %rax, 152(%rsp)\n"
25389 RESTORE_REGS_STRING
25390 " popfq\n"
25391+#ifdef KERNEXEC_PLUGIN
25392+ " btsq $63,(%rsp)\n"
25393+#endif
25394 #else
25395 " pushf\n"
25396 SAVE_REGS_STRING
25397@@ -779,7 +789,7 @@ static void __kprobes
25398 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25399 {
25400 unsigned long *tos = stack_addr(regs);
25401- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25402+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25403 unsigned long orig_ip = (unsigned long)p->addr;
25404 kprobe_opcode_t *insn = p->ainsn.insn;
25405
25406@@ -959,7 +969,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25407 struct die_args *args = data;
25408 int ret = NOTIFY_DONE;
25409
25410- if (args->regs && user_mode_vm(args->regs))
25411+ if (args->regs && user_mode(args->regs))
25412 return ret;
25413
25414 switch (val) {
25415diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25416index 898160b..758cde8 100644
25417--- a/arch/x86/kernel/kprobes/opt.c
25418+++ b/arch/x86/kernel/kprobes/opt.c
25419@@ -79,6 +79,7 @@ found:
25420 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25421 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25422 {
25423+ pax_open_kernel();
25424 #ifdef CONFIG_X86_64
25425 *addr++ = 0x48;
25426 *addr++ = 0xbf;
25427@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25428 *addr++ = 0xb8;
25429 #endif
25430 *(unsigned long *)addr = val;
25431+ pax_close_kernel();
25432 }
25433
25434 asm (
25435@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25436 * Verify if the address gap is in 2GB range, because this uses
25437 * a relative jump.
25438 */
25439- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25440+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25441 if (abs(rel) > 0x7fffffff)
25442 return -ERANGE;
25443
25444@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25445 op->optinsn.size = ret;
25446
25447 /* Copy arch-dep-instance from template */
25448- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25449+ pax_open_kernel();
25450+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25451+ pax_close_kernel();
25452
25453 /* Set probe information */
25454 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25455
25456 /* Set probe function call */
25457- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25458+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25459
25460 /* Set returning jmp instruction at the tail of out-of-line buffer */
25461- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25462+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25463 (u8 *)op->kp.addr + op->optinsn.size);
25464
25465 flush_icache_range((unsigned long) buf,
25466@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25467 WARN_ON(kprobe_disabled(&op->kp));
25468
25469 /* Backup instructions which will be replaced by jump address */
25470- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25471+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25472 RELATIVE_ADDR_SIZE);
25473
25474 insn_buf[0] = RELATIVEJUMP_OPCODE;
25475@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25476 /* This kprobe is really able to run optimized path. */
25477 op = container_of(p, struct optimized_kprobe, kp);
25478 /* Detour through copied instructions */
25479- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25480+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25481 if (!reenter)
25482 reset_current_kprobe();
25483 preempt_enable_no_resched();
25484diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25485index c2bedae..25e7ab60 100644
25486--- a/arch/x86/kernel/ksysfs.c
25487+++ b/arch/x86/kernel/ksysfs.c
25488@@ -184,7 +184,7 @@ out:
25489
25490 static struct kobj_attribute type_attr = __ATTR_RO(type);
25491
25492-static struct bin_attribute data_attr = {
25493+static bin_attribute_no_const data_attr __read_only = {
25494 .attr = {
25495 .name = "data",
25496 .mode = S_IRUGO,
25497diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25498index dcbbaa1..81ae763 100644
25499--- a/arch/x86/kernel/ldt.c
25500+++ b/arch/x86/kernel/ldt.c
25501@@ -68,13 +68,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25502 if (reload) {
25503 #ifdef CONFIG_SMP
25504 preempt_disable();
25505- load_LDT(pc);
25506+ load_LDT_nolock(pc);
25507 if (!cpumask_equal(mm_cpumask(current->mm),
25508 cpumask_of(smp_processor_id())))
25509 smp_call_function(flush_ldt, current->mm, 1);
25510 preempt_enable();
25511 #else
25512- load_LDT(pc);
25513+ load_LDT_nolock(pc);
25514 #endif
25515 }
25516 if (oldsize) {
25517@@ -96,7 +96,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25518 return err;
25519
25520 for (i = 0; i < old->size; i++)
25521- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25522+ write_ldt_entry(new->ldt, i, old->ldt + i);
25523 return 0;
25524 }
25525
25526@@ -117,6 +117,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25527 retval = copy_ldt(&mm->context, &old_mm->context);
25528 mutex_unlock(&old_mm->context.lock);
25529 }
25530+
25531+ if (tsk == current) {
25532+ mm->context.vdso = 0;
25533+
25534+#ifdef CONFIG_X86_32
25535+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25536+ mm->context.user_cs_base = 0UL;
25537+ mm->context.user_cs_limit = ~0UL;
25538+
25539+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25540+ cpus_clear(mm->context.cpu_user_cs_mask);
25541+#endif
25542+
25543+#endif
25544+#endif
25545+
25546+ }
25547+
25548 return retval;
25549 }
25550
25551@@ -231,6 +249,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25552 }
25553 }
25554
25555+#ifdef CONFIG_PAX_SEGMEXEC
25556+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25557+ error = -EINVAL;
25558+ goto out_unlock;
25559+ }
25560+#endif
25561+
25562 /*
25563 * On x86-64 we do not support 16-bit segments due to
25564 * IRET leaking the high bits of the kernel stack address.
25565diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25566index 1667b1d..16492c5 100644
25567--- a/arch/x86/kernel/machine_kexec_32.c
25568+++ b/arch/x86/kernel/machine_kexec_32.c
25569@@ -25,7 +25,7 @@
25570 #include <asm/cacheflush.h>
25571 #include <asm/debugreg.h>
25572
25573-static void set_idt(void *newidt, __u16 limit)
25574+static void set_idt(struct desc_struct *newidt, __u16 limit)
25575 {
25576 struct desc_ptr curidt;
25577
25578@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25579 }
25580
25581
25582-static void set_gdt(void *newgdt, __u16 limit)
25583+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25584 {
25585 struct desc_ptr curgdt;
25586
25587@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25588 }
25589
25590 control_page = page_address(image->control_code_page);
25591- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25592+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25593
25594 relocate_kernel_ptr = control_page;
25595 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25596diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25597index e69f988..da078ea 100644
25598--- a/arch/x86/kernel/module.c
25599+++ b/arch/x86/kernel/module.c
25600@@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25601 }
25602 #endif
25603
25604-void *module_alloc(unsigned long size)
25605+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25606 {
25607- if (PAGE_ALIGN(size) > MODULES_LEN)
25608+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25609 return NULL;
25610 return __vmalloc_node_range(size, 1,
25611 MODULES_VADDR + get_module_load_offset(),
25612- MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25613- PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25614+ MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25615+ prot, NUMA_NO_NODE,
25616 __builtin_return_address(0));
25617 }
25618
25619+void *module_alloc(unsigned long size)
25620+{
25621+
25622+#ifdef CONFIG_PAX_KERNEXEC
25623+ return __module_alloc(size, PAGE_KERNEL);
25624+#else
25625+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25626+#endif
25627+
25628+}
25629+
25630+#ifdef CONFIG_PAX_KERNEXEC
25631+#ifdef CONFIG_X86_32
25632+void *module_alloc_exec(unsigned long size)
25633+{
25634+ struct vm_struct *area;
25635+
25636+ if (size == 0)
25637+ return NULL;
25638+
25639+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25640+return area ? area->addr : NULL;
25641+}
25642+EXPORT_SYMBOL(module_alloc_exec);
25643+
25644+void module_free_exec(struct module *mod, void *module_region)
25645+{
25646+ vunmap(module_region);
25647+}
25648+EXPORT_SYMBOL(module_free_exec);
25649+#else
25650+void module_free_exec(struct module *mod, void *module_region)
25651+{
25652+ module_free(mod, module_region);
25653+}
25654+EXPORT_SYMBOL(module_free_exec);
25655+
25656+void *module_alloc_exec(unsigned long size)
25657+{
25658+ return __module_alloc(size, PAGE_KERNEL_RX);
25659+}
25660+EXPORT_SYMBOL(module_alloc_exec);
25661+#endif
25662+#endif
25663+
25664 #ifdef CONFIG_X86_32
25665 int apply_relocate(Elf32_Shdr *sechdrs,
25666 const char *strtab,
25667@@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25668 unsigned int i;
25669 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25670 Elf32_Sym *sym;
25671- uint32_t *location;
25672+ uint32_t *plocation, location;
25673
25674 DEBUGP("Applying relocate section %u to %u\n",
25675 relsec, sechdrs[relsec].sh_info);
25676 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25677 /* This is where to make the change */
25678- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25679- + rel[i].r_offset;
25680+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25681+ location = (uint32_t)plocation;
25682+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25683+ plocation = ktla_ktva((void *)plocation);
25684 /* This is the symbol it is referring to. Note that all
25685 undefined symbols have been resolved. */
25686 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25687@@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25688 switch (ELF32_R_TYPE(rel[i].r_info)) {
25689 case R_386_32:
25690 /* We add the value into the location given */
25691- *location += sym->st_value;
25692+ pax_open_kernel();
25693+ *plocation += sym->st_value;
25694+ pax_close_kernel();
25695 break;
25696 case R_386_PC32:
25697 /* Add the value, subtract its position */
25698- *location += sym->st_value - (uint32_t)location;
25699+ pax_open_kernel();
25700+ *plocation += sym->st_value - location;
25701+ pax_close_kernel();
25702 break;
25703 default:
25704 pr_err("%s: Unknown relocation: %u\n",
25705@@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25706 case R_X86_64_NONE:
25707 break;
25708 case R_X86_64_64:
25709+ pax_open_kernel();
25710 *(u64 *)loc = val;
25711+ pax_close_kernel();
25712 break;
25713 case R_X86_64_32:
25714+ pax_open_kernel();
25715 *(u32 *)loc = val;
25716+ pax_close_kernel();
25717 if (val != *(u32 *)loc)
25718 goto overflow;
25719 break;
25720 case R_X86_64_32S:
25721+ pax_open_kernel();
25722 *(s32 *)loc = val;
25723+ pax_close_kernel();
25724 if ((s64)val != *(s32 *)loc)
25725 goto overflow;
25726 break;
25727 case R_X86_64_PC32:
25728 val -= (u64)loc;
25729+ pax_open_kernel();
25730 *(u32 *)loc = val;
25731+ pax_close_kernel();
25732+
25733 #if 0
25734 if ((s64)val != *(s32 *)loc)
25735 goto overflow;
25736diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25737index c9603ac..9f88728 100644
25738--- a/arch/x86/kernel/msr.c
25739+++ b/arch/x86/kernel/msr.c
25740@@ -37,6 +37,7 @@
25741 #include <linux/notifier.h>
25742 #include <linux/uaccess.h>
25743 #include <linux/gfp.h>
25744+#include <linux/grsecurity.h>
25745
25746 #include <asm/processor.h>
25747 #include <asm/msr.h>
25748@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25749 int err = 0;
25750 ssize_t bytes = 0;
25751
25752+#ifdef CONFIG_GRKERNSEC_KMEM
25753+ gr_handle_msr_write();
25754+ return -EPERM;
25755+#endif
25756+
25757 if (count % 8)
25758 return -EINVAL; /* Invalid chunk size */
25759
25760@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25761 err = -EBADF;
25762 break;
25763 }
25764+#ifdef CONFIG_GRKERNSEC_KMEM
25765+ gr_handle_msr_write();
25766+ return -EPERM;
25767+#endif
25768 if (copy_from_user(&regs, uregs, sizeof regs)) {
25769 err = -EFAULT;
25770 break;
25771@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25772 return notifier_from_errno(err);
25773 }
25774
25775-static struct notifier_block __refdata msr_class_cpu_notifier = {
25776+static struct notifier_block msr_class_cpu_notifier = {
25777 .notifier_call = msr_class_cpu_callback,
25778 };
25779
25780diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25781index b4872b9..5bf0684 100644
25782--- a/arch/x86/kernel/nmi.c
25783+++ b/arch/x86/kernel/nmi.c
25784@@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
25785
25786 static void nmi_max_handler(struct irq_work *w)
25787 {
25788- struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
25789+ struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
25790 int remainder_ns, decimal_msecs;
25791- u64 whole_msecs = ACCESS_ONCE(a->max_duration);
25792+ u64 whole_msecs = ACCESS_ONCE(n->max_duration);
25793
25794 remainder_ns = do_div(whole_msecs, (1000 * 1000));
25795 decimal_msecs = remainder_ns / 1000;
25796
25797 printk_ratelimited(KERN_INFO
25798 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
25799- a->handler, whole_msecs, decimal_msecs);
25800+ n->action->handler, whole_msecs, decimal_msecs);
25801 }
25802
25803 static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
25804@@ -134,11 +134,11 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25805 delta = sched_clock() - delta;
25806 trace_nmi_handler(a->handler, (int)delta, thishandled);
25807
25808- if (delta < nmi_longest_ns || delta < a->max_duration)
25809+ if (delta < nmi_longest_ns || delta < a->work->max_duration)
25810 continue;
25811
25812- a->max_duration = delta;
25813- irq_work_queue(&a->irq_work);
25814+ a->work->max_duration = delta;
25815+ irq_work_queue(&a->work->irq_work);
25816 }
25817
25818 rcu_read_unlock();
25819@@ -147,7 +147,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25820 return handled;
25821 }
25822
25823-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25824+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25825 {
25826 struct nmi_desc *desc = nmi_to_desc(type);
25827 unsigned long flags;
25828@@ -155,7 +155,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25829 if (!action->handler)
25830 return -EINVAL;
25831
25832- init_irq_work(&action->irq_work, nmi_max_handler);
25833+ action->work->action = action;
25834+ init_irq_work(&action->work->irq_work, nmi_max_handler);
25835
25836 spin_lock_irqsave(&desc->lock, flags);
25837
25838@@ -173,9 +174,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25839 * event confuses some handlers (kdump uses this flag)
25840 */
25841 if (action->flags & NMI_FLAG_FIRST)
25842- list_add_rcu(&action->list, &desc->head);
25843+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25844 else
25845- list_add_tail_rcu(&action->list, &desc->head);
25846+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25847
25848 spin_unlock_irqrestore(&desc->lock, flags);
25849 return 0;
25850@@ -198,7 +199,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25851 if (!strcmp(n->name, name)) {
25852 WARN(in_nmi(),
25853 "Trying to free NMI (%s) from NMI context!\n", n->name);
25854- list_del_rcu(&n->list);
25855+ pax_list_del_rcu((struct list_head *)&n->list);
25856 break;
25857 }
25858 }
25859@@ -523,6 +524,17 @@ static inline void nmi_nesting_postprocess(void)
25860 dotraplinkage notrace __kprobes void
25861 do_nmi(struct pt_regs *regs, long error_code)
25862 {
25863+
25864+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25865+ if (!user_mode(regs)) {
25866+ unsigned long cs = regs->cs & 0xFFFF;
25867+ unsigned long ip = ktva_ktla(regs->ip);
25868+
25869+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25870+ regs->ip = ip;
25871+ }
25872+#endif
25873+
25874 nmi_nesting_preprocess(regs);
25875
25876 nmi_enter();
25877diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25878index 6d9582e..f746287 100644
25879--- a/arch/x86/kernel/nmi_selftest.c
25880+++ b/arch/x86/kernel/nmi_selftest.c
25881@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25882 {
25883 /* trap all the unknown NMIs we may generate */
25884 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25885- __initdata);
25886+ __initconst);
25887 }
25888
25889 static void __init cleanup_nmi_testsuite(void)
25890@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25891 unsigned long timeout;
25892
25893 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25894- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25895+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25896 nmi_fail = FAILURE;
25897 return;
25898 }
25899diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25900index bbb6c73..24a58ef 100644
25901--- a/arch/x86/kernel/paravirt-spinlocks.c
25902+++ b/arch/x86/kernel/paravirt-spinlocks.c
25903@@ -8,7 +8,7 @@
25904
25905 #include <asm/paravirt.h>
25906
25907-struct pv_lock_ops pv_lock_ops = {
25908+struct pv_lock_ops pv_lock_ops __read_only = {
25909 #ifdef CONFIG_SMP
25910 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25911 .unlock_kick = paravirt_nop,
25912diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25913index 1b10af8..45bfbec 100644
25914--- a/arch/x86/kernel/paravirt.c
25915+++ b/arch/x86/kernel/paravirt.c
25916@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25917 {
25918 return x;
25919 }
25920+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25921+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25922+#endif
25923
25924 void __init default_banner(void)
25925 {
25926@@ -141,16 +144,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25927
25928 if (opfunc == NULL)
25929 /* If there's no function, patch it with a ud2a (BUG) */
25930- ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25931- else if (opfunc == _paravirt_nop)
25932+ ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
25933+ else if (opfunc == (void *)_paravirt_nop)
25934 /* If the operation is a nop, then nop the callsite */
25935 ret = paravirt_patch_nop();
25936
25937 /* identity functions just return their single argument */
25938- else if (opfunc == _paravirt_ident_32)
25939+ else if (opfunc == (void *)_paravirt_ident_32)
25940 ret = paravirt_patch_ident_32(insnbuf, len);
25941- else if (opfunc == _paravirt_ident_64)
25942+ else if (opfunc == (void *)_paravirt_ident_64)
25943 ret = paravirt_patch_ident_64(insnbuf, len);
25944+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25945+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25946+ ret = paravirt_patch_ident_64(insnbuf, len);
25947+#endif
25948
25949 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25950 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25951@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25952 if (insn_len > len || start == NULL)
25953 insn_len = len;
25954 else
25955- memcpy(insnbuf, start, insn_len);
25956+ memcpy(insnbuf, ktla_ktva(start), insn_len);
25957
25958 return insn_len;
25959 }
25960@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25961 return this_cpu_read(paravirt_lazy_mode);
25962 }
25963
25964-struct pv_info pv_info = {
25965+struct pv_info pv_info __read_only = {
25966 .name = "bare hardware",
25967 .paravirt_enabled = 0,
25968 .kernel_rpl = 0,
25969@@ -310,16 +317,16 @@ struct pv_info pv_info = {
25970 #endif
25971 };
25972
25973-struct pv_init_ops pv_init_ops = {
25974+struct pv_init_ops pv_init_ops __read_only = {
25975 .patch = native_patch,
25976 };
25977
25978-struct pv_time_ops pv_time_ops = {
25979+struct pv_time_ops pv_time_ops __read_only = {
25980 .sched_clock = native_sched_clock,
25981 .steal_clock = native_steal_clock,
25982 };
25983
25984-__visible struct pv_irq_ops pv_irq_ops = {
25985+__visible struct pv_irq_ops pv_irq_ops __read_only = {
25986 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25987 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25988 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25989@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25990 #endif
25991 };
25992
25993-__visible struct pv_cpu_ops pv_cpu_ops = {
25994+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25995 .cpuid = native_cpuid,
25996 .get_debugreg = native_get_debugreg,
25997 .set_debugreg = native_set_debugreg,
25998@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25999 .end_context_switch = paravirt_nop,
26000 };
26001
26002-struct pv_apic_ops pv_apic_ops = {
26003+struct pv_apic_ops pv_apic_ops __read_only= {
26004 #ifdef CONFIG_X86_LOCAL_APIC
26005 .startup_ipi_hook = paravirt_nop,
26006 #endif
26007 };
26008
26009-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26010+#ifdef CONFIG_X86_32
26011+#ifdef CONFIG_X86_PAE
26012+/* 64-bit pagetable entries */
26013+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26014+#else
26015 /* 32-bit pagetable entries */
26016 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26017+#endif
26018 #else
26019 /* 64-bit pagetable entries */
26020 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26021 #endif
26022
26023-struct pv_mmu_ops pv_mmu_ops = {
26024+struct pv_mmu_ops pv_mmu_ops __read_only = {
26025
26026 .read_cr2 = native_read_cr2,
26027 .write_cr2 = native_write_cr2,
26028@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26029 .make_pud = PTE_IDENT,
26030
26031 .set_pgd = native_set_pgd,
26032+ .set_pgd_batched = native_set_pgd_batched,
26033 #endif
26034 #endif /* PAGETABLE_LEVELS >= 3 */
26035
26036@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26037 },
26038
26039 .set_fixmap = native_set_fixmap,
26040+
26041+#ifdef CONFIG_PAX_KERNEXEC
26042+ .pax_open_kernel = native_pax_open_kernel,
26043+ .pax_close_kernel = native_pax_close_kernel,
26044+#endif
26045+
26046 };
26047
26048 EXPORT_SYMBOL_GPL(pv_time_ops);
26049diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26050index 0497f71..7186c0d 100644
26051--- a/arch/x86/kernel/pci-calgary_64.c
26052+++ b/arch/x86/kernel/pci-calgary_64.c
26053@@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26054 tce_space = be64_to_cpu(readq(target));
26055 tce_space = tce_space & TAR_SW_BITS;
26056
26057- tce_space = tce_space & (~specified_table_size);
26058+ tce_space = tce_space & (~(unsigned long)specified_table_size);
26059 info->tce_space = (u64 *)__va(tce_space);
26060 }
26061 }
26062diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26063index 35ccf75..7a15747 100644
26064--- a/arch/x86/kernel/pci-iommu_table.c
26065+++ b/arch/x86/kernel/pci-iommu_table.c
26066@@ -2,7 +2,7 @@
26067 #include <asm/iommu_table.h>
26068 #include <linux/string.h>
26069 #include <linux/kallsyms.h>
26070-
26071+#include <linux/sched.h>
26072
26073 #define DEBUG 1
26074
26075diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26076index 6c483ba..d10ce2f 100644
26077--- a/arch/x86/kernel/pci-swiotlb.c
26078+++ b/arch/x86/kernel/pci-swiotlb.c
26079@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26080 void *vaddr, dma_addr_t dma_addr,
26081 struct dma_attrs *attrs)
26082 {
26083- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26084+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26085 }
26086
26087 static struct dma_map_ops swiotlb_dma_ops = {
26088diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26089index ca7f0d5..8996469 100644
26090--- a/arch/x86/kernel/preempt.S
26091+++ b/arch/x86/kernel/preempt.S
26092@@ -3,12 +3,14 @@
26093 #include <asm/dwarf2.h>
26094 #include <asm/asm.h>
26095 #include <asm/calling.h>
26096+#include <asm/alternative-asm.h>
26097
26098 ENTRY(___preempt_schedule)
26099 CFI_STARTPROC
26100 SAVE_ALL
26101 call preempt_schedule
26102 RESTORE_ALL
26103+ pax_force_retaddr
26104 ret
26105 CFI_ENDPROC
26106
26107@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26108 SAVE_ALL
26109 call preempt_schedule_context
26110 RESTORE_ALL
26111+ pax_force_retaddr
26112 ret
26113 CFI_ENDPROC
26114
26115diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26116index 4505e2a..ae28b0d 100644
26117--- a/arch/x86/kernel/process.c
26118+++ b/arch/x86/kernel/process.c
26119@@ -36,7 +36,8 @@
26120 * section. Since TSS's are completely CPU-local, we want them
26121 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26122 */
26123-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26124+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26125+EXPORT_SYMBOL(init_tss);
26126
26127 #ifdef CONFIG_X86_64
26128 static DEFINE_PER_CPU(unsigned char, is_idle);
26129@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26130 task_xstate_cachep =
26131 kmem_cache_create("task_xstate", xstate_size,
26132 __alignof__(union thread_xstate),
26133- SLAB_PANIC | SLAB_NOTRACK, NULL);
26134+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26135 }
26136
26137 /*
26138@@ -105,7 +106,7 @@ void exit_thread(void)
26139 unsigned long *bp = t->io_bitmap_ptr;
26140
26141 if (bp) {
26142- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26143+ struct tss_struct *tss = init_tss + get_cpu();
26144
26145 t->io_bitmap_ptr = NULL;
26146 clear_thread_flag(TIF_IO_BITMAP);
26147@@ -125,6 +126,9 @@ void flush_thread(void)
26148 {
26149 struct task_struct *tsk = current;
26150
26151+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26152+ loadsegment(gs, 0);
26153+#endif
26154 flush_ptrace_hw_breakpoint(tsk);
26155 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26156 drop_init_fpu(tsk);
26157@@ -271,7 +275,7 @@ static void __exit_idle(void)
26158 void exit_idle(void)
26159 {
26160 /* idle loop has pid 0 */
26161- if (current->pid)
26162+ if (task_pid_nr(current))
26163 return;
26164 __exit_idle();
26165 }
26166@@ -324,7 +328,7 @@ bool xen_set_default_idle(void)
26167 return ret;
26168 }
26169 #endif
26170-void stop_this_cpu(void *dummy)
26171+__noreturn void stop_this_cpu(void *dummy)
26172 {
26173 local_irq_disable();
26174 /*
26175@@ -453,16 +457,37 @@ static int __init idle_setup(char *str)
26176 }
26177 early_param("idle", idle_setup);
26178
26179-unsigned long arch_align_stack(unsigned long sp)
26180+#ifdef CONFIG_PAX_RANDKSTACK
26181+void pax_randomize_kstack(struct pt_regs *regs)
26182 {
26183- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26184- sp -= get_random_int() % 8192;
26185- return sp & ~0xf;
26186-}
26187+ struct thread_struct *thread = &current->thread;
26188+ unsigned long time;
26189
26190-unsigned long arch_randomize_brk(struct mm_struct *mm)
26191-{
26192- unsigned long range_end = mm->brk + 0x02000000;
26193- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26194-}
26195+ if (!randomize_va_space)
26196+ return;
26197+
26198+ if (v8086_mode(regs))
26199+ return;
26200
26201+ rdtscl(time);
26202+
26203+ /* P4 seems to return a 0 LSB, ignore it */
26204+#ifdef CONFIG_MPENTIUM4
26205+ time &= 0x3EUL;
26206+ time <<= 2;
26207+#elif defined(CONFIG_X86_64)
26208+ time &= 0xFUL;
26209+ time <<= 4;
26210+#else
26211+ time &= 0x1FUL;
26212+ time <<= 3;
26213+#endif
26214+
26215+ thread->sp0 ^= time;
26216+ load_sp0(init_tss + smp_processor_id(), thread);
26217+
26218+#ifdef CONFIG_X86_64
26219+ this_cpu_write(kernel_stack, thread->sp0);
26220+#endif
26221+}
26222+#endif
26223diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26224index 7bc86bb..0ea06e8 100644
26225--- a/arch/x86/kernel/process_32.c
26226+++ b/arch/x86/kernel/process_32.c
26227@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26228 unsigned long thread_saved_pc(struct task_struct *tsk)
26229 {
26230 return ((unsigned long *)tsk->thread.sp)[3];
26231+//XXX return tsk->thread.eip;
26232 }
26233
26234 void __show_regs(struct pt_regs *regs, int all)
26235@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26236 unsigned long sp;
26237 unsigned short ss, gs;
26238
26239- if (user_mode_vm(regs)) {
26240+ if (user_mode(regs)) {
26241 sp = regs->sp;
26242 ss = regs->ss & 0xffff;
26243- gs = get_user_gs(regs);
26244 } else {
26245 sp = kernel_stack_pointer(regs);
26246 savesegment(ss, ss);
26247- savesegment(gs, gs);
26248 }
26249+ gs = get_user_gs(regs);
26250
26251 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26252 (u16)regs->cs, regs->ip, regs->flags,
26253- smp_processor_id());
26254+ raw_smp_processor_id());
26255 print_symbol("EIP is at %s\n", regs->ip);
26256
26257 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26258@@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26259 int copy_thread(unsigned long clone_flags, unsigned long sp,
26260 unsigned long arg, struct task_struct *p)
26261 {
26262- struct pt_regs *childregs = task_pt_regs(p);
26263+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26264 struct task_struct *tsk;
26265 int err;
26266
26267 p->thread.sp = (unsigned long) childregs;
26268 p->thread.sp0 = (unsigned long) (childregs+1);
26269+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26270
26271 if (unlikely(p->flags & PF_KTHREAD)) {
26272 /* kernel thread */
26273 memset(childregs, 0, sizeof(struct pt_regs));
26274 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26275- task_user_gs(p) = __KERNEL_STACK_CANARY;
26276- childregs->ds = __USER_DS;
26277- childregs->es = __USER_DS;
26278+ savesegment(gs, childregs->gs);
26279+ childregs->ds = __KERNEL_DS;
26280+ childregs->es = __KERNEL_DS;
26281 childregs->fs = __KERNEL_PERCPU;
26282 childregs->bx = sp; /* function */
26283 childregs->bp = arg;
26284@@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26285 struct thread_struct *prev = &prev_p->thread,
26286 *next = &next_p->thread;
26287 int cpu = smp_processor_id();
26288- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26289+ struct tss_struct *tss = init_tss + cpu;
26290 fpu_switch_t fpu;
26291
26292 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26293@@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26294 */
26295 lazy_save_gs(prev->gs);
26296
26297+#ifdef CONFIG_PAX_MEMORY_UDEREF
26298+ __set_fs(task_thread_info(next_p)->addr_limit);
26299+#endif
26300+
26301 /*
26302 * Load the per-thread Thread-Local Storage descriptor.
26303 */
26304@@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26305 */
26306 arch_end_context_switch(next_p);
26307
26308- this_cpu_write(kernel_stack,
26309- (unsigned long)task_stack_page(next_p) +
26310- THREAD_SIZE - KERNEL_STACK_OFFSET);
26311+ this_cpu_write(current_task, next_p);
26312+ this_cpu_write(current_tinfo, &next_p->tinfo);
26313+ this_cpu_write(kernel_stack, next->sp0);
26314
26315 /*
26316 * Restore %gs if needed (which is common)
26317@@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26318
26319 switch_fpu_finish(next_p, fpu);
26320
26321- this_cpu_write(current_task, next_p);
26322-
26323 return prev_p;
26324 }
26325
26326@@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26327 } while (count++ < 16);
26328 return 0;
26329 }
26330-
26331diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26332index 898d077..4c458ff 100644
26333--- a/arch/x86/kernel/process_64.c
26334+++ b/arch/x86/kernel/process_64.c
26335@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26336 struct pt_regs *childregs;
26337 struct task_struct *me = current;
26338
26339- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26340+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26341 childregs = task_pt_regs(p);
26342 p->thread.sp = (unsigned long) childregs;
26343 p->thread.usersp = me->thread.usersp;
26344+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26345 set_tsk_thread_flag(p, TIF_FORK);
26346 p->thread.fpu_counter = 0;
26347 p->thread.io_bitmap_ptr = NULL;
26348@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26349 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26350 savesegment(es, p->thread.es);
26351 savesegment(ds, p->thread.ds);
26352+ savesegment(ss, p->thread.ss);
26353+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26354 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26355
26356 if (unlikely(p->flags & PF_KTHREAD)) {
26357@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26358 struct thread_struct *prev = &prev_p->thread;
26359 struct thread_struct *next = &next_p->thread;
26360 int cpu = smp_processor_id();
26361- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26362+ struct tss_struct *tss = init_tss + cpu;
26363 unsigned fsindex, gsindex;
26364 fpu_switch_t fpu;
26365
26366@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26367 if (unlikely(next->ds | prev->ds))
26368 loadsegment(ds, next->ds);
26369
26370+ savesegment(ss, prev->ss);
26371+ if (unlikely(next->ss != prev->ss))
26372+ loadsegment(ss, next->ss);
26373
26374 /* We must save %fs and %gs before load_TLS() because
26375 * %fs and %gs may be cleared by load_TLS().
26376@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26377 prev->usersp = this_cpu_read(old_rsp);
26378 this_cpu_write(old_rsp, next->usersp);
26379 this_cpu_write(current_task, next_p);
26380+ this_cpu_write(current_tinfo, &next_p->tinfo);
26381
26382 /*
26383 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26384@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26385 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26386 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26387
26388- this_cpu_write(kernel_stack,
26389- (unsigned long)task_stack_page(next_p) +
26390- THREAD_SIZE - KERNEL_STACK_OFFSET);
26391+ this_cpu_write(kernel_stack, next->sp0);
26392
26393 /*
26394 * Now maybe reload the debug registers and handle I/O bitmaps
26395@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26396 if (!p || p == current || p->state == TASK_RUNNING)
26397 return 0;
26398 stack = (unsigned long)task_stack_page(p);
26399- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26400+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26401 return 0;
26402 fp = *(u64 *)(p->thread.sp);
26403 do {
26404- if (fp < (unsigned long)stack ||
26405- fp >= (unsigned long)stack+THREAD_SIZE)
26406+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26407 return 0;
26408 ip = *(u64 *)(fp+8);
26409 if (!in_sched_functions(ip))
26410diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26411index 678c0ad..2fc2a7b 100644
26412--- a/arch/x86/kernel/ptrace.c
26413+++ b/arch/x86/kernel/ptrace.c
26414@@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26415 unsigned long sp = (unsigned long)&regs->sp;
26416 u32 *prev_esp;
26417
26418- if (context == (sp & ~(THREAD_SIZE - 1)))
26419+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26420 return sp;
26421
26422- prev_esp = (u32 *)(context);
26423+ prev_esp = *(u32 **)(context);
26424 if (prev_esp)
26425 return (unsigned long)prev_esp;
26426
26427@@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26428 if (child->thread.gs != value)
26429 return do_arch_prctl(child, ARCH_SET_GS, value);
26430 return 0;
26431+
26432+ case offsetof(struct user_regs_struct,ip):
26433+ /*
26434+ * Protect against any attempt to set ip to an
26435+ * impossible address. There are dragons lurking if the
26436+ * address is noncanonical. (This explicitly allows
26437+ * setting ip to TASK_SIZE_MAX, because user code can do
26438+ * that all by itself by running off the end of its
26439+ * address space.
26440+ */
26441+ if (value > TASK_SIZE_MAX)
26442+ return -EIO;
26443+ break;
26444+
26445 #endif
26446 }
26447
26448@@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26449 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26450 {
26451 int i;
26452- int dr7 = 0;
26453+ unsigned long dr7 = 0;
26454 struct arch_hw_breakpoint *info;
26455
26456 for (i = 0; i < HBP_NUM; i++) {
26457@@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26458 unsigned long addr, unsigned long data)
26459 {
26460 int ret;
26461- unsigned long __user *datap = (unsigned long __user *)data;
26462+ unsigned long __user *datap = (__force unsigned long __user *)data;
26463
26464 switch (request) {
26465 /* read the word at location addr in the USER area. */
26466@@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26467 if ((int) addr < 0)
26468 return -EIO;
26469 ret = do_get_thread_area(child, addr,
26470- (struct user_desc __user *)data);
26471+ (__force struct user_desc __user *) data);
26472 break;
26473
26474 case PTRACE_SET_THREAD_AREA:
26475 if ((int) addr < 0)
26476 return -EIO;
26477 ret = do_set_thread_area(child, addr,
26478- (struct user_desc __user *)data, 0);
26479+ (__force struct user_desc __user *) data, 0);
26480 break;
26481 #endif
26482
26483@@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26484
26485 #ifdef CONFIG_X86_64
26486
26487-static struct user_regset x86_64_regsets[] __read_mostly = {
26488+static user_regset_no_const x86_64_regsets[] __read_only = {
26489 [REGSET_GENERAL] = {
26490 .core_note_type = NT_PRSTATUS,
26491 .n = sizeof(struct user_regs_struct) / sizeof(long),
26492@@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
26493 #endif /* CONFIG_X86_64 */
26494
26495 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26496-static struct user_regset x86_32_regsets[] __read_mostly = {
26497+static user_regset_no_const x86_32_regsets[] __read_only = {
26498 [REGSET_GENERAL] = {
26499 .core_note_type = NT_PRSTATUS,
26500 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26501@@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
26502 */
26503 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26504
26505-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26506+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26507 {
26508 #ifdef CONFIG_X86_64
26509 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26510@@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26511 memset(info, 0, sizeof(*info));
26512 info->si_signo = SIGTRAP;
26513 info->si_code = si_code;
26514- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26515+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26516 }
26517
26518 void user_single_step_siginfo(struct task_struct *tsk,
26519@@ -1450,6 +1464,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26520 # define IS_IA32 0
26521 #endif
26522
26523+#ifdef CONFIG_GRKERNSEC_SETXID
26524+extern void gr_delayed_cred_worker(void);
26525+#endif
26526+
26527 /*
26528 * We must return the syscall number to actually look up in the table.
26529 * This can be -1L to skip running any syscall at all.
26530@@ -1460,6 +1478,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26531
26532 user_exit();
26533
26534+#ifdef CONFIG_GRKERNSEC_SETXID
26535+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26536+ gr_delayed_cred_worker();
26537+#endif
26538+
26539 /*
26540 * If we stepped into a sysenter/syscall insn, it trapped in
26541 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26542@@ -1515,6 +1538,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26543 */
26544 user_exit();
26545
26546+#ifdef CONFIG_GRKERNSEC_SETXID
26547+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26548+ gr_delayed_cred_worker();
26549+#endif
26550+
26551 audit_syscall_exit(regs);
26552
26553 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26554diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26555index 2f355d2..e75ed0a 100644
26556--- a/arch/x86/kernel/pvclock.c
26557+++ b/arch/x86/kernel/pvclock.c
26558@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26559 reset_hung_task_detector();
26560 }
26561
26562-static atomic64_t last_value = ATOMIC64_INIT(0);
26563+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26564
26565 void pvclock_resume(void)
26566 {
26567- atomic64_set(&last_value, 0);
26568+ atomic64_set_unchecked(&last_value, 0);
26569 }
26570
26571 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26572@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26573 * updating at the same time, and one of them could be slightly behind,
26574 * making the assumption that last_value always go forward fail to hold.
26575 */
26576- last = atomic64_read(&last_value);
26577+ last = atomic64_read_unchecked(&last_value);
26578 do {
26579 if (ret < last)
26580 return last;
26581- last = atomic64_cmpxchg(&last_value, last, ret);
26582+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26583 } while (unlikely(last != ret));
26584
26585 return ret;
26586diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26587index 52b1157..c6e67c4 100644
26588--- a/arch/x86/kernel/reboot.c
26589+++ b/arch/x86/kernel/reboot.c
26590@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26591
26592 void __noreturn machine_real_restart(unsigned int type)
26593 {
26594+
26595+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26596+ struct desc_struct *gdt;
26597+#endif
26598+
26599 local_irq_disable();
26600
26601 /*
26602@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26603
26604 /* Jump to the identity-mapped low memory code */
26605 #ifdef CONFIG_X86_32
26606- asm volatile("jmpl *%0" : :
26607+
26608+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26609+ gdt = get_cpu_gdt_table(smp_processor_id());
26610+ pax_open_kernel();
26611+#ifdef CONFIG_PAX_MEMORY_UDEREF
26612+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26613+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26614+ loadsegment(ds, __KERNEL_DS);
26615+ loadsegment(es, __KERNEL_DS);
26616+ loadsegment(ss, __KERNEL_DS);
26617+#endif
26618+#ifdef CONFIG_PAX_KERNEXEC
26619+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26620+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26621+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26622+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26623+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26624+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26625+#endif
26626+ pax_close_kernel();
26627+#endif
26628+
26629+ asm volatile("ljmpl *%0" : :
26630 "rm" (real_mode_header->machine_real_restart_asm),
26631 "a" (type));
26632 #else
26633@@ -486,7 +513,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26634 * This means that this function can never return, it can misbehave
26635 * by not rebooting properly and hanging.
26636 */
26637-static void native_machine_emergency_restart(void)
26638+static void __noreturn native_machine_emergency_restart(void)
26639 {
26640 int i;
26641 int attempt = 0;
26642@@ -610,13 +637,13 @@ void native_machine_shutdown(void)
26643 #endif
26644 }
26645
26646-static void __machine_emergency_restart(int emergency)
26647+static void __noreturn __machine_emergency_restart(int emergency)
26648 {
26649 reboot_emergency = emergency;
26650 machine_ops.emergency_restart();
26651 }
26652
26653-static void native_machine_restart(char *__unused)
26654+static void __noreturn native_machine_restart(char *__unused)
26655 {
26656 pr_notice("machine restart\n");
26657
26658@@ -625,7 +652,7 @@ static void native_machine_restart(char *__unused)
26659 __machine_emergency_restart(0);
26660 }
26661
26662-static void native_machine_halt(void)
26663+static void __noreturn native_machine_halt(void)
26664 {
26665 /* Stop other cpus and apics */
26666 machine_shutdown();
26667@@ -635,7 +662,7 @@ static void native_machine_halt(void)
26668 stop_this_cpu(NULL);
26669 }
26670
26671-static void native_machine_power_off(void)
26672+static void __noreturn native_machine_power_off(void)
26673 {
26674 if (pm_power_off) {
26675 if (!reboot_force)
26676@@ -644,9 +671,10 @@ static void native_machine_power_off(void)
26677 }
26678 /* A fallback in case there is no PM info available */
26679 tboot_shutdown(TB_SHUTDOWN_HALT);
26680+ unreachable();
26681 }
26682
26683-struct machine_ops machine_ops = {
26684+struct machine_ops machine_ops __read_only = {
26685 .power_off = native_machine_power_off,
26686 .shutdown = native_machine_shutdown,
26687 .emergency_restart = native_machine_emergency_restart,
26688diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26689index c8e41e9..64049ef 100644
26690--- a/arch/x86/kernel/reboot_fixups_32.c
26691+++ b/arch/x86/kernel/reboot_fixups_32.c
26692@@ -57,7 +57,7 @@ struct device_fixup {
26693 unsigned int vendor;
26694 unsigned int device;
26695 void (*reboot_fixup)(struct pci_dev *);
26696-};
26697+} __do_const;
26698
26699 /*
26700 * PCI ids solely used for fixups_table go here
26701diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26702index 3fd2c69..a444264 100644
26703--- a/arch/x86/kernel/relocate_kernel_64.S
26704+++ b/arch/x86/kernel/relocate_kernel_64.S
26705@@ -96,8 +96,7 @@ relocate_kernel:
26706
26707 /* jump to identity mapped page */
26708 addq $(identity_mapped - relocate_kernel), %r8
26709- pushq %r8
26710- ret
26711+ jmp *%r8
26712
26713 identity_mapped:
26714 /* set return address to 0 if not preserving context */
26715diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26716index 09c76d2..7f33fc2 100644
26717--- a/arch/x86/kernel/setup.c
26718+++ b/arch/x86/kernel/setup.c
26719@@ -110,6 +110,7 @@
26720 #include <asm/mce.h>
26721 #include <asm/alternative.h>
26722 #include <asm/prom.h>
26723+#include <asm/boot.h>
26724
26725 /*
26726 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26727@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26728 #endif
26729
26730
26731-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26732-__visible unsigned long mmu_cr4_features;
26733+#ifdef CONFIG_X86_64
26734+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26735+#elif defined(CONFIG_X86_PAE)
26736+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26737 #else
26738-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26739+__visible unsigned long mmu_cr4_features __read_only;
26740 #endif
26741
26742+void set_in_cr4(unsigned long mask)
26743+{
26744+ unsigned long cr4 = read_cr4();
26745+
26746+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26747+ return;
26748+
26749+ pax_open_kernel();
26750+ mmu_cr4_features |= mask;
26751+ pax_close_kernel();
26752+
26753+ if (trampoline_cr4_features)
26754+ *trampoline_cr4_features = mmu_cr4_features;
26755+ cr4 |= mask;
26756+ write_cr4(cr4);
26757+}
26758+EXPORT_SYMBOL(set_in_cr4);
26759+
26760+void clear_in_cr4(unsigned long mask)
26761+{
26762+ unsigned long cr4 = read_cr4();
26763+
26764+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26765+ return;
26766+
26767+ pax_open_kernel();
26768+ mmu_cr4_features &= ~mask;
26769+ pax_close_kernel();
26770+
26771+ if (trampoline_cr4_features)
26772+ *trampoline_cr4_features = mmu_cr4_features;
26773+ cr4 &= ~mask;
26774+ write_cr4(cr4);
26775+}
26776+EXPORT_SYMBOL(clear_in_cr4);
26777+
26778 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26779 int bootloader_type, bootloader_version;
26780
26781@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
26782 * area (640->1Mb) as ram even though it is not.
26783 * take them out.
26784 */
26785- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26786+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26787
26788 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26789 }
26790@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
26791 /* called before trim_bios_range() to spare extra sanitize */
26792 static void __init e820_add_kernel_range(void)
26793 {
26794- u64 start = __pa_symbol(_text);
26795+ u64 start = __pa_symbol(ktla_ktva(_text));
26796 u64 size = __pa_symbol(_end) - start;
26797
26798 /*
26799@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
26800
26801 void __init setup_arch(char **cmdline_p)
26802 {
26803+#ifdef CONFIG_X86_32
26804+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26805+#else
26806 memblock_reserve(__pa_symbol(_text),
26807 (unsigned long)__bss_stop - (unsigned long)_text);
26808+#endif
26809
26810 early_reserve_initrd();
26811
26812@@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
26813
26814 if (!boot_params.hdr.root_flags)
26815 root_mountflags &= ~MS_RDONLY;
26816- init_mm.start_code = (unsigned long) _text;
26817- init_mm.end_code = (unsigned long) _etext;
26818+ init_mm.start_code = ktla_ktva((unsigned long) _text);
26819+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
26820 init_mm.end_data = (unsigned long) _edata;
26821 init_mm.brk = _brk_end;
26822
26823- code_resource.start = __pa_symbol(_text);
26824- code_resource.end = __pa_symbol(_etext)-1;
26825- data_resource.start = __pa_symbol(_etext);
26826+ code_resource.start = __pa_symbol(ktla_ktva(_text));
26827+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26828+ data_resource.start = __pa_symbol(_sdata);
26829 data_resource.end = __pa_symbol(_edata)-1;
26830 bss_resource.start = __pa_symbol(__bss_start);
26831 bss_resource.end = __pa_symbol(__bss_stop)-1;
26832diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26833index 5cdff03..80fa283 100644
26834--- a/arch/x86/kernel/setup_percpu.c
26835+++ b/arch/x86/kernel/setup_percpu.c
26836@@ -21,19 +21,17 @@
26837 #include <asm/cpu.h>
26838 #include <asm/stackprotector.h>
26839
26840-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26841+#ifdef CONFIG_SMP
26842+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26843 EXPORT_PER_CPU_SYMBOL(cpu_number);
26844+#endif
26845
26846-#ifdef CONFIG_X86_64
26847 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26848-#else
26849-#define BOOT_PERCPU_OFFSET 0
26850-#endif
26851
26852 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26853 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26854
26855-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26856+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26857 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26858 };
26859 EXPORT_SYMBOL(__per_cpu_offset);
26860@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26861 {
26862 #ifdef CONFIG_NEED_MULTIPLE_NODES
26863 pg_data_t *last = NULL;
26864- unsigned int cpu;
26865+ int cpu;
26866
26867 for_each_possible_cpu(cpu) {
26868 int node = early_cpu_to_node(cpu);
26869@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26870 {
26871 #ifdef CONFIG_X86_32
26872 struct desc_struct gdt;
26873+ unsigned long base = per_cpu_offset(cpu);
26874
26875- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26876- 0x2 | DESCTYPE_S, 0x8);
26877- gdt.s = 1;
26878+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26879+ 0x83 | DESCTYPE_S, 0xC);
26880 write_gdt_entry(get_cpu_gdt_table(cpu),
26881 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26882 #endif
26883@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26884 /* alrighty, percpu areas up and running */
26885 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26886 for_each_possible_cpu(cpu) {
26887+#ifdef CONFIG_CC_STACKPROTECTOR
26888+#ifdef CONFIG_X86_32
26889+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
26890+#endif
26891+#endif
26892 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26893 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26894 per_cpu(cpu_number, cpu) = cpu;
26895@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26896 */
26897 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26898 #endif
26899+#ifdef CONFIG_CC_STACKPROTECTOR
26900+#ifdef CONFIG_X86_32
26901+ if (!cpu)
26902+ per_cpu(stack_canary.canary, cpu) = canary;
26903+#endif
26904+#endif
26905 /*
26906 * Up to this point, the boot CPU has been using .init.data
26907 * area. Reload any changed state for the boot CPU.
26908diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26909index 9e5de68..16c53cb 100644
26910--- a/arch/x86/kernel/signal.c
26911+++ b/arch/x86/kernel/signal.c
26912@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26913 * Align the stack pointer according to the i386 ABI,
26914 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26915 */
26916- sp = ((sp + 4) & -16ul) - 4;
26917+ sp = ((sp - 12) & -16ul) - 4;
26918 #else /* !CONFIG_X86_32 */
26919 sp = round_down(sp, 16) - 8;
26920 #endif
26921@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26922 }
26923
26924 if (current->mm->context.vdso)
26925- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26926+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26927 else
26928- restorer = &frame->retcode;
26929+ restorer = (void __user *)&frame->retcode;
26930 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26931 restorer = ksig->ka.sa.sa_restorer;
26932
26933@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26934 * reasons and because gdb uses it as a signature to notice
26935 * signal handler stack frames.
26936 */
26937- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26938+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26939
26940 if (err)
26941 return -EFAULT;
26942@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26943 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26944
26945 /* Set up to return from userspace. */
26946- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26947+ if (current->mm->context.vdso)
26948+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26949+ else
26950+ restorer = (void __user *)&frame->retcode;
26951 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26952 restorer = ksig->ka.sa.sa_restorer;
26953 put_user_ex(restorer, &frame->pretcode);
26954@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26955 * reasons and because gdb uses it as a signature to notice
26956 * signal handler stack frames.
26957 */
26958- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26959+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26960 } put_user_catch(err);
26961
26962 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26963@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26964 {
26965 int usig = signr_convert(ksig->sig);
26966 sigset_t *set = sigmask_to_save();
26967- compat_sigset_t *cset = (compat_sigset_t *) set;
26968+ sigset_t sigcopy;
26969+ compat_sigset_t *cset;
26970+
26971+ sigcopy = *set;
26972+
26973+ cset = (compat_sigset_t *) &sigcopy;
26974
26975 /* Set up the stack frame */
26976 if (is_ia32_frame()) {
26977@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26978 } else if (is_x32_frame()) {
26979 return x32_setup_rt_frame(ksig, cset, regs);
26980 } else {
26981- return __setup_rt_frame(ksig->sig, ksig, set, regs);
26982+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26983 }
26984 }
26985
26986diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26987index be8e1bd..a3d93fa 100644
26988--- a/arch/x86/kernel/smp.c
26989+++ b/arch/x86/kernel/smp.c
26990@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26991
26992 __setup("nonmi_ipi", nonmi_ipi_setup);
26993
26994-struct smp_ops smp_ops = {
26995+struct smp_ops smp_ops __read_only = {
26996 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26997 .smp_prepare_cpus = native_smp_prepare_cpus,
26998 .smp_cpus_done = native_smp_cpus_done,
26999diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27000index ae2fd975..c0c8d10 100644
27001--- a/arch/x86/kernel/smpboot.c
27002+++ b/arch/x86/kernel/smpboot.c
27003@@ -230,14 +230,17 @@ static void notrace start_secondary(void *unused)
27004
27005 enable_start_cpu0 = 0;
27006
27007-#ifdef CONFIG_X86_32
27008+ /* otherwise gcc will move up smp_processor_id before the cpu_init */
27009+ barrier();
27010+
27011 /* switch away from the initial page table */
27012+#ifdef CONFIG_PAX_PER_CPU_PGD
27013+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27014+#else
27015 load_cr3(swapper_pg_dir);
27016+#endif
27017 __flush_tlb_all();
27018-#endif
27019
27020- /* otherwise gcc will move up smp_processor_id before the cpu_init */
27021- barrier();
27022 /*
27023 * Check TSC synchronization with the BP:
27024 */
27025@@ -757,8 +760,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27026 alternatives_enable_smp();
27027
27028 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27029- (THREAD_SIZE + task_stack_page(idle))) - 1);
27030+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27031 per_cpu(current_task, cpu) = idle;
27032+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
27033
27034 #ifdef CONFIG_X86_32
27035 /* Stack for startup_32 can be just as for start_secondary onwards */
27036@@ -767,10 +771,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27037 clear_tsk_thread_flag(idle, TIF_FORK);
27038 initial_gs = per_cpu_offset(cpu);
27039 #endif
27040- per_cpu(kernel_stack, cpu) =
27041- (unsigned long)task_stack_page(idle) -
27042- KERNEL_STACK_OFFSET + THREAD_SIZE;
27043+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27044+ pax_open_kernel();
27045 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27046+ pax_close_kernel();
27047 initial_code = (unsigned long)start_secondary;
27048 stack_start = idle->thread.sp;
27049
27050@@ -916,6 +920,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27051 /* the FPU context is blank, nobody can own it */
27052 __cpu_disable_lazy_restore(cpu);
27053
27054+#ifdef CONFIG_PAX_PER_CPU_PGD
27055+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27056+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27057+ KERNEL_PGD_PTRS);
27058+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27059+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27060+ KERNEL_PGD_PTRS);
27061+#endif
27062+
27063 err = do_boot_cpu(apicid, cpu, tidle);
27064 if (err) {
27065 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27066diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27067index 9b4d51d..5d28b58 100644
27068--- a/arch/x86/kernel/step.c
27069+++ b/arch/x86/kernel/step.c
27070@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27071 struct desc_struct *desc;
27072 unsigned long base;
27073
27074- seg &= ~7UL;
27075+ seg >>= 3;
27076
27077 mutex_lock(&child->mm->context.lock);
27078- if (unlikely((seg >> 3) >= child->mm->context.size))
27079+ if (unlikely(seg >= child->mm->context.size))
27080 addr = -1L; /* bogus selector, access would fault */
27081 else {
27082 desc = child->mm->context.ldt + seg;
27083@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27084 addr += base;
27085 }
27086 mutex_unlock(&child->mm->context.lock);
27087- }
27088+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27089+ addr = ktla_ktva(addr);
27090
27091 return addr;
27092 }
27093@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27094 unsigned char opcode[15];
27095 unsigned long addr = convert_ip_to_linear(child, regs);
27096
27097+ if (addr == -EINVAL)
27098+ return 0;
27099+
27100 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27101 for (i = 0; i < copied; i++) {
27102 switch (opcode[i]) {
27103diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27104new file mode 100644
27105index 0000000..5877189
27106--- /dev/null
27107+++ b/arch/x86/kernel/sys_i386_32.c
27108@@ -0,0 +1,189 @@
27109+/*
27110+ * This file contains various random system calls that
27111+ * have a non-standard calling sequence on the Linux/i386
27112+ * platform.
27113+ */
27114+
27115+#include <linux/errno.h>
27116+#include <linux/sched.h>
27117+#include <linux/mm.h>
27118+#include <linux/fs.h>
27119+#include <linux/smp.h>
27120+#include <linux/sem.h>
27121+#include <linux/msg.h>
27122+#include <linux/shm.h>
27123+#include <linux/stat.h>
27124+#include <linux/syscalls.h>
27125+#include <linux/mman.h>
27126+#include <linux/file.h>
27127+#include <linux/utsname.h>
27128+#include <linux/ipc.h>
27129+#include <linux/elf.h>
27130+
27131+#include <linux/uaccess.h>
27132+#include <linux/unistd.h>
27133+
27134+#include <asm/syscalls.h>
27135+
27136+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27137+{
27138+ unsigned long pax_task_size = TASK_SIZE;
27139+
27140+#ifdef CONFIG_PAX_SEGMEXEC
27141+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27142+ pax_task_size = SEGMEXEC_TASK_SIZE;
27143+#endif
27144+
27145+ if (flags & MAP_FIXED)
27146+ if (len > pax_task_size || addr > pax_task_size - len)
27147+ return -EINVAL;
27148+
27149+ return 0;
27150+}
27151+
27152+/*
27153+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27154+ */
27155+static unsigned long get_align_mask(void)
27156+{
27157+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27158+ return 0;
27159+
27160+ if (!(current->flags & PF_RANDOMIZE))
27161+ return 0;
27162+
27163+ return va_align.mask;
27164+}
27165+
27166+unsigned long
27167+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27168+ unsigned long len, unsigned long pgoff, unsigned long flags)
27169+{
27170+ struct mm_struct *mm = current->mm;
27171+ struct vm_area_struct *vma;
27172+ unsigned long pax_task_size = TASK_SIZE;
27173+ struct vm_unmapped_area_info info;
27174+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27175+
27176+#ifdef CONFIG_PAX_SEGMEXEC
27177+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27178+ pax_task_size = SEGMEXEC_TASK_SIZE;
27179+#endif
27180+
27181+ pax_task_size -= PAGE_SIZE;
27182+
27183+ if (len > pax_task_size)
27184+ return -ENOMEM;
27185+
27186+ if (flags & MAP_FIXED)
27187+ return addr;
27188+
27189+#ifdef CONFIG_PAX_RANDMMAP
27190+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27191+#endif
27192+
27193+ if (addr) {
27194+ addr = PAGE_ALIGN(addr);
27195+ if (pax_task_size - len >= addr) {
27196+ vma = find_vma(mm, addr);
27197+ if (check_heap_stack_gap(vma, addr, len, offset))
27198+ return addr;
27199+ }
27200+ }
27201+
27202+ info.flags = 0;
27203+ info.length = len;
27204+ info.align_mask = filp ? get_align_mask() : 0;
27205+ info.align_offset = pgoff << PAGE_SHIFT;
27206+ info.threadstack_offset = offset;
27207+
27208+#ifdef CONFIG_PAX_PAGEEXEC
27209+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27210+ info.low_limit = 0x00110000UL;
27211+ info.high_limit = mm->start_code;
27212+
27213+#ifdef CONFIG_PAX_RANDMMAP
27214+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27215+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27216+#endif
27217+
27218+ if (info.low_limit < info.high_limit) {
27219+ addr = vm_unmapped_area(&info);
27220+ if (!IS_ERR_VALUE(addr))
27221+ return addr;
27222+ }
27223+ } else
27224+#endif
27225+
27226+ info.low_limit = mm->mmap_base;
27227+ info.high_limit = pax_task_size;
27228+
27229+ return vm_unmapped_area(&info);
27230+}
27231+
27232+unsigned long
27233+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27234+ const unsigned long len, const unsigned long pgoff,
27235+ const unsigned long flags)
27236+{
27237+ struct vm_area_struct *vma;
27238+ struct mm_struct *mm = current->mm;
27239+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27240+ struct vm_unmapped_area_info info;
27241+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27242+
27243+#ifdef CONFIG_PAX_SEGMEXEC
27244+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27245+ pax_task_size = SEGMEXEC_TASK_SIZE;
27246+#endif
27247+
27248+ pax_task_size -= PAGE_SIZE;
27249+
27250+ /* requested length too big for entire address space */
27251+ if (len > pax_task_size)
27252+ return -ENOMEM;
27253+
27254+ if (flags & MAP_FIXED)
27255+ return addr;
27256+
27257+#ifdef CONFIG_PAX_PAGEEXEC
27258+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27259+ goto bottomup;
27260+#endif
27261+
27262+#ifdef CONFIG_PAX_RANDMMAP
27263+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27264+#endif
27265+
27266+ /* requesting a specific address */
27267+ if (addr) {
27268+ addr = PAGE_ALIGN(addr);
27269+ if (pax_task_size - len >= addr) {
27270+ vma = find_vma(mm, addr);
27271+ if (check_heap_stack_gap(vma, addr, len, offset))
27272+ return addr;
27273+ }
27274+ }
27275+
27276+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27277+ info.length = len;
27278+ info.low_limit = PAGE_SIZE;
27279+ info.high_limit = mm->mmap_base;
27280+ info.align_mask = filp ? get_align_mask() : 0;
27281+ info.align_offset = pgoff << PAGE_SHIFT;
27282+ info.threadstack_offset = offset;
27283+
27284+ addr = vm_unmapped_area(&info);
27285+ if (!(addr & ~PAGE_MASK))
27286+ return addr;
27287+ VM_BUG_ON(addr != -ENOMEM);
27288+
27289+bottomup:
27290+ /*
27291+ * A failed mmap() very likely causes application failure,
27292+ * so fall back to the bottom-up function here. This scenario
27293+ * can happen with large stack limits and large mmap()
27294+ * allocations.
27295+ */
27296+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27297+}
27298diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27299index 30277e2..5664a29 100644
27300--- a/arch/x86/kernel/sys_x86_64.c
27301+++ b/arch/x86/kernel/sys_x86_64.c
27302@@ -81,8 +81,8 @@ out:
27303 return error;
27304 }
27305
27306-static void find_start_end(unsigned long flags, unsigned long *begin,
27307- unsigned long *end)
27308+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27309+ unsigned long *begin, unsigned long *end)
27310 {
27311 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27312 unsigned long new_begin;
27313@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27314 *begin = new_begin;
27315 }
27316 } else {
27317- *begin = current->mm->mmap_legacy_base;
27318+ *begin = mm->mmap_legacy_base;
27319 *end = TASK_SIZE;
27320 }
27321 }
27322@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27323 struct vm_area_struct *vma;
27324 struct vm_unmapped_area_info info;
27325 unsigned long begin, end;
27326+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27327
27328 if (flags & MAP_FIXED)
27329 return addr;
27330
27331- find_start_end(flags, &begin, &end);
27332+ find_start_end(mm, flags, &begin, &end);
27333
27334 if (len > end)
27335 return -ENOMEM;
27336
27337+#ifdef CONFIG_PAX_RANDMMAP
27338+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27339+#endif
27340+
27341 if (addr) {
27342 addr = PAGE_ALIGN(addr);
27343 vma = find_vma(mm, addr);
27344- if (end - len >= addr &&
27345- (!vma || addr + len <= vma->vm_start))
27346+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27347 return addr;
27348 }
27349
27350@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27351 info.high_limit = end;
27352 info.align_mask = filp ? get_align_mask() : 0;
27353 info.align_offset = pgoff << PAGE_SHIFT;
27354+ info.threadstack_offset = offset;
27355 return vm_unmapped_area(&info);
27356 }
27357
27358@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27359 struct mm_struct *mm = current->mm;
27360 unsigned long addr = addr0;
27361 struct vm_unmapped_area_info info;
27362+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27363
27364 /* requested length too big for entire address space */
27365 if (len > TASK_SIZE)
27366@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27367 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27368 goto bottomup;
27369
27370+#ifdef CONFIG_PAX_RANDMMAP
27371+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27372+#endif
27373+
27374 /* requesting a specific address */
27375 if (addr) {
27376 addr = PAGE_ALIGN(addr);
27377 vma = find_vma(mm, addr);
27378- if (TASK_SIZE - len >= addr &&
27379- (!vma || addr + len <= vma->vm_start))
27380+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27381 return addr;
27382 }
27383
27384@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27385 info.high_limit = mm->mmap_base;
27386 info.align_mask = filp ? get_align_mask() : 0;
27387 info.align_offset = pgoff << PAGE_SHIFT;
27388+ info.threadstack_offset = offset;
27389 addr = vm_unmapped_area(&info);
27390 if (!(addr & ~PAGE_MASK))
27391 return addr;
27392diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27393index 91a4496..bb87552 100644
27394--- a/arch/x86/kernel/tboot.c
27395+++ b/arch/x86/kernel/tboot.c
27396@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27397
27398 void tboot_shutdown(u32 shutdown_type)
27399 {
27400- void (*shutdown)(void);
27401+ void (* __noreturn shutdown)(void);
27402
27403 if (!tboot_enabled())
27404 return;
27405@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27406
27407 switch_to_tboot_pt();
27408
27409- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27410+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27411 shutdown();
27412
27413 /* should not reach here */
27414@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27415 return -ENODEV;
27416 }
27417
27418-static atomic_t ap_wfs_count;
27419+static atomic_unchecked_t ap_wfs_count;
27420
27421 static int tboot_wait_for_aps(int num_aps)
27422 {
27423@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27424 {
27425 switch (action) {
27426 case CPU_DYING:
27427- atomic_inc(&ap_wfs_count);
27428+ atomic_inc_unchecked(&ap_wfs_count);
27429 if (num_online_cpus() == 1)
27430- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27431+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27432 return NOTIFY_BAD;
27433 break;
27434 }
27435@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27436
27437 tboot_create_trampoline();
27438
27439- atomic_set(&ap_wfs_count, 0);
27440+ atomic_set_unchecked(&ap_wfs_count, 0);
27441 register_hotcpu_notifier(&tboot_cpu_notifier);
27442
27443 #ifdef CONFIG_DEBUG_FS
27444diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27445index bf7ef5c..59d0ac9 100644
27446--- a/arch/x86/kernel/time.c
27447+++ b/arch/x86/kernel/time.c
27448@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27449 {
27450 unsigned long pc = instruction_pointer(regs);
27451
27452- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27453+ if (!user_mode(regs) && in_lock_functions(pc)) {
27454 #ifdef CONFIG_FRAME_POINTER
27455- return *(unsigned long *)(regs->bp + sizeof(long));
27456+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27457 #else
27458 unsigned long *sp =
27459 (unsigned long *)kernel_stack_pointer(regs);
27460@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27461 * or above a saved flags. Eflags has bits 22-31 zero,
27462 * kernel addresses don't.
27463 */
27464+
27465+#ifdef CONFIG_PAX_KERNEXEC
27466+ return ktla_ktva(sp[0]);
27467+#else
27468 if (sp[0] >> 22)
27469 return sp[0];
27470 if (sp[1] >> 22)
27471 return sp[1];
27472 #endif
27473+
27474+#endif
27475 }
27476 return pc;
27477 }
27478diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27479index f7fec09..9991981 100644
27480--- a/arch/x86/kernel/tls.c
27481+++ b/arch/x86/kernel/tls.c
27482@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27483 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27484 return -EINVAL;
27485
27486+#ifdef CONFIG_PAX_SEGMEXEC
27487+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27488+ return -EINVAL;
27489+#endif
27490+
27491 set_tls_desc(p, idx, &info, 1);
27492
27493 return 0;
27494@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27495
27496 if (kbuf)
27497 info = kbuf;
27498- else if (__copy_from_user(infobuf, ubuf, count))
27499+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27500 return -EFAULT;
27501 else
27502 info = infobuf;
27503diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27504index 1c113db..287b42e 100644
27505--- a/arch/x86/kernel/tracepoint.c
27506+++ b/arch/x86/kernel/tracepoint.c
27507@@ -9,11 +9,11 @@
27508 #include <linux/atomic.h>
27509
27510 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27511-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27512+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27513 (unsigned long) trace_idt_table };
27514
27515 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27516-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27517+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27518
27519 static int trace_irq_vector_refcount;
27520 static DEFINE_MUTEX(irq_vector_mutex);
27521diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27522index f73b5d4..0adcc9a 100644
27523--- a/arch/x86/kernel/traps.c
27524+++ b/arch/x86/kernel/traps.c
27525@@ -66,7 +66,7 @@
27526 #include <asm/proto.h>
27527
27528 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27529-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27530+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27531 #else
27532 #include <asm/processor-flags.h>
27533 #include <asm/setup.h>
27534@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27535 #endif
27536
27537 /* Must be page-aligned because the real IDT is used in a fixmap. */
27538-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27539+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27540
27541 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27542 EXPORT_SYMBOL_GPL(used_vectors);
27543@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27544 }
27545
27546 static int __kprobes
27547-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27548+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27549 struct pt_regs *regs, long error_code)
27550 {
27551 #ifdef CONFIG_X86_32
27552- if (regs->flags & X86_VM_MASK) {
27553+ if (v8086_mode(regs)) {
27554 /*
27555 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27556 * On nmi (interrupt 2), do_trap should not be called.
27557@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27558 return -1;
27559 }
27560 #endif
27561- if (!user_mode(regs)) {
27562+ if (!user_mode_novm(regs)) {
27563 if (!fixup_exception(regs)) {
27564 tsk->thread.error_code = error_code;
27565 tsk->thread.trap_nr = trapnr;
27566+
27567+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27568+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27569+ str = "PAX: suspicious stack segment fault";
27570+#endif
27571+
27572 die(str, regs, error_code);
27573 }
27574+
27575+#ifdef CONFIG_PAX_REFCOUNT
27576+ if (trapnr == X86_TRAP_OF)
27577+ pax_report_refcount_overflow(regs);
27578+#endif
27579+
27580 return 0;
27581 }
27582
27583@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27584 }
27585
27586 static void __kprobes
27587-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27588+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27589 long error_code, siginfo_t *info)
27590 {
27591 struct task_struct *tsk = current;
27592@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27593 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27594 printk_ratelimit()) {
27595 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27596- tsk->comm, tsk->pid, str,
27597+ tsk->comm, task_pid_nr(tsk), str,
27598 regs->ip, regs->sp, error_code);
27599 print_vma_addr(" in ", regs->ip);
27600 pr_cont("\n");
27601@@ -251,6 +263,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
27602 tsk->thread.error_code = error_code;
27603 tsk->thread.trap_nr = X86_TRAP_DF;
27604
27605+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
27606+ if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
27607+ die("grsec: kernel stack overflow detected", regs, error_code);
27608+#endif
27609+
27610 #ifdef CONFIG_DOUBLEFAULT
27611 df_debug(regs, error_code);
27612 #endif
27613@@ -273,7 +290,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27614 conditional_sti(regs);
27615
27616 #ifdef CONFIG_X86_32
27617- if (regs->flags & X86_VM_MASK) {
27618+ if (v8086_mode(regs)) {
27619 local_irq_enable();
27620 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27621 goto exit;
27622@@ -281,18 +298,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27623 #endif
27624
27625 tsk = current;
27626- if (!user_mode(regs)) {
27627+ if (!user_mode_novm(regs)) {
27628 if (fixup_exception(regs))
27629 goto exit;
27630
27631 tsk->thread.error_code = error_code;
27632 tsk->thread.trap_nr = X86_TRAP_GP;
27633 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27634- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27635+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27636+
27637+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27638+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27639+ die("PAX: suspicious general protection fault", regs, error_code);
27640+ else
27641+#endif
27642+
27643 die("general protection fault", regs, error_code);
27644+ }
27645 goto exit;
27646 }
27647
27648+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27649+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27650+ struct mm_struct *mm = tsk->mm;
27651+ unsigned long limit;
27652+
27653+ down_write(&mm->mmap_sem);
27654+ limit = mm->context.user_cs_limit;
27655+ if (limit < TASK_SIZE) {
27656+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27657+ up_write(&mm->mmap_sem);
27658+ return;
27659+ }
27660+ up_write(&mm->mmap_sem);
27661+ }
27662+#endif
27663+
27664 tsk->thread.error_code = error_code;
27665 tsk->thread.trap_nr = X86_TRAP_GP;
27666
27667@@ -453,7 +494,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27668 /* It's safe to allow irq's after DR6 has been saved */
27669 preempt_conditional_sti(regs);
27670
27671- if (regs->flags & X86_VM_MASK) {
27672+ if (v8086_mode(regs)) {
27673 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27674 X86_TRAP_DB);
27675 preempt_conditional_cli(regs);
27676@@ -468,7 +509,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27677 * We already checked v86 mode above, so we can check for kernel mode
27678 * by just checking the CPL of CS.
27679 */
27680- if ((dr6 & DR_STEP) && !user_mode(regs)) {
27681+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27682 tsk->thread.debugreg6 &= ~DR_STEP;
27683 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27684 regs->flags &= ~X86_EFLAGS_TF;
27685@@ -500,7 +541,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27686 return;
27687 conditional_sti(regs);
27688
27689- if (!user_mode_vm(regs))
27690+ if (!user_mode(regs))
27691 {
27692 if (!fixup_exception(regs)) {
27693 task->thread.error_code = error_code;
27694diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27695index 57e5ce1..20b0040 100644
27696--- a/arch/x86/kernel/tsc.c
27697+++ b/arch/x86/kernel/tsc.c
27698@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27699 */
27700 smp_wmb();
27701
27702- ACCESS_ONCE(c2n->head) = data;
27703+ ACCESS_ONCE_RW(c2n->head) = data;
27704 }
27705
27706 /*
27707diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27708index 2ed8459..7cf329f 100644
27709--- a/arch/x86/kernel/uprobes.c
27710+++ b/arch/x86/kernel/uprobes.c
27711@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27712 int ret = NOTIFY_DONE;
27713
27714 /* We are only interested in userspace traps */
27715- if (regs && !user_mode_vm(regs))
27716+ if (regs && !user_mode(regs))
27717 return NOTIFY_DONE;
27718
27719 switch (val) {
27720@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27721
27722 if (ncopied != rasize) {
27723 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27724- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27725+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27726
27727 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27728 }
27729diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27730index b9242ba..50c5edd 100644
27731--- a/arch/x86/kernel/verify_cpu.S
27732+++ b/arch/x86/kernel/verify_cpu.S
27733@@ -20,6 +20,7 @@
27734 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27735 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27736 * arch/x86/kernel/head_32.S: processor startup
27737+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27738 *
27739 * verify_cpu, returns the status of longmode and SSE in register %eax.
27740 * 0: Success 1: Failure
27741diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27742index e8edcf5..27f9344 100644
27743--- a/arch/x86/kernel/vm86_32.c
27744+++ b/arch/x86/kernel/vm86_32.c
27745@@ -44,6 +44,7 @@
27746 #include <linux/ptrace.h>
27747 #include <linux/audit.h>
27748 #include <linux/stddef.h>
27749+#include <linux/grsecurity.h>
27750
27751 #include <asm/uaccess.h>
27752 #include <asm/io.h>
27753@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27754 do_exit(SIGSEGV);
27755 }
27756
27757- tss = &per_cpu(init_tss, get_cpu());
27758+ tss = init_tss + get_cpu();
27759 current->thread.sp0 = current->thread.saved_sp0;
27760 current->thread.sysenter_cs = __KERNEL_CS;
27761 load_sp0(tss, &current->thread);
27762@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27763
27764 if (tsk->thread.saved_sp0)
27765 return -EPERM;
27766+
27767+#ifdef CONFIG_GRKERNSEC_VM86
27768+ if (!capable(CAP_SYS_RAWIO)) {
27769+ gr_handle_vm86();
27770+ return -EPERM;
27771+ }
27772+#endif
27773+
27774 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27775 offsetof(struct kernel_vm86_struct, vm86plus) -
27776 sizeof(info.regs));
27777@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27778 int tmp;
27779 struct vm86plus_struct __user *v86;
27780
27781+#ifdef CONFIG_GRKERNSEC_VM86
27782+ if (!capable(CAP_SYS_RAWIO)) {
27783+ gr_handle_vm86();
27784+ return -EPERM;
27785+ }
27786+#endif
27787+
27788 tsk = current;
27789 switch (cmd) {
27790 case VM86_REQUEST_IRQ:
27791@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27792 tsk->thread.saved_fs = info->regs32->fs;
27793 tsk->thread.saved_gs = get_user_gs(info->regs32);
27794
27795- tss = &per_cpu(init_tss, get_cpu());
27796+ tss = init_tss + get_cpu();
27797 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27798 if (cpu_has_sep)
27799 tsk->thread.sysenter_cs = 0;
27800@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27801 goto cannot_handle;
27802 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27803 goto cannot_handle;
27804- intr_ptr = (unsigned long __user *) (i << 2);
27805+ intr_ptr = (__force unsigned long __user *) (i << 2);
27806 if (get_user(segoffs, intr_ptr))
27807 goto cannot_handle;
27808 if ((segoffs >> 16) == BIOSSEG)
27809diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27810index 49edf2d..c0d1362 100644
27811--- a/arch/x86/kernel/vmlinux.lds.S
27812+++ b/arch/x86/kernel/vmlinux.lds.S
27813@@ -26,6 +26,13 @@
27814 #include <asm/page_types.h>
27815 #include <asm/cache.h>
27816 #include <asm/boot.h>
27817+#include <asm/segment.h>
27818+
27819+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27820+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27821+#else
27822+#define __KERNEL_TEXT_OFFSET 0
27823+#endif
27824
27825 #undef i386 /* in case the preprocessor is a 32bit one */
27826
27827@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27828
27829 PHDRS {
27830 text PT_LOAD FLAGS(5); /* R_E */
27831+#ifdef CONFIG_X86_32
27832+ module PT_LOAD FLAGS(5); /* R_E */
27833+#endif
27834+#ifdef CONFIG_XEN
27835+ rodata PT_LOAD FLAGS(5); /* R_E */
27836+#else
27837+ rodata PT_LOAD FLAGS(4); /* R__ */
27838+#endif
27839 data PT_LOAD FLAGS(6); /* RW_ */
27840-#ifdef CONFIG_X86_64
27841+ init.begin PT_LOAD FLAGS(6); /* RW_ */
27842 #ifdef CONFIG_SMP
27843 percpu PT_LOAD FLAGS(6); /* RW_ */
27844 #endif
27845+ text.init PT_LOAD FLAGS(5); /* R_E */
27846+ text.exit PT_LOAD FLAGS(5); /* R_E */
27847 init PT_LOAD FLAGS(7); /* RWE */
27848-#endif
27849 note PT_NOTE FLAGS(0); /* ___ */
27850 }
27851
27852 SECTIONS
27853 {
27854 #ifdef CONFIG_X86_32
27855- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27856- phys_startup_32 = startup_32 - LOAD_OFFSET;
27857+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27858 #else
27859- . = __START_KERNEL;
27860- phys_startup_64 = startup_64 - LOAD_OFFSET;
27861+ . = __START_KERNEL;
27862 #endif
27863
27864 /* Text and read-only data */
27865- .text : AT(ADDR(.text) - LOAD_OFFSET) {
27866- _text = .;
27867+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27868 /* bootstrapping code */
27869+#ifdef CONFIG_X86_32
27870+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27871+#else
27872+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27873+#endif
27874+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27875+ _text = .;
27876 HEAD_TEXT
27877 . = ALIGN(8);
27878 _stext = .;
27879@@ -104,13 +124,47 @@ SECTIONS
27880 IRQENTRY_TEXT
27881 *(.fixup)
27882 *(.gnu.warning)
27883- /* End of text section */
27884- _etext = .;
27885 } :text = 0x9090
27886
27887- NOTES :text :note
27888+ . += __KERNEL_TEXT_OFFSET;
27889
27890- EXCEPTION_TABLE(16) :text = 0x9090
27891+#ifdef CONFIG_X86_32
27892+ . = ALIGN(PAGE_SIZE);
27893+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27894+
27895+#ifdef CONFIG_PAX_KERNEXEC
27896+ MODULES_EXEC_VADDR = .;
27897+ BYTE(0)
27898+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27899+ . = ALIGN(HPAGE_SIZE) - 1;
27900+ MODULES_EXEC_END = .;
27901+#endif
27902+
27903+ } :module
27904+#endif
27905+
27906+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27907+ /* End of text section */
27908+ BYTE(0)
27909+ _etext = . - __KERNEL_TEXT_OFFSET;
27910+ }
27911+
27912+#ifdef CONFIG_X86_32
27913+ . = ALIGN(PAGE_SIZE);
27914+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27915+ . = ALIGN(PAGE_SIZE);
27916+ *(.empty_zero_page)
27917+ *(.initial_pg_fixmap)
27918+ *(.initial_pg_pmd)
27919+ *(.initial_page_table)
27920+ *(.swapper_pg_dir)
27921+ } :rodata
27922+#endif
27923+
27924+ . = ALIGN(PAGE_SIZE);
27925+ NOTES :rodata :note
27926+
27927+ EXCEPTION_TABLE(16) :rodata
27928
27929 #if defined(CONFIG_DEBUG_RODATA)
27930 /* .text should occupy whole number of pages */
27931@@ -122,16 +176,20 @@ SECTIONS
27932
27933 /* Data */
27934 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27935+
27936+#ifdef CONFIG_PAX_KERNEXEC
27937+ . = ALIGN(HPAGE_SIZE);
27938+#else
27939+ . = ALIGN(PAGE_SIZE);
27940+#endif
27941+
27942 /* Start of data section */
27943 _sdata = .;
27944
27945 /* init_task */
27946 INIT_TASK_DATA(THREAD_SIZE)
27947
27948-#ifdef CONFIG_X86_32
27949- /* 32 bit has nosave before _edata */
27950 NOSAVE_DATA
27951-#endif
27952
27953 PAGE_ALIGNED_DATA(PAGE_SIZE)
27954
27955@@ -174,12 +232,19 @@ SECTIONS
27956 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
27957
27958 /* Init code and data - will be freed after init */
27959- . = ALIGN(PAGE_SIZE);
27960 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27961+ BYTE(0)
27962+
27963+#ifdef CONFIG_PAX_KERNEXEC
27964+ . = ALIGN(HPAGE_SIZE);
27965+#else
27966+ . = ALIGN(PAGE_SIZE);
27967+#endif
27968+
27969 __init_begin = .; /* paired with __init_end */
27970- }
27971+ } :init.begin
27972
27973-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27974+#ifdef CONFIG_SMP
27975 /*
27976 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27977 * output PHDR, so the next output section - .init.text - should
27978@@ -188,12 +253,27 @@ SECTIONS
27979 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27980 #endif
27981
27982- INIT_TEXT_SECTION(PAGE_SIZE)
27983-#ifdef CONFIG_X86_64
27984- :init
27985-#endif
27986+ . = ALIGN(PAGE_SIZE);
27987+ init_begin = .;
27988+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27989+ VMLINUX_SYMBOL(_sinittext) = .;
27990+ INIT_TEXT
27991+ VMLINUX_SYMBOL(_einittext) = .;
27992+ . = ALIGN(PAGE_SIZE);
27993+ } :text.init
27994
27995- INIT_DATA_SECTION(16)
27996+ /*
27997+ * .exit.text is discard at runtime, not link time, to deal with
27998+ * references from .altinstructions and .eh_frame
27999+ */
28000+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28001+ EXIT_TEXT
28002+ . = ALIGN(16);
28003+ } :text.exit
28004+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28005+
28006+ . = ALIGN(PAGE_SIZE);
28007+ INIT_DATA_SECTION(16) :init
28008
28009 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28010 __x86_cpu_dev_start = .;
28011@@ -264,19 +344,12 @@ SECTIONS
28012 }
28013
28014 . = ALIGN(8);
28015- /*
28016- * .exit.text is discard at runtime, not link time, to deal with
28017- * references from .altinstructions and .eh_frame
28018- */
28019- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28020- EXIT_TEXT
28021- }
28022
28023 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28024 EXIT_DATA
28025 }
28026
28027-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28028+#ifndef CONFIG_SMP
28029 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28030 #endif
28031
28032@@ -295,16 +368,10 @@ SECTIONS
28033 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28034 __smp_locks = .;
28035 *(.smp_locks)
28036- . = ALIGN(PAGE_SIZE);
28037 __smp_locks_end = .;
28038+ . = ALIGN(PAGE_SIZE);
28039 }
28040
28041-#ifdef CONFIG_X86_64
28042- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28043- NOSAVE_DATA
28044- }
28045-#endif
28046-
28047 /* BSS */
28048 . = ALIGN(PAGE_SIZE);
28049 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28050@@ -320,6 +387,7 @@ SECTIONS
28051 __brk_base = .;
28052 . += 64 * 1024; /* 64k alignment slop space */
28053 *(.brk_reservation) /* areas brk users have reserved */
28054+ . = ALIGN(HPAGE_SIZE);
28055 __brk_limit = .;
28056 }
28057
28058@@ -346,13 +414,12 @@ SECTIONS
28059 * for the boot processor.
28060 */
28061 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28062-INIT_PER_CPU(gdt_page);
28063 INIT_PER_CPU(irq_stack_union);
28064
28065 /*
28066 * Build-time check on the image size:
28067 */
28068-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28069+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28070 "kernel image bigger than KERNEL_IMAGE_SIZE");
28071
28072 #ifdef CONFIG_SMP
28073diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28074index 8b3b3eb..9395aa9 100644
28075--- a/arch/x86/kernel/vsyscall_64.c
28076+++ b/arch/x86/kernel/vsyscall_64.c
28077@@ -54,15 +54,13 @@
28078
28079 DEFINE_VVAR(int, vgetcpu_mode);
28080
28081-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28082+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28083
28084 static int __init vsyscall_setup(char *str)
28085 {
28086 if (str) {
28087 if (!strcmp("emulate", str))
28088 vsyscall_mode = EMULATE;
28089- else if (!strcmp("native", str))
28090- vsyscall_mode = NATIVE;
28091 else if (!strcmp("none", str))
28092 vsyscall_mode = NONE;
28093 else
28094@@ -279,8 +277,7 @@ do_ret:
28095 return true;
28096
28097 sigsegv:
28098- force_sig(SIGSEGV, current);
28099- return true;
28100+ do_group_exit(SIGKILL);
28101 }
28102
28103 /*
28104@@ -332,10 +329,7 @@ void __init map_vsyscall(void)
28105 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28106 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
28107
28108- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
28109- vsyscall_mode == NATIVE
28110- ? PAGE_KERNEL_VSYSCALL
28111- : PAGE_KERNEL_VVAR);
28112+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28113 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
28114 (unsigned long)VSYSCALL_START);
28115
28116diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28117index 04068192..4d75aa6 100644
28118--- a/arch/x86/kernel/x8664_ksyms_64.c
28119+++ b/arch/x86/kernel/x8664_ksyms_64.c
28120@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28121 EXPORT_SYMBOL(copy_user_generic_unrolled);
28122 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28123 EXPORT_SYMBOL(__copy_user_nocache);
28124-EXPORT_SYMBOL(_copy_from_user);
28125-EXPORT_SYMBOL(_copy_to_user);
28126
28127 EXPORT_SYMBOL(copy_page);
28128 EXPORT_SYMBOL(clear_page);
28129@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28130 EXPORT_SYMBOL(___preempt_schedule_context);
28131 #endif
28132 #endif
28133+
28134+#ifdef CONFIG_PAX_PER_CPU_PGD
28135+EXPORT_SYMBOL(cpu_pgd);
28136+#endif
28137diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28138index e48b674..a451dd9 100644
28139--- a/arch/x86/kernel/x86_init.c
28140+++ b/arch/x86/kernel/x86_init.c
28141@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28142 static void default_nmi_init(void) { };
28143 static int default_i8042_detect(void) { return 1; };
28144
28145-struct x86_platform_ops x86_platform = {
28146+struct x86_platform_ops x86_platform __read_only = {
28147 .calibrate_tsc = native_calibrate_tsc,
28148 .get_wallclock = mach_get_cmos_time,
28149 .set_wallclock = mach_set_rtc_mmss,
28150@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28151 EXPORT_SYMBOL_GPL(x86_platform);
28152
28153 #if defined(CONFIG_PCI_MSI)
28154-struct x86_msi_ops x86_msi = {
28155+struct x86_msi_ops x86_msi __read_only = {
28156 .setup_msi_irqs = native_setup_msi_irqs,
28157 .compose_msi_msg = native_compose_msi_msg,
28158 .teardown_msi_irq = native_teardown_msi_irq,
28159@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28160 }
28161 #endif
28162
28163-struct x86_io_apic_ops x86_io_apic_ops = {
28164+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28165 .init = native_io_apic_init_mappings,
28166 .read = native_io_apic_read,
28167 .write = native_io_apic_write,
28168diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28169index a4b451c..8dfe1ad 100644
28170--- a/arch/x86/kernel/xsave.c
28171+++ b/arch/x86/kernel/xsave.c
28172@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28173
28174 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28175 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28176- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28177+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28178
28179 if (!use_xsave())
28180 return err;
28181
28182- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28183+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28184
28185 /*
28186 * Read the xstate_bv which we copied (directly from the cpu or
28187 * from the state in task struct) to the user buffers.
28188 */
28189- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28190+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28191
28192 /*
28193 * For legacy compatible, we always set FP/SSE bits in the bit
28194@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28195 */
28196 xstate_bv |= XSTATE_FPSSE;
28197
28198- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28199+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28200
28201 return err;
28202 }
28203@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28204 {
28205 int err;
28206
28207+ buf = (struct xsave_struct __user *)____m(buf);
28208 if (use_xsave())
28209 err = xsave_user(buf);
28210 else if (use_fxsr())
28211@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28212 */
28213 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28214 {
28215+ buf = (void __user *)____m(buf);
28216 if (use_xsave()) {
28217 if ((unsigned long)buf % 64 || fx_only) {
28218 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28219diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28220index f47a104..5ce59a8 100644
28221--- a/arch/x86/kvm/cpuid.c
28222+++ b/arch/x86/kvm/cpuid.c
28223@@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28224 struct kvm_cpuid2 *cpuid,
28225 struct kvm_cpuid_entry2 __user *entries)
28226 {
28227- int r;
28228+ int r, i;
28229
28230 r = -E2BIG;
28231 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28232 goto out;
28233 r = -EFAULT;
28234- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28235- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28236+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28237 goto out;
28238+ for (i = 0; i < cpuid->nent; ++i) {
28239+ struct kvm_cpuid_entry2 cpuid_entry;
28240+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28241+ goto out;
28242+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28243+ }
28244 vcpu->arch.cpuid_nent = cpuid->nent;
28245 kvm_apic_set_version(vcpu);
28246 kvm_x86_ops->cpuid_update(vcpu);
28247@@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28248 struct kvm_cpuid2 *cpuid,
28249 struct kvm_cpuid_entry2 __user *entries)
28250 {
28251- int r;
28252+ int r, i;
28253
28254 r = -E2BIG;
28255 if (cpuid->nent < vcpu->arch.cpuid_nent)
28256 goto out;
28257 r = -EFAULT;
28258- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28259- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28260+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28261 goto out;
28262+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28263+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28264+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28265+ goto out;
28266+ }
28267 return 0;
28268
28269 out:
28270diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28271index 0069118..c28ec0a 100644
28272--- a/arch/x86/kvm/lapic.c
28273+++ b/arch/x86/kvm/lapic.c
28274@@ -55,7 +55,7 @@
28275 #define APIC_BUS_CYCLE_NS 1
28276
28277 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28278-#define apic_debug(fmt, arg...)
28279+#define apic_debug(fmt, arg...) do {} while (0)
28280
28281 #define APIC_LVT_NUM 6
28282 /* 14 is the version for Xeon and Pentium 8.4.8*/
28283diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28284index 123efd3..ad7726e 100644
28285--- a/arch/x86/kvm/paging_tmpl.h
28286+++ b/arch/x86/kvm/paging_tmpl.h
28287@@ -331,7 +331,7 @@ retry_walk:
28288 if (unlikely(kvm_is_error_hva(host_addr)))
28289 goto error;
28290
28291- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28292+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28293 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28294 goto error;
28295 walker->ptep_user[walker->level - 1] = ptep_user;
28296diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28297index 7f4f9c2..67b1db0 100644
28298--- a/arch/x86/kvm/svm.c
28299+++ b/arch/x86/kvm/svm.c
28300@@ -3535,7 +3535,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28301 int cpu = raw_smp_processor_id();
28302
28303 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28304+
28305+ pax_open_kernel();
28306 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28307+ pax_close_kernel();
28308+
28309 load_TR_desc();
28310 }
28311
28312@@ -3936,6 +3940,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28313 #endif
28314 #endif
28315
28316+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28317+ __set_fs(current_thread_info()->addr_limit);
28318+#endif
28319+
28320 reload_tss(vcpu);
28321
28322 local_irq_disable();
28323diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28324index 138ceff..2e584f0 100644
28325--- a/arch/x86/kvm/vmx.c
28326+++ b/arch/x86/kvm/vmx.c
28327@@ -1339,12 +1339,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28328 #endif
28329 }
28330
28331-static void vmcs_clear_bits(unsigned long field, u32 mask)
28332+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28333 {
28334 vmcs_writel(field, vmcs_readl(field) & ~mask);
28335 }
28336
28337-static void vmcs_set_bits(unsigned long field, u32 mask)
28338+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28339 {
28340 vmcs_writel(field, vmcs_readl(field) | mask);
28341 }
28342@@ -1604,7 +1604,11 @@ static void reload_tss(void)
28343 struct desc_struct *descs;
28344
28345 descs = (void *)gdt->address;
28346+
28347+ pax_open_kernel();
28348 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28349+ pax_close_kernel();
28350+
28351 load_TR_desc();
28352 }
28353
28354@@ -1832,6 +1836,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28355 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28356 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28357
28358+#ifdef CONFIG_PAX_PER_CPU_PGD
28359+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28360+#endif
28361+
28362 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28363 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28364 vmx->loaded_vmcs->cpu = cpu;
28365@@ -2121,7 +2129,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28366 * reads and returns guest's timestamp counter "register"
28367 * guest_tsc = host_tsc + tsc_offset -- 21.3
28368 */
28369-static u64 guest_read_tsc(void)
28370+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28371 {
28372 u64 host_tsc, tsc_offset;
28373
28374@@ -3093,8 +3101,11 @@ static __init int hardware_setup(void)
28375 if (!cpu_has_vmx_flexpriority())
28376 flexpriority_enabled = 0;
28377
28378- if (!cpu_has_vmx_tpr_shadow())
28379- kvm_x86_ops->update_cr8_intercept = NULL;
28380+ if (!cpu_has_vmx_tpr_shadow()) {
28381+ pax_open_kernel();
28382+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28383+ pax_close_kernel();
28384+ }
28385
28386 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28387 kvm_disable_largepages();
28388@@ -3105,13 +3116,15 @@ static __init int hardware_setup(void)
28389 if (!cpu_has_vmx_apicv())
28390 enable_apicv = 0;
28391
28392+ pax_open_kernel();
28393 if (enable_apicv)
28394- kvm_x86_ops->update_cr8_intercept = NULL;
28395+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28396 else {
28397- kvm_x86_ops->hwapic_irr_update = NULL;
28398- kvm_x86_ops->deliver_posted_interrupt = NULL;
28399- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28400+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28401+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28402+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28403 }
28404+ pax_close_kernel();
28405
28406 if (nested)
28407 nested_vmx_setup_ctls_msrs();
28408@@ -4235,7 +4248,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28409
28410 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28411 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28412+
28413+#ifndef CONFIG_PAX_PER_CPU_PGD
28414 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28415+#endif
28416
28417 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28418 #ifdef CONFIG_X86_64
28419@@ -4257,7 +4273,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28420 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28421 vmx->host_idt_base = dt.address;
28422
28423- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28424+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28425
28426 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28427 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28428@@ -7333,6 +7349,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28429 "jmp 2f \n\t"
28430 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28431 "2: "
28432+
28433+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28434+ "ljmp %[cs],$3f\n\t"
28435+ "3: "
28436+#endif
28437+
28438 /* Save guest registers, load host registers, keep flags */
28439 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28440 "pop %0 \n\t"
28441@@ -7385,6 +7407,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28442 #endif
28443 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28444 [wordsize]"i"(sizeof(ulong))
28445+
28446+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28447+ ,[cs]"i"(__KERNEL_CS)
28448+#endif
28449+
28450 : "cc", "memory"
28451 #ifdef CONFIG_X86_64
28452 , "rax", "rbx", "rdi", "rsi"
28453@@ -7398,7 +7425,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28454 if (debugctlmsr)
28455 update_debugctlmsr(debugctlmsr);
28456
28457-#ifndef CONFIG_X86_64
28458+#ifdef CONFIG_X86_32
28459 /*
28460 * The sysexit path does not restore ds/es, so we must set them to
28461 * a reasonable value ourselves.
28462@@ -7407,8 +7434,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28463 * may be executed in interrupt context, which saves and restore segments
28464 * around it, nullifying its effect.
28465 */
28466- loadsegment(ds, __USER_DS);
28467- loadsegment(es, __USER_DS);
28468+ loadsegment(ds, __KERNEL_DS);
28469+ loadsegment(es, __KERNEL_DS);
28470+ loadsegment(ss, __KERNEL_DS);
28471+
28472+#ifdef CONFIG_PAX_KERNEXEC
28473+ loadsegment(fs, __KERNEL_PERCPU);
28474+#endif
28475+
28476+#ifdef CONFIG_PAX_MEMORY_UDEREF
28477+ __set_fs(current_thread_info()->addr_limit);
28478+#endif
28479+
28480 #endif
28481
28482 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28483diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28484index 5521f7c..691b7a3 100644
28485--- a/arch/x86/kvm/x86.c
28486+++ b/arch/x86/kvm/x86.c
28487@@ -1822,8 +1822,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28488 {
28489 struct kvm *kvm = vcpu->kvm;
28490 int lm = is_long_mode(vcpu);
28491- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28492- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28493+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28494+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28495 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28496 : kvm->arch.xen_hvm_config.blob_size_32;
28497 u32 page_num = data & ~PAGE_MASK;
28498@@ -2738,6 +2738,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28499 if (n < msr_list.nmsrs)
28500 goto out;
28501 r = -EFAULT;
28502+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28503+ goto out;
28504 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28505 num_msrs_to_save * sizeof(u32)))
28506 goto out;
28507@@ -5574,7 +5576,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28508 };
28509 #endif
28510
28511-int kvm_arch_init(void *opaque)
28512+int kvm_arch_init(const void *opaque)
28513 {
28514 int r;
28515 struct kvm_x86_ops *ops = opaque;
28516diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28517index aae9413..d11e829 100644
28518--- a/arch/x86/lguest/boot.c
28519+++ b/arch/x86/lguest/boot.c
28520@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28521 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28522 * Launcher to reboot us.
28523 */
28524-static void lguest_restart(char *reason)
28525+static __noreturn void lguest_restart(char *reason)
28526 {
28527 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28528+ BUG();
28529 }
28530
28531 /*G:050
28532diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28533index 00933d5..3a64af9 100644
28534--- a/arch/x86/lib/atomic64_386_32.S
28535+++ b/arch/x86/lib/atomic64_386_32.S
28536@@ -48,6 +48,10 @@ BEGIN(read)
28537 movl (v), %eax
28538 movl 4(v), %edx
28539 RET_ENDP
28540+BEGIN(read_unchecked)
28541+ movl (v), %eax
28542+ movl 4(v), %edx
28543+RET_ENDP
28544 #undef v
28545
28546 #define v %esi
28547@@ -55,6 +59,10 @@ BEGIN(set)
28548 movl %ebx, (v)
28549 movl %ecx, 4(v)
28550 RET_ENDP
28551+BEGIN(set_unchecked)
28552+ movl %ebx, (v)
28553+ movl %ecx, 4(v)
28554+RET_ENDP
28555 #undef v
28556
28557 #define v %esi
28558@@ -70,6 +78,20 @@ RET_ENDP
28559 BEGIN(add)
28560 addl %eax, (v)
28561 adcl %edx, 4(v)
28562+
28563+#ifdef CONFIG_PAX_REFCOUNT
28564+ jno 0f
28565+ subl %eax, (v)
28566+ sbbl %edx, 4(v)
28567+ int $4
28568+0:
28569+ _ASM_EXTABLE(0b, 0b)
28570+#endif
28571+
28572+RET_ENDP
28573+BEGIN(add_unchecked)
28574+ addl %eax, (v)
28575+ adcl %edx, 4(v)
28576 RET_ENDP
28577 #undef v
28578
28579@@ -77,6 +99,24 @@ RET_ENDP
28580 BEGIN(add_return)
28581 addl (v), %eax
28582 adcl 4(v), %edx
28583+
28584+#ifdef CONFIG_PAX_REFCOUNT
28585+ into
28586+1234:
28587+ _ASM_EXTABLE(1234b, 2f)
28588+#endif
28589+
28590+ movl %eax, (v)
28591+ movl %edx, 4(v)
28592+
28593+#ifdef CONFIG_PAX_REFCOUNT
28594+2:
28595+#endif
28596+
28597+RET_ENDP
28598+BEGIN(add_return_unchecked)
28599+ addl (v), %eax
28600+ adcl 4(v), %edx
28601 movl %eax, (v)
28602 movl %edx, 4(v)
28603 RET_ENDP
28604@@ -86,6 +126,20 @@ RET_ENDP
28605 BEGIN(sub)
28606 subl %eax, (v)
28607 sbbl %edx, 4(v)
28608+
28609+#ifdef CONFIG_PAX_REFCOUNT
28610+ jno 0f
28611+ addl %eax, (v)
28612+ adcl %edx, 4(v)
28613+ int $4
28614+0:
28615+ _ASM_EXTABLE(0b, 0b)
28616+#endif
28617+
28618+RET_ENDP
28619+BEGIN(sub_unchecked)
28620+ subl %eax, (v)
28621+ sbbl %edx, 4(v)
28622 RET_ENDP
28623 #undef v
28624
28625@@ -96,6 +150,27 @@ BEGIN(sub_return)
28626 sbbl $0, %edx
28627 addl (v), %eax
28628 adcl 4(v), %edx
28629+
28630+#ifdef CONFIG_PAX_REFCOUNT
28631+ into
28632+1234:
28633+ _ASM_EXTABLE(1234b, 2f)
28634+#endif
28635+
28636+ movl %eax, (v)
28637+ movl %edx, 4(v)
28638+
28639+#ifdef CONFIG_PAX_REFCOUNT
28640+2:
28641+#endif
28642+
28643+RET_ENDP
28644+BEGIN(sub_return_unchecked)
28645+ negl %edx
28646+ negl %eax
28647+ sbbl $0, %edx
28648+ addl (v), %eax
28649+ adcl 4(v), %edx
28650 movl %eax, (v)
28651 movl %edx, 4(v)
28652 RET_ENDP
28653@@ -105,6 +180,20 @@ RET_ENDP
28654 BEGIN(inc)
28655 addl $1, (v)
28656 adcl $0, 4(v)
28657+
28658+#ifdef CONFIG_PAX_REFCOUNT
28659+ jno 0f
28660+ subl $1, (v)
28661+ sbbl $0, 4(v)
28662+ int $4
28663+0:
28664+ _ASM_EXTABLE(0b, 0b)
28665+#endif
28666+
28667+RET_ENDP
28668+BEGIN(inc_unchecked)
28669+ addl $1, (v)
28670+ adcl $0, 4(v)
28671 RET_ENDP
28672 #undef v
28673
28674@@ -114,6 +203,26 @@ BEGIN(inc_return)
28675 movl 4(v), %edx
28676 addl $1, %eax
28677 adcl $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(inc_return_unchecked)
28694+ movl (v), %eax
28695+ movl 4(v), %edx
28696+ addl $1, %eax
28697+ adcl $0, %edx
28698 movl %eax, (v)
28699 movl %edx, 4(v)
28700 RET_ENDP
28701@@ -123,6 +232,20 @@ RET_ENDP
28702 BEGIN(dec)
28703 subl $1, (v)
28704 sbbl $0, 4(v)
28705+
28706+#ifdef CONFIG_PAX_REFCOUNT
28707+ jno 0f
28708+ addl $1, (v)
28709+ adcl $0, 4(v)
28710+ int $4
28711+0:
28712+ _ASM_EXTABLE(0b, 0b)
28713+#endif
28714+
28715+RET_ENDP
28716+BEGIN(dec_unchecked)
28717+ subl $1, (v)
28718+ sbbl $0, 4(v)
28719 RET_ENDP
28720 #undef v
28721
28722@@ -132,6 +255,26 @@ BEGIN(dec_return)
28723 movl 4(v), %edx
28724 subl $1, %eax
28725 sbbl $0, %edx
28726+
28727+#ifdef CONFIG_PAX_REFCOUNT
28728+ into
28729+1234:
28730+ _ASM_EXTABLE(1234b, 2f)
28731+#endif
28732+
28733+ movl %eax, (v)
28734+ movl %edx, 4(v)
28735+
28736+#ifdef CONFIG_PAX_REFCOUNT
28737+2:
28738+#endif
28739+
28740+RET_ENDP
28741+BEGIN(dec_return_unchecked)
28742+ movl (v), %eax
28743+ movl 4(v), %edx
28744+ subl $1, %eax
28745+ sbbl $0, %edx
28746 movl %eax, (v)
28747 movl %edx, 4(v)
28748 RET_ENDP
28749@@ -143,6 +286,13 @@ BEGIN(add_unless)
28750 adcl %edx, %edi
28751 addl (v), %eax
28752 adcl 4(v), %edx
28753+
28754+#ifdef CONFIG_PAX_REFCOUNT
28755+ into
28756+1234:
28757+ _ASM_EXTABLE(1234b, 2f)
28758+#endif
28759+
28760 cmpl %eax, %ecx
28761 je 3f
28762 1:
28763@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28764 1:
28765 addl $1, %eax
28766 adcl $0, %edx
28767+
28768+#ifdef CONFIG_PAX_REFCOUNT
28769+ into
28770+1234:
28771+ _ASM_EXTABLE(1234b, 2f)
28772+#endif
28773+
28774 movl %eax, (v)
28775 movl %edx, 4(v)
28776 movl $1, %eax
28777@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28778 movl 4(v), %edx
28779 subl $1, %eax
28780 sbbl $0, %edx
28781+
28782+#ifdef CONFIG_PAX_REFCOUNT
28783+ into
28784+1234:
28785+ _ASM_EXTABLE(1234b, 1f)
28786+#endif
28787+
28788 js 1f
28789 movl %eax, (v)
28790 movl %edx, 4(v)
28791diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28792index f5cc9eb..51fa319 100644
28793--- a/arch/x86/lib/atomic64_cx8_32.S
28794+++ b/arch/x86/lib/atomic64_cx8_32.S
28795@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28796 CFI_STARTPROC
28797
28798 read64 %ecx
28799+ pax_force_retaddr
28800 ret
28801 CFI_ENDPROC
28802 ENDPROC(atomic64_read_cx8)
28803
28804+ENTRY(atomic64_read_unchecked_cx8)
28805+ CFI_STARTPROC
28806+
28807+ read64 %ecx
28808+ pax_force_retaddr
28809+ ret
28810+ CFI_ENDPROC
28811+ENDPROC(atomic64_read_unchecked_cx8)
28812+
28813 ENTRY(atomic64_set_cx8)
28814 CFI_STARTPROC
28815
28816@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28817 cmpxchg8b (%esi)
28818 jne 1b
28819
28820+ pax_force_retaddr
28821 ret
28822 CFI_ENDPROC
28823 ENDPROC(atomic64_set_cx8)
28824
28825+ENTRY(atomic64_set_unchecked_cx8)
28826+ CFI_STARTPROC
28827+
28828+1:
28829+/* we don't need LOCK_PREFIX since aligned 64-bit writes
28830+ * are atomic on 586 and newer */
28831+ cmpxchg8b (%esi)
28832+ jne 1b
28833+
28834+ pax_force_retaddr
28835+ ret
28836+ CFI_ENDPROC
28837+ENDPROC(atomic64_set_unchecked_cx8)
28838+
28839 ENTRY(atomic64_xchg_cx8)
28840 CFI_STARTPROC
28841
28842@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28843 cmpxchg8b (%esi)
28844 jne 1b
28845
28846+ pax_force_retaddr
28847 ret
28848 CFI_ENDPROC
28849 ENDPROC(atomic64_xchg_cx8)
28850
28851-.macro addsub_return func ins insc
28852-ENTRY(atomic64_\func\()_return_cx8)
28853+.macro addsub_return func ins insc unchecked=""
28854+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28855 CFI_STARTPROC
28856 SAVE ebp
28857 SAVE ebx
28858@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28859 movl %edx, %ecx
28860 \ins\()l %esi, %ebx
28861 \insc\()l %edi, %ecx
28862+
28863+.ifb \unchecked
28864+#ifdef CONFIG_PAX_REFCOUNT
28865+ into
28866+2:
28867+ _ASM_EXTABLE(2b, 3f)
28868+#endif
28869+.endif
28870+
28871 LOCK_PREFIX
28872 cmpxchg8b (%ebp)
28873 jne 1b
28874-
28875-10:
28876 movl %ebx, %eax
28877 movl %ecx, %edx
28878+
28879+.ifb \unchecked
28880+#ifdef CONFIG_PAX_REFCOUNT
28881+3:
28882+#endif
28883+.endif
28884+
28885 RESTORE edi
28886 RESTORE esi
28887 RESTORE ebx
28888 RESTORE ebp
28889+ pax_force_retaddr
28890 ret
28891 CFI_ENDPROC
28892-ENDPROC(atomic64_\func\()_return_cx8)
28893+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28894 .endm
28895
28896 addsub_return add add adc
28897 addsub_return sub sub sbb
28898+addsub_return add add adc _unchecked
28899+addsub_return sub sub sbb _unchecked
28900
28901-.macro incdec_return func ins insc
28902-ENTRY(atomic64_\func\()_return_cx8)
28903+.macro incdec_return func ins insc unchecked=""
28904+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28905 CFI_STARTPROC
28906 SAVE ebx
28907
28908@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28909 movl %edx, %ecx
28910 \ins\()l $1, %ebx
28911 \insc\()l $0, %ecx
28912+
28913+.ifb \unchecked
28914+#ifdef CONFIG_PAX_REFCOUNT
28915+ into
28916+2:
28917+ _ASM_EXTABLE(2b, 3f)
28918+#endif
28919+.endif
28920+
28921 LOCK_PREFIX
28922 cmpxchg8b (%esi)
28923 jne 1b
28924
28925-10:
28926 movl %ebx, %eax
28927 movl %ecx, %edx
28928+
28929+.ifb \unchecked
28930+#ifdef CONFIG_PAX_REFCOUNT
28931+3:
28932+#endif
28933+.endif
28934+
28935 RESTORE ebx
28936+ pax_force_retaddr
28937 ret
28938 CFI_ENDPROC
28939-ENDPROC(atomic64_\func\()_return_cx8)
28940+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28941 .endm
28942
28943 incdec_return inc add adc
28944 incdec_return dec sub sbb
28945+incdec_return inc add adc _unchecked
28946+incdec_return dec sub sbb _unchecked
28947
28948 ENTRY(atomic64_dec_if_positive_cx8)
28949 CFI_STARTPROC
28950@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28951 movl %edx, %ecx
28952 subl $1, %ebx
28953 sbb $0, %ecx
28954+
28955+#ifdef CONFIG_PAX_REFCOUNT
28956+ into
28957+1234:
28958+ _ASM_EXTABLE(1234b, 2f)
28959+#endif
28960+
28961 js 2f
28962 LOCK_PREFIX
28963 cmpxchg8b (%esi)
28964@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28965 movl %ebx, %eax
28966 movl %ecx, %edx
28967 RESTORE ebx
28968+ pax_force_retaddr
28969 ret
28970 CFI_ENDPROC
28971 ENDPROC(atomic64_dec_if_positive_cx8)
28972@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28973 movl %edx, %ecx
28974 addl %ebp, %ebx
28975 adcl %edi, %ecx
28976+
28977+#ifdef CONFIG_PAX_REFCOUNT
28978+ into
28979+1234:
28980+ _ASM_EXTABLE(1234b, 3f)
28981+#endif
28982+
28983 LOCK_PREFIX
28984 cmpxchg8b (%esi)
28985 jne 1b
28986@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28987 CFI_ADJUST_CFA_OFFSET -8
28988 RESTORE ebx
28989 RESTORE ebp
28990+ pax_force_retaddr
28991 ret
28992 4:
28993 cmpl %edx, 4(%esp)
28994@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28995 xorl %ecx, %ecx
28996 addl $1, %ebx
28997 adcl %edx, %ecx
28998+
28999+#ifdef CONFIG_PAX_REFCOUNT
29000+ into
29001+1234:
29002+ _ASM_EXTABLE(1234b, 3f)
29003+#endif
29004+
29005 LOCK_PREFIX
29006 cmpxchg8b (%esi)
29007 jne 1b
29008@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29009 movl $1, %eax
29010 3:
29011 RESTORE ebx
29012+ pax_force_retaddr
29013 ret
29014 CFI_ENDPROC
29015 ENDPROC(atomic64_inc_not_zero_cx8)
29016diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29017index e78b8ee..7e173a8 100644
29018--- a/arch/x86/lib/checksum_32.S
29019+++ b/arch/x86/lib/checksum_32.S
29020@@ -29,7 +29,8 @@
29021 #include <asm/dwarf2.h>
29022 #include <asm/errno.h>
29023 #include <asm/asm.h>
29024-
29025+#include <asm/segment.h>
29026+
29027 /*
29028 * computes a partial checksum, e.g. for TCP/UDP fragments
29029 */
29030@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29031
29032 #define ARGBASE 16
29033 #define FP 12
29034-
29035-ENTRY(csum_partial_copy_generic)
29036+
29037+ENTRY(csum_partial_copy_generic_to_user)
29038 CFI_STARTPROC
29039+
29040+#ifdef CONFIG_PAX_MEMORY_UDEREF
29041+ pushl_cfi %gs
29042+ popl_cfi %es
29043+ jmp csum_partial_copy_generic
29044+#endif
29045+
29046+ENTRY(csum_partial_copy_generic_from_user)
29047+
29048+#ifdef CONFIG_PAX_MEMORY_UDEREF
29049+ pushl_cfi %gs
29050+ popl_cfi %ds
29051+#endif
29052+
29053+ENTRY(csum_partial_copy_generic)
29054 subl $4,%esp
29055 CFI_ADJUST_CFA_OFFSET 4
29056 pushl_cfi %edi
29057@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29058 jmp 4f
29059 SRC(1: movw (%esi), %bx )
29060 addl $2, %esi
29061-DST( movw %bx, (%edi) )
29062+DST( movw %bx, %es:(%edi) )
29063 addl $2, %edi
29064 addw %bx, %ax
29065 adcl $0, %eax
29066@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29067 SRC(1: movl (%esi), %ebx )
29068 SRC( movl 4(%esi), %edx )
29069 adcl %ebx, %eax
29070-DST( movl %ebx, (%edi) )
29071+DST( movl %ebx, %es:(%edi) )
29072 adcl %edx, %eax
29073-DST( movl %edx, 4(%edi) )
29074+DST( movl %edx, %es:4(%edi) )
29075
29076 SRC( movl 8(%esi), %ebx )
29077 SRC( movl 12(%esi), %edx )
29078 adcl %ebx, %eax
29079-DST( movl %ebx, 8(%edi) )
29080+DST( movl %ebx, %es:8(%edi) )
29081 adcl %edx, %eax
29082-DST( movl %edx, 12(%edi) )
29083+DST( movl %edx, %es:12(%edi) )
29084
29085 SRC( movl 16(%esi), %ebx )
29086 SRC( movl 20(%esi), %edx )
29087 adcl %ebx, %eax
29088-DST( movl %ebx, 16(%edi) )
29089+DST( movl %ebx, %es:16(%edi) )
29090 adcl %edx, %eax
29091-DST( movl %edx, 20(%edi) )
29092+DST( movl %edx, %es:20(%edi) )
29093
29094 SRC( movl 24(%esi), %ebx )
29095 SRC( movl 28(%esi), %edx )
29096 adcl %ebx, %eax
29097-DST( movl %ebx, 24(%edi) )
29098+DST( movl %ebx, %es:24(%edi) )
29099 adcl %edx, %eax
29100-DST( movl %edx, 28(%edi) )
29101+DST( movl %edx, %es:28(%edi) )
29102
29103 lea 32(%esi), %esi
29104 lea 32(%edi), %edi
29105@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29106 shrl $2, %edx # This clears CF
29107 SRC(3: movl (%esi), %ebx )
29108 adcl %ebx, %eax
29109-DST( movl %ebx, (%edi) )
29110+DST( movl %ebx, %es:(%edi) )
29111 lea 4(%esi), %esi
29112 lea 4(%edi), %edi
29113 dec %edx
29114@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29115 jb 5f
29116 SRC( movw (%esi), %cx )
29117 leal 2(%esi), %esi
29118-DST( movw %cx, (%edi) )
29119+DST( movw %cx, %es:(%edi) )
29120 leal 2(%edi), %edi
29121 je 6f
29122 shll $16,%ecx
29123 SRC(5: movb (%esi), %cl )
29124-DST( movb %cl, (%edi) )
29125+DST( movb %cl, %es:(%edi) )
29126 6: addl %ecx, %eax
29127 adcl $0, %eax
29128 7:
29129@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29130
29131 6001:
29132 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29133- movl $-EFAULT, (%ebx)
29134+ movl $-EFAULT, %ss:(%ebx)
29135
29136 # zero the complete destination - computing the rest
29137 # is too much work
29138@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29139
29140 6002:
29141 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29142- movl $-EFAULT,(%ebx)
29143+ movl $-EFAULT,%ss:(%ebx)
29144 jmp 5000b
29145
29146 .previous
29147
29148+ pushl_cfi %ss
29149+ popl_cfi %ds
29150+ pushl_cfi %ss
29151+ popl_cfi %es
29152 popl_cfi %ebx
29153 CFI_RESTORE ebx
29154 popl_cfi %esi
29155@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29156 popl_cfi %ecx # equivalent to addl $4,%esp
29157 ret
29158 CFI_ENDPROC
29159-ENDPROC(csum_partial_copy_generic)
29160+ENDPROC(csum_partial_copy_generic_to_user)
29161
29162 #else
29163
29164 /* Version for PentiumII/PPro */
29165
29166 #define ROUND1(x) \
29167+ nop; nop; nop; \
29168 SRC(movl x(%esi), %ebx ) ; \
29169 addl %ebx, %eax ; \
29170- DST(movl %ebx, x(%edi) ) ;
29171+ DST(movl %ebx, %es:x(%edi)) ;
29172
29173 #define ROUND(x) \
29174+ nop; nop; nop; \
29175 SRC(movl x(%esi), %ebx ) ; \
29176 adcl %ebx, %eax ; \
29177- DST(movl %ebx, x(%edi) ) ;
29178+ DST(movl %ebx, %es:x(%edi)) ;
29179
29180 #define ARGBASE 12
29181-
29182-ENTRY(csum_partial_copy_generic)
29183+
29184+ENTRY(csum_partial_copy_generic_to_user)
29185 CFI_STARTPROC
29186+
29187+#ifdef CONFIG_PAX_MEMORY_UDEREF
29188+ pushl_cfi %gs
29189+ popl_cfi %es
29190+ jmp csum_partial_copy_generic
29191+#endif
29192+
29193+ENTRY(csum_partial_copy_generic_from_user)
29194+
29195+#ifdef CONFIG_PAX_MEMORY_UDEREF
29196+ pushl_cfi %gs
29197+ popl_cfi %ds
29198+#endif
29199+
29200+ENTRY(csum_partial_copy_generic)
29201 pushl_cfi %ebx
29202 CFI_REL_OFFSET ebx, 0
29203 pushl_cfi %edi
29204@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29205 subl %ebx, %edi
29206 lea -1(%esi),%edx
29207 andl $-32,%edx
29208- lea 3f(%ebx,%ebx), %ebx
29209+ lea 3f(%ebx,%ebx,2), %ebx
29210 testl %esi, %esi
29211 jmp *%ebx
29212 1: addl $64,%esi
29213@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29214 jb 5f
29215 SRC( movw (%esi), %dx )
29216 leal 2(%esi), %esi
29217-DST( movw %dx, (%edi) )
29218+DST( movw %dx, %es:(%edi) )
29219 leal 2(%edi), %edi
29220 je 6f
29221 shll $16,%edx
29222 5:
29223 SRC( movb (%esi), %dl )
29224-DST( movb %dl, (%edi) )
29225+DST( movb %dl, %es:(%edi) )
29226 6: addl %edx, %eax
29227 adcl $0, %eax
29228 7:
29229 .section .fixup, "ax"
29230 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29231- movl $-EFAULT, (%ebx)
29232+ movl $-EFAULT, %ss:(%ebx)
29233 # zero the complete destination (computing the rest is too much work)
29234 movl ARGBASE+8(%esp),%edi # dst
29235 movl ARGBASE+12(%esp),%ecx # len
29236@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29237 rep; stosb
29238 jmp 7b
29239 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29240- movl $-EFAULT, (%ebx)
29241+ movl $-EFAULT, %ss:(%ebx)
29242 jmp 7b
29243 .previous
29244
29245+#ifdef CONFIG_PAX_MEMORY_UDEREF
29246+ pushl_cfi %ss
29247+ popl_cfi %ds
29248+ pushl_cfi %ss
29249+ popl_cfi %es
29250+#endif
29251+
29252 popl_cfi %esi
29253 CFI_RESTORE esi
29254 popl_cfi %edi
29255@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29256 CFI_RESTORE ebx
29257 ret
29258 CFI_ENDPROC
29259-ENDPROC(csum_partial_copy_generic)
29260+ENDPROC(csum_partial_copy_generic_to_user)
29261
29262 #undef ROUND
29263 #undef ROUND1
29264diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29265index f2145cf..cea889d 100644
29266--- a/arch/x86/lib/clear_page_64.S
29267+++ b/arch/x86/lib/clear_page_64.S
29268@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29269 movl $4096/8,%ecx
29270 xorl %eax,%eax
29271 rep stosq
29272+ pax_force_retaddr
29273 ret
29274 CFI_ENDPROC
29275 ENDPROC(clear_page_c)
29276@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29277 movl $4096,%ecx
29278 xorl %eax,%eax
29279 rep stosb
29280+ pax_force_retaddr
29281 ret
29282 CFI_ENDPROC
29283 ENDPROC(clear_page_c_e)
29284@@ -43,6 +45,7 @@ ENTRY(clear_page)
29285 leaq 64(%rdi),%rdi
29286 jnz .Lloop
29287 nop
29288+ pax_force_retaddr
29289 ret
29290 CFI_ENDPROC
29291 .Lclear_page_end:
29292@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29293
29294 #include <asm/cpufeature.h>
29295
29296- .section .altinstr_replacement,"ax"
29297+ .section .altinstr_replacement,"a"
29298 1: .byte 0xeb /* jmp <disp8> */
29299 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29300 2: .byte 0xeb /* jmp <disp8> */
29301diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29302index 1e572c5..2a162cd 100644
29303--- a/arch/x86/lib/cmpxchg16b_emu.S
29304+++ b/arch/x86/lib/cmpxchg16b_emu.S
29305@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29306
29307 popf
29308 mov $1, %al
29309+ pax_force_retaddr
29310 ret
29311
29312 not_same:
29313 popf
29314 xor %al,%al
29315+ pax_force_retaddr
29316 ret
29317
29318 CFI_ENDPROC
29319diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29320index 176cca6..e0d658e 100644
29321--- a/arch/x86/lib/copy_page_64.S
29322+++ b/arch/x86/lib/copy_page_64.S
29323@@ -9,6 +9,7 @@ copy_page_rep:
29324 CFI_STARTPROC
29325 movl $4096/8, %ecx
29326 rep movsq
29327+ pax_force_retaddr
29328 ret
29329 CFI_ENDPROC
29330 ENDPROC(copy_page_rep)
29331@@ -24,8 +25,8 @@ ENTRY(copy_page)
29332 CFI_ADJUST_CFA_OFFSET 2*8
29333 movq %rbx, (%rsp)
29334 CFI_REL_OFFSET rbx, 0
29335- movq %r12, 1*8(%rsp)
29336- CFI_REL_OFFSET r12, 1*8
29337+ movq %r13, 1*8(%rsp)
29338+ CFI_REL_OFFSET r13, 1*8
29339
29340 movl $(4096/64)-5, %ecx
29341 .p2align 4
29342@@ -38,7 +39,7 @@ ENTRY(copy_page)
29343 movq 0x8*4(%rsi), %r9
29344 movq 0x8*5(%rsi), %r10
29345 movq 0x8*6(%rsi), %r11
29346- movq 0x8*7(%rsi), %r12
29347+ movq 0x8*7(%rsi), %r13
29348
29349 prefetcht0 5*64(%rsi)
29350
29351@@ -49,7 +50,7 @@ ENTRY(copy_page)
29352 movq %r9, 0x8*4(%rdi)
29353 movq %r10, 0x8*5(%rdi)
29354 movq %r11, 0x8*6(%rdi)
29355- movq %r12, 0x8*7(%rdi)
29356+ movq %r13, 0x8*7(%rdi)
29357
29358 leaq 64 (%rsi), %rsi
29359 leaq 64 (%rdi), %rdi
29360@@ -68,7 +69,7 @@ ENTRY(copy_page)
29361 movq 0x8*4(%rsi), %r9
29362 movq 0x8*5(%rsi), %r10
29363 movq 0x8*6(%rsi), %r11
29364- movq 0x8*7(%rsi), %r12
29365+ movq 0x8*7(%rsi), %r13
29366
29367 movq %rax, 0x8*0(%rdi)
29368 movq %rbx, 0x8*1(%rdi)
29369@@ -77,7 +78,7 @@ ENTRY(copy_page)
29370 movq %r9, 0x8*4(%rdi)
29371 movq %r10, 0x8*5(%rdi)
29372 movq %r11, 0x8*6(%rdi)
29373- movq %r12, 0x8*7(%rdi)
29374+ movq %r13, 0x8*7(%rdi)
29375
29376 leaq 64(%rdi), %rdi
29377 leaq 64(%rsi), %rsi
29378@@ -85,10 +86,11 @@ ENTRY(copy_page)
29379
29380 movq (%rsp), %rbx
29381 CFI_RESTORE rbx
29382- movq 1*8(%rsp), %r12
29383- CFI_RESTORE r12
29384+ movq 1*8(%rsp), %r13
29385+ CFI_RESTORE r13
29386 addq $2*8, %rsp
29387 CFI_ADJUST_CFA_OFFSET -2*8
29388+ pax_force_retaddr
29389 ret
29390 .Lcopy_page_end:
29391 CFI_ENDPROC
29392@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29393
29394 #include <asm/cpufeature.h>
29395
29396- .section .altinstr_replacement,"ax"
29397+ .section .altinstr_replacement,"a"
29398 1: .byte 0xeb /* jmp <disp8> */
29399 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29400 2:
29401diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29402index dee945d..a84067b 100644
29403--- a/arch/x86/lib/copy_user_64.S
29404+++ b/arch/x86/lib/copy_user_64.S
29405@@ -18,31 +18,7 @@
29406 #include <asm/alternative-asm.h>
29407 #include <asm/asm.h>
29408 #include <asm/smap.h>
29409-
29410-/*
29411- * By placing feature2 after feature1 in altinstructions section, we logically
29412- * implement:
29413- * If CPU has feature2, jmp to alt2 is used
29414- * else if CPU has feature1, jmp to alt1 is used
29415- * else jmp to orig is used.
29416- */
29417- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29418-0:
29419- .byte 0xe9 /* 32bit jump */
29420- .long \orig-1f /* by default jump to orig */
29421-1:
29422- .section .altinstr_replacement,"ax"
29423-2: .byte 0xe9 /* near jump with 32bit immediate */
29424- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29425-3: .byte 0xe9 /* near jump with 32bit immediate */
29426- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29427- .previous
29428-
29429- .section .altinstructions,"a"
29430- altinstruction_entry 0b,2b,\feature1,5,5
29431- altinstruction_entry 0b,3b,\feature2,5,5
29432- .previous
29433- .endm
29434+#include <asm/pgtable.h>
29435
29436 .macro ALIGN_DESTINATION
29437 #ifdef FIX_ALIGNMENT
29438@@ -70,52 +46,6 @@
29439 #endif
29440 .endm
29441
29442-/* Standard copy_to_user with segment limit checking */
29443-ENTRY(_copy_to_user)
29444- CFI_STARTPROC
29445- GET_THREAD_INFO(%rax)
29446- movq %rdi,%rcx
29447- addq %rdx,%rcx
29448- jc bad_to_user
29449- cmpq TI_addr_limit(%rax),%rcx
29450- ja bad_to_user
29451- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29452- copy_user_generic_unrolled,copy_user_generic_string, \
29453- copy_user_enhanced_fast_string
29454- CFI_ENDPROC
29455-ENDPROC(_copy_to_user)
29456-
29457-/* Standard copy_from_user with segment limit checking */
29458-ENTRY(_copy_from_user)
29459- CFI_STARTPROC
29460- GET_THREAD_INFO(%rax)
29461- movq %rsi,%rcx
29462- addq %rdx,%rcx
29463- jc bad_from_user
29464- cmpq TI_addr_limit(%rax),%rcx
29465- ja bad_from_user
29466- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29467- copy_user_generic_unrolled,copy_user_generic_string, \
29468- copy_user_enhanced_fast_string
29469- CFI_ENDPROC
29470-ENDPROC(_copy_from_user)
29471-
29472- .section .fixup,"ax"
29473- /* must zero dest */
29474-ENTRY(bad_from_user)
29475-bad_from_user:
29476- CFI_STARTPROC
29477- movl %edx,%ecx
29478- xorl %eax,%eax
29479- rep
29480- stosb
29481-bad_to_user:
29482- movl %edx,%eax
29483- ret
29484- CFI_ENDPROC
29485-ENDPROC(bad_from_user)
29486- .previous
29487-
29488 /*
29489 * copy_user_generic_unrolled - memory copy with exception handling.
29490 * This version is for CPUs like P4 that don't have efficient micro
29491@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29492 */
29493 ENTRY(copy_user_generic_unrolled)
29494 CFI_STARTPROC
29495+ ASM_PAX_OPEN_USERLAND
29496 ASM_STAC
29497 cmpl $8,%edx
29498 jb 20f /* less then 8 bytes, go to byte copy loop */
29499@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29500 jnz 21b
29501 23: xor %eax,%eax
29502 ASM_CLAC
29503+ ASM_PAX_CLOSE_USERLAND
29504+ pax_force_retaddr
29505 ret
29506
29507 .section .fixup,"ax"
29508@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29509 */
29510 ENTRY(copy_user_generic_string)
29511 CFI_STARTPROC
29512+ ASM_PAX_OPEN_USERLAND
29513 ASM_STAC
29514 cmpl $8,%edx
29515 jb 2f /* less than 8 bytes, go to byte copy loop */
29516@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29517 movsb
29518 xorl %eax,%eax
29519 ASM_CLAC
29520+ ASM_PAX_CLOSE_USERLAND
29521+ pax_force_retaddr
29522 ret
29523
29524 .section .fixup,"ax"
29525@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29526 */
29527 ENTRY(copy_user_enhanced_fast_string)
29528 CFI_STARTPROC
29529+ ASM_PAX_OPEN_USERLAND
29530 ASM_STAC
29531 movl %edx,%ecx
29532 1: rep
29533 movsb
29534 xorl %eax,%eax
29535 ASM_CLAC
29536+ ASM_PAX_CLOSE_USERLAND
29537+ pax_force_retaddr
29538 ret
29539
29540 .section .fixup,"ax"
29541diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29542index 6a4f43c..c70fb52 100644
29543--- a/arch/x86/lib/copy_user_nocache_64.S
29544+++ b/arch/x86/lib/copy_user_nocache_64.S
29545@@ -8,6 +8,7 @@
29546
29547 #include <linux/linkage.h>
29548 #include <asm/dwarf2.h>
29549+#include <asm/alternative-asm.h>
29550
29551 #define FIX_ALIGNMENT 1
29552
29553@@ -16,6 +17,7 @@
29554 #include <asm/thread_info.h>
29555 #include <asm/asm.h>
29556 #include <asm/smap.h>
29557+#include <asm/pgtable.h>
29558
29559 .macro ALIGN_DESTINATION
29560 #ifdef FIX_ALIGNMENT
29561@@ -49,6 +51,16 @@
29562 */
29563 ENTRY(__copy_user_nocache)
29564 CFI_STARTPROC
29565+
29566+#ifdef CONFIG_PAX_MEMORY_UDEREF
29567+ mov pax_user_shadow_base,%rcx
29568+ cmp %rcx,%rsi
29569+ jae 1f
29570+ add %rcx,%rsi
29571+1:
29572+#endif
29573+
29574+ ASM_PAX_OPEN_USERLAND
29575 ASM_STAC
29576 cmpl $8,%edx
29577 jb 20f /* less then 8 bytes, go to byte copy loop */
29578@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29579 jnz 21b
29580 23: xorl %eax,%eax
29581 ASM_CLAC
29582+ ASM_PAX_CLOSE_USERLAND
29583 sfence
29584+ pax_force_retaddr
29585 ret
29586
29587 .section .fixup,"ax"
29588diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29589index 2419d5f..fe52d0e 100644
29590--- a/arch/x86/lib/csum-copy_64.S
29591+++ b/arch/x86/lib/csum-copy_64.S
29592@@ -9,6 +9,7 @@
29593 #include <asm/dwarf2.h>
29594 #include <asm/errno.h>
29595 #include <asm/asm.h>
29596+#include <asm/alternative-asm.h>
29597
29598 /*
29599 * Checksum copy with exception handling.
29600@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29601 CFI_ADJUST_CFA_OFFSET 7*8
29602 movq %rbx, 2*8(%rsp)
29603 CFI_REL_OFFSET rbx, 2*8
29604- movq %r12, 3*8(%rsp)
29605- CFI_REL_OFFSET r12, 3*8
29606+ movq %r15, 3*8(%rsp)
29607+ CFI_REL_OFFSET r15, 3*8
29608 movq %r14, 4*8(%rsp)
29609 CFI_REL_OFFSET r14, 4*8
29610 movq %r13, 5*8(%rsp)
29611@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29612 movl %edx, %ecx
29613
29614 xorl %r9d, %r9d
29615- movq %rcx, %r12
29616+ movq %rcx, %r15
29617
29618- shrq $6, %r12
29619+ shrq $6, %r15
29620 jz .Lhandle_tail /* < 64 */
29621
29622 clc
29623
29624 /* main loop. clear in 64 byte blocks */
29625 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29626- /* r11: temp3, rdx: temp4, r12 loopcnt */
29627+ /* r11: temp3, rdx: temp4, r15 loopcnt */
29628 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29629 .p2align 4
29630 .Lloop:
29631@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29632 adcq %r14, %rax
29633 adcq %r13, %rax
29634
29635- decl %r12d
29636+ decl %r15d
29637
29638 dest
29639 movq %rbx, (%rsi)
29640@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29641 .Lende:
29642 movq 2*8(%rsp), %rbx
29643 CFI_RESTORE rbx
29644- movq 3*8(%rsp), %r12
29645- CFI_RESTORE r12
29646+ movq 3*8(%rsp), %r15
29647+ CFI_RESTORE r15
29648 movq 4*8(%rsp), %r14
29649 CFI_RESTORE r14
29650 movq 5*8(%rsp), %r13
29651@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29652 CFI_RESTORE rbp
29653 addq $7*8, %rsp
29654 CFI_ADJUST_CFA_OFFSET -7*8
29655+ pax_force_retaddr
29656 ret
29657 CFI_RESTORE_STATE
29658
29659diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29660index 7609e0e..b449b98 100644
29661--- a/arch/x86/lib/csum-wrappers_64.c
29662+++ b/arch/x86/lib/csum-wrappers_64.c
29663@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29664 len -= 2;
29665 }
29666 }
29667+ pax_open_userland();
29668 stac();
29669- isum = csum_partial_copy_generic((__force const void *)src,
29670+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29671 dst, len, isum, errp, NULL);
29672 clac();
29673+ pax_close_userland();
29674 if (unlikely(*errp))
29675 goto out_err;
29676
29677@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29678 }
29679
29680 *errp = 0;
29681+ pax_open_userland();
29682 stac();
29683- ret = csum_partial_copy_generic(src, (void __force *)dst,
29684+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29685 len, isum, NULL, errp);
29686 clac();
29687+ pax_close_userland();
29688 return ret;
29689 }
29690 EXPORT_SYMBOL(csum_partial_copy_to_user);
29691diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29692index a451235..1daa956 100644
29693--- a/arch/x86/lib/getuser.S
29694+++ b/arch/x86/lib/getuser.S
29695@@ -33,17 +33,40 @@
29696 #include <asm/thread_info.h>
29697 #include <asm/asm.h>
29698 #include <asm/smap.h>
29699+#include <asm/segment.h>
29700+#include <asm/pgtable.h>
29701+#include <asm/alternative-asm.h>
29702+
29703+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29704+#define __copyuser_seg gs;
29705+#else
29706+#define __copyuser_seg
29707+#endif
29708
29709 .text
29710 ENTRY(__get_user_1)
29711 CFI_STARTPROC
29712+
29713+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29714 GET_THREAD_INFO(%_ASM_DX)
29715 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29716 jae bad_get_user
29717 ASM_STAC
29718-1: movzbl (%_ASM_AX),%edx
29719+
29720+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29721+ mov pax_user_shadow_base,%_ASM_DX
29722+ cmp %_ASM_DX,%_ASM_AX
29723+ jae 1234f
29724+ add %_ASM_DX,%_ASM_AX
29725+1234:
29726+#endif
29727+
29728+#endif
29729+
29730+1: __copyuser_seg movzbl (%_ASM_AX),%edx
29731 xor %eax,%eax
29732 ASM_CLAC
29733+ pax_force_retaddr
29734 ret
29735 CFI_ENDPROC
29736 ENDPROC(__get_user_1)
29737@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29738 ENTRY(__get_user_2)
29739 CFI_STARTPROC
29740 add $1,%_ASM_AX
29741+
29742+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29743 jc bad_get_user
29744 GET_THREAD_INFO(%_ASM_DX)
29745 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29746 jae bad_get_user
29747 ASM_STAC
29748-2: movzwl -1(%_ASM_AX),%edx
29749+
29750+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29751+ mov pax_user_shadow_base,%_ASM_DX
29752+ cmp %_ASM_DX,%_ASM_AX
29753+ jae 1234f
29754+ add %_ASM_DX,%_ASM_AX
29755+1234:
29756+#endif
29757+
29758+#endif
29759+
29760+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29761 xor %eax,%eax
29762 ASM_CLAC
29763+ pax_force_retaddr
29764 ret
29765 CFI_ENDPROC
29766 ENDPROC(__get_user_2)
29767@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29768 ENTRY(__get_user_4)
29769 CFI_STARTPROC
29770 add $3,%_ASM_AX
29771+
29772+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29773 jc bad_get_user
29774 GET_THREAD_INFO(%_ASM_DX)
29775 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29776 jae bad_get_user
29777 ASM_STAC
29778-3: movl -3(%_ASM_AX),%edx
29779+
29780+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29781+ mov pax_user_shadow_base,%_ASM_DX
29782+ cmp %_ASM_DX,%_ASM_AX
29783+ jae 1234f
29784+ add %_ASM_DX,%_ASM_AX
29785+1234:
29786+#endif
29787+
29788+#endif
29789+
29790+3: __copyuser_seg movl -3(%_ASM_AX),%edx
29791 xor %eax,%eax
29792 ASM_CLAC
29793+ pax_force_retaddr
29794 ret
29795 CFI_ENDPROC
29796 ENDPROC(__get_user_4)
29797@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29798 GET_THREAD_INFO(%_ASM_DX)
29799 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29800 jae bad_get_user
29801+
29802+#ifdef CONFIG_PAX_MEMORY_UDEREF
29803+ mov pax_user_shadow_base,%_ASM_DX
29804+ cmp %_ASM_DX,%_ASM_AX
29805+ jae 1234f
29806+ add %_ASM_DX,%_ASM_AX
29807+1234:
29808+#endif
29809+
29810 ASM_STAC
29811 4: movq -7(%_ASM_AX),%rdx
29812 xor %eax,%eax
29813 ASM_CLAC
29814+ pax_force_retaddr
29815 ret
29816 #else
29817 add $7,%_ASM_AX
29818@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29819 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29820 jae bad_get_user_8
29821 ASM_STAC
29822-4: movl -7(%_ASM_AX),%edx
29823-5: movl -3(%_ASM_AX),%ecx
29824+4: __copyuser_seg movl -7(%_ASM_AX),%edx
29825+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29826 xor %eax,%eax
29827 ASM_CLAC
29828+ pax_force_retaddr
29829 ret
29830 #endif
29831 CFI_ENDPROC
29832@@ -113,6 +175,7 @@ bad_get_user:
29833 xor %edx,%edx
29834 mov $(-EFAULT),%_ASM_AX
29835 ASM_CLAC
29836+ pax_force_retaddr
29837 ret
29838 CFI_ENDPROC
29839 END(bad_get_user)
29840@@ -124,6 +187,7 @@ bad_get_user_8:
29841 xor %ecx,%ecx
29842 mov $(-EFAULT),%_ASM_AX
29843 ASM_CLAC
29844+ pax_force_retaddr
29845 ret
29846 CFI_ENDPROC
29847 END(bad_get_user_8)
29848diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29849index 54fcffe..7be149e 100644
29850--- a/arch/x86/lib/insn.c
29851+++ b/arch/x86/lib/insn.c
29852@@ -20,8 +20,10 @@
29853
29854 #ifdef __KERNEL__
29855 #include <linux/string.h>
29856+#include <asm/pgtable_types.h>
29857 #else
29858 #include <string.h>
29859+#define ktla_ktva(addr) addr
29860 #endif
29861 #include <asm/inat.h>
29862 #include <asm/insn.h>
29863@@ -53,8 +55,8 @@
29864 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29865 {
29866 memset(insn, 0, sizeof(*insn));
29867- insn->kaddr = kaddr;
29868- insn->next_byte = kaddr;
29869+ insn->kaddr = ktla_ktva(kaddr);
29870+ insn->next_byte = ktla_ktva(kaddr);
29871 insn->x86_64 = x86_64 ? 1 : 0;
29872 insn->opnd_bytes = 4;
29873 if (x86_64)
29874diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29875index 05a95e7..326f2fa 100644
29876--- a/arch/x86/lib/iomap_copy_64.S
29877+++ b/arch/x86/lib/iomap_copy_64.S
29878@@ -17,6 +17,7 @@
29879
29880 #include <linux/linkage.h>
29881 #include <asm/dwarf2.h>
29882+#include <asm/alternative-asm.h>
29883
29884 /*
29885 * override generic version in lib/iomap_copy.c
29886@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29887 CFI_STARTPROC
29888 movl %edx,%ecx
29889 rep movsd
29890+ pax_force_retaddr
29891 ret
29892 CFI_ENDPROC
29893 ENDPROC(__iowrite32_copy)
29894diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29895index 56313a3..0db417e 100644
29896--- a/arch/x86/lib/memcpy_64.S
29897+++ b/arch/x86/lib/memcpy_64.S
29898@@ -24,7 +24,7 @@
29899 * This gets patched over the unrolled variant (below) via the
29900 * alternative instructions framework:
29901 */
29902- .section .altinstr_replacement, "ax", @progbits
29903+ .section .altinstr_replacement, "a", @progbits
29904 .Lmemcpy_c:
29905 movq %rdi, %rax
29906 movq %rdx, %rcx
29907@@ -33,6 +33,7 @@
29908 rep movsq
29909 movl %edx, %ecx
29910 rep movsb
29911+ pax_force_retaddr
29912 ret
29913 .Lmemcpy_e:
29914 .previous
29915@@ -44,11 +45,12 @@
29916 * This gets patched over the unrolled variant (below) via the
29917 * alternative instructions framework:
29918 */
29919- .section .altinstr_replacement, "ax", @progbits
29920+ .section .altinstr_replacement, "a", @progbits
29921 .Lmemcpy_c_e:
29922 movq %rdi, %rax
29923 movq %rdx, %rcx
29924 rep movsb
29925+ pax_force_retaddr
29926 ret
29927 .Lmemcpy_e_e:
29928 .previous
29929@@ -136,6 +138,7 @@ ENTRY(memcpy)
29930 movq %r9, 1*8(%rdi)
29931 movq %r10, -2*8(%rdi, %rdx)
29932 movq %r11, -1*8(%rdi, %rdx)
29933+ pax_force_retaddr
29934 retq
29935 .p2align 4
29936 .Lless_16bytes:
29937@@ -148,6 +151,7 @@ ENTRY(memcpy)
29938 movq -1*8(%rsi, %rdx), %r9
29939 movq %r8, 0*8(%rdi)
29940 movq %r9, -1*8(%rdi, %rdx)
29941+ pax_force_retaddr
29942 retq
29943 .p2align 4
29944 .Lless_8bytes:
29945@@ -161,6 +165,7 @@ ENTRY(memcpy)
29946 movl -4(%rsi, %rdx), %r8d
29947 movl %ecx, (%rdi)
29948 movl %r8d, -4(%rdi, %rdx)
29949+ pax_force_retaddr
29950 retq
29951 .p2align 4
29952 .Lless_3bytes:
29953@@ -179,6 +184,7 @@ ENTRY(memcpy)
29954 movb %cl, (%rdi)
29955
29956 .Lend:
29957+ pax_force_retaddr
29958 retq
29959 CFI_ENDPROC
29960 ENDPROC(memcpy)
29961diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29962index 65268a6..dd1de11 100644
29963--- a/arch/x86/lib/memmove_64.S
29964+++ b/arch/x86/lib/memmove_64.S
29965@@ -202,14 +202,16 @@ ENTRY(memmove)
29966 movb (%rsi), %r11b
29967 movb %r11b, (%rdi)
29968 13:
29969+ pax_force_retaddr
29970 retq
29971 CFI_ENDPROC
29972
29973- .section .altinstr_replacement,"ax"
29974+ .section .altinstr_replacement,"a"
29975 .Lmemmove_begin_forward_efs:
29976 /* Forward moving data. */
29977 movq %rdx, %rcx
29978 rep movsb
29979+ pax_force_retaddr
29980 retq
29981 .Lmemmove_end_forward_efs:
29982 .previous
29983diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29984index 2dcb380..2eb79fe 100644
29985--- a/arch/x86/lib/memset_64.S
29986+++ b/arch/x86/lib/memset_64.S
29987@@ -16,7 +16,7 @@
29988 *
29989 * rax original destination
29990 */
29991- .section .altinstr_replacement, "ax", @progbits
29992+ .section .altinstr_replacement, "a", @progbits
29993 .Lmemset_c:
29994 movq %rdi,%r9
29995 movq %rdx,%rcx
29996@@ -30,6 +30,7 @@
29997 movl %edx,%ecx
29998 rep stosb
29999 movq %r9,%rax
30000+ pax_force_retaddr
30001 ret
30002 .Lmemset_e:
30003 .previous
30004@@ -45,13 +46,14 @@
30005 *
30006 * rax original destination
30007 */
30008- .section .altinstr_replacement, "ax", @progbits
30009+ .section .altinstr_replacement, "a", @progbits
30010 .Lmemset_c_e:
30011 movq %rdi,%r9
30012 movb %sil,%al
30013 movq %rdx,%rcx
30014 rep stosb
30015 movq %r9,%rax
30016+ pax_force_retaddr
30017 ret
30018 .Lmemset_e_e:
30019 .previous
30020@@ -118,6 +120,7 @@ ENTRY(__memset)
30021
30022 .Lende:
30023 movq %r10,%rax
30024+ pax_force_retaddr
30025 ret
30026
30027 CFI_RESTORE_STATE
30028diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30029index c9f2d9b..e7fd2c0 100644
30030--- a/arch/x86/lib/mmx_32.c
30031+++ b/arch/x86/lib/mmx_32.c
30032@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30033 {
30034 void *p;
30035 int i;
30036+ unsigned long cr0;
30037
30038 if (unlikely(in_interrupt()))
30039 return __memcpy(to, from, len);
30040@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30041 kernel_fpu_begin();
30042
30043 __asm__ __volatile__ (
30044- "1: prefetch (%0)\n" /* This set is 28 bytes */
30045- " prefetch 64(%0)\n"
30046- " prefetch 128(%0)\n"
30047- " prefetch 192(%0)\n"
30048- " prefetch 256(%0)\n"
30049+ "1: prefetch (%1)\n" /* This set is 28 bytes */
30050+ " prefetch 64(%1)\n"
30051+ " prefetch 128(%1)\n"
30052+ " prefetch 192(%1)\n"
30053+ " prefetch 256(%1)\n"
30054 "2: \n"
30055 ".section .fixup, \"ax\"\n"
30056- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30057+ "3: \n"
30058+
30059+#ifdef CONFIG_PAX_KERNEXEC
30060+ " movl %%cr0, %0\n"
30061+ " movl %0, %%eax\n"
30062+ " andl $0xFFFEFFFF, %%eax\n"
30063+ " movl %%eax, %%cr0\n"
30064+#endif
30065+
30066+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30067+
30068+#ifdef CONFIG_PAX_KERNEXEC
30069+ " movl %0, %%cr0\n"
30070+#endif
30071+
30072 " jmp 2b\n"
30073 ".previous\n"
30074 _ASM_EXTABLE(1b, 3b)
30075- : : "r" (from));
30076+ : "=&r" (cr0) : "r" (from) : "ax");
30077
30078 for ( ; i > 5; i--) {
30079 __asm__ __volatile__ (
30080- "1: prefetch 320(%0)\n"
30081- "2: movq (%0), %%mm0\n"
30082- " movq 8(%0), %%mm1\n"
30083- " movq 16(%0), %%mm2\n"
30084- " movq 24(%0), %%mm3\n"
30085- " movq %%mm0, (%1)\n"
30086- " movq %%mm1, 8(%1)\n"
30087- " movq %%mm2, 16(%1)\n"
30088- " movq %%mm3, 24(%1)\n"
30089- " movq 32(%0), %%mm0\n"
30090- " movq 40(%0), %%mm1\n"
30091- " movq 48(%0), %%mm2\n"
30092- " movq 56(%0), %%mm3\n"
30093- " movq %%mm0, 32(%1)\n"
30094- " movq %%mm1, 40(%1)\n"
30095- " movq %%mm2, 48(%1)\n"
30096- " movq %%mm3, 56(%1)\n"
30097+ "1: prefetch 320(%1)\n"
30098+ "2: movq (%1), %%mm0\n"
30099+ " movq 8(%1), %%mm1\n"
30100+ " movq 16(%1), %%mm2\n"
30101+ " movq 24(%1), %%mm3\n"
30102+ " movq %%mm0, (%2)\n"
30103+ " movq %%mm1, 8(%2)\n"
30104+ " movq %%mm2, 16(%2)\n"
30105+ " movq %%mm3, 24(%2)\n"
30106+ " movq 32(%1), %%mm0\n"
30107+ " movq 40(%1), %%mm1\n"
30108+ " movq 48(%1), %%mm2\n"
30109+ " movq 56(%1), %%mm3\n"
30110+ " movq %%mm0, 32(%2)\n"
30111+ " movq %%mm1, 40(%2)\n"
30112+ " movq %%mm2, 48(%2)\n"
30113+ " movq %%mm3, 56(%2)\n"
30114 ".section .fixup, \"ax\"\n"
30115- "3: movw $0x05EB, 1b\n" /* jmp on 5 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 $0x05EB, 1b\n" /* jmp on 5 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)
30134- : : "r" (from), "r" (to) : "memory");
30135+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30136
30137 from += 64;
30138 to += 64;
30139@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30140 static void fast_copy_page(void *to, void *from)
30141 {
30142 int i;
30143+ unsigned long cr0;
30144
30145 kernel_fpu_begin();
30146
30147@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30148 * but that is for later. -AV
30149 */
30150 __asm__ __volatile__(
30151- "1: prefetch (%0)\n"
30152- " prefetch 64(%0)\n"
30153- " prefetch 128(%0)\n"
30154- " prefetch 192(%0)\n"
30155- " prefetch 256(%0)\n"
30156+ "1: prefetch (%1)\n"
30157+ " prefetch 64(%1)\n"
30158+ " prefetch 128(%1)\n"
30159+ " prefetch 192(%1)\n"
30160+ " prefetch 256(%1)\n"
30161 "2: \n"
30162 ".section .fixup, \"ax\"\n"
30163- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30164+ "3: \n"
30165+
30166+#ifdef CONFIG_PAX_KERNEXEC
30167+ " movl %%cr0, %0\n"
30168+ " movl %0, %%eax\n"
30169+ " andl $0xFFFEFFFF, %%eax\n"
30170+ " movl %%eax, %%cr0\n"
30171+#endif
30172+
30173+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30174+
30175+#ifdef CONFIG_PAX_KERNEXEC
30176+ " movl %0, %%cr0\n"
30177+#endif
30178+
30179 " jmp 2b\n"
30180 ".previous\n"
30181- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30182+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30183
30184 for (i = 0; i < (4096-320)/64; i++) {
30185 __asm__ __volatile__ (
30186- "1: prefetch 320(%0)\n"
30187- "2: movq (%0), %%mm0\n"
30188- " movntq %%mm0, (%1)\n"
30189- " movq 8(%0), %%mm1\n"
30190- " movntq %%mm1, 8(%1)\n"
30191- " movq 16(%0), %%mm2\n"
30192- " movntq %%mm2, 16(%1)\n"
30193- " movq 24(%0), %%mm3\n"
30194- " movntq %%mm3, 24(%1)\n"
30195- " movq 32(%0), %%mm4\n"
30196- " movntq %%mm4, 32(%1)\n"
30197- " movq 40(%0), %%mm5\n"
30198- " movntq %%mm5, 40(%1)\n"
30199- " movq 48(%0), %%mm6\n"
30200- " movntq %%mm6, 48(%1)\n"
30201- " movq 56(%0), %%mm7\n"
30202- " movntq %%mm7, 56(%1)\n"
30203+ "1: prefetch 320(%1)\n"
30204+ "2: movq (%1), %%mm0\n"
30205+ " movntq %%mm0, (%2)\n"
30206+ " movq 8(%1), %%mm1\n"
30207+ " movntq %%mm1, 8(%2)\n"
30208+ " movq 16(%1), %%mm2\n"
30209+ " movntq %%mm2, 16(%2)\n"
30210+ " movq 24(%1), %%mm3\n"
30211+ " movntq %%mm3, 24(%2)\n"
30212+ " movq 32(%1), %%mm4\n"
30213+ " movntq %%mm4, 32(%2)\n"
30214+ " movq 40(%1), %%mm5\n"
30215+ " movntq %%mm5, 40(%2)\n"
30216+ " movq 48(%1), %%mm6\n"
30217+ " movntq %%mm6, 48(%2)\n"
30218+ " movq 56(%1), %%mm7\n"
30219+ " movntq %%mm7, 56(%2)\n"
30220 ".section .fixup, \"ax\"\n"
30221- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30222+ "3:\n"
30223+
30224+#ifdef CONFIG_PAX_KERNEXEC
30225+ " movl %%cr0, %0\n"
30226+ " movl %0, %%eax\n"
30227+ " andl $0xFFFEFFFF, %%eax\n"
30228+ " movl %%eax, %%cr0\n"
30229+#endif
30230+
30231+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30232+
30233+#ifdef CONFIG_PAX_KERNEXEC
30234+ " movl %0, %%cr0\n"
30235+#endif
30236+
30237 " jmp 2b\n"
30238 ".previous\n"
30239- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30240+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30241
30242 from += 64;
30243 to += 64;
30244@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30245 static void fast_copy_page(void *to, void *from)
30246 {
30247 int i;
30248+ unsigned long cr0;
30249
30250 kernel_fpu_begin();
30251
30252 __asm__ __volatile__ (
30253- "1: prefetch (%0)\n"
30254- " prefetch 64(%0)\n"
30255- " prefetch 128(%0)\n"
30256- " prefetch 192(%0)\n"
30257- " prefetch 256(%0)\n"
30258+ "1: prefetch (%1)\n"
30259+ " prefetch 64(%1)\n"
30260+ " prefetch 128(%1)\n"
30261+ " prefetch 192(%1)\n"
30262+ " prefetch 256(%1)\n"
30263 "2: \n"
30264 ".section .fixup, \"ax\"\n"
30265- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30266+ "3: \n"
30267+
30268+#ifdef CONFIG_PAX_KERNEXEC
30269+ " movl %%cr0, %0\n"
30270+ " movl %0, %%eax\n"
30271+ " andl $0xFFFEFFFF, %%eax\n"
30272+ " movl %%eax, %%cr0\n"
30273+#endif
30274+
30275+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30276+
30277+#ifdef CONFIG_PAX_KERNEXEC
30278+ " movl %0, %%cr0\n"
30279+#endif
30280+
30281 " jmp 2b\n"
30282 ".previous\n"
30283- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30284+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30285
30286 for (i = 0; i < 4096/64; i++) {
30287 __asm__ __volatile__ (
30288- "1: prefetch 320(%0)\n"
30289- "2: movq (%0), %%mm0\n"
30290- " movq 8(%0), %%mm1\n"
30291- " movq 16(%0), %%mm2\n"
30292- " movq 24(%0), %%mm3\n"
30293- " movq %%mm0, (%1)\n"
30294- " movq %%mm1, 8(%1)\n"
30295- " movq %%mm2, 16(%1)\n"
30296- " movq %%mm3, 24(%1)\n"
30297- " movq 32(%0), %%mm0\n"
30298- " movq 40(%0), %%mm1\n"
30299- " movq 48(%0), %%mm2\n"
30300- " movq 56(%0), %%mm3\n"
30301- " movq %%mm0, 32(%1)\n"
30302- " movq %%mm1, 40(%1)\n"
30303- " movq %%mm2, 48(%1)\n"
30304- " movq %%mm3, 56(%1)\n"
30305+ "1: prefetch 320(%1)\n"
30306+ "2: movq (%1), %%mm0\n"
30307+ " movq 8(%1), %%mm1\n"
30308+ " movq 16(%1), %%mm2\n"
30309+ " movq 24(%1), %%mm3\n"
30310+ " movq %%mm0, (%2)\n"
30311+ " movq %%mm1, 8(%2)\n"
30312+ " movq %%mm2, 16(%2)\n"
30313+ " movq %%mm3, 24(%2)\n"
30314+ " movq 32(%1), %%mm0\n"
30315+ " movq 40(%1), %%mm1\n"
30316+ " movq 48(%1), %%mm2\n"
30317+ " movq 56(%1), %%mm3\n"
30318+ " movq %%mm0, 32(%2)\n"
30319+ " movq %%mm1, 40(%2)\n"
30320+ " movq %%mm2, 48(%2)\n"
30321+ " movq %%mm3, 56(%2)\n"
30322 ".section .fixup, \"ax\"\n"
30323- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30324+ "3:\n"
30325+
30326+#ifdef CONFIG_PAX_KERNEXEC
30327+ " movl %%cr0, %0\n"
30328+ " movl %0, %%eax\n"
30329+ " andl $0xFFFEFFFF, %%eax\n"
30330+ " movl %%eax, %%cr0\n"
30331+#endif
30332+
30333+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30334+
30335+#ifdef CONFIG_PAX_KERNEXEC
30336+ " movl %0, %%cr0\n"
30337+#endif
30338+
30339 " jmp 2b\n"
30340 ".previous\n"
30341 _ASM_EXTABLE(1b, 3b)
30342- : : "r" (from), "r" (to) : "memory");
30343+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30344
30345 from += 64;
30346 to += 64;
30347diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30348index f6d13ee..d789440 100644
30349--- a/arch/x86/lib/msr-reg.S
30350+++ b/arch/x86/lib/msr-reg.S
30351@@ -3,6 +3,7 @@
30352 #include <asm/dwarf2.h>
30353 #include <asm/asm.h>
30354 #include <asm/msr.h>
30355+#include <asm/alternative-asm.h>
30356
30357 #ifdef CONFIG_X86_64
30358 /*
30359@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30360 movl %edi, 28(%r10)
30361 popq_cfi %rbp
30362 popq_cfi %rbx
30363+ pax_force_retaddr
30364 ret
30365 3:
30366 CFI_RESTORE_STATE
30367diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30368index fc6ba17..d4d989d 100644
30369--- a/arch/x86/lib/putuser.S
30370+++ b/arch/x86/lib/putuser.S
30371@@ -16,7 +16,9 @@
30372 #include <asm/errno.h>
30373 #include <asm/asm.h>
30374 #include <asm/smap.h>
30375-
30376+#include <asm/segment.h>
30377+#include <asm/pgtable.h>
30378+#include <asm/alternative-asm.h>
30379
30380 /*
30381 * __put_user_X
30382@@ -30,57 +32,125 @@
30383 * as they get called from within inline assembly.
30384 */
30385
30386-#define ENTER CFI_STARTPROC ; \
30387- GET_THREAD_INFO(%_ASM_BX)
30388-#define EXIT ASM_CLAC ; \
30389- ret ; \
30390+#define ENTER CFI_STARTPROC
30391+#define EXIT ASM_CLAC ; \
30392+ pax_force_retaddr ; \
30393+ ret ; \
30394 CFI_ENDPROC
30395
30396+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30397+#define _DEST %_ASM_CX,%_ASM_BX
30398+#else
30399+#define _DEST %_ASM_CX
30400+#endif
30401+
30402+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30403+#define __copyuser_seg gs;
30404+#else
30405+#define __copyuser_seg
30406+#endif
30407+
30408 .text
30409 ENTRY(__put_user_1)
30410 ENTER
30411+
30412+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30413+ GET_THREAD_INFO(%_ASM_BX)
30414 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30415 jae bad_put_user
30416 ASM_STAC
30417-1: movb %al,(%_ASM_CX)
30418+
30419+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30420+ mov pax_user_shadow_base,%_ASM_BX
30421+ cmp %_ASM_BX,%_ASM_CX
30422+ jb 1234f
30423+ xor %ebx,%ebx
30424+1234:
30425+#endif
30426+
30427+#endif
30428+
30429+1: __copyuser_seg movb %al,(_DEST)
30430 xor %eax,%eax
30431 EXIT
30432 ENDPROC(__put_user_1)
30433
30434 ENTRY(__put_user_2)
30435 ENTER
30436+
30437+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30438+ GET_THREAD_INFO(%_ASM_BX)
30439 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30440 sub $1,%_ASM_BX
30441 cmp %_ASM_BX,%_ASM_CX
30442 jae bad_put_user
30443 ASM_STAC
30444-2: movw %ax,(%_ASM_CX)
30445+
30446+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30447+ mov pax_user_shadow_base,%_ASM_BX
30448+ cmp %_ASM_BX,%_ASM_CX
30449+ jb 1234f
30450+ xor %ebx,%ebx
30451+1234:
30452+#endif
30453+
30454+#endif
30455+
30456+2: __copyuser_seg movw %ax,(_DEST)
30457 xor %eax,%eax
30458 EXIT
30459 ENDPROC(__put_user_2)
30460
30461 ENTRY(__put_user_4)
30462 ENTER
30463+
30464+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30465+ GET_THREAD_INFO(%_ASM_BX)
30466 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30467 sub $3,%_ASM_BX
30468 cmp %_ASM_BX,%_ASM_CX
30469 jae bad_put_user
30470 ASM_STAC
30471-3: movl %eax,(%_ASM_CX)
30472+
30473+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30474+ mov pax_user_shadow_base,%_ASM_BX
30475+ cmp %_ASM_BX,%_ASM_CX
30476+ jb 1234f
30477+ xor %ebx,%ebx
30478+1234:
30479+#endif
30480+
30481+#endif
30482+
30483+3: __copyuser_seg movl %eax,(_DEST)
30484 xor %eax,%eax
30485 EXIT
30486 ENDPROC(__put_user_4)
30487
30488 ENTRY(__put_user_8)
30489 ENTER
30490+
30491+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30492+ GET_THREAD_INFO(%_ASM_BX)
30493 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30494 sub $7,%_ASM_BX
30495 cmp %_ASM_BX,%_ASM_CX
30496 jae bad_put_user
30497 ASM_STAC
30498-4: mov %_ASM_AX,(%_ASM_CX)
30499+
30500+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30501+ mov pax_user_shadow_base,%_ASM_BX
30502+ cmp %_ASM_BX,%_ASM_CX
30503+ jb 1234f
30504+ xor %ebx,%ebx
30505+1234:
30506+#endif
30507+
30508+#endif
30509+
30510+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30511 #ifdef CONFIG_X86_32
30512-5: movl %edx,4(%_ASM_CX)
30513+5: __copyuser_seg movl %edx,4(_DEST)
30514 #endif
30515 xor %eax,%eax
30516 EXIT
30517diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30518index 1cad221..de671ee 100644
30519--- a/arch/x86/lib/rwlock.S
30520+++ b/arch/x86/lib/rwlock.S
30521@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30522 FRAME
30523 0: LOCK_PREFIX
30524 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30525+
30526+#ifdef CONFIG_PAX_REFCOUNT
30527+ jno 1234f
30528+ LOCK_PREFIX
30529+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30530+ int $4
30531+1234:
30532+ _ASM_EXTABLE(1234b, 1234b)
30533+#endif
30534+
30535 1: rep; nop
30536 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30537 jne 1b
30538 LOCK_PREFIX
30539 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30540+
30541+#ifdef CONFIG_PAX_REFCOUNT
30542+ jno 1234f
30543+ LOCK_PREFIX
30544+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30545+ int $4
30546+1234:
30547+ _ASM_EXTABLE(1234b, 1234b)
30548+#endif
30549+
30550 jnz 0b
30551 ENDFRAME
30552+ pax_force_retaddr
30553 ret
30554 CFI_ENDPROC
30555 END(__write_lock_failed)
30556@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30557 FRAME
30558 0: LOCK_PREFIX
30559 READ_LOCK_SIZE(inc) (%__lock_ptr)
30560+
30561+#ifdef CONFIG_PAX_REFCOUNT
30562+ jno 1234f
30563+ LOCK_PREFIX
30564+ READ_LOCK_SIZE(dec) (%__lock_ptr)
30565+ int $4
30566+1234:
30567+ _ASM_EXTABLE(1234b, 1234b)
30568+#endif
30569+
30570 1: rep; nop
30571 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30572 js 1b
30573 LOCK_PREFIX
30574 READ_LOCK_SIZE(dec) (%__lock_ptr)
30575+
30576+#ifdef CONFIG_PAX_REFCOUNT
30577+ jno 1234f
30578+ LOCK_PREFIX
30579+ READ_LOCK_SIZE(inc) (%__lock_ptr)
30580+ int $4
30581+1234:
30582+ _ASM_EXTABLE(1234b, 1234b)
30583+#endif
30584+
30585 js 0b
30586 ENDFRAME
30587+ pax_force_retaddr
30588 ret
30589 CFI_ENDPROC
30590 END(__read_lock_failed)
30591diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30592index 5dff5f0..cadebf4 100644
30593--- a/arch/x86/lib/rwsem.S
30594+++ b/arch/x86/lib/rwsem.S
30595@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30596 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30597 CFI_RESTORE __ASM_REG(dx)
30598 restore_common_regs
30599+ pax_force_retaddr
30600 ret
30601 CFI_ENDPROC
30602 ENDPROC(call_rwsem_down_read_failed)
30603@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30604 movq %rax,%rdi
30605 call rwsem_down_write_failed
30606 restore_common_regs
30607+ pax_force_retaddr
30608 ret
30609 CFI_ENDPROC
30610 ENDPROC(call_rwsem_down_write_failed)
30611@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30612 movq %rax,%rdi
30613 call rwsem_wake
30614 restore_common_regs
30615-1: ret
30616+1: pax_force_retaddr
30617+ ret
30618 CFI_ENDPROC
30619 ENDPROC(call_rwsem_wake)
30620
30621@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30622 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30623 CFI_RESTORE __ASM_REG(dx)
30624 restore_common_regs
30625+ pax_force_retaddr
30626 ret
30627 CFI_ENDPROC
30628 ENDPROC(call_rwsem_downgrade_wake)
30629diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30630index a63efd6..8149fbe 100644
30631--- a/arch/x86/lib/thunk_64.S
30632+++ b/arch/x86/lib/thunk_64.S
30633@@ -8,6 +8,7 @@
30634 #include <linux/linkage.h>
30635 #include <asm/dwarf2.h>
30636 #include <asm/calling.h>
30637+#include <asm/alternative-asm.h>
30638
30639 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30640 .macro THUNK name, func, put_ret_addr_in_rdi=0
30641@@ -15,11 +16,11 @@
30642 \name:
30643 CFI_STARTPROC
30644
30645- /* this one pushes 9 elems, the next one would be %rIP */
30646- SAVE_ARGS
30647+ /* this one pushes 15+1 elems, the next one would be %rIP */
30648+ SAVE_ARGS 8
30649
30650 .if \put_ret_addr_in_rdi
30651- movq_cfi_restore 9*8, rdi
30652+ movq_cfi_restore RIP, rdi
30653 .endif
30654
30655 call \func
30656@@ -38,8 +39,9 @@
30657
30658 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30659 CFI_STARTPROC
30660- SAVE_ARGS
30661+ SAVE_ARGS 8
30662 restore:
30663- RESTORE_ARGS
30664+ RESTORE_ARGS 1,8
30665+ pax_force_retaddr
30666 ret
30667 CFI_ENDPROC
30668diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30669index e2f5e21..4b22130 100644
30670--- a/arch/x86/lib/usercopy_32.c
30671+++ b/arch/x86/lib/usercopy_32.c
30672@@ -42,11 +42,13 @@ do { \
30673 int __d0; \
30674 might_fault(); \
30675 __asm__ __volatile__( \
30676+ __COPYUSER_SET_ES \
30677 ASM_STAC "\n" \
30678 "0: rep; stosl\n" \
30679 " movl %2,%0\n" \
30680 "1: rep; stosb\n" \
30681 "2: " ASM_CLAC "\n" \
30682+ __COPYUSER_RESTORE_ES \
30683 ".section .fixup,\"ax\"\n" \
30684 "3: lea 0(%2,%0,4),%0\n" \
30685 " jmp 2b\n" \
30686@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30687
30688 #ifdef CONFIG_X86_INTEL_USERCOPY
30689 static unsigned long
30690-__copy_user_intel(void __user *to, const void *from, unsigned long size)
30691+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30692 {
30693 int d0, d1;
30694 __asm__ __volatile__(
30695@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30696 " .align 2,0x90\n"
30697 "3: movl 0(%4), %%eax\n"
30698 "4: movl 4(%4), %%edx\n"
30699- "5: movl %%eax, 0(%3)\n"
30700- "6: movl %%edx, 4(%3)\n"
30701+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30702+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30703 "7: movl 8(%4), %%eax\n"
30704 "8: movl 12(%4),%%edx\n"
30705- "9: movl %%eax, 8(%3)\n"
30706- "10: movl %%edx, 12(%3)\n"
30707+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30708+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30709 "11: movl 16(%4), %%eax\n"
30710 "12: movl 20(%4), %%edx\n"
30711- "13: movl %%eax, 16(%3)\n"
30712- "14: movl %%edx, 20(%3)\n"
30713+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30714+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30715 "15: movl 24(%4), %%eax\n"
30716 "16: movl 28(%4), %%edx\n"
30717- "17: movl %%eax, 24(%3)\n"
30718- "18: movl %%edx, 28(%3)\n"
30719+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30720+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30721 "19: movl 32(%4), %%eax\n"
30722 "20: movl 36(%4), %%edx\n"
30723- "21: movl %%eax, 32(%3)\n"
30724- "22: movl %%edx, 36(%3)\n"
30725+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30726+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30727 "23: movl 40(%4), %%eax\n"
30728 "24: movl 44(%4), %%edx\n"
30729- "25: movl %%eax, 40(%3)\n"
30730- "26: movl %%edx, 44(%3)\n"
30731+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30732+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30733 "27: movl 48(%4), %%eax\n"
30734 "28: movl 52(%4), %%edx\n"
30735- "29: movl %%eax, 48(%3)\n"
30736- "30: movl %%edx, 52(%3)\n"
30737+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30738+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30739 "31: movl 56(%4), %%eax\n"
30740 "32: movl 60(%4), %%edx\n"
30741- "33: movl %%eax, 56(%3)\n"
30742- "34: movl %%edx, 60(%3)\n"
30743+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30744+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30745 " addl $-64, %0\n"
30746 " addl $64, %4\n"
30747 " addl $64, %3\n"
30748@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30749 " shrl $2, %0\n"
30750 " andl $3, %%eax\n"
30751 " cld\n"
30752+ __COPYUSER_SET_ES
30753 "99: rep; movsl\n"
30754 "36: movl %%eax, %0\n"
30755 "37: rep; movsb\n"
30756 "100:\n"
30757+ __COPYUSER_RESTORE_ES
30758+ ".section .fixup,\"ax\"\n"
30759+ "101: lea 0(%%eax,%0,4),%0\n"
30760+ " jmp 100b\n"
30761+ ".previous\n"
30762+ _ASM_EXTABLE(1b,100b)
30763+ _ASM_EXTABLE(2b,100b)
30764+ _ASM_EXTABLE(3b,100b)
30765+ _ASM_EXTABLE(4b,100b)
30766+ _ASM_EXTABLE(5b,100b)
30767+ _ASM_EXTABLE(6b,100b)
30768+ _ASM_EXTABLE(7b,100b)
30769+ _ASM_EXTABLE(8b,100b)
30770+ _ASM_EXTABLE(9b,100b)
30771+ _ASM_EXTABLE(10b,100b)
30772+ _ASM_EXTABLE(11b,100b)
30773+ _ASM_EXTABLE(12b,100b)
30774+ _ASM_EXTABLE(13b,100b)
30775+ _ASM_EXTABLE(14b,100b)
30776+ _ASM_EXTABLE(15b,100b)
30777+ _ASM_EXTABLE(16b,100b)
30778+ _ASM_EXTABLE(17b,100b)
30779+ _ASM_EXTABLE(18b,100b)
30780+ _ASM_EXTABLE(19b,100b)
30781+ _ASM_EXTABLE(20b,100b)
30782+ _ASM_EXTABLE(21b,100b)
30783+ _ASM_EXTABLE(22b,100b)
30784+ _ASM_EXTABLE(23b,100b)
30785+ _ASM_EXTABLE(24b,100b)
30786+ _ASM_EXTABLE(25b,100b)
30787+ _ASM_EXTABLE(26b,100b)
30788+ _ASM_EXTABLE(27b,100b)
30789+ _ASM_EXTABLE(28b,100b)
30790+ _ASM_EXTABLE(29b,100b)
30791+ _ASM_EXTABLE(30b,100b)
30792+ _ASM_EXTABLE(31b,100b)
30793+ _ASM_EXTABLE(32b,100b)
30794+ _ASM_EXTABLE(33b,100b)
30795+ _ASM_EXTABLE(34b,100b)
30796+ _ASM_EXTABLE(35b,100b)
30797+ _ASM_EXTABLE(36b,100b)
30798+ _ASM_EXTABLE(37b,100b)
30799+ _ASM_EXTABLE(99b,101b)
30800+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
30801+ : "1"(to), "2"(from), "0"(size)
30802+ : "eax", "edx", "memory");
30803+ return size;
30804+}
30805+
30806+static unsigned long
30807+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30808+{
30809+ int d0, d1;
30810+ __asm__ __volatile__(
30811+ " .align 2,0x90\n"
30812+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30813+ " cmpl $67, %0\n"
30814+ " jbe 3f\n"
30815+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30816+ " .align 2,0x90\n"
30817+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30818+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30819+ "5: movl %%eax, 0(%3)\n"
30820+ "6: movl %%edx, 4(%3)\n"
30821+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30822+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30823+ "9: movl %%eax, 8(%3)\n"
30824+ "10: movl %%edx, 12(%3)\n"
30825+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30826+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30827+ "13: movl %%eax, 16(%3)\n"
30828+ "14: movl %%edx, 20(%3)\n"
30829+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30830+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30831+ "17: movl %%eax, 24(%3)\n"
30832+ "18: movl %%edx, 28(%3)\n"
30833+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30834+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30835+ "21: movl %%eax, 32(%3)\n"
30836+ "22: movl %%edx, 36(%3)\n"
30837+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30838+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30839+ "25: movl %%eax, 40(%3)\n"
30840+ "26: movl %%edx, 44(%3)\n"
30841+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30842+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30843+ "29: movl %%eax, 48(%3)\n"
30844+ "30: movl %%edx, 52(%3)\n"
30845+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30846+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30847+ "33: movl %%eax, 56(%3)\n"
30848+ "34: movl %%edx, 60(%3)\n"
30849+ " addl $-64, %0\n"
30850+ " addl $64, %4\n"
30851+ " addl $64, %3\n"
30852+ " cmpl $63, %0\n"
30853+ " ja 1b\n"
30854+ "35: movl %0, %%eax\n"
30855+ " shrl $2, %0\n"
30856+ " andl $3, %%eax\n"
30857+ " cld\n"
30858+ "99: rep; "__copyuser_seg" movsl\n"
30859+ "36: movl %%eax, %0\n"
30860+ "37: rep; "__copyuser_seg" movsb\n"
30861+ "100:\n"
30862 ".section .fixup,\"ax\"\n"
30863 "101: lea 0(%%eax,%0,4),%0\n"
30864 " jmp 100b\n"
30865@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30866 int d0, d1;
30867 __asm__ __volatile__(
30868 " .align 2,0x90\n"
30869- "0: movl 32(%4), %%eax\n"
30870+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30871 " cmpl $67, %0\n"
30872 " jbe 2f\n"
30873- "1: movl 64(%4), %%eax\n"
30874+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30875 " .align 2,0x90\n"
30876- "2: movl 0(%4), %%eax\n"
30877- "21: movl 4(%4), %%edx\n"
30878+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30879+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30880 " movl %%eax, 0(%3)\n"
30881 " movl %%edx, 4(%3)\n"
30882- "3: movl 8(%4), %%eax\n"
30883- "31: movl 12(%4),%%edx\n"
30884+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30885+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30886 " movl %%eax, 8(%3)\n"
30887 " movl %%edx, 12(%3)\n"
30888- "4: movl 16(%4), %%eax\n"
30889- "41: movl 20(%4), %%edx\n"
30890+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30891+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30892 " movl %%eax, 16(%3)\n"
30893 " movl %%edx, 20(%3)\n"
30894- "10: movl 24(%4), %%eax\n"
30895- "51: movl 28(%4), %%edx\n"
30896+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30897+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30898 " movl %%eax, 24(%3)\n"
30899 " movl %%edx, 28(%3)\n"
30900- "11: movl 32(%4), %%eax\n"
30901- "61: movl 36(%4), %%edx\n"
30902+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30903+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30904 " movl %%eax, 32(%3)\n"
30905 " movl %%edx, 36(%3)\n"
30906- "12: movl 40(%4), %%eax\n"
30907- "71: movl 44(%4), %%edx\n"
30908+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30909+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30910 " movl %%eax, 40(%3)\n"
30911 " movl %%edx, 44(%3)\n"
30912- "13: movl 48(%4), %%eax\n"
30913- "81: movl 52(%4), %%edx\n"
30914+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30915+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30916 " movl %%eax, 48(%3)\n"
30917 " movl %%edx, 52(%3)\n"
30918- "14: movl 56(%4), %%eax\n"
30919- "91: movl 60(%4), %%edx\n"
30920+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30921+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30922 " movl %%eax, 56(%3)\n"
30923 " movl %%edx, 60(%3)\n"
30924 " addl $-64, %0\n"
30925@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30926 " shrl $2, %0\n"
30927 " andl $3, %%eax\n"
30928 " cld\n"
30929- "6: rep; movsl\n"
30930+ "6: rep; "__copyuser_seg" movsl\n"
30931 " movl %%eax,%0\n"
30932- "7: rep; movsb\n"
30933+ "7: rep; "__copyuser_seg" movsb\n"
30934 "8:\n"
30935 ".section .fixup,\"ax\"\n"
30936 "9: lea 0(%%eax,%0,4),%0\n"
30937@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30938
30939 __asm__ __volatile__(
30940 " .align 2,0x90\n"
30941- "0: movl 32(%4), %%eax\n"
30942+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30943 " cmpl $67, %0\n"
30944 " jbe 2f\n"
30945- "1: movl 64(%4), %%eax\n"
30946+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30947 " .align 2,0x90\n"
30948- "2: movl 0(%4), %%eax\n"
30949- "21: movl 4(%4), %%edx\n"
30950+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30951+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30952 " movnti %%eax, 0(%3)\n"
30953 " movnti %%edx, 4(%3)\n"
30954- "3: movl 8(%4), %%eax\n"
30955- "31: movl 12(%4),%%edx\n"
30956+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30957+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30958 " movnti %%eax, 8(%3)\n"
30959 " movnti %%edx, 12(%3)\n"
30960- "4: movl 16(%4), %%eax\n"
30961- "41: movl 20(%4), %%edx\n"
30962+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30963+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30964 " movnti %%eax, 16(%3)\n"
30965 " movnti %%edx, 20(%3)\n"
30966- "10: movl 24(%4), %%eax\n"
30967- "51: movl 28(%4), %%edx\n"
30968+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30969+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30970 " movnti %%eax, 24(%3)\n"
30971 " movnti %%edx, 28(%3)\n"
30972- "11: movl 32(%4), %%eax\n"
30973- "61: movl 36(%4), %%edx\n"
30974+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30975+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30976 " movnti %%eax, 32(%3)\n"
30977 " movnti %%edx, 36(%3)\n"
30978- "12: movl 40(%4), %%eax\n"
30979- "71: movl 44(%4), %%edx\n"
30980+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30981+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30982 " movnti %%eax, 40(%3)\n"
30983 " movnti %%edx, 44(%3)\n"
30984- "13: movl 48(%4), %%eax\n"
30985- "81: movl 52(%4), %%edx\n"
30986+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30987+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30988 " movnti %%eax, 48(%3)\n"
30989 " movnti %%edx, 52(%3)\n"
30990- "14: movl 56(%4), %%eax\n"
30991- "91: movl 60(%4), %%edx\n"
30992+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30993+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30994 " movnti %%eax, 56(%3)\n"
30995 " movnti %%edx, 60(%3)\n"
30996 " addl $-64, %0\n"
30997@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30998 " shrl $2, %0\n"
30999 " andl $3, %%eax\n"
31000 " cld\n"
31001- "6: rep; movsl\n"
31002+ "6: rep; "__copyuser_seg" movsl\n"
31003 " movl %%eax,%0\n"
31004- "7: rep; movsb\n"
31005+ "7: rep; "__copyuser_seg" movsb\n"
31006 "8:\n"
31007 ".section .fixup,\"ax\"\n"
31008 "9: lea 0(%%eax,%0,4),%0\n"
31009@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31010
31011 __asm__ __volatile__(
31012 " .align 2,0x90\n"
31013- "0: movl 32(%4), %%eax\n"
31014+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31015 " cmpl $67, %0\n"
31016 " jbe 2f\n"
31017- "1: movl 64(%4), %%eax\n"
31018+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31019 " .align 2,0x90\n"
31020- "2: movl 0(%4), %%eax\n"
31021- "21: movl 4(%4), %%edx\n"
31022+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31023+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31024 " movnti %%eax, 0(%3)\n"
31025 " movnti %%edx, 4(%3)\n"
31026- "3: movl 8(%4), %%eax\n"
31027- "31: movl 12(%4),%%edx\n"
31028+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31029+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31030 " movnti %%eax, 8(%3)\n"
31031 " movnti %%edx, 12(%3)\n"
31032- "4: movl 16(%4), %%eax\n"
31033- "41: movl 20(%4), %%edx\n"
31034+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31035+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31036 " movnti %%eax, 16(%3)\n"
31037 " movnti %%edx, 20(%3)\n"
31038- "10: movl 24(%4), %%eax\n"
31039- "51: movl 28(%4), %%edx\n"
31040+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31041+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31042 " movnti %%eax, 24(%3)\n"
31043 " movnti %%edx, 28(%3)\n"
31044- "11: movl 32(%4), %%eax\n"
31045- "61: movl 36(%4), %%edx\n"
31046+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31047+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31048 " movnti %%eax, 32(%3)\n"
31049 " movnti %%edx, 36(%3)\n"
31050- "12: movl 40(%4), %%eax\n"
31051- "71: movl 44(%4), %%edx\n"
31052+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31053+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31054 " movnti %%eax, 40(%3)\n"
31055 " movnti %%edx, 44(%3)\n"
31056- "13: movl 48(%4), %%eax\n"
31057- "81: movl 52(%4), %%edx\n"
31058+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31059+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31060 " movnti %%eax, 48(%3)\n"
31061 " movnti %%edx, 52(%3)\n"
31062- "14: movl 56(%4), %%eax\n"
31063- "91: movl 60(%4), %%edx\n"
31064+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31065+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31066 " movnti %%eax, 56(%3)\n"
31067 " movnti %%edx, 60(%3)\n"
31068 " addl $-64, %0\n"
31069@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31070 " shrl $2, %0\n"
31071 " andl $3, %%eax\n"
31072 " cld\n"
31073- "6: rep; movsl\n"
31074+ "6: rep; "__copyuser_seg" movsl\n"
31075 " movl %%eax,%0\n"
31076- "7: rep; movsb\n"
31077+ "7: rep; "__copyuser_seg" movsb\n"
31078 "8:\n"
31079 ".section .fixup,\"ax\"\n"
31080 "9: lea 0(%%eax,%0,4),%0\n"
31081@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31082 */
31083 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31084 unsigned long size);
31085-unsigned long __copy_user_intel(void __user *to, const void *from,
31086+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31087+ unsigned long size);
31088+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31089 unsigned long size);
31090 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31091 const void __user *from, unsigned long size);
31092 #endif /* CONFIG_X86_INTEL_USERCOPY */
31093
31094 /* Generic arbitrary sized copy. */
31095-#define __copy_user(to, from, size) \
31096+#define __copy_user(to, from, size, prefix, set, restore) \
31097 do { \
31098 int __d0, __d1, __d2; \
31099 __asm__ __volatile__( \
31100+ set \
31101 " cmp $7,%0\n" \
31102 " jbe 1f\n" \
31103 " movl %1,%0\n" \
31104 " negl %0\n" \
31105 " andl $7,%0\n" \
31106 " subl %0,%3\n" \
31107- "4: rep; movsb\n" \
31108+ "4: rep; "prefix"movsb\n" \
31109 " movl %3,%0\n" \
31110 " shrl $2,%0\n" \
31111 " andl $3,%3\n" \
31112 " .align 2,0x90\n" \
31113- "0: rep; movsl\n" \
31114+ "0: rep; "prefix"movsl\n" \
31115 " movl %3,%0\n" \
31116- "1: rep; movsb\n" \
31117+ "1: rep; "prefix"movsb\n" \
31118 "2:\n" \
31119+ restore \
31120 ".section .fixup,\"ax\"\n" \
31121 "5: addl %3,%0\n" \
31122 " jmp 2b\n" \
31123@@ -538,14 +650,14 @@ do { \
31124 " negl %0\n" \
31125 " andl $7,%0\n" \
31126 " subl %0,%3\n" \
31127- "4: rep; movsb\n" \
31128+ "4: rep; "__copyuser_seg"movsb\n" \
31129 " movl %3,%0\n" \
31130 " shrl $2,%0\n" \
31131 " andl $3,%3\n" \
31132 " .align 2,0x90\n" \
31133- "0: rep; movsl\n" \
31134+ "0: rep; "__copyuser_seg"movsl\n" \
31135 " movl %3,%0\n" \
31136- "1: rep; movsb\n" \
31137+ "1: rep; "__copyuser_seg"movsb\n" \
31138 "2:\n" \
31139 ".section .fixup,\"ax\"\n" \
31140 "5: addl %3,%0\n" \
31141@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31142 {
31143 stac();
31144 if (movsl_is_ok(to, from, n))
31145- __copy_user(to, from, n);
31146+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31147 else
31148- n = __copy_user_intel(to, from, n);
31149+ n = __generic_copy_to_user_intel(to, from, n);
31150 clac();
31151 return n;
31152 }
31153@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31154 {
31155 stac();
31156 if (movsl_is_ok(to, from, n))
31157- __copy_user(to, from, n);
31158+ __copy_user(to, from, n, __copyuser_seg, "", "");
31159 else
31160- n = __copy_user_intel((void __user *)to,
31161- (const void *)from, n);
31162+ n = __generic_copy_from_user_intel(to, from, n);
31163 clac();
31164 return n;
31165 }
31166@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31167 if (n > 64 && cpu_has_xmm2)
31168 n = __copy_user_intel_nocache(to, from, n);
31169 else
31170- __copy_user(to, from, n);
31171+ __copy_user(to, from, n, __copyuser_seg, "", "");
31172 #else
31173- __copy_user(to, from, n);
31174+ __copy_user(to, from, n, __copyuser_seg, "", "");
31175 #endif
31176 clac();
31177 return n;
31178 }
31179 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31180
31181-/**
31182- * copy_to_user: - Copy a block of data into user space.
31183- * @to: Destination address, in user space.
31184- * @from: Source address, in kernel space.
31185- * @n: Number of bytes to copy.
31186- *
31187- * Context: User context only. This function may sleep.
31188- *
31189- * Copy data from kernel space to user space.
31190- *
31191- * Returns number of bytes that could not be copied.
31192- * On success, this will be zero.
31193- */
31194-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31195+#ifdef CONFIG_PAX_MEMORY_UDEREF
31196+void __set_fs(mm_segment_t x)
31197 {
31198- if (access_ok(VERIFY_WRITE, to, n))
31199- n = __copy_to_user(to, from, n);
31200- return n;
31201+ switch (x.seg) {
31202+ case 0:
31203+ loadsegment(gs, 0);
31204+ break;
31205+ case TASK_SIZE_MAX:
31206+ loadsegment(gs, __USER_DS);
31207+ break;
31208+ case -1UL:
31209+ loadsegment(gs, __KERNEL_DS);
31210+ break;
31211+ default:
31212+ BUG();
31213+ }
31214 }
31215-EXPORT_SYMBOL(_copy_to_user);
31216+EXPORT_SYMBOL(__set_fs);
31217
31218-/**
31219- * copy_from_user: - Copy a block of data from user space.
31220- * @to: Destination address, in kernel space.
31221- * @from: Source address, in user space.
31222- * @n: Number of bytes to copy.
31223- *
31224- * Context: User context only. This function may sleep.
31225- *
31226- * Copy data from user space to kernel space.
31227- *
31228- * Returns number of bytes that could not be copied.
31229- * On success, this will be zero.
31230- *
31231- * If some data could not be copied, this function will pad the copied
31232- * data to the requested size using zero bytes.
31233- */
31234-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31235+void set_fs(mm_segment_t x)
31236 {
31237- if (access_ok(VERIFY_READ, from, n))
31238- n = __copy_from_user(to, from, n);
31239- else
31240- memset(to, 0, n);
31241- return n;
31242+ current_thread_info()->addr_limit = x;
31243+ __set_fs(x);
31244 }
31245-EXPORT_SYMBOL(_copy_from_user);
31246+EXPORT_SYMBOL(set_fs);
31247+#endif
31248diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31249index c905e89..01ab928 100644
31250--- a/arch/x86/lib/usercopy_64.c
31251+++ b/arch/x86/lib/usercopy_64.c
31252@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31253 might_fault();
31254 /* no memory constraint because it doesn't change any memory gcc knows
31255 about */
31256+ pax_open_userland();
31257 stac();
31258 asm volatile(
31259 " testq %[size8],%[size8]\n"
31260@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31261 _ASM_EXTABLE(0b,3b)
31262 _ASM_EXTABLE(1b,2b)
31263 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31264- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31265+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31266 [zero] "r" (0UL), [eight] "r" (8UL));
31267 clac();
31268+ pax_close_userland();
31269 return size;
31270 }
31271 EXPORT_SYMBOL(__clear_user);
31272@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31273 }
31274 EXPORT_SYMBOL(clear_user);
31275
31276-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31277+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31278 {
31279- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31280- return copy_user_generic((__force void *)to, (__force void *)from, len);
31281- }
31282- return len;
31283+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31284+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31285+ return len;
31286 }
31287 EXPORT_SYMBOL(copy_in_user);
31288
31289@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31290 * it is not necessary to optimize tail handling.
31291 */
31292 __visible unsigned long
31293-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31294+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31295 {
31296 char c;
31297 unsigned zero_len;
31298
31299+ clac();
31300+ pax_close_userland();
31301 for (; len; --len, to++) {
31302 if (__get_user_nocheck(c, from++, sizeof(char)))
31303 break;
31304@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31305 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31306 if (__put_user_nocheck(c, to++, sizeof(char)))
31307 break;
31308- clac();
31309 return len;
31310 }
31311diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31312index 6a19ad9..1c48f9a 100644
31313--- a/arch/x86/mm/Makefile
31314+++ b/arch/x86/mm/Makefile
31315@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31316 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31317
31318 obj-$(CONFIG_MEMTEST) += memtest.o
31319+
31320+quote:="
31321+obj-$(CONFIG_X86_64) += uderef_64.o
31322+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31323diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31324index 903ec1e..c4166b2 100644
31325--- a/arch/x86/mm/extable.c
31326+++ b/arch/x86/mm/extable.c
31327@@ -6,12 +6,24 @@
31328 static inline unsigned long
31329 ex_insn_addr(const struct exception_table_entry *x)
31330 {
31331- return (unsigned long)&x->insn + x->insn;
31332+ unsigned long reloc = 0;
31333+
31334+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31335+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31336+#endif
31337+
31338+ return (unsigned long)&x->insn + x->insn + reloc;
31339 }
31340 static inline unsigned long
31341 ex_fixup_addr(const struct exception_table_entry *x)
31342 {
31343- return (unsigned long)&x->fixup + x->fixup;
31344+ unsigned long reloc = 0;
31345+
31346+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31347+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31348+#endif
31349+
31350+ return (unsigned long)&x->fixup + x->fixup + reloc;
31351 }
31352
31353 int fixup_exception(struct pt_regs *regs)
31354@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31355 unsigned long new_ip;
31356
31357 #ifdef CONFIG_PNPBIOS
31358- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31359+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31360 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31361 extern u32 pnp_bios_is_utter_crap;
31362 pnp_bios_is_utter_crap = 1;
31363@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31364 i += 4;
31365 p->fixup -= i;
31366 i += 4;
31367+
31368+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31369+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31370+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31371+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31372+#endif
31373+
31374 }
31375 }
31376
31377diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31378index 8e57229..31cce89 100644
31379--- a/arch/x86/mm/fault.c
31380+++ b/arch/x86/mm/fault.c
31381@@ -14,11 +14,18 @@
31382 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31383 #include <linux/prefetch.h> /* prefetchw */
31384 #include <linux/context_tracking.h> /* exception_enter(), ... */
31385+#include <linux/unistd.h>
31386+#include <linux/compiler.h>
31387
31388 #include <asm/traps.h> /* dotraplinkage, ... */
31389 #include <asm/pgalloc.h> /* pgd_*(), ... */
31390 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31391 #include <asm/fixmap.h> /* VSYSCALL_START */
31392+#include <asm/tlbflush.h>
31393+
31394+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31395+#include <asm/stacktrace.h>
31396+#endif
31397
31398 #define CREATE_TRACE_POINTS
31399 #include <asm/trace/exceptions.h>
31400@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31401 int ret = 0;
31402
31403 /* kprobe_running() needs smp_processor_id() */
31404- if (kprobes_built_in() && !user_mode_vm(regs)) {
31405+ if (kprobes_built_in() && !user_mode(regs)) {
31406 preempt_disable();
31407 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31408 ret = 1;
31409@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31410 return !instr_lo || (instr_lo>>1) == 1;
31411 case 0x00:
31412 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31413- if (probe_kernel_address(instr, opcode))
31414+ if (user_mode(regs)) {
31415+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31416+ return 0;
31417+ } else if (probe_kernel_address(instr, opcode))
31418 return 0;
31419
31420 *prefetch = (instr_lo == 0xF) &&
31421@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31422 while (instr < max_instr) {
31423 unsigned char opcode;
31424
31425- if (probe_kernel_address(instr, opcode))
31426+ if (user_mode(regs)) {
31427+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31428+ break;
31429+ } else if (probe_kernel_address(instr, opcode))
31430 break;
31431
31432 instr++;
31433@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31434 force_sig_info(si_signo, &info, tsk);
31435 }
31436
31437+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31438+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31439+#endif
31440+
31441+#ifdef CONFIG_PAX_EMUTRAMP
31442+static int pax_handle_fetch_fault(struct pt_regs *regs);
31443+#endif
31444+
31445+#ifdef CONFIG_PAX_PAGEEXEC
31446+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31447+{
31448+ pgd_t *pgd;
31449+ pud_t *pud;
31450+ pmd_t *pmd;
31451+
31452+ pgd = pgd_offset(mm, address);
31453+ if (!pgd_present(*pgd))
31454+ return NULL;
31455+ pud = pud_offset(pgd, address);
31456+ if (!pud_present(*pud))
31457+ return NULL;
31458+ pmd = pmd_offset(pud, address);
31459+ if (!pmd_present(*pmd))
31460+ return NULL;
31461+ return pmd;
31462+}
31463+#endif
31464+
31465 DEFINE_SPINLOCK(pgd_lock);
31466 LIST_HEAD(pgd_list);
31467
31468@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31469 for (address = VMALLOC_START & PMD_MASK;
31470 address >= TASK_SIZE && address < FIXADDR_TOP;
31471 address += PMD_SIZE) {
31472+
31473+#ifdef CONFIG_PAX_PER_CPU_PGD
31474+ unsigned long cpu;
31475+#else
31476 struct page *page;
31477+#endif
31478
31479 spin_lock(&pgd_lock);
31480+
31481+#ifdef CONFIG_PAX_PER_CPU_PGD
31482+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31483+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31484+ pmd_t *ret;
31485+
31486+ ret = vmalloc_sync_one(pgd, address);
31487+ if (!ret)
31488+ break;
31489+ pgd = get_cpu_pgd(cpu, kernel);
31490+#else
31491 list_for_each_entry(page, &pgd_list, lru) {
31492+ pgd_t *pgd;
31493 spinlock_t *pgt_lock;
31494 pmd_t *ret;
31495
31496@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31497 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31498
31499 spin_lock(pgt_lock);
31500- ret = vmalloc_sync_one(page_address(page), address);
31501+ pgd = page_address(page);
31502+#endif
31503+
31504+ ret = vmalloc_sync_one(pgd, address);
31505+
31506+#ifndef CONFIG_PAX_PER_CPU_PGD
31507 spin_unlock(pgt_lock);
31508+#endif
31509
31510 if (!ret)
31511 break;
31512@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31513 * an interrupt in the middle of a task switch..
31514 */
31515 pgd_paddr = read_cr3();
31516+
31517+#ifdef CONFIG_PAX_PER_CPU_PGD
31518+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31519+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31520+#endif
31521+
31522 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31523 if (!pmd_k)
31524 return -1;
31525@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31526 * happen within a race in page table update. In the later
31527 * case just flush:
31528 */
31529- pgd = pgd_offset(current->active_mm, address);
31530+
31531 pgd_ref = pgd_offset_k(address);
31532 if (pgd_none(*pgd_ref))
31533 return -1;
31534
31535+#ifdef CONFIG_PAX_PER_CPU_PGD
31536+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31537+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31538+ if (pgd_none(*pgd)) {
31539+ set_pgd(pgd, *pgd_ref);
31540+ arch_flush_lazy_mmu_mode();
31541+ } else {
31542+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31543+ }
31544+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31545+#else
31546+ pgd = pgd_offset(current->active_mm, address);
31547+#endif
31548+
31549 if (pgd_none(*pgd)) {
31550 set_pgd(pgd, *pgd_ref);
31551 arch_flush_lazy_mmu_mode();
31552@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31553 static int is_errata100(struct pt_regs *regs, unsigned long address)
31554 {
31555 #ifdef CONFIG_X86_64
31556- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31557+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31558 return 1;
31559 #endif
31560 return 0;
31561@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31562 }
31563
31564 static const char nx_warning[] = KERN_CRIT
31565-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31566+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31567
31568 static void
31569 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31570@@ -582,7 +666,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31571 if (!oops_may_print())
31572 return;
31573
31574- if (error_code & PF_INSTR) {
31575+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31576 unsigned int level;
31577 pgd_t *pgd;
31578 pte_t *pte;
31579@@ -593,9 +677,21 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31580 pte = lookup_address_in_pgd(pgd, address, &level);
31581
31582 if (pte && pte_present(*pte) && !pte_exec(*pte))
31583- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31584+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31585 }
31586
31587+#ifdef CONFIG_PAX_KERNEXEC
31588+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31589+ if (current->signal->curr_ip)
31590+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31591+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31592+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31593+ else
31594+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31595+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31596+ }
31597+#endif
31598+
31599 printk(KERN_ALERT "BUG: unable to handle kernel ");
31600 if (address < PAGE_SIZE)
31601 printk(KERN_CONT "NULL pointer dereference");
31602@@ -776,6 +872,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31603 return;
31604 }
31605 #endif
31606+
31607+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31608+ if (pax_is_fetch_fault(regs, error_code, address)) {
31609+
31610+#ifdef CONFIG_PAX_EMUTRAMP
31611+ switch (pax_handle_fetch_fault(regs)) {
31612+ case 2:
31613+ return;
31614+ }
31615+#endif
31616+
31617+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31618+ do_group_exit(SIGKILL);
31619+ }
31620+#endif
31621+
31622 /* Kernel addresses are always protection faults: */
31623 if (address >= TASK_SIZE)
31624 error_code |= PF_PROT;
31625@@ -861,7 +973,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31626 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31627 printk(KERN_ERR
31628 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31629- tsk->comm, tsk->pid, address);
31630+ tsk->comm, task_pid_nr(tsk), address);
31631 code = BUS_MCEERR_AR;
31632 }
31633 #endif
31634@@ -915,6 +1027,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31635 return 1;
31636 }
31637
31638+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31639+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31640+{
31641+ pte_t *pte;
31642+ pmd_t *pmd;
31643+ spinlock_t *ptl;
31644+ unsigned char pte_mask;
31645+
31646+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31647+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
31648+ return 0;
31649+
31650+ /* PaX: it's our fault, let's handle it if we can */
31651+
31652+ /* PaX: take a look at read faults before acquiring any locks */
31653+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31654+ /* instruction fetch attempt from a protected page in user mode */
31655+ up_read(&mm->mmap_sem);
31656+
31657+#ifdef CONFIG_PAX_EMUTRAMP
31658+ switch (pax_handle_fetch_fault(regs)) {
31659+ case 2:
31660+ return 1;
31661+ }
31662+#endif
31663+
31664+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31665+ do_group_exit(SIGKILL);
31666+ }
31667+
31668+ pmd = pax_get_pmd(mm, address);
31669+ if (unlikely(!pmd))
31670+ return 0;
31671+
31672+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31673+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31674+ pte_unmap_unlock(pte, ptl);
31675+ return 0;
31676+ }
31677+
31678+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31679+ /* write attempt to a protected page in user mode */
31680+ pte_unmap_unlock(pte, ptl);
31681+ return 0;
31682+ }
31683+
31684+#ifdef CONFIG_SMP
31685+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31686+#else
31687+ if (likely(address > get_limit(regs->cs)))
31688+#endif
31689+ {
31690+ set_pte(pte, pte_mkread(*pte));
31691+ __flush_tlb_one(address);
31692+ pte_unmap_unlock(pte, ptl);
31693+ up_read(&mm->mmap_sem);
31694+ return 1;
31695+ }
31696+
31697+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31698+
31699+ /*
31700+ * PaX: fill DTLB with user rights and retry
31701+ */
31702+ __asm__ __volatile__ (
31703+ "orb %2,(%1)\n"
31704+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31705+/*
31706+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31707+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31708+ * page fault when examined during a TLB load attempt. this is true not only
31709+ * for PTEs holding a non-present entry but also present entries that will
31710+ * raise a page fault (such as those set up by PaX, or the copy-on-write
31711+ * mechanism). in effect it means that we do *not* need to flush the TLBs
31712+ * for our target pages since their PTEs are simply not in the TLBs at all.
31713+
31714+ * the best thing in omitting it is that we gain around 15-20% speed in the
31715+ * fast path of the page fault handler and can get rid of tracing since we
31716+ * can no longer flush unintended entries.
31717+ */
31718+ "invlpg (%0)\n"
31719+#endif
31720+ __copyuser_seg"testb $0,(%0)\n"
31721+ "xorb %3,(%1)\n"
31722+ :
31723+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31724+ : "memory", "cc");
31725+ pte_unmap_unlock(pte, ptl);
31726+ up_read(&mm->mmap_sem);
31727+ return 1;
31728+}
31729+#endif
31730+
31731 /*
31732 * Handle a spurious fault caused by a stale TLB entry.
31733 *
31734@@ -981,6 +1186,9 @@ int show_unhandled_signals = 1;
31735 static inline int
31736 access_error(unsigned long error_code, struct vm_area_struct *vma)
31737 {
31738+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31739+ return 1;
31740+
31741 if (error_code & PF_WRITE) {
31742 /* write, present and write, not present: */
31743 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31744@@ -1015,7 +1223,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31745 if (error_code & PF_USER)
31746 return false;
31747
31748- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31749+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31750 return false;
31751
31752 return true;
31753@@ -1043,6 +1251,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31754 tsk = current;
31755 mm = tsk->mm;
31756
31757+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31758+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31759+ if (!search_exception_tables(regs->ip)) {
31760+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31761+ bad_area_nosemaphore(regs, error_code, address);
31762+ return;
31763+ }
31764+ if (address < pax_user_shadow_base) {
31765+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31766+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31767+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31768+ } else
31769+ address -= pax_user_shadow_base;
31770+ }
31771+#endif
31772+
31773 /*
31774 * Detect and handle instructions that would cause a page fault for
31775 * both a tracked kernel page and a userspace page.
31776@@ -1120,7 +1344,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31777 * User-mode registers count as a user access even for any
31778 * potential system fault or CPU buglet:
31779 */
31780- if (user_mode_vm(regs)) {
31781+ if (user_mode(regs)) {
31782 local_irq_enable();
31783 error_code |= PF_USER;
31784 flags |= FAULT_FLAG_USER;
31785@@ -1167,6 +1391,11 @@ retry:
31786 might_sleep();
31787 }
31788
31789+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31790+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31791+ return;
31792+#endif
31793+
31794 vma = find_vma(mm, address);
31795 if (unlikely(!vma)) {
31796 bad_area(regs, error_code, address);
31797@@ -1178,18 +1407,24 @@ retry:
31798 bad_area(regs, error_code, address);
31799 return;
31800 }
31801- if (error_code & PF_USER) {
31802- /*
31803- * Accessing the stack below %sp is always a bug.
31804- * The large cushion allows instructions like enter
31805- * and pusha to work. ("enter $65535, $31" pushes
31806- * 32 pointers and then decrements %sp by 65535.)
31807- */
31808- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31809- bad_area(regs, error_code, address);
31810- return;
31811- }
31812+ /*
31813+ * Accessing the stack below %sp is always a bug.
31814+ * The large cushion allows instructions like enter
31815+ * and pusha to work. ("enter $65535, $31" pushes
31816+ * 32 pointers and then decrements %sp by 65535.)
31817+ */
31818+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31819+ bad_area(regs, error_code, address);
31820+ return;
31821 }
31822+
31823+#ifdef CONFIG_PAX_SEGMEXEC
31824+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31825+ bad_area(regs, error_code, address);
31826+ return;
31827+ }
31828+#endif
31829+
31830 if (unlikely(expand_stack(vma, address))) {
31831 bad_area(regs, error_code, address);
31832 return;
31833@@ -1301,3 +1536,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31834 exception_exit(prev_state);
31835 }
31836 #endif /* CONFIG_TRACING */
31837+
31838+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31839+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31840+{
31841+ struct mm_struct *mm = current->mm;
31842+ unsigned long ip = regs->ip;
31843+
31844+ if (v8086_mode(regs))
31845+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31846+
31847+#ifdef CONFIG_PAX_PAGEEXEC
31848+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31849+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31850+ return true;
31851+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31852+ return true;
31853+ return false;
31854+ }
31855+#endif
31856+
31857+#ifdef CONFIG_PAX_SEGMEXEC
31858+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31859+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31860+ return true;
31861+ return false;
31862+ }
31863+#endif
31864+
31865+ return false;
31866+}
31867+#endif
31868+
31869+#ifdef CONFIG_PAX_EMUTRAMP
31870+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31871+{
31872+ int err;
31873+
31874+ do { /* PaX: libffi trampoline emulation */
31875+ unsigned char mov, jmp;
31876+ unsigned int addr1, addr2;
31877+
31878+#ifdef CONFIG_X86_64
31879+ if ((regs->ip + 9) >> 32)
31880+ break;
31881+#endif
31882+
31883+ err = get_user(mov, (unsigned char __user *)regs->ip);
31884+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31885+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31886+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31887+
31888+ if (err)
31889+ break;
31890+
31891+ if (mov == 0xB8 && jmp == 0xE9) {
31892+ regs->ax = addr1;
31893+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31894+ return 2;
31895+ }
31896+ } while (0);
31897+
31898+ do { /* PaX: gcc trampoline emulation #1 */
31899+ unsigned char mov1, mov2;
31900+ unsigned short jmp;
31901+ unsigned int addr1, addr2;
31902+
31903+#ifdef CONFIG_X86_64
31904+ if ((regs->ip + 11) >> 32)
31905+ break;
31906+#endif
31907+
31908+ err = get_user(mov1, (unsigned char __user *)regs->ip);
31909+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31910+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31911+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31912+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31913+
31914+ if (err)
31915+ break;
31916+
31917+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31918+ regs->cx = addr1;
31919+ regs->ax = addr2;
31920+ regs->ip = addr2;
31921+ return 2;
31922+ }
31923+ } while (0);
31924+
31925+ do { /* PaX: gcc trampoline emulation #2 */
31926+ unsigned char mov, jmp;
31927+ unsigned int addr1, addr2;
31928+
31929+#ifdef CONFIG_X86_64
31930+ if ((regs->ip + 9) >> 32)
31931+ break;
31932+#endif
31933+
31934+ err = get_user(mov, (unsigned char __user *)regs->ip);
31935+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31936+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31937+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31938+
31939+ if (err)
31940+ break;
31941+
31942+ if (mov == 0xB9 && jmp == 0xE9) {
31943+ regs->cx = addr1;
31944+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31945+ return 2;
31946+ }
31947+ } while (0);
31948+
31949+ return 1; /* PaX in action */
31950+}
31951+
31952+#ifdef CONFIG_X86_64
31953+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31954+{
31955+ int err;
31956+
31957+ do { /* PaX: libffi trampoline emulation */
31958+ unsigned short mov1, mov2, jmp1;
31959+ unsigned char stcclc, jmp2;
31960+ unsigned long addr1, addr2;
31961+
31962+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31963+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31964+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31965+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31966+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31967+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31968+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31969+
31970+ if (err)
31971+ break;
31972+
31973+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31974+ regs->r11 = addr1;
31975+ regs->r10 = addr2;
31976+ if (stcclc == 0xF8)
31977+ regs->flags &= ~X86_EFLAGS_CF;
31978+ else
31979+ regs->flags |= X86_EFLAGS_CF;
31980+ regs->ip = addr1;
31981+ return 2;
31982+ }
31983+ } while (0);
31984+
31985+ do { /* PaX: gcc trampoline emulation #1 */
31986+ unsigned short mov1, mov2, jmp1;
31987+ unsigned char jmp2;
31988+ unsigned int addr1;
31989+ unsigned long addr2;
31990+
31991+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31992+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31993+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31994+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31995+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31996+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31997+
31998+ if (err)
31999+ break;
32000+
32001+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32002+ regs->r11 = addr1;
32003+ regs->r10 = addr2;
32004+ regs->ip = addr1;
32005+ return 2;
32006+ }
32007+ } while (0);
32008+
32009+ do { /* PaX: gcc trampoline emulation #2 */
32010+ unsigned short mov1, mov2, jmp1;
32011+ unsigned char jmp2;
32012+ unsigned long addr1, addr2;
32013+
32014+ err = get_user(mov1, (unsigned short __user *)regs->ip);
32015+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32016+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32017+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32018+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32019+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32020+
32021+ if (err)
32022+ break;
32023+
32024+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32025+ regs->r11 = addr1;
32026+ regs->r10 = addr2;
32027+ regs->ip = addr1;
32028+ return 2;
32029+ }
32030+ } while (0);
32031+
32032+ return 1; /* PaX in action */
32033+}
32034+#endif
32035+
32036+/*
32037+ * PaX: decide what to do with offenders (regs->ip = fault address)
32038+ *
32039+ * returns 1 when task should be killed
32040+ * 2 when gcc trampoline was detected
32041+ */
32042+static int pax_handle_fetch_fault(struct pt_regs *regs)
32043+{
32044+ if (v8086_mode(regs))
32045+ return 1;
32046+
32047+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32048+ return 1;
32049+
32050+#ifdef CONFIG_X86_32
32051+ return pax_handle_fetch_fault_32(regs);
32052+#else
32053+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32054+ return pax_handle_fetch_fault_32(regs);
32055+ else
32056+ return pax_handle_fetch_fault_64(regs);
32057+#endif
32058+}
32059+#endif
32060+
32061+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32062+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32063+{
32064+ long i;
32065+
32066+ printk(KERN_ERR "PAX: bytes at PC: ");
32067+ for (i = 0; i < 20; i++) {
32068+ unsigned char c;
32069+ if (get_user(c, (unsigned char __force_user *)pc+i))
32070+ printk(KERN_CONT "?? ");
32071+ else
32072+ printk(KERN_CONT "%02x ", c);
32073+ }
32074+ printk("\n");
32075+
32076+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32077+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
32078+ unsigned long c;
32079+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
32080+#ifdef CONFIG_X86_32
32081+ printk(KERN_CONT "???????? ");
32082+#else
32083+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32084+ printk(KERN_CONT "???????? ???????? ");
32085+ else
32086+ printk(KERN_CONT "???????????????? ");
32087+#endif
32088+ } else {
32089+#ifdef CONFIG_X86_64
32090+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32091+ printk(KERN_CONT "%08x ", (unsigned int)c);
32092+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32093+ } else
32094+#endif
32095+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32096+ }
32097+ }
32098+ printk("\n");
32099+}
32100+#endif
32101+
32102+/**
32103+ * probe_kernel_write(): safely attempt to write to a location
32104+ * @dst: address to write to
32105+ * @src: pointer to the data that shall be written
32106+ * @size: size of the data chunk
32107+ *
32108+ * Safely write to address @dst from the buffer at @src. If a kernel fault
32109+ * happens, handle that and return -EFAULT.
32110+ */
32111+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32112+{
32113+ long ret;
32114+ mm_segment_t old_fs = get_fs();
32115+
32116+ set_fs(KERNEL_DS);
32117+ pagefault_disable();
32118+ pax_open_kernel();
32119+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32120+ pax_close_kernel();
32121+ pagefault_enable();
32122+ set_fs(old_fs);
32123+
32124+ return ret ? -EFAULT : 0;
32125+}
32126diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32127index 207d9aef..69030980 100644
32128--- a/arch/x86/mm/gup.c
32129+++ b/arch/x86/mm/gup.c
32130@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32131 addr = start;
32132 len = (unsigned long) nr_pages << PAGE_SHIFT;
32133 end = start + len;
32134- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32135+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32136 (void __user *)start, len)))
32137 return 0;
32138
32139@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32140 goto slow_irqon;
32141 #endif
32142
32143+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32144+ (void __user *)start, len)))
32145+ return 0;
32146+
32147 /*
32148 * XXX: batch / limit 'nr', to avoid large irq off latency
32149 * needs some instrumenting to determine the common sizes used by
32150diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32151index 4500142..53a363c 100644
32152--- a/arch/x86/mm/highmem_32.c
32153+++ b/arch/x86/mm/highmem_32.c
32154@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32155 idx = type + KM_TYPE_NR*smp_processor_id();
32156 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32157 BUG_ON(!pte_none(*(kmap_pte-idx)));
32158+
32159+ pax_open_kernel();
32160 set_pte(kmap_pte-idx, mk_pte(page, prot));
32161+ pax_close_kernel();
32162+
32163 arch_flush_lazy_mmu_mode();
32164
32165 return (void *)vaddr;
32166diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32167index 8b977eb..4732c33 100644
32168--- a/arch/x86/mm/hugetlbpage.c
32169+++ b/arch/x86/mm/hugetlbpage.c
32170@@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32171 #ifdef CONFIG_HUGETLB_PAGE
32172 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32173 unsigned long addr, unsigned long len,
32174- unsigned long pgoff, unsigned long flags)
32175+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32176 {
32177 struct hstate *h = hstate_file(file);
32178 struct vm_unmapped_area_info info;
32179-
32180+
32181 info.flags = 0;
32182 info.length = len;
32183 info.low_limit = current->mm->mmap_legacy_base;
32184 info.high_limit = TASK_SIZE;
32185 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32186 info.align_offset = 0;
32187+ info.threadstack_offset = offset;
32188 return vm_unmapped_area(&info);
32189 }
32190
32191 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32192 unsigned long addr0, unsigned long len,
32193- unsigned long pgoff, unsigned long flags)
32194+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32195 {
32196 struct hstate *h = hstate_file(file);
32197 struct vm_unmapped_area_info info;
32198@@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32199 info.high_limit = current->mm->mmap_base;
32200 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32201 info.align_offset = 0;
32202+ info.threadstack_offset = offset;
32203 addr = vm_unmapped_area(&info);
32204
32205 /*
32206@@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32207 VM_BUG_ON(addr != -ENOMEM);
32208 info.flags = 0;
32209 info.low_limit = TASK_UNMAPPED_BASE;
32210+
32211+#ifdef CONFIG_PAX_RANDMMAP
32212+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32213+ info.low_limit += current->mm->delta_mmap;
32214+#endif
32215+
32216 info.high_limit = TASK_SIZE;
32217 addr = vm_unmapped_area(&info);
32218 }
32219@@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32220 struct hstate *h = hstate_file(file);
32221 struct mm_struct *mm = current->mm;
32222 struct vm_area_struct *vma;
32223+ unsigned long pax_task_size = TASK_SIZE;
32224+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32225
32226 if (len & ~huge_page_mask(h))
32227 return -EINVAL;
32228- if (len > TASK_SIZE)
32229+
32230+#ifdef CONFIG_PAX_SEGMEXEC
32231+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32232+ pax_task_size = SEGMEXEC_TASK_SIZE;
32233+#endif
32234+
32235+ pax_task_size -= PAGE_SIZE;
32236+
32237+ if (len > pax_task_size)
32238 return -ENOMEM;
32239
32240 if (flags & MAP_FIXED) {
32241@@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32242 return addr;
32243 }
32244
32245+#ifdef CONFIG_PAX_RANDMMAP
32246+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32247+#endif
32248+
32249 if (addr) {
32250 addr = ALIGN(addr, huge_page_size(h));
32251 vma = find_vma(mm, addr);
32252- if (TASK_SIZE - len >= addr &&
32253- (!vma || addr + len <= vma->vm_start))
32254+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32255 return addr;
32256 }
32257 if (mm->get_unmapped_area == arch_get_unmapped_area)
32258 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32259- pgoff, flags);
32260+ pgoff, flags, offset);
32261 else
32262 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32263- pgoff, flags);
32264+ pgoff, flags, offset);
32265 }
32266 #endif /* CONFIG_HUGETLB_PAGE */
32267
32268diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32269index f971306..e83e0f6 100644
32270--- a/arch/x86/mm/init.c
32271+++ b/arch/x86/mm/init.c
32272@@ -4,6 +4,7 @@
32273 #include <linux/swap.h>
32274 #include <linux/memblock.h>
32275 #include <linux/bootmem.h> /* for max_low_pfn */
32276+#include <linux/tboot.h>
32277
32278 #include <asm/cacheflush.h>
32279 #include <asm/e820.h>
32280@@ -17,6 +18,8 @@
32281 #include <asm/proto.h>
32282 #include <asm/dma.h> /* for MAX_DMA_PFN */
32283 #include <asm/microcode.h>
32284+#include <asm/desc.h>
32285+#include <asm/bios_ebda.h>
32286
32287 #include "mm_internal.h"
32288
32289@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32290 early_ioremap_page_table_range_init();
32291 #endif
32292
32293+#ifdef CONFIG_PAX_PER_CPU_PGD
32294+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32295+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32296+ KERNEL_PGD_PTRS);
32297+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32298+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32299+ KERNEL_PGD_PTRS);
32300+ load_cr3(get_cpu_pgd(0, kernel));
32301+#else
32302 load_cr3(swapper_pg_dir);
32303+#endif
32304+
32305 __flush_tlb_all();
32306
32307 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32308@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32309 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32310 * mmio resources as well as potential bios/acpi data regions.
32311 */
32312+
32313+#ifdef CONFIG_GRKERNSEC_KMEM
32314+static unsigned int ebda_start __read_only;
32315+static unsigned int ebda_end __read_only;
32316+#endif
32317+
32318 int devmem_is_allowed(unsigned long pagenr)
32319 {
32320- if (pagenr < 256)
32321+#ifdef CONFIG_GRKERNSEC_KMEM
32322+ /* allow BDA */
32323+ if (!pagenr)
32324 return 1;
32325+ /* allow EBDA */
32326+ if (pagenr >= ebda_start && pagenr < ebda_end)
32327+ return 1;
32328+ /* if tboot is in use, allow access to its hardcoded serial log range */
32329+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32330+ return 1;
32331+#else
32332+ if (!pagenr)
32333+ return 1;
32334+#ifdef CONFIG_VM86
32335+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32336+ return 1;
32337+#endif
32338+#endif
32339+
32340+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32341+ return 1;
32342+#ifdef CONFIG_GRKERNSEC_KMEM
32343+ /* throw out everything else below 1MB */
32344+ if (pagenr <= 256)
32345+ return 0;
32346+#endif
32347 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32348 return 0;
32349 if (!page_is_ram(pagenr))
32350@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32351 #endif
32352 }
32353
32354+#ifdef CONFIG_GRKERNSEC_KMEM
32355+static inline void gr_init_ebda(void)
32356+{
32357+ unsigned int ebda_addr;
32358+ unsigned int ebda_size = 0;
32359+
32360+ ebda_addr = get_bios_ebda();
32361+ if (ebda_addr) {
32362+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32363+ ebda_size <<= 10;
32364+ }
32365+ if (ebda_addr && ebda_size) {
32366+ ebda_start = ebda_addr >> PAGE_SHIFT;
32367+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32368+ } else {
32369+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32370+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32371+ }
32372+}
32373+#else
32374+static inline void gr_init_ebda(void) { }
32375+#endif
32376+
32377 void free_initmem(void)
32378 {
32379+#ifdef CONFIG_PAX_KERNEXEC
32380+#ifdef CONFIG_X86_32
32381+ /* PaX: limit KERNEL_CS to actual size */
32382+ unsigned long addr, limit;
32383+ struct desc_struct d;
32384+ int cpu;
32385+#else
32386+ pgd_t *pgd;
32387+ pud_t *pud;
32388+ pmd_t *pmd;
32389+ unsigned long addr, end;
32390+#endif
32391+#endif
32392+
32393+ gr_init_ebda();
32394+
32395+#ifdef CONFIG_PAX_KERNEXEC
32396+#ifdef CONFIG_X86_32
32397+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32398+ limit = (limit - 1UL) >> PAGE_SHIFT;
32399+
32400+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32401+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32402+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32403+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32404+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32405+ }
32406+
32407+ /* PaX: make KERNEL_CS read-only */
32408+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32409+ if (!paravirt_enabled())
32410+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32411+/*
32412+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32413+ pgd = pgd_offset_k(addr);
32414+ pud = pud_offset(pgd, addr);
32415+ pmd = pmd_offset(pud, addr);
32416+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32417+ }
32418+*/
32419+#ifdef CONFIG_X86_PAE
32420+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32421+/*
32422+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32423+ pgd = pgd_offset_k(addr);
32424+ pud = pud_offset(pgd, addr);
32425+ pmd = pmd_offset(pud, addr);
32426+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32427+ }
32428+*/
32429+#endif
32430+
32431+#ifdef CONFIG_MODULES
32432+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32433+#endif
32434+
32435+#else
32436+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32437+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32438+ pgd = pgd_offset_k(addr);
32439+ pud = pud_offset(pgd, addr);
32440+ pmd = pmd_offset(pud, addr);
32441+ if (!pmd_present(*pmd))
32442+ continue;
32443+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32444+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32445+ else
32446+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32447+ }
32448+
32449+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32450+ end = addr + KERNEL_IMAGE_SIZE;
32451+ for (; addr < end; addr += PMD_SIZE) {
32452+ pgd = pgd_offset_k(addr);
32453+ pud = pud_offset(pgd, addr);
32454+ pmd = pmd_offset(pud, addr);
32455+ if (!pmd_present(*pmd))
32456+ continue;
32457+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32458+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32459+ }
32460+#endif
32461+
32462+ flush_tlb_all();
32463+#endif
32464+
32465 free_init_pages("unused kernel",
32466 (unsigned long)(&__init_begin),
32467 (unsigned long)(&__init_end));
32468diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32469index e395048..cd38278 100644
32470--- a/arch/x86/mm/init_32.c
32471+++ b/arch/x86/mm/init_32.c
32472@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32473 bool __read_mostly __vmalloc_start_set = false;
32474
32475 /*
32476- * Creates a middle page table and puts a pointer to it in the
32477- * given global directory entry. This only returns the gd entry
32478- * in non-PAE compilation mode, since the middle layer is folded.
32479- */
32480-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32481-{
32482- pud_t *pud;
32483- pmd_t *pmd_table;
32484-
32485-#ifdef CONFIG_X86_PAE
32486- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32487- pmd_table = (pmd_t *)alloc_low_page();
32488- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32489- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32490- pud = pud_offset(pgd, 0);
32491- BUG_ON(pmd_table != pmd_offset(pud, 0));
32492-
32493- return pmd_table;
32494- }
32495-#endif
32496- pud = pud_offset(pgd, 0);
32497- pmd_table = pmd_offset(pud, 0);
32498-
32499- return pmd_table;
32500-}
32501-
32502-/*
32503 * Create a page table and place a pointer to it in a middle page
32504 * directory entry:
32505 */
32506@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32507 pte_t *page_table = (pte_t *)alloc_low_page();
32508
32509 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32510+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32511+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32512+#else
32513 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32514+#endif
32515 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32516 }
32517
32518 return pte_offset_kernel(pmd, 0);
32519 }
32520
32521+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32522+{
32523+ pud_t *pud;
32524+ pmd_t *pmd_table;
32525+
32526+ pud = pud_offset(pgd, 0);
32527+ pmd_table = pmd_offset(pud, 0);
32528+
32529+ return pmd_table;
32530+}
32531+
32532 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32533 {
32534 int pgd_idx = pgd_index(vaddr);
32535@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32536 int pgd_idx, pmd_idx;
32537 unsigned long vaddr;
32538 pgd_t *pgd;
32539+ pud_t *pud;
32540 pmd_t *pmd;
32541 pte_t *pte = NULL;
32542 unsigned long count = page_table_range_init_count(start, end);
32543@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32544 pgd = pgd_base + pgd_idx;
32545
32546 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32547- pmd = one_md_table_init(pgd);
32548- pmd = pmd + pmd_index(vaddr);
32549+ pud = pud_offset(pgd, vaddr);
32550+ pmd = pmd_offset(pud, vaddr);
32551+
32552+#ifdef CONFIG_X86_PAE
32553+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32554+#endif
32555+
32556 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32557 pmd++, pmd_idx++) {
32558 pte = page_table_kmap_check(one_page_table_init(pmd),
32559@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32560 }
32561 }
32562
32563-static inline int is_kernel_text(unsigned long addr)
32564+static inline int is_kernel_text(unsigned long start, unsigned long end)
32565 {
32566- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32567- return 1;
32568- return 0;
32569+ if ((start >= ktla_ktva((unsigned long)_etext) ||
32570+ end <= ktla_ktva((unsigned long)_stext)) &&
32571+ (start >= ktla_ktva((unsigned long)_einittext) ||
32572+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32573+
32574+#ifdef CONFIG_ACPI_SLEEP
32575+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32576+#endif
32577+
32578+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32579+ return 0;
32580+ return 1;
32581 }
32582
32583 /*
32584@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32585 unsigned long last_map_addr = end;
32586 unsigned long start_pfn, end_pfn;
32587 pgd_t *pgd_base = swapper_pg_dir;
32588- int pgd_idx, pmd_idx, pte_ofs;
32589+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32590 unsigned long pfn;
32591 pgd_t *pgd;
32592+ pud_t *pud;
32593 pmd_t *pmd;
32594 pte_t *pte;
32595 unsigned pages_2m, pages_4k;
32596@@ -291,8 +295,13 @@ repeat:
32597 pfn = start_pfn;
32598 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32599 pgd = pgd_base + pgd_idx;
32600- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32601- pmd = one_md_table_init(pgd);
32602+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32603+ pud = pud_offset(pgd, 0);
32604+ pmd = pmd_offset(pud, 0);
32605+
32606+#ifdef CONFIG_X86_PAE
32607+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32608+#endif
32609
32610 if (pfn >= end_pfn)
32611 continue;
32612@@ -304,14 +313,13 @@ repeat:
32613 #endif
32614 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32615 pmd++, pmd_idx++) {
32616- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32617+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32618
32619 /*
32620 * Map with big pages if possible, otherwise
32621 * create normal page tables:
32622 */
32623 if (use_pse) {
32624- unsigned int addr2;
32625 pgprot_t prot = PAGE_KERNEL_LARGE;
32626 /*
32627 * first pass will use the same initial
32628@@ -322,11 +330,7 @@ repeat:
32629 _PAGE_PSE);
32630
32631 pfn &= PMD_MASK >> PAGE_SHIFT;
32632- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32633- PAGE_OFFSET + PAGE_SIZE-1;
32634-
32635- if (is_kernel_text(addr) ||
32636- is_kernel_text(addr2))
32637+ if (is_kernel_text(address, address + PMD_SIZE))
32638 prot = PAGE_KERNEL_LARGE_EXEC;
32639
32640 pages_2m++;
32641@@ -343,7 +347,7 @@ repeat:
32642 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32643 pte += pte_ofs;
32644 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32645- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32646+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32647 pgprot_t prot = PAGE_KERNEL;
32648 /*
32649 * first pass will use the same initial
32650@@ -351,7 +355,7 @@ repeat:
32651 */
32652 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32653
32654- if (is_kernel_text(addr))
32655+ if (is_kernel_text(address, address + PAGE_SIZE))
32656 prot = PAGE_KERNEL_EXEC;
32657
32658 pages_4k++;
32659@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32660
32661 pud = pud_offset(pgd, va);
32662 pmd = pmd_offset(pud, va);
32663- if (!pmd_present(*pmd))
32664+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32665 break;
32666
32667 /* should not be large page here */
32668@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32669
32670 static void __init pagetable_init(void)
32671 {
32672- pgd_t *pgd_base = swapper_pg_dir;
32673-
32674- permanent_kmaps_init(pgd_base);
32675+ permanent_kmaps_init(swapper_pg_dir);
32676 }
32677
32678-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32679+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32680 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32681
32682 /* user-defined highmem size */
32683@@ -787,10 +789,10 @@ void __init mem_init(void)
32684 ((unsigned long)&__init_end -
32685 (unsigned long)&__init_begin) >> 10,
32686
32687- (unsigned long)&_etext, (unsigned long)&_edata,
32688- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32689+ (unsigned long)&_sdata, (unsigned long)&_edata,
32690+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32691
32692- (unsigned long)&_text, (unsigned long)&_etext,
32693+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32694 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32695
32696 /*
32697@@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32698 if (!kernel_set_to_readonly)
32699 return;
32700
32701+ start = ktla_ktva(start);
32702 pr_debug("Set kernel text: %lx - %lx for read write\n",
32703 start, start+size);
32704
32705@@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32706 if (!kernel_set_to_readonly)
32707 return;
32708
32709+ start = ktla_ktva(start);
32710 pr_debug("Set kernel text: %lx - %lx for read only\n",
32711 start, start+size);
32712
32713@@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32714 unsigned long start = PFN_ALIGN(_text);
32715 unsigned long size = PFN_ALIGN(_etext) - start;
32716
32717+ start = ktla_ktva(start);
32718 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32719 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32720 size >> 10);
32721diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32722index f35c66c..84b95ef 100644
32723--- a/arch/x86/mm/init_64.c
32724+++ b/arch/x86/mm/init_64.c
32725@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32726 * around without checking the pgd every time.
32727 */
32728
32729-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32730+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32731 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32732
32733 int force_personality32;
32734@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32735
32736 for (address = start; address <= end; address += PGDIR_SIZE) {
32737 const pgd_t *pgd_ref = pgd_offset_k(address);
32738+
32739+#ifdef CONFIG_PAX_PER_CPU_PGD
32740+ unsigned long cpu;
32741+#else
32742 struct page *page;
32743+#endif
32744
32745 if (pgd_none(*pgd_ref))
32746 continue;
32747
32748 spin_lock(&pgd_lock);
32749+
32750+#ifdef CONFIG_PAX_PER_CPU_PGD
32751+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32752+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32753+
32754+ if (pgd_none(*pgd))
32755+ set_pgd(pgd, *pgd_ref);
32756+ else
32757+ BUG_ON(pgd_page_vaddr(*pgd)
32758+ != pgd_page_vaddr(*pgd_ref));
32759+ pgd = pgd_offset_cpu(cpu, kernel, address);
32760+#else
32761 list_for_each_entry(page, &pgd_list, lru) {
32762 pgd_t *pgd;
32763 spinlock_t *pgt_lock;
32764@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32765 /* the pgt_lock only for Xen */
32766 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32767 spin_lock(pgt_lock);
32768+#endif
32769
32770 if (pgd_none(*pgd))
32771 set_pgd(pgd, *pgd_ref);
32772@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32773 BUG_ON(pgd_page_vaddr(*pgd)
32774 != pgd_page_vaddr(*pgd_ref));
32775
32776+#ifndef CONFIG_PAX_PER_CPU_PGD
32777 spin_unlock(pgt_lock);
32778+#endif
32779+
32780 }
32781 spin_unlock(&pgd_lock);
32782 }
32783@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32784 {
32785 if (pgd_none(*pgd)) {
32786 pud_t *pud = (pud_t *)spp_getpage();
32787- pgd_populate(&init_mm, pgd, pud);
32788+ pgd_populate_kernel(&init_mm, pgd, pud);
32789 if (pud != pud_offset(pgd, 0))
32790 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32791 pud, pud_offset(pgd, 0));
32792@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32793 {
32794 if (pud_none(*pud)) {
32795 pmd_t *pmd = (pmd_t *) spp_getpage();
32796- pud_populate(&init_mm, pud, pmd);
32797+ pud_populate_kernel(&init_mm, pud, pmd);
32798 if (pmd != pmd_offset(pud, 0))
32799 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32800 pmd, pmd_offset(pud, 0));
32801@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32802 pmd = fill_pmd(pud, vaddr);
32803 pte = fill_pte(pmd, vaddr);
32804
32805+ pax_open_kernel();
32806 set_pte(pte, new_pte);
32807+ pax_close_kernel();
32808
32809 /*
32810 * It's enough to flush this one mapping.
32811@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32812 pgd = pgd_offset_k((unsigned long)__va(phys));
32813 if (pgd_none(*pgd)) {
32814 pud = (pud_t *) spp_getpage();
32815- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32816- _PAGE_USER));
32817+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32818 }
32819 pud = pud_offset(pgd, (unsigned long)__va(phys));
32820 if (pud_none(*pud)) {
32821 pmd = (pmd_t *) spp_getpage();
32822- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32823- _PAGE_USER));
32824+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32825 }
32826 pmd = pmd_offset(pud, phys);
32827 BUG_ON(!pmd_none(*pmd));
32828@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32829 prot);
32830
32831 spin_lock(&init_mm.page_table_lock);
32832- pud_populate(&init_mm, pud, pmd);
32833+ pud_populate_kernel(&init_mm, pud, pmd);
32834 spin_unlock(&init_mm.page_table_lock);
32835 }
32836 __flush_tlb_all();
32837@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32838 page_size_mask);
32839
32840 spin_lock(&init_mm.page_table_lock);
32841- pgd_populate(&init_mm, pgd, pud);
32842+ pgd_populate_kernel(&init_mm, pgd, pud);
32843 spin_unlock(&init_mm.page_table_lock);
32844 pgd_changed = true;
32845 }
32846@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32847 static struct vm_area_struct gate_vma = {
32848 .vm_start = VSYSCALL_START,
32849 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32850- .vm_page_prot = PAGE_READONLY_EXEC,
32851- .vm_flags = VM_READ | VM_EXEC
32852+ .vm_page_prot = PAGE_READONLY,
32853+ .vm_flags = VM_READ
32854 };
32855
32856 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32857@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32858
32859 const char *arch_vma_name(struct vm_area_struct *vma)
32860 {
32861- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32862+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32863 return "[vdso]";
32864 if (vma == &gate_vma)
32865 return "[vsyscall]";
32866diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32867index 7b179b4..6bd17777 100644
32868--- a/arch/x86/mm/iomap_32.c
32869+++ b/arch/x86/mm/iomap_32.c
32870@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32871 type = kmap_atomic_idx_push();
32872 idx = type + KM_TYPE_NR * smp_processor_id();
32873 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32874+
32875+ pax_open_kernel();
32876 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32877+ pax_close_kernel();
32878+
32879 arch_flush_lazy_mmu_mode();
32880
32881 return (void *)vaddr;
32882diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32883index 597ac15..49841be 100644
32884--- a/arch/x86/mm/ioremap.c
32885+++ b/arch/x86/mm/ioremap.c
32886@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32887 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32888 int is_ram = page_is_ram(pfn);
32889
32890- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32891+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32892 return NULL;
32893 WARN_ON_ONCE(is_ram);
32894 }
32895@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32896 *
32897 * Caller must ensure there is only one unmapping for the same pointer.
32898 */
32899-void iounmap(volatile void __iomem *addr)
32900+void iounmap(const volatile void __iomem *addr)
32901 {
32902 struct vm_struct *p, *o;
32903
32904@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32905
32906 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32907 if (page_is_ram(start >> PAGE_SHIFT))
32908+#ifdef CONFIG_HIGHMEM
32909+ if ((start >> PAGE_SHIFT) < max_low_pfn)
32910+#endif
32911 return __va(phys);
32912
32913 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32914@@ -322,13 +325,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32915 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32916 {
32917 if (page_is_ram(phys >> PAGE_SHIFT))
32918+#ifdef CONFIG_HIGHMEM
32919+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
32920+#endif
32921 return;
32922
32923 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32924 return;
32925 }
32926
32927-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32928+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32929
32930 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32931 {
32932@@ -358,8 +364,7 @@ void __init early_ioremap_init(void)
32933 early_ioremap_setup();
32934
32935 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32936- memset(bm_pte, 0, sizeof(bm_pte));
32937- pmd_populate_kernel(&init_mm, pmd, bm_pte);
32938+ pmd_populate_user(&init_mm, pmd, bm_pte);
32939
32940 /*
32941 * The boot-ioremap range spans multiple pmds, for which
32942diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32943index dd89a13..d77bdcc 100644
32944--- a/arch/x86/mm/kmemcheck/kmemcheck.c
32945+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32946@@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32947 * memory (e.g. tracked pages)? For now, we need this to avoid
32948 * invoking kmemcheck for PnP BIOS calls.
32949 */
32950- if (regs->flags & X86_VM_MASK)
32951+ if (v8086_mode(regs))
32952 return false;
32953- if (regs->cs != __KERNEL_CS)
32954+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32955 return false;
32956
32957 pte = kmemcheck_pte_lookup(address);
32958diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32959index 25e7e13..1964579 100644
32960--- a/arch/x86/mm/mmap.c
32961+++ b/arch/x86/mm/mmap.c
32962@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32963 * Leave an at least ~128 MB hole with possible stack randomization.
32964 */
32965 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32966-#define MAX_GAP (TASK_SIZE/6*5)
32967+#define MAX_GAP (pax_task_size/6*5)
32968
32969 static int mmap_is_legacy(void)
32970 {
32971@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32972 return rnd << PAGE_SHIFT;
32973 }
32974
32975-static unsigned long mmap_base(void)
32976+static unsigned long mmap_base(struct mm_struct *mm)
32977 {
32978 unsigned long gap = rlimit(RLIMIT_STACK);
32979+ unsigned long pax_task_size = TASK_SIZE;
32980+
32981+#ifdef CONFIG_PAX_SEGMEXEC
32982+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32983+ pax_task_size = SEGMEXEC_TASK_SIZE;
32984+#endif
32985
32986 if (gap < MIN_GAP)
32987 gap = MIN_GAP;
32988 else if (gap > MAX_GAP)
32989 gap = MAX_GAP;
32990
32991- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32992+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32993 }
32994
32995 /*
32996 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32997 * does, but not when emulating X86_32
32998 */
32999-static unsigned long mmap_legacy_base(void)
33000+static unsigned long mmap_legacy_base(struct mm_struct *mm)
33001 {
33002- if (mmap_is_ia32())
33003+ if (mmap_is_ia32()) {
33004+
33005+#ifdef CONFIG_PAX_SEGMEXEC
33006+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33007+ return SEGMEXEC_TASK_UNMAPPED_BASE;
33008+ else
33009+#endif
33010+
33011 return TASK_UNMAPPED_BASE;
33012- else
33013+ } else
33014 return TASK_UNMAPPED_BASE + mmap_rnd();
33015 }
33016
33017@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33018 */
33019 void arch_pick_mmap_layout(struct mm_struct *mm)
33020 {
33021- mm->mmap_legacy_base = mmap_legacy_base();
33022- mm->mmap_base = mmap_base();
33023+ mm->mmap_legacy_base = mmap_legacy_base(mm);
33024+ mm->mmap_base = mmap_base(mm);
33025+
33026+#ifdef CONFIG_PAX_RANDMMAP
33027+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
33028+ mm->mmap_legacy_base += mm->delta_mmap;
33029+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33030+ }
33031+#endif
33032
33033 if (mmap_is_legacy()) {
33034 mm->mmap_base = mm->mmap_legacy_base;
33035diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33036index 0057a7a..95c7edd 100644
33037--- a/arch/x86/mm/mmio-mod.c
33038+++ b/arch/x86/mm/mmio-mod.c
33039@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33040 break;
33041 default:
33042 {
33043- unsigned char *ip = (unsigned char *)instptr;
33044+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33045 my_trace->opcode = MMIO_UNKNOWN_OP;
33046 my_trace->width = 0;
33047 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33048@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33049 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33050 void __iomem *addr)
33051 {
33052- static atomic_t next_id;
33053+ static atomic_unchecked_t next_id;
33054 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33055 /* These are page-unaligned. */
33056 struct mmiotrace_map map = {
33057@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33058 .private = trace
33059 },
33060 .phys = offset,
33061- .id = atomic_inc_return(&next_id)
33062+ .id = atomic_inc_return_unchecked(&next_id)
33063 };
33064 map.map_id = trace->id;
33065
33066@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33067 ioremap_trace_core(offset, size, addr);
33068 }
33069
33070-static void iounmap_trace_core(volatile void __iomem *addr)
33071+static void iounmap_trace_core(const volatile void __iomem *addr)
33072 {
33073 struct mmiotrace_map map = {
33074 .phys = 0,
33075@@ -328,7 +328,7 @@ not_enabled:
33076 }
33077 }
33078
33079-void mmiotrace_iounmap(volatile void __iomem *addr)
33080+void mmiotrace_iounmap(const volatile void __iomem *addr)
33081 {
33082 might_sleep();
33083 if (is_enabled()) /* recheck and proper locking in *_core() */
33084diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33085index 1d045f9..3a00249 100644
33086--- a/arch/x86/mm/numa.c
33087+++ b/arch/x86/mm/numa.c
33088@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33089 return true;
33090 }
33091
33092-static int __init numa_register_memblks(struct numa_meminfo *mi)
33093+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33094 {
33095 unsigned long uninitialized_var(pfn_align);
33096 int i, nid;
33097diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
33098index 461bc82..4e091a3 100644
33099--- a/arch/x86/mm/pageattr-test.c
33100+++ b/arch/x86/mm/pageattr-test.c
33101@@ -35,7 +35,7 @@ enum {
33102
33103 static int pte_testbit(pte_t pte)
33104 {
33105- return pte_flags(pte) & _PAGE_UNUSED1;
33106+ return pte_flags(pte) & _PAGE_CPA_TEST;
33107 }
33108
33109 struct split_state {
33110diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33111index ae242a7..1c7998f 100644
33112--- a/arch/x86/mm/pageattr.c
33113+++ b/arch/x86/mm/pageattr.c
33114@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33115 */
33116 #ifdef CONFIG_PCI_BIOS
33117 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33118- pgprot_val(forbidden) |= _PAGE_NX;
33119+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33120 #endif
33121
33122 /*
33123@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33124 * Does not cover __inittext since that is gone later on. On
33125 * 64bit we do not enforce !NX on the low mapping
33126 */
33127- if (within(address, (unsigned long)_text, (unsigned long)_etext))
33128- pgprot_val(forbidden) |= _PAGE_NX;
33129+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33130+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33131
33132+#ifdef CONFIG_DEBUG_RODATA
33133 /*
33134 * The .rodata section needs to be read-only. Using the pfn
33135 * catches all aliases.
33136@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33137 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33138 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33139 pgprot_val(forbidden) |= _PAGE_RW;
33140+#endif
33141
33142 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33143 /*
33144@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33145 }
33146 #endif
33147
33148+#ifdef CONFIG_PAX_KERNEXEC
33149+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33150+ pgprot_val(forbidden) |= _PAGE_RW;
33151+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33152+ }
33153+#endif
33154+
33155 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33156
33157 return prot;
33158@@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33159 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33160 {
33161 /* change init_mm */
33162+ pax_open_kernel();
33163 set_pte_atomic(kpte, pte);
33164+
33165 #ifdef CONFIG_X86_32
33166 if (!SHARED_KERNEL_PMD) {
33167+
33168+#ifdef CONFIG_PAX_PER_CPU_PGD
33169+ unsigned long cpu;
33170+#else
33171 struct page *page;
33172+#endif
33173
33174+#ifdef CONFIG_PAX_PER_CPU_PGD
33175+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33176+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33177+#else
33178 list_for_each_entry(page, &pgd_list, lru) {
33179- pgd_t *pgd;
33180+ pgd_t *pgd = (pgd_t *)page_address(page);
33181+#endif
33182+
33183 pud_t *pud;
33184 pmd_t *pmd;
33185
33186- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33187+ pgd += pgd_index(address);
33188 pud = pud_offset(pgd, address);
33189 pmd = pmd_offset(pud, address);
33190 set_pte_atomic((pte_t *)pmd, pte);
33191 }
33192 }
33193 #endif
33194+ pax_close_kernel();
33195 }
33196
33197 static int
33198diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33199index 6574388..87e9bef 100644
33200--- a/arch/x86/mm/pat.c
33201+++ b/arch/x86/mm/pat.c
33202@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33203
33204 if (!entry) {
33205 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33206- current->comm, current->pid, start, end - 1);
33207+ current->comm, task_pid_nr(current), start, end - 1);
33208 return -EINVAL;
33209 }
33210
33211@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33212
33213 while (cursor < to) {
33214 if (!devmem_is_allowed(pfn)) {
33215- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33216- current->comm, from, to - 1);
33217+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33218+ current->comm, from, to - 1, cursor);
33219 return 0;
33220 }
33221 cursor += PAGE_SIZE;
33222@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33223 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33224 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33225 "for [mem %#010Lx-%#010Lx]\n",
33226- current->comm, current->pid,
33227+ current->comm, task_pid_nr(current),
33228 cattr_name(flags),
33229 base, (unsigned long long)(base + size-1));
33230 return -EINVAL;
33231@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33232 flags = lookup_memtype(paddr);
33233 if (want_flags != flags) {
33234 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33235- current->comm, current->pid,
33236+ current->comm, task_pid_nr(current),
33237 cattr_name(want_flags),
33238 (unsigned long long)paddr,
33239 (unsigned long long)(paddr + size - 1),
33240@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33241 free_memtype(paddr, paddr + size);
33242 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33243 " for [mem %#010Lx-%#010Lx], got %s\n",
33244- current->comm, current->pid,
33245+ current->comm, task_pid_nr(current),
33246 cattr_name(want_flags),
33247 (unsigned long long)paddr,
33248 (unsigned long long)(paddr + size - 1),
33249diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33250index 415f6c4..d319983 100644
33251--- a/arch/x86/mm/pat_rbtree.c
33252+++ b/arch/x86/mm/pat_rbtree.c
33253@@ -160,7 +160,7 @@ success:
33254
33255 failure:
33256 printk(KERN_INFO "%s:%d conflicting memory types "
33257- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33258+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33259 end, cattr_name(found_type), cattr_name(match->type));
33260 return -EBUSY;
33261 }
33262diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33263index 9f0614d..92ae64a 100644
33264--- a/arch/x86/mm/pf_in.c
33265+++ b/arch/x86/mm/pf_in.c
33266@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33267 int i;
33268 enum reason_type rv = OTHERS;
33269
33270- p = (unsigned char *)ins_addr;
33271+ p = (unsigned char *)ktla_ktva(ins_addr);
33272 p += skip_prefix(p, &prf);
33273 p += get_opcode(p, &opcode);
33274
33275@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33276 struct prefix_bits prf;
33277 int i;
33278
33279- p = (unsigned char *)ins_addr;
33280+ p = (unsigned char *)ktla_ktva(ins_addr);
33281 p += skip_prefix(p, &prf);
33282 p += get_opcode(p, &opcode);
33283
33284@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33285 struct prefix_bits prf;
33286 int i;
33287
33288- p = (unsigned char *)ins_addr;
33289+ p = (unsigned char *)ktla_ktva(ins_addr);
33290 p += skip_prefix(p, &prf);
33291 p += get_opcode(p, &opcode);
33292
33293@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33294 struct prefix_bits prf;
33295 int i;
33296
33297- p = (unsigned char *)ins_addr;
33298+ p = (unsigned char *)ktla_ktva(ins_addr);
33299 p += skip_prefix(p, &prf);
33300 p += get_opcode(p, &opcode);
33301 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33302@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33303 struct prefix_bits prf;
33304 int i;
33305
33306- p = (unsigned char *)ins_addr;
33307+ p = (unsigned char *)ktla_ktva(ins_addr);
33308 p += skip_prefix(p, &prf);
33309 p += get_opcode(p, &opcode);
33310 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33311diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33312index c96314a..433b127 100644
33313--- a/arch/x86/mm/pgtable.c
33314+++ b/arch/x86/mm/pgtable.c
33315@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33316 list_del(&page->lru);
33317 }
33318
33319-#define UNSHARED_PTRS_PER_PGD \
33320- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33321+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33322+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33323
33324+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33325+{
33326+ unsigned int count = USER_PGD_PTRS;
33327
33328+ if (!pax_user_shadow_base)
33329+ return;
33330+
33331+ while (count--)
33332+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33333+}
33334+#endif
33335+
33336+#ifdef CONFIG_PAX_PER_CPU_PGD
33337+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33338+{
33339+ unsigned int count = USER_PGD_PTRS;
33340+
33341+ while (count--) {
33342+ pgd_t pgd;
33343+
33344+#ifdef CONFIG_X86_64
33345+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33346+#else
33347+ pgd = *src++;
33348+#endif
33349+
33350+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33351+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33352+#endif
33353+
33354+ *dst++ = pgd;
33355+ }
33356+
33357+}
33358+#endif
33359+
33360+#ifdef CONFIG_X86_64
33361+#define pxd_t pud_t
33362+#define pyd_t pgd_t
33363+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33364+#define pgtable_pxd_page_ctor(page) true
33365+#define pgtable_pxd_page_dtor(page)
33366+#define pxd_free(mm, pud) pud_free((mm), (pud))
33367+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33368+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33369+#define PYD_SIZE PGDIR_SIZE
33370+#else
33371+#define pxd_t pmd_t
33372+#define pyd_t pud_t
33373+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33374+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33375+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33376+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33377+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33378+#define pyd_offset(mm, address) pud_offset((mm), (address))
33379+#define PYD_SIZE PUD_SIZE
33380+#endif
33381+
33382+#ifdef CONFIG_PAX_PER_CPU_PGD
33383+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33384+static inline void pgd_dtor(pgd_t *pgd) {}
33385+#else
33386 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33387 {
33388 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33389@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33390 pgd_list_del(pgd);
33391 spin_unlock(&pgd_lock);
33392 }
33393+#endif
33394
33395 /*
33396 * List of all pgd's needed for non-PAE so it can invalidate entries
33397@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33398 * -- nyc
33399 */
33400
33401-#ifdef CONFIG_X86_PAE
33402+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33403 /*
33404 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33405 * updating the top-level pagetable entries to guarantee the
33406@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33407 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33408 * and initialize the kernel pmds here.
33409 */
33410-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33411+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33412
33413 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33414 {
33415@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33416 */
33417 flush_tlb_mm(mm);
33418 }
33419+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33420+#define PREALLOCATED_PXDS USER_PGD_PTRS
33421 #else /* !CONFIG_X86_PAE */
33422
33423 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33424-#define PREALLOCATED_PMDS 0
33425+#define PREALLOCATED_PXDS 0
33426
33427 #endif /* CONFIG_X86_PAE */
33428
33429-static void free_pmds(pmd_t *pmds[])
33430+static void free_pxds(pxd_t *pxds[])
33431 {
33432 int i;
33433
33434- for(i = 0; i < PREALLOCATED_PMDS; i++)
33435- if (pmds[i]) {
33436- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33437- free_page((unsigned long)pmds[i]);
33438+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33439+ if (pxds[i]) {
33440+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33441+ free_page((unsigned long)pxds[i]);
33442 }
33443 }
33444
33445-static int preallocate_pmds(pmd_t *pmds[])
33446+static int preallocate_pxds(pxd_t *pxds[])
33447 {
33448 int i;
33449 bool failed = false;
33450
33451- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33452- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33453- if (!pmd)
33454+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33455+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33456+ if (!pxd)
33457 failed = true;
33458- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33459- free_page((unsigned long)pmd);
33460- pmd = NULL;
33461+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33462+ free_page((unsigned long)pxd);
33463+ pxd = NULL;
33464 failed = true;
33465 }
33466- pmds[i] = pmd;
33467+ pxds[i] = pxd;
33468 }
33469
33470 if (failed) {
33471- free_pmds(pmds);
33472+ free_pxds(pxds);
33473 return -ENOMEM;
33474 }
33475
33476@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33477 * preallocate which never got a corresponding vma will need to be
33478 * freed manually.
33479 */
33480-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33481+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33482 {
33483 int i;
33484
33485- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33486+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33487 pgd_t pgd = pgdp[i];
33488
33489 if (pgd_val(pgd) != 0) {
33490- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33491+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33492
33493- pgdp[i] = native_make_pgd(0);
33494+ set_pgd(pgdp + i, native_make_pgd(0));
33495
33496- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33497- pmd_free(mm, pmd);
33498+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33499+ pxd_free(mm, pxd);
33500 }
33501 }
33502 }
33503
33504-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33505+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33506 {
33507- pud_t *pud;
33508+ pyd_t *pyd;
33509 int i;
33510
33511- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33512+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33513 return;
33514
33515- pud = pud_offset(pgd, 0);
33516-
33517- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33518- pmd_t *pmd = pmds[i];
33519+#ifdef CONFIG_X86_64
33520+ pyd = pyd_offset(mm, 0L);
33521+#else
33522+ pyd = pyd_offset(pgd, 0L);
33523+#endif
33524
33525+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33526+ pxd_t *pxd = pxds[i];
33527 if (i >= KERNEL_PGD_BOUNDARY)
33528- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33529- sizeof(pmd_t) * PTRS_PER_PMD);
33530+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33531+ sizeof(pxd_t) * PTRS_PER_PMD);
33532
33533- pud_populate(mm, pud, pmd);
33534+ pyd_populate(mm, pyd, pxd);
33535 }
33536 }
33537
33538 pgd_t *pgd_alloc(struct mm_struct *mm)
33539 {
33540 pgd_t *pgd;
33541- pmd_t *pmds[PREALLOCATED_PMDS];
33542+ pxd_t *pxds[PREALLOCATED_PXDS];
33543
33544 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33545
33546@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33547
33548 mm->pgd = pgd;
33549
33550- if (preallocate_pmds(pmds) != 0)
33551+ if (preallocate_pxds(pxds) != 0)
33552 goto out_free_pgd;
33553
33554 if (paravirt_pgd_alloc(mm) != 0)
33555- goto out_free_pmds;
33556+ goto out_free_pxds;
33557
33558 /*
33559 * Make sure that pre-populating the pmds is atomic with
33560@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33561 spin_lock(&pgd_lock);
33562
33563 pgd_ctor(mm, pgd);
33564- pgd_prepopulate_pmd(mm, pgd, pmds);
33565+ pgd_prepopulate_pxd(mm, pgd, pxds);
33566
33567 spin_unlock(&pgd_lock);
33568
33569 return pgd;
33570
33571-out_free_pmds:
33572- free_pmds(pmds);
33573+out_free_pxds:
33574+ free_pxds(pxds);
33575 out_free_pgd:
33576 free_page((unsigned long)pgd);
33577 out:
33578@@ -313,7 +380,7 @@ out:
33579
33580 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33581 {
33582- pgd_mop_up_pmds(mm, pgd);
33583+ pgd_mop_up_pxds(mm, pgd);
33584 pgd_dtor(pgd);
33585 paravirt_pgd_free(mm, pgd);
33586 free_page((unsigned long)pgd);
33587diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33588index 4dd8cf6..f9d143e 100644
33589--- a/arch/x86/mm/pgtable_32.c
33590+++ b/arch/x86/mm/pgtable_32.c
33591@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33592 return;
33593 }
33594 pte = pte_offset_kernel(pmd, vaddr);
33595+
33596+ pax_open_kernel();
33597 if (pte_val(pteval))
33598 set_pte_at(&init_mm, vaddr, pte, pteval);
33599 else
33600 pte_clear(&init_mm, vaddr, pte);
33601+ pax_close_kernel();
33602
33603 /*
33604 * It's enough to flush this one mapping.
33605diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33606index e666cbb..61788c45 100644
33607--- a/arch/x86/mm/physaddr.c
33608+++ b/arch/x86/mm/physaddr.c
33609@@ -10,7 +10,7 @@
33610 #ifdef CONFIG_X86_64
33611
33612 #ifdef CONFIG_DEBUG_VIRTUAL
33613-unsigned long __phys_addr(unsigned long x)
33614+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33615 {
33616 unsigned long y = x - __START_KERNEL_map;
33617
33618@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33619 #else
33620
33621 #ifdef CONFIG_DEBUG_VIRTUAL
33622-unsigned long __phys_addr(unsigned long x)
33623+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33624 {
33625 unsigned long phys_addr = x - PAGE_OFFSET;
33626 /* VMALLOC_* aren't constants */
33627diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33628index 90555bf..f5f1828 100644
33629--- a/arch/x86/mm/setup_nx.c
33630+++ b/arch/x86/mm/setup_nx.c
33631@@ -5,8 +5,10 @@
33632 #include <asm/pgtable.h>
33633 #include <asm/proto.h>
33634
33635+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33636 static int disable_nx;
33637
33638+#ifndef CONFIG_PAX_PAGEEXEC
33639 /*
33640 * noexec = on|off
33641 *
33642@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33643 return 0;
33644 }
33645 early_param("noexec", noexec_setup);
33646+#endif
33647+
33648+#endif
33649
33650 void x86_configure_nx(void)
33651 {
33652+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33653 if (cpu_has_nx && !disable_nx)
33654 __supported_pte_mask |= _PAGE_NX;
33655 else
33656+#endif
33657 __supported_pte_mask &= ~_PAGE_NX;
33658 }
33659
33660diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33661index dd8dda1..9e9b0f6 100644
33662--- a/arch/x86/mm/tlb.c
33663+++ b/arch/x86/mm/tlb.c
33664@@ -48,7 +48,11 @@ void leave_mm(int cpu)
33665 BUG();
33666 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33667 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33668+
33669+#ifndef CONFIG_PAX_PER_CPU_PGD
33670 load_cr3(swapper_pg_dir);
33671+#endif
33672+
33673 }
33674 }
33675 EXPORT_SYMBOL_GPL(leave_mm);
33676diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33677new file mode 100644
33678index 0000000..dace51c
33679--- /dev/null
33680+++ b/arch/x86/mm/uderef_64.c
33681@@ -0,0 +1,37 @@
33682+#include <linux/mm.h>
33683+#include <asm/pgtable.h>
33684+#include <asm/uaccess.h>
33685+
33686+#ifdef CONFIG_PAX_MEMORY_UDEREF
33687+/* PaX: due to the special call convention these functions must
33688+ * - remain leaf functions under all configurations,
33689+ * - never be called directly, only dereferenced from the wrappers.
33690+ */
33691+void __pax_open_userland(void)
33692+{
33693+ unsigned int cpu;
33694+
33695+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33696+ return;
33697+
33698+ cpu = raw_get_cpu();
33699+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33700+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33701+ raw_put_cpu_no_resched();
33702+}
33703+EXPORT_SYMBOL(__pax_open_userland);
33704+
33705+void __pax_close_userland(void)
33706+{
33707+ unsigned int cpu;
33708+
33709+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33710+ return;
33711+
33712+ cpu = raw_get_cpu();
33713+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33714+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33715+ raw_put_cpu_no_resched();
33716+}
33717+EXPORT_SYMBOL(__pax_close_userland);
33718+#endif
33719diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33720index 0149575..f746de8 100644
33721--- a/arch/x86/net/bpf_jit.S
33722+++ b/arch/x86/net/bpf_jit.S
33723@@ -9,6 +9,7 @@
33724 */
33725 #include <linux/linkage.h>
33726 #include <asm/dwarf2.h>
33727+#include <asm/alternative-asm.h>
33728
33729 /*
33730 * Calling convention :
33731@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33732 jle bpf_slow_path_word
33733 mov (SKBDATA,%rsi),%eax
33734 bswap %eax /* ntohl() */
33735+ pax_force_retaddr
33736 ret
33737
33738 sk_load_half:
33739@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33740 jle bpf_slow_path_half
33741 movzwl (SKBDATA,%rsi),%eax
33742 rol $8,%ax # ntohs()
33743+ pax_force_retaddr
33744 ret
33745
33746 sk_load_byte:
33747@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33748 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33749 jle bpf_slow_path_byte
33750 movzbl (SKBDATA,%rsi),%eax
33751+ pax_force_retaddr
33752 ret
33753
33754 /**
33755@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33756 movzbl (SKBDATA,%rsi),%ebx
33757 and $15,%bl
33758 shl $2,%bl
33759+ pax_force_retaddr
33760 ret
33761
33762 /* rsi contains offset and can be scratched */
33763@@ -109,6 +114,7 @@ bpf_slow_path_word:
33764 js bpf_error
33765 mov -12(%rbp),%eax
33766 bswap %eax
33767+ pax_force_retaddr
33768 ret
33769
33770 bpf_slow_path_half:
33771@@ -117,12 +123,14 @@ bpf_slow_path_half:
33772 mov -12(%rbp),%ax
33773 rol $8,%ax
33774 movzwl %ax,%eax
33775+ pax_force_retaddr
33776 ret
33777
33778 bpf_slow_path_byte:
33779 bpf_slow_path_common(1)
33780 js bpf_error
33781 movzbl -12(%rbp),%eax
33782+ pax_force_retaddr
33783 ret
33784
33785 bpf_slow_path_byte_msh:
33786@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33787 and $15,%al
33788 shl $2,%al
33789 xchg %eax,%ebx
33790+ pax_force_retaddr
33791 ret
33792
33793 #define sk_negative_common(SIZE) \
33794@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33795 sk_negative_common(4)
33796 mov (%rax), %eax
33797 bswap %eax
33798+ pax_force_retaddr
33799 ret
33800
33801 bpf_slow_path_half_neg:
33802@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33803 mov (%rax),%ax
33804 rol $8,%ax
33805 movzwl %ax,%eax
33806+ pax_force_retaddr
33807 ret
33808
33809 bpf_slow_path_byte_neg:
33810@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33811 .globl sk_load_byte_negative_offset
33812 sk_negative_common(1)
33813 movzbl (%rax), %eax
33814+ pax_force_retaddr
33815 ret
33816
33817 bpf_slow_path_byte_msh_neg:
33818@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33819 and $15,%al
33820 shl $2,%al
33821 xchg %eax,%ebx
33822+ pax_force_retaddr
33823 ret
33824
33825 bpf_error:
33826@@ -197,4 +210,5 @@ bpf_error:
33827 xor %eax,%eax
33828 mov -8(%rbp),%rbx
33829 leaveq
33830+ pax_force_retaddr
33831 ret
33832diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33833index 6d5663a..f1ec380 100644
33834--- a/arch/x86/net/bpf_jit_comp.c
33835+++ b/arch/x86/net/bpf_jit_comp.c
33836@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33837 return ptr + len;
33838 }
33839
33840+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33841+#define MAX_INSTR_CODE_SIZE 96
33842+#else
33843+#define MAX_INSTR_CODE_SIZE 64
33844+#endif
33845+
33846 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33847
33848 #define EMIT1(b1) EMIT(b1, 1)
33849 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33850 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33851 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33852+
33853+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33854+/* original constant will appear in ecx */
33855+#define DILUTE_CONST_SEQUENCE(_off, _key) \
33856+do { \
33857+ /* mov ecx, randkey */ \
33858+ EMIT1(0xb9); \
33859+ EMIT(_key, 4); \
33860+ /* xor ecx, randkey ^ off */ \
33861+ EMIT2(0x81, 0xf1); \
33862+ EMIT((_key) ^ (_off), 4); \
33863+} while (0)
33864+
33865+#define EMIT1_off32(b1, _off) \
33866+do { \
33867+ switch (b1) { \
33868+ case 0x05: /* add eax, imm32 */ \
33869+ case 0x2d: /* sub eax, imm32 */ \
33870+ case 0x25: /* and eax, imm32 */ \
33871+ case 0x0d: /* or eax, imm32 */ \
33872+ case 0xb8: /* mov eax, imm32 */ \
33873+ case 0x35: /* xor eax, imm32 */ \
33874+ case 0x3d: /* cmp eax, imm32 */ \
33875+ case 0xa9: /* test eax, imm32 */ \
33876+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33877+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33878+ break; \
33879+ case 0xbb: /* mov ebx, imm32 */ \
33880+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33881+ /* mov ebx, ecx */ \
33882+ EMIT2(0x89, 0xcb); \
33883+ break; \
33884+ case 0xbe: /* mov esi, imm32 */ \
33885+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33886+ /* mov esi, ecx */ \
33887+ EMIT2(0x89, 0xce); \
33888+ break; \
33889+ case 0xe8: /* call rel imm32, always to known funcs */ \
33890+ EMIT1(b1); \
33891+ EMIT(_off, 4); \
33892+ break; \
33893+ case 0xe9: /* jmp rel imm32 */ \
33894+ EMIT1(b1); \
33895+ EMIT(_off, 4); \
33896+ /* prevent fall-through, we're not called if off = 0 */ \
33897+ EMIT(0xcccccccc, 4); \
33898+ EMIT(0xcccccccc, 4); \
33899+ break; \
33900+ default: \
33901+ BUILD_BUG(); \
33902+ } \
33903+} while (0)
33904+
33905+#define EMIT2_off32(b1, b2, _off) \
33906+do { \
33907+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33908+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33909+ EMIT(randkey, 4); \
33910+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33911+ EMIT((_off) - randkey, 4); \
33912+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33913+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33914+ /* imul eax, ecx */ \
33915+ EMIT3(0x0f, 0xaf, 0xc1); \
33916+ } else { \
33917+ BUILD_BUG(); \
33918+ } \
33919+} while (0)
33920+#else
33921 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33922+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33923+#endif
33924
33925 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33926 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33927@@ -91,6 +168,24 @@ do { \
33928 #define X86_JBE 0x76
33929 #define X86_JA 0x77
33930
33931+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33932+#define APPEND_FLOW_VERIFY() \
33933+do { \
33934+ /* mov ecx, randkey */ \
33935+ EMIT1(0xb9); \
33936+ EMIT(randkey, 4); \
33937+ /* cmp ecx, randkey */ \
33938+ EMIT2(0x81, 0xf9); \
33939+ EMIT(randkey, 4); \
33940+ /* jz after 8 int 3s */ \
33941+ EMIT2(0x74, 0x08); \
33942+ EMIT(0xcccccccc, 4); \
33943+ EMIT(0xcccccccc, 4); \
33944+} while (0)
33945+#else
33946+#define APPEND_FLOW_VERIFY() do { } while (0)
33947+#endif
33948+
33949 #define EMIT_COND_JMP(op, offset) \
33950 do { \
33951 if (is_near(offset)) \
33952@@ -98,6 +193,7 @@ do { \
33953 else { \
33954 EMIT2(0x0f, op + 0x10); \
33955 EMIT(offset, 4); /* jxx .+off32 */ \
33956+ APPEND_FLOW_VERIFY(); \
33957 } \
33958 } while (0)
33959
33960@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33961 return -1;
33962 }
33963
33964-struct bpf_binary_header {
33965- unsigned int pages;
33966- /* Note : for security reasons, bpf code will follow a randomly
33967- * sized amount of int3 instructions
33968- */
33969- u8 image[];
33970-};
33971-
33972-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33973+/* Note : for security reasons, bpf code will follow a randomly
33974+ * sized amount of int3 instructions
33975+ */
33976+static u8 *bpf_alloc_binary(unsigned int proglen,
33977 u8 **image_ptr)
33978 {
33979 unsigned int sz, hole;
33980- struct bpf_binary_header *header;
33981+ u8 *header;
33982
33983 /* Most of BPF filters are really small,
33984 * but if some of them fill a page, allow at least
33985 * 128 extra bytes to insert a random section of int3
33986 */
33987- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33988- header = module_alloc(sz);
33989+ sz = round_up(proglen + 128, PAGE_SIZE);
33990+ header = module_alloc_exec(sz);
33991 if (!header)
33992 return NULL;
33993
33994+ pax_open_kernel();
33995 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33996+ pax_close_kernel();
33997
33998- header->pages = sz / PAGE_SIZE;
33999- hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34000+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34001
34002 /* insert a random number of int3 instructions before BPF code */
34003- *image_ptr = &header->image[prandom_u32() % hole];
34004+ *image_ptr = &header[prandom_u32() % hole];
34005 return header;
34006 }
34007
34008 void bpf_jit_compile(struct sk_filter *fp)
34009 {
34010- u8 temp[64];
34011+ u8 temp[MAX_INSTR_CODE_SIZE];
34012 u8 *prog;
34013 unsigned int proglen, oldproglen = 0;
34014 int ilen, i;
34015 int t_offset, f_offset;
34016 u8 t_op, f_op, seen = 0, pass;
34017 u8 *image = NULL;
34018- struct bpf_binary_header *header = NULL;
34019+ u8 *header = NULL;
34020 u8 *func;
34021 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
34022 unsigned int cleanup_addr; /* epilogue code offset */
34023 unsigned int *addrs;
34024 const struct sock_filter *filter = fp->insns;
34025 int flen = fp->len;
34026+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34027+ unsigned int randkey;
34028+#endif
34029
34030 if (!bpf_jit_enable)
34031 return;
34032@@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34033 return;
34034
34035 /* Before first pass, make a rough estimation of addrs[]
34036- * each bpf instruction is translated to less than 64 bytes
34037+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
34038 */
34039 for (proglen = 0, i = 0; i < flen; i++) {
34040- proglen += 64;
34041+ proglen += MAX_INSTR_CODE_SIZE;
34042 addrs[i] = proglen;
34043 }
34044 cleanup_addr = proglen; /* epilogue address */
34045@@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34046 for (i = 0; i < flen; i++) {
34047 unsigned int K = filter[i].k;
34048
34049+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34050+ randkey = prandom_u32();
34051+#endif
34052+
34053 switch (filter[i].code) {
34054 case BPF_S_ALU_ADD_X: /* A += X; */
34055 seen |= SEEN_XREG;
34056@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
34057 case BPF_S_ALU_MUL_K: /* A *= K */
34058 if (is_imm8(K))
34059 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
34060- else {
34061- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
34062- EMIT(K, 4);
34063- }
34064+ else
34065+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
34066 break;
34067 case BPF_S_ALU_DIV_X: /* A /= X; */
34068 seen |= SEEN_XREG;
34069@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34070 break;
34071 }
34072 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34073+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34074+ DILUTE_CONST_SEQUENCE(K, randkey);
34075+#else
34076 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34077+#endif
34078 EMIT2(0xf7, 0xf1); /* div %ecx */
34079 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
34080 break;
34081@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34082 if (K == 1)
34083 break;
34084 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34085+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34086+ DILUTE_CONST_SEQUENCE(K, randkey);
34087+#else
34088 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34089+#endif
34090 EMIT2(0xf7, 0xf1); /* div %ecx */
34091 break;
34092 case BPF_S_ALU_AND_X:
34093@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
34094 if (is_imm8(K)) {
34095 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
34096 } else {
34097- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
34098- EMIT(K, 4);
34099+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
34100 }
34101 } else {
34102 EMIT2(0x89,0xde); /* mov %ebx,%esi */
34103@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34104 if (unlikely(proglen + ilen > oldproglen)) {
34105 pr_err("bpb_jit_compile fatal error\n");
34106 kfree(addrs);
34107- module_free(NULL, header);
34108+ module_free_exec(NULL, image);
34109 return;
34110 }
34111+ pax_open_kernel();
34112 memcpy(image + proglen, temp, ilen);
34113+ pax_close_kernel();
34114 }
34115 proglen += ilen;
34116 addrs[i] = proglen;
34117@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34118
34119 if (image) {
34120 bpf_flush_icache(header, image + proglen);
34121- set_memory_ro((unsigned long)header, header->pages);
34122 fp->bpf_func = (void *)image;
34123 fp->jited = 1;
34124 }
34125@@ -783,10 +888,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
34126 {
34127 struct sk_filter *fp = container_of(work, struct sk_filter, work);
34128 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34129- struct bpf_binary_header *header = (void *)addr;
34130
34131- set_memory_rw(addr, header->pages);
34132- module_free(NULL, header);
34133+ set_memory_rw(addr, 1);
34134+ module_free_exec(NULL, (void *)addr);
34135 kfree(fp);
34136 }
34137
34138diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34139index 5d04be5..2beeaa2 100644
34140--- a/arch/x86/oprofile/backtrace.c
34141+++ b/arch/x86/oprofile/backtrace.c
34142@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34143 struct stack_frame_ia32 *fp;
34144 unsigned long bytes;
34145
34146- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34147+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34148 if (bytes != 0)
34149 return NULL;
34150
34151- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34152+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34153
34154 oprofile_add_trace(bufhead[0].return_address);
34155
34156@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34157 struct stack_frame bufhead[2];
34158 unsigned long bytes;
34159
34160- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34161+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34162 if (bytes != 0)
34163 return NULL;
34164
34165@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34166 {
34167 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34168
34169- if (!user_mode_vm(regs)) {
34170+ if (!user_mode(regs)) {
34171 unsigned long stack = kernel_stack_pointer(regs);
34172 if (depth)
34173 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34174diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34175index 379e8bd..6386e09 100644
34176--- a/arch/x86/oprofile/nmi_int.c
34177+++ b/arch/x86/oprofile/nmi_int.c
34178@@ -23,6 +23,7 @@
34179 #include <asm/nmi.h>
34180 #include <asm/msr.h>
34181 #include <asm/apic.h>
34182+#include <asm/pgtable.h>
34183
34184 #include "op_counter.h"
34185 #include "op_x86_model.h"
34186@@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34187 if (ret)
34188 return ret;
34189
34190- if (!model->num_virt_counters)
34191- model->num_virt_counters = model->num_counters;
34192+ if (!model->num_virt_counters) {
34193+ pax_open_kernel();
34194+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34195+ pax_close_kernel();
34196+ }
34197
34198 mux_init(ops);
34199
34200diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34201index 50d86c0..7985318 100644
34202--- a/arch/x86/oprofile/op_model_amd.c
34203+++ b/arch/x86/oprofile/op_model_amd.c
34204@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34205 num_counters = AMD64_NUM_COUNTERS;
34206 }
34207
34208- op_amd_spec.num_counters = num_counters;
34209- op_amd_spec.num_controls = num_counters;
34210- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34211+ pax_open_kernel();
34212+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34213+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34214+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34215+ pax_close_kernel();
34216
34217 return 0;
34218 }
34219diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34220index d90528e..0127e2b 100644
34221--- a/arch/x86/oprofile/op_model_ppro.c
34222+++ b/arch/x86/oprofile/op_model_ppro.c
34223@@ -19,6 +19,7 @@
34224 #include <asm/msr.h>
34225 #include <asm/apic.h>
34226 #include <asm/nmi.h>
34227+#include <asm/pgtable.h>
34228
34229 #include "op_x86_model.h"
34230 #include "op_counter.h"
34231@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34232
34233 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34234
34235- op_arch_perfmon_spec.num_counters = num_counters;
34236- op_arch_perfmon_spec.num_controls = num_counters;
34237+ pax_open_kernel();
34238+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34239+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34240+ pax_close_kernel();
34241 }
34242
34243 static int arch_perfmon_init(struct oprofile_operations *ignore)
34244diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34245index 71e8a67..6a313bb 100644
34246--- a/arch/x86/oprofile/op_x86_model.h
34247+++ b/arch/x86/oprofile/op_x86_model.h
34248@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34249 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34250 struct op_msrs const * const msrs);
34251 #endif
34252-};
34253+} __do_const;
34254
34255 struct op_counter_config;
34256
34257diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34258index 84b9d67..260e5ff 100644
34259--- a/arch/x86/pci/intel_mid_pci.c
34260+++ b/arch/x86/pci/intel_mid_pci.c
34261@@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34262 pr_info("Intel MID platform detected, using MID PCI ops\n");
34263 pci_mmcfg_late_init();
34264 pcibios_enable_irq = intel_mid_pci_irq_enable;
34265- pci_root_ops = intel_mid_pci_ops;
34266+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34267 pci_soc_mode = 1;
34268 /* Continue with standard init */
34269 return 1;
34270diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34271index 84112f5..6334d60 100644
34272--- a/arch/x86/pci/irq.c
34273+++ b/arch/x86/pci/irq.c
34274@@ -50,7 +50,7 @@ struct irq_router {
34275 struct irq_router_handler {
34276 u16 vendor;
34277 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34278-};
34279+} __do_const;
34280
34281 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34282 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34283@@ -790,7 +790,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34284 return 0;
34285 }
34286
34287-static __initdata struct irq_router_handler pirq_routers[] = {
34288+static __initconst const struct irq_router_handler pirq_routers[] = {
34289 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34290 { PCI_VENDOR_ID_AL, ali_router_probe },
34291 { PCI_VENDOR_ID_ITE, ite_router_probe },
34292@@ -817,7 +817,7 @@ static struct pci_dev *pirq_router_dev;
34293 static void __init pirq_find_router(struct irq_router *r)
34294 {
34295 struct irq_routing_table *rt = pirq_table;
34296- struct irq_router_handler *h;
34297+ const struct irq_router_handler *h;
34298
34299 #ifdef CONFIG_PCI_BIOS
34300 if (!rt->signature) {
34301@@ -1090,7 +1090,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34302 return 0;
34303 }
34304
34305-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34306+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34307 {
34308 .callback = fix_broken_hp_bios_irq9,
34309 .ident = "HP Pavilion N5400 Series Laptop",
34310diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34311index c77b24a..c979855 100644
34312--- a/arch/x86/pci/pcbios.c
34313+++ b/arch/x86/pci/pcbios.c
34314@@ -79,7 +79,7 @@ union bios32 {
34315 static struct {
34316 unsigned long address;
34317 unsigned short segment;
34318-} bios32_indirect = { 0, __KERNEL_CS };
34319+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34320
34321 /*
34322 * Returns the entry point for the given service, NULL on error
34323@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34324 unsigned long length; /* %ecx */
34325 unsigned long entry; /* %edx */
34326 unsigned long flags;
34327+ struct desc_struct d, *gdt;
34328
34329 local_irq_save(flags);
34330- __asm__("lcall *(%%edi); cld"
34331+
34332+ gdt = get_cpu_gdt_table(smp_processor_id());
34333+
34334+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34335+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34336+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34337+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34338+
34339+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34340 : "=a" (return_code),
34341 "=b" (address),
34342 "=c" (length),
34343 "=d" (entry)
34344 : "0" (service),
34345 "1" (0),
34346- "D" (&bios32_indirect));
34347+ "D" (&bios32_indirect),
34348+ "r"(__PCIBIOS_DS)
34349+ : "memory");
34350+
34351+ pax_open_kernel();
34352+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34353+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34354+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34355+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34356+ pax_close_kernel();
34357+
34358 local_irq_restore(flags);
34359
34360 switch (return_code) {
34361- case 0:
34362- return address + entry;
34363- case 0x80: /* Not present */
34364- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34365- return 0;
34366- default: /* Shouldn't happen */
34367- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34368- service, return_code);
34369+ case 0: {
34370+ int cpu;
34371+ unsigned char flags;
34372+
34373+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34374+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34375+ printk(KERN_WARNING "bios32_service: not valid\n");
34376 return 0;
34377+ }
34378+ address = address + PAGE_OFFSET;
34379+ length += 16UL; /* some BIOSs underreport this... */
34380+ flags = 4;
34381+ if (length >= 64*1024*1024) {
34382+ length >>= PAGE_SHIFT;
34383+ flags |= 8;
34384+ }
34385+
34386+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34387+ gdt = get_cpu_gdt_table(cpu);
34388+ pack_descriptor(&d, address, length, 0x9b, flags);
34389+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34390+ pack_descriptor(&d, address, length, 0x93, flags);
34391+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34392+ }
34393+ return entry;
34394+ }
34395+ case 0x80: /* Not present */
34396+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34397+ return 0;
34398+ default: /* Shouldn't happen */
34399+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34400+ service, return_code);
34401+ return 0;
34402 }
34403 }
34404
34405 static struct {
34406 unsigned long address;
34407 unsigned short segment;
34408-} pci_indirect = { 0, __KERNEL_CS };
34409+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34410
34411-static int pci_bios_present;
34412+static int pci_bios_present __read_only;
34413
34414 static int check_pcibios(void)
34415 {
34416@@ -131,11 +174,13 @@ static int check_pcibios(void)
34417 unsigned long flags, pcibios_entry;
34418
34419 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34420- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34421+ pci_indirect.address = pcibios_entry;
34422
34423 local_irq_save(flags);
34424- __asm__(
34425- "lcall *(%%edi); cld\n\t"
34426+ __asm__("movw %w6, %%ds\n\t"
34427+ "lcall *%%ss:(%%edi); cld\n\t"
34428+ "push %%ss\n\t"
34429+ "pop %%ds\n\t"
34430 "jc 1f\n\t"
34431 "xor %%ah, %%ah\n"
34432 "1:"
34433@@ -144,7 +189,8 @@ static int check_pcibios(void)
34434 "=b" (ebx),
34435 "=c" (ecx)
34436 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34437- "D" (&pci_indirect)
34438+ "D" (&pci_indirect),
34439+ "r" (__PCIBIOS_DS)
34440 : "memory");
34441 local_irq_restore(flags);
34442
34443@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34444
34445 switch (len) {
34446 case 1:
34447- __asm__("lcall *(%%esi); cld\n\t"
34448+ __asm__("movw %w6, %%ds\n\t"
34449+ "lcall *%%ss:(%%esi); cld\n\t"
34450+ "push %%ss\n\t"
34451+ "pop %%ds\n\t"
34452 "jc 1f\n\t"
34453 "xor %%ah, %%ah\n"
34454 "1:"
34455@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34456 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34457 "b" (bx),
34458 "D" ((long)reg),
34459- "S" (&pci_indirect));
34460+ "S" (&pci_indirect),
34461+ "r" (__PCIBIOS_DS));
34462 /*
34463 * Zero-extend the result beyond 8 bits, do not trust the
34464 * BIOS having done it:
34465@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34466 *value &= 0xff;
34467 break;
34468 case 2:
34469- __asm__("lcall *(%%esi); cld\n\t"
34470+ __asm__("movw %w6, %%ds\n\t"
34471+ "lcall *%%ss:(%%esi); cld\n\t"
34472+ "push %%ss\n\t"
34473+ "pop %%ds\n\t"
34474 "jc 1f\n\t"
34475 "xor %%ah, %%ah\n"
34476 "1:"
34477@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34478 : "1" (PCIBIOS_READ_CONFIG_WORD),
34479 "b" (bx),
34480 "D" ((long)reg),
34481- "S" (&pci_indirect));
34482+ "S" (&pci_indirect),
34483+ "r" (__PCIBIOS_DS));
34484 /*
34485 * Zero-extend the result beyond 16 bits, do not trust the
34486 * BIOS having done it:
34487@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34488 *value &= 0xffff;
34489 break;
34490 case 4:
34491- __asm__("lcall *(%%esi); cld\n\t"
34492+ __asm__("movw %w6, %%ds\n\t"
34493+ "lcall *%%ss:(%%esi); cld\n\t"
34494+ "push %%ss\n\t"
34495+ "pop %%ds\n\t"
34496 "jc 1f\n\t"
34497 "xor %%ah, %%ah\n"
34498 "1:"
34499@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34500 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34501 "b" (bx),
34502 "D" ((long)reg),
34503- "S" (&pci_indirect));
34504+ "S" (&pci_indirect),
34505+ "r" (__PCIBIOS_DS));
34506 break;
34507 }
34508
34509@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34510
34511 switch (len) {
34512 case 1:
34513- __asm__("lcall *(%%esi); cld\n\t"
34514+ __asm__("movw %w6, %%ds\n\t"
34515+ "lcall *%%ss:(%%esi); cld\n\t"
34516+ "push %%ss\n\t"
34517+ "pop %%ds\n\t"
34518 "jc 1f\n\t"
34519 "xor %%ah, %%ah\n"
34520 "1:"
34521@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34522 "c" (value),
34523 "b" (bx),
34524 "D" ((long)reg),
34525- "S" (&pci_indirect));
34526+ "S" (&pci_indirect),
34527+ "r" (__PCIBIOS_DS));
34528 break;
34529 case 2:
34530- __asm__("lcall *(%%esi); cld\n\t"
34531+ __asm__("movw %w6, %%ds\n\t"
34532+ "lcall *%%ss:(%%esi); cld\n\t"
34533+ "push %%ss\n\t"
34534+ "pop %%ds\n\t"
34535 "jc 1f\n\t"
34536 "xor %%ah, %%ah\n"
34537 "1:"
34538@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34539 "c" (value),
34540 "b" (bx),
34541 "D" ((long)reg),
34542- "S" (&pci_indirect));
34543+ "S" (&pci_indirect),
34544+ "r" (__PCIBIOS_DS));
34545 break;
34546 case 4:
34547- __asm__("lcall *(%%esi); cld\n\t"
34548+ __asm__("movw %w6, %%ds\n\t"
34549+ "lcall *%%ss:(%%esi); cld\n\t"
34550+ "push %%ss\n\t"
34551+ "pop %%ds\n\t"
34552 "jc 1f\n\t"
34553 "xor %%ah, %%ah\n"
34554 "1:"
34555@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34556 "c" (value),
34557 "b" (bx),
34558 "D" ((long)reg),
34559- "S" (&pci_indirect));
34560+ "S" (&pci_indirect),
34561+ "r" (__PCIBIOS_DS));
34562 break;
34563 }
34564
34565@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34566
34567 DBG("PCI: Fetching IRQ routing table... ");
34568 __asm__("push %%es\n\t"
34569+ "movw %w8, %%ds\n\t"
34570 "push %%ds\n\t"
34571 "pop %%es\n\t"
34572- "lcall *(%%esi); cld\n\t"
34573+ "lcall *%%ss:(%%esi); cld\n\t"
34574 "pop %%es\n\t"
34575+ "push %%ss\n\t"
34576+ "pop %%ds\n"
34577 "jc 1f\n\t"
34578 "xor %%ah, %%ah\n"
34579 "1:"
34580@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34581 "1" (0),
34582 "D" ((long) &opt),
34583 "S" (&pci_indirect),
34584- "m" (opt)
34585+ "m" (opt),
34586+ "r" (__PCIBIOS_DS)
34587 : "memory");
34588 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34589 if (ret & 0xff00)
34590@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34591 {
34592 int ret;
34593
34594- __asm__("lcall *(%%esi); cld\n\t"
34595+ __asm__("movw %w5, %%ds\n\t"
34596+ "lcall *%%ss:(%%esi); cld\n\t"
34597+ "push %%ss\n\t"
34598+ "pop %%ds\n"
34599 "jc 1f\n\t"
34600 "xor %%ah, %%ah\n"
34601 "1:"
34602@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34603 : "0" (PCIBIOS_SET_PCI_HW_INT),
34604 "b" ((dev->bus->number << 8) | dev->devfn),
34605 "c" ((irq << 8) | (pin + 10)),
34606- "S" (&pci_indirect));
34607+ "S" (&pci_indirect),
34608+ "r" (__PCIBIOS_DS));
34609 return !(ret & 0xff00);
34610 }
34611 EXPORT_SYMBOL(pcibios_set_irq_routing);
34612diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34613index 9ee3491..872192f 100644
34614--- a/arch/x86/platform/efi/efi_32.c
34615+++ b/arch/x86/platform/efi/efi_32.c
34616@@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34617 {
34618 struct desc_ptr gdt_descr;
34619
34620+#ifdef CONFIG_PAX_KERNEXEC
34621+ struct desc_struct d;
34622+#endif
34623+
34624 local_irq_save(efi_rt_eflags);
34625
34626 load_cr3(initial_page_table);
34627 __flush_tlb_all();
34628
34629+#ifdef CONFIG_PAX_KERNEXEC
34630+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34631+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34632+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34633+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34634+#endif
34635+
34636 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34637 gdt_descr.size = GDT_SIZE - 1;
34638 load_gdt(&gdt_descr);
34639@@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34640 {
34641 struct desc_ptr gdt_descr;
34642
34643+#ifdef CONFIG_PAX_KERNEXEC
34644+ struct desc_struct d;
34645+
34646+ memset(&d, 0, sizeof d);
34647+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34648+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34649+#endif
34650+
34651 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34652 gdt_descr.size = GDT_SIZE - 1;
34653 load_gdt(&gdt_descr);
34654
34655+#ifdef CONFIG_PAX_PER_CPU_PGD
34656+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34657+#else
34658 load_cr3(swapper_pg_dir);
34659+#endif
34660+
34661 __flush_tlb_all();
34662
34663 local_irq_restore(efi_rt_eflags);
34664diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34665index 290d397..3906bcd 100644
34666--- a/arch/x86/platform/efi/efi_64.c
34667+++ b/arch/x86/platform/efi/efi_64.c
34668@@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
34669 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34670 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34671 }
34672+
34673+#ifdef CONFIG_PAX_PER_CPU_PGD
34674+ load_cr3(swapper_pg_dir);
34675+#endif
34676+
34677 __flush_tlb_all();
34678 }
34679
34680@@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34681 for (pgd = 0; pgd < n_pgds; pgd++)
34682 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34683 kfree(save_pgd);
34684+
34685+#ifdef CONFIG_PAX_PER_CPU_PGD
34686+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34687+#endif
34688+
34689 __flush_tlb_all();
34690 local_irq_restore(efi_flags);
34691 early_code_mapping_set_exec(0);
34692diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34693index fbe66e6..eae5e38 100644
34694--- a/arch/x86/platform/efi/efi_stub_32.S
34695+++ b/arch/x86/platform/efi/efi_stub_32.S
34696@@ -6,7 +6,9 @@
34697 */
34698
34699 #include <linux/linkage.h>
34700+#include <linux/init.h>
34701 #include <asm/page_types.h>
34702+#include <asm/segment.h>
34703
34704 /*
34705 * efi_call_phys(void *, ...) is a function with variable parameters.
34706@@ -20,7 +22,7 @@
34707 * service functions will comply with gcc calling convention, too.
34708 */
34709
34710-.text
34711+__INIT
34712 ENTRY(efi_call_phys)
34713 /*
34714 * 0. The function can only be called in Linux kernel. So CS has been
34715@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34716 * The mapping of lower virtual memory has been created in prelog and
34717 * epilog.
34718 */
34719- movl $1f, %edx
34720- subl $__PAGE_OFFSET, %edx
34721- jmp *%edx
34722+#ifdef CONFIG_PAX_KERNEXEC
34723+ movl $(__KERNEXEC_EFI_DS), %edx
34724+ mov %edx, %ds
34725+ mov %edx, %es
34726+ mov %edx, %ss
34727+ addl $2f,(1f)
34728+ ljmp *(1f)
34729+
34730+__INITDATA
34731+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34732+.previous
34733+
34734+2:
34735+ subl $2b,(1b)
34736+#else
34737+ jmp 1f-__PAGE_OFFSET
34738 1:
34739+#endif
34740
34741 /*
34742 * 2. Now on the top of stack is the return
34743@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34744 * parameter 2, ..., param n. To make things easy, we save the return
34745 * address of efi_call_phys in a global variable.
34746 */
34747- popl %edx
34748- movl %edx, saved_return_addr
34749- /* get the function pointer into ECX*/
34750- popl %ecx
34751- movl %ecx, efi_rt_function_ptr
34752- movl $2f, %edx
34753- subl $__PAGE_OFFSET, %edx
34754- pushl %edx
34755+ popl (saved_return_addr)
34756+ popl (efi_rt_function_ptr)
34757
34758 /*
34759 * 3. Clear PG bit in %CR0.
34760@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34761 /*
34762 * 5. Call the physical function.
34763 */
34764- jmp *%ecx
34765+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34766
34767-2:
34768 /*
34769 * 6. After EFI runtime service returns, control will return to
34770 * following instruction. We'd better readjust stack pointer first.
34771@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34772 movl %cr0, %edx
34773 orl $0x80000000, %edx
34774 movl %edx, %cr0
34775- jmp 1f
34776-1:
34777+
34778 /*
34779 * 8. Now restore the virtual mode from flat mode by
34780 * adding EIP with PAGE_OFFSET.
34781 */
34782- movl $1f, %edx
34783- jmp *%edx
34784+#ifdef CONFIG_PAX_KERNEXEC
34785+ movl $(__KERNEL_DS), %edx
34786+ mov %edx, %ds
34787+ mov %edx, %es
34788+ mov %edx, %ss
34789+ ljmp $(__KERNEL_CS),$1f
34790+#else
34791+ jmp 1f+__PAGE_OFFSET
34792+#endif
34793 1:
34794
34795 /*
34796 * 9. Balance the stack. And because EAX contain the return value,
34797 * we'd better not clobber it.
34798 */
34799- leal efi_rt_function_ptr, %edx
34800- movl (%edx), %ecx
34801- pushl %ecx
34802+ pushl (efi_rt_function_ptr)
34803
34804 /*
34805- * 10. Push the saved return address onto the stack and return.
34806+ * 10. Return to the saved return address.
34807 */
34808- leal saved_return_addr, %edx
34809- movl (%edx), %ecx
34810- pushl %ecx
34811- ret
34812+ jmpl *(saved_return_addr)
34813 ENDPROC(efi_call_phys)
34814 .previous
34815
34816-.data
34817+__INITDATA
34818 saved_return_addr:
34819 .long 0
34820 efi_rt_function_ptr:
34821diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34822index e0984ef..a062dac 100644
34823--- a/arch/x86/platform/efi/efi_stub_64.S
34824+++ b/arch/x86/platform/efi/efi_stub_64.S
34825@@ -11,6 +11,7 @@
34826 #include <asm/msr.h>
34827 #include <asm/processor-flags.h>
34828 #include <asm/page_types.h>
34829+#include <asm/alternative-asm.h>
34830
34831 #define SAVE_XMM \
34832 mov %rsp, %rax; \
34833@@ -81,6 +82,7 @@ ENTRY(efi_call0)
34834 RESTORE_PGT
34835 addq $32, %rsp
34836 RESTORE_XMM
34837+ pax_force_retaddr 0, 1
34838 ret
34839 ENDPROC(efi_call0)
34840
34841@@ -93,6 +95,7 @@ ENTRY(efi_call1)
34842 RESTORE_PGT
34843 addq $32, %rsp
34844 RESTORE_XMM
34845+ pax_force_retaddr 0, 1
34846 ret
34847 ENDPROC(efi_call1)
34848
34849@@ -105,6 +108,7 @@ ENTRY(efi_call2)
34850 RESTORE_PGT
34851 addq $32, %rsp
34852 RESTORE_XMM
34853+ pax_force_retaddr 0, 1
34854 ret
34855 ENDPROC(efi_call2)
34856
34857@@ -118,6 +122,7 @@ ENTRY(efi_call3)
34858 RESTORE_PGT
34859 addq $32, %rsp
34860 RESTORE_XMM
34861+ pax_force_retaddr 0, 1
34862 ret
34863 ENDPROC(efi_call3)
34864
34865@@ -132,6 +137,7 @@ ENTRY(efi_call4)
34866 RESTORE_PGT
34867 addq $32, %rsp
34868 RESTORE_XMM
34869+ pax_force_retaddr 0, 1
34870 ret
34871 ENDPROC(efi_call4)
34872
34873@@ -147,6 +153,7 @@ ENTRY(efi_call5)
34874 RESTORE_PGT
34875 addq $48, %rsp
34876 RESTORE_XMM
34877+ pax_force_retaddr 0, 1
34878 ret
34879 ENDPROC(efi_call5)
34880
34881@@ -165,6 +172,7 @@ ENTRY(efi_call6)
34882 RESTORE_PGT
34883 addq $48, %rsp
34884 RESTORE_XMM
34885+ pax_force_retaddr 0, 1
34886 ret
34887 ENDPROC(efi_call6)
34888
34889diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34890index 1bbedc4..eb795b5 100644
34891--- a/arch/x86/platform/intel-mid/intel-mid.c
34892+++ b/arch/x86/platform/intel-mid/intel-mid.c
34893@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34894 {
34895 };
34896
34897-static void intel_mid_reboot(void)
34898+static void __noreturn intel_mid_reboot(void)
34899 {
34900 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34901+ BUG();
34902 }
34903
34904 static unsigned long __init intel_mid_calibrate_tsc(void)
34905diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34906index d6ee929..3637cb5 100644
34907--- a/arch/x86/platform/olpc/olpc_dt.c
34908+++ b/arch/x86/platform/olpc/olpc_dt.c
34909@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34910 return res;
34911 }
34912
34913-static struct of_pdt_ops prom_olpc_ops __initdata = {
34914+static struct of_pdt_ops prom_olpc_ops __initconst = {
34915 .nextprop = olpc_dt_nextprop,
34916 .getproplen = olpc_dt_getproplen,
34917 .getproperty = olpc_dt_getproperty,
34918diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34919index 424f4c9..f2a2988 100644
34920--- a/arch/x86/power/cpu.c
34921+++ b/arch/x86/power/cpu.c
34922@@ -137,11 +137,8 @@ static void do_fpu_end(void)
34923 static void fix_processor_context(void)
34924 {
34925 int cpu = smp_processor_id();
34926- struct tss_struct *t = &per_cpu(init_tss, cpu);
34927-#ifdef CONFIG_X86_64
34928- struct desc_struct *desc = get_cpu_gdt_table(cpu);
34929- tss_desc tss;
34930-#endif
34931+ struct tss_struct *t = init_tss + cpu;
34932+
34933 set_tss_desc(cpu, t); /*
34934 * This just modifies memory; should not be
34935 * necessary. But... This is necessary, because
34936@@ -150,10 +147,6 @@ static void fix_processor_context(void)
34937 */
34938
34939 #ifdef CONFIG_X86_64
34940- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34941- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34942- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34943-
34944 syscall_init(); /* This sets MSR_*STAR and related */
34945 #endif
34946 load_TR_desc(); /* This does ltr */
34947diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34948index bad628a..a102610 100644
34949--- a/arch/x86/realmode/init.c
34950+++ b/arch/x86/realmode/init.c
34951@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
34952 __va(real_mode_header->trampoline_header);
34953
34954 #ifdef CONFIG_X86_32
34955- trampoline_header->start = __pa_symbol(startup_32_smp);
34956+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34957+
34958+#ifdef CONFIG_PAX_KERNEXEC
34959+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34960+#endif
34961+
34962+ trampoline_header->boot_cs = __BOOT_CS;
34963 trampoline_header->gdt_limit = __BOOT_DS + 7;
34964 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34965 #else
34966@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
34967 *trampoline_cr4_features = read_cr4();
34968
34969 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34970- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34971+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34972 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34973 #endif
34974 }
34975diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34976index 3497f14..cc73b92 100644
34977--- a/arch/x86/realmode/rm/Makefile
34978+++ b/arch/x86/realmode/rm/Makefile
34979@@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
34980
34981 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
34982 -I$(srctree)/arch/x86/boot
34983+ifdef CONSTIFY_PLUGIN
34984+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34985+endif
34986 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34987 GCOV_PROFILE := n
34988diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34989index a28221d..93c40f1 100644
34990--- a/arch/x86/realmode/rm/header.S
34991+++ b/arch/x86/realmode/rm/header.S
34992@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34993 #endif
34994 /* APM/BIOS reboot */
34995 .long pa_machine_real_restart_asm
34996-#ifdef CONFIG_X86_64
34997+#ifdef CONFIG_X86_32
34998+ .long __KERNEL_CS
34999+#else
35000 .long __KERNEL32_CS
35001 #endif
35002 END(real_mode_header)
35003diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35004index 48ddd76..c26749f 100644
35005--- a/arch/x86/realmode/rm/trampoline_32.S
35006+++ b/arch/x86/realmode/rm/trampoline_32.S
35007@@ -24,6 +24,12 @@
35008 #include <asm/page_types.h>
35009 #include "realmode.h"
35010
35011+#ifdef CONFIG_PAX_KERNEXEC
35012+#define ta(X) (X)
35013+#else
35014+#define ta(X) (pa_ ## X)
35015+#endif
35016+
35017 .text
35018 .code16
35019
35020@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35021
35022 cli # We should be safe anyway
35023
35024- movl tr_start, %eax # where we need to go
35025-
35026 movl $0xA5A5A5A5, trampoline_status
35027 # write marker for master knows we're running
35028
35029@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35030 movw $1, %dx # protected mode (PE) bit
35031 lmsw %dx # into protected mode
35032
35033- ljmpl $__BOOT_CS, $pa_startup_32
35034+ ljmpl *(trampoline_header)
35035
35036 .section ".text32","ax"
35037 .code32
35038@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35039 .balign 8
35040 GLOBAL(trampoline_header)
35041 tr_start: .space 4
35042- tr_gdt_pad: .space 2
35043+ tr_boot_cs: .space 2
35044 tr_gdt: .space 6
35045 END(trampoline_header)
35046
35047diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35048index dac7b20..72dbaca 100644
35049--- a/arch/x86/realmode/rm/trampoline_64.S
35050+++ b/arch/x86/realmode/rm/trampoline_64.S
35051@@ -93,6 +93,7 @@ ENTRY(startup_32)
35052 movl %edx, %gs
35053
35054 movl pa_tr_cr4, %eax
35055+ andl $~X86_CR4_PCIDE, %eax
35056 movl %eax, %cr4 # Enable PAE mode
35057
35058 # Setup trampoline 4 level pagetables
35059@@ -106,7 +107,7 @@ ENTRY(startup_32)
35060 wrmsr
35061
35062 # Enable paging and in turn activate Long Mode
35063- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35064+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
35065 movl %eax, %cr0
35066
35067 /*
35068diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35069index 9e7e147..25a4158 100644
35070--- a/arch/x86/realmode/rm/wakeup_asm.S
35071+++ b/arch/x86/realmode/rm/wakeup_asm.S
35072@@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35073 lgdtl pmode_gdt
35074
35075 /* This really couldn't... */
35076- movl pmode_entry, %eax
35077 movl pmode_cr0, %ecx
35078 movl %ecx, %cr0
35079- ljmpl $__KERNEL_CS, $pa_startup_32
35080- /* -> jmp *%eax in trampoline_32.S */
35081+
35082+ ljmpl *pmode_entry
35083 #else
35084 jmp trampoline_start
35085 #endif
35086diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35087index 604a37e..e49702a 100644
35088--- a/arch/x86/tools/Makefile
35089+++ b/arch/x86/tools/Makefile
35090@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35091
35092 $(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
35093
35094-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35095+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35096 hostprogs-y += relocs
35097 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35098 PHONY += relocs
35099diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35100index bbb1d22..e505211 100644
35101--- a/arch/x86/tools/relocs.c
35102+++ b/arch/x86/tools/relocs.c
35103@@ -1,5 +1,7 @@
35104 /* This is included from relocs_32/64.c */
35105
35106+#include "../../../include/generated/autoconf.h"
35107+
35108 #define ElfW(type) _ElfW(ELF_BITS, type)
35109 #define _ElfW(bits, type) __ElfW(bits, type)
35110 #define __ElfW(bits, type) Elf##bits##_##type
35111@@ -11,6 +13,7 @@
35112 #define Elf_Sym ElfW(Sym)
35113
35114 static Elf_Ehdr ehdr;
35115+static Elf_Phdr *phdr;
35116
35117 struct relocs {
35118 uint32_t *offset;
35119@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35120 }
35121 }
35122
35123+static void read_phdrs(FILE *fp)
35124+{
35125+ unsigned int i;
35126+
35127+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35128+ if (!phdr) {
35129+ die("Unable to allocate %d program headers\n",
35130+ ehdr.e_phnum);
35131+ }
35132+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35133+ die("Seek to %d failed: %s\n",
35134+ ehdr.e_phoff, strerror(errno));
35135+ }
35136+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35137+ die("Cannot read ELF program headers: %s\n",
35138+ strerror(errno));
35139+ }
35140+ for(i = 0; i < ehdr.e_phnum; i++) {
35141+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35142+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35143+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35144+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35145+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35146+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35147+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35148+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35149+ }
35150+
35151+}
35152+
35153 static void read_shdrs(FILE *fp)
35154 {
35155- int i;
35156+ unsigned int i;
35157 Elf_Shdr shdr;
35158
35159 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35160@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35161
35162 static void read_strtabs(FILE *fp)
35163 {
35164- int i;
35165+ unsigned int i;
35166 for (i = 0; i < ehdr.e_shnum; i++) {
35167 struct section *sec = &secs[i];
35168 if (sec->shdr.sh_type != SHT_STRTAB) {
35169@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35170
35171 static void read_symtabs(FILE *fp)
35172 {
35173- int i,j;
35174+ unsigned int i,j;
35175 for (i = 0; i < ehdr.e_shnum; i++) {
35176 struct section *sec = &secs[i];
35177 if (sec->shdr.sh_type != SHT_SYMTAB) {
35178@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35179 }
35180
35181
35182-static void read_relocs(FILE *fp)
35183+static void read_relocs(FILE *fp, int use_real_mode)
35184 {
35185- int i,j;
35186+ unsigned int i,j;
35187+ uint32_t base;
35188+
35189 for (i = 0; i < ehdr.e_shnum; i++) {
35190 struct section *sec = &secs[i];
35191 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35192@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35193 die("Cannot read symbol table: %s\n",
35194 strerror(errno));
35195 }
35196+ base = 0;
35197+
35198+#ifdef CONFIG_X86_32
35199+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35200+ if (phdr[j].p_type != PT_LOAD )
35201+ continue;
35202+ 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)
35203+ continue;
35204+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35205+ break;
35206+ }
35207+#endif
35208+
35209 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35210 Elf_Rel *rel = &sec->reltab[j];
35211- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35212+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35213 rel->r_info = elf_xword_to_cpu(rel->r_info);
35214 #if (SHT_REL_TYPE == SHT_RELA)
35215 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35216@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35217
35218 static void print_absolute_symbols(void)
35219 {
35220- int i;
35221+ unsigned int i;
35222 const char *format;
35223
35224 if (ELF_BITS == 64)
35225@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35226 for (i = 0; i < ehdr.e_shnum; i++) {
35227 struct section *sec = &secs[i];
35228 char *sym_strtab;
35229- int j;
35230+ unsigned int j;
35231
35232 if (sec->shdr.sh_type != SHT_SYMTAB) {
35233 continue;
35234@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35235
35236 static void print_absolute_relocs(void)
35237 {
35238- int i, printed = 0;
35239+ unsigned int i, printed = 0;
35240 const char *format;
35241
35242 if (ELF_BITS == 64)
35243@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35244 struct section *sec_applies, *sec_symtab;
35245 char *sym_strtab;
35246 Elf_Sym *sh_symtab;
35247- int j;
35248+ unsigned int j;
35249 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35250 continue;
35251 }
35252@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35253 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35254 Elf_Sym *sym, const char *symname))
35255 {
35256- int i;
35257+ unsigned int i;
35258 /* Walk through the relocations */
35259 for (i = 0; i < ehdr.e_shnum; i++) {
35260 char *sym_strtab;
35261 Elf_Sym *sh_symtab;
35262 struct section *sec_applies, *sec_symtab;
35263- int j;
35264+ unsigned int j;
35265 struct section *sec = &secs[i];
35266
35267 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35268@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35269 {
35270 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35271 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35272+ char *sym_strtab = sec->link->link->strtab;
35273+
35274+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35275+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35276+ return 0;
35277+
35278+#ifdef CONFIG_PAX_KERNEXEC
35279+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35280+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35281+ return 0;
35282+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35283+ return 0;
35284+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35285+ return 0;
35286+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35287+ return 0;
35288+#endif
35289
35290 switch (r_type) {
35291 case R_386_NONE:
35292@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35293
35294 static void emit_relocs(int as_text, int use_real_mode)
35295 {
35296- int i;
35297+ unsigned int i;
35298 int (*write_reloc)(uint32_t, FILE *) = write32;
35299 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35300 const char *symname);
35301@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35302 {
35303 regex_init(use_real_mode);
35304 read_ehdr(fp);
35305+ read_phdrs(fp);
35306 read_shdrs(fp);
35307 read_strtabs(fp);
35308 read_symtabs(fp);
35309- read_relocs(fp);
35310+ read_relocs(fp, use_real_mode);
35311 if (ELF_BITS == 64)
35312 percpu_init();
35313 if (show_absolute_syms) {
35314diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35315index f40281e..92728c9 100644
35316--- a/arch/x86/um/mem_32.c
35317+++ b/arch/x86/um/mem_32.c
35318@@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35319 gate_vma.vm_start = FIXADDR_USER_START;
35320 gate_vma.vm_end = FIXADDR_USER_END;
35321 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35322- gate_vma.vm_page_prot = __P101;
35323+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35324
35325 return 0;
35326 }
35327diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35328index 80ffa5b..a33bd15 100644
35329--- a/arch/x86/um/tls_32.c
35330+++ b/arch/x86/um/tls_32.c
35331@@ -260,7 +260,7 @@ out:
35332 if (unlikely(task == current &&
35333 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35334 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35335- "without flushed TLS.", current->pid);
35336+ "without flushed TLS.", task_pid_nr(current));
35337 }
35338
35339 return 0;
35340diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35341index c580d12..0a0ba35 100644
35342--- a/arch/x86/vdso/Makefile
35343+++ b/arch/x86/vdso/Makefile
35344@@ -196,7 +196,7 @@ quiet_cmd_vdso = VDSO $@
35345 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35346 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35347
35348-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35349+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35350 $(LTO_CFLAGS)
35351 GCOV_PROFILE := n
35352
35353diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35354index 310c5f0..766d0a7 100644
35355--- a/arch/x86/vdso/vdso32-setup.c
35356+++ b/arch/x86/vdso/vdso32-setup.c
35357@@ -29,6 +29,7 @@
35358 #include <asm/fixmap.h>
35359 #include <asm/hpet.h>
35360 #include <asm/vvar.h>
35361+#include <asm/mman.h>
35362
35363 #ifdef CONFIG_COMPAT_VDSO
35364 #define VDSO_DEFAULT 0
35365@@ -99,7 +100,7 @@ void syscall32_cpu_init(void)
35366 void enable_sep_cpu(void)
35367 {
35368 int cpu = get_cpu();
35369- struct tss_struct *tss = &per_cpu(init_tss, cpu);
35370+ struct tss_struct *tss = init_tss + cpu;
35371
35372 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35373 put_cpu();
35374@@ -167,7 +168,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35375
35376 down_write(&mm->mmap_sem);
35377
35378- addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, 0);
35379+ addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, MAP_EXECUTABLE);
35380 if (IS_ERR_VALUE(addr)) {
35381 ret = addr;
35382 goto up_fail;
35383@@ -175,7 +176,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35384
35385 addr += VDSO_OFFSET(VDSO_PREV_PAGES);
35386
35387- current->mm->context.vdso = (void *)addr;
35388+ current->mm->context.vdso = addr;
35389
35390 /*
35391 * MAYWRITE to allow gdb to COW and set breakpoints
35392@@ -224,11 +225,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35393 #endif
35394
35395 current_thread_info()->sysenter_return =
35396- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35397+ (void __force_user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35398
35399 up_fail:
35400 if (ret)
35401- current->mm->context.vdso = NULL;
35402+ current->mm->context.vdso = 0;
35403
35404 up_write(&mm->mmap_sem);
35405
35406@@ -282,8 +283,14 @@ __initcall(ia32_binfmt_init);
35407
35408 const char *arch_vma_name(struct vm_area_struct *vma)
35409 {
35410- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35411+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35412 return "[vdso]";
35413+
35414+#ifdef CONFIG_PAX_SEGMEXEC
35415+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35416+ return "[vdso]";
35417+#endif
35418+
35419 return NULL;
35420 }
35421
35422diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35423index 1ad1026..1a08abe 100644
35424--- a/arch/x86/vdso/vma.c
35425+++ b/arch/x86/vdso/vma.c
35426@@ -17,8 +17,6 @@
35427 #include <asm/page.h>
35428
35429 #if defined(CONFIG_X86_64)
35430-unsigned int __read_mostly vdso_enabled = 1;
35431-
35432 DECLARE_VDSO_IMAGE(vdso);
35433 extern unsigned short vdso_sync_cpuid;
35434 static unsigned vdso_size;
35435@@ -144,7 +142,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35436 * unaligned here as a result of stack start randomization.
35437 */
35438 addr = PAGE_ALIGN(addr);
35439- addr = align_vdso_addr(addr);
35440
35441 return addr;
35442 }
35443@@ -157,30 +154,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35444 unsigned size)
35445 {
35446 struct mm_struct *mm = current->mm;
35447- unsigned long addr;
35448+ unsigned long addr = 0;
35449 int ret;
35450
35451- if (!vdso_enabled)
35452- return 0;
35453-
35454 down_write(&mm->mmap_sem);
35455+
35456+#ifdef CONFIG_PAX_RANDMMAP
35457+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35458+#endif
35459+
35460 addr = vdso_addr(mm->start_stack, size);
35461+ addr = align_vdso_addr(addr);
35462 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35463 if (IS_ERR_VALUE(addr)) {
35464 ret = addr;
35465 goto up_fail;
35466 }
35467
35468- current->mm->context.vdso = (void *)addr;
35469+ mm->context.vdso = addr;
35470
35471 ret = install_special_mapping(mm, addr, size,
35472 VM_READ|VM_EXEC|
35473 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35474 pages);
35475- if (ret) {
35476- current->mm->context.vdso = NULL;
35477- goto up_fail;
35478- }
35479+ if (ret)
35480+ mm->context.vdso = 0;
35481
35482 up_fail:
35483 up_write(&mm->mmap_sem);
35484@@ -200,11 +198,4 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35485 vdsox32_size);
35486 }
35487 #endif
35488-
35489-static __init int vdso_setup(char *s)
35490-{
35491- vdso_enabled = simple_strtoul(s, NULL, 0);
35492- return 0;
35493-}
35494-__setup("vdso=", vdso_setup);
35495 #endif
35496diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35497index e88fda8..76ce7ce 100644
35498--- a/arch/x86/xen/Kconfig
35499+++ b/arch/x86/xen/Kconfig
35500@@ -9,6 +9,7 @@ config XEN
35501 select XEN_HAVE_PVMMU
35502 depends on X86_64 || (X86_32 && X86_PAE)
35503 depends on X86_TSC
35504+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35505 help
35506 This is the Linux Xen port. Enabling this will allow the
35507 kernel to boot in a paravirtualized environment under the
35508diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35509index c34bfc4..e599673 100644
35510--- a/arch/x86/xen/enlighten.c
35511+++ b/arch/x86/xen/enlighten.c
35512@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35513
35514 struct shared_info xen_dummy_shared_info;
35515
35516-void *xen_initial_gdt;
35517-
35518 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35519 __read_mostly int xen_have_vector_callback;
35520 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35521@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35522 {
35523 unsigned long va = dtr->address;
35524 unsigned int size = dtr->size + 1;
35525- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35526- unsigned long frames[pages];
35527+ unsigned long frames[65536 / PAGE_SIZE];
35528 int f;
35529
35530 /*
35531@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35532 {
35533 unsigned long va = dtr->address;
35534 unsigned int size = dtr->size + 1;
35535- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35536- unsigned long frames[pages];
35537+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35538 int f;
35539
35540 /*
35541@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35542 * 8-byte entries, or 16 4k pages..
35543 */
35544
35545- BUG_ON(size > 65536);
35546+ BUG_ON(size > GDT_SIZE);
35547 BUG_ON(va & ~PAGE_MASK);
35548
35549 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35550@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35551 return 0;
35552 }
35553
35554-static void set_xen_basic_apic_ops(void)
35555+static void __init set_xen_basic_apic_ops(void)
35556 {
35557 apic->read = xen_apic_read;
35558 apic->write = xen_apic_write;
35559@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35560 #endif
35561 };
35562
35563-static void xen_reboot(int reason)
35564+static __noreturn void xen_reboot(int reason)
35565 {
35566 struct sched_shutdown r = { .reason = reason };
35567
35568- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35569- BUG();
35570+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35571+ BUG();
35572 }
35573
35574-static void xen_restart(char *msg)
35575+static __noreturn void xen_restart(char *msg)
35576 {
35577 xen_reboot(SHUTDOWN_reboot);
35578 }
35579
35580-static void xen_emergency_restart(void)
35581+static __noreturn void xen_emergency_restart(void)
35582 {
35583 xen_reboot(SHUTDOWN_reboot);
35584 }
35585
35586-static void xen_machine_halt(void)
35587+static __noreturn void xen_machine_halt(void)
35588 {
35589 xen_reboot(SHUTDOWN_poweroff);
35590 }
35591
35592-static void xen_machine_power_off(void)
35593+static __noreturn void xen_machine_power_off(void)
35594 {
35595 if (pm_power_off)
35596 pm_power_off();
35597@@ -1564,7 +1560,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35598 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35599
35600 /* Work out if we support NX */
35601- x86_configure_nx();
35602+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35603+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35604+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35605+ unsigned l, h;
35606+
35607+ __supported_pte_mask |= _PAGE_NX;
35608+ rdmsr(MSR_EFER, l, h);
35609+ l |= EFER_NX;
35610+ wrmsr(MSR_EFER, l, h);
35611+ }
35612+#endif
35613
35614 /* Get mfn list */
35615 xen_build_dynamic_phys_to_machine();
35616@@ -1592,13 +1598,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35617
35618 machine_ops = xen_machine_ops;
35619
35620- /*
35621- * The only reliable way to retain the initial address of the
35622- * percpu gdt_page is to remember it here, so we can go and
35623- * mark it RW later, when the initial percpu area is freed.
35624- */
35625- xen_initial_gdt = &per_cpu(gdt_page, 0);
35626-
35627 xen_smp_init();
35628
35629 #ifdef CONFIG_ACPI_NUMA
35630diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35631index 86e02ea..e3705ca 100644
35632--- a/arch/x86/xen/mmu.c
35633+++ b/arch/x86/xen/mmu.c
35634@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35635 return val;
35636 }
35637
35638-static pteval_t pte_pfn_to_mfn(pteval_t val)
35639+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35640 {
35641 if (val & _PAGE_PRESENT) {
35642 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35643@@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35644 /* L3_k[510] -> level2_kernel_pgt
35645 * L3_i[511] -> level2_fixmap_pgt */
35646 convert_pfn_mfn(level3_kernel_pgt);
35647+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35648+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35649+ convert_pfn_mfn(level3_vmemmap_pgt);
35650 }
35651 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35652 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35653@@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35654 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35655 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35656 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35657+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35658+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35659+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35660 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35661 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35662+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35663 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35664 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35665
35666@@ -2122,6 +2129,7 @@ static void __init xen_post_allocator_init(void)
35667 pv_mmu_ops.set_pud = xen_set_pud;
35668 #if PAGETABLE_LEVELS == 4
35669 pv_mmu_ops.set_pgd = xen_set_pgd;
35670+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35671 #endif
35672
35673 /* This will work as long as patching hasn't happened yet
35674@@ -2200,6 +2208,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35675 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35676 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35677 .set_pgd = xen_set_pgd_hyper,
35678+ .set_pgd_batched = xen_set_pgd_hyper,
35679
35680 .alloc_pud = xen_alloc_pmd_init,
35681 .release_pud = xen_release_pmd_init,
35682diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35683index 7005974..54fb05f 100644
35684--- a/arch/x86/xen/smp.c
35685+++ b/arch/x86/xen/smp.c
35686@@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35687
35688 if (xen_pv_domain()) {
35689 if (!xen_feature(XENFEAT_writable_page_tables))
35690- /* We've switched to the "real" per-cpu gdt, so make
35691- * sure the old memory can be recycled. */
35692- make_lowmem_page_readwrite(xen_initial_gdt);
35693-
35694 #ifdef CONFIG_X86_32
35695 /*
35696 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35697 * expects __USER_DS
35698 */
35699- loadsegment(ds, __USER_DS);
35700- loadsegment(es, __USER_DS);
35701+ loadsegment(ds, __KERNEL_DS);
35702+ loadsegment(es, __KERNEL_DS);
35703 #endif
35704
35705 xen_filter_cpu_maps();
35706@@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35707 #ifdef CONFIG_X86_32
35708 /* Note: PVH is not yet supported on x86_32. */
35709 ctxt->user_regs.fs = __KERNEL_PERCPU;
35710- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35711+ savesegment(gs, ctxt->user_regs.gs);
35712 #endif
35713 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35714
35715@@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35716 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35717 ctxt->flags = VGCF_IN_KERNEL;
35718 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35719- ctxt->user_regs.ds = __USER_DS;
35720- ctxt->user_regs.es = __USER_DS;
35721+ ctxt->user_regs.ds = __KERNEL_DS;
35722+ ctxt->user_regs.es = __KERNEL_DS;
35723 ctxt->user_regs.ss = __KERNEL_DS;
35724
35725 xen_copy_trap_info(ctxt->trap_ctxt);
35726@@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35727 int rc;
35728
35729 per_cpu(current_task, cpu) = idle;
35730+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35731 #ifdef CONFIG_X86_32
35732 irq_ctx_init(cpu);
35733 #else
35734 clear_tsk_thread_flag(idle, TIF_FORK);
35735 #endif
35736- per_cpu(kernel_stack, cpu) =
35737- (unsigned long)task_stack_page(idle) -
35738- KERNEL_STACK_OFFSET + THREAD_SIZE;
35739+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35740
35741 xen_setup_runstate_info(cpu);
35742 xen_setup_timer(cpu);
35743@@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35744
35745 void __init xen_smp_init(void)
35746 {
35747- smp_ops = xen_smp_ops;
35748+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35749 xen_fill_possible_map();
35750 }
35751
35752diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35753index fd92a64..1f72641 100644
35754--- a/arch/x86/xen/xen-asm_32.S
35755+++ b/arch/x86/xen/xen-asm_32.S
35756@@ -99,7 +99,7 @@ ENTRY(xen_iret)
35757 pushw %fs
35758 movl $(__KERNEL_PERCPU), %eax
35759 movl %eax, %fs
35760- movl %fs:xen_vcpu, %eax
35761+ mov PER_CPU_VAR(xen_vcpu), %eax
35762 POP_FS
35763 #else
35764 movl %ss:xen_vcpu, %eax
35765diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35766index 485b695..fda3e7c 100644
35767--- a/arch/x86/xen/xen-head.S
35768+++ b/arch/x86/xen/xen-head.S
35769@@ -39,6 +39,17 @@ ENTRY(startup_xen)
35770 #ifdef CONFIG_X86_32
35771 mov %esi,xen_start_info
35772 mov $init_thread_union+THREAD_SIZE,%esp
35773+#ifdef CONFIG_SMP
35774+ movl $cpu_gdt_table,%edi
35775+ movl $__per_cpu_load,%eax
35776+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35777+ rorl $16,%eax
35778+ movb %al,__KERNEL_PERCPU + 4(%edi)
35779+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35780+ movl $__per_cpu_end - 1,%eax
35781+ subl $__per_cpu_start,%eax
35782+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35783+#endif
35784 #else
35785 mov %rsi,xen_start_info
35786 mov $init_thread_union+THREAD_SIZE,%rsp
35787diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35788index 1cb6f4c..9981524 100644
35789--- a/arch/x86/xen/xen-ops.h
35790+++ b/arch/x86/xen/xen-ops.h
35791@@ -10,8 +10,6 @@
35792 extern const char xen_hypervisor_callback[];
35793 extern const char xen_failsafe_callback[];
35794
35795-extern void *xen_initial_gdt;
35796-
35797 struct trap_info;
35798 void xen_copy_trap_info(struct trap_info *traps);
35799
35800diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35801index 525bd3d..ef888b1 100644
35802--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35803+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35804@@ -119,9 +119,9 @@
35805 ----------------------------------------------------------------------*/
35806
35807 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35808-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35809 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35810 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35811+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35812
35813 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35814 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35815diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35816index 2f33760..835e50a 100644
35817--- a/arch/xtensa/variants/fsf/include/variant/core.h
35818+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35819@@ -11,6 +11,7 @@
35820 #ifndef _XTENSA_CORE_H
35821 #define _XTENSA_CORE_H
35822
35823+#include <linux/const.h>
35824
35825 /****************************************************************************
35826 Parameters Useful for Any Code, USER or PRIVILEGED
35827@@ -112,9 +113,9 @@
35828 ----------------------------------------------------------------------*/
35829
35830 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35831-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35832 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35833 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35834+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35835
35836 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35837 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35838diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35839index af00795..2bb8105 100644
35840--- a/arch/xtensa/variants/s6000/include/variant/core.h
35841+++ b/arch/xtensa/variants/s6000/include/variant/core.h
35842@@ -11,6 +11,7 @@
35843 #ifndef _XTENSA_CORE_CONFIGURATION_H
35844 #define _XTENSA_CORE_CONFIGURATION_H
35845
35846+#include <linux/const.h>
35847
35848 /****************************************************************************
35849 Parameters Useful for Any Code, USER or PRIVILEGED
35850@@ -118,9 +119,9 @@
35851 ----------------------------------------------------------------------*/
35852
35853 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35854-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35855 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35856 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35857+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35858
35859 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35860 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35861diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35862index 95ee425..c9c7237 100644
35863--- a/block/blk-cgroup.c
35864+++ b/block/blk-cgroup.c
35865@@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35866 static struct cgroup_subsys_state *
35867 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35868 {
35869- static atomic64_t id_seq = ATOMIC64_INIT(0);
35870+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35871 struct blkcg *blkcg;
35872
35873 if (!parent_css) {
35874@@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35875
35876 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35877 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35878- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35879+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35880 done:
35881 spin_lock_init(&blkcg->lock);
35882 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35883diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35884index c11d24e..e915d24 100644
35885--- a/block/blk-iopoll.c
35886+++ b/block/blk-iopoll.c
35887@@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35888 }
35889 EXPORT_SYMBOL(blk_iopoll_complete);
35890
35891-static void blk_iopoll_softirq(struct softirq_action *h)
35892+static __latent_entropy void blk_iopoll_softirq(void)
35893 {
35894 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35895 int rearm = 0, budget = blk_iopoll_budget;
35896diff --git a/block/blk-map.c b/block/blk-map.c
35897index f7b22bc..ec2ddf4 100644
35898--- a/block/blk-map.c
35899+++ b/block/blk-map.c
35900@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35901 if (!len || !kbuf)
35902 return -EINVAL;
35903
35904- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35905+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35906 if (do_copy)
35907 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35908 else
35909diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35910index 53b1737..08177d2e 100644
35911--- a/block/blk-softirq.c
35912+++ b/block/blk-softirq.c
35913@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35914 * Softirq action handler - move entries to local list and loop over them
35915 * while passing them to the queue registered handler.
35916 */
35917-static void blk_done_softirq(struct softirq_action *h)
35918+static __latent_entropy void blk_done_softirq(void)
35919 {
35920 struct list_head *cpu_list, local_list;
35921
35922diff --git a/block/bsg.c b/block/bsg.c
35923index 420a5a9..23834aa 100644
35924--- a/block/bsg.c
35925+++ b/block/bsg.c
35926@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35927 struct sg_io_v4 *hdr, struct bsg_device *bd,
35928 fmode_t has_write_perm)
35929 {
35930+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35931+ unsigned char *cmdptr;
35932+
35933 if (hdr->request_len > BLK_MAX_CDB) {
35934 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35935 if (!rq->cmd)
35936 return -ENOMEM;
35937- }
35938+ cmdptr = rq->cmd;
35939+ } else
35940+ cmdptr = tmpcmd;
35941
35942- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35943+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35944 hdr->request_len))
35945 return -EFAULT;
35946
35947+ if (cmdptr != rq->cmd)
35948+ memcpy(rq->cmd, cmdptr, hdr->request_len);
35949+
35950 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35951 if (blk_verify_command(rq->cmd, has_write_perm))
35952 return -EPERM;
35953diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35954index fbd5a67..f24fd95 100644
35955--- a/block/compat_ioctl.c
35956+++ b/block/compat_ioctl.c
35957@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35958 cgc = compat_alloc_user_space(sizeof(*cgc));
35959 cgc32 = compat_ptr(arg);
35960
35961- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35962+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35963 get_user(data, &cgc32->buffer) ||
35964 put_user(compat_ptr(data), &cgc->buffer) ||
35965 copy_in_user(&cgc->buflen, &cgc32->buflen,
35966@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35967 err |= __get_user(f->spec1, &uf->spec1);
35968 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35969 err |= __get_user(name, &uf->name);
35970- f->name = compat_ptr(name);
35971+ f->name = (void __force_kernel *)compat_ptr(name);
35972 if (err) {
35973 err = -EFAULT;
35974 goto out;
35975diff --git a/block/genhd.c b/block/genhd.c
35976index 791f419..89f21c4 100644
35977--- a/block/genhd.c
35978+++ b/block/genhd.c
35979@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35980
35981 /*
35982 * Register device numbers dev..(dev+range-1)
35983- * range must be nonzero
35984+ * Noop if @range is zero.
35985 * The hash chain is sorted on range, so that subranges can override.
35986 */
35987 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35988 struct kobject *(*probe)(dev_t, int *, void *),
35989 int (*lock)(dev_t, void *), void *data)
35990 {
35991- kobj_map(bdev_map, devt, range, module, probe, lock, data);
35992+ if (range)
35993+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
35994 }
35995
35996 EXPORT_SYMBOL(blk_register_region);
35997
35998+/* undo blk_register_region(), noop if @range is zero */
35999 void blk_unregister_region(dev_t devt, unsigned long range)
36000 {
36001- kobj_unmap(bdev_map, devt, range);
36002+ if (range)
36003+ kobj_unmap(bdev_map, devt, range);
36004 }
36005
36006 EXPORT_SYMBOL(blk_unregister_region);
36007diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36008index dc51f46..d5446a8 100644
36009--- a/block/partitions/efi.c
36010+++ b/block/partitions/efi.c
36011@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36012 if (!gpt)
36013 return NULL;
36014
36015+ if (!le32_to_cpu(gpt->num_partition_entries))
36016+ return NULL;
36017+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36018+ if (!pte)
36019+ return NULL;
36020+
36021 count = le32_to_cpu(gpt->num_partition_entries) *
36022 le32_to_cpu(gpt->sizeof_partition_entry);
36023- if (!count)
36024- return NULL;
36025- pte = kmalloc(count, GFP_KERNEL);
36026- if (!pte)
36027- return NULL;
36028-
36029 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36030 (u8 *) pte, count) < count) {
36031 kfree(pte);
36032diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36033index 2648797..92ed21f 100644
36034--- a/block/scsi_ioctl.c
36035+++ b/block/scsi_ioctl.c
36036@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36037 return put_user(0, p);
36038 }
36039
36040-static int sg_get_timeout(struct request_queue *q)
36041+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36042 {
36043 return jiffies_to_clock_t(q->sg_timeout);
36044 }
36045@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
36046 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36047 struct sg_io_hdr *hdr, fmode_t mode)
36048 {
36049- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36050+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36051+ unsigned char *cmdptr;
36052+
36053+ if (rq->cmd != rq->__cmd)
36054+ cmdptr = rq->cmd;
36055+ else
36056+ cmdptr = tmpcmd;
36057+
36058+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36059 return -EFAULT;
36060+
36061+ if (cmdptr != rq->cmd)
36062+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36063+
36064 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36065 return -EPERM;
36066
36067@@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36068 int err;
36069 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36070 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36071+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36072+ unsigned char *cmdptr;
36073
36074 if (!sic)
36075 return -EINVAL;
36076@@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36077 */
36078 err = -EFAULT;
36079 rq->cmd_len = cmdlen;
36080- if (copy_from_user(rq->cmd, sic->data, cmdlen))
36081+
36082+ if (rq->cmd != rq->__cmd)
36083+ cmdptr = rq->cmd;
36084+ else
36085+ cmdptr = tmpcmd;
36086+
36087+ if (copy_from_user(cmdptr, sic->data, cmdlen))
36088 goto error;
36089
36090+ if (rq->cmd != cmdptr)
36091+ memcpy(rq->cmd, cmdptr, cmdlen);
36092+
36093 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36094 goto error;
36095
36096diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36097index 7bdd61b..afec999 100644
36098--- a/crypto/cryptd.c
36099+++ b/crypto/cryptd.c
36100@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36101
36102 struct cryptd_blkcipher_request_ctx {
36103 crypto_completion_t complete;
36104-};
36105+} __no_const;
36106
36107 struct cryptd_hash_ctx {
36108 struct crypto_shash *child;
36109@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36110
36111 struct cryptd_aead_request_ctx {
36112 crypto_completion_t complete;
36113-};
36114+} __no_const;
36115
36116 static void cryptd_queue_worker(struct work_struct *work);
36117
36118diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36119index 309d345..1632720 100644
36120--- a/crypto/pcrypt.c
36121+++ b/crypto/pcrypt.c
36122@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36123 int ret;
36124
36125 pinst->kobj.kset = pcrypt_kset;
36126- ret = kobject_add(&pinst->kobj, NULL, name);
36127+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36128 if (!ret)
36129 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36130
36131diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36132index 6921c7f..78e1af7 100644
36133--- a/drivers/acpi/acpica/hwxfsleep.c
36134+++ b/drivers/acpi/acpica/hwxfsleep.c
36135@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36136 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36137
36138 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36139- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36140- acpi_hw_extended_sleep},
36141- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36142- acpi_hw_extended_wake_prep},
36143- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36144+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36145+ .extended_function = acpi_hw_extended_sleep},
36146+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36147+ .extended_function = acpi_hw_extended_wake_prep},
36148+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36149+ .extended_function = acpi_hw_extended_wake}
36150 };
36151
36152 /*
36153diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36154index e5bcd91..74f050d 100644
36155--- a/drivers/acpi/apei/apei-internal.h
36156+++ b/drivers/acpi/apei/apei-internal.h
36157@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36158 struct apei_exec_ins_type {
36159 u32 flags;
36160 apei_exec_ins_func_t run;
36161-};
36162+} __do_const;
36163
36164 struct apei_exec_context {
36165 u32 ip;
36166diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36167index dab7cb7..f0d2994 100644
36168--- a/drivers/acpi/apei/ghes.c
36169+++ b/drivers/acpi/apei/ghes.c
36170@@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
36171 const struct acpi_hest_generic *generic,
36172 const struct acpi_generic_status *estatus)
36173 {
36174- static atomic_t seqno;
36175+ static atomic_unchecked_t seqno;
36176 unsigned int curr_seqno;
36177 char pfx_seq[64];
36178
36179@@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
36180 else
36181 pfx = KERN_ERR;
36182 }
36183- curr_seqno = atomic_inc_return(&seqno);
36184+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36185 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36186 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36187 pfx_seq, generic->header.source_id);
36188diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36189index a83e3c6..c3d617f 100644
36190--- a/drivers/acpi/bgrt.c
36191+++ b/drivers/acpi/bgrt.c
36192@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36193 if (!bgrt_image)
36194 return -ENODEV;
36195
36196- bin_attr_image.private = bgrt_image;
36197- bin_attr_image.size = bgrt_image_size;
36198+ pax_open_kernel();
36199+ *(void **)&bin_attr_image.private = bgrt_image;
36200+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36201+ pax_close_kernel();
36202
36203 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36204 if (!bgrt_kobj)
36205diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36206index 3d8413d..95f638c 100644
36207--- a/drivers/acpi/blacklist.c
36208+++ b/drivers/acpi/blacklist.c
36209@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36210 u32 is_critical_error;
36211 };
36212
36213-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36214+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36215
36216 /*
36217 * POLICY: If *anything* doesn't work, put it on the blacklist.
36218@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36219 return 0;
36220 }
36221
36222-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36223+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36224 {
36225 .callback = dmi_disable_osi_vista,
36226 .ident = "Fujitsu Siemens",
36227diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36228index c68e724..e863008 100644
36229--- a/drivers/acpi/custom_method.c
36230+++ b/drivers/acpi/custom_method.c
36231@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36232 struct acpi_table_header table;
36233 acpi_status status;
36234
36235+#ifdef CONFIG_GRKERNSEC_KMEM
36236+ return -EPERM;
36237+#endif
36238+
36239 if (!(*ppos)) {
36240 /* parse the table header to get the table length */
36241 if (count <= sizeof(struct acpi_table_header))
36242diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36243index 3dca36d..abaf070 100644
36244--- a/drivers/acpi/processor_idle.c
36245+++ b/drivers/acpi/processor_idle.c
36246@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36247 {
36248 int i, count = CPUIDLE_DRIVER_STATE_START;
36249 struct acpi_processor_cx *cx;
36250- struct cpuidle_state *state;
36251+ cpuidle_state_no_const *state;
36252 struct cpuidle_driver *drv = &acpi_idle_driver;
36253
36254 if (!pr->flags.power_setup_done)
36255diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36256index 38cb978..352c761 100644
36257--- a/drivers/acpi/sysfs.c
36258+++ b/drivers/acpi/sysfs.c
36259@@ -423,11 +423,11 @@ static u32 num_counters;
36260 static struct attribute **all_attrs;
36261 static u32 acpi_gpe_count;
36262
36263-static struct attribute_group interrupt_stats_attr_group = {
36264+static attribute_group_no_const interrupt_stats_attr_group = {
36265 .name = "interrupts",
36266 };
36267
36268-static struct kobj_attribute *counter_attrs;
36269+static kobj_attribute_no_const *counter_attrs;
36270
36271 static void delete_gpe_attr_array(void)
36272 {
36273diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36274index b986145..82bddb8 100644
36275--- a/drivers/ata/libahci.c
36276+++ b/drivers/ata/libahci.c
36277@@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36278 }
36279 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36280
36281-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36282+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36283 struct ata_taskfile *tf, int is_cmd, u16 flags,
36284 unsigned long timeout_msec)
36285 {
36286diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36287index 18d97d5..be690af 100644
36288--- a/drivers/ata/libata-core.c
36289+++ b/drivers/ata/libata-core.c
36290@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36291 static void ata_dev_xfermask(struct ata_device *dev);
36292 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36293
36294-atomic_t ata_print_id = ATOMIC_INIT(0);
36295+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36296
36297 struct ata_force_param {
36298 const char *name;
36299@@ -4858,7 +4858,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36300 struct ata_port *ap;
36301 unsigned int tag;
36302
36303- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36304+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36305 ap = qc->ap;
36306
36307 qc->flags = 0;
36308@@ -4874,7 +4874,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36309 struct ata_port *ap;
36310 struct ata_link *link;
36311
36312- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36313+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36314 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36315 ap = qc->ap;
36316 link = qc->dev->link;
36317@@ -5978,6 +5978,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36318 return;
36319
36320 spin_lock(&lock);
36321+ pax_open_kernel();
36322
36323 for (cur = ops->inherits; cur; cur = cur->inherits) {
36324 void **inherit = (void **)cur;
36325@@ -5991,8 +5992,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36326 if (IS_ERR(*pp))
36327 *pp = NULL;
36328
36329- ops->inherits = NULL;
36330+ *(struct ata_port_operations **)&ops->inherits = NULL;
36331
36332+ pax_close_kernel();
36333 spin_unlock(&lock);
36334 }
36335
36336@@ -6185,7 +6187,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36337
36338 /* give ports names and add SCSI hosts */
36339 for (i = 0; i < host->n_ports; i++) {
36340- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36341+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36342 host->ports[i]->local_port_no = i + 1;
36343 }
36344
36345diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36346index ef8567d..8bdbd03 100644
36347--- a/drivers/ata/libata-scsi.c
36348+++ b/drivers/ata/libata-scsi.c
36349@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36350
36351 if (rc)
36352 return rc;
36353- ap->print_id = atomic_inc_return(&ata_print_id);
36354+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36355 return 0;
36356 }
36357 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36358diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36359index 45b5ab3..98446b8 100644
36360--- a/drivers/ata/libata.h
36361+++ b/drivers/ata/libata.h
36362@@ -53,7 +53,7 @@ enum {
36363 ATA_DNXFER_QUIET = (1 << 31),
36364 };
36365
36366-extern atomic_t ata_print_id;
36367+extern atomic_unchecked_t ata_print_id;
36368 extern int atapi_passthru16;
36369 extern int libata_fua;
36370 extern int libata_noacpi;
36371diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36372index 4edb1a8..84e1658 100644
36373--- a/drivers/ata/pata_arasan_cf.c
36374+++ b/drivers/ata/pata_arasan_cf.c
36375@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36376 /* Handle platform specific quirks */
36377 if (quirk) {
36378 if (quirk & CF_BROKEN_PIO) {
36379- ap->ops->set_piomode = NULL;
36380+ pax_open_kernel();
36381+ *(void **)&ap->ops->set_piomode = NULL;
36382+ pax_close_kernel();
36383 ap->pio_mask = 0;
36384 }
36385 if (quirk & CF_BROKEN_MWDMA)
36386diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36387index f9b983a..887b9d8 100644
36388--- a/drivers/atm/adummy.c
36389+++ b/drivers/atm/adummy.c
36390@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36391 vcc->pop(vcc, skb);
36392 else
36393 dev_kfree_skb_any(skb);
36394- atomic_inc(&vcc->stats->tx);
36395+ atomic_inc_unchecked(&vcc->stats->tx);
36396
36397 return 0;
36398 }
36399diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36400index f1a9198..f466a4a 100644
36401--- a/drivers/atm/ambassador.c
36402+++ b/drivers/atm/ambassador.c
36403@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36404 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36405
36406 // VC layer stats
36407- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36408+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36409
36410 // free the descriptor
36411 kfree (tx_descr);
36412@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36413 dump_skb ("<<<", vc, skb);
36414
36415 // VC layer stats
36416- atomic_inc(&atm_vcc->stats->rx);
36417+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36418 __net_timestamp(skb);
36419 // end of our responsibility
36420 atm_vcc->push (atm_vcc, skb);
36421@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36422 } else {
36423 PRINTK (KERN_INFO, "dropped over-size frame");
36424 // should we count this?
36425- atomic_inc(&atm_vcc->stats->rx_drop);
36426+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36427 }
36428
36429 } else {
36430@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36431 }
36432
36433 if (check_area (skb->data, skb->len)) {
36434- atomic_inc(&atm_vcc->stats->tx_err);
36435+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36436 return -ENOMEM; // ?
36437 }
36438
36439diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36440index 0e3f8f9..765a7a5 100644
36441--- a/drivers/atm/atmtcp.c
36442+++ b/drivers/atm/atmtcp.c
36443@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36444 if (vcc->pop) vcc->pop(vcc,skb);
36445 else dev_kfree_skb(skb);
36446 if (dev_data) return 0;
36447- atomic_inc(&vcc->stats->tx_err);
36448+ atomic_inc_unchecked(&vcc->stats->tx_err);
36449 return -ENOLINK;
36450 }
36451 size = skb->len+sizeof(struct atmtcp_hdr);
36452@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36453 if (!new_skb) {
36454 if (vcc->pop) vcc->pop(vcc,skb);
36455 else dev_kfree_skb(skb);
36456- atomic_inc(&vcc->stats->tx_err);
36457+ atomic_inc_unchecked(&vcc->stats->tx_err);
36458 return -ENOBUFS;
36459 }
36460 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36461@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36462 if (vcc->pop) vcc->pop(vcc,skb);
36463 else dev_kfree_skb(skb);
36464 out_vcc->push(out_vcc,new_skb);
36465- atomic_inc(&vcc->stats->tx);
36466- atomic_inc(&out_vcc->stats->rx);
36467+ atomic_inc_unchecked(&vcc->stats->tx);
36468+ atomic_inc_unchecked(&out_vcc->stats->rx);
36469 return 0;
36470 }
36471
36472@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36473 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36474 read_unlock(&vcc_sklist_lock);
36475 if (!out_vcc) {
36476- atomic_inc(&vcc->stats->tx_err);
36477+ atomic_inc_unchecked(&vcc->stats->tx_err);
36478 goto done;
36479 }
36480 skb_pull(skb,sizeof(struct atmtcp_hdr));
36481@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36482 __net_timestamp(new_skb);
36483 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36484 out_vcc->push(out_vcc,new_skb);
36485- atomic_inc(&vcc->stats->tx);
36486- atomic_inc(&out_vcc->stats->rx);
36487+ atomic_inc_unchecked(&vcc->stats->tx);
36488+ atomic_inc_unchecked(&out_vcc->stats->rx);
36489 done:
36490 if (vcc->pop) vcc->pop(vcc,skb);
36491 else dev_kfree_skb(skb);
36492diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36493index b1955ba..b179940 100644
36494--- a/drivers/atm/eni.c
36495+++ b/drivers/atm/eni.c
36496@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36497 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36498 vcc->dev->number);
36499 length = 0;
36500- atomic_inc(&vcc->stats->rx_err);
36501+ atomic_inc_unchecked(&vcc->stats->rx_err);
36502 }
36503 else {
36504 length = ATM_CELL_SIZE-1; /* no HEC */
36505@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36506 size);
36507 }
36508 eff = length = 0;
36509- atomic_inc(&vcc->stats->rx_err);
36510+ atomic_inc_unchecked(&vcc->stats->rx_err);
36511 }
36512 else {
36513 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36514@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36515 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36516 vcc->dev->number,vcc->vci,length,size << 2,descr);
36517 length = eff = 0;
36518- atomic_inc(&vcc->stats->rx_err);
36519+ atomic_inc_unchecked(&vcc->stats->rx_err);
36520 }
36521 }
36522 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36523@@ -767,7 +767,7 @@ rx_dequeued++;
36524 vcc->push(vcc,skb);
36525 pushed++;
36526 }
36527- atomic_inc(&vcc->stats->rx);
36528+ atomic_inc_unchecked(&vcc->stats->rx);
36529 }
36530 wake_up(&eni_dev->rx_wait);
36531 }
36532@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36533 PCI_DMA_TODEVICE);
36534 if (vcc->pop) vcc->pop(vcc,skb);
36535 else dev_kfree_skb_irq(skb);
36536- atomic_inc(&vcc->stats->tx);
36537+ atomic_inc_unchecked(&vcc->stats->tx);
36538 wake_up(&eni_dev->tx_wait);
36539 dma_complete++;
36540 }
36541diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36542index 82f2ae0..f205c02 100644
36543--- a/drivers/atm/firestream.c
36544+++ b/drivers/atm/firestream.c
36545@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36546 }
36547 }
36548
36549- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36550+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36551
36552 fs_dprintk (FS_DEBUG_TXMEM, "i");
36553 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36554@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36555 #endif
36556 skb_put (skb, qe->p1 & 0xffff);
36557 ATM_SKB(skb)->vcc = atm_vcc;
36558- atomic_inc(&atm_vcc->stats->rx);
36559+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36560 __net_timestamp(skb);
36561 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36562 atm_vcc->push (atm_vcc, skb);
36563@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36564 kfree (pe);
36565 }
36566 if (atm_vcc)
36567- atomic_inc(&atm_vcc->stats->rx_drop);
36568+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36569 break;
36570 case 0x1f: /* Reassembly abort: no buffers. */
36571 /* Silently increment error counter. */
36572 if (atm_vcc)
36573- atomic_inc(&atm_vcc->stats->rx_drop);
36574+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36575 break;
36576 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36577 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36578diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36579index 204814e..cede831 100644
36580--- a/drivers/atm/fore200e.c
36581+++ b/drivers/atm/fore200e.c
36582@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36583 #endif
36584 /* check error condition */
36585 if (*entry->status & STATUS_ERROR)
36586- atomic_inc(&vcc->stats->tx_err);
36587+ atomic_inc_unchecked(&vcc->stats->tx_err);
36588 else
36589- atomic_inc(&vcc->stats->tx);
36590+ atomic_inc_unchecked(&vcc->stats->tx);
36591 }
36592 }
36593
36594@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36595 if (skb == NULL) {
36596 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36597
36598- atomic_inc(&vcc->stats->rx_drop);
36599+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36600 return -ENOMEM;
36601 }
36602
36603@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36604
36605 dev_kfree_skb_any(skb);
36606
36607- atomic_inc(&vcc->stats->rx_drop);
36608+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36609 return -ENOMEM;
36610 }
36611
36612 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36613
36614 vcc->push(vcc, skb);
36615- atomic_inc(&vcc->stats->rx);
36616+ atomic_inc_unchecked(&vcc->stats->rx);
36617
36618 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36619
36620@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36621 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36622 fore200e->atm_dev->number,
36623 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36624- atomic_inc(&vcc->stats->rx_err);
36625+ atomic_inc_unchecked(&vcc->stats->rx_err);
36626 }
36627 }
36628
36629@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36630 goto retry_here;
36631 }
36632
36633- atomic_inc(&vcc->stats->tx_err);
36634+ atomic_inc_unchecked(&vcc->stats->tx_err);
36635
36636 fore200e->tx_sat++;
36637 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36638diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36639index aa6be26..f70a785 100644
36640--- a/drivers/atm/he.c
36641+++ b/drivers/atm/he.c
36642@@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36643
36644 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36645 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36646- atomic_inc(&vcc->stats->rx_drop);
36647+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36648 goto return_host_buffers;
36649 }
36650
36651@@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36652 RBRQ_LEN_ERR(he_dev->rbrq_head)
36653 ? "LEN_ERR" : "",
36654 vcc->vpi, vcc->vci);
36655- atomic_inc(&vcc->stats->rx_err);
36656+ atomic_inc_unchecked(&vcc->stats->rx_err);
36657 goto return_host_buffers;
36658 }
36659
36660@@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36661 vcc->push(vcc, skb);
36662 spin_lock(&he_dev->global_lock);
36663
36664- atomic_inc(&vcc->stats->rx);
36665+ atomic_inc_unchecked(&vcc->stats->rx);
36666
36667 return_host_buffers:
36668 ++pdus_assembled;
36669@@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36670 tpd->vcc->pop(tpd->vcc, tpd->skb);
36671 else
36672 dev_kfree_skb_any(tpd->skb);
36673- atomic_inc(&tpd->vcc->stats->tx_err);
36674+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36675 }
36676 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36677 return;
36678@@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36679 vcc->pop(vcc, skb);
36680 else
36681 dev_kfree_skb_any(skb);
36682- atomic_inc(&vcc->stats->tx_err);
36683+ atomic_inc_unchecked(&vcc->stats->tx_err);
36684 return -EINVAL;
36685 }
36686
36687@@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36688 vcc->pop(vcc, skb);
36689 else
36690 dev_kfree_skb_any(skb);
36691- atomic_inc(&vcc->stats->tx_err);
36692+ atomic_inc_unchecked(&vcc->stats->tx_err);
36693 return -EINVAL;
36694 }
36695 #endif
36696@@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36697 vcc->pop(vcc, skb);
36698 else
36699 dev_kfree_skb_any(skb);
36700- atomic_inc(&vcc->stats->tx_err);
36701+ atomic_inc_unchecked(&vcc->stats->tx_err);
36702 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36703 return -ENOMEM;
36704 }
36705@@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36706 vcc->pop(vcc, skb);
36707 else
36708 dev_kfree_skb_any(skb);
36709- atomic_inc(&vcc->stats->tx_err);
36710+ atomic_inc_unchecked(&vcc->stats->tx_err);
36711 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36712 return -ENOMEM;
36713 }
36714@@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36715 __enqueue_tpd(he_dev, tpd, cid);
36716 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36717
36718- atomic_inc(&vcc->stats->tx);
36719+ atomic_inc_unchecked(&vcc->stats->tx);
36720
36721 return 0;
36722 }
36723diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36724index 1dc0519..1aadaf7 100644
36725--- a/drivers/atm/horizon.c
36726+++ b/drivers/atm/horizon.c
36727@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36728 {
36729 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36730 // VC layer stats
36731- atomic_inc(&vcc->stats->rx);
36732+ atomic_inc_unchecked(&vcc->stats->rx);
36733 __net_timestamp(skb);
36734 // end of our responsibility
36735 vcc->push (vcc, skb);
36736@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36737 dev->tx_iovec = NULL;
36738
36739 // VC layer stats
36740- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36741+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36742
36743 // free the skb
36744 hrz_kfree_skb (skb);
36745diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36746index 1bdf104..9dc44b1 100644
36747--- a/drivers/atm/idt77252.c
36748+++ b/drivers/atm/idt77252.c
36749@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36750 else
36751 dev_kfree_skb(skb);
36752
36753- atomic_inc(&vcc->stats->tx);
36754+ atomic_inc_unchecked(&vcc->stats->tx);
36755 }
36756
36757 atomic_dec(&scq->used);
36758@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36759 if ((sb = dev_alloc_skb(64)) == NULL) {
36760 printk("%s: Can't allocate buffers for aal0.\n",
36761 card->name);
36762- atomic_add(i, &vcc->stats->rx_drop);
36763+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36764 break;
36765 }
36766 if (!atm_charge(vcc, sb->truesize)) {
36767 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36768 card->name);
36769- atomic_add(i - 1, &vcc->stats->rx_drop);
36770+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36771 dev_kfree_skb(sb);
36772 break;
36773 }
36774@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36775 ATM_SKB(sb)->vcc = vcc;
36776 __net_timestamp(sb);
36777 vcc->push(vcc, sb);
36778- atomic_inc(&vcc->stats->rx);
36779+ atomic_inc_unchecked(&vcc->stats->rx);
36780
36781 cell += ATM_CELL_PAYLOAD;
36782 }
36783@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36784 "(CDC: %08x)\n",
36785 card->name, len, rpp->len, readl(SAR_REG_CDC));
36786 recycle_rx_pool_skb(card, rpp);
36787- atomic_inc(&vcc->stats->rx_err);
36788+ atomic_inc_unchecked(&vcc->stats->rx_err);
36789 return;
36790 }
36791 if (stat & SAR_RSQE_CRC) {
36792 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36793 recycle_rx_pool_skb(card, rpp);
36794- atomic_inc(&vcc->stats->rx_err);
36795+ atomic_inc_unchecked(&vcc->stats->rx_err);
36796 return;
36797 }
36798 if (skb_queue_len(&rpp->queue) > 1) {
36799@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36800 RXPRINTK("%s: Can't alloc RX skb.\n",
36801 card->name);
36802 recycle_rx_pool_skb(card, rpp);
36803- atomic_inc(&vcc->stats->rx_err);
36804+ atomic_inc_unchecked(&vcc->stats->rx_err);
36805 return;
36806 }
36807 if (!atm_charge(vcc, skb->truesize)) {
36808@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36809 __net_timestamp(skb);
36810
36811 vcc->push(vcc, skb);
36812- atomic_inc(&vcc->stats->rx);
36813+ atomic_inc_unchecked(&vcc->stats->rx);
36814
36815 return;
36816 }
36817@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36818 __net_timestamp(skb);
36819
36820 vcc->push(vcc, skb);
36821- atomic_inc(&vcc->stats->rx);
36822+ atomic_inc_unchecked(&vcc->stats->rx);
36823
36824 if (skb->truesize > SAR_FB_SIZE_3)
36825 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36826@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36827 if (vcc->qos.aal != ATM_AAL0) {
36828 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36829 card->name, vpi, vci);
36830- atomic_inc(&vcc->stats->rx_drop);
36831+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36832 goto drop;
36833 }
36834
36835 if ((sb = dev_alloc_skb(64)) == NULL) {
36836 printk("%s: Can't allocate buffers for AAL0.\n",
36837 card->name);
36838- atomic_inc(&vcc->stats->rx_err);
36839+ atomic_inc_unchecked(&vcc->stats->rx_err);
36840 goto drop;
36841 }
36842
36843@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36844 ATM_SKB(sb)->vcc = vcc;
36845 __net_timestamp(sb);
36846 vcc->push(vcc, sb);
36847- atomic_inc(&vcc->stats->rx);
36848+ atomic_inc_unchecked(&vcc->stats->rx);
36849
36850 drop:
36851 skb_pull(queue, 64);
36852@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36853
36854 if (vc == NULL) {
36855 printk("%s: NULL connection in send().\n", card->name);
36856- atomic_inc(&vcc->stats->tx_err);
36857+ atomic_inc_unchecked(&vcc->stats->tx_err);
36858 dev_kfree_skb(skb);
36859 return -EINVAL;
36860 }
36861 if (!test_bit(VCF_TX, &vc->flags)) {
36862 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36863- atomic_inc(&vcc->stats->tx_err);
36864+ atomic_inc_unchecked(&vcc->stats->tx_err);
36865 dev_kfree_skb(skb);
36866 return -EINVAL;
36867 }
36868@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36869 break;
36870 default:
36871 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36872- atomic_inc(&vcc->stats->tx_err);
36873+ atomic_inc_unchecked(&vcc->stats->tx_err);
36874 dev_kfree_skb(skb);
36875 return -EINVAL;
36876 }
36877
36878 if (skb_shinfo(skb)->nr_frags != 0) {
36879 printk("%s: No scatter-gather yet.\n", card->name);
36880- atomic_inc(&vcc->stats->tx_err);
36881+ atomic_inc_unchecked(&vcc->stats->tx_err);
36882 dev_kfree_skb(skb);
36883 return -EINVAL;
36884 }
36885@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36886
36887 err = queue_skb(card, vc, skb, oam);
36888 if (err) {
36889- atomic_inc(&vcc->stats->tx_err);
36890+ atomic_inc_unchecked(&vcc->stats->tx_err);
36891 dev_kfree_skb(skb);
36892 return err;
36893 }
36894@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36895 skb = dev_alloc_skb(64);
36896 if (!skb) {
36897 printk("%s: Out of memory in send_oam().\n", card->name);
36898- atomic_inc(&vcc->stats->tx_err);
36899+ atomic_inc_unchecked(&vcc->stats->tx_err);
36900 return -ENOMEM;
36901 }
36902 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36903diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36904index 4217f29..88f547a 100644
36905--- a/drivers/atm/iphase.c
36906+++ b/drivers/atm/iphase.c
36907@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36908 status = (u_short) (buf_desc_ptr->desc_mode);
36909 if (status & (RX_CER | RX_PTE | RX_OFL))
36910 {
36911- atomic_inc(&vcc->stats->rx_err);
36912+ atomic_inc_unchecked(&vcc->stats->rx_err);
36913 IF_ERR(printk("IA: bad packet, dropping it");)
36914 if (status & RX_CER) {
36915 IF_ERR(printk(" cause: packet CRC error\n");)
36916@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36917 len = dma_addr - buf_addr;
36918 if (len > iadev->rx_buf_sz) {
36919 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36920- atomic_inc(&vcc->stats->rx_err);
36921+ atomic_inc_unchecked(&vcc->stats->rx_err);
36922 goto out_free_desc;
36923 }
36924
36925@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36926 ia_vcc = INPH_IA_VCC(vcc);
36927 if (ia_vcc == NULL)
36928 {
36929- atomic_inc(&vcc->stats->rx_err);
36930+ atomic_inc_unchecked(&vcc->stats->rx_err);
36931 atm_return(vcc, skb->truesize);
36932 dev_kfree_skb_any(skb);
36933 goto INCR_DLE;
36934@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36935 if ((length > iadev->rx_buf_sz) || (length >
36936 (skb->len - sizeof(struct cpcs_trailer))))
36937 {
36938- atomic_inc(&vcc->stats->rx_err);
36939+ atomic_inc_unchecked(&vcc->stats->rx_err);
36940 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36941 length, skb->len);)
36942 atm_return(vcc, skb->truesize);
36943@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36944
36945 IF_RX(printk("rx_dle_intr: skb push");)
36946 vcc->push(vcc,skb);
36947- atomic_inc(&vcc->stats->rx);
36948+ atomic_inc_unchecked(&vcc->stats->rx);
36949 iadev->rx_pkt_cnt++;
36950 }
36951 INCR_DLE:
36952@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36953 {
36954 struct k_sonet_stats *stats;
36955 stats = &PRIV(_ia_dev[board])->sonet_stats;
36956- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36957- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36958- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36959- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36960- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36961- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36962- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36963- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36964- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36965+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36966+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36967+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36968+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36969+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36970+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36971+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36972+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36973+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36974 }
36975 ia_cmds.status = 0;
36976 break;
36977@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36978 if ((desc == 0) || (desc > iadev->num_tx_desc))
36979 {
36980 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36981- atomic_inc(&vcc->stats->tx);
36982+ atomic_inc_unchecked(&vcc->stats->tx);
36983 if (vcc->pop)
36984 vcc->pop(vcc, skb);
36985 else
36986@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36987 ATM_DESC(skb) = vcc->vci;
36988 skb_queue_tail(&iadev->tx_dma_q, skb);
36989
36990- atomic_inc(&vcc->stats->tx);
36991+ atomic_inc_unchecked(&vcc->stats->tx);
36992 iadev->tx_pkt_cnt++;
36993 /* Increment transaction counter */
36994 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36995
36996 #if 0
36997 /* add flow control logic */
36998- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36999+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37000 if (iavcc->vc_desc_cnt > 10) {
37001 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37002 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37003diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37004index fa7d701..1e404c7 100644
37005--- a/drivers/atm/lanai.c
37006+++ b/drivers/atm/lanai.c
37007@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37008 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37009 lanai_endtx(lanai, lvcc);
37010 lanai_free_skb(lvcc->tx.atmvcc, skb);
37011- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37012+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37013 }
37014
37015 /* Try to fill the buffer - don't call unless there is backlog */
37016@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37017 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37018 __net_timestamp(skb);
37019 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37020- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37021+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37022 out:
37023 lvcc->rx.buf.ptr = end;
37024 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37025@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37026 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37027 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37028 lanai->stats.service_rxnotaal5++;
37029- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37030+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37031 return 0;
37032 }
37033 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37034@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37035 int bytes;
37036 read_unlock(&vcc_sklist_lock);
37037 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37038- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37039+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37040 lvcc->stats.x.aal5.service_trash++;
37041 bytes = (SERVICE_GET_END(s) * 16) -
37042 (((unsigned long) lvcc->rx.buf.ptr) -
37043@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37044 }
37045 if (s & SERVICE_STREAM) {
37046 read_unlock(&vcc_sklist_lock);
37047- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37048+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37049 lvcc->stats.x.aal5.service_stream++;
37050 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37051 "PDU on VCI %d!\n", lanai->number, vci);
37052@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37053 return 0;
37054 }
37055 DPRINTK("got rx crc error on vci %d\n", vci);
37056- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37057+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37058 lvcc->stats.x.aal5.service_rxcrc++;
37059 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37060 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37061diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37062index 9988ac9..7c52585 100644
37063--- a/drivers/atm/nicstar.c
37064+++ b/drivers/atm/nicstar.c
37065@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37066 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37067 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37068 card->index);
37069- atomic_inc(&vcc->stats->tx_err);
37070+ atomic_inc_unchecked(&vcc->stats->tx_err);
37071 dev_kfree_skb_any(skb);
37072 return -EINVAL;
37073 }
37074@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37075 if (!vc->tx) {
37076 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37077 card->index);
37078- atomic_inc(&vcc->stats->tx_err);
37079+ atomic_inc_unchecked(&vcc->stats->tx_err);
37080 dev_kfree_skb_any(skb);
37081 return -EINVAL;
37082 }
37083@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37084 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37085 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37086 card->index);
37087- atomic_inc(&vcc->stats->tx_err);
37088+ atomic_inc_unchecked(&vcc->stats->tx_err);
37089 dev_kfree_skb_any(skb);
37090 return -EINVAL;
37091 }
37092
37093 if (skb_shinfo(skb)->nr_frags != 0) {
37094 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37095- atomic_inc(&vcc->stats->tx_err);
37096+ atomic_inc_unchecked(&vcc->stats->tx_err);
37097 dev_kfree_skb_any(skb);
37098 return -EINVAL;
37099 }
37100@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37101 }
37102
37103 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37104- atomic_inc(&vcc->stats->tx_err);
37105+ atomic_inc_unchecked(&vcc->stats->tx_err);
37106 dev_kfree_skb_any(skb);
37107 return -EIO;
37108 }
37109- atomic_inc(&vcc->stats->tx);
37110+ atomic_inc_unchecked(&vcc->stats->tx);
37111
37112 return 0;
37113 }
37114@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37115 printk
37116 ("nicstar%d: Can't allocate buffers for aal0.\n",
37117 card->index);
37118- atomic_add(i, &vcc->stats->rx_drop);
37119+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37120 break;
37121 }
37122 if (!atm_charge(vcc, sb->truesize)) {
37123 RXPRINTK
37124 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37125 card->index);
37126- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37127+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37128 dev_kfree_skb_any(sb);
37129 break;
37130 }
37131@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37132 ATM_SKB(sb)->vcc = vcc;
37133 __net_timestamp(sb);
37134 vcc->push(vcc, sb);
37135- atomic_inc(&vcc->stats->rx);
37136+ atomic_inc_unchecked(&vcc->stats->rx);
37137 cell += ATM_CELL_PAYLOAD;
37138 }
37139
37140@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37141 if (iovb == NULL) {
37142 printk("nicstar%d: Out of iovec buffers.\n",
37143 card->index);
37144- atomic_inc(&vcc->stats->rx_drop);
37145+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37146 recycle_rx_buf(card, skb);
37147 return;
37148 }
37149@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37150 small or large buffer itself. */
37151 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37152 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37153- atomic_inc(&vcc->stats->rx_err);
37154+ atomic_inc_unchecked(&vcc->stats->rx_err);
37155 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37156 NS_MAX_IOVECS);
37157 NS_PRV_IOVCNT(iovb) = 0;
37158@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37159 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37160 card->index);
37161 which_list(card, skb);
37162- atomic_inc(&vcc->stats->rx_err);
37163+ atomic_inc_unchecked(&vcc->stats->rx_err);
37164 recycle_rx_buf(card, skb);
37165 vc->rx_iov = NULL;
37166 recycle_iov_buf(card, iovb);
37167@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37168 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37169 card->index);
37170 which_list(card, skb);
37171- atomic_inc(&vcc->stats->rx_err);
37172+ atomic_inc_unchecked(&vcc->stats->rx_err);
37173 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37174 NS_PRV_IOVCNT(iovb));
37175 vc->rx_iov = NULL;
37176@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37177 printk(" - PDU size mismatch.\n");
37178 else
37179 printk(".\n");
37180- atomic_inc(&vcc->stats->rx_err);
37181+ atomic_inc_unchecked(&vcc->stats->rx_err);
37182 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37183 NS_PRV_IOVCNT(iovb));
37184 vc->rx_iov = NULL;
37185@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37186 /* skb points to a small buffer */
37187 if (!atm_charge(vcc, skb->truesize)) {
37188 push_rxbufs(card, skb);
37189- atomic_inc(&vcc->stats->rx_drop);
37190+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37191 } else {
37192 skb_put(skb, len);
37193 dequeue_sm_buf(card, skb);
37194@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37195 ATM_SKB(skb)->vcc = vcc;
37196 __net_timestamp(skb);
37197 vcc->push(vcc, skb);
37198- atomic_inc(&vcc->stats->rx);
37199+ atomic_inc_unchecked(&vcc->stats->rx);
37200 }
37201 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37202 struct sk_buff *sb;
37203@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37204 if (len <= NS_SMBUFSIZE) {
37205 if (!atm_charge(vcc, sb->truesize)) {
37206 push_rxbufs(card, sb);
37207- atomic_inc(&vcc->stats->rx_drop);
37208+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37209 } else {
37210 skb_put(sb, len);
37211 dequeue_sm_buf(card, sb);
37212@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37213 ATM_SKB(sb)->vcc = vcc;
37214 __net_timestamp(sb);
37215 vcc->push(vcc, sb);
37216- atomic_inc(&vcc->stats->rx);
37217+ atomic_inc_unchecked(&vcc->stats->rx);
37218 }
37219
37220 push_rxbufs(card, skb);
37221@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37222
37223 if (!atm_charge(vcc, skb->truesize)) {
37224 push_rxbufs(card, skb);
37225- atomic_inc(&vcc->stats->rx_drop);
37226+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37227 } else {
37228 dequeue_lg_buf(card, skb);
37229 #ifdef NS_USE_DESTRUCTORS
37230@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37231 ATM_SKB(skb)->vcc = vcc;
37232 __net_timestamp(skb);
37233 vcc->push(vcc, skb);
37234- atomic_inc(&vcc->stats->rx);
37235+ atomic_inc_unchecked(&vcc->stats->rx);
37236 }
37237
37238 push_rxbufs(card, sb);
37239@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37240 printk
37241 ("nicstar%d: Out of huge buffers.\n",
37242 card->index);
37243- atomic_inc(&vcc->stats->rx_drop);
37244+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37245 recycle_iovec_rx_bufs(card,
37246 (struct iovec *)
37247 iovb->data,
37248@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37249 card->hbpool.count++;
37250 } else
37251 dev_kfree_skb_any(hb);
37252- atomic_inc(&vcc->stats->rx_drop);
37253+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37254 } else {
37255 /* Copy the small buffer to the huge buffer */
37256 sb = (struct sk_buff *)iov->iov_base;
37257@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37258 #endif /* NS_USE_DESTRUCTORS */
37259 __net_timestamp(hb);
37260 vcc->push(vcc, hb);
37261- atomic_inc(&vcc->stats->rx);
37262+ atomic_inc_unchecked(&vcc->stats->rx);
37263 }
37264 }
37265
37266diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37267index 943cf0d..37d15d5 100644
37268--- a/drivers/atm/solos-pci.c
37269+++ b/drivers/atm/solos-pci.c
37270@@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37271 }
37272 atm_charge(vcc, skb->truesize);
37273 vcc->push(vcc, skb);
37274- atomic_inc(&vcc->stats->rx);
37275+ atomic_inc_unchecked(&vcc->stats->rx);
37276 break;
37277
37278 case PKT_STATUS:
37279@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37280 vcc = SKB_CB(oldskb)->vcc;
37281
37282 if (vcc) {
37283- atomic_inc(&vcc->stats->tx);
37284+ atomic_inc_unchecked(&vcc->stats->tx);
37285 solos_pop(vcc, oldskb);
37286 } else {
37287 dev_kfree_skb_irq(oldskb);
37288diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37289index 0215934..ce9f5b1 100644
37290--- a/drivers/atm/suni.c
37291+++ b/drivers/atm/suni.c
37292@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37293
37294
37295 #define ADD_LIMITED(s,v) \
37296- atomic_add((v),&stats->s); \
37297- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37298+ atomic_add_unchecked((v),&stats->s); \
37299+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37300
37301
37302 static void suni_hz(unsigned long from_timer)
37303diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37304index 5120a96..e2572bd 100644
37305--- a/drivers/atm/uPD98402.c
37306+++ b/drivers/atm/uPD98402.c
37307@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37308 struct sonet_stats tmp;
37309 int error = 0;
37310
37311- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37312+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37313 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37314 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37315 if (zero && !error) {
37316@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37317
37318
37319 #define ADD_LIMITED(s,v) \
37320- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37321- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37322- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37323+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37324+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37325+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37326
37327
37328 static void stat_event(struct atm_dev *dev)
37329@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37330 if (reason & uPD98402_INT_PFM) stat_event(dev);
37331 if (reason & uPD98402_INT_PCO) {
37332 (void) GET(PCOCR); /* clear interrupt cause */
37333- atomic_add(GET(HECCT),
37334+ atomic_add_unchecked(GET(HECCT),
37335 &PRIV(dev)->sonet_stats.uncorr_hcs);
37336 }
37337 if ((reason & uPD98402_INT_RFO) &&
37338@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37339 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37340 uPD98402_INT_LOS),PIMR); /* enable them */
37341 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37342- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37343- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37344- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37345+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37346+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37347+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37348 return 0;
37349 }
37350
37351diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37352index 969c3c2..9b72956 100644
37353--- a/drivers/atm/zatm.c
37354+++ b/drivers/atm/zatm.c
37355@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37356 }
37357 if (!size) {
37358 dev_kfree_skb_irq(skb);
37359- if (vcc) atomic_inc(&vcc->stats->rx_err);
37360+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37361 continue;
37362 }
37363 if (!atm_charge(vcc,skb->truesize)) {
37364@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37365 skb->len = size;
37366 ATM_SKB(skb)->vcc = vcc;
37367 vcc->push(vcc,skb);
37368- atomic_inc(&vcc->stats->rx);
37369+ atomic_inc_unchecked(&vcc->stats->rx);
37370 }
37371 zout(pos & 0xffff,MTA(mbx));
37372 #if 0 /* probably a stupid idea */
37373@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37374 skb_queue_head(&zatm_vcc->backlog,skb);
37375 break;
37376 }
37377- atomic_inc(&vcc->stats->tx);
37378+ atomic_inc_unchecked(&vcc->stats->tx);
37379 wake_up(&zatm_vcc->tx_wait);
37380 }
37381
37382diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37383index 83e910a..b224a73 100644
37384--- a/drivers/base/bus.c
37385+++ b/drivers/base/bus.c
37386@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37387 return -EINVAL;
37388
37389 mutex_lock(&subsys->p->mutex);
37390- list_add_tail(&sif->node, &subsys->p->interfaces);
37391+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37392 if (sif->add_dev) {
37393 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37394 while ((dev = subsys_dev_iter_next(&iter)))
37395@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37396 subsys = sif->subsys;
37397
37398 mutex_lock(&subsys->p->mutex);
37399- list_del_init(&sif->node);
37400+ pax_list_del_init((struct list_head *)&sif->node);
37401 if (sif->remove_dev) {
37402 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37403 while ((dev = subsys_dev_iter_next(&iter)))
37404diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37405index 25798db..15f130e 100644
37406--- a/drivers/base/devtmpfs.c
37407+++ b/drivers/base/devtmpfs.c
37408@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37409 if (!thread)
37410 return 0;
37411
37412- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37413+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37414 if (err)
37415 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37416 else
37417@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37418 *err = sys_unshare(CLONE_NEWNS);
37419 if (*err)
37420 goto out;
37421- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37422+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37423 if (*err)
37424 goto out;
37425- sys_chdir("/.."); /* will traverse into overmounted root */
37426- sys_chroot(".");
37427+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37428+ sys_chroot((char __force_user *)".");
37429 complete(&setup_done);
37430 while (1) {
37431 spin_lock(&req_lock);
37432diff --git a/drivers/base/node.c b/drivers/base/node.c
37433index 8f7ed99..700dd0c 100644
37434--- a/drivers/base/node.c
37435+++ b/drivers/base/node.c
37436@@ -624,7 +624,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37437 struct node_attr {
37438 struct device_attribute attr;
37439 enum node_states state;
37440-};
37441+} __do_const;
37442
37443 static ssize_t show_node_state(struct device *dev,
37444 struct device_attribute *attr, char *buf)
37445diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37446index ae098a2..0999830 100644
37447--- a/drivers/base/power/domain.c
37448+++ b/drivers/base/power/domain.c
37449@@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37450
37451 if (dev->power.subsys_data->domain_data) {
37452 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37453- gpd_data->ops = (struct gpd_dev_ops){ NULL };
37454+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37455 if (clear_td)
37456- gpd_data->td = (struct gpd_timing_data){ 0 };
37457+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37458
37459 if (--gpd_data->refcount == 0) {
37460 dev->power.subsys_data->domain_data = NULL;
37461@@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37462 {
37463 struct cpuidle_driver *cpuidle_drv;
37464 struct gpd_cpu_data *cpu_data;
37465- struct cpuidle_state *idle_state;
37466+ cpuidle_state_no_const *idle_state;
37467 int ret = 0;
37468
37469 if (IS_ERR_OR_NULL(genpd) || state < 0)
37470@@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37471 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37472 {
37473 struct gpd_cpu_data *cpu_data;
37474- struct cpuidle_state *idle_state;
37475+ cpuidle_state_no_const *idle_state;
37476 int ret = 0;
37477
37478 if (IS_ERR_OR_NULL(genpd))
37479diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37480index 95b181d1..c4f0e19 100644
37481--- a/drivers/base/power/sysfs.c
37482+++ b/drivers/base/power/sysfs.c
37483@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37484 return -EIO;
37485 }
37486 }
37487- return sprintf(buf, p);
37488+ return sprintf(buf, "%s", p);
37489 }
37490
37491 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37492diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37493index 2d56f41..8830f19 100644
37494--- a/drivers/base/power/wakeup.c
37495+++ b/drivers/base/power/wakeup.c
37496@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37497 * They need to be modified together atomically, so it's better to use one
37498 * atomic variable to hold them both.
37499 */
37500-static atomic_t combined_event_count = ATOMIC_INIT(0);
37501+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37502
37503 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37504 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37505
37506 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37507 {
37508- unsigned int comb = atomic_read(&combined_event_count);
37509+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37510
37511 *cnt = (comb >> IN_PROGRESS_BITS);
37512 *inpr = comb & MAX_IN_PROGRESS;
37513@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37514 ws->start_prevent_time = ws->last_time;
37515
37516 /* Increment the counter of events in progress. */
37517- cec = atomic_inc_return(&combined_event_count);
37518+ cec = atomic_inc_return_unchecked(&combined_event_count);
37519
37520 trace_wakeup_source_activate(ws->name, cec);
37521 }
37522@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37523 * Increment the counter of registered wakeup events and decrement the
37524 * couter of wakeup events in progress simultaneously.
37525 */
37526- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37527+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37528 trace_wakeup_source_deactivate(ws->name, cec);
37529
37530 split_counters(&cnt, &inpr);
37531diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37532index e8d11b6..7b1b36f 100644
37533--- a/drivers/base/syscore.c
37534+++ b/drivers/base/syscore.c
37535@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37536 void register_syscore_ops(struct syscore_ops *ops)
37537 {
37538 mutex_lock(&syscore_ops_lock);
37539- list_add_tail(&ops->node, &syscore_ops_list);
37540+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37541 mutex_unlock(&syscore_ops_lock);
37542 }
37543 EXPORT_SYMBOL_GPL(register_syscore_ops);
37544@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37545 void unregister_syscore_ops(struct syscore_ops *ops)
37546 {
37547 mutex_lock(&syscore_ops_lock);
37548- list_del(&ops->node);
37549+ pax_list_del((struct list_head *)&ops->node);
37550 mutex_unlock(&syscore_ops_lock);
37551 }
37552 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37553diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37554index 73894ca..69f64ef 100644
37555--- a/drivers/block/cciss.c
37556+++ b/drivers/block/cciss.c
37557@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37558 while (!list_empty(&h->reqQ)) {
37559 c = list_entry(h->reqQ.next, CommandList_struct, list);
37560 /* can't do anything if fifo is full */
37561- if ((h->access.fifo_full(h))) {
37562+ if ((h->access->fifo_full(h))) {
37563 dev_warn(&h->pdev->dev, "fifo full\n");
37564 break;
37565 }
37566@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37567 h->Qdepth--;
37568
37569 /* Tell the controller execute command */
37570- h->access.submit_command(h, c);
37571+ h->access->submit_command(h, c);
37572
37573 /* Put job onto the completed Q */
37574 addQ(&h->cmpQ, c);
37575@@ -3447,17 +3447,17 @@ startio:
37576
37577 static inline unsigned long get_next_completion(ctlr_info_t *h)
37578 {
37579- return h->access.command_completed(h);
37580+ return h->access->command_completed(h);
37581 }
37582
37583 static inline int interrupt_pending(ctlr_info_t *h)
37584 {
37585- return h->access.intr_pending(h);
37586+ return h->access->intr_pending(h);
37587 }
37588
37589 static inline long interrupt_not_for_us(ctlr_info_t *h)
37590 {
37591- return ((h->access.intr_pending(h) == 0) ||
37592+ return ((h->access->intr_pending(h) == 0) ||
37593 (h->interrupts_enabled == 0));
37594 }
37595
37596@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37597 u32 a;
37598
37599 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37600- return h->access.command_completed(h);
37601+ return h->access->command_completed(h);
37602
37603 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37604 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37605@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37606 trans_support & CFGTBL_Trans_use_short_tags);
37607
37608 /* Change the access methods to the performant access methods */
37609- h->access = SA5_performant_access;
37610+ h->access = &SA5_performant_access;
37611 h->transMethod = CFGTBL_Trans_Performant;
37612
37613 return;
37614@@ -4325,7 +4325,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37615 if (prod_index < 0)
37616 return -ENODEV;
37617 h->product_name = products[prod_index].product_name;
37618- h->access = *(products[prod_index].access);
37619+ h->access = products[prod_index].access;
37620
37621 if (cciss_board_disabled(h)) {
37622 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37623@@ -5057,7 +5057,7 @@ reinit_after_soft_reset:
37624 }
37625
37626 /* make sure the board interrupts are off */
37627- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37628+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37629 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37630 if (rc)
37631 goto clean2;
37632@@ -5107,7 +5107,7 @@ reinit_after_soft_reset:
37633 * fake ones to scoop up any residual completions.
37634 */
37635 spin_lock_irqsave(&h->lock, flags);
37636- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37637+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37638 spin_unlock_irqrestore(&h->lock, flags);
37639 free_irq(h->intr[h->intr_mode], h);
37640 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37641@@ -5127,9 +5127,9 @@ reinit_after_soft_reset:
37642 dev_info(&h->pdev->dev, "Board READY.\n");
37643 dev_info(&h->pdev->dev,
37644 "Waiting for stale completions to drain.\n");
37645- h->access.set_intr_mask(h, CCISS_INTR_ON);
37646+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37647 msleep(10000);
37648- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37649+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37650
37651 rc = controller_reset_failed(h->cfgtable);
37652 if (rc)
37653@@ -5152,7 +5152,7 @@ reinit_after_soft_reset:
37654 cciss_scsi_setup(h);
37655
37656 /* Turn the interrupts on so we can service requests */
37657- h->access.set_intr_mask(h, CCISS_INTR_ON);
37658+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37659
37660 /* Get the firmware version */
37661 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37662@@ -5224,7 +5224,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37663 kfree(flush_buf);
37664 if (return_code != IO_OK)
37665 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37666- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37667+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37668 free_irq(h->intr[h->intr_mode], h);
37669 }
37670
37671diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37672index 7fda30e..2f27946 100644
37673--- a/drivers/block/cciss.h
37674+++ b/drivers/block/cciss.h
37675@@ -101,7 +101,7 @@ struct ctlr_info
37676 /* information about each logical volume */
37677 drive_info_struct *drv[CISS_MAX_LUN];
37678
37679- struct access_method access;
37680+ struct access_method *access;
37681
37682 /* queue and queue Info */
37683 struct list_head reqQ;
37684@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37685 }
37686
37687 static struct access_method SA5_access = {
37688- SA5_submit_command,
37689- SA5_intr_mask,
37690- SA5_fifo_full,
37691- SA5_intr_pending,
37692- SA5_completed,
37693+ .submit_command = SA5_submit_command,
37694+ .set_intr_mask = SA5_intr_mask,
37695+ .fifo_full = SA5_fifo_full,
37696+ .intr_pending = SA5_intr_pending,
37697+ .command_completed = SA5_completed,
37698 };
37699
37700 static struct access_method SA5B_access = {
37701- SA5_submit_command,
37702- SA5B_intr_mask,
37703- SA5_fifo_full,
37704- SA5B_intr_pending,
37705- SA5_completed,
37706+ .submit_command = SA5_submit_command,
37707+ .set_intr_mask = SA5B_intr_mask,
37708+ .fifo_full = SA5_fifo_full,
37709+ .intr_pending = SA5B_intr_pending,
37710+ .command_completed = SA5_completed,
37711 };
37712
37713 static struct access_method SA5_performant_access = {
37714- SA5_submit_command,
37715- SA5_performant_intr_mask,
37716- SA5_fifo_full,
37717- SA5_performant_intr_pending,
37718- SA5_performant_completed,
37719+ .submit_command = SA5_submit_command,
37720+ .set_intr_mask = SA5_performant_intr_mask,
37721+ .fifo_full = SA5_fifo_full,
37722+ .intr_pending = SA5_performant_intr_pending,
37723+ .command_completed = SA5_performant_completed,
37724 };
37725
37726 struct board_type {
37727diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37728index 2b94403..fd6ad1f 100644
37729--- a/drivers/block/cpqarray.c
37730+++ b/drivers/block/cpqarray.c
37731@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37732 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37733 goto Enomem4;
37734 }
37735- hba[i]->access.set_intr_mask(hba[i], 0);
37736+ hba[i]->access->set_intr_mask(hba[i], 0);
37737 if (request_irq(hba[i]->intr, do_ida_intr,
37738 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37739 {
37740@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37741 add_timer(&hba[i]->timer);
37742
37743 /* Enable IRQ now that spinlock and rate limit timer are set up */
37744- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37745+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37746
37747 for(j=0; j<NWD; j++) {
37748 struct gendisk *disk = ida_gendisk[i][j];
37749@@ -694,7 +694,7 @@ DBGINFO(
37750 for(i=0; i<NR_PRODUCTS; i++) {
37751 if (board_id == products[i].board_id) {
37752 c->product_name = products[i].product_name;
37753- c->access = *(products[i].access);
37754+ c->access = products[i].access;
37755 break;
37756 }
37757 }
37758@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37759 hba[ctlr]->intr = intr;
37760 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37761 hba[ctlr]->product_name = products[j].product_name;
37762- hba[ctlr]->access = *(products[j].access);
37763+ hba[ctlr]->access = products[j].access;
37764 hba[ctlr]->ctlr = ctlr;
37765 hba[ctlr]->board_id = board_id;
37766 hba[ctlr]->pci_dev = NULL; /* not PCI */
37767@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37768
37769 while((c = h->reqQ) != NULL) {
37770 /* Can't do anything if we're busy */
37771- if (h->access.fifo_full(h) == 0)
37772+ if (h->access->fifo_full(h) == 0)
37773 return;
37774
37775 /* Get the first entry from the request Q */
37776@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37777 h->Qdepth--;
37778
37779 /* Tell the controller to do our bidding */
37780- h->access.submit_command(h, c);
37781+ h->access->submit_command(h, c);
37782
37783 /* Get onto the completion Q */
37784 addQ(&h->cmpQ, c);
37785@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37786 unsigned long flags;
37787 __u32 a,a1;
37788
37789- istat = h->access.intr_pending(h);
37790+ istat = h->access->intr_pending(h);
37791 /* Is this interrupt for us? */
37792 if (istat == 0)
37793 return IRQ_NONE;
37794@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37795 */
37796 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37797 if (istat & FIFO_NOT_EMPTY) {
37798- while((a = h->access.command_completed(h))) {
37799+ while((a = h->access->command_completed(h))) {
37800 a1 = a; a &= ~3;
37801 if ((c = h->cmpQ) == NULL)
37802 {
37803@@ -1448,11 +1448,11 @@ static int sendcmd(
37804 /*
37805 * Disable interrupt
37806 */
37807- info_p->access.set_intr_mask(info_p, 0);
37808+ info_p->access->set_intr_mask(info_p, 0);
37809 /* Make sure there is room in the command FIFO */
37810 /* Actually it should be completely empty at this time. */
37811 for (i = 200000; i > 0; i--) {
37812- temp = info_p->access.fifo_full(info_p);
37813+ temp = info_p->access->fifo_full(info_p);
37814 if (temp != 0) {
37815 break;
37816 }
37817@@ -1465,7 +1465,7 @@ DBG(
37818 /*
37819 * Send the cmd
37820 */
37821- info_p->access.submit_command(info_p, c);
37822+ info_p->access->submit_command(info_p, c);
37823 complete = pollcomplete(ctlr);
37824
37825 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37826@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37827 * we check the new geometry. Then turn interrupts back on when
37828 * we're done.
37829 */
37830- host->access.set_intr_mask(host, 0);
37831+ host->access->set_intr_mask(host, 0);
37832 getgeometry(ctlr);
37833- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37834+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37835
37836 for(i=0; i<NWD; i++) {
37837 struct gendisk *disk = ida_gendisk[ctlr][i];
37838@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37839 /* Wait (up to 2 seconds) for a command to complete */
37840
37841 for (i = 200000; i > 0; i--) {
37842- done = hba[ctlr]->access.command_completed(hba[ctlr]);
37843+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
37844 if (done == 0) {
37845 udelay(10); /* a short fixed delay */
37846 } else
37847diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37848index be73e9d..7fbf140 100644
37849--- a/drivers/block/cpqarray.h
37850+++ b/drivers/block/cpqarray.h
37851@@ -99,7 +99,7 @@ struct ctlr_info {
37852 drv_info_t drv[NWD];
37853 struct proc_dir_entry *proc;
37854
37855- struct access_method access;
37856+ struct access_method *access;
37857
37858 cmdlist_t *reqQ;
37859 cmdlist_t *cmpQ;
37860diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37861index e7093d4..b364085 100644
37862--- a/drivers/block/drbd/drbd_int.h
37863+++ b/drivers/block/drbd/drbd_int.h
37864@@ -331,7 +331,7 @@ struct drbd_epoch {
37865 struct drbd_connection *connection;
37866 struct list_head list;
37867 unsigned int barrier_nr;
37868- atomic_t epoch_size; /* increased on every request added. */
37869+ atomic_unchecked_t epoch_size; /* increased on every request added. */
37870 atomic_t active; /* increased on every req. added, and dec on every finished. */
37871 unsigned long flags;
37872 };
37873@@ -787,7 +787,7 @@ struct drbd_device {
37874 unsigned int al_tr_number;
37875 int al_tr_cycle;
37876 wait_queue_head_t seq_wait;
37877- atomic_t packet_seq;
37878+ atomic_unchecked_t packet_seq;
37879 unsigned int peer_seq;
37880 spinlock_t peer_seq_lock;
37881 unsigned int minor;
37882@@ -1361,7 +1361,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37883 char __user *uoptval;
37884 int err;
37885
37886- uoptval = (char __user __force *)optval;
37887+ uoptval = (char __force_user *)optval;
37888
37889 set_fs(KERNEL_DS);
37890 if (level == SOL_SOCKET)
37891diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37892index 89c497c..9c736ae 100644
37893--- a/drivers/block/drbd/drbd_interval.c
37894+++ b/drivers/block/drbd/drbd_interval.c
37895@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37896 }
37897
37898 static const struct rb_augment_callbacks augment_callbacks = {
37899- augment_propagate,
37900- augment_copy,
37901- augment_rotate,
37902+ .propagate = augment_propagate,
37903+ .copy = augment_copy,
37904+ .rotate = augment_rotate,
37905 };
37906
37907 /**
37908diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37909index 331e5cc..6d657bce 100644
37910--- a/drivers/block/drbd/drbd_main.c
37911+++ b/drivers/block/drbd/drbd_main.c
37912@@ -1322,7 +1322,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
37913 p->sector = sector;
37914 p->block_id = block_id;
37915 p->blksize = blksize;
37916- p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
37917+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
37918 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
37919 }
37920
37921@@ -1628,7 +1628,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
37922 return -EIO;
37923 p->sector = cpu_to_be64(req->i.sector);
37924 p->block_id = (unsigned long)req;
37925- p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
37926+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
37927 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
37928 if (device->state.conn >= C_SYNC_SOURCE &&
37929 device->state.conn <= C_PAUSED_SYNC_T)
37930@@ -2658,8 +2658,8 @@ void drbd_destroy_connection(struct kref *kref)
37931 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
37932 struct drbd_resource *resource = connection->resource;
37933
37934- if (atomic_read(&connection->current_epoch->epoch_size) != 0)
37935- drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
37936+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
37937+ drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
37938 kfree(connection->current_epoch);
37939
37940 idr_destroy(&connection->peer_devices);
37941diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37942index 526414b..4eb8184 100644
37943--- a/drivers/block/drbd/drbd_nl.c
37944+++ b/drivers/block/drbd/drbd_nl.c
37945@@ -3505,7 +3505,7 @@ out:
37946
37947 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
37948 {
37949- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37950+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37951 struct sk_buff *msg;
37952 struct drbd_genlmsghdr *d_out;
37953 unsigned seq;
37954@@ -3518,7 +3518,7 @@ void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
37955 return;
37956 }
37957
37958- seq = atomic_inc_return(&drbd_genl_seq);
37959+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37960 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37961 if (!msg)
37962 goto failed;
37963diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37964index 68e3992..1aca24a 100644
37965--- a/drivers/block/drbd/drbd_receiver.c
37966+++ b/drivers/block/drbd/drbd_receiver.c
37967@@ -826,7 +826,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
37968 struct drbd_device *device = peer_device->device;
37969 int err;
37970
37971- atomic_set(&device->packet_seq, 0);
37972+ atomic_set_unchecked(&device->packet_seq, 0);
37973 device->peer_seq = 0;
37974
37975 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
37976@@ -1188,7 +1188,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
37977 do {
37978 next_epoch = NULL;
37979
37980- epoch_size = atomic_read(&epoch->epoch_size);
37981+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37982
37983 switch (ev & ~EV_CLEANUP) {
37984 case EV_PUT:
37985@@ -1228,7 +1228,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
37986 rv = FE_DESTROYED;
37987 } else {
37988 epoch->flags = 0;
37989- atomic_set(&epoch->epoch_size, 0);
37990+ atomic_set_unchecked(&epoch->epoch_size, 0);
37991 /* atomic_set(&epoch->active, 0); is already zero */
37992 if (rv == FE_STILL_LIVE)
37993 rv = FE_RECYCLED;
37994@@ -1456,7 +1456,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
37995 conn_wait_active_ee_empty(connection);
37996 drbd_flush(connection);
37997
37998- if (atomic_read(&connection->current_epoch->epoch_size)) {
37999+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38000 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38001 if (epoch)
38002 break;
38003@@ -1469,11 +1469,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38004 }
38005
38006 epoch->flags = 0;
38007- atomic_set(&epoch->epoch_size, 0);
38008+ atomic_set_unchecked(&epoch->epoch_size, 0);
38009 atomic_set(&epoch->active, 0);
38010
38011 spin_lock(&connection->epoch_lock);
38012- if (atomic_read(&connection->current_epoch->epoch_size)) {
38013+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38014 list_add(&epoch->list, &connection->current_epoch->list);
38015 connection->current_epoch = epoch;
38016 connection->epochs++;
38017@@ -2182,7 +2182,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38018
38019 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
38020 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38021- atomic_inc(&connection->current_epoch->epoch_size);
38022+ atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38023 err2 = drbd_drain_block(peer_device, pi->size);
38024 if (!err)
38025 err = err2;
38026@@ -2216,7 +2216,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38027
38028 spin_lock(&connection->epoch_lock);
38029 peer_req->epoch = connection->current_epoch;
38030- atomic_inc(&peer_req->epoch->epoch_size);
38031+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38032 atomic_inc(&peer_req->epoch->active);
38033 spin_unlock(&connection->epoch_lock);
38034
38035@@ -4396,7 +4396,7 @@ struct data_cmd {
38036 int expect_payload;
38037 size_t pkt_size;
38038 int (*fn)(struct drbd_connection *, struct packet_info *);
38039-};
38040+} __do_const;
38041
38042 static struct data_cmd drbd_cmd_handler[] = {
38043 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38044@@ -4506,7 +4506,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38045 if (!list_empty(&connection->current_epoch->list))
38046 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38047 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38048- atomic_set(&connection->current_epoch->epoch_size, 0);
38049+ atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38050 connection->send.seen_any_write_yet = false;
38051
38052 drbd_info(connection, "Connection closed\n");
38053@@ -5281,7 +5281,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38054 struct asender_cmd {
38055 size_t pkt_size;
38056 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38057-};
38058+} __do_const;
38059
38060 static struct asender_cmd asender_tbl[] = {
38061 [P_PING] = { 0, got_Ping },
38062diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38063index f70a230..9dc90d5 100644
38064--- a/drivers/block/loop.c
38065+++ b/drivers/block/loop.c
38066@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38067
38068 file_start_write(file);
38069 set_fs(get_ds());
38070- bw = file->f_op->write(file, buf, len, &pos);
38071+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38072 set_fs(old_fs);
38073 file_end_write(file);
38074 if (likely(bw == len))
38075diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
38076index 091b9ea..f5428f8 100644
38077--- a/drivers/block/null_blk.c
38078+++ b/drivers/block/null_blk.c
38079@@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
38080 return 0;
38081 }
38082
38083-static struct blk_mq_ops null_mq_ops = {
38084- .queue_rq = null_queue_rq,
38085- .map_queue = blk_mq_map_queue,
38086+static struct blk_mq_ops null_mq_single_ops = {
38087+ .queue_rq = null_queue_rq,
38088+ .map_queue = blk_mq_map_queue,
38089 .init_hctx = null_init_hctx,
38090 .complete = null_softirq_done_fn,
38091+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
38092+ .free_hctx = blk_mq_free_single_hw_queue,
38093+};
38094+
38095+static struct blk_mq_ops null_mq_per_node_ops = {
38096+ .queue_rq = null_queue_rq,
38097+ .map_queue = blk_mq_map_queue,
38098+ .init_hctx = null_init_hctx,
38099+ .alloc_hctx = null_alloc_hctx,
38100+ .free_hctx = null_free_hctx,
38101 };
38102
38103 static struct blk_mq_reg null_mq_reg = {
38104- .ops = &null_mq_ops,
38105+ .ops = &null_mq_single_ops,
38106 .queue_depth = 64,
38107 .cmd_size = sizeof(struct nullb_cmd),
38108 .flags = BLK_MQ_F_SHOULD_MERGE,
38109@@ -521,13 +531,8 @@ static int null_add_dev(void)
38110 null_mq_reg.queue_depth = hw_queue_depth;
38111 null_mq_reg.nr_hw_queues = submit_queues;
38112
38113- if (use_per_node_hctx) {
38114- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
38115- null_mq_reg.ops->free_hctx = null_free_hctx;
38116- } else {
38117- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
38118- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
38119- }
38120+ if (use_per_node_hctx)
38121+ null_mq_reg.ops = &null_mq_per_node_ops;
38122
38123 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
38124 } else if (queue_mode == NULL_Q_BIO) {
38125diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38126index a2af73d..c0b8f61 100644
38127--- a/drivers/block/pktcdvd.c
38128+++ b/drivers/block/pktcdvd.c
38129@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38130
38131 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38132 {
38133- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38134+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38135 }
38136
38137 /*
38138@@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38139 return -EROFS;
38140 }
38141 pd->settings.fp = ti.fp;
38142- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38143+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38144
38145 if (ti.nwa_v) {
38146 pd->nwa = be32_to_cpu(ti.next_writable);
38147diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38148index e5565fb..71be10b4 100644
38149--- a/drivers/block/smart1,2.h
38150+++ b/drivers/block/smart1,2.h
38151@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38152 }
38153
38154 static struct access_method smart4_access = {
38155- smart4_submit_command,
38156- smart4_intr_mask,
38157- smart4_fifo_full,
38158- smart4_intr_pending,
38159- smart4_completed,
38160+ .submit_command = smart4_submit_command,
38161+ .set_intr_mask = smart4_intr_mask,
38162+ .fifo_full = smart4_fifo_full,
38163+ .intr_pending = smart4_intr_pending,
38164+ .command_completed = smart4_completed,
38165 };
38166
38167 /*
38168@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38169 }
38170
38171 static struct access_method smart2_access = {
38172- smart2_submit_command,
38173- smart2_intr_mask,
38174- smart2_fifo_full,
38175- smart2_intr_pending,
38176- smart2_completed,
38177+ .submit_command = smart2_submit_command,
38178+ .set_intr_mask = smart2_intr_mask,
38179+ .fifo_full = smart2_fifo_full,
38180+ .intr_pending = smart2_intr_pending,
38181+ .command_completed = smart2_completed,
38182 };
38183
38184 /*
38185@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38186 }
38187
38188 static struct access_method smart2e_access = {
38189- smart2e_submit_command,
38190- smart2e_intr_mask,
38191- smart2e_fifo_full,
38192- smart2e_intr_pending,
38193- smart2e_completed,
38194+ .submit_command = smart2e_submit_command,
38195+ .set_intr_mask = smart2e_intr_mask,
38196+ .fifo_full = smart2e_fifo_full,
38197+ .intr_pending = smart2e_intr_pending,
38198+ .command_completed = smart2e_completed,
38199 };
38200
38201 /*
38202@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38203 }
38204
38205 static struct access_method smart1_access = {
38206- smart1_submit_command,
38207- smart1_intr_mask,
38208- smart1_fifo_full,
38209- smart1_intr_pending,
38210- smart1_completed,
38211+ .submit_command = smart1_submit_command,
38212+ .set_intr_mask = smart1_intr_mask,
38213+ .fifo_full = smart1_fifo_full,
38214+ .intr_pending = smart1_intr_pending,
38215+ .command_completed = smart1_completed,
38216 };
38217diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38218index f038dba..bb74c08 100644
38219--- a/drivers/bluetooth/btwilink.c
38220+++ b/drivers/bluetooth/btwilink.c
38221@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38222
38223 static int bt_ti_probe(struct platform_device *pdev)
38224 {
38225- static struct ti_st *hst;
38226+ struct ti_st *hst;
38227 struct hci_dev *hdev;
38228 int err;
38229
38230diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38231index 8a3aff7..d7538c2 100644
38232--- a/drivers/cdrom/cdrom.c
38233+++ b/drivers/cdrom/cdrom.c
38234@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38235 ENSURE(reset, CDC_RESET);
38236 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38237 cdi->mc_flags = 0;
38238- cdo->n_minors = 0;
38239 cdi->options = CDO_USE_FFLAGS;
38240
38241 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38242@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38243 else
38244 cdi->cdda_method = CDDA_OLD;
38245
38246- if (!cdo->generic_packet)
38247- cdo->generic_packet = cdrom_dummy_generic_packet;
38248+ if (!cdo->generic_packet) {
38249+ pax_open_kernel();
38250+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38251+ pax_close_kernel();
38252+ }
38253
38254 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38255 mutex_lock(&cdrom_mutex);
38256@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38257 if (cdi->exit)
38258 cdi->exit(cdi);
38259
38260- cdi->ops->n_minors--;
38261 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38262 }
38263
38264@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38265 */
38266 nr = nframes;
38267 do {
38268- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38269+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38270 if (cgc.buffer)
38271 break;
38272
38273@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38274 struct cdrom_device_info *cdi;
38275 int ret;
38276
38277- ret = scnprintf(info + *pos, max_size - *pos, header);
38278+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38279 if (!ret)
38280 return 1;
38281
38282diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38283index 51e75ad..39c4c76 100644
38284--- a/drivers/cdrom/gdrom.c
38285+++ b/drivers/cdrom/gdrom.c
38286@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38287 .audio_ioctl = gdrom_audio_ioctl,
38288 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38289 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38290- .n_minors = 1,
38291 };
38292
38293 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38294diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38295index 6e9f74a..50c7ceae 100644
38296--- a/drivers/char/Kconfig
38297+++ b/drivers/char/Kconfig
38298@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38299
38300 config DEVKMEM
38301 bool "/dev/kmem virtual device support"
38302- default y
38303+ default n
38304+ depends on !GRKERNSEC_KMEM
38305 help
38306 Say Y here if you want to support the /dev/kmem device. The
38307 /dev/kmem device is rarely used, but can be used for certain
38308@@ -577,6 +578,7 @@ config DEVPORT
38309 bool
38310 depends on !M68K
38311 depends on ISA || PCI
38312+ depends on !GRKERNSEC_KMEM
38313 default y
38314
38315 source "drivers/s390/char/Kconfig"
38316diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38317index a48e05b..6bac831 100644
38318--- a/drivers/char/agp/compat_ioctl.c
38319+++ b/drivers/char/agp/compat_ioctl.c
38320@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38321 return -ENOMEM;
38322 }
38323
38324- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38325+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38326 sizeof(*usegment) * ureserve.seg_count)) {
38327 kfree(usegment);
38328 kfree(ksegment);
38329diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38330index b297033..fa217ca 100644
38331--- a/drivers/char/agp/frontend.c
38332+++ b/drivers/char/agp/frontend.c
38333@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38334 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38335 return -EFAULT;
38336
38337- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38338+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38339 return -EFAULT;
38340
38341 client = agp_find_client_by_pid(reserve.pid);
38342@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38343 if (segment == NULL)
38344 return -ENOMEM;
38345
38346- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38347+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38348 sizeof(struct agp_segment) * reserve.seg_count)) {
38349 kfree(segment);
38350 return -EFAULT;
38351diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38352index 4f94375..413694e 100644
38353--- a/drivers/char/genrtc.c
38354+++ b/drivers/char/genrtc.c
38355@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38356 switch (cmd) {
38357
38358 case RTC_PLL_GET:
38359+ memset(&pll, 0, sizeof(pll));
38360 if (get_rtc_pll(&pll))
38361 return -EINVAL;
38362 else
38363diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38364index d5d4cd8..22d561d 100644
38365--- a/drivers/char/hpet.c
38366+++ b/drivers/char/hpet.c
38367@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38368 }
38369
38370 static int
38371-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38372+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38373 struct hpet_info *info)
38374 {
38375 struct hpet_timer __iomem *timer;
38376diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38377index 86fe45c..c0ea948 100644
38378--- a/drivers/char/hw_random/intel-rng.c
38379+++ b/drivers/char/hw_random/intel-rng.c
38380@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38381
38382 if (no_fwh_detect)
38383 return -ENODEV;
38384- printk(warning);
38385+ printk("%s", warning);
38386 return -EBUSY;
38387 }
38388
38389diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38390index e6db938..835e3a2 100644
38391--- a/drivers/char/ipmi/ipmi_msghandler.c
38392+++ b/drivers/char/ipmi/ipmi_msghandler.c
38393@@ -438,7 +438,7 @@ struct ipmi_smi {
38394 struct proc_dir_entry *proc_dir;
38395 char proc_dir_name[10];
38396
38397- atomic_t stats[IPMI_NUM_STATS];
38398+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38399
38400 /*
38401 * run_to_completion duplicate of smb_info, smi_info
38402@@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38403 static DEFINE_MUTEX(smi_watchers_mutex);
38404
38405 #define ipmi_inc_stat(intf, stat) \
38406- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38407+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38408 #define ipmi_get_stat(intf, stat) \
38409- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38410+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38411
38412 static int is_lan_addr(struct ipmi_addr *addr)
38413 {
38414@@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38415 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38416 init_waitqueue_head(&intf->waitq);
38417 for (i = 0; i < IPMI_NUM_STATS; i++)
38418- atomic_set(&intf->stats[i], 0);
38419+ atomic_set_unchecked(&intf->stats[i], 0);
38420
38421 intf->proc_dir = NULL;
38422
38423diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38424index 1c4bb4f..719e873 100644
38425--- a/drivers/char/ipmi/ipmi_si_intf.c
38426+++ b/drivers/char/ipmi/ipmi_si_intf.c
38427@@ -285,7 +285,7 @@ struct smi_info {
38428 unsigned char slave_addr;
38429
38430 /* Counters and things for the proc filesystem. */
38431- atomic_t stats[SI_NUM_STATS];
38432+ atomic_unchecked_t stats[SI_NUM_STATS];
38433
38434 struct task_struct *thread;
38435
38436@@ -294,9 +294,9 @@ struct smi_info {
38437 };
38438
38439 #define smi_inc_stat(smi, stat) \
38440- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38441+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38442 #define smi_get_stat(smi, stat) \
38443- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38444+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38445
38446 #define SI_MAX_PARMS 4
38447
38448@@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
38449 atomic_set(&new_smi->req_events, 0);
38450 new_smi->run_to_completion = false;
38451 for (i = 0; i < SI_NUM_STATS; i++)
38452- atomic_set(&new_smi->stats[i], 0);
38453+ atomic_set_unchecked(&new_smi->stats[i], 0);
38454
38455 new_smi->interrupt_disabled = true;
38456 atomic_set(&new_smi->stop_operation, 0);
38457diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38458index 917403f..dddd899 100644
38459--- a/drivers/char/mem.c
38460+++ b/drivers/char/mem.c
38461@@ -18,6 +18,7 @@
38462 #include <linux/raw.h>
38463 #include <linux/tty.h>
38464 #include <linux/capability.h>
38465+#include <linux/security.h>
38466 #include <linux/ptrace.h>
38467 #include <linux/device.h>
38468 #include <linux/highmem.h>
38469@@ -36,6 +37,10 @@
38470
38471 #define DEVPORT_MINOR 4
38472
38473+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38474+extern const struct file_operations grsec_fops;
38475+#endif
38476+
38477 static inline unsigned long size_inside_page(unsigned long start,
38478 unsigned long size)
38479 {
38480@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38481
38482 while (cursor < to) {
38483 if (!devmem_is_allowed(pfn)) {
38484+#ifdef CONFIG_GRKERNSEC_KMEM
38485+ gr_handle_mem_readwrite(from, to);
38486+#else
38487 printk(KERN_INFO
38488 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38489 current->comm, from, to);
38490+#endif
38491 return 0;
38492 }
38493 cursor += PAGE_SIZE;
38494@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38495 }
38496 return 1;
38497 }
38498+#elif defined(CONFIG_GRKERNSEC_KMEM)
38499+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38500+{
38501+ return 0;
38502+}
38503 #else
38504 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38505 {
38506@@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38507
38508 while (count > 0) {
38509 unsigned long remaining;
38510+ char *temp;
38511
38512 sz = size_inside_page(p, count);
38513
38514@@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38515 if (!ptr)
38516 return -EFAULT;
38517
38518- remaining = copy_to_user(buf, ptr, sz);
38519+#ifdef CONFIG_PAX_USERCOPY
38520+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38521+ if (!temp) {
38522+ unxlate_dev_mem_ptr(p, ptr);
38523+ return -ENOMEM;
38524+ }
38525+ memcpy(temp, ptr, sz);
38526+#else
38527+ temp = ptr;
38528+#endif
38529+
38530+ remaining = copy_to_user(buf, temp, sz);
38531+
38532+#ifdef CONFIG_PAX_USERCOPY
38533+ kfree(temp);
38534+#endif
38535+
38536 unxlate_dev_mem_ptr(p, ptr);
38537 if (remaining)
38538 return -EFAULT;
38539@@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38540 size_t count, loff_t *ppos)
38541 {
38542 unsigned long p = *ppos;
38543- ssize_t low_count, read, sz;
38544+ ssize_t low_count, read, sz, err = 0;
38545 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38546- int err = 0;
38547
38548 read = 0;
38549 if (p < (unsigned long) high_memory) {
38550@@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38551 }
38552 #endif
38553 while (low_count > 0) {
38554+ char *temp;
38555+
38556 sz = size_inside_page(p, low_count);
38557
38558 /*
38559@@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38560 */
38561 kbuf = xlate_dev_kmem_ptr((char *)p);
38562
38563- if (copy_to_user(buf, kbuf, sz))
38564+#ifdef CONFIG_PAX_USERCOPY
38565+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38566+ if (!temp)
38567+ return -ENOMEM;
38568+ memcpy(temp, kbuf, sz);
38569+#else
38570+ temp = kbuf;
38571+#endif
38572+
38573+ err = copy_to_user(buf, temp, sz);
38574+
38575+#ifdef CONFIG_PAX_USERCOPY
38576+ kfree(temp);
38577+#endif
38578+
38579+ if (err)
38580 return -EFAULT;
38581 buf += sz;
38582 p += sz;
38583@@ -827,6 +874,9 @@ static const struct memdev {
38584 #ifdef CONFIG_PRINTK
38585 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38586 #endif
38587+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38588+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38589+#endif
38590 };
38591
38592 static int memory_open(struct inode *inode, struct file *filp)
38593@@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
38594 continue;
38595
38596 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38597- NULL, devlist[minor].name);
38598+ NULL, "%s", devlist[minor].name);
38599 }
38600
38601 return tty_init();
38602diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38603index 9df78e2..01ba9ae 100644
38604--- a/drivers/char/nvram.c
38605+++ b/drivers/char/nvram.c
38606@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38607
38608 spin_unlock_irq(&rtc_lock);
38609
38610- if (copy_to_user(buf, contents, tmp - contents))
38611+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38612 return -EFAULT;
38613
38614 *ppos = i;
38615diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38616index 8320abd..ec48108 100644
38617--- a/drivers/char/pcmcia/synclink_cs.c
38618+++ b/drivers/char/pcmcia/synclink_cs.c
38619@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38620
38621 if (debug_level >= DEBUG_LEVEL_INFO)
38622 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38623- __FILE__, __LINE__, info->device_name, port->count);
38624+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38625
38626- WARN_ON(!port->count);
38627+ WARN_ON(!atomic_read(&port->count));
38628
38629 if (tty_port_close_start(port, tty, filp) == 0)
38630 goto cleanup;
38631@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38632 cleanup:
38633 if (debug_level >= DEBUG_LEVEL_INFO)
38634 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38635- tty->driver->name, port->count);
38636+ tty->driver->name, atomic_read(&port->count));
38637 }
38638
38639 /* Wait until the transmitter is empty.
38640@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38641
38642 if (debug_level >= DEBUG_LEVEL_INFO)
38643 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38644- __FILE__, __LINE__, tty->driver->name, port->count);
38645+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38646
38647 /* If port is closing, signal caller to try again */
38648 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38649@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38650 goto cleanup;
38651 }
38652 spin_lock(&port->lock);
38653- port->count++;
38654+ atomic_inc(&port->count);
38655 spin_unlock(&port->lock);
38656 spin_unlock_irqrestore(&info->netlock, flags);
38657
38658- if (port->count == 1) {
38659+ if (atomic_read(&port->count) == 1) {
38660 /* 1st open on this device, init hardware */
38661 retval = startup(info, tty);
38662 if (retval < 0)
38663@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38664 unsigned short new_crctype;
38665
38666 /* return error if TTY interface open */
38667- if (info->port.count)
38668+ if (atomic_read(&info->port.count))
38669 return -EBUSY;
38670
38671 switch (encoding)
38672@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38673
38674 /* arbitrate between network and tty opens */
38675 spin_lock_irqsave(&info->netlock, flags);
38676- if (info->port.count != 0 || info->netcount != 0) {
38677+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38678 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38679 spin_unlock_irqrestore(&info->netlock, flags);
38680 return -EBUSY;
38681@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38682 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38683
38684 /* return error if TTY interface open */
38685- if (info->port.count)
38686+ if (atomic_read(&info->port.count))
38687 return -EBUSY;
38688
38689 if (cmd != SIOCWANDEV)
38690diff --git a/drivers/char/random.c b/drivers/char/random.c
38691index 2b6e4cd..43d7ae1 100644
38692--- a/drivers/char/random.c
38693+++ b/drivers/char/random.c
38694@@ -270,10 +270,17 @@
38695 /*
38696 * Configuration information
38697 */
38698+#ifdef CONFIG_GRKERNSEC_RANDNET
38699+#define INPUT_POOL_SHIFT 14
38700+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38701+#define OUTPUT_POOL_SHIFT 12
38702+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38703+#else
38704 #define INPUT_POOL_SHIFT 12
38705 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38706 #define OUTPUT_POOL_SHIFT 10
38707 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38708+#endif
38709 #define SEC_XFER_SIZE 512
38710 #define EXTRACT_SIZE 10
38711
38712@@ -284,9 +291,6 @@
38713 /*
38714 * To allow fractional bits to be tracked, the entropy_count field is
38715 * denominated in units of 1/8th bits.
38716- *
38717- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38718- * credit_entropy_bits() needs to be 64 bits wide.
38719 */
38720 #define ENTROPY_SHIFT 3
38721 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38722@@ -361,12 +365,19 @@ static struct poolinfo {
38723 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38724 int tap1, tap2, tap3, tap4, tap5;
38725 } poolinfo_table[] = {
38726+#ifdef CONFIG_GRKERNSEC_RANDNET
38727+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38728+ { S(512), 411, 308, 208, 104, 1 },
38729+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38730+ { S(128), 104, 76, 51, 25, 1 },
38731+#else
38732 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38733 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38734 { S(128), 104, 76, 51, 25, 1 },
38735 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38736 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38737 { S(32), 26, 19, 14, 7, 1 },
38738+#endif
38739 #if 0
38740 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38741 { S(2048), 1638, 1231, 819, 411, 1 },
38742@@ -433,9 +444,9 @@ struct entropy_store {
38743 };
38744
38745 static void push_to_pool(struct work_struct *work);
38746-static __u32 input_pool_data[INPUT_POOL_WORDS];
38747-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38748-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38749+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38750+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38751+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38752
38753 static struct entropy_store input_pool = {
38754 .poolinfo = &poolinfo_table[0],
38755@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38756 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38757 }
38758
38759- ACCESS_ONCE(r->input_rotate) = input_rotate;
38760- ACCESS_ONCE(r->add_ptr) = i;
38761+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38762+ ACCESS_ONCE_RW(r->add_ptr) = i;
38763 smp_wmb();
38764
38765 if (out)
38766@@ -632,7 +643,7 @@ retry:
38767 /* The +2 corresponds to the /4 in the denominator */
38768
38769 do {
38770- unsigned int anfrac = min(pnfrac, pool_size/2);
38771+ u64 anfrac = min(pnfrac, pool_size/2);
38772 unsigned int add =
38773 ((pool_size - entropy_count)*anfrac*3) >> s;
38774
38775@@ -1166,7 +1177,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38776
38777 extract_buf(r, tmp);
38778 i = min_t(int, nbytes, EXTRACT_SIZE);
38779- if (copy_to_user(buf, tmp, i)) {
38780+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38781 ret = -EFAULT;
38782 break;
38783 }
38784@@ -1555,7 +1566,7 @@ static char sysctl_bootid[16];
38785 static int proc_do_uuid(struct ctl_table *table, int write,
38786 void __user *buffer, size_t *lenp, loff_t *ppos)
38787 {
38788- struct ctl_table fake_table;
38789+ ctl_table_no_const fake_table;
38790 unsigned char buf[64], tmp_uuid[16], *uuid;
38791
38792 uuid = table->data;
38793@@ -1585,7 +1596,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38794 static int proc_do_entropy(ctl_table *table, int write,
38795 void __user *buffer, size_t *lenp, loff_t *ppos)
38796 {
38797- ctl_table fake_table;
38798+ ctl_table_no_const fake_table;
38799 int entropy_count;
38800
38801 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38802diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38803index 7cc1fe22..b602d6b 100644
38804--- a/drivers/char/sonypi.c
38805+++ b/drivers/char/sonypi.c
38806@@ -54,6 +54,7 @@
38807
38808 #include <asm/uaccess.h>
38809 #include <asm/io.h>
38810+#include <asm/local.h>
38811
38812 #include <linux/sonypi.h>
38813
38814@@ -490,7 +491,7 @@ static struct sonypi_device {
38815 spinlock_t fifo_lock;
38816 wait_queue_head_t fifo_proc_list;
38817 struct fasync_struct *fifo_async;
38818- int open_count;
38819+ local_t open_count;
38820 int model;
38821 struct input_dev *input_jog_dev;
38822 struct input_dev *input_key_dev;
38823@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38824 static int sonypi_misc_release(struct inode *inode, struct file *file)
38825 {
38826 mutex_lock(&sonypi_device.lock);
38827- sonypi_device.open_count--;
38828+ local_dec(&sonypi_device.open_count);
38829 mutex_unlock(&sonypi_device.lock);
38830 return 0;
38831 }
38832@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38833 {
38834 mutex_lock(&sonypi_device.lock);
38835 /* Flush input queue on first open */
38836- if (!sonypi_device.open_count)
38837+ if (!local_read(&sonypi_device.open_count))
38838 kfifo_reset(&sonypi_device.fifo);
38839- sonypi_device.open_count++;
38840+ local_inc(&sonypi_device.open_count);
38841 mutex_unlock(&sonypi_device.lock);
38842
38843 return 0;
38844diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38845index b9a57fa..5bb9e38 100644
38846--- a/drivers/char/tpm/tpm_acpi.c
38847+++ b/drivers/char/tpm/tpm_acpi.c
38848@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38849 virt = acpi_os_map_memory(start, len);
38850 if (!virt) {
38851 kfree(log->bios_event_log);
38852+ log->bios_event_log = NULL;
38853 printk("%s: ERROR - Unable to map memory\n", __func__);
38854 return -EIO;
38855 }
38856
38857- memcpy_fromio(log->bios_event_log, virt, len);
38858+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38859
38860 acpi_os_unmap_memory(virt, len);
38861 return 0;
38862diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38863index 59f7cb2..bac8b6d 100644
38864--- a/drivers/char/tpm/tpm_eventlog.c
38865+++ b/drivers/char/tpm/tpm_eventlog.c
38866@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38867 event = addr;
38868
38869 if ((event->event_type == 0 && event->event_size == 0) ||
38870- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38871+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38872 return NULL;
38873
38874 return addr;
38875@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38876 return NULL;
38877
38878 if ((event->event_type == 0 && event->event_size == 0) ||
38879- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38880+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38881 return NULL;
38882
38883 (*pos)++;
38884@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38885 int i;
38886
38887 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38888- seq_putc(m, data[i]);
38889+ if (!seq_putc(m, data[i]))
38890+ return -EFAULT;
38891
38892 return 0;
38893 }
38894diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38895index 60aafb8..10c08e0 100644
38896--- a/drivers/char/virtio_console.c
38897+++ b/drivers/char/virtio_console.c
38898@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38899 if (to_user) {
38900 ssize_t ret;
38901
38902- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38903+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38904 if (ret)
38905 return -EFAULT;
38906 } else {
38907@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38908 if (!port_has_data(port) && !port->host_connected)
38909 return 0;
38910
38911- return fill_readbuf(port, ubuf, count, true);
38912+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38913 }
38914
38915 static int wait_port_writable(struct port *port, bool nonblock)
38916diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38917index 57a078e..c17cde8 100644
38918--- a/drivers/clk/clk-composite.c
38919+++ b/drivers/clk/clk-composite.c
38920@@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38921 struct clk *clk;
38922 struct clk_init_data init;
38923 struct clk_composite *composite;
38924- struct clk_ops *clk_composite_ops;
38925+ clk_ops_no_const *clk_composite_ops;
38926
38927 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38928 if (!composite) {
38929diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
38930index 501d513..fb0ecf9 100644
38931--- a/drivers/clk/socfpga/clk-gate.c
38932+++ b/drivers/clk/socfpga/clk-gate.c
38933@@ -22,6 +22,7 @@
38934 #include <linux/mfd/syscon.h>
38935 #include <linux/of.h>
38936 #include <linux/regmap.h>
38937+#include <asm/pgtable.h>
38938
38939 #include "clk.h"
38940
38941@@ -175,7 +176,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
38942 return 0;
38943 }
38944
38945-static struct clk_ops gateclk_ops = {
38946+static clk_ops_no_const gateclk_ops __read_only = {
38947 .prepare = socfpga_clk_prepare,
38948 .recalc_rate = socfpga_clk_recalc_rate,
38949 .get_parent = socfpga_clk_get_parent,
38950@@ -209,8 +210,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
38951 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
38952 socfpga_clk->hw.bit_idx = clk_gate[1];
38953
38954- gateclk_ops.enable = clk_gate_ops.enable;
38955- gateclk_ops.disable = clk_gate_ops.disable;
38956+ pax_open_kernel();
38957+ *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
38958+ *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
38959+ pax_close_kernel();
38960 }
38961
38962 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
38963diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
38964index de6da95..a2e72c0 100644
38965--- a/drivers/clk/socfpga/clk-pll.c
38966+++ b/drivers/clk/socfpga/clk-pll.c
38967@@ -21,6 +21,7 @@
38968 #include <linux/io.h>
38969 #include <linux/of.h>
38970 #include <linux/of_address.h>
38971+#include <asm/pgtable.h>
38972
38973 #include "clk.h"
38974
38975@@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
38976 CLK_MGR_PLL_CLK_SRC_MASK;
38977 }
38978
38979-static struct clk_ops clk_pll_ops = {
38980+static struct clk_ops_no_const clk_pll_ops __read_only = {
38981 .recalc_rate = clk_pll_recalc_rate,
38982 .get_parent = clk_pll_get_parent,
38983 };
38984@@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
38985 pll_clk->hw.hw.init = &init;
38986
38987 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38988- clk_pll_ops.enable = clk_gate_ops.enable;
38989- clk_pll_ops.disable = clk_gate_ops.disable;
38990+ pax_open_kernel();
38991+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38992+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38993+ pax_close_kernel();
38994
38995 clk = clk_register(NULL, &pll_clk->hw.hw);
38996 if (WARN_ON(IS_ERR(clk))) {
38997diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38998index 000e4e0..4770351 100644
38999--- a/drivers/cpufreq/acpi-cpufreq.c
39000+++ b/drivers/cpufreq/acpi-cpufreq.c
39001@@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39002 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39003 per_cpu(acfreq_data, cpu) = data;
39004
39005- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39006- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39007+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39008+ pax_open_kernel();
39009+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39010+ pax_close_kernel();
39011+ }
39012
39013 result = acpi_processor_register_performance(data->acpi_data, cpu);
39014 if (result)
39015@@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39016 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39017 break;
39018 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39019- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39020+ pax_open_kernel();
39021+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39022+ pax_close_kernel();
39023 break;
39024 default:
39025 break;
39026@@ -904,8 +909,10 @@ static void __init acpi_cpufreq_boost_init(void)
39027 if (!msrs)
39028 return;
39029
39030- acpi_cpufreq_driver.boost_supported = true;
39031- acpi_cpufreq_driver.boost_enabled = boost_state(0);
39032+ pax_open_kernel();
39033+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39034+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39035+ pax_close_kernel();
39036
39037 cpu_notifier_register_begin();
39038
39039diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39040index 558224c..55e3b57 100644
39041--- a/drivers/cpufreq/cpufreq.c
39042+++ b/drivers/cpufreq/cpufreq.c
39043@@ -2022,7 +2022,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39044 }
39045
39046 mutex_lock(&cpufreq_governor_mutex);
39047- list_del(&governor->governor_list);
39048+ pax_list_del(&governor->governor_list);
39049 mutex_unlock(&cpufreq_governor_mutex);
39050 return;
39051 }
39052@@ -2238,7 +2238,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39053 return NOTIFY_OK;
39054 }
39055
39056-static struct notifier_block __refdata cpufreq_cpu_notifier = {
39057+static struct notifier_block cpufreq_cpu_notifier = {
39058 .notifier_call = cpufreq_cpu_callback,
39059 };
39060
39061@@ -2278,13 +2278,17 @@ int cpufreq_boost_trigger_state(int state)
39062 return 0;
39063
39064 write_lock_irqsave(&cpufreq_driver_lock, flags);
39065- cpufreq_driver->boost_enabled = state;
39066+ pax_open_kernel();
39067+ *(bool *)&cpufreq_driver->boost_enabled = state;
39068+ pax_close_kernel();
39069 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39070
39071 ret = cpufreq_driver->set_boost(state);
39072 if (ret) {
39073 write_lock_irqsave(&cpufreq_driver_lock, flags);
39074- cpufreq_driver->boost_enabled = !state;
39075+ pax_open_kernel();
39076+ *(bool *)&cpufreq_driver->boost_enabled = !state;
39077+ pax_close_kernel();
39078 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39079
39080 pr_err("%s: Cannot %s BOOST\n",
39081@@ -2340,8 +2344,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39082
39083 pr_debug("trying to register driver %s\n", driver_data->name);
39084
39085- if (driver_data->setpolicy)
39086- driver_data->flags |= CPUFREQ_CONST_LOOPS;
39087+ if (driver_data->setpolicy) {
39088+ pax_open_kernel();
39089+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39090+ pax_close_kernel();
39091+ }
39092
39093 write_lock_irqsave(&cpufreq_driver_lock, flags);
39094 if (cpufreq_driver) {
39095@@ -2356,8 +2363,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39096 * Check if driver provides function to enable boost -
39097 * if not, use cpufreq_boost_set_sw as default
39098 */
39099- if (!cpufreq_driver->set_boost)
39100- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39101+ if (!cpufreq_driver->set_boost) {
39102+ pax_open_kernel();
39103+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39104+ pax_close_kernel();
39105+ }
39106
39107 ret = cpufreq_sysfs_create_file(&boost.attr);
39108 if (ret) {
39109diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39110index e1c6433..31203ae 100644
39111--- a/drivers/cpufreq/cpufreq_governor.c
39112+++ b/drivers/cpufreq/cpufreq_governor.c
39113@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39114 struct dbs_data *dbs_data;
39115 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39116 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39117- struct od_ops *od_ops = NULL;
39118+ const struct od_ops *od_ops = NULL;
39119 struct od_dbs_tuners *od_tuners = NULL;
39120 struct cs_dbs_tuners *cs_tuners = NULL;
39121 struct cpu_dbs_common_info *cpu_cdbs;
39122@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39123
39124 if ((cdata->governor == GOV_CONSERVATIVE) &&
39125 (!policy->governor->initialized)) {
39126- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39127+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39128
39129 cpufreq_register_notifier(cs_ops->notifier_block,
39130 CPUFREQ_TRANSITION_NOTIFIER);
39131@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39132
39133 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39134 (policy->governor->initialized == 1)) {
39135- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39136+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39137
39138 cpufreq_unregister_notifier(cs_ops->notifier_block,
39139 CPUFREQ_TRANSITION_NOTIFIER);
39140diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39141index bfb9ae1..e1d3a7e 100644
39142--- a/drivers/cpufreq/cpufreq_governor.h
39143+++ b/drivers/cpufreq/cpufreq_governor.h
39144@@ -205,7 +205,7 @@ struct common_dbs_data {
39145 void (*exit)(struct dbs_data *dbs_data);
39146
39147 /* Governor specific ops, see below */
39148- void *gov_ops;
39149+ const void *gov_ops;
39150 };
39151
39152 /* Governor Per policy data */
39153@@ -225,7 +225,7 @@ struct od_ops {
39154 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39155 unsigned int freq_next, unsigned int relation);
39156 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39157-};
39158+} __no_const;
39159
39160 struct cs_ops {
39161 struct notifier_block *notifier_block;
39162diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39163index 18d4091..434be15 100644
39164--- a/drivers/cpufreq/cpufreq_ondemand.c
39165+++ b/drivers/cpufreq/cpufreq_ondemand.c
39166@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39167
39168 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39169
39170-static struct od_ops od_ops = {
39171+static struct od_ops od_ops __read_only = {
39172 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39173 .powersave_bias_target = generic_powersave_bias_target,
39174 .freq_increase = dbs_freq_increase,
39175@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39176 (struct cpufreq_policy *, unsigned int, unsigned int),
39177 unsigned int powersave_bias)
39178 {
39179- od_ops.powersave_bias_target = f;
39180+ pax_open_kernel();
39181+ *(void **)&od_ops.powersave_bias_target = f;
39182+ pax_close_kernel();
39183 od_set_powersave_bias(powersave_bias);
39184 }
39185 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39186
39187 void od_unregister_powersave_bias_handler(void)
39188 {
39189- od_ops.powersave_bias_target = generic_powersave_bias_target;
39190+ pax_open_kernel();
39191+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39192+ pax_close_kernel();
39193 od_set_powersave_bias(0);
39194 }
39195 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39196diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39197index fcd0c92..7b736c2 100644
39198--- a/drivers/cpufreq/intel_pstate.c
39199+++ b/drivers/cpufreq/intel_pstate.c
39200@@ -125,10 +125,10 @@ struct pstate_funcs {
39201 struct cpu_defaults {
39202 struct pstate_adjust_policy pid_policy;
39203 struct pstate_funcs funcs;
39204-};
39205+} __do_const;
39206
39207 static struct pstate_adjust_policy pid_params;
39208-static struct pstate_funcs pstate_funcs;
39209+static struct pstate_funcs *pstate_funcs;
39210
39211 struct perf_limits {
39212 int no_turbo;
39213@@ -526,7 +526,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39214
39215 cpu->pstate.current_pstate = pstate;
39216
39217- pstate_funcs.set(cpu, pstate);
39218+ pstate_funcs->set(cpu, pstate);
39219 }
39220
39221 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39222@@ -548,12 +548,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39223 {
39224 sprintf(cpu->name, "Intel 2nd generation core");
39225
39226- cpu->pstate.min_pstate = pstate_funcs.get_min();
39227- cpu->pstate.max_pstate = pstate_funcs.get_max();
39228- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39229+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39230+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39231+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39232
39233- if (pstate_funcs.get_vid)
39234- pstate_funcs.get_vid(cpu);
39235+ if (pstate_funcs->get_vid)
39236+ pstate_funcs->get_vid(cpu);
39237 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39238 }
39239
39240@@ -838,9 +838,9 @@ static int intel_pstate_msrs_not_valid(void)
39241 rdmsrl(MSR_IA32_APERF, aperf);
39242 rdmsrl(MSR_IA32_MPERF, mperf);
39243
39244- if (!pstate_funcs.get_max() ||
39245- !pstate_funcs.get_min() ||
39246- !pstate_funcs.get_turbo())
39247+ if (!pstate_funcs->get_max() ||
39248+ !pstate_funcs->get_min() ||
39249+ !pstate_funcs->get_turbo())
39250 return -ENODEV;
39251
39252 rdmsrl(MSR_IA32_APERF, tmp);
39253@@ -854,7 +854,7 @@ static int intel_pstate_msrs_not_valid(void)
39254 return 0;
39255 }
39256
39257-static void copy_pid_params(struct pstate_adjust_policy *policy)
39258+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39259 {
39260 pid_params.sample_rate_ms = policy->sample_rate_ms;
39261 pid_params.p_gain_pct = policy->p_gain_pct;
39262@@ -866,11 +866,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39263
39264 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39265 {
39266- pstate_funcs.get_max = funcs->get_max;
39267- pstate_funcs.get_min = funcs->get_min;
39268- pstate_funcs.get_turbo = funcs->get_turbo;
39269- pstate_funcs.set = funcs->set;
39270- pstate_funcs.get_vid = funcs->get_vid;
39271+ pstate_funcs = funcs;
39272 }
39273
39274 #if IS_ENABLED(CONFIG_ACPI)
39275diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39276index 529cfd9..0e28fff 100644
39277--- a/drivers/cpufreq/p4-clockmod.c
39278+++ b/drivers/cpufreq/p4-clockmod.c
39279@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39280 case 0x0F: /* Core Duo */
39281 case 0x16: /* Celeron Core */
39282 case 0x1C: /* Atom */
39283- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39284+ pax_open_kernel();
39285+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39286+ pax_close_kernel();
39287 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39288 case 0x0D: /* Pentium M (Dothan) */
39289- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39290+ pax_open_kernel();
39291+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39292+ pax_close_kernel();
39293 /* fall through */
39294 case 0x09: /* Pentium M (Banias) */
39295 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39296@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39297
39298 /* on P-4s, the TSC runs with constant frequency independent whether
39299 * throttling is active or not. */
39300- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39301+ pax_open_kernel();
39302+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39303+ pax_close_kernel();
39304
39305 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39306 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39307diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39308index 9bb42ba..b01b4a2 100644
39309--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39310+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39311@@ -18,14 +18,12 @@
39312 #include <asm/head.h>
39313 #include <asm/timer.h>
39314
39315-static struct cpufreq_driver *cpufreq_us3_driver;
39316-
39317 struct us3_freq_percpu_info {
39318 struct cpufreq_frequency_table table[4];
39319 };
39320
39321 /* Indexed by cpu number. */
39322-static struct us3_freq_percpu_info *us3_freq_table;
39323+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39324
39325 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39326 * in the Safari config register.
39327@@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39328
39329 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39330 {
39331- if (cpufreq_us3_driver)
39332- us3_freq_target(policy, 0);
39333+ us3_freq_target(policy, 0);
39334
39335 return 0;
39336 }
39337
39338+static int __init us3_freq_init(void);
39339+static void __exit us3_freq_exit(void);
39340+
39341+static struct cpufreq_driver cpufreq_us3_driver = {
39342+ .init = us3_freq_cpu_init,
39343+ .verify = cpufreq_generic_frequency_table_verify,
39344+ .target_index = us3_freq_target,
39345+ .get = us3_freq_get,
39346+ .exit = us3_freq_cpu_exit,
39347+ .name = "UltraSPARC-III",
39348+
39349+};
39350+
39351 static int __init us3_freq_init(void)
39352 {
39353 unsigned long manuf, impl, ver;
39354- int ret;
39355
39356 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39357 return -ENODEV;
39358@@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39359 (impl == CHEETAH_IMPL ||
39360 impl == CHEETAH_PLUS_IMPL ||
39361 impl == JAGUAR_IMPL ||
39362- impl == PANTHER_IMPL)) {
39363- struct cpufreq_driver *driver;
39364-
39365- ret = -ENOMEM;
39366- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39367- if (!driver)
39368- goto err_out;
39369-
39370- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39371- GFP_KERNEL);
39372- if (!us3_freq_table)
39373- goto err_out;
39374-
39375- driver->init = us3_freq_cpu_init;
39376- driver->verify = cpufreq_generic_frequency_table_verify;
39377- driver->target_index = us3_freq_target;
39378- driver->get = us3_freq_get;
39379- driver->exit = us3_freq_cpu_exit;
39380- strcpy(driver->name, "UltraSPARC-III");
39381-
39382- cpufreq_us3_driver = driver;
39383- ret = cpufreq_register_driver(driver);
39384- if (ret)
39385- goto err_out;
39386-
39387- return 0;
39388-
39389-err_out:
39390- if (driver) {
39391- kfree(driver);
39392- cpufreq_us3_driver = NULL;
39393- }
39394- kfree(us3_freq_table);
39395- us3_freq_table = NULL;
39396- return ret;
39397- }
39398+ impl == PANTHER_IMPL))
39399+ return cpufreq_register_driver(&cpufreq_us3_driver);
39400
39401 return -ENODEV;
39402 }
39403
39404 static void __exit us3_freq_exit(void)
39405 {
39406- if (cpufreq_us3_driver) {
39407- cpufreq_unregister_driver(cpufreq_us3_driver);
39408- kfree(cpufreq_us3_driver);
39409- cpufreq_us3_driver = NULL;
39410- kfree(us3_freq_table);
39411- us3_freq_table = NULL;
39412- }
39413+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39414 }
39415
39416 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39417diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39418index 6723f03..3465190 100644
39419--- a/drivers/cpufreq/speedstep-centrino.c
39420+++ b/drivers/cpufreq/speedstep-centrino.c
39421@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39422 !cpu_has(cpu, X86_FEATURE_EST))
39423 return -ENODEV;
39424
39425- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39426- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39427+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39428+ pax_open_kernel();
39429+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39430+ pax_close_kernel();
39431+ }
39432
39433 if (policy->cpu != 0)
39434 return -ENODEV;
39435diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39436index 136d6a2..06e373d 100644
39437--- a/drivers/cpuidle/driver.c
39438+++ b/drivers/cpuidle/driver.c
39439@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39440
39441 static void poll_idle_init(struct cpuidle_driver *drv)
39442 {
39443- struct cpuidle_state *state = &drv->states[0];
39444+ cpuidle_state_no_const *state = &drv->states[0];
39445
39446 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39447 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39448diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39449index ca89412..a7b9c49 100644
39450--- a/drivers/cpuidle/governor.c
39451+++ b/drivers/cpuidle/governor.c
39452@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39453 mutex_lock(&cpuidle_lock);
39454 if (__cpuidle_find_governor(gov->name) == NULL) {
39455 ret = 0;
39456- list_add_tail(&gov->governor_list, &cpuidle_governors);
39457+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39458 if (!cpuidle_curr_governor ||
39459 cpuidle_curr_governor->rating < gov->rating)
39460 cpuidle_switch_governor(gov);
39461diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39462index efe2f17..b8124f9 100644
39463--- a/drivers/cpuidle/sysfs.c
39464+++ b/drivers/cpuidle/sysfs.c
39465@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39466 NULL
39467 };
39468
39469-static struct attribute_group cpuidle_attr_group = {
39470+static attribute_group_no_const cpuidle_attr_group = {
39471 .attrs = cpuidle_default_attrs,
39472 .name = "cpuidle",
39473 };
39474diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39475index 12fea3e..1e28f47 100644
39476--- a/drivers/crypto/hifn_795x.c
39477+++ b/drivers/crypto/hifn_795x.c
39478@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39479 MODULE_PARM_DESC(hifn_pll_ref,
39480 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39481
39482-static atomic_t hifn_dev_number;
39483+static atomic_unchecked_t hifn_dev_number;
39484
39485 #define ACRYPTO_OP_DECRYPT 0
39486 #define ACRYPTO_OP_ENCRYPT 1
39487@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39488 goto err_out_disable_pci_device;
39489
39490 snprintf(name, sizeof(name), "hifn%d",
39491- atomic_inc_return(&hifn_dev_number)-1);
39492+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39493
39494 err = pci_request_regions(pdev, name);
39495 if (err)
39496diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39497index 2042ec3..a9ce67f 100644
39498--- a/drivers/devfreq/devfreq.c
39499+++ b/drivers/devfreq/devfreq.c
39500@@ -616,7 +616,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39501 goto err_out;
39502 }
39503
39504- list_add(&governor->node, &devfreq_governor_list);
39505+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39506
39507 list_for_each_entry(devfreq, &devfreq_list, node) {
39508 int ret = 0;
39509@@ -704,7 +704,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39510 }
39511 }
39512
39513- list_del(&governor->node);
39514+ pax_list_del((struct list_head *)&governor->node);
39515 err_out:
39516 mutex_unlock(&devfreq_list_lock);
39517
39518diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39519index 5239677..1cb71a8 100644
39520--- a/drivers/dma/sh/shdma-base.c
39521+++ b/drivers/dma/sh/shdma-base.c
39522@@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39523 schan->slave_id = -EINVAL;
39524 }
39525
39526- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39527- sdev->desc_size, GFP_KERNEL);
39528+ schan->desc = kcalloc(sdev->desc_size,
39529+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39530 if (!schan->desc) {
39531 ret = -ENOMEM;
39532 goto edescalloc;
39533diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39534index dda7e75..0a4c867 100644
39535--- a/drivers/dma/sh/shdmac.c
39536+++ b/drivers/dma/sh/shdmac.c
39537@@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39538 return ret;
39539 }
39540
39541-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39542+static struct notifier_block sh_dmae_nmi_notifier = {
39543 .notifier_call = sh_dmae_nmi_handler,
39544
39545 /* Run before NMI debug handler and KGDB */
39546diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39547index 592af5f..bb1d583 100644
39548--- a/drivers/edac/edac_device.c
39549+++ b/drivers/edac/edac_device.c
39550@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39551 */
39552 int edac_device_alloc_index(void)
39553 {
39554- static atomic_t device_indexes = ATOMIC_INIT(0);
39555+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39556
39557- return atomic_inc_return(&device_indexes) - 1;
39558+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39559 }
39560 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39561
39562diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39563index 01fae82..1dd8289 100644
39564--- a/drivers/edac/edac_mc_sysfs.c
39565+++ b/drivers/edac/edac_mc_sysfs.c
39566@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39567 struct dev_ch_attribute {
39568 struct device_attribute attr;
39569 int channel;
39570-};
39571+} __do_const;
39572
39573 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39574 struct dev_ch_attribute dev_attr_legacy_##_name = \
39575@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39576 }
39577
39578 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39579+ pax_open_kernel();
39580 if (mci->get_sdram_scrub_rate) {
39581- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39582- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39583+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39584+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39585 }
39586 if (mci->set_sdram_scrub_rate) {
39587- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39588- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39589+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39590+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39591 }
39592+ pax_close_kernel();
39593 err = device_create_file(&mci->dev,
39594 &dev_attr_sdram_scrub_rate);
39595 if (err) {
39596diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39597index 2cf44b4d..6dd2dc7 100644
39598--- a/drivers/edac/edac_pci.c
39599+++ b/drivers/edac/edac_pci.c
39600@@ -29,7 +29,7 @@
39601
39602 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39603 static LIST_HEAD(edac_pci_list);
39604-static atomic_t pci_indexes = ATOMIC_INIT(0);
39605+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39606
39607 /*
39608 * edac_pci_alloc_ctl_info
39609@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39610 */
39611 int edac_pci_alloc_index(void)
39612 {
39613- return atomic_inc_return(&pci_indexes) - 1;
39614+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39615 }
39616 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39617
39618diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39619index e8658e4..22746d6 100644
39620--- a/drivers/edac/edac_pci_sysfs.c
39621+++ b/drivers/edac/edac_pci_sysfs.c
39622@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39623 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39624 static int edac_pci_poll_msec = 1000; /* one second workq period */
39625
39626-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39627-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39628+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39629+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39630
39631 static struct kobject *edac_pci_top_main_kobj;
39632 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39633@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39634 void *value;
39635 ssize_t(*show) (void *, char *);
39636 ssize_t(*store) (void *, const char *, size_t);
39637-};
39638+} __do_const;
39639
39640 /* Set of show/store abstract level functions for PCI Parity object */
39641 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39642@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39643 edac_printk(KERN_CRIT, EDAC_PCI,
39644 "Signaled System Error on %s\n",
39645 pci_name(dev));
39646- atomic_inc(&pci_nonparity_count);
39647+ atomic_inc_unchecked(&pci_nonparity_count);
39648 }
39649
39650 if (status & (PCI_STATUS_PARITY)) {
39651@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39652 "Master Data Parity Error on %s\n",
39653 pci_name(dev));
39654
39655- atomic_inc(&pci_parity_count);
39656+ atomic_inc_unchecked(&pci_parity_count);
39657 }
39658
39659 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39660@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39661 "Detected Parity Error on %s\n",
39662 pci_name(dev));
39663
39664- atomic_inc(&pci_parity_count);
39665+ atomic_inc_unchecked(&pci_parity_count);
39666 }
39667 }
39668
39669@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39670 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39671 "Signaled System Error on %s\n",
39672 pci_name(dev));
39673- atomic_inc(&pci_nonparity_count);
39674+ atomic_inc_unchecked(&pci_nonparity_count);
39675 }
39676
39677 if (status & (PCI_STATUS_PARITY)) {
39678@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39679 "Master Data Parity Error on "
39680 "%s\n", pci_name(dev));
39681
39682- atomic_inc(&pci_parity_count);
39683+ atomic_inc_unchecked(&pci_parity_count);
39684 }
39685
39686 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39687@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39688 "Detected Parity Error on %s\n",
39689 pci_name(dev));
39690
39691- atomic_inc(&pci_parity_count);
39692+ atomic_inc_unchecked(&pci_parity_count);
39693 }
39694 }
39695 }
39696@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39697 if (!check_pci_errors)
39698 return;
39699
39700- before_count = atomic_read(&pci_parity_count);
39701+ before_count = atomic_read_unchecked(&pci_parity_count);
39702
39703 /* scan all PCI devices looking for a Parity Error on devices and
39704 * bridges.
39705@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39706 /* Only if operator has selected panic on PCI Error */
39707 if (edac_pci_get_panic_on_pe()) {
39708 /* If the count is different 'after' from 'before' */
39709- if (before_count != atomic_read(&pci_parity_count))
39710+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39711 panic("EDAC: PCI Parity Error");
39712 }
39713 }
39714diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39715index 51b7e3a..aa8a3e8 100644
39716--- a/drivers/edac/mce_amd.h
39717+++ b/drivers/edac/mce_amd.h
39718@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39719 bool (*mc0_mce)(u16, u8);
39720 bool (*mc1_mce)(u16, u8);
39721 bool (*mc2_mce)(u16, u8);
39722-};
39723+} __no_const;
39724
39725 void amd_report_gart_errors(bool);
39726 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39727diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39728index 57ea7f4..af06b76 100644
39729--- a/drivers/firewire/core-card.c
39730+++ b/drivers/firewire/core-card.c
39731@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39732 const struct fw_card_driver *driver,
39733 struct device *device)
39734 {
39735- static atomic_t index = ATOMIC_INIT(-1);
39736+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
39737
39738- card->index = atomic_inc_return(&index);
39739+ card->index = atomic_inc_return_unchecked(&index);
39740 card->driver = driver;
39741 card->device = device;
39742 card->current_tlabel = 0;
39743@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39744
39745 void fw_core_remove_card(struct fw_card *card)
39746 {
39747- struct fw_card_driver dummy_driver = dummy_driver_template;
39748+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
39749
39750 card->driver->update_phy_reg(card, 4,
39751 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39752diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39753index 2c6d5e1..a2cca6b 100644
39754--- a/drivers/firewire/core-device.c
39755+++ b/drivers/firewire/core-device.c
39756@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39757 struct config_rom_attribute {
39758 struct device_attribute attr;
39759 u32 key;
39760-};
39761+} __do_const;
39762
39763 static ssize_t show_immediate(struct device *dev,
39764 struct device_attribute *dattr, char *buf)
39765diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39766index eb6935c..3cc2bfa 100644
39767--- a/drivers/firewire/core-transaction.c
39768+++ b/drivers/firewire/core-transaction.c
39769@@ -38,6 +38,7 @@
39770 #include <linux/timer.h>
39771 #include <linux/types.h>
39772 #include <linux/workqueue.h>
39773+#include <linux/sched.h>
39774
39775 #include <asm/byteorder.h>
39776
39777diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39778index f477308..2795f24 100644
39779--- a/drivers/firewire/core.h
39780+++ b/drivers/firewire/core.h
39781@@ -111,6 +111,7 @@ struct fw_card_driver {
39782
39783 int (*stop_iso)(struct fw_iso_context *ctx);
39784 };
39785+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39786
39787 void fw_card_initialize(struct fw_card *card,
39788 const struct fw_card_driver *driver, struct device *device);
39789diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39790index 586f2f7..3545ad2 100644
39791--- a/drivers/firewire/ohci.c
39792+++ b/drivers/firewire/ohci.c
39793@@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39794 be32_to_cpu(ohci->next_header));
39795 }
39796
39797+#ifndef CONFIG_GRKERNSEC
39798 if (param_remote_dma) {
39799 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39800 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39801 }
39802+#endif
39803
39804 spin_unlock_irq(&ohci->lock);
39805
39806@@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39807 unsigned long flags;
39808 int n, ret = 0;
39809
39810+#ifndef CONFIG_GRKERNSEC
39811 if (param_remote_dma)
39812 return 0;
39813+#endif
39814
39815 /*
39816 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39817diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39818index 94a58a0..f5eba42 100644
39819--- a/drivers/firmware/dmi-id.c
39820+++ b/drivers/firmware/dmi-id.c
39821@@ -16,7 +16,7 @@
39822 struct dmi_device_attribute{
39823 struct device_attribute dev_attr;
39824 int field;
39825-};
39826+} __do_const;
39827 #define to_dmi_dev_attr(_dev_attr) \
39828 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39829
39830diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39831index 17afc51..0ef90cd 100644
39832--- a/drivers/firmware/dmi_scan.c
39833+++ b/drivers/firmware/dmi_scan.c
39834@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39835 if (buf == NULL)
39836 return -1;
39837
39838- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39839+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39840
39841 dmi_unmap(buf);
39842 return 0;
39843diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39844index 1491dd4..aa910db 100644
39845--- a/drivers/firmware/efi/cper.c
39846+++ b/drivers/firmware/efi/cper.c
39847@@ -41,12 +41,12 @@
39848 */
39849 u64 cper_next_record_id(void)
39850 {
39851- static atomic64_t seq;
39852+ static atomic64_unchecked_t seq;
39853
39854- if (!atomic64_read(&seq))
39855- atomic64_set(&seq, ((u64)get_seconds()) << 32);
39856+ if (!atomic64_read_unchecked(&seq))
39857+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39858
39859- return atomic64_inc_return(&seq);
39860+ return atomic64_inc_return_unchecked(&seq);
39861 }
39862 EXPORT_SYMBOL_GPL(cper_next_record_id);
39863
39864diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39865index af20f17..4e4e545 100644
39866--- a/drivers/firmware/efi/efi.c
39867+++ b/drivers/firmware/efi/efi.c
39868@@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39869 };
39870
39871 static struct efivars generic_efivars;
39872-static struct efivar_operations generic_ops;
39873+static efivar_operations_no_const generic_ops __read_only;
39874
39875 static int generic_ops_register(void)
39876 {
39877- generic_ops.get_variable = efi.get_variable;
39878- generic_ops.set_variable = efi.set_variable;
39879- generic_ops.get_next_variable = efi.get_next_variable;
39880- generic_ops.query_variable_store = efi_query_variable_store;
39881+ pax_open_kernel();
39882+ *(void **)&generic_ops.get_variable = efi.get_variable;
39883+ *(void **)&generic_ops.set_variable = efi.set_variable;
39884+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39885+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39886+ pax_close_kernel();
39887
39888 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39889 }
39890diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39891index 50ea412..caccd6e9 100644
39892--- a/drivers/firmware/efi/efivars.c
39893+++ b/drivers/firmware/efi/efivars.c
39894@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39895 static int
39896 create_efivars_bin_attributes(void)
39897 {
39898- struct bin_attribute *attr;
39899+ bin_attribute_no_const *attr;
39900 int error;
39901
39902 /* new_var */
39903diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39904index 2f569aa..c95f4fb 100644
39905--- a/drivers/firmware/google/memconsole.c
39906+++ b/drivers/firmware/google/memconsole.c
39907@@ -155,7 +155,10 @@ static int __init memconsole_init(void)
39908 if (!found_memconsole())
39909 return -ENODEV;
39910
39911- memconsole_bin_attr.size = memconsole_length;
39912+ pax_open_kernel();
39913+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39914+ pax_close_kernel();
39915+
39916 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39917 }
39918
39919diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39920index 8765bd6..2e5b147 100644
39921--- a/drivers/gpio/gpio-em.c
39922+++ b/drivers/gpio/gpio-em.c
39923@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39924 struct em_gio_priv *p;
39925 struct resource *io[2], *irq[2];
39926 struct gpio_chip *gpio_chip;
39927- struct irq_chip *irq_chip;
39928+ irq_chip_no_const *irq_chip;
39929 const char *name = dev_name(&pdev->dev);
39930 int ret;
39931
39932diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39933index 7030422..42a3fe9 100644
39934--- a/drivers/gpio/gpio-ich.c
39935+++ b/drivers/gpio/gpio-ich.c
39936@@ -94,7 +94,7 @@ struct ichx_desc {
39937 * this option allows driver caching written output values
39938 */
39939 bool use_outlvl_cache;
39940-};
39941+} __do_const;
39942
39943 static struct {
39944 spinlock_t lock;
39945diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39946index 03c9148..c66e753 100644
39947--- a/drivers/gpio/gpio-rcar.c
39948+++ b/drivers/gpio/gpio-rcar.c
39949@@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39950 struct gpio_rcar_priv *p;
39951 struct resource *io, *irq;
39952 struct gpio_chip *gpio_chip;
39953- struct irq_chip *irq_chip;
39954+ irq_chip_no_const *irq_chip;
39955 struct device *dev = &pdev->dev;
39956 const char *name = dev_name(dev);
39957 int ret;
39958diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39959index 66cbcc1..0c5e622 100644
39960--- a/drivers/gpio/gpio-vr41xx.c
39961+++ b/drivers/gpio/gpio-vr41xx.c
39962@@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
39963 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39964 maskl, pendl, maskh, pendh);
39965
39966- atomic_inc(&irq_err_count);
39967+ atomic_inc_unchecked(&irq_err_count);
39968
39969 return -EINVAL;
39970 }
39971diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39972index d8b7099..8a314a5 100644
39973--- a/drivers/gpu/drm/drm_crtc.c
39974+++ b/drivers/gpu/drm/drm_crtc.c
39975@@ -3500,7 +3500,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39976 goto done;
39977 }
39978
39979- if (copy_to_user(&enum_ptr[copied].name,
39980+ if (copy_to_user(enum_ptr[copied].name,
39981 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39982 ret = -EFAULT;
39983 goto done;
39984diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39985old mode 100644
39986new mode 100755
39987index 8218078..9960928a
39988--- a/drivers/gpu/drm/drm_drv.c
39989+++ b/drivers/gpu/drm/drm_drv.c
39990@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39991 /**
39992 * Copy and IOCTL return string to user space
39993 */
39994-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39995+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39996 {
39997 int len;
39998
39999@@ -342,7 +342,7 @@ long drm_ioctl(struct file *filp,
40000 struct drm_file *file_priv = filp->private_data;
40001 struct drm_device *dev;
40002 const struct drm_ioctl_desc *ioctl = NULL;
40003- drm_ioctl_t *func;
40004+ drm_ioctl_no_const_t func;
40005 unsigned int nr = DRM_IOCTL_NR(cmd);
40006 int retcode = -EINVAL;
40007 char stack_kdata[128];
40008diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40009index e1eba0b..98f69f9 100644
40010--- a/drivers/gpu/drm/drm_fops.c
40011+++ b/drivers/gpu/drm/drm_fops.c
40012@@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40013 return PTR_ERR(minor);
40014
40015 dev = minor->dev;
40016- if (!dev->open_count++)
40017+ if (local_inc_return(&dev->open_count) == 1)
40018 need_setup = 1;
40019
40020 /* share address_space across all char-devs of a single device */
40021@@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40022 return 0;
40023
40024 err_undo:
40025- dev->open_count--;
40026+ local_dec(&dev->open_count);
40027 drm_minor_release(minor);
40028 return retcode;
40029 }
40030@@ -430,7 +430,7 @@ int drm_release(struct inode *inode, struct file *filp)
40031
40032 mutex_lock(&drm_global_mutex);
40033
40034- DRM_DEBUG("open_count = %d\n", dev->open_count);
40035+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40036
40037 if (dev->driver->preclose)
40038 dev->driver->preclose(dev, file_priv);
40039@@ -439,10 +439,10 @@ int drm_release(struct inode *inode, struct file *filp)
40040 * Begin inline drm_release
40041 */
40042
40043- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40044+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40045 task_pid_nr(current),
40046 (long)old_encode_dev(file_priv->minor->kdev->devt),
40047- dev->open_count);
40048+ local_read(&dev->open_count));
40049
40050 /* Release any auth tokens that might point to this file_priv,
40051 (do that under the drm_global_mutex) */
40052@@ -543,7 +543,7 @@ int drm_release(struct inode *inode, struct file *filp)
40053 * End inline drm_release
40054 */
40055
40056- if (!--dev->open_count) {
40057+ if (local_dec_and_test(&dev->open_count)) {
40058 retcode = drm_lastclose(dev);
40059 if (drm_device_is_unplugged(dev))
40060 drm_put_dev(dev);
40061diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40062index 3d2e91c..d31c4c9 100644
40063--- a/drivers/gpu/drm/drm_global.c
40064+++ b/drivers/gpu/drm/drm_global.c
40065@@ -36,7 +36,7 @@
40066 struct drm_global_item {
40067 struct mutex mutex;
40068 void *object;
40069- int refcount;
40070+ atomic_t refcount;
40071 };
40072
40073 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40074@@ -49,7 +49,7 @@ void drm_global_init(void)
40075 struct drm_global_item *item = &glob[i];
40076 mutex_init(&item->mutex);
40077 item->object = NULL;
40078- item->refcount = 0;
40079+ atomic_set(&item->refcount, 0);
40080 }
40081 }
40082
40083@@ -59,7 +59,7 @@ void drm_global_release(void)
40084 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40085 struct drm_global_item *item = &glob[i];
40086 BUG_ON(item->object != NULL);
40087- BUG_ON(item->refcount != 0);
40088+ BUG_ON(atomic_read(&item->refcount) != 0);
40089 }
40090 }
40091
40092@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40093 struct drm_global_item *item = &glob[ref->global_type];
40094
40095 mutex_lock(&item->mutex);
40096- if (item->refcount == 0) {
40097+ if (atomic_read(&item->refcount) == 0) {
40098 item->object = kzalloc(ref->size, GFP_KERNEL);
40099 if (unlikely(item->object == NULL)) {
40100 ret = -ENOMEM;
40101@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40102 goto out_err;
40103
40104 }
40105- ++item->refcount;
40106+ atomic_inc(&item->refcount);
40107 ref->object = item->object;
40108 mutex_unlock(&item->mutex);
40109 return 0;
40110@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40111 struct drm_global_item *item = &glob[ref->global_type];
40112
40113 mutex_lock(&item->mutex);
40114- BUG_ON(item->refcount == 0);
40115+ BUG_ON(atomic_read(&item->refcount) == 0);
40116 BUG_ON(ref->object != item->object);
40117- if (--item->refcount == 0) {
40118+ if (atomic_dec_and_test(&item->refcount)) {
40119 ref->release(ref);
40120 item->object = NULL;
40121 }
40122diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40123index 7473035..a48b9c5 100644
40124--- a/drivers/gpu/drm/drm_info.c
40125+++ b/drivers/gpu/drm/drm_info.c
40126@@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40127 struct drm_local_map *map;
40128 struct drm_map_list *r_list;
40129
40130- /* Hardcoded from _DRM_FRAME_BUFFER,
40131- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40132- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40133- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40134+ static const char * const types[] = {
40135+ [_DRM_FRAME_BUFFER] = "FB",
40136+ [_DRM_REGISTERS] = "REG",
40137+ [_DRM_SHM] = "SHM",
40138+ [_DRM_AGP] = "AGP",
40139+ [_DRM_SCATTER_GATHER] = "SG",
40140+ [_DRM_CONSISTENT] = "PCI"};
40141 const char *type;
40142 int i;
40143
40144@@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40145 map = r_list->map;
40146 if (!map)
40147 continue;
40148- if (map->type < 0 || map->type > 5)
40149+ if (map->type >= ARRAY_SIZE(types))
40150 type = "??";
40151 else
40152 type = types[map->type];
40153@@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40154 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40155 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40156 vma->vm_flags & VM_IO ? 'i' : '-',
40157+#ifdef CONFIG_GRKERNSEC_HIDESYM
40158+ 0);
40159+#else
40160 vma->vm_pgoff);
40161+#endif
40162
40163 #if defined(__i386__)
40164 pgprot = pgprot_val(vma->vm_page_prot);
40165diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40166index 2f4c4343..dd12cd2 100644
40167--- a/drivers/gpu/drm/drm_ioc32.c
40168+++ b/drivers/gpu/drm/drm_ioc32.c
40169@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40170 request = compat_alloc_user_space(nbytes);
40171 if (!access_ok(VERIFY_WRITE, request, nbytes))
40172 return -EFAULT;
40173- list = (struct drm_buf_desc *) (request + 1);
40174+ list = (struct drm_buf_desc __user *) (request + 1);
40175
40176 if (__put_user(count, &request->count)
40177 || __put_user(list, &request->list))
40178@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40179 request = compat_alloc_user_space(nbytes);
40180 if (!access_ok(VERIFY_WRITE, request, nbytes))
40181 return -EFAULT;
40182- list = (struct drm_buf_pub *) (request + 1);
40183+ list = (struct drm_buf_pub __user *) (request + 1);
40184
40185 if (__put_user(count, &request->count)
40186 || __put_user(list, &request->list))
40187@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40188 return 0;
40189 }
40190
40191-drm_ioctl_compat_t *drm_compat_ioctls[] = {
40192+drm_ioctl_compat_t drm_compat_ioctls[] = {
40193 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40194 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40195 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40196@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40197 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40198 {
40199 unsigned int nr = DRM_IOCTL_NR(cmd);
40200- drm_ioctl_compat_t *fn;
40201 int ret;
40202
40203 /* Assume that ioctls without an explicit compat routine will just
40204@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40205 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40206 return drm_ioctl(filp, cmd, arg);
40207
40208- fn = drm_compat_ioctls[nr];
40209-
40210- if (fn != NULL)
40211- ret = (*fn) (filp, cmd, arg);
40212+ if (drm_compat_ioctls[nr] != NULL)
40213+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40214 else
40215 ret = drm_ioctl(filp, cmd, arg);
40216
40217diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40218index 4c24c3a..c903cab 100644
40219--- a/drivers/gpu/drm/drm_stub.c
40220+++ b/drivers/gpu/drm/drm_stub.c
40221@@ -455,7 +455,7 @@ void drm_unplug_dev(struct drm_device *dev)
40222
40223 drm_device_set_unplugged(dev);
40224
40225- if (dev->open_count == 0) {
40226+ if (local_read(&dev->open_count) == 0) {
40227 drm_put_dev(dev);
40228 }
40229 mutex_unlock(&drm_global_mutex);
40230diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40231index c22c309..ae758c3 100644
40232--- a/drivers/gpu/drm/drm_sysfs.c
40233+++ b/drivers/gpu/drm/drm_sysfs.c
40234@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40235 */
40236 int drm_sysfs_device_add(struct drm_minor *minor)
40237 {
40238- char *minor_str;
40239+ const char *minor_str;
40240 int r;
40241
40242 if (minor->type == DRM_MINOR_CONTROL)
40243diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40244index d4d16ed..8fb0b51 100644
40245--- a/drivers/gpu/drm/i810/i810_drv.h
40246+++ b/drivers/gpu/drm/i810/i810_drv.h
40247@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40248 int page_flipping;
40249
40250 wait_queue_head_t irq_queue;
40251- atomic_t irq_received;
40252- atomic_t irq_emitted;
40253+ atomic_unchecked_t irq_received;
40254+ atomic_unchecked_t irq_emitted;
40255
40256 int front_offset;
40257 } drm_i810_private_t;
40258diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40259index eedb023..25076a4 100644
40260--- a/drivers/gpu/drm/i915/i915_dma.c
40261+++ b/drivers/gpu/drm/i915/i915_dma.c
40262@@ -1280,7 +1280,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40263 bool can_switch;
40264
40265 spin_lock(&dev->count_lock);
40266- can_switch = (dev->open_count == 0);
40267+ can_switch = (local_read(&dev->open_count) == 0);
40268 spin_unlock(&dev->count_lock);
40269 return can_switch;
40270 }
40271diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40272index 20fef6c..76c78fb 100644
40273--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40274+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40275@@ -886,9 +886,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40276
40277 static int
40278 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40279- int count)
40280+ unsigned int count)
40281 {
40282- int i;
40283+ unsigned int i;
40284 unsigned relocs_total = 0;
40285 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40286
40287diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40288index 3c59584..500f2e9 100644
40289--- a/drivers/gpu/drm/i915/i915_ioc32.c
40290+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40291@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40292 (unsigned long)request);
40293 }
40294
40295-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40296+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40297 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40298 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40299 [DRM_I915_GETPARAM] = compat_i915_getparam,
40300@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40301 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40302 {
40303 unsigned int nr = DRM_IOCTL_NR(cmd);
40304- drm_ioctl_compat_t *fn = NULL;
40305 int ret;
40306
40307 if (nr < DRM_COMMAND_BASE)
40308 return drm_compat_ioctl(filp, cmd, arg);
40309
40310- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40311- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40312-
40313- if (fn != NULL)
40314+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40315+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40316 ret = (*fn) (filp, cmd, arg);
40317- else
40318+ } else
40319 ret = drm_ioctl(filp, cmd, arg);
40320
40321 return ret;
40322diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40323index 5b60e25..eac1625 100644
40324--- a/drivers/gpu/drm/i915/intel_display.c
40325+++ b/drivers/gpu/drm/i915/intel_display.c
40326@@ -11171,13 +11171,13 @@ struct intel_quirk {
40327 int subsystem_vendor;
40328 int subsystem_device;
40329 void (*hook)(struct drm_device *dev);
40330-};
40331+} __do_const;
40332
40333 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40334 struct intel_dmi_quirk {
40335 void (*hook)(struct drm_device *dev);
40336 const struct dmi_system_id (*dmi_id_list)[];
40337-};
40338+} __do_const;
40339
40340 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40341 {
40342@@ -11185,18 +11185,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40343 return 1;
40344 }
40345
40346-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40347+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40348 {
40349- .dmi_id_list = &(const struct dmi_system_id[]) {
40350- {
40351- .callback = intel_dmi_reverse_brightness,
40352- .ident = "NCR Corporation",
40353- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40354- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40355- },
40356- },
40357- { } /* terminating entry */
40358+ .callback = intel_dmi_reverse_brightness,
40359+ .ident = "NCR Corporation",
40360+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40361+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40362 },
40363+ },
40364+ { } /* terminating entry */
40365+};
40366+
40367+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40368+ {
40369+ .dmi_id_list = &intel_dmi_quirks_table,
40370 .hook = quirk_invert_brightness,
40371 },
40372 };
40373diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40374index fe45321..836fdca 100644
40375--- a/drivers/gpu/drm/mga/mga_drv.h
40376+++ b/drivers/gpu/drm/mga/mga_drv.h
40377@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40378 u32 clear_cmd;
40379 u32 maccess;
40380
40381- atomic_t vbl_received; /**< Number of vblanks received. */
40382+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40383 wait_queue_head_t fence_queue;
40384- atomic_t last_fence_retired;
40385+ atomic_unchecked_t last_fence_retired;
40386 u32 next_fence_to_post;
40387
40388 unsigned int fb_cpp;
40389diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40390index 86b4bb8..ae237ad 100644
40391--- a/drivers/gpu/drm/mga/mga_ioc32.c
40392+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40393@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40394 return 0;
40395 }
40396
40397-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40398+drm_ioctl_compat_t mga_compat_ioctls[] = {
40399 [DRM_MGA_INIT] = compat_mga_init,
40400 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40401 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40402@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40403 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40404 {
40405 unsigned int nr = DRM_IOCTL_NR(cmd);
40406- drm_ioctl_compat_t *fn = NULL;
40407 int ret;
40408
40409 if (nr < DRM_COMMAND_BASE)
40410 return drm_compat_ioctl(filp, cmd, arg);
40411
40412- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40413- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40414-
40415- if (fn != NULL)
40416+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40417+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40418 ret = (*fn) (filp, cmd, arg);
40419- else
40420+ } else
40421 ret = drm_ioctl(filp, cmd, arg);
40422
40423 return ret;
40424diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40425index 1b071b8..de8601a 100644
40426--- a/drivers/gpu/drm/mga/mga_irq.c
40427+++ b/drivers/gpu/drm/mga/mga_irq.c
40428@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40429 if (crtc != 0)
40430 return 0;
40431
40432- return atomic_read(&dev_priv->vbl_received);
40433+ return atomic_read_unchecked(&dev_priv->vbl_received);
40434 }
40435
40436
40437@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40438 /* VBLANK interrupt */
40439 if (status & MGA_VLINEPEN) {
40440 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40441- atomic_inc(&dev_priv->vbl_received);
40442+ atomic_inc_unchecked(&dev_priv->vbl_received);
40443 drm_handle_vblank(dev, 0);
40444 handled = 1;
40445 }
40446@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40447 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40448 MGA_WRITE(MGA_PRIMEND, prim_end);
40449
40450- atomic_inc(&dev_priv->last_fence_retired);
40451+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40452 wake_up(&dev_priv->fence_queue);
40453 handled = 1;
40454 }
40455@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40456 * using fences.
40457 */
40458 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40459- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40460+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40461 - *sequence) <= (1 << 23)));
40462
40463 *sequence = cur_fence;
40464diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40465index 8268a4c..5105708 100644
40466--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40467+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40468@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40469 struct bit_table {
40470 const char id;
40471 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40472-};
40473+} __no_const;
40474
40475 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40476
40477diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40478index 7efbafa..19f8087 100644
40479--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40480+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40481@@ -97,7 +97,6 @@ struct nouveau_drm {
40482 struct drm_global_reference mem_global_ref;
40483 struct ttm_bo_global_ref bo_global_ref;
40484 struct ttm_bo_device bdev;
40485- atomic_t validate_sequence;
40486 int (*move)(struct nouveau_channel *,
40487 struct ttm_buffer_object *,
40488 struct ttm_mem_reg *, struct ttm_mem_reg *);
40489diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40490index c1a7e5a..38b8539 100644
40491--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40492+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40493@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40494 unsigned long arg)
40495 {
40496 unsigned int nr = DRM_IOCTL_NR(cmd);
40497- drm_ioctl_compat_t *fn = NULL;
40498+ drm_ioctl_compat_t fn = NULL;
40499 int ret;
40500
40501 if (nr < DRM_COMMAND_BASE)
40502diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40503index ab0228f..20b756b 100644
40504--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40505+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40506@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40507 }
40508
40509 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40510- nouveau_vram_manager_init,
40511- nouveau_vram_manager_fini,
40512- nouveau_vram_manager_new,
40513- nouveau_vram_manager_del,
40514- nouveau_vram_manager_debug
40515+ .init = nouveau_vram_manager_init,
40516+ .takedown = nouveau_vram_manager_fini,
40517+ .get_node = nouveau_vram_manager_new,
40518+ .put_node = nouveau_vram_manager_del,
40519+ .debug = nouveau_vram_manager_debug
40520 };
40521
40522 static int
40523@@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40524 }
40525
40526 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40527- nouveau_gart_manager_init,
40528- nouveau_gart_manager_fini,
40529- nouveau_gart_manager_new,
40530- nouveau_gart_manager_del,
40531- nouveau_gart_manager_debug
40532+ .init = nouveau_gart_manager_init,
40533+ .takedown = nouveau_gart_manager_fini,
40534+ .get_node = nouveau_gart_manager_new,
40535+ .put_node = nouveau_gart_manager_del,
40536+ .debug = nouveau_gart_manager_debug
40537 };
40538
40539 #include <core/subdev/vm/nv04.h>
40540@@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40541 }
40542
40543 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40544- nv04_gart_manager_init,
40545- nv04_gart_manager_fini,
40546- nv04_gart_manager_new,
40547- nv04_gart_manager_del,
40548- nv04_gart_manager_debug
40549+ .init = nv04_gart_manager_init,
40550+ .takedown = nv04_gart_manager_fini,
40551+ .get_node = nv04_gart_manager_new,
40552+ .put_node = nv04_gart_manager_del,
40553+ .debug = nv04_gart_manager_debug
40554 };
40555
40556 int
40557diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40558index fb84da3..d7ee463 100644
40559--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40560+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40561@@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40562 bool can_switch;
40563
40564 spin_lock(&dev->count_lock);
40565- can_switch = (dev->open_count == 0);
40566+ can_switch = (local_read(&dev->open_count) == 0);
40567 spin_unlock(&dev->count_lock);
40568 return can_switch;
40569 }
40570diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40571index eb89653..613cf71 100644
40572--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40573+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40574@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40575 int ret;
40576
40577 mutex_lock(&qdev->async_io_mutex);
40578- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40579+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40580 if (qdev->last_sent_io_cmd > irq_num) {
40581 if (intr)
40582 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40583- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40584+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40585 else
40586 ret = wait_event_timeout(qdev->io_cmd_event,
40587- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40588+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40589 /* 0 is timeout, just bail the "hw" has gone away */
40590 if (ret <= 0)
40591 goto out;
40592- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40593+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40594 }
40595 outb(val, addr);
40596 qdev->last_sent_io_cmd = irq_num + 1;
40597 if (intr)
40598 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40599- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40600+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40601 else
40602 ret = wait_event_timeout(qdev->io_cmd_event,
40603- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40604+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40605 out:
40606 if (ret > 0)
40607 ret = 0;
40608diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40609index c3c2bbd..bc3c0fb 100644
40610--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40611+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40612@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40613 struct drm_info_node *node = (struct drm_info_node *) m->private;
40614 struct qxl_device *qdev = node->minor->dev->dev_private;
40615
40616- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40617- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40618- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40619- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40620+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40621+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40622+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40623+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40624 seq_printf(m, "%d\n", qdev->irq_received_error);
40625 return 0;
40626 }
40627diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40628index 36ed40b..0397633 100644
40629--- a/drivers/gpu/drm/qxl/qxl_drv.h
40630+++ b/drivers/gpu/drm/qxl/qxl_drv.h
40631@@ -290,10 +290,10 @@ struct qxl_device {
40632 unsigned int last_sent_io_cmd;
40633
40634 /* interrupt handling */
40635- atomic_t irq_received;
40636- atomic_t irq_received_display;
40637- atomic_t irq_received_cursor;
40638- atomic_t irq_received_io_cmd;
40639+ atomic_unchecked_t irq_received;
40640+ atomic_unchecked_t irq_received_display;
40641+ atomic_unchecked_t irq_received_cursor;
40642+ atomic_unchecked_t irq_received_io_cmd;
40643 unsigned irq_received_error;
40644 wait_queue_head_t display_event;
40645 wait_queue_head_t cursor_event;
40646diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40647index 0bb86e6..d41416d 100644
40648--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40649+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40650@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40651
40652 /* TODO copy slow path code from i915 */
40653 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40654- 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);
40655+ 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);
40656
40657 {
40658 struct qxl_drawable *draw = fb_cmd;
40659@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40660 struct drm_qxl_reloc reloc;
40661
40662 if (copy_from_user(&reloc,
40663- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40664+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40665 sizeof(reloc))) {
40666 ret = -EFAULT;
40667 goto out_free_bos;
40668@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40669
40670 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40671
40672- struct drm_qxl_command *commands =
40673- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40674+ struct drm_qxl_command __user *commands =
40675+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40676
40677- if (copy_from_user(&user_cmd, &commands[cmd_num],
40678+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40679 sizeof(user_cmd)))
40680 return -EFAULT;
40681
40682diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40683index 28f84b4..fb3e224 100644
40684--- a/drivers/gpu/drm/qxl/qxl_irq.c
40685+++ b/drivers/gpu/drm/qxl/qxl_irq.c
40686@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40687
40688 pending = xchg(&qdev->ram_header->int_pending, 0);
40689
40690- atomic_inc(&qdev->irq_received);
40691+ atomic_inc_unchecked(&qdev->irq_received);
40692
40693 if (pending & QXL_INTERRUPT_DISPLAY) {
40694- atomic_inc(&qdev->irq_received_display);
40695+ atomic_inc_unchecked(&qdev->irq_received_display);
40696 wake_up_all(&qdev->display_event);
40697 qxl_queue_garbage_collect(qdev, false);
40698 }
40699 if (pending & QXL_INTERRUPT_CURSOR) {
40700- atomic_inc(&qdev->irq_received_cursor);
40701+ atomic_inc_unchecked(&qdev->irq_received_cursor);
40702 wake_up_all(&qdev->cursor_event);
40703 }
40704 if (pending & QXL_INTERRUPT_IO_CMD) {
40705- atomic_inc(&qdev->irq_received_io_cmd);
40706+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40707 wake_up_all(&qdev->io_cmd_event);
40708 }
40709 if (pending & QXL_INTERRUPT_ERROR) {
40710@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40711 init_waitqueue_head(&qdev->io_cmd_event);
40712 INIT_WORK(&qdev->client_monitors_config_work,
40713 qxl_client_monitors_config_work_func);
40714- atomic_set(&qdev->irq_received, 0);
40715- atomic_set(&qdev->irq_received_display, 0);
40716- atomic_set(&qdev->irq_received_cursor, 0);
40717- atomic_set(&qdev->irq_received_io_cmd, 0);
40718+ atomic_set_unchecked(&qdev->irq_received, 0);
40719+ atomic_set_unchecked(&qdev->irq_received_display, 0);
40720+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40721+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40722 qdev->irq_received_error = 0;
40723 ret = drm_irq_install(qdev->ddev);
40724 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40725diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40726index d52c275..4e6b43d 100644
40727--- a/drivers/gpu/drm/qxl/qxl_ttm.c
40728+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40729@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40730 }
40731 }
40732
40733-static struct vm_operations_struct qxl_ttm_vm_ops;
40734+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40735 static const struct vm_operations_struct *ttm_vm_ops;
40736
40737 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40738@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40739 return r;
40740 if (unlikely(ttm_vm_ops == NULL)) {
40741 ttm_vm_ops = vma->vm_ops;
40742+ pax_open_kernel();
40743 qxl_ttm_vm_ops = *ttm_vm_ops;
40744 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40745+ pax_close_kernel();
40746 }
40747 vma->vm_ops = &qxl_ttm_vm_ops;
40748 return 0;
40749@@ -561,25 +563,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40750 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40751 {
40752 #if defined(CONFIG_DEBUG_FS)
40753- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40754- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40755- unsigned i;
40756+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40757+ {
40758+ .name = "qxl_mem_mm",
40759+ .show = &qxl_mm_dump_table,
40760+ },
40761+ {
40762+ .name = "qxl_surf_mm",
40763+ .show = &qxl_mm_dump_table,
40764+ }
40765+ };
40766
40767- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40768- if (i == 0)
40769- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40770- else
40771- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40772- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40773- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40774- qxl_mem_types_list[i].driver_features = 0;
40775- if (i == 0)
40776- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40777- else
40778- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40779+ pax_open_kernel();
40780+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40781+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40782+ pax_close_kernel();
40783
40784- }
40785- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40786+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40787 #else
40788 return 0;
40789 #endif
40790diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40791index 59459fe..be26b31 100644
40792--- a/drivers/gpu/drm/r128/r128_cce.c
40793+++ b/drivers/gpu/drm/r128/r128_cce.c
40794@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40795
40796 /* GH: Simple idle check.
40797 */
40798- atomic_set(&dev_priv->idle_count, 0);
40799+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40800
40801 /* We don't support anything other than bus-mastering ring mode,
40802 * but the ring can be in either AGP or PCI space for the ring
40803diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40804index 5bf3f5f..7000661 100644
40805--- a/drivers/gpu/drm/r128/r128_drv.h
40806+++ b/drivers/gpu/drm/r128/r128_drv.h
40807@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40808 int is_pci;
40809 unsigned long cce_buffers_offset;
40810
40811- atomic_t idle_count;
40812+ atomic_unchecked_t idle_count;
40813
40814 int page_flipping;
40815 int current_page;
40816 u32 crtc_offset;
40817 u32 crtc_offset_cntl;
40818
40819- atomic_t vbl_received;
40820+ atomic_unchecked_t vbl_received;
40821
40822 u32 color_fmt;
40823 unsigned int front_offset;
40824diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40825index b0d0fd3..a6fbbe4 100644
40826--- a/drivers/gpu/drm/r128/r128_ioc32.c
40827+++ b/drivers/gpu/drm/r128/r128_ioc32.c
40828@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40829 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40830 }
40831
40832-drm_ioctl_compat_t *r128_compat_ioctls[] = {
40833+drm_ioctl_compat_t r128_compat_ioctls[] = {
40834 [DRM_R128_INIT] = compat_r128_init,
40835 [DRM_R128_DEPTH] = compat_r128_depth,
40836 [DRM_R128_STIPPLE] = compat_r128_stipple,
40837@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40838 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40839 {
40840 unsigned int nr = DRM_IOCTL_NR(cmd);
40841- drm_ioctl_compat_t *fn = NULL;
40842 int ret;
40843
40844 if (nr < DRM_COMMAND_BASE)
40845 return drm_compat_ioctl(filp, cmd, arg);
40846
40847- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40848- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40849-
40850- if (fn != NULL)
40851+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40852+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40853 ret = (*fn) (filp, cmd, arg);
40854- else
40855+ } else
40856 ret = drm_ioctl(filp, cmd, arg);
40857
40858 return ret;
40859diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40860index c2ae496..30b5993 100644
40861--- a/drivers/gpu/drm/r128/r128_irq.c
40862+++ b/drivers/gpu/drm/r128/r128_irq.c
40863@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40864 if (crtc != 0)
40865 return 0;
40866
40867- return atomic_read(&dev_priv->vbl_received);
40868+ return atomic_read_unchecked(&dev_priv->vbl_received);
40869 }
40870
40871 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40872@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40873 /* VBLANK interrupt */
40874 if (status & R128_CRTC_VBLANK_INT) {
40875 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40876- atomic_inc(&dev_priv->vbl_received);
40877+ atomic_inc_unchecked(&dev_priv->vbl_received);
40878 drm_handle_vblank(dev, 0);
40879 return IRQ_HANDLED;
40880 }
40881diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40882index e806dac..f81d32f 100644
40883--- a/drivers/gpu/drm/r128/r128_state.c
40884+++ b/drivers/gpu/drm/r128/r128_state.c
40885@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40886
40887 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40888 {
40889- if (atomic_read(&dev_priv->idle_count) == 0)
40890+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40891 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40892 else
40893- atomic_set(&dev_priv->idle_count, 0);
40894+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40895 }
40896
40897 #endif
40898diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40899index 4a85bb6..aaea819 100644
40900--- a/drivers/gpu/drm/radeon/mkregtable.c
40901+++ b/drivers/gpu/drm/radeon/mkregtable.c
40902@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40903 regex_t mask_rex;
40904 regmatch_t match[4];
40905 char buf[1024];
40906- size_t end;
40907+ long end;
40908 int len;
40909 int done = 0;
40910 int r;
40911 unsigned o;
40912 struct offset *offset;
40913 char last_reg_s[10];
40914- int last_reg;
40915+ unsigned long last_reg;
40916
40917 if (regcomp
40918 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40919diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40920index 2cd144c..a01c95a 100644
40921--- a/drivers/gpu/drm/radeon/radeon_device.c
40922+++ b/drivers/gpu/drm/radeon/radeon_device.c
40923@@ -1129,7 +1129,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40924 bool can_switch;
40925
40926 spin_lock(&dev->count_lock);
40927- can_switch = (dev->open_count == 0);
40928+ can_switch = (local_read(&dev->open_count) == 0);
40929 spin_unlock(&dev->count_lock);
40930 return can_switch;
40931 }
40932diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40933index dafd812..1bf20c7 100644
40934--- a/drivers/gpu/drm/radeon/radeon_drv.h
40935+++ b/drivers/gpu/drm/radeon/radeon_drv.h
40936@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40937
40938 /* SW interrupt */
40939 wait_queue_head_t swi_queue;
40940- atomic_t swi_emitted;
40941+ atomic_unchecked_t swi_emitted;
40942 int vblank_crtc;
40943 uint32_t irq_enable_reg;
40944 uint32_t r500_disp_irq_reg;
40945diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40946index bdb0f93..5ff558f 100644
40947--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40948+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40949@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40950 request = compat_alloc_user_space(sizeof(*request));
40951 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40952 || __put_user(req32.param, &request->param)
40953- || __put_user((void __user *)(unsigned long)req32.value,
40954+ || __put_user((unsigned long)req32.value,
40955 &request->value))
40956 return -EFAULT;
40957
40958@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40959 #define compat_radeon_cp_setparam NULL
40960 #endif /* X86_64 || IA64 */
40961
40962-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40963+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40964 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40965 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40966 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40967@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40968 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40969 {
40970 unsigned int nr = DRM_IOCTL_NR(cmd);
40971- drm_ioctl_compat_t *fn = NULL;
40972 int ret;
40973
40974 if (nr < DRM_COMMAND_BASE)
40975 return drm_compat_ioctl(filp, cmd, arg);
40976
40977- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40978- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40979-
40980- if (fn != NULL)
40981+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40982+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40983 ret = (*fn) (filp, cmd, arg);
40984- else
40985+ } else
40986 ret = drm_ioctl(filp, cmd, arg);
40987
40988 return ret;
40989diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40990index 244b19b..c19226d 100644
40991--- a/drivers/gpu/drm/radeon/radeon_irq.c
40992+++ b/drivers/gpu/drm/radeon/radeon_irq.c
40993@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40994 unsigned int ret;
40995 RING_LOCALS;
40996
40997- atomic_inc(&dev_priv->swi_emitted);
40998- ret = atomic_read(&dev_priv->swi_emitted);
40999+ atomic_inc_unchecked(&dev_priv->swi_emitted);
41000+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41001
41002 BEGIN_RING(4);
41003 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41004@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41005 drm_radeon_private_t *dev_priv =
41006 (drm_radeon_private_t *) dev->dev_private;
41007
41008- atomic_set(&dev_priv->swi_emitted, 0);
41009+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41010 init_waitqueue_head(&dev_priv->swi_queue);
41011
41012 dev->max_vblank_count = 0x001fffff;
41013diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41014index 956ab7f..fbd36d8 100644
41015--- a/drivers/gpu/drm/radeon/radeon_state.c
41016+++ b/drivers/gpu/drm/radeon/radeon_state.c
41017@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41018 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41019 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41020
41021- if (copy_from_user(&depth_boxes, clear->depth_boxes,
41022+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41023 sarea_priv->nbox * sizeof(depth_boxes[0])))
41024 return -EFAULT;
41025
41026@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41027 {
41028 drm_radeon_private_t *dev_priv = dev->dev_private;
41029 drm_radeon_getparam_t *param = data;
41030- int value;
41031+ int value = 0;
41032
41033 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41034
41035diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41036index c8a8a51..219dacc 100644
41037--- a/drivers/gpu/drm/radeon/radeon_ttm.c
41038+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41039@@ -797,7 +797,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41040 man->size = size >> PAGE_SHIFT;
41041 }
41042
41043-static struct vm_operations_struct radeon_ttm_vm_ops;
41044+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41045 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41046
41047 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41048@@ -838,8 +838,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41049 }
41050 if (unlikely(ttm_vm_ops == NULL)) {
41051 ttm_vm_ops = vma->vm_ops;
41052+ pax_open_kernel();
41053 radeon_ttm_vm_ops = *ttm_vm_ops;
41054 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41055+ pax_close_kernel();
41056 }
41057 vma->vm_ops = &radeon_ttm_vm_ops;
41058 return 0;
41059diff --git a/drivers/gpu/drm/radeon/radeon_vm.c b/drivers/gpu/drm/radeon/radeon_vm.c
41060index c11b71d..c8c48aa 100644
41061--- a/drivers/gpu/drm/radeon/radeon_vm.c
41062+++ b/drivers/gpu/drm/radeon/radeon_vm.c
41063@@ -493,7 +493,7 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev,
41064 mutex_unlock(&vm->mutex);
41065
41066 r = radeon_bo_create(rdev, RADEON_VM_PTE_COUNT * 8,
41067- RADEON_GPU_PAGE_SIZE, false,
41068+ RADEON_GPU_PAGE_SIZE, true,
41069 RADEON_GEM_DOMAIN_VRAM, NULL, &pt);
41070 if (r)
41071 return r;
41072@@ -913,7 +913,7 @@ int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm)
41073 return -ENOMEM;
41074 }
41075
41076- r = radeon_bo_create(rdev, pd_size, RADEON_VM_PTB_ALIGN_SIZE, false,
41077+ r = radeon_bo_create(rdev, pd_size, RADEON_VM_PTB_ALIGN_SIZE, true,
41078 RADEON_GEM_DOMAIN_VRAM, NULL,
41079 &vm->page_directory);
41080 if (r)
41081diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41082index edb871d..a275c6ed 100644
41083--- a/drivers/gpu/drm/tegra/dc.c
41084+++ b/drivers/gpu/drm/tegra/dc.c
41085@@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41086 }
41087
41088 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41089- dc->debugfs_files[i].data = dc;
41090+ *(void **)&dc->debugfs_files[i].data = dc;
41091
41092 err = drm_debugfs_create_files(dc->debugfs_files,
41093 ARRAY_SIZE(debugfs_files),
41094diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41095index 0e599f0..c9ea7c7 100644
41096--- a/drivers/gpu/drm/tegra/dsi.c
41097+++ b/drivers/gpu/drm/tegra/dsi.c
41098@@ -39,7 +39,7 @@ struct tegra_dsi {
41099 struct clk *clk_lp;
41100 struct clk *clk;
41101
41102- struct drm_info_list *debugfs_files;
41103+ drm_info_list_no_const *debugfs_files;
41104 struct drm_minor *minor;
41105 struct dentry *debugfs;
41106
41107diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41108index 6928015..c9853e7 100644
41109--- a/drivers/gpu/drm/tegra/hdmi.c
41110+++ b/drivers/gpu/drm/tegra/hdmi.c
41111@@ -59,7 +59,7 @@ struct tegra_hdmi {
41112 bool stereo;
41113 bool dvi;
41114
41115- struct drm_info_list *debugfs_files;
41116+ drm_info_list_no_const *debugfs_files;
41117 struct drm_minor *minor;
41118 struct dentry *debugfs;
41119 };
41120diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41121index bd850c9..d9f3573 100644
41122--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41123+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41124@@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41125 }
41126
41127 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41128- ttm_bo_man_init,
41129- ttm_bo_man_takedown,
41130- ttm_bo_man_get_node,
41131- ttm_bo_man_put_node,
41132- ttm_bo_man_debug
41133+ .init = ttm_bo_man_init,
41134+ .takedown = ttm_bo_man_takedown,
41135+ .get_node = ttm_bo_man_get_node,
41136+ .put_node = ttm_bo_man_put_node,
41137+ .debug = ttm_bo_man_debug
41138 };
41139 EXPORT_SYMBOL(ttm_bo_manager_func);
41140diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41141index dbc2def..0a9f710 100644
41142--- a/drivers/gpu/drm/ttm/ttm_memory.c
41143+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41144@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41145 zone->glob = glob;
41146 glob->zone_kernel = zone;
41147 ret = kobject_init_and_add(
41148- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41149+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41150 if (unlikely(ret != 0)) {
41151 kobject_put(&zone->kobj);
41152 return ret;
41153@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41154 zone->glob = glob;
41155 glob->zone_dma32 = zone;
41156 ret = kobject_init_and_add(
41157- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41158+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41159 if (unlikely(ret != 0)) {
41160 kobject_put(&zone->kobj);
41161 return ret;
41162diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41163index 863bef9..cba15cf 100644
41164--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41165+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41166@@ -391,9 +391,9 @@ out:
41167 static unsigned long
41168 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41169 {
41170- static atomic_t start_pool = ATOMIC_INIT(0);
41171+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41172 unsigned i;
41173- unsigned pool_offset = atomic_add_return(1, &start_pool);
41174+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41175 struct ttm_page_pool *pool;
41176 int shrink_pages = sc->nr_to_scan;
41177 unsigned long freed = 0;
41178diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41179index 3771763..883f206 100644
41180--- a/drivers/gpu/drm/udl/udl_fb.c
41181+++ b/drivers/gpu/drm/udl/udl_fb.c
41182@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41183 fb_deferred_io_cleanup(info);
41184 kfree(info->fbdefio);
41185 info->fbdefio = NULL;
41186- info->fbops->fb_mmap = udl_fb_mmap;
41187 }
41188
41189 pr_warn("released /dev/fb%d user=%d count=%d\n",
41190diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41191index ad02732..144f5ed 100644
41192--- a/drivers/gpu/drm/via/via_drv.h
41193+++ b/drivers/gpu/drm/via/via_drv.h
41194@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41195 typedef uint32_t maskarray_t[5];
41196
41197 typedef struct drm_via_irq {
41198- atomic_t irq_received;
41199+ atomic_unchecked_t irq_received;
41200 uint32_t pending_mask;
41201 uint32_t enable_mask;
41202 wait_queue_head_t irq_queue;
41203@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41204 struct timeval last_vblank;
41205 int last_vblank_valid;
41206 unsigned usec_per_vblank;
41207- atomic_t vbl_received;
41208+ atomic_unchecked_t vbl_received;
41209 drm_via_state_t hc_state;
41210 char pci_buf[VIA_PCI_BUF_SIZE];
41211 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41212diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41213index 1319433..a993b0c 100644
41214--- a/drivers/gpu/drm/via/via_irq.c
41215+++ b/drivers/gpu/drm/via/via_irq.c
41216@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41217 if (crtc != 0)
41218 return 0;
41219
41220- return atomic_read(&dev_priv->vbl_received);
41221+ return atomic_read_unchecked(&dev_priv->vbl_received);
41222 }
41223
41224 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41225@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41226
41227 status = VIA_READ(VIA_REG_INTERRUPT);
41228 if (status & VIA_IRQ_VBLANK_PENDING) {
41229- atomic_inc(&dev_priv->vbl_received);
41230- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41231+ atomic_inc_unchecked(&dev_priv->vbl_received);
41232+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41233 do_gettimeofday(&cur_vblank);
41234 if (dev_priv->last_vblank_valid) {
41235 dev_priv->usec_per_vblank =
41236@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41237 dev_priv->last_vblank = cur_vblank;
41238 dev_priv->last_vblank_valid = 1;
41239 }
41240- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41241+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41242 DRM_DEBUG("US per vblank is: %u\n",
41243 dev_priv->usec_per_vblank);
41244 }
41245@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41246
41247 for (i = 0; i < dev_priv->num_irqs; ++i) {
41248 if (status & cur_irq->pending_mask) {
41249- atomic_inc(&cur_irq->irq_received);
41250+ atomic_inc_unchecked(&cur_irq->irq_received);
41251 wake_up(&cur_irq->irq_queue);
41252 handled = 1;
41253 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41254@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41255 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41256 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41257 masks[irq][4]));
41258- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41259+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41260 } else {
41261 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41262 (((cur_irq_sequence =
41263- atomic_read(&cur_irq->irq_received)) -
41264+ atomic_read_unchecked(&cur_irq->irq_received)) -
41265 *sequence) <= (1 << 23)));
41266 }
41267 *sequence = cur_irq_sequence;
41268@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41269 }
41270
41271 for (i = 0; i < dev_priv->num_irqs; ++i) {
41272- atomic_set(&cur_irq->irq_received, 0);
41273+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41274 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41275 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41276 init_waitqueue_head(&cur_irq->irq_queue);
41277@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41278 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41279 case VIA_IRQ_RELATIVE:
41280 irqwait->request.sequence +=
41281- atomic_read(&cur_irq->irq_received);
41282+ atomic_read_unchecked(&cur_irq->irq_received);
41283 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41284 case VIA_IRQ_ABSOLUTE:
41285 break;
41286diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41287index 6b252a8..5975dfe 100644
41288--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41289+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41290@@ -437,7 +437,7 @@ struct vmw_private {
41291 * Fencing and IRQs.
41292 */
41293
41294- atomic_t marker_seq;
41295+ atomic_unchecked_t marker_seq;
41296 wait_queue_head_t fence_queue;
41297 wait_queue_head_t fifo_queue;
41298 int fence_queue_waiters; /* Protected by hw_mutex */
41299diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41300index 6ccd993..618d592 100644
41301--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41302+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41303@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41304 (unsigned int) min,
41305 (unsigned int) fifo->capabilities);
41306
41307- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41308+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41309 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41310 vmw_marker_queue_init(&fifo->marker_queue);
41311 return vmw_fifo_send_fence(dev_priv, &dummy);
41312@@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41313 if (reserveable)
41314 iowrite32(bytes, fifo_mem +
41315 SVGA_FIFO_RESERVED);
41316- return fifo_mem + (next_cmd >> 2);
41317+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41318 } else {
41319 need_bounce = true;
41320 }
41321@@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41322
41323 fm = vmw_fifo_reserve(dev_priv, bytes);
41324 if (unlikely(fm == NULL)) {
41325- *seqno = atomic_read(&dev_priv->marker_seq);
41326+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41327 ret = -ENOMEM;
41328 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41329 false, 3*HZ);
41330@@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41331 }
41332
41333 do {
41334- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41335+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41336 } while (*seqno == 0);
41337
41338 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41339diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41340index b1273e8..9c274fd 100644
41341--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41342+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41343@@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41344 }
41345
41346 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41347- vmw_gmrid_man_init,
41348- vmw_gmrid_man_takedown,
41349- vmw_gmrid_man_get_node,
41350- vmw_gmrid_man_put_node,
41351- vmw_gmrid_man_debug
41352+ .init = vmw_gmrid_man_init,
41353+ .takedown = vmw_gmrid_man_takedown,
41354+ .get_node = vmw_gmrid_man_get_node,
41355+ .put_node = vmw_gmrid_man_put_node,
41356+ .debug = vmw_gmrid_man_debug
41357 };
41358diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41359index 37881ec..319065d 100644
41360--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41361+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41362@@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41363 int ret;
41364
41365 num_clips = arg->num_clips;
41366- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41367+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41368
41369 if (unlikely(num_clips == 0))
41370 return 0;
41371@@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41372 int ret;
41373
41374 num_clips = arg->num_clips;
41375- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41376+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41377
41378 if (unlikely(num_clips == 0))
41379 return 0;
41380diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41381index 0c42376..6febe77 100644
41382--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41383+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41384@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41385 * emitted. Then the fence is stale and signaled.
41386 */
41387
41388- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41389+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41390 > VMW_FENCE_WRAP);
41391
41392 return ret;
41393@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41394
41395 if (fifo_idle)
41396 down_read(&fifo_state->rwsem);
41397- signal_seq = atomic_read(&dev_priv->marker_seq);
41398+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41399 ret = 0;
41400
41401 for (;;) {
41402diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41403index 8a8725c2..afed796 100644
41404--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41405+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41406@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41407 while (!vmw_lag_lt(queue, us)) {
41408 spin_lock(&queue->lock);
41409 if (list_empty(&queue->head))
41410- seqno = atomic_read(&dev_priv->marker_seq);
41411+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41412 else {
41413 marker = list_first_entry(&queue->head,
41414 struct vmw_marker, head);
41415diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41416index 6866448..2ad2b34 100644
41417--- a/drivers/gpu/vga/vga_switcheroo.c
41418+++ b/drivers/gpu/vga/vga_switcheroo.c
41419@@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41420
41421 /* this version is for the case where the power switch is separate
41422 to the device being powered down. */
41423-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41424+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41425 {
41426 /* copy over all the bus versions */
41427 if (dev->bus && dev->bus->pm) {
41428@@ -689,7 +689,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41429 return ret;
41430 }
41431
41432-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41433+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41434 {
41435 /* copy over all the bus versions */
41436 if (dev->bus && dev->bus->pm) {
41437diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41438index a5c7927..025a2b4 100644
41439--- a/drivers/hid/hid-core.c
41440+++ b/drivers/hid/hid-core.c
41441@@ -2476,7 +2476,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41442
41443 int hid_add_device(struct hid_device *hdev)
41444 {
41445- static atomic_t id = ATOMIC_INIT(0);
41446+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41447 int ret;
41448
41449 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41450@@ -2518,7 +2518,7 @@ int hid_add_device(struct hid_device *hdev)
41451 /* XXX hack, any other cleaner solution after the driver core
41452 * is converted to allow more than 20 bytes as the device name? */
41453 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41454- hdev->vendor, hdev->product, atomic_inc_return(&id));
41455+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41456
41457 hid_debug_register(hdev, dev_name(&hdev->dev));
41458 ret = device_add(&hdev->dev);
41459diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41460index c13fb5b..55a3802 100644
41461--- a/drivers/hid/hid-wiimote-debug.c
41462+++ b/drivers/hid/hid-wiimote-debug.c
41463@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41464 else if (size == 0)
41465 return -EIO;
41466
41467- if (copy_to_user(u, buf, size))
41468+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41469 return -EFAULT;
41470
41471 *off += size;
41472diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41473index 0d078c3..cd0962c 100644
41474--- a/drivers/hid/uhid.c
41475+++ b/drivers/hid/uhid.c
41476@@ -47,7 +47,7 @@ struct uhid_device {
41477 struct mutex report_lock;
41478 wait_queue_head_t report_wait;
41479 atomic_t report_done;
41480- atomic_t report_id;
41481+ atomic_unchecked_t report_id;
41482 struct uhid_event report_buf;
41483 };
41484
41485@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41486
41487 spin_lock_irqsave(&uhid->qlock, flags);
41488 ev->type = UHID_FEATURE;
41489- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41490+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41491 ev->u.feature.rnum = rnum;
41492 ev->u.feature.rtype = report_type;
41493
41494@@ -539,7 +539,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41495 spin_lock_irqsave(&uhid->qlock, flags);
41496
41497 /* id for old report; drop it silently */
41498- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41499+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41500 goto unlock;
41501 if (atomic_read(&uhid->report_done))
41502 goto unlock;
41503diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41504index 602ca86..10a6573 100644
41505--- a/drivers/hv/channel.c
41506+++ b/drivers/hv/channel.c
41507@@ -365,8 +365,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41508 int ret = 0;
41509 int t;
41510
41511- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41512- atomic_inc(&vmbus_connection.next_gpadl_handle);
41513+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41514+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41515
41516 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41517 if (ret)
41518diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41519index bcb4950..61dba6c 100644
41520--- a/drivers/hv/hv.c
41521+++ b/drivers/hv/hv.c
41522@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41523 u64 output_address = (output) ? virt_to_phys(output) : 0;
41524 u32 output_address_hi = output_address >> 32;
41525 u32 output_address_lo = output_address & 0xFFFFFFFF;
41526- void *hypercall_page = hv_context.hypercall_page;
41527+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41528
41529 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41530 "=a"(hv_status_lo) : "d" (control_hi),
41531@@ -154,7 +154,7 @@ int hv_init(void)
41532 /* See if the hypercall page is already set */
41533 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41534
41535- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41536+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41537
41538 if (!virtaddr)
41539 goto cleanup;
41540diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41541index 5e90c5d..d8fcefb 100644
41542--- a/drivers/hv/hv_balloon.c
41543+++ b/drivers/hv/hv_balloon.c
41544@@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41545
41546 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41547 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41548-static atomic_t trans_id = ATOMIC_INIT(0);
41549+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41550
41551 static int dm_ring_size = (5 * PAGE_SIZE);
41552
41553@@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
41554 pr_info("Memory hot add failed\n");
41555
41556 dm->state = DM_INITIALIZED;
41557- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41558+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41559 vmbus_sendpacket(dm->dev->channel, &resp,
41560 sizeof(struct dm_hot_add_response),
41561 (unsigned long)NULL,
41562@@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
41563 memset(&status, 0, sizeof(struct dm_status));
41564 status.hdr.type = DM_STATUS_REPORT;
41565 status.hdr.size = sizeof(struct dm_status);
41566- status.hdr.trans_id = atomic_inc_return(&trans_id);
41567+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41568
41569 /*
41570 * The host expects the guest to report free memory.
41571@@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
41572 * send the status. This can happen if we were interrupted
41573 * after we picked our transaction ID.
41574 */
41575- if (status.hdr.trans_id != atomic_read(&trans_id))
41576+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41577 return;
41578
41579 /*
41580@@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
41581 */
41582
41583 do {
41584- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41585+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41586 ret = vmbus_sendpacket(dm_device.dev->channel,
41587 bl_resp,
41588 bl_resp->hdr.size,
41589@@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41590
41591 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41592 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41593- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41594+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41595 resp.hdr.size = sizeof(struct dm_unballoon_response);
41596
41597 vmbus_sendpacket(dm_device.dev->channel, &resp,
41598@@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41599 memset(&version_req, 0, sizeof(struct dm_version_request));
41600 version_req.hdr.type = DM_VERSION_REQUEST;
41601 version_req.hdr.size = sizeof(struct dm_version_request);
41602- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41603+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41604 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41605 version_req.is_last_attempt = 1;
41606
41607@@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
41608 memset(&version_req, 0, sizeof(struct dm_version_request));
41609 version_req.hdr.type = DM_VERSION_REQUEST;
41610 version_req.hdr.size = sizeof(struct dm_version_request);
41611- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41612+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41613 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41614 version_req.is_last_attempt = 0;
41615
41616@@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
41617 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41618 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41619 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41620- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41621+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41622
41623 cap_msg.caps.cap_bits.balloon = 1;
41624 cap_msg.caps.cap_bits.hot_add = 1;
41625diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41626index 860134d..ea3a79a 100644
41627--- a/drivers/hv/hyperv_vmbus.h
41628+++ b/drivers/hv/hyperv_vmbus.h
41629@@ -602,7 +602,7 @@ enum vmbus_connect_state {
41630 struct vmbus_connection {
41631 enum vmbus_connect_state conn_state;
41632
41633- atomic_t next_gpadl_handle;
41634+ atomic_unchecked_t next_gpadl_handle;
41635
41636 /*
41637 * Represents channel interrupts. Each bit position represents a
41638diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41639index 8e53a3c..7a64e44 100644
41640--- a/drivers/hv/vmbus_drv.c
41641+++ b/drivers/hv/vmbus_drv.c
41642@@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41643 {
41644 int ret = 0;
41645
41646- static atomic_t device_num = ATOMIC_INIT(0);
41647+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41648
41649 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41650- atomic_inc_return(&device_num));
41651+ atomic_inc_return_unchecked(&device_num));
41652
41653 child_device_obj->device.bus = &hv_bus;
41654 child_device_obj->device.parent = &hv_acpi_dev->dev;
41655diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41656index 579bdf9..75118b5 100644
41657--- a/drivers/hwmon/acpi_power_meter.c
41658+++ b/drivers/hwmon/acpi_power_meter.c
41659@@ -116,7 +116,7 @@ struct sensor_template {
41660 struct device_attribute *devattr,
41661 const char *buf, size_t count);
41662 int index;
41663-};
41664+} __do_const;
41665
41666 /* Averaging interval */
41667 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41668@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41669 struct sensor_template *attrs)
41670 {
41671 struct device *dev = &resource->acpi_dev->dev;
41672- struct sensor_device_attribute *sensors =
41673+ sensor_device_attribute_no_const *sensors =
41674 &resource->sensors[resource->num_sensors];
41675 int res = 0;
41676
41677diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41678index 3288f13..71cfb4e 100644
41679--- a/drivers/hwmon/applesmc.c
41680+++ b/drivers/hwmon/applesmc.c
41681@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41682 {
41683 struct applesmc_node_group *grp;
41684 struct applesmc_dev_attr *node;
41685- struct attribute *attr;
41686+ attribute_no_const *attr;
41687 int ret, i;
41688
41689 for (grp = groups; grp->format; grp++) {
41690diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41691index ae208f6..48b6c5b 100644
41692--- a/drivers/hwmon/asus_atk0110.c
41693+++ b/drivers/hwmon/asus_atk0110.c
41694@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41695 struct atk_sensor_data {
41696 struct list_head list;
41697 struct atk_data *data;
41698- struct device_attribute label_attr;
41699- struct device_attribute input_attr;
41700- struct device_attribute limit1_attr;
41701- struct device_attribute limit2_attr;
41702+ device_attribute_no_const label_attr;
41703+ device_attribute_no_const input_attr;
41704+ device_attribute_no_const limit1_attr;
41705+ device_attribute_no_const limit2_attr;
41706 char label_attr_name[ATTR_NAME_SIZE];
41707 char input_attr_name[ATTR_NAME_SIZE];
41708 char limit1_attr_name[ATTR_NAME_SIZE];
41709@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41710 static struct device_attribute atk_name_attr =
41711 __ATTR(name, 0444, atk_name_show, NULL);
41712
41713-static void atk_init_attribute(struct device_attribute *attr, char *name,
41714+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41715 sysfs_show_func show)
41716 {
41717 sysfs_attr_init(&attr->attr);
41718diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41719index d76f0b7..55ae976 100644
41720--- a/drivers/hwmon/coretemp.c
41721+++ b/drivers/hwmon/coretemp.c
41722@@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41723 return NOTIFY_OK;
41724 }
41725
41726-static struct notifier_block coretemp_cpu_notifier __refdata = {
41727+static struct notifier_block coretemp_cpu_notifier = {
41728 .notifier_call = coretemp_cpu_callback,
41729 };
41730
41731diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41732index 632f1dc..57e6a58 100644
41733--- a/drivers/hwmon/ibmaem.c
41734+++ b/drivers/hwmon/ibmaem.c
41735@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41736 struct aem_rw_sensor_template *rw)
41737 {
41738 struct device *dev = &data->pdev->dev;
41739- struct sensor_device_attribute *sensors = data->sensors;
41740+ sensor_device_attribute_no_const *sensors = data->sensors;
41741 int err;
41742
41743 /* Set up read-only sensors */
41744diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41745index 9fbb1b1..efbaa3e 100644
41746--- a/drivers/hwmon/iio_hwmon.c
41747+++ b/drivers/hwmon/iio_hwmon.c
41748@@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41749 {
41750 struct device *dev = &pdev->dev;
41751 struct iio_hwmon_state *st;
41752- struct sensor_device_attribute *a;
41753+ sensor_device_attribute_no_const *a;
41754 int ret, i;
41755 int in_i = 1, temp_i = 1, curr_i = 1;
41756 enum iio_chan_type type;
41757diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41758index 38d5a63..cf2c2ea 100644
41759--- a/drivers/hwmon/nct6775.c
41760+++ b/drivers/hwmon/nct6775.c
41761@@ -944,10 +944,10 @@ static struct attribute_group *
41762 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41763 int repeat)
41764 {
41765- struct attribute_group *group;
41766+ attribute_group_no_const *group;
41767 struct sensor_device_attr_u *su;
41768- struct sensor_device_attribute *a;
41769- struct sensor_device_attribute_2 *a2;
41770+ sensor_device_attribute_no_const *a;
41771+ sensor_device_attribute_2_no_const *a2;
41772 struct attribute **attrs;
41773 struct sensor_device_template **t;
41774 int i, count;
41775diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41776index 291d11f..3f0dbbd 100644
41777--- a/drivers/hwmon/pmbus/pmbus_core.c
41778+++ b/drivers/hwmon/pmbus/pmbus_core.c
41779@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41780 return 0;
41781 }
41782
41783-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41784+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41785 const char *name,
41786 umode_t mode,
41787 ssize_t (*show)(struct device *dev,
41788@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41789 dev_attr->store = store;
41790 }
41791
41792-static void pmbus_attr_init(struct sensor_device_attribute *a,
41793+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41794 const char *name,
41795 umode_t mode,
41796 ssize_t (*show)(struct device *dev,
41797@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41798 u16 reg, u8 mask)
41799 {
41800 struct pmbus_boolean *boolean;
41801- struct sensor_device_attribute *a;
41802+ sensor_device_attribute_no_const *a;
41803
41804 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41805 if (!boolean)
41806@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41807 bool update, bool readonly)
41808 {
41809 struct pmbus_sensor *sensor;
41810- struct device_attribute *a;
41811+ device_attribute_no_const *a;
41812
41813 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41814 if (!sensor)
41815@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41816 const char *lstring, int index)
41817 {
41818 struct pmbus_label *label;
41819- struct device_attribute *a;
41820+ device_attribute_no_const *a;
41821
41822 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41823 if (!label)
41824diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41825index 97cd45a..ac54d8b 100644
41826--- a/drivers/hwmon/sht15.c
41827+++ b/drivers/hwmon/sht15.c
41828@@ -169,7 +169,7 @@ struct sht15_data {
41829 int supply_uv;
41830 bool supply_uv_valid;
41831 struct work_struct update_supply_work;
41832- atomic_t interrupt_handled;
41833+ atomic_unchecked_t interrupt_handled;
41834 };
41835
41836 /**
41837@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41838 ret = gpio_direction_input(data->pdata->gpio_data);
41839 if (ret)
41840 return ret;
41841- atomic_set(&data->interrupt_handled, 0);
41842+ atomic_set_unchecked(&data->interrupt_handled, 0);
41843
41844 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41845 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41846 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41847 /* Only relevant if the interrupt hasn't occurred. */
41848- if (!atomic_read(&data->interrupt_handled))
41849+ if (!atomic_read_unchecked(&data->interrupt_handled))
41850 schedule_work(&data->read_work);
41851 }
41852 ret = wait_event_timeout(data->wait_queue,
41853@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41854
41855 /* First disable the interrupt */
41856 disable_irq_nosync(irq);
41857- atomic_inc(&data->interrupt_handled);
41858+ atomic_inc_unchecked(&data->interrupt_handled);
41859 /* Then schedule a reading work struct */
41860 if (data->state != SHT15_READING_NOTHING)
41861 schedule_work(&data->read_work);
41862@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41863 * If not, then start the interrupt again - care here as could
41864 * have gone low in meantime so verify it hasn't!
41865 */
41866- atomic_set(&data->interrupt_handled, 0);
41867+ atomic_set_unchecked(&data->interrupt_handled, 0);
41868 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41869 /* If still not occurred or another handler was scheduled */
41870 if (gpio_get_value(data->pdata->gpio_data)
41871- || atomic_read(&data->interrupt_handled))
41872+ || atomic_read_unchecked(&data->interrupt_handled))
41873 return;
41874 }
41875
41876diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41877index 8df43c5..b07b91d 100644
41878--- a/drivers/hwmon/via-cputemp.c
41879+++ b/drivers/hwmon/via-cputemp.c
41880@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41881 return NOTIFY_OK;
41882 }
41883
41884-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41885+static struct notifier_block via_cputemp_cpu_notifier = {
41886 .notifier_call = via_cputemp_cpu_callback,
41887 };
41888
41889diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41890index 41fc683..a39cfea 100644
41891--- a/drivers/i2c/busses/i2c-amd756-s4882.c
41892+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41893@@ -43,7 +43,7 @@
41894 extern struct i2c_adapter amd756_smbus;
41895
41896 static struct i2c_adapter *s4882_adapter;
41897-static struct i2c_algorithm *s4882_algo;
41898+static i2c_algorithm_no_const *s4882_algo;
41899
41900 /* Wrapper access functions for multiplexed SMBus */
41901 static DEFINE_MUTEX(amd756_lock);
41902diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41903index 721f7eb..0fd2a09 100644
41904--- a/drivers/i2c/busses/i2c-diolan-u2c.c
41905+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41906@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41907 /* usb layer */
41908
41909 /* Send command to device, and get response. */
41910-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41911+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41912 {
41913 int ret = 0;
41914 int actual;
41915diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41916index b170bdf..3c76427 100644
41917--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41918+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41919@@ -41,7 +41,7 @@
41920 extern struct i2c_adapter *nforce2_smbus;
41921
41922 static struct i2c_adapter *s4985_adapter;
41923-static struct i2c_algorithm *s4985_algo;
41924+static i2c_algorithm_no_const *s4985_algo;
41925
41926 /* Wrapper access functions for multiplexed SMBus */
41927 static DEFINE_MUTEX(nforce2_lock);
41928diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41929index 80b47e8..1a6040d9 100644
41930--- a/drivers/i2c/i2c-dev.c
41931+++ b/drivers/i2c/i2c-dev.c
41932@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41933 break;
41934 }
41935
41936- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41937+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41938 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41939 if (IS_ERR(rdwr_pa[i].buf)) {
41940 res = PTR_ERR(rdwr_pa[i].buf);
41941diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41942index 0b510ba..4fbb5085 100644
41943--- a/drivers/ide/ide-cd.c
41944+++ b/drivers/ide/ide-cd.c
41945@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41946 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41947 if ((unsigned long)buf & alignment
41948 || blk_rq_bytes(rq) & q->dma_pad_mask
41949- || object_is_on_stack(buf))
41950+ || object_starts_on_stack(buf))
41951 drive->dma = 0;
41952 }
41953 }
41954diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41955index ede16aec..e423e8a 100644
41956--- a/drivers/iio/industrialio-core.c
41957+++ b/drivers/iio/industrialio-core.c
41958@@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41959 }
41960
41961 static
41962-int __iio_device_attr_init(struct device_attribute *dev_attr,
41963+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41964 const char *postfix,
41965 struct iio_chan_spec const *chan,
41966 ssize_t (*readfunc)(struct device *dev,
41967diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41968index c323917..6ddea8b 100644
41969--- a/drivers/infiniband/core/cm.c
41970+++ b/drivers/infiniband/core/cm.c
41971@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41972
41973 struct cm_counter_group {
41974 struct kobject obj;
41975- atomic_long_t counter[CM_ATTR_COUNT];
41976+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41977 };
41978
41979 struct cm_counter_attribute {
41980@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41981 struct ib_mad_send_buf *msg = NULL;
41982 int ret;
41983
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_REQ_COUNTER]);
41987
41988 /* Quick state check to discard duplicate REQs. */
41989@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41990 if (!cm_id_priv)
41991 return;
41992
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_REP_COUNTER]);
41996 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41997 if (ret)
41998@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
41999 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42000 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42001 spin_unlock_irq(&cm_id_priv->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_RTU_COUNTER]);
42005 goto out;
42006 }
42007@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42008 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42009 dreq_msg->local_comm_id);
42010 if (!cm_id_priv) {
42011- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42012+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42013 counter[CM_DREQ_COUNTER]);
42014 cm_issue_drep(work->port, work->mad_recv_wc);
42015 return -EINVAL;
42016@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42017 case IB_CM_MRA_REP_RCVD:
42018 break;
42019 case IB_CM_TIMEWAIT:
42020- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42021+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42022 counter[CM_DREQ_COUNTER]);
42023 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42024 goto unlock;
42025@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42026 cm_free_msg(msg);
42027 goto deref;
42028 case IB_CM_DREQ_RCVD:
42029- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42030+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42031 counter[CM_DREQ_COUNTER]);
42032 goto unlock;
42033 default:
42034@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42035 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42036 cm_id_priv->msg, timeout)) {
42037 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42038- atomic_long_inc(&work->port->
42039+ atomic_long_inc_unchecked(&work->port->
42040 counter_group[CM_RECV_DUPLICATES].
42041 counter[CM_MRA_COUNTER]);
42042 goto out;
42043@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42044 break;
42045 case IB_CM_MRA_REQ_RCVD:
42046 case IB_CM_MRA_REP_RCVD:
42047- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42048+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42049 counter[CM_MRA_COUNTER]);
42050 /* fall through */
42051 default:
42052@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42053 case IB_CM_LAP_IDLE:
42054 break;
42055 case IB_CM_MRA_LAP_SENT:
42056- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42057+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42058 counter[CM_LAP_COUNTER]);
42059 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42060 goto unlock;
42061@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42062 cm_free_msg(msg);
42063 goto deref;
42064 case IB_CM_LAP_RCVD:
42065- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42066+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42067 counter[CM_LAP_COUNTER]);
42068 goto unlock;
42069 default:
42070@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42071 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42072 if (cur_cm_id_priv) {
42073 spin_unlock_irq(&cm.lock);
42074- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42075+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42076 counter[CM_SIDR_REQ_COUNTER]);
42077 goto out; /* Duplicate message. */
42078 }
42079@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42080 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42081 msg->retries = 1;
42082
42083- atomic_long_add(1 + msg->retries,
42084+ atomic_long_add_unchecked(1 + msg->retries,
42085 &port->counter_group[CM_XMIT].counter[attr_index]);
42086 if (msg->retries)
42087- atomic_long_add(msg->retries,
42088+ atomic_long_add_unchecked(msg->retries,
42089 &port->counter_group[CM_XMIT_RETRIES].
42090 counter[attr_index]);
42091
42092@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42093 }
42094
42095 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42096- atomic_long_inc(&port->counter_group[CM_RECV].
42097+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42098 counter[attr_id - CM_ATTR_ID_OFFSET]);
42099
42100 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42101@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42102 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42103
42104 return sprintf(buf, "%ld\n",
42105- atomic_long_read(&group->counter[cm_attr->index]));
42106+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42107 }
42108
42109 static const struct sysfs_ops cm_counter_ops = {
42110diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42111index 9f5ad7c..588cd84 100644
42112--- a/drivers/infiniband/core/fmr_pool.c
42113+++ b/drivers/infiniband/core/fmr_pool.c
42114@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42115
42116 struct task_struct *thread;
42117
42118- atomic_t req_ser;
42119- atomic_t flush_ser;
42120+ atomic_unchecked_t req_ser;
42121+ atomic_unchecked_t flush_ser;
42122
42123 wait_queue_head_t force_wait;
42124 };
42125@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42126 struct ib_fmr_pool *pool = pool_ptr;
42127
42128 do {
42129- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42130+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42131 ib_fmr_batch_release(pool);
42132
42133- atomic_inc(&pool->flush_ser);
42134+ atomic_inc_unchecked(&pool->flush_ser);
42135 wake_up_interruptible(&pool->force_wait);
42136
42137 if (pool->flush_function)
42138@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42139 }
42140
42141 set_current_state(TASK_INTERRUPTIBLE);
42142- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42143+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42144 !kthread_should_stop())
42145 schedule();
42146 __set_current_state(TASK_RUNNING);
42147@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42148 pool->dirty_watermark = params->dirty_watermark;
42149 pool->dirty_len = 0;
42150 spin_lock_init(&pool->pool_lock);
42151- atomic_set(&pool->req_ser, 0);
42152- atomic_set(&pool->flush_ser, 0);
42153+ atomic_set_unchecked(&pool->req_ser, 0);
42154+ atomic_set_unchecked(&pool->flush_ser, 0);
42155 init_waitqueue_head(&pool->force_wait);
42156
42157 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42158@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42159 }
42160 spin_unlock_irq(&pool->pool_lock);
42161
42162- serial = atomic_inc_return(&pool->req_ser);
42163+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42164 wake_up_process(pool->thread);
42165
42166 if (wait_event_interruptible(pool->force_wait,
42167- atomic_read(&pool->flush_ser) - serial >= 0))
42168+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42169 return -EINTR;
42170
42171 return 0;
42172@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42173 } else {
42174 list_add_tail(&fmr->list, &pool->dirty_list);
42175 if (++pool->dirty_len >= pool->dirty_watermark) {
42176- atomic_inc(&pool->req_ser);
42177+ atomic_inc_unchecked(&pool->req_ser);
42178 wake_up_process(pool->thread);
42179 }
42180 }
42181diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42182index ec7a298..8742e59 100644
42183--- a/drivers/infiniband/hw/cxgb4/mem.c
42184+++ b/drivers/infiniband/hw/cxgb4/mem.c
42185@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42186 int err;
42187 struct fw_ri_tpte tpt;
42188 u32 stag_idx;
42189- static atomic_t key;
42190+ static atomic_unchecked_t key;
42191
42192 if (c4iw_fatal_error(rdev))
42193 return -EIO;
42194@@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42195 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42196 rdev->stats.stag.max = rdev->stats.stag.cur;
42197 mutex_unlock(&rdev->stats.lock);
42198- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42199+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42200 }
42201 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42202 __func__, stag_state, type, pdid, stag_idx);
42203diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42204index 79b3dbc..96e5fcc 100644
42205--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42206+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42207@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42208 struct ib_atomic_eth *ateth;
42209 struct ipath_ack_entry *e;
42210 u64 vaddr;
42211- atomic64_t *maddr;
42212+ atomic64_unchecked_t *maddr;
42213 u64 sdata;
42214 u32 rkey;
42215 u8 next;
42216@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42217 IB_ACCESS_REMOTE_ATOMIC)))
42218 goto nack_acc_unlck;
42219 /* Perform atomic OP and save result. */
42220- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42221+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42222 sdata = be64_to_cpu(ateth->swap_data);
42223 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42224 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42225- (u64) atomic64_add_return(sdata, maddr) - sdata :
42226+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42227 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42228 be64_to_cpu(ateth->compare_data),
42229 sdata);
42230diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42231index 1f95bba..9530f87 100644
42232--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42233+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42234@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42235 unsigned long flags;
42236 struct ib_wc wc;
42237 u64 sdata;
42238- atomic64_t *maddr;
42239+ atomic64_unchecked_t *maddr;
42240 enum ib_wc_status send_status;
42241
42242 /*
42243@@ -382,11 +382,11 @@ again:
42244 IB_ACCESS_REMOTE_ATOMIC)))
42245 goto acc_err;
42246 /* Perform atomic OP and save result. */
42247- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42248+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42249 sdata = wqe->wr.wr.atomic.compare_add;
42250 *(u64 *) sqp->s_sge.sge.vaddr =
42251 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42252- (u64) atomic64_add_return(sdata, maddr) - sdata :
42253+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42254 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42255 sdata, wqe->wr.wr.atomic.swap);
42256 goto send_comp;
42257diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42258index fd36ec6..a6a082f 100644
42259--- a/drivers/infiniband/hw/mlx4/mad.c
42260+++ b/drivers/infiniband/hw/mlx4/mad.c
42261@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42262
42263 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42264 {
42265- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42266+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42267 cpu_to_be64(0xff00000000000000LL);
42268 }
42269
42270diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42271index ed327e6..ca1739e0 100644
42272--- a/drivers/infiniband/hw/mlx4/mcg.c
42273+++ b/drivers/infiniband/hw/mlx4/mcg.c
42274@@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42275 {
42276 char name[20];
42277
42278- atomic_set(&ctx->tid, 0);
42279+ atomic_set_unchecked(&ctx->tid, 0);
42280 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42281 ctx->mcg_wq = create_singlethread_workqueue(name);
42282 if (!ctx->mcg_wq)
42283diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42284index 66b0b7d..f14836a 100644
42285--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42286+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42287@@ -425,7 +425,7 @@ struct mlx4_ib_demux_ctx {
42288 struct list_head mcg_mgid0_list;
42289 struct workqueue_struct *mcg_wq;
42290 struct mlx4_ib_demux_pv_ctx **tun;
42291- atomic_t tid;
42292+ atomic_unchecked_t tid;
42293 int flushing; /* flushing the work queue */
42294 };
42295
42296diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42297index 9d3e5c1..6f166df 100644
42298--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42299+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42300@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42301 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42302 }
42303
42304-int mthca_QUERY_FW(struct mthca_dev *dev)
42305+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42306 {
42307 struct mthca_mailbox *mailbox;
42308 u32 *outbox;
42309@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42310 CMD_TIME_CLASS_B);
42311 }
42312
42313-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42314+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42315 int num_mtt)
42316 {
42317 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42318@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42319 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42320 }
42321
42322-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42323+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42324 int eq_num)
42325 {
42326 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42327@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42328 CMD_TIME_CLASS_B);
42329 }
42330
42331-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42332+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42333 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42334 void *in_mad, void *response_mad)
42335 {
42336diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42337index ded76c1..0cf0a08 100644
42338--- a/drivers/infiniband/hw/mthca/mthca_main.c
42339+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42340@@ -692,7 +692,7 @@ err_close:
42341 return err;
42342 }
42343
42344-static int mthca_setup_hca(struct mthca_dev *dev)
42345+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42346 {
42347 int err;
42348
42349diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42350index ed9a989..6aa5dc2 100644
42351--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42352+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42353@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42354 * through the bitmaps)
42355 */
42356
42357-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42358+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42359 {
42360 int o;
42361 int m;
42362@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42363 return key;
42364 }
42365
42366-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42367+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42368 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42369 {
42370 struct mthca_mailbox *mailbox;
42371@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42372 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42373 }
42374
42375-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42376+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42377 u64 *buffer_list, int buffer_size_shift,
42378 int list_len, u64 iova, u64 total_size,
42379 u32 access, struct mthca_mr *mr)
42380diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42381index 415f8e1..e34214e 100644
42382--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42383+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42384@@ -764,7 +764,7 @@ unlock:
42385 return 0;
42386 }
42387
42388-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42389+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42390 {
42391 struct mthca_dev *dev = to_mdev(ibcq->device);
42392 struct mthca_cq *cq = to_mcq(ibcq);
42393diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42394index 353c7b0..c6ce921 100644
42395--- a/drivers/infiniband/hw/nes/nes.c
42396+++ b/drivers/infiniband/hw/nes/nes.c
42397@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42398 LIST_HEAD(nes_adapter_list);
42399 static LIST_HEAD(nes_dev_list);
42400
42401-atomic_t qps_destroyed;
42402+atomic_unchecked_t qps_destroyed;
42403
42404 static unsigned int ee_flsh_adapter;
42405 static unsigned int sysfs_nonidx_addr;
42406@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42407 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42408 struct nes_adapter *nesadapter = nesdev->nesadapter;
42409
42410- atomic_inc(&qps_destroyed);
42411+ atomic_inc_unchecked(&qps_destroyed);
42412
42413 /* Free the control structures */
42414
42415diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42416index 33cc589..3bd6538 100644
42417--- a/drivers/infiniband/hw/nes/nes.h
42418+++ b/drivers/infiniband/hw/nes/nes.h
42419@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42420 extern unsigned int wqm_quanta;
42421 extern struct list_head nes_adapter_list;
42422
42423-extern atomic_t cm_connects;
42424-extern atomic_t cm_accepts;
42425-extern atomic_t cm_disconnects;
42426-extern atomic_t cm_closes;
42427-extern atomic_t cm_connecteds;
42428-extern atomic_t cm_connect_reqs;
42429-extern atomic_t cm_rejects;
42430-extern atomic_t mod_qp_timouts;
42431-extern atomic_t qps_created;
42432-extern atomic_t qps_destroyed;
42433-extern atomic_t sw_qps_destroyed;
42434+extern atomic_unchecked_t cm_connects;
42435+extern atomic_unchecked_t cm_accepts;
42436+extern atomic_unchecked_t cm_disconnects;
42437+extern atomic_unchecked_t cm_closes;
42438+extern atomic_unchecked_t cm_connecteds;
42439+extern atomic_unchecked_t cm_connect_reqs;
42440+extern atomic_unchecked_t cm_rejects;
42441+extern atomic_unchecked_t mod_qp_timouts;
42442+extern atomic_unchecked_t qps_created;
42443+extern atomic_unchecked_t qps_destroyed;
42444+extern atomic_unchecked_t sw_qps_destroyed;
42445 extern u32 mh_detected;
42446 extern u32 mh_pauses_sent;
42447 extern u32 cm_packets_sent;
42448@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42449 extern u32 cm_packets_received;
42450 extern u32 cm_packets_dropped;
42451 extern u32 cm_packets_retrans;
42452-extern atomic_t cm_listens_created;
42453-extern atomic_t cm_listens_destroyed;
42454+extern atomic_unchecked_t cm_listens_created;
42455+extern atomic_unchecked_t cm_listens_destroyed;
42456 extern u32 cm_backlog_drops;
42457-extern atomic_t cm_loopbacks;
42458-extern atomic_t cm_nodes_created;
42459-extern atomic_t cm_nodes_destroyed;
42460-extern atomic_t cm_accel_dropped_pkts;
42461-extern atomic_t cm_resets_recvd;
42462-extern atomic_t pau_qps_created;
42463-extern atomic_t pau_qps_destroyed;
42464+extern atomic_unchecked_t cm_loopbacks;
42465+extern atomic_unchecked_t cm_nodes_created;
42466+extern atomic_unchecked_t cm_nodes_destroyed;
42467+extern atomic_unchecked_t cm_accel_dropped_pkts;
42468+extern atomic_unchecked_t cm_resets_recvd;
42469+extern atomic_unchecked_t pau_qps_created;
42470+extern atomic_unchecked_t pau_qps_destroyed;
42471
42472 extern u32 int_mod_timer_init;
42473 extern u32 int_mod_cq_depth_256;
42474diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42475index dfa9df4..6bf7221 100644
42476--- a/drivers/infiniband/hw/nes/nes_cm.c
42477+++ b/drivers/infiniband/hw/nes/nes_cm.c
42478@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42479 u32 cm_packets_retrans;
42480 u32 cm_packets_created;
42481 u32 cm_packets_received;
42482-atomic_t cm_listens_created;
42483-atomic_t cm_listens_destroyed;
42484+atomic_unchecked_t cm_listens_created;
42485+atomic_unchecked_t cm_listens_destroyed;
42486 u32 cm_backlog_drops;
42487-atomic_t cm_loopbacks;
42488-atomic_t cm_nodes_created;
42489-atomic_t cm_nodes_destroyed;
42490-atomic_t cm_accel_dropped_pkts;
42491-atomic_t cm_resets_recvd;
42492+atomic_unchecked_t cm_loopbacks;
42493+atomic_unchecked_t cm_nodes_created;
42494+atomic_unchecked_t cm_nodes_destroyed;
42495+atomic_unchecked_t cm_accel_dropped_pkts;
42496+atomic_unchecked_t cm_resets_recvd;
42497
42498 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42499 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42500@@ -134,28 +134,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
42501 /* instance of function pointers for client API */
42502 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42503 static struct nes_cm_ops nes_cm_api = {
42504- mini_cm_accelerated,
42505- mini_cm_listen,
42506- mini_cm_del_listen,
42507- mini_cm_connect,
42508- mini_cm_close,
42509- mini_cm_accept,
42510- mini_cm_reject,
42511- mini_cm_recv_pkt,
42512- mini_cm_dealloc_core,
42513- mini_cm_get,
42514- mini_cm_set
42515+ .accelerated = mini_cm_accelerated,
42516+ .listen = mini_cm_listen,
42517+ .stop_listener = mini_cm_del_listen,
42518+ .connect = mini_cm_connect,
42519+ .close = mini_cm_close,
42520+ .accept = mini_cm_accept,
42521+ .reject = mini_cm_reject,
42522+ .recv_pkt = mini_cm_recv_pkt,
42523+ .destroy_cm_core = mini_cm_dealloc_core,
42524+ .get = mini_cm_get,
42525+ .set = mini_cm_set
42526 };
42527
42528 static struct nes_cm_core *g_cm_core;
42529
42530-atomic_t cm_connects;
42531-atomic_t cm_accepts;
42532-atomic_t cm_disconnects;
42533-atomic_t cm_closes;
42534-atomic_t cm_connecteds;
42535-atomic_t cm_connect_reqs;
42536-atomic_t cm_rejects;
42537+atomic_unchecked_t cm_connects;
42538+atomic_unchecked_t cm_accepts;
42539+atomic_unchecked_t cm_disconnects;
42540+atomic_unchecked_t cm_closes;
42541+atomic_unchecked_t cm_connecteds;
42542+atomic_unchecked_t cm_connect_reqs;
42543+atomic_unchecked_t cm_rejects;
42544
42545 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42546 {
42547@@ -1319,7 +1319,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42548 kfree(listener);
42549 listener = NULL;
42550 ret = 0;
42551- atomic_inc(&cm_listens_destroyed);
42552+ atomic_inc_unchecked(&cm_listens_destroyed);
42553 } else {
42554 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42555 }
42556@@ -1513,7 +1513,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42557 cm_node->rem_mac);
42558
42559 add_hte_node(cm_core, cm_node);
42560- atomic_inc(&cm_nodes_created);
42561+ atomic_inc_unchecked(&cm_nodes_created);
42562
42563 return cm_node;
42564 }
42565@@ -1571,7 +1571,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42566 }
42567
42568 atomic_dec(&cm_core->node_cnt);
42569- atomic_inc(&cm_nodes_destroyed);
42570+ atomic_inc_unchecked(&cm_nodes_destroyed);
42571 nesqp = cm_node->nesqp;
42572 if (nesqp) {
42573 nesqp->cm_node = NULL;
42574@@ -1635,7 +1635,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42575
42576 static void drop_packet(struct sk_buff *skb)
42577 {
42578- atomic_inc(&cm_accel_dropped_pkts);
42579+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42580 dev_kfree_skb_any(skb);
42581 }
42582
42583@@ -1698,7 +1698,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42584 {
42585
42586 int reset = 0; /* whether to send reset in case of err.. */
42587- atomic_inc(&cm_resets_recvd);
42588+ atomic_inc_unchecked(&cm_resets_recvd);
42589 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42590 " refcnt=%d\n", cm_node, cm_node->state,
42591 atomic_read(&cm_node->ref_count));
42592@@ -2339,7 +2339,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42593 rem_ref_cm_node(cm_node->cm_core, cm_node);
42594 return NULL;
42595 }
42596- atomic_inc(&cm_loopbacks);
42597+ atomic_inc_unchecked(&cm_loopbacks);
42598 loopbackremotenode->loopbackpartner = cm_node;
42599 loopbackremotenode->tcp_cntxt.rcv_wscale =
42600 NES_CM_DEFAULT_RCV_WND_SCALE;
42601@@ -2614,7 +2614,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42602 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42603 else {
42604 rem_ref_cm_node(cm_core, cm_node);
42605- atomic_inc(&cm_accel_dropped_pkts);
42606+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42607 dev_kfree_skb_any(skb);
42608 }
42609 break;
42610@@ -2922,7 +2922,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42611
42612 if ((cm_id) && (cm_id->event_handler)) {
42613 if (issue_disconn) {
42614- atomic_inc(&cm_disconnects);
42615+ atomic_inc_unchecked(&cm_disconnects);
42616 cm_event.event = IW_CM_EVENT_DISCONNECT;
42617 cm_event.status = disconn_status;
42618 cm_event.local_addr = cm_id->local_addr;
42619@@ -2944,7 +2944,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42620 }
42621
42622 if (issue_close) {
42623- atomic_inc(&cm_closes);
42624+ atomic_inc_unchecked(&cm_closes);
42625 nes_disconnect(nesqp, 1);
42626
42627 cm_id->provider_data = nesqp;
42628@@ -3082,7 +3082,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42629
42630 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42631 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42632- atomic_inc(&cm_accepts);
42633+ atomic_inc_unchecked(&cm_accepts);
42634
42635 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42636 netdev_refcnt_read(nesvnic->netdev));
42637@@ -3278,7 +3278,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42638 struct nes_cm_core *cm_core;
42639 u8 *start_buff;
42640
42641- atomic_inc(&cm_rejects);
42642+ atomic_inc_unchecked(&cm_rejects);
42643 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42644 loopback = cm_node->loopbackpartner;
42645 cm_core = cm_node->cm_core;
42646@@ -3340,7 +3340,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42647 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42648 ntohs(laddr->sin_port));
42649
42650- atomic_inc(&cm_connects);
42651+ atomic_inc_unchecked(&cm_connects);
42652 nesqp->active_conn = 1;
42653
42654 /* cache the cm_id in the qp */
42655@@ -3451,7 +3451,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42656 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42657 return err;
42658 }
42659- atomic_inc(&cm_listens_created);
42660+ atomic_inc_unchecked(&cm_listens_created);
42661 }
42662
42663 cm_id->add_ref(cm_id);
42664@@ -3558,7 +3558,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42665
42666 if (nesqp->destroyed)
42667 return;
42668- atomic_inc(&cm_connecteds);
42669+ atomic_inc_unchecked(&cm_connecteds);
42670 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42671 " local port 0x%04X. jiffies = %lu.\n",
42672 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42673@@ -3741,7 +3741,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42674
42675 cm_id->add_ref(cm_id);
42676 ret = cm_id->event_handler(cm_id, &cm_event);
42677- atomic_inc(&cm_closes);
42678+ atomic_inc_unchecked(&cm_closes);
42679 cm_event.event = IW_CM_EVENT_CLOSE;
42680 cm_event.status = 0;
42681 cm_event.provider_data = cm_id->provider_data;
42682@@ -3781,7 +3781,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42683 return;
42684 cm_id = cm_node->cm_id;
42685
42686- atomic_inc(&cm_connect_reqs);
42687+ atomic_inc_unchecked(&cm_connect_reqs);
42688 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42689 cm_node, cm_id, jiffies);
42690
42691@@ -3830,7 +3830,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42692 return;
42693 cm_id = cm_node->cm_id;
42694
42695- atomic_inc(&cm_connect_reqs);
42696+ atomic_inc_unchecked(&cm_connect_reqs);
42697 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42698 cm_node, cm_id, jiffies);
42699
42700diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42701index 4166452..fc952c3 100644
42702--- a/drivers/infiniband/hw/nes/nes_mgt.c
42703+++ b/drivers/infiniband/hw/nes/nes_mgt.c
42704@@ -40,8 +40,8 @@
42705 #include "nes.h"
42706 #include "nes_mgt.h"
42707
42708-atomic_t pau_qps_created;
42709-atomic_t pau_qps_destroyed;
42710+atomic_unchecked_t pau_qps_created;
42711+atomic_unchecked_t pau_qps_destroyed;
42712
42713 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42714 {
42715@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42716 {
42717 struct sk_buff *skb;
42718 unsigned long flags;
42719- atomic_inc(&pau_qps_destroyed);
42720+ atomic_inc_unchecked(&pau_qps_destroyed);
42721
42722 /* Free packets that have not yet been forwarded */
42723 /* Lock is acquired by skb_dequeue when removing the skb */
42724@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42725 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42726 skb_queue_head_init(&nesqp->pau_list);
42727 spin_lock_init(&nesqp->pau_lock);
42728- atomic_inc(&pau_qps_created);
42729+ atomic_inc_unchecked(&pau_qps_created);
42730 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42731 }
42732
42733diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42734index 49eb511..a774366 100644
42735--- a/drivers/infiniband/hw/nes/nes_nic.c
42736+++ b/drivers/infiniband/hw/nes/nes_nic.c
42737@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42738 target_stat_values[++index] = mh_detected;
42739 target_stat_values[++index] = mh_pauses_sent;
42740 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42741- target_stat_values[++index] = atomic_read(&cm_connects);
42742- target_stat_values[++index] = atomic_read(&cm_accepts);
42743- target_stat_values[++index] = atomic_read(&cm_disconnects);
42744- target_stat_values[++index] = atomic_read(&cm_connecteds);
42745- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42746- target_stat_values[++index] = atomic_read(&cm_rejects);
42747- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42748- target_stat_values[++index] = atomic_read(&qps_created);
42749- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42750- target_stat_values[++index] = atomic_read(&qps_destroyed);
42751- target_stat_values[++index] = atomic_read(&cm_closes);
42752+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42753+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42754+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42755+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42756+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42757+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42758+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42759+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42760+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42761+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42762+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42763 target_stat_values[++index] = cm_packets_sent;
42764 target_stat_values[++index] = cm_packets_bounced;
42765 target_stat_values[++index] = cm_packets_created;
42766 target_stat_values[++index] = cm_packets_received;
42767 target_stat_values[++index] = cm_packets_dropped;
42768 target_stat_values[++index] = cm_packets_retrans;
42769- target_stat_values[++index] = atomic_read(&cm_listens_created);
42770- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42771+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42772+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42773 target_stat_values[++index] = cm_backlog_drops;
42774- target_stat_values[++index] = atomic_read(&cm_loopbacks);
42775- target_stat_values[++index] = atomic_read(&cm_nodes_created);
42776- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42777- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42778- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42779+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42780+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42781+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42782+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42783+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42784 target_stat_values[++index] = nesadapter->free_4kpbl;
42785 target_stat_values[++index] = nesadapter->free_256pbl;
42786 target_stat_values[++index] = int_mod_timer_init;
42787 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42788 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42789 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42790- target_stat_values[++index] = atomic_read(&pau_qps_created);
42791- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42792+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42793+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42794 }
42795
42796 /**
42797diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42798index 218dd35..97ce31d 100644
42799--- a/drivers/infiniband/hw/nes/nes_verbs.c
42800+++ b/drivers/infiniband/hw/nes/nes_verbs.c
42801@@ -46,9 +46,9 @@
42802
42803 #include <rdma/ib_umem.h>
42804
42805-atomic_t mod_qp_timouts;
42806-atomic_t qps_created;
42807-atomic_t sw_qps_destroyed;
42808+atomic_unchecked_t mod_qp_timouts;
42809+atomic_unchecked_t qps_created;
42810+atomic_unchecked_t sw_qps_destroyed;
42811
42812 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42813
42814@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42815 if (init_attr->create_flags)
42816 return ERR_PTR(-EINVAL);
42817
42818- atomic_inc(&qps_created);
42819+ atomic_inc_unchecked(&qps_created);
42820 switch (init_attr->qp_type) {
42821 case IB_QPT_RC:
42822 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42823@@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42824 struct iw_cm_event cm_event;
42825 int ret = 0;
42826
42827- atomic_inc(&sw_qps_destroyed);
42828+ atomic_inc_unchecked(&sw_qps_destroyed);
42829 nesqp->destroyed = 1;
42830
42831 /* Blow away the connection if it exists. */
42832diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42833index c00ae09..04e91be 100644
42834--- a/drivers/infiniband/hw/qib/qib.h
42835+++ b/drivers/infiniband/hw/qib/qib.h
42836@@ -52,6 +52,7 @@
42837 #include <linux/kref.h>
42838 #include <linux/sched.h>
42839 #include <linux/kthread.h>
42840+#include <linux/slab.h>
42841
42842 #include "qib_common.h"
42843 #include "qib_verbs.h"
42844diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42845index 24c41ba..102d71f 100644
42846--- a/drivers/input/gameport/gameport.c
42847+++ b/drivers/input/gameport/gameport.c
42848@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42849 */
42850 static void gameport_init_port(struct gameport *gameport)
42851 {
42852- static atomic_t gameport_no = ATOMIC_INIT(0);
42853+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42854
42855 __module_get(THIS_MODULE);
42856
42857 mutex_init(&gameport->drv_mutex);
42858 device_initialize(&gameport->dev);
42859 dev_set_name(&gameport->dev, "gameport%lu",
42860- (unsigned long)atomic_inc_return(&gameport_no) - 1);
42861+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42862 gameport->dev.bus = &gameport_bus;
42863 gameport->dev.release = gameport_release_port;
42864 if (gameport->parent)
42865diff --git a/drivers/input/input.c b/drivers/input/input.c
42866index 1c4c0db..6f7abe3 100644
42867--- a/drivers/input/input.c
42868+++ b/drivers/input/input.c
42869@@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
42870 */
42871 struct input_dev *input_allocate_device(void)
42872 {
42873- static atomic_t input_no = ATOMIC_INIT(0);
42874+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42875 struct input_dev *dev;
42876
42877 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42878@@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
42879 INIT_LIST_HEAD(&dev->node);
42880
42881 dev_set_name(&dev->dev, "input%ld",
42882- (unsigned long) atomic_inc_return(&input_no) - 1);
42883+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42884
42885 __module_get(THIS_MODULE);
42886 }
42887diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42888index 4a95b22..874c182 100644
42889--- a/drivers/input/joystick/sidewinder.c
42890+++ b/drivers/input/joystick/sidewinder.c
42891@@ -30,6 +30,7 @@
42892 #include <linux/kernel.h>
42893 #include <linux/module.h>
42894 #include <linux/slab.h>
42895+#include <linux/sched.h>
42896 #include <linux/input.h>
42897 #include <linux/gameport.h>
42898 #include <linux/jiffies.h>
42899diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42900index 603fe0d..f63decc 100644
42901--- a/drivers/input/joystick/xpad.c
42902+++ b/drivers/input/joystick/xpad.c
42903@@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42904
42905 static int xpad_led_probe(struct usb_xpad *xpad)
42906 {
42907- static atomic_t led_seq = ATOMIC_INIT(0);
42908+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42909 long led_no;
42910 struct xpad_led *led;
42911 struct led_classdev *led_cdev;
42912@@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42913 if (!led)
42914 return -ENOMEM;
42915
42916- led_no = (long)atomic_inc_return(&led_seq) - 1;
42917+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42918
42919 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42920 led->xpad = xpad;
42921diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42922index 5a73639..d586683 100644
42923--- a/drivers/input/misc/ims-pcu.c
42924+++ b/drivers/input/misc/ims-pcu.c
42925@@ -1850,7 +1850,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42926
42927 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42928 {
42929- static atomic_t device_no = ATOMIC_INIT(0);
42930+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42931
42932 const struct ims_pcu_device_info *info;
42933 int error;
42934@@ -1881,7 +1881,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42935 }
42936
42937 /* Device appears to be operable, complete initialization */
42938- pcu->device_no = atomic_inc_return(&device_no) - 1;
42939+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42940
42941 /*
42942 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
42943diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42944index 2f0b39d..7370f13 100644
42945--- a/drivers/input/mouse/psmouse.h
42946+++ b/drivers/input/mouse/psmouse.h
42947@@ -116,7 +116,7 @@ struct psmouse_attribute {
42948 ssize_t (*set)(struct psmouse *psmouse, void *data,
42949 const char *buf, size_t count);
42950 bool protect;
42951-};
42952+} __do_const;
42953 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42954
42955 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42956diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42957index b604564..3f14ae4 100644
42958--- a/drivers/input/mousedev.c
42959+++ b/drivers/input/mousedev.c
42960@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42961
42962 spin_unlock_irq(&client->packet_lock);
42963
42964- if (copy_to_user(buffer, data, count))
42965+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
42966 return -EFAULT;
42967
42968 return count;
42969diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42970index b29134d..394deb0 100644
42971--- a/drivers/input/serio/serio.c
42972+++ b/drivers/input/serio/serio.c
42973@@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
42974 */
42975 static void serio_init_port(struct serio *serio)
42976 {
42977- static atomic_t serio_no = ATOMIC_INIT(0);
42978+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42979
42980 __module_get(THIS_MODULE);
42981
42982@@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
42983 mutex_init(&serio->drv_mutex);
42984 device_initialize(&serio->dev);
42985 dev_set_name(&serio->dev, "serio%ld",
42986- (long)atomic_inc_return(&serio_no) - 1);
42987+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
42988 serio->dev.bus = &serio_bus;
42989 serio->dev.release = serio_release_port;
42990 serio->dev.groups = serio_device_attr_groups;
42991diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42992index c9a02fe..0debc75 100644
42993--- a/drivers/input/serio/serio_raw.c
42994+++ b/drivers/input/serio/serio_raw.c
42995@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42996
42997 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42998 {
42999- static atomic_t serio_raw_no = ATOMIC_INIT(0);
43000+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43001 struct serio_raw *serio_raw;
43002 int err;
43003
43004@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43005 }
43006
43007 snprintf(serio_raw->name, sizeof(serio_raw->name),
43008- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43009+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43010 kref_init(&serio_raw->kref);
43011 INIT_LIST_HEAD(&serio_raw->client_list);
43012 init_waitqueue_head(&serio_raw->wait);
43013diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43014index e5555fc..937986d 100644
43015--- a/drivers/iommu/iommu.c
43016+++ b/drivers/iommu/iommu.c
43017@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
43018 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
43019 {
43020 bus_register_notifier(bus, &iommu_bus_nb);
43021- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43022+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43023 }
43024
43025 /**
43026diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43027index 228632c9..edfe331 100644
43028--- a/drivers/iommu/irq_remapping.c
43029+++ b/drivers/iommu/irq_remapping.c
43030@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43031 void panic_if_irq_remap(const char *msg)
43032 {
43033 if (irq_remapping_enabled)
43034- panic(msg);
43035+ panic("%s", msg);
43036 }
43037
43038 static void ir_ack_apic_edge(struct irq_data *data)
43039@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43040
43041 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43042 {
43043- chip->irq_print_chip = ir_print_prefix;
43044- chip->irq_ack = ir_ack_apic_edge;
43045- chip->irq_eoi = ir_ack_apic_level;
43046- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43047+ pax_open_kernel();
43048+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43049+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43050+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43051+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43052+ pax_close_kernel();
43053 }
43054
43055 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43056diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43057index 57d165e..611997e 100644
43058--- a/drivers/irqchip/irq-gic.c
43059+++ b/drivers/irqchip/irq-gic.c
43060@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43061 * Supported arch specific GIC irq extension.
43062 * Default make them NULL.
43063 */
43064-struct irq_chip gic_arch_extn = {
43065+irq_chip_no_const gic_arch_extn = {
43066 .irq_eoi = NULL,
43067 .irq_mask = NULL,
43068 .irq_unmask = NULL,
43069@@ -336,7 +336,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43070 chained_irq_exit(chip, desc);
43071 }
43072
43073-static struct irq_chip gic_chip = {
43074+static irq_chip_no_const gic_chip __read_only = {
43075 .name = "GIC",
43076 .irq_mask = gic_mask_irq,
43077 .irq_unmask = gic_unmask_irq,
43078diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43079index 8777065..a4a9967 100644
43080--- a/drivers/irqchip/irq-renesas-irqc.c
43081+++ b/drivers/irqchip/irq-renesas-irqc.c
43082@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43083 struct irqc_priv *p;
43084 struct resource *io;
43085 struct resource *irq;
43086- struct irq_chip *irq_chip;
43087+ irq_chip_no_const *irq_chip;
43088 const char *name = dev_name(&pdev->dev);
43089 int ret;
43090 int k;
43091diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43092index ac6f72b..81150f2 100644
43093--- a/drivers/isdn/capi/capi.c
43094+++ b/drivers/isdn/capi/capi.c
43095@@ -81,8 +81,8 @@ struct capiminor {
43096
43097 struct capi20_appl *ap;
43098 u32 ncci;
43099- atomic_t datahandle;
43100- atomic_t msgid;
43101+ atomic_unchecked_t datahandle;
43102+ atomic_unchecked_t msgid;
43103
43104 struct tty_port port;
43105 int ttyinstop;
43106@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43107 capimsg_setu16(s, 2, mp->ap->applid);
43108 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43109 capimsg_setu8 (s, 5, CAPI_RESP);
43110- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43111+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43112 capimsg_setu32(s, 8, mp->ncci);
43113 capimsg_setu16(s, 12, datahandle);
43114 }
43115@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43116 mp->outbytes -= len;
43117 spin_unlock_bh(&mp->outlock);
43118
43119- datahandle = atomic_inc_return(&mp->datahandle);
43120+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43121 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43122 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43123 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43124 capimsg_setu16(skb->data, 2, mp->ap->applid);
43125 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43126 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43127- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43128+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43129 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43130 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43131 capimsg_setu16(skb->data, 16, len); /* Data length */
43132diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43133index c44950d..10ac276 100644
43134--- a/drivers/isdn/gigaset/bas-gigaset.c
43135+++ b/drivers/isdn/gigaset/bas-gigaset.c
43136@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43137
43138
43139 static const struct gigaset_ops gigops = {
43140- gigaset_write_cmd,
43141- gigaset_write_room,
43142- gigaset_chars_in_buffer,
43143- gigaset_brkchars,
43144- gigaset_init_bchannel,
43145- gigaset_close_bchannel,
43146- gigaset_initbcshw,
43147- gigaset_freebcshw,
43148- gigaset_reinitbcshw,
43149- gigaset_initcshw,
43150- gigaset_freecshw,
43151- gigaset_set_modem_ctrl,
43152- gigaset_baud_rate,
43153- gigaset_set_line_ctrl,
43154- gigaset_isoc_send_skb,
43155- gigaset_isoc_input,
43156+ .write_cmd = gigaset_write_cmd,
43157+ .write_room = gigaset_write_room,
43158+ .chars_in_buffer = gigaset_chars_in_buffer,
43159+ .brkchars = gigaset_brkchars,
43160+ .init_bchannel = gigaset_init_bchannel,
43161+ .close_bchannel = gigaset_close_bchannel,
43162+ .initbcshw = gigaset_initbcshw,
43163+ .freebcshw = gigaset_freebcshw,
43164+ .reinitbcshw = gigaset_reinitbcshw,
43165+ .initcshw = gigaset_initcshw,
43166+ .freecshw = gigaset_freecshw,
43167+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43168+ .baud_rate = gigaset_baud_rate,
43169+ .set_line_ctrl = gigaset_set_line_ctrl,
43170+ .send_skb = gigaset_isoc_send_skb,
43171+ .handle_input = gigaset_isoc_input,
43172 };
43173
43174 /* bas_gigaset_init
43175diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43176index 600c79b..3752bab 100644
43177--- a/drivers/isdn/gigaset/interface.c
43178+++ b/drivers/isdn/gigaset/interface.c
43179@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43180 }
43181 tty->driver_data = cs;
43182
43183- ++cs->port.count;
43184+ atomic_inc(&cs->port.count);
43185
43186- if (cs->port.count == 1) {
43187+ if (atomic_read(&cs->port.count) == 1) {
43188 tty_port_tty_set(&cs->port, tty);
43189 cs->port.low_latency = 1;
43190 }
43191@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43192
43193 if (!cs->connected)
43194 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43195- else if (!cs->port.count)
43196+ else if (!atomic_read(&cs->port.count))
43197 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43198- else if (!--cs->port.count)
43199+ else if (!atomic_dec_return(&cs->port.count))
43200 tty_port_tty_set(&cs->port, NULL);
43201
43202 mutex_unlock(&cs->mutex);
43203diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43204index 8c91fd5..14f13ce 100644
43205--- a/drivers/isdn/gigaset/ser-gigaset.c
43206+++ b/drivers/isdn/gigaset/ser-gigaset.c
43207@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43208 }
43209
43210 static const struct gigaset_ops ops = {
43211- gigaset_write_cmd,
43212- gigaset_write_room,
43213- gigaset_chars_in_buffer,
43214- gigaset_brkchars,
43215- gigaset_init_bchannel,
43216- gigaset_close_bchannel,
43217- gigaset_initbcshw,
43218- gigaset_freebcshw,
43219- gigaset_reinitbcshw,
43220- gigaset_initcshw,
43221- gigaset_freecshw,
43222- gigaset_set_modem_ctrl,
43223- gigaset_baud_rate,
43224- gigaset_set_line_ctrl,
43225- gigaset_m10x_send_skb, /* asyncdata.c */
43226- gigaset_m10x_input, /* asyncdata.c */
43227+ .write_cmd = gigaset_write_cmd,
43228+ .write_room = gigaset_write_room,
43229+ .chars_in_buffer = gigaset_chars_in_buffer,
43230+ .brkchars = gigaset_brkchars,
43231+ .init_bchannel = gigaset_init_bchannel,
43232+ .close_bchannel = gigaset_close_bchannel,
43233+ .initbcshw = gigaset_initbcshw,
43234+ .freebcshw = gigaset_freebcshw,
43235+ .reinitbcshw = gigaset_reinitbcshw,
43236+ .initcshw = gigaset_initcshw,
43237+ .freecshw = gigaset_freecshw,
43238+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43239+ .baud_rate = gigaset_baud_rate,
43240+ .set_line_ctrl = gigaset_set_line_ctrl,
43241+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43242+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43243 };
43244
43245
43246diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43247index d0a41cb..b953e50 100644
43248--- a/drivers/isdn/gigaset/usb-gigaset.c
43249+++ b/drivers/isdn/gigaset/usb-gigaset.c
43250@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43251 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43252 memcpy(cs->hw.usb->bchars, buf, 6);
43253 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43254- 0, 0, &buf, 6, 2000);
43255+ 0, 0, buf, 6, 2000);
43256 }
43257
43258 static void gigaset_freebcshw(struct bc_state *bcs)
43259@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43260 }
43261
43262 static const struct gigaset_ops ops = {
43263- gigaset_write_cmd,
43264- gigaset_write_room,
43265- gigaset_chars_in_buffer,
43266- gigaset_brkchars,
43267- gigaset_init_bchannel,
43268- gigaset_close_bchannel,
43269- gigaset_initbcshw,
43270- gigaset_freebcshw,
43271- gigaset_reinitbcshw,
43272- gigaset_initcshw,
43273- gigaset_freecshw,
43274- gigaset_set_modem_ctrl,
43275- gigaset_baud_rate,
43276- gigaset_set_line_ctrl,
43277- gigaset_m10x_send_skb,
43278- gigaset_m10x_input,
43279+ .write_cmd = gigaset_write_cmd,
43280+ .write_room = gigaset_write_room,
43281+ .chars_in_buffer = gigaset_chars_in_buffer,
43282+ .brkchars = gigaset_brkchars,
43283+ .init_bchannel = gigaset_init_bchannel,
43284+ .close_bchannel = gigaset_close_bchannel,
43285+ .initbcshw = gigaset_initbcshw,
43286+ .freebcshw = gigaset_freebcshw,
43287+ .reinitbcshw = gigaset_reinitbcshw,
43288+ .initcshw = gigaset_initcshw,
43289+ .freecshw = gigaset_freecshw,
43290+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43291+ .baud_rate = gigaset_baud_rate,
43292+ .set_line_ctrl = gigaset_set_line_ctrl,
43293+ .send_skb = gigaset_m10x_send_skb,
43294+ .handle_input = gigaset_m10x_input,
43295 };
43296
43297 /*
43298diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43299index 4d9b195..455075c 100644
43300--- a/drivers/isdn/hardware/avm/b1.c
43301+++ b/drivers/isdn/hardware/avm/b1.c
43302@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43303 }
43304 if (left) {
43305 if (t4file->user) {
43306- if (copy_from_user(buf, dp, left))
43307+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43308 return -EFAULT;
43309 } else {
43310 memcpy(buf, dp, left);
43311@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43312 }
43313 if (left) {
43314 if (config->user) {
43315- if (copy_from_user(buf, dp, left))
43316+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43317 return -EFAULT;
43318 } else {
43319 memcpy(buf, dp, left);
43320diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43321index 9b856e1..fa03c92 100644
43322--- a/drivers/isdn/i4l/isdn_common.c
43323+++ b/drivers/isdn/i4l/isdn_common.c
43324@@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43325 } else
43326 return -EINVAL;
43327 case IIOCDBGVAR:
43328+ if (!capable(CAP_SYS_RAWIO))
43329+ return -EPERM;
43330 if (arg) {
43331 if (copy_to_user(argp, &dev, sizeof(ulong)))
43332 return -EFAULT;
43333diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43334index 91d5730..336523e 100644
43335--- a/drivers/isdn/i4l/isdn_concap.c
43336+++ b/drivers/isdn/i4l/isdn_concap.c
43337@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43338 }
43339
43340 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43341- &isdn_concap_dl_data_req,
43342- &isdn_concap_dl_connect_req,
43343- &isdn_concap_dl_disconn_req
43344+ .data_req = &isdn_concap_dl_data_req,
43345+ .connect_req = &isdn_concap_dl_connect_req,
43346+ .disconn_req = &isdn_concap_dl_disconn_req
43347 };
43348
43349 /* The following should better go into a dedicated source file such that
43350diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43351index 3c5f249..5fac4d0 100644
43352--- a/drivers/isdn/i4l/isdn_tty.c
43353+++ b/drivers/isdn/i4l/isdn_tty.c
43354@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43355
43356 #ifdef ISDN_DEBUG_MODEM_OPEN
43357 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43358- port->count);
43359+ atomic_read(&port->count));
43360 #endif
43361- port->count++;
43362+ atomic_inc(&port->count);
43363 port->tty = tty;
43364 /*
43365 * Start up serial port
43366@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43367 #endif
43368 return;
43369 }
43370- if ((tty->count == 1) && (port->count != 1)) {
43371+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43372 /*
43373 * Uh, oh. tty->count is 1, which means that the tty
43374 * structure will be freed. Info->count should always
43375@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43376 * serial port won't be shutdown.
43377 */
43378 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43379- "info->count is %d\n", port->count);
43380- port->count = 1;
43381+ "info->count is %d\n", atomic_read(&port->count));
43382+ atomic_set(&port->count, 1);
43383 }
43384- if (--port->count < 0) {
43385+ if (atomic_dec_return(&port->count) < 0) {
43386 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43387- info->line, port->count);
43388- port->count = 0;
43389+ info->line, atomic_read(&port->count));
43390+ atomic_set(&port->count, 0);
43391 }
43392- if (port->count) {
43393+ if (atomic_read(&port->count)) {
43394 #ifdef ISDN_DEBUG_MODEM_OPEN
43395 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43396 #endif
43397@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43398 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43399 return;
43400 isdn_tty_shutdown(info);
43401- port->count = 0;
43402+ atomic_set(&port->count, 0);
43403 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43404 port->tty = NULL;
43405 wake_up_interruptible(&port->open_wait);
43406@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43407 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43408 modem_info *info = &dev->mdm.info[i];
43409
43410- if (info->port.count == 0)
43411+ if (atomic_read(&info->port.count) == 0)
43412 continue;
43413 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43414 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43415diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43416index e2d4e58..40cd045 100644
43417--- a/drivers/isdn/i4l/isdn_x25iface.c
43418+++ b/drivers/isdn/i4l/isdn_x25iface.c
43419@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43420
43421
43422 static struct concap_proto_ops ix25_pops = {
43423- &isdn_x25iface_proto_new,
43424- &isdn_x25iface_proto_del,
43425- &isdn_x25iface_proto_restart,
43426- &isdn_x25iface_proto_close,
43427- &isdn_x25iface_xmit,
43428- &isdn_x25iface_receive,
43429- &isdn_x25iface_connect_ind,
43430- &isdn_x25iface_disconn_ind
43431+ .proto_new = &isdn_x25iface_proto_new,
43432+ .proto_del = &isdn_x25iface_proto_del,
43433+ .restart = &isdn_x25iface_proto_restart,
43434+ .close = &isdn_x25iface_proto_close,
43435+ .encap_and_xmit = &isdn_x25iface_xmit,
43436+ .data_ind = &isdn_x25iface_receive,
43437+ .connect_ind = &isdn_x25iface_connect_ind,
43438+ .disconn_ind = &isdn_x25iface_disconn_ind
43439 };
43440
43441 /* error message helper function */
43442diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43443index 6a7447c..cae33fe 100644
43444--- a/drivers/isdn/icn/icn.c
43445+++ b/drivers/isdn/icn/icn.c
43446@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43447 if (count > len)
43448 count = len;
43449 if (user) {
43450- if (copy_from_user(msg, buf, count))
43451+ if (count > sizeof msg || copy_from_user(msg, buf, count))
43452 return -EFAULT;
43453 } else
43454 memcpy(msg, buf, count);
43455diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43456index a4f05c5..1433bc5 100644
43457--- a/drivers/isdn/mISDN/dsp_cmx.c
43458+++ b/drivers/isdn/mISDN/dsp_cmx.c
43459@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43460 static u16 dsp_count; /* last sample count */
43461 static int dsp_count_valid; /* if we have last sample count */
43462
43463-void
43464+void __intentional_overflow(-1)
43465 dsp_cmx_send(void *arg)
43466 {
43467 struct dsp_conf *conf;
43468diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43469index f58a354..fbae176 100644
43470--- a/drivers/leds/leds-clevo-mail.c
43471+++ b/drivers/leds/leds-clevo-mail.c
43472@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43473 * detected as working, but in reality it is not) as low as
43474 * possible.
43475 */
43476-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43477+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43478 {
43479 .callback = clevo_mail_led_dmi_callback,
43480 .ident = "Clevo D410J",
43481diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43482index 2eb3ef6..295891f 100644
43483--- a/drivers/leds/leds-ss4200.c
43484+++ b/drivers/leds/leds-ss4200.c
43485@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43486 * detected as working, but in reality it is not) as low as
43487 * possible.
43488 */
43489-static struct dmi_system_id nas_led_whitelist[] __initdata = {
43490+static struct dmi_system_id nas_led_whitelist[] __initconst = {
43491 {
43492 .callback = ss4200_led_dmi_callback,
43493 .ident = "Intel SS4200-E",
43494diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43495index 0bf1e4e..b4bf44e 100644
43496--- a/drivers/lguest/core.c
43497+++ b/drivers/lguest/core.c
43498@@ -97,9 +97,17 @@ static __init int map_switcher(void)
43499 * The end address needs +1 because __get_vm_area allocates an
43500 * extra guard page, so we need space for that.
43501 */
43502+
43503+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43504+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43505+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43506+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43507+#else
43508 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43509 VM_ALLOC, switcher_addr, switcher_addr
43510 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43511+#endif
43512+
43513 if (!switcher_vma) {
43514 err = -ENOMEM;
43515 printk("lguest: could not map switcher pages high\n");
43516@@ -124,7 +132,7 @@ static __init int map_switcher(void)
43517 * Now the Switcher is mapped at the right address, we can't fail!
43518 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43519 */
43520- memcpy(switcher_vma->addr, start_switcher_text,
43521+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43522 end_switcher_text - start_switcher_text);
43523
43524 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43525diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43526index e8b55c3..3514c37 100644
43527--- a/drivers/lguest/page_tables.c
43528+++ b/drivers/lguest/page_tables.c
43529@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43530 /*:*/
43531
43532 #ifdef CONFIG_X86_PAE
43533-static void release_pmd(pmd_t *spmd)
43534+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43535 {
43536 /* If the entry's not present, there's nothing to release. */
43537 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43538diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43539index 922a1ac..9dd0c2a 100644
43540--- a/drivers/lguest/x86/core.c
43541+++ b/drivers/lguest/x86/core.c
43542@@ -59,7 +59,7 @@ static struct {
43543 /* Offset from where switcher.S was compiled to where we've copied it */
43544 static unsigned long switcher_offset(void)
43545 {
43546- return switcher_addr - (unsigned long)start_switcher_text;
43547+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43548 }
43549
43550 /* This cpu's struct lguest_pages (after the Switcher text page) */
43551@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43552 * These copies are pretty cheap, so we do them unconditionally: */
43553 /* Save the current Host top-level page directory.
43554 */
43555+
43556+#ifdef CONFIG_PAX_PER_CPU_PGD
43557+ pages->state.host_cr3 = read_cr3();
43558+#else
43559 pages->state.host_cr3 = __pa(current->mm->pgd);
43560+#endif
43561+
43562 /*
43563 * Set up the Guest's page tables to see this CPU's pages (and no
43564 * other CPU's pages).
43565@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43566 * compiled-in switcher code and the high-mapped copy we just made.
43567 */
43568 for (i = 0; i < IDT_ENTRIES; i++)
43569- default_idt_entries[i] += switcher_offset();
43570+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43571
43572 /*
43573 * Set up the Switcher's per-cpu areas.
43574@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43575 * it will be undisturbed when we switch. To change %cs and jump we
43576 * need this structure to feed to Intel's "lcall" instruction.
43577 */
43578- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43579+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43580 lguest_entry.segment = LGUEST_CS;
43581
43582 /*
43583diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43584index 40634b0..4f5855e 100644
43585--- a/drivers/lguest/x86/switcher_32.S
43586+++ b/drivers/lguest/x86/switcher_32.S
43587@@ -87,6 +87,7 @@
43588 #include <asm/page.h>
43589 #include <asm/segment.h>
43590 #include <asm/lguest.h>
43591+#include <asm/processor-flags.h>
43592
43593 // We mark the start of the code to copy
43594 // It's placed in .text tho it's never run here
43595@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43596 // Changes type when we load it: damn Intel!
43597 // For after we switch over our page tables
43598 // That entry will be read-only: we'd crash.
43599+
43600+#ifdef CONFIG_PAX_KERNEXEC
43601+ mov %cr0, %edx
43602+ xor $X86_CR0_WP, %edx
43603+ mov %edx, %cr0
43604+#endif
43605+
43606 movl $(GDT_ENTRY_TSS*8), %edx
43607 ltr %dx
43608
43609@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43610 // Let's clear it again for our return.
43611 // The GDT descriptor of the Host
43612 // Points to the table after two "size" bytes
43613- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43614+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43615 // Clear "used" from type field (byte 5, bit 2)
43616- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43617+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43618+
43619+#ifdef CONFIG_PAX_KERNEXEC
43620+ mov %cr0, %eax
43621+ xor $X86_CR0_WP, %eax
43622+ mov %eax, %cr0
43623+#endif
43624
43625 // Once our page table's switched, the Guest is live!
43626 // The Host fades as we run this final step.
43627@@ -295,13 +309,12 @@ deliver_to_host:
43628 // I consulted gcc, and it gave
43629 // These instructions, which I gladly credit:
43630 leal (%edx,%ebx,8), %eax
43631- movzwl (%eax),%edx
43632- movl 4(%eax), %eax
43633- xorw %ax, %ax
43634- orl %eax, %edx
43635+ movl 4(%eax), %edx
43636+ movw (%eax), %dx
43637 // Now the address of the handler's in %edx
43638 // We call it now: its "iret" drops us home.
43639- jmp *%edx
43640+ ljmp $__KERNEL_CS, $1f
43641+1: jmp *%edx
43642
43643 // Every interrupt can come to us here
43644 // But we must truly tell each apart.
43645diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43646index 7ef7461..5a09dac 100644
43647--- a/drivers/md/bcache/closure.h
43648+++ b/drivers/md/bcache/closure.h
43649@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43650 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43651 struct workqueue_struct *wq)
43652 {
43653- BUG_ON(object_is_on_stack(cl));
43654+ BUG_ON(object_starts_on_stack(cl));
43655 closure_set_ip(cl);
43656 cl->fn = fn;
43657 cl->wq = wq;
43658diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43659index 9a8e66a..10cc762 100644
43660--- a/drivers/md/bitmap.c
43661+++ b/drivers/md/bitmap.c
43662@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43663 chunk_kb ? "KB" : "B");
43664 if (bitmap->storage.file) {
43665 seq_printf(seq, ", file: ");
43666- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43667+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43668 }
43669
43670 seq_printf(seq, "\n");
43671diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43672index 5152142..623d141 100644
43673--- a/drivers/md/dm-ioctl.c
43674+++ b/drivers/md/dm-ioctl.c
43675@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43676 cmd == DM_LIST_VERSIONS_CMD)
43677 return 0;
43678
43679- if ((cmd == DM_DEV_CREATE_CMD)) {
43680+ if (cmd == DM_DEV_CREATE_CMD) {
43681 if (!*param->name) {
43682 DMWARN("name not supplied when creating device");
43683 return -EINVAL;
43684diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43685index 7dfdb5c..4caada6 100644
43686--- a/drivers/md/dm-raid1.c
43687+++ b/drivers/md/dm-raid1.c
43688@@ -40,7 +40,7 @@ enum dm_raid1_error {
43689
43690 struct mirror {
43691 struct mirror_set *ms;
43692- atomic_t error_count;
43693+ atomic_unchecked_t error_count;
43694 unsigned long error_type;
43695 struct dm_dev *dev;
43696 sector_t offset;
43697@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43698 struct mirror *m;
43699
43700 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43701- if (!atomic_read(&m->error_count))
43702+ if (!atomic_read_unchecked(&m->error_count))
43703 return m;
43704
43705 return NULL;
43706@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43707 * simple way to tell if a device has encountered
43708 * errors.
43709 */
43710- atomic_inc(&m->error_count);
43711+ atomic_inc_unchecked(&m->error_count);
43712
43713 if (test_and_set_bit(error_type, &m->error_type))
43714 return;
43715@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43716 struct mirror *m = get_default_mirror(ms);
43717
43718 do {
43719- if (likely(!atomic_read(&m->error_count)))
43720+ if (likely(!atomic_read_unchecked(&m->error_count)))
43721 return m;
43722
43723 if (m-- == ms->mirror)
43724@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43725 {
43726 struct mirror *default_mirror = get_default_mirror(m->ms);
43727
43728- return !atomic_read(&default_mirror->error_count);
43729+ return !atomic_read_unchecked(&default_mirror->error_count);
43730 }
43731
43732 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43733@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43734 */
43735 if (likely(region_in_sync(ms, region, 1)))
43736 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43737- else if (m && atomic_read(&m->error_count))
43738+ else if (m && atomic_read_unchecked(&m->error_count))
43739 m = NULL;
43740
43741 if (likely(m))
43742@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43743 }
43744
43745 ms->mirror[mirror].ms = ms;
43746- atomic_set(&(ms->mirror[mirror].error_count), 0);
43747+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43748 ms->mirror[mirror].error_type = 0;
43749 ms->mirror[mirror].offset = offset;
43750
43751@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43752 */
43753 static char device_status_char(struct mirror *m)
43754 {
43755- if (!atomic_read(&(m->error_count)))
43756+ if (!atomic_read_unchecked(&(m->error_count)))
43757 return 'A';
43758
43759 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43760diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43761index 28a9012..9c0f6a5 100644
43762--- a/drivers/md/dm-stats.c
43763+++ b/drivers/md/dm-stats.c
43764@@ -382,7 +382,7 @@ do_sync_free:
43765 synchronize_rcu_expedited();
43766 dm_stat_free(&s->rcu_head);
43767 } else {
43768- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43769+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43770 call_rcu(&s->rcu_head, dm_stat_free);
43771 }
43772 return 0;
43773@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43774 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43775 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43776 ));
43777- ACCESS_ONCE(last->last_sector) = end_sector;
43778- ACCESS_ONCE(last->last_rw) = bi_rw;
43779+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
43780+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43781 }
43782
43783 rcu_read_lock();
43784diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43785index d1600d2..4c3af3a 100644
43786--- a/drivers/md/dm-stripe.c
43787+++ b/drivers/md/dm-stripe.c
43788@@ -21,7 +21,7 @@ struct stripe {
43789 struct dm_dev *dev;
43790 sector_t physical_start;
43791
43792- atomic_t error_count;
43793+ atomic_unchecked_t error_count;
43794 };
43795
43796 struct stripe_c {
43797@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43798 kfree(sc);
43799 return r;
43800 }
43801- atomic_set(&(sc->stripe[i].error_count), 0);
43802+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43803 }
43804
43805 ti->private = sc;
43806@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43807 DMEMIT("%d ", sc->stripes);
43808 for (i = 0; i < sc->stripes; i++) {
43809 DMEMIT("%s ", sc->stripe[i].dev->name);
43810- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43811+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43812 'D' : 'A';
43813 }
43814 buffer[i] = '\0';
43815@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43816 */
43817 for (i = 0; i < sc->stripes; i++)
43818 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43819- atomic_inc(&(sc->stripe[i].error_count));
43820- if (atomic_read(&(sc->stripe[i].error_count)) <
43821+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
43822+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43823 DM_IO_ERROR_THRESHOLD)
43824 schedule_work(&sc->trigger_event);
43825 }
43826diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43827index 50601ec..6d3b9dc 100644
43828--- a/drivers/md/dm-table.c
43829+++ b/drivers/md/dm-table.c
43830@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43831 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43832 struct mapped_device *md)
43833 {
43834- static char *_claim_ptr = "I belong to device-mapper";
43835+ static char _claim_ptr[] = "I belong to device-mapper";
43836 struct block_device *bdev;
43837
43838 int r;
43839@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43840 if (!dev_size)
43841 return 0;
43842
43843- if ((start >= dev_size) || (start + len > dev_size)) {
43844+ if ((start >= dev_size) || (len > dev_size - start)) {
43845 DMWARN("%s: %s too small for target: "
43846 "start=%llu, len=%llu, dev_size=%llu",
43847 dm_device_name(ti->table->md), bdevname(bdev, b),
43848diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43849index b086a94..74cb67e 100644
43850--- a/drivers/md/dm-thin-metadata.c
43851+++ b/drivers/md/dm-thin-metadata.c
43852@@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43853 {
43854 pmd->info.tm = pmd->tm;
43855 pmd->info.levels = 2;
43856- pmd->info.value_type.context = pmd->data_sm;
43857+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43858 pmd->info.value_type.size = sizeof(__le64);
43859 pmd->info.value_type.inc = data_block_inc;
43860 pmd->info.value_type.dec = data_block_dec;
43861@@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43862
43863 pmd->bl_info.tm = pmd->tm;
43864 pmd->bl_info.levels = 1;
43865- pmd->bl_info.value_type.context = pmd->data_sm;
43866+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43867 pmd->bl_info.value_type.size = sizeof(__le64);
43868 pmd->bl_info.value_type.inc = data_block_inc;
43869 pmd->bl_info.value_type.dec = data_block_dec;
43870diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43871index 455e649..1f214be 100644
43872--- a/drivers/md/dm.c
43873+++ b/drivers/md/dm.c
43874@@ -178,9 +178,9 @@ struct mapped_device {
43875 /*
43876 * Event handling.
43877 */
43878- atomic_t event_nr;
43879+ atomic_unchecked_t event_nr;
43880 wait_queue_head_t eventq;
43881- atomic_t uevent_seq;
43882+ atomic_unchecked_t uevent_seq;
43883 struct list_head uevent_list;
43884 spinlock_t uevent_lock; /* Protect access to uevent_list */
43885
43886@@ -1884,8 +1884,8 @@ static struct mapped_device *alloc_dev(int minor)
43887 spin_lock_init(&md->deferred_lock);
43888 atomic_set(&md->holders, 1);
43889 atomic_set(&md->open_count, 0);
43890- atomic_set(&md->event_nr, 0);
43891- atomic_set(&md->uevent_seq, 0);
43892+ atomic_set_unchecked(&md->event_nr, 0);
43893+ atomic_set_unchecked(&md->uevent_seq, 0);
43894 INIT_LIST_HEAD(&md->uevent_list);
43895 spin_lock_init(&md->uevent_lock);
43896
43897@@ -2039,7 +2039,7 @@ static void event_callback(void *context)
43898
43899 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43900
43901- atomic_inc(&md->event_nr);
43902+ atomic_inc_unchecked(&md->event_nr);
43903 wake_up(&md->eventq);
43904 }
43905
43906@@ -2732,18 +2732,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43907
43908 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43909 {
43910- return atomic_add_return(1, &md->uevent_seq);
43911+ return atomic_add_return_unchecked(1, &md->uevent_seq);
43912 }
43913
43914 uint32_t dm_get_event_nr(struct mapped_device *md)
43915 {
43916- return atomic_read(&md->event_nr);
43917+ return atomic_read_unchecked(&md->event_nr);
43918 }
43919
43920 int dm_wait_event(struct mapped_device *md, int event_nr)
43921 {
43922 return wait_event_interruptible(md->eventq,
43923- (event_nr != atomic_read(&md->event_nr)));
43924+ (event_nr != atomic_read_unchecked(&md->event_nr)));
43925 }
43926
43927 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43928diff --git a/drivers/md/md.c b/drivers/md/md.c
43929index 9a18209..ec4d3ec 100644
43930--- a/drivers/md/md.c
43931+++ b/drivers/md/md.c
43932@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43933 * start build, activate spare
43934 */
43935 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43936-static atomic_t md_event_count;
43937+static atomic_unchecked_t md_event_count;
43938 void md_new_event(struct mddev *mddev)
43939 {
43940- atomic_inc(&md_event_count);
43941+ atomic_inc_unchecked(&md_event_count);
43942 wake_up(&md_event_waiters);
43943 }
43944 EXPORT_SYMBOL_GPL(md_new_event);
43945@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43946 */
43947 static void md_new_event_inintr(struct mddev *mddev)
43948 {
43949- atomic_inc(&md_event_count);
43950+ atomic_inc_unchecked(&md_event_count);
43951 wake_up(&md_event_waiters);
43952 }
43953
43954@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43955 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43956 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43957 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43958- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43959+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43960
43961 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43962 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43963@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43964 else
43965 sb->resync_offset = cpu_to_le64(0);
43966
43967- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43968+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43969
43970 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43971 sb->size = cpu_to_le64(mddev->dev_sectors);
43972@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43973 static ssize_t
43974 errors_show(struct md_rdev *rdev, char *page)
43975 {
43976- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43977+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43978 }
43979
43980 static ssize_t
43981@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43982 char *e;
43983 unsigned long n = simple_strtoul(buf, &e, 10);
43984 if (*buf && (*e == 0 || *e == '\n')) {
43985- atomic_set(&rdev->corrected_errors, n);
43986+ atomic_set_unchecked(&rdev->corrected_errors, n);
43987 return len;
43988 }
43989 return -EINVAL;
43990@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
43991 rdev->sb_loaded = 0;
43992 rdev->bb_page = NULL;
43993 atomic_set(&rdev->nr_pending, 0);
43994- atomic_set(&rdev->read_errors, 0);
43995- atomic_set(&rdev->corrected_errors, 0);
43996+ atomic_set_unchecked(&rdev->read_errors, 0);
43997+ atomic_set_unchecked(&rdev->corrected_errors, 0);
43998
43999 INIT_LIST_HEAD(&rdev->same_set);
44000 init_waitqueue_head(&rdev->blocked_wait);
44001@@ -7058,7 +7058,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44002
44003 spin_unlock(&pers_lock);
44004 seq_printf(seq, "\n");
44005- seq->poll_event = atomic_read(&md_event_count);
44006+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44007 return 0;
44008 }
44009 if (v == (void*)2) {
44010@@ -7161,7 +7161,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44011 return error;
44012
44013 seq = file->private_data;
44014- seq->poll_event = atomic_read(&md_event_count);
44015+ seq->poll_event = atomic_read_unchecked(&md_event_count);
44016 return error;
44017 }
44018
44019@@ -7178,7 +7178,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44020 /* always allow read */
44021 mask = POLLIN | POLLRDNORM;
44022
44023- if (seq->poll_event != atomic_read(&md_event_count))
44024+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44025 mask |= POLLERR | POLLPRI;
44026 return mask;
44027 }
44028@@ -7222,7 +7222,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44029 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44030 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44031 (int)part_stat_read(&disk->part0, sectors[1]) -
44032- atomic_read(&disk->sync_io);
44033+ atomic_read_unchecked(&disk->sync_io);
44034 /* sync IO will cause sync_io to increase before the disk_stats
44035 * as sync_io is counted when a request starts, and
44036 * disk_stats is counted when it completes.
44037diff --git a/drivers/md/md.h b/drivers/md/md.h
44038index a49d991..3582bb7 100644
44039--- a/drivers/md/md.h
44040+++ b/drivers/md/md.h
44041@@ -94,13 +94,13 @@ struct md_rdev {
44042 * only maintained for arrays that
44043 * support hot removal
44044 */
44045- atomic_t read_errors; /* number of consecutive read errors that
44046+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44047 * we have tried to ignore.
44048 */
44049 struct timespec last_read_error; /* monotonic time since our
44050 * last read error
44051 */
44052- atomic_t corrected_errors; /* number of corrected read errors,
44053+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44054 * for reporting to userspace and storing
44055 * in superblock.
44056 */
44057@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44058
44059 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44060 {
44061- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44062+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44063 }
44064
44065 struct md_personality
44066diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44067index 786b689..ea8c956 100644
44068--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44069+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44070@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44071 * Flick into a mode where all blocks get allocated in the new area.
44072 */
44073 smm->begin = old_len;
44074- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44075+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44076
44077 /*
44078 * Extend.
44079@@ -710,7 +710,7 @@ out:
44080 /*
44081 * Switch back to normal behaviour.
44082 */
44083- memcpy(sm, &ops, sizeof(*sm));
44084+ memcpy((void *)sm, &ops, sizeof(*sm));
44085 return r;
44086 }
44087
44088diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44089index 3e6d115..ffecdeb 100644
44090--- a/drivers/md/persistent-data/dm-space-map.h
44091+++ b/drivers/md/persistent-data/dm-space-map.h
44092@@ -71,6 +71,7 @@ struct dm_space_map {
44093 dm_sm_threshold_fn fn,
44094 void *context);
44095 };
44096+typedef struct dm_space_map __no_const dm_space_map_no_const;
44097
44098 /*----------------------------------------------------------------*/
44099
44100diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44101index 56e24c0..e1c8e1f 100644
44102--- a/drivers/md/raid1.c
44103+++ b/drivers/md/raid1.c
44104@@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44105 if (r1_sync_page_io(rdev, sect, s,
44106 bio->bi_io_vec[idx].bv_page,
44107 READ) != 0)
44108- atomic_add(s, &rdev->corrected_errors);
44109+ atomic_add_unchecked(s, &rdev->corrected_errors);
44110 }
44111 sectors -= s;
44112 sect += s;
44113@@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44114 test_bit(In_sync, &rdev->flags)) {
44115 if (r1_sync_page_io(rdev, sect, s,
44116 conf->tmppage, READ)) {
44117- atomic_add(s, &rdev->corrected_errors);
44118+ atomic_add_unchecked(s, &rdev->corrected_errors);
44119 printk(KERN_INFO
44120 "md/raid1:%s: read error corrected "
44121 "(%d sectors at %llu on %s)\n",
44122diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44123index cb882aa..9bd076e 100644
44124--- a/drivers/md/raid10.c
44125+++ b/drivers/md/raid10.c
44126@@ -1949,7 +1949,7 @@ static void end_sync_read(struct bio *bio, int error)
44127 /* The write handler will notice the lack of
44128 * R10BIO_Uptodate and record any errors etc
44129 */
44130- atomic_add(r10_bio->sectors,
44131+ atomic_add_unchecked(r10_bio->sectors,
44132 &conf->mirrors[d].rdev->corrected_errors);
44133
44134 /* for reconstruct, we always reschedule after a read.
44135@@ -2307,7 +2307,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44136 {
44137 struct timespec cur_time_mon;
44138 unsigned long hours_since_last;
44139- unsigned int read_errors = atomic_read(&rdev->read_errors);
44140+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44141
44142 ktime_get_ts(&cur_time_mon);
44143
44144@@ -2329,9 +2329,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44145 * overflowing the shift of read_errors by hours_since_last.
44146 */
44147 if (hours_since_last >= 8 * sizeof(read_errors))
44148- atomic_set(&rdev->read_errors, 0);
44149+ atomic_set_unchecked(&rdev->read_errors, 0);
44150 else
44151- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44152+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44153 }
44154
44155 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44156@@ -2385,8 +2385,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44157 return;
44158
44159 check_decay_read_errors(mddev, rdev);
44160- atomic_inc(&rdev->read_errors);
44161- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44162+ atomic_inc_unchecked(&rdev->read_errors);
44163+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44164 char b[BDEVNAME_SIZE];
44165 bdevname(rdev->bdev, b);
44166
44167@@ -2394,7 +2394,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44168 "md/raid10:%s: %s: Raid device exceeded "
44169 "read_error threshold [cur %d:max %d]\n",
44170 mdname(mddev), b,
44171- atomic_read(&rdev->read_errors), max_read_errors);
44172+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44173 printk(KERN_NOTICE
44174 "md/raid10:%s: %s: Failing raid device\n",
44175 mdname(mddev), b);
44176@@ -2549,7 +2549,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44177 sect +
44178 choose_data_offset(r10_bio, rdev)),
44179 bdevname(rdev->bdev, b));
44180- atomic_add(s, &rdev->corrected_errors);
44181+ atomic_add_unchecked(s, &rdev->corrected_errors);
44182 }
44183
44184 rdev_dec_pending(rdev, mddev);
44185diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44186index ad1b9be..b417412 100644
44187--- a/drivers/md/raid5.c
44188+++ b/drivers/md/raid5.c
44189@@ -1702,6 +1702,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44190 return 1;
44191 }
44192
44193+#ifdef CONFIG_GRKERNSEC_HIDESYM
44194+static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44195+#endif
44196+
44197 static int grow_stripes(struct r5conf *conf, int num)
44198 {
44199 struct kmem_cache *sc;
44200@@ -1713,7 +1717,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44201 "raid%d-%s", conf->level, mdname(conf->mddev));
44202 else
44203 sprintf(conf->cache_name[0],
44204+#ifdef CONFIG_GRKERNSEC_HIDESYM
44205+ "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44206+#else
44207 "raid%d-%p", conf->level, conf->mddev);
44208+#endif
44209 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44210
44211 conf->active_name = 0;
44212@@ -1986,21 +1994,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44213 mdname(conf->mddev), STRIPE_SECTORS,
44214 (unsigned long long)s,
44215 bdevname(rdev->bdev, b));
44216- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44217+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44218 clear_bit(R5_ReadError, &sh->dev[i].flags);
44219 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44220 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44221 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44222
44223- if (atomic_read(&rdev->read_errors))
44224- atomic_set(&rdev->read_errors, 0);
44225+ if (atomic_read_unchecked(&rdev->read_errors))
44226+ atomic_set_unchecked(&rdev->read_errors, 0);
44227 } else {
44228 const char *bdn = bdevname(rdev->bdev, b);
44229 int retry = 0;
44230 int set_bad = 0;
44231
44232 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44233- atomic_inc(&rdev->read_errors);
44234+ atomic_inc_unchecked(&rdev->read_errors);
44235 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44236 printk_ratelimited(
44237 KERN_WARNING
44238@@ -2028,7 +2036,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44239 mdname(conf->mddev),
44240 (unsigned long long)s,
44241 bdn);
44242- } else if (atomic_read(&rdev->read_errors)
44243+ } else if (atomic_read_unchecked(&rdev->read_errors)
44244 > conf->max_nr_stripes)
44245 printk(KERN_WARNING
44246 "md/raid:%s: Too many read errors, failing device %s.\n",
44247diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44248index 983db75..ef9248c 100644
44249--- a/drivers/media/dvb-core/dvbdev.c
44250+++ b/drivers/media/dvb-core/dvbdev.c
44251@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44252 const struct dvb_device *template, void *priv, int type)
44253 {
44254 struct dvb_device *dvbdev;
44255- struct file_operations *dvbdevfops;
44256+ file_operations_no_const *dvbdevfops;
44257 struct device *clsdev;
44258 int minor;
44259 int id;
44260diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
44261index 539f4db..cdd403b 100644
44262--- a/drivers/media/dvb-frontends/af9033.h
44263+++ b/drivers/media/dvb-frontends/af9033.h
44264@@ -82,7 +82,7 @@ struct af9033_ops {
44265 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
44266 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
44267 int onoff);
44268-};
44269+} __no_const;
44270
44271
44272 #if IS_ENABLED(CONFIG_DVB_AF9033)
44273diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44274index 9b6c3bb..baeb5c7 100644
44275--- a/drivers/media/dvb-frontends/dib3000.h
44276+++ b/drivers/media/dvb-frontends/dib3000.h
44277@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44278 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44279 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44280 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44281-};
44282+} __no_const;
44283
44284 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44285 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44286diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44287index ed8cb90..5ef7f79 100644
44288--- a/drivers/media/pci/cx88/cx88-video.c
44289+++ b/drivers/media/pci/cx88/cx88-video.c
44290@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44291
44292 /* ------------------------------------------------------------------ */
44293
44294-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44295-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44296-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44297+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44298+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44299+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44300
44301 module_param_array(video_nr, int, NULL, 0444);
44302 module_param_array(vbi_nr, int, NULL, 0444);
44303diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44304index 802642d..5534900 100644
44305--- a/drivers/media/pci/ivtv/ivtv-driver.c
44306+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44307@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44308 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44309
44310 /* ivtv instance counter */
44311-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44312+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44313
44314 /* Parameter declarations */
44315 static int cardtype[IVTV_MAX_CARDS];
44316diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44317index 9a726ea..f5e9b52 100644
44318--- a/drivers/media/platform/omap/omap_vout.c
44319+++ b/drivers/media/platform/omap/omap_vout.c
44320@@ -63,7 +63,6 @@ enum omap_vout_channels {
44321 OMAP_VIDEO2,
44322 };
44323
44324-static struct videobuf_queue_ops video_vbq_ops;
44325 /* Variables configurable through module params*/
44326 static u32 video1_numbuffers = 3;
44327 static u32 video2_numbuffers = 3;
44328@@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
44329 {
44330 struct videobuf_queue *q;
44331 struct omap_vout_device *vout = NULL;
44332+ static struct videobuf_queue_ops video_vbq_ops = {
44333+ .buf_setup = omap_vout_buffer_setup,
44334+ .buf_prepare = omap_vout_buffer_prepare,
44335+ .buf_release = omap_vout_buffer_release,
44336+ .buf_queue = omap_vout_buffer_queue,
44337+ };
44338
44339 vout = video_drvdata(file);
44340 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44341@@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
44342 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44343
44344 q = &vout->vbq;
44345- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44346- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44347- video_vbq_ops.buf_release = omap_vout_buffer_release;
44348- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44349 spin_lock_init(&vout->vbq_lock);
44350
44351 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44352diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44353index fb2acc5..a2fcbdc4 100644
44354--- a/drivers/media/platform/s5p-tv/mixer.h
44355+++ b/drivers/media/platform/s5p-tv/mixer.h
44356@@ -156,7 +156,7 @@ struct mxr_layer {
44357 /** layer index (unique identifier) */
44358 int idx;
44359 /** callbacks for layer methods */
44360- struct mxr_layer_ops ops;
44361+ struct mxr_layer_ops *ops;
44362 /** format array */
44363 const struct mxr_format **fmt_array;
44364 /** size of format array */
44365diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44366index 74344c7..a39e70e 100644
44367--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44368+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44369@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44370 {
44371 struct mxr_layer *layer;
44372 int ret;
44373- struct mxr_layer_ops ops = {
44374+ static struct mxr_layer_ops ops = {
44375 .release = mxr_graph_layer_release,
44376 .buffer_set = mxr_graph_buffer_set,
44377 .stream_set = mxr_graph_stream_set,
44378diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44379index b713403..53cb5ad 100644
44380--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44381+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44382@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44383 layer->update_buf = next;
44384 }
44385
44386- layer->ops.buffer_set(layer, layer->update_buf);
44387+ layer->ops->buffer_set(layer, layer->update_buf);
44388
44389 if (done && done != layer->shadow_buf)
44390 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44391diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44392index a1ce55f..4a3c4d9 100644
44393--- a/drivers/media/platform/s5p-tv/mixer_video.c
44394+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44395@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44396 layer->geo.src.height = layer->geo.src.full_height;
44397
44398 mxr_geometry_dump(mdev, &layer->geo);
44399- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44400+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44401 mxr_geometry_dump(mdev, &layer->geo);
44402 }
44403
44404@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44405 layer->geo.dst.full_width = mbus_fmt.width;
44406 layer->geo.dst.full_height = mbus_fmt.height;
44407 layer->geo.dst.field = mbus_fmt.field;
44408- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44409+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44410
44411 mxr_geometry_dump(mdev, &layer->geo);
44412 }
44413@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44414 /* set source size to highest accepted value */
44415 geo->src.full_width = max(geo->dst.full_width, pix->width);
44416 geo->src.full_height = max(geo->dst.full_height, pix->height);
44417- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44418+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44419 mxr_geometry_dump(mdev, &layer->geo);
44420 /* set cropping to total visible screen */
44421 geo->src.width = pix->width;
44422@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44423 geo->src.x_offset = 0;
44424 geo->src.y_offset = 0;
44425 /* assure consistency of geometry */
44426- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44427+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44428 mxr_geometry_dump(mdev, &layer->geo);
44429 /* set full size to lowest possible value */
44430 geo->src.full_width = 0;
44431 geo->src.full_height = 0;
44432- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44433+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44434 mxr_geometry_dump(mdev, &layer->geo);
44435
44436 /* returning results */
44437@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44438 target->width = s->r.width;
44439 target->height = s->r.height;
44440
44441- layer->ops.fix_geometry(layer, stage, s->flags);
44442+ layer->ops->fix_geometry(layer, stage, s->flags);
44443
44444 /* retrieve update selection rectangle */
44445 res.left = target->x_offset;
44446@@ -950,13 +950,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44447 mxr_output_get(mdev);
44448
44449 mxr_layer_update_output(layer);
44450- layer->ops.format_set(layer);
44451+ layer->ops->format_set(layer);
44452 /* enabling layer in hardware */
44453 spin_lock_irqsave(&layer->enq_slock, flags);
44454 layer->state = MXR_LAYER_STREAMING;
44455 spin_unlock_irqrestore(&layer->enq_slock, flags);
44456
44457- layer->ops.stream_set(layer, MXR_ENABLE);
44458+ layer->ops->stream_set(layer, MXR_ENABLE);
44459 mxr_streamer_get(mdev);
44460
44461 return 0;
44462@@ -1026,7 +1026,7 @@ static int stop_streaming(struct vb2_queue *vq)
44463 spin_unlock_irqrestore(&layer->enq_slock, flags);
44464
44465 /* disabling layer in hardware */
44466- layer->ops.stream_set(layer, MXR_DISABLE);
44467+ layer->ops->stream_set(layer, MXR_DISABLE);
44468 /* remove one streamer */
44469 mxr_streamer_put(mdev);
44470 /* allow changes in output configuration */
44471@@ -1065,8 +1065,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44472
44473 void mxr_layer_release(struct mxr_layer *layer)
44474 {
44475- if (layer->ops.release)
44476- layer->ops.release(layer);
44477+ if (layer->ops->release)
44478+ layer->ops->release(layer);
44479 }
44480
44481 void mxr_base_layer_release(struct mxr_layer *layer)
44482@@ -1092,7 +1092,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44483
44484 layer->mdev = mdev;
44485 layer->idx = idx;
44486- layer->ops = *ops;
44487+ layer->ops = ops;
44488
44489 spin_lock_init(&layer->enq_slock);
44490 INIT_LIST_HEAD(&layer->enq_list);
44491diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44492index c9388c4..ce71ece 100644
44493--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44494+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44495@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44496 {
44497 struct mxr_layer *layer;
44498 int ret;
44499- struct mxr_layer_ops ops = {
44500+ static struct mxr_layer_ops ops = {
44501 .release = mxr_vp_layer_release,
44502 .buffer_set = mxr_vp_buffer_set,
44503 .stream_set = mxr_vp_stream_set,
44504diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44505index 3890f4f..b5c7511 100644
44506--- a/drivers/media/platform/vivi.c
44507+++ b/drivers/media/platform/vivi.c
44508@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44509 MODULE_LICENSE("Dual BSD/GPL");
44510 MODULE_VERSION(VIVI_VERSION);
44511
44512-static unsigned video_nr = -1;
44513-module_param(video_nr, uint, 0644);
44514+static int video_nr = -1;
44515+module_param(video_nr, int, 0644);
44516 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44517
44518 static unsigned n_devs = 1;
44519diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44520index d719e59..63f3470 100644
44521--- a/drivers/media/radio/radio-cadet.c
44522+++ b/drivers/media/radio/radio-cadet.c
44523@@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44524 unsigned char readbuf[RDS_BUFFER];
44525 int i = 0;
44526
44527+ if (count > RDS_BUFFER)
44528+ return -EFAULT;
44529 mutex_lock(&dev->lock);
44530 if (dev->rdsstat == 0)
44531 cadet_start_rds(dev);
44532@@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44533 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44534 mutex_unlock(&dev->lock);
44535
44536- if (i && copy_to_user(data, readbuf, i))
44537- return -EFAULT;
44538+ if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
44539+ i = -EFAULT;
44540+
44541 return i;
44542 }
44543
44544diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44545index 5236035..c622c74 100644
44546--- a/drivers/media/radio/radio-maxiradio.c
44547+++ b/drivers/media/radio/radio-maxiradio.c
44548@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44549 /* TEA5757 pin mappings */
44550 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44551
44552-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44553+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44554
44555 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44556 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44557diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44558index 050b3bb..79f62b9 100644
44559--- a/drivers/media/radio/radio-shark.c
44560+++ b/drivers/media/radio/radio-shark.c
44561@@ -79,7 +79,7 @@ struct shark_device {
44562 u32 last_val;
44563 };
44564
44565-static atomic_t shark_instance = ATOMIC_INIT(0);
44566+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44567
44568 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44569 {
44570diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44571index 8654e0d..0608a64 100644
44572--- a/drivers/media/radio/radio-shark2.c
44573+++ b/drivers/media/radio/radio-shark2.c
44574@@ -74,7 +74,7 @@ struct shark_device {
44575 u8 *transfer_buffer;
44576 };
44577
44578-static atomic_t shark_instance = ATOMIC_INIT(0);
44579+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44580
44581 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44582 {
44583diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44584index 2fd9009..278cc1e 100644
44585--- a/drivers/media/radio/radio-si476x.c
44586+++ b/drivers/media/radio/radio-si476x.c
44587@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44588 struct si476x_radio *radio;
44589 struct v4l2_ctrl *ctrl;
44590
44591- static atomic_t instance = ATOMIC_INIT(0);
44592+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
44593
44594 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44595 if (!radio)
44596diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44597index a1c641e..3007da9 100644
44598--- a/drivers/media/usb/dvb-usb/cxusb.c
44599+++ b/drivers/media/usb/dvb-usb/cxusb.c
44600@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44601
44602 struct dib0700_adapter_state {
44603 int (*set_param_save) (struct dvb_frontend *);
44604-};
44605+} __no_const;
44606
44607 static int dib7070_set_param_override(struct dvb_frontend *fe)
44608 {
44609diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44610index ae0f56a..ec71784 100644
44611--- a/drivers/media/usb/dvb-usb/dw2102.c
44612+++ b/drivers/media/usb/dvb-usb/dw2102.c
44613@@ -118,7 +118,7 @@ struct su3000_state {
44614
44615 struct s6x0_state {
44616 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44617-};
44618+} __no_const;
44619
44620 /* debug */
44621 static int dvb_usb_dw2102_debug;
44622diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44623index 7e2411c..cef73ca 100644
44624--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44625+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44626@@ -328,7 +328,7 @@ struct v4l2_buffer32 {
44627 __u32 reserved;
44628 };
44629
44630-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44631+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44632 enum v4l2_memory memory)
44633 {
44634 void __user *up_pln;
44635@@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44636 return 0;
44637 }
44638
44639-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44640+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44641 enum v4l2_memory memory)
44642 {
44643 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44644@@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44645 * by passing a very big num_planes value */
44646 uplane = compat_alloc_user_space(num_planes *
44647 sizeof(struct v4l2_plane));
44648- kp->m.planes = uplane;
44649+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44650
44651 while (--num_planes >= 0) {
44652 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44653@@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44654 if (num_planes == 0)
44655 return 0;
44656
44657- uplane = kp->m.planes;
44658+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44659 if (get_user(p, &up->m.planes))
44660 return -EFAULT;
44661 uplane32 = compat_ptr(p);
44662@@ -552,7 +552,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44663 get_user(kp->capability, &up->capability) ||
44664 get_user(kp->flags, &up->flags))
44665 return -EFAULT;
44666- kp->base = compat_ptr(tmp);
44667+ kp->base = (void __force_kernel *)compat_ptr(tmp);
44668 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44669 return 0;
44670 }
44671@@ -658,7 +658,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44672 n * sizeof(struct v4l2_ext_control32)))
44673 return -EFAULT;
44674 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44675- kp->controls = kcontrols;
44676+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44677 while (--n >= 0) {
44678 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44679 return -EFAULT;
44680@@ -680,7 +680,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44681 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44682 {
44683 struct v4l2_ext_control32 __user *ucontrols;
44684- struct v4l2_ext_control __user *kcontrols = kp->controls;
44685+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44686 int n = kp->count;
44687 compat_caddr_t p;
44688
44689@@ -774,7 +774,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
44690 put_user(kp->start_block, &up->start_block) ||
44691 put_user(kp->blocks, &up->blocks) ||
44692 put_user(tmp, &up->edid) ||
44693- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44694+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44695 return -EFAULT;
44696 return 0;
44697 }
44698diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44699index 55c6832..a91c7a6 100644
44700--- a/drivers/media/v4l2-core/v4l2-ctrls.c
44701+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44702@@ -1431,8 +1431,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44703 return 0;
44704
44705 case V4L2_CTRL_TYPE_STRING:
44706- len = strlen(c->string);
44707- if (len < ctrl->minimum)
44708+ len = strlen_user(c->string);
44709+ if (!len || len < ctrl->minimum)
44710 return -ERANGE;
44711 if ((len - ctrl->minimum) % ctrl->step)
44712 return -ERANGE;
44713diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44714index 02d1b63..5fd6b16 100644
44715--- a/drivers/media/v4l2-core/v4l2-device.c
44716+++ b/drivers/media/v4l2-core/v4l2-device.c
44717@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44718 EXPORT_SYMBOL_GPL(v4l2_device_put);
44719
44720 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44721- atomic_t *instance)
44722+ atomic_unchecked_t *instance)
44723 {
44724- int num = atomic_inc_return(instance) - 1;
44725+ int num = atomic_inc_return_unchecked(instance) - 1;
44726 int len = strlen(basename);
44727
44728 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44729diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44730index d9113cc..7de6ccc 100644
44731--- a/drivers/media/v4l2-core/v4l2-ioctl.c
44732+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44733@@ -2003,7 +2003,8 @@ struct v4l2_ioctl_info {
44734 struct file *file, void *fh, void *p);
44735 } u;
44736 void (*debug)(const void *arg, bool write_only);
44737-};
44738+} __do_const;
44739+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44740
44741 /* This control needs a priority check */
44742 #define INFO_FL_PRIO (1 << 0)
44743@@ -2186,7 +2187,7 @@ static long __video_do_ioctl(struct file *file,
44744 struct video_device *vfd = video_devdata(file);
44745 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44746 bool write_only = false;
44747- struct v4l2_ioctl_info default_info;
44748+ v4l2_ioctl_info_no_const default_info;
44749 const struct v4l2_ioctl_info *info;
44750 void *fh = file->private_data;
44751 struct v4l2_fh *vfh = NULL;
44752@@ -2260,7 +2261,7 @@ done:
44753 }
44754
44755 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44756- void * __user *user_ptr, void ***kernel_ptr)
44757+ void __user **user_ptr, void ***kernel_ptr)
44758 {
44759 int ret = 0;
44760
44761@@ -2276,7 +2277,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44762 ret = -EINVAL;
44763 break;
44764 }
44765- *user_ptr = (void __user *)buf->m.planes;
44766+ *user_ptr = (void __force_user *)buf->m.planes;
44767 *kernel_ptr = (void *)&buf->m.planes;
44768 *array_size = sizeof(struct v4l2_plane) * buf->length;
44769 ret = 1;
44770@@ -2311,7 +2312,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44771 ret = -EINVAL;
44772 break;
44773 }
44774- *user_ptr = (void __user *)ctrls->controls;
44775+ *user_ptr = (void __force_user *)ctrls->controls;
44776 *kernel_ptr = (void *)&ctrls->controls;
44777 *array_size = sizeof(struct v4l2_ext_control)
44778 * ctrls->count;
44779@@ -2412,7 +2413,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44780 }
44781
44782 if (has_array_args) {
44783- *kernel_ptr = user_ptr;
44784+ *kernel_ptr = (void __force_kernel *)user_ptr;
44785 if (copy_to_user(user_ptr, mbuf, array_size))
44786 err = -EFAULT;
44787 goto out_array_args;
44788diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44789index 570b18a..f880314 100644
44790--- a/drivers/message/fusion/mptbase.c
44791+++ b/drivers/message/fusion/mptbase.c
44792@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44793 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44794 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44795
44796+#ifdef CONFIG_GRKERNSEC_HIDESYM
44797+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44798+#else
44799 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44800 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44801+#endif
44802+
44803 /*
44804 * Rounding UP to nearest 4-kB boundary here...
44805 */
44806@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44807 ioc->facts.GlobalCredits);
44808
44809 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44810+#ifdef CONFIG_GRKERNSEC_HIDESYM
44811+ NULL, NULL);
44812+#else
44813 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44814+#endif
44815 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44816 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44817 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44818diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44819index 00d339c..2ea899d 100644
44820--- a/drivers/message/fusion/mptsas.c
44821+++ b/drivers/message/fusion/mptsas.c
44822@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44823 return 0;
44824 }
44825
44826+static inline void
44827+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44828+{
44829+ if (phy_info->port_details) {
44830+ phy_info->port_details->rphy = rphy;
44831+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44832+ ioc->name, rphy));
44833+ }
44834+
44835+ if (rphy) {
44836+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44837+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44838+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44839+ ioc->name, rphy, rphy->dev.release));
44840+ }
44841+}
44842+
44843 /* no mutex */
44844 static void
44845 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44846@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44847 return NULL;
44848 }
44849
44850-static inline void
44851-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44852-{
44853- if (phy_info->port_details) {
44854- phy_info->port_details->rphy = rphy;
44855- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44856- ioc->name, rphy));
44857- }
44858-
44859- if (rphy) {
44860- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44861- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44862- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44863- ioc->name, rphy, rphy->dev.release));
44864- }
44865-}
44866-
44867 static inline struct sas_port *
44868 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44869 {
44870diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44871index 727819c..ad74694 100644
44872--- a/drivers/message/fusion/mptscsih.c
44873+++ b/drivers/message/fusion/mptscsih.c
44874@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44875
44876 h = shost_priv(SChost);
44877
44878- if (h) {
44879- if (h->info_kbuf == NULL)
44880- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44881- return h->info_kbuf;
44882- h->info_kbuf[0] = '\0';
44883+ if (!h)
44884+ return NULL;
44885
44886- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44887- h->info_kbuf[size-1] = '\0';
44888- }
44889+ if (h->info_kbuf == NULL)
44890+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44891+ return h->info_kbuf;
44892+ h->info_kbuf[0] = '\0';
44893+
44894+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44895+ h->info_kbuf[size-1] = '\0';
44896
44897 return h->info_kbuf;
44898 }
44899diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44900index b7d87cd..3fb36da 100644
44901--- a/drivers/message/i2o/i2o_proc.c
44902+++ b/drivers/message/i2o/i2o_proc.c
44903@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44904 "Array Controller Device"
44905 };
44906
44907-static char *chtostr(char *tmp, u8 *chars, int n)
44908-{
44909- tmp[0] = 0;
44910- return strncat(tmp, (char *)chars, n);
44911-}
44912-
44913 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44914 char *group)
44915 {
44916@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44917 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44918 {
44919 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44920- static u32 work32[5];
44921- static u8 *work8 = (u8 *) work32;
44922- static u16 *work16 = (u16 *) work32;
44923+ u32 work32[5];
44924+ u8 *work8 = (u8 *) work32;
44925+ u16 *work16 = (u16 *) work32;
44926 int token;
44927 u32 hwcap;
44928
44929@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44930 } *result;
44931
44932 i2o_exec_execute_ddm_table ddm_table;
44933- char tmp[28 + 1];
44934
44935 result = kmalloc(sizeof(*result), GFP_KERNEL);
44936 if (!result)
44937@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44938
44939 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44940 seq_printf(seq, "%-#8x", ddm_table.module_id);
44941- seq_printf(seq, "%-29s",
44942- chtostr(tmp, ddm_table.module_name_version, 28));
44943+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44944 seq_printf(seq, "%9d ", ddm_table.data_size);
44945 seq_printf(seq, "%8d", ddm_table.code_size);
44946
44947@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44948
44949 i2o_driver_result_table *result;
44950 i2o_driver_store_table *dst;
44951- char tmp[28 + 1];
44952
44953 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44954 if (result == NULL)
44955@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44956
44957 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44958 seq_printf(seq, "%-#8x", dst->module_id);
44959- seq_printf(seq, "%-29s",
44960- chtostr(tmp, dst->module_name_version, 28));
44961- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44962+ seq_printf(seq, "%-.28s", dst->module_name_version);
44963+ seq_printf(seq, "%-.8s", dst->date);
44964 seq_printf(seq, "%8d ", dst->module_size);
44965 seq_printf(seq, "%8d ", dst->mpb_size);
44966 seq_printf(seq, "0x%04x", dst->module_flags);
44967@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44968 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44969 {
44970 struct i2o_device *d = (struct i2o_device *)seq->private;
44971- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44972+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44973 // == (allow) 512d bytes (max)
44974- static u16 *work16 = (u16 *) work32;
44975+ u16 *work16 = (u16 *) work32;
44976 int token;
44977- char tmp[16 + 1];
44978
44979 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44980
44981@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44982 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44983 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44984 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44985- seq_printf(seq, "Vendor info : %s\n",
44986- chtostr(tmp, (u8 *) (work32 + 2), 16));
44987- seq_printf(seq, "Product info : %s\n",
44988- chtostr(tmp, (u8 *) (work32 + 6), 16));
44989- seq_printf(seq, "Description : %s\n",
44990- chtostr(tmp, (u8 *) (work32 + 10), 16));
44991- seq_printf(seq, "Product rev. : %s\n",
44992- chtostr(tmp, (u8 *) (work32 + 14), 8));
44993+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44994+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44995+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44996+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44997
44998 seq_printf(seq, "Serial number : ");
44999 print_serial_number(seq, (u8 *) (work32 + 16),
45000@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45001 u8 pad[256]; // allow up to 256 byte (max) serial number
45002 } result;
45003
45004- char tmp[24 + 1];
45005-
45006 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45007
45008 if (token < 0) {
45009@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45010 }
45011
45012 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45013- seq_printf(seq, "Module name : %s\n",
45014- chtostr(tmp, result.module_name, 24));
45015- seq_printf(seq, "Module revision : %s\n",
45016- chtostr(tmp, result.module_rev, 8));
45017+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
45018+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45019
45020 seq_printf(seq, "Serial number : ");
45021 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45022@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45023 u8 instance_number[4];
45024 } result;
45025
45026- char tmp[64 + 1];
45027-
45028 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45029
45030 if (token < 0) {
45031@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45032 return 0;
45033 }
45034
45035- seq_printf(seq, "Device name : %s\n",
45036- chtostr(tmp, result.device_name, 64));
45037- seq_printf(seq, "Service name : %s\n",
45038- chtostr(tmp, result.service_name, 64));
45039- seq_printf(seq, "Physical name : %s\n",
45040- chtostr(tmp, result.physical_location, 64));
45041- seq_printf(seq, "Instance number : %s\n",
45042- chtostr(tmp, result.instance_number, 4));
45043+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
45044+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
45045+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45046+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45047
45048 return 0;
45049 }
45050@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45051 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45052 {
45053 struct i2o_device *d = (struct i2o_device *)seq->private;
45054- static u32 work32[12];
45055- static u16 *work16 = (u16 *) work32;
45056- static u8 *work8 = (u8 *) work32;
45057+ u32 work32[12];
45058+ u16 *work16 = (u16 *) work32;
45059+ u8 *work8 = (u8 *) work32;
45060 int token;
45061
45062 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45063diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45064index 92752fb..a7494f6 100644
45065--- a/drivers/message/i2o/iop.c
45066+++ b/drivers/message/i2o/iop.c
45067@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45068
45069 spin_lock_irqsave(&c->context_list_lock, flags);
45070
45071- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45072- atomic_inc(&c->context_list_counter);
45073+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45074+ atomic_inc_unchecked(&c->context_list_counter);
45075
45076- entry->context = atomic_read(&c->context_list_counter);
45077+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45078
45079 list_add(&entry->list, &c->context_list);
45080
45081@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45082
45083 #if BITS_PER_LONG == 64
45084 spin_lock_init(&c->context_list_lock);
45085- atomic_set(&c->context_list_counter, 0);
45086+ atomic_set_unchecked(&c->context_list_counter, 0);
45087 INIT_LIST_HEAD(&c->context_list);
45088 #endif
45089
45090diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45091index d1a22aa..d0f7bf7 100644
45092--- a/drivers/mfd/ab8500-debugfs.c
45093+++ b/drivers/mfd/ab8500-debugfs.c
45094@@ -100,7 +100,7 @@ static int irq_last;
45095 static u32 *irq_count;
45096 static int num_irqs;
45097
45098-static struct device_attribute **dev_attr;
45099+static device_attribute_no_const **dev_attr;
45100 static char **event_name;
45101
45102 static u8 avg_sample = SAMPLE_16;
45103diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45104index a83eed5..62a58a9 100644
45105--- a/drivers/mfd/max8925-i2c.c
45106+++ b/drivers/mfd/max8925-i2c.c
45107@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45108 const struct i2c_device_id *id)
45109 {
45110 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45111- static struct max8925_chip *chip;
45112+ struct max8925_chip *chip;
45113 struct device_node *node = client->dev.of_node;
45114
45115 if (node && !pdata) {
45116diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45117index 460a014..21d3061 100644
45118--- a/drivers/mfd/tps65910.c
45119+++ b/drivers/mfd/tps65910.c
45120@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45121 struct tps65910_platform_data *pdata)
45122 {
45123 int ret = 0;
45124- static struct regmap_irq_chip *tps6591x_irqs_chip;
45125+ struct regmap_irq_chip *tps6591x_irqs_chip;
45126
45127 if (!irq) {
45128 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45129diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45130index 596b1f6..5b6ab74 100644
45131--- a/drivers/mfd/twl4030-irq.c
45132+++ b/drivers/mfd/twl4030-irq.c
45133@@ -34,6 +34,7 @@
45134 #include <linux/of.h>
45135 #include <linux/irqdomain.h>
45136 #include <linux/i2c/twl.h>
45137+#include <asm/pgtable.h>
45138
45139 #include "twl-core.h"
45140
45141@@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45142 * Install an irq handler for each of the SIH modules;
45143 * clone dummy irq_chip since PIH can't *do* anything
45144 */
45145- twl4030_irq_chip = dummy_irq_chip;
45146- twl4030_irq_chip.name = "twl4030";
45147+ pax_open_kernel();
45148+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45149+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45150
45151- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45152+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45153+ pax_close_kernel();
45154
45155 for (i = irq_base; i < irq_end; i++) {
45156 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45157diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45158index 464419b..64bae8d 100644
45159--- a/drivers/misc/c2port/core.c
45160+++ b/drivers/misc/c2port/core.c
45161@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45162 goto error_idr_alloc;
45163 c2dev->id = ret;
45164
45165- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45166+ pax_open_kernel();
45167+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45168+ pax_close_kernel();
45169
45170 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45171 "c2port%d", c2dev->id);
45172diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45173index 3f2b625..945e179 100644
45174--- a/drivers/misc/eeprom/sunxi_sid.c
45175+++ b/drivers/misc/eeprom/sunxi_sid.c
45176@@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45177
45178 platform_set_drvdata(pdev, sid_data);
45179
45180- sid_bin_attr.size = sid_data->keysize;
45181+ pax_open_kernel();
45182+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45183+ pax_close_kernel();
45184 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45185 return -ENODEV;
45186
45187diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45188index 36f5d52..32311c3 100644
45189--- a/drivers/misc/kgdbts.c
45190+++ b/drivers/misc/kgdbts.c
45191@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45192 char before[BREAK_INSTR_SIZE];
45193 char after[BREAK_INSTR_SIZE];
45194
45195- probe_kernel_read(before, (char *)kgdbts_break_test,
45196+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45197 BREAK_INSTR_SIZE);
45198 init_simple_test();
45199 ts.tst = plant_and_detach_test;
45200@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45201 /* Activate test with initial breakpoint */
45202 if (!is_early)
45203 kgdb_breakpoint();
45204- probe_kernel_read(after, (char *)kgdbts_break_test,
45205+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45206 BREAK_INSTR_SIZE);
45207 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45208 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45209diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45210index 3ef4627..8d00486 100644
45211--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45212+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45213@@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45214 * the lid is closed. This leads to interrupts as soon as a little move
45215 * is done.
45216 */
45217- atomic_inc(&lis3->count);
45218+ atomic_inc_unchecked(&lis3->count);
45219
45220 wake_up_interruptible(&lis3->misc_wait);
45221 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45222@@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45223 if (lis3->pm_dev)
45224 pm_runtime_get_sync(lis3->pm_dev);
45225
45226- atomic_set(&lis3->count, 0);
45227+ atomic_set_unchecked(&lis3->count, 0);
45228 return 0;
45229 }
45230
45231@@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45232 add_wait_queue(&lis3->misc_wait, &wait);
45233 while (true) {
45234 set_current_state(TASK_INTERRUPTIBLE);
45235- data = atomic_xchg(&lis3->count, 0);
45236+ data = atomic_xchg_unchecked(&lis3->count, 0);
45237 if (data)
45238 break;
45239
45240@@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45241 struct lis3lv02d, miscdev);
45242
45243 poll_wait(file, &lis3->misc_wait, wait);
45244- if (atomic_read(&lis3->count))
45245+ if (atomic_read_unchecked(&lis3->count))
45246 return POLLIN | POLLRDNORM;
45247 return 0;
45248 }
45249diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45250index c439c82..1f20f57 100644
45251--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45252+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45253@@ -297,7 +297,7 @@ struct lis3lv02d {
45254 struct input_polled_dev *idev; /* input device */
45255 struct platform_device *pdev; /* platform device */
45256 struct regulator_bulk_data regulators[2];
45257- atomic_t count; /* interrupt count after last read */
45258+ atomic_unchecked_t count; /* interrupt count after last read */
45259 union axis_conversion ac; /* hw -> logical axis */
45260 int mapped_btns[3];
45261
45262diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45263index 2f30bad..c4c13d0 100644
45264--- a/drivers/misc/sgi-gru/gruhandles.c
45265+++ b/drivers/misc/sgi-gru/gruhandles.c
45266@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45267 unsigned long nsec;
45268
45269 nsec = CLKS2NSEC(clks);
45270- atomic_long_inc(&mcs_op_statistics[op].count);
45271- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45272+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45273+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45274 if (mcs_op_statistics[op].max < nsec)
45275 mcs_op_statistics[op].max = nsec;
45276 }
45277diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45278index 4f76359..cdfcb2e 100644
45279--- a/drivers/misc/sgi-gru/gruprocfs.c
45280+++ b/drivers/misc/sgi-gru/gruprocfs.c
45281@@ -32,9 +32,9 @@
45282
45283 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45284
45285-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45286+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45287 {
45288- unsigned long val = atomic_long_read(v);
45289+ unsigned long val = atomic_long_read_unchecked(v);
45290
45291 seq_printf(s, "%16lu %s\n", val, id);
45292 }
45293@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45294
45295 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45296 for (op = 0; op < mcsop_last; op++) {
45297- count = atomic_long_read(&mcs_op_statistics[op].count);
45298- total = atomic_long_read(&mcs_op_statistics[op].total);
45299+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45300+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45301 max = mcs_op_statistics[op].max;
45302 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45303 count ? total / count : 0, max);
45304diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45305index 5c3ce24..4915ccb 100644
45306--- a/drivers/misc/sgi-gru/grutables.h
45307+++ b/drivers/misc/sgi-gru/grutables.h
45308@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45309 * GRU statistics.
45310 */
45311 struct gru_stats_s {
45312- atomic_long_t vdata_alloc;
45313- atomic_long_t vdata_free;
45314- atomic_long_t gts_alloc;
45315- atomic_long_t gts_free;
45316- atomic_long_t gms_alloc;
45317- atomic_long_t gms_free;
45318- atomic_long_t gts_double_allocate;
45319- atomic_long_t assign_context;
45320- atomic_long_t assign_context_failed;
45321- atomic_long_t free_context;
45322- atomic_long_t load_user_context;
45323- atomic_long_t load_kernel_context;
45324- atomic_long_t lock_kernel_context;
45325- atomic_long_t unlock_kernel_context;
45326- atomic_long_t steal_user_context;
45327- atomic_long_t steal_kernel_context;
45328- atomic_long_t steal_context_failed;
45329- atomic_long_t nopfn;
45330- atomic_long_t asid_new;
45331- atomic_long_t asid_next;
45332- atomic_long_t asid_wrap;
45333- atomic_long_t asid_reuse;
45334- atomic_long_t intr;
45335- atomic_long_t intr_cbr;
45336- atomic_long_t intr_tfh;
45337- atomic_long_t intr_spurious;
45338- atomic_long_t intr_mm_lock_failed;
45339- atomic_long_t call_os;
45340- atomic_long_t call_os_wait_queue;
45341- atomic_long_t user_flush_tlb;
45342- atomic_long_t user_unload_context;
45343- atomic_long_t user_exception;
45344- atomic_long_t set_context_option;
45345- atomic_long_t check_context_retarget_intr;
45346- atomic_long_t check_context_unload;
45347- atomic_long_t tlb_dropin;
45348- atomic_long_t tlb_preload_page;
45349- atomic_long_t tlb_dropin_fail_no_asid;
45350- atomic_long_t tlb_dropin_fail_upm;
45351- atomic_long_t tlb_dropin_fail_invalid;
45352- atomic_long_t tlb_dropin_fail_range_active;
45353- atomic_long_t tlb_dropin_fail_idle;
45354- atomic_long_t tlb_dropin_fail_fmm;
45355- atomic_long_t tlb_dropin_fail_no_exception;
45356- atomic_long_t tfh_stale_on_fault;
45357- atomic_long_t mmu_invalidate_range;
45358- atomic_long_t mmu_invalidate_page;
45359- atomic_long_t flush_tlb;
45360- atomic_long_t flush_tlb_gru;
45361- atomic_long_t flush_tlb_gru_tgh;
45362- atomic_long_t flush_tlb_gru_zero_asid;
45363+ atomic_long_unchecked_t vdata_alloc;
45364+ atomic_long_unchecked_t vdata_free;
45365+ atomic_long_unchecked_t gts_alloc;
45366+ atomic_long_unchecked_t gts_free;
45367+ atomic_long_unchecked_t gms_alloc;
45368+ atomic_long_unchecked_t gms_free;
45369+ atomic_long_unchecked_t gts_double_allocate;
45370+ atomic_long_unchecked_t assign_context;
45371+ atomic_long_unchecked_t assign_context_failed;
45372+ atomic_long_unchecked_t free_context;
45373+ atomic_long_unchecked_t load_user_context;
45374+ atomic_long_unchecked_t load_kernel_context;
45375+ atomic_long_unchecked_t lock_kernel_context;
45376+ atomic_long_unchecked_t unlock_kernel_context;
45377+ atomic_long_unchecked_t steal_user_context;
45378+ atomic_long_unchecked_t steal_kernel_context;
45379+ atomic_long_unchecked_t steal_context_failed;
45380+ atomic_long_unchecked_t nopfn;
45381+ atomic_long_unchecked_t asid_new;
45382+ atomic_long_unchecked_t asid_next;
45383+ atomic_long_unchecked_t asid_wrap;
45384+ atomic_long_unchecked_t asid_reuse;
45385+ atomic_long_unchecked_t intr;
45386+ atomic_long_unchecked_t intr_cbr;
45387+ atomic_long_unchecked_t intr_tfh;
45388+ atomic_long_unchecked_t intr_spurious;
45389+ atomic_long_unchecked_t intr_mm_lock_failed;
45390+ atomic_long_unchecked_t call_os;
45391+ atomic_long_unchecked_t call_os_wait_queue;
45392+ atomic_long_unchecked_t user_flush_tlb;
45393+ atomic_long_unchecked_t user_unload_context;
45394+ atomic_long_unchecked_t user_exception;
45395+ atomic_long_unchecked_t set_context_option;
45396+ atomic_long_unchecked_t check_context_retarget_intr;
45397+ atomic_long_unchecked_t check_context_unload;
45398+ atomic_long_unchecked_t tlb_dropin;
45399+ atomic_long_unchecked_t tlb_preload_page;
45400+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45401+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45402+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45403+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45404+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45405+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45406+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45407+ atomic_long_unchecked_t tfh_stale_on_fault;
45408+ atomic_long_unchecked_t mmu_invalidate_range;
45409+ atomic_long_unchecked_t mmu_invalidate_page;
45410+ atomic_long_unchecked_t flush_tlb;
45411+ atomic_long_unchecked_t flush_tlb_gru;
45412+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45413+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45414
45415- atomic_long_t copy_gpa;
45416- atomic_long_t read_gpa;
45417+ atomic_long_unchecked_t copy_gpa;
45418+ atomic_long_unchecked_t read_gpa;
45419
45420- atomic_long_t mesq_receive;
45421- atomic_long_t mesq_receive_none;
45422- atomic_long_t mesq_send;
45423- atomic_long_t mesq_send_failed;
45424- atomic_long_t mesq_noop;
45425- atomic_long_t mesq_send_unexpected_error;
45426- atomic_long_t mesq_send_lb_overflow;
45427- atomic_long_t mesq_send_qlimit_reached;
45428- atomic_long_t mesq_send_amo_nacked;
45429- atomic_long_t mesq_send_put_nacked;
45430- atomic_long_t mesq_page_overflow;
45431- atomic_long_t mesq_qf_locked;
45432- atomic_long_t mesq_qf_noop_not_full;
45433- atomic_long_t mesq_qf_switch_head_failed;
45434- atomic_long_t mesq_qf_unexpected_error;
45435- atomic_long_t mesq_noop_unexpected_error;
45436- atomic_long_t mesq_noop_lb_overflow;
45437- atomic_long_t mesq_noop_qlimit_reached;
45438- atomic_long_t mesq_noop_amo_nacked;
45439- atomic_long_t mesq_noop_put_nacked;
45440- atomic_long_t mesq_noop_page_overflow;
45441+ atomic_long_unchecked_t mesq_receive;
45442+ atomic_long_unchecked_t mesq_receive_none;
45443+ atomic_long_unchecked_t mesq_send;
45444+ atomic_long_unchecked_t mesq_send_failed;
45445+ atomic_long_unchecked_t mesq_noop;
45446+ atomic_long_unchecked_t mesq_send_unexpected_error;
45447+ atomic_long_unchecked_t mesq_send_lb_overflow;
45448+ atomic_long_unchecked_t mesq_send_qlimit_reached;
45449+ atomic_long_unchecked_t mesq_send_amo_nacked;
45450+ atomic_long_unchecked_t mesq_send_put_nacked;
45451+ atomic_long_unchecked_t mesq_page_overflow;
45452+ atomic_long_unchecked_t mesq_qf_locked;
45453+ atomic_long_unchecked_t mesq_qf_noop_not_full;
45454+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
45455+ atomic_long_unchecked_t mesq_qf_unexpected_error;
45456+ atomic_long_unchecked_t mesq_noop_unexpected_error;
45457+ atomic_long_unchecked_t mesq_noop_lb_overflow;
45458+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
45459+ atomic_long_unchecked_t mesq_noop_amo_nacked;
45460+ atomic_long_unchecked_t mesq_noop_put_nacked;
45461+ atomic_long_unchecked_t mesq_noop_page_overflow;
45462
45463 };
45464
45465@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45466 tghop_invalidate, mcsop_last};
45467
45468 struct mcs_op_statistic {
45469- atomic_long_t count;
45470- atomic_long_t total;
45471+ atomic_long_unchecked_t count;
45472+ atomic_long_unchecked_t total;
45473 unsigned long max;
45474 };
45475
45476@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45477
45478 #define STAT(id) do { \
45479 if (gru_options & OPT_STATS) \
45480- atomic_long_inc(&gru_stats.id); \
45481+ atomic_long_inc_unchecked(&gru_stats.id); \
45482 } while (0)
45483
45484 #ifdef CONFIG_SGI_GRU_DEBUG
45485diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45486index c862cd4..0d176fe 100644
45487--- a/drivers/misc/sgi-xp/xp.h
45488+++ b/drivers/misc/sgi-xp/xp.h
45489@@ -288,7 +288,7 @@ struct xpc_interface {
45490 xpc_notify_func, void *);
45491 void (*received) (short, int, void *);
45492 enum xp_retval (*partid_to_nasids) (short, void *);
45493-};
45494+} __no_const;
45495
45496 extern struct xpc_interface xpc_interface;
45497
45498diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45499index 01be66d..e3a0c7e 100644
45500--- a/drivers/misc/sgi-xp/xp_main.c
45501+++ b/drivers/misc/sgi-xp/xp_main.c
45502@@ -78,13 +78,13 @@ xpc_notloaded(void)
45503 }
45504
45505 struct xpc_interface xpc_interface = {
45506- (void (*)(int))xpc_notloaded,
45507- (void (*)(int))xpc_notloaded,
45508- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45509- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45510+ .connect = (void (*)(int))xpc_notloaded,
45511+ .disconnect = (void (*)(int))xpc_notloaded,
45512+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45513+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45514 void *))xpc_notloaded,
45515- (void (*)(short, int, void *))xpc_notloaded,
45516- (enum xp_retval(*)(short, void *))xpc_notloaded
45517+ .received = (void (*)(short, int, void *))xpc_notloaded,
45518+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45519 };
45520 EXPORT_SYMBOL_GPL(xpc_interface);
45521
45522diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45523index b94d5f7..7f494c5 100644
45524--- a/drivers/misc/sgi-xp/xpc.h
45525+++ b/drivers/misc/sgi-xp/xpc.h
45526@@ -835,6 +835,7 @@ struct xpc_arch_operations {
45527 void (*received_payload) (struct xpc_channel *, void *);
45528 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45529 };
45530+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45531
45532 /* struct xpc_partition act_state values (for XPC HB) */
45533
45534@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45535 /* found in xpc_main.c */
45536 extern struct device *xpc_part;
45537 extern struct device *xpc_chan;
45538-extern struct xpc_arch_operations xpc_arch_ops;
45539+extern xpc_arch_operations_no_const xpc_arch_ops;
45540 extern int xpc_disengage_timelimit;
45541 extern int xpc_disengage_timedout;
45542 extern int xpc_activate_IRQ_rcvd;
45543diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45544index 82dc574..8539ab2 100644
45545--- a/drivers/misc/sgi-xp/xpc_main.c
45546+++ b/drivers/misc/sgi-xp/xpc_main.c
45547@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45548 .notifier_call = xpc_system_die,
45549 };
45550
45551-struct xpc_arch_operations xpc_arch_ops;
45552+xpc_arch_operations_no_const xpc_arch_ops;
45553
45554 /*
45555 * Timer function to enforce the timelimit on the partition disengage.
45556@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45557
45558 if (((die_args->trapnr == X86_TRAP_MF) ||
45559 (die_args->trapnr == X86_TRAP_XF)) &&
45560- !user_mode_vm(die_args->regs))
45561+ !user_mode(die_args->regs))
45562 xpc_die_deactivate();
45563
45564 break;
45565diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45566index 452782b..0c10e40 100644
45567--- a/drivers/mmc/card/block.c
45568+++ b/drivers/mmc/card/block.c
45569@@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45570 if (idata->ic.postsleep_min_us)
45571 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45572
45573- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45574+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45575 err = -EFAULT;
45576 goto cmd_rel_host;
45577 }
45578diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45579index f51b5ba..86614a7 100644
45580--- a/drivers/mmc/core/mmc_ops.c
45581+++ b/drivers/mmc/core/mmc_ops.c
45582@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45583 void *data_buf;
45584 int is_on_stack;
45585
45586- is_on_stack = object_is_on_stack(buf);
45587+ is_on_stack = object_starts_on_stack(buf);
45588 if (is_on_stack) {
45589 /*
45590 * dma onto stack is unsafe/nonportable, but callers to this
45591diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45592index 6834977..824ee1b 100644
45593--- a/drivers/mmc/host/dw_mmc.h
45594+++ b/drivers/mmc/host/dw_mmc.h
45595@@ -259,5 +259,5 @@ struct dw_mci_drv_data {
45596 int (*parse_dt)(struct dw_mci *host);
45597 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45598 struct dw_mci_tuning_data *tuning_data);
45599-};
45600+} __do_const;
45601 #endif /* _DW_MMC_H_ */
45602diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45603index 771c60a..12cb615 100644
45604--- a/drivers/mmc/host/mmci.c
45605+++ b/drivers/mmc/host/mmci.c
45606@@ -1570,7 +1570,9 @@ static int mmci_probe(struct amba_device *dev,
45607 mmc->caps2 = plat->capabilities2;
45608
45609 if (variant->busy_detect) {
45610- mmci_ops.card_busy = mmci_card_busy;
45611+ pax_open_kernel();
45612+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
45613+ pax_close_kernel();
45614 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45615 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
45616 mmc->max_busy_timeout = 0;
45617diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45618index b841bb7..d82712f5 100644
45619--- a/drivers/mmc/host/sdhci-esdhc-imx.c
45620+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45621@@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45622 host->mmc->caps |= MMC_CAP_1_8V_DDR;
45623 }
45624
45625- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45626- sdhci_esdhc_ops.platform_execute_tuning =
45627+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45628+ pax_open_kernel();
45629+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45630 esdhc_executing_tuning;
45631+ pax_close_kernel();
45632+ }
45633
45634 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
45635 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
45636diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45637index d61eb5a..88c0f5d 100644
45638--- a/drivers/mmc/host/sdhci-s3c.c
45639+++ b/drivers/mmc/host/sdhci-s3c.c
45640@@ -657,9 +657,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45641 * we can use overriding functions instead of default.
45642 */
45643 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45644- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45645- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45646- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45647+ pax_open_kernel();
45648+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45649+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45650+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45651+ pax_close_kernel();
45652 }
45653
45654 /* It supports additional host capabilities if needed */
45655diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45656index 6293855..3415551 100644
45657--- a/drivers/mtd/chips/cfi_cmdset_0020.c
45658+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45659@@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45660 size_t totlen = 0, thislen;
45661 int ret = 0;
45662 size_t buflen = 0;
45663- static char *buffer;
45664+ char *buffer;
45665
45666 if (!ECCBUF_SIZE) {
45667 /* We should fall back to a general writev implementation.
45668diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45669index c07cd57..61c4fbd 100644
45670--- a/drivers/mtd/nand/denali.c
45671+++ b/drivers/mtd/nand/denali.c
45672@@ -24,6 +24,7 @@
45673 #include <linux/slab.h>
45674 #include <linux/mtd/mtd.h>
45675 #include <linux/module.h>
45676+#include <linux/slab.h>
45677
45678 #include "denali.h"
45679
45680diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45681index bb77f75..47539b1 100644
45682--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45683+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45684@@ -370,7 +370,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
45685
45686 /* first try to map the upper buffer directly */
45687 if (virt_addr_valid(this->upper_buf) &&
45688- !object_is_on_stack(this->upper_buf)) {
45689+ !object_starts_on_stack(this->upper_buf)) {
45690 sg_init_one(sgl, this->upper_buf, this->upper_len);
45691 ret = dma_map_sg(this->dev, sgl, 1, dr);
45692 if (ret == 0)
45693diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45694index 51b9d6a..52af9a7 100644
45695--- a/drivers/mtd/nftlmount.c
45696+++ b/drivers/mtd/nftlmount.c
45697@@ -24,6 +24,7 @@
45698 #include <asm/errno.h>
45699 #include <linux/delay.h>
45700 #include <linux/slab.h>
45701+#include <linux/sched.h>
45702 #include <linux/mtd/mtd.h>
45703 #include <linux/mtd/nand.h>
45704 #include <linux/mtd/nftl.h>
45705diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45706index cf49c22..971b133 100644
45707--- a/drivers/mtd/sm_ftl.c
45708+++ b/drivers/mtd/sm_ftl.c
45709@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45710 #define SM_CIS_VENDOR_OFFSET 0x59
45711 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45712 {
45713- struct attribute_group *attr_group;
45714+ attribute_group_no_const *attr_group;
45715 struct attribute **attributes;
45716 struct sm_sysfs_attribute *vendor_attribute;
45717 char *vendor;
45718diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45719index f847e16..fc8dbe9 100644
45720--- a/drivers/net/bonding/bond_netlink.c
45721+++ b/drivers/net/bonding/bond_netlink.c
45722@@ -542,7 +542,7 @@ nla_put_failure:
45723 return -EMSGSIZE;
45724 }
45725
45726-struct rtnl_link_ops bond_link_ops __read_mostly = {
45727+struct rtnl_link_ops bond_link_ops = {
45728 .kind = "bond",
45729 .priv_size = sizeof(struct bonding),
45730 .setup = bond_setup,
45731diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45732index 9e7d95d..d447b88 100644
45733--- a/drivers/net/can/Kconfig
45734+++ b/drivers/net/can/Kconfig
45735@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45736
45737 config CAN_FLEXCAN
45738 tristate "Support for Freescale FLEXCAN based chips"
45739- depends on ARM || PPC
45740+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45741 ---help---
45742 Say Y here if you want to support for Freescale FlexCAN.
45743
45744diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45745index 455d4c3..3353ee7 100644
45746--- a/drivers/net/ethernet/8390/ax88796.c
45747+++ b/drivers/net/ethernet/8390/ax88796.c
45748@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
45749 if (ax->plat->reg_offsets)
45750 ei_local->reg_offset = ax->plat->reg_offsets;
45751 else {
45752+ resource_size_t _mem_size = mem_size;
45753+ do_div(_mem_size, 0x18);
45754 ei_local->reg_offset = ax->reg_offsets;
45755 for (ret = 0; ret < 0x18; ret++)
45756- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45757+ ax->reg_offsets[ret] = _mem_size * ret;
45758 }
45759
45760 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45761diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
45762index 7330681..7e9e463 100644
45763--- a/drivers/net/ethernet/altera/altera_tse_main.c
45764+++ b/drivers/net/ethernet/altera/altera_tse_main.c
45765@@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
45766 return 0;
45767 }
45768
45769-static struct net_device_ops altera_tse_netdev_ops = {
45770+static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
45771 .ndo_open = tse_open,
45772 .ndo_stop = tse_shutdown,
45773 .ndo_start_xmit = tse_start_xmit,
45774@@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
45775 ndev->netdev_ops = &altera_tse_netdev_ops;
45776 altera_tse_set_ethtool_ops(ndev);
45777
45778+ pax_open_kernel();
45779 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
45780
45781 if (priv->hash_filter)
45782 altera_tse_netdev_ops.ndo_set_rx_mode =
45783 tse_set_rx_mode_hashfilter;
45784+ pax_close_kernel();
45785
45786 /* Scatter/gather IO is not supported,
45787 * so it is turned off
45788diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45789index 3448cc0..67b2dc4 100644
45790--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45791+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45792@@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45793 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45794 {
45795 /* RX_MODE controlling object */
45796- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45797+ bnx2x_init_rx_mode_obj(bp);
45798
45799 /* multicast configuration controlling object */
45800 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45801diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45802index 31297266..944cf6e 100644
45803--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45804+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45805@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45806 return rc;
45807 }
45808
45809-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45810- struct bnx2x_rx_mode_obj *o)
45811+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45812 {
45813 if (CHIP_IS_E1x(bp)) {
45814- o->wait_comp = bnx2x_empty_rx_mode_wait;
45815- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45816+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45817+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45818 } else {
45819- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45820- o->config_rx_mode = bnx2x_set_rx_mode_e2;
45821+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45822+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45823 }
45824 }
45825
45826diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45827index 80f6c79..fb7d12d 100644
45828--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45829+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45830@@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45831
45832 /********************* RX MODE ****************/
45833
45834-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45835- struct bnx2x_rx_mode_obj *o);
45836+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45837
45838 /**
45839 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45840diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45841index 04321e5..b51cdc4 100644
45842--- a/drivers/net/ethernet/broadcom/tg3.h
45843+++ b/drivers/net/ethernet/broadcom/tg3.h
45844@@ -150,6 +150,7 @@
45845 #define CHIPREV_ID_5750_A0 0x4000
45846 #define CHIPREV_ID_5750_A1 0x4001
45847 #define CHIPREV_ID_5750_A3 0x4003
45848+#define CHIPREV_ID_5750_C1 0x4201
45849 #define CHIPREV_ID_5750_C2 0x4202
45850 #define CHIPREV_ID_5752_A0_HW 0x5000
45851 #define CHIPREV_ID_5752_A0 0x6000
45852diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45853index 13f9636..228040f 100644
45854--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45855+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45856@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45857 }
45858
45859 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45860- bna_cb_ioceth_enable,
45861- bna_cb_ioceth_disable,
45862- bna_cb_ioceth_hbfail,
45863- bna_cb_ioceth_reset
45864+ .enable_cbfn = bna_cb_ioceth_enable,
45865+ .disable_cbfn = bna_cb_ioceth_disable,
45866+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
45867+ .reset_cbfn = bna_cb_ioceth_reset
45868 };
45869
45870 static void bna_attr_init(struct bna_ioceth *ioceth)
45871diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45872index 8cffcdf..aadf043 100644
45873--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45874+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45875@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45876 */
45877 struct l2t_skb_cb {
45878 arp_failure_handler_func arp_failure_handler;
45879-};
45880+} __no_const;
45881
45882 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45883
45884diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45885index 24e16e3..bfe6ef2 100644
45886--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45887+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45888@@ -2139,7 +2139,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45889
45890 int i;
45891 struct adapter *ap = netdev2adap(dev);
45892- static const unsigned int *reg_ranges;
45893+ const unsigned int *reg_ranges;
45894 int arr_size = 0, buf_size = 0;
45895
45896 if (is_t4(ap->params.chip)) {
45897diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45898index c05b66d..ed69872 100644
45899--- a/drivers/net/ethernet/dec/tulip/de4x5.c
45900+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45901@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45902 for (i=0; i<ETH_ALEN; i++) {
45903 tmp.addr[i] = dev->dev_addr[i];
45904 }
45905- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45906+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45907 break;
45908
45909 case DE4X5_SET_HWADDR: /* Set the hardware address */
45910@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45911 spin_lock_irqsave(&lp->lock, flags);
45912 memcpy(&statbuf, &lp->pktStats, ioc->len);
45913 spin_unlock_irqrestore(&lp->lock, flags);
45914- if (copy_to_user(ioc->data, &statbuf, ioc->len))
45915+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45916 return -EFAULT;
45917 break;
45918 }
45919diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45920index dc19bc5..f2d4548 100644
45921--- a/drivers/net/ethernet/emulex/benet/be_main.c
45922+++ b/drivers/net/ethernet/emulex/benet/be_main.c
45923@@ -535,7 +535,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45924
45925 if (wrapped)
45926 newacc += 65536;
45927- ACCESS_ONCE(*acc) = newacc;
45928+ ACCESS_ONCE_RW(*acc) = newacc;
45929 }
45930
45931 static void populate_erx_stats(struct be_adapter *adapter,
45932diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45933index 68069ea..c4484f6 100644
45934--- a/drivers/net/ethernet/faraday/ftgmac100.c
45935+++ b/drivers/net/ethernet/faraday/ftgmac100.c
45936@@ -30,6 +30,8 @@
45937 #include <linux/netdevice.h>
45938 #include <linux/phy.h>
45939 #include <linux/platform_device.h>
45940+#include <linux/interrupt.h>
45941+#include <linux/irqreturn.h>
45942 #include <net/ip.h>
45943
45944 #include "ftgmac100.h"
45945diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45946index 8be5b40..081bc1b 100644
45947--- a/drivers/net/ethernet/faraday/ftmac100.c
45948+++ b/drivers/net/ethernet/faraday/ftmac100.c
45949@@ -31,6 +31,8 @@
45950 #include <linux/module.h>
45951 #include <linux/netdevice.h>
45952 #include <linux/platform_device.h>
45953+#include <linux/interrupt.h>
45954+#include <linux/irqreturn.h>
45955
45956 #include "ftmac100.h"
45957
45958diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45959index e61e637..9117795 100644
45960--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45961+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
45962@@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
45963 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
45964
45965 /* Update the base adjustement value. */
45966- ACCESS_ONCE(pf->ptp_base_adj) = incval;
45967+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
45968 smp_mb(); /* Force the above update. */
45969 }
45970
45971diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45972index 8902ae6..e7bcdce 100644
45973--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45974+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45975@@ -771,7 +771,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45976 }
45977
45978 /* update the base incval used to calculate frequency adjustment */
45979- ACCESS_ONCE(adapter->base_incval) = incval;
45980+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
45981 smp_mb();
45982
45983 /* need lock to prevent incorrect read while modifying cyclecounter */
45984diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45985index 089b713..28d87ae 100644
45986--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45987+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45988@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45989 struct __vxge_hw_fifo *fifo;
45990 struct vxge_hw_fifo_config *config;
45991 u32 txdl_size, txdl_per_memblock;
45992- struct vxge_hw_mempool_cbs fifo_mp_callback;
45993+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45994+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45995+ };
45996+
45997 struct __vxge_hw_virtualpath *vpath;
45998
45999 if ((vp == NULL) || (attr == NULL)) {
46000@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46001 goto exit;
46002 }
46003
46004- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
46005-
46006 fifo->mempool =
46007 __vxge_hw_mempool_create(vpath->hldev,
46008 fifo->config->memblock_size,
46009diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46010index ba20c72..f30c0fe 100644
46011--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46012+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46013@@ -2176,7 +2176,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
46014 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
46015 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
46016 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
46017- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46018+ pax_open_kernel();
46019+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46020+ pax_close_kernel();
46021 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46022 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46023 max_tx_rings = QLCNIC_MAX_TX_RINGS;
46024diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46025index be7d7a6..a8983f8 100644
46026--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46027+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46028@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46029 case QLCNIC_NON_PRIV_FUNC:
46030 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46031 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46032- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46033+ pax_open_kernel();
46034+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46035+ pax_close_kernel();
46036 break;
46037 case QLCNIC_PRIV_FUNC:
46038 ahw->op_mode = QLCNIC_PRIV_FUNC;
46039 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46040- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46041+ pax_open_kernel();
46042+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46043+ pax_close_kernel();
46044 break;
46045 case QLCNIC_MGMT_FUNC:
46046 ahw->op_mode = QLCNIC_MGMT_FUNC;
46047 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46048- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46049+ pax_open_kernel();
46050+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46051+ pax_close_kernel();
46052 break;
46053 default:
46054 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46055diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46056index 37b979b..50f5b95 100644
46057--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46058+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46059@@ -1217,7 +1217,7 @@ flash_temp:
46060 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46061 {
46062 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46063- static const struct qlcnic_dump_operations *fw_dump_ops;
46064+ const struct qlcnic_dump_operations *fw_dump_ops;
46065 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
46066 u32 entry_offset, dump, no_entries, buf_offset = 0;
46067 int i, k, ops_cnt, ops_index, dump_size = 0;
46068diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46069index aa1c079..2b1a3e8 100644
46070--- a/drivers/net/ethernet/realtek/r8169.c
46071+++ b/drivers/net/ethernet/realtek/r8169.c
46072@@ -758,22 +758,22 @@ struct rtl8169_private {
46073 struct mdio_ops {
46074 void (*write)(struct rtl8169_private *, int, int);
46075 int (*read)(struct rtl8169_private *, int);
46076- } mdio_ops;
46077+ } __no_const mdio_ops;
46078
46079 struct pll_power_ops {
46080 void (*down)(struct rtl8169_private *);
46081 void (*up)(struct rtl8169_private *);
46082- } pll_power_ops;
46083+ } __no_const pll_power_ops;
46084
46085 struct jumbo_ops {
46086 void (*enable)(struct rtl8169_private *);
46087 void (*disable)(struct rtl8169_private *);
46088- } jumbo_ops;
46089+ } __no_const jumbo_ops;
46090
46091 struct csi_ops {
46092 void (*write)(struct rtl8169_private *, int, int);
46093 u32 (*read)(struct rtl8169_private *, int);
46094- } csi_ops;
46095+ } __no_const csi_ops;
46096
46097 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46098 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46099diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46100index 6b861e3..204ac86 100644
46101--- a/drivers/net/ethernet/sfc/ptp.c
46102+++ b/drivers/net/ethernet/sfc/ptp.c
46103@@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46104 ptp->start.dma_addr);
46105
46106 /* Clear flag that signals MC ready */
46107- ACCESS_ONCE(*start) = 0;
46108+ ACCESS_ONCE_RW(*start) = 0;
46109 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46110 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46111 EFX_BUG_ON_PARANOID(rc);
46112diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46113index 50617c5..b13724c 100644
46114--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46115+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46116@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46117
46118 writel(value, ioaddr + MMC_CNTRL);
46119
46120- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46121- MMC_CNTRL, value);
46122+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46123+// MMC_CNTRL, value);
46124 }
46125
46126 /* To mask all all interrupts.*/
46127diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46128index d18f711d..5755800 100644
46129--- a/drivers/net/hyperv/hyperv_net.h
46130+++ b/drivers/net/hyperv/hyperv_net.h
46131@@ -101,7 +101,7 @@ struct rndis_device {
46132
46133 enum rndis_device_state state;
46134 bool link_state;
46135- atomic_t new_req_id;
46136+ atomic_unchecked_t new_req_id;
46137
46138 spinlock_t request_lock;
46139 struct list_head req_list;
46140diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46141index 143a98c..d54fbaa 100644
46142--- a/drivers/net/hyperv/rndis_filter.c
46143+++ b/drivers/net/hyperv/rndis_filter.c
46144@@ -100,7 +100,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46145 * template
46146 */
46147 set = &rndis_msg->msg.set_req;
46148- set->req_id = atomic_inc_return(&dev->new_req_id);
46149+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46150
46151 /* Add to the request list */
46152 spin_lock_irqsave(&dev->request_lock, flags);
46153@@ -834,7 +834,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46154
46155 /* Setup the rndis set */
46156 halt = &request->request_msg.msg.halt_req;
46157- halt->req_id = atomic_inc_return(&dev->new_req_id);
46158+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46159
46160 /* Ignore return since this msg is optional. */
46161 rndis_filter_send_request(dev, request);
46162diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46163index 78f18be..1d19c62 100644
46164--- a/drivers/net/ieee802154/fakehard.c
46165+++ b/drivers/net/ieee802154/fakehard.c
46166@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46167 phy->transmit_power = 0xbf;
46168
46169 dev->netdev_ops = &fake_ops;
46170- dev->ml_priv = &fake_mlme;
46171+ dev->ml_priv = (void *)&fake_mlme;
46172
46173 priv = netdev_priv(dev);
46174 priv->phy = phy;
46175diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46176index 7eec598..90b8428 100644
46177--- a/drivers/net/macvlan.c
46178+++ b/drivers/net/macvlan.c
46179@@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46180 int macvlan_link_register(struct rtnl_link_ops *ops)
46181 {
46182 /* common fields */
46183- ops->priv_size = sizeof(struct macvlan_dev);
46184- ops->validate = macvlan_validate;
46185- ops->maxtype = IFLA_MACVLAN_MAX;
46186- ops->policy = macvlan_policy;
46187- ops->changelink = macvlan_changelink;
46188- ops->get_size = macvlan_get_size;
46189- ops->fill_info = macvlan_fill_info;
46190+ pax_open_kernel();
46191+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46192+ *(void **)&ops->validate = macvlan_validate;
46193+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46194+ *(const void **)&ops->policy = macvlan_policy;
46195+ *(void **)&ops->changelink = macvlan_changelink;
46196+ *(void **)&ops->get_size = macvlan_get_size;
46197+ *(void **)&ops->fill_info = macvlan_fill_info;
46198+ pax_close_kernel();
46199
46200 return rtnl_link_register(ops);
46201 };
46202@@ -1044,7 +1046,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46203 return NOTIFY_DONE;
46204 }
46205
46206-static struct notifier_block macvlan_notifier_block __read_mostly = {
46207+static struct notifier_block macvlan_notifier_block = {
46208 .notifier_call = macvlan_device_event,
46209 };
46210
46211diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46212index 3381c4f..dea5fd5 100644
46213--- a/drivers/net/macvtap.c
46214+++ b/drivers/net/macvtap.c
46215@@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46216 }
46217
46218 ret = 0;
46219- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46220+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46221 put_user(q->flags, &ifr->ifr_flags))
46222 ret = -EFAULT;
46223 macvtap_put_vlan(vlan);
46224@@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46225 return NOTIFY_DONE;
46226 }
46227
46228-static struct notifier_block macvtap_notifier_block __read_mostly = {
46229+static struct notifier_block macvtap_notifier_block = {
46230 .notifier_call = macvtap_device_event,
46231 };
46232
46233diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46234index e3923eb..2a0373b 100644
46235--- a/drivers/net/ppp/ppp_generic.c
46236+++ b/drivers/net/ppp/ppp_generic.c
46237@@ -1012,7 +1012,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46238 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46239 struct ppp_stats stats;
46240 struct ppp_comp_stats cstats;
46241- char *vers;
46242
46243 switch (cmd) {
46244 case SIOCGPPPSTATS:
46245@@ -1034,8 +1033,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46246 break;
46247
46248 case SIOCGPPPVER:
46249- vers = PPP_VERSION;
46250- if (copy_to_user(addr, vers, strlen(vers) + 1))
46251+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46252 break;
46253 err = 0;
46254 break;
46255diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46256index 1252d9c..80e660b 100644
46257--- a/drivers/net/slip/slhc.c
46258+++ b/drivers/net/slip/slhc.c
46259@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46260 register struct tcphdr *thp;
46261 register struct iphdr *ip;
46262 register struct cstate *cs;
46263- int len, hdrlen;
46264+ long len, hdrlen;
46265 unsigned char *cp = icp;
46266
46267 /* We've got a compressed packet; read the change byte */
46268diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46269index ce4989b..b40b328 100644
46270--- a/drivers/net/team/team.c
46271+++ b/drivers/net/team/team.c
46272@@ -2868,7 +2868,7 @@ static int team_device_event(struct notifier_block *unused,
46273 return NOTIFY_DONE;
46274 }
46275
46276-static struct notifier_block team_notifier_block __read_mostly = {
46277+static struct notifier_block team_notifier_block = {
46278 .notifier_call = team_device_event,
46279 };
46280
46281diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46282index ee328ba..c4a0041 100644
46283--- a/drivers/net/tun.c
46284+++ b/drivers/net/tun.c
46285@@ -1876,7 +1876,7 @@ unlock:
46286 }
46287
46288 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46289- unsigned long arg, int ifreq_len)
46290+ unsigned long arg, size_t ifreq_len)
46291 {
46292 struct tun_file *tfile = file->private_data;
46293 struct tun_struct *tun;
46294@@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46295 unsigned int ifindex;
46296 int ret;
46297
46298+ if (ifreq_len > sizeof ifr)
46299+ return -EFAULT;
46300+
46301 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46302 if (copy_from_user(&ifr, argp, ifreq_len))
46303 return -EFAULT;
46304diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46305index 660bd5e..ac59452 100644
46306--- a/drivers/net/usb/hso.c
46307+++ b/drivers/net/usb/hso.c
46308@@ -71,7 +71,7 @@
46309 #include <asm/byteorder.h>
46310 #include <linux/serial_core.h>
46311 #include <linux/serial.h>
46312-
46313+#include <asm/local.h>
46314
46315 #define MOD_AUTHOR "Option Wireless"
46316 #define MOD_DESCRIPTION "USB High Speed Option driver"
46317@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46318 struct urb *urb;
46319
46320 urb = serial->rx_urb[0];
46321- if (serial->port.count > 0) {
46322+ if (atomic_read(&serial->port.count) > 0) {
46323 count = put_rxbuf_data(urb, serial);
46324 if (count == -1)
46325 return;
46326@@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46327 DUMP1(urb->transfer_buffer, urb->actual_length);
46328
46329 /* Anyone listening? */
46330- if (serial->port.count == 0)
46331+ if (atomic_read(&serial->port.count) == 0)
46332 return;
46333
46334 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46335@@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46336 tty_port_tty_set(&serial->port, tty);
46337
46338 /* check for port already opened, if not set the termios */
46339- serial->port.count++;
46340- if (serial->port.count == 1) {
46341+ if (atomic_inc_return(&serial->port.count) == 1) {
46342 serial->rx_state = RX_IDLE;
46343 /* Force default termio settings */
46344 _hso_serial_set_termios(tty, NULL);
46345@@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46346 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46347 if (result) {
46348 hso_stop_serial_device(serial->parent);
46349- serial->port.count--;
46350+ atomic_dec(&serial->port.count);
46351 kref_put(&serial->parent->ref, hso_serial_ref_free);
46352 }
46353 } else {
46354@@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46355
46356 /* reset the rts and dtr */
46357 /* do the actual close */
46358- serial->port.count--;
46359+ atomic_dec(&serial->port.count);
46360
46361- if (serial->port.count <= 0) {
46362- serial->port.count = 0;
46363+ if (atomic_read(&serial->port.count) <= 0) {
46364+ atomic_set(&serial->port.count, 0);
46365 tty_port_tty_set(&serial->port, NULL);
46366 if (!usb_gone)
46367 hso_stop_serial_device(serial->parent);
46368@@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46369
46370 /* the actual setup */
46371 spin_lock_irqsave(&serial->serial_lock, flags);
46372- if (serial->port.count)
46373+ if (atomic_read(&serial->port.count))
46374 _hso_serial_set_termios(tty, old);
46375 else
46376 tty->termios = *old;
46377@@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46378 D1("Pending read interrupt on port %d\n", i);
46379 spin_lock(&serial->serial_lock);
46380 if (serial->rx_state == RX_IDLE &&
46381- serial->port.count > 0) {
46382+ atomic_read(&serial->port.count) > 0) {
46383 /* Setup and send a ctrl req read on
46384 * port i */
46385 if (!serial->rx_urb_filled[0]) {
46386@@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46387 /* Start all serial ports */
46388 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46389 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46390- if (dev2ser(serial_table[i])->port.count) {
46391+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46392 result =
46393 hso_start_serial_device(serial_table[i], GFP_NOIO);
46394 hso_kick_transmit(dev2ser(serial_table[i]));
46395diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46396index 3fbfb08..2c16265 100644
46397--- a/drivers/net/usb/r8152.c
46398+++ b/drivers/net/usb/r8152.c
46399@@ -567,7 +567,7 @@ struct r8152 {
46400 void (*up)(struct r8152 *);
46401 void (*down)(struct r8152 *);
46402 void (*unload)(struct r8152 *);
46403- } rtl_ops;
46404+ } __no_const rtl_ops;
46405
46406 int intr_interval;
46407 u32 saved_wolopts;
46408diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46409index a2515887..6d13233 100644
46410--- a/drivers/net/usb/sierra_net.c
46411+++ b/drivers/net/usb/sierra_net.c
46412@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46413 /* atomic counter partially included in MAC address to make sure 2 devices
46414 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46415 */
46416-static atomic_t iface_counter = ATOMIC_INIT(0);
46417+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46418
46419 /*
46420 * SYNC Timer Delay definition used to set the expiry time
46421@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46422 dev->net->netdev_ops = &sierra_net_device_ops;
46423
46424 /* change MAC addr to include, ifacenum, and to be unique */
46425- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46426+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46427 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46428
46429 /* we will have to manufacture ethernet headers, prepare template */
46430diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
46431index 8a852b5..668a4b6 100644
46432--- a/drivers/net/virtio_net.c
46433+++ b/drivers/net/virtio_net.c
46434@@ -47,7 +47,7 @@ module_param(gso, bool, 0444);
46435 #define RECEIVE_AVG_WEIGHT 64
46436
46437 /* Minimum alignment for mergeable packet buffers. */
46438-#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
46439+#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
46440
46441 #define VIRTNET_DRIVER_VERSION "1.0.0"
46442
46443diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46444index 77dcf92..549924a 100644
46445--- a/drivers/net/vxlan.c
46446+++ b/drivers/net/vxlan.c
46447@@ -2839,7 +2839,7 @@ nla_put_failure:
46448 return -EMSGSIZE;
46449 }
46450
46451-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46452+static struct rtnl_link_ops vxlan_link_ops = {
46453 .kind = "vxlan",
46454 .maxtype = IFLA_VXLAN_MAX,
46455 .policy = vxlan_policy,
46456@@ -2886,7 +2886,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46457 return NOTIFY_DONE;
46458 }
46459
46460-static struct notifier_block vxlan_notifier_block __read_mostly = {
46461+static struct notifier_block vxlan_notifier_block = {
46462 .notifier_call = vxlan_lowerdev_event,
46463 };
46464
46465diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46466index 5920c99..ff2e4a5 100644
46467--- a/drivers/net/wan/lmc/lmc_media.c
46468+++ b/drivers/net/wan/lmc/lmc_media.c
46469@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46470 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46471
46472 lmc_media_t lmc_ds3_media = {
46473- lmc_ds3_init, /* special media init stuff */
46474- lmc_ds3_default, /* reset to default state */
46475- lmc_ds3_set_status, /* reset status to state provided */
46476- lmc_dummy_set_1, /* set clock source */
46477- lmc_dummy_set2_1, /* set line speed */
46478- lmc_ds3_set_100ft, /* set cable length */
46479- lmc_ds3_set_scram, /* set scrambler */
46480- lmc_ds3_get_link_status, /* get link status */
46481- lmc_dummy_set_1, /* set link status */
46482- lmc_ds3_set_crc_length, /* set CRC length */
46483- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46484- lmc_ds3_watchdog
46485+ .init = lmc_ds3_init, /* special media init stuff */
46486+ .defaults = lmc_ds3_default, /* reset to default state */
46487+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
46488+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
46489+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46490+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46491+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46492+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
46493+ .set_link_status = lmc_dummy_set_1, /* set link status */
46494+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46495+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46496+ .watchdog = lmc_ds3_watchdog
46497 };
46498
46499 lmc_media_t lmc_hssi_media = {
46500- lmc_hssi_init, /* special media init stuff */
46501- lmc_hssi_default, /* reset to default state */
46502- lmc_hssi_set_status, /* reset status to state provided */
46503- lmc_hssi_set_clock, /* set clock source */
46504- lmc_dummy_set2_1, /* set line speed */
46505- lmc_dummy_set_1, /* set cable length */
46506- lmc_dummy_set_1, /* set scrambler */
46507- lmc_hssi_get_link_status, /* get link status */
46508- lmc_hssi_set_link_status, /* set link status */
46509- lmc_hssi_set_crc_length, /* set CRC length */
46510- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46511- lmc_hssi_watchdog
46512+ .init = lmc_hssi_init, /* special media init stuff */
46513+ .defaults = lmc_hssi_default, /* reset to default state */
46514+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
46515+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46516+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46517+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46518+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46519+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
46520+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
46521+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46522+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46523+ .watchdog = lmc_hssi_watchdog
46524 };
46525
46526-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46527- lmc_ssi_default, /* reset to default state */
46528- lmc_ssi_set_status, /* reset status to state provided */
46529- lmc_ssi_set_clock, /* set clock source */
46530- lmc_ssi_set_speed, /* set line speed */
46531- lmc_dummy_set_1, /* set cable length */
46532- lmc_dummy_set_1, /* set scrambler */
46533- lmc_ssi_get_link_status, /* get link status */
46534- lmc_ssi_set_link_status, /* set link status */
46535- lmc_ssi_set_crc_length, /* set CRC length */
46536- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46537- lmc_ssi_watchdog
46538+lmc_media_t lmc_ssi_media = {
46539+ .init = lmc_ssi_init, /* special media init stuff */
46540+ .defaults = lmc_ssi_default, /* reset to default state */
46541+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
46542+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46543+ .set_speed = lmc_ssi_set_speed, /* set line speed */
46544+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46545+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46546+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
46547+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
46548+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46549+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46550+ .watchdog = lmc_ssi_watchdog
46551 };
46552
46553 lmc_media_t lmc_t1_media = {
46554- lmc_t1_init, /* special media init stuff */
46555- lmc_t1_default, /* reset to default state */
46556- lmc_t1_set_status, /* reset status to state provided */
46557- lmc_t1_set_clock, /* set clock source */
46558- lmc_dummy_set2_1, /* set line speed */
46559- lmc_dummy_set_1, /* set cable length */
46560- lmc_dummy_set_1, /* set scrambler */
46561- lmc_t1_get_link_status, /* get link status */
46562- lmc_dummy_set_1, /* set link status */
46563- lmc_t1_set_crc_length, /* set CRC length */
46564- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46565- lmc_t1_watchdog
46566+ .init = lmc_t1_init, /* special media init stuff */
46567+ .defaults = lmc_t1_default, /* reset to default state */
46568+ .set_status = lmc_t1_set_status, /* reset status to state provided */
46569+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
46570+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46571+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46572+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46573+ .get_link_status = lmc_t1_get_link_status, /* get link status */
46574+ .set_link_status = lmc_dummy_set_1, /* set link status */
46575+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46576+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46577+ .watchdog = lmc_t1_watchdog
46578 };
46579
46580 static void
46581diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46582index feacc3b..5bac0de 100644
46583--- a/drivers/net/wan/z85230.c
46584+++ b/drivers/net/wan/z85230.c
46585@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46586
46587 struct z8530_irqhandler z8530_sync =
46588 {
46589- z8530_rx,
46590- z8530_tx,
46591- z8530_status
46592+ .rx = z8530_rx,
46593+ .tx = z8530_tx,
46594+ .status = z8530_status
46595 };
46596
46597 EXPORT_SYMBOL(z8530_sync);
46598@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46599 }
46600
46601 static struct z8530_irqhandler z8530_dma_sync = {
46602- z8530_dma_rx,
46603- z8530_dma_tx,
46604- z8530_dma_status
46605+ .rx = z8530_dma_rx,
46606+ .tx = z8530_dma_tx,
46607+ .status = z8530_dma_status
46608 };
46609
46610 static struct z8530_irqhandler z8530_txdma_sync = {
46611- z8530_rx,
46612- z8530_dma_tx,
46613- z8530_dma_status
46614+ .rx = z8530_rx,
46615+ .tx = z8530_dma_tx,
46616+ .status = z8530_dma_status
46617 };
46618
46619 /**
46620@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46621
46622 struct z8530_irqhandler z8530_nop=
46623 {
46624- z8530_rx_clear,
46625- z8530_tx_clear,
46626- z8530_status_clear
46627+ .rx = z8530_rx_clear,
46628+ .tx = z8530_tx_clear,
46629+ .status = z8530_status_clear
46630 };
46631
46632
46633diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46634index 0b60295..b8bfa5b 100644
46635--- a/drivers/net/wimax/i2400m/rx.c
46636+++ b/drivers/net/wimax/i2400m/rx.c
46637@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46638 if (i2400m->rx_roq == NULL)
46639 goto error_roq_alloc;
46640
46641- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46642+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46643 GFP_KERNEL);
46644 if (rd == NULL) {
46645 result = -ENOMEM;
46646diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46647index 64747d4..17c4cf3 100644
46648--- a/drivers/net/wireless/airo.c
46649+++ b/drivers/net/wireless/airo.c
46650@@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46651 struct airo_info *ai = dev->ml_priv;
46652 int ridcode;
46653 int enabled;
46654- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46655+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46656 unsigned char *iobuf;
46657
46658 /* Only super-user can write RIDs */
46659diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46660index 99b3bfa..9559372 100644
46661--- a/drivers/net/wireless/at76c50x-usb.c
46662+++ b/drivers/net/wireless/at76c50x-usb.c
46663@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46664 }
46665
46666 /* Convert timeout from the DFU status to jiffies */
46667-static inline unsigned long at76_get_timeout(struct dfu_status *s)
46668+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46669 {
46670 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46671 | (s->poll_timeout[1] << 8)
46672diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46673index 7f1bccd..ca2ffca 100644
46674--- a/drivers/net/wireless/ath/ath10k/htc.c
46675+++ b/drivers/net/wireless/ath/ath10k/htc.c
46676@@ -840,7 +840,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46677 /* registered target arrival callback from the HIF layer */
46678 int ath10k_htc_init(struct ath10k *ar)
46679 {
46680- struct ath10k_hif_cb htc_callbacks;
46681+ static struct ath10k_hif_cb htc_callbacks = {
46682+ .rx_completion = ath10k_htc_rx_completion_handler,
46683+ .tx_completion = ath10k_htc_tx_completion_handler,
46684+ };
46685 struct ath10k_htc_ep *ep = NULL;
46686 struct ath10k_htc *htc = &ar->htc;
46687
46688@@ -850,8 +853,6 @@ int ath10k_htc_init(struct ath10k *ar)
46689 ath10k_htc_reset_endpoint_states(htc);
46690
46691 /* setup HIF layer callbacks */
46692- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46693- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46694 htc->ar = ar;
46695
46696 /* Get HIF default pipe for HTC message exchange */
46697diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46698index 4716d33..a688310 100644
46699--- a/drivers/net/wireless/ath/ath10k/htc.h
46700+++ b/drivers/net/wireless/ath/ath10k/htc.h
46701@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46702
46703 struct ath10k_htc_ops {
46704 void (*target_send_suspend_complete)(struct ath10k *ar);
46705-};
46706+} __no_const;
46707
46708 struct ath10k_htc_ep_ops {
46709 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46710 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46711 void (*ep_tx_credits)(struct ath10k *);
46712-};
46713+} __no_const;
46714
46715 /* service connection information */
46716 struct ath10k_htc_svc_conn_req {
46717diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46718index 741b38d..b7ae41b 100644
46719--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46720+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46721@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46722 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46723 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46724
46725- ACCESS_ONCE(ads->ds_link) = i->link;
46726- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46727+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
46728+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46729
46730 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46731 ctl6 = SM(i->keytype, AR_EncrType);
46732@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46733
46734 if ((i->is_first || i->is_last) &&
46735 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46736- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46737+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46738 | set11nTries(i->rates, 1)
46739 | set11nTries(i->rates, 2)
46740 | set11nTries(i->rates, 3)
46741 | (i->dur_update ? AR_DurUpdateEna : 0)
46742 | SM(0, AR_BurstDur);
46743
46744- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46745+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46746 | set11nRate(i->rates, 1)
46747 | set11nRate(i->rates, 2)
46748 | set11nRate(i->rates, 3);
46749 } else {
46750- ACCESS_ONCE(ads->ds_ctl2) = 0;
46751- ACCESS_ONCE(ads->ds_ctl3) = 0;
46752+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46753+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46754 }
46755
46756 if (!i->is_first) {
46757- ACCESS_ONCE(ads->ds_ctl0) = 0;
46758- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46759- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46760+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46761+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46762+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46763 return;
46764 }
46765
46766@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46767 break;
46768 }
46769
46770- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46771+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46772 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46773 | SM(i->txpower, AR_XmitPower)
46774 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46775@@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46776 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46777 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46778
46779- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46780- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46781+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46782+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46783
46784 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46785 return;
46786
46787- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46788+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46789 | set11nPktDurRTSCTS(i->rates, 1);
46790
46791- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46792+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46793 | set11nPktDurRTSCTS(i->rates, 3);
46794
46795- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46796+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46797 | set11nRateFlags(i->rates, 1)
46798 | set11nRateFlags(i->rates, 2)
46799 | set11nRateFlags(i->rates, 3)
46800diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46801index 729ffbf..49f50e3 100644
46802--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46803+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46804@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46805 (i->qcu << AR_TxQcuNum_S) | desc_len;
46806
46807 checksum += val;
46808- ACCESS_ONCE(ads->info) = val;
46809+ ACCESS_ONCE_RW(ads->info) = val;
46810
46811 checksum += i->link;
46812- ACCESS_ONCE(ads->link) = i->link;
46813+ ACCESS_ONCE_RW(ads->link) = i->link;
46814
46815 checksum += i->buf_addr[0];
46816- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46817+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46818 checksum += i->buf_addr[1];
46819- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46820+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46821 checksum += i->buf_addr[2];
46822- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46823+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46824 checksum += i->buf_addr[3];
46825- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46826+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46827
46828 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46829- ACCESS_ONCE(ads->ctl3) = val;
46830+ ACCESS_ONCE_RW(ads->ctl3) = val;
46831 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46832- ACCESS_ONCE(ads->ctl5) = val;
46833+ ACCESS_ONCE_RW(ads->ctl5) = val;
46834 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46835- ACCESS_ONCE(ads->ctl7) = val;
46836+ ACCESS_ONCE_RW(ads->ctl7) = val;
46837 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46838- ACCESS_ONCE(ads->ctl9) = val;
46839+ ACCESS_ONCE_RW(ads->ctl9) = val;
46840
46841 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46842- ACCESS_ONCE(ads->ctl10) = checksum;
46843+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
46844
46845 if (i->is_first || i->is_last) {
46846- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46847+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46848 | set11nTries(i->rates, 1)
46849 | set11nTries(i->rates, 2)
46850 | set11nTries(i->rates, 3)
46851 | (i->dur_update ? AR_DurUpdateEna : 0)
46852 | SM(0, AR_BurstDur);
46853
46854- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46855+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46856 | set11nRate(i->rates, 1)
46857 | set11nRate(i->rates, 2)
46858 | set11nRate(i->rates, 3);
46859 } else {
46860- ACCESS_ONCE(ads->ctl13) = 0;
46861- ACCESS_ONCE(ads->ctl14) = 0;
46862+ ACCESS_ONCE_RW(ads->ctl13) = 0;
46863+ ACCESS_ONCE_RW(ads->ctl14) = 0;
46864 }
46865
46866 ads->ctl20 = 0;
46867@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46868
46869 ctl17 = SM(i->keytype, AR_EncrType);
46870 if (!i->is_first) {
46871- ACCESS_ONCE(ads->ctl11) = 0;
46872- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46873- ACCESS_ONCE(ads->ctl15) = 0;
46874- ACCESS_ONCE(ads->ctl16) = 0;
46875- ACCESS_ONCE(ads->ctl17) = ctl17;
46876- ACCESS_ONCE(ads->ctl18) = 0;
46877- ACCESS_ONCE(ads->ctl19) = 0;
46878+ ACCESS_ONCE_RW(ads->ctl11) = 0;
46879+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46880+ ACCESS_ONCE_RW(ads->ctl15) = 0;
46881+ ACCESS_ONCE_RW(ads->ctl16) = 0;
46882+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46883+ ACCESS_ONCE_RW(ads->ctl18) = 0;
46884+ ACCESS_ONCE_RW(ads->ctl19) = 0;
46885 return;
46886 }
46887
46888- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46889+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46890 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46891 | SM(i->txpower, AR_XmitPower)
46892 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46893@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46894 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46895 ctl12 |= SM(val, AR_PAPRDChainMask);
46896
46897- ACCESS_ONCE(ads->ctl12) = ctl12;
46898- ACCESS_ONCE(ads->ctl17) = ctl17;
46899+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46900+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46901
46902- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46903+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46904 | set11nPktDurRTSCTS(i->rates, 1);
46905
46906- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46907+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46908 | set11nPktDurRTSCTS(i->rates, 3);
46909
46910- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46911+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46912 | set11nRateFlags(i->rates, 1)
46913 | set11nRateFlags(i->rates, 2)
46914 | set11nRateFlags(i->rates, 3)
46915 | SM(i->rtscts_rate, AR_RTSCTSRate);
46916
46917- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46918+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46919 }
46920
46921 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46922diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46923index 0acd4b5..0591c91 100644
46924--- a/drivers/net/wireless/ath/ath9k/hw.h
46925+++ b/drivers/net/wireless/ath/ath9k/hw.h
46926@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
46927
46928 /* ANI */
46929 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46930-};
46931+} __no_const;
46932
46933 /**
46934 * struct ath_spec_scan - parameters for Atheros spectral scan
46935@@ -706,7 +706,7 @@ struct ath_hw_ops {
46936 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46937 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46938 #endif
46939-};
46940+} __no_const;
46941
46942 struct ath_nf_limits {
46943 s16 max;
46944diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46945index 92190da..f3a4c4c 100644
46946--- a/drivers/net/wireless/b43/phy_lp.c
46947+++ b/drivers/net/wireless/b43/phy_lp.c
46948@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46949 {
46950 struct ssb_bus *bus = dev->dev->sdev->bus;
46951
46952- static const struct b206x_channel *chandata = NULL;
46953+ const struct b206x_channel *chandata = NULL;
46954 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46955 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46956 u16 old_comm15, scale;
46957diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46958index dc1d20c..f7a4f06 100644
46959--- a/drivers/net/wireless/iwlegacy/3945-mac.c
46960+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46961@@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46962 */
46963 if (il3945_mod_params.disable_hw_scan) {
46964 D_INFO("Disabling hw_scan\n");
46965- il3945_mac_ops.hw_scan = NULL;
46966+ pax_open_kernel();
46967+ *(void **)&il3945_mac_ops.hw_scan = NULL;
46968+ pax_close_kernel();
46969 }
46970
46971 D_INFO("*** LOAD DRIVER ***\n");
46972diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46973index d2fe259..0c4c682 100644
46974--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46975+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46976@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46977 {
46978 struct iwl_priv *priv = file->private_data;
46979 char buf[64];
46980- int buf_size;
46981+ size_t buf_size;
46982 u32 offset, len;
46983
46984 memset(buf, 0, sizeof(buf));
46985@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46986 struct iwl_priv *priv = file->private_data;
46987
46988 char buf[8];
46989- int buf_size;
46990+ size_t buf_size;
46991 u32 reset_flag;
46992
46993 memset(buf, 0, sizeof(buf));
46994@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46995 {
46996 struct iwl_priv *priv = file->private_data;
46997 char buf[8];
46998- int buf_size;
46999+ size_t buf_size;
47000 int ht40;
47001
47002 memset(buf, 0, sizeof(buf));
47003@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
47004 {
47005 struct iwl_priv *priv = file->private_data;
47006 char buf[8];
47007- int buf_size;
47008+ size_t buf_size;
47009 int value;
47010
47011 memset(buf, 0, sizeof(buf));
47012@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47013 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47014 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47015
47016-static const char *fmt_value = " %-30s %10u\n";
47017-static const char *fmt_hex = " %-30s 0x%02X\n";
47018-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47019-static const char *fmt_header =
47020+static const char fmt_value[] = " %-30s %10u\n";
47021+static const char fmt_hex[] = " %-30s 0x%02X\n";
47022+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47023+static const char fmt_header[] =
47024 "%-32s current cumulative delta max\n";
47025
47026 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47027@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47028 {
47029 struct iwl_priv *priv = file->private_data;
47030 char buf[8];
47031- int buf_size;
47032+ size_t buf_size;
47033 int clear;
47034
47035 memset(buf, 0, sizeof(buf));
47036@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47037 {
47038 struct iwl_priv *priv = file->private_data;
47039 char buf[8];
47040- int buf_size;
47041+ size_t buf_size;
47042 int trace;
47043
47044 memset(buf, 0, sizeof(buf));
47045@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47046 {
47047 struct iwl_priv *priv = file->private_data;
47048 char buf[8];
47049- int buf_size;
47050+ size_t buf_size;
47051 int missed;
47052
47053 memset(buf, 0, sizeof(buf));
47054@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47055
47056 struct iwl_priv *priv = file->private_data;
47057 char buf[8];
47058- int buf_size;
47059+ size_t buf_size;
47060 int plcp;
47061
47062 memset(buf, 0, sizeof(buf));
47063@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47064
47065 struct iwl_priv *priv = file->private_data;
47066 char buf[8];
47067- int buf_size;
47068+ size_t buf_size;
47069 int flush;
47070
47071 memset(buf, 0, sizeof(buf));
47072@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47073
47074 struct iwl_priv *priv = file->private_data;
47075 char buf[8];
47076- int buf_size;
47077+ size_t buf_size;
47078 int rts;
47079
47080 if (!priv->cfg->ht_params)
47081@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47082 {
47083 struct iwl_priv *priv = file->private_data;
47084 char buf[8];
47085- int buf_size;
47086+ size_t buf_size;
47087
47088 memset(buf, 0, sizeof(buf));
47089 buf_size = min(count, sizeof(buf) - 1);
47090@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47091 struct iwl_priv *priv = file->private_data;
47092 u32 event_log_flag;
47093 char buf[8];
47094- int buf_size;
47095+ size_t buf_size;
47096
47097 /* check that the interface is up */
47098 if (!iwl_is_ready(priv))
47099@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47100 struct iwl_priv *priv = file->private_data;
47101 char buf[8];
47102 u32 calib_disabled;
47103- int buf_size;
47104+ size_t buf_size;
47105
47106 memset(buf, 0, sizeof(buf));
47107 buf_size = min(count, sizeof(buf) - 1);
47108diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47109index 6a6df71..eb5c93a 100644
47110--- a/drivers/net/wireless/iwlwifi/dvm/main.c
47111+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47112@@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47113 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47114 {
47115 struct iwl_nvm_data *data = priv->nvm_data;
47116- char *debug_msg;
47117+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47118
47119 if (data->sku_cap_11n_enable &&
47120 !priv->cfg->ht_params) {
47121@@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47122 return -EINVAL;
47123 }
47124
47125- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47126 IWL_DEBUG_INFO(priv, debug_msg,
47127 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47128 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47129diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47130index 295b24c..cb4f823 100644
47131--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47132+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47133@@ -1558,7 +1558,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47134 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47135
47136 char buf[8];
47137- int buf_size;
47138+ size_t buf_size;
47139 u32 reset_flag;
47140
47141 memset(buf, 0, sizeof(buf));
47142@@ -1579,7 +1579,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47143 {
47144 struct iwl_trans *trans = file->private_data;
47145 char buf[8];
47146- int buf_size;
47147+ size_t buf_size;
47148 int csr;
47149
47150 memset(buf, 0, sizeof(buf));
47151diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47152index 9d7a52f..2729a99 100644
47153--- a/drivers/net/wireless/mac80211_hwsim.c
47154+++ b/drivers/net/wireless/mac80211_hwsim.c
47155@@ -2570,20 +2570,20 @@ static int __init init_mac80211_hwsim(void)
47156 if (channels < 1)
47157 return -EINVAL;
47158
47159- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47160- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47161- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47162- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47163- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47164- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47165- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47166- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47167- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47168- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47169- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47170- mac80211_hwsim_assign_vif_chanctx;
47171- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47172- mac80211_hwsim_unassign_vif_chanctx;
47173+ pax_open_kernel();
47174+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47175+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47176+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47177+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47178+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47179+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47180+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47181+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47182+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47183+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47184+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47185+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47186+ pax_close_kernel();
47187
47188 spin_lock_init(&hwsim_radio_lock);
47189 INIT_LIST_HEAD(&hwsim_radios);
47190diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47191index 39d22a1..4ec8612 100644
47192--- a/drivers/net/wireless/rndis_wlan.c
47193+++ b/drivers/net/wireless/rndis_wlan.c
47194@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47195
47196 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47197
47198- if (rts_threshold < 0 || rts_threshold > 2347)
47199+ if (rts_threshold > 2347)
47200 rts_threshold = 2347;
47201
47202 tmp = cpu_to_le32(rts_threshold);
47203diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47204index 5d45a1a..6f5f041 100644
47205--- a/drivers/net/wireless/rt2x00/rt2x00.h
47206+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47207@@ -375,7 +375,7 @@ struct rt2x00_intf {
47208 * for hardware which doesn't support hardware
47209 * sequence counting.
47210 */
47211- atomic_t seqno;
47212+ atomic_unchecked_t seqno;
47213 };
47214
47215 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47216diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47217index 5642ccc..01f03eb 100644
47218--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47219+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47220@@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47221 * sequence counter given by mac80211.
47222 */
47223 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47224- seqno = atomic_add_return(0x10, &intf->seqno);
47225+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47226 else
47227- seqno = atomic_read(&intf->seqno);
47228+ seqno = atomic_read_unchecked(&intf->seqno);
47229
47230 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47231 hdr->seq_ctrl |= cpu_to_le16(seqno);
47232diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47233index b661f896..ddf7d2b 100644
47234--- a/drivers/net/wireless/ti/wl1251/sdio.c
47235+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47236@@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47237
47238 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47239
47240- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47241- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47242+ pax_open_kernel();
47243+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47244+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47245+ pax_close_kernel();
47246
47247 wl1251_info("using dedicated interrupt line");
47248 } else {
47249- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47250- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47251+ pax_open_kernel();
47252+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47253+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47254+ pax_close_kernel();
47255
47256 wl1251_info("using SDIO interrupt");
47257 }
47258diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47259index d50dfac..0a6f5be3 100644
47260--- a/drivers/net/wireless/ti/wl12xx/main.c
47261+++ b/drivers/net/wireless/ti/wl12xx/main.c
47262@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47263 sizeof(wl->conf.mem));
47264
47265 /* read data preparation is only needed by wl127x */
47266- wl->ops->prepare_read = wl127x_prepare_read;
47267+ pax_open_kernel();
47268+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47269+ pax_close_kernel();
47270
47271 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47272 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47273@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47274 sizeof(wl->conf.mem));
47275
47276 /* read data preparation is only needed by wl127x */
47277- wl->ops->prepare_read = wl127x_prepare_read;
47278+ pax_open_kernel();
47279+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47280+ pax_close_kernel();
47281
47282 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47283 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47284diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47285index de5b4fa..7996ec6 100644
47286--- a/drivers/net/wireless/ti/wl18xx/main.c
47287+++ b/drivers/net/wireless/ti/wl18xx/main.c
47288@@ -1900,8 +1900,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47289 }
47290
47291 if (!checksum_param) {
47292- wl18xx_ops.set_rx_csum = NULL;
47293- wl18xx_ops.init_vif = NULL;
47294+ pax_open_kernel();
47295+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47296+ *(void **)&wl18xx_ops.init_vif = NULL;
47297+ pax_close_kernel();
47298 }
47299
47300 /* Enable 11a Band only if we have 5G antennas */
47301diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47302index a912dc0..a8225ba 100644
47303--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47304+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47305@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47306 {
47307 struct zd_usb *usb = urb->context;
47308 struct zd_usb_interrupt *intr = &usb->intr;
47309- int len;
47310+ unsigned int len;
47311 u16 int_num;
47312
47313 ZD_ASSERT(in_interrupt());
47314diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47315index 683671a..4519fc2 100644
47316--- a/drivers/nfc/nfcwilink.c
47317+++ b/drivers/nfc/nfcwilink.c
47318@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47319
47320 static int nfcwilink_probe(struct platform_device *pdev)
47321 {
47322- static struct nfcwilink *drv;
47323+ struct nfcwilink *drv;
47324 int rc;
47325 __u32 protocols;
47326
47327diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47328index d93b2b6..ae50401 100644
47329--- a/drivers/oprofile/buffer_sync.c
47330+++ b/drivers/oprofile/buffer_sync.c
47331@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47332 if (cookie == NO_COOKIE)
47333 offset = pc;
47334 if (cookie == INVALID_COOKIE) {
47335- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47336+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47337 offset = pc;
47338 }
47339 if (cookie != last_cookie) {
47340@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47341 /* add userspace sample */
47342
47343 if (!mm) {
47344- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47345+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47346 return 0;
47347 }
47348
47349 cookie = lookup_dcookie(mm, s->eip, &offset);
47350
47351 if (cookie == INVALID_COOKIE) {
47352- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47353+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47354 return 0;
47355 }
47356
47357@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47358 /* ignore backtraces if failed to add a sample */
47359 if (state == sb_bt_start) {
47360 state = sb_bt_ignore;
47361- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47362+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47363 }
47364 }
47365 release_mm(mm);
47366diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47367index c0cc4e7..44d4e54 100644
47368--- a/drivers/oprofile/event_buffer.c
47369+++ b/drivers/oprofile/event_buffer.c
47370@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47371 }
47372
47373 if (buffer_pos == buffer_size) {
47374- atomic_inc(&oprofile_stats.event_lost_overflow);
47375+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47376 return;
47377 }
47378
47379diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47380index ed2c3ec..deda85a 100644
47381--- a/drivers/oprofile/oprof.c
47382+++ b/drivers/oprofile/oprof.c
47383@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47384 if (oprofile_ops.switch_events())
47385 return;
47386
47387- atomic_inc(&oprofile_stats.multiplex_counter);
47388+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47389 start_switch_worker();
47390 }
47391
47392diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47393index ee2cfce..7f8f699 100644
47394--- a/drivers/oprofile/oprofile_files.c
47395+++ b/drivers/oprofile/oprofile_files.c
47396@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47397
47398 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47399
47400-static ssize_t timeout_read(struct file *file, char __user *buf,
47401+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47402 size_t count, loff_t *offset)
47403 {
47404 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47405diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47406index 59659ce..6c860a0 100644
47407--- a/drivers/oprofile/oprofile_stats.c
47408+++ b/drivers/oprofile/oprofile_stats.c
47409@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47410 cpu_buf->sample_invalid_eip = 0;
47411 }
47412
47413- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47414- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47415- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47416- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47417- atomic_set(&oprofile_stats.multiplex_counter, 0);
47418+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47419+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47420+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47421+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47422+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47423 }
47424
47425
47426diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47427index 1fc622b..8c48fc3 100644
47428--- a/drivers/oprofile/oprofile_stats.h
47429+++ b/drivers/oprofile/oprofile_stats.h
47430@@ -13,11 +13,11 @@
47431 #include <linux/atomic.h>
47432
47433 struct oprofile_stat_struct {
47434- atomic_t sample_lost_no_mm;
47435- atomic_t sample_lost_no_mapping;
47436- atomic_t bt_lost_no_mapping;
47437- atomic_t event_lost_overflow;
47438- atomic_t multiplex_counter;
47439+ atomic_unchecked_t sample_lost_no_mm;
47440+ atomic_unchecked_t sample_lost_no_mapping;
47441+ atomic_unchecked_t bt_lost_no_mapping;
47442+ atomic_unchecked_t event_lost_overflow;
47443+ atomic_unchecked_t multiplex_counter;
47444 };
47445
47446 extern struct oprofile_stat_struct oprofile_stats;
47447diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47448index 3f49345..c750d0b 100644
47449--- a/drivers/oprofile/oprofilefs.c
47450+++ b/drivers/oprofile/oprofilefs.c
47451@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47452
47453 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47454 {
47455- atomic_t *val = file->private_data;
47456- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47457+ atomic_unchecked_t *val = file->private_data;
47458+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47459 }
47460
47461
47462@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47463
47464
47465 int oprofilefs_create_ro_atomic(struct dentry *root,
47466- char const *name, atomic_t *val)
47467+ char const *name, atomic_unchecked_t *val)
47468 {
47469 return __oprofilefs_create_file(root, name,
47470 &atomic_ro_fops, 0444, val);
47471diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47472index 61be1d9..dec05d7 100644
47473--- a/drivers/oprofile/timer_int.c
47474+++ b/drivers/oprofile/timer_int.c
47475@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47476 return NOTIFY_OK;
47477 }
47478
47479-static struct notifier_block __refdata oprofile_cpu_notifier = {
47480+static struct notifier_block oprofile_cpu_notifier = {
47481 .notifier_call = oprofile_cpu_notify,
47482 };
47483
47484diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47485index 92ed045..62d39bd7 100644
47486--- a/drivers/parport/procfs.c
47487+++ b/drivers/parport/procfs.c
47488@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47489
47490 *ppos += len;
47491
47492- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47493+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47494 }
47495
47496 #ifdef CONFIG_PARPORT_1284
47497@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47498
47499 *ppos += len;
47500
47501- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47502+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47503 }
47504 #endif /* IEEE1284.3 support. */
47505
47506diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47507index 8dcccff..35d701d 100644
47508--- a/drivers/pci/hotplug/acpiphp_ibm.c
47509+++ b/drivers/pci/hotplug/acpiphp_ibm.c
47510@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47511 goto init_cleanup;
47512 }
47513
47514- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47515+ pax_open_kernel();
47516+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47517+ pax_close_kernel();
47518 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47519
47520 return retval;
47521diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47522index 7536eef..52dc8fa 100644
47523--- a/drivers/pci/hotplug/cpcihp_generic.c
47524+++ b/drivers/pci/hotplug/cpcihp_generic.c
47525@@ -73,7 +73,6 @@ static u16 port;
47526 static unsigned int enum_bit;
47527 static u8 enum_mask;
47528
47529-static struct cpci_hp_controller_ops generic_hpc_ops;
47530 static struct cpci_hp_controller generic_hpc;
47531
47532 static int __init validate_parameters(void)
47533@@ -139,6 +138,10 @@ static int query_enum(void)
47534 return ((value & enum_mask) == enum_mask);
47535 }
47536
47537+static struct cpci_hp_controller_ops generic_hpc_ops = {
47538+ .query_enum = query_enum,
47539+};
47540+
47541 static int __init cpcihp_generic_init(void)
47542 {
47543 int status;
47544@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47545 pci_dev_put(dev);
47546
47547 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47548- generic_hpc_ops.query_enum = query_enum;
47549 generic_hpc.ops = &generic_hpc_ops;
47550
47551 status = cpci_hp_register_controller(&generic_hpc);
47552diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47553index e8c4a7c..7046f5c 100644
47554--- a/drivers/pci/hotplug/cpcihp_zt5550.c
47555+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47556@@ -59,7 +59,6 @@
47557 /* local variables */
47558 static bool debug;
47559 static bool poll;
47560-static struct cpci_hp_controller_ops zt5550_hpc_ops;
47561 static struct cpci_hp_controller zt5550_hpc;
47562
47563 /* Primary cPCI bus bridge device */
47564@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47565 return 0;
47566 }
47567
47568+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47569+ .query_enum = zt5550_hc_query_enum,
47570+};
47571+
47572 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47573 {
47574 int status;
47575@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47576 dbg("returned from zt5550_hc_config");
47577
47578 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47579- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47580 zt5550_hpc.ops = &zt5550_hpc_ops;
47581 if(!poll) {
47582 zt5550_hpc.irq = hc_dev->irq;
47583 zt5550_hpc.irq_flags = IRQF_SHARED;
47584 zt5550_hpc.dev_id = hc_dev;
47585
47586- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47587- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47588- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47589+ pax_open_kernel();
47590+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47591+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47592+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47593+ pax_open_kernel();
47594 } else {
47595 info("using ENUM# polling mode");
47596 }
47597diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47598index 76ba8a1..20ca857 100644
47599--- a/drivers/pci/hotplug/cpqphp_nvram.c
47600+++ b/drivers/pci/hotplug/cpqphp_nvram.c
47601@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47602
47603 void compaq_nvram_init (void __iomem *rom_start)
47604 {
47605+
47606+#ifndef CONFIG_PAX_KERNEXEC
47607 if (rom_start) {
47608 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47609 }
47610+#endif
47611+
47612 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47613
47614 /* initialize our int15 lock */
47615diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47616index cfa92a9..29539c5 100644
47617--- a/drivers/pci/hotplug/pci_hotplug_core.c
47618+++ b/drivers/pci/hotplug/pci_hotplug_core.c
47619@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47620 return -EINVAL;
47621 }
47622
47623- slot->ops->owner = owner;
47624- slot->ops->mod_name = mod_name;
47625+ pax_open_kernel();
47626+ *(struct module **)&slot->ops->owner = owner;
47627+ *(const char **)&slot->ops->mod_name = mod_name;
47628+ pax_close_kernel();
47629
47630 mutex_lock(&pci_hp_mutex);
47631 /*
47632diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47633index 0e0a2ff..29dff57 100644
47634--- a/drivers/pci/hotplug/pciehp_core.c
47635+++ b/drivers/pci/hotplug/pciehp_core.c
47636@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47637 struct slot *slot = ctrl->slot;
47638 struct hotplug_slot *hotplug = NULL;
47639 struct hotplug_slot_info *info = NULL;
47640- struct hotplug_slot_ops *ops = NULL;
47641+ hotplug_slot_ops_no_const *ops = NULL;
47642 char name[SLOT_NAME_SIZE];
47643 int retval = -ENOMEM;
47644
47645diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
47646index fb02fc2..83dc2c3 100644
47647--- a/drivers/pci/msi.c
47648+++ b/drivers/pci/msi.c
47649@@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
47650 {
47651 struct attribute **msi_attrs;
47652 struct attribute *msi_attr;
47653- struct device_attribute *msi_dev_attr;
47654- struct attribute_group *msi_irq_group;
47655+ device_attribute_no_const *msi_dev_attr;
47656+ attribute_group_no_const *msi_irq_group;
47657 const struct attribute_group **msi_irq_groups;
47658 struct msi_desc *entry;
47659 int ret = -ENOMEM;
47660@@ -589,7 +589,7 @@ error_attrs:
47661 count = 0;
47662 msi_attr = msi_attrs[count];
47663 while (msi_attr) {
47664- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
47665+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
47666 kfree(msi_attr->name);
47667 kfree(msi_dev_attr);
47668 ++count;
47669diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47670index 4e0acef..bd98e31 100644
47671--- a/drivers/pci/pci-sysfs.c
47672+++ b/drivers/pci/pci-sysfs.c
47673@@ -1101,7 +1101,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47674 {
47675 /* allocate attribute structure, piggyback attribute name */
47676 int name_len = write_combine ? 13 : 10;
47677- struct bin_attribute *res_attr;
47678+ bin_attribute_no_const *res_attr;
47679 int retval;
47680
47681 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47682@@ -1286,7 +1286,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47683 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47684 {
47685 int retval;
47686- struct bin_attribute *attr;
47687+ bin_attribute_no_const *attr;
47688
47689 /* If the device has VPD, try to expose it in sysfs. */
47690 if (dev->vpd) {
47691@@ -1333,7 +1333,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47692 {
47693 int retval;
47694 int rom_size = 0;
47695- struct bin_attribute *attr;
47696+ bin_attribute_no_const *attr;
47697
47698 if (!sysfs_initialized)
47699 return -EACCES;
47700diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47701index 6bd0822..35bc2b3 100644
47702--- a/drivers/pci/pci.h
47703+++ b/drivers/pci/pci.h
47704@@ -91,7 +91,7 @@ struct pci_vpd_ops {
47705 struct pci_vpd {
47706 unsigned int len;
47707 const struct pci_vpd_ops *ops;
47708- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47709+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47710 };
47711
47712 int pci_vpd_pci22_init(struct pci_dev *dev);
47713diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47714index e1e7026..d28dd33 100644
47715--- a/drivers/pci/pcie/aspm.c
47716+++ b/drivers/pci/pcie/aspm.c
47717@@ -27,9 +27,9 @@
47718 #define MODULE_PARAM_PREFIX "pcie_aspm."
47719
47720 /* Note: those are not register definitions */
47721-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47722-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47723-#define ASPM_STATE_L1 (4) /* L1 state */
47724+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47725+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47726+#define ASPM_STATE_L1 (4U) /* L1 state */
47727 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47728 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47729
47730diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47731index ef09f5f..49ac62f 100644
47732--- a/drivers/pci/probe.c
47733+++ b/drivers/pci/probe.c
47734@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47735 struct pci_bus_region region, inverted_region;
47736 bool bar_too_big = false, bar_disabled = false;
47737
47738- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47739+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47740
47741 /* No printks while decoding is disabled! */
47742 if (!dev->mmio_always_on) {
47743diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47744index 46d1378..30e452b 100644
47745--- a/drivers/pci/proc.c
47746+++ b/drivers/pci/proc.c
47747@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47748 static int __init pci_proc_init(void)
47749 {
47750 struct pci_dev *dev = NULL;
47751+
47752+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47753+#ifdef CONFIG_GRKERNSEC_PROC_USER
47754+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47755+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47756+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47757+#endif
47758+#else
47759 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47760+#endif
47761 proc_create("devices", 0, proc_bus_pci_dir,
47762 &proc_bus_pci_dev_operations);
47763 proc_initialized = 1;
47764diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47765index 7f3aad0..7d604bb 100644
47766--- a/drivers/platform/chrome/chromeos_laptop.c
47767+++ b/drivers/platform/chrome/chromeos_laptop.c
47768@@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
47769 .callback = chromeos_laptop_dmi_matched, \
47770 .driver_data = (void *)&board_
47771
47772-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
47773+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
47774 {
47775 .ident = "Samsung Series 5 550",
47776 .matches = {
47777diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
47778index 541f951..4dfd598 100644
47779--- a/drivers/platform/x86/alienware-wmi.c
47780+++ b/drivers/platform/x86/alienware-wmi.c
47781@@ -132,7 +132,7 @@ struct wmax_led_args {
47782 } __packed;
47783
47784 static struct platform_device *platform_device;
47785-static struct device_attribute *zone_dev_attrs;
47786+static device_attribute_no_const *zone_dev_attrs;
47787 static struct attribute **zone_attrs;
47788 static struct platform_zone *zone_data;
47789
47790@@ -143,7 +143,7 @@ static struct platform_driver platform_driver = {
47791 }
47792 };
47793
47794-static struct attribute_group zone_attribute_group = {
47795+static attribute_group_no_const zone_attribute_group = {
47796 .name = "rgb_zones",
47797 };
47798
47799diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47800index c5e082f..d6307a0 100644
47801--- a/drivers/platform/x86/asus-wmi.c
47802+++ b/drivers/platform/x86/asus-wmi.c
47803@@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
47804 int err;
47805 u32 retval = -1;
47806
47807+#ifdef CONFIG_GRKERNSEC_KMEM
47808+ return -EPERM;
47809+#endif
47810+
47811 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47812
47813 if (err < 0)
47814@@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
47815 int err;
47816 u32 retval = -1;
47817
47818+#ifdef CONFIG_GRKERNSEC_KMEM
47819+ return -EPERM;
47820+#endif
47821+
47822 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47823 &retval);
47824
47825@@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
47826 union acpi_object *obj;
47827 acpi_status status;
47828
47829+#ifdef CONFIG_GRKERNSEC_KMEM
47830+ return -EPERM;
47831+#endif
47832+
47833 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47834 1, asus->debug.method_id,
47835 &input, &output);
47836diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47837index 62f8030..c7f2a45 100644
47838--- a/drivers/platform/x86/msi-laptop.c
47839+++ b/drivers/platform/x86/msi-laptop.c
47840@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47841
47842 if (!quirks->ec_read_only) {
47843 /* allow userland write sysfs file */
47844- dev_attr_bluetooth.store = store_bluetooth;
47845- dev_attr_wlan.store = store_wlan;
47846- dev_attr_threeg.store = store_threeg;
47847- dev_attr_bluetooth.attr.mode |= S_IWUSR;
47848- dev_attr_wlan.attr.mode |= S_IWUSR;
47849- dev_attr_threeg.attr.mode |= S_IWUSR;
47850+ pax_open_kernel();
47851+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47852+ *(void **)&dev_attr_wlan.store = store_wlan;
47853+ *(void **)&dev_attr_threeg.store = store_threeg;
47854+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47855+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47856+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47857+ pax_close_kernel();
47858 }
47859
47860 /* disable hardware control by fn key */
47861diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47862index 70222f2..8c8ce66 100644
47863--- a/drivers/platform/x86/msi-wmi.c
47864+++ b/drivers/platform/x86/msi-wmi.c
47865@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47866 static void msi_wmi_notify(u32 value, void *context)
47867 {
47868 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47869- static struct key_entry *key;
47870+ struct key_entry *key;
47871 union acpi_object *obj;
47872 acpi_status status;
47873
47874diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47875index 9c5a074..06c976a 100644
47876--- a/drivers/platform/x86/sony-laptop.c
47877+++ b/drivers/platform/x86/sony-laptop.c
47878@@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47879 }
47880
47881 /* High speed charging function */
47882-static struct device_attribute *hsc_handle;
47883+static device_attribute_no_const *hsc_handle;
47884
47885 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47886 struct device_attribute *attr,
47887@@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
47888 }
47889
47890 /* low battery function */
47891-static struct device_attribute *lowbatt_handle;
47892+static device_attribute_no_const *lowbatt_handle;
47893
47894 static ssize_t sony_nc_lowbatt_store(struct device *dev,
47895 struct device_attribute *attr,
47896@@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
47897 }
47898
47899 /* fan speed function */
47900-static struct device_attribute *fan_handle, *hsf_handle;
47901+static device_attribute_no_const *fan_handle, *hsf_handle;
47902
47903 static ssize_t sony_nc_hsfan_store(struct device *dev,
47904 struct device_attribute *attr,
47905@@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
47906 }
47907
47908 /* USB charge function */
47909-static struct device_attribute *uc_handle;
47910+static device_attribute_no_const *uc_handle;
47911
47912 static ssize_t sony_nc_usb_charge_store(struct device *dev,
47913 struct device_attribute *attr,
47914@@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
47915 }
47916
47917 /* Panel ID function */
47918-static struct device_attribute *panel_handle;
47919+static device_attribute_no_const *panel_handle;
47920
47921 static ssize_t sony_nc_panelid_show(struct device *dev,
47922 struct device_attribute *attr, char *buffer)
47923@@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
47924 }
47925
47926 /* smart connect function */
47927-static struct device_attribute *sc_handle;
47928+static device_attribute_no_const *sc_handle;
47929
47930 static ssize_t sony_nc_smart_conn_store(struct device *dev,
47931 struct device_attribute *attr,
47932diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47933index 15e61c1..40a39c7 100644
47934--- a/drivers/platform/x86/thinkpad_acpi.c
47935+++ b/drivers/platform/x86/thinkpad_acpi.c
47936@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
47937 return 0;
47938 }
47939
47940-void static hotkey_mask_warn_incomplete_mask(void)
47941+static void hotkey_mask_warn_incomplete_mask(void)
47942 {
47943 /* log only what the user can fix... */
47944 const u32 wantedmask = hotkey_driver_mask &
47945@@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47946 && !tp_features.bright_unkfw)
47947 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47948 }
47949+}
47950
47951 #undef TPACPI_COMPARE_KEY
47952 #undef TPACPI_MAY_SEND_KEY
47953-}
47954
47955 /*
47956 * Polling driver
47957diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47958index 438d4c7..ca8a2fb 100644
47959--- a/drivers/pnp/pnpbios/bioscalls.c
47960+++ b/drivers/pnp/pnpbios/bioscalls.c
47961@@ -59,7 +59,7 @@ do { \
47962 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47963 } while(0)
47964
47965-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47966+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47967 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47968
47969 /*
47970@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47971
47972 cpu = get_cpu();
47973 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47974+
47975+ pax_open_kernel();
47976 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47977+ pax_close_kernel();
47978
47979 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47980 spin_lock_irqsave(&pnp_bios_lock, flags);
47981@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47982 :"memory");
47983 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47984
47985+ pax_open_kernel();
47986 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47987+ pax_close_kernel();
47988+
47989 put_cpu();
47990
47991 /* If we get here and this is set then the PnP BIOS faulted on us. */
47992@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47993 return status;
47994 }
47995
47996-void pnpbios_calls_init(union pnp_bios_install_struct *header)
47997+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47998 {
47999 int i;
48000
48001@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48002 pnp_bios_callpoint.offset = header->fields.pm16offset;
48003 pnp_bios_callpoint.segment = PNP_CS16;
48004
48005+ pax_open_kernel();
48006+
48007 for_each_possible_cpu(i) {
48008 struct desc_struct *gdt = get_cpu_gdt_table(i);
48009 if (!gdt)
48010@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48011 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48012 (unsigned long)__va(header->fields.pm16dseg));
48013 }
48014+
48015+ pax_close_kernel();
48016 }
48017diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48018index 01712cb..782e822 100644
48019--- a/drivers/pnp/resource.c
48020+++ b/drivers/pnp/resource.c
48021@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48022 return 1;
48023
48024 /* check if the resource is valid */
48025- if (*irq < 0 || *irq > 15)
48026+ if (*irq > 15)
48027 return 0;
48028
48029 /* check if the resource is reserved */
48030@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48031 return 1;
48032
48033 /* check if the resource is valid */
48034- if (*dma < 0 || *dma == 4 || *dma > 7)
48035+ if (*dma == 4 || *dma > 7)
48036 return 0;
48037
48038 /* check if the resource is reserved */
48039diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48040index 0c52e2a..3421ab7 100644
48041--- a/drivers/power/pda_power.c
48042+++ b/drivers/power/pda_power.c
48043@@ -37,7 +37,11 @@ static int polling;
48044
48045 #if IS_ENABLED(CONFIG_USB_PHY)
48046 static struct usb_phy *transceiver;
48047-static struct notifier_block otg_nb;
48048+static int otg_handle_notification(struct notifier_block *nb,
48049+ unsigned long event, void *unused);
48050+static struct notifier_block otg_nb = {
48051+ .notifier_call = otg_handle_notification
48052+};
48053 #endif
48054
48055 static struct regulator *ac_draw;
48056@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48057
48058 #if IS_ENABLED(CONFIG_USB_PHY)
48059 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48060- otg_nb.notifier_call = otg_handle_notification;
48061 ret = usb_register_notifier(transceiver, &otg_nb);
48062 if (ret) {
48063 dev_err(dev, "failure to register otg notifier\n");
48064diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48065index cc439fd..8fa30df 100644
48066--- a/drivers/power/power_supply.h
48067+++ b/drivers/power/power_supply.h
48068@@ -16,12 +16,12 @@ struct power_supply;
48069
48070 #ifdef CONFIG_SYSFS
48071
48072-extern void power_supply_init_attrs(struct device_type *dev_type);
48073+extern void power_supply_init_attrs(void);
48074 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48075
48076 #else
48077
48078-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48079+static inline void power_supply_init_attrs(void) {}
48080 #define power_supply_uevent NULL
48081
48082 #endif /* CONFIG_SYSFS */
48083diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48084index 2660664..75fcb04 100644
48085--- a/drivers/power/power_supply_core.c
48086+++ b/drivers/power/power_supply_core.c
48087@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48088 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48089 EXPORT_SYMBOL_GPL(power_supply_notifier);
48090
48091-static struct device_type power_supply_dev_type;
48092+extern const struct attribute_group *power_supply_attr_groups[];
48093+static struct device_type power_supply_dev_type = {
48094+ .groups = power_supply_attr_groups,
48095+};
48096
48097 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48098 struct power_supply *supply)
48099@@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48100 return PTR_ERR(power_supply_class);
48101
48102 power_supply_class->dev_uevent = power_supply_uevent;
48103- power_supply_init_attrs(&power_supply_dev_type);
48104+ power_supply_init_attrs();
48105
48106 return 0;
48107 }
48108diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48109index 44420d1..967126e 100644
48110--- a/drivers/power/power_supply_sysfs.c
48111+++ b/drivers/power/power_supply_sysfs.c
48112@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48113 .is_visible = power_supply_attr_is_visible,
48114 };
48115
48116-static const struct attribute_group *power_supply_attr_groups[] = {
48117+const struct attribute_group *power_supply_attr_groups[] = {
48118 &power_supply_attr_group,
48119 NULL,
48120 };
48121
48122-void power_supply_init_attrs(struct device_type *dev_type)
48123+void power_supply_init_attrs(void)
48124 {
48125 int i;
48126
48127- dev_type->groups = power_supply_attr_groups;
48128-
48129 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48130 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48131 }
48132diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48133index 84419af..268ede8 100644
48134--- a/drivers/powercap/powercap_sys.c
48135+++ b/drivers/powercap/powercap_sys.c
48136@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48137 struct device_attribute name_attr;
48138 };
48139
48140+static ssize_t show_constraint_name(struct device *dev,
48141+ struct device_attribute *dev_attr,
48142+ char *buf);
48143+
48144 static struct powercap_constraint_attr
48145- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48146+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48147+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48148+ .power_limit_attr = {
48149+ .attr = {
48150+ .name = NULL,
48151+ .mode = S_IWUSR | S_IRUGO
48152+ },
48153+ .show = show_constraint_power_limit_uw,
48154+ .store = store_constraint_power_limit_uw
48155+ },
48156+
48157+ .time_window_attr = {
48158+ .attr = {
48159+ .name = NULL,
48160+ .mode = S_IWUSR | S_IRUGO
48161+ },
48162+ .show = show_constraint_time_window_us,
48163+ .store = store_constraint_time_window_us
48164+ },
48165+
48166+ .max_power_attr = {
48167+ .attr = {
48168+ .name = NULL,
48169+ .mode = S_IRUGO
48170+ },
48171+ .show = show_constraint_max_power_uw,
48172+ .store = NULL
48173+ },
48174+
48175+ .min_power_attr = {
48176+ .attr = {
48177+ .name = NULL,
48178+ .mode = S_IRUGO
48179+ },
48180+ .show = show_constraint_min_power_uw,
48181+ .store = NULL
48182+ },
48183+
48184+ .max_time_window_attr = {
48185+ .attr = {
48186+ .name = NULL,
48187+ .mode = S_IRUGO
48188+ },
48189+ .show = show_constraint_max_time_window_us,
48190+ .store = NULL
48191+ },
48192+
48193+ .min_time_window_attr = {
48194+ .attr = {
48195+ .name = NULL,
48196+ .mode = S_IRUGO
48197+ },
48198+ .show = show_constraint_min_time_window_us,
48199+ .store = NULL
48200+ },
48201+
48202+ .name_attr = {
48203+ .attr = {
48204+ .name = NULL,
48205+ .mode = S_IRUGO
48206+ },
48207+ .show = show_constraint_name,
48208+ .store = NULL
48209+ }
48210+ }
48211+};
48212
48213 /* A list of powercap control_types */
48214 static LIST_HEAD(powercap_cntrl_list);
48215@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48216 }
48217
48218 static int create_constraint_attribute(int id, const char *name,
48219- int mode,
48220- struct device_attribute *dev_attr,
48221- ssize_t (*show)(struct device *,
48222- struct device_attribute *, char *),
48223- ssize_t (*store)(struct device *,
48224- struct device_attribute *,
48225- const char *, size_t)
48226- )
48227+ struct device_attribute *dev_attr)
48228 {
48229+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48230
48231- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48232- id, name);
48233- if (!dev_attr->attr.name)
48234+ if (!name)
48235 return -ENOMEM;
48236- dev_attr->attr.mode = mode;
48237- dev_attr->show = show;
48238- dev_attr->store = store;
48239+
48240+ pax_open_kernel();
48241+ *(const char **)&dev_attr->attr.name = name;
48242+ pax_close_kernel();
48243
48244 return 0;
48245 }
48246@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48247
48248 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48249 ret = create_constraint_attribute(i, "power_limit_uw",
48250- S_IWUSR | S_IRUGO,
48251- &constraint_attrs[i].power_limit_attr,
48252- show_constraint_power_limit_uw,
48253- store_constraint_power_limit_uw);
48254+ &constraint_attrs[i].power_limit_attr);
48255 if (ret)
48256 goto err_alloc;
48257 ret = create_constraint_attribute(i, "time_window_us",
48258- S_IWUSR | S_IRUGO,
48259- &constraint_attrs[i].time_window_attr,
48260- show_constraint_time_window_us,
48261- store_constraint_time_window_us);
48262+ &constraint_attrs[i].time_window_attr);
48263 if (ret)
48264 goto err_alloc;
48265- ret = create_constraint_attribute(i, "name", S_IRUGO,
48266- &constraint_attrs[i].name_attr,
48267- show_constraint_name,
48268- NULL);
48269+ ret = create_constraint_attribute(i, "name",
48270+ &constraint_attrs[i].name_attr);
48271 if (ret)
48272 goto err_alloc;
48273- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48274- &constraint_attrs[i].max_power_attr,
48275- show_constraint_max_power_uw,
48276- NULL);
48277+ ret = create_constraint_attribute(i, "max_power_uw",
48278+ &constraint_attrs[i].max_power_attr);
48279 if (ret)
48280 goto err_alloc;
48281- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48282- &constraint_attrs[i].min_power_attr,
48283- show_constraint_min_power_uw,
48284- NULL);
48285+ ret = create_constraint_attribute(i, "min_power_uw",
48286+ &constraint_attrs[i].min_power_attr);
48287 if (ret)
48288 goto err_alloc;
48289 ret = create_constraint_attribute(i, "max_time_window_us",
48290- S_IRUGO,
48291- &constraint_attrs[i].max_time_window_attr,
48292- show_constraint_max_time_window_us,
48293- NULL);
48294+ &constraint_attrs[i].max_time_window_attr);
48295 if (ret)
48296 goto err_alloc;
48297 ret = create_constraint_attribute(i, "min_time_window_us",
48298- S_IRUGO,
48299- &constraint_attrs[i].min_time_window_attr,
48300- show_constraint_min_time_window_us,
48301- NULL);
48302+ &constraint_attrs[i].min_time_window_attr);
48303 if (ret)
48304 goto err_alloc;
48305
48306@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48307 power_zone->zone_dev_attrs[count++] =
48308 &dev_attr_max_energy_range_uj.attr;
48309 if (power_zone->ops->get_energy_uj) {
48310+ pax_open_kernel();
48311 if (power_zone->ops->reset_energy_uj)
48312- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48313+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48314 else
48315- dev_attr_energy_uj.attr.mode = S_IRUGO;
48316+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48317+ pax_close_kernel();
48318 power_zone->zone_dev_attrs[count++] =
48319 &dev_attr_energy_uj.attr;
48320 }
48321diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
48322index 9c5d414..c7900ce 100644
48323--- a/drivers/ptp/ptp_private.h
48324+++ b/drivers/ptp/ptp_private.h
48325@@ -51,7 +51,7 @@ struct ptp_clock {
48326 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
48327 wait_queue_head_t tsev_wq;
48328 int defunct; /* tells readers to go away when clock is being removed */
48329- struct device_attribute *pin_dev_attr;
48330+ device_attribute_no_const *pin_dev_attr;
48331 struct attribute **pin_attr;
48332 struct attribute_group pin_attr_group;
48333 };
48334diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
48335index 302e626..12579af 100644
48336--- a/drivers/ptp/ptp_sysfs.c
48337+++ b/drivers/ptp/ptp_sysfs.c
48338@@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
48339 goto no_pin_attr;
48340
48341 for (i = 0; i < n_pins; i++) {
48342- struct device_attribute *da = &ptp->pin_dev_attr[i];
48343+ device_attribute_no_const *da = &ptp->pin_dev_attr[i];
48344 sysfs_attr_init(&da->attr);
48345 da->attr.name = info->pin_config[i].name;
48346 da->attr.mode = 0644;
48347diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48348index 9a09f3c..450b523 100644
48349--- a/drivers/regulator/core.c
48350+++ b/drivers/regulator/core.c
48351@@ -3380,7 +3380,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48352 {
48353 const struct regulation_constraints *constraints = NULL;
48354 const struct regulator_init_data *init_data;
48355- static atomic_t regulator_no = ATOMIC_INIT(0);
48356+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48357 struct regulator_dev *rdev;
48358 struct device *dev;
48359 int ret, i;
48360@@ -3450,7 +3450,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48361 rdev->dev.of_node = config->of_node;
48362 rdev->dev.parent = dev;
48363 dev_set_name(&rdev->dev, "regulator.%d",
48364- atomic_inc_return(&regulator_no) - 1);
48365+ atomic_inc_return_unchecked(&regulator_no) - 1);
48366 ret = device_register(&rdev->dev);
48367 if (ret != 0) {
48368 put_device(&rdev->dev);
48369diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48370index 2fc4111..6aa88ca 100644
48371--- a/drivers/regulator/max8660.c
48372+++ b/drivers/regulator/max8660.c
48373@@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
48374 max8660->shadow_regs[MAX8660_OVER1] = 5;
48375 } else {
48376 /* Otherwise devices can be toggled via software */
48377- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48378- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48379+ pax_open_kernel();
48380+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48381+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48382+ pax_close_kernel();
48383 }
48384
48385 /*
48386diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48387index dbedf17..18ff6b7 100644
48388--- a/drivers/regulator/max8973-regulator.c
48389+++ b/drivers/regulator/max8973-regulator.c
48390@@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
48391 if (!pdata || !pdata->enable_ext_control) {
48392 max->desc.enable_reg = MAX8973_VOUT;
48393 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48394- max->ops.enable = regulator_enable_regmap;
48395- max->ops.disable = regulator_disable_regmap;
48396- max->ops.is_enabled = regulator_is_enabled_regmap;
48397+ pax_open_kernel();
48398+ *(void **)&max->ops.enable = regulator_enable_regmap;
48399+ *(void **)&max->ops.disable = regulator_disable_regmap;
48400+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48401+ pax_close_kernel();
48402 }
48403
48404 if (pdata) {
48405diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48406index f374fa5..26f0683 100644
48407--- a/drivers/regulator/mc13892-regulator.c
48408+++ b/drivers/regulator/mc13892-regulator.c
48409@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48410 }
48411 mc13xxx_unlock(mc13892);
48412
48413- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48414+ pax_open_kernel();
48415+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48416 = mc13892_vcam_set_mode;
48417- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48418+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48419 = mc13892_vcam_get_mode;
48420+ pax_close_kernel();
48421
48422 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48423 ARRAY_SIZE(mc13892_regulators));
48424diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48425index 0963c93..ea29cce 100644
48426--- a/drivers/rtc/rtc-cmos.c
48427+++ b/drivers/rtc/rtc-cmos.c
48428@@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48429 hpet_rtc_timer_init();
48430
48431 /* export at least the first block of NVRAM */
48432- nvram.size = address_space - NVRAM_OFFSET;
48433+ pax_open_kernel();
48434+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48435+ pax_close_kernel();
48436 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48437 if (retval < 0) {
48438 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48439diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48440index d049393..bb20be0 100644
48441--- a/drivers/rtc/rtc-dev.c
48442+++ b/drivers/rtc/rtc-dev.c
48443@@ -16,6 +16,7 @@
48444 #include <linux/module.h>
48445 #include <linux/rtc.h>
48446 #include <linux/sched.h>
48447+#include <linux/grsecurity.h>
48448 #include "rtc-core.h"
48449
48450 static dev_t rtc_devt;
48451@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48452 if (copy_from_user(&tm, uarg, sizeof(tm)))
48453 return -EFAULT;
48454
48455+ gr_log_timechange();
48456+
48457 return rtc_set_time(rtc, &tm);
48458
48459 case RTC_PIE_ON:
48460diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48461index f03d5ba..8325bf6 100644
48462--- a/drivers/rtc/rtc-ds1307.c
48463+++ b/drivers/rtc/rtc-ds1307.c
48464@@ -107,7 +107,7 @@ struct ds1307 {
48465 u8 offset; /* register's offset */
48466 u8 regs[11];
48467 u16 nvram_offset;
48468- struct bin_attribute *nvram;
48469+ bin_attribute_no_const *nvram;
48470 enum ds_type type;
48471 unsigned long flags;
48472 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48473diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48474index 11880c1..b823aa4 100644
48475--- a/drivers/rtc/rtc-m48t59.c
48476+++ b/drivers/rtc/rtc-m48t59.c
48477@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48478 if (IS_ERR(m48t59->rtc))
48479 return PTR_ERR(m48t59->rtc);
48480
48481- m48t59_nvram_attr.size = pdata->offset;
48482+ pax_open_kernel();
48483+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48484+ pax_close_kernel();
48485
48486 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48487 if (ret)
48488diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48489index 14b5f8d..cc9bd26 100644
48490--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48491+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48492@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48493 for (bit = 0; bit < 8; bit++) {
48494
48495 if ((pci_status[i] & (0x1 << bit)) != 0) {
48496- static const char *s;
48497+ const char *s;
48498
48499 s = pci_status_strings[bit];
48500 if (i == 7/*TARG*/ && bit == 3)
48501@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48502
48503 for (bit = 0; bit < 8; bit++) {
48504
48505- if ((split_status[i] & (0x1 << bit)) != 0) {
48506- static const char *s;
48507-
48508- s = split_status_strings[bit];
48509- printk(s, ahd_name(ahd),
48510+ if ((split_status[i] & (0x1 << bit)) != 0)
48511+ printk(split_status_strings[bit], ahd_name(ahd),
48512 split_status_source[i]);
48513- }
48514
48515 if (i > 1)
48516 continue;
48517
48518- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48519- static const char *s;
48520-
48521- s = split_status_strings[bit];
48522- printk(s, ahd_name(ahd), "SG");
48523- }
48524+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
48525+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
48526 }
48527 }
48528 /*
48529diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48530index e693af6..2e525b6 100644
48531--- a/drivers/scsi/bfa/bfa_fcpim.h
48532+++ b/drivers/scsi/bfa/bfa_fcpim.h
48533@@ -36,7 +36,7 @@ struct bfa_iotag_s {
48534
48535 struct bfa_itn_s {
48536 bfa_isr_func_t isr;
48537-};
48538+} __no_const;
48539
48540 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48541 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48542diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48543index a3ab5cc..8143622 100644
48544--- a/drivers/scsi/bfa/bfa_fcs.c
48545+++ b/drivers/scsi/bfa/bfa_fcs.c
48546@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48547 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48548
48549 static struct bfa_fcs_mod_s fcs_modules[] = {
48550- { bfa_fcs_port_attach, NULL, NULL },
48551- { bfa_fcs_uf_attach, NULL, NULL },
48552- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48553- bfa_fcs_fabric_modexit },
48554+ {
48555+ .attach = bfa_fcs_port_attach,
48556+ .modinit = NULL,
48557+ .modexit = NULL
48558+ },
48559+ {
48560+ .attach = bfa_fcs_uf_attach,
48561+ .modinit = NULL,
48562+ .modexit = NULL
48563+ },
48564+ {
48565+ .attach = bfa_fcs_fabric_attach,
48566+ .modinit = bfa_fcs_fabric_modinit,
48567+ .modexit = bfa_fcs_fabric_modexit
48568+ },
48569 };
48570
48571 /*
48572diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48573index ff75ef8..2dfe00a 100644
48574--- a/drivers/scsi/bfa/bfa_fcs_lport.c
48575+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48576@@ -89,15 +89,26 @@ static struct {
48577 void (*offline) (struct bfa_fcs_lport_s *port);
48578 } __port_action[] = {
48579 {
48580- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48581- bfa_fcs_lport_unknown_offline}, {
48582- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48583- bfa_fcs_lport_fab_offline}, {
48584- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48585- bfa_fcs_lport_n2n_offline}, {
48586- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48587- bfa_fcs_lport_loop_offline},
48588- };
48589+ .init = bfa_fcs_lport_unknown_init,
48590+ .online = bfa_fcs_lport_unknown_online,
48591+ .offline = bfa_fcs_lport_unknown_offline
48592+ },
48593+ {
48594+ .init = bfa_fcs_lport_fab_init,
48595+ .online = bfa_fcs_lport_fab_online,
48596+ .offline = bfa_fcs_lport_fab_offline
48597+ },
48598+ {
48599+ .init = bfa_fcs_lport_n2n_init,
48600+ .online = bfa_fcs_lport_n2n_online,
48601+ .offline = bfa_fcs_lport_n2n_offline
48602+ },
48603+ {
48604+ .init = bfa_fcs_lport_loop_init,
48605+ .online = bfa_fcs_lport_loop_online,
48606+ .offline = bfa_fcs_lport_loop_offline
48607+ },
48608+};
48609
48610 /*
48611 * fcs_port_sm FCS logical port state machine
48612diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48613index 2e28392..9d865b6 100644
48614--- a/drivers/scsi/bfa/bfa_ioc.h
48615+++ b/drivers/scsi/bfa/bfa_ioc.h
48616@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48617 bfa_ioc_disable_cbfn_t disable_cbfn;
48618 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48619 bfa_ioc_reset_cbfn_t reset_cbfn;
48620-};
48621+} __no_const;
48622
48623 /*
48624 * IOC event notification mechanism.
48625@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48626 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48627 enum bfi_ioc_state fwstate);
48628 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48629-};
48630+} __no_const;
48631
48632 /*
48633 * Queue element to wait for room in request queue. FIFO order is
48634diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48635index a14c784..6de6790 100644
48636--- a/drivers/scsi/bfa/bfa_modules.h
48637+++ b/drivers/scsi/bfa/bfa_modules.h
48638@@ -78,12 +78,12 @@ enum {
48639 \
48640 extern struct bfa_module_s hal_mod_ ## __mod; \
48641 struct bfa_module_s hal_mod_ ## __mod = { \
48642- bfa_ ## __mod ## _meminfo, \
48643- bfa_ ## __mod ## _attach, \
48644- bfa_ ## __mod ## _detach, \
48645- bfa_ ## __mod ## _start, \
48646- bfa_ ## __mod ## _stop, \
48647- bfa_ ## __mod ## _iocdisable, \
48648+ .meminfo = bfa_ ## __mod ## _meminfo, \
48649+ .attach = bfa_ ## __mod ## _attach, \
48650+ .detach = bfa_ ## __mod ## _detach, \
48651+ .start = bfa_ ## __mod ## _start, \
48652+ .stop = bfa_ ## __mod ## _stop, \
48653+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
48654 }
48655
48656 #define BFA_CACHELINE_SZ (256)
48657diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48658index 045c4e1..13de803 100644
48659--- a/drivers/scsi/fcoe/fcoe_sysfs.c
48660+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48661@@ -33,8 +33,8 @@
48662 */
48663 #include "libfcoe.h"
48664
48665-static atomic_t ctlr_num;
48666-static atomic_t fcf_num;
48667+static atomic_unchecked_t ctlr_num;
48668+static atomic_unchecked_t fcf_num;
48669
48670 /*
48671 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48672@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48673 if (!ctlr)
48674 goto out;
48675
48676- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48677+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48678 ctlr->f = f;
48679 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48680 INIT_LIST_HEAD(&ctlr->fcfs);
48681@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48682 fcf->dev.parent = &ctlr->dev;
48683 fcf->dev.bus = &fcoe_bus_type;
48684 fcf->dev.type = &fcoe_fcf_device_type;
48685- fcf->id = atomic_inc_return(&fcf_num) - 1;
48686+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48687 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48688
48689 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48690@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48691 {
48692 int error;
48693
48694- atomic_set(&ctlr_num, 0);
48695- atomic_set(&fcf_num, 0);
48696+ atomic_set_unchecked(&ctlr_num, 0);
48697+ atomic_set_unchecked(&fcf_num, 0);
48698
48699 error = bus_register(&fcoe_bus_type);
48700 if (error)
48701diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48702index 3cbb57a..95e47a3 100644
48703--- a/drivers/scsi/hosts.c
48704+++ b/drivers/scsi/hosts.c
48705@@ -42,7 +42,7 @@
48706 #include "scsi_logging.h"
48707
48708
48709-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48710+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48711
48712
48713 static void scsi_host_cls_release(struct device *dev)
48714@@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48715 * subtract one because we increment first then return, but we need to
48716 * know what the next host number was before increment
48717 */
48718- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48719+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48720 shost->dma_channel = 0xff;
48721
48722 /* These three are default values which can be overridden */
48723diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48724index fda6cf1..7a6b5d8 100644
48725--- a/drivers/scsi/hpsa.c
48726+++ b/drivers/scsi/hpsa.c
48727@@ -699,10 +699,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48728 unsigned long flags;
48729
48730 if (h->transMethod & CFGTBL_Trans_io_accel1)
48731- return h->access.command_completed(h, q);
48732+ return h->access->command_completed(h, q);
48733
48734 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48735- return h->access.command_completed(h, q);
48736+ return h->access->command_completed(h, q);
48737
48738 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48739 a = rq->head[rq->current_entry];
48740@@ -5460,7 +5460,7 @@ static void start_io(struct ctlr_info *h)
48741 while (!list_empty(&h->reqQ)) {
48742 c = list_entry(h->reqQ.next, struct CommandList, list);
48743 /* can't do anything if fifo is full */
48744- if ((h->access.fifo_full(h))) {
48745+ if ((h->access->fifo_full(h))) {
48746 h->fifo_recently_full = 1;
48747 dev_warn(&h->pdev->dev, "fifo full\n");
48748 break;
48749@@ -5484,7 +5484,7 @@ static void start_io(struct ctlr_info *h)
48750
48751 /* Tell the controller execute command */
48752 spin_unlock_irqrestore(&h->lock, flags);
48753- h->access.submit_command(h, c);
48754+ h->access->submit_command(h, c);
48755 spin_lock_irqsave(&h->lock, flags);
48756 }
48757 spin_unlock_irqrestore(&h->lock, flags);
48758@@ -5492,17 +5492,17 @@ static void start_io(struct ctlr_info *h)
48759
48760 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48761 {
48762- return h->access.command_completed(h, q);
48763+ return h->access->command_completed(h, q);
48764 }
48765
48766 static inline bool interrupt_pending(struct ctlr_info *h)
48767 {
48768- return h->access.intr_pending(h);
48769+ return h->access->intr_pending(h);
48770 }
48771
48772 static inline long interrupt_not_for_us(struct ctlr_info *h)
48773 {
48774- return (h->access.intr_pending(h) == 0) ||
48775+ return (h->access->intr_pending(h) == 0) ||
48776 (h->interrupts_enabled == 0);
48777 }
48778
48779@@ -6456,7 +6456,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48780 if (prod_index < 0)
48781 return -ENODEV;
48782 h->product_name = products[prod_index].product_name;
48783- h->access = *(products[prod_index].access);
48784+ h->access = products[prod_index].access;
48785
48786 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48787 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48788@@ -6735,7 +6735,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48789 {
48790 unsigned long flags;
48791
48792- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48793+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48794 spin_lock_irqsave(&h->lock, flags);
48795 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48796 spin_unlock_irqrestore(&h->lock, flags);
48797@@ -6963,7 +6963,7 @@ reinit_after_soft_reset:
48798 }
48799
48800 /* make sure the board interrupts are off */
48801- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48802+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48803
48804 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48805 goto clean2;
48806@@ -6998,7 +6998,7 @@ reinit_after_soft_reset:
48807 * fake ones to scoop up any residual completions.
48808 */
48809 spin_lock_irqsave(&h->lock, flags);
48810- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48811+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48812 spin_unlock_irqrestore(&h->lock, flags);
48813 free_irqs(h);
48814 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48815@@ -7017,9 +7017,9 @@ reinit_after_soft_reset:
48816 dev_info(&h->pdev->dev, "Board READY.\n");
48817 dev_info(&h->pdev->dev,
48818 "Waiting for stale completions to drain.\n");
48819- h->access.set_intr_mask(h, HPSA_INTR_ON);
48820+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48821 msleep(10000);
48822- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48823+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48824
48825 rc = controller_reset_failed(h->cfgtable);
48826 if (rc)
48827@@ -7045,7 +7045,7 @@ reinit_after_soft_reset:
48828 h->drv_req_rescan = 0;
48829
48830 /* Turn the interrupts on so we can service requests */
48831- h->access.set_intr_mask(h, HPSA_INTR_ON);
48832+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48833
48834 hpsa_hba_inquiry(h);
48835 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48836@@ -7114,7 +7114,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48837 * To write all data in the battery backed cache to disks
48838 */
48839 hpsa_flush_cache(h);
48840- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48841+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48842 hpsa_free_irqs_and_disable_msix(h);
48843 }
48844
48845@@ -7232,7 +7232,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
48846 CFGTBL_Trans_enable_directed_msix |
48847 (trans_support & (CFGTBL_Trans_io_accel1 |
48848 CFGTBL_Trans_io_accel2));
48849- struct access_method access = SA5_performant_access;
48850+ struct access_method *access = &SA5_performant_access;
48851
48852 /* This is a bit complicated. There are 8 registers on
48853 * the controller which we write to to tell it 8 different
48854@@ -7297,12 +7297,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
48855 * enable outbound interrupt coalescing in accelerator mode;
48856 */
48857 if (trans_support & CFGTBL_Trans_io_accel1) {
48858- access = SA5_ioaccel_mode1_access;
48859+ access = &SA5_ioaccel_mode1_access;
48860 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
48861 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
48862 } else {
48863 if (trans_support & CFGTBL_Trans_io_accel2) {
48864- access = SA5_ioaccel_mode2_access;
48865+ access = &SA5_ioaccel_mode2_access;
48866 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
48867 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
48868 }
48869diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48870index 44235a2..962e91b 100644
48871--- a/drivers/scsi/hpsa.h
48872+++ b/drivers/scsi/hpsa.h
48873@@ -128,7 +128,7 @@ struct ctlr_info {
48874 unsigned int msix_vector;
48875 unsigned int msi_vector;
48876 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48877- struct access_method access;
48878+ struct access_method *access;
48879 char hba_mode_enabled;
48880
48881 /* queue and queue Info */
48882@@ -541,35 +541,35 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
48883 }
48884
48885 static struct access_method SA5_access = {
48886- SA5_submit_command,
48887- SA5_intr_mask,
48888- SA5_fifo_full,
48889- SA5_intr_pending,
48890- SA5_completed,
48891+ .submit_command = SA5_submit_command,
48892+ .set_intr_mask = SA5_intr_mask,
48893+ .fifo_full = SA5_fifo_full,
48894+ .intr_pending = SA5_intr_pending,
48895+ .command_completed = SA5_completed,
48896 };
48897
48898 static struct access_method SA5_ioaccel_mode1_access = {
48899- SA5_submit_command,
48900- SA5_performant_intr_mask,
48901- SA5_fifo_full,
48902- SA5_ioaccel_mode1_intr_pending,
48903- SA5_ioaccel_mode1_completed,
48904+ .submit_command = SA5_submit_command,
48905+ .set_intr_mask = SA5_performant_intr_mask,
48906+ .fifo_full = SA5_fifo_full,
48907+ .intr_pending = SA5_ioaccel_mode1_intr_pending,
48908+ .command_completed = SA5_ioaccel_mode1_completed,
48909 };
48910
48911 static struct access_method SA5_ioaccel_mode2_access = {
48912- SA5_submit_command_ioaccel2,
48913- SA5_performant_intr_mask,
48914- SA5_fifo_full,
48915- SA5_performant_intr_pending,
48916- SA5_performant_completed,
48917+ .submit_command = SA5_submit_command_ioaccel2,
48918+ .set_intr_mask = SA5_performant_intr_mask,
48919+ .fifo_full = SA5_fifo_full,
48920+ .intr_pending = SA5_performant_intr_pending,
48921+ .command_completed = SA5_performant_completed,
48922 };
48923
48924 static struct access_method SA5_performant_access = {
48925- SA5_submit_command,
48926- SA5_performant_intr_mask,
48927- SA5_fifo_full,
48928- SA5_performant_intr_pending,
48929- SA5_performant_completed,
48930+ .submit_command = SA5_submit_command,
48931+ .set_intr_mask = SA5_performant_intr_mask,
48932+ .fifo_full = SA5_fifo_full,
48933+ .intr_pending = SA5_performant_intr_pending,
48934+ .command_completed = SA5_performant_completed,
48935 };
48936
48937 struct board_type {
48938diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48939index 1b3a094..068e683 100644
48940--- a/drivers/scsi/libfc/fc_exch.c
48941+++ b/drivers/scsi/libfc/fc_exch.c
48942@@ -101,12 +101,12 @@ struct fc_exch_mgr {
48943 u16 pool_max_index;
48944
48945 struct {
48946- atomic_t no_free_exch;
48947- atomic_t no_free_exch_xid;
48948- atomic_t xid_not_found;
48949- atomic_t xid_busy;
48950- atomic_t seq_not_found;
48951- atomic_t non_bls_resp;
48952+ atomic_unchecked_t no_free_exch;
48953+ atomic_unchecked_t no_free_exch_xid;
48954+ atomic_unchecked_t xid_not_found;
48955+ atomic_unchecked_t xid_busy;
48956+ atomic_unchecked_t seq_not_found;
48957+ atomic_unchecked_t non_bls_resp;
48958 } stats;
48959 };
48960
48961@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48962 /* allocate memory for exchange */
48963 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48964 if (!ep) {
48965- atomic_inc(&mp->stats.no_free_exch);
48966+ atomic_inc_unchecked(&mp->stats.no_free_exch);
48967 goto out;
48968 }
48969 memset(ep, 0, sizeof(*ep));
48970@@ -874,7 +874,7 @@ out:
48971 return ep;
48972 err:
48973 spin_unlock_bh(&pool->lock);
48974- atomic_inc(&mp->stats.no_free_exch_xid);
48975+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48976 mempool_free(ep, mp->ep_pool);
48977 return NULL;
48978 }
48979@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48980 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48981 ep = fc_exch_find(mp, xid);
48982 if (!ep) {
48983- atomic_inc(&mp->stats.xid_not_found);
48984+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48985 reject = FC_RJT_OX_ID;
48986 goto out;
48987 }
48988@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48989 ep = fc_exch_find(mp, xid);
48990 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48991 if (ep) {
48992- atomic_inc(&mp->stats.xid_busy);
48993+ atomic_inc_unchecked(&mp->stats.xid_busy);
48994 reject = FC_RJT_RX_ID;
48995 goto rel;
48996 }
48997@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48998 }
48999 xid = ep->xid; /* get our XID */
49000 } else if (!ep) {
49001- atomic_inc(&mp->stats.xid_not_found);
49002+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49003 reject = FC_RJT_RX_ID; /* XID not found */
49004 goto out;
49005 }
49006@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49007 } else {
49008 sp = &ep->seq;
49009 if (sp->id != fh->fh_seq_id) {
49010- atomic_inc(&mp->stats.seq_not_found);
49011+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49012 if (f_ctl & FC_FC_END_SEQ) {
49013 /*
49014 * Update sequence_id based on incoming last
49015@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49016
49017 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49018 if (!ep) {
49019- atomic_inc(&mp->stats.xid_not_found);
49020+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49021 goto out;
49022 }
49023 if (ep->esb_stat & ESB_ST_COMPLETE) {
49024- atomic_inc(&mp->stats.xid_not_found);
49025+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49026 goto rel;
49027 }
49028 if (ep->rxid == FC_XID_UNKNOWN)
49029 ep->rxid = ntohs(fh->fh_rx_id);
49030 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49031- atomic_inc(&mp->stats.xid_not_found);
49032+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49033 goto rel;
49034 }
49035 if (ep->did != ntoh24(fh->fh_s_id) &&
49036 ep->did != FC_FID_FLOGI) {
49037- atomic_inc(&mp->stats.xid_not_found);
49038+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49039 goto rel;
49040 }
49041 sof = fr_sof(fp);
49042@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49043 sp->ssb_stat |= SSB_ST_RESP;
49044 sp->id = fh->fh_seq_id;
49045 } else if (sp->id != fh->fh_seq_id) {
49046- atomic_inc(&mp->stats.seq_not_found);
49047+ atomic_inc_unchecked(&mp->stats.seq_not_found);
49048 goto rel;
49049 }
49050
49051@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49052 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49053
49054 if (!sp)
49055- atomic_inc(&mp->stats.xid_not_found);
49056+ atomic_inc_unchecked(&mp->stats.xid_not_found);
49057 else
49058- atomic_inc(&mp->stats.non_bls_resp);
49059+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
49060
49061 fc_frame_free(fp);
49062 }
49063@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49064
49065 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49066 mp = ema->mp;
49067- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49068+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49069 st->fc_no_free_exch_xid +=
49070- atomic_read(&mp->stats.no_free_exch_xid);
49071- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49072- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49073- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49074- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49075+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49076+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49077+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49078+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49079+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49080 }
49081 }
49082 EXPORT_SYMBOL(fc_exch_update_stats);
49083diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49084index 766098a..1c6c971 100644
49085--- a/drivers/scsi/libsas/sas_ata.c
49086+++ b/drivers/scsi/libsas/sas_ata.c
49087@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49088 .postreset = ata_std_postreset,
49089 .error_handler = ata_std_error_handler,
49090 .post_internal_cmd = sas_ata_post_internal,
49091- .qc_defer = ata_std_qc_defer,
49092+ .qc_defer = ata_std_qc_defer,
49093 .qc_prep = ata_noop_qc_prep,
49094 .qc_issue = sas_ata_qc_issue,
49095 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49096diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49097index 94a3caf..a118dec 100644
49098--- a/drivers/scsi/lpfc/lpfc.h
49099+++ b/drivers/scsi/lpfc/lpfc.h
49100@@ -430,7 +430,7 @@ struct lpfc_vport {
49101 struct dentry *debug_nodelist;
49102 struct dentry *vport_debugfs_root;
49103 struct lpfc_debugfs_trc *disc_trc;
49104- atomic_t disc_trc_cnt;
49105+ atomic_unchecked_t disc_trc_cnt;
49106 #endif
49107 uint8_t stat_data_enabled;
49108 uint8_t stat_data_blocked;
49109@@ -879,8 +879,8 @@ struct lpfc_hba {
49110 struct timer_list fabric_block_timer;
49111 unsigned long bit_flags;
49112 #define FABRIC_COMANDS_BLOCKED 0
49113- atomic_t num_rsrc_err;
49114- atomic_t num_cmd_success;
49115+ atomic_unchecked_t num_rsrc_err;
49116+ atomic_unchecked_t num_cmd_success;
49117 unsigned long last_rsrc_error_time;
49118 unsigned long last_ramp_down_time;
49119 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
49120@@ -915,7 +915,7 @@ struct lpfc_hba {
49121
49122 struct dentry *debug_slow_ring_trc;
49123 struct lpfc_debugfs_trc *slow_ring_trc;
49124- atomic_t slow_ring_trc_cnt;
49125+ atomic_unchecked_t slow_ring_trc_cnt;
49126 /* iDiag debugfs sub-directory */
49127 struct dentry *idiag_root;
49128 struct dentry *idiag_pci_cfg;
49129diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49130index 828c08e..e3378e0 100644
49131--- a/drivers/scsi/lpfc/lpfc_debugfs.c
49132+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49133@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49134
49135 #include <linux/debugfs.h>
49136
49137-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49138+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49139 static unsigned long lpfc_debugfs_start_time = 0L;
49140
49141 /* iDiag */
49142@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49143 lpfc_debugfs_enable = 0;
49144
49145 len = 0;
49146- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49147+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49148 (lpfc_debugfs_max_disc_trc - 1);
49149 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49150 dtp = vport->disc_trc + i;
49151@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49152 lpfc_debugfs_enable = 0;
49153
49154 len = 0;
49155- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49156+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49157 (lpfc_debugfs_max_slow_ring_trc - 1);
49158 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49159 dtp = phba->slow_ring_trc + i;
49160@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49161 !vport || !vport->disc_trc)
49162 return;
49163
49164- index = atomic_inc_return(&vport->disc_trc_cnt) &
49165+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49166 (lpfc_debugfs_max_disc_trc - 1);
49167 dtp = vport->disc_trc + index;
49168 dtp->fmt = fmt;
49169 dtp->data1 = data1;
49170 dtp->data2 = data2;
49171 dtp->data3 = data3;
49172- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49173+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49174 dtp->jif = jiffies;
49175 #endif
49176 return;
49177@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49178 !phba || !phba->slow_ring_trc)
49179 return;
49180
49181- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49182+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49183 (lpfc_debugfs_max_slow_ring_trc - 1);
49184 dtp = phba->slow_ring_trc + index;
49185 dtp->fmt = fmt;
49186 dtp->data1 = data1;
49187 dtp->data2 = data2;
49188 dtp->data3 = data3;
49189- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49190+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49191 dtp->jif = jiffies;
49192 #endif
49193 return;
49194@@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49195 "slow_ring buffer\n");
49196 goto debug_failed;
49197 }
49198- atomic_set(&phba->slow_ring_trc_cnt, 0);
49199+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49200 memset(phba->slow_ring_trc, 0,
49201 (sizeof(struct lpfc_debugfs_trc) *
49202 lpfc_debugfs_max_slow_ring_trc));
49203@@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49204 "buffer\n");
49205 goto debug_failed;
49206 }
49207- atomic_set(&vport->disc_trc_cnt, 0);
49208+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49209
49210 snprintf(name, sizeof(name), "discovery_trace");
49211 vport->debug_disc_trc =
49212diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49213index 635eeb3..038aef6 100644
49214--- a/drivers/scsi/lpfc/lpfc_init.c
49215+++ b/drivers/scsi/lpfc/lpfc_init.c
49216@@ -11194,8 +11194,10 @@ lpfc_init(void)
49217 "misc_register returned with status %d", error);
49218
49219 if (lpfc_enable_npiv) {
49220- lpfc_transport_functions.vport_create = lpfc_vport_create;
49221- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49222+ pax_open_kernel();
49223+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49224+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49225+ pax_close_kernel();
49226 }
49227 lpfc_transport_template =
49228 fc_attach_transport(&lpfc_transport_functions);
49229diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49230index 462453e..c0023a6 100644
49231--- a/drivers/scsi/lpfc/lpfc_scsi.c
49232+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49233@@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49234 uint32_t evt_posted;
49235
49236 spin_lock_irqsave(&phba->hbalock, flags);
49237- atomic_inc(&phba->num_rsrc_err);
49238+ atomic_inc_unchecked(&phba->num_rsrc_err);
49239 phba->last_rsrc_error_time = jiffies;
49240
49241 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49242@@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49243 unsigned long num_rsrc_err, num_cmd_success;
49244 int i;
49245
49246- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49247- num_cmd_success = atomic_read(&phba->num_cmd_success);
49248+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49249+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49250
49251 /*
49252 * The error and success command counters are global per
49253@@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49254 }
49255 }
49256 lpfc_destroy_vport_work_array(phba, vports);
49257- atomic_set(&phba->num_rsrc_err, 0);
49258- atomic_set(&phba->num_cmd_success, 0);
49259+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49260+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49261 }
49262
49263 /**
49264diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49265index 6fd7d40..b444223 100644
49266--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49267+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49268@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49269 {
49270 struct scsi_device *sdev = to_scsi_device(dev);
49271 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49272- static struct _raid_device *raid_device;
49273+ struct _raid_device *raid_device;
49274 unsigned long flags;
49275 Mpi2RaidVolPage0_t vol_pg0;
49276 Mpi2ConfigReply_t mpi_reply;
49277@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49278 {
49279 struct scsi_device *sdev = to_scsi_device(dev);
49280 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49281- static struct _raid_device *raid_device;
49282+ struct _raid_device *raid_device;
49283 unsigned long flags;
49284 Mpi2RaidVolPage0_t vol_pg0;
49285 Mpi2ConfigReply_t mpi_reply;
49286@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49287 struct fw_event_work *fw_event)
49288 {
49289 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49290- static struct _raid_device *raid_device;
49291+ struct _raid_device *raid_device;
49292 unsigned long flags;
49293 u16 handle;
49294
49295@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49296 u64 sas_address;
49297 struct _sas_device *sas_device;
49298 struct _sas_node *expander_device;
49299- static struct _raid_device *raid_device;
49300+ struct _raid_device *raid_device;
49301 u8 retry_count;
49302 unsigned long flags;
49303
49304diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49305index be8ce54..94ed33a 100644
49306--- a/drivers/scsi/pmcraid.c
49307+++ b/drivers/scsi/pmcraid.c
49308@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49309 res->scsi_dev = scsi_dev;
49310 scsi_dev->hostdata = res;
49311 res->change_detected = 0;
49312- atomic_set(&res->read_failures, 0);
49313- atomic_set(&res->write_failures, 0);
49314+ atomic_set_unchecked(&res->read_failures, 0);
49315+ atomic_set_unchecked(&res->write_failures, 0);
49316 rc = 0;
49317 }
49318 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49319@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49320
49321 /* If this was a SCSI read/write command keep count of errors */
49322 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49323- atomic_inc(&res->read_failures);
49324+ atomic_inc_unchecked(&res->read_failures);
49325 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49326- atomic_inc(&res->write_failures);
49327+ atomic_inc_unchecked(&res->write_failures);
49328
49329 if (!RES_IS_GSCSI(res->cfg_entry) &&
49330 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49331@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49332 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49333 * hrrq_id assigned here in queuecommand
49334 */
49335- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49336+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49337 pinstance->num_hrrq;
49338 cmd->cmd_done = pmcraid_io_done;
49339
49340@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49341 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49342 * hrrq_id assigned here in queuecommand
49343 */
49344- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49345+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49346 pinstance->num_hrrq;
49347
49348 if (request_size) {
49349@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49350
49351 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49352 /* add resources only after host is added into system */
49353- if (!atomic_read(&pinstance->expose_resources))
49354+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49355 return;
49356
49357 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49358@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49359 init_waitqueue_head(&pinstance->reset_wait_q);
49360
49361 atomic_set(&pinstance->outstanding_cmds, 0);
49362- atomic_set(&pinstance->last_message_id, 0);
49363- atomic_set(&pinstance->expose_resources, 0);
49364+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49365+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49366
49367 INIT_LIST_HEAD(&pinstance->free_res_q);
49368 INIT_LIST_HEAD(&pinstance->used_res_q);
49369@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49370 /* Schedule worker thread to handle CCN and take care of adding and
49371 * removing devices to OS
49372 */
49373- atomic_set(&pinstance->expose_resources, 1);
49374+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49375 schedule_work(&pinstance->worker_q);
49376 return rc;
49377
49378diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49379index e1d150f..6c6df44 100644
49380--- a/drivers/scsi/pmcraid.h
49381+++ b/drivers/scsi/pmcraid.h
49382@@ -748,7 +748,7 @@ struct pmcraid_instance {
49383 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49384
49385 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49386- atomic_t last_message_id;
49387+ atomic_unchecked_t last_message_id;
49388
49389 /* configuration table */
49390 struct pmcraid_config_table *cfg_table;
49391@@ -777,7 +777,7 @@ struct pmcraid_instance {
49392 atomic_t outstanding_cmds;
49393
49394 /* should add/delete resources to mid-layer now ?*/
49395- atomic_t expose_resources;
49396+ atomic_unchecked_t expose_resources;
49397
49398
49399
49400@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49401 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49402 };
49403 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49404- atomic_t read_failures; /* count of failed READ commands */
49405- atomic_t write_failures; /* count of failed WRITE commands */
49406+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49407+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49408
49409 /* To indicate add/delete/modify during CCN */
49410 u8 change_detected;
49411diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49412index 07befcf..c0bff13 100644
49413--- a/drivers/scsi/qla2xxx/qla_attr.c
49414+++ b/drivers/scsi/qla2xxx/qla_attr.c
49415@@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49416 return 0;
49417 }
49418
49419-struct fc_function_template qla2xxx_transport_functions = {
49420+fc_function_template_no_const qla2xxx_transport_functions = {
49421
49422 .show_host_node_name = 1,
49423 .show_host_port_name = 1,
49424@@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49425 .bsg_timeout = qla24xx_bsg_timeout,
49426 };
49427
49428-struct fc_function_template qla2xxx_transport_vport_functions = {
49429+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49430
49431 .show_host_node_name = 1,
49432 .show_host_port_name = 1,
49433diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49434index e665e81..16e84e6 100644
49435--- a/drivers/scsi/qla2xxx/qla_gbl.h
49436+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49437@@ -557,8 +557,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49438 struct device_attribute;
49439 extern struct device_attribute *qla2x00_host_attrs[];
49440 struct fc_function_template;
49441-extern struct fc_function_template qla2xxx_transport_functions;
49442-extern struct fc_function_template qla2xxx_transport_vport_functions;
49443+extern fc_function_template_no_const qla2xxx_transport_functions;
49444+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49445 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49446 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49447 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49448diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49449index 19e99cc..b3c0b7b 100644
49450--- a/drivers/scsi/qla2xxx/qla_os.c
49451+++ b/drivers/scsi/qla2xxx/qla_os.c
49452@@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49453 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49454 /* Ok, a 64bit DMA mask is applicable. */
49455 ha->flags.enable_64bit_addressing = 1;
49456- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49457- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49458+ pax_open_kernel();
49459+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49460+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49461+ pax_close_kernel();
49462 return;
49463 }
49464 }
49465diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49466index 73a5022..4e0797c 100644
49467--- a/drivers/scsi/qla4xxx/ql4_def.h
49468+++ b/drivers/scsi/qla4xxx/ql4_def.h
49469@@ -305,7 +305,7 @@ struct ddb_entry {
49470 * (4000 only) */
49471 atomic_t relogin_timer; /* Max Time to wait for
49472 * relogin to complete */
49473- atomic_t relogin_retry_count; /* Num of times relogin has been
49474+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49475 * retried */
49476 uint32_t default_time2wait; /* Default Min time between
49477 * relogins (+aens) */
49478diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49479index 459b9f7..2930a68 100644
49480--- a/drivers/scsi/qla4xxx/ql4_os.c
49481+++ b/drivers/scsi/qla4xxx/ql4_os.c
49482@@ -4499,12 +4499,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49483 */
49484 if (!iscsi_is_session_online(cls_sess)) {
49485 /* Reset retry relogin timer */
49486- atomic_inc(&ddb_entry->relogin_retry_count);
49487+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49488 DEBUG2(ql4_printk(KERN_INFO, ha,
49489 "%s: index[%d] relogin timed out-retrying"
49490 " relogin (%d), retry (%d)\n", __func__,
49491 ddb_entry->fw_ddb_index,
49492- atomic_read(&ddb_entry->relogin_retry_count),
49493+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49494 ddb_entry->default_time2wait + 4));
49495 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49496 atomic_set(&ddb_entry->retry_relogin_timer,
49497@@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49498
49499 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49500 atomic_set(&ddb_entry->relogin_timer, 0);
49501- atomic_set(&ddb_entry->relogin_retry_count, 0);
49502+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49503 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49504 ddb_entry->default_relogin_timeout =
49505 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49506diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49507index 88d46fe..7351be5 100644
49508--- a/drivers/scsi/scsi.c
49509+++ b/drivers/scsi/scsi.c
49510@@ -640,7 +640,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49511 struct Scsi_Host *host = cmd->device->host;
49512 int rtn = 0;
49513
49514- atomic_inc(&cmd->device->iorequest_cnt);
49515+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49516
49517 /* check if the device is still usable */
49518 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49519diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49520index 9db097a..ca5c291 100644
49521--- a/drivers/scsi/scsi_lib.c
49522+++ b/drivers/scsi/scsi_lib.c
49523@@ -1464,7 +1464,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49524 shost = sdev->host;
49525 scsi_init_cmd_errh(cmd);
49526 cmd->result = DID_NO_CONNECT << 16;
49527- atomic_inc(&cmd->device->iorequest_cnt);
49528+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49529
49530 /*
49531 * SCSI request completion path will do scsi_device_unbusy(),
49532@@ -1490,9 +1490,9 @@ static void scsi_softirq_done(struct request *rq)
49533
49534 INIT_LIST_HEAD(&cmd->eh_entry);
49535
49536- atomic_inc(&cmd->device->iodone_cnt);
49537+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
49538 if (cmd->result)
49539- atomic_inc(&cmd->device->ioerr_cnt);
49540+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49541
49542 disposition = scsi_decide_disposition(cmd);
49543 if (disposition != SUCCESS &&
49544diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49545index 074e8cc..f612e5c 100644
49546--- a/drivers/scsi/scsi_sysfs.c
49547+++ b/drivers/scsi/scsi_sysfs.c
49548@@ -780,7 +780,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49549 char *buf) \
49550 { \
49551 struct scsi_device *sdev = to_scsi_device(dev); \
49552- unsigned long long count = atomic_read(&sdev->field); \
49553+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
49554 return snprintf(buf, 20, "0x%llx\n", count); \
49555 } \
49556 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49557diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49558index e51add0..1e06a96 100644
49559--- a/drivers/scsi/scsi_tgt_lib.c
49560+++ b/drivers/scsi/scsi_tgt_lib.c
49561@@ -363,7 +363,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49562 int err;
49563
49564 dprintk("%lx %u\n", uaddr, len);
49565- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49566+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49567 if (err) {
49568 /*
49569 * TODO: need to fixup sg_tablesize, max_segment_size,
49570diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49571index f80908f..22aba76 100644
49572--- a/drivers/scsi/scsi_transport_fc.c
49573+++ b/drivers/scsi/scsi_transport_fc.c
49574@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49575 * Netlink Infrastructure
49576 */
49577
49578-static atomic_t fc_event_seq;
49579+static atomic_unchecked_t fc_event_seq;
49580
49581 /**
49582 * fc_get_event_number - Obtain the next sequential FC event number
49583@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
49584 u32
49585 fc_get_event_number(void)
49586 {
49587- return atomic_add_return(1, &fc_event_seq);
49588+ return atomic_add_return_unchecked(1, &fc_event_seq);
49589 }
49590 EXPORT_SYMBOL(fc_get_event_number);
49591
49592@@ -655,7 +655,7 @@ static __init int fc_transport_init(void)
49593 {
49594 int error;
49595
49596- atomic_set(&fc_event_seq, 0);
49597+ atomic_set_unchecked(&fc_event_seq, 0);
49598
49599 error = transport_class_register(&fc_host_class);
49600 if (error)
49601@@ -845,7 +845,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49602 char *cp;
49603
49604 *val = simple_strtoul(buf, &cp, 0);
49605- if ((*cp && (*cp != '\n')) || (*val < 0))
49606+ if (*cp && (*cp != '\n'))
49607 return -EINVAL;
49608 /*
49609 * Check for overflow; dev_loss_tmo is u32
49610diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49611index 0102a2d..cc3f8e9 100644
49612--- a/drivers/scsi/scsi_transport_iscsi.c
49613+++ b/drivers/scsi/scsi_transport_iscsi.c
49614@@ -79,7 +79,7 @@ struct iscsi_internal {
49615 struct transport_container session_cont;
49616 };
49617
49618-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49619+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49620 static struct workqueue_struct *iscsi_eh_timer_workq;
49621
49622 static DEFINE_IDA(iscsi_sess_ida);
49623@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49624 int err;
49625
49626 ihost = shost->shost_data;
49627- session->sid = atomic_add_return(1, &iscsi_session_nr);
49628+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49629
49630 if (target_id == ISCSI_MAX_TARGET) {
49631 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49632@@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
49633 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49634 ISCSI_TRANSPORT_VERSION);
49635
49636- atomic_set(&iscsi_session_nr, 0);
49637+ atomic_set_unchecked(&iscsi_session_nr, 0);
49638
49639 err = class_register(&iscsi_transport_class);
49640 if (err)
49641diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49642index 13e8983..d306a68 100644
49643--- a/drivers/scsi/scsi_transport_srp.c
49644+++ b/drivers/scsi/scsi_transport_srp.c
49645@@ -36,7 +36,7 @@
49646 #include "scsi_transport_srp_internal.h"
49647
49648 struct srp_host_attrs {
49649- atomic_t next_port_id;
49650+ atomic_unchecked_t next_port_id;
49651 };
49652 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49653
49654@@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49655 struct Scsi_Host *shost = dev_to_shost(dev);
49656 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49657
49658- atomic_set(&srp_host->next_port_id, 0);
49659+ atomic_set_unchecked(&srp_host->next_port_id, 0);
49660 return 0;
49661 }
49662
49663@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49664 rport_fast_io_fail_timedout);
49665 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49666
49667- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49668+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49669 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49670
49671 transport_setup_device(&rport->dev);
49672diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49673index bffbd4b..cb1b68a 100644
49674--- a/drivers/scsi/sd.c
49675+++ b/drivers/scsi/sd.c
49676@@ -2971,7 +2971,7 @@ static int sd_probe(struct device *dev)
49677 sdkp->disk = gd;
49678 sdkp->index = index;
49679 atomic_set(&sdkp->openers, 0);
49680- atomic_set(&sdkp->device->ioerr_cnt, 0);
49681+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49682
49683 if (!sdp->request_queue->rq_timeout) {
49684 if (sdp->type != TYPE_MOD)
49685diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49686index df5e961..df6b97f 100644
49687--- a/drivers/scsi/sg.c
49688+++ b/drivers/scsi/sg.c
49689@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49690 sdp->disk->disk_name,
49691 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49692 NULL,
49693- (char *)arg);
49694+ (char __user *)arg);
49695 case BLKTRACESTART:
49696 return blk_trace_startstop(sdp->device->request_queue, 1);
49697 case BLKTRACESTOP:
49698diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49699index 939edf4..3f50423 100644
49700--- a/drivers/spi/spi.c
49701+++ b/drivers/spi/spi.c
49702@@ -2204,7 +2204,7 @@ int spi_bus_unlock(struct spi_master *master)
49703 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49704
49705 /* portable code must never pass more than 32 bytes */
49706-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49707+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49708
49709 static u8 *buf;
49710
49711diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49712index 2c61783..4d49e4e 100644
49713--- a/drivers/staging/android/timed_output.c
49714+++ b/drivers/staging/android/timed_output.c
49715@@ -25,7 +25,7 @@
49716 #include "timed_output.h"
49717
49718 static struct class *timed_output_class;
49719-static atomic_t device_count;
49720+static atomic_unchecked_t device_count;
49721
49722 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49723 char *buf)
49724@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49725 timed_output_class = class_create(THIS_MODULE, "timed_output");
49726 if (IS_ERR(timed_output_class))
49727 return PTR_ERR(timed_output_class);
49728- atomic_set(&device_count, 0);
49729+ atomic_set_unchecked(&device_count, 0);
49730 timed_output_class->dev_groups = timed_output_groups;
49731 }
49732
49733@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49734 if (ret < 0)
49735 return ret;
49736
49737- tdev->index = atomic_inc_return(&device_count);
49738+ tdev->index = atomic_inc_return_unchecked(&device_count);
49739 tdev->dev = device_create(timed_output_class, NULL,
49740 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49741 if (IS_ERR(tdev->dev))
49742diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49743index fe47cd3..19a1bd1 100644
49744--- a/drivers/staging/gdm724x/gdm_tty.c
49745+++ b/drivers/staging/gdm724x/gdm_tty.c
49746@@ -44,7 +44,7 @@
49747 #define gdm_tty_send_control(n, r, v, d, l) (\
49748 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49749
49750-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49751+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49752
49753 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49754 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49755diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49756index c270c9a..94ddf82 100644
49757--- a/drivers/staging/imx-drm/imx-drm-core.c
49758+++ b/drivers/staging/imx-drm/imx-drm-core.c
49759@@ -362,7 +362,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
49760 if (imxdrm->pipes >= MAX_CRTC)
49761 return -EINVAL;
49762
49763- if (imxdrm->drm->open_count)
49764+ if (local_read(&imxdrm->drm->open_count))
49765 return -EBUSY;
49766
49767 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
49768diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49769index 3f8020c..649fded 100644
49770--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49771+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49772@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49773 return 0;
49774 }
49775
49776-sfw_test_client_ops_t brw_test_client;
49777-void brw_init_test_client(void)
49778-{
49779- brw_test_client.tso_init = brw_client_init;
49780- brw_test_client.tso_fini = brw_client_fini;
49781- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49782- brw_test_client.tso_done_rpc = brw_client_done_rpc;
49783+sfw_test_client_ops_t brw_test_client = {
49784+ .tso_init = brw_client_init,
49785+ .tso_fini = brw_client_fini,
49786+ .tso_prep_rpc = brw_client_prep_rpc,
49787+ .tso_done_rpc = brw_client_done_rpc,
49788 };
49789
49790 srpc_service_t brw_test_service;
49791diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49792index 050723a..fa6fdf1 100644
49793--- a/drivers/staging/lustre/lnet/selftest/framework.c
49794+++ b/drivers/staging/lustre/lnet/selftest/framework.c
49795@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49796
49797 extern sfw_test_client_ops_t ping_test_client;
49798 extern srpc_service_t ping_test_service;
49799-extern void ping_init_test_client(void);
49800 extern void ping_init_test_service(void);
49801
49802 extern sfw_test_client_ops_t brw_test_client;
49803 extern srpc_service_t brw_test_service;
49804-extern void brw_init_test_client(void);
49805 extern void brw_init_test_service(void);
49806
49807
49808@@ -1684,12 +1682,10 @@ sfw_startup (void)
49809 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49810 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49811
49812- brw_init_test_client();
49813 brw_init_test_service();
49814 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49815 LASSERT (rc == 0);
49816
49817- ping_init_test_client();
49818 ping_init_test_service();
49819 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49820 LASSERT (rc == 0);
49821diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49822index 750cac4..e4d751f 100644
49823--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49824+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49825@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49826 return 0;
49827 }
49828
49829-sfw_test_client_ops_t ping_test_client;
49830-void ping_init_test_client(void)
49831-{
49832- ping_test_client.tso_init = ping_client_init;
49833- ping_test_client.tso_fini = ping_client_fini;
49834- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49835- ping_test_client.tso_done_rpc = ping_client_done_rpc;
49836-}
49837+sfw_test_client_ops_t ping_test_client = {
49838+ .tso_init = ping_client_init,
49839+ .tso_fini = ping_client_fini,
49840+ .tso_prep_rpc = ping_client_prep_rpc,
49841+ .tso_done_rpc = ping_client_done_rpc,
49842+};
49843
49844 srpc_service_t ping_test_service;
49845 void ping_init_test_service(void)
49846diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49847index 3e25f00..0d59cf5 100644
49848--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49849+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49850@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49851 ldlm_completion_callback lcs_completion;
49852 ldlm_blocking_callback lcs_blocking;
49853 ldlm_glimpse_callback lcs_glimpse;
49854-};
49855+} __no_const;
49856
49857 /* ldlm_lockd.c */
49858 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49859diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49860index 72cf3fe..4beac19 100644
49861--- a/drivers/staging/lustre/lustre/include/obd.h
49862+++ b/drivers/staging/lustre/lustre/include/obd.h
49863@@ -1427,7 +1427,7 @@ struct md_ops {
49864 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49865 * wrapper function in include/linux/obd_class.h.
49866 */
49867-};
49868+} __no_const;
49869
49870 struct lsm_operations {
49871 void (*lsm_free)(struct lov_stripe_md *);
49872diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49873index 986bf38..eab2558f 100644
49874--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49875+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49876@@ -259,7 +259,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49877 int added = (mode == LCK_NL);
49878 int overlaps = 0;
49879 int splitted = 0;
49880- const struct ldlm_callback_suite null_cbs = { NULL };
49881+ const struct ldlm_callback_suite null_cbs = { };
49882
49883 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49884 LPU64" end "LPU64"\n", *flags,
49885diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49886index e947b91..f408990 100644
49887--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49888+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49889@@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49890 int LL_PROC_PROTO(proc_console_max_delay_cs)
49891 {
49892 int rc, max_delay_cs;
49893- ctl_table_t dummy = *table;
49894+ ctl_table_no_const dummy = *table;
49895 cfs_duration_t d;
49896
49897 dummy.data = &max_delay_cs;
49898@@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49899 int LL_PROC_PROTO(proc_console_min_delay_cs)
49900 {
49901 int rc, min_delay_cs;
49902- ctl_table_t dummy = *table;
49903+ ctl_table_no_const dummy = *table;
49904 cfs_duration_t d;
49905
49906 dummy.data = &min_delay_cs;
49907@@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49908 int LL_PROC_PROTO(proc_console_backoff)
49909 {
49910 int rc, backoff;
49911- ctl_table_t dummy = *table;
49912+ ctl_table_no_const dummy = *table;
49913
49914 dummy.data = &backoff;
49915 dummy.proc_handler = &proc_dointvec;
49916diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49917index 24ae26d..9d09cab 100644
49918--- a/drivers/staging/lustre/lustre/libcfs/module.c
49919+++ b/drivers/staging/lustre/lustre/libcfs/module.c
49920@@ -313,11 +313,11 @@ out:
49921
49922
49923 struct cfs_psdev_ops libcfs_psdev_ops = {
49924- libcfs_psdev_open,
49925- libcfs_psdev_release,
49926- NULL,
49927- NULL,
49928- libcfs_ioctl
49929+ .p_open = libcfs_psdev_open,
49930+ .p_close = libcfs_psdev_release,
49931+ .p_read = NULL,
49932+ .p_write = NULL,
49933+ .p_ioctl = libcfs_ioctl
49934 };
49935
49936 extern int insert_proc(void);
49937diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
49938index 7fbc18e..f982071 100644
49939--- a/drivers/staging/lustre/lustre/llite/dir.c
49940+++ b/drivers/staging/lustre/lustre/llite/dir.c
49941@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
49942 int mode;
49943 int err;
49944
49945- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
49946+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
49947 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
49948 strlen(filename), mode, LUSTRE_OPC_MKDIR,
49949 lump);
49950diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49951index f670469..03b7438 100644
49952--- a/drivers/staging/media/solo6x10/solo6x10-core.c
49953+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49954@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49955
49956 static int solo_sysfs_init(struct solo_dev *solo_dev)
49957 {
49958- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49959+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49960 struct device *dev = &solo_dev->dev;
49961 const char *driver;
49962 int i;
49963diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49964index 74f037b..5b5bb76 100644
49965--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49966+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49967@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49968
49969 int solo_g723_init(struct solo_dev *solo_dev)
49970 {
49971- static struct snd_device_ops ops = { NULL };
49972+ static struct snd_device_ops ops = { };
49973 struct snd_card *card;
49974 struct snd_kcontrol_new kctl;
49975 char name[32];
49976diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49977index 7f2f247..d999137 100644
49978--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49979+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49980@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49981
49982 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49983 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49984- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49985+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49986 if (p2m_id < 0)
49987 p2m_id = -p2m_id;
49988 }
49989diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49990index 8964f8b..36eb087 100644
49991--- a/drivers/staging/media/solo6x10/solo6x10.h
49992+++ b/drivers/staging/media/solo6x10/solo6x10.h
49993@@ -237,7 +237,7 @@ struct solo_dev {
49994
49995 /* P2M DMA Engine */
49996 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49997- atomic_t p2m_count;
49998+ atomic_unchecked_t p2m_count;
49999 int p2m_jiffies;
50000 unsigned int p2m_timeouts;
50001
50002diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50003index a0f4868..139f1fb 100644
50004--- a/drivers/staging/octeon/ethernet-rx.c
50005+++ b/drivers/staging/octeon/ethernet-rx.c
50006@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50007 /* Increment RX stats for virtual ports */
50008 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50009 #ifdef CONFIG_64BIT
50010- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50011- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50012+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50013+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50014 #else
50015- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50016- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50017+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50018+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50019 #endif
50020 }
50021 netif_receive_skb(skb);
50022@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50023 dev->name);
50024 */
50025 #ifdef CONFIG_64BIT
50026- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50027+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50028 #else
50029- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50030+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50031 #endif
50032 dev_kfree_skb_irq(skb);
50033 }
50034diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50035index ff7214a..6dd90f0 100644
50036--- a/drivers/staging/octeon/ethernet.c
50037+++ b/drivers/staging/octeon/ethernet.c
50038@@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50039 * since the RX tasklet also increments it.
50040 */
50041 #ifdef CONFIG_64BIT
50042- atomic64_add(rx_status.dropped_packets,
50043- (atomic64_t *)&priv->stats.rx_dropped);
50044+ atomic64_add_unchecked(rx_status.dropped_packets,
50045+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50046 #else
50047- atomic_add(rx_status.dropped_packets,
50048- (atomic_t *)&priv->stats.rx_dropped);
50049+ atomic_add_unchecked(rx_status.dropped_packets,
50050+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
50051 #endif
50052 }
50053
50054diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50055index c274b34..f84de76 100644
50056--- a/drivers/staging/rtl8188eu/include/hal_intf.h
50057+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50058@@ -271,7 +271,7 @@ struct hal_ops {
50059 s32 (*c2h_handler)(struct adapter *padapter,
50060 struct c2h_evt_hdr *c2h_evt);
50061 c2h_id_filter c2h_id_filter_ccx;
50062-};
50063+} __no_const;
50064
50065 enum rt_eeprom_type {
50066 EEPROM_93C46,
50067diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50068index e8790f8..b4a5980 100644
50069--- a/drivers/staging/rtl8188eu/include/rtw_io.h
50070+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50071@@ -124,7 +124,7 @@ struct _io_ops {
50072 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50073 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50074 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50075-};
50076+} __no_const;
50077
50078 struct io_req {
50079 struct list_head list;
50080diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50081index dc23395..cf7e9b1 100644
50082--- a/drivers/staging/rtl8712/rtl871x_io.h
50083+++ b/drivers/staging/rtl8712/rtl871x_io.h
50084@@ -108,7 +108,7 @@ struct _io_ops {
50085 u8 *pmem);
50086 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50087 u8 *pmem);
50088-};
50089+} __no_const;
50090
50091 struct io_req {
50092 struct list_head list;
50093diff --git a/drivers/staging/rtl8723au/include/hal_intf.h b/drivers/staging/rtl8723au/include/hal_intf.h
50094index d183f4b..3f4903d 100644
50095--- a/drivers/staging/rtl8723au/include/hal_intf.h
50096+++ b/drivers/staging/rtl8723au/include/hal_intf.h
50097@@ -251,7 +251,7 @@ struct hal_ops {
50098 void (*hal_reset_security_engine)(struct rtw_adapter *adapter);
50099 s32 (*c2h_handler)(struct rtw_adapter *padapter, struct c2h_evt_hdr *c2h_evt);
50100 c2h_id_filter c2h_id_filter_ccx;
50101-};
50102+} __no_const;
50103
50104 enum rt_eeprom_type {
50105 EEPROM_93C46,
50106diff --git a/drivers/staging/rtl8723au/include/rtw_io.h b/drivers/staging/rtl8723au/include/rtw_io.h
50107index 8d39d800..3f21c0c 100644
50108--- a/drivers/staging/rtl8723au/include/rtw_io.h
50109+++ b/drivers/staging/rtl8723au/include/rtw_io.h
50110@@ -130,7 +130,7 @@ struct _io_ops
50111 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50112 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50113
50114-};
50115+} __no_const;
50116
50117 struct io_req {
50118 struct list_head list;
50119diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50120index fe6c951..72935ba 100644
50121--- a/drivers/staging/sbe-2t3e3/netdev.c
50122+++ b/drivers/staging/sbe-2t3e3/netdev.c
50123@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50124 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50125
50126 if (rlen)
50127- if (copy_to_user(data, &resp, rlen))
50128+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50129 return -EFAULT;
50130
50131 return 0;
50132diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50133index a863a98..d272795 100644
50134--- a/drivers/staging/usbip/vhci.h
50135+++ b/drivers/staging/usbip/vhci.h
50136@@ -83,7 +83,7 @@ struct vhci_hcd {
50137 unsigned resuming:1;
50138 unsigned long re_timeout;
50139
50140- atomic_t seqnum;
50141+ atomic_unchecked_t seqnum;
50142
50143 /*
50144 * NOTE:
50145diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50146index 70e1755..de41855 100644
50147--- a/drivers/staging/usbip/vhci_hcd.c
50148+++ b/drivers/staging/usbip/vhci_hcd.c
50149@@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
50150
50151 spin_lock(&vdev->priv_lock);
50152
50153- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50154+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50155 if (priv->seqnum == 0xffff)
50156 dev_info(&urb->dev->dev, "seqnum max\n");
50157
50158@@ -685,7 +685,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50159 return -ENOMEM;
50160 }
50161
50162- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50163+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50164 if (unlink->seqnum == 0xffff)
50165 pr_info("seqnum max\n");
50166
50167@@ -889,7 +889,7 @@ static int vhci_start(struct usb_hcd *hcd)
50168 vdev->rhport = rhport;
50169 }
50170
50171- atomic_set(&vhci->seqnum, 0);
50172+ atomic_set_unchecked(&vhci->seqnum, 0);
50173 spin_lock_init(&vhci->lock);
50174
50175 hcd->power_budget = 0; /* no limit */
50176diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50177index d07fcb5..358e1e1 100644
50178--- a/drivers/staging/usbip/vhci_rx.c
50179+++ b/drivers/staging/usbip/vhci_rx.c
50180@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50181 if (!urb) {
50182 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50183 pr_info("max seqnum %d\n",
50184- atomic_read(&the_controller->seqnum));
50185+ atomic_read_unchecked(&the_controller->seqnum));
50186 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50187 return;
50188 }
50189diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50190index 6eecd53..29317c6 100644
50191--- a/drivers/staging/vt6655/hostap.c
50192+++ b/drivers/staging/vt6655/hostap.c
50193@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50194 *
50195 */
50196
50197+static net_device_ops_no_const apdev_netdev_ops;
50198+
50199 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50200 {
50201 PSDevice apdev_priv;
50202 struct net_device *dev = pDevice->dev;
50203 int ret;
50204- const struct net_device_ops apdev_netdev_ops = {
50205- .ndo_start_xmit = pDevice->tx_80211,
50206- };
50207
50208 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50209
50210@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50211 *apdev_priv = *pDevice;
50212 eth_hw_addr_inherit(pDevice->apdev, dev);
50213
50214+ /* only half broken now */
50215+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50216 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50217
50218 pDevice->apdev->type = ARPHRD_IEEE80211;
50219diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50220index 67ba48b..24e602f 100644
50221--- a/drivers/staging/vt6656/hostap.c
50222+++ b/drivers/staging/vt6656/hostap.c
50223@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50224 *
50225 */
50226
50227+static net_device_ops_no_const apdev_netdev_ops;
50228+
50229 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50230 {
50231 struct vnt_private *apdev_priv;
50232 struct net_device *dev = pDevice->dev;
50233 int ret;
50234- const struct net_device_ops apdev_netdev_ops = {
50235- .ndo_start_xmit = pDevice->tx_80211,
50236- };
50237
50238 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50239
50240@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50241 *apdev_priv = *pDevice;
50242 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50243
50244+ /* only half broken now */
50245+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50246 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50247
50248 pDevice->apdev->type = ARPHRD_IEEE80211;
50249diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50250index e7e9372..161f530 100644
50251--- a/drivers/target/sbp/sbp_target.c
50252+++ b/drivers/target/sbp/sbp_target.c
50253@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50254
50255 #define SESSION_MAINTENANCE_INTERVAL HZ
50256
50257-static atomic_t login_id = ATOMIC_INIT(0);
50258+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50259
50260 static void session_maintenance_work(struct work_struct *);
50261 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50262@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50263 login->lun = se_lun;
50264 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50265 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50266- login->login_id = atomic_inc_return(&login_id);
50267+ login->login_id = atomic_inc_return_unchecked(&login_id);
50268
50269 login->tgt_agt = sbp_target_agent_register(login);
50270 if (IS_ERR(login->tgt_agt)) {
50271diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50272index 6ea95d2..88607b4 100644
50273--- a/drivers/target/target_core_device.c
50274+++ b/drivers/target/target_core_device.c
50275@@ -1525,7 +1525,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50276 spin_lock_init(&dev->se_tmr_lock);
50277 spin_lock_init(&dev->qf_cmd_lock);
50278 sema_init(&dev->caw_sem, 1);
50279- atomic_set(&dev->dev_ordered_id, 0);
50280+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50281 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50282 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50283 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50284diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50285index 14772e9..42d9f63 100644
50286--- a/drivers/target/target_core_transport.c
50287+++ b/drivers/target/target_core_transport.c
50288@@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50289 * Used to determine when ORDERED commands should go from
50290 * Dormant to Active status.
50291 */
50292- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50293+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50294 smp_mb__after_atomic_inc();
50295 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50296 cmd->se_ordered_id, cmd->sam_task_attr,
50297diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50298index 04b1be7..5eff86d 100644
50299--- a/drivers/thermal/of-thermal.c
50300+++ b/drivers/thermal/of-thermal.c
50301@@ -30,6 +30,7 @@
50302 #include <linux/err.h>
50303 #include <linux/export.h>
50304 #include <linux/string.h>
50305+#include <linux/mm.h>
50306
50307 #include "thermal_core.h"
50308
50309@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50310 tz->get_trend = get_trend;
50311 tz->sensor_data = data;
50312
50313- tzd->ops->get_temp = of_thermal_get_temp;
50314- tzd->ops->get_trend = of_thermal_get_trend;
50315+ pax_open_kernel();
50316+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50317+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50318+ pax_close_kernel();
50319 mutex_unlock(&tzd->lock);
50320
50321 return tzd;
50322@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50323 return;
50324
50325 mutex_lock(&tzd->lock);
50326- tzd->ops->get_temp = NULL;
50327- tzd->ops->get_trend = NULL;
50328+ pax_open_kernel();
50329+ *(void **)&tzd->ops->get_temp = NULL;
50330+ *(void **)&tzd->ops->get_trend = NULL;
50331+ pax_close_kernel();
50332
50333 tz->get_temp = NULL;
50334 tz->get_trend = NULL;
50335diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50336index a57bb5a..1f727d33 100644
50337--- a/drivers/tty/cyclades.c
50338+++ b/drivers/tty/cyclades.c
50339@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50340 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50341 info->port.count);
50342 #endif
50343- info->port.count++;
50344+ atomic_inc(&info->port.count);
50345 #ifdef CY_DEBUG_COUNT
50346 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50347- current->pid, info->port.count);
50348+ current->pid, atomic_read(&info->port.count));
50349 #endif
50350
50351 /*
50352@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50353 for (j = 0; j < cy_card[i].nports; j++) {
50354 info = &cy_card[i].ports[j];
50355
50356- if (info->port.count) {
50357+ if (atomic_read(&info->port.count)) {
50358 /* XXX is the ldisc num worth this? */
50359 struct tty_struct *tty;
50360 struct tty_ldisc *ld;
50361diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50362index 0ff7fda..dbc7d52 100644
50363--- a/drivers/tty/hvc/hvc_console.c
50364+++ b/drivers/tty/hvc/hvc_console.c
50365@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50366
50367 spin_lock_irqsave(&hp->port.lock, flags);
50368 /* Check and then increment for fast path open. */
50369- if (hp->port.count++ > 0) {
50370+ if (atomic_inc_return(&hp->port.count) > 1) {
50371 spin_unlock_irqrestore(&hp->port.lock, flags);
50372 hvc_kick();
50373 return 0;
50374@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50375
50376 spin_lock_irqsave(&hp->port.lock, flags);
50377
50378- if (--hp->port.count == 0) {
50379+ if (atomic_dec_return(&hp->port.count) == 0) {
50380 spin_unlock_irqrestore(&hp->port.lock, flags);
50381 /* We are done with the tty pointer now. */
50382 tty_port_tty_set(&hp->port, NULL);
50383@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50384 */
50385 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50386 } else {
50387- if (hp->port.count < 0)
50388+ if (atomic_read(&hp->port.count) < 0)
50389 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50390- hp->vtermno, hp->port.count);
50391+ hp->vtermno, atomic_read(&hp->port.count));
50392 spin_unlock_irqrestore(&hp->port.lock, flags);
50393 }
50394 }
50395@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50396 * open->hangup case this can be called after the final close so prevent
50397 * that from happening for now.
50398 */
50399- if (hp->port.count <= 0) {
50400+ if (atomic_read(&hp->port.count) <= 0) {
50401 spin_unlock_irqrestore(&hp->port.lock, flags);
50402 return;
50403 }
50404
50405- hp->port.count = 0;
50406+ atomic_set(&hp->port.count, 0);
50407 spin_unlock_irqrestore(&hp->port.lock, flags);
50408 tty_port_tty_set(&hp->port, NULL);
50409
50410@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50411 return -EPIPE;
50412
50413 /* FIXME what's this (unprotected) check for? */
50414- if (hp->port.count <= 0)
50415+ if (atomic_read(&hp->port.count) <= 0)
50416 return -EIO;
50417
50418 spin_lock_irqsave(&hp->lock, flags);
50419diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50420index 81e939e..95ead10 100644
50421--- a/drivers/tty/hvc/hvcs.c
50422+++ b/drivers/tty/hvc/hvcs.c
50423@@ -83,6 +83,7 @@
50424 #include <asm/hvcserver.h>
50425 #include <asm/uaccess.h>
50426 #include <asm/vio.h>
50427+#include <asm/local.h>
50428
50429 /*
50430 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50431@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50432
50433 spin_lock_irqsave(&hvcsd->lock, flags);
50434
50435- if (hvcsd->port.count > 0) {
50436+ if (atomic_read(&hvcsd->port.count) > 0) {
50437 spin_unlock_irqrestore(&hvcsd->lock, flags);
50438 printk(KERN_INFO "HVCS: vterm state unchanged. "
50439 "The hvcs device node is still in use.\n");
50440@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50441 }
50442 }
50443
50444- hvcsd->port.count = 0;
50445+ atomic_set(&hvcsd->port.count, 0);
50446 hvcsd->port.tty = tty;
50447 tty->driver_data = hvcsd;
50448
50449@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50450 unsigned long flags;
50451
50452 spin_lock_irqsave(&hvcsd->lock, flags);
50453- hvcsd->port.count++;
50454+ atomic_inc(&hvcsd->port.count);
50455 hvcsd->todo_mask |= HVCS_SCHED_READ;
50456 spin_unlock_irqrestore(&hvcsd->lock, flags);
50457
50458@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50459 hvcsd = tty->driver_data;
50460
50461 spin_lock_irqsave(&hvcsd->lock, flags);
50462- if (--hvcsd->port.count == 0) {
50463+ if (atomic_dec_and_test(&hvcsd->port.count)) {
50464
50465 vio_disable_interrupts(hvcsd->vdev);
50466
50467@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50468
50469 free_irq(irq, hvcsd);
50470 return;
50471- } else if (hvcsd->port.count < 0) {
50472+ } else if (atomic_read(&hvcsd->port.count) < 0) {
50473 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50474 " is missmanaged.\n",
50475- hvcsd->vdev->unit_address, hvcsd->port.count);
50476+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50477 }
50478
50479 spin_unlock_irqrestore(&hvcsd->lock, flags);
50480@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50481
50482 spin_lock_irqsave(&hvcsd->lock, flags);
50483 /* Preserve this so that we know how many kref refs to put */
50484- temp_open_count = hvcsd->port.count;
50485+ temp_open_count = atomic_read(&hvcsd->port.count);
50486
50487 /*
50488 * Don't kref put inside the spinlock because the destruction
50489@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50490 tty->driver_data = NULL;
50491 hvcsd->port.tty = NULL;
50492
50493- hvcsd->port.count = 0;
50494+ atomic_set(&hvcsd->port.count, 0);
50495
50496 /* This will drop any buffered data on the floor which is OK in a hangup
50497 * scenario. */
50498@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50499 * the middle of a write operation? This is a crummy place to do this
50500 * but we want to keep it all in the spinlock.
50501 */
50502- if (hvcsd->port.count <= 0) {
50503+ if (atomic_read(&hvcsd->port.count) <= 0) {
50504 spin_unlock_irqrestore(&hvcsd->lock, flags);
50505 return -ENODEV;
50506 }
50507@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50508 {
50509 struct hvcs_struct *hvcsd = tty->driver_data;
50510
50511- if (!hvcsd || hvcsd->port.count <= 0)
50512+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50513 return 0;
50514
50515 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50516diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50517index 4190199..06d5bfa 100644
50518--- a/drivers/tty/hvc/hvsi.c
50519+++ b/drivers/tty/hvc/hvsi.c
50520@@ -85,7 +85,7 @@ struct hvsi_struct {
50521 int n_outbuf;
50522 uint32_t vtermno;
50523 uint32_t virq;
50524- atomic_t seqno; /* HVSI packet sequence number */
50525+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
50526 uint16_t mctrl;
50527 uint8_t state; /* HVSI protocol state */
50528 uint8_t flags;
50529@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50530
50531 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50532 packet.hdr.len = sizeof(struct hvsi_query_response);
50533- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50534+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50535 packet.verb = VSV_SEND_VERSION_NUMBER;
50536 packet.u.version = HVSI_VERSION;
50537 packet.query_seqno = query_seqno+1;
50538@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50539
50540 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50541 packet.hdr.len = sizeof(struct hvsi_query);
50542- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50543+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50544 packet.verb = verb;
50545
50546 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50547@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50548 int wrote;
50549
50550 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50551- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50552+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50553 packet.hdr.len = sizeof(struct hvsi_control);
50554 packet.verb = VSV_SET_MODEM_CTL;
50555 packet.mask = HVSI_TSDTR;
50556@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50557 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50558
50559 packet.hdr.type = VS_DATA_PACKET_HEADER;
50560- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50561+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50562 packet.hdr.len = count + sizeof(struct hvsi_header);
50563 memcpy(&packet.data, buf, count);
50564
50565@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50566 struct hvsi_control packet __ALIGNED__;
50567
50568 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50569- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50570+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50571 packet.hdr.len = 6;
50572 packet.verb = VSV_CLOSE_PROTOCOL;
50573
50574@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50575
50576 tty_port_tty_set(&hp->port, tty);
50577 spin_lock_irqsave(&hp->lock, flags);
50578- hp->port.count++;
50579+ atomic_inc(&hp->port.count);
50580 atomic_set(&hp->seqno, 0);
50581 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50582 spin_unlock_irqrestore(&hp->lock, flags);
50583@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50584
50585 spin_lock_irqsave(&hp->lock, flags);
50586
50587- if (--hp->port.count == 0) {
50588+ if (atomic_dec_return(&hp->port.count) == 0) {
50589 tty_port_tty_set(&hp->port, NULL);
50590 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50591
50592@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50593
50594 spin_lock_irqsave(&hp->lock, flags);
50595 }
50596- } else if (hp->port.count < 0)
50597+ } else if (atomic_read(&hp->port.count) < 0)
50598 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50599- hp - hvsi_ports, hp->port.count);
50600+ hp - hvsi_ports, atomic_read(&hp->port.count));
50601
50602 spin_unlock_irqrestore(&hp->lock, flags);
50603 }
50604@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50605 tty_port_tty_set(&hp->port, NULL);
50606
50607 spin_lock_irqsave(&hp->lock, flags);
50608- hp->port.count = 0;
50609+ atomic_set(&hp->port.count, 0);
50610 hp->n_outbuf = 0;
50611 spin_unlock_irqrestore(&hp->lock, flags);
50612 }
50613diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50614index 7ae6c29..05c6dba 100644
50615--- a/drivers/tty/hvc/hvsi_lib.c
50616+++ b/drivers/tty/hvc/hvsi_lib.c
50617@@ -8,7 +8,7 @@
50618
50619 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50620 {
50621- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50622+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50623
50624 /* Assumes that always succeeds, works in practice */
50625 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50626@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50627
50628 /* Reset state */
50629 pv->established = 0;
50630- atomic_set(&pv->seqno, 0);
50631+ atomic_set_unchecked(&pv->seqno, 0);
50632
50633 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50634
50635diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50636index 17ee3bf..8d2520d 100644
50637--- a/drivers/tty/ipwireless/tty.c
50638+++ b/drivers/tty/ipwireless/tty.c
50639@@ -28,6 +28,7 @@
50640 #include <linux/tty_driver.h>
50641 #include <linux/tty_flip.h>
50642 #include <linux/uaccess.h>
50643+#include <asm/local.h>
50644
50645 #include "tty.h"
50646 #include "network.h"
50647@@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50648 mutex_unlock(&tty->ipw_tty_mutex);
50649 return -ENODEV;
50650 }
50651- if (tty->port.count == 0)
50652+ if (atomic_read(&tty->port.count) == 0)
50653 tty->tx_bytes_queued = 0;
50654
50655- tty->port.count++;
50656+ atomic_inc(&tty->port.count);
50657
50658 tty->port.tty = linux_tty;
50659 linux_tty->driver_data = tty;
50660@@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50661
50662 static void do_ipw_close(struct ipw_tty *tty)
50663 {
50664- tty->port.count--;
50665-
50666- if (tty->port.count == 0) {
50667+ if (atomic_dec_return(&tty->port.count) == 0) {
50668 struct tty_struct *linux_tty = tty->port.tty;
50669
50670 if (linux_tty != NULL) {
50671@@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50672 return;
50673
50674 mutex_lock(&tty->ipw_tty_mutex);
50675- if (tty->port.count == 0) {
50676+ if (atomic_read(&tty->port.count) == 0) {
50677 mutex_unlock(&tty->ipw_tty_mutex);
50678 return;
50679 }
50680@@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50681
50682 mutex_lock(&tty->ipw_tty_mutex);
50683
50684- if (!tty->port.count) {
50685+ if (!atomic_read(&tty->port.count)) {
50686 mutex_unlock(&tty->ipw_tty_mutex);
50687 return;
50688 }
50689@@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50690 return -ENODEV;
50691
50692 mutex_lock(&tty->ipw_tty_mutex);
50693- if (!tty->port.count) {
50694+ if (!atomic_read(&tty->port.count)) {
50695 mutex_unlock(&tty->ipw_tty_mutex);
50696 return -EINVAL;
50697 }
50698@@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50699 if (!tty)
50700 return -ENODEV;
50701
50702- if (!tty->port.count)
50703+ if (!atomic_read(&tty->port.count))
50704 return -EINVAL;
50705
50706 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50707@@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50708 if (!tty)
50709 return 0;
50710
50711- if (!tty->port.count)
50712+ if (!atomic_read(&tty->port.count))
50713 return 0;
50714
50715 return tty->tx_bytes_queued;
50716@@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50717 if (!tty)
50718 return -ENODEV;
50719
50720- if (!tty->port.count)
50721+ if (!atomic_read(&tty->port.count))
50722 return -EINVAL;
50723
50724 return get_control_lines(tty);
50725@@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50726 if (!tty)
50727 return -ENODEV;
50728
50729- if (!tty->port.count)
50730+ if (!atomic_read(&tty->port.count))
50731 return -EINVAL;
50732
50733 return set_control_lines(tty, set, clear);
50734@@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50735 if (!tty)
50736 return -ENODEV;
50737
50738- if (!tty->port.count)
50739+ if (!atomic_read(&tty->port.count))
50740 return -EINVAL;
50741
50742 /* FIXME: Exactly how is the tty object locked here .. */
50743@@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50744 * are gone */
50745 mutex_lock(&ttyj->ipw_tty_mutex);
50746 }
50747- while (ttyj->port.count)
50748+ while (atomic_read(&ttyj->port.count))
50749 do_ipw_close(ttyj);
50750 ipwireless_disassociate_network_ttys(network,
50751 ttyj->channel_idx);
50752diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50753index 1deaca4..c8582d4 100644
50754--- a/drivers/tty/moxa.c
50755+++ b/drivers/tty/moxa.c
50756@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50757 }
50758
50759 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50760- ch->port.count++;
50761+ atomic_inc(&ch->port.count);
50762 tty->driver_data = ch;
50763 tty_port_tty_set(&ch->port, tty);
50764 mutex_lock(&ch->port.mutex);
50765diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50766index 2ebe47b..3205833 100644
50767--- a/drivers/tty/n_gsm.c
50768+++ b/drivers/tty/n_gsm.c
50769@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50770 spin_lock_init(&dlci->lock);
50771 mutex_init(&dlci->mutex);
50772 dlci->fifo = &dlci->_fifo;
50773- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50774+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50775 kfree(dlci);
50776 return NULL;
50777 }
50778@@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50779 struct gsm_dlci *dlci = tty->driver_data;
50780 struct tty_port *port = &dlci->port;
50781
50782- port->count++;
50783+ atomic_inc(&port->count);
50784 tty_port_tty_set(port, tty);
50785
50786 dlci->modem_rx = 0;
50787diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50788index 0391f17..31fa586 100644
50789--- a/drivers/tty/n_tty.c
50790+++ b/drivers/tty/n_tty.c
50791@@ -115,7 +115,7 @@ struct n_tty_data {
50792 int minimum_to_wake;
50793
50794 /* consumer-published */
50795- size_t read_tail;
50796+ size_t read_tail __intentional_overflow(-1);
50797 size_t line_start;
50798
50799 /* protected by output lock */
50800@@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50801 {
50802 *ops = tty_ldisc_N_TTY;
50803 ops->owner = NULL;
50804- ops->refcount = ops->flags = 0;
50805+ atomic_set(&ops->refcount, 0);
50806+ ops->flags = 0;
50807 }
50808 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50809diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50810index 25c9bc7..24077b7 100644
50811--- a/drivers/tty/pty.c
50812+++ b/drivers/tty/pty.c
50813@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50814 panic("Couldn't register Unix98 pts driver");
50815
50816 /* Now create the /dev/ptmx special device */
50817+ pax_open_kernel();
50818 tty_default_fops(&ptmx_fops);
50819- ptmx_fops.open = ptmx_open;
50820+ *(void **)&ptmx_fops.open = ptmx_open;
50821+ pax_close_kernel();
50822
50823 cdev_init(&ptmx_cdev, &ptmx_fops);
50824 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50825diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50826index 383c4c7..d408e21 100644
50827--- a/drivers/tty/rocket.c
50828+++ b/drivers/tty/rocket.c
50829@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50830 tty->driver_data = info;
50831 tty_port_tty_set(port, tty);
50832
50833- if (port->count++ == 0) {
50834+ if (atomic_inc_return(&port->count) == 1) {
50835 atomic_inc(&rp_num_ports_open);
50836
50837 #ifdef ROCKET_DEBUG_OPEN
50838@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50839 #endif
50840 }
50841 #ifdef ROCKET_DEBUG_OPEN
50842- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50843+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50844 #endif
50845
50846 /*
50847@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50848 spin_unlock_irqrestore(&info->port.lock, flags);
50849 return;
50850 }
50851- if (info->port.count)
50852+ if (atomic_read(&info->port.count))
50853 atomic_dec(&rp_num_ports_open);
50854 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50855 spin_unlock_irqrestore(&info->port.lock, flags);
50856diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50857index 1274499..f541382 100644
50858--- a/drivers/tty/serial/ioc4_serial.c
50859+++ b/drivers/tty/serial/ioc4_serial.c
50860@@ -437,7 +437,7 @@ struct ioc4_soft {
50861 } is_intr_info[MAX_IOC4_INTR_ENTS];
50862
50863 /* Number of entries active in the above array */
50864- atomic_t is_num_intrs;
50865+ atomic_unchecked_t is_num_intrs;
50866 } is_intr_type[IOC4_NUM_INTR_TYPES];
50867
50868 /* is_ir_lock must be held while
50869@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50870 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50871 || (type == IOC4_OTHER_INTR_TYPE)));
50872
50873- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50874+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50875 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50876
50877 /* Save off the lower level interrupt handler */
50878@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50879
50880 soft = arg;
50881 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50882- num_intrs = (int)atomic_read(
50883+ num_intrs = (int)atomic_read_unchecked(
50884 &soft->is_intr_type[intr_type].is_num_intrs);
50885
50886 this_mir = this_ir = pending_intrs(soft, intr_type);
50887diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50888index a260cde..6b2b5ce 100644
50889--- a/drivers/tty/serial/kgdboc.c
50890+++ b/drivers/tty/serial/kgdboc.c
50891@@ -24,8 +24,9 @@
50892 #define MAX_CONFIG_LEN 40
50893
50894 static struct kgdb_io kgdboc_io_ops;
50895+static struct kgdb_io kgdboc_io_ops_console;
50896
50897-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50898+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50899 static int configured = -1;
50900
50901 static char config[MAX_CONFIG_LEN];
50902@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50903 kgdboc_unregister_kbd();
50904 if (configured == 1)
50905 kgdb_unregister_io_module(&kgdboc_io_ops);
50906+ else if (configured == 2)
50907+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
50908 }
50909
50910 static int configure_kgdboc(void)
50911@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50912 int err;
50913 char *cptr = config;
50914 struct console *cons;
50915+ int is_console = 0;
50916
50917 err = kgdboc_option_setup(config);
50918 if (err || !strlen(config) || isspace(config[0]))
50919 goto noconfig;
50920
50921 err = -ENODEV;
50922- kgdboc_io_ops.is_console = 0;
50923 kgdb_tty_driver = NULL;
50924
50925 kgdboc_use_kms = 0;
50926@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50927 int idx;
50928 if (cons->device && cons->device(cons, &idx) == p &&
50929 idx == tty_line) {
50930- kgdboc_io_ops.is_console = 1;
50931+ is_console = 1;
50932 break;
50933 }
50934 cons = cons->next;
50935@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50936 kgdb_tty_line = tty_line;
50937
50938 do_register:
50939- err = kgdb_register_io_module(&kgdboc_io_ops);
50940+ if (is_console) {
50941+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
50942+ configured = 2;
50943+ } else {
50944+ err = kgdb_register_io_module(&kgdboc_io_ops);
50945+ configured = 1;
50946+ }
50947 if (err)
50948 goto noconfig;
50949
50950@@ -205,8 +214,6 @@ do_register:
50951 if (err)
50952 goto nmi_con_failed;
50953
50954- configured = 1;
50955-
50956 return 0;
50957
50958 nmi_con_failed:
50959@@ -223,7 +230,7 @@ noconfig:
50960 static int __init init_kgdboc(void)
50961 {
50962 /* Already configured? */
50963- if (configured == 1)
50964+ if (configured >= 1)
50965 return 0;
50966
50967 return configure_kgdboc();
50968@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50969 if (config[len - 1] == '\n')
50970 config[len - 1] = '\0';
50971
50972- if (configured == 1)
50973+ if (configured >= 1)
50974 cleanup_kgdboc();
50975
50976 /* Go and configure with the new params. */
50977@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50978 .post_exception = kgdboc_post_exp_handler,
50979 };
50980
50981+static struct kgdb_io kgdboc_io_ops_console = {
50982+ .name = "kgdboc",
50983+ .read_char = kgdboc_get_char,
50984+ .write_char = kgdboc_put_char,
50985+ .pre_exception = kgdboc_pre_exp_handler,
50986+ .post_exception = kgdboc_post_exp_handler,
50987+ .is_console = 1
50988+};
50989+
50990 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50991 /* This is only available if kgdboc is a built in for early debugging */
50992 static int __init kgdboc_early_init(char *opt)
50993diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50994index 7307dc4..ce4fe90 100644
50995--- a/drivers/tty/serial/msm_serial.c
50996+++ b/drivers/tty/serial/msm_serial.c
50997@@ -1026,7 +1026,7 @@ static struct uart_driver msm_uart_driver = {
50998 .cons = MSM_CONSOLE,
50999 };
51000
51001-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51002+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51003
51004 static const struct of_device_id msm_uartdm_table[] = {
51005 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
51006@@ -1045,7 +1045,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51007 int irq;
51008
51009 if (pdev->id == -1)
51010- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51011+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51012
51013 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51014 return -ENXIO;
51015diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51016index 1f5505e..a1a767d 100644
51017--- a/drivers/tty/serial/samsung.c
51018+++ b/drivers/tty/serial/samsung.c
51019@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51020 }
51021 }
51022
51023+static int s3c64xx_serial_startup(struct uart_port *port);
51024 static int s3c24xx_serial_startup(struct uart_port *port)
51025 {
51026 struct s3c24xx_uart_port *ourport = to_ourport(port);
51027 int ret;
51028
51029+ /* Startup sequence is different for s3c64xx and higher SoC's */
51030+ if (s3c24xx_serial_has_interrupt_mask(port))
51031+ return s3c64xx_serial_startup(port);
51032+
51033 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51034 port->mapbase, port->membase);
51035
51036@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51037 /* setup info for port */
51038 port->dev = &platdev->dev;
51039
51040- /* Startup sequence is different for s3c64xx and higher SoC's */
51041- if (s3c24xx_serial_has_interrupt_mask(port))
51042- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51043-
51044 port->uartclk = 1;
51045
51046 if (cfg->uart_flags & UPF_CONS_FLOW) {
51047diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51048index b68550d..a62d7f8 100644
51049--- a/drivers/tty/serial/serial_core.c
51050+++ b/drivers/tty/serial/serial_core.c
51051@@ -1329,7 +1329,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
51052
51053 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
51054
51055- if (!port->count || tty_port_close_start(port, tty, filp) == 0)
51056+ if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
51057 return;
51058
51059 /*
51060@@ -1456,7 +1456,7 @@ static void uart_hangup(struct tty_struct *tty)
51061 uart_flush_buffer(tty);
51062 uart_shutdown(tty, state);
51063 spin_lock_irqsave(&port->lock, flags);
51064- port->count = 0;
51065+ atomic_set(&port->count, 0);
51066 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51067 spin_unlock_irqrestore(&port->lock, flags);
51068 tty_port_tty_set(port, NULL);
51069@@ -1554,7 +1554,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51070 goto end;
51071 }
51072
51073- port->count++;
51074+ atomic_inc(&port->count);
51075 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51076 retval = -ENXIO;
51077 goto err_dec_count;
51078@@ -1594,7 +1594,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51079 end:
51080 return retval;
51081 err_dec_count:
51082- port->count--;
51083+ atomic_inc(&port->count);
51084 mutex_unlock(&port->mutex);
51085 goto end;
51086 }
51087diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51088index d48e040..0f52764 100644
51089--- a/drivers/tty/synclink.c
51090+++ b/drivers/tty/synclink.c
51091@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51092
51093 if (debug_level >= DEBUG_LEVEL_INFO)
51094 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51095- __FILE__,__LINE__, info->device_name, info->port.count);
51096+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51097
51098 if (tty_port_close_start(&info->port, tty, filp) == 0)
51099 goto cleanup;
51100@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51101 cleanup:
51102 if (debug_level >= DEBUG_LEVEL_INFO)
51103 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51104- tty->driver->name, info->port.count);
51105+ tty->driver->name, atomic_read(&info->port.count));
51106
51107 } /* end of mgsl_close() */
51108
51109@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51110
51111 mgsl_flush_buffer(tty);
51112 shutdown(info);
51113-
51114- info->port.count = 0;
51115+
51116+ atomic_set(&info->port.count, 0);
51117 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51118 info->port.tty = NULL;
51119
51120@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51121
51122 if (debug_level >= DEBUG_LEVEL_INFO)
51123 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51124- __FILE__,__LINE__, tty->driver->name, port->count );
51125+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51126
51127 spin_lock_irqsave(&info->irq_spinlock, flags);
51128 if (!tty_hung_up_p(filp)) {
51129 extra_count = true;
51130- port->count--;
51131+ atomic_dec(&port->count);
51132 }
51133 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51134 port->blocked_open++;
51135@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51136
51137 if (debug_level >= DEBUG_LEVEL_INFO)
51138 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51139- __FILE__,__LINE__, tty->driver->name, port->count );
51140+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51141
51142 tty_unlock(tty);
51143 schedule();
51144@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51145
51146 /* FIXME: Racy on hangup during close wait */
51147 if (extra_count)
51148- port->count++;
51149+ atomic_inc(&port->count);
51150 port->blocked_open--;
51151
51152 if (debug_level >= DEBUG_LEVEL_INFO)
51153 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51154- __FILE__,__LINE__, tty->driver->name, port->count );
51155+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51156
51157 if (!retval)
51158 port->flags |= ASYNC_NORMAL_ACTIVE;
51159@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51160
51161 if (debug_level >= DEBUG_LEVEL_INFO)
51162 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51163- __FILE__,__LINE__,tty->driver->name, info->port.count);
51164+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51165
51166 /* If port is closing, signal caller to try again */
51167 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51168@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51169 spin_unlock_irqrestore(&info->netlock, flags);
51170 goto cleanup;
51171 }
51172- info->port.count++;
51173+ atomic_inc(&info->port.count);
51174 spin_unlock_irqrestore(&info->netlock, flags);
51175
51176- if (info->port.count == 1) {
51177+ if (atomic_read(&info->port.count) == 1) {
51178 /* 1st open on this device, init hardware */
51179 retval = startup(info);
51180 if (retval < 0)
51181@@ -3446,8 +3446,8 @@ cleanup:
51182 if (retval) {
51183 if (tty->count == 1)
51184 info->port.tty = NULL; /* tty layer will release tty struct */
51185- if(info->port.count)
51186- info->port.count--;
51187+ if (atomic_read(&info->port.count))
51188+ atomic_dec(&info->port.count);
51189 }
51190
51191 return retval;
51192@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51193 unsigned short new_crctype;
51194
51195 /* return error if TTY interface open */
51196- if (info->port.count)
51197+ if (atomic_read(&info->port.count))
51198 return -EBUSY;
51199
51200 switch (encoding)
51201@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51202
51203 /* arbitrate between network and tty opens */
51204 spin_lock_irqsave(&info->netlock, flags);
51205- if (info->port.count != 0 || info->netcount != 0) {
51206+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51207 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51208 spin_unlock_irqrestore(&info->netlock, flags);
51209 return -EBUSY;
51210@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51211 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51212
51213 /* return error if TTY interface open */
51214- if (info->port.count)
51215+ if (atomic_read(&info->port.count))
51216 return -EBUSY;
51217
51218 if (cmd != SIOCWANDEV)
51219diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51220index c359a91..959fc26 100644
51221--- a/drivers/tty/synclink_gt.c
51222+++ b/drivers/tty/synclink_gt.c
51223@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51224 tty->driver_data = info;
51225 info->port.tty = tty;
51226
51227- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51228+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51229
51230 /* If port is closing, signal caller to try again */
51231 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51232@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51233 mutex_unlock(&info->port.mutex);
51234 goto cleanup;
51235 }
51236- info->port.count++;
51237+ atomic_inc(&info->port.count);
51238 spin_unlock_irqrestore(&info->netlock, flags);
51239
51240- if (info->port.count == 1) {
51241+ if (atomic_read(&info->port.count) == 1) {
51242 /* 1st open on this device, init hardware */
51243 retval = startup(info);
51244 if (retval < 0) {
51245@@ -715,8 +715,8 @@ cleanup:
51246 if (retval) {
51247 if (tty->count == 1)
51248 info->port.tty = NULL; /* tty layer will release tty struct */
51249- if(info->port.count)
51250- info->port.count--;
51251+ if(atomic_read(&info->port.count))
51252+ atomic_dec(&info->port.count);
51253 }
51254
51255 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51256@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51257
51258 if (sanity_check(info, tty->name, "close"))
51259 return;
51260- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51261+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51262
51263 if (tty_port_close_start(&info->port, tty, filp) == 0)
51264 goto cleanup;
51265@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51266 tty_port_close_end(&info->port, tty);
51267 info->port.tty = NULL;
51268 cleanup:
51269- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51270+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51271 }
51272
51273 static void hangup(struct tty_struct *tty)
51274@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51275 shutdown(info);
51276
51277 spin_lock_irqsave(&info->port.lock, flags);
51278- info->port.count = 0;
51279+ atomic_set(&info->port.count, 0);
51280 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51281 info->port.tty = NULL;
51282 spin_unlock_irqrestore(&info->port.lock, flags);
51283@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51284 unsigned short new_crctype;
51285
51286 /* return error if TTY interface open */
51287- if (info->port.count)
51288+ if (atomic_read(&info->port.count))
51289 return -EBUSY;
51290
51291 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51292@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51293
51294 /* arbitrate between network and tty opens */
51295 spin_lock_irqsave(&info->netlock, flags);
51296- if (info->port.count != 0 || info->netcount != 0) {
51297+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51298 DBGINFO(("%s hdlc_open busy\n", dev->name));
51299 spin_unlock_irqrestore(&info->netlock, flags);
51300 return -EBUSY;
51301@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51302 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51303
51304 /* return error if TTY interface open */
51305- if (info->port.count)
51306+ if (atomic_read(&info->port.count))
51307 return -EBUSY;
51308
51309 if (cmd != SIOCWANDEV)
51310@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51311 if (port == NULL)
51312 continue;
51313 spin_lock(&port->lock);
51314- if ((port->port.count || port->netcount) &&
51315+ if ((atomic_read(&port->port.count) || port->netcount) &&
51316 port->pending_bh && !port->bh_running &&
51317 !port->bh_requested) {
51318 DBGISR(("%s bh queued\n", port->device_name));
51319@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51320 spin_lock_irqsave(&info->lock, flags);
51321 if (!tty_hung_up_p(filp)) {
51322 extra_count = true;
51323- port->count--;
51324+ atomic_dec(&port->count);
51325 }
51326 spin_unlock_irqrestore(&info->lock, flags);
51327 port->blocked_open++;
51328@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51329 remove_wait_queue(&port->open_wait, &wait);
51330
51331 if (extra_count)
51332- port->count++;
51333+ atomic_inc(&port->count);
51334 port->blocked_open--;
51335
51336 if (!retval)
51337diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51338index 53ba853..3c30f6d 100644
51339--- a/drivers/tty/synclinkmp.c
51340+++ b/drivers/tty/synclinkmp.c
51341@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51342
51343 if (debug_level >= DEBUG_LEVEL_INFO)
51344 printk("%s(%d):%s open(), old ref count = %d\n",
51345- __FILE__,__LINE__,tty->driver->name, info->port.count);
51346+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51347
51348 /* If port is closing, signal caller to try again */
51349 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51350@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51351 spin_unlock_irqrestore(&info->netlock, flags);
51352 goto cleanup;
51353 }
51354- info->port.count++;
51355+ atomic_inc(&info->port.count);
51356 spin_unlock_irqrestore(&info->netlock, flags);
51357
51358- if (info->port.count == 1) {
51359+ if (atomic_read(&info->port.count) == 1) {
51360 /* 1st open on this device, init hardware */
51361 retval = startup(info);
51362 if (retval < 0)
51363@@ -796,8 +796,8 @@ cleanup:
51364 if (retval) {
51365 if (tty->count == 1)
51366 info->port.tty = NULL; /* tty layer will release tty struct */
51367- if(info->port.count)
51368- info->port.count--;
51369+ if(atomic_read(&info->port.count))
51370+ atomic_dec(&info->port.count);
51371 }
51372
51373 return retval;
51374@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51375
51376 if (debug_level >= DEBUG_LEVEL_INFO)
51377 printk("%s(%d):%s close() entry, count=%d\n",
51378- __FILE__,__LINE__, info->device_name, info->port.count);
51379+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51380
51381 if (tty_port_close_start(&info->port, tty, filp) == 0)
51382 goto cleanup;
51383@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51384 cleanup:
51385 if (debug_level >= DEBUG_LEVEL_INFO)
51386 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51387- tty->driver->name, info->port.count);
51388+ tty->driver->name, atomic_read(&info->port.count));
51389 }
51390
51391 /* Called by tty_hangup() when a hangup is signaled.
51392@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51393 shutdown(info);
51394
51395 spin_lock_irqsave(&info->port.lock, flags);
51396- info->port.count = 0;
51397+ atomic_set(&info->port.count, 0);
51398 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51399 info->port.tty = NULL;
51400 spin_unlock_irqrestore(&info->port.lock, flags);
51401@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51402 unsigned short new_crctype;
51403
51404 /* return error if TTY interface open */
51405- if (info->port.count)
51406+ if (atomic_read(&info->port.count))
51407 return -EBUSY;
51408
51409 switch (encoding)
51410@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51411
51412 /* arbitrate between network and tty opens */
51413 spin_lock_irqsave(&info->netlock, flags);
51414- if (info->port.count != 0 || info->netcount != 0) {
51415+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51416 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51417 spin_unlock_irqrestore(&info->netlock, flags);
51418 return -EBUSY;
51419@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51420 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51421
51422 /* return error if TTY interface open */
51423- if (info->port.count)
51424+ if (atomic_read(&info->port.count))
51425 return -EBUSY;
51426
51427 if (cmd != SIOCWANDEV)
51428@@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51429 * do not request bottom half processing if the
51430 * device is not open in a normal mode.
51431 */
51432- if ( port && (port->port.count || port->netcount) &&
51433+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51434 port->pending_bh && !port->bh_running &&
51435 !port->bh_requested ) {
51436 if ( debug_level >= DEBUG_LEVEL_ISR )
51437@@ -3319,12 +3319,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51438
51439 if (debug_level >= DEBUG_LEVEL_INFO)
51440 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51441- __FILE__,__LINE__, tty->driver->name, port->count );
51442+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51443
51444 spin_lock_irqsave(&info->lock, flags);
51445 if (!tty_hung_up_p(filp)) {
51446 extra_count = true;
51447- port->count--;
51448+ atomic_dec(&port->count);
51449 }
51450 spin_unlock_irqrestore(&info->lock, flags);
51451 port->blocked_open++;
51452@@ -3353,7 +3353,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51453
51454 if (debug_level >= DEBUG_LEVEL_INFO)
51455 printk("%s(%d):%s block_til_ready() count=%d\n",
51456- __FILE__,__LINE__, tty->driver->name, port->count );
51457+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51458
51459 tty_unlock(tty);
51460 schedule();
51461@@ -3364,12 +3364,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51462 remove_wait_queue(&port->open_wait, &wait);
51463
51464 if (extra_count)
51465- port->count++;
51466+ atomic_inc(&port->count);
51467 port->blocked_open--;
51468
51469 if (debug_level >= DEBUG_LEVEL_INFO)
51470 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51471- __FILE__,__LINE__, tty->driver->name, port->count );
51472+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51473
51474 if (!retval)
51475 port->flags |= ASYNC_NORMAL_ACTIVE;
51476diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51477index ce396ec..04a37be 100644
51478--- a/drivers/tty/sysrq.c
51479+++ b/drivers/tty/sysrq.c
51480@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51481 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51482 size_t count, loff_t *ppos)
51483 {
51484- if (count) {
51485+ if (count && capable(CAP_SYS_ADMIN)) {
51486 char c;
51487
51488 if (get_user(c, buf))
51489diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51490index 3411071..86f2cf2 100644
51491--- a/drivers/tty/tty_io.c
51492+++ b/drivers/tty/tty_io.c
51493@@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51494
51495 void tty_default_fops(struct file_operations *fops)
51496 {
51497- *fops = tty_fops;
51498+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51499 }
51500
51501 /*
51502diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51503index 2d822aa..a566234 100644
51504--- a/drivers/tty/tty_ldisc.c
51505+++ b/drivers/tty/tty_ldisc.c
51506@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51507 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51508 tty_ldiscs[disc] = new_ldisc;
51509 new_ldisc->num = disc;
51510- new_ldisc->refcount = 0;
51511+ atomic_set(&new_ldisc->refcount, 0);
51512 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51513
51514 return ret;
51515@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51516 return -EINVAL;
51517
51518 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51519- if (tty_ldiscs[disc]->refcount)
51520+ if (atomic_read(&tty_ldiscs[disc]->refcount))
51521 ret = -EBUSY;
51522 else
51523 tty_ldiscs[disc] = NULL;
51524@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51525 if (ldops) {
51526 ret = ERR_PTR(-EAGAIN);
51527 if (try_module_get(ldops->owner)) {
51528- ldops->refcount++;
51529+ atomic_inc(&ldops->refcount);
51530 ret = ldops;
51531 }
51532 }
51533@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51534 unsigned long flags;
51535
51536 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51537- ldops->refcount--;
51538+ atomic_dec(&ldops->refcount);
51539 module_put(ldops->owner);
51540 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51541 }
51542diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51543index 3f746c8..2f2fcaa 100644
51544--- a/drivers/tty/tty_port.c
51545+++ b/drivers/tty/tty_port.c
51546@@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51547 unsigned long flags;
51548
51549 spin_lock_irqsave(&port->lock, flags);
51550- port->count = 0;
51551+ atomic_set(&port->count, 0);
51552 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51553 tty = port->tty;
51554 if (tty)
51555@@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51556 /* The port lock protects the port counts */
51557 spin_lock_irqsave(&port->lock, flags);
51558 if (!tty_hung_up_p(filp))
51559- port->count--;
51560+ atomic_dec(&port->count);
51561 port->blocked_open++;
51562 spin_unlock_irqrestore(&port->lock, flags);
51563
51564@@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51565 we must not mess that up further */
51566 spin_lock_irqsave(&port->lock, flags);
51567 if (!tty_hung_up_p(filp))
51568- port->count++;
51569+ atomic_inc(&port->count);
51570 port->blocked_open--;
51571 if (retval == 0)
51572 port->flags |= ASYNC_NORMAL_ACTIVE;
51573@@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51574 return 0;
51575 }
51576
51577- if (tty->count == 1 && port->count != 1) {
51578+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
51579 printk(KERN_WARNING
51580 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51581- port->count);
51582- port->count = 1;
51583+ atomic_read(&port->count));
51584+ atomic_set(&port->count, 1);
51585 }
51586- if (--port->count < 0) {
51587+ if (atomic_dec_return(&port->count) < 0) {
51588 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51589- port->count);
51590- port->count = 0;
51591+ atomic_read(&port->count));
51592+ atomic_set(&port->count, 0);
51593 }
51594
51595- if (port->count) {
51596+ if (atomic_read(&port->count)) {
51597 spin_unlock_irqrestore(&port->lock, flags);
51598 return 0;
51599 }
51600@@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51601 {
51602 spin_lock_irq(&port->lock);
51603 if (!tty_hung_up_p(filp))
51604- ++port->count;
51605+ atomic_inc(&port->count);
51606 spin_unlock_irq(&port->lock);
51607 tty_port_tty_set(port, tty);
51608
51609diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51610index d0e3a44..5f8b754 100644
51611--- a/drivers/tty/vt/keyboard.c
51612+++ b/drivers/tty/vt/keyboard.c
51613@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51614 kbd->kbdmode == VC_OFF) &&
51615 value != KVAL(K_SAK))
51616 return; /* SAK is allowed even in raw mode */
51617+
51618+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51619+ {
51620+ void *func = fn_handler[value];
51621+ if (func == fn_show_state || func == fn_show_ptregs ||
51622+ func == fn_show_mem)
51623+ return;
51624+ }
51625+#endif
51626+
51627 fn_handler[value](vc);
51628 }
51629
51630@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51631 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51632 return -EFAULT;
51633
51634- if (!capable(CAP_SYS_TTY_CONFIG))
51635- perm = 0;
51636-
51637 switch (cmd) {
51638 case KDGKBENT:
51639 /* Ensure another thread doesn't free it under us */
51640@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51641 spin_unlock_irqrestore(&kbd_event_lock, flags);
51642 return put_user(val, &user_kbe->kb_value);
51643 case KDSKBENT:
51644+ if (!capable(CAP_SYS_TTY_CONFIG))
51645+ perm = 0;
51646+
51647 if (!perm)
51648 return -EPERM;
51649 if (!i && v == K_NOSUCHMAP) {
51650@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51651 int i, j, k;
51652 int ret;
51653
51654- if (!capable(CAP_SYS_TTY_CONFIG))
51655- perm = 0;
51656-
51657 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51658 if (!kbs) {
51659 ret = -ENOMEM;
51660@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51661 kfree(kbs);
51662 return ((p && *p) ? -EOVERFLOW : 0);
51663 case KDSKBSENT:
51664+ if (!capable(CAP_SYS_TTY_CONFIG))
51665+ perm = 0;
51666+
51667 if (!perm) {
51668 ret = -EPERM;
51669 goto reterr;
51670diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51671index a673e5b..36e5d32 100644
51672--- a/drivers/uio/uio.c
51673+++ b/drivers/uio/uio.c
51674@@ -25,6 +25,7 @@
51675 #include <linux/kobject.h>
51676 #include <linux/cdev.h>
51677 #include <linux/uio_driver.h>
51678+#include <asm/local.h>
51679
51680 #define UIO_MAX_DEVICES (1U << MINORBITS)
51681
51682@@ -32,7 +33,7 @@ struct uio_device {
51683 struct module *owner;
51684 struct device *dev;
51685 int minor;
51686- atomic_t event;
51687+ atomic_unchecked_t event;
51688 struct fasync_struct *async_queue;
51689 wait_queue_head_t wait;
51690 struct uio_info *info;
51691@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51692 struct device_attribute *attr, char *buf)
51693 {
51694 struct uio_device *idev = dev_get_drvdata(dev);
51695- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51696+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51697 }
51698 static DEVICE_ATTR_RO(event);
51699
51700@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51701 {
51702 struct uio_device *idev = info->uio_dev;
51703
51704- atomic_inc(&idev->event);
51705+ atomic_inc_unchecked(&idev->event);
51706 wake_up_interruptible(&idev->wait);
51707 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51708 }
51709@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51710 }
51711
51712 listener->dev = idev;
51713- listener->event_count = atomic_read(&idev->event);
51714+ listener->event_count = atomic_read_unchecked(&idev->event);
51715 filep->private_data = listener;
51716
51717 if (idev->info->open) {
51718@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51719 return -EIO;
51720
51721 poll_wait(filep, &idev->wait, wait);
51722- if (listener->event_count != atomic_read(&idev->event))
51723+ if (listener->event_count != atomic_read_unchecked(&idev->event))
51724 return POLLIN | POLLRDNORM;
51725 return 0;
51726 }
51727@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51728 do {
51729 set_current_state(TASK_INTERRUPTIBLE);
51730
51731- event_count = atomic_read(&idev->event);
51732+ event_count = atomic_read_unchecked(&idev->event);
51733 if (event_count != listener->event_count) {
51734 if (copy_to_user(buf, &event_count, count))
51735 retval = -EFAULT;
51736@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51737 static int uio_find_mem_index(struct vm_area_struct *vma)
51738 {
51739 struct uio_device *idev = vma->vm_private_data;
51740+ unsigned long size;
51741
51742 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51743- if (idev->info->mem[vma->vm_pgoff].size == 0)
51744+ size = idev->info->mem[vma->vm_pgoff].size;
51745+ if (size == 0)
51746+ return -1;
51747+ if (vma->vm_end - vma->vm_start > size)
51748 return -1;
51749 return (int)vma->vm_pgoff;
51750 }
51751@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51752 idev->owner = owner;
51753 idev->info = info;
51754 init_waitqueue_head(&idev->wait);
51755- atomic_set(&idev->event, 0);
51756+ atomic_set_unchecked(&idev->event, 0);
51757
51758 ret = uio_get_minor(idev);
51759 if (ret)
51760diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51761index 813d4d3..a71934f 100644
51762--- a/drivers/usb/atm/cxacru.c
51763+++ b/drivers/usb/atm/cxacru.c
51764@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51765 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51766 if (ret < 2)
51767 return -EINVAL;
51768- if (index < 0 || index > 0x7f)
51769+ if (index > 0x7f)
51770 return -EINVAL;
51771 pos += tmp;
51772
51773diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51774index dada014..1d0d517 100644
51775--- a/drivers/usb/atm/usbatm.c
51776+++ b/drivers/usb/atm/usbatm.c
51777@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51778 if (printk_ratelimit())
51779 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51780 __func__, vpi, vci);
51781- atomic_inc(&vcc->stats->rx_err);
51782+ atomic_inc_unchecked(&vcc->stats->rx_err);
51783 return;
51784 }
51785
51786@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51787 if (length > ATM_MAX_AAL5_PDU) {
51788 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51789 __func__, length, vcc);
51790- atomic_inc(&vcc->stats->rx_err);
51791+ atomic_inc_unchecked(&vcc->stats->rx_err);
51792 goto out;
51793 }
51794
51795@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51796 if (sarb->len < pdu_length) {
51797 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51798 __func__, pdu_length, sarb->len, vcc);
51799- atomic_inc(&vcc->stats->rx_err);
51800+ atomic_inc_unchecked(&vcc->stats->rx_err);
51801 goto out;
51802 }
51803
51804 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51805 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51806 __func__, vcc);
51807- atomic_inc(&vcc->stats->rx_err);
51808+ atomic_inc_unchecked(&vcc->stats->rx_err);
51809 goto out;
51810 }
51811
51812@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51813 if (printk_ratelimit())
51814 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51815 __func__, length);
51816- atomic_inc(&vcc->stats->rx_drop);
51817+ atomic_inc_unchecked(&vcc->stats->rx_drop);
51818 goto out;
51819 }
51820
51821@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51822
51823 vcc->push(vcc, skb);
51824
51825- atomic_inc(&vcc->stats->rx);
51826+ atomic_inc_unchecked(&vcc->stats->rx);
51827 out:
51828 skb_trim(sarb, 0);
51829 }
51830@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51831 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51832
51833 usbatm_pop(vcc, skb);
51834- atomic_inc(&vcc->stats->tx);
51835+ atomic_inc_unchecked(&vcc->stats->tx);
51836
51837 skb = skb_dequeue(&instance->sndqueue);
51838 }
51839@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
51840 if (!left--)
51841 return sprintf(page,
51842 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51843- atomic_read(&atm_dev->stats.aal5.tx),
51844- atomic_read(&atm_dev->stats.aal5.tx_err),
51845- atomic_read(&atm_dev->stats.aal5.rx),
51846- atomic_read(&atm_dev->stats.aal5.rx_err),
51847- atomic_read(&atm_dev->stats.aal5.rx_drop));
51848+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51849+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51850+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51851+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51852+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51853
51854 if (!left--) {
51855 if (instance->disconnected)
51856diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51857index 2a3bbdf..91d72cf 100644
51858--- a/drivers/usb/core/devices.c
51859+++ b/drivers/usb/core/devices.c
51860@@ -126,7 +126,7 @@ static const char format_endpt[] =
51861 * time it gets called.
51862 */
51863 static struct device_connect_event {
51864- atomic_t count;
51865+ atomic_unchecked_t count;
51866 wait_queue_head_t wait;
51867 } device_event = {
51868 .count = ATOMIC_INIT(1),
51869@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51870
51871 void usbfs_conn_disc_event(void)
51872 {
51873- atomic_add(2, &device_event.count);
51874+ atomic_add_unchecked(2, &device_event.count);
51875 wake_up(&device_event.wait);
51876 }
51877
51878@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51879
51880 poll_wait(file, &device_event.wait, wait);
51881
51882- event_count = atomic_read(&device_event.count);
51883+ event_count = atomic_read_unchecked(&device_event.count);
51884 if (file->f_version != event_count) {
51885 file->f_version = event_count;
51886 return POLLIN | POLLRDNORM;
51887diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51888index 257876e..4304364 100644
51889--- a/drivers/usb/core/devio.c
51890+++ b/drivers/usb/core/devio.c
51891@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51892 struct usb_dev_state *ps = file->private_data;
51893 struct usb_device *dev = ps->dev;
51894 ssize_t ret = 0;
51895- unsigned len;
51896+ size_t len;
51897 loff_t pos;
51898 int i;
51899
51900@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51901 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51902 struct usb_config_descriptor *config =
51903 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51904- unsigned int length = le16_to_cpu(config->wTotalLength);
51905+ size_t length = le16_to_cpu(config->wTotalLength);
51906
51907 if (*ppos < pos + length) {
51908
51909 /* The descriptor may claim to be longer than it
51910 * really is. Here is the actual allocated length. */
51911- unsigned alloclen =
51912+ size_t alloclen =
51913 le16_to_cpu(dev->config[i].desc.wTotalLength);
51914
51915- len = length - (*ppos - pos);
51916+ len = length + pos - *ppos;
51917 if (len > nbytes)
51918 len = nbytes;
51919
51920 /* Simply don't write (skip over) unallocated parts */
51921 if (alloclen > (*ppos - pos)) {
51922- alloclen -= (*ppos - pos);
51923+ alloclen = alloclen + pos - *ppos;
51924 if (copy_to_user(buf,
51925 dev->rawdescriptors[i] + (*ppos - pos),
51926 min(len, alloclen))) {
51927diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51928index 9c4e292..b89877f 100644
51929--- a/drivers/usb/core/hcd.c
51930+++ b/drivers/usb/core/hcd.c
51931@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51932 */
51933 usb_get_urb(urb);
51934 atomic_inc(&urb->use_count);
51935- atomic_inc(&urb->dev->urbnum);
51936+ atomic_inc_unchecked(&urb->dev->urbnum);
51937 usbmon_urb_submit(&hcd->self, urb);
51938
51939 /* NOTE requirements on root-hub callers (usbfs and the hub
51940@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51941 urb->hcpriv = NULL;
51942 INIT_LIST_HEAD(&urb->urb_list);
51943 atomic_dec(&urb->use_count);
51944- atomic_dec(&urb->dev->urbnum);
51945+ atomic_dec_unchecked(&urb->dev->urbnum);
51946 if (atomic_read(&urb->reject))
51947 wake_up(&usb_kill_urb_queue);
51948 usb_put_urb(urb);
51949diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51950index 229a73f..ef86f98 100644
51951--- a/drivers/usb/core/hub.c
51952+++ b/drivers/usb/core/hub.c
51953@@ -27,6 +27,7 @@
51954 #include <linux/freezer.h>
51955 #include <linux/random.h>
51956 #include <linux/pm_qos.h>
51957+#include <linux/grsecurity.h>
51958
51959 #include <asm/uaccess.h>
51960 #include <asm/byteorder.h>
51961@@ -4512,6 +4513,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51962 goto done;
51963 return;
51964 }
51965+
51966+ if (gr_handle_new_usb())
51967+ goto done;
51968+
51969 if (hub_is_superspeed(hub->hdev))
51970 unit_load = 150;
51971 else
51972diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51973index 0c8a7fc..c45b40a 100644
51974--- a/drivers/usb/core/message.c
51975+++ b/drivers/usb/core/message.c
51976@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51977 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51978 * error number.
51979 */
51980-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51981+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51982 __u8 requesttype, __u16 value, __u16 index, void *data,
51983 __u16 size, int timeout)
51984 {
51985@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51986 * If successful, 0. Otherwise a negative error number. The number of actual
51987 * bytes transferred will be stored in the @actual_length parameter.
51988 */
51989-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51990+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51991 void *data, int len, int *actual_length, int timeout)
51992 {
51993 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51994@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51995 * bytes transferred will be stored in the @actual_length parameter.
51996 *
51997 */
51998-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51999+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52000 void *data, int len, int *actual_length, int timeout)
52001 {
52002 struct urb *urb;
52003diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52004index 1236c60..d47a51c 100644
52005--- a/drivers/usb/core/sysfs.c
52006+++ b/drivers/usb/core/sysfs.c
52007@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52008 struct usb_device *udev;
52009
52010 udev = to_usb_device(dev);
52011- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52012+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52013 }
52014 static DEVICE_ATTR_RO(urbnum);
52015
52016diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52017index 4d11449..f4ccabf 100644
52018--- a/drivers/usb/core/usb.c
52019+++ b/drivers/usb/core/usb.c
52020@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52021 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52022 dev->state = USB_STATE_ATTACHED;
52023 dev->lpm_disable_count = 1;
52024- atomic_set(&dev->urbnum, 0);
52025+ atomic_set_unchecked(&dev->urbnum, 0);
52026
52027 INIT_LIST_HEAD(&dev->ep0.urb_list);
52028 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52029diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52030index 85f398d..d375bbe 100644
52031--- a/drivers/usb/dwc3/gadget.c
52032+++ b/drivers/usb/dwc3/gadget.c
52033@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52034 if (!usb_endpoint_xfer_isoc(desc))
52035 return 0;
52036
52037- memset(&trb_link, 0, sizeof(trb_link));
52038-
52039 /* Link TRB for ISOC. The HWO bit is never reset */
52040 trb_st_hw = &dep->trb_pool[0];
52041
52042diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52043index 8cfc319..4868255 100644
52044--- a/drivers/usb/early/ehci-dbgp.c
52045+++ b/drivers/usb/early/ehci-dbgp.c
52046@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52047
52048 #ifdef CONFIG_KGDB
52049 static struct kgdb_io kgdbdbgp_io_ops;
52050-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52051+static struct kgdb_io kgdbdbgp_io_ops_console;
52052+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52053 #else
52054 #define dbgp_kgdb_mode (0)
52055 #endif
52056@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52057 .write_char = kgdbdbgp_write_char,
52058 };
52059
52060+static struct kgdb_io kgdbdbgp_io_ops_console = {
52061+ .name = "kgdbdbgp",
52062+ .read_char = kgdbdbgp_read_char,
52063+ .write_char = kgdbdbgp_write_char,
52064+ .is_console = 1
52065+};
52066+
52067 static int kgdbdbgp_wait_time;
52068
52069 static int __init kgdbdbgp_parse_config(char *str)
52070@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52071 ptr++;
52072 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52073 }
52074- kgdb_register_io_module(&kgdbdbgp_io_ops);
52075- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52076+ if (early_dbgp_console.index != -1)
52077+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52078+ else
52079+ kgdb_register_io_module(&kgdbdbgp_io_ops);
52080
52081 return 0;
52082 }
52083diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52084index 2b4c82d..06a8ee6 100644
52085--- a/drivers/usb/gadget/f_uac1.c
52086+++ b/drivers/usb/gadget/f_uac1.c
52087@@ -13,6 +13,7 @@
52088 #include <linux/kernel.h>
52089 #include <linux/device.h>
52090 #include <linux/atomic.h>
52091+#include <linux/module.h>
52092
52093 #include "u_uac1.h"
52094
52095diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52096index ad0aca8..8ff84865 100644
52097--- a/drivers/usb/gadget/u_serial.c
52098+++ b/drivers/usb/gadget/u_serial.c
52099@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52100 spin_lock_irq(&port->port_lock);
52101
52102 /* already open? Great. */
52103- if (port->port.count) {
52104+ if (atomic_read(&port->port.count)) {
52105 status = 0;
52106- port->port.count++;
52107+ atomic_inc(&port->port.count);
52108
52109 /* currently opening/closing? wait ... */
52110 } else if (port->openclose) {
52111@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52112 tty->driver_data = port;
52113 port->port.tty = tty;
52114
52115- port->port.count = 1;
52116+ atomic_set(&port->port.count, 1);
52117 port->openclose = false;
52118
52119 /* if connected, start the I/O stream */
52120@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52121
52122 spin_lock_irq(&port->port_lock);
52123
52124- if (port->port.count != 1) {
52125- if (port->port.count == 0)
52126+ if (atomic_read(&port->port.count) != 1) {
52127+ if (atomic_read(&port->port.count) == 0)
52128 WARN_ON(1);
52129 else
52130- --port->port.count;
52131+ atomic_dec(&port->port.count);
52132 goto exit;
52133 }
52134
52135@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52136 * and sleep if necessary
52137 */
52138 port->openclose = true;
52139- port->port.count = 0;
52140+ atomic_set(&port->port.count, 0);
52141
52142 gser = port->port_usb;
52143 if (gser && gser->disconnect)
52144@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52145 int cond;
52146
52147 spin_lock_irq(&port->port_lock);
52148- cond = (port->port.count == 0) && !port->openclose;
52149+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52150 spin_unlock_irq(&port->port_lock);
52151 return cond;
52152 }
52153@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52154 /* if it's already open, start I/O ... and notify the serial
52155 * protocol about open/close status (connect/disconnect).
52156 */
52157- if (port->port.count) {
52158+ if (atomic_read(&port->port.count)) {
52159 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52160 gs_start_io(port);
52161 if (gser->connect)
52162@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52163
52164 port->port_usb = NULL;
52165 gser->ioport = NULL;
52166- if (port->port.count > 0 || port->openclose) {
52167+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
52168 wake_up_interruptible(&port->drain_wait);
52169 if (port->port.tty)
52170 tty_hangup(port->port.tty);
52171@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52172
52173 /* finally, free any unused/unusable I/O buffers */
52174 spin_lock_irqsave(&port->port_lock, flags);
52175- if (port->port.count == 0 && !port->openclose)
52176+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
52177 gs_buf_free(&port->port_write_buf);
52178 gs_free_requests(gser->out, &port->read_pool, NULL);
52179 gs_free_requests(gser->out, &port->read_queue, NULL);
52180diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52181index 7a55fea..cc0ed4f 100644
52182--- a/drivers/usb/gadget/u_uac1.c
52183+++ b/drivers/usb/gadget/u_uac1.c
52184@@ -16,6 +16,7 @@
52185 #include <linux/ctype.h>
52186 #include <linux/random.h>
52187 #include <linux/syscalls.h>
52188+#include <linux/module.h>
52189
52190 #include "u_uac1.h"
52191
52192diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52193index 7ae0c4d..35521b7 100644
52194--- a/drivers/usb/host/ehci-hub.c
52195+++ b/drivers/usb/host/ehci-hub.c
52196@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52197 urb->transfer_flags = URB_DIR_IN;
52198 usb_get_urb(urb);
52199 atomic_inc(&urb->use_count);
52200- atomic_inc(&urb->dev->urbnum);
52201+ atomic_inc_unchecked(&urb->dev->urbnum);
52202 urb->setup_dma = dma_map_single(
52203 hcd->self.controller,
52204 urb->setup_packet,
52205@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52206 urb->status = -EINPROGRESS;
52207 usb_get_urb(urb);
52208 atomic_inc(&urb->use_count);
52209- atomic_inc(&urb->dev->urbnum);
52210+ atomic_inc_unchecked(&urb->dev->urbnum);
52211 retval = submit_single_step_set_feature(hcd, urb, 0);
52212 if (!retval && !wait_for_completion_timeout(&done,
52213 msecs_to_jiffies(2000))) {
52214diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52215index ba6a5d6..f88f7f3 100644
52216--- a/drivers/usb/misc/appledisplay.c
52217+++ b/drivers/usb/misc/appledisplay.c
52218@@ -83,7 +83,7 @@ struct appledisplay {
52219 spinlock_t lock;
52220 };
52221
52222-static atomic_t count_displays = ATOMIC_INIT(0);
52223+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52224 static struct workqueue_struct *wq;
52225
52226 static void appledisplay_complete(struct urb *urb)
52227@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52228
52229 /* Register backlight device */
52230 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52231- atomic_inc_return(&count_displays) - 1);
52232+ atomic_inc_return_unchecked(&count_displays) - 1);
52233 memset(&props, 0, sizeof(struct backlight_properties));
52234 props.type = BACKLIGHT_RAW;
52235 props.max_brightness = 0xff;
52236diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52237index 8d7fc48..01c4986 100644
52238--- a/drivers/usb/serial/console.c
52239+++ b/drivers/usb/serial/console.c
52240@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52241
52242 info->port = port;
52243
52244- ++port->port.count;
52245+ atomic_inc(&port->port.count);
52246 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52247 if (serial->type->set_termios) {
52248 /*
52249@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52250 }
52251 /* Now that any required fake tty operations are completed restore
52252 * the tty port count */
52253- --port->port.count;
52254+ atomic_dec(&port->port.count);
52255 /* The console is special in terms of closing the device so
52256 * indicate this port is now acting as a system console. */
52257 port->port.console = 1;
52258@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52259 free_tty:
52260 kfree(tty);
52261 reset_open_count:
52262- port->port.count = 0;
52263+ atomic_set(&port->port.count, 0);
52264 usb_autopm_put_interface(serial->interface);
52265 error_get_interface:
52266 usb_serial_put(serial);
52267@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52268 static void usb_console_write(struct console *co,
52269 const char *buf, unsigned count)
52270 {
52271- static struct usbcons_info *info = &usbcons_info;
52272+ struct usbcons_info *info = &usbcons_info;
52273 struct usb_serial_port *port = info->port;
52274 struct usb_serial *serial;
52275 int retval = -ENODEV;
52276diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52277index 307e339..6aa97cb 100644
52278--- a/drivers/usb/storage/usb.h
52279+++ b/drivers/usb/storage/usb.h
52280@@ -63,7 +63,7 @@ struct us_unusual_dev {
52281 __u8 useProtocol;
52282 __u8 useTransport;
52283 int (*initFunction)(struct us_data *);
52284-};
52285+} __do_const;
52286
52287
52288 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52289diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52290index f2a8d29..7bc3fe7 100644
52291--- a/drivers/usb/wusbcore/wa-hc.h
52292+++ b/drivers/usb/wusbcore/wa-hc.h
52293@@ -240,7 +240,7 @@ struct wahc {
52294 spinlock_t xfer_list_lock;
52295 struct work_struct xfer_enqueue_work;
52296 struct work_struct xfer_error_work;
52297- atomic_t xfer_id_count;
52298+ atomic_unchecked_t xfer_id_count;
52299
52300 kernel_ulong_t quirks;
52301 };
52302@@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
52303 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52304 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52305 wa->dto_in_use = 0;
52306- atomic_set(&wa->xfer_id_count, 1);
52307+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52308 /* init the buf in URBs */
52309 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
52310 usb_init_urb(&(wa->buf_in_urbs[index]));
52311diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52312index 3e2e4ed..060c9b8 100644
52313--- a/drivers/usb/wusbcore/wa-xfer.c
52314+++ b/drivers/usb/wusbcore/wa-xfer.c
52315@@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52316 */
52317 static void wa_xfer_id_init(struct wa_xfer *xfer)
52318 {
52319- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52320+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52321 }
52322
52323 /* Return the xfer's ID. */
52324diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52325index 512f479..7e041d0 100644
52326--- a/drivers/vfio/vfio.c
52327+++ b/drivers/vfio/vfio.c
52328@@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52329 return 0;
52330
52331 /* TODO Prevent device auto probing */
52332- WARN("Device %s added to live group %d!\n", dev_name(dev),
52333+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52334 iommu_group_id(group->iommu_group));
52335
52336 return 0;
52337diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52338index 5174eba..451e6bc 100644
52339--- a/drivers/vhost/vringh.c
52340+++ b/drivers/vhost/vringh.c
52341@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52342 /* Userspace access helpers: in this case, addresses are really userspace. */
52343 static inline int getu16_user(u16 *val, const u16 *p)
52344 {
52345- return get_user(*val, (__force u16 __user *)p);
52346+ return get_user(*val, (u16 __force_user *)p);
52347 }
52348
52349 static inline int putu16_user(u16 *p, u16 val)
52350 {
52351- return put_user(val, (__force u16 __user *)p);
52352+ return put_user(val, (u16 __force_user *)p);
52353 }
52354
52355 static inline int copydesc_user(void *dst, const void *src, size_t len)
52356 {
52357- return copy_from_user(dst, (__force void __user *)src, len) ?
52358+ return copy_from_user(dst, (void __force_user *)src, len) ?
52359 -EFAULT : 0;
52360 }
52361
52362@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52363 const struct vring_used_elem *src,
52364 unsigned int num)
52365 {
52366- return copy_to_user((__force void __user *)dst, src,
52367+ return copy_to_user((void __force_user *)dst, src,
52368 sizeof(*dst) * num) ? -EFAULT : 0;
52369 }
52370
52371 static inline int xfer_from_user(void *src, void *dst, size_t len)
52372 {
52373- return copy_from_user(dst, (__force void __user *)src, len) ?
52374+ return copy_from_user(dst, (void __force_user *)src, len) ?
52375 -EFAULT : 0;
52376 }
52377
52378 static inline int xfer_to_user(void *dst, void *src, size_t len)
52379 {
52380- return copy_to_user((__force void __user *)dst, src, len) ?
52381+ return copy_to_user((void __force_user *)dst, src, len) ?
52382 -EFAULT : 0;
52383 }
52384
52385@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52386 vrh->last_used_idx = 0;
52387 vrh->vring.num = num;
52388 /* vring expects kernel addresses, but only used via accessors. */
52389- vrh->vring.desc = (__force struct vring_desc *)desc;
52390- vrh->vring.avail = (__force struct vring_avail *)avail;
52391- vrh->vring.used = (__force struct vring_used *)used;
52392+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52393+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52394+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52395 return 0;
52396 }
52397 EXPORT_SYMBOL(vringh_init_user);
52398@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52399
52400 static inline int putu16_kern(u16 *p, u16 val)
52401 {
52402- ACCESS_ONCE(*p) = val;
52403+ ACCESS_ONCE_RW(*p) = val;
52404 return 0;
52405 }
52406
52407diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52408index 84a110a..96312c3 100644
52409--- a/drivers/video/backlight/kb3886_bl.c
52410+++ b/drivers/video/backlight/kb3886_bl.c
52411@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52412 static unsigned long kb3886bl_flags;
52413 #define KB3886BL_SUSPENDED 0x01
52414
52415-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52416+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52417 {
52418 .ident = "Sahara Touch-iT",
52419 .matches = {
52420diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
52421index 1b0b233..6f34c2c 100644
52422--- a/drivers/video/fbdev/arcfb.c
52423+++ b/drivers/video/fbdev/arcfb.c
52424@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52425 return -ENOSPC;
52426
52427 err = 0;
52428- if ((count + p) > fbmemlength) {
52429+ if (count > (fbmemlength - p)) {
52430 count = fbmemlength - p;
52431 err = -ENOSPC;
52432 }
52433diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
52434index 52108be..c7c110d 100644
52435--- a/drivers/video/fbdev/aty/aty128fb.c
52436+++ b/drivers/video/fbdev/aty/aty128fb.c
52437@@ -149,7 +149,7 @@ enum {
52438 };
52439
52440 /* Must match above enum */
52441-static char * const r128_family[] = {
52442+static const char * const r128_family[] = {
52443 "AGP",
52444 "PCI",
52445 "PRO AGP",
52446diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
52447index c3d0074..0b9077e 100644
52448--- a/drivers/video/fbdev/aty/atyfb_base.c
52449+++ b/drivers/video/fbdev/aty/atyfb_base.c
52450@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52451 par->accel_flags = var->accel_flags; /* hack */
52452
52453 if (var->accel_flags) {
52454- info->fbops->fb_sync = atyfb_sync;
52455+ pax_open_kernel();
52456+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52457+ pax_close_kernel();
52458 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52459 } else {
52460- info->fbops->fb_sync = NULL;
52461+ pax_open_kernel();
52462+ *(void **)&info->fbops->fb_sync = NULL;
52463+ pax_close_kernel();
52464 info->flags |= FBINFO_HWACCEL_DISABLED;
52465 }
52466
52467diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
52468index 2fa0317..4983f2a 100644
52469--- a/drivers/video/fbdev/aty/mach64_cursor.c
52470+++ b/drivers/video/fbdev/aty/mach64_cursor.c
52471@@ -8,6 +8,7 @@
52472 #include "../core/fb_draw.h"
52473
52474 #include <asm/io.h>
52475+#include <asm/pgtable.h>
52476
52477 #ifdef __sparc__
52478 #include <asm/fbio.h>
52479@@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
52480 info->sprite.buf_align = 16; /* and 64 lines tall. */
52481 info->sprite.flags = FB_PIXMAP_IO;
52482
52483- info->fbops->fb_cursor = atyfb_cursor;
52484+ pax_open_kernel();
52485+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52486+ pax_close_kernel();
52487
52488 return 0;
52489 }
52490diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
52491index 900aa4e..6d49418 100644
52492--- a/drivers/video/fbdev/core/fb_defio.c
52493+++ b/drivers/video/fbdev/core/fb_defio.c
52494@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52495
52496 BUG_ON(!fbdefio);
52497 mutex_init(&fbdefio->lock);
52498- info->fbops->fb_mmap = fb_deferred_io_mmap;
52499+ pax_open_kernel();
52500+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52501+ pax_close_kernel();
52502 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52503 INIT_LIST_HEAD(&fbdefio->pagelist);
52504 if (fbdefio->delay == 0) /* set a default of 1 s */
52505@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52506 page->mapping = NULL;
52507 }
52508
52509- info->fbops->fb_mmap = NULL;
52510+ *(void **)&info->fbops->fb_mmap = NULL;
52511 mutex_destroy(&fbdefio->lock);
52512 }
52513 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52514diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
52515index b6d5008..5bca7bf 100644
52516--- a/drivers/video/fbdev/core/fbmem.c
52517+++ b/drivers/video/fbdev/core/fbmem.c
52518@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52519 image->dx += image->width + 8;
52520 }
52521 } else if (rotate == FB_ROTATE_UD) {
52522- for (x = 0; x < num && image->dx >= 0; x++) {
52523+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52524 info->fbops->fb_imageblit(info, image);
52525 image->dx -= image->width + 8;
52526 }
52527@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52528 image->dy += image->height + 8;
52529 }
52530 } else if (rotate == FB_ROTATE_CCW) {
52531- for (x = 0; x < num && image->dy >= 0; x++) {
52532+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52533 info->fbops->fb_imageblit(info, image);
52534 image->dy -= image->height + 8;
52535 }
52536@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52537 return -EFAULT;
52538 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52539 return -EINVAL;
52540- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52541+ if (con2fb.framebuffer >= FB_MAX)
52542 return -EINVAL;
52543 if (!registered_fb[con2fb.framebuffer])
52544 request_module("fb%d", con2fb.framebuffer);
52545@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52546 __u32 data;
52547 int err;
52548
52549- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52550+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52551
52552 data = (__u32) (unsigned long) fix->smem_start;
52553 err |= put_user(data, &fix32->smem_start);
52554diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
52555index e23392e..8a77540 100644
52556--- a/drivers/video/fbdev/hyperv_fb.c
52557+++ b/drivers/video/fbdev/hyperv_fb.c
52558@@ -235,7 +235,7 @@ static uint screen_fb_size;
52559 static inline int synthvid_send(struct hv_device *hdev,
52560 struct synthvid_msg *msg)
52561 {
52562- static atomic64_t request_id = ATOMIC64_INIT(0);
52563+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52564 int ret;
52565
52566 msg->pipe_hdr.type = PIPE_MSG_DATA;
52567@@ -243,7 +243,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52568
52569 ret = vmbus_sendpacket(hdev->channel, msg,
52570 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52571- atomic64_inc_return(&request_id),
52572+ atomic64_inc_return_unchecked(&request_id),
52573 VM_PKT_DATA_INBAND, 0);
52574
52575 if (ret)
52576diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
52577index 7672d2e..b56437f 100644
52578--- a/drivers/video/fbdev/i810/i810_accel.c
52579+++ b/drivers/video/fbdev/i810/i810_accel.c
52580@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52581 }
52582 }
52583 printk("ringbuffer lockup!!!\n");
52584+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52585 i810_report_error(mmio);
52586 par->dev_flags |= LOCKUP;
52587 info->pixmap.scan_align = 1;
52588diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52589index a01147f..5d896f8 100644
52590--- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52591+++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52592@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
52593
52594 #ifdef CONFIG_FB_MATROX_MYSTIQUE
52595 struct matrox_switch matrox_mystique = {
52596- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
52597+ .preinit = MGA1064_preinit,
52598+ .reset = MGA1064_reset,
52599+ .init = MGA1064_init,
52600+ .restore = MGA1064_restore,
52601 };
52602 EXPORT_SYMBOL(matrox_mystique);
52603 #endif
52604
52605 #ifdef CONFIG_FB_MATROX_G
52606 struct matrox_switch matrox_G100 = {
52607- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
52608+ .preinit = MGAG100_preinit,
52609+ .reset = MGAG100_reset,
52610+ .init = MGAG100_init,
52611+ .restore = MGAG100_restore,
52612 };
52613 EXPORT_SYMBOL(matrox_G100);
52614 #endif
52615diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52616index 195ad7c..09743fc 100644
52617--- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52618+++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52619@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
52620 }
52621
52622 struct matrox_switch matrox_millennium = {
52623- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
52624+ .preinit = Ti3026_preinit,
52625+ .reset = Ti3026_reset,
52626+ .init = Ti3026_init,
52627+ .restore = Ti3026_restore
52628 };
52629 EXPORT_SYMBOL(matrox_millennium);
52630 #endif
52631diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52632index fe92eed..106e085 100644
52633--- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52634+++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52635@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
52636 struct mb862xxfb_par *par = info->par;
52637
52638 if (info->var.bits_per_pixel == 32) {
52639- info->fbops->fb_fillrect = cfb_fillrect;
52640- info->fbops->fb_copyarea = cfb_copyarea;
52641- info->fbops->fb_imageblit = cfb_imageblit;
52642+ pax_open_kernel();
52643+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52644+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52645+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52646+ pax_close_kernel();
52647 } else {
52648 outreg(disp, GC_L0EM, 3);
52649- info->fbops->fb_fillrect = mb86290fb_fillrect;
52650- info->fbops->fb_copyarea = mb86290fb_copyarea;
52651- info->fbops->fb_imageblit = mb86290fb_imageblit;
52652+ pax_open_kernel();
52653+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
52654+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
52655+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
52656+ pax_close_kernel();
52657 }
52658 outreg(draw, GDC_REG_DRAW_BASE, 0);
52659 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
52660diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
52661index def0412..fed6529 100644
52662--- a/drivers/video/fbdev/nvidia/nvidia.c
52663+++ b/drivers/video/fbdev/nvidia/nvidia.c
52664@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
52665 info->fix.line_length = (info->var.xres_virtual *
52666 info->var.bits_per_pixel) >> 3;
52667 if (info->var.accel_flags) {
52668- info->fbops->fb_imageblit = nvidiafb_imageblit;
52669- info->fbops->fb_fillrect = nvidiafb_fillrect;
52670- info->fbops->fb_copyarea = nvidiafb_copyarea;
52671- info->fbops->fb_sync = nvidiafb_sync;
52672+ pax_open_kernel();
52673+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
52674+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
52675+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
52676+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
52677+ pax_close_kernel();
52678 info->pixmap.scan_align = 4;
52679 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52680 info->flags |= FBINFO_READS_FAST;
52681 NVResetGraphics(info);
52682 } else {
52683- info->fbops->fb_imageblit = cfb_imageblit;
52684- info->fbops->fb_fillrect = cfb_fillrect;
52685- info->fbops->fb_copyarea = cfb_copyarea;
52686- info->fbops->fb_sync = NULL;
52687+ pax_open_kernel();
52688+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52689+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52690+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52691+ *(void **)&info->fbops->fb_sync = NULL;
52692+ pax_close_kernel();
52693 info->pixmap.scan_align = 1;
52694 info->flags |= FBINFO_HWACCEL_DISABLED;
52695 info->flags &= ~FBINFO_READS_FAST;
52696@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
52697 info->pixmap.size = 8 * 1024;
52698 info->pixmap.flags = FB_PIXMAP_SYSTEM;
52699
52700- if (!hwcur)
52701- info->fbops->fb_cursor = NULL;
52702+ if (!hwcur) {
52703+ pax_open_kernel();
52704+ *(void **)&info->fbops->fb_cursor = NULL;
52705+ pax_close_kernel();
52706+ }
52707
52708 info->var.accel_flags = (!noaccel);
52709
52710diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
52711index 2412a0d..294215b 100644
52712--- a/drivers/video/fbdev/omap2/dss/display.c
52713+++ b/drivers/video/fbdev/omap2/dss/display.c
52714@@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
52715 if (dssdev->name == NULL)
52716 dssdev->name = dssdev->alias;
52717
52718+ pax_open_kernel();
52719 if (drv && drv->get_resolution == NULL)
52720- drv->get_resolution = omapdss_default_get_resolution;
52721+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
52722 if (drv && drv->get_recommended_bpp == NULL)
52723- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
52724+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
52725 if (drv && drv->get_timings == NULL)
52726- drv->get_timings = omapdss_default_get_timings;
52727+ *(void **)&drv->get_timings = omapdss_default_get_timings;
52728+ pax_close_kernel();
52729
52730 mutex_lock(&panel_list_mutex);
52731 list_add_tail(&dssdev->panel_list, &panel_list);
52732diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
52733index 83433cb..71e9b98 100644
52734--- a/drivers/video/fbdev/s1d13xxxfb.c
52735+++ b/drivers/video/fbdev/s1d13xxxfb.c
52736@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
52737
52738 switch(prod_id) {
52739 case S1D13506_PROD_ID: /* activate acceleration */
52740- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52741- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52742+ pax_open_kernel();
52743+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52744+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52745+ pax_close_kernel();
52746 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
52747 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
52748 break;
52749diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
52750index 2bcc84a..29dd1ea 100644
52751--- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
52752+++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
52753@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
52754 }
52755
52756 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
52757- lcdc_sys_write_index,
52758- lcdc_sys_write_data,
52759- lcdc_sys_read_data,
52760+ .write_index = lcdc_sys_write_index,
52761+ .write_data = lcdc_sys_write_data,
52762+ .read_data = lcdc_sys_read_data,
52763 };
52764
52765 static int sh_mobile_lcdc_sginit(struct fb_info *info,
52766diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
52767index d513ed6..90b0de9 100644
52768--- a/drivers/video/fbdev/smscufx.c
52769+++ b/drivers/video/fbdev/smscufx.c
52770@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
52771 fb_deferred_io_cleanup(info);
52772 kfree(info->fbdefio);
52773 info->fbdefio = NULL;
52774- info->fbops->fb_mmap = ufx_ops_mmap;
52775+ pax_open_kernel();
52776+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
52777+ pax_close_kernel();
52778 }
52779
52780 pr_debug("released /dev/fb%d user=%d count=%d",
52781diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
52782index 77b890e..458e666 100644
52783--- a/drivers/video/fbdev/udlfb.c
52784+++ b/drivers/video/fbdev/udlfb.c
52785@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
52786 dlfb_urb_completion(urb);
52787
52788 error:
52789- atomic_add(bytes_sent, &dev->bytes_sent);
52790- atomic_add(bytes_identical, &dev->bytes_identical);
52791- atomic_add(width*height*2, &dev->bytes_rendered);
52792+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52793+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52794+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
52795 end_cycles = get_cycles();
52796- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52797+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52798 >> 10)), /* Kcycles */
52799 &dev->cpu_kcycles_used);
52800
52801@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
52802 dlfb_urb_completion(urb);
52803
52804 error:
52805- atomic_add(bytes_sent, &dev->bytes_sent);
52806- atomic_add(bytes_identical, &dev->bytes_identical);
52807- atomic_add(bytes_rendered, &dev->bytes_rendered);
52808+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52809+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52810+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
52811 end_cycles = get_cycles();
52812- atomic_add(((unsigned int) ((end_cycles - start_cycles)
52813+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52814 >> 10)), /* Kcycles */
52815 &dev->cpu_kcycles_used);
52816 }
52817@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
52818 fb_deferred_io_cleanup(info);
52819 kfree(info->fbdefio);
52820 info->fbdefio = NULL;
52821- info->fbops->fb_mmap = dlfb_ops_mmap;
52822+ pax_open_kernel();
52823+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
52824+ pax_close_kernel();
52825 }
52826
52827 pr_warn("released /dev/fb%d user=%d count=%d\n",
52828@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
52829 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52830 struct dlfb_data *dev = fb_info->par;
52831 return snprintf(buf, PAGE_SIZE, "%u\n",
52832- atomic_read(&dev->bytes_rendered));
52833+ atomic_read_unchecked(&dev->bytes_rendered));
52834 }
52835
52836 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52837@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
52838 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52839 struct dlfb_data *dev = fb_info->par;
52840 return snprintf(buf, PAGE_SIZE, "%u\n",
52841- atomic_read(&dev->bytes_identical));
52842+ atomic_read_unchecked(&dev->bytes_identical));
52843 }
52844
52845 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52846@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
52847 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52848 struct dlfb_data *dev = fb_info->par;
52849 return snprintf(buf, PAGE_SIZE, "%u\n",
52850- atomic_read(&dev->bytes_sent));
52851+ atomic_read_unchecked(&dev->bytes_sent));
52852 }
52853
52854 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52855@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
52856 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52857 struct dlfb_data *dev = fb_info->par;
52858 return snprintf(buf, PAGE_SIZE, "%u\n",
52859- atomic_read(&dev->cpu_kcycles_used));
52860+ atomic_read_unchecked(&dev->cpu_kcycles_used));
52861 }
52862
52863 static ssize_t edid_show(
52864@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
52865 struct fb_info *fb_info = dev_get_drvdata(fbdev);
52866 struct dlfb_data *dev = fb_info->par;
52867
52868- atomic_set(&dev->bytes_rendered, 0);
52869- atomic_set(&dev->bytes_identical, 0);
52870- atomic_set(&dev->bytes_sent, 0);
52871- atomic_set(&dev->cpu_kcycles_used, 0);
52872+ atomic_set_unchecked(&dev->bytes_rendered, 0);
52873+ atomic_set_unchecked(&dev->bytes_identical, 0);
52874+ atomic_set_unchecked(&dev->bytes_sent, 0);
52875+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
52876
52877 return count;
52878 }
52879diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
52880index 509d452..7c9d2de 100644
52881--- a/drivers/video/fbdev/uvesafb.c
52882+++ b/drivers/video/fbdev/uvesafb.c
52883@@ -19,6 +19,7 @@
52884 #include <linux/io.h>
52885 #include <linux/mutex.h>
52886 #include <linux/slab.h>
52887+#include <linux/moduleloader.h>
52888 #include <video/edid.h>
52889 #include <video/uvesafb.h>
52890 #ifdef CONFIG_X86
52891@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
52892 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
52893 par->pmi_setpal = par->ypan = 0;
52894 } else {
52895+
52896+#ifdef CONFIG_PAX_KERNEXEC
52897+#ifdef CONFIG_MODULES
52898+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
52899+#endif
52900+ if (!par->pmi_code) {
52901+ par->pmi_setpal = par->ypan = 0;
52902+ return 0;
52903+ }
52904+#endif
52905+
52906 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
52907 + task->t.regs.edi);
52908+
52909+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52910+ pax_open_kernel();
52911+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
52912+ pax_close_kernel();
52913+
52914+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
52915+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
52916+#else
52917 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
52918 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
52919+#endif
52920+
52921 printk(KERN_INFO "uvesafb: protected mode interface info at "
52922 "%04x:%04x\n",
52923 (u16)task->t.regs.es, (u16)task->t.regs.edi);
52924@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
52925 par->ypan = ypan;
52926
52927 if (par->pmi_setpal || par->ypan) {
52928+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
52929 if (__supported_pte_mask & _PAGE_NX) {
52930 par->pmi_setpal = par->ypan = 0;
52931 printk(KERN_WARNING "uvesafb: NX protection is active, "
52932 "better not use the PMI.\n");
52933- } else {
52934+ } else
52935+#endif
52936 uvesafb_vbe_getpmi(task, par);
52937- }
52938 }
52939 #else
52940 /* The protected mode interface is not available on non-x86. */
52941@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52942 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
52943
52944 /* Disable blanking if the user requested so. */
52945- if (!blank)
52946- info->fbops->fb_blank = NULL;
52947+ if (!blank) {
52948+ pax_open_kernel();
52949+ *(void **)&info->fbops->fb_blank = NULL;
52950+ pax_close_kernel();
52951+ }
52952
52953 /*
52954 * Find out how much IO memory is required for the mode with
52955@@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52956 info->flags = FBINFO_FLAG_DEFAULT |
52957 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
52958
52959- if (!par->ypan)
52960- info->fbops->fb_pan_display = NULL;
52961+ if (!par->ypan) {
52962+ pax_open_kernel();
52963+ *(void **)&info->fbops->fb_pan_display = NULL;
52964+ pax_close_kernel();
52965+ }
52966 }
52967
52968 static void uvesafb_init_mtrr(struct fb_info *info)
52969@@ -1787,6 +1817,11 @@ out_mode:
52970 out:
52971 kfree(par->vbe_modes);
52972
52973+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52974+ if (par->pmi_code)
52975+ module_free_exec(NULL, par->pmi_code);
52976+#endif
52977+
52978 framebuffer_release(info);
52979 return err;
52980 }
52981@@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
52982 kfree(par->vbe_state_orig);
52983 kfree(par->vbe_state_saved);
52984
52985+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52986+ if (par->pmi_code)
52987+ module_free_exec(NULL, par->pmi_code);
52988+#endif
52989+
52990 framebuffer_release(info);
52991 }
52992 return 0;
52993diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
52994index 6170e7f..dd63031 100644
52995--- a/drivers/video/fbdev/vesafb.c
52996+++ b/drivers/video/fbdev/vesafb.c
52997@@ -9,6 +9,7 @@
52998 */
52999
53000 #include <linux/module.h>
53001+#include <linux/moduleloader.h>
53002 #include <linux/kernel.h>
53003 #include <linux/errno.h>
53004 #include <linux/string.h>
53005@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
53006 static int vram_total; /* Set total amount of memory */
53007 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
53008 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
53009-static void (*pmi_start)(void) __read_mostly;
53010-static void (*pmi_pal) (void) __read_mostly;
53011+static void (*pmi_start)(void) __read_only;
53012+static void (*pmi_pal) (void) __read_only;
53013 static int depth __read_mostly;
53014 static int vga_compat __read_mostly;
53015 /* --------------------------------------------------------------------- */
53016@@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
53017 unsigned int size_remap;
53018 unsigned int size_total;
53019 char *option = NULL;
53020+ void *pmi_code = NULL;
53021
53022 /* ignore error return of fb_get_options */
53023 fb_get_options("vesafb", &option);
53024@@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
53025 size_remap = size_total;
53026 vesafb_fix.smem_len = size_remap;
53027
53028-#ifndef __i386__
53029- screen_info.vesapm_seg = 0;
53030-#endif
53031-
53032 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
53033 printk(KERN_WARNING
53034 "vesafb: cannot reserve video memory at 0x%lx\n",
53035@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
53036 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
53037 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
53038
53039+#ifdef __i386__
53040+
53041+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53042+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
53043+ if (!pmi_code)
53044+#elif !defined(CONFIG_PAX_KERNEXEC)
53045+ if (0)
53046+#endif
53047+
53048+#endif
53049+ screen_info.vesapm_seg = 0;
53050+
53051 if (screen_info.vesapm_seg) {
53052- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
53053- screen_info.vesapm_seg,screen_info.vesapm_off);
53054+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
53055+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
53056 }
53057
53058 if (screen_info.vesapm_seg < 0xc000)
53059@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
53060
53061 if (ypan || pmi_setpal) {
53062 unsigned short *pmi_base;
53063+
53064 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
53065- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
53066- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
53067+
53068+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53069+ pax_open_kernel();
53070+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
53071+#else
53072+ pmi_code = pmi_base;
53073+#endif
53074+
53075+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
53076+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
53077+
53078+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53079+ pmi_start = ktva_ktla(pmi_start);
53080+ pmi_pal = ktva_ktla(pmi_pal);
53081+ pax_close_kernel();
53082+#endif
53083+
53084 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
53085 if (pmi_base[3]) {
53086 printk(KERN_INFO "vesafb: pmi: ports = ");
53087@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
53088 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
53089 (ypan ? FBINFO_HWACCEL_YPAN : 0);
53090
53091- if (!ypan)
53092- info->fbops->fb_pan_display = NULL;
53093+ if (!ypan) {
53094+ pax_open_kernel();
53095+ *(void **)&info->fbops->fb_pan_display = NULL;
53096+ pax_close_kernel();
53097+ }
53098
53099 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
53100 err = -ENOMEM;
53101@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
53102 fb_info(info, "%s frame buffer device\n", info->fix.id);
53103 return 0;
53104 err:
53105+
53106+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53107+ module_free_exec(NULL, pmi_code);
53108+#endif
53109+
53110 if (info->screen_base)
53111 iounmap(info->screen_base);
53112 framebuffer_release(info);
53113diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
53114index 88714ae..16c2e11 100644
53115--- a/drivers/video/fbdev/via/via_clock.h
53116+++ b/drivers/video/fbdev/via/via_clock.h
53117@@ -56,7 +56,7 @@ struct via_clock {
53118
53119 void (*set_engine_pll_state)(u8 state);
53120 void (*set_engine_pll)(struct via_pll_config config);
53121-};
53122+} __no_const;
53123
53124
53125 static inline u32 get_pll_internal_frequency(u32 ref_freq,
53126diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53127index 3c14e43..2630570 100644
53128--- a/drivers/video/logo/logo_linux_clut224.ppm
53129+++ b/drivers/video/logo/logo_linux_clut224.ppm
53130@@ -2,1603 +2,1123 @@ P3
53131 # Standard 224-color Linux logo
53132 80 80
53133 255
53134- 0 0 0 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 0 0 0
53141- 0 0 0 0 0 0 0 0 0 0 0 0
53142- 0 0 0 0 0 0 0 0 0 0 0 0
53143- 6 6 6 6 6 6 10 10 10 10 10 10
53144- 10 10 10 6 6 6 6 6 6 6 6 6
53145- 0 0 0 0 0 0 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 0 0 0 0 0 0 0 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 0 0 0 0 0 0
53161- 0 0 0 0 0 0 0 0 0 0 0 0
53162- 0 0 0 6 6 6 10 10 10 14 14 14
53163- 22 22 22 26 26 26 30 30 30 34 34 34
53164- 30 30 30 30 30 30 26 26 26 18 18 18
53165- 14 14 14 10 10 10 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 1 0 0 1 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 0 0 0 0 0 0 0 0 0
53181- 0 0 0 0 0 0 0 0 0 0 0 0
53182- 6 6 6 14 14 14 26 26 26 42 42 42
53183- 54 54 54 66 66 66 78 78 78 78 78 78
53184- 78 78 78 74 74 74 66 66 66 54 54 54
53185- 42 42 42 26 26 26 18 18 18 10 10 10
53186- 6 6 6 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 0 0 0 0 0 0 0 0 0 0
53195- 0 0 1 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- 0 0 0 0 0 0 0 0 0 0 0 0
53201- 0 0 0 0 0 0 0 0 0 10 10 10
53202- 22 22 22 42 42 42 66 66 66 86 86 86
53203- 66 66 66 38 38 38 38 38 38 22 22 22
53204- 26 26 26 34 34 34 54 54 54 66 66 66
53205- 86 86 86 70 70 70 46 46 46 26 26 26
53206- 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0 0
53215- 0 0 1 0 0 1 0 0 1 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- 0 0 0 0 0 0 0 0 0 0 0 0
53221- 0 0 0 0 0 0 10 10 10 26 26 26
53222- 50 50 50 82 82 82 58 58 58 6 6 6
53223- 2 2 6 2 2 6 2 2 6 2 2 6
53224- 2 2 6 2 2 6 2 2 6 2 2 6
53225- 6 6 6 54 54 54 86 86 86 66 66 66
53226- 38 38 38 18 18 18 6 6 6 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 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
53241- 0 0 0 6 6 6 22 22 22 50 50 50
53242- 78 78 78 34 34 34 2 2 6 2 2 6
53243- 2 2 6 2 2 6 2 2 6 2 2 6
53244- 2 2 6 2 2 6 2 2 6 2 2 6
53245- 2 2 6 2 2 6 6 6 6 70 70 70
53246- 78 78 78 46 46 46 22 22 22 6 6 6
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 1 0 0 1 0 0 1 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 0 0 0
53260- 0 0 0 0 0 0 0 0 0 0 0 0
53261- 6 6 6 18 18 18 42 42 42 82 82 82
53262- 26 26 26 2 2 6 2 2 6 2 2 6
53263- 2 2 6 2 2 6 2 2 6 2 2 6
53264- 2 2 6 2 2 6 2 2 6 14 14 14
53265- 46 46 46 34 34 34 6 6 6 2 2 6
53266- 42 42 42 78 78 78 42 42 42 18 18 18
53267- 6 6 6 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 0 0 0 0 0 0 0
53275- 0 0 1 0 0 0 0 0 1 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 0 0 0
53280- 0 0 0 0 0 0 0 0 0 0 0 0
53281- 10 10 10 30 30 30 66 66 66 58 58 58
53282- 2 2 6 2 2 6 2 2 6 2 2 6
53283- 2 2 6 2 2 6 2 2 6 2 2 6
53284- 2 2 6 2 2 6 2 2 6 26 26 26
53285- 86 86 86 101 101 101 46 46 46 10 10 10
53286- 2 2 6 58 58 58 70 70 70 34 34 34
53287- 10 10 10 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 0 0 0 0 0 0 0 0 0 0
53295- 0 0 1 0 0 1 0 0 1 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 0 0 0
53300- 0 0 0 0 0 0 0 0 0 0 0 0
53301- 14 14 14 42 42 42 86 86 86 10 10 10
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 30 30 30
53305- 94 94 94 94 94 94 58 58 58 26 26 26
53306- 2 2 6 6 6 6 78 78 78 54 54 54
53307- 22 22 22 6 6 6 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 0 0 0 0 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 0 0 0
53320- 0 0 0 0 0 0 0 0 0 6 6 6
53321- 22 22 22 62 62 62 62 62 62 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 2 2 6
53324- 2 2 6 2 2 6 2 2 6 26 26 26
53325- 54 54 54 38 38 38 18 18 18 10 10 10
53326- 2 2 6 2 2 6 34 34 34 82 82 82
53327- 38 38 38 14 14 14 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 0 0 0 0 0 0 0 0 0 0
53335- 0 0 0 0 0 1 0 0 1 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 0 0 0
53340- 0 0 0 0 0 0 0 0 0 6 6 6
53341- 30 30 30 78 78 78 30 30 30 2 2 6
53342- 2 2 6 2 2 6 2 2 6 2 2 6
53343- 2 2 6 2 2 6 2 2 6 2 2 6
53344- 2 2 6 2 2 6 2 2 6 10 10 10
53345- 10 10 10 2 2 6 2 2 6 2 2 6
53346- 2 2 6 2 2 6 2 2 6 78 78 78
53347- 50 50 50 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0 0
53355- 0 0 1 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 0 0 0
53360- 0 0 0 0 0 0 0 0 0 10 10 10
53361- 38 38 38 86 86 86 14 14 14 2 2 6
53362- 2 2 6 2 2 6 2 2 6 2 2 6
53363- 2 2 6 2 2 6 2 2 6 2 2 6
53364- 2 2 6 2 2 6 2 2 6 2 2 6
53365- 2 2 6 2 2 6 2 2 6 2 2 6
53366- 2 2 6 2 2 6 2 2 6 54 54 54
53367- 66 66 66 26 26 26 6 6 6 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 1 0 0 1 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 0 0 0
53380- 0 0 0 0 0 0 0 0 0 14 14 14
53381- 42 42 42 82 82 82 2 2 6 2 2 6
53382- 2 2 6 6 6 6 10 10 10 2 2 6
53383- 2 2 6 2 2 6 2 2 6 2 2 6
53384- 2 2 6 2 2 6 2 2 6 6 6 6
53385- 14 14 14 10 10 10 2 2 6 2 2 6
53386- 2 2 6 2 2 6 2 2 6 18 18 18
53387- 82 82 82 34 34 34 10 10 10 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 0 0 0 0
53394- 0 0 0 0 0 0 0 0 0 0 0 0
53395- 0 0 1 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 0 0 0
53400- 0 0 0 0 0 0 0 0 0 14 14 14
53401- 46 46 46 86 86 86 2 2 6 2 2 6
53402- 6 6 6 6 6 6 22 22 22 34 34 34
53403- 6 6 6 2 2 6 2 2 6 2 2 6
53404- 2 2 6 2 2 6 18 18 18 34 34 34
53405- 10 10 10 50 50 50 22 22 22 2 2 6
53406- 2 2 6 2 2 6 2 2 6 10 10 10
53407- 86 86 86 42 42 42 14 14 14 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 1 0 0 1 0 0 1 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 0 0 0
53420- 0 0 0 0 0 0 0 0 0 14 14 14
53421- 46 46 46 86 86 86 2 2 6 2 2 6
53422- 38 38 38 116 116 116 94 94 94 22 22 22
53423- 22 22 22 2 2 6 2 2 6 2 2 6
53424- 14 14 14 86 86 86 138 138 138 162 162 162
53425-154 154 154 38 38 38 26 26 26 6 6 6
53426- 2 2 6 2 2 6 2 2 6 2 2 6
53427- 86 86 86 46 46 46 14 14 14 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 0 0 0 0
53434- 0 0 0 0 0 0 0 0 0 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 0 0 0
53440- 0 0 0 0 0 0 0 0 0 14 14 14
53441- 46 46 46 86 86 86 2 2 6 14 14 14
53442-134 134 134 198 198 198 195 195 195 116 116 116
53443- 10 10 10 2 2 6 2 2 6 6 6 6
53444-101 98 89 187 187 187 210 210 210 218 218 218
53445-214 214 214 134 134 134 14 14 14 6 6 6
53446- 2 2 6 2 2 6 2 2 6 2 2 6
53447- 86 86 86 50 50 50 18 18 18 6 6 6
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 0 0 0 0
53454- 0 0 0 0 0 0 0 0 1 0 0 0
53455- 0 0 1 0 0 1 0 0 1 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 0 0 0
53460- 0 0 0 0 0 0 0 0 0 14 14 14
53461- 46 46 46 86 86 86 2 2 6 54 54 54
53462-218 218 218 195 195 195 226 226 226 246 246 246
53463- 58 58 58 2 2 6 2 2 6 30 30 30
53464-210 210 210 253 253 253 174 174 174 123 123 123
53465-221 221 221 234 234 234 74 74 74 2 2 6
53466- 2 2 6 2 2 6 2 2 6 2 2 6
53467- 70 70 70 58 58 58 22 22 22 6 6 6
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 0 0 0 0
53474- 0 0 0 0 0 0 0 0 0 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 0 0 0
53480- 0 0 0 0 0 0 0 0 0 14 14 14
53481- 46 46 46 82 82 82 2 2 6 106 106 106
53482-170 170 170 26 26 26 86 86 86 226 226 226
53483-123 123 123 10 10 10 14 14 14 46 46 46
53484-231 231 231 190 190 190 6 6 6 70 70 70
53485- 90 90 90 238 238 238 158 158 158 2 2 6
53486- 2 2 6 2 2 6 2 2 6 2 2 6
53487- 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
53495- 0 0 1 0 0 1 0 0 1 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 0 0 0
53500- 0 0 0 0 0 0 0 0 0 14 14 14
53501- 42 42 42 86 86 86 6 6 6 116 116 116
53502-106 106 106 6 6 6 70 70 70 149 149 149
53503-128 128 128 18 18 18 38 38 38 54 54 54
53504-221 221 221 106 106 106 2 2 6 14 14 14
53505- 46 46 46 190 190 190 198 198 198 2 2 6
53506- 2 2 6 2 2 6 2 2 6 2 2 6
53507- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 0
53515- 0 0 1 0 0 0 0 0 1 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 0 0 0
53520- 0 0 0 0 0 0 0 0 0 14 14 14
53521- 42 42 42 94 94 94 14 14 14 101 101 101
53522-128 128 128 2 2 6 18 18 18 116 116 116
53523-118 98 46 121 92 8 121 92 8 98 78 10
53524-162 162 162 106 106 106 2 2 6 2 2 6
53525- 2 2 6 195 195 195 195 195 195 6 6 6
53526- 2 2 6 2 2 6 2 2 6 2 2 6
53527- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
53535- 0 0 1 0 0 0 0 0 1 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 0 0 0
53540- 0 0 0 0 0 0 0 0 0 10 10 10
53541- 38 38 38 90 90 90 14 14 14 58 58 58
53542-210 210 210 26 26 26 54 38 6 154 114 10
53543-226 170 11 236 186 11 225 175 15 184 144 12
53544-215 174 15 175 146 61 37 26 9 2 2 6
53545- 70 70 70 246 246 246 138 138 138 2 2 6
53546- 2 2 6 2 2 6 2 2 6 2 2 6
53547- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
53560- 0 0 0 0 0 0 0 0 0 10 10 10
53561- 38 38 38 86 86 86 14 14 14 10 10 10
53562-195 195 195 188 164 115 192 133 9 225 175 15
53563-239 182 13 234 190 10 232 195 16 232 200 30
53564-245 207 45 241 208 19 232 195 16 184 144 12
53565-218 194 134 211 206 186 42 42 42 2 2 6
53566- 2 2 6 2 2 6 2 2 6 2 2 6
53567- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
53580- 0 0 0 0 0 0 0 0 0 10 10 10
53581- 34 34 34 86 86 86 14 14 14 2 2 6
53582-121 87 25 192 133 9 219 162 10 239 182 13
53583-236 186 11 232 195 16 241 208 19 244 214 54
53584-246 218 60 246 218 38 246 215 20 241 208 19
53585-241 208 19 226 184 13 121 87 25 2 2 6
53586- 2 2 6 2 2 6 2 2 6 2 2 6
53587- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
53600- 0 0 0 0 0 0 0 0 0 10 10 10
53601- 34 34 34 82 82 82 30 30 30 61 42 6
53602-180 123 7 206 145 10 230 174 11 239 182 13
53603-234 190 10 238 202 15 241 208 19 246 218 74
53604-246 218 38 246 215 20 246 215 20 246 215 20
53605-226 184 13 215 174 15 184 144 12 6 6 6
53606- 2 2 6 2 2 6 2 2 6 2 2 6
53607- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0
53620- 0 0 0 0 0 0 0 0 0 10 10 10
53621- 30 30 30 78 78 78 50 50 50 104 69 6
53622-192 133 9 216 158 10 236 178 12 236 186 11
53623-232 195 16 241 208 19 244 214 54 245 215 43
53624-246 215 20 246 215 20 241 208 19 198 155 10
53625-200 144 11 216 158 10 156 118 10 2 2 6
53626- 2 2 6 2 2 6 2 2 6 2 2 6
53627- 6 6 6 90 90 90 54 54 54 18 18 18
53628- 6 6 6 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 0 0 0 0 0 0
53640- 0 0 0 0 0 0 0 0 0 10 10 10
53641- 30 30 30 78 78 78 46 46 46 22 22 22
53642-137 92 6 210 162 10 239 182 13 238 190 10
53643-238 202 15 241 208 19 246 215 20 246 215 20
53644-241 208 19 203 166 17 185 133 11 210 150 10
53645-216 158 10 210 150 10 102 78 10 2 2 6
53646- 6 6 6 54 54 54 14 14 14 2 2 6
53647- 2 2 6 62 62 62 74 74 74 30 30 30
53648- 10 10 10 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 0 0 0 0 0 0
53660- 0 0 0 0 0 0 0 0 0 10 10 10
53661- 34 34 34 78 78 78 50 50 50 6 6 6
53662- 94 70 30 139 102 15 190 146 13 226 184 13
53663-232 200 30 232 195 16 215 174 15 190 146 13
53664-168 122 10 192 133 9 210 150 10 213 154 11
53665-202 150 34 182 157 106 101 98 89 2 2 6
53666- 2 2 6 78 78 78 116 116 116 58 58 58
53667- 2 2 6 22 22 22 90 90 90 46 46 46
53668- 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
53680- 0 0 0 0 0 0 0 0 0 10 10 10
53681- 38 38 38 86 86 86 50 50 50 6 6 6
53682-128 128 128 174 154 114 156 107 11 168 122 10
53683-198 155 10 184 144 12 197 138 11 200 144 11
53684-206 145 10 206 145 10 197 138 11 188 164 115
53685-195 195 195 198 198 198 174 174 174 14 14 14
53686- 2 2 6 22 22 22 116 116 116 116 116 116
53687- 22 22 22 2 2 6 74 74 74 70 70 70
53688- 30 30 30 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
53700- 0 0 0 0 0 0 6 6 6 18 18 18
53701- 50 50 50 101 101 101 26 26 26 10 10 10
53702-138 138 138 190 190 190 174 154 114 156 107 11
53703-197 138 11 200 144 11 197 138 11 192 133 9
53704-180 123 7 190 142 34 190 178 144 187 187 187
53705-202 202 202 221 221 221 214 214 214 66 66 66
53706- 2 2 6 2 2 6 50 50 50 62 62 62
53707- 6 6 6 2 2 6 10 10 10 90 90 90
53708- 50 50 50 18 18 18 6 6 6 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 0 0 0
53719- 0 0 0 0 0 0 0 0 0 0 0 0
53720- 0 0 0 0 0 0 10 10 10 34 34 34
53721- 74 74 74 74 74 74 2 2 6 6 6 6
53722-144 144 144 198 198 198 190 190 190 178 166 146
53723-154 121 60 156 107 11 156 107 11 168 124 44
53724-174 154 114 187 187 187 190 190 190 210 210 210
53725-246 246 246 253 253 253 253 253 253 182 182 182
53726- 6 6 6 2 2 6 2 2 6 2 2 6
53727- 2 2 6 2 2 6 2 2 6 62 62 62
53728- 74 74 74 34 34 34 14 14 14 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 0 0 0
53739- 0 0 0 0 0 0 0 0 0 0 0 0
53740- 0 0 0 10 10 10 22 22 22 54 54 54
53741- 94 94 94 18 18 18 2 2 6 46 46 46
53742-234 234 234 221 221 221 190 190 190 190 190 190
53743-190 190 190 187 187 187 187 187 187 190 190 190
53744-190 190 190 195 195 195 214 214 214 242 242 242
53745-253 253 253 253 253 253 253 253 253 253 253 253
53746- 82 82 82 2 2 6 2 2 6 2 2 6
53747- 2 2 6 2 2 6 2 2 6 14 14 14
53748- 86 86 86 54 54 54 22 22 22 6 6 6
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 0 0 0 0 0 0
53759- 0 0 0 0 0 0 0 0 0 0 0 0
53760- 6 6 6 18 18 18 46 46 46 90 90 90
53761- 46 46 46 18 18 18 6 6 6 182 182 182
53762-253 253 253 246 246 246 206 206 206 190 190 190
53763-190 190 190 190 190 190 190 190 190 190 190 190
53764-206 206 206 231 231 231 250 250 250 253 253 253
53765-253 253 253 253 253 253 253 253 253 253 253 253
53766-202 202 202 14 14 14 2 2 6 2 2 6
53767- 2 2 6 2 2 6 2 2 6 2 2 6
53768- 42 42 42 86 86 86 42 42 42 18 18 18
53769- 6 6 6 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 0 0 0 0 0 0 0 0 0
53779- 0 0 0 0 0 0 0 0 0 6 6 6
53780- 14 14 14 38 38 38 74 74 74 66 66 66
53781- 2 2 6 6 6 6 90 90 90 250 250 250
53782-253 253 253 253 253 253 238 238 238 198 198 198
53783-190 190 190 190 190 190 195 195 195 221 221 221
53784-246 246 246 253 253 253 253 253 253 253 253 253
53785-253 253 253 253 253 253 253 253 253 253 253 253
53786-253 253 253 82 82 82 2 2 6 2 2 6
53787- 2 2 6 2 2 6 2 2 6 2 2 6
53788- 2 2 6 78 78 78 70 70 70 34 34 34
53789- 14 14 14 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
53799- 0 0 0 0 0 0 0 0 0 14 14 14
53800- 34 34 34 66 66 66 78 78 78 6 6 6
53801- 2 2 6 18 18 18 218 218 218 253 253 253
53802-253 253 253 253 253 253 253 253 253 246 246 246
53803-226 226 226 231 231 231 246 246 246 253 253 253
53804-253 253 253 253 253 253 253 253 253 253 253 253
53805-253 253 253 253 253 253 253 253 253 253 253 253
53806-253 253 253 178 178 178 2 2 6 2 2 6
53807- 2 2 6 2 2 6 2 2 6 2 2 6
53808- 2 2 6 18 18 18 90 90 90 62 62 62
53809- 30 30 30 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
53819- 0 0 0 0 0 0 10 10 10 26 26 26
53820- 58 58 58 90 90 90 18 18 18 2 2 6
53821- 2 2 6 110 110 110 253 253 253 253 253 253
53822-253 253 253 253 253 253 253 253 253 253 253 253
53823-250 250 250 253 253 253 253 253 253 253 253 253
53824-253 253 253 253 253 253 253 253 253 253 253 253
53825-253 253 253 253 253 253 253 253 253 253 253 253
53826-253 253 253 231 231 231 18 18 18 2 2 6
53827- 2 2 6 2 2 6 2 2 6 2 2 6
53828- 2 2 6 2 2 6 18 18 18 94 94 94
53829- 54 54 54 26 26 26 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
53839- 0 0 0 6 6 6 22 22 22 50 50 50
53840- 90 90 90 26 26 26 2 2 6 2 2 6
53841- 14 14 14 195 195 195 250 250 250 253 253 253
53842-253 253 253 253 253 253 253 253 253 253 253 253
53843-253 253 253 253 253 253 253 253 253 253 253 253
53844-253 253 253 253 253 253 253 253 253 253 253 253
53845-253 253 253 253 253 253 253 253 253 253 253 253
53846-250 250 250 242 242 242 54 54 54 2 2 6
53847- 2 2 6 2 2 6 2 2 6 2 2 6
53848- 2 2 6 2 2 6 2 2 6 38 38 38
53849- 86 86 86 50 50 50 22 22 22 6 6 6
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 0 0 0
53858- 0 0 0 0 0 0 0 0 0 0 0 0
53859- 6 6 6 14 14 14 38 38 38 82 82 82
53860- 34 34 34 2 2 6 2 2 6 2 2 6
53861- 42 42 42 195 195 195 246 246 246 253 253 253
53862-253 253 253 253 253 253 253 253 253 250 250 250
53863-242 242 242 242 242 242 250 250 250 253 253 253
53864-253 253 253 253 253 253 253 253 253 253 253 253
53865-253 253 253 250 250 250 246 246 246 238 238 238
53866-226 226 226 231 231 231 101 101 101 6 6 6
53867- 2 2 6 2 2 6 2 2 6 2 2 6
53868- 2 2 6 2 2 6 2 2 6 2 2 6
53869- 38 38 38 82 82 82 42 42 42 14 14 14
53870- 6 6 6 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 0 0 0
53878- 0 0 0 0 0 0 0 0 0 0 0 0
53879- 10 10 10 26 26 26 62 62 62 66 66 66
53880- 2 2 6 2 2 6 2 2 6 6 6 6
53881- 70 70 70 170 170 170 206 206 206 234 234 234
53882-246 246 246 250 250 250 250 250 250 238 238 238
53883-226 226 226 231 231 231 238 238 238 250 250 250
53884-250 250 250 250 250 250 246 246 246 231 231 231
53885-214 214 214 206 206 206 202 202 202 202 202 202
53886-198 198 198 202 202 202 182 182 182 18 18 18
53887- 2 2 6 2 2 6 2 2 6 2 2 6
53888- 2 2 6 2 2 6 2 2 6 2 2 6
53889- 2 2 6 62 62 62 66 66 66 30 30 30
53890- 10 10 10 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 0 0 0
53898- 0 0 0 0 0 0 0 0 0 0 0 0
53899- 14 14 14 42 42 42 82 82 82 18 18 18
53900- 2 2 6 2 2 6 2 2 6 10 10 10
53901- 94 94 94 182 182 182 218 218 218 242 242 242
53902-250 250 250 253 253 253 253 253 253 250 250 250
53903-234 234 234 253 253 253 253 253 253 253 253 253
53904-253 253 253 253 253 253 253 253 253 246 246 246
53905-238 238 238 226 226 226 210 210 210 202 202 202
53906-195 195 195 195 195 195 210 210 210 158 158 158
53907- 6 6 6 14 14 14 50 50 50 14 14 14
53908- 2 2 6 2 2 6 2 2 6 2 2 6
53909- 2 2 6 6 6 6 86 86 86 46 46 46
53910- 18 18 18 6 6 6 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 0 0 0 0 0 0
53918- 0 0 0 0 0 0 0 0 0 6 6 6
53919- 22 22 22 54 54 54 70 70 70 2 2 6
53920- 2 2 6 10 10 10 2 2 6 22 22 22
53921-166 166 166 231 231 231 250 250 250 253 253 253
53922-253 253 253 253 253 253 253 253 253 250 250 250
53923-242 242 242 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 246 246 246
53926-231 231 231 206 206 206 198 198 198 226 226 226
53927- 94 94 94 2 2 6 6 6 6 38 38 38
53928- 30 30 30 2 2 6 2 2 6 2 2 6
53929- 2 2 6 2 2 6 62 62 62 66 66 66
53930- 26 26 26 10 10 10 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 0 0 0 0 0 0
53938- 0 0 0 0 0 0 0 0 0 10 10 10
53939- 30 30 30 74 74 74 50 50 50 2 2 6
53940- 26 26 26 26 26 26 2 2 6 106 106 106
53941-238 238 238 253 253 253 253 253 253 253 253 253
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 218 218 218 202 202 202
53947-210 210 210 14 14 14 2 2 6 2 2 6
53948- 30 30 30 22 22 22 2 2 6 2 2 6
53949- 2 2 6 2 2 6 18 18 18 86 86 86
53950- 42 42 42 14 14 14 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 0 0 0 0 0 0 0 0 0
53958- 0 0 0 0 0 0 0 0 0 14 14 14
53959- 42 42 42 90 90 90 22 22 22 2 2 6
53960- 42 42 42 2 2 6 18 18 18 218 218 218
53961-253 253 253 253 253 253 253 253 253 253 253 253
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 250 250 250 221 221 221
53967-218 218 218 101 101 101 2 2 6 14 14 14
53968- 18 18 18 38 38 38 10 10 10 2 2 6
53969- 2 2 6 2 2 6 2 2 6 78 78 78
53970- 58 58 58 22 22 22 6 6 6 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 0 0 0 0 0 0 0 0 0
53978- 0 0 0 0 0 0 6 6 6 18 18 18
53979- 54 54 54 82 82 82 2 2 6 26 26 26
53980- 22 22 22 2 2 6 123 123 123 253 253 253
53981-253 253 253 253 253 253 253 253 253 253 253 253
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 253 253 253 250 250 250
53987-238 238 238 198 198 198 6 6 6 38 38 38
53988- 58 58 58 26 26 26 38 38 38 2 2 6
53989- 2 2 6 2 2 6 2 2 6 46 46 46
53990- 78 78 78 30 30 30 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
53998- 0 0 0 0 0 0 10 10 10 30 30 30
53999- 74 74 74 58 58 58 2 2 6 42 42 42
54000- 2 2 6 22 22 22 231 231 231 253 253 253
54001-253 253 253 253 253 253 253 253 253 253 253 253
54002-253 253 253 253 253 253 253 253 253 250 250 250
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 253 253 253 253 253 253
54007-253 253 253 246 246 246 46 46 46 38 38 38
54008- 42 42 42 14 14 14 38 38 38 14 14 14
54009- 2 2 6 2 2 6 2 2 6 6 6 6
54010- 86 86 86 46 46 46 14 14 14 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- 0 0 0 0 0 0 0 0 0 0 0 0
54018- 0 0 0 6 6 6 14 14 14 42 42 42
54019- 90 90 90 18 18 18 18 18 18 26 26 26
54020- 2 2 6 116 116 116 253 253 253 253 253 253
54021-253 253 253 253 253 253 253 253 253 253 253 253
54022-253 253 253 253 253 253 250 250 250 238 238 238
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 253 253 253 253 253 253
54027-253 253 253 253 253 253 94 94 94 6 6 6
54028- 2 2 6 2 2 6 10 10 10 34 34 34
54029- 2 2 6 2 2 6 2 2 6 2 2 6
54030- 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0
54037- 0 0 0 0 0 0 0 0 0 0 0 0
54038- 0 0 0 10 10 10 26 26 26 66 66 66
54039- 82 82 82 2 2 6 38 38 38 6 6 6
54040- 14 14 14 210 210 210 253 253 253 253 253 253
54041-253 253 253 253 253 253 253 253 253 253 253 253
54042-253 253 253 253 253 253 246 246 246 242 242 242
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 253 253 253 253 253 253
54047-253 253 253 253 253 253 144 144 144 2 2 6
54048- 2 2 6 2 2 6 2 2 6 46 46 46
54049- 2 2 6 2 2 6 2 2 6 2 2 6
54050- 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0
54057- 0 0 0 0 0 0 0 0 0 0 0 0
54058- 6 6 6 14 14 14 42 42 42 90 90 90
54059- 26 26 26 6 6 6 42 42 42 2 2 6
54060- 74 74 74 250 250 250 253 253 253 253 253 253
54061-253 253 253 253 253 253 253 253 253 253 253 253
54062-253 253 253 253 253 253 242 242 242 242 242 242
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 253 253 253 253 253 253
54067-253 253 253 253 253 253 182 182 182 2 2 6
54068- 2 2 6 2 2 6 2 2 6 46 46 46
54069- 2 2 6 2 2 6 2 2 6 2 2 6
54070- 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0
54077- 0 0 0 0 0 0 0 0 0 0 0 0
54078- 10 10 10 26 26 26 66 66 66 82 82 82
54079- 2 2 6 22 22 22 18 18 18 2 2 6
54080-149 149 149 253 253 253 253 253 253 253 253 253
54081-253 253 253 253 253 253 253 253 253 253 253 253
54082-253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 253 253 253
54087-253 253 253 253 253 253 206 206 206 2 2 6
54088- 2 2 6 2 2 6 2 2 6 38 38 38
54089- 2 2 6 2 2 6 2 2 6 2 2 6
54090- 6 6 6 86 86 86 46 46 46 14 14 14
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 0 0 0 0 0 0
54097- 0 0 0 0 0 0 0 0 0 6 6 6
54098- 18 18 18 46 46 46 86 86 86 18 18 18
54099- 2 2 6 34 34 34 10 10 10 6 6 6
54100-210 210 210 253 253 253 253 253 253 253 253 253
54101-253 253 253 253 253 253 253 253 253 253 253 253
54102-253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 253 253 253
54107-253 253 253 253 253 253 221 221 221 6 6 6
54108- 2 2 6 2 2 6 6 6 6 30 30 30
54109- 2 2 6 2 2 6 2 2 6 2 2 6
54110- 2 2 6 82 82 82 54 54 54 18 18 18
54111- 6 6 6 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 0 0 0 0 0 0
54117- 0 0 0 0 0 0 0 0 0 10 10 10
54118- 26 26 26 66 66 66 62 62 62 2 2 6
54119- 2 2 6 38 38 38 10 10 10 26 26 26
54120-238 238 238 253 253 253 253 253 253 253 253 253
54121-253 253 253 253 253 253 253 253 253 253 253 253
54122-253 253 253 253 253 253 231 231 231 238 238 238
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 253 253 253 253 253 253
54127-253 253 253 253 253 253 231 231 231 6 6 6
54128- 2 2 6 2 2 6 10 10 10 30 30 30
54129- 2 2 6 2 2 6 2 2 6 2 2 6
54130- 2 2 6 66 66 66 58 58 58 22 22 22
54131- 6 6 6 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 0 0 0 0 0 0
54137- 0 0 0 0 0 0 0 0 0 10 10 10
54138- 38 38 38 78 78 78 6 6 6 2 2 6
54139- 2 2 6 46 46 46 14 14 14 42 42 42
54140-246 246 246 253 253 253 253 253 253 253 253 253
54141-253 253 253 253 253 253 253 253 253 253 253 253
54142-253 253 253 253 253 253 231 231 231 242 242 242
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 253 253 253 253 253 253
54147-253 253 253 253 253 253 234 234 234 10 10 10
54148- 2 2 6 2 2 6 22 22 22 14 14 14
54149- 2 2 6 2 2 6 2 2 6 2 2 6
54150- 2 2 6 66 66 66 62 62 62 22 22 22
54151- 6 6 6 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 0 0 0 0 0 0
54157- 0 0 0 0 0 0 6 6 6 18 18 18
54158- 50 50 50 74 74 74 2 2 6 2 2 6
54159- 14 14 14 70 70 70 34 34 34 62 62 62
54160-250 250 250 253 253 253 253 253 253 253 253 253
54161-253 253 253 253 253 253 253 253 253 253 253 253
54162-253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253 253 253 253
54167-253 253 253 253 253 253 234 234 234 14 14 14
54168- 2 2 6 2 2 6 30 30 30 2 2 6
54169- 2 2 6 2 2 6 2 2 6 2 2 6
54170- 2 2 6 66 66 66 62 62 62 22 22 22
54171- 6 6 6 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 0 0 0
54176- 0 0 0 0 0 0 0 0 0 0 0 0
54177- 0 0 0 0 0 0 6 6 6 18 18 18
54178- 54 54 54 62 62 62 2 2 6 2 2 6
54179- 2 2 6 30 30 30 46 46 46 70 70 70
54180-250 250 250 253 253 253 253 253 253 253 253 253
54181-253 253 253 253 253 253 253 253 253 253 253 253
54182-253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253
54186-253 253 253 253 253 253 253 253 253 253 253 253
54187-253 253 253 253 253 253 226 226 226 10 10 10
54188- 2 2 6 6 6 6 30 30 30 2 2 6
54189- 2 2 6 2 2 6 2 2 6 2 2 6
54190- 2 2 6 66 66 66 58 58 58 22 22 22
54191- 6 6 6 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 0 0 0 0 0 0 0 0 0
54196- 0 0 0 0 0 0 0 0 0 0 0 0
54197- 0 0 0 0 0 0 6 6 6 22 22 22
54198- 58 58 58 62 62 62 2 2 6 2 2 6
54199- 2 2 6 2 2 6 30 30 30 78 78 78
54200-250 250 250 253 253 253 253 253 253 253 253 253
54201-253 253 253 253 253 253 253 253 253 253 253 253
54202-253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253
54206-253 253 253 253 253 253 253 253 253 253 253 253
54207-253 253 253 253 253 253 206 206 206 2 2 6
54208- 22 22 22 34 34 34 18 14 6 22 22 22
54209- 26 26 26 18 18 18 6 6 6 2 2 6
54210- 2 2 6 82 82 82 54 54 54 18 18 18
54211- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
54216- 0 0 0 0 0 0 0 0 0 0 0 0
54217- 0 0 0 0 0 0 6 6 6 26 26 26
54218- 62 62 62 106 106 106 74 54 14 185 133 11
54219-210 162 10 121 92 8 6 6 6 62 62 62
54220-238 238 238 253 253 253 253 253 253 253 253 253
54221-253 253 253 253 253 253 253 253 253 253 253 253
54222-253 253 253 253 253 253 231 231 231 246 246 246
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 253 253 253
54226-253 253 253 253 253 253 253 253 253 253 253 253
54227-253 253 253 253 253 253 158 158 158 18 18 18
54228- 14 14 14 2 2 6 2 2 6 2 2 6
54229- 6 6 6 18 18 18 66 66 66 38 38 38
54230- 6 6 6 94 94 94 50 50 50 18 18 18
54231- 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
54236- 0 0 0 0 0 0 0 0 0 6 6 6
54237- 10 10 10 10 10 10 18 18 18 38 38 38
54238- 78 78 78 142 134 106 216 158 10 242 186 14
54239-246 190 14 246 190 14 156 118 10 10 10 10
54240- 90 90 90 238 238 238 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 231 231 231 250 250 250
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 253 253 253 253 253 253 253 253 253
54246-253 253 253 253 253 253 253 253 253 246 230 190
54247-238 204 91 238 204 91 181 142 44 37 26 9
54248- 2 2 6 2 2 6 2 2 6 2 2 6
54249- 2 2 6 2 2 6 38 38 38 46 46 46
54250- 26 26 26 106 106 106 54 54 54 18 18 18
54251- 6 6 6 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 0 0 0
54255- 0 0 0 0 0 0 0 0 0 0 0 0
54256- 0 0 0 6 6 6 14 14 14 22 22 22
54257- 30 30 30 38 38 38 50 50 50 70 70 70
54258-106 106 106 190 142 34 226 170 11 242 186 14
54259-246 190 14 246 190 14 246 190 14 154 114 10
54260- 6 6 6 74 74 74 226 226 226 253 253 253
54261-253 253 253 253 253 253 253 253 253 253 253 253
54262-253 253 253 253 253 253 231 231 231 250 250 250
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 253 253 253 253 253 253 253 253 253
54266-253 253 253 253 253 253 253 253 253 228 184 62
54267-241 196 14 241 208 19 232 195 16 38 30 10
54268- 2 2 6 2 2 6 2 2 6 2 2 6
54269- 2 2 6 6 6 6 30 30 30 26 26 26
54270-203 166 17 154 142 90 66 66 66 26 26 26
54271- 6 6 6 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 0 0 0
54275- 0 0 0 0 0 0 0 0 0 0 0 0
54276- 6 6 6 18 18 18 38 38 38 58 58 58
54277- 78 78 78 86 86 86 101 101 101 123 123 123
54278-175 146 61 210 150 10 234 174 13 246 186 14
54279-246 190 14 246 190 14 246 190 14 238 190 10
54280-102 78 10 2 2 6 46 46 46 198 198 198
54281-253 253 253 253 253 253 253 253 253 253 253 253
54282-253 253 253 253 253 253 234 234 234 242 242 242
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 253 253 253 253 253 253 253 253 253
54286-253 253 253 253 253 253 253 253 253 224 178 62
54287-242 186 14 241 196 14 210 166 10 22 18 6
54288- 2 2 6 2 2 6 2 2 6 2 2 6
54289- 2 2 6 2 2 6 6 6 6 121 92 8
54290-238 202 15 232 195 16 82 82 82 34 34 34
54291- 10 10 10 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 0 0 0
54295- 0 0 0 0 0 0 0 0 0 0 0 0
54296- 14 14 14 38 38 38 70 70 70 154 122 46
54297-190 142 34 200 144 11 197 138 11 197 138 11
54298-213 154 11 226 170 11 242 186 14 246 190 14
54299-246 190 14 246 190 14 246 190 14 246 190 14
54300-225 175 15 46 32 6 2 2 6 22 22 22
54301-158 158 158 250 250 250 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-253 253 253 253 253 253 253 253 253 253 253 253
54306-253 253 253 250 250 250 242 242 242 224 178 62
54307-239 182 13 236 186 11 213 154 11 46 32 6
54308- 2 2 6 2 2 6 2 2 6 2 2 6
54309- 2 2 6 2 2 6 61 42 6 225 175 15
54310-238 190 10 236 186 11 112 100 78 42 42 42
54311- 14 14 14 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 0 0 0
54315- 0 0 0 0 0 0 0 0 0 6 6 6
54316- 22 22 22 54 54 54 154 122 46 213 154 11
54317-226 170 11 230 174 11 226 170 11 226 170 11
54318-236 178 12 242 186 14 246 190 14 246 190 14
54319-246 190 14 246 190 14 246 190 14 246 190 14
54320-241 196 14 184 144 12 10 10 10 2 2 6
54321- 6 6 6 116 116 116 242 242 242 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-253 253 253 253 253 253 253 253 253 253 253 253
54326-253 253 253 231 231 231 198 198 198 214 170 54
54327-236 178 12 236 178 12 210 150 10 137 92 6
54328- 18 14 6 2 2 6 2 2 6 2 2 6
54329- 6 6 6 70 47 6 200 144 11 236 178 12
54330-239 182 13 239 182 13 124 112 88 58 58 58
54331- 22 22 22 6 6 6 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 0 0 0
54335- 0 0 0 0 0 0 0 0 0 10 10 10
54336- 30 30 30 70 70 70 180 133 36 226 170 11
54337-239 182 13 242 186 14 242 186 14 246 186 14
54338-246 190 14 246 190 14 246 190 14 246 190 14
54339-246 190 14 246 190 14 246 190 14 246 190 14
54340-246 190 14 232 195 16 98 70 6 2 2 6
54341- 2 2 6 2 2 6 66 66 66 221 221 221
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 253 253 253 253 253 253 253 253 253
54346-253 253 253 206 206 206 198 198 198 214 166 58
54347-230 174 11 230 174 11 216 158 10 192 133 9
54348-163 110 8 116 81 8 102 78 10 116 81 8
54349-167 114 7 197 138 11 226 170 11 239 182 13
54350-242 186 14 242 186 14 162 146 94 78 78 78
54351- 34 34 34 14 14 14 6 6 6 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 0 0 0
54355- 0 0 0 0 0 0 0 0 0 6 6 6
54356- 30 30 30 78 78 78 190 142 34 226 170 11
54357-239 182 13 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 246 190 14
54360-246 190 14 241 196 14 203 166 17 22 18 6
54361- 2 2 6 2 2 6 2 2 6 38 38 38
54362-218 218 218 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 253 253 253 253 253 253 253 253 253
54366-250 250 250 206 206 206 198 198 198 202 162 69
54367-226 170 11 236 178 12 224 166 10 210 150 10
54368-200 144 11 197 138 11 192 133 9 197 138 11
54369-210 150 10 226 170 11 242 186 14 246 190 14
54370-246 190 14 246 186 14 225 175 15 124 112 88
54371- 62 62 62 30 30 30 14 14 14 6 6 6
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 0 0 0
54375- 0 0 0 0 0 0 0 0 0 10 10 10
54376- 30 30 30 78 78 78 174 135 50 224 166 10
54377-239 182 13 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-246 190 14 246 190 14 241 196 14 139 102 15
54381- 2 2 6 2 2 6 2 2 6 2 2 6
54382- 78 78 78 250 250 250 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-253 253 253 253 253 253 253 253 253 253 253 253
54386-250 250 250 214 214 214 198 198 198 190 150 46
54387-219 162 10 236 178 12 234 174 13 224 166 10
54388-216 158 10 213 154 11 213 154 11 216 158 10
54389-226 170 11 239 182 13 246 190 14 246 190 14
54390-246 190 14 246 190 14 242 186 14 206 162 42
54391-101 101 101 58 58 58 30 30 30 14 14 14
54392- 6 6 6 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 0 0 0
54395- 0 0 0 0 0 0 0 0 0 10 10 10
54396- 30 30 30 74 74 74 174 135 50 216 158 10
54397-236 178 12 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-246 190 14 246 190 14 241 196 14 226 184 13
54401- 61 42 6 2 2 6 2 2 6 2 2 6
54402- 22 22 22 238 238 238 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 253 253 253
54405-253 253 253 253 253 253 253 253 253 253 253 253
54406-253 253 253 226 226 226 187 187 187 180 133 36
54407-216 158 10 236 178 12 239 182 13 236 178 12
54408-230 174 11 226 170 11 226 170 11 230 174 11
54409-236 178 12 242 186 14 246 190 14 246 190 14
54410-246 190 14 246 190 14 246 186 14 239 182 13
54411-206 162 42 106 106 106 66 66 66 34 34 34
54412- 14 14 14 6 6 6 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 0 0 0
54415- 0 0 0 0 0 0 0 0 0 6 6 6
54416- 26 26 26 70 70 70 163 133 67 213 154 11
54417-236 178 12 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 246 190 14 246 190 14 241 196 14
54421-190 146 13 18 14 6 2 2 6 2 2 6
54422- 46 46 46 246 246 246 253 253 253 253 253 253
54423-253 253 253 253 253 253 253 253 253 253 253 253
54424-253 253 253 253 253 253 253 253 253 253 253 253
54425-253 253 253 253 253 253 253 253 253 253 253 253
54426-253 253 253 221 221 221 86 86 86 156 107 11
54427-216 158 10 236 178 12 242 186 14 246 186 14
54428-242 186 14 239 182 13 239 182 13 242 186 14
54429-242 186 14 246 186 14 246 190 14 246 190 14
54430-246 190 14 246 190 14 246 190 14 246 190 14
54431-242 186 14 225 175 15 142 122 72 66 66 66
54432- 30 30 30 10 10 10 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 0 0 0 0 0 0
54435- 0 0 0 0 0 0 0 0 0 6 6 6
54436- 26 26 26 70 70 70 163 133 67 210 150 10
54437-236 178 12 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-246 190 14 246 190 14 246 190 14 246 190 14
54441-232 195 16 121 92 8 34 34 34 106 106 106
54442-221 221 221 253 253 253 253 253 253 253 253 253
54443-253 253 253 253 253 253 253 253 253 253 253 253
54444-253 253 253 253 253 253 253 253 253 253 253 253
54445-253 253 253 253 253 253 253 253 253 253 253 253
54446-242 242 242 82 82 82 18 14 6 163 110 8
54447-216 158 10 236 178 12 242 186 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 246 190 14
54450-246 190 14 246 190 14 246 190 14 246 190 14
54451-246 190 14 246 190 14 242 186 14 163 133 67
54452- 46 46 46 18 18 18 6 6 6 0 0 0
54453- 0 0 0 0 0 0 0 0 0 0 0 0
54454- 0 0 0 0 0 0 0 0 0 0 0 0
54455- 0 0 0 0 0 0 0 0 0 10 10 10
54456- 30 30 30 78 78 78 163 133 67 210 150 10
54457-236 178 12 246 186 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 190 14 246 190 14 246 190 14 246 190 14
54461-241 196 14 215 174 15 190 178 144 253 253 253
54462-253 253 253 253 253 253 253 253 253 253 253 253
54463-253 253 253 253 253 253 253 253 253 253 253 253
54464-253 253 253 253 253 253 253 253 253 253 253 253
54465-253 253 253 253 253 253 253 253 253 218 218 218
54466- 58 58 58 2 2 6 22 18 6 167 114 7
54467-216 158 10 236 178 12 246 186 14 246 190 14
54468-246 190 14 246 190 14 246 190 14 246 190 14
54469-246 190 14 246 190 14 246 190 14 246 190 14
54470-246 190 14 246 190 14 246 190 14 246 190 14
54471-246 190 14 246 186 14 242 186 14 190 150 46
54472- 54 54 54 22 22 22 6 6 6 0 0 0
54473- 0 0 0 0 0 0 0 0 0 0 0 0
54474- 0 0 0 0 0 0 0 0 0 0 0 0
54475- 0 0 0 0 0 0 0 0 0 14 14 14
54476- 38 38 38 86 86 86 180 133 36 213 154 11
54477-236 178 12 246 186 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 246 190 14 246 190 14 246 190 14
54481-246 190 14 232 195 16 190 146 13 214 214 214
54482-253 253 253 253 253 253 253 253 253 253 253 253
54483-253 253 253 253 253 253 253 253 253 253 253 253
54484-253 253 253 253 253 253 253 253 253 253 253 253
54485-253 253 253 250 250 250 170 170 170 26 26 26
54486- 2 2 6 2 2 6 37 26 9 163 110 8
54487-219 162 10 239 182 13 246 186 14 246 190 14
54488-246 190 14 246 190 14 246 190 14 246 190 14
54489-246 190 14 246 190 14 246 190 14 246 190 14
54490-246 190 14 246 190 14 246 190 14 246 190 14
54491-246 186 14 236 178 12 224 166 10 142 122 72
54492- 46 46 46 18 18 18 6 6 6 0 0 0
54493- 0 0 0 0 0 0 0 0 0 0 0 0
54494- 0 0 0 0 0 0 0 0 0 0 0 0
54495- 0 0 0 0 0 0 6 6 6 18 18 18
54496- 50 50 50 109 106 95 192 133 9 224 166 10
54497-242 186 14 246 190 14 246 190 14 246 190 14
54498-246 190 14 246 190 14 246 190 14 246 190 14
54499-246 190 14 246 190 14 246 190 14 246 190 14
54500-246 190 14 246 190 14 246 190 14 246 190 14
54501-242 186 14 226 184 13 210 162 10 142 110 46
54502-226 226 226 253 253 253 253 253 253 253 253 253
54503-253 253 253 253 253 253 253 253 253 253 253 253
54504-253 253 253 253 253 253 253 253 253 253 253 253
54505-198 198 198 66 66 66 2 2 6 2 2 6
54506- 2 2 6 2 2 6 50 34 6 156 107 11
54507-219 162 10 239 182 13 246 186 14 246 190 14
54508-246 190 14 246 190 14 246 190 14 246 190 14
54509-246 190 14 246 190 14 246 190 14 246 190 14
54510-246 190 14 246 190 14 246 190 14 242 186 14
54511-234 174 13 213 154 11 154 122 46 66 66 66
54512- 30 30 30 10 10 10 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 0 0 0
54515- 0 0 0 0 0 0 6 6 6 22 22 22
54516- 58 58 58 154 121 60 206 145 10 234 174 13
54517-242 186 14 246 186 14 246 190 14 246 190 14
54518-246 190 14 246 190 14 246 190 14 246 190 14
54519-246 190 14 246 190 14 246 190 14 246 190 14
54520-246 190 14 246 190 14 246 190 14 246 190 14
54521-246 186 14 236 178 12 210 162 10 163 110 8
54522- 61 42 6 138 138 138 218 218 218 250 250 250
54523-253 253 253 253 253 253 253 253 253 250 250 250
54524-242 242 242 210 210 210 144 144 144 66 66 66
54525- 6 6 6 2 2 6 2 2 6 2 2 6
54526- 2 2 6 2 2 6 61 42 6 163 110 8
54527-216 158 10 236 178 12 246 190 14 246 190 14
54528-246 190 14 246 190 14 246 190 14 246 190 14
54529-246 190 14 246 190 14 246 190 14 246 190 14
54530-246 190 14 239 182 13 230 174 11 216 158 10
54531-190 142 34 124 112 88 70 70 70 38 38 38
54532- 18 18 18 6 6 6 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 0 0 0
54535- 0 0 0 0 0 0 6 6 6 22 22 22
54536- 62 62 62 168 124 44 206 145 10 224 166 10
54537-236 178 12 239 182 13 242 186 14 242 186 14
54538-246 186 14 246 190 14 246 190 14 246 190 14
54539-246 190 14 246 190 14 246 190 14 246 190 14
54540-246 190 14 246 190 14 246 190 14 246 190 14
54541-246 190 14 236 178 12 216 158 10 175 118 6
54542- 80 54 7 2 2 6 6 6 6 30 30 30
54543- 54 54 54 62 62 62 50 50 50 38 38 38
54544- 14 14 14 2 2 6 2 2 6 2 2 6
54545- 2 2 6 2 2 6 2 2 6 2 2 6
54546- 2 2 6 6 6 6 80 54 7 167 114 7
54547-213 154 11 236 178 12 246 190 14 246 190 14
54548-246 190 14 246 190 14 246 190 14 246 190 14
54549-246 190 14 242 186 14 239 182 13 239 182 13
54550-230 174 11 210 150 10 174 135 50 124 112 88
54551- 82 82 82 54 54 54 34 34 34 18 18 18
54552- 6 6 6 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- 0 0 0 0 0 0 6 6 6 18 18 18
54556- 50 50 50 158 118 36 192 133 9 200 144 11
54557-216 158 10 219 162 10 224 166 10 226 170 11
54558-230 174 11 236 178 12 239 182 13 239 182 13
54559-242 186 14 246 186 14 246 190 14 246 190 14
54560-246 190 14 246 190 14 246 190 14 246 190 14
54561-246 186 14 230 174 11 210 150 10 163 110 8
54562-104 69 6 10 10 10 2 2 6 2 2 6
54563- 2 2 6 2 2 6 2 2 6 2 2 6
54564- 2 2 6 2 2 6 2 2 6 2 2 6
54565- 2 2 6 2 2 6 2 2 6 2 2 6
54566- 2 2 6 6 6 6 91 60 6 167 114 7
54567-206 145 10 230 174 11 242 186 14 246 190 14
54568-246 190 14 246 190 14 246 186 14 242 186 14
54569-239 182 13 230 174 11 224 166 10 213 154 11
54570-180 133 36 124 112 88 86 86 86 58 58 58
54571- 38 38 38 22 22 22 10 10 10 6 6 6
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 0 0 0 14 14 14
54576- 34 34 34 70 70 70 138 110 50 158 118 36
54577-167 114 7 180 123 7 192 133 9 197 138 11
54578-200 144 11 206 145 10 213 154 11 219 162 10
54579-224 166 10 230 174 11 239 182 13 242 186 14
54580-246 186 14 246 186 14 246 186 14 246 186 14
54581-239 182 13 216 158 10 185 133 11 152 99 6
54582-104 69 6 18 14 6 2 2 6 2 2 6
54583- 2 2 6 2 2 6 2 2 6 2 2 6
54584- 2 2 6 2 2 6 2 2 6 2 2 6
54585- 2 2 6 2 2 6 2 2 6 2 2 6
54586- 2 2 6 6 6 6 80 54 7 152 99 6
54587-192 133 9 219 162 10 236 178 12 239 182 13
54588-246 186 14 242 186 14 239 182 13 236 178 12
54589-224 166 10 206 145 10 192 133 9 154 121 60
54590- 94 94 94 62 62 62 42 42 42 22 22 22
54591- 14 14 14 6 6 6 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 6 6 6
54596- 18 18 18 34 34 34 58 58 58 78 78 78
54597-101 98 89 124 112 88 142 110 46 156 107 11
54598-163 110 8 167 114 7 175 118 6 180 123 7
54599-185 133 11 197 138 11 210 150 10 219 162 10
54600-226 170 11 236 178 12 236 178 12 234 174 13
54601-219 162 10 197 138 11 163 110 8 130 83 6
54602- 91 60 6 10 10 10 2 2 6 2 2 6
54603- 18 18 18 38 38 38 38 38 38 38 38 38
54604- 38 38 38 38 38 38 38 38 38 38 38 38
54605- 38 38 38 38 38 38 26 26 26 2 2 6
54606- 2 2 6 6 6 6 70 47 6 137 92 6
54607-175 118 6 200 144 11 219 162 10 230 174 11
54608-234 174 13 230 174 11 219 162 10 210 150 10
54609-192 133 9 163 110 8 124 112 88 82 82 82
54610- 50 50 50 30 30 30 14 14 14 6 6 6
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- 6 6 6 14 14 14 22 22 22 34 34 34
54617- 42 42 42 58 58 58 74 74 74 86 86 86
54618-101 98 89 122 102 70 130 98 46 121 87 25
54619-137 92 6 152 99 6 163 110 8 180 123 7
54620-185 133 11 197 138 11 206 145 10 200 144 11
54621-180 123 7 156 107 11 130 83 6 104 69 6
54622- 50 34 6 54 54 54 110 110 110 101 98 89
54623- 86 86 86 82 82 82 78 78 78 78 78 78
54624- 78 78 78 78 78 78 78 78 78 78 78 78
54625- 78 78 78 82 82 82 86 86 86 94 94 94
54626-106 106 106 101 101 101 86 66 34 124 80 6
54627-156 107 11 180 123 7 192 133 9 200 144 11
54628-206 145 10 200 144 11 192 133 9 175 118 6
54629-139 102 15 109 106 95 70 70 70 42 42 42
54630- 22 22 22 10 10 10 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 6 6 6 10 10 10
54637- 14 14 14 22 22 22 30 30 30 38 38 38
54638- 50 50 50 62 62 62 74 74 74 90 90 90
54639-101 98 89 112 100 78 121 87 25 124 80 6
54640-137 92 6 152 99 6 152 99 6 152 99 6
54641-138 86 6 124 80 6 98 70 6 86 66 30
54642-101 98 89 82 82 82 58 58 58 46 46 46
54643- 38 38 38 34 34 34 34 34 34 34 34 34
54644- 34 34 34 34 34 34 34 34 34 34 34 34
54645- 34 34 34 34 34 34 38 38 38 42 42 42
54646- 54 54 54 82 82 82 94 86 76 91 60 6
54647-134 86 6 156 107 11 167 114 7 175 118 6
54648-175 118 6 167 114 7 152 99 6 121 87 25
54649-101 98 89 62 62 62 34 34 34 18 18 18
54650- 6 6 6 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 6 6 6 6 6 6 10 10 10
54658- 18 18 18 22 22 22 30 30 30 42 42 42
54659- 50 50 50 66 66 66 86 86 86 101 98 89
54660-106 86 58 98 70 6 104 69 6 104 69 6
54661-104 69 6 91 60 6 82 62 34 90 90 90
54662- 62 62 62 38 38 38 22 22 22 14 14 14
54663- 10 10 10 10 10 10 10 10 10 10 10 10
54664- 10 10 10 10 10 10 6 6 6 10 10 10
54665- 10 10 10 10 10 10 10 10 10 14 14 14
54666- 22 22 22 42 42 42 70 70 70 89 81 66
54667- 80 54 7 104 69 6 124 80 6 137 92 6
54668-134 86 6 116 81 8 100 82 52 86 86 86
54669- 58 58 58 30 30 30 14 14 14 6 6 6
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- 0 0 0 0 0 0 0 0 0 0 0 0
54674- 0 0 0 0 0 0 0 0 0 0 0 0
54675- 0 0 0 0 0 0 0 0 0 0 0 0
54676- 0 0 0 0 0 0 0 0 0 0 0 0
54677- 0 0 0 0 0 0 0 0 0 0 0 0
54678- 0 0 0 6 6 6 10 10 10 14 14 14
54679- 18 18 18 26 26 26 38 38 38 54 54 54
54680- 70 70 70 86 86 86 94 86 76 89 81 66
54681- 89 81 66 86 86 86 74 74 74 50 50 50
54682- 30 30 30 14 14 14 6 6 6 0 0 0
54683- 0 0 0 0 0 0 0 0 0 0 0 0
54684- 0 0 0 0 0 0 0 0 0 0 0 0
54685- 0 0 0 0 0 0 0 0 0 0 0 0
54686- 6 6 6 18 18 18 34 34 34 58 58 58
54687- 82 82 82 89 81 66 89 81 66 89 81 66
54688- 94 86 66 94 86 76 74 74 74 50 50 50
54689- 26 26 26 14 14 14 6 6 6 0 0 0
54690- 0 0 0 0 0 0 0 0 0 0 0 0
54691- 0 0 0 0 0 0 0 0 0 0 0 0
54692- 0 0 0 0 0 0 0 0 0 0 0 0
54693- 0 0 0 0 0 0 0 0 0 0 0 0
54694- 0 0 0 0 0 0 0 0 0 0 0 0
54695- 0 0 0 0 0 0 0 0 0 0 0 0
54696- 0 0 0 0 0 0 0 0 0 0 0 0
54697- 0 0 0 0 0 0 0 0 0 0 0 0
54698- 0 0 0 0 0 0 0 0 0 0 0 0
54699- 6 6 6 6 6 6 14 14 14 18 18 18
54700- 30 30 30 38 38 38 46 46 46 54 54 54
54701- 50 50 50 42 42 42 30 30 30 18 18 18
54702- 10 10 10 0 0 0 0 0 0 0 0 0
54703- 0 0 0 0 0 0 0 0 0 0 0 0
54704- 0 0 0 0 0 0 0 0 0 0 0 0
54705- 0 0 0 0 0 0 0 0 0 0 0 0
54706- 0 0 0 6 6 6 14 14 14 26 26 26
54707- 38 38 38 50 50 50 58 58 58 58 58 58
54708- 54 54 54 42 42 42 30 30 30 18 18 18
54709- 10 10 10 0 0 0 0 0 0 0 0 0
54710- 0 0 0 0 0 0 0 0 0 0 0 0
54711- 0 0 0 0 0 0 0 0 0 0 0 0
54712- 0 0 0 0 0 0 0 0 0 0 0 0
54713- 0 0 0 0 0 0 0 0 0 0 0 0
54714- 0 0 0 0 0 0 0 0 0 0 0 0
54715- 0 0 0 0 0 0 0 0 0 0 0 0
54716- 0 0 0 0 0 0 0 0 0 0 0 0
54717- 0 0 0 0 0 0 0 0 0 0 0 0
54718- 0 0 0 0 0 0 0 0 0 0 0 0
54719- 0 0 0 0 0 0 0 0 0 6 6 6
54720- 6 6 6 10 10 10 14 14 14 18 18 18
54721- 18 18 18 14 14 14 10 10 10 6 6 6
54722- 0 0 0 0 0 0 0 0 0 0 0 0
54723- 0 0 0 0 0 0 0 0 0 0 0 0
54724- 0 0 0 0 0 0 0 0 0 0 0 0
54725- 0 0 0 0 0 0 0 0 0 0 0 0
54726- 0 0 0 0 0 0 0 0 0 6 6 6
54727- 14 14 14 18 18 18 22 22 22 22 22 22
54728- 18 18 18 14 14 14 10 10 10 6 6 6
54729- 0 0 0 0 0 0 0 0 0 0 0 0
54730- 0 0 0 0 0 0 0 0 0 0 0 0
54731- 0 0 0 0 0 0 0 0 0 0 0 0
54732- 0 0 0 0 0 0 0 0 0 0 0 0
54733- 0 0 0 0 0 0 0 0 0 0 0 0
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 4 4 4 4 4 4 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
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 4 4 4 4 4 4 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
54762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
54767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4 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
54776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54777+4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
54781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54784+4 4 4 4 4 4 4 4 4 4 4 4 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+4 4 4 4 4 4
54790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54791+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
54795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54798+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
54803+4 4 4 4 4 4
54804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
54808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54812+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54817+4 4 4 4 4 4
54818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54822+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54823+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54827+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54828+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54829+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54830+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54831+4 4 4 4 4 4
54832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54836+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54837+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54838+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54841+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
54842+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54843+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54844+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54845+4 4 4 4 4 4
54846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54850+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54851+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54852+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54855+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
54856+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54857+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54858+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54859+4 4 4 4 4 4
54860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54862+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54863+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
54864+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54865+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54866+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
54867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54868+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54869+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54870+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54871+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54872+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54873+4 4 4 4 4 4
54874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54877+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54878+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54879+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54880+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54881+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54882+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54883+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54884+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54885+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54886+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54887+4 4 4 4 4 4
54888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54891+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54892+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54893+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54894+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54895+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54896+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54897+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54898+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54899+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54900+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54901+4 4 4 4 4 4
54902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54903+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54904+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
54905+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54906+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54907+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54908+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54909+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54910+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54911+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54912+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54913+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54914+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54915+4 4 4 4 4 4
54916+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54918+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
54919+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54920+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54921+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54922+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54923+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54924+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54925+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54926+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54927+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54928+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54929+4 4 4 4 4 4
54930+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54932+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54933+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54934+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54935+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54936+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54937+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54938+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54939+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54940+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54941+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54942+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54943+4 4 4 4 4 4
54944+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54946+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54947+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54948+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54949+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54950+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54951+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54952+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54953+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54954+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54955+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54956+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54957+4 4 4 4 4 4
54958+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54959+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
54960+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54961+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54962+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54963+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54964+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54965+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54966+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54967+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54968+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54969+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54970+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54971+4 4 4 4 4 4
54972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54973+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54974+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54975+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54976+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54977+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54978+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54979+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54980+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54981+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54982+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54983+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54984+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54985+0 0 0 4 4 4
54986+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54987+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54988+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54989+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54990+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54991+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54992+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54993+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54994+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54995+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54996+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54997+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54998+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54999+2 0 0 0 0 0
55000+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
55001+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
55002+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
55003+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
55004+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
55005+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
55006+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
55007+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
55008+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
55009+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
55010+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
55011+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
55012+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
55013+37 38 37 0 0 0
55014+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55015+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
55016+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
55017+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
55018+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
55019+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
55020+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
55021+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
55022+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
55023+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
55024+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
55025+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
55026+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
55027+85 115 134 4 0 0
55028+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
55029+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
55030+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
55031+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
55032+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
55033+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
55034+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
55035+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
55036+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
55037+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
55038+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
55039+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
55040+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
55041+60 73 81 4 0 0
55042+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
55043+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
55044+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
55045+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
55046+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
55047+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
55048+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
55049+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
55050+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
55051+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
55052+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
55053+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
55054+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
55055+16 19 21 4 0 0
55056+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
55057+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
55058+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
55059+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
55060+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
55061+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
55062+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
55063+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
55064+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
55065+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
55066+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
55067+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
55068+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
55069+4 0 0 4 3 3
55070+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
55071+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
55072+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
55073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
55074+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
55075+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
55076+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
55077+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
55078+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
55079+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
55080+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
55081+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
55082+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
55083+3 2 2 4 4 4
55084+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
55085+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
55086+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
55087+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55088+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
55089+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
55090+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
55091+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
55092+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
55093+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
55094+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
55095+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
55096+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
55097+4 4 4 4 4 4
55098+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
55099+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
55100+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
55101+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
55102+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
55103+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
55104+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
55105+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
55106+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
55107+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
55108+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
55109+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
55110+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
55111+4 4 4 4 4 4
55112+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
55113+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
55114+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
55115+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
55116+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
55117+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55118+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
55119+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
55120+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
55121+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
55122+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
55123+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
55124+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
55125+5 5 5 5 5 5
55126+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55127+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55128+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55129+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55130+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55131+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55132+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55133+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55134+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55135+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55136+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55137+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55138+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55139+5 5 5 4 4 4
55140+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55141+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55142+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55143+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55144+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55145+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55146+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55147+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55148+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55149+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55150+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55151+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55153+4 4 4 4 4 4
55154+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55155+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55156+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55157+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55158+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55159+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55160+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55161+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55162+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55163+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55164+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55165+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
55166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55167+4 4 4 4 4 4
55168+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
55169+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55170+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55171+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55172+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55173+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
55174+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55175+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55176+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55177+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55178+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
55179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55181+4 4 4 4 4 4
55182+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
55183+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55184+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55185+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55186+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55187+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55188+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55189+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55190+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55191+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55192+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
55193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55195+4 4 4 4 4 4
55196+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55197+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55198+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55199+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55200+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55201+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55202+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55203+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55204+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55205+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
55206+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55209+4 4 4 4 4 4
55210+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55211+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55212+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55213+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55214+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55215+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55216+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55217+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55218+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55219+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55220+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
55221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55223+4 4 4 4 4 4
55224+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55225+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55226+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55227+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55228+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55229+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55230+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55231+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55232+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55233+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55234+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
55235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55237+4 4 4 4 4 4
55238+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
55239+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55240+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55241+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55242+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55243+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55244+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55245+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55246+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55247+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55248+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55251+4 4 4 4 4 4
55252+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
55253+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55254+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55255+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55256+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55257+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55258+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55259+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55260+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55261+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55262+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55265+4 4 4 4 4 4
55266+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
55267+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55268+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55269+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55270+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55271+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55272+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55273+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55274+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55275+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55276+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55279+4 4 4 4 4 4
55280+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
55281+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55282+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55283+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55284+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55285+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55286+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55287+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
55288+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55289+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55290+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55293+4 4 4 4 4 4
55294+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55295+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55296+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55297+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55298+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55299+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55300+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55301+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55302+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55303+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55304+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55307+4 4 4 4 4 4
55308+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55309+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
55310+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55311+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55312+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55313+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55314+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55315+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55316+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55317+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55318+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55321+4 4 4 4 4 4
55322+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55323+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55324+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55325+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55326+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55327+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55328+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55329+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
55330+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55331+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55332+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55335+4 4 4 4 4 4
55336+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55337+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
55338+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55339+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55340+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55341+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55342+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55343+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55344+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55345+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55346+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55349+4 4 4 4 4 4
55350+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55351+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55352+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55353+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55354+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55355+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55356+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55357+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
55358+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55359+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55360+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55363+4 4 4 4 4 4
55364+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
55365+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55366+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55367+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55368+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55369+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55370+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55371+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55372+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
55373+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55374+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55377+4 4 4 4 4 4
55378+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55379+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55380+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55381+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55382+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55383+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55384+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55385+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55386+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55387+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55388+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55391+4 4 4 4 4 4
55392+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55393+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55394+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55395+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55396+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55397+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55398+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55399+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55400+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55401+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55402+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55405+4 4 4 4 4 4
55406+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55407+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55408+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55409+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55410+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55411+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55412+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55413+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55414+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55415+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55416+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55419+4 4 4 4 4 4
55420+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55421+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55422+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55423+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55424+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55425+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55426+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55427+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55428+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55429+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55430+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55433+4 4 4 4 4 4
55434+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55435+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55436+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55437+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55438+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55439+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55440+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55441+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55442+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55443+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55444+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55447+4 4 4 4 4 4
55448+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55449+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55450+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55451+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55452+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55453+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55454+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55455+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55456+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
55457+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55458+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55461+4 4 4 4 4 4
55462+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55463+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55464+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55465+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55466+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55467+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55468+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55469+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55470+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55471+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55472+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55475+4 4 4 4 4 4
55476+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55477+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
55478+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
55479+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
55480+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
55481+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
55482+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
55483+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
55484+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
55485+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55486+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55489+4 4 4 4 4 4
55490+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
55491+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
55492+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
55493+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
55494+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
55495+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
55496+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
55497+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
55498+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
55499+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
55500+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55503+4 4 4 4 4 4
55504+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
55505+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55506+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
55507+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
55508+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
55509+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
55510+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
55511+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
55512+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
55513+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
55514+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55517+4 4 4 4 4 4
55518+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
55519+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55520+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
55521+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
55522+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
55523+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
55524+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55525+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
55526+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
55527+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
55528+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55530+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55531+4 4 4 4 4 4
55532+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
55533+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
55534+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
55535+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
55536+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55537+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55538+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55539+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55540+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55541+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55542+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55545+4 4 4 4 4 4
55546+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55547+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55548+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55549+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55550+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55551+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55552+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55553+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55554+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55555+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
55556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55559+4 4 4 4 4 4
55560+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55561+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55562+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55563+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55564+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
55565+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55566+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55567+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55568+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55569+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55573+4 4 4 4 4 4
55574+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55575+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55576+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55577+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55578+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55579+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55580+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55581+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55582+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55583+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55587+4 4 4 4 4 4
55588+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55589+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55590+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
55591+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
55592+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
55593+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
55594+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
55595+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
55596+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55597+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55601+4 4 4 4 4 4
55602+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
55603+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55604+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
55605+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55606+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
55607+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55608+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55609+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55610+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
55611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55615+4 4 4 4 4 4
55616+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55617+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55618+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55619+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55620+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55621+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55622+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55623+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55624+4 0 0 4 0 0 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55629+4 4 4 4 4 4
55630+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55631+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55632+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55633+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55634+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55635+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55636+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55637+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55638+4 0 0 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
55641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55643+4 4 4 4 4 4
55644+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55645+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55646+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55647+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55648+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55649+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55650+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55651+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55652+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55657+4 4 4 4 4 4
55658+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55659+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55660+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55661+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55662+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55663+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55664+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55665+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55666+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
55670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55671+4 4 4 4 4 4
55672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55673+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55674+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55675+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55676+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55677+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55678+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55679+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55680+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55685+4 4 4 4 4 4
55686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55687+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55688+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55689+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55690+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55691+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55692+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55693+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55694+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
55699+4 4 4 4 4 4
55700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55701+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55702+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55703+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55704+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55705+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55706+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55707+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55708+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
55713+4 4 4 4 4 4
55714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55716+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55717+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55718+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55719+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55720+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55721+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55722+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
55727+4 4 4 4 4 4
55728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55729+4 4 4 4 4 4 4 4 4 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 5 5 5
55731+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55732+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55733+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55734+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 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 4 4 4
55742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55743+4 4 4 4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55746+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55747+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55748+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 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 4 4 4
55756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55757+4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6
55760+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55761+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55762+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 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
55770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 5 5 5 4 3 3 5 5 5
55774+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55775+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55776+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 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
55784+4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5
55788+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55789+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55790+6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55797+4 4 4 4 4 4
55798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55799+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55800+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55801+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55802+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55803+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55804+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55807+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55811+4 4 4 4 4 4
55812+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55813+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55814+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55815+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55816+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55817+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55818+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55825+4 4 4 4 4 4
55826+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55827+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55828+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55829+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55830+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55831+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55839+4 4 4 4 4 4
55840+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55841+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55842+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55843+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55844+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55845+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55848+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55853+4 4 4 4 4 4
55854diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55855index fef20db..d28b1ab 100644
55856--- a/drivers/xen/xenfs/xenstored.c
55857+++ b/drivers/xen/xenfs/xenstored.c
55858@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55859 static int xsd_kva_open(struct inode *inode, struct file *file)
55860 {
55861 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55862+#ifdef CONFIG_GRKERNSEC_HIDESYM
55863+ NULL);
55864+#else
55865 xen_store_interface);
55866+#endif
55867+
55868 if (!file->private_data)
55869 return -ENOMEM;
55870 return 0;
55871diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55872index c71e886..61d3d44b 100644
55873--- a/fs/9p/vfs_addr.c
55874+++ b/fs/9p/vfs_addr.c
55875@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55876
55877 retval = v9fs_file_write_internal(inode,
55878 v9inode->writeback_fid,
55879- (__force const char __user *)buffer,
55880+ (const char __force_user *)buffer,
55881 len, &offset, 0);
55882 if (retval > 0)
55883 retval = 0;
55884diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55885index 53161ec..e261d8a 100644
55886--- a/fs/9p/vfs_inode.c
55887+++ b/fs/9p/vfs_inode.c
55888@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55889 void
55890 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55891 {
55892- char *s = nd_get_link(nd);
55893+ const char *s = nd_get_link(nd);
55894
55895 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55896 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55897diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55898index 370b24c..ff0be7b 100644
55899--- a/fs/Kconfig.binfmt
55900+++ b/fs/Kconfig.binfmt
55901@@ -103,7 +103,7 @@ config HAVE_AOUT
55902
55903 config BINFMT_AOUT
55904 tristate "Kernel support for a.out and ECOFF binaries"
55905- depends on HAVE_AOUT
55906+ depends on HAVE_AOUT && BROKEN
55907 ---help---
55908 A.out (Assembler.OUTput) is a set of formats for libraries and
55909 executables used in the earliest versions of UNIX. Linux used
55910diff --git a/fs/afs/inode.c b/fs/afs/inode.c
55911index 2946712..f737435 100644
55912--- a/fs/afs/inode.c
55913+++ b/fs/afs/inode.c
55914@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55915 struct afs_vnode *vnode;
55916 struct super_block *sb;
55917 struct inode *inode;
55918- static atomic_t afs_autocell_ino;
55919+ static atomic_unchecked_t afs_autocell_ino;
55920
55921 _enter("{%x:%u},%*.*s,",
55922 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
55923@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55924 data.fid.unique = 0;
55925 data.fid.vnode = 0;
55926
55927- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55928+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55929 afs_iget5_autocell_test, afs_iget5_set,
55930 &data);
55931 if (!inode) {
55932diff --git a/fs/aio.c b/fs/aio.c
55933index e609e15..c9fcd97 100644
55934--- a/fs/aio.c
55935+++ b/fs/aio.c
55936@@ -380,7 +380,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55937 size += sizeof(struct io_event) * nr_events;
55938
55939 nr_pages = PFN_UP(size);
55940- if (nr_pages < 0)
55941+ if (nr_pages <= 0)
55942 return -EINVAL;
55943
55944 file = aio_private_file(ctx, nr_pages);
55945diff --git a/fs/attr.c b/fs/attr.c
55946index 6530ced..4a827e2 100644
55947--- a/fs/attr.c
55948+++ b/fs/attr.c
55949@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55950 unsigned long limit;
55951
55952 limit = rlimit(RLIMIT_FSIZE);
55953+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55954 if (limit != RLIM_INFINITY && offset > limit)
55955 goto out_sig;
55956 if (offset > inode->i_sb->s_maxbytes)
55957diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55958index 116fd38..c04182da 100644
55959--- a/fs/autofs4/waitq.c
55960+++ b/fs/autofs4/waitq.c
55961@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55962 {
55963 unsigned long sigpipe, flags;
55964 mm_segment_t fs;
55965- const char *data = (const char *)addr;
55966+ const char __user *data = (const char __force_user *)addr;
55967 ssize_t wr = 0;
55968
55969 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55970@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55971 return 1;
55972 }
55973
55974+#ifdef CONFIG_GRKERNSEC_HIDESYM
55975+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
55976+#endif
55977+
55978 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55979 enum autofs_notify notify)
55980 {
55981@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55982
55983 /* If this is a direct mount request create a dummy name */
55984 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
55985+#ifdef CONFIG_GRKERNSEC_HIDESYM
55986+ /* this name does get written to userland via autofs4_write() */
55987+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
55988+#else
55989 qstr.len = sprintf(name, "%p", dentry);
55990+#endif
55991 else {
55992 qstr.len = autofs4_getpath(sbi, dentry, &name);
55993 if (!qstr.len) {
55994diff --git a/fs/befs/endian.h b/fs/befs/endian.h
55995index 2722387..56059b5 100644
55996--- a/fs/befs/endian.h
55997+++ b/fs/befs/endian.h
55998@@ -11,7 +11,7 @@
55999
56000 #include <asm/byteorder.h>
56001
56002-static inline u64
56003+static inline u64 __intentional_overflow(-1)
56004 fs64_to_cpu(const struct super_block *sb, fs64 n)
56005 {
56006 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56007@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56008 return (__force fs64)cpu_to_be64(n);
56009 }
56010
56011-static inline u32
56012+static inline u32 __intentional_overflow(-1)
56013 fs32_to_cpu(const struct super_block *sb, fs32 n)
56014 {
56015 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56016@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56017 return (__force fs32)cpu_to_be32(n);
56018 }
56019
56020-static inline u16
56021+static inline u16 __intentional_overflow(-1)
56022 fs16_to_cpu(const struct super_block *sb, fs16 n)
56023 {
56024 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56025diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56026index ca0ba15..0fa3257 100644
56027--- a/fs/binfmt_aout.c
56028+++ b/fs/binfmt_aout.c
56029@@ -16,6 +16,7 @@
56030 #include <linux/string.h>
56031 #include <linux/fs.h>
56032 #include <linux/file.h>
56033+#include <linux/security.h>
56034 #include <linux/stat.h>
56035 #include <linux/fcntl.h>
56036 #include <linux/ptrace.h>
56037@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56038 #endif
56039 # define START_STACK(u) ((void __user *)u.start_stack)
56040
56041+ memset(&dump, 0, sizeof(dump));
56042+
56043 fs = get_fs();
56044 set_fs(KERNEL_DS);
56045 has_dumped = 1;
56046@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56047
56048 /* If the size of the dump file exceeds the rlimit, then see what would happen
56049 if we wrote the stack, but not the data area. */
56050+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56051 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56052 dump.u_dsize = 0;
56053
56054 /* Make sure we have enough room to write the stack and data areas. */
56055+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56056 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56057 dump.u_ssize = 0;
56058
56059@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56060 rlim = rlimit(RLIMIT_DATA);
56061 if (rlim >= RLIM_INFINITY)
56062 rlim = ~0;
56063+
56064+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56065 if (ex.a_data + ex.a_bss > rlim)
56066 return -ENOMEM;
56067
56068@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56069
56070 install_exec_creds(bprm);
56071
56072+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56073+ current->mm->pax_flags = 0UL;
56074+#endif
56075+
56076+#ifdef CONFIG_PAX_PAGEEXEC
56077+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56078+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56079+
56080+#ifdef CONFIG_PAX_EMUTRAMP
56081+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56082+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56083+#endif
56084+
56085+#ifdef CONFIG_PAX_MPROTECT
56086+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56087+ current->mm->pax_flags |= MF_PAX_MPROTECT;
56088+#endif
56089+
56090+ }
56091+#endif
56092+
56093 if (N_MAGIC(ex) == OMAGIC) {
56094 unsigned long text_addr, map_size;
56095 loff_t pos;
56096@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56097 }
56098
56099 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56100- PROT_READ | PROT_WRITE | PROT_EXEC,
56101+ PROT_READ | PROT_WRITE,
56102 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56103 fd_offset + ex.a_text);
56104 if (error != N_DATADDR(ex)) {
56105diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56106index aa3cb62..bc53934 100644
56107--- a/fs/binfmt_elf.c
56108+++ b/fs/binfmt_elf.c
56109@@ -34,6 +34,7 @@
56110 #include <linux/utsname.h>
56111 #include <linux/coredump.h>
56112 #include <linux/sched.h>
56113+#include <linux/xattr.h>
56114 #include <asm/uaccess.h>
56115 #include <asm/param.h>
56116 #include <asm/page.h>
56117@@ -47,7 +48,7 @@
56118
56119 static int load_elf_binary(struct linux_binprm *bprm);
56120 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56121- int, int, unsigned long);
56122+ int, int, unsigned long) __intentional_overflow(-1);
56123
56124 #ifdef CONFIG_USELIB
56125 static int load_elf_library(struct file *);
56126@@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56127 #define elf_core_dump NULL
56128 #endif
56129
56130+#ifdef CONFIG_PAX_MPROTECT
56131+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56132+#endif
56133+
56134+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56135+static void elf_handle_mmap(struct file *file);
56136+#endif
56137+
56138 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56139 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56140 #else
56141@@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
56142 .load_binary = load_elf_binary,
56143 .load_shlib = load_elf_library,
56144 .core_dump = elf_core_dump,
56145+
56146+#ifdef CONFIG_PAX_MPROTECT
56147+ .handle_mprotect= elf_handle_mprotect,
56148+#endif
56149+
56150+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56151+ .handle_mmap = elf_handle_mmap,
56152+#endif
56153+
56154 .min_coredump = ELF_EXEC_PAGESIZE,
56155 };
56156
56157@@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
56158
56159 static int set_brk(unsigned long start, unsigned long end)
56160 {
56161+ unsigned long e = end;
56162+
56163 start = ELF_PAGEALIGN(start);
56164 end = ELF_PAGEALIGN(end);
56165 if (end > start) {
56166@@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
56167 if (BAD_ADDR(addr))
56168 return addr;
56169 }
56170- current->mm->start_brk = current->mm->brk = end;
56171+ current->mm->start_brk = current->mm->brk = e;
56172 return 0;
56173 }
56174
56175@@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56176 elf_addr_t __user *u_rand_bytes;
56177 const char *k_platform = ELF_PLATFORM;
56178 const char *k_base_platform = ELF_BASE_PLATFORM;
56179- unsigned char k_rand_bytes[16];
56180+ u32 k_rand_bytes[4];
56181 int items;
56182 elf_addr_t *elf_info;
56183 int ei_index = 0;
56184 const struct cred *cred = current_cred();
56185 struct vm_area_struct *vma;
56186+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56187
56188 /*
56189 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56190@@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56191 * Generate 16 random bytes for userspace PRNG seeding.
56192 */
56193 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56194- u_rand_bytes = (elf_addr_t __user *)
56195- STACK_ALLOC(p, sizeof(k_rand_bytes));
56196+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56197+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56198+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56199+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56200+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56201+ u_rand_bytes = (elf_addr_t __user *) p;
56202 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56203 return -EFAULT;
56204
56205@@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56206 return -EFAULT;
56207 current->mm->env_end = p;
56208
56209+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56210+
56211 /* Put the elf_info on the stack in the right place. */
56212 sp = (elf_addr_t __user *)envp + 1;
56213- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56214+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56215 return -EFAULT;
56216 return 0;
56217 }
56218@@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56219 an ELF header */
56220
56221 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56222- struct file *interpreter, unsigned long *interp_map_addr,
56223- unsigned long no_base)
56224+ struct file *interpreter, unsigned long no_base)
56225 {
56226 struct elf_phdr *elf_phdata;
56227 struct elf_phdr *eppnt;
56228- unsigned long load_addr = 0;
56229+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56230 int load_addr_set = 0;
56231 unsigned long last_bss = 0, elf_bss = 0;
56232- unsigned long error = ~0UL;
56233+ unsigned long error = -EINVAL;
56234 unsigned long total_size;
56235 int retval, i, size;
56236
56237@@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56238 goto out_close;
56239 }
56240
56241+#ifdef CONFIG_PAX_SEGMEXEC
56242+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56243+ pax_task_size = SEGMEXEC_TASK_SIZE;
56244+#endif
56245+
56246 eppnt = elf_phdata;
56247 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56248 if (eppnt->p_type == PT_LOAD) {
56249@@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56250 map_addr = elf_map(interpreter, load_addr + vaddr,
56251 eppnt, elf_prot, elf_type, total_size);
56252 total_size = 0;
56253- if (!*interp_map_addr)
56254- *interp_map_addr = map_addr;
56255 error = map_addr;
56256 if (BAD_ADDR(map_addr))
56257 goto out_close;
56258@@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56259 k = load_addr + eppnt->p_vaddr;
56260 if (BAD_ADDR(k) ||
56261 eppnt->p_filesz > eppnt->p_memsz ||
56262- eppnt->p_memsz > TASK_SIZE ||
56263- TASK_SIZE - eppnt->p_memsz < k) {
56264+ eppnt->p_memsz > pax_task_size ||
56265+ pax_task_size - eppnt->p_memsz < k) {
56266 error = -ENOMEM;
56267 goto out_close;
56268 }
56269@@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56270 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56271
56272 /* Map the last of the bss segment */
56273- error = vm_brk(elf_bss, last_bss - elf_bss);
56274- if (BAD_ADDR(error))
56275- goto out_close;
56276+ if (last_bss > elf_bss) {
56277+ error = vm_brk(elf_bss, last_bss - elf_bss);
56278+ if (BAD_ADDR(error))
56279+ goto out_close;
56280+ }
56281 }
56282
56283 error = load_addr;
56284@@ -543,6 +574,336 @@ out:
56285 return error;
56286 }
56287
56288+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56289+#ifdef CONFIG_PAX_SOFTMODE
56290+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56291+{
56292+ unsigned long pax_flags = 0UL;
56293+
56294+#ifdef CONFIG_PAX_PAGEEXEC
56295+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56296+ pax_flags |= MF_PAX_PAGEEXEC;
56297+#endif
56298+
56299+#ifdef CONFIG_PAX_SEGMEXEC
56300+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56301+ pax_flags |= MF_PAX_SEGMEXEC;
56302+#endif
56303+
56304+#ifdef CONFIG_PAX_EMUTRAMP
56305+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56306+ pax_flags |= MF_PAX_EMUTRAMP;
56307+#endif
56308+
56309+#ifdef CONFIG_PAX_MPROTECT
56310+ if (elf_phdata->p_flags & PF_MPROTECT)
56311+ pax_flags |= MF_PAX_MPROTECT;
56312+#endif
56313+
56314+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56315+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56316+ pax_flags |= MF_PAX_RANDMMAP;
56317+#endif
56318+
56319+ return pax_flags;
56320+}
56321+#endif
56322+
56323+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56324+{
56325+ unsigned long pax_flags = 0UL;
56326+
56327+#ifdef CONFIG_PAX_PAGEEXEC
56328+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56329+ pax_flags |= MF_PAX_PAGEEXEC;
56330+#endif
56331+
56332+#ifdef CONFIG_PAX_SEGMEXEC
56333+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56334+ pax_flags |= MF_PAX_SEGMEXEC;
56335+#endif
56336+
56337+#ifdef CONFIG_PAX_EMUTRAMP
56338+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56339+ pax_flags |= MF_PAX_EMUTRAMP;
56340+#endif
56341+
56342+#ifdef CONFIG_PAX_MPROTECT
56343+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56344+ pax_flags |= MF_PAX_MPROTECT;
56345+#endif
56346+
56347+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56348+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56349+ pax_flags |= MF_PAX_RANDMMAP;
56350+#endif
56351+
56352+ return pax_flags;
56353+}
56354+#endif
56355+
56356+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56357+#ifdef CONFIG_PAX_SOFTMODE
56358+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56359+{
56360+ unsigned long pax_flags = 0UL;
56361+
56362+#ifdef CONFIG_PAX_PAGEEXEC
56363+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56364+ pax_flags |= MF_PAX_PAGEEXEC;
56365+#endif
56366+
56367+#ifdef CONFIG_PAX_SEGMEXEC
56368+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56369+ pax_flags |= MF_PAX_SEGMEXEC;
56370+#endif
56371+
56372+#ifdef CONFIG_PAX_EMUTRAMP
56373+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56374+ pax_flags |= MF_PAX_EMUTRAMP;
56375+#endif
56376+
56377+#ifdef CONFIG_PAX_MPROTECT
56378+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56379+ pax_flags |= MF_PAX_MPROTECT;
56380+#endif
56381+
56382+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56383+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56384+ pax_flags |= MF_PAX_RANDMMAP;
56385+#endif
56386+
56387+ return pax_flags;
56388+}
56389+#endif
56390+
56391+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56392+{
56393+ unsigned long pax_flags = 0UL;
56394+
56395+#ifdef CONFIG_PAX_PAGEEXEC
56396+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56397+ pax_flags |= MF_PAX_PAGEEXEC;
56398+#endif
56399+
56400+#ifdef CONFIG_PAX_SEGMEXEC
56401+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56402+ pax_flags |= MF_PAX_SEGMEXEC;
56403+#endif
56404+
56405+#ifdef CONFIG_PAX_EMUTRAMP
56406+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56407+ pax_flags |= MF_PAX_EMUTRAMP;
56408+#endif
56409+
56410+#ifdef CONFIG_PAX_MPROTECT
56411+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56412+ pax_flags |= MF_PAX_MPROTECT;
56413+#endif
56414+
56415+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56416+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56417+ pax_flags |= MF_PAX_RANDMMAP;
56418+#endif
56419+
56420+ return pax_flags;
56421+}
56422+#endif
56423+
56424+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56425+static unsigned long pax_parse_defaults(void)
56426+{
56427+ unsigned long pax_flags = 0UL;
56428+
56429+#ifdef CONFIG_PAX_SOFTMODE
56430+ if (pax_softmode)
56431+ return pax_flags;
56432+#endif
56433+
56434+#ifdef CONFIG_PAX_PAGEEXEC
56435+ pax_flags |= MF_PAX_PAGEEXEC;
56436+#endif
56437+
56438+#ifdef CONFIG_PAX_SEGMEXEC
56439+ pax_flags |= MF_PAX_SEGMEXEC;
56440+#endif
56441+
56442+#ifdef CONFIG_PAX_MPROTECT
56443+ pax_flags |= MF_PAX_MPROTECT;
56444+#endif
56445+
56446+#ifdef CONFIG_PAX_RANDMMAP
56447+ if (randomize_va_space)
56448+ pax_flags |= MF_PAX_RANDMMAP;
56449+#endif
56450+
56451+ return pax_flags;
56452+}
56453+
56454+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56455+{
56456+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56457+
56458+#ifdef CONFIG_PAX_EI_PAX
56459+
56460+#ifdef CONFIG_PAX_SOFTMODE
56461+ if (pax_softmode)
56462+ return pax_flags;
56463+#endif
56464+
56465+ pax_flags = 0UL;
56466+
56467+#ifdef CONFIG_PAX_PAGEEXEC
56468+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56469+ pax_flags |= MF_PAX_PAGEEXEC;
56470+#endif
56471+
56472+#ifdef CONFIG_PAX_SEGMEXEC
56473+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56474+ pax_flags |= MF_PAX_SEGMEXEC;
56475+#endif
56476+
56477+#ifdef CONFIG_PAX_EMUTRAMP
56478+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56479+ pax_flags |= MF_PAX_EMUTRAMP;
56480+#endif
56481+
56482+#ifdef CONFIG_PAX_MPROTECT
56483+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56484+ pax_flags |= MF_PAX_MPROTECT;
56485+#endif
56486+
56487+#ifdef CONFIG_PAX_ASLR
56488+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56489+ pax_flags |= MF_PAX_RANDMMAP;
56490+#endif
56491+
56492+#endif
56493+
56494+ return pax_flags;
56495+
56496+}
56497+
56498+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56499+{
56500+
56501+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56502+ unsigned long i;
56503+
56504+ for (i = 0UL; i < elf_ex->e_phnum; i++)
56505+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56506+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56507+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56508+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56509+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56510+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56511+ return PAX_PARSE_FLAGS_FALLBACK;
56512+
56513+#ifdef CONFIG_PAX_SOFTMODE
56514+ if (pax_softmode)
56515+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56516+ else
56517+#endif
56518+
56519+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56520+ break;
56521+ }
56522+#endif
56523+
56524+ return PAX_PARSE_FLAGS_FALLBACK;
56525+}
56526+
56527+static unsigned long pax_parse_xattr_pax(struct file * const file)
56528+{
56529+
56530+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56531+ ssize_t xattr_size, i;
56532+ unsigned char xattr_value[sizeof("pemrs") - 1];
56533+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56534+
56535+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56536+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56537+ return PAX_PARSE_FLAGS_FALLBACK;
56538+
56539+ for (i = 0; i < xattr_size; i++)
56540+ switch (xattr_value[i]) {
56541+ default:
56542+ return PAX_PARSE_FLAGS_FALLBACK;
56543+
56544+#define parse_flag(option1, option2, flag) \
56545+ case option1: \
56546+ if (pax_flags_hardmode & MF_PAX_##flag) \
56547+ return PAX_PARSE_FLAGS_FALLBACK;\
56548+ pax_flags_hardmode |= MF_PAX_##flag; \
56549+ break; \
56550+ case option2: \
56551+ if (pax_flags_softmode & MF_PAX_##flag) \
56552+ return PAX_PARSE_FLAGS_FALLBACK;\
56553+ pax_flags_softmode |= MF_PAX_##flag; \
56554+ break;
56555+
56556+ parse_flag('p', 'P', PAGEEXEC);
56557+ parse_flag('e', 'E', EMUTRAMP);
56558+ parse_flag('m', 'M', MPROTECT);
56559+ parse_flag('r', 'R', RANDMMAP);
56560+ parse_flag('s', 'S', SEGMEXEC);
56561+
56562+#undef parse_flag
56563+ }
56564+
56565+ if (pax_flags_hardmode & pax_flags_softmode)
56566+ return PAX_PARSE_FLAGS_FALLBACK;
56567+
56568+#ifdef CONFIG_PAX_SOFTMODE
56569+ if (pax_softmode)
56570+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56571+ else
56572+#endif
56573+
56574+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56575+#else
56576+ return PAX_PARSE_FLAGS_FALLBACK;
56577+#endif
56578+
56579+}
56580+
56581+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56582+{
56583+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56584+
56585+ pax_flags = pax_parse_defaults();
56586+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
56587+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56588+ xattr_pax_flags = pax_parse_xattr_pax(file);
56589+
56590+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56591+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56592+ pt_pax_flags != xattr_pax_flags)
56593+ return -EINVAL;
56594+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56595+ pax_flags = xattr_pax_flags;
56596+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56597+ pax_flags = pt_pax_flags;
56598+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56599+ pax_flags = ei_pax_flags;
56600+
56601+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56602+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56603+ if ((__supported_pte_mask & _PAGE_NX))
56604+ pax_flags &= ~MF_PAX_SEGMEXEC;
56605+ else
56606+ pax_flags &= ~MF_PAX_PAGEEXEC;
56607+ }
56608+#endif
56609+
56610+ if (0 > pax_check_flags(&pax_flags))
56611+ return -EINVAL;
56612+
56613+ current->mm->pax_flags = pax_flags;
56614+ return 0;
56615+}
56616+#endif
56617+
56618 /*
56619 * These are the functions used to load ELF style executables and shared
56620 * libraries. There is no binary dependent code anywhere else.
56621@@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56622 {
56623 unsigned int random_variable = 0;
56624
56625+#ifdef CONFIG_PAX_RANDUSTACK
56626+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56627+ return stack_top - current->mm->delta_stack;
56628+#endif
56629+
56630 if ((current->flags & PF_RANDOMIZE) &&
56631 !(current->personality & ADDR_NO_RANDOMIZE)) {
56632 random_variable = get_random_int() & STACK_RND_MASK;
56633@@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56634 unsigned long load_addr = 0, load_bias = 0;
56635 int load_addr_set = 0;
56636 char * elf_interpreter = NULL;
56637- unsigned long error;
56638+ unsigned long error = 0;
56639 struct elf_phdr *elf_ppnt, *elf_phdata;
56640 unsigned long elf_bss, elf_brk;
56641 int retval, i;
56642@@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56643 struct elfhdr elf_ex;
56644 struct elfhdr interp_elf_ex;
56645 } *loc;
56646+ unsigned long pax_task_size;
56647
56648 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56649 if (!loc) {
56650@@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
56651 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56652 may depend on the personality. */
56653 SET_PERSONALITY(loc->elf_ex);
56654+
56655+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56656+ current->mm->pax_flags = 0UL;
56657+#endif
56658+
56659+#ifdef CONFIG_PAX_DLRESOLVE
56660+ current->mm->call_dl_resolve = 0UL;
56661+#endif
56662+
56663+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56664+ current->mm->call_syscall = 0UL;
56665+#endif
56666+
56667+#ifdef CONFIG_PAX_ASLR
56668+ current->mm->delta_mmap = 0UL;
56669+ current->mm->delta_stack = 0UL;
56670+#endif
56671+
56672+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56673+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56674+ send_sig(SIGKILL, current, 0);
56675+ goto out_free_dentry;
56676+ }
56677+#endif
56678+
56679+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56680+ pax_set_initial_flags(bprm);
56681+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56682+ if (pax_set_initial_flags_func)
56683+ (pax_set_initial_flags_func)(bprm);
56684+#endif
56685+
56686+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56687+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56688+ current->mm->context.user_cs_limit = PAGE_SIZE;
56689+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56690+ }
56691+#endif
56692+
56693+#ifdef CONFIG_PAX_SEGMEXEC
56694+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56695+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56696+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56697+ pax_task_size = SEGMEXEC_TASK_SIZE;
56698+ current->mm->def_flags |= VM_NOHUGEPAGE;
56699+ } else
56700+#endif
56701+
56702+ pax_task_size = TASK_SIZE;
56703+
56704+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56705+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56706+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56707+ put_cpu();
56708+ }
56709+#endif
56710+
56711+#ifdef CONFIG_PAX_ASLR
56712+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56713+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56714+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56715+ }
56716+#endif
56717+
56718+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56719+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56720+ executable_stack = EXSTACK_DISABLE_X;
56721+ current->personality &= ~READ_IMPLIES_EXEC;
56722+ } else
56723+#endif
56724+
56725 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56726 current->personality |= READ_IMPLIES_EXEC;
56727
56728@@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56729 #else
56730 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56731 #endif
56732+
56733+#ifdef CONFIG_PAX_RANDMMAP
56734+ /* PaX: randomize base address at the default exe base if requested */
56735+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56736+#ifdef CONFIG_SPARC64
56737+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56738+#else
56739+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56740+#endif
56741+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56742+ elf_flags |= MAP_FIXED;
56743+ }
56744+#endif
56745+
56746 }
56747
56748 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56749@@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56750 * allowed task size. Note that p_filesz must always be
56751 * <= p_memsz so it is only necessary to check p_memsz.
56752 */
56753- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56754- elf_ppnt->p_memsz > TASK_SIZE ||
56755- TASK_SIZE - elf_ppnt->p_memsz < k) {
56756+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56757+ elf_ppnt->p_memsz > pax_task_size ||
56758+ pax_task_size - elf_ppnt->p_memsz < k) {
56759 /* set_brk can never work. Avoid overflows. */
56760 send_sig(SIGKILL, current, 0);
56761 retval = -EINVAL;
56762@@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56763 goto out_free_dentry;
56764 }
56765 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56766- send_sig(SIGSEGV, current, 0);
56767- retval = -EFAULT; /* Nobody gets to see this, but.. */
56768- goto out_free_dentry;
56769+ /*
56770+ * This bss-zeroing can fail if the ELF
56771+ * file specifies odd protections. So
56772+ * we don't check the return value
56773+ */
56774 }
56775
56776+#ifdef CONFIG_PAX_RANDMMAP
56777+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56778+ unsigned long start, size, flags;
56779+ vm_flags_t vm_flags;
56780+
56781+ start = ELF_PAGEALIGN(elf_brk);
56782+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56783+ flags = MAP_FIXED | MAP_PRIVATE;
56784+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56785+
56786+ down_write(&current->mm->mmap_sem);
56787+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56788+ retval = -ENOMEM;
56789+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56790+// if (current->personality & ADDR_NO_RANDOMIZE)
56791+// vm_flags |= VM_READ | VM_MAYREAD;
56792+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56793+ retval = IS_ERR_VALUE(start) ? start : 0;
56794+ }
56795+ up_write(&current->mm->mmap_sem);
56796+ if (retval == 0)
56797+ retval = set_brk(start + size, start + size + PAGE_SIZE);
56798+ if (retval < 0) {
56799+ send_sig(SIGKILL, current, 0);
56800+ goto out_free_dentry;
56801+ }
56802+ }
56803+#endif
56804+
56805 if (elf_interpreter) {
56806- unsigned long interp_map_addr = 0;
56807-
56808 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56809 interpreter,
56810- &interp_map_addr,
56811 load_bias);
56812 if (!IS_ERR((void *)elf_entry)) {
56813 /*
56814@@ -1122,7 +1602,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56815 * Decide what to dump of a segment, part, all or none.
56816 */
56817 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56818- unsigned long mm_flags)
56819+ unsigned long mm_flags, long signr)
56820 {
56821 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56822
56823@@ -1160,7 +1640,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56824 if (vma->vm_file == NULL)
56825 return 0;
56826
56827- if (FILTER(MAPPED_PRIVATE))
56828+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56829 goto whole;
56830
56831 /*
56832@@ -1367,9 +1847,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56833 {
56834 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56835 int i = 0;
56836- do
56837+ do {
56838 i += 2;
56839- while (auxv[i - 2] != AT_NULL);
56840+ } while (auxv[i - 2] != AT_NULL);
56841 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56842 }
56843
56844@@ -1378,7 +1858,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56845 {
56846 mm_segment_t old_fs = get_fs();
56847 set_fs(KERNEL_DS);
56848- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56849+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56850 set_fs(old_fs);
56851 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56852 }
56853@@ -2002,14 +2482,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56854 }
56855
56856 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56857- unsigned long mm_flags)
56858+ struct coredump_params *cprm)
56859 {
56860 struct vm_area_struct *vma;
56861 size_t size = 0;
56862
56863 for (vma = first_vma(current, gate_vma); vma != NULL;
56864 vma = next_vma(vma, gate_vma))
56865- size += vma_dump_size(vma, mm_flags);
56866+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56867 return size;
56868 }
56869
56870@@ -2100,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56871
56872 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56873
56874- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56875+ offset += elf_core_vma_data_size(gate_vma, cprm);
56876 offset += elf_core_extra_data_size();
56877 e_shoff = offset;
56878
56879@@ -2128,7 +2608,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56880 phdr.p_offset = offset;
56881 phdr.p_vaddr = vma->vm_start;
56882 phdr.p_paddr = 0;
56883- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56884+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56885 phdr.p_memsz = vma->vm_end - vma->vm_start;
56886 offset += phdr.p_filesz;
56887 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
56888@@ -2161,7 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56889 unsigned long addr;
56890 unsigned long end;
56891
56892- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
56893+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56894
56895 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
56896 struct page *page;
56897@@ -2202,6 +2682,167 @@ out:
56898
56899 #endif /* CONFIG_ELF_CORE */
56900
56901+#ifdef CONFIG_PAX_MPROTECT
56902+/* PaX: non-PIC ELF libraries need relocations on their executable segments
56903+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
56904+ * we'll remove VM_MAYWRITE for good on RELRO segments.
56905+ *
56906+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
56907+ * basis because we want to allow the common case and not the special ones.
56908+ */
56909+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
56910+{
56911+ struct elfhdr elf_h;
56912+ struct elf_phdr elf_p;
56913+ unsigned long i;
56914+ unsigned long oldflags;
56915+ bool is_textrel_rw, is_textrel_rx, is_relro;
56916+
56917+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
56918+ return;
56919+
56920+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
56921+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
56922+
56923+#ifdef CONFIG_PAX_ELFRELOCS
56924+ /* possible TEXTREL */
56925+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56926+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56927+#else
56928+ is_textrel_rw = false;
56929+ is_textrel_rx = false;
56930+#endif
56931+
56932+ /* possible RELRO */
56933+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56934+
56935+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56936+ return;
56937+
56938+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56939+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56940+
56941+#ifdef CONFIG_PAX_ETEXECRELOCS
56942+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56943+#else
56944+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56945+#endif
56946+
56947+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56948+ !elf_check_arch(&elf_h) ||
56949+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56950+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56951+ return;
56952+
56953+ for (i = 0UL; i < elf_h.e_phnum; i++) {
56954+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56955+ return;
56956+ switch (elf_p.p_type) {
56957+ case PT_DYNAMIC:
56958+ if (!is_textrel_rw && !is_textrel_rx)
56959+ continue;
56960+ i = 0UL;
56961+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
56962+ elf_dyn dyn;
56963+
56964+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
56965+ break;
56966+ if (dyn.d_tag == DT_NULL)
56967+ break;
56968+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56969+ gr_log_textrel(vma);
56970+ if (is_textrel_rw)
56971+ vma->vm_flags |= VM_MAYWRITE;
56972+ else
56973+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56974+ vma->vm_flags &= ~VM_MAYWRITE;
56975+ break;
56976+ }
56977+ i++;
56978+ }
56979+ is_textrel_rw = false;
56980+ is_textrel_rx = false;
56981+ continue;
56982+
56983+ case PT_GNU_RELRO:
56984+ if (!is_relro)
56985+ continue;
56986+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
56987+ vma->vm_flags &= ~VM_MAYWRITE;
56988+ is_relro = false;
56989+ continue;
56990+
56991+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56992+ case PT_PAX_FLAGS: {
56993+ const char *msg_mprotect = "", *msg_emutramp = "";
56994+ char *buffer_lib, *buffer_exe;
56995+
56996+ if (elf_p.p_flags & PF_NOMPROTECT)
56997+ msg_mprotect = "MPROTECT disabled";
56998+
56999+#ifdef CONFIG_PAX_EMUTRAMP
57000+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57001+ msg_emutramp = "EMUTRAMP enabled";
57002+#endif
57003+
57004+ if (!msg_mprotect[0] && !msg_emutramp[0])
57005+ continue;
57006+
57007+ if (!printk_ratelimit())
57008+ continue;
57009+
57010+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57011+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57012+ if (buffer_lib && buffer_exe) {
57013+ char *path_lib, *path_exe;
57014+
57015+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57016+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57017+
57018+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57019+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57020+
57021+ }
57022+ free_page((unsigned long)buffer_exe);
57023+ free_page((unsigned long)buffer_lib);
57024+ continue;
57025+ }
57026+#endif
57027+
57028+ }
57029+ }
57030+}
57031+#endif
57032+
57033+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57034+
57035+extern int grsec_enable_log_rwxmaps;
57036+
57037+static void elf_handle_mmap(struct file *file)
57038+{
57039+ struct elfhdr elf_h;
57040+ struct elf_phdr elf_p;
57041+ unsigned long i;
57042+
57043+ if (!grsec_enable_log_rwxmaps)
57044+ return;
57045+
57046+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57047+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57048+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57049+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57050+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57051+ return;
57052+
57053+ for (i = 0UL; i < elf_h.e_phnum; i++) {
57054+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57055+ return;
57056+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57057+ gr_log_ptgnustack(file);
57058+ }
57059+}
57060+#endif
57061+
57062 static int __init init_elf_binfmt(void)
57063 {
57064 register_binfmt(&elf_format);
57065diff --git a/fs/bio.c b/fs/bio.c
57066index 6f0362b..26a7496 100644
57067--- a/fs/bio.c
57068+++ b/fs/bio.c
57069@@ -1144,7 +1144,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57070 /*
57071 * Overflow, abort
57072 */
57073- if (end < start)
57074+ if (end < start || end - start > INT_MAX - nr_pages)
57075 return ERR_PTR(-EINVAL);
57076
57077 nr_pages += end - start;
57078@@ -1278,7 +1278,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57079 /*
57080 * Overflow, abort
57081 */
57082- if (end < start)
57083+ if (end < start || end - start > INT_MAX - nr_pages)
57084 return ERR_PTR(-EINVAL);
57085
57086 nr_pages += end - start;
57087@@ -1540,7 +1540,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57088 const int read = bio_data_dir(bio) == READ;
57089 struct bio_map_data *bmd = bio->bi_private;
57090 int i;
57091- char *p = bmd->sgvecs[0].iov_base;
57092+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57093
57094 bio_for_each_segment_all(bvec, bio, i) {
57095 char *addr = page_address(bvec->bv_page);
57096diff --git a/fs/block_dev.c b/fs/block_dev.c
57097index 552a8d1..d51ccf3 100644
57098--- a/fs/block_dev.c
57099+++ b/fs/block_dev.c
57100@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57101 else if (bdev->bd_contains == bdev)
57102 return true; /* is a whole device which isn't held */
57103
57104- else if (whole->bd_holder == bd_may_claim)
57105+ else if (whole->bd_holder == (void *)bd_may_claim)
57106 return true; /* is a partition of a device that is being partitioned */
57107 else if (whole->bd_holder != NULL)
57108 return false; /* is a partition of a held device */
57109diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57110index 1bcfcdb..e942132 100644
57111--- a/fs/btrfs/ctree.c
57112+++ b/fs/btrfs/ctree.c
57113@@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57114 free_extent_buffer(buf);
57115 add_root_to_dirty_list(root);
57116 } else {
57117- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57118- parent_start = parent->start;
57119- else
57120+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57121+ if (parent)
57122+ parent_start = parent->start;
57123+ else
57124+ parent_start = 0;
57125+ } else
57126 parent_start = 0;
57127
57128 WARN_ON(trans->transid != btrfs_header_generation(parent));
57129diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57130index 33e561a..16df7ae 100644
57131--- a/fs/btrfs/delayed-inode.c
57132+++ b/fs/btrfs/delayed-inode.c
57133@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57134
57135 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57136 {
57137- int seq = atomic_inc_return(&delayed_root->items_seq);
57138+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57139 if ((atomic_dec_return(&delayed_root->items) <
57140 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57141 waitqueue_active(&delayed_root->wait))
57142@@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57143
57144 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57145 {
57146- int val = atomic_read(&delayed_root->items_seq);
57147+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57148
57149 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57150 return 1;
57151@@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57152 int seq;
57153 int ret;
57154
57155- seq = atomic_read(&delayed_root->items_seq);
57156+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57157
57158 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57159 if (ret)
57160diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57161index f70119f..ab5894d 100644
57162--- a/fs/btrfs/delayed-inode.h
57163+++ b/fs/btrfs/delayed-inode.h
57164@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57165 */
57166 struct list_head prepare_list;
57167 atomic_t items; /* for delayed items */
57168- atomic_t items_seq; /* for delayed items */
57169+ atomic_unchecked_t items_seq; /* for delayed items */
57170 int nodes; /* for delayed nodes */
57171 wait_queue_head_t wait;
57172 };
57173@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57174 struct btrfs_delayed_root *delayed_root)
57175 {
57176 atomic_set(&delayed_root->items, 0);
57177- atomic_set(&delayed_root->items_seq, 0);
57178+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57179 delayed_root->nodes = 0;
57180 spin_lock_init(&delayed_root->lock);
57181 init_waitqueue_head(&delayed_root->wait);
57182diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57183index 2f6d7b1..f186382 100644
57184--- a/fs/btrfs/ioctl.c
57185+++ b/fs/btrfs/ioctl.c
57186@@ -3575,9 +3575,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57187 for (i = 0; i < num_types; i++) {
57188 struct btrfs_space_info *tmp;
57189
57190+ /* Don't copy in more than we allocated */
57191 if (!slot_count)
57192 break;
57193
57194+ slot_count--;
57195+
57196 info = NULL;
57197 rcu_read_lock();
57198 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57199@@ -3599,10 +3602,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57200 memcpy(dest, &space, sizeof(space));
57201 dest++;
57202 space_args.total_spaces++;
57203- slot_count--;
57204 }
57205- if (!slot_count)
57206- break;
57207 }
57208 up_read(&info->groups_sem);
57209 }
57210diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57211index 9601d25..2896d6c 100644
57212--- a/fs/btrfs/super.c
57213+++ b/fs/btrfs/super.c
57214@@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57215 function, line, errstr);
57216 return;
57217 }
57218- ACCESS_ONCE(trans->transaction->aborted) = errno;
57219+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57220 /* Wake up anybody who may be waiting on this transaction */
57221 wake_up(&root->fs_info->transaction_wait);
57222 wake_up(&root->fs_info->transaction_blocked_wait);
57223diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57224index 4825cd2..b2fe768 100644
57225--- a/fs/btrfs/sysfs.c
57226+++ b/fs/btrfs/sysfs.c
57227@@ -438,7 +438,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57228 for (set = 0; set < FEAT_MAX; set++) {
57229 int i;
57230 struct attribute *attrs[2];
57231- struct attribute_group agroup = {
57232+ attribute_group_no_const agroup = {
57233 .name = "features",
57234 .attrs = attrs,
57235 };
57236diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
57237index e2f45fc..b036909 100644
57238--- a/fs/btrfs/tree-log.c
57239+++ b/fs/btrfs/tree-log.c
57240@@ -2533,7 +2533,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57241 blk_finish_plug(&plug);
57242 btrfs_abort_transaction(trans, root, ret);
57243 btrfs_free_logged_extents(log, log_transid);
57244- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57245+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57246 trans->transid;
57247 mutex_unlock(&root->log_mutex);
57248 goto out;
57249@@ -2577,7 +2577,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57250 list_del_init(&root_log_ctx.list);
57251
57252 blk_finish_plug(&plug);
57253- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57254+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57255 trans->transid;
57256 if (ret != -ENOSPC) {
57257 btrfs_abort_transaction(trans, root, ret);
57258@@ -2622,7 +2622,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57259 * now that we've moved on to the tree of log tree roots,
57260 * check the full commit flag again
57261 */
57262- if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
57263+ if (ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) ==
57264 trans->transid) {
57265 blk_finish_plug(&plug);
57266 btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
57267@@ -2637,7 +2637,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57268 EXTENT_DIRTY | EXTENT_NEW);
57269 blk_finish_plug(&plug);
57270 if (ret) {
57271- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57272+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57273 trans->transid;
57274 btrfs_abort_transaction(trans, root, ret);
57275 btrfs_free_logged_extents(log, log_transid);
57276@@ -2667,7 +2667,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57277 */
57278 ret = write_ctree_super(trans, root->fs_info->tree_root, 1);
57279 if (ret) {
57280- ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57281+ ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57282 trans->transid;
57283 btrfs_abort_transaction(trans, root, ret);
57284 goto out_wake_log_root;
57285diff --git a/fs/buffer.c b/fs/buffer.c
57286index 9ddb9fc..7aa2487 100644
57287--- a/fs/buffer.c
57288+++ b/fs/buffer.c
57289@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57290 bh_cachep = kmem_cache_create("buffer_head",
57291 sizeof(struct buffer_head), 0,
57292 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57293- SLAB_MEM_SPREAD),
57294+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57295 NULL);
57296
57297 /*
57298diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57299index 5b99baf..47fffb5 100644
57300--- a/fs/cachefiles/bind.c
57301+++ b/fs/cachefiles/bind.c
57302@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57303 args);
57304
57305 /* start by checking things over */
57306- ASSERT(cache->fstop_percent >= 0 &&
57307- cache->fstop_percent < cache->fcull_percent &&
57308+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57309 cache->fcull_percent < cache->frun_percent &&
57310 cache->frun_percent < 100);
57311
57312- ASSERT(cache->bstop_percent >= 0 &&
57313- cache->bstop_percent < cache->bcull_percent &&
57314+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57315 cache->bcull_percent < cache->brun_percent &&
57316 cache->brun_percent < 100);
57317
57318diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57319index 0a1467b..6a53245 100644
57320--- a/fs/cachefiles/daemon.c
57321+++ b/fs/cachefiles/daemon.c
57322@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57323 if (n > buflen)
57324 return -EMSGSIZE;
57325
57326- if (copy_to_user(_buffer, buffer, n) != 0)
57327+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57328 return -EFAULT;
57329
57330 return n;
57331@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57332 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57333 return -EIO;
57334
57335- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57336+ if (datalen > PAGE_SIZE - 1)
57337 return -EOPNOTSUPP;
57338
57339 /* drag the command string into the kernel so we can parse it */
57340@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57341 if (args[0] != '%' || args[1] != '\0')
57342 return -EINVAL;
57343
57344- if (fstop < 0 || fstop >= cache->fcull_percent)
57345+ if (fstop >= cache->fcull_percent)
57346 return cachefiles_daemon_range_error(cache, args);
57347
57348 cache->fstop_percent = fstop;
57349@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57350 if (args[0] != '%' || args[1] != '\0')
57351 return -EINVAL;
57352
57353- if (bstop < 0 || bstop >= cache->bcull_percent)
57354+ if (bstop >= cache->bcull_percent)
57355 return cachefiles_daemon_range_error(cache, args);
57356
57357 cache->bstop_percent = bstop;
57358diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57359index 5349473..d6c0b93 100644
57360--- a/fs/cachefiles/internal.h
57361+++ b/fs/cachefiles/internal.h
57362@@ -59,7 +59,7 @@ struct cachefiles_cache {
57363 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57364 struct rb_root active_nodes; /* active nodes (can't be culled) */
57365 rwlock_t active_lock; /* lock for active_nodes */
57366- atomic_t gravecounter; /* graveyard uniquifier */
57367+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57368 unsigned frun_percent; /* when to stop culling (% files) */
57369 unsigned fcull_percent; /* when to start culling (% files) */
57370 unsigned fstop_percent; /* when to stop allocating (% files) */
57371@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57372 * proc.c
57373 */
57374 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57375-extern atomic_t cachefiles_lookup_histogram[HZ];
57376-extern atomic_t cachefiles_mkdir_histogram[HZ];
57377-extern atomic_t cachefiles_create_histogram[HZ];
57378+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57379+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57380+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57381
57382 extern int __init cachefiles_proc_init(void);
57383 extern void cachefiles_proc_cleanup(void);
57384 static inline
57385-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57386+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57387 {
57388 unsigned long jif = jiffies - start_jif;
57389 if (jif >= HZ)
57390 jif = HZ - 1;
57391- atomic_inc(&histogram[jif]);
57392+ atomic_inc_unchecked(&histogram[jif]);
57393 }
57394
57395 #else
57396diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57397index c0a6817..ea811166 100644
57398--- a/fs/cachefiles/namei.c
57399+++ b/fs/cachefiles/namei.c
57400@@ -317,7 +317,7 @@ try_again:
57401 /* first step is to make up a grave dentry in the graveyard */
57402 sprintf(nbuffer, "%08x%08x",
57403 (uint32_t) get_seconds(),
57404- (uint32_t) atomic_inc_return(&cache->gravecounter));
57405+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57406
57407 /* do the multiway lock magic */
57408 trap = lock_rename(cache->graveyard, dir);
57409diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57410index eccd339..4c1d995 100644
57411--- a/fs/cachefiles/proc.c
57412+++ b/fs/cachefiles/proc.c
57413@@ -14,9 +14,9 @@
57414 #include <linux/seq_file.h>
57415 #include "internal.h"
57416
57417-atomic_t cachefiles_lookup_histogram[HZ];
57418-atomic_t cachefiles_mkdir_histogram[HZ];
57419-atomic_t cachefiles_create_histogram[HZ];
57420+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57421+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57422+atomic_unchecked_t cachefiles_create_histogram[HZ];
57423
57424 /*
57425 * display the latency histogram
57426@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57427 return 0;
57428 default:
57429 index = (unsigned long) v - 3;
57430- x = atomic_read(&cachefiles_lookup_histogram[index]);
57431- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57432- z = atomic_read(&cachefiles_create_histogram[index]);
57433+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57434+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57435+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57436 if (x == 0 && y == 0 && z == 0)
57437 return 0;
57438
57439diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57440index 4b1fb5c..0d2a699 100644
57441--- a/fs/cachefiles/rdwr.c
57442+++ b/fs/cachefiles/rdwr.c
57443@@ -943,7 +943,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57444 old_fs = get_fs();
57445 set_fs(KERNEL_DS);
57446 ret = file->f_op->write(
57447- file, (const void __user *) data, len, &pos);
57448+ file, (const void __force_user *) data, len, &pos);
57449 set_fs(old_fs);
57450 kunmap(page);
57451 file_end_write(file);
57452diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57453index c29d6ae..a56c4ae 100644
57454--- a/fs/ceph/dir.c
57455+++ b/fs/ceph/dir.c
57456@@ -250,7 +250,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57457 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57458 struct ceph_mds_client *mdsc = fsc->mdsc;
57459 unsigned frag = fpos_frag(ctx->pos);
57460- int off = fpos_off(ctx->pos);
57461+ unsigned int off = fpos_off(ctx->pos);
57462 int err;
57463 u32 ftype;
57464 struct ceph_mds_reply_info_parsed *rinfo;
57465diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57466index 06150fd..192061b 100644
57467--- a/fs/ceph/super.c
57468+++ b/fs/ceph/super.c
57469@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57470 /*
57471 * construct our own bdi so we can control readahead, etc.
57472 */
57473-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57474+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57475
57476 static int ceph_register_bdi(struct super_block *sb,
57477 struct ceph_fs_client *fsc)
57478@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57479 default_backing_dev_info.ra_pages;
57480
57481 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57482- atomic_long_inc_return(&bdi_seq));
57483+ atomic_long_inc_return_unchecked(&bdi_seq));
57484 if (!err)
57485 sb->s_bdi = &fsc->backing_dev_info;
57486 return err;
57487diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57488index f3ac415..3d2420c 100644
57489--- a/fs/cifs/cifs_debug.c
57490+++ b/fs/cifs/cifs_debug.c
57491@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57492
57493 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57494 #ifdef CONFIG_CIFS_STATS2
57495- atomic_set(&totBufAllocCount, 0);
57496- atomic_set(&totSmBufAllocCount, 0);
57497+ atomic_set_unchecked(&totBufAllocCount, 0);
57498+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57499 #endif /* CONFIG_CIFS_STATS2 */
57500 spin_lock(&cifs_tcp_ses_lock);
57501 list_for_each(tmp1, &cifs_tcp_ses_list) {
57502@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57503 tcon = list_entry(tmp3,
57504 struct cifs_tcon,
57505 tcon_list);
57506- atomic_set(&tcon->num_smbs_sent, 0);
57507+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57508 if (server->ops->clear_stats)
57509 server->ops->clear_stats(tcon);
57510 }
57511@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57512 smBufAllocCount.counter, cifs_min_small);
57513 #ifdef CONFIG_CIFS_STATS2
57514 seq_printf(m, "Total Large %d Small %d Allocations\n",
57515- atomic_read(&totBufAllocCount),
57516- atomic_read(&totSmBufAllocCount));
57517+ atomic_read_unchecked(&totBufAllocCount),
57518+ atomic_read_unchecked(&totSmBufAllocCount));
57519 #endif /* CONFIG_CIFS_STATS2 */
57520
57521 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57522@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57523 if (tcon->need_reconnect)
57524 seq_puts(m, "\tDISCONNECTED ");
57525 seq_printf(m, "\nSMBs: %d",
57526- atomic_read(&tcon->num_smbs_sent));
57527+ atomic_read_unchecked(&tcon->num_smbs_sent));
57528 if (server->ops->print_stats)
57529 server->ops->print_stats(m, tcon);
57530 }
57531diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57532index 5be1f997..fa1015a1 100644
57533--- a/fs/cifs/cifsfs.c
57534+++ b/fs/cifs/cifsfs.c
57535@@ -1068,7 +1068,7 @@ cifs_init_request_bufs(void)
57536 */
57537 cifs_req_cachep = kmem_cache_create("cifs_request",
57538 CIFSMaxBufSize + max_hdr_size, 0,
57539- SLAB_HWCACHE_ALIGN, NULL);
57540+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57541 if (cifs_req_cachep == NULL)
57542 return -ENOMEM;
57543
57544@@ -1095,7 +1095,7 @@ cifs_init_request_bufs(void)
57545 efficient to alloc 1 per page off the slab compared to 17K (5page)
57546 alloc of large cifs buffers even when page debugging is on */
57547 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57548- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57549+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57550 NULL);
57551 if (cifs_sm_req_cachep == NULL) {
57552 mempool_destroy(cifs_req_poolp);
57553@@ -1180,8 +1180,8 @@ init_cifs(void)
57554 atomic_set(&bufAllocCount, 0);
57555 atomic_set(&smBufAllocCount, 0);
57556 #ifdef CONFIG_CIFS_STATS2
57557- atomic_set(&totBufAllocCount, 0);
57558- atomic_set(&totSmBufAllocCount, 0);
57559+ atomic_set_unchecked(&totBufAllocCount, 0);
57560+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57561 #endif /* CONFIG_CIFS_STATS2 */
57562
57563 atomic_set(&midCount, 0);
57564diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57565index 30f6e92..e915ba5 100644
57566--- a/fs/cifs/cifsglob.h
57567+++ b/fs/cifs/cifsglob.h
57568@@ -806,35 +806,35 @@ struct cifs_tcon {
57569 __u16 Flags; /* optional support bits */
57570 enum statusEnum tidStatus;
57571 #ifdef CONFIG_CIFS_STATS
57572- atomic_t num_smbs_sent;
57573+ atomic_unchecked_t num_smbs_sent;
57574 union {
57575 struct {
57576- atomic_t num_writes;
57577- atomic_t num_reads;
57578- atomic_t num_flushes;
57579- atomic_t num_oplock_brks;
57580- atomic_t num_opens;
57581- atomic_t num_closes;
57582- atomic_t num_deletes;
57583- atomic_t num_mkdirs;
57584- atomic_t num_posixopens;
57585- atomic_t num_posixmkdirs;
57586- atomic_t num_rmdirs;
57587- atomic_t num_renames;
57588- atomic_t num_t2renames;
57589- atomic_t num_ffirst;
57590- atomic_t num_fnext;
57591- atomic_t num_fclose;
57592- atomic_t num_hardlinks;
57593- atomic_t num_symlinks;
57594- atomic_t num_locks;
57595- atomic_t num_acl_get;
57596- atomic_t num_acl_set;
57597+ atomic_unchecked_t num_writes;
57598+ atomic_unchecked_t num_reads;
57599+ atomic_unchecked_t num_flushes;
57600+ atomic_unchecked_t num_oplock_brks;
57601+ atomic_unchecked_t num_opens;
57602+ atomic_unchecked_t num_closes;
57603+ atomic_unchecked_t num_deletes;
57604+ atomic_unchecked_t num_mkdirs;
57605+ atomic_unchecked_t num_posixopens;
57606+ atomic_unchecked_t num_posixmkdirs;
57607+ atomic_unchecked_t num_rmdirs;
57608+ atomic_unchecked_t num_renames;
57609+ atomic_unchecked_t num_t2renames;
57610+ atomic_unchecked_t num_ffirst;
57611+ atomic_unchecked_t num_fnext;
57612+ atomic_unchecked_t num_fclose;
57613+ atomic_unchecked_t num_hardlinks;
57614+ atomic_unchecked_t num_symlinks;
57615+ atomic_unchecked_t num_locks;
57616+ atomic_unchecked_t num_acl_get;
57617+ atomic_unchecked_t num_acl_set;
57618 } cifs_stats;
57619 #ifdef CONFIG_CIFS_SMB2
57620 struct {
57621- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57622- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57623+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57624+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57625 } smb2_stats;
57626 #endif /* CONFIG_CIFS_SMB2 */
57627 } stats;
57628@@ -1170,7 +1170,7 @@ convert_delimiter(char *path, char delim)
57629 }
57630
57631 #ifdef CONFIG_CIFS_STATS
57632-#define cifs_stats_inc atomic_inc
57633+#define cifs_stats_inc atomic_inc_unchecked
57634
57635 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57636 unsigned int bytes)
57637@@ -1536,8 +1536,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57638 /* Various Debug counters */
57639 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57640 #ifdef CONFIG_CIFS_STATS2
57641-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57642-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57643+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57644+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57645 #endif
57646 GLOBAL_EXTERN atomic_t smBufAllocCount;
57647 GLOBAL_EXTERN atomic_t midCount;
57648diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57649index 5ed03e0..e9a3a6c 100644
57650--- a/fs/cifs/file.c
57651+++ b/fs/cifs/file.c
57652@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57653 index = mapping->writeback_index; /* Start from prev offset */
57654 end = -1;
57655 } else {
57656- index = wbc->range_start >> PAGE_CACHE_SHIFT;
57657- end = wbc->range_end >> PAGE_CACHE_SHIFT;
57658- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57659+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57660 range_whole = true;
57661+ index = 0;
57662+ end = ULONG_MAX;
57663+ } else {
57664+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
57665+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
57666+ }
57667 scanned = true;
57668 }
57669 retry:
57670diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57671index 3b0c62e..f7d090c 100644
57672--- a/fs/cifs/misc.c
57673+++ b/fs/cifs/misc.c
57674@@ -170,7 +170,7 @@ cifs_buf_get(void)
57675 memset(ret_buf, 0, buf_size + 3);
57676 atomic_inc(&bufAllocCount);
57677 #ifdef CONFIG_CIFS_STATS2
57678- atomic_inc(&totBufAllocCount);
57679+ atomic_inc_unchecked(&totBufAllocCount);
57680 #endif /* CONFIG_CIFS_STATS2 */
57681 }
57682
57683@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57684 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57685 atomic_inc(&smBufAllocCount);
57686 #ifdef CONFIG_CIFS_STATS2
57687- atomic_inc(&totSmBufAllocCount);
57688+ atomic_inc_unchecked(&totSmBufAllocCount);
57689 #endif /* CONFIG_CIFS_STATS2 */
57690
57691 }
57692diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57693index d1fdfa8..94558f8 100644
57694--- a/fs/cifs/smb1ops.c
57695+++ b/fs/cifs/smb1ops.c
57696@@ -626,27 +626,27 @@ static void
57697 cifs_clear_stats(struct cifs_tcon *tcon)
57698 {
57699 #ifdef CONFIG_CIFS_STATS
57700- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57701- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57702- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57703- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57704- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57705- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57706- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57707- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57708- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57709- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57710- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57711- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57712- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57713- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57714- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57715- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57716- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57717- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57718- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57719- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57720- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57721+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57722+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57723+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57724+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57725+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57726+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57727+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57728+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57729+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57730+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57731+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57732+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57733+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57734+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57735+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57736+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57737+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57738+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57739+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57740+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57741+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57742 #endif
57743 }
57744
57745@@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57746 {
57747 #ifdef CONFIG_CIFS_STATS
57748 seq_printf(m, " Oplocks breaks: %d",
57749- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57750+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57751 seq_printf(m, "\nReads: %d Bytes: %llu",
57752- atomic_read(&tcon->stats.cifs_stats.num_reads),
57753+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57754 (long long)(tcon->bytes_read));
57755 seq_printf(m, "\nWrites: %d Bytes: %llu",
57756- atomic_read(&tcon->stats.cifs_stats.num_writes),
57757+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57758 (long long)(tcon->bytes_written));
57759 seq_printf(m, "\nFlushes: %d",
57760- atomic_read(&tcon->stats.cifs_stats.num_flushes));
57761+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57762 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57763- atomic_read(&tcon->stats.cifs_stats.num_locks),
57764- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57765- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57766+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57767+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57768+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57769 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57770- atomic_read(&tcon->stats.cifs_stats.num_opens),
57771- atomic_read(&tcon->stats.cifs_stats.num_closes),
57772- atomic_read(&tcon->stats.cifs_stats.num_deletes));
57773+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57774+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57775+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57776 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57777- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57778- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57779+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57780+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57781 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57782- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57783- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57784+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57785+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57786 seq_printf(m, "\nRenames: %d T2 Renames %d",
57787- atomic_read(&tcon->stats.cifs_stats.num_renames),
57788- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57789+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57790+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57791 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57792- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57793- atomic_read(&tcon->stats.cifs_stats.num_fnext),
57794- atomic_read(&tcon->stats.cifs_stats.num_fclose));
57795+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57796+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57797+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57798 #endif
57799 }
57800
57801diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57802index 35ddc3e..563e809 100644
57803--- a/fs/cifs/smb2ops.c
57804+++ b/fs/cifs/smb2ops.c
57805@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57806 #ifdef CONFIG_CIFS_STATS
57807 int i;
57808 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57809- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57810- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57811+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57812+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57813 }
57814 #endif
57815 }
57816@@ -405,65 +405,65 @@ static void
57817 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57818 {
57819 #ifdef CONFIG_CIFS_STATS
57820- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57821- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57822+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57823+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57824 seq_printf(m, "\nNegotiates: %d sent %d failed",
57825- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57826- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57827+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57828+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57829 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57830- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57831- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57832+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57833+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57834 seq_printf(m, "\nLogoffs: %d sent %d failed",
57835- atomic_read(&sent[SMB2_LOGOFF_HE]),
57836- atomic_read(&failed[SMB2_LOGOFF_HE]));
57837+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57838+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57839 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57840- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57841- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57842+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57843+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57844 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57845- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57846- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57847+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57848+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57849 seq_printf(m, "\nCreates: %d sent %d failed",
57850- atomic_read(&sent[SMB2_CREATE_HE]),
57851- atomic_read(&failed[SMB2_CREATE_HE]));
57852+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57853+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57854 seq_printf(m, "\nCloses: %d sent %d failed",
57855- atomic_read(&sent[SMB2_CLOSE_HE]),
57856- atomic_read(&failed[SMB2_CLOSE_HE]));
57857+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57858+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57859 seq_printf(m, "\nFlushes: %d sent %d failed",
57860- atomic_read(&sent[SMB2_FLUSH_HE]),
57861- atomic_read(&failed[SMB2_FLUSH_HE]));
57862+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57863+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57864 seq_printf(m, "\nReads: %d sent %d failed",
57865- atomic_read(&sent[SMB2_READ_HE]),
57866- atomic_read(&failed[SMB2_READ_HE]));
57867+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
57868+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
57869 seq_printf(m, "\nWrites: %d sent %d failed",
57870- atomic_read(&sent[SMB2_WRITE_HE]),
57871- atomic_read(&failed[SMB2_WRITE_HE]));
57872+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57873+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57874 seq_printf(m, "\nLocks: %d sent %d failed",
57875- atomic_read(&sent[SMB2_LOCK_HE]),
57876- atomic_read(&failed[SMB2_LOCK_HE]));
57877+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57878+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57879 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57880- atomic_read(&sent[SMB2_IOCTL_HE]),
57881- atomic_read(&failed[SMB2_IOCTL_HE]));
57882+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57883+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57884 seq_printf(m, "\nCancels: %d sent %d failed",
57885- atomic_read(&sent[SMB2_CANCEL_HE]),
57886- atomic_read(&failed[SMB2_CANCEL_HE]));
57887+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57888+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57889 seq_printf(m, "\nEchos: %d sent %d failed",
57890- atomic_read(&sent[SMB2_ECHO_HE]),
57891- atomic_read(&failed[SMB2_ECHO_HE]));
57892+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57893+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57894 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57895- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57896- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57897+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57898+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
57899 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
57900- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
57901- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
57902+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
57903+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
57904 seq_printf(m, "\nQueryInfos: %d sent %d failed",
57905- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
57906- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
57907+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
57908+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
57909 seq_printf(m, "\nSetInfos: %d sent %d failed",
57910- atomic_read(&sent[SMB2_SET_INFO_HE]),
57911- atomic_read(&failed[SMB2_SET_INFO_HE]));
57912+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
57913+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
57914 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
57915- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
57916- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
57917+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
57918+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
57919 #endif
57920 }
57921
57922diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
57923index 1fb6ad2..758e171 100644
57924--- a/fs/cifs/smb2pdu.c
57925+++ b/fs/cifs/smb2pdu.c
57926@@ -2097,8 +2097,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
57927 default:
57928 cifs_dbg(VFS, "info level %u isn't supported\n",
57929 srch_inf->info_level);
57930- rc = -EINVAL;
57931- goto qdir_exit;
57932+ return -EINVAL;
57933 }
57934
57935 req->FileIndex = cpu_to_le32(index);
57936diff --git a/fs/coda/cache.c b/fs/coda/cache.c
57937index 1da168c..8bc7ff6 100644
57938--- a/fs/coda/cache.c
57939+++ b/fs/coda/cache.c
57940@@ -24,7 +24,7 @@
57941 #include "coda_linux.h"
57942 #include "coda_cache.h"
57943
57944-static atomic_t permission_epoch = ATOMIC_INIT(0);
57945+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
57946
57947 /* replace or extend an acl cache hit */
57948 void coda_cache_enter(struct inode *inode, int mask)
57949@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
57950 struct coda_inode_info *cii = ITOC(inode);
57951
57952 spin_lock(&cii->c_lock);
57953- cii->c_cached_epoch = atomic_read(&permission_epoch);
57954+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57955 if (!uid_eq(cii->c_uid, current_fsuid())) {
57956 cii->c_uid = current_fsuid();
57957 cii->c_cached_perm = mask;
57958@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57959 {
57960 struct coda_inode_info *cii = ITOC(inode);
57961 spin_lock(&cii->c_lock);
57962- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57963+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57964 spin_unlock(&cii->c_lock);
57965 }
57966
57967 /* remove all acl caches */
57968 void coda_cache_clear_all(struct super_block *sb)
57969 {
57970- atomic_inc(&permission_epoch);
57971+ atomic_inc_unchecked(&permission_epoch);
57972 }
57973
57974
57975@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
57976 spin_lock(&cii->c_lock);
57977 hit = (mask & cii->c_cached_perm) == mask &&
57978 uid_eq(cii->c_uid, current_fsuid()) &&
57979- cii->c_cached_epoch == atomic_read(&permission_epoch);
57980+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
57981 spin_unlock(&cii->c_lock);
57982
57983 return hit;
57984diff --git a/fs/compat.c b/fs/compat.c
57985index 66d3d3c..9c10175 100644
57986--- a/fs/compat.c
57987+++ b/fs/compat.c
57988@@ -54,7 +54,7 @@
57989 #include <asm/ioctls.h>
57990 #include "internal.h"
57991
57992-int compat_log = 1;
57993+int compat_log = 0;
57994
57995 int compat_printk(const char *fmt, ...)
57996 {
57997@@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
57998
57999 set_fs(KERNEL_DS);
58000 /* The __user pointer cast is valid because of the set_fs() */
58001- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58002+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58003 set_fs(oldfs);
58004 /* truncating is ok because it's a user address */
58005 if (!ret)
58006@@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58007 goto out;
58008
58009 ret = -EINVAL;
58010- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58011+ if (nr_segs > UIO_MAXIOV)
58012 goto out;
58013 if (nr_segs > fast_segs) {
58014 ret = -ENOMEM;
58015@@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
58016 struct compat_readdir_callback {
58017 struct dir_context ctx;
58018 struct compat_old_linux_dirent __user *dirent;
58019+ struct file * file;
58020 int result;
58021 };
58022
58023@@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58024 buf->result = -EOVERFLOW;
58025 return -EOVERFLOW;
58026 }
58027+
58028+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58029+ return 0;
58030+
58031 buf->result++;
58032 dirent = buf->dirent;
58033 if (!access_ok(VERIFY_WRITE, dirent,
58034@@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
58035 if (!f.file)
58036 return -EBADF;
58037
58038+ buf.file = f.file;
58039 error = iterate_dir(f.file, &buf.ctx);
58040 if (buf.result)
58041 error = buf.result;
58042@@ -917,6 +923,7 @@ struct compat_getdents_callback {
58043 struct dir_context ctx;
58044 struct compat_linux_dirent __user *current_dir;
58045 struct compat_linux_dirent __user *previous;
58046+ struct file * file;
58047 int count;
58048 int error;
58049 };
58050@@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58051 buf->error = -EOVERFLOW;
58052 return -EOVERFLOW;
58053 }
58054+
58055+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58056+ return 0;
58057+
58058 dirent = buf->previous;
58059 if (dirent) {
58060 if (__put_user(offset, &dirent->d_off))
58061@@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
58062 if (!f.file)
58063 return -EBADF;
58064
58065+ buf.file = f.file;
58066 error = iterate_dir(f.file, &buf.ctx);
58067 if (error >= 0)
58068 error = buf.error;
58069@@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
58070 struct dir_context ctx;
58071 struct linux_dirent64 __user *current_dir;
58072 struct linux_dirent64 __user *previous;
58073+ struct file * file;
58074 int count;
58075 int error;
58076 };
58077@@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58078 buf->error = -EINVAL; /* only used if we fail.. */
58079 if (reclen > buf->count)
58080 return -EINVAL;
58081+
58082+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58083+ return 0;
58084+
58085 dirent = buf->previous;
58086
58087 if (dirent) {
58088@@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
58089 if (!f.file)
58090 return -EBADF;
58091
58092+ buf.file = f.file;
58093 error = iterate_dir(f.file, &buf.ctx);
58094 if (error >= 0)
58095 error = buf.error;
58096diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58097index 4d24d17..4f8c09e 100644
58098--- a/fs/compat_binfmt_elf.c
58099+++ b/fs/compat_binfmt_elf.c
58100@@ -30,11 +30,13 @@
58101 #undef elf_phdr
58102 #undef elf_shdr
58103 #undef elf_note
58104+#undef elf_dyn
58105 #undef elf_addr_t
58106 #define elfhdr elf32_hdr
58107 #define elf_phdr elf32_phdr
58108 #define elf_shdr elf32_shdr
58109 #define elf_note elf32_note
58110+#define elf_dyn Elf32_Dyn
58111 #define elf_addr_t Elf32_Addr
58112
58113 /*
58114diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58115index e822890..59374d5 100644
58116--- a/fs/compat_ioctl.c
58117+++ b/fs/compat_ioctl.c
58118@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58119 return -EFAULT;
58120 if (__get_user(udata, &ss32->iomem_base))
58121 return -EFAULT;
58122- ss.iomem_base = compat_ptr(udata);
58123+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58124 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58125 __get_user(ss.port_high, &ss32->port_high))
58126 return -EFAULT;
58127@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58128 for (i = 0; i < nmsgs; i++) {
58129 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58130 return -EFAULT;
58131- if (get_user(datap, &umsgs[i].buf) ||
58132- put_user(compat_ptr(datap), &tmsgs[i].buf))
58133+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58134+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58135 return -EFAULT;
58136 }
58137 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58138@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58139 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58140 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58141 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58142- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58143+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58144 return -EFAULT;
58145
58146 return ioctl_preallocate(file, p);
58147@@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
58148 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58149 {
58150 unsigned int a, b;
58151- a = *(unsigned int *)p;
58152- b = *(unsigned int *)q;
58153+ a = *(const unsigned int *)p;
58154+ b = *(const unsigned int *)q;
58155 if (a > b)
58156 return 1;
58157 if (a < b)
58158diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58159index e081acb..911df21 100644
58160--- a/fs/configfs/dir.c
58161+++ b/fs/configfs/dir.c
58162@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58163 }
58164 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58165 struct configfs_dirent *next;
58166- const char *name;
58167+ const unsigned char * name;
58168+ char d_name[sizeof(next->s_dentry->d_iname)];
58169 int len;
58170 struct inode *inode = NULL;
58171
58172@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58173 continue;
58174
58175 name = configfs_get_name(next);
58176- len = strlen(name);
58177+ if (next->s_dentry && name == next->s_dentry->d_iname) {
58178+ len = next->s_dentry->d_name.len;
58179+ memcpy(d_name, name, len);
58180+ name = d_name;
58181+ } else
58182+ len = strlen(name);
58183
58184 /*
58185 * We'll have a dentry and an inode for
58186diff --git a/fs/coredump.c b/fs/coredump.c
58187index 0b2528f..836c55f 100644
58188--- a/fs/coredump.c
58189+++ b/fs/coredump.c
58190@@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58191 struct pipe_inode_info *pipe = file->private_data;
58192
58193 pipe_lock(pipe);
58194- pipe->readers++;
58195- pipe->writers--;
58196+ atomic_inc(&pipe->readers);
58197+ atomic_dec(&pipe->writers);
58198 wake_up_interruptible_sync(&pipe->wait);
58199 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58200 pipe_unlock(pipe);
58201@@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58202 * We actually want wait_event_freezable() but then we need
58203 * to clear TIF_SIGPENDING and improve dump_interrupted().
58204 */
58205- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58206+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58207
58208 pipe_lock(pipe);
58209- pipe->readers--;
58210- pipe->writers++;
58211+ atomic_dec(&pipe->readers);
58212+ atomic_inc(&pipe->writers);
58213 pipe_unlock(pipe);
58214 }
58215
58216@@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58217 struct files_struct *displaced;
58218 bool need_nonrelative = false;
58219 bool core_dumped = false;
58220- static atomic_t core_dump_count = ATOMIC_INIT(0);
58221+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58222+ long signr = siginfo->si_signo;
58223+ int dumpable;
58224 struct coredump_params cprm = {
58225 .siginfo = siginfo,
58226 .regs = signal_pt_regs(),
58227@@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58228 .mm_flags = mm->flags,
58229 };
58230
58231- audit_core_dumps(siginfo->si_signo);
58232+ audit_core_dumps(signr);
58233+
58234+ dumpable = __get_dumpable(cprm.mm_flags);
58235+
58236+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58237+ gr_handle_brute_attach(dumpable);
58238
58239 binfmt = mm->binfmt;
58240 if (!binfmt || !binfmt->core_dump)
58241 goto fail;
58242- if (!__get_dumpable(cprm.mm_flags))
58243+ if (!dumpable)
58244 goto fail;
58245
58246 cred = prepare_creds();
58247@@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58248 need_nonrelative = true;
58249 }
58250
58251- retval = coredump_wait(siginfo->si_signo, &core_state);
58252+ retval = coredump_wait(signr, &core_state);
58253 if (retval < 0)
58254 goto fail_creds;
58255
58256@@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58257 }
58258 cprm.limit = RLIM_INFINITY;
58259
58260- dump_count = atomic_inc_return(&core_dump_count);
58261+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58262 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58263 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58264 task_tgid_vnr(current), current->comm);
58265@@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58266 } else {
58267 struct inode *inode;
58268
58269+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58270+
58271 if (cprm.limit < binfmt->min_coredump)
58272 goto fail_unlock;
58273
58274@@ -673,7 +682,7 @@ close_fail:
58275 filp_close(cprm.file, NULL);
58276 fail_dropcount:
58277 if (ispipe)
58278- atomic_dec(&core_dump_count);
58279+ atomic_dec_unchecked(&core_dump_count);
58280 fail_unlock:
58281 kfree(cn.corename);
58282 coredump_finish(mm, core_dumped);
58283@@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58284 struct file *file = cprm->file;
58285 loff_t pos = file->f_pos;
58286 ssize_t n;
58287+
58288+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58289 if (cprm->written + nr > cprm->limit)
58290 return 0;
58291 while (nr) {
58292diff --git a/fs/dcache.c b/fs/dcache.c
58293index e99c6f5..2838bf58 100644
58294--- a/fs/dcache.c
58295+++ b/fs/dcache.c
58296@@ -1445,7 +1445,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58297 */
58298 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58299 if (name->len > DNAME_INLINE_LEN-1) {
58300- dname = kmalloc(name->len + 1, GFP_KERNEL);
58301+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58302 if (!dname) {
58303 kmem_cache_free(dentry_cache, dentry);
58304 return NULL;
58305@@ -3413,7 +3413,8 @@ void __init vfs_caches_init(unsigned long mempages)
58306 mempages -= reserve;
58307
58308 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58309- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58310+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58311+ SLAB_NO_SANITIZE, NULL);
58312
58313 dcache_init();
58314 inode_init();
58315diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58316index 8c41b52..145b1b9 100644
58317--- a/fs/debugfs/inode.c
58318+++ b/fs/debugfs/inode.c
58319@@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58320 */
58321 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58322 {
58323+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58324+ return __create_file(name, S_IFDIR | S_IRWXU,
58325+#else
58326 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58327+#endif
58328 parent, NULL, NULL);
58329 }
58330 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58331diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58332index d4a9431..77f9b2e 100644
58333--- a/fs/ecryptfs/inode.c
58334+++ b/fs/ecryptfs/inode.c
58335@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58336 old_fs = get_fs();
58337 set_fs(get_ds());
58338 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58339- (char __user *)lower_buf,
58340+ (char __force_user *)lower_buf,
58341 PATH_MAX);
58342 set_fs(old_fs);
58343 if (rc < 0)
58344diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58345index e4141f2..d8263e8 100644
58346--- a/fs/ecryptfs/miscdev.c
58347+++ b/fs/ecryptfs/miscdev.c
58348@@ -304,7 +304,7 @@ check_list:
58349 goto out_unlock_msg_ctx;
58350 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58351 if (msg_ctx->msg) {
58352- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58353+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58354 goto out_unlock_msg_ctx;
58355 i += packet_length_size;
58356 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58357diff --git a/fs/exec.c b/fs/exec.c
58358index 238b7aa..a421d91 100644
58359--- a/fs/exec.c
58360+++ b/fs/exec.c
58361@@ -56,8 +56,20 @@
58362 #include <linux/pipe_fs_i.h>
58363 #include <linux/oom.h>
58364 #include <linux/compat.h>
58365+#include <linux/random.h>
58366+#include <linux/seq_file.h>
58367+#include <linux/coredump.h>
58368+#include <linux/mman.h>
58369+
58370+#ifdef CONFIG_PAX_REFCOUNT
58371+#include <linux/kallsyms.h>
58372+#include <linux/kdebug.h>
58373+#endif
58374+
58375+#include <trace/events/fs.h>
58376
58377 #include <asm/uaccess.h>
58378+#include <asm/sections.h>
58379 #include <asm/mmu_context.h>
58380 #include <asm/tlb.h>
58381
58382@@ -66,19 +78,34 @@
58383
58384 #include <trace/events/sched.h>
58385
58386+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58387+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58388+{
58389+ 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");
58390+}
58391+#endif
58392+
58393+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58394+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58395+EXPORT_SYMBOL(pax_set_initial_flags_func);
58396+#endif
58397+
58398 int suid_dumpable = 0;
58399
58400 static LIST_HEAD(formats);
58401 static DEFINE_RWLOCK(binfmt_lock);
58402
58403+extern int gr_process_kernel_exec_ban(void);
58404+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58405+
58406 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58407 {
58408 BUG_ON(!fmt);
58409 if (WARN_ON(!fmt->load_binary))
58410 return;
58411 write_lock(&binfmt_lock);
58412- insert ? list_add(&fmt->lh, &formats) :
58413- list_add_tail(&fmt->lh, &formats);
58414+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58415+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58416 write_unlock(&binfmt_lock);
58417 }
58418
58419@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58420 void unregister_binfmt(struct linux_binfmt * fmt)
58421 {
58422 write_lock(&binfmt_lock);
58423- list_del(&fmt->lh);
58424+ pax_list_del((struct list_head *)&fmt->lh);
58425 write_unlock(&binfmt_lock);
58426 }
58427
58428@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58429 int write)
58430 {
58431 struct page *page;
58432- int ret;
58433
58434-#ifdef CONFIG_STACK_GROWSUP
58435- if (write) {
58436- ret = expand_downwards(bprm->vma, pos);
58437- if (ret < 0)
58438- return NULL;
58439- }
58440-#endif
58441- ret = get_user_pages(current, bprm->mm, pos,
58442- 1, write, 1, &page, NULL);
58443- if (ret <= 0)
58444+ if (0 > expand_downwards(bprm->vma, pos))
58445+ return NULL;
58446+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58447 return NULL;
58448
58449 if (write) {
58450@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58451 if (size <= ARG_MAX)
58452 return page;
58453
58454+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58455+ // only allow 512KB for argv+env on suid/sgid binaries
58456+ // to prevent easy ASLR exhaustion
58457+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58458+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58459+ (size > (512 * 1024))) {
58460+ put_page(page);
58461+ return NULL;
58462+ }
58463+#endif
58464+
58465 /*
58466 * Limit to 1/4-th the stack size for the argv+env strings.
58467 * This ensures that:
58468@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58469 vma->vm_end = STACK_TOP_MAX;
58470 vma->vm_start = vma->vm_end - PAGE_SIZE;
58471 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58472+
58473+#ifdef CONFIG_PAX_SEGMEXEC
58474+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58475+#endif
58476+
58477 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58478 INIT_LIST_HEAD(&vma->anon_vma_chain);
58479
58480@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58481 mm->stack_vm = mm->total_vm = 1;
58482 up_write(&mm->mmap_sem);
58483 bprm->p = vma->vm_end - sizeof(void *);
58484+
58485+#ifdef CONFIG_PAX_RANDUSTACK
58486+ if (randomize_va_space)
58487+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
58488+#endif
58489+
58490 return 0;
58491 err:
58492 up_write(&mm->mmap_sem);
58493@@ -399,7 +440,7 @@ struct user_arg_ptr {
58494 } ptr;
58495 };
58496
58497-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58498+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58499 {
58500 const char __user *native;
58501
58502@@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58503 compat_uptr_t compat;
58504
58505 if (get_user(compat, argv.ptr.compat + nr))
58506- return ERR_PTR(-EFAULT);
58507+ return (const char __force_user *)ERR_PTR(-EFAULT);
58508
58509 return compat_ptr(compat);
58510 }
58511 #endif
58512
58513 if (get_user(native, argv.ptr.native + nr))
58514- return ERR_PTR(-EFAULT);
58515+ return (const char __force_user *)ERR_PTR(-EFAULT);
58516
58517 return native;
58518 }
58519@@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
58520 if (!p)
58521 break;
58522
58523- if (IS_ERR(p))
58524+ if (IS_ERR((const char __force_kernel *)p))
58525 return -EFAULT;
58526
58527 if (i >= max)
58528@@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58529
58530 ret = -EFAULT;
58531 str = get_user_arg_ptr(argv, argc);
58532- if (IS_ERR(str))
58533+ if (IS_ERR((const char __force_kernel *)str))
58534 goto out;
58535
58536 len = strnlen_user(str, MAX_ARG_STRLEN);
58537@@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58538 int r;
58539 mm_segment_t oldfs = get_fs();
58540 struct user_arg_ptr argv = {
58541- .ptr.native = (const char __user *const __user *)__argv,
58542+ .ptr.native = (const char __user * const __force_user *)__argv,
58543 };
58544
58545 set_fs(KERNEL_DS);
58546@@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58547 unsigned long new_end = old_end - shift;
58548 struct mmu_gather tlb;
58549
58550- BUG_ON(new_start > new_end);
58551+ if (new_start >= new_end || new_start < mmap_min_addr)
58552+ return -ENOMEM;
58553
58554 /*
58555 * ensure there are no vmas between where we want to go
58556@@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58557 if (vma != find_vma(mm, new_start))
58558 return -EFAULT;
58559
58560+#ifdef CONFIG_PAX_SEGMEXEC
58561+ BUG_ON(pax_find_mirror_vma(vma));
58562+#endif
58563+
58564 /*
58565 * cover the whole range: [new_start, old_end)
58566 */
58567@@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58568 stack_top = arch_align_stack(stack_top);
58569 stack_top = PAGE_ALIGN(stack_top);
58570
58571- if (unlikely(stack_top < mmap_min_addr) ||
58572- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58573- return -ENOMEM;
58574-
58575 stack_shift = vma->vm_end - stack_top;
58576
58577 bprm->p -= stack_shift;
58578@@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58579 bprm->exec -= stack_shift;
58580
58581 down_write(&mm->mmap_sem);
58582+
58583+ /* Move stack pages down in memory. */
58584+ if (stack_shift) {
58585+ ret = shift_arg_pages(vma, stack_shift);
58586+ if (ret)
58587+ goto out_unlock;
58588+ }
58589+
58590 vm_flags = VM_STACK_FLAGS;
58591
58592+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58593+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58594+ vm_flags &= ~VM_EXEC;
58595+
58596+#ifdef CONFIG_PAX_MPROTECT
58597+ if (mm->pax_flags & MF_PAX_MPROTECT)
58598+ vm_flags &= ~VM_MAYEXEC;
58599+#endif
58600+
58601+ }
58602+#endif
58603+
58604 /*
58605 * Adjust stack execute permissions; explicitly enable for
58606 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58607@@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58608 goto out_unlock;
58609 BUG_ON(prev != vma);
58610
58611- /* Move stack pages down in memory. */
58612- if (stack_shift) {
58613- ret = shift_arg_pages(vma, stack_shift);
58614- if (ret)
58615- goto out_unlock;
58616- }
58617-
58618 /* mprotect_fixup is overkill to remove the temporary stack flags */
58619 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58620
58621@@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58622 #endif
58623 current->mm->start_stack = bprm->p;
58624 ret = expand_stack(vma, stack_base);
58625+
58626+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58627+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58628+ unsigned long size;
58629+ vm_flags_t vm_flags;
58630+
58631+ size = STACK_TOP - vma->vm_end;
58632+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58633+
58634+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58635+
58636+#ifdef CONFIG_X86
58637+ if (!ret) {
58638+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58639+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58640+ }
58641+#endif
58642+
58643+ }
58644+#endif
58645+
58646 if (ret)
58647 ret = -EFAULT;
58648
58649@@ -775,6 +851,8 @@ static struct file *do_open_exec(struct filename *name)
58650
58651 fsnotify_open(file);
58652
58653+ trace_open_exec(name->name);
58654+
58655 err = deny_write_access(file);
58656 if (err)
58657 goto exit;
58658@@ -804,7 +882,7 @@ int kernel_read(struct file *file, loff_t offset,
58659 old_fs = get_fs();
58660 set_fs(get_ds());
58661 /* The cast to a user pointer is valid due to the set_fs() */
58662- result = vfs_read(file, (void __user *)addr, count, &pos);
58663+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
58664 set_fs(old_fs);
58665 return result;
58666 }
58667@@ -849,6 +927,7 @@ static int exec_mmap(struct mm_struct *mm)
58668 tsk->mm = mm;
58669 tsk->active_mm = mm;
58670 activate_mm(active_mm, mm);
58671+ populate_stack();
58672 tsk->mm->vmacache_seqnum = 0;
58673 vmacache_flush(tsk);
58674 task_unlock(tsk);
58675@@ -1246,7 +1325,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
58676 }
58677 rcu_read_unlock();
58678
58679- if (p->fs->users > n_fs)
58680+ if (atomic_read(&p->fs->users) > n_fs)
58681 bprm->unsafe |= LSM_UNSAFE_SHARE;
58682 else
58683 p->fs->in_exec = 1;
58684@@ -1422,6 +1501,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58685 return ret;
58686 }
58687
58688+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58689+static DEFINE_PER_CPU(u64, exec_counter);
58690+static int __init init_exec_counters(void)
58691+{
58692+ unsigned int cpu;
58693+
58694+ for_each_possible_cpu(cpu) {
58695+ per_cpu(exec_counter, cpu) = (u64)cpu;
58696+ }
58697+
58698+ return 0;
58699+}
58700+early_initcall(init_exec_counters);
58701+static inline void increment_exec_counter(void)
58702+{
58703+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
58704+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58705+}
58706+#else
58707+static inline void increment_exec_counter(void) {}
58708+#endif
58709+
58710+extern void gr_handle_exec_args(struct linux_binprm *bprm,
58711+ struct user_arg_ptr argv);
58712+
58713 /*
58714 * sys_execve() executes a new program.
58715 */
58716@@ -1429,6 +1533,11 @@ static int do_execve_common(struct filename *filename,
58717 struct user_arg_ptr argv,
58718 struct user_arg_ptr envp)
58719 {
58720+#ifdef CONFIG_GRKERNSEC
58721+ struct file *old_exec_file;
58722+ struct acl_subject_label *old_acl;
58723+ struct rlimit old_rlim[RLIM_NLIMITS];
58724+#endif
58725 struct linux_binprm *bprm;
58726 struct file *file;
58727 struct files_struct *displaced;
58728@@ -1437,6 +1546,8 @@ static int do_execve_common(struct filename *filename,
58729 if (IS_ERR(filename))
58730 return PTR_ERR(filename);
58731
58732+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58733+
58734 /*
58735 * We move the actual failure in case of RLIMIT_NPROC excess from
58736 * set*uid() to execve() because too many poorly written programs
58737@@ -1474,11 +1585,21 @@ static int do_execve_common(struct filename *filename,
58738 if (IS_ERR(file))
58739 goto out_unmark;
58740
58741+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
58742+ retval = -EPERM;
58743+ goto out_unmark;
58744+ }
58745+
58746 sched_exec();
58747
58748 bprm->file = file;
58749 bprm->filename = bprm->interp = filename->name;
58750
58751+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58752+ retval = -EACCES;
58753+ goto out_unmark;
58754+ }
58755+
58756 retval = bprm_mm_init(bprm);
58757 if (retval)
58758 goto out_unmark;
58759@@ -1495,24 +1616,70 @@ static int do_execve_common(struct filename *filename,
58760 if (retval < 0)
58761 goto out;
58762
58763+#ifdef CONFIG_GRKERNSEC
58764+ old_acl = current->acl;
58765+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58766+ old_exec_file = current->exec_file;
58767+ get_file(file);
58768+ current->exec_file = file;
58769+#endif
58770+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58771+ /* limit suid stack to 8MB
58772+ * we saved the old limits above and will restore them if this exec fails
58773+ */
58774+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58775+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58776+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58777+#endif
58778+
58779+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58780+ retval = -EPERM;
58781+ goto out_fail;
58782+ }
58783+
58784+ if (!gr_tpe_allow(file)) {
58785+ retval = -EACCES;
58786+ goto out_fail;
58787+ }
58788+
58789+ if (gr_check_crash_exec(file)) {
58790+ retval = -EACCES;
58791+ goto out_fail;
58792+ }
58793+
58794+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58795+ bprm->unsafe);
58796+ if (retval < 0)
58797+ goto out_fail;
58798+
58799 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58800 if (retval < 0)
58801- goto out;
58802+ goto out_fail;
58803
58804 bprm->exec = bprm->p;
58805 retval = copy_strings(bprm->envc, envp, bprm);
58806 if (retval < 0)
58807- goto out;
58808+ goto out_fail;
58809
58810 retval = copy_strings(bprm->argc, argv, bprm);
58811 if (retval < 0)
58812- goto out;
58813+ goto out_fail;
58814+
58815+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58816+
58817+ gr_handle_exec_args(bprm, argv);
58818
58819 retval = exec_binprm(bprm);
58820 if (retval < 0)
58821- goto out;
58822+ goto out_fail;
58823+#ifdef CONFIG_GRKERNSEC
58824+ if (old_exec_file)
58825+ fput(old_exec_file);
58826+#endif
58827
58828 /* execve succeeded */
58829+
58830+ increment_exec_counter();
58831 current->fs->in_exec = 0;
58832 current->in_execve = 0;
58833 acct_update_integrals(current);
58834@@ -1523,6 +1690,14 @@ static int do_execve_common(struct filename *filename,
58835 put_files_struct(displaced);
58836 return retval;
58837
58838+out_fail:
58839+#ifdef CONFIG_GRKERNSEC
58840+ current->acl = old_acl;
58841+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58842+ fput(current->exec_file);
58843+ current->exec_file = old_exec_file;
58844+#endif
58845+
58846 out:
58847 if (bprm->mm) {
58848 acct_arg_size(bprm, 0);
58849@@ -1614,3 +1789,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
58850 return compat_do_execve(getname(filename), argv, envp);
58851 }
58852 #endif
58853+
58854+int pax_check_flags(unsigned long *flags)
58855+{
58856+ int retval = 0;
58857+
58858+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58859+ if (*flags & MF_PAX_SEGMEXEC)
58860+ {
58861+ *flags &= ~MF_PAX_SEGMEXEC;
58862+ retval = -EINVAL;
58863+ }
58864+#endif
58865+
58866+ if ((*flags & MF_PAX_PAGEEXEC)
58867+
58868+#ifdef CONFIG_PAX_PAGEEXEC
58869+ && (*flags & MF_PAX_SEGMEXEC)
58870+#endif
58871+
58872+ )
58873+ {
58874+ *flags &= ~MF_PAX_PAGEEXEC;
58875+ retval = -EINVAL;
58876+ }
58877+
58878+ if ((*flags & MF_PAX_MPROTECT)
58879+
58880+#ifdef CONFIG_PAX_MPROTECT
58881+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58882+#endif
58883+
58884+ )
58885+ {
58886+ *flags &= ~MF_PAX_MPROTECT;
58887+ retval = -EINVAL;
58888+ }
58889+
58890+ if ((*flags & MF_PAX_EMUTRAMP)
58891+
58892+#ifdef CONFIG_PAX_EMUTRAMP
58893+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58894+#endif
58895+
58896+ )
58897+ {
58898+ *flags &= ~MF_PAX_EMUTRAMP;
58899+ retval = -EINVAL;
58900+ }
58901+
58902+ return retval;
58903+}
58904+
58905+EXPORT_SYMBOL(pax_check_flags);
58906+
58907+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58908+char *pax_get_path(const struct path *path, char *buf, int buflen)
58909+{
58910+ char *pathname = d_path(path, buf, buflen);
58911+
58912+ if (IS_ERR(pathname))
58913+ goto toolong;
58914+
58915+ pathname = mangle_path(buf, pathname, "\t\n\\");
58916+ if (!pathname)
58917+ goto toolong;
58918+
58919+ *pathname = 0;
58920+ return buf;
58921+
58922+toolong:
58923+ return "<path too long>";
58924+}
58925+EXPORT_SYMBOL(pax_get_path);
58926+
58927+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
58928+{
58929+ struct task_struct *tsk = current;
58930+ struct mm_struct *mm = current->mm;
58931+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
58932+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
58933+ char *path_exec = NULL;
58934+ char *path_fault = NULL;
58935+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
58936+ siginfo_t info = { };
58937+
58938+ if (buffer_exec && buffer_fault) {
58939+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
58940+
58941+ down_read(&mm->mmap_sem);
58942+ vma = mm->mmap;
58943+ while (vma && (!vma_exec || !vma_fault)) {
58944+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
58945+ vma_exec = vma;
58946+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
58947+ vma_fault = vma;
58948+ vma = vma->vm_next;
58949+ }
58950+ if (vma_exec)
58951+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
58952+ if (vma_fault) {
58953+ start = vma_fault->vm_start;
58954+ end = vma_fault->vm_end;
58955+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
58956+ if (vma_fault->vm_file)
58957+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
58958+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58959+ path_fault = "<heap>";
58960+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58961+ path_fault = "<stack>";
58962+ else
58963+ path_fault = "<anonymous mapping>";
58964+ }
58965+ up_read(&mm->mmap_sem);
58966+ }
58967+ if (tsk->signal->curr_ip)
58968+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
58969+ else
58970+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
58971+ 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),
58972+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
58973+ free_page((unsigned long)buffer_exec);
58974+ free_page((unsigned long)buffer_fault);
58975+ pax_report_insns(regs, pc, sp);
58976+ info.si_signo = SIGKILL;
58977+ info.si_errno = 0;
58978+ info.si_code = SI_KERNEL;
58979+ info.si_pid = 0;
58980+ info.si_uid = 0;
58981+ do_coredump(&info);
58982+}
58983+#endif
58984+
58985+#ifdef CONFIG_PAX_REFCOUNT
58986+void pax_report_refcount_overflow(struct pt_regs *regs)
58987+{
58988+ if (current->signal->curr_ip)
58989+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
58990+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
58991+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58992+ else
58993+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
58994+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58995+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
58996+ preempt_disable();
58997+ show_regs(regs);
58998+ preempt_enable();
58999+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59000+}
59001+#endif
59002+
59003+#ifdef CONFIG_PAX_USERCOPY
59004+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59005+static noinline int check_stack_object(const void *obj, unsigned long len)
59006+{
59007+ const void * const stack = task_stack_page(current);
59008+ const void * const stackend = stack + THREAD_SIZE;
59009+
59010+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59011+ const void *frame = NULL;
59012+ const void *oldframe;
59013+#endif
59014+
59015+ if (obj + len < obj)
59016+ return -1;
59017+
59018+ if (obj + len <= stack || stackend <= obj)
59019+ return 0;
59020+
59021+ if (obj < stack || stackend < obj + len)
59022+ return -1;
59023+
59024+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59025+ oldframe = __builtin_frame_address(1);
59026+ if (oldframe)
59027+ frame = __builtin_frame_address(2);
59028+ /*
59029+ low ----------------------------------------------> high
59030+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
59031+ ^----------------^
59032+ allow copies only within here
59033+ */
59034+ while (stack <= frame && frame < stackend) {
59035+ /* if obj + len extends past the last frame, this
59036+ check won't pass and the next frame will be 0,
59037+ causing us to bail out and correctly report
59038+ the copy as invalid
59039+ */
59040+ if (obj + len <= frame)
59041+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59042+ oldframe = frame;
59043+ frame = *(const void * const *)frame;
59044+ }
59045+ return -1;
59046+#else
59047+ return 1;
59048+#endif
59049+}
59050+
59051+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59052+{
59053+ if (current->signal->curr_ip)
59054+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59055+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59056+ else
59057+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59058+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59059+ dump_stack();
59060+ gr_handle_kernel_exploit();
59061+ do_group_exit(SIGKILL);
59062+}
59063+#endif
59064+
59065+#ifdef CONFIG_PAX_USERCOPY
59066+
59067+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59068+{
59069+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59070+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
59071+#ifdef CONFIG_MODULES
59072+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59073+#else
59074+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59075+#endif
59076+
59077+#else
59078+ unsigned long textlow = (unsigned long)_stext;
59079+ unsigned long texthigh = (unsigned long)_etext;
59080+
59081+#ifdef CONFIG_X86_64
59082+ /* check against linear mapping as well */
59083+ if (high > (unsigned long)__va(__pa(textlow)) &&
59084+ low < (unsigned long)__va(__pa(texthigh)))
59085+ return true;
59086+#endif
59087+
59088+#endif
59089+
59090+ if (high <= textlow || low >= texthigh)
59091+ return false;
59092+ else
59093+ return true;
59094+}
59095+#endif
59096+
59097+void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
59098+{
59099+#ifdef CONFIG_PAX_USERCOPY
59100+ const char *type;
59101+#endif
59102+
59103+#ifndef CONFIG_STACK_GROWSUP
59104+ unsigned long stackstart = (unsigned long)task_stack_page(current);
59105+ unsigned long currentsp = (unsigned long)&stackstart;
59106+ if (unlikely((currentsp < stackstart + 512 ||
59107+ currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
59108+ BUG();
59109+#endif
59110+
59111+#ifndef CONFIG_PAX_USERCOPY_DEBUG
59112+ if (const_size)
59113+ return;
59114+#endif
59115+
59116+#ifdef CONFIG_PAX_USERCOPY
59117+ if (!n)
59118+ return;
59119+
59120+ type = check_heap_object(ptr, n);
59121+ if (!type) {
59122+ int ret = check_stack_object(ptr, n);
59123+ if (ret == 1 || ret == 2)
59124+ return;
59125+ if (ret == 0) {
59126+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59127+ type = "<kernel text>";
59128+ else
59129+ return;
59130+ } else
59131+ type = "<process stack>";
59132+ }
59133+
59134+ pax_report_usercopy(ptr, n, to_user, type);
59135+#endif
59136+
59137+}
59138+EXPORT_SYMBOL(__check_object_size);
59139+
59140+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59141+void pax_track_stack(void)
59142+{
59143+ unsigned long sp = (unsigned long)&sp;
59144+ if (sp < current_thread_info()->lowest_stack &&
59145+ sp > (unsigned long)task_stack_page(current))
59146+ current_thread_info()->lowest_stack = sp;
59147+ if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
59148+ BUG();
59149+}
59150+EXPORT_SYMBOL(pax_track_stack);
59151+#endif
59152+
59153+#ifdef CONFIG_PAX_SIZE_OVERFLOW
59154+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59155+{
59156+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59157+ dump_stack();
59158+ do_group_exit(SIGKILL);
59159+}
59160+EXPORT_SYMBOL(report_size_overflow);
59161+#endif
59162diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59163index 9f9992b..8b59411 100644
59164--- a/fs/ext2/balloc.c
59165+++ b/fs/ext2/balloc.c
59166@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59167
59168 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59169 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59170- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59171+ if (free_blocks < root_blocks + 1 &&
59172 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59173 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59174- !in_group_p (sbi->s_resgid))) {
59175+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59176 return 0;
59177 }
59178 return 1;
59179diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59180index 9142614..97484fa 100644
59181--- a/fs/ext2/xattr.c
59182+++ b/fs/ext2/xattr.c
59183@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59184 struct buffer_head *bh = NULL;
59185 struct ext2_xattr_entry *entry;
59186 char *end;
59187- size_t rest = buffer_size;
59188+ size_t rest = buffer_size, total_size = 0;
59189 int error;
59190
59191 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59192@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59193 buffer += size;
59194 }
59195 rest -= size;
59196+ total_size += size;
59197 }
59198 }
59199- error = buffer_size - rest; /* total size */
59200+ error = total_size;
59201
59202 cleanup:
59203 brelse(bh);
59204diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59205index 158b5d4..2432610 100644
59206--- a/fs/ext3/balloc.c
59207+++ b/fs/ext3/balloc.c
59208@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59209
59210 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59211 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59212- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59213+ if (free_blocks < root_blocks + 1 &&
59214 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59215 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59216- !in_group_p (sbi->s_resgid))) {
59217+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59218 return 0;
59219 }
59220 return 1;
59221diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59222index c6874be..f8a6ae8 100644
59223--- a/fs/ext3/xattr.c
59224+++ b/fs/ext3/xattr.c
59225@@ -330,7 +330,7 @@ static int
59226 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59227 char *buffer, size_t buffer_size)
59228 {
59229- size_t rest = buffer_size;
59230+ size_t rest = buffer_size, total_size = 0;
59231
59232 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59233 const struct xattr_handler *handler =
59234@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59235 buffer += size;
59236 }
59237 rest -= size;
59238+ total_size += size;
59239 }
59240 }
59241- return buffer_size - rest;
59242+ return total_size;
59243 }
59244
59245 static int
59246diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59247index 5c56785..77698a2 100644
59248--- a/fs/ext4/balloc.c
59249+++ b/fs/ext4/balloc.c
59250@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59251 /* Hm, nope. Are (enough) root reserved clusters available? */
59252 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59253 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59254- capable(CAP_SYS_RESOURCE) ||
59255- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59256+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59257+ capable_nolog(CAP_SYS_RESOURCE)) {
59258
59259 if (free_clusters >= (nclusters + dirty_clusters +
59260 resv_clusters))
59261diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59262index f542e48..c0275f5 100644
59263--- a/fs/ext4/ext4.h
59264+++ b/fs/ext4/ext4.h
59265@@ -1274,19 +1274,19 @@ struct ext4_sb_info {
59266 unsigned long s_mb_last_start;
59267
59268 /* stats for buddy allocator */
59269- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59270- atomic_t s_bal_success; /* we found long enough chunks */
59271- atomic_t s_bal_allocated; /* in blocks */
59272- atomic_t s_bal_ex_scanned; /* total extents scanned */
59273- atomic_t s_bal_goals; /* goal hits */
59274- atomic_t s_bal_breaks; /* too long searches */
59275- atomic_t s_bal_2orders; /* 2^order hits */
59276+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59277+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59278+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59279+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59280+ atomic_unchecked_t s_bal_goals; /* goal hits */
59281+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59282+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59283 spinlock_t s_bal_lock;
59284 unsigned long s_mb_buddies_generated;
59285 unsigned long long s_mb_generation_time;
59286- atomic_t s_mb_lost_chunks;
59287- atomic_t s_mb_preallocated;
59288- atomic_t s_mb_discarded;
59289+ atomic_unchecked_t s_mb_lost_chunks;
59290+ atomic_unchecked_t s_mb_preallocated;
59291+ atomic_unchecked_t s_mb_discarded;
59292 atomic_t s_lock_busy;
59293
59294 /* locality groups */
59295diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
59296index e6574d7..c30cbe2 100644
59297--- a/fs/ext4/indirect.c
59298+++ b/fs/ext4/indirect.c
59299@@ -1345,8 +1345,8 @@ static int free_hole_blocks(handle_t *handle, struct inode *inode,
59300 if (level == 0 ||
59301 (bh && all_zeroes((__le32 *)bh->b_data,
59302 (__le32 *)bh->b_data + addr_per_block))) {
59303- ext4_free_data(handle, inode, parent_bh, &blk, &blk+1);
59304- *i_data = 0;
59305+ ext4_free_data(handle, inode, parent_bh,
59306+ i_data, i_data + 1);
59307 }
59308 brelse(bh);
59309 bh = NULL;
59310diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59311index fe4e668..f983538 100644
59312--- a/fs/ext4/mballoc.c
59313+++ b/fs/ext4/mballoc.c
59314@@ -1889,7 +1889,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59315 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59316
59317 if (EXT4_SB(sb)->s_mb_stats)
59318- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59319+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59320
59321 break;
59322 }
59323@@ -2199,7 +2199,7 @@ repeat:
59324 ac->ac_status = AC_STATUS_CONTINUE;
59325 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59326 cr = 3;
59327- atomic_inc(&sbi->s_mb_lost_chunks);
59328+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59329 goto repeat;
59330 }
59331 }
59332@@ -2707,25 +2707,25 @@ int ext4_mb_release(struct super_block *sb)
59333 if (sbi->s_mb_stats) {
59334 ext4_msg(sb, KERN_INFO,
59335 "mballoc: %u blocks %u reqs (%u success)",
59336- atomic_read(&sbi->s_bal_allocated),
59337- atomic_read(&sbi->s_bal_reqs),
59338- atomic_read(&sbi->s_bal_success));
59339+ atomic_read_unchecked(&sbi->s_bal_allocated),
59340+ atomic_read_unchecked(&sbi->s_bal_reqs),
59341+ atomic_read_unchecked(&sbi->s_bal_success));
59342 ext4_msg(sb, KERN_INFO,
59343 "mballoc: %u extents scanned, %u goal hits, "
59344 "%u 2^N hits, %u breaks, %u lost",
59345- atomic_read(&sbi->s_bal_ex_scanned),
59346- atomic_read(&sbi->s_bal_goals),
59347- atomic_read(&sbi->s_bal_2orders),
59348- atomic_read(&sbi->s_bal_breaks),
59349- atomic_read(&sbi->s_mb_lost_chunks));
59350+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59351+ atomic_read_unchecked(&sbi->s_bal_goals),
59352+ atomic_read_unchecked(&sbi->s_bal_2orders),
59353+ atomic_read_unchecked(&sbi->s_bal_breaks),
59354+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59355 ext4_msg(sb, KERN_INFO,
59356 "mballoc: %lu generated and it took %Lu",
59357 sbi->s_mb_buddies_generated,
59358 sbi->s_mb_generation_time);
59359 ext4_msg(sb, KERN_INFO,
59360 "mballoc: %u preallocated, %u discarded",
59361- atomic_read(&sbi->s_mb_preallocated),
59362- atomic_read(&sbi->s_mb_discarded));
59363+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59364+ atomic_read_unchecked(&sbi->s_mb_discarded));
59365 }
59366
59367 free_percpu(sbi->s_locality_groups);
59368@@ -3179,16 +3179,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59369 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59370
59371 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59372- atomic_inc(&sbi->s_bal_reqs);
59373- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59374+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59375+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59376 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59377- atomic_inc(&sbi->s_bal_success);
59378- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59379+ atomic_inc_unchecked(&sbi->s_bal_success);
59380+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59381 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59382 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59383- atomic_inc(&sbi->s_bal_goals);
59384+ atomic_inc_unchecked(&sbi->s_bal_goals);
59385 if (ac->ac_found > sbi->s_mb_max_to_scan)
59386- atomic_inc(&sbi->s_bal_breaks);
59387+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59388 }
59389
59390 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59391@@ -3593,7 +3593,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59392 trace_ext4_mb_new_inode_pa(ac, pa);
59393
59394 ext4_mb_use_inode_pa(ac, pa);
59395- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59396+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59397
59398 ei = EXT4_I(ac->ac_inode);
59399 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59400@@ -3653,7 +3653,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59401 trace_ext4_mb_new_group_pa(ac, pa);
59402
59403 ext4_mb_use_group_pa(ac, pa);
59404- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59405+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59406
59407 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59408 lg = ac->ac_lg;
59409@@ -3742,7 +3742,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59410 * from the bitmap and continue.
59411 */
59412 }
59413- atomic_add(free, &sbi->s_mb_discarded);
59414+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59415
59416 return err;
59417 }
59418@@ -3760,7 +3760,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59419 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59420 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59421 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59422- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59423+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59424 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59425
59426 return 0;
59427diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59428index 04434ad..6404663 100644
59429--- a/fs/ext4/mmp.c
59430+++ b/fs/ext4/mmp.c
59431@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59432 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59433 const char *function, unsigned int line, const char *msg)
59434 {
59435- __ext4_warning(sb, function, line, msg);
59436+ __ext4_warning(sb, function, line, "%s", msg);
59437 __ext4_warning(sb, function, line,
59438 "MMP failure info: last update time: %llu, last update "
59439 "node: %s, last update device: %s\n",
59440diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59441index 6f9e6fa..5431c02 100644
59442--- a/fs/ext4/super.c
59443+++ b/fs/ext4/super.c
59444@@ -1275,7 +1275,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59445 }
59446
59447 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59448-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59449+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59450 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59451
59452 #ifdef CONFIG_QUOTA
59453@@ -2455,7 +2455,7 @@ struct ext4_attr {
59454 int offset;
59455 int deprecated_val;
59456 } u;
59457-};
59458+} __do_const;
59459
59460 static int parse_strtoull(const char *buf,
59461 unsigned long long max, unsigned long long *value)
59462diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59463index 4eec399..1d9444c 100644
59464--- a/fs/ext4/xattr.c
59465+++ b/fs/ext4/xattr.c
59466@@ -383,7 +383,7 @@ static int
59467 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59468 char *buffer, size_t buffer_size)
59469 {
59470- size_t rest = buffer_size;
59471+ size_t rest = buffer_size, total_size = 0;
59472
59473 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59474 const struct xattr_handler *handler =
59475@@ -400,9 +400,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59476 buffer += size;
59477 }
59478 rest -= size;
59479+ total_size += size;
59480 }
59481 }
59482- return buffer_size - rest;
59483+ return total_size;
59484 }
59485
59486 static int
59487diff --git a/fs/fcntl.c b/fs/fcntl.c
59488index 72c82f6..a18b263 100644
59489--- a/fs/fcntl.c
59490+++ b/fs/fcntl.c
59491@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59492 if (err)
59493 return err;
59494
59495+ if (gr_handle_chroot_fowner(pid, type))
59496+ return -ENOENT;
59497+ if (gr_check_protected_task_fowner(pid, type))
59498+ return -EACCES;
59499+
59500 f_modown(filp, pid, type, force);
59501 return 0;
59502 }
59503diff --git a/fs/fhandle.c b/fs/fhandle.c
59504index 999ff5c..ac037c9 100644
59505--- a/fs/fhandle.c
59506+++ b/fs/fhandle.c
59507@@ -8,6 +8,7 @@
59508 #include <linux/fs_struct.h>
59509 #include <linux/fsnotify.h>
59510 #include <linux/personality.h>
59511+#include <linux/grsecurity.h>
59512 #include <asm/uaccess.h>
59513 #include "internal.h"
59514 #include "mount.h"
59515@@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
59516 } else
59517 retval = 0;
59518 /* copy the mount id */
59519- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59520- sizeof(*mnt_id)) ||
59521+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59522 copy_to_user(ufh, handle,
59523 sizeof(struct file_handle) + handle_bytes))
59524 retval = -EFAULT;
59525@@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
59526 * the directory. Ideally we would like CAP_DAC_SEARCH.
59527 * But we don't have that
59528 */
59529- if (!capable(CAP_DAC_READ_SEARCH)) {
59530+ if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
59531 retval = -EPERM;
59532 goto out_err;
59533 }
59534diff --git a/fs/file.c b/fs/file.c
59535index 8f294cf..d0f3872 100644
59536--- a/fs/file.c
59537+++ b/fs/file.c
59538@@ -16,6 +16,7 @@
59539 #include <linux/slab.h>
59540 #include <linux/vmalloc.h>
59541 #include <linux/file.h>
59542+#include <linux/security.h>
59543 #include <linux/fdtable.h>
59544 #include <linux/bitops.h>
59545 #include <linux/interrupt.h>
59546@@ -144,7 +145,7 @@ out:
59547 * Return <0 error code on error; 1 on successful completion.
59548 * The files->file_lock should be held on entry, and will be held on exit.
59549 */
59550-static int expand_fdtable(struct files_struct *files, int nr)
59551+static int expand_fdtable(struct files_struct *files, unsigned int nr)
59552 __releases(files->file_lock)
59553 __acquires(files->file_lock)
59554 {
59555@@ -189,7 +190,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59556 * expanded and execution may have blocked.
59557 * The files->file_lock should be held on entry, and will be held on exit.
59558 */
59559-static int expand_files(struct files_struct *files, int nr)
59560+static int expand_files(struct files_struct *files, unsigned int nr)
59561 {
59562 struct fdtable *fdt;
59563
59564@@ -804,6 +805,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59565 if (!file)
59566 return __close_fd(files, fd);
59567
59568+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59569 if (fd >= rlimit(RLIMIT_NOFILE))
59570 return -EBADF;
59571
59572@@ -830,6 +832,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59573 if (unlikely(oldfd == newfd))
59574 return -EINVAL;
59575
59576+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59577 if (newfd >= rlimit(RLIMIT_NOFILE))
59578 return -EBADF;
59579
59580@@ -885,6 +888,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59581 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59582 {
59583 int err;
59584+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59585 if (from >= rlimit(RLIMIT_NOFILE))
59586 return -EINVAL;
59587 err = alloc_fd(from, flags);
59588diff --git a/fs/filesystems.c b/fs/filesystems.c
59589index 5797d45..7d7d79a 100644
59590--- a/fs/filesystems.c
59591+++ b/fs/filesystems.c
59592@@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
59593 int len = dot ? dot - name : strlen(name);
59594
59595 fs = __get_fs_type(name, len);
59596+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59597+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59598+#else
59599 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59600+#endif
59601 fs = __get_fs_type(name, len);
59602
59603 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59604diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59605index 7dca743..543d620 100644
59606--- a/fs/fs_struct.c
59607+++ b/fs/fs_struct.c
59608@@ -4,6 +4,7 @@
59609 #include <linux/path.h>
59610 #include <linux/slab.h>
59611 #include <linux/fs_struct.h>
59612+#include <linux/grsecurity.h>
59613 #include "internal.h"
59614
59615 /*
59616@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59617 write_seqcount_begin(&fs->seq);
59618 old_root = fs->root;
59619 fs->root = *path;
59620+ gr_set_chroot_entries(current, path);
59621 write_seqcount_end(&fs->seq);
59622 spin_unlock(&fs->lock);
59623 if (old_root.dentry)
59624@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59625 int hits = 0;
59626 spin_lock(&fs->lock);
59627 write_seqcount_begin(&fs->seq);
59628+ /* this root replacement is only done by pivot_root,
59629+ leave grsec's chroot tagging alone for this task
59630+ so that a pivoted root isn't treated as a chroot
59631+ */
59632 hits += replace_path(&fs->root, old_root, new_root);
59633 hits += replace_path(&fs->pwd, old_root, new_root);
59634 write_seqcount_end(&fs->seq);
59635@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59636 task_lock(tsk);
59637 spin_lock(&fs->lock);
59638 tsk->fs = NULL;
59639- kill = !--fs->users;
59640+ gr_clear_chroot_entries(tsk);
59641+ kill = !atomic_dec_return(&fs->users);
59642 spin_unlock(&fs->lock);
59643 task_unlock(tsk);
59644 if (kill)
59645@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59646 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59647 /* We don't need to lock fs - think why ;-) */
59648 if (fs) {
59649- fs->users = 1;
59650+ atomic_set(&fs->users, 1);
59651 fs->in_exec = 0;
59652 spin_lock_init(&fs->lock);
59653 seqcount_init(&fs->seq);
59654@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59655 spin_lock(&old->lock);
59656 fs->root = old->root;
59657 path_get(&fs->root);
59658+ /* instead of calling gr_set_chroot_entries here,
59659+ we call it from every caller of this function
59660+ */
59661 fs->pwd = old->pwd;
59662 path_get(&fs->pwd);
59663 spin_unlock(&old->lock);
59664@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59665
59666 task_lock(current);
59667 spin_lock(&fs->lock);
59668- kill = !--fs->users;
59669+ kill = !atomic_dec_return(&fs->users);
59670 current->fs = new_fs;
59671+ gr_set_chroot_entries(current, &new_fs->root);
59672 spin_unlock(&fs->lock);
59673 task_unlock(current);
59674
59675@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59676
59677 int current_umask(void)
59678 {
59679- return current->fs->umask;
59680+ return current->fs->umask | gr_acl_umask();
59681 }
59682 EXPORT_SYMBOL(current_umask);
59683
59684 /* to be mentioned only in INIT_TASK */
59685 struct fs_struct init_fs = {
59686- .users = 1,
59687+ .users = ATOMIC_INIT(1),
59688 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59689 .seq = SEQCNT_ZERO(init_fs.seq),
59690 .umask = 0022,
59691diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59692index 29d7feb..303644d 100644
59693--- a/fs/fscache/cookie.c
59694+++ b/fs/fscache/cookie.c
59695@@ -19,7 +19,7 @@
59696
59697 struct kmem_cache *fscache_cookie_jar;
59698
59699-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59700+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59701
59702 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59703 static int fscache_alloc_object(struct fscache_cache *cache,
59704@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59705 parent ? (char *) parent->def->name : "<no-parent>",
59706 def->name, netfs_data, enable);
59707
59708- fscache_stat(&fscache_n_acquires);
59709+ fscache_stat_unchecked(&fscache_n_acquires);
59710
59711 /* if there's no parent cookie, then we don't create one here either */
59712 if (!parent) {
59713- fscache_stat(&fscache_n_acquires_null);
59714+ fscache_stat_unchecked(&fscache_n_acquires_null);
59715 _leave(" [no parent]");
59716 return NULL;
59717 }
59718@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59719 /* allocate and initialise a cookie */
59720 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59721 if (!cookie) {
59722- fscache_stat(&fscache_n_acquires_oom);
59723+ fscache_stat_unchecked(&fscache_n_acquires_oom);
59724 _leave(" [ENOMEM]");
59725 return NULL;
59726 }
59727@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59728
59729 switch (cookie->def->type) {
59730 case FSCACHE_COOKIE_TYPE_INDEX:
59731- fscache_stat(&fscache_n_cookie_index);
59732+ fscache_stat_unchecked(&fscache_n_cookie_index);
59733 break;
59734 case FSCACHE_COOKIE_TYPE_DATAFILE:
59735- fscache_stat(&fscache_n_cookie_data);
59736+ fscache_stat_unchecked(&fscache_n_cookie_data);
59737 break;
59738 default:
59739- fscache_stat(&fscache_n_cookie_special);
59740+ fscache_stat_unchecked(&fscache_n_cookie_special);
59741 break;
59742 }
59743
59744@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59745 } else {
59746 atomic_dec(&parent->n_children);
59747 __fscache_cookie_put(cookie);
59748- fscache_stat(&fscache_n_acquires_nobufs);
59749+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59750 _leave(" = NULL");
59751 return NULL;
59752 }
59753@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59754 }
59755 }
59756
59757- fscache_stat(&fscache_n_acquires_ok);
59758+ fscache_stat_unchecked(&fscache_n_acquires_ok);
59759 _leave(" = %p", cookie);
59760 return cookie;
59761 }
59762@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59763 cache = fscache_select_cache_for_object(cookie->parent);
59764 if (!cache) {
59765 up_read(&fscache_addremove_sem);
59766- fscache_stat(&fscache_n_acquires_no_cache);
59767+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59768 _leave(" = -ENOMEDIUM [no cache]");
59769 return -ENOMEDIUM;
59770 }
59771@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59772 object = cache->ops->alloc_object(cache, cookie);
59773 fscache_stat_d(&fscache_n_cop_alloc_object);
59774 if (IS_ERR(object)) {
59775- fscache_stat(&fscache_n_object_no_alloc);
59776+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
59777 ret = PTR_ERR(object);
59778 goto error;
59779 }
59780
59781- fscache_stat(&fscache_n_object_alloc);
59782+ fscache_stat_unchecked(&fscache_n_object_alloc);
59783
59784- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59785+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59786
59787 _debug("ALLOC OBJ%x: %s {%lx}",
59788 object->debug_id, cookie->def->name, object->events);
59789@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59790
59791 _enter("{%s}", cookie->def->name);
59792
59793- fscache_stat(&fscache_n_invalidates);
59794+ fscache_stat_unchecked(&fscache_n_invalidates);
59795
59796 /* Only permit invalidation of data files. Invalidating an index will
59797 * require the caller to release all its attachments to the tree rooted
59798@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59799 {
59800 struct fscache_object *object;
59801
59802- fscache_stat(&fscache_n_updates);
59803+ fscache_stat_unchecked(&fscache_n_updates);
59804
59805 if (!cookie) {
59806- fscache_stat(&fscache_n_updates_null);
59807+ fscache_stat_unchecked(&fscache_n_updates_null);
59808 _leave(" [no cookie]");
59809 return;
59810 }
59811@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59812 */
59813 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59814 {
59815- fscache_stat(&fscache_n_relinquishes);
59816+ fscache_stat_unchecked(&fscache_n_relinquishes);
59817 if (retire)
59818- fscache_stat(&fscache_n_relinquishes_retire);
59819+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59820
59821 if (!cookie) {
59822- fscache_stat(&fscache_n_relinquishes_null);
59823+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
59824 _leave(" [no cookie]");
59825 return;
59826 }
59827@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59828 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59829 goto inconsistent;
59830
59831- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59832+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59833
59834 __fscache_use_cookie(cookie);
59835 if (fscache_submit_op(object, op) < 0)
59836diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59837index 4226f66..0fb3f45 100644
59838--- a/fs/fscache/internal.h
59839+++ b/fs/fscache/internal.h
59840@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59841 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59842 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59843 struct fscache_operation *,
59844- atomic_t *,
59845- atomic_t *,
59846+ atomic_unchecked_t *,
59847+ atomic_unchecked_t *,
59848 void (*)(struct fscache_operation *));
59849 extern void fscache_invalidate_writes(struct fscache_cookie *);
59850
59851@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59852 * stats.c
59853 */
59854 #ifdef CONFIG_FSCACHE_STATS
59855-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59856-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59857+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59858+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59859
59860-extern atomic_t fscache_n_op_pend;
59861-extern atomic_t fscache_n_op_run;
59862-extern atomic_t fscache_n_op_enqueue;
59863-extern atomic_t fscache_n_op_deferred_release;
59864-extern atomic_t fscache_n_op_release;
59865-extern atomic_t fscache_n_op_gc;
59866-extern atomic_t fscache_n_op_cancelled;
59867-extern atomic_t fscache_n_op_rejected;
59868+extern atomic_unchecked_t fscache_n_op_pend;
59869+extern atomic_unchecked_t fscache_n_op_run;
59870+extern atomic_unchecked_t fscache_n_op_enqueue;
59871+extern atomic_unchecked_t fscache_n_op_deferred_release;
59872+extern atomic_unchecked_t fscache_n_op_release;
59873+extern atomic_unchecked_t fscache_n_op_gc;
59874+extern atomic_unchecked_t fscache_n_op_cancelled;
59875+extern atomic_unchecked_t fscache_n_op_rejected;
59876
59877-extern atomic_t fscache_n_attr_changed;
59878-extern atomic_t fscache_n_attr_changed_ok;
59879-extern atomic_t fscache_n_attr_changed_nobufs;
59880-extern atomic_t fscache_n_attr_changed_nomem;
59881-extern atomic_t fscache_n_attr_changed_calls;
59882+extern atomic_unchecked_t fscache_n_attr_changed;
59883+extern atomic_unchecked_t fscache_n_attr_changed_ok;
59884+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59885+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59886+extern atomic_unchecked_t fscache_n_attr_changed_calls;
59887
59888-extern atomic_t fscache_n_allocs;
59889-extern atomic_t fscache_n_allocs_ok;
59890-extern atomic_t fscache_n_allocs_wait;
59891-extern atomic_t fscache_n_allocs_nobufs;
59892-extern atomic_t fscache_n_allocs_intr;
59893-extern atomic_t fscache_n_allocs_object_dead;
59894-extern atomic_t fscache_n_alloc_ops;
59895-extern atomic_t fscache_n_alloc_op_waits;
59896+extern atomic_unchecked_t fscache_n_allocs;
59897+extern atomic_unchecked_t fscache_n_allocs_ok;
59898+extern atomic_unchecked_t fscache_n_allocs_wait;
59899+extern atomic_unchecked_t fscache_n_allocs_nobufs;
59900+extern atomic_unchecked_t fscache_n_allocs_intr;
59901+extern atomic_unchecked_t fscache_n_allocs_object_dead;
59902+extern atomic_unchecked_t fscache_n_alloc_ops;
59903+extern atomic_unchecked_t fscache_n_alloc_op_waits;
59904
59905-extern atomic_t fscache_n_retrievals;
59906-extern atomic_t fscache_n_retrievals_ok;
59907-extern atomic_t fscache_n_retrievals_wait;
59908-extern atomic_t fscache_n_retrievals_nodata;
59909-extern atomic_t fscache_n_retrievals_nobufs;
59910-extern atomic_t fscache_n_retrievals_intr;
59911-extern atomic_t fscache_n_retrievals_nomem;
59912-extern atomic_t fscache_n_retrievals_object_dead;
59913-extern atomic_t fscache_n_retrieval_ops;
59914-extern atomic_t fscache_n_retrieval_op_waits;
59915+extern atomic_unchecked_t fscache_n_retrievals;
59916+extern atomic_unchecked_t fscache_n_retrievals_ok;
59917+extern atomic_unchecked_t fscache_n_retrievals_wait;
59918+extern atomic_unchecked_t fscache_n_retrievals_nodata;
59919+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59920+extern atomic_unchecked_t fscache_n_retrievals_intr;
59921+extern atomic_unchecked_t fscache_n_retrievals_nomem;
59922+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59923+extern atomic_unchecked_t fscache_n_retrieval_ops;
59924+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59925
59926-extern atomic_t fscache_n_stores;
59927-extern atomic_t fscache_n_stores_ok;
59928-extern atomic_t fscache_n_stores_again;
59929-extern atomic_t fscache_n_stores_nobufs;
59930-extern atomic_t fscache_n_stores_oom;
59931-extern atomic_t fscache_n_store_ops;
59932-extern atomic_t fscache_n_store_calls;
59933-extern atomic_t fscache_n_store_pages;
59934-extern atomic_t fscache_n_store_radix_deletes;
59935-extern atomic_t fscache_n_store_pages_over_limit;
59936+extern atomic_unchecked_t fscache_n_stores;
59937+extern atomic_unchecked_t fscache_n_stores_ok;
59938+extern atomic_unchecked_t fscache_n_stores_again;
59939+extern atomic_unchecked_t fscache_n_stores_nobufs;
59940+extern atomic_unchecked_t fscache_n_stores_oom;
59941+extern atomic_unchecked_t fscache_n_store_ops;
59942+extern atomic_unchecked_t fscache_n_store_calls;
59943+extern atomic_unchecked_t fscache_n_store_pages;
59944+extern atomic_unchecked_t fscache_n_store_radix_deletes;
59945+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
59946
59947-extern atomic_t fscache_n_store_vmscan_not_storing;
59948-extern atomic_t fscache_n_store_vmscan_gone;
59949-extern atomic_t fscache_n_store_vmscan_busy;
59950-extern atomic_t fscache_n_store_vmscan_cancelled;
59951-extern atomic_t fscache_n_store_vmscan_wait;
59952+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59953+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
59954+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
59955+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59956+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
59957
59958-extern atomic_t fscache_n_marks;
59959-extern atomic_t fscache_n_uncaches;
59960+extern atomic_unchecked_t fscache_n_marks;
59961+extern atomic_unchecked_t fscache_n_uncaches;
59962
59963-extern atomic_t fscache_n_acquires;
59964-extern atomic_t fscache_n_acquires_null;
59965-extern atomic_t fscache_n_acquires_no_cache;
59966-extern atomic_t fscache_n_acquires_ok;
59967-extern atomic_t fscache_n_acquires_nobufs;
59968-extern atomic_t fscache_n_acquires_oom;
59969+extern atomic_unchecked_t fscache_n_acquires;
59970+extern atomic_unchecked_t fscache_n_acquires_null;
59971+extern atomic_unchecked_t fscache_n_acquires_no_cache;
59972+extern atomic_unchecked_t fscache_n_acquires_ok;
59973+extern atomic_unchecked_t fscache_n_acquires_nobufs;
59974+extern atomic_unchecked_t fscache_n_acquires_oom;
59975
59976-extern atomic_t fscache_n_invalidates;
59977-extern atomic_t fscache_n_invalidates_run;
59978+extern atomic_unchecked_t fscache_n_invalidates;
59979+extern atomic_unchecked_t fscache_n_invalidates_run;
59980
59981-extern atomic_t fscache_n_updates;
59982-extern atomic_t fscache_n_updates_null;
59983-extern atomic_t fscache_n_updates_run;
59984+extern atomic_unchecked_t fscache_n_updates;
59985+extern atomic_unchecked_t fscache_n_updates_null;
59986+extern atomic_unchecked_t fscache_n_updates_run;
59987
59988-extern atomic_t fscache_n_relinquishes;
59989-extern atomic_t fscache_n_relinquishes_null;
59990-extern atomic_t fscache_n_relinquishes_waitcrt;
59991-extern atomic_t fscache_n_relinquishes_retire;
59992+extern atomic_unchecked_t fscache_n_relinquishes;
59993+extern atomic_unchecked_t fscache_n_relinquishes_null;
59994+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59995+extern atomic_unchecked_t fscache_n_relinquishes_retire;
59996
59997-extern atomic_t fscache_n_cookie_index;
59998-extern atomic_t fscache_n_cookie_data;
59999-extern atomic_t fscache_n_cookie_special;
60000+extern atomic_unchecked_t fscache_n_cookie_index;
60001+extern atomic_unchecked_t fscache_n_cookie_data;
60002+extern atomic_unchecked_t fscache_n_cookie_special;
60003
60004-extern atomic_t fscache_n_object_alloc;
60005-extern atomic_t fscache_n_object_no_alloc;
60006-extern atomic_t fscache_n_object_lookups;
60007-extern atomic_t fscache_n_object_lookups_negative;
60008-extern atomic_t fscache_n_object_lookups_positive;
60009-extern atomic_t fscache_n_object_lookups_timed_out;
60010-extern atomic_t fscache_n_object_created;
60011-extern atomic_t fscache_n_object_avail;
60012-extern atomic_t fscache_n_object_dead;
60013+extern atomic_unchecked_t fscache_n_object_alloc;
60014+extern atomic_unchecked_t fscache_n_object_no_alloc;
60015+extern atomic_unchecked_t fscache_n_object_lookups;
60016+extern atomic_unchecked_t fscache_n_object_lookups_negative;
60017+extern atomic_unchecked_t fscache_n_object_lookups_positive;
60018+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60019+extern atomic_unchecked_t fscache_n_object_created;
60020+extern atomic_unchecked_t fscache_n_object_avail;
60021+extern atomic_unchecked_t fscache_n_object_dead;
60022
60023-extern atomic_t fscache_n_checkaux_none;
60024-extern atomic_t fscache_n_checkaux_okay;
60025-extern atomic_t fscache_n_checkaux_update;
60026-extern atomic_t fscache_n_checkaux_obsolete;
60027+extern atomic_unchecked_t fscache_n_checkaux_none;
60028+extern atomic_unchecked_t fscache_n_checkaux_okay;
60029+extern atomic_unchecked_t fscache_n_checkaux_update;
60030+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60031
60032 extern atomic_t fscache_n_cop_alloc_object;
60033 extern atomic_t fscache_n_cop_lookup_object;
60034@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60035 atomic_inc(stat);
60036 }
60037
60038+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60039+{
60040+ atomic_inc_unchecked(stat);
60041+}
60042+
60043 static inline void fscache_stat_d(atomic_t *stat)
60044 {
60045 atomic_dec(stat);
60046@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60047
60048 #define __fscache_stat(stat) (NULL)
60049 #define fscache_stat(stat) do {} while (0)
60050+#define fscache_stat_unchecked(stat) do {} while (0)
60051 #define fscache_stat_d(stat) do {} while (0)
60052 #endif
60053
60054diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60055index d3b4539..ed0c659 100644
60056--- a/fs/fscache/object.c
60057+++ b/fs/fscache/object.c
60058@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60059 _debug("LOOKUP \"%s\" in \"%s\"",
60060 cookie->def->name, object->cache->tag->name);
60061
60062- fscache_stat(&fscache_n_object_lookups);
60063+ fscache_stat_unchecked(&fscache_n_object_lookups);
60064 fscache_stat(&fscache_n_cop_lookup_object);
60065 ret = object->cache->ops->lookup_object(object);
60066 fscache_stat_d(&fscache_n_cop_lookup_object);
60067@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60068 if (ret == -ETIMEDOUT) {
60069 /* probably stuck behind another object, so move this one to
60070 * the back of the queue */
60071- fscache_stat(&fscache_n_object_lookups_timed_out);
60072+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60073 _leave(" [timeout]");
60074 return NO_TRANSIT;
60075 }
60076@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60077 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60078
60079 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60080- fscache_stat(&fscache_n_object_lookups_negative);
60081+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60082
60083 /* Allow write requests to begin stacking up and read requests to begin
60084 * returning ENODATA.
60085@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60086 /* if we were still looking up, then we must have a positive lookup
60087 * result, in which case there may be data available */
60088 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60089- fscache_stat(&fscache_n_object_lookups_positive);
60090+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60091
60092 /* We do (presumably) have data */
60093 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60094@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60095 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60096 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60097 } else {
60098- fscache_stat(&fscache_n_object_created);
60099+ fscache_stat_unchecked(&fscache_n_object_created);
60100 }
60101
60102 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60103@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60104 fscache_stat_d(&fscache_n_cop_lookup_complete);
60105
60106 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60107- fscache_stat(&fscache_n_object_avail);
60108+ fscache_stat_unchecked(&fscache_n_object_avail);
60109
60110 _leave("");
60111 return transit_to(JUMPSTART_DEPS);
60112@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60113
60114 /* this just shifts the object release to the work processor */
60115 fscache_put_object(object);
60116- fscache_stat(&fscache_n_object_dead);
60117+ fscache_stat_unchecked(&fscache_n_object_dead);
60118
60119 _leave("");
60120 return transit_to(OBJECT_DEAD);
60121@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60122 enum fscache_checkaux result;
60123
60124 if (!object->cookie->def->check_aux) {
60125- fscache_stat(&fscache_n_checkaux_none);
60126+ fscache_stat_unchecked(&fscache_n_checkaux_none);
60127 return FSCACHE_CHECKAUX_OKAY;
60128 }
60129
60130@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60131 switch (result) {
60132 /* entry okay as is */
60133 case FSCACHE_CHECKAUX_OKAY:
60134- fscache_stat(&fscache_n_checkaux_okay);
60135+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
60136 break;
60137
60138 /* entry requires update */
60139 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60140- fscache_stat(&fscache_n_checkaux_update);
60141+ fscache_stat_unchecked(&fscache_n_checkaux_update);
60142 break;
60143
60144 /* entry requires deletion */
60145 case FSCACHE_CHECKAUX_OBSOLETE:
60146- fscache_stat(&fscache_n_checkaux_obsolete);
60147+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60148 break;
60149
60150 default:
60151@@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60152 {
60153 const struct fscache_state *s;
60154
60155- fscache_stat(&fscache_n_invalidates_run);
60156+ fscache_stat_unchecked(&fscache_n_invalidates_run);
60157 fscache_stat(&fscache_n_cop_invalidate_object);
60158 s = _fscache_invalidate_object(object, event);
60159 fscache_stat_d(&fscache_n_cop_invalidate_object);
60160@@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60161 {
60162 _enter("{OBJ%x},%d", object->debug_id, event);
60163
60164- fscache_stat(&fscache_n_updates_run);
60165+ fscache_stat_unchecked(&fscache_n_updates_run);
60166 fscache_stat(&fscache_n_cop_update_object);
60167 object->cache->ops->update_object(object);
60168 fscache_stat_d(&fscache_n_cop_update_object);
60169diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60170index 318071a..379938b 100644
60171--- a/fs/fscache/operation.c
60172+++ b/fs/fscache/operation.c
60173@@ -17,7 +17,7 @@
60174 #include <linux/slab.h>
60175 #include "internal.h"
60176
60177-atomic_t fscache_op_debug_id;
60178+atomic_unchecked_t fscache_op_debug_id;
60179 EXPORT_SYMBOL(fscache_op_debug_id);
60180
60181 /**
60182@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60183 ASSERTCMP(atomic_read(&op->usage), >, 0);
60184 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60185
60186- fscache_stat(&fscache_n_op_enqueue);
60187+ fscache_stat_unchecked(&fscache_n_op_enqueue);
60188 switch (op->flags & FSCACHE_OP_TYPE) {
60189 case FSCACHE_OP_ASYNC:
60190 _debug("queue async");
60191@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60192 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60193 if (op->processor)
60194 fscache_enqueue_operation(op);
60195- fscache_stat(&fscache_n_op_run);
60196+ fscache_stat_unchecked(&fscache_n_op_run);
60197 }
60198
60199 /*
60200@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60201 if (object->n_in_progress > 0) {
60202 atomic_inc(&op->usage);
60203 list_add_tail(&op->pend_link, &object->pending_ops);
60204- fscache_stat(&fscache_n_op_pend);
60205+ fscache_stat_unchecked(&fscache_n_op_pend);
60206 } else if (!list_empty(&object->pending_ops)) {
60207 atomic_inc(&op->usage);
60208 list_add_tail(&op->pend_link, &object->pending_ops);
60209- fscache_stat(&fscache_n_op_pend);
60210+ fscache_stat_unchecked(&fscache_n_op_pend);
60211 fscache_start_operations(object);
60212 } else {
60213 ASSERTCMP(object->n_in_progress, ==, 0);
60214@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60215 object->n_exclusive++; /* reads and writes must wait */
60216 atomic_inc(&op->usage);
60217 list_add_tail(&op->pend_link, &object->pending_ops);
60218- fscache_stat(&fscache_n_op_pend);
60219+ fscache_stat_unchecked(&fscache_n_op_pend);
60220 ret = 0;
60221 } else {
60222 /* If we're in any other state, there must have been an I/O
60223@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60224 if (object->n_exclusive > 0) {
60225 atomic_inc(&op->usage);
60226 list_add_tail(&op->pend_link, &object->pending_ops);
60227- fscache_stat(&fscache_n_op_pend);
60228+ fscache_stat_unchecked(&fscache_n_op_pend);
60229 } else if (!list_empty(&object->pending_ops)) {
60230 atomic_inc(&op->usage);
60231 list_add_tail(&op->pend_link, &object->pending_ops);
60232- fscache_stat(&fscache_n_op_pend);
60233+ fscache_stat_unchecked(&fscache_n_op_pend);
60234 fscache_start_operations(object);
60235 } else {
60236 ASSERTCMP(object->n_exclusive, ==, 0);
60237@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60238 object->n_ops++;
60239 atomic_inc(&op->usage);
60240 list_add_tail(&op->pend_link, &object->pending_ops);
60241- fscache_stat(&fscache_n_op_pend);
60242+ fscache_stat_unchecked(&fscache_n_op_pend);
60243 ret = 0;
60244 } else if (fscache_object_is_dying(object)) {
60245- fscache_stat(&fscache_n_op_rejected);
60246+ fscache_stat_unchecked(&fscache_n_op_rejected);
60247 op->state = FSCACHE_OP_ST_CANCELLED;
60248 ret = -ENOBUFS;
60249 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60250@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60251 ret = -EBUSY;
60252 if (op->state == FSCACHE_OP_ST_PENDING) {
60253 ASSERT(!list_empty(&op->pend_link));
60254- fscache_stat(&fscache_n_op_cancelled);
60255+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60256 list_del_init(&op->pend_link);
60257 if (do_cancel)
60258 do_cancel(op);
60259@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60260 while (!list_empty(&object->pending_ops)) {
60261 op = list_entry(object->pending_ops.next,
60262 struct fscache_operation, pend_link);
60263- fscache_stat(&fscache_n_op_cancelled);
60264+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60265 list_del_init(&op->pend_link);
60266
60267 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60268@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60269 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60270 op->state = FSCACHE_OP_ST_DEAD;
60271
60272- fscache_stat(&fscache_n_op_release);
60273+ fscache_stat_unchecked(&fscache_n_op_release);
60274
60275 if (op->release) {
60276 op->release(op);
60277@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60278 * lock, and defer it otherwise */
60279 if (!spin_trylock(&object->lock)) {
60280 _debug("defer put");
60281- fscache_stat(&fscache_n_op_deferred_release);
60282+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60283
60284 cache = object->cache;
60285 spin_lock(&cache->op_gc_list_lock);
60286@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60287
60288 _debug("GC DEFERRED REL OBJ%x OP%x",
60289 object->debug_id, op->debug_id);
60290- fscache_stat(&fscache_n_op_gc);
60291+ fscache_stat_unchecked(&fscache_n_op_gc);
60292
60293 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60294 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60295diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60296index 7f5c658..6c1e164 100644
60297--- a/fs/fscache/page.c
60298+++ b/fs/fscache/page.c
60299@@ -61,7 +61,7 @@ try_again:
60300 val = radix_tree_lookup(&cookie->stores, page->index);
60301 if (!val) {
60302 rcu_read_unlock();
60303- fscache_stat(&fscache_n_store_vmscan_not_storing);
60304+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60305 __fscache_uncache_page(cookie, page);
60306 return true;
60307 }
60308@@ -91,11 +91,11 @@ try_again:
60309 spin_unlock(&cookie->stores_lock);
60310
60311 if (xpage) {
60312- fscache_stat(&fscache_n_store_vmscan_cancelled);
60313- fscache_stat(&fscache_n_store_radix_deletes);
60314+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60315+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60316 ASSERTCMP(xpage, ==, page);
60317 } else {
60318- fscache_stat(&fscache_n_store_vmscan_gone);
60319+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60320 }
60321
60322 wake_up_bit(&cookie->flags, 0);
60323@@ -110,11 +110,11 @@ page_busy:
60324 * sleeping on memory allocation, so we may need to impose a timeout
60325 * too. */
60326 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60327- fscache_stat(&fscache_n_store_vmscan_busy);
60328+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60329 return false;
60330 }
60331
60332- fscache_stat(&fscache_n_store_vmscan_wait);
60333+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60334 __fscache_wait_on_page_write(cookie, page);
60335 gfp &= ~__GFP_WAIT;
60336 goto try_again;
60337@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60338 FSCACHE_COOKIE_STORING_TAG);
60339 if (!radix_tree_tag_get(&cookie->stores, page->index,
60340 FSCACHE_COOKIE_PENDING_TAG)) {
60341- fscache_stat(&fscache_n_store_radix_deletes);
60342+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60343 xpage = radix_tree_delete(&cookie->stores, page->index);
60344 }
60345 spin_unlock(&cookie->stores_lock);
60346@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60347
60348 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60349
60350- fscache_stat(&fscache_n_attr_changed_calls);
60351+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60352
60353 if (fscache_object_is_active(object)) {
60354 fscache_stat(&fscache_n_cop_attr_changed);
60355@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60356
60357 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60358
60359- fscache_stat(&fscache_n_attr_changed);
60360+ fscache_stat_unchecked(&fscache_n_attr_changed);
60361
60362 op = kzalloc(sizeof(*op), GFP_KERNEL);
60363 if (!op) {
60364- fscache_stat(&fscache_n_attr_changed_nomem);
60365+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60366 _leave(" = -ENOMEM");
60367 return -ENOMEM;
60368 }
60369@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60370 if (fscache_submit_exclusive_op(object, op) < 0)
60371 goto nobufs;
60372 spin_unlock(&cookie->lock);
60373- fscache_stat(&fscache_n_attr_changed_ok);
60374+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60375 fscache_put_operation(op);
60376 _leave(" = 0");
60377 return 0;
60378@@ -225,7 +225,7 @@ nobufs:
60379 kfree(op);
60380 if (wake_cookie)
60381 __fscache_wake_unused_cookie(cookie);
60382- fscache_stat(&fscache_n_attr_changed_nobufs);
60383+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60384 _leave(" = %d", -ENOBUFS);
60385 return -ENOBUFS;
60386 }
60387@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60388 /* allocate a retrieval operation and attempt to submit it */
60389 op = kzalloc(sizeof(*op), GFP_NOIO);
60390 if (!op) {
60391- fscache_stat(&fscache_n_retrievals_nomem);
60392+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60393 return NULL;
60394 }
60395
60396@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60397 return 0;
60398 }
60399
60400- fscache_stat(&fscache_n_retrievals_wait);
60401+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60402
60403 jif = jiffies;
60404 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60405 fscache_wait_bit_interruptible,
60406 TASK_INTERRUPTIBLE) != 0) {
60407- fscache_stat(&fscache_n_retrievals_intr);
60408+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60409 _leave(" = -ERESTARTSYS");
60410 return -ERESTARTSYS;
60411 }
60412@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60413 */
60414 int fscache_wait_for_operation_activation(struct fscache_object *object,
60415 struct fscache_operation *op,
60416- atomic_t *stat_op_waits,
60417- atomic_t *stat_object_dead,
60418+ atomic_unchecked_t *stat_op_waits,
60419+ atomic_unchecked_t *stat_object_dead,
60420 void (*do_cancel)(struct fscache_operation *))
60421 {
60422 int ret;
60423@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60424
60425 _debug(">>> WT");
60426 if (stat_op_waits)
60427- fscache_stat(stat_op_waits);
60428+ fscache_stat_unchecked(stat_op_waits);
60429 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60430 fscache_wait_bit_interruptible,
60431 TASK_INTERRUPTIBLE) != 0) {
60432@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60433 check_if_dead:
60434 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60435 if (stat_object_dead)
60436- fscache_stat(stat_object_dead);
60437+ fscache_stat_unchecked(stat_object_dead);
60438 _leave(" = -ENOBUFS [cancelled]");
60439 return -ENOBUFS;
60440 }
60441@@ -366,7 +366,7 @@ check_if_dead:
60442 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60443 fscache_cancel_op(op, do_cancel);
60444 if (stat_object_dead)
60445- fscache_stat(stat_object_dead);
60446+ fscache_stat_unchecked(stat_object_dead);
60447 return -ENOBUFS;
60448 }
60449 return 0;
60450@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60451
60452 _enter("%p,%p,,,", cookie, page);
60453
60454- fscache_stat(&fscache_n_retrievals);
60455+ fscache_stat_unchecked(&fscache_n_retrievals);
60456
60457 if (hlist_empty(&cookie->backing_objects))
60458 goto nobufs;
60459@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60460 goto nobufs_unlock_dec;
60461 spin_unlock(&cookie->lock);
60462
60463- fscache_stat(&fscache_n_retrieval_ops);
60464+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60465
60466 /* pin the netfs read context in case we need to do the actual netfs
60467 * read because we've encountered a cache read failure */
60468@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60469
60470 error:
60471 if (ret == -ENOMEM)
60472- fscache_stat(&fscache_n_retrievals_nomem);
60473+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60474 else if (ret == -ERESTARTSYS)
60475- fscache_stat(&fscache_n_retrievals_intr);
60476+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60477 else if (ret == -ENODATA)
60478- fscache_stat(&fscache_n_retrievals_nodata);
60479+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60480 else if (ret < 0)
60481- fscache_stat(&fscache_n_retrievals_nobufs);
60482+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60483 else
60484- fscache_stat(&fscache_n_retrievals_ok);
60485+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60486
60487 fscache_put_retrieval(op);
60488 _leave(" = %d", ret);
60489@@ -490,7 +490,7 @@ nobufs_unlock:
60490 __fscache_wake_unused_cookie(cookie);
60491 kfree(op);
60492 nobufs:
60493- fscache_stat(&fscache_n_retrievals_nobufs);
60494+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60495 _leave(" = -ENOBUFS");
60496 return -ENOBUFS;
60497 }
60498@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60499
60500 _enter("%p,,%d,,,", cookie, *nr_pages);
60501
60502- fscache_stat(&fscache_n_retrievals);
60503+ fscache_stat_unchecked(&fscache_n_retrievals);
60504
60505 if (hlist_empty(&cookie->backing_objects))
60506 goto nobufs;
60507@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60508 goto nobufs_unlock_dec;
60509 spin_unlock(&cookie->lock);
60510
60511- fscache_stat(&fscache_n_retrieval_ops);
60512+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60513
60514 /* pin the netfs read context in case we need to do the actual netfs
60515 * read because we've encountered a cache read failure */
60516@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60517
60518 error:
60519 if (ret == -ENOMEM)
60520- fscache_stat(&fscache_n_retrievals_nomem);
60521+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60522 else if (ret == -ERESTARTSYS)
60523- fscache_stat(&fscache_n_retrievals_intr);
60524+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60525 else if (ret == -ENODATA)
60526- fscache_stat(&fscache_n_retrievals_nodata);
60527+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60528 else if (ret < 0)
60529- fscache_stat(&fscache_n_retrievals_nobufs);
60530+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60531 else
60532- fscache_stat(&fscache_n_retrievals_ok);
60533+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60534
60535 fscache_put_retrieval(op);
60536 _leave(" = %d", ret);
60537@@ -621,7 +621,7 @@ nobufs_unlock:
60538 if (wake_cookie)
60539 __fscache_wake_unused_cookie(cookie);
60540 nobufs:
60541- fscache_stat(&fscache_n_retrievals_nobufs);
60542+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60543 _leave(" = -ENOBUFS");
60544 return -ENOBUFS;
60545 }
60546@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60547
60548 _enter("%p,%p,,,", cookie, page);
60549
60550- fscache_stat(&fscache_n_allocs);
60551+ fscache_stat_unchecked(&fscache_n_allocs);
60552
60553 if (hlist_empty(&cookie->backing_objects))
60554 goto nobufs;
60555@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60556 goto nobufs_unlock_dec;
60557 spin_unlock(&cookie->lock);
60558
60559- fscache_stat(&fscache_n_alloc_ops);
60560+ fscache_stat_unchecked(&fscache_n_alloc_ops);
60561
60562 ret = fscache_wait_for_operation_activation(
60563 object, &op->op,
60564@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60565
60566 error:
60567 if (ret == -ERESTARTSYS)
60568- fscache_stat(&fscache_n_allocs_intr);
60569+ fscache_stat_unchecked(&fscache_n_allocs_intr);
60570 else if (ret < 0)
60571- fscache_stat(&fscache_n_allocs_nobufs);
60572+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60573 else
60574- fscache_stat(&fscache_n_allocs_ok);
60575+ fscache_stat_unchecked(&fscache_n_allocs_ok);
60576
60577 fscache_put_retrieval(op);
60578 _leave(" = %d", ret);
60579@@ -715,7 +715,7 @@ nobufs_unlock:
60580 if (wake_cookie)
60581 __fscache_wake_unused_cookie(cookie);
60582 nobufs:
60583- fscache_stat(&fscache_n_allocs_nobufs);
60584+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60585 _leave(" = -ENOBUFS");
60586 return -ENOBUFS;
60587 }
60588@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60589
60590 spin_lock(&cookie->stores_lock);
60591
60592- fscache_stat(&fscache_n_store_calls);
60593+ fscache_stat_unchecked(&fscache_n_store_calls);
60594
60595 /* find a page to store */
60596 page = NULL;
60597@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60598 page = results[0];
60599 _debug("gang %d [%lx]", n, page->index);
60600 if (page->index > op->store_limit) {
60601- fscache_stat(&fscache_n_store_pages_over_limit);
60602+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60603 goto superseded;
60604 }
60605
60606@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60607 spin_unlock(&cookie->stores_lock);
60608 spin_unlock(&object->lock);
60609
60610- fscache_stat(&fscache_n_store_pages);
60611+ fscache_stat_unchecked(&fscache_n_store_pages);
60612 fscache_stat(&fscache_n_cop_write_page);
60613 ret = object->cache->ops->write_page(op, page);
60614 fscache_stat_d(&fscache_n_cop_write_page);
60615@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60616 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60617 ASSERT(PageFsCache(page));
60618
60619- fscache_stat(&fscache_n_stores);
60620+ fscache_stat_unchecked(&fscache_n_stores);
60621
60622 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60623 _leave(" = -ENOBUFS [invalidating]");
60624@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60625 spin_unlock(&cookie->stores_lock);
60626 spin_unlock(&object->lock);
60627
60628- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60629+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60630 op->store_limit = object->store_limit;
60631
60632 __fscache_use_cookie(cookie);
60633@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60634
60635 spin_unlock(&cookie->lock);
60636 radix_tree_preload_end();
60637- fscache_stat(&fscache_n_store_ops);
60638- fscache_stat(&fscache_n_stores_ok);
60639+ fscache_stat_unchecked(&fscache_n_store_ops);
60640+ fscache_stat_unchecked(&fscache_n_stores_ok);
60641
60642 /* the work queue now carries its own ref on the object */
60643 fscache_put_operation(&op->op);
60644@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60645 return 0;
60646
60647 already_queued:
60648- fscache_stat(&fscache_n_stores_again);
60649+ fscache_stat_unchecked(&fscache_n_stores_again);
60650 already_pending:
60651 spin_unlock(&cookie->stores_lock);
60652 spin_unlock(&object->lock);
60653 spin_unlock(&cookie->lock);
60654 radix_tree_preload_end();
60655 kfree(op);
60656- fscache_stat(&fscache_n_stores_ok);
60657+ fscache_stat_unchecked(&fscache_n_stores_ok);
60658 _leave(" = 0");
60659 return 0;
60660
60661@@ -1024,14 +1024,14 @@ nobufs:
60662 kfree(op);
60663 if (wake_cookie)
60664 __fscache_wake_unused_cookie(cookie);
60665- fscache_stat(&fscache_n_stores_nobufs);
60666+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
60667 _leave(" = -ENOBUFS");
60668 return -ENOBUFS;
60669
60670 nomem_free:
60671 kfree(op);
60672 nomem:
60673- fscache_stat(&fscache_n_stores_oom);
60674+ fscache_stat_unchecked(&fscache_n_stores_oom);
60675 _leave(" = -ENOMEM");
60676 return -ENOMEM;
60677 }
60678@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60679 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60680 ASSERTCMP(page, !=, NULL);
60681
60682- fscache_stat(&fscache_n_uncaches);
60683+ fscache_stat_unchecked(&fscache_n_uncaches);
60684
60685 /* cache withdrawal may beat us to it */
60686 if (!PageFsCache(page))
60687@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60688 struct fscache_cookie *cookie = op->op.object->cookie;
60689
60690 #ifdef CONFIG_FSCACHE_STATS
60691- atomic_inc(&fscache_n_marks);
60692+ atomic_inc_unchecked(&fscache_n_marks);
60693 #endif
60694
60695 _debug("- mark %p{%lx}", page, page->index);
60696diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60697index 40d13c7..ddf52b9 100644
60698--- a/fs/fscache/stats.c
60699+++ b/fs/fscache/stats.c
60700@@ -18,99 +18,99 @@
60701 /*
60702 * operation counters
60703 */
60704-atomic_t fscache_n_op_pend;
60705-atomic_t fscache_n_op_run;
60706-atomic_t fscache_n_op_enqueue;
60707-atomic_t fscache_n_op_requeue;
60708-atomic_t fscache_n_op_deferred_release;
60709-atomic_t fscache_n_op_release;
60710-atomic_t fscache_n_op_gc;
60711-atomic_t fscache_n_op_cancelled;
60712-atomic_t fscache_n_op_rejected;
60713+atomic_unchecked_t fscache_n_op_pend;
60714+atomic_unchecked_t fscache_n_op_run;
60715+atomic_unchecked_t fscache_n_op_enqueue;
60716+atomic_unchecked_t fscache_n_op_requeue;
60717+atomic_unchecked_t fscache_n_op_deferred_release;
60718+atomic_unchecked_t fscache_n_op_release;
60719+atomic_unchecked_t fscache_n_op_gc;
60720+atomic_unchecked_t fscache_n_op_cancelled;
60721+atomic_unchecked_t fscache_n_op_rejected;
60722
60723-atomic_t fscache_n_attr_changed;
60724-atomic_t fscache_n_attr_changed_ok;
60725-atomic_t fscache_n_attr_changed_nobufs;
60726-atomic_t fscache_n_attr_changed_nomem;
60727-atomic_t fscache_n_attr_changed_calls;
60728+atomic_unchecked_t fscache_n_attr_changed;
60729+atomic_unchecked_t fscache_n_attr_changed_ok;
60730+atomic_unchecked_t fscache_n_attr_changed_nobufs;
60731+atomic_unchecked_t fscache_n_attr_changed_nomem;
60732+atomic_unchecked_t fscache_n_attr_changed_calls;
60733
60734-atomic_t fscache_n_allocs;
60735-atomic_t fscache_n_allocs_ok;
60736-atomic_t fscache_n_allocs_wait;
60737-atomic_t fscache_n_allocs_nobufs;
60738-atomic_t fscache_n_allocs_intr;
60739-atomic_t fscache_n_allocs_object_dead;
60740-atomic_t fscache_n_alloc_ops;
60741-atomic_t fscache_n_alloc_op_waits;
60742+atomic_unchecked_t fscache_n_allocs;
60743+atomic_unchecked_t fscache_n_allocs_ok;
60744+atomic_unchecked_t fscache_n_allocs_wait;
60745+atomic_unchecked_t fscache_n_allocs_nobufs;
60746+atomic_unchecked_t fscache_n_allocs_intr;
60747+atomic_unchecked_t fscache_n_allocs_object_dead;
60748+atomic_unchecked_t fscache_n_alloc_ops;
60749+atomic_unchecked_t fscache_n_alloc_op_waits;
60750
60751-atomic_t fscache_n_retrievals;
60752-atomic_t fscache_n_retrievals_ok;
60753-atomic_t fscache_n_retrievals_wait;
60754-atomic_t fscache_n_retrievals_nodata;
60755-atomic_t fscache_n_retrievals_nobufs;
60756-atomic_t fscache_n_retrievals_intr;
60757-atomic_t fscache_n_retrievals_nomem;
60758-atomic_t fscache_n_retrievals_object_dead;
60759-atomic_t fscache_n_retrieval_ops;
60760-atomic_t fscache_n_retrieval_op_waits;
60761+atomic_unchecked_t fscache_n_retrievals;
60762+atomic_unchecked_t fscache_n_retrievals_ok;
60763+atomic_unchecked_t fscache_n_retrievals_wait;
60764+atomic_unchecked_t fscache_n_retrievals_nodata;
60765+atomic_unchecked_t fscache_n_retrievals_nobufs;
60766+atomic_unchecked_t fscache_n_retrievals_intr;
60767+atomic_unchecked_t fscache_n_retrievals_nomem;
60768+atomic_unchecked_t fscache_n_retrievals_object_dead;
60769+atomic_unchecked_t fscache_n_retrieval_ops;
60770+atomic_unchecked_t fscache_n_retrieval_op_waits;
60771
60772-atomic_t fscache_n_stores;
60773-atomic_t fscache_n_stores_ok;
60774-atomic_t fscache_n_stores_again;
60775-atomic_t fscache_n_stores_nobufs;
60776-atomic_t fscache_n_stores_oom;
60777-atomic_t fscache_n_store_ops;
60778-atomic_t fscache_n_store_calls;
60779-atomic_t fscache_n_store_pages;
60780-atomic_t fscache_n_store_radix_deletes;
60781-atomic_t fscache_n_store_pages_over_limit;
60782+atomic_unchecked_t fscache_n_stores;
60783+atomic_unchecked_t fscache_n_stores_ok;
60784+atomic_unchecked_t fscache_n_stores_again;
60785+atomic_unchecked_t fscache_n_stores_nobufs;
60786+atomic_unchecked_t fscache_n_stores_oom;
60787+atomic_unchecked_t fscache_n_store_ops;
60788+atomic_unchecked_t fscache_n_store_calls;
60789+atomic_unchecked_t fscache_n_store_pages;
60790+atomic_unchecked_t fscache_n_store_radix_deletes;
60791+atomic_unchecked_t fscache_n_store_pages_over_limit;
60792
60793-atomic_t fscache_n_store_vmscan_not_storing;
60794-atomic_t fscache_n_store_vmscan_gone;
60795-atomic_t fscache_n_store_vmscan_busy;
60796-atomic_t fscache_n_store_vmscan_cancelled;
60797-atomic_t fscache_n_store_vmscan_wait;
60798+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60799+atomic_unchecked_t fscache_n_store_vmscan_gone;
60800+atomic_unchecked_t fscache_n_store_vmscan_busy;
60801+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60802+atomic_unchecked_t fscache_n_store_vmscan_wait;
60803
60804-atomic_t fscache_n_marks;
60805-atomic_t fscache_n_uncaches;
60806+atomic_unchecked_t fscache_n_marks;
60807+atomic_unchecked_t fscache_n_uncaches;
60808
60809-atomic_t fscache_n_acquires;
60810-atomic_t fscache_n_acquires_null;
60811-atomic_t fscache_n_acquires_no_cache;
60812-atomic_t fscache_n_acquires_ok;
60813-atomic_t fscache_n_acquires_nobufs;
60814-atomic_t fscache_n_acquires_oom;
60815+atomic_unchecked_t fscache_n_acquires;
60816+atomic_unchecked_t fscache_n_acquires_null;
60817+atomic_unchecked_t fscache_n_acquires_no_cache;
60818+atomic_unchecked_t fscache_n_acquires_ok;
60819+atomic_unchecked_t fscache_n_acquires_nobufs;
60820+atomic_unchecked_t fscache_n_acquires_oom;
60821
60822-atomic_t fscache_n_invalidates;
60823-atomic_t fscache_n_invalidates_run;
60824+atomic_unchecked_t fscache_n_invalidates;
60825+atomic_unchecked_t fscache_n_invalidates_run;
60826
60827-atomic_t fscache_n_updates;
60828-atomic_t fscache_n_updates_null;
60829-atomic_t fscache_n_updates_run;
60830+atomic_unchecked_t fscache_n_updates;
60831+atomic_unchecked_t fscache_n_updates_null;
60832+atomic_unchecked_t fscache_n_updates_run;
60833
60834-atomic_t fscache_n_relinquishes;
60835-atomic_t fscache_n_relinquishes_null;
60836-atomic_t fscache_n_relinquishes_waitcrt;
60837-atomic_t fscache_n_relinquishes_retire;
60838+atomic_unchecked_t fscache_n_relinquishes;
60839+atomic_unchecked_t fscache_n_relinquishes_null;
60840+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60841+atomic_unchecked_t fscache_n_relinquishes_retire;
60842
60843-atomic_t fscache_n_cookie_index;
60844-atomic_t fscache_n_cookie_data;
60845-atomic_t fscache_n_cookie_special;
60846+atomic_unchecked_t fscache_n_cookie_index;
60847+atomic_unchecked_t fscache_n_cookie_data;
60848+atomic_unchecked_t fscache_n_cookie_special;
60849
60850-atomic_t fscache_n_object_alloc;
60851-atomic_t fscache_n_object_no_alloc;
60852-atomic_t fscache_n_object_lookups;
60853-atomic_t fscache_n_object_lookups_negative;
60854-atomic_t fscache_n_object_lookups_positive;
60855-atomic_t fscache_n_object_lookups_timed_out;
60856-atomic_t fscache_n_object_created;
60857-atomic_t fscache_n_object_avail;
60858-atomic_t fscache_n_object_dead;
60859+atomic_unchecked_t fscache_n_object_alloc;
60860+atomic_unchecked_t fscache_n_object_no_alloc;
60861+atomic_unchecked_t fscache_n_object_lookups;
60862+atomic_unchecked_t fscache_n_object_lookups_negative;
60863+atomic_unchecked_t fscache_n_object_lookups_positive;
60864+atomic_unchecked_t fscache_n_object_lookups_timed_out;
60865+atomic_unchecked_t fscache_n_object_created;
60866+atomic_unchecked_t fscache_n_object_avail;
60867+atomic_unchecked_t fscache_n_object_dead;
60868
60869-atomic_t fscache_n_checkaux_none;
60870-atomic_t fscache_n_checkaux_okay;
60871-atomic_t fscache_n_checkaux_update;
60872-atomic_t fscache_n_checkaux_obsolete;
60873+atomic_unchecked_t fscache_n_checkaux_none;
60874+atomic_unchecked_t fscache_n_checkaux_okay;
60875+atomic_unchecked_t fscache_n_checkaux_update;
60876+atomic_unchecked_t fscache_n_checkaux_obsolete;
60877
60878 atomic_t fscache_n_cop_alloc_object;
60879 atomic_t fscache_n_cop_lookup_object;
60880@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60881 seq_puts(m, "FS-Cache statistics\n");
60882
60883 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60884- atomic_read(&fscache_n_cookie_index),
60885- atomic_read(&fscache_n_cookie_data),
60886- atomic_read(&fscache_n_cookie_special));
60887+ atomic_read_unchecked(&fscache_n_cookie_index),
60888+ atomic_read_unchecked(&fscache_n_cookie_data),
60889+ atomic_read_unchecked(&fscache_n_cookie_special));
60890
60891 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60892- atomic_read(&fscache_n_object_alloc),
60893- atomic_read(&fscache_n_object_no_alloc),
60894- atomic_read(&fscache_n_object_avail),
60895- atomic_read(&fscache_n_object_dead));
60896+ atomic_read_unchecked(&fscache_n_object_alloc),
60897+ atomic_read_unchecked(&fscache_n_object_no_alloc),
60898+ atomic_read_unchecked(&fscache_n_object_avail),
60899+ atomic_read_unchecked(&fscache_n_object_dead));
60900 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60901- atomic_read(&fscache_n_checkaux_none),
60902- atomic_read(&fscache_n_checkaux_okay),
60903- atomic_read(&fscache_n_checkaux_update),
60904- atomic_read(&fscache_n_checkaux_obsolete));
60905+ atomic_read_unchecked(&fscache_n_checkaux_none),
60906+ atomic_read_unchecked(&fscache_n_checkaux_okay),
60907+ atomic_read_unchecked(&fscache_n_checkaux_update),
60908+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60909
60910 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60911- atomic_read(&fscache_n_marks),
60912- atomic_read(&fscache_n_uncaches));
60913+ atomic_read_unchecked(&fscache_n_marks),
60914+ atomic_read_unchecked(&fscache_n_uncaches));
60915
60916 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60917 " oom=%u\n",
60918- atomic_read(&fscache_n_acquires),
60919- atomic_read(&fscache_n_acquires_null),
60920- atomic_read(&fscache_n_acquires_no_cache),
60921- atomic_read(&fscache_n_acquires_ok),
60922- atomic_read(&fscache_n_acquires_nobufs),
60923- atomic_read(&fscache_n_acquires_oom));
60924+ atomic_read_unchecked(&fscache_n_acquires),
60925+ atomic_read_unchecked(&fscache_n_acquires_null),
60926+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
60927+ atomic_read_unchecked(&fscache_n_acquires_ok),
60928+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
60929+ atomic_read_unchecked(&fscache_n_acquires_oom));
60930
60931 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60932- atomic_read(&fscache_n_object_lookups),
60933- atomic_read(&fscache_n_object_lookups_negative),
60934- atomic_read(&fscache_n_object_lookups_positive),
60935- atomic_read(&fscache_n_object_created),
60936- atomic_read(&fscache_n_object_lookups_timed_out));
60937+ atomic_read_unchecked(&fscache_n_object_lookups),
60938+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
60939+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
60940+ atomic_read_unchecked(&fscache_n_object_created),
60941+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
60942
60943 seq_printf(m, "Invals : n=%u run=%u\n",
60944- atomic_read(&fscache_n_invalidates),
60945- atomic_read(&fscache_n_invalidates_run));
60946+ atomic_read_unchecked(&fscache_n_invalidates),
60947+ atomic_read_unchecked(&fscache_n_invalidates_run));
60948
60949 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
60950- atomic_read(&fscache_n_updates),
60951- atomic_read(&fscache_n_updates_null),
60952- atomic_read(&fscache_n_updates_run));
60953+ atomic_read_unchecked(&fscache_n_updates),
60954+ atomic_read_unchecked(&fscache_n_updates_null),
60955+ atomic_read_unchecked(&fscache_n_updates_run));
60956
60957 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
60958- atomic_read(&fscache_n_relinquishes),
60959- atomic_read(&fscache_n_relinquishes_null),
60960- atomic_read(&fscache_n_relinquishes_waitcrt),
60961- atomic_read(&fscache_n_relinquishes_retire));
60962+ atomic_read_unchecked(&fscache_n_relinquishes),
60963+ atomic_read_unchecked(&fscache_n_relinquishes_null),
60964+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
60965+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
60966
60967 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
60968- atomic_read(&fscache_n_attr_changed),
60969- atomic_read(&fscache_n_attr_changed_ok),
60970- atomic_read(&fscache_n_attr_changed_nobufs),
60971- atomic_read(&fscache_n_attr_changed_nomem),
60972- atomic_read(&fscache_n_attr_changed_calls));
60973+ atomic_read_unchecked(&fscache_n_attr_changed),
60974+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
60975+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
60976+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
60977+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
60978
60979 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
60980- atomic_read(&fscache_n_allocs),
60981- atomic_read(&fscache_n_allocs_ok),
60982- atomic_read(&fscache_n_allocs_wait),
60983- atomic_read(&fscache_n_allocs_nobufs),
60984- atomic_read(&fscache_n_allocs_intr));
60985+ atomic_read_unchecked(&fscache_n_allocs),
60986+ atomic_read_unchecked(&fscache_n_allocs_ok),
60987+ atomic_read_unchecked(&fscache_n_allocs_wait),
60988+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
60989+ atomic_read_unchecked(&fscache_n_allocs_intr));
60990 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
60991- atomic_read(&fscache_n_alloc_ops),
60992- atomic_read(&fscache_n_alloc_op_waits),
60993- atomic_read(&fscache_n_allocs_object_dead));
60994+ atomic_read_unchecked(&fscache_n_alloc_ops),
60995+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
60996+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
60997
60998 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
60999 " int=%u oom=%u\n",
61000- atomic_read(&fscache_n_retrievals),
61001- atomic_read(&fscache_n_retrievals_ok),
61002- atomic_read(&fscache_n_retrievals_wait),
61003- atomic_read(&fscache_n_retrievals_nodata),
61004- atomic_read(&fscache_n_retrievals_nobufs),
61005- atomic_read(&fscache_n_retrievals_intr),
61006- atomic_read(&fscache_n_retrievals_nomem));
61007+ atomic_read_unchecked(&fscache_n_retrievals),
61008+ atomic_read_unchecked(&fscache_n_retrievals_ok),
61009+ atomic_read_unchecked(&fscache_n_retrievals_wait),
61010+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
61011+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61012+ atomic_read_unchecked(&fscache_n_retrievals_intr),
61013+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
61014 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61015- atomic_read(&fscache_n_retrieval_ops),
61016- atomic_read(&fscache_n_retrieval_op_waits),
61017- atomic_read(&fscache_n_retrievals_object_dead));
61018+ atomic_read_unchecked(&fscache_n_retrieval_ops),
61019+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61020+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61021
61022 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61023- atomic_read(&fscache_n_stores),
61024- atomic_read(&fscache_n_stores_ok),
61025- atomic_read(&fscache_n_stores_again),
61026- atomic_read(&fscache_n_stores_nobufs),
61027- atomic_read(&fscache_n_stores_oom));
61028+ atomic_read_unchecked(&fscache_n_stores),
61029+ atomic_read_unchecked(&fscache_n_stores_ok),
61030+ atomic_read_unchecked(&fscache_n_stores_again),
61031+ atomic_read_unchecked(&fscache_n_stores_nobufs),
61032+ atomic_read_unchecked(&fscache_n_stores_oom));
61033 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61034- atomic_read(&fscache_n_store_ops),
61035- atomic_read(&fscache_n_store_calls),
61036- atomic_read(&fscache_n_store_pages),
61037- atomic_read(&fscache_n_store_radix_deletes),
61038- atomic_read(&fscache_n_store_pages_over_limit));
61039+ atomic_read_unchecked(&fscache_n_store_ops),
61040+ atomic_read_unchecked(&fscache_n_store_calls),
61041+ atomic_read_unchecked(&fscache_n_store_pages),
61042+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
61043+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61044
61045 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61046- atomic_read(&fscache_n_store_vmscan_not_storing),
61047- atomic_read(&fscache_n_store_vmscan_gone),
61048- atomic_read(&fscache_n_store_vmscan_busy),
61049- atomic_read(&fscache_n_store_vmscan_cancelled),
61050- atomic_read(&fscache_n_store_vmscan_wait));
61051+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61052+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61053+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61054+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61055+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61056
61057 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61058- atomic_read(&fscache_n_op_pend),
61059- atomic_read(&fscache_n_op_run),
61060- atomic_read(&fscache_n_op_enqueue),
61061- atomic_read(&fscache_n_op_cancelled),
61062- atomic_read(&fscache_n_op_rejected));
61063+ atomic_read_unchecked(&fscache_n_op_pend),
61064+ atomic_read_unchecked(&fscache_n_op_run),
61065+ atomic_read_unchecked(&fscache_n_op_enqueue),
61066+ atomic_read_unchecked(&fscache_n_op_cancelled),
61067+ atomic_read_unchecked(&fscache_n_op_rejected));
61068 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61069- atomic_read(&fscache_n_op_deferred_release),
61070- atomic_read(&fscache_n_op_release),
61071- atomic_read(&fscache_n_op_gc));
61072+ atomic_read_unchecked(&fscache_n_op_deferred_release),
61073+ atomic_read_unchecked(&fscache_n_op_release),
61074+ atomic_read_unchecked(&fscache_n_op_gc));
61075
61076 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61077 atomic_read(&fscache_n_cop_alloc_object),
61078diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61079index 13b691a..1ffca5ae 100644
61080--- a/fs/fuse/cuse.c
61081+++ b/fs/fuse/cuse.c
61082@@ -607,10 +607,12 @@ static int __init cuse_init(void)
61083 INIT_LIST_HEAD(&cuse_conntbl[i]);
61084
61085 /* inherit and extend fuse_dev_operations */
61086- cuse_channel_fops = fuse_dev_operations;
61087- cuse_channel_fops.owner = THIS_MODULE;
61088- cuse_channel_fops.open = cuse_channel_open;
61089- cuse_channel_fops.release = cuse_channel_release;
61090+ pax_open_kernel();
61091+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61092+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61093+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
61094+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
61095+ pax_close_kernel();
61096
61097 cuse_class = class_create(THIS_MODULE, "cuse");
61098 if (IS_ERR(cuse_class))
61099diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61100index aac71ce..fcd6a1b 100644
61101--- a/fs/fuse/dev.c
61102+++ b/fs/fuse/dev.c
61103@@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61104 ret = 0;
61105 pipe_lock(pipe);
61106
61107- if (!pipe->readers) {
61108+ if (!atomic_read(&pipe->readers)) {
61109 send_sig(SIGPIPE, current, 0);
61110 if (!ret)
61111 ret = -EPIPE;
61112@@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61113 page_nr++;
61114 ret += buf->len;
61115
61116- if (pipe->files)
61117+ if (atomic_read(&pipe->files))
61118 do_wakeup = 1;
61119 }
61120
61121diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61122index 4219835..3473b7e 100644
61123--- a/fs/fuse/dir.c
61124+++ b/fs/fuse/dir.c
61125@@ -1478,7 +1478,7 @@ static char *read_link(struct dentry *dentry)
61126 return link;
61127 }
61128
61129-static void free_link(char *link)
61130+static void free_link(const char *link)
61131 {
61132 if (!IS_ERR(link))
61133 free_page((unsigned long) link);
61134diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61135index 9c470fd..aae410e 100644
61136--- a/fs/hostfs/hostfs_kern.c
61137+++ b/fs/hostfs/hostfs_kern.c
61138@@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61139
61140 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61141 {
61142- char *s = nd_get_link(nd);
61143+ const char *s = nd_get_link(nd);
61144 if (!IS_ERR(s))
61145 __putname(s);
61146 }
61147diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61148index e19d4c0..8a357a9 100644
61149--- a/fs/hugetlbfs/inode.c
61150+++ b/fs/hugetlbfs/inode.c
61151@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61152 struct mm_struct *mm = current->mm;
61153 struct vm_area_struct *vma;
61154 struct hstate *h = hstate_file(file);
61155+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61156 struct vm_unmapped_area_info info;
61157
61158 if (len & ~huge_page_mask(h))
61159@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61160 return addr;
61161 }
61162
61163+#ifdef CONFIG_PAX_RANDMMAP
61164+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61165+#endif
61166+
61167 if (addr) {
61168 addr = ALIGN(addr, huge_page_size(h));
61169 vma = find_vma(mm, addr);
61170- if (TASK_SIZE - len >= addr &&
61171- (!vma || addr + len <= vma->vm_start))
61172+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61173 return addr;
61174 }
61175
61176 info.flags = 0;
61177 info.length = len;
61178 info.low_limit = TASK_UNMAPPED_BASE;
61179+
61180+#ifdef CONFIG_PAX_RANDMMAP
61181+ if (mm->pax_flags & MF_PAX_RANDMMAP)
61182+ info.low_limit += mm->delta_mmap;
61183+#endif
61184+
61185 info.high_limit = TASK_SIZE;
61186 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61187 info.align_offset = 0;
61188@@ -921,7 +931,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61189 };
61190 MODULE_ALIAS_FS("hugetlbfs");
61191
61192-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61193+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61194
61195 static int can_do_hugetlb_shm(void)
61196 {
61197diff --git a/fs/inode.c b/fs/inode.c
61198index d2fb2f2..a6444b0 100644
61199--- a/fs/inode.c
61200+++ b/fs/inode.c
61201@@ -839,16 +839,20 @@ unsigned int get_next_ino(void)
61202 unsigned int *p = &get_cpu_var(last_ino);
61203 unsigned int res = *p;
61204
61205+start:
61206+
61207 #ifdef CONFIG_SMP
61208 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61209- static atomic_t shared_last_ino;
61210- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61211+ static atomic_unchecked_t shared_last_ino;
61212+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61213
61214 res = next - LAST_INO_BATCH;
61215 }
61216 #endif
61217
61218- *p = ++res;
61219+ if (unlikely(!++res))
61220+ goto start; /* never zero */
61221+ *p = res;
61222 put_cpu_var(last_ino);
61223 return res;
61224 }
61225diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61226index 4a6cf28..d3a29d3 100644
61227--- a/fs/jffs2/erase.c
61228+++ b/fs/jffs2/erase.c
61229@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61230 struct jffs2_unknown_node marker = {
61231 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61232 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61233- .totlen = cpu_to_je32(c->cleanmarker_size)
61234+ .totlen = cpu_to_je32(c->cleanmarker_size),
61235+ .hdr_crc = cpu_to_je32(0)
61236 };
61237
61238 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61239diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61240index a6597d6..41b30ec 100644
61241--- a/fs/jffs2/wbuf.c
61242+++ b/fs/jffs2/wbuf.c
61243@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61244 {
61245 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61246 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61247- .totlen = constant_cpu_to_je32(8)
61248+ .totlen = constant_cpu_to_je32(8),
61249+ .hdr_crc = constant_cpu_to_je32(0)
61250 };
61251
61252 /*
61253diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61254index 97f7fda..09bd33d 100644
61255--- a/fs/jfs/super.c
61256+++ b/fs/jfs/super.c
61257@@ -885,7 +885,7 @@ static int __init init_jfs_fs(void)
61258
61259 jfs_inode_cachep =
61260 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61261- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61262+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61263 init_once);
61264 if (jfs_inode_cachep == NULL)
61265 return -ENOMEM;
61266diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61267index ac127cd..d8079db 100644
61268--- a/fs/kernfs/dir.c
61269+++ b/fs/kernfs/dir.c
61270@@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
61271 *
61272 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61273 */
61274-static unsigned int kernfs_name_hash(const char *name, const void *ns)
61275+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61276 {
61277 unsigned long hash = init_name_hash();
61278 unsigned int len = strlen(name);
61279diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61280index 5e9a80c..3853a24 100644
61281--- a/fs/kernfs/file.c
61282+++ b/fs/kernfs/file.c
61283@@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61284
61285 struct kernfs_open_node {
61286 atomic_t refcnt;
61287- atomic_t event;
61288+ atomic_unchecked_t event;
61289 wait_queue_head_t poll;
61290 struct list_head files; /* goes through kernfs_open_file.list */
61291 };
61292@@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61293 {
61294 struct kernfs_open_file *of = sf->private;
61295
61296- of->event = atomic_read(&of->kn->attr.open->event);
61297+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61298
61299 return of->kn->attr.ops->seq_show(sf, v);
61300 }
61301@@ -361,12 +361,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61302 return ret;
61303 }
61304
61305-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61306- void *buf, int len, int write)
61307+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61308+ void *buf, size_t len, int write)
61309 {
61310 struct file *file = vma->vm_file;
61311 struct kernfs_open_file *of = kernfs_of(file);
61312- int ret;
61313+ ssize_t ret;
61314
61315 if (!of->vm_ops)
61316 return -EINVAL;
61317@@ -567,7 +567,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61318 return -ENOMEM;
61319
61320 atomic_set(&new_on->refcnt, 0);
61321- atomic_set(&new_on->event, 1);
61322+ atomic_set_unchecked(&new_on->event, 1);
61323 init_waitqueue_head(&new_on->poll);
61324 INIT_LIST_HEAD(&new_on->files);
61325 goto retry;
61326@@ -773,7 +773,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61327
61328 kernfs_put_active(kn);
61329
61330- if (of->event != atomic_read(&on->event))
61331+ if (of->event != atomic_read_unchecked(&on->event))
61332 goto trigger;
61333
61334 return DEFAULT_POLLMASK;
61335@@ -798,7 +798,7 @@ void kernfs_notify(struct kernfs_node *kn)
61336 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61337 on = kn->attr.open;
61338 if (on) {
61339- atomic_inc(&on->event);
61340+ atomic_inc_unchecked(&on->event);
61341 wake_up_interruptible(&on->poll);
61342 }
61343 }
61344diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61345index 8a19889..4c3069a 100644
61346--- a/fs/kernfs/symlink.c
61347+++ b/fs/kernfs/symlink.c
61348@@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61349 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61350 void *cookie)
61351 {
61352- char *page = nd_get_link(nd);
61353+ const char *page = nd_get_link(nd);
61354 if (!IS_ERR(page))
61355 free_page((unsigned long)page);
61356 }
61357diff --git a/fs/libfs.c b/fs/libfs.c
61358index a184424..944ddce 100644
61359--- a/fs/libfs.c
61360+++ b/fs/libfs.c
61361@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61362
61363 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61364 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61365+ char d_name[sizeof(next->d_iname)];
61366+ const unsigned char *name;
61367+
61368 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61369 if (!simple_positive(next)) {
61370 spin_unlock(&next->d_lock);
61371@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61372
61373 spin_unlock(&next->d_lock);
61374 spin_unlock(&dentry->d_lock);
61375- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61376+ name = next->d_name.name;
61377+ if (name == next->d_iname) {
61378+ memcpy(d_name, name, next->d_name.len);
61379+ name = d_name;
61380+ }
61381+ if (!dir_emit(ctx, name, next->d_name.len,
61382 next->d_inode->i_ino, dt_type(next->d_inode)))
61383 return 0;
61384 spin_lock(&dentry->d_lock);
61385@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61386 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61387 void *cookie)
61388 {
61389- char *s = nd_get_link(nd);
61390+ const char *s = nd_get_link(nd);
61391 if (!IS_ERR(s))
61392 kfree(s);
61393 }
61394diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61395index acd3947..1f896e2 100644
61396--- a/fs/lockd/clntproc.c
61397+++ b/fs/lockd/clntproc.c
61398@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61399 /*
61400 * Cookie counter for NLM requests
61401 */
61402-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61403+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61404
61405 void nlmclnt_next_cookie(struct nlm_cookie *c)
61406 {
61407- u32 cookie = atomic_inc_return(&nlm_cookie);
61408+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61409
61410 memcpy(c->data, &cookie, 4);
61411 c->len=4;
61412diff --git a/fs/locks.c b/fs/locks.c
61413index e390bd9..c79870e 100644
61414--- a/fs/locks.c
61415+++ b/fs/locks.c
61416@@ -2315,16 +2315,16 @@ void locks_remove_file(struct file *filp)
61417 locks_remove_posix(filp, (fl_owner_t)filp);
61418
61419 if (filp->f_op->flock) {
61420- struct file_lock fl = {
61421+ struct file_lock flock = {
61422 .fl_pid = current->tgid,
61423 .fl_file = filp,
61424 .fl_flags = FL_FLOCK,
61425 .fl_type = F_UNLCK,
61426 .fl_end = OFFSET_MAX,
61427 };
61428- filp->f_op->flock(filp, F_SETLKW, &fl);
61429- if (fl.fl_ops && fl.fl_ops->fl_release_private)
61430- fl.fl_ops->fl_release_private(&fl);
61431+ filp->f_op->flock(filp, F_SETLKW, &flock);
61432+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
61433+ flock.fl_ops->fl_release_private(&flock);
61434 }
61435
61436 spin_lock(&inode->i_lock);
61437diff --git a/fs/mount.h b/fs/mount.h
61438index d55297f..f5b28c5 100644
61439--- a/fs/mount.h
61440+++ b/fs/mount.h
61441@@ -11,7 +11,7 @@ struct mnt_namespace {
61442 u64 seq; /* Sequence number to prevent loops */
61443 wait_queue_head_t poll;
61444 u64 event;
61445-};
61446+} __randomize_layout;
61447
61448 struct mnt_pcp {
61449 int mnt_count;
61450@@ -57,7 +57,7 @@ struct mount {
61451 int mnt_expiry_mark; /* true if marked for expiry */
61452 int mnt_pinned;
61453 struct path mnt_ex_mountpoint;
61454-};
61455+} __randomize_layout;
61456
61457 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61458
61459diff --git a/fs/namei.c b/fs/namei.c
61460index 985c6f3..f67a0f8 100644
61461--- a/fs/namei.c
61462+++ b/fs/namei.c
61463@@ -330,17 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61464 if (ret != -EACCES)
61465 return ret;
61466
61467+#ifdef CONFIG_GRKERNSEC
61468+ /* we'll block if we have to log due to a denied capability use */
61469+ if (mask & MAY_NOT_BLOCK)
61470+ return -ECHILD;
61471+#endif
61472+
61473 if (S_ISDIR(inode->i_mode)) {
61474 /* DACs are overridable for directories */
61475- if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61476- return 0;
61477 if (!(mask & MAY_WRITE))
61478- if (capable_wrt_inode_uidgid(inode,
61479- CAP_DAC_READ_SEARCH))
61480+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61481+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61482 return 0;
61483+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61484+ return 0;
61485 return -EACCES;
61486 }
61487 /*
61488+ * Searching includes executable on directories, else just read.
61489+ */
61490+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61491+ if (mask == MAY_READ)
61492+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61493+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61494+ return 0;
61495+
61496+ /*
61497 * Read/write DACs are always overridable.
61498 * Executable DACs are overridable when there is
61499 * at least one exec bit set.
61500@@ -349,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61501 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61502 return 0;
61503
61504- /*
61505- * Searching includes executable on directories, else just read.
61506- */
61507- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61508- if (mask == MAY_READ)
61509- if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61510- return 0;
61511-
61512 return -EACCES;
61513 }
61514 EXPORT_SYMBOL(generic_permission);
61515@@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61516 {
61517 struct dentry *dentry = link->dentry;
61518 int error;
61519- char *s;
61520+ const char *s;
61521
61522 BUG_ON(nd->flags & LOOKUP_RCU);
61523
61524@@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61525 if (error)
61526 goto out_put_nd_path;
61527
61528+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
61529+ dentry->d_inode, dentry, nd->path.mnt)) {
61530+ error = -EACCES;
61531+ goto out_put_nd_path;
61532+ }
61533+
61534 nd->last_type = LAST_BIND;
61535 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61536 error = PTR_ERR(*p);
61537@@ -1596,6 +1609,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61538 if (res)
61539 break;
61540 res = walk_component(nd, path, LOOKUP_FOLLOW);
61541+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61542+ res = -EACCES;
61543 put_link(nd, &link, cookie);
61544 } while (res > 0);
61545
61546@@ -1669,7 +1684,7 @@ EXPORT_SYMBOL(full_name_hash);
61547 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61548 {
61549 unsigned long a, b, adata, bdata, mask, hash, len;
61550- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61551+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61552
61553 hash = a = 0;
61554 len = -sizeof(unsigned long);
61555@@ -1953,6 +1968,8 @@ static int path_lookupat(int dfd, const char *name,
61556 if (err)
61557 break;
61558 err = lookup_last(nd, &path);
61559+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
61560+ err = -EACCES;
61561 put_link(nd, &link, cookie);
61562 }
61563 }
61564@@ -1960,6 +1977,13 @@ static int path_lookupat(int dfd, const char *name,
61565 if (!err)
61566 err = complete_walk(nd);
61567
61568+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
61569+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61570+ path_put(&nd->path);
61571+ err = -ENOENT;
61572+ }
61573+ }
61574+
61575 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61576 if (!d_can_lookup(nd->path.dentry)) {
61577 path_put(&nd->path);
61578@@ -1987,8 +2011,15 @@ static int filename_lookup(int dfd, struct filename *name,
61579 retval = path_lookupat(dfd, name->name,
61580 flags | LOOKUP_REVAL, nd);
61581
61582- if (likely(!retval))
61583+ if (likely(!retval)) {
61584 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61585+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61586+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61587+ path_put(&nd->path);
61588+ return -ENOENT;
61589+ }
61590+ }
61591+ }
61592 return retval;
61593 }
61594
61595@@ -2569,6 +2600,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61596 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61597 return -EPERM;
61598
61599+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61600+ return -EPERM;
61601+ if (gr_handle_rawio(inode))
61602+ return -EPERM;
61603+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61604+ return -EACCES;
61605+
61606 return 0;
61607 }
61608
61609@@ -2800,7 +2838,7 @@ looked_up:
61610 * cleared otherwise prior to returning.
61611 */
61612 static int lookup_open(struct nameidata *nd, struct path *path,
61613- struct file *file,
61614+ struct path *link, struct file *file,
61615 const struct open_flags *op,
61616 bool got_write, int *opened)
61617 {
61618@@ -2835,6 +2873,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61619 /* Negative dentry, just create the file */
61620 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61621 umode_t mode = op->mode;
61622+
61623+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61624+ error = -EACCES;
61625+ goto out_dput;
61626+ }
61627+
61628+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61629+ error = -EACCES;
61630+ goto out_dput;
61631+ }
61632+
61633 if (!IS_POSIXACL(dir->d_inode))
61634 mode &= ~current_umask();
61635 /*
61636@@ -2856,6 +2905,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61637 nd->flags & LOOKUP_EXCL);
61638 if (error)
61639 goto out_dput;
61640+ else
61641+ gr_handle_create(dentry, nd->path.mnt);
61642 }
61643 out_no_open:
61644 path->dentry = dentry;
61645@@ -2870,7 +2921,7 @@ out_dput:
61646 /*
61647 * Handle the last step of open()
61648 */
61649-static int do_last(struct nameidata *nd, struct path *path,
61650+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61651 struct file *file, const struct open_flags *op,
61652 int *opened, struct filename *name)
61653 {
61654@@ -2920,6 +2971,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61655 if (error)
61656 return error;
61657
61658+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61659+ error = -ENOENT;
61660+ goto out;
61661+ }
61662+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61663+ error = -EACCES;
61664+ goto out;
61665+ }
61666+
61667 audit_inode(name, dir, LOOKUP_PARENT);
61668 error = -EISDIR;
61669 /* trailing slashes? */
61670@@ -2939,7 +2999,7 @@ retry_lookup:
61671 */
61672 }
61673 mutex_lock(&dir->d_inode->i_mutex);
61674- error = lookup_open(nd, path, file, op, got_write, opened);
61675+ error = lookup_open(nd, path, link, file, op, got_write, opened);
61676 mutex_unlock(&dir->d_inode->i_mutex);
61677
61678 if (error <= 0) {
61679@@ -2963,11 +3023,28 @@ retry_lookup:
61680 goto finish_open_created;
61681 }
61682
61683+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61684+ error = -ENOENT;
61685+ goto exit_dput;
61686+ }
61687+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61688+ error = -EACCES;
61689+ goto exit_dput;
61690+ }
61691+
61692 /*
61693 * create/update audit record if it already exists.
61694 */
61695- if (d_is_positive(path->dentry))
61696+ if (d_is_positive(path->dentry)) {
61697+ /* only check if O_CREAT is specified, all other checks need to go
61698+ into may_open */
61699+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61700+ error = -EACCES;
61701+ goto exit_dput;
61702+ }
61703+
61704 audit_inode(name, path->dentry, 0);
61705+ }
61706
61707 /*
61708 * If atomic_open() acquired write access it is dropped now due to
61709@@ -3008,6 +3085,11 @@ finish_lookup:
61710 }
61711 }
61712 BUG_ON(inode != path->dentry->d_inode);
61713+ /* if we're resolving a symlink to another symlink */
61714+ if (link && gr_handle_symlink_owner(link, inode)) {
61715+ error = -EACCES;
61716+ goto out;
61717+ }
61718 return 1;
61719 }
61720
61721@@ -3017,7 +3099,6 @@ finish_lookup:
61722 save_parent.dentry = nd->path.dentry;
61723 save_parent.mnt = mntget(path->mnt);
61724 nd->path.dentry = path->dentry;
61725-
61726 }
61727 nd->inode = inode;
61728 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61729@@ -3027,7 +3108,18 @@ finish_open:
61730 path_put(&save_parent);
61731 return error;
61732 }
61733+
61734+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61735+ error = -ENOENT;
61736+ goto out;
61737+ }
61738+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61739+ error = -EACCES;
61740+ goto out;
61741+ }
61742+
61743 audit_inode(name, nd->path.dentry, 0);
61744+
61745 error = -EISDIR;
61746 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
61747 goto out;
61748@@ -3190,7 +3282,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61749 if (unlikely(error))
61750 goto out;
61751
61752- error = do_last(nd, &path, file, op, &opened, pathname);
61753+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61754 while (unlikely(error > 0)) { /* trailing symlink */
61755 struct path link = path;
61756 void *cookie;
61757@@ -3208,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61758 error = follow_link(&link, nd, &cookie);
61759 if (unlikely(error))
61760 break;
61761- error = do_last(nd, &path, file, op, &opened, pathname);
61762+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
61763 put_link(nd, &link, cookie);
61764 }
61765 out:
61766@@ -3308,9 +3400,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61767 goto unlock;
61768
61769 error = -EEXIST;
61770- if (d_is_positive(dentry))
61771+ if (d_is_positive(dentry)) {
61772+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61773+ error = -ENOENT;
61774 goto fail;
61775-
61776+ }
61777 /*
61778 * Special case - lookup gave negative, but... we had foo/bar/
61779 * From the vfs_mknod() POV we just have a negative dentry -
61780@@ -3362,6 +3456,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61781 }
61782 EXPORT_SYMBOL(user_path_create);
61783
61784+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61785+{
61786+ struct filename *tmp = getname(pathname);
61787+ struct dentry *res;
61788+ if (IS_ERR(tmp))
61789+ return ERR_CAST(tmp);
61790+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61791+ if (IS_ERR(res))
61792+ putname(tmp);
61793+ else
61794+ *to = tmp;
61795+ return res;
61796+}
61797+
61798 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61799 {
61800 int error = may_create(dir, dentry);
61801@@ -3425,6 +3533,17 @@ retry:
61802
61803 if (!IS_POSIXACL(path.dentry->d_inode))
61804 mode &= ~current_umask();
61805+
61806+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61807+ error = -EPERM;
61808+ goto out;
61809+ }
61810+
61811+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61812+ error = -EACCES;
61813+ goto out;
61814+ }
61815+
61816 error = security_path_mknod(&path, dentry, mode, dev);
61817 if (error)
61818 goto out;
61819@@ -3441,6 +3560,8 @@ retry:
61820 break;
61821 }
61822 out:
61823+ if (!error)
61824+ gr_handle_create(dentry, path.mnt);
61825 done_path_create(&path, dentry);
61826 if (retry_estale(error, lookup_flags)) {
61827 lookup_flags |= LOOKUP_REVAL;
61828@@ -3494,9 +3615,16 @@ retry:
61829
61830 if (!IS_POSIXACL(path.dentry->d_inode))
61831 mode &= ~current_umask();
61832+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61833+ error = -EACCES;
61834+ goto out;
61835+ }
61836 error = security_path_mkdir(&path, dentry, mode);
61837 if (!error)
61838 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61839+ if (!error)
61840+ gr_handle_create(dentry, path.mnt);
61841+out:
61842 done_path_create(&path, dentry);
61843 if (retry_estale(error, lookup_flags)) {
61844 lookup_flags |= LOOKUP_REVAL;
61845@@ -3579,6 +3707,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61846 struct filename *name;
61847 struct dentry *dentry;
61848 struct nameidata nd;
61849+ ino_t saved_ino = 0;
61850+ dev_t saved_dev = 0;
61851 unsigned int lookup_flags = 0;
61852 retry:
61853 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61854@@ -3611,10 +3741,21 @@ retry:
61855 error = -ENOENT;
61856 goto exit3;
61857 }
61858+
61859+ saved_ino = dentry->d_inode->i_ino;
61860+ saved_dev = gr_get_dev_from_dentry(dentry);
61861+
61862+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61863+ error = -EACCES;
61864+ goto exit3;
61865+ }
61866+
61867 error = security_path_rmdir(&nd.path, dentry);
61868 if (error)
61869 goto exit3;
61870 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61871+ if (!error && (saved_dev || saved_ino))
61872+ gr_handle_delete(saved_ino, saved_dev);
61873 exit3:
61874 dput(dentry);
61875 exit2:
61876@@ -3705,6 +3846,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61877 struct nameidata nd;
61878 struct inode *inode = NULL;
61879 struct inode *delegated_inode = NULL;
61880+ ino_t saved_ino = 0;
61881+ dev_t saved_dev = 0;
61882 unsigned int lookup_flags = 0;
61883 retry:
61884 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61885@@ -3731,10 +3874,22 @@ retry_deleg:
61886 if (d_is_negative(dentry))
61887 goto slashes;
61888 ihold(inode);
61889+
61890+ if (inode->i_nlink <= 1) {
61891+ saved_ino = inode->i_ino;
61892+ saved_dev = gr_get_dev_from_dentry(dentry);
61893+ }
61894+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61895+ error = -EACCES;
61896+ goto exit2;
61897+ }
61898+
61899 error = security_path_unlink(&nd.path, dentry);
61900 if (error)
61901 goto exit2;
61902 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61903+ if (!error && (saved_ino || saved_dev))
61904+ gr_handle_delete(saved_ino, saved_dev);
61905 exit2:
61906 dput(dentry);
61907 }
61908@@ -3823,9 +3978,17 @@ retry:
61909 if (IS_ERR(dentry))
61910 goto out_putname;
61911
61912+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61913+ error = -EACCES;
61914+ goto out;
61915+ }
61916+
61917 error = security_path_symlink(&path, dentry, from->name);
61918 if (!error)
61919 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61920+ if (!error)
61921+ gr_handle_create(dentry, path.mnt);
61922+out:
61923 done_path_create(&path, dentry);
61924 if (retry_estale(error, lookup_flags)) {
61925 lookup_flags |= LOOKUP_REVAL;
61926@@ -3929,6 +4092,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61927 struct dentry *new_dentry;
61928 struct path old_path, new_path;
61929 struct inode *delegated_inode = NULL;
61930+ struct filename *to = NULL;
61931 int how = 0;
61932 int error;
61933
61934@@ -3952,7 +4116,7 @@ retry:
61935 if (error)
61936 return error;
61937
61938- new_dentry = user_path_create(newdfd, newname, &new_path,
61939+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
61940 (how & LOOKUP_REVAL));
61941 error = PTR_ERR(new_dentry);
61942 if (IS_ERR(new_dentry))
61943@@ -3964,11 +4128,28 @@ retry:
61944 error = may_linkat(&old_path);
61945 if (unlikely(error))
61946 goto out_dput;
61947+
61948+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
61949+ old_path.dentry->d_inode,
61950+ old_path.dentry->d_inode->i_mode, to)) {
61951+ error = -EACCES;
61952+ goto out_dput;
61953+ }
61954+
61955+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
61956+ old_path.dentry, old_path.mnt, to)) {
61957+ error = -EACCES;
61958+ goto out_dput;
61959+ }
61960+
61961 error = security_path_link(old_path.dentry, &new_path, new_dentry);
61962 if (error)
61963 goto out_dput;
61964 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
61965+ if (!error)
61966+ gr_handle_create(new_dentry, new_path.mnt);
61967 out_dput:
61968+ putname(to);
61969 done_path_create(&new_path, new_dentry);
61970 if (delegated_inode) {
61971 error = break_deleg_wait(&delegated_inode);
61972@@ -4278,6 +4459,12 @@ retry_deleg:
61973 if (new_dentry == trap)
61974 goto exit5;
61975
61976+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
61977+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
61978+ to, flags);
61979+ if (error)
61980+ goto exit5;
61981+
61982 error = security_path_rename(&oldnd.path, old_dentry,
61983 &newnd.path, new_dentry, flags);
61984 if (error)
61985@@ -4285,6 +4472,9 @@ retry_deleg:
61986 error = vfs_rename(old_dir->d_inode, old_dentry,
61987 new_dir->d_inode, new_dentry,
61988 &delegated_inode, flags);
61989+ if (!error)
61990+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
61991+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
61992 exit5:
61993 dput(new_dentry);
61994 exit4:
61995@@ -4327,14 +4517,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
61996
61997 int readlink_copy(char __user *buffer, int buflen, const char *link)
61998 {
61999+ char tmpbuf[64];
62000+ const char *newlink;
62001 int len = PTR_ERR(link);
62002+
62003 if (IS_ERR(link))
62004 goto out;
62005
62006 len = strlen(link);
62007 if (len > (unsigned) buflen)
62008 len = buflen;
62009- if (copy_to_user(buffer, link, len))
62010+
62011+ if (len < sizeof(tmpbuf)) {
62012+ memcpy(tmpbuf, link, len);
62013+ newlink = tmpbuf;
62014+ } else
62015+ newlink = link;
62016+
62017+ if (copy_to_user(buffer, newlink, len))
62018 len = -EFAULT;
62019 out:
62020 return len;
62021diff --git a/fs/namespace.c b/fs/namespace.c
62022index 182bc41..72e3cf1 100644
62023--- a/fs/namespace.c
62024+++ b/fs/namespace.c
62025@@ -1348,6 +1348,9 @@ static int do_umount(struct mount *mnt, int flags)
62026 if (!(sb->s_flags & MS_RDONLY))
62027 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62028 up_write(&sb->s_umount);
62029+
62030+ gr_log_remount(mnt->mnt_devname, retval);
62031+
62032 return retval;
62033 }
62034
62035@@ -1370,6 +1373,9 @@ static int do_umount(struct mount *mnt, int flags)
62036 }
62037 unlock_mount_hash();
62038 namespace_unlock();
62039+
62040+ gr_log_unmount(mnt->mnt_devname, retval);
62041+
62042 return retval;
62043 }
62044
62045@@ -1389,7 +1395,7 @@ static inline bool may_mount(void)
62046 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62047 */
62048
62049-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62050+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62051 {
62052 struct path path;
62053 struct mount *mnt;
62054@@ -1431,7 +1437,7 @@ out:
62055 /*
62056 * The 2.0 compatible umount. No flags.
62057 */
62058-SYSCALL_DEFINE1(oldumount, char __user *, name)
62059+SYSCALL_DEFINE1(oldumount, const char __user *, name)
62060 {
62061 return sys_umount(name, 0);
62062 }
62063@@ -2440,6 +2446,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62064 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62065 MS_STRICTATIME);
62066
62067+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62068+ retval = -EPERM;
62069+ goto dput_out;
62070+ }
62071+
62072+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62073+ retval = -EPERM;
62074+ goto dput_out;
62075+ }
62076+
62077 if (flags & MS_REMOUNT)
62078 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62079 data_page);
62080@@ -2454,6 +2470,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62081 dev_name, data_page);
62082 dput_out:
62083 path_put(&path);
62084+
62085+ gr_log_mount(dev_name, dir_name, retval);
62086+
62087 return retval;
62088 }
62089
62090@@ -2471,7 +2490,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62091 * number incrementing at 10Ghz will take 12,427 years to wrap which
62092 * is effectively never, so we can ignore the possibility.
62093 */
62094-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62095+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62096
62097 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62098 {
62099@@ -2486,7 +2505,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62100 kfree(new_ns);
62101 return ERR_PTR(ret);
62102 }
62103- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62104+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62105 atomic_set(&new_ns->count, 1);
62106 new_ns->root = NULL;
62107 INIT_LIST_HEAD(&new_ns->list);
62108@@ -2496,7 +2515,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62109 return new_ns;
62110 }
62111
62112-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62113+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62114 struct user_namespace *user_ns, struct fs_struct *new_fs)
62115 {
62116 struct mnt_namespace *new_ns;
62117@@ -2617,8 +2636,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62118 }
62119 EXPORT_SYMBOL(mount_subtree);
62120
62121-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62122- char __user *, type, unsigned long, flags, void __user *, data)
62123+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62124+ const char __user *, type, unsigned long, flags, void __user *, data)
62125 {
62126 int ret;
62127 char *kernel_type;
62128@@ -2731,6 +2750,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62129 if (error)
62130 goto out2;
62131
62132+ if (gr_handle_chroot_pivot()) {
62133+ error = -EPERM;
62134+ goto out2;
62135+ }
62136+
62137 get_fs_root(current->fs, &root);
62138 old_mp = lock_mount(&old);
62139 error = PTR_ERR(old_mp);
62140@@ -2999,7 +3023,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62141 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62142 return -EPERM;
62143
62144- if (fs->users != 1)
62145+ if (atomic_read(&fs->users) != 1)
62146 return -EINVAL;
62147
62148 get_mnt_ns(mnt_ns);
62149diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62150index f4ccfe6..a5cf064 100644
62151--- a/fs/nfs/callback_xdr.c
62152+++ b/fs/nfs/callback_xdr.c
62153@@ -51,7 +51,7 @@ struct callback_op {
62154 callback_decode_arg_t decode_args;
62155 callback_encode_res_t encode_res;
62156 long res_maxsize;
62157-};
62158+} __do_const;
62159
62160 static struct callback_op callback_ops[];
62161
62162diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62163index c79f3e7..d61d671 100644
62164--- a/fs/nfs/inode.c
62165+++ b/fs/nfs/inode.c
62166@@ -1209,16 +1209,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62167 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62168 }
62169
62170-static atomic_long_t nfs_attr_generation_counter;
62171+static atomic_long_unchecked_t nfs_attr_generation_counter;
62172
62173 static unsigned long nfs_read_attr_generation_counter(void)
62174 {
62175- return atomic_long_read(&nfs_attr_generation_counter);
62176+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62177 }
62178
62179 unsigned long nfs_inc_attr_generation_counter(void)
62180 {
62181- return atomic_long_inc_return(&nfs_attr_generation_counter);
62182+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62183 }
62184
62185 void nfs_fattr_init(struct nfs_fattr *fattr)
62186diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62187index 95e3720..46c23fa 100644
62188--- a/fs/nfsd/nfs4proc.c
62189+++ b/fs/nfsd/nfs4proc.c
62190@@ -1169,7 +1169,7 @@ struct nfsd4_operation {
62191 nfsd4op_rsize op_rsize_bop;
62192 stateid_getter op_get_currentstateid;
62193 stateid_setter op_set_currentstateid;
62194-};
62195+} __do_const;
62196
62197 static struct nfsd4_operation nfsd4_ops[];
62198
62199diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62200index 3297158..7bb8436 100644
62201--- a/fs/nfsd/nfs4xdr.c
62202+++ b/fs/nfsd/nfs4xdr.c
62203@@ -1541,7 +1541,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62204
62205 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62206
62207-static nfsd4_dec nfsd4_dec_ops[] = {
62208+static const nfsd4_dec nfsd4_dec_ops[] = {
62209 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62210 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62211 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62212diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62213index f8f060f..c4ba09a 100644
62214--- a/fs/nfsd/nfscache.c
62215+++ b/fs/nfsd/nfscache.c
62216@@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62217 {
62218 struct svc_cacherep *rp = rqstp->rq_cacherep;
62219 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62220- int len;
62221+ long len;
62222 size_t bufsize = 0;
62223
62224 if (!rp)
62225 return;
62226
62227- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62228- len >>= 2;
62229+ if (statp) {
62230+ len = (char*)statp - (char*)resv->iov_base;
62231+ len = resv->iov_len - len;
62232+ len >>= 2;
62233+ }
62234
62235 /* Don't cache excessive amounts of data and XDR failures */
62236 if (!statp || len > (256 >> 2)) {
62237diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62238index 16f0673..1c2c30ab 100644
62239--- a/fs/nfsd/vfs.c
62240+++ b/fs/nfsd/vfs.c
62241@@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62242 } else {
62243 oldfs = get_fs();
62244 set_fs(KERNEL_DS);
62245- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62246+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62247 set_fs(oldfs);
62248 }
62249
62250@@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62251
62252 /* Write the data. */
62253 oldfs = get_fs(); set_fs(KERNEL_DS);
62254- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62255+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62256 set_fs(oldfs);
62257 if (host_err < 0)
62258 goto out_nfserr;
62259@@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62260 */
62261
62262 oldfs = get_fs(); set_fs(KERNEL_DS);
62263- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62264+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62265 set_fs(oldfs);
62266
62267 if (host_err < 0)
62268diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62269index 52ccd34..43a53b1 100644
62270--- a/fs/nls/nls_base.c
62271+++ b/fs/nls/nls_base.c
62272@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62273
62274 int __register_nls(struct nls_table *nls, struct module *owner)
62275 {
62276- struct nls_table ** tmp = &tables;
62277+ struct nls_table *tmp = tables;
62278
62279 if (nls->next)
62280 return -EBUSY;
62281
62282- nls->owner = owner;
62283+ pax_open_kernel();
62284+ *(void **)&nls->owner = owner;
62285+ pax_close_kernel();
62286 spin_lock(&nls_lock);
62287- while (*tmp) {
62288- if (nls == *tmp) {
62289+ while (tmp) {
62290+ if (nls == tmp) {
62291 spin_unlock(&nls_lock);
62292 return -EBUSY;
62293 }
62294- tmp = &(*tmp)->next;
62295+ tmp = tmp->next;
62296 }
62297- nls->next = tables;
62298+ pax_open_kernel();
62299+ *(struct nls_table **)&nls->next = tables;
62300+ pax_close_kernel();
62301 tables = nls;
62302 spin_unlock(&nls_lock);
62303 return 0;
62304@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62305
62306 int unregister_nls(struct nls_table * nls)
62307 {
62308- struct nls_table ** tmp = &tables;
62309+ struct nls_table * const * tmp = &tables;
62310
62311 spin_lock(&nls_lock);
62312 while (*tmp) {
62313 if (nls == *tmp) {
62314- *tmp = nls->next;
62315+ pax_open_kernel();
62316+ *(struct nls_table **)tmp = nls->next;
62317+ pax_close_kernel();
62318 spin_unlock(&nls_lock);
62319 return 0;
62320 }
62321diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62322index 162b3f1..6076a7c 100644
62323--- a/fs/nls/nls_euc-jp.c
62324+++ b/fs/nls/nls_euc-jp.c
62325@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62326 p_nls = load_nls("cp932");
62327
62328 if (p_nls) {
62329- table.charset2upper = p_nls->charset2upper;
62330- table.charset2lower = p_nls->charset2lower;
62331+ pax_open_kernel();
62332+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62333+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62334+ pax_close_kernel();
62335 return register_nls(&table);
62336 }
62337
62338diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62339index a80a741..7b96e1b 100644
62340--- a/fs/nls/nls_koi8-ru.c
62341+++ b/fs/nls/nls_koi8-ru.c
62342@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62343 p_nls = load_nls("koi8-u");
62344
62345 if (p_nls) {
62346- table.charset2upper = p_nls->charset2upper;
62347- table.charset2lower = p_nls->charset2lower;
62348+ pax_open_kernel();
62349+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62350+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62351+ pax_close_kernel();
62352 return register_nls(&table);
62353 }
62354
62355diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62356index 732648b..d3b017f 100644
62357--- a/fs/notify/fanotify/fanotify_user.c
62358+++ b/fs/notify/fanotify/fanotify_user.c
62359@@ -203,8 +203,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62360
62361 fd = fanotify_event_metadata.fd;
62362 ret = -EFAULT;
62363- if (copy_to_user(buf, &fanotify_event_metadata,
62364- fanotify_event_metadata.event_len))
62365+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62366+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62367 goto out_close_fd;
62368
62369 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62370diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62371index 1e58402..bb2d6f4 100644
62372--- a/fs/notify/notification.c
62373+++ b/fs/notify/notification.c
62374@@ -48,7 +48,7 @@
62375 #include <linux/fsnotify_backend.h>
62376 #include "fsnotify.h"
62377
62378-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62379+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62380
62381 /**
62382 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62383@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62384 */
62385 u32 fsnotify_get_cookie(void)
62386 {
62387- return atomic_inc_return(&fsnotify_sync_cookie);
62388+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62389 }
62390 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62391
62392diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62393index 9e38daf..5727cae 100644
62394--- a/fs/ntfs/dir.c
62395+++ b/fs/ntfs/dir.c
62396@@ -1310,7 +1310,7 @@ find_next_index_buffer:
62397 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62398 ~(s64)(ndir->itype.index.block_size - 1)));
62399 /* Bounds checks. */
62400- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62401+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62402 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62403 "inode 0x%lx or driver bug.", vdir->i_ino);
62404 goto err_out;
62405diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62406index db9bd8a..8338fb6 100644
62407--- a/fs/ntfs/file.c
62408+++ b/fs/ntfs/file.c
62409@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62410 char *addr;
62411 size_t total = 0;
62412 unsigned len;
62413- int left;
62414+ unsigned left;
62415
62416 do {
62417 len = PAGE_CACHE_SIZE - ofs;
62418diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62419index 9de2491..3306095 100644
62420--- a/fs/ntfs/super.c
62421+++ b/fs/ntfs/super.c
62422@@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62423 if (!silent)
62424 ntfs_error(sb, "Primary boot sector is invalid.");
62425 } else if (!silent)
62426- ntfs_error(sb, read_err_str, "primary");
62427+ ntfs_error(sb, read_err_str, "%s", "primary");
62428 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62429 if (bh_primary)
62430 brelse(bh_primary);
62431@@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62432 goto hotfix_primary_boot_sector;
62433 brelse(bh_backup);
62434 } else if (!silent)
62435- ntfs_error(sb, read_err_str, "backup");
62436+ ntfs_error(sb, read_err_str, "%s", "backup");
62437 /* Try to read NT3.51- backup boot sector. */
62438 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62439 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62440@@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62441 "sector.");
62442 brelse(bh_backup);
62443 } else if (!silent)
62444- ntfs_error(sb, read_err_str, "backup");
62445+ ntfs_error(sb, read_err_str, "%s", "backup");
62446 /* We failed. Cleanup and return. */
62447 if (bh_primary)
62448 brelse(bh_primary);
62449diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62450index 0440134..d52c93a 100644
62451--- a/fs/ocfs2/localalloc.c
62452+++ b/fs/ocfs2/localalloc.c
62453@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62454 goto bail;
62455 }
62456
62457- atomic_inc(&osb->alloc_stats.moves);
62458+ atomic_inc_unchecked(&osb->alloc_stats.moves);
62459
62460 bail:
62461 if (handle)
62462diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62463index 8d64a97..c37665d 100644
62464--- a/fs/ocfs2/ocfs2.h
62465+++ b/fs/ocfs2/ocfs2.h
62466@@ -236,11 +236,11 @@ enum ocfs2_vol_state
62467
62468 struct ocfs2_alloc_stats
62469 {
62470- atomic_t moves;
62471- atomic_t local_data;
62472- atomic_t bitmap_data;
62473- atomic_t bg_allocs;
62474- atomic_t bg_extends;
62475+ atomic_unchecked_t moves;
62476+ atomic_unchecked_t local_data;
62477+ atomic_unchecked_t bitmap_data;
62478+ atomic_unchecked_t bg_allocs;
62479+ atomic_unchecked_t bg_extends;
62480 };
62481
62482 enum ocfs2_local_alloc_state
62483diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62484index 0cb889a..6a26b24 100644
62485--- a/fs/ocfs2/suballoc.c
62486+++ b/fs/ocfs2/suballoc.c
62487@@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62488 mlog_errno(status);
62489 goto bail;
62490 }
62491- atomic_inc(&osb->alloc_stats.bg_extends);
62492+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62493
62494 /* You should never ask for this much metadata */
62495 BUG_ON(bits_wanted >
62496@@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62497 mlog_errno(status);
62498 goto bail;
62499 }
62500- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62501+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62502
62503 *suballoc_loc = res.sr_bg_blkno;
62504 *suballoc_bit_start = res.sr_bit_offset;
62505@@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62506 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62507 res->sr_bits);
62508
62509- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62510+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62511
62512 BUG_ON(res->sr_bits != 1);
62513
62514@@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62515 mlog_errno(status);
62516 goto bail;
62517 }
62518- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62519+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62520
62521 BUG_ON(res.sr_bits != 1);
62522
62523@@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62524 cluster_start,
62525 num_clusters);
62526 if (!status)
62527- atomic_inc(&osb->alloc_stats.local_data);
62528+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
62529 } else {
62530 if (min_clusters > (osb->bitmap_cpg - 1)) {
62531 /* The only paths asking for contiguousness
62532@@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62533 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62534 res.sr_bg_blkno,
62535 res.sr_bit_offset);
62536- atomic_inc(&osb->alloc_stats.bitmap_data);
62537+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62538 *num_clusters = res.sr_bits;
62539 }
62540 }
62541diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62542index a7cdd56..c583144 100644
62543--- a/fs/ocfs2/super.c
62544+++ b/fs/ocfs2/super.c
62545@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62546 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62547 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62548 "Stats",
62549- atomic_read(&osb->alloc_stats.bitmap_data),
62550- atomic_read(&osb->alloc_stats.local_data),
62551- atomic_read(&osb->alloc_stats.bg_allocs),
62552- atomic_read(&osb->alloc_stats.moves),
62553- atomic_read(&osb->alloc_stats.bg_extends));
62554+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62555+ atomic_read_unchecked(&osb->alloc_stats.local_data),
62556+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62557+ atomic_read_unchecked(&osb->alloc_stats.moves),
62558+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62559
62560 out += snprintf(buf + out, len - out,
62561 "%10s => State: %u Descriptor: %llu Size: %u bits "
62562@@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62563
62564 mutex_init(&osb->system_file_mutex);
62565
62566- atomic_set(&osb->alloc_stats.moves, 0);
62567- atomic_set(&osb->alloc_stats.local_data, 0);
62568- atomic_set(&osb->alloc_stats.bitmap_data, 0);
62569- atomic_set(&osb->alloc_stats.bg_allocs, 0);
62570- atomic_set(&osb->alloc_stats.bg_extends, 0);
62571+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62572+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62573+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62574+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62575+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62576
62577 /* Copy the blockcheck stats from the superblock probe */
62578 osb->osb_ecc_stats = *stats;
62579diff --git a/fs/open.c b/fs/open.c
62580index 9d64679..75f925c 100644
62581--- a/fs/open.c
62582+++ b/fs/open.c
62583@@ -32,6 +32,8 @@
62584 #include <linux/dnotify.h>
62585 #include <linux/compat.h>
62586
62587+#define CREATE_TRACE_POINTS
62588+#include <trace/events/fs.h>
62589 #include "internal.h"
62590
62591 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62592@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62593 error = locks_verify_truncate(inode, NULL, length);
62594 if (!error)
62595 error = security_path_truncate(path);
62596+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62597+ error = -EACCES;
62598 if (!error)
62599 error = do_truncate(path->dentry, length, 0, NULL);
62600
62601@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62602 error = locks_verify_truncate(inode, f.file, length);
62603 if (!error)
62604 error = security_path_truncate(&f.file->f_path);
62605+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62606+ error = -EACCES;
62607 if (!error)
62608 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62609 sb_end_write(inode->i_sb);
62610@@ -381,6 +387,9 @@ retry:
62611 if (__mnt_is_readonly(path.mnt))
62612 res = -EROFS;
62613
62614+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62615+ res = -EACCES;
62616+
62617 out_path_release:
62618 path_put(&path);
62619 if (retry_estale(res, lookup_flags)) {
62620@@ -412,6 +421,8 @@ retry:
62621 if (error)
62622 goto dput_and_out;
62623
62624+ gr_log_chdir(path.dentry, path.mnt);
62625+
62626 set_fs_pwd(current->fs, &path);
62627
62628 dput_and_out:
62629@@ -441,6 +452,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62630 goto out_putf;
62631
62632 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62633+
62634+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62635+ error = -EPERM;
62636+
62637+ if (!error)
62638+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62639+
62640 if (!error)
62641 set_fs_pwd(current->fs, &f.file->f_path);
62642 out_putf:
62643@@ -470,7 +488,13 @@ retry:
62644 if (error)
62645 goto dput_and_out;
62646
62647+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62648+ goto dput_and_out;
62649+
62650 set_fs_root(current->fs, &path);
62651+
62652+ gr_handle_chroot_chdir(&path);
62653+
62654 error = 0;
62655 dput_and_out:
62656 path_put(&path);
62657@@ -494,6 +518,16 @@ static int chmod_common(struct path *path, umode_t mode)
62658 return error;
62659 retry_deleg:
62660 mutex_lock(&inode->i_mutex);
62661+
62662+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62663+ error = -EACCES;
62664+ goto out_unlock;
62665+ }
62666+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62667+ error = -EACCES;
62668+ goto out_unlock;
62669+ }
62670+
62671 error = security_path_chmod(path, mode);
62672 if (error)
62673 goto out_unlock;
62674@@ -559,6 +593,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62675 uid = make_kuid(current_user_ns(), user);
62676 gid = make_kgid(current_user_ns(), group);
62677
62678+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
62679+ return -EACCES;
62680+
62681 newattrs.ia_valid = ATTR_CTIME;
62682 if (user != (uid_t) -1) {
62683 if (!uid_valid(uid))
62684@@ -978,6 +1015,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62685 } else {
62686 fsnotify_open(f);
62687 fd_install(fd, f);
62688+ trace_do_sys_open(tmp->name, flags, mode);
62689 }
62690 }
62691 putname(tmp);
62692diff --git a/fs/pipe.c b/fs/pipe.c
62693index 034bffa..6c6b522 100644
62694--- a/fs/pipe.c
62695+++ b/fs/pipe.c
62696@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62697
62698 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62699 {
62700- if (pipe->files)
62701+ if (atomic_read(&pipe->files))
62702 mutex_lock_nested(&pipe->mutex, subclass);
62703 }
62704
62705@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62706
62707 void pipe_unlock(struct pipe_inode_info *pipe)
62708 {
62709- if (pipe->files)
62710+ if (atomic_read(&pipe->files))
62711 mutex_unlock(&pipe->mutex);
62712 }
62713 EXPORT_SYMBOL(pipe_unlock);
62714@@ -342,9 +342,9 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
62715 }
62716 if (bufs) /* More to do? */
62717 continue;
62718- if (!pipe->writers)
62719+ if (!atomic_read(&pipe->writers))
62720 break;
62721- if (!pipe->waiting_writers) {
62722+ if (!atomic_read(&pipe->waiting_writers)) {
62723 /* syscall merging: Usually we must not sleep
62724 * if O_NONBLOCK is set, or if we got some data.
62725 * But if a writer sleeps in kernel space, then
62726@@ -406,7 +406,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62727 ret = 0;
62728 __pipe_lock(pipe);
62729
62730- if (!pipe->readers) {
62731+ if (!atomic_read(&pipe->readers)) {
62732 send_sig(SIGPIPE, current, 0);
62733 ret = -EPIPE;
62734 goto out;
62735@@ -461,7 +461,7 @@ redo1:
62736 for (;;) {
62737 int bufs;
62738
62739- if (!pipe->readers) {
62740+ if (!atomic_read(&pipe->readers)) {
62741 send_sig(SIGPIPE, current, 0);
62742 if (!ret)
62743 ret = -EPIPE;
62744@@ -552,9 +552,9 @@ redo2:
62745 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62746 do_wakeup = 0;
62747 }
62748- pipe->waiting_writers++;
62749+ atomic_inc(&pipe->waiting_writers);
62750 pipe_wait(pipe);
62751- pipe->waiting_writers--;
62752+ atomic_dec(&pipe->waiting_writers);
62753 }
62754 out:
62755 __pipe_unlock(pipe);
62756@@ -609,7 +609,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62757 mask = 0;
62758 if (filp->f_mode & FMODE_READ) {
62759 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62760- if (!pipe->writers && filp->f_version != pipe->w_counter)
62761+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62762 mask |= POLLHUP;
62763 }
62764
62765@@ -619,7 +619,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62766 * Most Unices do not set POLLERR for FIFOs but on Linux they
62767 * behave exactly like pipes for poll().
62768 */
62769- if (!pipe->readers)
62770+ if (!atomic_read(&pipe->readers))
62771 mask |= POLLERR;
62772 }
62773
62774@@ -631,7 +631,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62775 int kill = 0;
62776
62777 spin_lock(&inode->i_lock);
62778- if (!--pipe->files) {
62779+ if (atomic_dec_and_test(&pipe->files)) {
62780 inode->i_pipe = NULL;
62781 kill = 1;
62782 }
62783@@ -648,11 +648,11 @@ pipe_release(struct inode *inode, struct file *file)
62784
62785 __pipe_lock(pipe);
62786 if (file->f_mode & FMODE_READ)
62787- pipe->readers--;
62788+ atomic_dec(&pipe->readers);
62789 if (file->f_mode & FMODE_WRITE)
62790- pipe->writers--;
62791+ atomic_dec(&pipe->writers);
62792
62793- if (pipe->readers || pipe->writers) {
62794+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62795 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62796 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62797 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62798@@ -717,7 +717,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62799 kfree(pipe);
62800 }
62801
62802-static struct vfsmount *pipe_mnt __read_mostly;
62803+struct vfsmount *pipe_mnt __read_mostly;
62804
62805 /*
62806 * pipefs_dname() is called from d_path().
62807@@ -747,8 +747,9 @@ static struct inode * get_pipe_inode(void)
62808 goto fail_iput;
62809
62810 inode->i_pipe = pipe;
62811- pipe->files = 2;
62812- pipe->readers = pipe->writers = 1;
62813+ atomic_set(&pipe->files, 2);
62814+ atomic_set(&pipe->readers, 1);
62815+ atomic_set(&pipe->writers, 1);
62816 inode->i_fop = &pipefifo_fops;
62817
62818 /*
62819@@ -927,17 +928,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62820 spin_lock(&inode->i_lock);
62821 if (inode->i_pipe) {
62822 pipe = inode->i_pipe;
62823- pipe->files++;
62824+ atomic_inc(&pipe->files);
62825 spin_unlock(&inode->i_lock);
62826 } else {
62827 spin_unlock(&inode->i_lock);
62828 pipe = alloc_pipe_info();
62829 if (!pipe)
62830 return -ENOMEM;
62831- pipe->files = 1;
62832+ atomic_set(&pipe->files, 1);
62833 spin_lock(&inode->i_lock);
62834 if (unlikely(inode->i_pipe)) {
62835- inode->i_pipe->files++;
62836+ atomic_inc(&inode->i_pipe->files);
62837 spin_unlock(&inode->i_lock);
62838 free_pipe_info(pipe);
62839 pipe = inode->i_pipe;
62840@@ -962,10 +963,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62841 * opened, even when there is no process writing the FIFO.
62842 */
62843 pipe->r_counter++;
62844- if (pipe->readers++ == 0)
62845+ if (atomic_inc_return(&pipe->readers) == 1)
62846 wake_up_partner(pipe);
62847
62848- if (!is_pipe && !pipe->writers) {
62849+ if (!is_pipe && !atomic_read(&pipe->writers)) {
62850 if ((filp->f_flags & O_NONBLOCK)) {
62851 /* suppress POLLHUP until we have
62852 * seen a writer */
62853@@ -984,14 +985,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62854 * errno=ENXIO when there is no process reading the FIFO.
62855 */
62856 ret = -ENXIO;
62857- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62858+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62859 goto err;
62860
62861 pipe->w_counter++;
62862- if (!pipe->writers++)
62863+ if (atomic_inc_return(&pipe->writers) == 1)
62864 wake_up_partner(pipe);
62865
62866- if (!is_pipe && !pipe->readers) {
62867+ if (!is_pipe && !atomic_read(&pipe->readers)) {
62868 if (wait_for_partner(pipe, &pipe->r_counter))
62869 goto err_wr;
62870 }
62871@@ -1005,11 +1006,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62872 * the process can at least talk to itself.
62873 */
62874
62875- pipe->readers++;
62876- pipe->writers++;
62877+ atomic_inc(&pipe->readers);
62878+ atomic_inc(&pipe->writers);
62879 pipe->r_counter++;
62880 pipe->w_counter++;
62881- if (pipe->readers == 1 || pipe->writers == 1)
62882+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62883 wake_up_partner(pipe);
62884 break;
62885
62886@@ -1023,13 +1024,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62887 return 0;
62888
62889 err_rd:
62890- if (!--pipe->readers)
62891+ if (atomic_dec_and_test(&pipe->readers))
62892 wake_up_interruptible(&pipe->wait);
62893 ret = -ERESTARTSYS;
62894 goto err;
62895
62896 err_wr:
62897- if (!--pipe->writers)
62898+ if (atomic_dec_and_test(&pipe->writers))
62899 wake_up_interruptible(&pipe->wait);
62900 ret = -ERESTARTSYS;
62901 goto err;
62902diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62903index 0855f77..6787d50 100644
62904--- a/fs/posix_acl.c
62905+++ b/fs/posix_acl.c
62906@@ -20,6 +20,7 @@
62907 #include <linux/xattr.h>
62908 #include <linux/export.h>
62909 #include <linux/user_namespace.h>
62910+#include <linux/grsecurity.h>
62911
62912 struct posix_acl **acl_by_type(struct inode *inode, int type)
62913 {
62914@@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62915 }
62916 }
62917 if (mode_p)
62918- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62919+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62920 return not_equiv;
62921 }
62922 EXPORT_SYMBOL(posix_acl_equiv_mode);
62923@@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62924 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62925 }
62926
62927- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62928+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62929 return not_equiv;
62930 }
62931
62932@@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62933 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
62934 int err = -ENOMEM;
62935 if (clone) {
62936+ *mode_p &= ~gr_acl_umask();
62937+
62938 err = posix_acl_create_masq(clone, mode_p);
62939 if (err < 0) {
62940 posix_acl_release(clone);
62941@@ -659,11 +662,12 @@ struct posix_acl *
62942 posix_acl_from_xattr(struct user_namespace *user_ns,
62943 const void *value, size_t size)
62944 {
62945- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
62946- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
62947+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
62948+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
62949 int count;
62950 struct posix_acl *acl;
62951 struct posix_acl_entry *acl_e;
62952+ umode_t umask = gr_acl_umask();
62953
62954 if (!value)
62955 return NULL;
62956@@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62957
62958 switch(acl_e->e_tag) {
62959 case ACL_USER_OBJ:
62960+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62961+ break;
62962 case ACL_GROUP_OBJ:
62963 case ACL_MASK:
62964+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
62965+ break;
62966 case ACL_OTHER:
62967+ acl_e->e_perm &= ~(umask & S_IRWXO);
62968 break;
62969
62970 case ACL_USER:
62971+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
62972 acl_e->e_uid =
62973 make_kuid(user_ns,
62974 le32_to_cpu(entry->e_id));
62975@@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
62976 goto fail;
62977 break;
62978 case ACL_GROUP:
62979+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
62980 acl_e->e_gid =
62981 make_kgid(user_ns,
62982 le32_to_cpu(entry->e_id));
62983diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
62984index 2183fcf..3c32a98 100644
62985--- a/fs/proc/Kconfig
62986+++ b/fs/proc/Kconfig
62987@@ -30,7 +30,7 @@ config PROC_FS
62988
62989 config PROC_KCORE
62990 bool "/proc/kcore support" if !ARM
62991- depends on PROC_FS && MMU
62992+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
62993 help
62994 Provides a virtual ELF core file of the live kernel. This can
62995 be read with gdb and other ELF tools. No modifications can be
62996@@ -38,8 +38,8 @@ config PROC_KCORE
62997
62998 config PROC_VMCORE
62999 bool "/proc/vmcore support"
63000- depends on PROC_FS && CRASH_DUMP
63001- default y
63002+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63003+ default n
63004 help
63005 Exports the dump image of crashed kernel in ELF format.
63006
63007@@ -63,8 +63,8 @@ config PROC_SYSCTL
63008 limited in memory.
63009
63010 config PROC_PAGE_MONITOR
63011- default y
63012- depends on PROC_FS && MMU
63013+ default n
63014+ depends on PROC_FS && MMU && !GRKERNSEC
63015 bool "Enable /proc page monitoring" if EXPERT
63016 help
63017 Various /proc files exist to monitor process memory utilization:
63018diff --git a/fs/proc/array.c b/fs/proc/array.c
63019index 64db2bc..a8185d6 100644
63020--- a/fs/proc/array.c
63021+++ b/fs/proc/array.c
63022@@ -60,6 +60,7 @@
63023 #include <linux/tty.h>
63024 #include <linux/string.h>
63025 #include <linux/mman.h>
63026+#include <linux/grsecurity.h>
63027 #include <linux/proc_fs.h>
63028 #include <linux/ioport.h>
63029 #include <linux/uaccess.h>
63030@@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63031 seq_putc(m, '\n');
63032 }
63033
63034+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63035+static inline void task_pax(struct seq_file *m, struct task_struct *p)
63036+{
63037+ if (p->mm)
63038+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63039+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63040+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63041+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63042+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63043+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63044+ else
63045+ seq_printf(m, "PaX:\t-----\n");
63046+}
63047+#endif
63048+
63049 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63050 struct pid *pid, struct task_struct *task)
63051 {
63052@@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63053 task_cpus_allowed(m, task);
63054 cpuset_task_status_allowed(m, task);
63055 task_context_switch_counts(m, task);
63056+
63057+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63058+ task_pax(m, task);
63059+#endif
63060+
63061+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63062+ task_grsec_rbac(m, task);
63063+#endif
63064+
63065 return 0;
63066 }
63067
63068+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63069+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63070+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63071+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63072+#endif
63073+
63074 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63075 struct pid *pid, struct task_struct *task, int whole)
63076 {
63077@@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63078 char tcomm[sizeof(task->comm)];
63079 unsigned long flags;
63080
63081+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63082+ if (current->exec_id != m->exec_id) {
63083+ gr_log_badprocpid("stat");
63084+ return 0;
63085+ }
63086+#endif
63087+
63088 state = *get_task_state(task);
63089 vsize = eip = esp = 0;
63090 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63091@@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63092 gtime = task_gtime(task);
63093 }
63094
63095+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63096+ if (PAX_RAND_FLAGS(mm)) {
63097+ eip = 0;
63098+ esp = 0;
63099+ wchan = 0;
63100+ }
63101+#endif
63102+#ifdef CONFIG_GRKERNSEC_HIDESYM
63103+ wchan = 0;
63104+ eip =0;
63105+ esp =0;
63106+#endif
63107+
63108 /* scale priority and nice values from timeslices to -20..20 */
63109 /* to make it look like a "normal" Unix priority/nice value */
63110 priority = task_prio(task);
63111@@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63112 seq_put_decimal_ull(m, ' ', vsize);
63113 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63114 seq_put_decimal_ull(m, ' ', rsslim);
63115+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63116+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63117+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63118+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63119+#else
63120 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63121 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63122 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63123+#endif
63124 seq_put_decimal_ull(m, ' ', esp);
63125 seq_put_decimal_ull(m, ' ', eip);
63126 /* The signal information here is obsolete.
63127@@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63128 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63129 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63130
63131- if (mm && permitted) {
63132+ if (mm && permitted
63133+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63134+ && !PAX_RAND_FLAGS(mm)
63135+#endif
63136+ ) {
63137 seq_put_decimal_ull(m, ' ', mm->start_data);
63138 seq_put_decimal_ull(m, ' ', mm->end_data);
63139 seq_put_decimal_ull(m, ' ', mm->start_brk);
63140@@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63141 struct pid *pid, struct task_struct *task)
63142 {
63143 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63144- struct mm_struct *mm = get_task_mm(task);
63145+ struct mm_struct *mm;
63146
63147+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63148+ if (current->exec_id != m->exec_id) {
63149+ gr_log_badprocpid("statm");
63150+ return 0;
63151+ }
63152+#endif
63153+ mm = get_task_mm(task);
63154 if (mm) {
63155 size = task_statm(mm, &shared, &text, &data, &resident);
63156 mmput(mm);
63157@@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63158 return 0;
63159 }
63160
63161+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63162+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63163+{
63164+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63165+}
63166+#endif
63167+
63168 #ifdef CONFIG_CHECKPOINT_RESTORE
63169 static struct pid *
63170 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63171diff --git a/fs/proc/base.c b/fs/proc/base.c
63172index 2d696b0..b9da447 100644
63173--- a/fs/proc/base.c
63174+++ b/fs/proc/base.c
63175@@ -113,6 +113,14 @@ struct pid_entry {
63176 union proc_op op;
63177 };
63178
63179+struct getdents_callback {
63180+ struct linux_dirent __user * current_dir;
63181+ struct linux_dirent __user * previous;
63182+ struct file * file;
63183+ int count;
63184+ int error;
63185+};
63186+
63187 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63188 .name = (NAME), \
63189 .len = sizeof(NAME) - 1, \
63190@@ -205,12 +213,28 @@ static int proc_pid_cmdline(struct task_struct *task, char *buffer)
63191 return get_cmdline(task, buffer, PAGE_SIZE);
63192 }
63193
63194+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63195+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63196+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63197+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63198+#endif
63199+
63200 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63201 {
63202 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63203 int res = PTR_ERR(mm);
63204 if (mm && !IS_ERR(mm)) {
63205 unsigned int nwords = 0;
63206+
63207+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63208+ /* allow if we're currently ptracing this task */
63209+ if (PAX_RAND_FLAGS(mm) &&
63210+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63211+ mmput(mm);
63212+ return 0;
63213+ }
63214+#endif
63215+
63216 do {
63217 nwords += 2;
63218 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63219@@ -224,7 +248,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63220 }
63221
63222
63223-#ifdef CONFIG_KALLSYMS
63224+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63225 /*
63226 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63227 * Returns the resolved symbol. If that fails, simply return the address.
63228@@ -263,7 +287,7 @@ static void unlock_trace(struct task_struct *task)
63229 mutex_unlock(&task->signal->cred_guard_mutex);
63230 }
63231
63232-#ifdef CONFIG_STACKTRACE
63233+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63234
63235 #define MAX_STACK_TRACE_DEPTH 64
63236
63237@@ -486,7 +510,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63238 return count;
63239 }
63240
63241-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63242+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63243 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63244 {
63245 long nr;
63246@@ -515,7 +539,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63247 /************************************************************************/
63248
63249 /* permission checks */
63250-static int proc_fd_access_allowed(struct inode *inode)
63251+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63252 {
63253 struct task_struct *task;
63254 int allowed = 0;
63255@@ -525,7 +549,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63256 */
63257 task = get_proc_task(inode);
63258 if (task) {
63259- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63260+ if (log)
63261+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63262+ else
63263+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63264 put_task_struct(task);
63265 }
63266 return allowed;
63267@@ -556,10 +583,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63268 struct task_struct *task,
63269 int hide_pid_min)
63270 {
63271+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63272+ return false;
63273+
63274+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63275+ rcu_read_lock();
63276+ {
63277+ const struct cred *tmpcred = current_cred();
63278+ const struct cred *cred = __task_cred(task);
63279+
63280+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63281+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63282+ || in_group_p(grsec_proc_gid)
63283+#endif
63284+ ) {
63285+ rcu_read_unlock();
63286+ return true;
63287+ }
63288+ }
63289+ rcu_read_unlock();
63290+
63291+ if (!pid->hide_pid)
63292+ return false;
63293+#endif
63294+
63295 if (pid->hide_pid < hide_pid_min)
63296 return true;
63297 if (in_group_p(pid->pid_gid))
63298 return true;
63299+
63300 return ptrace_may_access(task, PTRACE_MODE_READ);
63301 }
63302
63303@@ -577,7 +629,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63304 put_task_struct(task);
63305
63306 if (!has_perms) {
63307+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63308+ {
63309+#else
63310 if (pid->hide_pid == 2) {
63311+#endif
63312 /*
63313 * Let's make getdents(), stat(), and open()
63314 * consistent with each other. If a process
63315@@ -675,6 +731,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63316 if (!task)
63317 return -ESRCH;
63318
63319+ if (gr_acl_handle_procpidmem(task)) {
63320+ put_task_struct(task);
63321+ return -EPERM;
63322+ }
63323+
63324 mm = mm_access(task, mode);
63325 put_task_struct(task);
63326
63327@@ -690,6 +751,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63328
63329 file->private_data = mm;
63330
63331+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63332+ file->f_version = current->exec_id;
63333+#endif
63334+
63335 return 0;
63336 }
63337
63338@@ -711,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63339 ssize_t copied;
63340 char *page;
63341
63342+#ifdef CONFIG_GRKERNSEC
63343+ if (write)
63344+ return -EPERM;
63345+#endif
63346+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63347+ if (file->f_version != current->exec_id) {
63348+ gr_log_badprocpid("mem");
63349+ return 0;
63350+ }
63351+#endif
63352+
63353 if (!mm)
63354 return 0;
63355
63356@@ -723,7 +799,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63357 goto free;
63358
63359 while (count > 0) {
63360- int this_len = min_t(int, count, PAGE_SIZE);
63361+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63362
63363 if (write && copy_from_user(page, buf, this_len)) {
63364 copied = -EFAULT;
63365@@ -815,6 +891,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63366 if (!mm)
63367 return 0;
63368
63369+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63370+ if (file->f_version != current->exec_id) {
63371+ gr_log_badprocpid("environ");
63372+ return 0;
63373+ }
63374+#endif
63375+
63376 page = (char *)__get_free_page(GFP_TEMPORARY);
63377 if (!page)
63378 return -ENOMEM;
63379@@ -824,7 +907,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63380 goto free;
63381 while (count > 0) {
63382 size_t this_len, max_len;
63383- int retval;
63384+ ssize_t retval;
63385
63386 if (src >= (mm->env_end - mm->env_start))
63387 break;
63388@@ -1438,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63389 int error = -EACCES;
63390
63391 /* Are we allowed to snoop on the tasks file descriptors? */
63392- if (!proc_fd_access_allowed(inode))
63393+ if (!proc_fd_access_allowed(inode, 0))
63394 goto out;
63395
63396 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63397@@ -1482,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63398 struct path path;
63399
63400 /* Are we allowed to snoop on the tasks file descriptors? */
63401- if (!proc_fd_access_allowed(inode))
63402- goto out;
63403+ /* logging this is needed for learning on chromium to work properly,
63404+ but we don't want to flood the logs from 'ps' which does a readlink
63405+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63406+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
63407+ */
63408+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63409+ if (!proc_fd_access_allowed(inode,0))
63410+ goto out;
63411+ } else {
63412+ if (!proc_fd_access_allowed(inode,1))
63413+ goto out;
63414+ }
63415
63416 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63417 if (error)
63418@@ -1533,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63419 rcu_read_lock();
63420 cred = __task_cred(task);
63421 inode->i_uid = cred->euid;
63422+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63423+ inode->i_gid = grsec_proc_gid;
63424+#else
63425 inode->i_gid = cred->egid;
63426+#endif
63427 rcu_read_unlock();
63428 }
63429 security_task_to_inode(task, inode);
63430@@ -1569,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63431 return -ENOENT;
63432 }
63433 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63434+#ifdef CONFIG_GRKERNSEC_PROC_USER
63435+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63436+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63437+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63438+#endif
63439 task_dumpable(task)) {
63440 cred = __task_cred(task);
63441 stat->uid = cred->euid;
63442+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63443+ stat->gid = grsec_proc_gid;
63444+#else
63445 stat->gid = cred->egid;
63446+#endif
63447 }
63448 }
63449 rcu_read_unlock();
63450@@ -1610,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63451
63452 if (task) {
63453 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63454+#ifdef CONFIG_GRKERNSEC_PROC_USER
63455+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63456+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63457+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63458+#endif
63459 task_dumpable(task)) {
63460 rcu_read_lock();
63461 cred = __task_cred(task);
63462 inode->i_uid = cred->euid;
63463+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63464+ inode->i_gid = grsec_proc_gid;
63465+#else
63466 inode->i_gid = cred->egid;
63467+#endif
63468 rcu_read_unlock();
63469 } else {
63470 inode->i_uid = GLOBAL_ROOT_UID;
63471@@ -2149,6 +2264,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63472 if (!task)
63473 goto out_no_task;
63474
63475+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63476+ goto out;
63477+
63478 /*
63479 * Yes, it does not scale. And it should not. Don't add
63480 * new entries into /proc/<tgid>/ without very good reasons.
63481@@ -2179,6 +2297,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63482 if (!task)
63483 return -ENOENT;
63484
63485+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63486+ goto out;
63487+
63488 if (!dir_emit_dots(file, ctx))
63489 goto out;
63490
63491@@ -2568,7 +2689,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63492 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63493 #endif
63494 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63495-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63496+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63497 INF("syscall", S_IRUSR, proc_pid_syscall),
63498 #endif
63499 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63500@@ -2593,10 +2714,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63501 #ifdef CONFIG_SECURITY
63502 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63503 #endif
63504-#ifdef CONFIG_KALLSYMS
63505+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63506 INF("wchan", S_IRUGO, proc_pid_wchan),
63507 #endif
63508-#ifdef CONFIG_STACKTRACE
63509+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63510 ONE("stack", S_IRUSR, proc_pid_stack),
63511 #endif
63512 #ifdef CONFIG_SCHEDSTATS
63513@@ -2630,6 +2751,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63514 #ifdef CONFIG_HARDWALL
63515 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63516 #endif
63517+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63518+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63519+#endif
63520 #ifdef CONFIG_USER_NS
63521 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63522 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63523@@ -2760,7 +2884,14 @@ static int proc_pid_instantiate(struct inode *dir,
63524 if (!inode)
63525 goto out;
63526
63527+#ifdef CONFIG_GRKERNSEC_PROC_USER
63528+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63529+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63530+ inode->i_gid = grsec_proc_gid;
63531+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63532+#else
63533 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63534+#endif
63535 inode->i_op = &proc_tgid_base_inode_operations;
63536 inode->i_fop = &proc_tgid_base_operations;
63537 inode->i_flags|=S_IMMUTABLE;
63538@@ -2798,7 +2929,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63539 if (!task)
63540 goto out;
63541
63542+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63543+ goto out_put_task;
63544+
63545 result = proc_pid_instantiate(dir, dentry, task, NULL);
63546+out_put_task:
63547 put_task_struct(task);
63548 out:
63549 return ERR_PTR(result);
63550@@ -2904,7 +3039,7 @@ static const struct pid_entry tid_base_stuff[] = {
63551 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63552 #endif
63553 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63554-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63555+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63556 INF("syscall", S_IRUSR, proc_pid_syscall),
63557 #endif
63558 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63559@@ -2931,10 +3066,10 @@ static const struct pid_entry tid_base_stuff[] = {
63560 #ifdef CONFIG_SECURITY
63561 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63562 #endif
63563-#ifdef CONFIG_KALLSYMS
63564+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63565 INF("wchan", S_IRUGO, proc_pid_wchan),
63566 #endif
63567-#ifdef CONFIG_STACKTRACE
63568+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63569 ONE("stack", S_IRUSR, proc_pid_stack),
63570 #endif
63571 #ifdef CONFIG_SCHEDSTATS
63572diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63573index cbd82df..c0407d2 100644
63574--- a/fs/proc/cmdline.c
63575+++ b/fs/proc/cmdline.c
63576@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63577
63578 static int __init proc_cmdline_init(void)
63579 {
63580+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63581+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63582+#else
63583 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63584+#endif
63585 return 0;
63586 }
63587 fs_initcall(proc_cmdline_init);
63588diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63589index 50493ed..248166b 100644
63590--- a/fs/proc/devices.c
63591+++ b/fs/proc/devices.c
63592@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63593
63594 static int __init proc_devices_init(void)
63595 {
63596+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63597+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63598+#else
63599 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63600+#endif
63601 return 0;
63602 }
63603 fs_initcall(proc_devices_init);
63604diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63605index 0788d09..9cc1385 100644
63606--- a/fs/proc/fd.c
63607+++ b/fs/proc/fd.c
63608@@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
63609 if (!task)
63610 return -ENOENT;
63611
63612- files = get_files_struct(task);
63613+ if (!gr_acl_handle_procpidmem(task))
63614+ files = get_files_struct(task);
63615 put_task_struct(task);
63616
63617 if (files) {
63618@@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63619 */
63620 int proc_fd_permission(struct inode *inode, int mask)
63621 {
63622+ struct task_struct *task;
63623 int rv = generic_permission(inode, mask);
63624- if (rv == 0)
63625- return 0;
63626+
63627 if (task_tgid(current) == proc_pid(inode))
63628 rv = 0;
63629+
63630+ task = get_proc_task(inode);
63631+ if (task == NULL)
63632+ return rv;
63633+
63634+ if (gr_acl_handle_procpidmem(task))
63635+ rv = -EACCES;
63636+
63637+ put_task_struct(task);
63638+
63639 return rv;
63640 }
63641
63642diff --git a/fs/proc/generic.c b/fs/proc/generic.c
63643index b7f268e..3bea6b7 100644
63644--- a/fs/proc/generic.c
63645+++ b/fs/proc/generic.c
63646@@ -23,6 +23,7 @@
63647 #include <linux/bitops.h>
63648 #include <linux/spinlock.h>
63649 #include <linux/completion.h>
63650+#include <linux/grsecurity.h>
63651 #include <asm/uaccess.h>
63652
63653 #include "internal.h"
63654@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
63655 return proc_lookup_de(PDE(dir), dir, dentry);
63656 }
63657
63658+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
63659+ unsigned int flags)
63660+{
63661+ if (gr_proc_is_restricted())
63662+ return ERR_PTR(-EACCES);
63663+
63664+ return proc_lookup_de(PDE(dir), dir, dentry);
63665+}
63666+
63667 /*
63668 * This returns non-zero if at EOF, so that the /proc
63669 * root directory can use this and check if it should
63670@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
63671 return proc_readdir_de(PDE(inode), file, ctx);
63672 }
63673
63674+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
63675+{
63676+ struct inode *inode = file_inode(file);
63677+
63678+ if (gr_proc_is_restricted())
63679+ return -EACCES;
63680+
63681+ return proc_readdir_de(PDE(inode), file, ctx);
63682+}
63683+
63684 /*
63685 * These are the generic /proc directory operations. They
63686 * use the in-memory "struct proc_dir_entry" tree to parse
63687@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
63688 .iterate = proc_readdir,
63689 };
63690
63691+static const struct file_operations proc_dir_restricted_operations = {
63692+ .llseek = generic_file_llseek,
63693+ .read = generic_read_dir,
63694+ .iterate = proc_readdir_restrict,
63695+};
63696+
63697 /*
63698 * proc directories can do almost nothing..
63699 */
63700@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
63701 .setattr = proc_notify_change,
63702 };
63703
63704+static const struct inode_operations proc_dir_restricted_inode_operations = {
63705+ .lookup = proc_lookup_restrict,
63706+ .getattr = proc_getattr,
63707+ .setattr = proc_notify_change,
63708+};
63709+
63710 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
63711 {
63712 struct proc_dir_entry *tmp;
63713@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
63714 return ret;
63715
63716 if (S_ISDIR(dp->mode)) {
63717- dp->proc_fops = &proc_dir_operations;
63718- dp->proc_iops = &proc_dir_inode_operations;
63719+ if (dp->restricted) {
63720+ dp->proc_fops = &proc_dir_restricted_operations;
63721+ dp->proc_iops = &proc_dir_restricted_inode_operations;
63722+ } else {
63723+ dp->proc_fops = &proc_dir_operations;
63724+ dp->proc_iops = &proc_dir_inode_operations;
63725+ }
63726 dir->nlink++;
63727 } else if (S_ISLNK(dp->mode)) {
63728 dp->proc_iops = &proc_link_inode_operations;
63729@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
63730 }
63731 EXPORT_SYMBOL_GPL(proc_mkdir_data);
63732
63733+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
63734+ struct proc_dir_entry *parent, void *data)
63735+{
63736+ struct proc_dir_entry *ent;
63737+
63738+ if (mode == 0)
63739+ mode = S_IRUGO | S_IXUGO;
63740+
63741+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
63742+ if (ent) {
63743+ ent->data = data;
63744+ ent->restricted = 1;
63745+ if (proc_register(parent, ent) < 0) {
63746+ kfree(ent);
63747+ ent = NULL;
63748+ }
63749+ }
63750+ return ent;
63751+}
63752+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
63753+
63754 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
63755 struct proc_dir_entry *parent)
63756 {
63757@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
63758 }
63759 EXPORT_SYMBOL(proc_mkdir);
63760
63761+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
63762+ struct proc_dir_entry *parent)
63763+{
63764+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
63765+}
63766+EXPORT_SYMBOL(proc_mkdir_restrict);
63767+
63768 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
63769 struct proc_dir_entry *parent,
63770 const struct file_operations *proc_fops,
63771diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63772index 0adbc02..bee4d0b 100644
63773--- a/fs/proc/inode.c
63774+++ b/fs/proc/inode.c
63775@@ -23,11 +23,17 @@
63776 #include <linux/slab.h>
63777 #include <linux/mount.h>
63778 #include <linux/magic.h>
63779+#include <linux/grsecurity.h>
63780
63781 #include <asm/uaccess.h>
63782
63783 #include "internal.h"
63784
63785+#ifdef CONFIG_PROC_SYSCTL
63786+extern const struct inode_operations proc_sys_inode_operations;
63787+extern const struct inode_operations proc_sys_dir_operations;
63788+#endif
63789+
63790 static void proc_evict_inode(struct inode *inode)
63791 {
63792 struct proc_dir_entry *de;
63793@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63794 ns = PROC_I(inode)->ns.ns;
63795 if (ns_ops && ns)
63796 ns_ops->put(ns);
63797+
63798+#ifdef CONFIG_PROC_SYSCTL
63799+ if (inode->i_op == &proc_sys_inode_operations ||
63800+ inode->i_op == &proc_sys_dir_operations)
63801+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63802+#endif
63803+
63804 }
63805
63806 static struct kmem_cache * proc_inode_cachep;
63807@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63808 if (de->mode) {
63809 inode->i_mode = de->mode;
63810 inode->i_uid = de->uid;
63811+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63812+ inode->i_gid = grsec_proc_gid;
63813+#else
63814 inode->i_gid = de->gid;
63815+#endif
63816 }
63817 if (de->size)
63818 inode->i_size = de->size;
63819diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63820index 3ab6d14..b26174e 100644
63821--- a/fs/proc/internal.h
63822+++ b/fs/proc/internal.h
63823@@ -46,9 +46,10 @@ struct proc_dir_entry {
63824 struct completion *pde_unload_completion;
63825 struct list_head pde_openers; /* who did ->open, but not ->release */
63826 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63827+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
63828 u8 namelen;
63829 char name[];
63830-};
63831+} __randomize_layout;
63832
63833 union proc_op {
63834 int (*proc_get_link)(struct dentry *, struct path *);
63835@@ -67,7 +68,7 @@ struct proc_inode {
63836 struct ctl_table *sysctl_entry;
63837 struct proc_ns ns;
63838 struct inode vfs_inode;
63839-};
63840+} __randomize_layout;
63841
63842 /*
63843 * General functions
63844@@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63845 struct pid *, struct task_struct *);
63846 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63847 struct pid *, struct task_struct *);
63848+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63849+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63850+#endif
63851
63852 /*
63853 * base.c
63854@@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
63855 extern spinlock_t proc_subdir_lock;
63856
63857 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
63858+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
63859 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
63860 struct dentry *);
63861 extern int proc_readdir(struct file *, struct dir_context *);
63862+extern int proc_readdir_restrict(struct file *, struct dir_context *);
63863 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
63864
63865 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
63866diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63867index a352d57..cb94a5c 100644
63868--- a/fs/proc/interrupts.c
63869+++ b/fs/proc/interrupts.c
63870@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63871
63872 static int __init proc_interrupts_init(void)
63873 {
63874+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63875+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63876+#else
63877 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63878+#endif
63879 return 0;
63880 }
63881 fs_initcall(proc_interrupts_init);
63882diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63883index 39e6ef3..2f9cb5e 100644
63884--- a/fs/proc/kcore.c
63885+++ b/fs/proc/kcore.c
63886@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63887 * the addresses in the elf_phdr on our list.
63888 */
63889 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63890- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63891+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63892+ if (tsz > buflen)
63893 tsz = buflen;
63894-
63895+
63896 while (buflen) {
63897 struct kcore_list *m;
63898
63899@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63900 kfree(elf_buf);
63901 } else {
63902 if (kern_addr_valid(start)) {
63903- unsigned long n;
63904+ char *elf_buf;
63905+ mm_segment_t oldfs;
63906
63907- n = copy_to_user(buffer, (char *)start, tsz);
63908- /*
63909- * We cannot distinguish between fault on source
63910- * and fault on destination. When this happens
63911- * we clear too and hope it will trigger the
63912- * EFAULT again.
63913- */
63914- if (n) {
63915- if (clear_user(buffer + tsz - n,
63916- n))
63917+ elf_buf = kmalloc(tsz, GFP_KERNEL);
63918+ if (!elf_buf)
63919+ return -ENOMEM;
63920+ oldfs = get_fs();
63921+ set_fs(KERNEL_DS);
63922+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63923+ set_fs(oldfs);
63924+ if (copy_to_user(buffer, elf_buf, tsz)) {
63925+ kfree(elf_buf);
63926 return -EFAULT;
63927+ }
63928 }
63929+ set_fs(oldfs);
63930+ kfree(elf_buf);
63931 } else {
63932 if (clear_user(buffer, tsz))
63933 return -EFAULT;
63934@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63935
63936 static int open_kcore(struct inode *inode, struct file *filp)
63937 {
63938+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63939+ return -EPERM;
63940+#endif
63941 if (!capable(CAP_SYS_RAWIO))
63942 return -EPERM;
63943 if (kcore_need_update)
63944diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
63945index 7445af0..7c5113c 100644
63946--- a/fs/proc/meminfo.c
63947+++ b/fs/proc/meminfo.c
63948@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
63949 vmi.used >> 10,
63950 vmi.largest_chunk >> 10
63951 #ifdef CONFIG_MEMORY_FAILURE
63952- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63953+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63954 #endif
63955 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63956 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
63957diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
63958index d4a3574..b421ce9 100644
63959--- a/fs/proc/nommu.c
63960+++ b/fs/proc/nommu.c
63961@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
63962
63963 if (file) {
63964 seq_pad(m, ' ');
63965- seq_path(m, &file->f_path, "");
63966+ seq_path(m, &file->f_path, "\n\\");
63967 }
63968
63969 seq_putc(m, '\n');
63970diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
63971index 4677bb7..dad3045 100644
63972--- a/fs/proc/proc_net.c
63973+++ b/fs/proc/proc_net.c
63974@@ -23,9 +23,27 @@
63975 #include <linux/nsproxy.h>
63976 #include <net/net_namespace.h>
63977 #include <linux/seq_file.h>
63978+#include <linux/grsecurity.h>
63979
63980 #include "internal.h"
63981
63982+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
63983+static struct seq_operations *ipv6_seq_ops_addr;
63984+
63985+void register_ipv6_seq_ops_addr(struct seq_operations *addr)
63986+{
63987+ ipv6_seq_ops_addr = addr;
63988+}
63989+
63990+void unregister_ipv6_seq_ops_addr(void)
63991+{
63992+ ipv6_seq_ops_addr = NULL;
63993+}
63994+
63995+EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
63996+EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
63997+#endif
63998+
63999 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
64000 {
64001 return pde->parent->data;
64002@@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
64003 return maybe_get_net(PDE_NET(PDE(inode)));
64004 }
64005
64006+extern const struct seq_operations dev_seq_ops;
64007+
64008 int seq_open_net(struct inode *ino, struct file *f,
64009 const struct seq_operations *ops, int size)
64010 {
64011@@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
64012
64013 BUG_ON(size < sizeof(*p));
64014
64015+ /* only permit access to /proc/net/dev */
64016+ if (
64017+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
64018+ ops != ipv6_seq_ops_addr &&
64019+#endif
64020+ ops != &dev_seq_ops && gr_proc_is_restricted())
64021+ return -EACCES;
64022+
64023 net = get_proc_net(ino);
64024 if (net == NULL)
64025 return -ENXIO;
64026@@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
64027 int err;
64028 struct net *net;
64029
64030+ if (gr_proc_is_restricted())
64031+ return -EACCES;
64032+
64033 err = -ENXIO;
64034 net = get_proc_net(inode);
64035 if (net == NULL)
64036diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64037index 7129046..6914844 100644
64038--- a/fs/proc/proc_sysctl.c
64039+++ b/fs/proc/proc_sysctl.c
64040@@ -11,13 +11,21 @@
64041 #include <linux/namei.h>
64042 #include <linux/mm.h>
64043 #include <linux/module.h>
64044+#include <linux/nsproxy.h>
64045+#ifdef CONFIG_GRKERNSEC
64046+#include <net/net_namespace.h>
64047+#endif
64048 #include "internal.h"
64049
64050+extern int gr_handle_chroot_sysctl(const int op);
64051+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64052+ const int op);
64053+
64054 static const struct dentry_operations proc_sys_dentry_operations;
64055 static const struct file_operations proc_sys_file_operations;
64056-static const struct inode_operations proc_sys_inode_operations;
64057+const struct inode_operations proc_sys_inode_operations;
64058 static const struct file_operations proc_sys_dir_file_operations;
64059-static const struct inode_operations proc_sys_dir_operations;
64060+const struct inode_operations proc_sys_dir_operations;
64061
64062 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64063 {
64064@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64065
64066 err = NULL;
64067 d_set_d_op(dentry, &proc_sys_dentry_operations);
64068+
64069+ gr_handle_proc_create(dentry, inode);
64070+
64071 d_add(dentry, inode);
64072
64073 out:
64074@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64075 struct inode *inode = file_inode(filp);
64076 struct ctl_table_header *head = grab_header(inode);
64077 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64078+ int op = write ? MAY_WRITE : MAY_READ;
64079 ssize_t error;
64080 size_t res;
64081
64082@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64083 * and won't be until we finish.
64084 */
64085 error = -EPERM;
64086- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64087+ if (sysctl_perm(head, table, op))
64088 goto out;
64089
64090 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64091@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64092 if (!table->proc_handler)
64093 goto out;
64094
64095+#ifdef CONFIG_GRKERNSEC
64096+ error = -EPERM;
64097+ if (gr_handle_chroot_sysctl(op))
64098+ goto out;
64099+ dget(filp->f_path.dentry);
64100+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64101+ dput(filp->f_path.dentry);
64102+ goto out;
64103+ }
64104+ dput(filp->f_path.dentry);
64105+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64106+ goto out;
64107+ if (write) {
64108+ if (current->nsproxy->net_ns != table->extra2) {
64109+ if (!capable(CAP_SYS_ADMIN))
64110+ goto out;
64111+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64112+ goto out;
64113+ }
64114+#endif
64115+
64116 /* careful: calling conventions are nasty here */
64117 res = count;
64118 error = table->proc_handler(table, write, buf, &res, ppos);
64119@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64120 return false;
64121 } else {
64122 d_set_d_op(child, &proc_sys_dentry_operations);
64123+
64124+ gr_handle_proc_create(child, inode);
64125+
64126 d_add(child, inode);
64127 }
64128 } else {
64129@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64130 if ((*pos)++ < ctx->pos)
64131 return true;
64132
64133+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64134+ return 0;
64135+
64136 if (unlikely(S_ISLNK(table->mode)))
64137 res = proc_sys_link_fill_cache(file, ctx, head, table);
64138 else
64139@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64140 if (IS_ERR(head))
64141 return PTR_ERR(head);
64142
64143+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64144+ return -ENOENT;
64145+
64146 generic_fillattr(inode, stat);
64147 if (table)
64148 stat->mode = (stat->mode & S_IFMT) | table->mode;
64149@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64150 .llseek = generic_file_llseek,
64151 };
64152
64153-static const struct inode_operations proc_sys_inode_operations = {
64154+const struct inode_operations proc_sys_inode_operations = {
64155 .permission = proc_sys_permission,
64156 .setattr = proc_sys_setattr,
64157 .getattr = proc_sys_getattr,
64158 };
64159
64160-static const struct inode_operations proc_sys_dir_operations = {
64161+const struct inode_operations proc_sys_dir_operations = {
64162 .lookup = proc_sys_lookup,
64163 .permission = proc_sys_permission,
64164 .setattr = proc_sys_setattr,
64165@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64166 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64167 const char *name, int namelen)
64168 {
64169- struct ctl_table *table;
64170+ ctl_table_no_const *table;
64171 struct ctl_dir *new;
64172 struct ctl_node *node;
64173 char *new_name;
64174@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64175 return NULL;
64176
64177 node = (struct ctl_node *)(new + 1);
64178- table = (struct ctl_table *)(node + 1);
64179+ table = (ctl_table_no_const *)(node + 1);
64180 new_name = (char *)(table + 2);
64181 memcpy(new_name, name, namelen);
64182 new_name[namelen] = '\0';
64183@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64184 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64185 struct ctl_table_root *link_root)
64186 {
64187- struct ctl_table *link_table, *entry, *link;
64188+ ctl_table_no_const *link_table, *link;
64189+ struct ctl_table *entry;
64190 struct ctl_table_header *links;
64191 struct ctl_node *node;
64192 char *link_name;
64193@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64194 return NULL;
64195
64196 node = (struct ctl_node *)(links + 1);
64197- link_table = (struct ctl_table *)(node + nr_entries);
64198+ link_table = (ctl_table_no_const *)(node + nr_entries);
64199 link_name = (char *)&link_table[nr_entries + 1];
64200
64201 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64202@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64203 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64204 struct ctl_table *table)
64205 {
64206- struct ctl_table *ctl_table_arg = NULL;
64207- struct ctl_table *entry, *files;
64208+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64209+ struct ctl_table *entry;
64210 int nr_files = 0;
64211 int nr_dirs = 0;
64212 int err = -ENOMEM;
64213@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64214 nr_files++;
64215 }
64216
64217- files = table;
64218 /* If there are mixed files and directories we need a new table */
64219 if (nr_dirs && nr_files) {
64220- struct ctl_table *new;
64221+ ctl_table_no_const *new;
64222 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64223 GFP_KERNEL);
64224 if (!files)
64225@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64226 /* Register everything except a directory full of subdirectories */
64227 if (nr_files || !nr_dirs) {
64228 struct ctl_table_header *header;
64229- header = __register_sysctl_table(set, path, files);
64230+ header = __register_sysctl_table(set, path, files ? files : table);
64231 if (!header) {
64232 kfree(ctl_table_arg);
64233 goto out;
64234diff --git a/fs/proc/root.c b/fs/proc/root.c
64235index 5dbadec..473af2f 100644
64236--- a/fs/proc/root.c
64237+++ b/fs/proc/root.c
64238@@ -185,7 +185,15 @@ void __init proc_root_init(void)
64239 proc_mkdir("openprom", NULL);
64240 #endif
64241 proc_tty_init();
64242+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64243+#ifdef CONFIG_GRKERNSEC_PROC_USER
64244+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64245+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64246+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64247+#endif
64248+#else
64249 proc_mkdir("bus", NULL);
64250+#endif
64251 proc_sys_init();
64252 }
64253
64254diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64255index 9d231e9..2e1b51a 100644
64256--- a/fs/proc/stat.c
64257+++ b/fs/proc/stat.c
64258@@ -11,6 +11,7 @@
64259 #include <linux/irqnr.h>
64260 #include <linux/cputime.h>
64261 #include <linux/tick.h>
64262+#include <linux/grsecurity.h>
64263
64264 #ifndef arch_irq_stat_cpu
64265 #define arch_irq_stat_cpu(cpu) 0
64266@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64267 u64 sum_softirq = 0;
64268 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64269 struct timespec boottime;
64270+ int unrestricted = 1;
64271+
64272+#ifdef CONFIG_GRKERNSEC_PROC_ADD
64273+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64274+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64275+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64276+ && !in_group_p(grsec_proc_gid)
64277+#endif
64278+ )
64279+ unrestricted = 0;
64280+#endif
64281+#endif
64282
64283 user = nice = system = idle = iowait =
64284 irq = softirq = steal = 0;
64285@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
64286 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64287 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64288 idle += get_idle_time(i);
64289- iowait += get_iowait_time(i);
64290- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64291- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64292- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64293- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64294- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64295- sum += kstat_cpu_irqs_sum(i);
64296- sum += arch_irq_stat_cpu(i);
64297+ if (unrestricted) {
64298+ iowait += get_iowait_time(i);
64299+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64300+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64301+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64302+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64303+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64304+ sum += kstat_cpu_irqs_sum(i);
64305+ sum += arch_irq_stat_cpu(i);
64306+ for (j = 0; j < NR_SOFTIRQS; j++) {
64307+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64308
64309- for (j = 0; j < NR_SOFTIRQS; j++) {
64310- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64311-
64312- per_softirq_sums[j] += softirq_stat;
64313- sum_softirq += softirq_stat;
64314+ per_softirq_sums[j] += softirq_stat;
64315+ sum_softirq += softirq_stat;
64316+ }
64317 }
64318 }
64319- sum += arch_irq_stat();
64320+ if (unrestricted)
64321+ sum += arch_irq_stat();
64322
64323 seq_puts(p, "cpu ");
64324 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64325@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
64326 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64327 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64328 idle = get_idle_time(i);
64329- iowait = get_iowait_time(i);
64330- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64331- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64332- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64333- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64334- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64335+ if (unrestricted) {
64336+ iowait = get_iowait_time(i);
64337+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64338+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64339+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64340+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64341+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64342+ }
64343 seq_printf(p, "cpu%d", i);
64344 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64345 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64346@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64347
64348 /* sum again ? it could be updated? */
64349 for_each_irq_nr(j)
64350- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64351+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64352
64353 seq_printf(p,
64354 "\nctxt %llu\n"
64355@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64356 "processes %lu\n"
64357 "procs_running %lu\n"
64358 "procs_blocked %lu\n",
64359- nr_context_switches(),
64360+ unrestricted ? nr_context_switches() : 0ULL,
64361 (unsigned long)jif,
64362- total_forks,
64363- nr_running(),
64364- nr_iowait());
64365+ unrestricted ? total_forks : 0UL,
64366+ unrestricted ? nr_running() : 0UL,
64367+ unrestricted ? nr_iowait() : 0UL);
64368
64369 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64370
64371diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64372index c4b2646..84f0d7b 100644
64373--- a/fs/proc/task_mmu.c
64374+++ b/fs/proc/task_mmu.c
64375@@ -13,12 +13,19 @@
64376 #include <linux/swap.h>
64377 #include <linux/swapops.h>
64378 #include <linux/mmu_notifier.h>
64379+#include <linux/grsecurity.h>
64380
64381 #include <asm/elf.h>
64382 #include <asm/uaccess.h>
64383 #include <asm/tlbflush.h>
64384 #include "internal.h"
64385
64386+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64387+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64388+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
64389+ _mm->pax_flags & MF_PAX_SEGMEXEC))
64390+#endif
64391+
64392 void task_mem(struct seq_file *m, struct mm_struct *mm)
64393 {
64394 unsigned long data, text, lib, swap;
64395@@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64396 "VmExe:\t%8lu kB\n"
64397 "VmLib:\t%8lu kB\n"
64398 "VmPTE:\t%8lu kB\n"
64399- "VmSwap:\t%8lu kB\n",
64400- hiwater_vm << (PAGE_SHIFT-10),
64401+ "VmSwap:\t%8lu kB\n"
64402+
64403+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64404+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64405+#endif
64406+
64407+ ,hiwater_vm << (PAGE_SHIFT-10),
64408 total_vm << (PAGE_SHIFT-10),
64409 mm->locked_vm << (PAGE_SHIFT-10),
64410 mm->pinned_vm << (PAGE_SHIFT-10),
64411@@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64412 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64413 (PTRS_PER_PTE * sizeof(pte_t) *
64414 atomic_long_read(&mm->nr_ptes)) >> 10,
64415- swap << (PAGE_SHIFT-10));
64416+ swap << (PAGE_SHIFT-10)
64417+
64418+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64419+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64420+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64421+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64422+#else
64423+ , mm->context.user_cs_base
64424+ , mm->context.user_cs_limit
64425+#endif
64426+#endif
64427+
64428+ );
64429 }
64430
64431 unsigned long task_vsize(struct mm_struct *mm)
64432@@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64433 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64434 }
64435
64436- /* We don't show the stack guard page in /proc/maps */
64437+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64438+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64439+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64440+#else
64441 start = vma->vm_start;
64442- if (stack_guard_page_start(vma, start))
64443- start += PAGE_SIZE;
64444 end = vma->vm_end;
64445- if (stack_guard_page_end(vma, end))
64446- end -= PAGE_SIZE;
64447+#endif
64448
64449 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64450 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64451@@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64452 flags & VM_WRITE ? 'w' : '-',
64453 flags & VM_EXEC ? 'x' : '-',
64454 flags & VM_MAYSHARE ? 's' : 'p',
64455+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64456+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64457+#else
64458 pgoff,
64459+#endif
64460 MAJOR(dev), MINOR(dev), ino);
64461
64462 /*
64463@@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64464 */
64465 if (file) {
64466 seq_pad(m, ' ');
64467- seq_path(m, &file->f_path, "\n");
64468+ seq_path(m, &file->f_path, "\n\\");
64469 goto done;
64470 }
64471
64472@@ -322,8 +350,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64473 * Thread stack in /proc/PID/task/TID/maps or
64474 * the main process stack.
64475 */
64476- if (!is_pid || (vma->vm_start <= mm->start_stack &&
64477- vma->vm_end >= mm->start_stack)) {
64478+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64479+ (vma->vm_start <= mm->start_stack &&
64480+ vma->vm_end >= mm->start_stack)) {
64481 name = "[stack]";
64482 } else {
64483 /* Thread stack in /proc/PID/maps */
64484@@ -347,6 +376,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64485 struct proc_maps_private *priv = m->private;
64486 struct task_struct *task = priv->task;
64487
64488+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64489+ if (current->exec_id != m->exec_id) {
64490+ gr_log_badprocpid("maps");
64491+ return 0;
64492+ }
64493+#endif
64494+
64495 show_map_vma(m, vma, is_pid);
64496
64497 if (m->count < m->size) /* vma is copied successfully */
64498@@ -587,12 +623,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64499 .private = &mss,
64500 };
64501
64502+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64503+ if (current->exec_id != m->exec_id) {
64504+ gr_log_badprocpid("smaps");
64505+ return 0;
64506+ }
64507+#endif
64508 memset(&mss, 0, sizeof mss);
64509- mss.vma = vma;
64510- /* mmap_sem is held in m_start */
64511- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64512- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64513-
64514+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64515+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64516+#endif
64517+ mss.vma = vma;
64518+ /* mmap_sem is held in m_start */
64519+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64520+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64521+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64522+ }
64523+#endif
64524 show_map_vma(m, vma, is_pid);
64525
64526 seq_printf(m,
64527@@ -610,7 +657,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64528 "KernelPageSize: %8lu kB\n"
64529 "MMUPageSize: %8lu kB\n"
64530 "Locked: %8lu kB\n",
64531+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64532+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64533+#else
64534 (vma->vm_end - vma->vm_start) >> 10,
64535+#endif
64536 mss.resident >> 10,
64537 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64538 mss.shared_clean >> 10,
64539@@ -1388,6 +1439,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64540 char buffer[64];
64541 int nid;
64542
64543+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64544+ if (current->exec_id != m->exec_id) {
64545+ gr_log_badprocpid("numa_maps");
64546+ return 0;
64547+ }
64548+#endif
64549+
64550 if (!mm)
64551 return 0;
64552
64553@@ -1405,11 +1463,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64554 mpol_to_str(buffer, sizeof(buffer), pol);
64555 mpol_cond_put(pol);
64556
64557+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64558+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64559+#else
64560 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64561+#endif
64562
64563 if (file) {
64564 seq_printf(m, " file=");
64565- seq_path(m, &file->f_path, "\n\t= ");
64566+ seq_path(m, &file->f_path, "\n\t\\= ");
64567 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64568 seq_printf(m, " heap");
64569 } else {
64570diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64571index 678455d..ebd3245 100644
64572--- a/fs/proc/task_nommu.c
64573+++ b/fs/proc/task_nommu.c
64574@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64575 else
64576 bytes += kobjsize(mm);
64577
64578- if (current->fs && current->fs->users > 1)
64579+ if (current->fs && atomic_read(&current->fs->users) > 1)
64580 sbytes += kobjsize(current->fs);
64581 else
64582 bytes += kobjsize(current->fs);
64583@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64584
64585 if (file) {
64586 seq_pad(m, ' ');
64587- seq_path(m, &file->f_path, "");
64588+ seq_path(m, &file->f_path, "\n\\");
64589 } else if (mm) {
64590 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64591
64592diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64593index 6a8e785..41f2a6c 100644
64594--- a/fs/proc/vmcore.c
64595+++ b/fs/proc/vmcore.c
64596@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64597 nr_bytes = count;
64598
64599 /* If pfn is not ram, return zeros for sparse dump files */
64600- if (pfn_is_ram(pfn) == 0)
64601- memset(buf, 0, nr_bytes);
64602- else {
64603+ if (pfn_is_ram(pfn) == 0) {
64604+ if (userbuf) {
64605+ if (clear_user((char __force_user *)buf, nr_bytes))
64606+ return -EFAULT;
64607+ } else
64608+ memset(buf, 0, nr_bytes);
64609+ } else {
64610 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64611 offset, userbuf);
64612 if (tmp < 0)
64613@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64614 static int copy_to(void *target, void *src, size_t size, int userbuf)
64615 {
64616 if (userbuf) {
64617- if (copy_to_user((char __user *) target, src, size))
64618+ if (copy_to_user((char __force_user *) target, src, size))
64619 return -EFAULT;
64620 } else {
64621 memcpy(target, src, size);
64622@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64623 if (*fpos < m->offset + m->size) {
64624 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64625 start = m->paddr + *fpos - m->offset;
64626- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64627+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64628 if (tmp < 0)
64629 return tmp;
64630 buflen -= tsz;
64631@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64632 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64633 size_t buflen, loff_t *fpos)
64634 {
64635- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64636+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64637 }
64638
64639 /*
64640diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64641index b00fcc9..e0c6381 100644
64642--- a/fs/qnx6/qnx6.h
64643+++ b/fs/qnx6/qnx6.h
64644@@ -74,7 +74,7 @@ enum {
64645 BYTESEX_BE,
64646 };
64647
64648-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64649+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64650 {
64651 if (sbi->s_bytesex == BYTESEX_LE)
64652 return le64_to_cpu((__force __le64)n);
64653@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64654 return (__force __fs64)cpu_to_be64(n);
64655 }
64656
64657-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64658+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64659 {
64660 if (sbi->s_bytesex == BYTESEX_LE)
64661 return le32_to_cpu((__force __le32)n);
64662diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64663index 72d2917..c917c12 100644
64664--- a/fs/quota/netlink.c
64665+++ b/fs/quota/netlink.c
64666@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64667 void quota_send_warning(struct kqid qid, dev_t dev,
64668 const char warntype)
64669 {
64670- static atomic_t seq;
64671+ static atomic_unchecked_t seq;
64672 struct sk_buff *skb;
64673 void *msg_head;
64674 int ret;
64675@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64676 "VFS: Not enough memory to send quota warning.\n");
64677 return;
64678 }
64679- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64680+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64681 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64682 if (!msg_head) {
64683 printk(KERN_ERR
64684diff --git a/fs/read_write.c b/fs/read_write.c
64685index 31c6efa..a068805 100644
64686--- a/fs/read_write.c
64687+++ b/fs/read_write.c
64688@@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64689
64690 old_fs = get_fs();
64691 set_fs(get_ds());
64692- p = (__force const char __user *)buf;
64693+ p = (const char __force_user *)buf;
64694 if (count > MAX_RW_COUNT)
64695 count = MAX_RW_COUNT;
64696 if (file->f_op->write)
64697diff --git a/fs/readdir.c b/fs/readdir.c
64698index 5b53d99..a6c3049 100644
64699--- a/fs/readdir.c
64700+++ b/fs/readdir.c
64701@@ -17,6 +17,7 @@
64702 #include <linux/security.h>
64703 #include <linux/syscalls.h>
64704 #include <linux/unistd.h>
64705+#include <linux/namei.h>
64706
64707 #include <asm/uaccess.h>
64708
64709@@ -69,6 +70,7 @@ struct old_linux_dirent {
64710 struct readdir_callback {
64711 struct dir_context ctx;
64712 struct old_linux_dirent __user * dirent;
64713+ struct file * file;
64714 int result;
64715 };
64716
64717@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64718 buf->result = -EOVERFLOW;
64719 return -EOVERFLOW;
64720 }
64721+
64722+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64723+ return 0;
64724+
64725 buf->result++;
64726 dirent = buf->dirent;
64727 if (!access_ok(VERIFY_WRITE, dirent,
64728@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64729 if (!f.file)
64730 return -EBADF;
64731
64732+ buf.file = f.file;
64733 error = iterate_dir(f.file, &buf.ctx);
64734 if (buf.result)
64735 error = buf.result;
64736@@ -142,6 +149,7 @@ struct getdents_callback {
64737 struct dir_context ctx;
64738 struct linux_dirent __user * current_dir;
64739 struct linux_dirent __user * previous;
64740+ struct file * file;
64741 int count;
64742 int error;
64743 };
64744@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64745 buf->error = -EOVERFLOW;
64746 return -EOVERFLOW;
64747 }
64748+
64749+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64750+ return 0;
64751+
64752 dirent = buf->previous;
64753 if (dirent) {
64754 if (__put_user(offset, &dirent->d_off))
64755@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64756 if (!f.file)
64757 return -EBADF;
64758
64759+ buf.file = f.file;
64760 error = iterate_dir(f.file, &buf.ctx);
64761 if (error >= 0)
64762 error = buf.error;
64763@@ -226,6 +239,7 @@ struct getdents_callback64 {
64764 struct dir_context ctx;
64765 struct linux_dirent64 __user * current_dir;
64766 struct linux_dirent64 __user * previous;
64767+ struct file *file;
64768 int count;
64769 int error;
64770 };
64771@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64772 buf->error = -EINVAL; /* only used if we fail.. */
64773 if (reclen > buf->count)
64774 return -EINVAL;
64775+
64776+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64777+ return 0;
64778+
64779 dirent = buf->previous;
64780 if (dirent) {
64781 if (__put_user(offset, &dirent->d_off))
64782@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64783 if (!f.file)
64784 return -EBADF;
64785
64786+ buf.file = f.file;
64787 error = iterate_dir(f.file, &buf.ctx);
64788 if (error >= 0)
64789 error = buf.error;
64790diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64791index 9a3c68c..767933e 100644
64792--- a/fs/reiserfs/do_balan.c
64793+++ b/fs/reiserfs/do_balan.c
64794@@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64795 return;
64796 }
64797
64798- atomic_inc(&(fs_generation(tb->tb_sb)));
64799+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64800 do_balance_starts(tb);
64801
64802 /* balance leaf returns 0 except if combining L R and S into
64803diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64804index ee382ef..f4eb6eb5 100644
64805--- a/fs/reiserfs/item_ops.c
64806+++ b/fs/reiserfs/item_ops.c
64807@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64808 }
64809
64810 static struct item_operations errcatch_ops = {
64811- errcatch_bytes_number,
64812- errcatch_decrement_key,
64813- errcatch_is_left_mergeable,
64814- errcatch_print_item,
64815- errcatch_check_item,
64816+ .bytes_number = errcatch_bytes_number,
64817+ .decrement_key = errcatch_decrement_key,
64818+ .is_left_mergeable = errcatch_is_left_mergeable,
64819+ .print_item = errcatch_print_item,
64820+ .check_item = errcatch_check_item,
64821
64822- errcatch_create_vi,
64823- errcatch_check_left,
64824- errcatch_check_right,
64825- errcatch_part_size,
64826- errcatch_unit_num,
64827- errcatch_print_vi
64828+ .create_vi = errcatch_create_vi,
64829+ .check_left = errcatch_check_left,
64830+ .check_right = errcatch_check_right,
64831+ .part_size = errcatch_part_size,
64832+ .unit_num = errcatch_unit_num,
64833+ .print_vi = errcatch_print_vi
64834 };
64835
64836 //////////////////////////////////////////////////////////////////////////////
64837diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64838index 02b0b7d..c85018b 100644
64839--- a/fs/reiserfs/procfs.c
64840+++ b/fs/reiserfs/procfs.c
64841@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64842 "SMALL_TAILS " : "NO_TAILS ",
64843 replay_only(sb) ? "REPLAY_ONLY " : "",
64844 convert_reiserfs(sb) ? "CONV " : "",
64845- atomic_read(&r->s_generation_counter),
64846+ atomic_read_unchecked(&r->s_generation_counter),
64847 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64848 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64849 SF(s_good_search_by_key_reada), SF(s_bmaps),
64850diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64851index 83d4eac..04e39a7 100644
64852--- a/fs/reiserfs/reiserfs.h
64853+++ b/fs/reiserfs/reiserfs.h
64854@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64855 /* Comment? -Hans */
64856 wait_queue_head_t s_wait;
64857 /* To be obsoleted soon by per buffer seals.. -Hans */
64858- atomic_t s_generation_counter; // increased by one every time the
64859+ atomic_unchecked_t s_generation_counter; // increased by one every time the
64860 // tree gets re-balanced
64861 unsigned long s_properties; /* File system properties. Currently holds
64862 on-disk FS format */
64863@@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64864 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64865
64866 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64867-#define get_generation(s) atomic_read (&fs_generation(s))
64868+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64869 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64870 #define __fs_changed(gen,s) (gen != get_generation (s))
64871 #define fs_changed(gen,s) \
64872diff --git a/fs/select.c b/fs/select.c
64873index 467bb1c..cf9d65a 100644
64874--- a/fs/select.c
64875+++ b/fs/select.c
64876@@ -20,6 +20,7 @@
64877 #include <linux/export.h>
64878 #include <linux/slab.h>
64879 #include <linux/poll.h>
64880+#include <linux/security.h>
64881 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64882 #include <linux/file.h>
64883 #include <linux/fdtable.h>
64884@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64885 struct poll_list *walk = head;
64886 unsigned long todo = nfds;
64887
64888+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64889 if (nfds > rlimit(RLIMIT_NOFILE))
64890 return -EINVAL;
64891
64892diff --git a/fs/seq_file.c b/fs/seq_file.c
64893index 1d641bb..c2f4743 100644
64894--- a/fs/seq_file.c
64895+++ b/fs/seq_file.c
64896@@ -10,6 +10,8 @@
64897 #include <linux/seq_file.h>
64898 #include <linux/slab.h>
64899 #include <linux/cred.h>
64900+#include <linux/sched.h>
64901+#include <linux/grsecurity.h>
64902
64903 #include <asm/uaccess.h>
64904 #include <asm/page.h>
64905@@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64906 #ifdef CONFIG_USER_NS
64907 p->user_ns = file->f_cred->user_ns;
64908 #endif
64909+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64910+ p->exec_id = current->exec_id;
64911+#endif
64912
64913 /*
64914 * Wrappers around seq_open(e.g. swaps_open) need to be
64915@@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
64916 }
64917 EXPORT_SYMBOL(seq_open);
64918
64919+
64920+int seq_open_restrict(struct file *file, const struct seq_operations *op)
64921+{
64922+ if (gr_proc_is_restricted())
64923+ return -EACCES;
64924+
64925+ return seq_open(file, op);
64926+}
64927+EXPORT_SYMBOL(seq_open_restrict);
64928+
64929 static int traverse(struct seq_file *m, loff_t offset)
64930 {
64931 loff_t pos = 0, index;
64932@@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64933 return 0;
64934 }
64935 if (!m->buf) {
64936- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64937+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64938 if (!m->buf)
64939 return -ENOMEM;
64940 }
64941@@ -137,7 +152,7 @@ Eoverflow:
64942 m->op->stop(m, p);
64943 kfree(m->buf);
64944 m->count = 0;
64945- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64946+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64947 return !m->buf ? -ENOMEM : -EAGAIN;
64948 }
64949
64950@@ -153,7 +168,7 @@ Eoverflow:
64951 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64952 {
64953 struct seq_file *m = file->private_data;
64954- size_t copied = 0;
64955+ ssize_t copied = 0;
64956 loff_t pos;
64957 size_t n;
64958 void *p;
64959@@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64960
64961 /* grab buffer if we didn't have one */
64962 if (!m->buf) {
64963- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64964+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64965 if (!m->buf)
64966 goto Enomem;
64967 }
64968@@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64969 m->op->stop(m, p);
64970 kfree(m->buf);
64971 m->count = 0;
64972- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64973+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64974 if (!m->buf)
64975 goto Enomem;
64976 m->version = 0;
64977@@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
64978 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
64979 void *data)
64980 {
64981- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
64982+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
64983 int res = -ENOMEM;
64984
64985 if (op) {
64986@@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
64987 }
64988 EXPORT_SYMBOL(single_open_size);
64989
64990+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
64991+ void *data)
64992+{
64993+ if (gr_proc_is_restricted())
64994+ return -EACCES;
64995+
64996+ return single_open(file, show, data);
64997+}
64998+EXPORT_SYMBOL(single_open_restrict);
64999+
65000+
65001 int single_release(struct inode *inode, struct file *file)
65002 {
65003 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65004diff --git a/fs/splice.c b/fs/splice.c
65005index e246954..bd4f5b5 100644
65006--- a/fs/splice.c
65007+++ b/fs/splice.c
65008@@ -192,7 +192,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65009 pipe_lock(pipe);
65010
65011 for (;;) {
65012- if (!pipe->readers) {
65013+ if (!atomic_read(&pipe->readers)) {
65014 send_sig(SIGPIPE, current, 0);
65015 if (!ret)
65016 ret = -EPIPE;
65017@@ -215,7 +215,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65018 page_nr++;
65019 ret += buf->len;
65020
65021- if (pipe->files)
65022+ if (atomic_read(&pipe->files))
65023 do_wakeup = 1;
65024
65025 if (!--spd->nr_pages)
65026@@ -246,9 +246,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65027 do_wakeup = 0;
65028 }
65029
65030- pipe->waiting_writers++;
65031+ atomic_inc(&pipe->waiting_writers);
65032 pipe_wait(pipe);
65033- pipe->waiting_writers--;
65034+ atomic_dec(&pipe->waiting_writers);
65035 }
65036
65037 pipe_unlock(pipe);
65038@@ -575,7 +575,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65039 old_fs = get_fs();
65040 set_fs(get_ds());
65041 /* The cast to a user pointer is valid due to the set_fs() */
65042- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65043+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65044 set_fs(old_fs);
65045
65046 return res;
65047@@ -590,7 +590,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65048 old_fs = get_fs();
65049 set_fs(get_ds());
65050 /* The cast to a user pointer is valid due to the set_fs() */
65051- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65052+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65053 set_fs(old_fs);
65054
65055 return res;
65056@@ -643,7 +643,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65057 goto err;
65058
65059 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65060- vec[i].iov_base = (void __user *) page_address(page);
65061+ vec[i].iov_base = (void __force_user *) page_address(page);
65062 vec[i].iov_len = this_len;
65063 spd.pages[i] = page;
65064 spd.nr_pages++;
65065@@ -839,7 +839,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65066 ops->release(pipe, buf);
65067 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65068 pipe->nrbufs--;
65069- if (pipe->files)
65070+ if (atomic_read(&pipe->files))
65071 sd->need_wakeup = true;
65072 }
65073
65074@@ -864,10 +864,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65075 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65076 {
65077 while (!pipe->nrbufs) {
65078- if (!pipe->writers)
65079+ if (!atomic_read(&pipe->writers))
65080 return 0;
65081
65082- if (!pipe->waiting_writers && sd->num_spliced)
65083+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65084 return 0;
65085
65086 if (sd->flags & SPLICE_F_NONBLOCK)
65087@@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65088 * out of the pipe right after the splice_to_pipe(). So set
65089 * PIPE_READERS appropriately.
65090 */
65091- pipe->readers = 1;
65092+ atomic_set(&pipe->readers, 1);
65093
65094 current->splice_pipe = pipe;
65095 }
65096@@ -1485,6 +1485,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65097
65098 partial[buffers].offset = off;
65099 partial[buffers].len = plen;
65100+ partial[buffers].private = 0;
65101
65102 off = 0;
65103 len -= plen;
65104@@ -1721,9 +1722,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65105 ret = -ERESTARTSYS;
65106 break;
65107 }
65108- if (!pipe->writers)
65109+ if (!atomic_read(&pipe->writers))
65110 break;
65111- if (!pipe->waiting_writers) {
65112+ if (!atomic_read(&pipe->waiting_writers)) {
65113 if (flags & SPLICE_F_NONBLOCK) {
65114 ret = -EAGAIN;
65115 break;
65116@@ -1755,7 +1756,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65117 pipe_lock(pipe);
65118
65119 while (pipe->nrbufs >= pipe->buffers) {
65120- if (!pipe->readers) {
65121+ if (!atomic_read(&pipe->readers)) {
65122 send_sig(SIGPIPE, current, 0);
65123 ret = -EPIPE;
65124 break;
65125@@ -1768,9 +1769,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65126 ret = -ERESTARTSYS;
65127 break;
65128 }
65129- pipe->waiting_writers++;
65130+ atomic_inc(&pipe->waiting_writers);
65131 pipe_wait(pipe);
65132- pipe->waiting_writers--;
65133+ atomic_dec(&pipe->waiting_writers);
65134 }
65135
65136 pipe_unlock(pipe);
65137@@ -1806,14 +1807,14 @@ retry:
65138 pipe_double_lock(ipipe, opipe);
65139
65140 do {
65141- if (!opipe->readers) {
65142+ if (!atomic_read(&opipe->readers)) {
65143 send_sig(SIGPIPE, current, 0);
65144 if (!ret)
65145 ret = -EPIPE;
65146 break;
65147 }
65148
65149- if (!ipipe->nrbufs && !ipipe->writers)
65150+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65151 break;
65152
65153 /*
65154@@ -1910,7 +1911,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65155 pipe_double_lock(ipipe, opipe);
65156
65157 do {
65158- if (!opipe->readers) {
65159+ if (!atomic_read(&opipe->readers)) {
65160 send_sig(SIGPIPE, current, 0);
65161 if (!ret)
65162 ret = -EPIPE;
65163@@ -1955,7 +1956,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65164 * return EAGAIN if we have the potential of some data in the
65165 * future, otherwise just return 0
65166 */
65167- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65168+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65169 ret = -EAGAIN;
65170
65171 pipe_unlock(ipipe);
65172diff --git a/fs/stat.c b/fs/stat.c
65173index ae0c3ce..9ee641c 100644
65174--- a/fs/stat.c
65175+++ b/fs/stat.c
65176@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65177 stat->gid = inode->i_gid;
65178 stat->rdev = inode->i_rdev;
65179 stat->size = i_size_read(inode);
65180- stat->atime = inode->i_atime;
65181- stat->mtime = inode->i_mtime;
65182+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65183+ stat->atime = inode->i_ctime;
65184+ stat->mtime = inode->i_ctime;
65185+ } else {
65186+ stat->atime = inode->i_atime;
65187+ stat->mtime = inode->i_mtime;
65188+ }
65189 stat->ctime = inode->i_ctime;
65190 stat->blksize = (1 << inode->i_blkbits);
65191 stat->blocks = inode->i_blocks;
65192@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65193 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65194 {
65195 struct inode *inode = path->dentry->d_inode;
65196+ int retval;
65197
65198- if (inode->i_op->getattr)
65199- return inode->i_op->getattr(path->mnt, path->dentry, stat);
65200+ if (inode->i_op->getattr) {
65201+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65202+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65203+ stat->atime = stat->ctime;
65204+ stat->mtime = stat->ctime;
65205+ }
65206+ return retval;
65207+ }
65208
65209 generic_fillattr(inode, stat);
65210 return 0;
65211diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65212index 0b45ff4..847de5b 100644
65213--- a/fs/sysfs/dir.c
65214+++ b/fs/sysfs/dir.c
65215@@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65216 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65217 {
65218 struct kernfs_node *parent, *kn;
65219+ const char *name;
65220+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65221+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65222+ const char *parent_name;
65223+#endif
65224
65225 BUG_ON(!kobj);
65226
65227+ name = kobject_name(kobj);
65228+
65229 if (kobj->parent)
65230 parent = kobj->parent->sd;
65231 else
65232@@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65233 if (!parent)
65234 return -ENOENT;
65235
65236- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65237- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65238+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65239+ parent_name = parent->name;
65240+ mode = S_IRWXU;
65241+
65242+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65243+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65244+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65245+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65246+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
65247+#endif
65248+
65249+ kn = kernfs_create_dir_ns(parent, name,
65250+ mode, kobj, ns);
65251 if (IS_ERR(kn)) {
65252 if (PTR_ERR(kn) == -EEXIST)
65253- sysfs_warn_dup(parent, kobject_name(kobj));
65254+ sysfs_warn_dup(parent, name);
65255 return PTR_ERR(kn);
65256 }
65257
65258diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65259index 69d4889..a810bd4 100644
65260--- a/fs/sysv/sysv.h
65261+++ b/fs/sysv/sysv.h
65262@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65263 #endif
65264 }
65265
65266-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65267+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65268 {
65269 if (sbi->s_bytesex == BYTESEX_PDP)
65270 return PDP_swab((__force __u32)n);
65271diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65272index e18b988..f1d4ad0f 100644
65273--- a/fs/ubifs/io.c
65274+++ b/fs/ubifs/io.c
65275@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65276 return err;
65277 }
65278
65279-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65280+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65281 {
65282 int err;
65283
65284diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65285index c175b4d..8f36a16 100644
65286--- a/fs/udf/misc.c
65287+++ b/fs/udf/misc.c
65288@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65289
65290 u8 udf_tag_checksum(const struct tag *t)
65291 {
65292- u8 *data = (u8 *)t;
65293+ const u8 *data = (const u8 *)t;
65294 u8 checksum = 0;
65295 int i;
65296 for (i = 0; i < sizeof(struct tag); ++i)
65297diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65298index 8d974c4..b82f6ec 100644
65299--- a/fs/ufs/swab.h
65300+++ b/fs/ufs/swab.h
65301@@ -22,7 +22,7 @@ enum {
65302 BYTESEX_BE
65303 };
65304
65305-static inline u64
65306+static inline u64 __intentional_overflow(-1)
65307 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65308 {
65309 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65310@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65311 return (__force __fs64)cpu_to_be64(n);
65312 }
65313
65314-static inline u32
65315+static inline u32 __intentional_overflow(-1)
65316 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65317 {
65318 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65319diff --git a/fs/utimes.c b/fs/utimes.c
65320index aa138d6..5f3a811 100644
65321--- a/fs/utimes.c
65322+++ b/fs/utimes.c
65323@@ -1,6 +1,7 @@
65324 #include <linux/compiler.h>
65325 #include <linux/file.h>
65326 #include <linux/fs.h>
65327+#include <linux/security.h>
65328 #include <linux/linkage.h>
65329 #include <linux/mount.h>
65330 #include <linux/namei.h>
65331@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65332 }
65333 }
65334 retry_deleg:
65335+
65336+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65337+ error = -EACCES;
65338+ goto mnt_drop_write_and_out;
65339+ }
65340+
65341 mutex_lock(&inode->i_mutex);
65342 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65343 mutex_unlock(&inode->i_mutex);
65344diff --git a/fs/xattr.c b/fs/xattr.c
65345index 3377dff..f394815 100644
65346--- a/fs/xattr.c
65347+++ b/fs/xattr.c
65348@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65349 return rc;
65350 }
65351
65352+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65353+ssize_t
65354+pax_getxattr(struct dentry *dentry, void *value, size_t size)
65355+{
65356+ struct inode *inode = dentry->d_inode;
65357+ ssize_t error;
65358+
65359+ error = inode_permission(inode, MAY_EXEC);
65360+ if (error)
65361+ return error;
65362+
65363+ if (inode->i_op->getxattr)
65364+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65365+ else
65366+ error = -EOPNOTSUPP;
65367+
65368+ return error;
65369+}
65370+EXPORT_SYMBOL(pax_getxattr);
65371+#endif
65372+
65373 ssize_t
65374 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65375 {
65376@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65377 * Extended attribute SET operations
65378 */
65379 static long
65380-setxattr(struct dentry *d, const char __user *name, const void __user *value,
65381+setxattr(struct path *path, const char __user *name, const void __user *value,
65382 size_t size, int flags)
65383 {
65384 int error;
65385@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65386 posix_acl_fix_xattr_from_user(kvalue, size);
65387 }
65388
65389- error = vfs_setxattr(d, kname, kvalue, size, flags);
65390+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65391+ error = -EACCES;
65392+ goto out;
65393+ }
65394+
65395+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65396 out:
65397 if (vvalue)
65398 vfree(vvalue);
65399@@ -377,7 +403,7 @@ retry:
65400 return error;
65401 error = mnt_want_write(path.mnt);
65402 if (!error) {
65403- error = setxattr(path.dentry, name, value, size, flags);
65404+ error = setxattr(&path, name, value, size, flags);
65405 mnt_drop_write(path.mnt);
65406 }
65407 path_put(&path);
65408@@ -401,7 +427,7 @@ retry:
65409 return error;
65410 error = mnt_want_write(path.mnt);
65411 if (!error) {
65412- error = setxattr(path.dentry, name, value, size, flags);
65413+ error = setxattr(&path, name, value, size, flags);
65414 mnt_drop_write(path.mnt);
65415 }
65416 path_put(&path);
65417@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65418 const void __user *,value, size_t, size, int, flags)
65419 {
65420 struct fd f = fdget(fd);
65421- struct dentry *dentry;
65422 int error = -EBADF;
65423
65424 if (!f.file)
65425 return error;
65426- dentry = f.file->f_path.dentry;
65427- audit_inode(NULL, dentry, 0);
65428+ audit_inode(NULL, f.file->f_path.dentry, 0);
65429 error = mnt_want_write_file(f.file);
65430 if (!error) {
65431- error = setxattr(dentry, name, value, size, flags);
65432+ error = setxattr(&f.file->f_path, name, value, size, flags);
65433 mnt_drop_write_file(f.file);
65434 }
65435 fdput(f);
65436@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65437 * Extended attribute REMOVE operations
65438 */
65439 static long
65440-removexattr(struct dentry *d, const char __user *name)
65441+removexattr(struct path *path, const char __user *name)
65442 {
65443 int error;
65444 char kname[XATTR_NAME_MAX + 1];
65445@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65446 if (error < 0)
65447 return error;
65448
65449- return vfs_removexattr(d, kname);
65450+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65451+ return -EACCES;
65452+
65453+ return vfs_removexattr(path->dentry, kname);
65454 }
65455
65456 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65457@@ -652,7 +679,7 @@ retry:
65458 return error;
65459 error = mnt_want_write(path.mnt);
65460 if (!error) {
65461- error = removexattr(path.dentry, name);
65462+ error = removexattr(&path, name);
65463 mnt_drop_write(path.mnt);
65464 }
65465 path_put(&path);
65466@@ -675,7 +702,7 @@ retry:
65467 return error;
65468 error = mnt_want_write(path.mnt);
65469 if (!error) {
65470- error = removexattr(path.dentry, name);
65471+ error = removexattr(&path, name);
65472 mnt_drop_write(path.mnt);
65473 }
65474 path_put(&path);
65475@@ -689,16 +716,16 @@ retry:
65476 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65477 {
65478 struct fd f = fdget(fd);
65479- struct dentry *dentry;
65480+ struct path *path;
65481 int error = -EBADF;
65482
65483 if (!f.file)
65484 return error;
65485- dentry = f.file->f_path.dentry;
65486- audit_inode(NULL, dentry, 0);
65487+ path = &f.file->f_path;
65488+ audit_inode(NULL, path->dentry, 0);
65489 error = mnt_want_write_file(f.file);
65490 if (!error) {
65491- error = removexattr(dentry, name);
65492+ error = removexattr(path, name);
65493 mnt_drop_write_file(f.file);
65494 }
65495 fdput(f);
65496diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65497index f0efc7e..ba72910 100644
65498--- a/fs/xfs/xfs_bmap.c
65499+++ b/fs/xfs/xfs_bmap.c
65500@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65501
65502 #else
65503 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65504-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65505+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65506 #endif /* DEBUG */
65507
65508 /*
65509diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65510index aead369..0dfecfd 100644
65511--- a/fs/xfs/xfs_dir2_readdir.c
65512+++ b/fs/xfs/xfs_dir2_readdir.c
65513@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65514 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65515 filetype = dp->d_ops->sf_get_ftype(sfep);
65516 ctx->pos = off & 0x7fffffff;
65517- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65518+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65519+ char name[sfep->namelen];
65520+ memcpy(name, sfep->name, sfep->namelen);
65521+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65522+ return 0;
65523+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65524 xfs_dir3_get_dtype(mp, filetype)))
65525 return 0;
65526 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65527diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65528index 6152cbe..f0f9eaa 100644
65529--- a/fs/xfs/xfs_ioctl.c
65530+++ b/fs/xfs/xfs_ioctl.c
65531@@ -122,7 +122,7 @@ xfs_find_handle(
65532 }
65533
65534 error = -EFAULT;
65535- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65536+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65537 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65538 goto out_put;
65539
65540diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65541new file mode 100644
65542index 0000000..bfd482c
65543--- /dev/null
65544+++ b/grsecurity/Kconfig
65545@@ -0,0 +1,1176 @@
65546+#
65547+# grecurity configuration
65548+#
65549+menu "Memory Protections"
65550+depends on GRKERNSEC
65551+
65552+config GRKERNSEC_KMEM
65553+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65554+ default y if GRKERNSEC_CONFIG_AUTO
65555+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65556+ help
65557+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65558+ be written to or read from to modify or leak the contents of the running
65559+ kernel. /dev/port will also not be allowed to be opened, writing to
65560+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65561+ If you have module support disabled, enabling this will close up several
65562+ ways that are currently used to insert malicious code into the running
65563+ kernel.
65564+
65565+ Even with this feature enabled, we still highly recommend that
65566+ you use the RBAC system, as it is still possible for an attacker to
65567+ modify the running kernel through other more obscure methods.
65568+
65569+ It is highly recommended that you say Y here if you meet all the
65570+ conditions above.
65571+
65572+config GRKERNSEC_VM86
65573+ bool "Restrict VM86 mode"
65574+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65575+ depends on X86_32
65576+
65577+ help
65578+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65579+ make use of a special execution mode on 32bit x86 processors called
65580+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65581+ video cards and will still work with this option enabled. The purpose
65582+ of the option is to prevent exploitation of emulation errors in
65583+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
65584+ Nearly all users should be able to enable this option.
65585+
65586+config GRKERNSEC_IO
65587+ bool "Disable privileged I/O"
65588+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65589+ depends on X86
65590+ select RTC_CLASS
65591+ select RTC_INTF_DEV
65592+ select RTC_DRV_CMOS
65593+
65594+ help
65595+ If you say Y here, all ioperm and iopl calls will return an error.
65596+ Ioperm and iopl can be used to modify the running kernel.
65597+ Unfortunately, some programs need this access to operate properly,
65598+ the most notable of which are XFree86 and hwclock. hwclock can be
65599+ remedied by having RTC support in the kernel, so real-time
65600+ clock support is enabled if this option is enabled, to ensure
65601+ that hwclock operates correctly. If hwclock still does not work,
65602+ either update udev or symlink /dev/rtc to /dev/rtc0.
65603+
65604+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
65605+ you may not be able to boot into a graphical environment with this
65606+ option enabled. In this case, you should use the RBAC system instead.
65607+
65608+config GRKERNSEC_JIT_HARDEN
65609+ bool "Harden BPF JIT against spray attacks"
65610+ default y if GRKERNSEC_CONFIG_AUTO
65611+ depends on BPF_JIT && X86
65612+ help
65613+ If you say Y here, the native code generated by the kernel's Berkeley
65614+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65615+ attacks that attempt to fit attacker-beneficial instructions in
65616+ 32bit immediate fields of JIT-generated native instructions. The
65617+ attacker will generally aim to cause an unintended instruction sequence
65618+ of JIT-generated native code to execute by jumping into the middle of
65619+ a generated instruction. This feature effectively randomizes the 32bit
65620+ immediate constants present in the generated code to thwart such attacks.
65621+
65622+ If you're using KERNEXEC, it's recommended that you enable this option
65623+ to supplement the hardening of the kernel.
65624+
65625+config GRKERNSEC_PERF_HARDEN
65626+ bool "Disable unprivileged PERF_EVENTS usage by default"
65627+ default y if GRKERNSEC_CONFIG_AUTO
65628+ depends on PERF_EVENTS
65629+ help
65630+ If you say Y here, the range of acceptable values for the
65631+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65632+ default to a new value: 3. When the sysctl is set to this value, no
65633+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65634+
65635+ Though PERF_EVENTS can be used legitimately for performance monitoring
65636+ and low-level application profiling, it is forced on regardless of
65637+ configuration, has been at fault for several vulnerabilities, and
65638+ creates new opportunities for side channels and other information leaks.
65639+
65640+ This feature puts PERF_EVENTS into a secure default state and permits
65641+ the administrator to change out of it temporarily if unprivileged
65642+ application profiling is needed.
65643+
65644+config GRKERNSEC_RAND_THREADSTACK
65645+ bool "Insert random gaps between thread stacks"
65646+ default y if GRKERNSEC_CONFIG_AUTO
65647+ depends on PAX_RANDMMAP && !PPC
65648+ help
65649+ If you say Y here, a random-sized gap will be enforced between allocated
65650+ thread stacks. Glibc's NPTL and other threading libraries that
65651+ pass MAP_STACK to the kernel for thread stack allocation are supported.
65652+ The implementation currently provides 8 bits of entropy for the gap.
65653+
65654+ Many distributions do not compile threaded remote services with the
65655+ -fstack-check argument to GCC, causing the variable-sized stack-based
65656+ allocator, alloca(), to not probe the stack on allocation. This
65657+ permits an unbounded alloca() to skip over any guard page and potentially
65658+ modify another thread's stack reliably. An enforced random gap
65659+ reduces the reliability of such an attack and increases the chance
65660+ that such a read/write to another thread's stack instead lands in
65661+ an unmapped area, causing a crash and triggering grsecurity's
65662+ anti-bruteforcing logic.
65663+
65664+config GRKERNSEC_PROC_MEMMAP
65665+ bool "Harden ASLR against information leaks and entropy reduction"
65666+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65667+ depends on PAX_NOEXEC || PAX_ASLR
65668+ help
65669+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65670+ give no information about the addresses of its mappings if
65671+ PaX features that rely on random addresses are enabled on the task.
65672+ In addition to sanitizing this information and disabling other
65673+ dangerous sources of information, this option causes reads of sensitive
65674+ /proc/<pid> entries where the file descriptor was opened in a different
65675+ task than the one performing the read. Such attempts are logged.
65676+ This option also limits argv/env strings for suid/sgid binaries
65677+ to 512KB to prevent a complete exhaustion of the stack entropy provided
65678+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65679+ binaries to prevent alternative mmap layouts from being abused.
65680+
65681+ If you use PaX it is essential that you say Y here as it closes up
65682+ several holes that make full ASLR useless locally.
65683+
65684+
65685+config GRKERNSEC_KSTACKOVERFLOW
65686+ bool "Prevent kernel stack overflows"
65687+ default y if GRKERNSEC_CONFIG_AUTO
65688+ depends on !IA64 && 64BIT
65689+ help
65690+ If you say Y here, the kernel's process stacks will be allocated
65691+ with vmalloc instead of the kernel's default allocator. This
65692+ introduces guard pages that in combination with the alloca checking
65693+ of the STACKLEAK feature prevents all forms of kernel process stack
65694+ overflow abuse. Note that this is different from kernel stack
65695+ buffer overflows.
65696+
65697+config GRKERNSEC_BRUTE
65698+ bool "Deter exploit bruteforcing"
65699+ default y if GRKERNSEC_CONFIG_AUTO
65700+ help
65701+ If you say Y here, attempts to bruteforce exploits against forking
65702+ daemons such as apache or sshd, as well as against suid/sgid binaries
65703+ will be deterred. When a child of a forking daemon is killed by PaX
65704+ or crashes due to an illegal instruction or other suspicious signal,
65705+ the parent process will be delayed 30 seconds upon every subsequent
65706+ fork until the administrator is able to assess the situation and
65707+ restart the daemon.
65708+ In the suid/sgid case, the attempt is logged, the user has all their
65709+ existing instances of the suid/sgid binary terminated and will
65710+ be unable to execute any suid/sgid binaries for 15 minutes.
65711+
65712+ It is recommended that you also enable signal logging in the auditing
65713+ section so that logs are generated when a process triggers a suspicious
65714+ signal.
65715+ If the sysctl option is enabled, a sysctl option with name
65716+ "deter_bruteforce" is created.
65717+
65718+config GRKERNSEC_MODHARDEN
65719+ bool "Harden module auto-loading"
65720+ default y if GRKERNSEC_CONFIG_AUTO
65721+ depends on MODULES
65722+ help
65723+ If you say Y here, module auto-loading in response to use of some
65724+ feature implemented by an unloaded module will be restricted to
65725+ root users. Enabling this option helps defend against attacks
65726+ by unprivileged users who abuse the auto-loading behavior to
65727+ cause a vulnerable module to load that is then exploited.
65728+
65729+ If this option prevents a legitimate use of auto-loading for a
65730+ non-root user, the administrator can execute modprobe manually
65731+ with the exact name of the module mentioned in the alert log.
65732+ Alternatively, the administrator can add the module to the list
65733+ of modules loaded at boot by modifying init scripts.
65734+
65735+ Modification of init scripts will most likely be needed on
65736+ Ubuntu servers with encrypted home directory support enabled,
65737+ as the first non-root user logging in will cause the ecb(aes),
65738+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65739+
65740+config GRKERNSEC_HIDESYM
65741+ bool "Hide kernel symbols"
65742+ default y if GRKERNSEC_CONFIG_AUTO
65743+ select PAX_USERCOPY_SLABS
65744+ help
65745+ If you say Y here, getting information on loaded modules, and
65746+ displaying all kernel symbols through a syscall will be restricted
65747+ to users with CAP_SYS_MODULE. For software compatibility reasons,
65748+ /proc/kallsyms will be restricted to the root user. The RBAC
65749+ system can hide that entry even from root.
65750+
65751+ This option also prevents leaking of kernel addresses through
65752+ several /proc entries.
65753+
65754+ Note that this option is only effective provided the following
65755+ conditions are met:
65756+ 1) The kernel using grsecurity is not precompiled by some distribution
65757+ 2) You have also enabled GRKERNSEC_DMESG
65758+ 3) You are using the RBAC system and hiding other files such as your
65759+ kernel image and System.map. Alternatively, enabling this option
65760+ causes the permissions on /boot, /lib/modules, and the kernel
65761+ source directory to change at compile time to prevent
65762+ reading by non-root users.
65763+ If the above conditions are met, this option will aid in providing a
65764+ useful protection against local kernel exploitation of overflows
65765+ and arbitrary read/write vulnerabilities.
65766+
65767+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65768+ in addition to this feature.
65769+
65770+config GRKERNSEC_RANDSTRUCT
65771+ bool "Randomize layout of sensitive kernel structures"
65772+ default y if GRKERNSEC_CONFIG_AUTO
65773+ select GRKERNSEC_HIDESYM
65774+ select MODVERSIONS if MODULES
65775+ help
65776+ If you say Y here, the layouts of a number of sensitive kernel
65777+ structures (task, fs, cred, etc) and all structures composed entirely
65778+ of function pointers (aka "ops" structs) will be randomized at compile-time.
65779+ This can introduce the requirement of an additional infoleak
65780+ vulnerability for exploits targeting these structure types.
65781+
65782+ Enabling this feature will introduce some performance impact, slightly
65783+ increase memory usage, and prevent the use of forensic tools like
65784+ Volatility against the system (unless the kernel source tree isn't
65785+ cleaned after kernel installation).
65786+
65787+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65788+ It remains after a make clean to allow for external modules to be compiled
65789+ with the existing seed and will be removed by a make mrproper or
65790+ make distclean.
65791+
65792+ Note that the implementation requires gcc 4.6.4. or newer. You may need
65793+ to install the supporting headers explicitly in addition to the normal
65794+ gcc package.
65795+
65796+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65797+ bool "Use cacheline-aware structure randomization"
65798+ depends on GRKERNSEC_RANDSTRUCT
65799+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65800+ help
65801+ If you say Y here, the RANDSTRUCT randomization will make a best effort
65802+ at restricting randomization to cacheline-sized groups of elements. It
65803+ will further not randomize bitfields in structures. This reduces the
65804+ performance hit of RANDSTRUCT at the cost of weakened randomization.
65805+
65806+config GRKERNSEC_KERN_LOCKOUT
65807+ bool "Active kernel exploit response"
65808+ default y if GRKERNSEC_CONFIG_AUTO
65809+ depends on X86 || ARM || PPC || SPARC
65810+ help
65811+ If you say Y here, when a PaX alert is triggered due to suspicious
65812+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65813+ or an OOPS occurs due to bad memory accesses, instead of just
65814+ terminating the offending process (and potentially allowing
65815+ a subsequent exploit from the same user), we will take one of two
65816+ actions:
65817+ If the user was root, we will panic the system
65818+ If the user was non-root, we will log the attempt, terminate
65819+ all processes owned by the user, then prevent them from creating
65820+ any new processes until the system is restarted
65821+ This deters repeated kernel exploitation/bruteforcing attempts
65822+ and is useful for later forensics.
65823+
65824+config GRKERNSEC_OLD_ARM_USERLAND
65825+ bool "Old ARM userland compatibility"
65826+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65827+ help
65828+ If you say Y here, stubs of executable code to perform such operations
65829+ as "compare-exchange" will be placed at fixed locations in the ARM vector
65830+ table. This is unfortunately needed for old ARM userland meant to run
65831+ across a wide range of processors. Without this option enabled,
65832+ the get_tls and data memory barrier stubs will be emulated by the kernel,
65833+ which is enough for Linaro userlands or other userlands designed for v6
65834+ and newer ARM CPUs. It's recommended that you try without this option enabled
65835+ first, and only enable it if your userland does not boot (it will likely fail
65836+ at init time).
65837+
65838+endmenu
65839+menu "Role Based Access Control Options"
65840+depends on GRKERNSEC
65841+
65842+config GRKERNSEC_RBAC_DEBUG
65843+ bool
65844+
65845+config GRKERNSEC_NO_RBAC
65846+ bool "Disable RBAC system"
65847+ help
65848+ If you say Y here, the /dev/grsec device will be removed from the kernel,
65849+ preventing the RBAC system from being enabled. You should only say Y
65850+ here if you have no intention of using the RBAC system, so as to prevent
65851+ an attacker with root access from misusing the RBAC system to hide files
65852+ and processes when loadable module support and /dev/[k]mem have been
65853+ locked down.
65854+
65855+config GRKERNSEC_ACL_HIDEKERN
65856+ bool "Hide kernel processes"
65857+ help
65858+ If you say Y here, all kernel threads will be hidden to all
65859+ processes but those whose subject has the "view hidden processes"
65860+ flag.
65861+
65862+config GRKERNSEC_ACL_MAXTRIES
65863+ int "Maximum tries before password lockout"
65864+ default 3
65865+ help
65866+ This option enforces the maximum number of times a user can attempt
65867+ to authorize themselves with the grsecurity RBAC system before being
65868+ denied the ability to attempt authorization again for a specified time.
65869+ The lower the number, the harder it will be to brute-force a password.
65870+
65871+config GRKERNSEC_ACL_TIMEOUT
65872+ int "Time to wait after max password tries, in seconds"
65873+ default 30
65874+ help
65875+ This option specifies the time the user must wait after attempting to
65876+ authorize to the RBAC system with the maximum number of invalid
65877+ passwords. The higher the number, the harder it will be to brute-force
65878+ a password.
65879+
65880+endmenu
65881+menu "Filesystem Protections"
65882+depends on GRKERNSEC
65883+
65884+config GRKERNSEC_PROC
65885+ bool "Proc restrictions"
65886+ default y if GRKERNSEC_CONFIG_AUTO
65887+ help
65888+ If you say Y here, the permissions of the /proc filesystem
65889+ will be altered to enhance system security and privacy. You MUST
65890+ choose either a user only restriction or a user and group restriction.
65891+ Depending upon the option you choose, you can either restrict users to
65892+ see only the processes they themselves run, or choose a group that can
65893+ view all processes and files normally restricted to root if you choose
65894+ the "restrict to user only" option. NOTE: If you're running identd or
65895+ ntpd as a non-root user, you will have to run it as the group you
65896+ specify here.
65897+
65898+config GRKERNSEC_PROC_USER
65899+ bool "Restrict /proc to user only"
65900+ depends on GRKERNSEC_PROC
65901+ help
65902+ If you say Y here, non-root users will only be able to view their own
65903+ processes, and restricts them from viewing network-related information,
65904+ and viewing kernel symbol and module information.
65905+
65906+config GRKERNSEC_PROC_USERGROUP
65907+ bool "Allow special group"
65908+ default y if GRKERNSEC_CONFIG_AUTO
65909+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65910+ help
65911+ If you say Y here, you will be able to select a group that will be
65912+ able to view all processes and network-related information. If you've
65913+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65914+ remain hidden. This option is useful if you want to run identd as
65915+ a non-root user. The group you select may also be chosen at boot time
65916+ via "grsec_proc_gid=" on the kernel commandline.
65917+
65918+config GRKERNSEC_PROC_GID
65919+ int "GID for special group"
65920+ depends on GRKERNSEC_PROC_USERGROUP
65921+ default 1001
65922+
65923+config GRKERNSEC_PROC_ADD
65924+ bool "Additional restrictions"
65925+ default y if GRKERNSEC_CONFIG_AUTO
65926+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65927+ help
65928+ If you say Y here, additional restrictions will be placed on
65929+ /proc that keep normal users from viewing device information and
65930+ slabinfo information that could be useful for exploits.
65931+
65932+config GRKERNSEC_LINK
65933+ bool "Linking restrictions"
65934+ default y if GRKERNSEC_CONFIG_AUTO
65935+ help
65936+ If you say Y here, /tmp race exploits will be prevented, since users
65937+ will no longer be able to follow symlinks owned by other users in
65938+ world-writable +t directories (e.g. /tmp), unless the owner of the
65939+ symlink is the owner of the directory. users will also not be
65940+ able to hardlink to files they do not own. If the sysctl option is
65941+ enabled, a sysctl option with name "linking_restrictions" is created.
65942+
65943+config GRKERNSEC_SYMLINKOWN
65944+ bool "Kernel-enforced SymlinksIfOwnerMatch"
65945+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65946+ help
65947+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
65948+ that prevents it from being used as a security feature. As Apache
65949+ verifies the symlink by performing a stat() against the target of
65950+ the symlink before it is followed, an attacker can setup a symlink
65951+ to point to a same-owned file, then replace the symlink with one
65952+ that targets another user's file just after Apache "validates" the
65953+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
65954+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65955+ will be in place for the group you specify. If the sysctl option
65956+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
65957+ created.
65958+
65959+config GRKERNSEC_SYMLINKOWN_GID
65960+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
65961+ depends on GRKERNSEC_SYMLINKOWN
65962+ default 1006
65963+ help
65964+ Setting this GID determines what group kernel-enforced
65965+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
65966+ is enabled, a sysctl option with name "symlinkown_gid" is created.
65967+
65968+config GRKERNSEC_FIFO
65969+ bool "FIFO restrictions"
65970+ default y if GRKERNSEC_CONFIG_AUTO
65971+ help
65972+ If you say Y here, users will not be able to write to FIFOs they don't
65973+ own in world-writable +t directories (e.g. /tmp), unless the owner of
65974+ the FIFO is the same owner of the directory it's held in. If the sysctl
65975+ option is enabled, a sysctl option with name "fifo_restrictions" is
65976+ created.
65977+
65978+config GRKERNSEC_SYSFS_RESTRICT
65979+ bool "Sysfs/debugfs restriction"
65980+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65981+ depends on SYSFS
65982+ help
65983+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
65984+ any filesystem normally mounted under it (e.g. debugfs) will be
65985+ mostly accessible only by root. These filesystems generally provide access
65986+ to hardware and debug information that isn't appropriate for unprivileged
65987+ users of the system. Sysfs and debugfs have also become a large source
65988+ of new vulnerabilities, ranging from infoleaks to local compromise.
65989+ There has been very little oversight with an eye toward security involved
65990+ in adding new exporters of information to these filesystems, so their
65991+ use is discouraged.
65992+ For reasons of compatibility, a few directories have been whitelisted
65993+ for access by non-root users:
65994+ /sys/fs/selinux
65995+ /sys/fs/fuse
65996+ /sys/devices/system/cpu
65997+
65998+config GRKERNSEC_ROFS
65999+ bool "Runtime read-only mount protection"
66000+ depends on SYSCTL
66001+ help
66002+ If you say Y here, a sysctl option with name "romount_protect" will
66003+ be created. By setting this option to 1 at runtime, filesystems
66004+ will be protected in the following ways:
66005+ * No new writable mounts will be allowed
66006+ * Existing read-only mounts won't be able to be remounted read/write
66007+ * Write operations will be denied on all block devices
66008+ This option acts independently of grsec_lock: once it is set to 1,
66009+ it cannot be turned off. Therefore, please be mindful of the resulting
66010+ behavior if this option is enabled in an init script on a read-only
66011+ filesystem.
66012+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66013+ and GRKERNSEC_IO should be enabled and module loading disabled via
66014+ config or at runtime.
66015+ This feature is mainly intended for secure embedded systems.
66016+
66017+
66018+config GRKERNSEC_DEVICE_SIDECHANNEL
66019+ bool "Eliminate stat/notify-based device sidechannels"
66020+ default y if GRKERNSEC_CONFIG_AUTO
66021+ help
66022+ If you say Y here, timing analyses on block or character
66023+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66024+ will be thwarted for unprivileged users. If a process without
66025+ CAP_MKNOD stats such a device, the last access and last modify times
66026+ will match the device's create time. No access or modify events
66027+ will be triggered through inotify/dnotify/fanotify for such devices.
66028+ This feature will prevent attacks that may at a minimum
66029+ allow an attacker to determine the administrator's password length.
66030+
66031+config GRKERNSEC_CHROOT
66032+ bool "Chroot jail restrictions"
66033+ default y if GRKERNSEC_CONFIG_AUTO
66034+ help
66035+ If you say Y here, you will be able to choose several options that will
66036+ make breaking out of a chrooted jail much more difficult. If you
66037+ encounter no software incompatibilities with the following options, it
66038+ is recommended that you enable each one.
66039+
66040+ Note that the chroot restrictions are not intended to apply to "chroots"
66041+ to directories that are simple bind mounts of the global root filesystem.
66042+ For several other reasons, a user shouldn't expect any significant
66043+ security by performing such a chroot.
66044+
66045+config GRKERNSEC_CHROOT_MOUNT
66046+ bool "Deny mounts"
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 able to
66051+ mount or remount filesystems. If the sysctl option is enabled, a
66052+ sysctl option with name "chroot_deny_mount" is created.
66053+
66054+config GRKERNSEC_CHROOT_DOUBLE
66055+ bool "Deny double-chroots"
66056+ default y if GRKERNSEC_CONFIG_AUTO
66057+ depends on GRKERNSEC_CHROOT
66058+ help
66059+ If you say Y here, processes inside a chroot will not be able to chroot
66060+ again outside the chroot. This is a widely used method of breaking
66061+ out of a chroot jail and should not be allowed. If the sysctl
66062+ option is enabled, a sysctl option with name
66063+ "chroot_deny_chroot" is created.
66064+
66065+config GRKERNSEC_CHROOT_PIVOT
66066+ bool "Deny pivot_root in chroot"
66067+ default y if GRKERNSEC_CONFIG_AUTO
66068+ depends on GRKERNSEC_CHROOT
66069+ help
66070+ If you say Y here, processes inside a chroot will not be able to use
66071+ a function called pivot_root() that was introduced in Linux 2.3.41. It
66072+ works similar to chroot in that it changes the root filesystem. This
66073+ function could be misused in a chrooted process to attempt to break out
66074+ of the chroot, and therefore should not be allowed. If the sysctl
66075+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
66076+ created.
66077+
66078+config GRKERNSEC_CHROOT_CHDIR
66079+ bool "Enforce chdir(\"/\") on all chroots"
66080+ default y if GRKERNSEC_CONFIG_AUTO
66081+ depends on GRKERNSEC_CHROOT
66082+ help
66083+ If you say Y here, the current working directory of all newly-chrooted
66084+ applications will be set to the the root directory of the chroot.
66085+ The man page on chroot(2) states:
66086+ Note that this call does not change the current working
66087+ directory, so that `.' can be outside the tree rooted at
66088+ `/'. In particular, the super-user can escape from a
66089+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66090+
66091+ It is recommended that you say Y here, since it's not known to break
66092+ any software. If the sysctl option is enabled, a sysctl option with
66093+ name "chroot_enforce_chdir" is created.
66094+
66095+config GRKERNSEC_CHROOT_CHMOD
66096+ bool "Deny (f)chmod +s"
66097+ default y if GRKERNSEC_CONFIG_AUTO
66098+ depends on GRKERNSEC_CHROOT
66099+ help
66100+ If you say Y here, processes inside a chroot will not be able to chmod
66101+ or fchmod files to make them have suid or sgid bits. This protects
66102+ against another published method of breaking a chroot. If the sysctl
66103+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
66104+ created.
66105+
66106+config GRKERNSEC_CHROOT_FCHDIR
66107+ bool "Deny fchdir and fhandle out of chroot"
66108+ default y if GRKERNSEC_CONFIG_AUTO
66109+ depends on GRKERNSEC_CHROOT
66110+ help
66111+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
66112+ to a file descriptor of the chrooting process that points to a directory
66113+ outside the filesystem will be stopped. Additionally, this option prevents
66114+ use of the recently-created syscall for opening files by a guessable "file
66115+ handle" inside a chroot. If the sysctl option is enabled, a sysctl option
66116+ with name "chroot_deny_fchdir" is created.
66117+
66118+config GRKERNSEC_CHROOT_MKNOD
66119+ bool "Deny mknod"
66120+ default y if GRKERNSEC_CONFIG_AUTO
66121+ depends on GRKERNSEC_CHROOT
66122+ help
66123+ If you say Y here, processes inside a chroot will not be allowed to
66124+ mknod. The problem with using mknod inside a chroot is that it
66125+ would allow an attacker to create a device entry that is the same
66126+ as one on the physical root of your system, which could range from
66127+ anything from the console device to a device for your harddrive (which
66128+ they could then use to wipe the drive or steal data). It is recommended
66129+ that you say Y here, unless you run into software incompatibilities.
66130+ If the sysctl option is enabled, a sysctl option with name
66131+ "chroot_deny_mknod" is created.
66132+
66133+config GRKERNSEC_CHROOT_SHMAT
66134+ bool "Deny shmat() out of chroot"
66135+ default y if GRKERNSEC_CONFIG_AUTO
66136+ depends on GRKERNSEC_CHROOT
66137+ help
66138+ If you say Y here, processes inside a chroot will not be able to attach
66139+ to shared memory segments that were created outside of the chroot jail.
66140+ It is recommended that you say Y here. If the sysctl option is enabled,
66141+ a sysctl option with name "chroot_deny_shmat" is created.
66142+
66143+config GRKERNSEC_CHROOT_UNIX
66144+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
66145+ default y if GRKERNSEC_CONFIG_AUTO
66146+ depends on GRKERNSEC_CHROOT
66147+ help
66148+ If you say Y here, processes inside a chroot will not be able to
66149+ connect to abstract (meaning not belonging to a filesystem) Unix
66150+ domain sockets that were bound outside of a chroot. It is recommended
66151+ that you say Y here. If the sysctl option is enabled, a sysctl option
66152+ with name "chroot_deny_unix" is created.
66153+
66154+config GRKERNSEC_CHROOT_FINDTASK
66155+ bool "Protect outside processes"
66156+ default y if GRKERNSEC_CONFIG_AUTO
66157+ depends on GRKERNSEC_CHROOT
66158+ help
66159+ If you say Y here, processes inside a chroot will not be able to
66160+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66161+ getsid, or view any process outside of the chroot. If the sysctl
66162+ option is enabled, a sysctl option with name "chroot_findtask" is
66163+ created.
66164+
66165+config GRKERNSEC_CHROOT_NICE
66166+ bool "Restrict priority changes"
66167+ default y if GRKERNSEC_CONFIG_AUTO
66168+ depends on GRKERNSEC_CHROOT
66169+ help
66170+ If you say Y here, processes inside a chroot will not be able to raise
66171+ the priority of processes in the chroot, or alter the priority of
66172+ processes outside the chroot. This provides more security than simply
66173+ removing CAP_SYS_NICE from the process' capability set. If the
66174+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66175+ is created.
66176+
66177+config GRKERNSEC_CHROOT_SYSCTL
66178+ bool "Deny sysctl writes"
66179+ default y if GRKERNSEC_CONFIG_AUTO
66180+ depends on GRKERNSEC_CHROOT
66181+ help
66182+ If you say Y here, an attacker in a chroot will not be able to
66183+ write to sysctl entries, either by sysctl(2) or through a /proc
66184+ interface. It is strongly recommended that you say Y here. If the
66185+ sysctl option is enabled, a sysctl option with name
66186+ "chroot_deny_sysctl" is created.
66187+
66188+config GRKERNSEC_CHROOT_CAPS
66189+ bool "Capability restrictions"
66190+ default y if GRKERNSEC_CONFIG_AUTO
66191+ depends on GRKERNSEC_CHROOT
66192+ help
66193+ If you say Y here, the capabilities on all processes within a
66194+ chroot jail will be lowered to stop module insertion, raw i/o,
66195+ system and net admin tasks, rebooting the system, modifying immutable
66196+ files, modifying IPC owned by another, and changing the system time.
66197+ This is left an option because it can break some apps. Disable this
66198+ if your chrooted apps are having problems performing those kinds of
66199+ tasks. If the sysctl option is enabled, a sysctl option with
66200+ name "chroot_caps" is created.
66201+
66202+config GRKERNSEC_CHROOT_INITRD
66203+ bool "Exempt initrd tasks from restrictions"
66204+ default y if GRKERNSEC_CONFIG_AUTO
66205+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66206+ help
66207+ If you say Y here, tasks started prior to init will be exempted from
66208+ grsecurity's chroot restrictions. This option is mainly meant to
66209+ resolve Plymouth's performing privileged operations unnecessarily
66210+ in a chroot.
66211+
66212+endmenu
66213+menu "Kernel Auditing"
66214+depends on GRKERNSEC
66215+
66216+config GRKERNSEC_AUDIT_GROUP
66217+ bool "Single group for auditing"
66218+ help
66219+ If you say Y here, the exec and chdir logging features will only operate
66220+ on a group you specify. This option is recommended if you only want to
66221+ watch certain users instead of having a large amount of logs from the
66222+ entire system. If the sysctl option is enabled, a sysctl option with
66223+ name "audit_group" is created.
66224+
66225+config GRKERNSEC_AUDIT_GID
66226+ int "GID for auditing"
66227+ depends on GRKERNSEC_AUDIT_GROUP
66228+ default 1007
66229+
66230+config GRKERNSEC_EXECLOG
66231+ bool "Exec logging"
66232+ help
66233+ If you say Y here, all execve() calls will be logged (since the
66234+ other exec*() calls are frontends to execve(), all execution
66235+ will be logged). Useful for shell-servers that like to keep track
66236+ of their users. If the sysctl option is enabled, a sysctl option with
66237+ name "exec_logging" is created.
66238+ WARNING: This option when enabled will produce a LOT of logs, especially
66239+ on an active system.
66240+
66241+config GRKERNSEC_RESLOG
66242+ bool "Resource logging"
66243+ default y if GRKERNSEC_CONFIG_AUTO
66244+ help
66245+ If you say Y here, all attempts to overstep resource limits will
66246+ be logged with the resource name, the requested size, and the current
66247+ limit. It is highly recommended that you say Y here. If the sysctl
66248+ option is enabled, a sysctl option with name "resource_logging" is
66249+ created. If the RBAC system is enabled, the sysctl value is ignored.
66250+
66251+config GRKERNSEC_CHROOT_EXECLOG
66252+ bool "Log execs within chroot"
66253+ help
66254+ If you say Y here, all executions inside a chroot jail will be logged
66255+ to syslog. This can cause a large amount of logs if certain
66256+ applications (eg. djb's daemontools) are installed on the system, and
66257+ is therefore left as an option. If the sysctl option is enabled, a
66258+ sysctl option with name "chroot_execlog" is created.
66259+
66260+config GRKERNSEC_AUDIT_PTRACE
66261+ bool "Ptrace logging"
66262+ help
66263+ If you say Y here, all attempts to attach to a process via ptrace
66264+ will be logged. If the sysctl option is enabled, a sysctl option
66265+ with name "audit_ptrace" is created.
66266+
66267+config GRKERNSEC_AUDIT_CHDIR
66268+ bool "Chdir logging"
66269+ help
66270+ If you say Y here, all chdir() calls will be logged. If the sysctl
66271+ option is enabled, a sysctl option with name "audit_chdir" is created.
66272+
66273+config GRKERNSEC_AUDIT_MOUNT
66274+ bool "(Un)Mount logging"
66275+ help
66276+ If you say Y here, all mounts and unmounts will be logged. If the
66277+ sysctl option is enabled, a sysctl option with name "audit_mount" is
66278+ created.
66279+
66280+config GRKERNSEC_SIGNAL
66281+ bool "Signal logging"
66282+ default y if GRKERNSEC_CONFIG_AUTO
66283+ help
66284+ If you say Y here, certain important signals will be logged, such as
66285+ SIGSEGV, which will as a result inform you of when a error in a program
66286+ occurred, which in some cases could mean a possible exploit attempt.
66287+ If the sysctl option is enabled, a sysctl option with name
66288+ "signal_logging" is created.
66289+
66290+config GRKERNSEC_FORKFAIL
66291+ bool "Fork failure logging"
66292+ help
66293+ If you say Y here, all failed fork() attempts will be logged.
66294+ This could suggest a fork bomb, or someone attempting to overstep
66295+ their process limit. If the sysctl option is enabled, a sysctl option
66296+ with name "forkfail_logging" is created.
66297+
66298+config GRKERNSEC_TIME
66299+ bool "Time change logging"
66300+ default y if GRKERNSEC_CONFIG_AUTO
66301+ help
66302+ If you say Y here, any changes of the system clock will be logged.
66303+ If the sysctl option is enabled, a sysctl option with name
66304+ "timechange_logging" is created.
66305+
66306+config GRKERNSEC_PROC_IPADDR
66307+ bool "/proc/<pid>/ipaddr support"
66308+ default y if GRKERNSEC_CONFIG_AUTO
66309+ help
66310+ If you say Y here, a new entry will be added to each /proc/<pid>
66311+ directory that contains the IP address of the person using the task.
66312+ The IP is carried across local TCP and AF_UNIX stream sockets.
66313+ This information can be useful for IDS/IPSes to perform remote response
66314+ to a local attack. The entry is readable by only the owner of the
66315+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66316+ the RBAC system), and thus does not create privacy concerns.
66317+
66318+config GRKERNSEC_RWXMAP_LOG
66319+ bool 'Denied RWX mmap/mprotect logging'
66320+ default y if GRKERNSEC_CONFIG_AUTO
66321+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66322+ help
66323+ If you say Y here, calls to mmap() and mprotect() with explicit
66324+ usage of PROT_WRITE and PROT_EXEC together will be logged when
66325+ denied by the PAX_MPROTECT feature. This feature will also
66326+ log other problematic scenarios that can occur when PAX_MPROTECT
66327+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
66328+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66329+ is created.
66330+
66331+endmenu
66332+
66333+menu "Executable Protections"
66334+depends on GRKERNSEC
66335+
66336+config GRKERNSEC_DMESG
66337+ bool "Dmesg(8) restriction"
66338+ default y if GRKERNSEC_CONFIG_AUTO
66339+ help
66340+ If you say Y here, non-root users will not be able to use dmesg(8)
66341+ to view the contents of the kernel's circular log buffer.
66342+ The kernel's log buffer often contains kernel addresses and other
66343+ identifying information useful to an attacker in fingerprinting a
66344+ system for a targeted exploit.
66345+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
66346+ created.
66347+
66348+config GRKERNSEC_HARDEN_PTRACE
66349+ bool "Deter ptrace-based process snooping"
66350+ default y if GRKERNSEC_CONFIG_AUTO
66351+ help
66352+ If you say Y here, TTY sniffers and other malicious monitoring
66353+ programs implemented through ptrace will be defeated. If you
66354+ have been using the RBAC system, this option has already been
66355+ enabled for several years for all users, with the ability to make
66356+ fine-grained exceptions.
66357+
66358+ This option only affects the ability of non-root users to ptrace
66359+ processes that are not a descendent of the ptracing process.
66360+ This means that strace ./binary and gdb ./binary will still work,
66361+ but attaching to arbitrary processes will not. If the sysctl
66362+ option is enabled, a sysctl option with name "harden_ptrace" is
66363+ created.
66364+
66365+config GRKERNSEC_PTRACE_READEXEC
66366+ bool "Require read access to ptrace sensitive binaries"
66367+ default y if GRKERNSEC_CONFIG_AUTO
66368+ help
66369+ If you say Y here, unprivileged users will not be able to ptrace unreadable
66370+ binaries. This option is useful in environments that
66371+ remove the read bits (e.g. file mode 4711) from suid binaries to
66372+ prevent infoleaking of their contents. This option adds
66373+ consistency to the use of that file mode, as the binary could normally
66374+ be read out when run without privileges while ptracing.
66375+
66376+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66377+ is created.
66378+
66379+config GRKERNSEC_SETXID
66380+ bool "Enforce consistent multithreaded privileges"
66381+ default y if GRKERNSEC_CONFIG_AUTO
66382+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66383+ help
66384+ If you say Y here, a change from a root uid to a non-root uid
66385+ in a multithreaded application will cause the resulting uids,
66386+ gids, supplementary groups, and capabilities in that thread
66387+ to be propagated to the other threads of the process. In most
66388+ cases this is unnecessary, as glibc will emulate this behavior
66389+ on behalf of the application. Other libcs do not act in the
66390+ same way, allowing the other threads of the process to continue
66391+ running with root privileges. If the sysctl option is enabled,
66392+ a sysctl option with name "consistent_setxid" is created.
66393+
66394+config GRKERNSEC_HARDEN_IPC
66395+ bool "Disallow access to overly-permissive IPC objects"
66396+ default y if GRKERNSEC_CONFIG_AUTO
66397+ depends on SYSVIPC
66398+ help
66399+ If you say Y here, access to overly-permissive IPC objects (shared
66400+ memory, message queues, and semaphores) will be denied for processes
66401+ given the following criteria beyond normal permission checks:
66402+ 1) If the IPC object is world-accessible and the euid doesn't match
66403+ that of the creator or current uid for the IPC object
66404+ 2) If the IPC object is group-accessible and the egid doesn't
66405+ match that of the creator or current gid for the IPC object
66406+ It's a common error to grant too much permission to these objects,
66407+ with impact ranging from denial of service and information leaking to
66408+ privilege escalation. This feature was developed in response to
66409+ research by Tim Brown:
66410+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66411+ who found hundreds of such insecure usages. Processes with
66412+ CAP_IPC_OWNER are still permitted to access these IPC objects.
66413+ If the sysctl option is enabled, a sysctl option with name
66414+ "harden_ipc" is created.
66415+
66416+config GRKERNSEC_TPE
66417+ bool "Trusted Path Execution (TPE)"
66418+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66419+ help
66420+ If you say Y here, you will be able to choose a gid to add to the
66421+ supplementary groups of users you want to mark as "untrusted."
66422+ These users will not be able to execute any files that are not in
66423+ root-owned directories writable only by root. If the sysctl option
66424+ is enabled, a sysctl option with name "tpe" is created.
66425+
66426+config GRKERNSEC_TPE_ALL
66427+ bool "Partially restrict all non-root users"
66428+ depends on GRKERNSEC_TPE
66429+ help
66430+ If you say Y here, all non-root users will be covered under
66431+ a weaker TPE restriction. This is separate from, and in addition to,
66432+ the main TPE options that you have selected elsewhere. Thus, if a
66433+ "trusted" GID is chosen, this restriction applies to even that GID.
66434+ Under this restriction, all non-root users will only be allowed to
66435+ execute files in directories they own that are not group or
66436+ world-writable, or in directories owned by root and writable only by
66437+ root. If the sysctl option is enabled, a sysctl option with name
66438+ "tpe_restrict_all" is created.
66439+
66440+config GRKERNSEC_TPE_INVERT
66441+ bool "Invert GID option"
66442+ depends on GRKERNSEC_TPE
66443+ help
66444+ If you say Y here, the group you specify in the TPE configuration will
66445+ decide what group TPE restrictions will be *disabled* for. This
66446+ option is useful if you want TPE restrictions to be applied to most
66447+ users on the system. If the sysctl option is enabled, a sysctl option
66448+ with name "tpe_invert" is created. Unlike other sysctl options, this
66449+ entry will default to on for backward-compatibility.
66450+
66451+config GRKERNSEC_TPE_GID
66452+ int
66453+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66454+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66455+
66456+config GRKERNSEC_TPE_UNTRUSTED_GID
66457+ int "GID for TPE-untrusted users"
66458+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66459+ default 1005
66460+ help
66461+ Setting this GID determines what group TPE restrictions will be
66462+ *enabled* for. If the sysctl option is enabled, a sysctl option
66463+ with name "tpe_gid" is created.
66464+
66465+config GRKERNSEC_TPE_TRUSTED_GID
66466+ int "GID for TPE-trusted users"
66467+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66468+ default 1005
66469+ help
66470+ Setting this GID determines what group TPE restrictions will be
66471+ *disabled* for. If the sysctl option is enabled, a sysctl option
66472+ with name "tpe_gid" is created.
66473+
66474+endmenu
66475+menu "Network Protections"
66476+depends on GRKERNSEC
66477+
66478+config GRKERNSEC_RANDNET
66479+ bool "Larger entropy pools"
66480+ default y if GRKERNSEC_CONFIG_AUTO
66481+ help
66482+ If you say Y here, the entropy pools used for many features of Linux
66483+ and grsecurity will be doubled in size. Since several grsecurity
66484+ features use additional randomness, it is recommended that you say Y
66485+ here. Saying Y here has a similar effect as modifying
66486+ /proc/sys/kernel/random/poolsize.
66487+
66488+config GRKERNSEC_BLACKHOLE
66489+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66490+ default y if GRKERNSEC_CONFIG_AUTO
66491+ depends on NET
66492+ help
66493+ If you say Y here, neither TCP resets nor ICMP
66494+ destination-unreachable packets will be sent in response to packets
66495+ sent to ports for which no associated listening process exists.
66496+ This feature supports both IPV4 and IPV6 and exempts the
66497+ loopback interface from blackholing. Enabling this feature
66498+ makes a host more resilient to DoS attacks and reduces network
66499+ visibility against scanners.
66500+
66501+ The blackhole feature as-implemented is equivalent to the FreeBSD
66502+ blackhole feature, as it prevents RST responses to all packets, not
66503+ just SYNs. Under most application behavior this causes no
66504+ problems, but applications (like haproxy) may not close certain
66505+ connections in a way that cleanly terminates them on the remote
66506+ end, leaving the remote host in LAST_ACK state. Because of this
66507+ side-effect and to prevent intentional LAST_ACK DoSes, this
66508+ feature also adds automatic mitigation against such attacks.
66509+ The mitigation drastically reduces the amount of time a socket
66510+ can spend in LAST_ACK state. If you're using haproxy and not
66511+ all servers it connects to have this option enabled, consider
66512+ disabling this feature on the haproxy host.
66513+
66514+ If the sysctl option is enabled, two sysctl options with names
66515+ "ip_blackhole" and "lastack_retries" will be created.
66516+ While "ip_blackhole" takes the standard zero/non-zero on/off
66517+ toggle, "lastack_retries" uses the same kinds of values as
66518+ "tcp_retries1" and "tcp_retries2". The default value of 4
66519+ prevents a socket from lasting more than 45 seconds in LAST_ACK
66520+ state.
66521+
66522+config GRKERNSEC_NO_SIMULT_CONNECT
66523+ bool "Disable TCP Simultaneous Connect"
66524+ default y if GRKERNSEC_CONFIG_AUTO
66525+ depends on NET
66526+ help
66527+ If you say Y here, a feature by Willy Tarreau will be enabled that
66528+ removes a weakness in Linux's strict implementation of TCP that
66529+ allows two clients to connect to each other without either entering
66530+ a listening state. The weakness allows an attacker to easily prevent
66531+ a client from connecting to a known server provided the source port
66532+ for the connection is guessed correctly.
66533+
66534+ As the weakness could be used to prevent an antivirus or IPS from
66535+ fetching updates, or prevent an SSL gateway from fetching a CRL,
66536+ it should be eliminated by enabling this option. Though Linux is
66537+ one of few operating systems supporting simultaneous connect, it
66538+ has no legitimate use in practice and is rarely supported by firewalls.
66539+
66540+config GRKERNSEC_SOCKET
66541+ bool "Socket restrictions"
66542+ depends on NET
66543+ help
66544+ If you say Y here, you will be able to choose from several options.
66545+ If you assign a GID on your system and add it to the supplementary
66546+ groups of users you want to restrict socket access to, this patch
66547+ will perform up to three things, based on the option(s) you choose.
66548+
66549+config GRKERNSEC_SOCKET_ALL
66550+ bool "Deny any sockets to group"
66551+ depends on GRKERNSEC_SOCKET
66552+ help
66553+ If you say Y here, you will be able to choose a GID of whose users will
66554+ be unable to connect to other hosts from your machine or run server
66555+ applications from your machine. If the sysctl option is enabled, a
66556+ sysctl option with name "socket_all" is created.
66557+
66558+config GRKERNSEC_SOCKET_ALL_GID
66559+ int "GID to deny all sockets for"
66560+ depends on GRKERNSEC_SOCKET_ALL
66561+ default 1004
66562+ help
66563+ Here you can choose the GID to disable socket access for. Remember to
66564+ add the users you want socket access disabled for to the GID
66565+ specified here. If the sysctl option is enabled, a sysctl option
66566+ with name "socket_all_gid" is created.
66567+
66568+config GRKERNSEC_SOCKET_CLIENT
66569+ bool "Deny client sockets to group"
66570+ depends on GRKERNSEC_SOCKET
66571+ help
66572+ If you say Y here, you will be able to choose a GID of whose users will
66573+ be unable to connect to other hosts from your machine, but will be
66574+ able to run servers. If this option is enabled, all users in the group
66575+ you specify will have to use passive mode when initiating ftp transfers
66576+ from the shell on your machine. If the sysctl option is enabled, a
66577+ sysctl option with name "socket_client" is created.
66578+
66579+config GRKERNSEC_SOCKET_CLIENT_GID
66580+ int "GID to deny client sockets for"
66581+ depends on GRKERNSEC_SOCKET_CLIENT
66582+ default 1003
66583+ help
66584+ Here you can choose the GID to disable client socket access for.
66585+ Remember to add the users you want client socket access disabled for to
66586+ the GID specified here. If the sysctl option is enabled, a sysctl
66587+ option with name "socket_client_gid" is created.
66588+
66589+config GRKERNSEC_SOCKET_SERVER
66590+ bool "Deny server sockets to group"
66591+ depends on GRKERNSEC_SOCKET
66592+ help
66593+ If you say Y here, you will be able to choose a GID of whose users will
66594+ be unable to run server applications from your machine. If the sysctl
66595+ option is enabled, a sysctl option with name "socket_server" is created.
66596+
66597+config GRKERNSEC_SOCKET_SERVER_GID
66598+ int "GID to deny server sockets for"
66599+ depends on GRKERNSEC_SOCKET_SERVER
66600+ default 1002
66601+ help
66602+ Here you can choose the GID to disable server socket access for.
66603+ Remember to add the users you want server socket access disabled for to
66604+ the GID specified here. If the sysctl option is enabled, a sysctl
66605+ option with name "socket_server_gid" is created.
66606+
66607+endmenu
66608+
66609+menu "Physical Protections"
66610+depends on GRKERNSEC
66611+
66612+config GRKERNSEC_DENYUSB
66613+ bool "Deny new USB connections after toggle"
66614+ default y if GRKERNSEC_CONFIG_AUTO
66615+ depends on SYSCTL && USB_SUPPORT
66616+ help
66617+ If you say Y here, a new sysctl option with name "deny_new_usb"
66618+ will be created. Setting its value to 1 will prevent any new
66619+ USB devices from being recognized by the OS. Any attempted USB
66620+ device insertion will be logged. This option is intended to be
66621+ used against custom USB devices designed to exploit vulnerabilities
66622+ in various USB device drivers.
66623+
66624+ For greatest effectiveness, this sysctl should be set after any
66625+ relevant init scripts. This option is safe to enable in distros
66626+ as each user can choose whether or not to toggle the sysctl.
66627+
66628+config GRKERNSEC_DENYUSB_FORCE
66629+ bool "Reject all USB devices not connected at boot"
66630+ select USB
66631+ depends on GRKERNSEC_DENYUSB
66632+ help
66633+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66634+ that doesn't involve a sysctl entry. This option should only be
66635+ enabled if you're sure you want to deny all new USB connections
66636+ at runtime and don't want to modify init scripts. This should not
66637+ be enabled by distros. It forces the core USB code to be built
66638+ into the kernel image so that all devices connected at boot time
66639+ can be recognized and new USB device connections can be prevented
66640+ prior to init running.
66641+
66642+endmenu
66643+
66644+menu "Sysctl Support"
66645+depends on GRKERNSEC && SYSCTL
66646+
66647+config GRKERNSEC_SYSCTL
66648+ bool "Sysctl support"
66649+ default y if GRKERNSEC_CONFIG_AUTO
66650+ help
66651+ If you say Y here, you will be able to change the options that
66652+ grsecurity runs with at bootup, without having to recompile your
66653+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66654+ to enable (1) or disable (0) various features. All the sysctl entries
66655+ are mutable until the "grsec_lock" entry is set to a non-zero value.
66656+ All features enabled in the kernel configuration are disabled at boot
66657+ if you do not say Y to the "Turn on features by default" option.
66658+ All options should be set at startup, and the grsec_lock entry should
66659+ be set to a non-zero value after all the options are set.
66660+ *THIS IS EXTREMELY IMPORTANT*
66661+
66662+config GRKERNSEC_SYSCTL_DISTRO
66663+ bool "Extra sysctl support for distro makers (READ HELP)"
66664+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66665+ help
66666+ If you say Y here, additional sysctl options will be created
66667+ for features that affect processes running as root. Therefore,
66668+ it is critical when using this option that the grsec_lock entry be
66669+ enabled after boot. Only distros with prebuilt kernel packages
66670+ with this option enabled that can ensure grsec_lock is enabled
66671+ after boot should use this option.
66672+ *Failure to set grsec_lock after boot makes all grsec features
66673+ this option covers useless*
66674+
66675+ Currently this option creates the following sysctl entries:
66676+ "Disable Privileged I/O": "disable_priv_io"
66677+
66678+config GRKERNSEC_SYSCTL_ON
66679+ bool "Turn on features by default"
66680+ default y if GRKERNSEC_CONFIG_AUTO
66681+ depends on GRKERNSEC_SYSCTL
66682+ help
66683+ If you say Y here, instead of having all features enabled in the
66684+ kernel configuration disabled at boot time, the features will be
66685+ enabled at boot time. It is recommended you say Y here unless
66686+ there is some reason you would want all sysctl-tunable features to
66687+ be disabled by default. As mentioned elsewhere, it is important
66688+ to enable the grsec_lock entry once you have finished modifying
66689+ the sysctl entries.
66690+
66691+endmenu
66692+menu "Logging Options"
66693+depends on GRKERNSEC
66694+
66695+config GRKERNSEC_FLOODTIME
66696+ int "Seconds in between log messages (minimum)"
66697+ default 10
66698+ help
66699+ This option allows you to enforce the number of seconds between
66700+ grsecurity log messages. The default should be suitable for most
66701+ people, however, if you choose to change it, choose a value small enough
66702+ to allow informative logs to be produced, but large enough to
66703+ prevent flooding.
66704+
66705+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66706+ any rate limiting on grsecurity log messages.
66707+
66708+config GRKERNSEC_FLOODBURST
66709+ int "Number of messages in a burst (maximum)"
66710+ default 6
66711+ help
66712+ This option allows you to choose the maximum number of messages allowed
66713+ within the flood time interval you chose in a separate option. The
66714+ default should be suitable for most people, however if you find that
66715+ many of your logs are being interpreted as flooding, you may want to
66716+ raise this value.
66717+
66718+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66719+ any rate limiting on grsecurity log messages.
66720+
66721+endmenu
66722diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66723new file mode 100644
66724index 0000000..30ababb
66725--- /dev/null
66726+++ b/grsecurity/Makefile
66727@@ -0,0 +1,54 @@
66728+# grsecurity – access control and security hardening for Linux
66729+# All code in this directory and various hooks located throughout the Linux kernel are
66730+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66731+# http://www.grsecurity.net spender@grsecurity.net
66732+#
66733+# This program is free software; you can redistribute it and/or
66734+# modify it under the terms of the GNU General Public License version 2
66735+# as published by the Free Software Foundation.
66736+#
66737+# This program is distributed in the hope that it will be useful,
66738+# but WITHOUT ANY WARRANTY; without even the implied warranty of
66739+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66740+# GNU General Public License for more details.
66741+#
66742+# You should have received a copy of the GNU General Public License
66743+# along with this program; if not, write to the Free Software
66744+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66745+
66746+KBUILD_CFLAGS += -Werror
66747+
66748+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66749+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
66750+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66751+ grsec_usb.o grsec_ipc.o grsec_proc.o
66752+
66753+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66754+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66755+ gracl_learn.o grsec_log.o gracl_policy.o
66756+ifdef CONFIG_COMPAT
66757+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66758+endif
66759+
66760+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66761+
66762+ifdef CONFIG_NET
66763+obj-y += grsec_sock.o
66764+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66765+endif
66766+
66767+ifndef CONFIG_GRKERNSEC
66768+obj-y += grsec_disabled.o
66769+endif
66770+
66771+ifdef CONFIG_GRKERNSEC_HIDESYM
66772+extra-y := grsec_hidesym.o
66773+$(obj)/grsec_hidesym.o:
66774+ @-chmod -f 500 /boot
66775+ @-chmod -f 500 /lib/modules
66776+ @-chmod -f 500 /lib64/modules
66777+ @-chmod -f 500 /lib32/modules
66778+ @-chmod -f 700 .
66779+ @-chmod -f 700 $(objtree)
66780+ @echo ' grsec: protected kernel image paths'
66781+endif
66782diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66783new file mode 100644
66784index 0000000..58223f6
66785--- /dev/null
66786+++ b/grsecurity/gracl.c
66787@@ -0,0 +1,2702 @@
66788+#include <linux/kernel.h>
66789+#include <linux/module.h>
66790+#include <linux/sched.h>
66791+#include <linux/mm.h>
66792+#include <linux/file.h>
66793+#include <linux/fs.h>
66794+#include <linux/namei.h>
66795+#include <linux/mount.h>
66796+#include <linux/tty.h>
66797+#include <linux/proc_fs.h>
66798+#include <linux/lglock.h>
66799+#include <linux/slab.h>
66800+#include <linux/vmalloc.h>
66801+#include <linux/types.h>
66802+#include <linux/sysctl.h>
66803+#include <linux/netdevice.h>
66804+#include <linux/ptrace.h>
66805+#include <linux/gracl.h>
66806+#include <linux/gralloc.h>
66807+#include <linux/security.h>
66808+#include <linux/grinternal.h>
66809+#include <linux/pid_namespace.h>
66810+#include <linux/stop_machine.h>
66811+#include <linux/fdtable.h>
66812+#include <linux/percpu.h>
66813+#include <linux/lglock.h>
66814+#include <linux/hugetlb.h>
66815+#include <linux/posix-timers.h>
66816+#include <linux/prefetch.h>
66817+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66818+#include <linux/magic.h>
66819+#include <linux/pagemap.h>
66820+#include "../fs/btrfs/async-thread.h"
66821+#include "../fs/btrfs/ctree.h"
66822+#include "../fs/btrfs/btrfs_inode.h"
66823+#endif
66824+#include "../fs/mount.h"
66825+
66826+#include <asm/uaccess.h>
66827+#include <asm/errno.h>
66828+#include <asm/mman.h>
66829+
66830+#define FOR_EACH_ROLE_START(role) \
66831+ role = running_polstate.role_list; \
66832+ while (role) {
66833+
66834+#define FOR_EACH_ROLE_END(role) \
66835+ role = role->prev; \
66836+ }
66837+
66838+extern struct path gr_real_root;
66839+
66840+static struct gr_policy_state running_polstate;
66841+struct gr_policy_state *polstate = &running_polstate;
66842+extern struct gr_alloc_state *current_alloc_state;
66843+
66844+extern char *gr_shared_page[4];
66845+DEFINE_RWLOCK(gr_inode_lock);
66846+
66847+static unsigned int gr_status __read_only = GR_STATUS_INIT;
66848+
66849+#ifdef CONFIG_NET
66850+extern struct vfsmount *sock_mnt;
66851+#endif
66852+
66853+extern struct vfsmount *pipe_mnt;
66854+extern struct vfsmount *shm_mnt;
66855+
66856+#ifdef CONFIG_HUGETLBFS
66857+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66858+#endif
66859+
66860+extern u16 acl_sp_role_value;
66861+extern struct acl_object_label *fakefs_obj_rw;
66862+extern struct acl_object_label *fakefs_obj_rwx;
66863+
66864+int gr_acl_is_enabled(void)
66865+{
66866+ return (gr_status & GR_READY);
66867+}
66868+
66869+void gr_enable_rbac_system(void)
66870+{
66871+ pax_open_kernel();
66872+ gr_status |= GR_READY;
66873+ pax_close_kernel();
66874+}
66875+
66876+int gr_rbac_disable(void *unused)
66877+{
66878+ pax_open_kernel();
66879+ gr_status &= ~GR_READY;
66880+ pax_close_kernel();
66881+
66882+ return 0;
66883+}
66884+
66885+static inline dev_t __get_dev(const struct dentry *dentry)
66886+{
66887+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66888+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66889+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
66890+ else
66891+#endif
66892+ return dentry->d_sb->s_dev;
66893+}
66894+
66895+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66896+{
66897+ return __get_dev(dentry);
66898+}
66899+
66900+static char gr_task_roletype_to_char(struct task_struct *task)
66901+{
66902+ switch (task->role->roletype &
66903+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66904+ GR_ROLE_SPECIAL)) {
66905+ case GR_ROLE_DEFAULT:
66906+ return 'D';
66907+ case GR_ROLE_USER:
66908+ return 'U';
66909+ case GR_ROLE_GROUP:
66910+ return 'G';
66911+ case GR_ROLE_SPECIAL:
66912+ return 'S';
66913+ }
66914+
66915+ return 'X';
66916+}
66917+
66918+char gr_roletype_to_char(void)
66919+{
66920+ return gr_task_roletype_to_char(current);
66921+}
66922+
66923+__inline__ int
66924+gr_acl_tpe_check(void)
66925+{
66926+ if (unlikely(!(gr_status & GR_READY)))
66927+ return 0;
66928+ if (current->role->roletype & GR_ROLE_TPE)
66929+ return 1;
66930+ else
66931+ return 0;
66932+}
66933+
66934+int
66935+gr_handle_rawio(const struct inode *inode)
66936+{
66937+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66938+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66939+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66940+ !capable(CAP_SYS_RAWIO))
66941+ return 1;
66942+#endif
66943+ return 0;
66944+}
66945+
66946+int
66947+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66948+{
66949+ if (likely(lena != lenb))
66950+ return 0;
66951+
66952+ return !memcmp(a, b, lena);
66953+}
66954+
66955+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66956+{
66957+ *buflen -= namelen;
66958+ if (*buflen < 0)
66959+ return -ENAMETOOLONG;
66960+ *buffer -= namelen;
66961+ memcpy(*buffer, str, namelen);
66962+ return 0;
66963+}
66964+
66965+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
66966+{
66967+ return prepend(buffer, buflen, name->name, name->len);
66968+}
66969+
66970+static int prepend_path(const struct path *path, struct path *root,
66971+ char **buffer, int *buflen)
66972+{
66973+ struct dentry *dentry = path->dentry;
66974+ struct vfsmount *vfsmnt = path->mnt;
66975+ struct mount *mnt = real_mount(vfsmnt);
66976+ bool slash = false;
66977+ int error = 0;
66978+
66979+ while (dentry != root->dentry || vfsmnt != root->mnt) {
66980+ struct dentry * parent;
66981+
66982+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
66983+ /* Global root? */
66984+ if (!mnt_has_parent(mnt)) {
66985+ goto out;
66986+ }
66987+ dentry = mnt->mnt_mountpoint;
66988+ mnt = mnt->mnt_parent;
66989+ vfsmnt = &mnt->mnt;
66990+ continue;
66991+ }
66992+ parent = dentry->d_parent;
66993+ prefetch(parent);
66994+ spin_lock(&dentry->d_lock);
66995+ error = prepend_name(buffer, buflen, &dentry->d_name);
66996+ spin_unlock(&dentry->d_lock);
66997+ if (!error)
66998+ error = prepend(buffer, buflen, "/", 1);
66999+ if (error)
67000+ break;
67001+
67002+ slash = true;
67003+ dentry = parent;
67004+ }
67005+
67006+out:
67007+ if (!error && !slash)
67008+ error = prepend(buffer, buflen, "/", 1);
67009+
67010+ return error;
67011+}
67012+
67013+/* this must be called with mount_lock and rename_lock held */
67014+
67015+static char *__our_d_path(const struct path *path, struct path *root,
67016+ char *buf, int buflen)
67017+{
67018+ char *res = buf + buflen;
67019+ int error;
67020+
67021+ prepend(&res, &buflen, "\0", 1);
67022+ error = prepend_path(path, root, &res, &buflen);
67023+ if (error)
67024+ return ERR_PTR(error);
67025+
67026+ return res;
67027+}
67028+
67029+static char *
67030+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67031+{
67032+ char *retval;
67033+
67034+ retval = __our_d_path(path, root, buf, buflen);
67035+ if (unlikely(IS_ERR(retval)))
67036+ retval = strcpy(buf, "<path too long>");
67037+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67038+ retval[1] = '\0';
67039+
67040+ return retval;
67041+}
67042+
67043+static char *
67044+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67045+ char *buf, int buflen)
67046+{
67047+ struct path path;
67048+ char *res;
67049+
67050+ path.dentry = (struct dentry *)dentry;
67051+ path.mnt = (struct vfsmount *)vfsmnt;
67052+
67053+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67054+ by the RBAC system */
67055+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
67056+
67057+ return res;
67058+}
67059+
67060+static char *
67061+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67062+ char *buf, int buflen)
67063+{
67064+ char *res;
67065+ struct path path;
67066+ struct path root;
67067+ struct task_struct *reaper = init_pid_ns.child_reaper;
67068+
67069+ path.dentry = (struct dentry *)dentry;
67070+ path.mnt = (struct vfsmount *)vfsmnt;
67071+
67072+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67073+ get_fs_root(reaper->fs, &root);
67074+
67075+ read_seqlock_excl(&mount_lock);
67076+ write_seqlock(&rename_lock);
67077+ res = gen_full_path(&path, &root, buf, buflen);
67078+ write_sequnlock(&rename_lock);
67079+ read_sequnlock_excl(&mount_lock);
67080+
67081+ path_put(&root);
67082+ return res;
67083+}
67084+
67085+char *
67086+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67087+{
67088+ char *ret;
67089+ read_seqlock_excl(&mount_lock);
67090+ write_seqlock(&rename_lock);
67091+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67092+ PAGE_SIZE);
67093+ write_sequnlock(&rename_lock);
67094+ read_sequnlock_excl(&mount_lock);
67095+ return ret;
67096+}
67097+
67098+static char *
67099+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67100+{
67101+ char *ret;
67102+ char *buf;
67103+ int buflen;
67104+
67105+ read_seqlock_excl(&mount_lock);
67106+ write_seqlock(&rename_lock);
67107+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67108+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67109+ buflen = (int)(ret - buf);
67110+ if (buflen >= 5)
67111+ prepend(&ret, &buflen, "/proc", 5);
67112+ else
67113+ ret = strcpy(buf, "<path too long>");
67114+ write_sequnlock(&rename_lock);
67115+ read_sequnlock_excl(&mount_lock);
67116+ return ret;
67117+}
67118+
67119+char *
67120+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67121+{
67122+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67123+ PAGE_SIZE);
67124+}
67125+
67126+char *
67127+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67128+{
67129+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67130+ PAGE_SIZE);
67131+}
67132+
67133+char *
67134+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67135+{
67136+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67137+ PAGE_SIZE);
67138+}
67139+
67140+char *
67141+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67142+{
67143+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67144+ PAGE_SIZE);
67145+}
67146+
67147+char *
67148+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67149+{
67150+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67151+ PAGE_SIZE);
67152+}
67153+
67154+__inline__ __u32
67155+to_gr_audit(const __u32 reqmode)
67156+{
67157+ /* masks off auditable permission flags, then shifts them to create
67158+ auditing flags, and adds the special case of append auditing if
67159+ we're requesting write */
67160+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67161+}
67162+
67163+struct acl_role_label *
67164+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67165+ const gid_t gid)
67166+{
67167+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67168+ struct acl_role_label *match;
67169+ struct role_allowed_ip *ipp;
67170+ unsigned int x;
67171+ u32 curr_ip = task->signal->saved_ip;
67172+
67173+ match = state->acl_role_set.r_hash[index];
67174+
67175+ while (match) {
67176+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67177+ for (x = 0; x < match->domain_child_num; x++) {
67178+ if (match->domain_children[x] == uid)
67179+ goto found;
67180+ }
67181+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67182+ break;
67183+ match = match->next;
67184+ }
67185+found:
67186+ if (match == NULL) {
67187+ try_group:
67188+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67189+ match = state->acl_role_set.r_hash[index];
67190+
67191+ while (match) {
67192+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67193+ for (x = 0; x < match->domain_child_num; x++) {
67194+ if (match->domain_children[x] == gid)
67195+ goto found2;
67196+ }
67197+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67198+ break;
67199+ match = match->next;
67200+ }
67201+found2:
67202+ if (match == NULL)
67203+ match = state->default_role;
67204+ if (match->allowed_ips == NULL)
67205+ return match;
67206+ else {
67207+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67208+ if (likely
67209+ ((ntohl(curr_ip) & ipp->netmask) ==
67210+ (ntohl(ipp->addr) & ipp->netmask)))
67211+ return match;
67212+ }
67213+ match = state->default_role;
67214+ }
67215+ } else if (match->allowed_ips == NULL) {
67216+ return match;
67217+ } else {
67218+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67219+ if (likely
67220+ ((ntohl(curr_ip) & ipp->netmask) ==
67221+ (ntohl(ipp->addr) & ipp->netmask)))
67222+ return match;
67223+ }
67224+ goto try_group;
67225+ }
67226+
67227+ return match;
67228+}
67229+
67230+static struct acl_role_label *
67231+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67232+ const gid_t gid)
67233+{
67234+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67235+}
67236+
67237+struct acl_subject_label *
67238+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67239+ const struct acl_role_label *role)
67240+{
67241+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67242+ struct acl_subject_label *match;
67243+
67244+ match = role->subj_hash[index];
67245+
67246+ while (match && (match->inode != ino || match->device != dev ||
67247+ (match->mode & GR_DELETED))) {
67248+ match = match->next;
67249+ }
67250+
67251+ if (match && !(match->mode & GR_DELETED))
67252+ return match;
67253+ else
67254+ return NULL;
67255+}
67256+
67257+struct acl_subject_label *
67258+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67259+ const struct acl_role_label *role)
67260+{
67261+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67262+ struct acl_subject_label *match;
67263+
67264+ match = role->subj_hash[index];
67265+
67266+ while (match && (match->inode != ino || match->device != dev ||
67267+ !(match->mode & GR_DELETED))) {
67268+ match = match->next;
67269+ }
67270+
67271+ if (match && (match->mode & GR_DELETED))
67272+ return match;
67273+ else
67274+ return NULL;
67275+}
67276+
67277+static struct acl_object_label *
67278+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67279+ const struct acl_subject_label *subj)
67280+{
67281+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67282+ struct acl_object_label *match;
67283+
67284+ match = subj->obj_hash[index];
67285+
67286+ while (match && (match->inode != ino || match->device != dev ||
67287+ (match->mode & GR_DELETED))) {
67288+ match = match->next;
67289+ }
67290+
67291+ if (match && !(match->mode & GR_DELETED))
67292+ return match;
67293+ else
67294+ return NULL;
67295+}
67296+
67297+static struct acl_object_label *
67298+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67299+ const struct acl_subject_label *subj)
67300+{
67301+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67302+ struct acl_object_label *match;
67303+
67304+ match = subj->obj_hash[index];
67305+
67306+ while (match && (match->inode != ino || match->device != dev ||
67307+ !(match->mode & GR_DELETED))) {
67308+ match = match->next;
67309+ }
67310+
67311+ if (match && (match->mode & GR_DELETED))
67312+ return match;
67313+
67314+ match = subj->obj_hash[index];
67315+
67316+ while (match && (match->inode != ino || match->device != dev ||
67317+ (match->mode & GR_DELETED))) {
67318+ match = match->next;
67319+ }
67320+
67321+ if (match && !(match->mode & GR_DELETED))
67322+ return match;
67323+ else
67324+ return NULL;
67325+}
67326+
67327+struct name_entry *
67328+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67329+{
67330+ unsigned int len = strlen(name);
67331+ unsigned int key = full_name_hash(name, len);
67332+ unsigned int index = key % state->name_set.n_size;
67333+ struct name_entry *match;
67334+
67335+ match = state->name_set.n_hash[index];
67336+
67337+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67338+ match = match->next;
67339+
67340+ return match;
67341+}
67342+
67343+static struct name_entry *
67344+lookup_name_entry(const char *name)
67345+{
67346+ return __lookup_name_entry(&running_polstate, name);
67347+}
67348+
67349+static struct name_entry *
67350+lookup_name_entry_create(const char *name)
67351+{
67352+ unsigned int len = strlen(name);
67353+ unsigned int key = full_name_hash(name, len);
67354+ unsigned int index = key % running_polstate.name_set.n_size;
67355+ struct name_entry *match;
67356+
67357+ match = running_polstate.name_set.n_hash[index];
67358+
67359+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67360+ !match->deleted))
67361+ match = match->next;
67362+
67363+ if (match && match->deleted)
67364+ return match;
67365+
67366+ match = running_polstate.name_set.n_hash[index];
67367+
67368+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67369+ match->deleted))
67370+ match = match->next;
67371+
67372+ if (match && !match->deleted)
67373+ return match;
67374+ else
67375+ return NULL;
67376+}
67377+
67378+static struct inodev_entry *
67379+lookup_inodev_entry(const ino_t ino, const dev_t dev)
67380+{
67381+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67382+ struct inodev_entry *match;
67383+
67384+ match = running_polstate.inodev_set.i_hash[index];
67385+
67386+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67387+ match = match->next;
67388+
67389+ return match;
67390+}
67391+
67392+void
67393+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67394+{
67395+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67396+ state->inodev_set.i_size);
67397+ struct inodev_entry **curr;
67398+
67399+ entry->prev = NULL;
67400+
67401+ curr = &state->inodev_set.i_hash[index];
67402+ if (*curr != NULL)
67403+ (*curr)->prev = entry;
67404+
67405+ entry->next = *curr;
67406+ *curr = entry;
67407+
67408+ return;
67409+}
67410+
67411+static void
67412+insert_inodev_entry(struct inodev_entry *entry)
67413+{
67414+ __insert_inodev_entry(&running_polstate, entry);
67415+}
67416+
67417+void
67418+insert_acl_obj_label(struct acl_object_label *obj,
67419+ struct acl_subject_label *subj)
67420+{
67421+ unsigned int index =
67422+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67423+ struct acl_object_label **curr;
67424+
67425+ obj->prev = NULL;
67426+
67427+ curr = &subj->obj_hash[index];
67428+ if (*curr != NULL)
67429+ (*curr)->prev = obj;
67430+
67431+ obj->next = *curr;
67432+ *curr = obj;
67433+
67434+ return;
67435+}
67436+
67437+void
67438+insert_acl_subj_label(struct acl_subject_label *obj,
67439+ struct acl_role_label *role)
67440+{
67441+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67442+ struct acl_subject_label **curr;
67443+
67444+ obj->prev = NULL;
67445+
67446+ curr = &role->subj_hash[index];
67447+ if (*curr != NULL)
67448+ (*curr)->prev = obj;
67449+
67450+ obj->next = *curr;
67451+ *curr = obj;
67452+
67453+ return;
67454+}
67455+
67456+/* derived from glibc fnmatch() 0: match, 1: no match*/
67457+
67458+static int
67459+glob_match(const char *p, const char *n)
67460+{
67461+ char c;
67462+
67463+ while ((c = *p++) != '\0') {
67464+ switch (c) {
67465+ case '?':
67466+ if (*n == '\0')
67467+ return 1;
67468+ else if (*n == '/')
67469+ return 1;
67470+ break;
67471+ case '\\':
67472+ if (*n != c)
67473+ return 1;
67474+ break;
67475+ case '*':
67476+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
67477+ if (*n == '/')
67478+ return 1;
67479+ else if (c == '?') {
67480+ if (*n == '\0')
67481+ return 1;
67482+ else
67483+ ++n;
67484+ }
67485+ }
67486+ if (c == '\0') {
67487+ return 0;
67488+ } else {
67489+ const char *endp;
67490+
67491+ if ((endp = strchr(n, '/')) == NULL)
67492+ endp = n + strlen(n);
67493+
67494+ if (c == '[') {
67495+ for (--p; n < endp; ++n)
67496+ if (!glob_match(p, n))
67497+ return 0;
67498+ } else if (c == '/') {
67499+ while (*n != '\0' && *n != '/')
67500+ ++n;
67501+ if (*n == '/' && !glob_match(p, n + 1))
67502+ return 0;
67503+ } else {
67504+ for (--p; n < endp; ++n)
67505+ if (*n == c && !glob_match(p, n))
67506+ return 0;
67507+ }
67508+
67509+ return 1;
67510+ }
67511+ case '[':
67512+ {
67513+ int not;
67514+ char cold;
67515+
67516+ if (*n == '\0' || *n == '/')
67517+ return 1;
67518+
67519+ not = (*p == '!' || *p == '^');
67520+ if (not)
67521+ ++p;
67522+
67523+ c = *p++;
67524+ for (;;) {
67525+ unsigned char fn = (unsigned char)*n;
67526+
67527+ if (c == '\0')
67528+ return 1;
67529+ else {
67530+ if (c == fn)
67531+ goto matched;
67532+ cold = c;
67533+ c = *p++;
67534+
67535+ if (c == '-' && *p != ']') {
67536+ unsigned char cend = *p++;
67537+
67538+ if (cend == '\0')
67539+ return 1;
67540+
67541+ if (cold <= fn && fn <= cend)
67542+ goto matched;
67543+
67544+ c = *p++;
67545+ }
67546+ }
67547+
67548+ if (c == ']')
67549+ break;
67550+ }
67551+ if (!not)
67552+ return 1;
67553+ break;
67554+ matched:
67555+ while (c != ']') {
67556+ if (c == '\0')
67557+ return 1;
67558+
67559+ c = *p++;
67560+ }
67561+ if (not)
67562+ return 1;
67563+ }
67564+ break;
67565+ default:
67566+ if (c != *n)
67567+ return 1;
67568+ }
67569+
67570+ ++n;
67571+ }
67572+
67573+ if (*n == '\0')
67574+ return 0;
67575+
67576+ if (*n == '/')
67577+ return 0;
67578+
67579+ return 1;
67580+}
67581+
67582+static struct acl_object_label *
67583+chk_glob_label(struct acl_object_label *globbed,
67584+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67585+{
67586+ struct acl_object_label *tmp;
67587+
67588+ if (*path == NULL)
67589+ *path = gr_to_filename_nolock(dentry, mnt);
67590+
67591+ tmp = globbed;
67592+
67593+ while (tmp) {
67594+ if (!glob_match(tmp->filename, *path))
67595+ return tmp;
67596+ tmp = tmp->next;
67597+ }
67598+
67599+ return NULL;
67600+}
67601+
67602+static struct acl_object_label *
67603+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67604+ const ino_t curr_ino, const dev_t curr_dev,
67605+ const struct acl_subject_label *subj, char **path, const int checkglob)
67606+{
67607+ struct acl_subject_label *tmpsubj;
67608+ struct acl_object_label *retval;
67609+ struct acl_object_label *retval2;
67610+
67611+ tmpsubj = (struct acl_subject_label *) subj;
67612+ read_lock(&gr_inode_lock);
67613+ do {
67614+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67615+ if (retval) {
67616+ if (checkglob && retval->globbed) {
67617+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67618+ if (retval2)
67619+ retval = retval2;
67620+ }
67621+ break;
67622+ }
67623+ } while ((tmpsubj = tmpsubj->parent_subject));
67624+ read_unlock(&gr_inode_lock);
67625+
67626+ return retval;
67627+}
67628+
67629+static __inline__ struct acl_object_label *
67630+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67631+ struct dentry *curr_dentry,
67632+ const struct acl_subject_label *subj, char **path, const int checkglob)
67633+{
67634+ int newglob = checkglob;
67635+ ino_t inode;
67636+ dev_t device;
67637+
67638+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67639+ as we don't want a / * rule to match instead of the / object
67640+ don't do this for create lookups that call this function though, since they're looking up
67641+ on the parent and thus need globbing checks on all paths
67642+ */
67643+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67644+ newglob = GR_NO_GLOB;
67645+
67646+ spin_lock(&curr_dentry->d_lock);
67647+ inode = curr_dentry->d_inode->i_ino;
67648+ device = __get_dev(curr_dentry);
67649+ spin_unlock(&curr_dentry->d_lock);
67650+
67651+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67652+}
67653+
67654+#ifdef CONFIG_HUGETLBFS
67655+static inline bool
67656+is_hugetlbfs_mnt(const struct vfsmount *mnt)
67657+{
67658+ int i;
67659+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67660+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67661+ return true;
67662+ }
67663+
67664+ return false;
67665+}
67666+#endif
67667+
67668+static struct acl_object_label *
67669+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67670+ const struct acl_subject_label *subj, char *path, const int checkglob)
67671+{
67672+ struct dentry *dentry = (struct dentry *) l_dentry;
67673+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67674+ struct mount *real_mnt = real_mount(mnt);
67675+ struct acl_object_label *retval;
67676+ struct dentry *parent;
67677+
67678+ read_seqlock_excl(&mount_lock);
67679+ write_seqlock(&rename_lock);
67680+
67681+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67682+#ifdef CONFIG_NET
67683+ mnt == sock_mnt ||
67684+#endif
67685+#ifdef CONFIG_HUGETLBFS
67686+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67687+#endif
67688+ /* ignore Eric Biederman */
67689+ IS_PRIVATE(l_dentry->d_inode))) {
67690+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67691+ goto out;
67692+ }
67693+
67694+ for (;;) {
67695+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67696+ break;
67697+
67698+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67699+ if (!mnt_has_parent(real_mnt))
67700+ break;
67701+
67702+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67703+ if (retval != NULL)
67704+ goto out;
67705+
67706+ dentry = real_mnt->mnt_mountpoint;
67707+ real_mnt = real_mnt->mnt_parent;
67708+ mnt = &real_mnt->mnt;
67709+ continue;
67710+ }
67711+
67712+ parent = dentry->d_parent;
67713+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67714+ if (retval != NULL)
67715+ goto out;
67716+
67717+ dentry = parent;
67718+ }
67719+
67720+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67721+
67722+ /* gr_real_root is pinned so we don't have to hold a reference */
67723+ if (retval == NULL)
67724+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67725+out:
67726+ write_sequnlock(&rename_lock);
67727+ read_sequnlock_excl(&mount_lock);
67728+
67729+ BUG_ON(retval == NULL);
67730+
67731+ return retval;
67732+}
67733+
67734+static __inline__ struct acl_object_label *
67735+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67736+ const struct acl_subject_label *subj)
67737+{
67738+ char *path = NULL;
67739+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67740+}
67741+
67742+static __inline__ struct acl_object_label *
67743+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67744+ const struct acl_subject_label *subj)
67745+{
67746+ char *path = NULL;
67747+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67748+}
67749+
67750+static __inline__ struct acl_object_label *
67751+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67752+ const struct acl_subject_label *subj, char *path)
67753+{
67754+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67755+}
67756+
67757+struct acl_subject_label *
67758+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67759+ const struct acl_role_label *role)
67760+{
67761+ struct dentry *dentry = (struct dentry *) l_dentry;
67762+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67763+ struct mount *real_mnt = real_mount(mnt);
67764+ struct acl_subject_label *retval;
67765+ struct dentry *parent;
67766+
67767+ read_seqlock_excl(&mount_lock);
67768+ write_seqlock(&rename_lock);
67769+
67770+ for (;;) {
67771+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67772+ break;
67773+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67774+ if (!mnt_has_parent(real_mnt))
67775+ break;
67776+
67777+ spin_lock(&dentry->d_lock);
67778+ read_lock(&gr_inode_lock);
67779+ retval =
67780+ lookup_acl_subj_label(dentry->d_inode->i_ino,
67781+ __get_dev(dentry), role);
67782+ read_unlock(&gr_inode_lock);
67783+ spin_unlock(&dentry->d_lock);
67784+ if (retval != NULL)
67785+ goto out;
67786+
67787+ dentry = real_mnt->mnt_mountpoint;
67788+ real_mnt = real_mnt->mnt_parent;
67789+ mnt = &real_mnt->mnt;
67790+ continue;
67791+ }
67792+
67793+ spin_lock(&dentry->d_lock);
67794+ read_lock(&gr_inode_lock);
67795+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67796+ __get_dev(dentry), role);
67797+ read_unlock(&gr_inode_lock);
67798+ parent = dentry->d_parent;
67799+ spin_unlock(&dentry->d_lock);
67800+
67801+ if (retval != NULL)
67802+ goto out;
67803+
67804+ dentry = parent;
67805+ }
67806+
67807+ spin_lock(&dentry->d_lock);
67808+ read_lock(&gr_inode_lock);
67809+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67810+ __get_dev(dentry), role);
67811+ read_unlock(&gr_inode_lock);
67812+ spin_unlock(&dentry->d_lock);
67813+
67814+ if (unlikely(retval == NULL)) {
67815+ /* gr_real_root is pinned, we don't need to hold a reference */
67816+ read_lock(&gr_inode_lock);
67817+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67818+ __get_dev(gr_real_root.dentry), role);
67819+ read_unlock(&gr_inode_lock);
67820+ }
67821+out:
67822+ write_sequnlock(&rename_lock);
67823+ read_sequnlock_excl(&mount_lock);
67824+
67825+ BUG_ON(retval == NULL);
67826+
67827+ return retval;
67828+}
67829+
67830+void
67831+assign_special_role(const char *rolename)
67832+{
67833+ struct acl_object_label *obj;
67834+ struct acl_role_label *r;
67835+ struct acl_role_label *assigned = NULL;
67836+ struct task_struct *tsk;
67837+ struct file *filp;
67838+
67839+ FOR_EACH_ROLE_START(r)
67840+ if (!strcmp(rolename, r->rolename) &&
67841+ (r->roletype & GR_ROLE_SPECIAL)) {
67842+ assigned = r;
67843+ break;
67844+ }
67845+ FOR_EACH_ROLE_END(r)
67846+
67847+ if (!assigned)
67848+ return;
67849+
67850+ read_lock(&tasklist_lock);
67851+ read_lock(&grsec_exec_file_lock);
67852+
67853+ tsk = current->real_parent;
67854+ if (tsk == NULL)
67855+ goto out_unlock;
67856+
67857+ filp = tsk->exec_file;
67858+ if (filp == NULL)
67859+ goto out_unlock;
67860+
67861+ tsk->is_writable = 0;
67862+ tsk->inherited = 0;
67863+
67864+ tsk->acl_sp_role = 1;
67865+ tsk->acl_role_id = ++acl_sp_role_value;
67866+ tsk->role = assigned;
67867+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67868+
67869+ /* ignore additional mmap checks for processes that are writable
67870+ by the default ACL */
67871+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67872+ if (unlikely(obj->mode & GR_WRITE))
67873+ tsk->is_writable = 1;
67874+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67875+ if (unlikely(obj->mode & GR_WRITE))
67876+ tsk->is_writable = 1;
67877+
67878+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67879+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67880+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67881+#endif
67882+
67883+out_unlock:
67884+ read_unlock(&grsec_exec_file_lock);
67885+ read_unlock(&tasklist_lock);
67886+ return;
67887+}
67888+
67889+
67890+static void
67891+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67892+{
67893+ struct task_struct *task = current;
67894+ const struct cred *cred = current_cred();
67895+
67896+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67897+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67898+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67899+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67900+
67901+ return;
67902+}
67903+
67904+static void
67905+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67906+{
67907+ struct task_struct *task = current;
67908+ const struct cred *cred = current_cred();
67909+
67910+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67911+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67912+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67913+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67914+
67915+ return;
67916+}
67917+
67918+static void
67919+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67920+{
67921+ struct task_struct *task = current;
67922+ const struct cred *cred = current_cred();
67923+
67924+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67925+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67926+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67927+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67928+
67929+ return;
67930+}
67931+
67932+static void
67933+gr_set_proc_res(struct task_struct *task)
67934+{
67935+ struct acl_subject_label *proc;
67936+ unsigned short i;
67937+
67938+ proc = task->acl;
67939+
67940+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67941+ return;
67942+
67943+ for (i = 0; i < RLIM_NLIMITS; i++) {
67944+ if (!(proc->resmask & (1U << i)))
67945+ continue;
67946+
67947+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67948+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67949+
67950+ if (i == RLIMIT_CPU)
67951+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
67952+ }
67953+
67954+ return;
67955+}
67956+
67957+/* both of the below must be called with
67958+ rcu_read_lock();
67959+ read_lock(&tasklist_lock);
67960+ read_lock(&grsec_exec_file_lock);
67961+*/
67962+
67963+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
67964+{
67965+ char *tmpname;
67966+ struct acl_subject_label *tmpsubj;
67967+ struct file *filp;
67968+ struct name_entry *nmatch;
67969+
67970+ filp = task->exec_file;
67971+ if (filp == NULL)
67972+ return NULL;
67973+
67974+ /* the following is to apply the correct subject
67975+ on binaries running when the RBAC system
67976+ is enabled, when the binaries have been
67977+ replaced or deleted since their execution
67978+ -----
67979+ when the RBAC system starts, the inode/dev
67980+ from exec_file will be one the RBAC system
67981+ is unaware of. It only knows the inode/dev
67982+ of the present file on disk, or the absence
67983+ of it.
67984+ */
67985+
67986+ if (filename)
67987+ nmatch = __lookup_name_entry(state, filename);
67988+ else {
67989+ preempt_disable();
67990+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
67991+
67992+ nmatch = __lookup_name_entry(state, tmpname);
67993+ preempt_enable();
67994+ }
67995+ tmpsubj = NULL;
67996+ if (nmatch) {
67997+ if (nmatch->deleted)
67998+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
67999+ else
68000+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68001+ }
68002+ /* this also works for the reload case -- if we don't match a potentially inherited subject
68003+ then we fall back to a normal lookup based on the binary's ino/dev
68004+ */
68005+ if (tmpsubj == NULL)
68006+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68007+
68008+ return tmpsubj;
68009+}
68010+
68011+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68012+{
68013+ return __gr_get_subject_for_task(&running_polstate, task, filename);
68014+}
68015+
68016+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68017+{
68018+ struct acl_object_label *obj;
68019+ struct file *filp;
68020+
68021+ filp = task->exec_file;
68022+
68023+ task->acl = subj;
68024+ task->is_writable = 0;
68025+ /* ignore additional mmap checks for processes that are writable
68026+ by the default ACL */
68027+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68028+ if (unlikely(obj->mode & GR_WRITE))
68029+ task->is_writable = 1;
68030+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68031+ if (unlikely(obj->mode & GR_WRITE))
68032+ task->is_writable = 1;
68033+
68034+ gr_set_proc_res(task);
68035+
68036+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68037+ 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);
68038+#endif
68039+}
68040+
68041+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68042+{
68043+ __gr_apply_subject_to_task(&running_polstate, task, subj);
68044+}
68045+
68046+__u32
68047+gr_search_file(const struct dentry * dentry, const __u32 mode,
68048+ const struct vfsmount * mnt)
68049+{
68050+ __u32 retval = mode;
68051+ struct acl_subject_label *curracl;
68052+ struct acl_object_label *currobj;
68053+
68054+ if (unlikely(!(gr_status & GR_READY)))
68055+ return (mode & ~GR_AUDITS);
68056+
68057+ curracl = current->acl;
68058+
68059+ currobj = chk_obj_label(dentry, mnt, curracl);
68060+ retval = currobj->mode & mode;
68061+
68062+ /* if we're opening a specified transfer file for writing
68063+ (e.g. /dev/initctl), then transfer our role to init
68064+ */
68065+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68066+ current->role->roletype & GR_ROLE_PERSIST)) {
68067+ struct task_struct *task = init_pid_ns.child_reaper;
68068+
68069+ if (task->role != current->role) {
68070+ struct acl_subject_label *subj;
68071+
68072+ task->acl_sp_role = 0;
68073+ task->acl_role_id = current->acl_role_id;
68074+ task->role = current->role;
68075+ rcu_read_lock();
68076+ read_lock(&grsec_exec_file_lock);
68077+ subj = gr_get_subject_for_task(task, NULL);
68078+ gr_apply_subject_to_task(task, subj);
68079+ read_unlock(&grsec_exec_file_lock);
68080+ rcu_read_unlock();
68081+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68082+ }
68083+ }
68084+
68085+ if (unlikely
68086+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68087+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68088+ __u32 new_mode = mode;
68089+
68090+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68091+
68092+ retval = new_mode;
68093+
68094+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68095+ new_mode |= GR_INHERIT;
68096+
68097+ if (!(mode & GR_NOLEARN))
68098+ gr_log_learn(dentry, mnt, new_mode);
68099+ }
68100+
68101+ return retval;
68102+}
68103+
68104+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68105+ const struct dentry *parent,
68106+ const struct vfsmount *mnt)
68107+{
68108+ struct name_entry *match;
68109+ struct acl_object_label *matchpo;
68110+ struct acl_subject_label *curracl;
68111+ char *path;
68112+
68113+ if (unlikely(!(gr_status & GR_READY)))
68114+ return NULL;
68115+
68116+ preempt_disable();
68117+ path = gr_to_filename_rbac(new_dentry, mnt);
68118+ match = lookup_name_entry_create(path);
68119+
68120+ curracl = current->acl;
68121+
68122+ if (match) {
68123+ read_lock(&gr_inode_lock);
68124+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68125+ read_unlock(&gr_inode_lock);
68126+
68127+ if (matchpo) {
68128+ preempt_enable();
68129+ return matchpo;
68130+ }
68131+ }
68132+
68133+ // lookup parent
68134+
68135+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68136+
68137+ preempt_enable();
68138+ return matchpo;
68139+}
68140+
68141+__u32
68142+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68143+ const struct vfsmount * mnt, const __u32 mode)
68144+{
68145+ struct acl_object_label *matchpo;
68146+ __u32 retval;
68147+
68148+ if (unlikely(!(gr_status & GR_READY)))
68149+ return (mode & ~GR_AUDITS);
68150+
68151+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
68152+
68153+ retval = matchpo->mode & mode;
68154+
68155+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68156+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68157+ __u32 new_mode = mode;
68158+
68159+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68160+
68161+ gr_log_learn(new_dentry, mnt, new_mode);
68162+ return new_mode;
68163+ }
68164+
68165+ return retval;
68166+}
68167+
68168+__u32
68169+gr_check_link(const struct dentry * new_dentry,
68170+ const struct dentry * parent_dentry,
68171+ const struct vfsmount * parent_mnt,
68172+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68173+{
68174+ struct acl_object_label *obj;
68175+ __u32 oldmode, newmode;
68176+ __u32 needmode;
68177+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68178+ GR_DELETE | GR_INHERIT;
68179+
68180+ if (unlikely(!(gr_status & GR_READY)))
68181+ return (GR_CREATE | GR_LINK);
68182+
68183+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68184+ oldmode = obj->mode;
68185+
68186+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68187+ newmode = obj->mode;
68188+
68189+ needmode = newmode & checkmodes;
68190+
68191+ // old name for hardlink must have at least the permissions of the new name
68192+ if ((oldmode & needmode) != needmode)
68193+ goto bad;
68194+
68195+ // if old name had restrictions/auditing, make sure the new name does as well
68196+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68197+
68198+ // don't allow hardlinking of suid/sgid/fcapped files without permission
68199+ if (is_privileged_binary(old_dentry))
68200+ needmode |= GR_SETID;
68201+
68202+ if ((newmode & needmode) != needmode)
68203+ goto bad;
68204+
68205+ // enforce minimum permissions
68206+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68207+ return newmode;
68208+bad:
68209+ needmode = oldmode;
68210+ if (is_privileged_binary(old_dentry))
68211+ needmode |= GR_SETID;
68212+
68213+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68214+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68215+ return (GR_CREATE | GR_LINK);
68216+ } else if (newmode & GR_SUPPRESS)
68217+ return GR_SUPPRESS;
68218+ else
68219+ return 0;
68220+}
68221+
68222+int
68223+gr_check_hidden_task(const struct task_struct *task)
68224+{
68225+ if (unlikely(!(gr_status & GR_READY)))
68226+ return 0;
68227+
68228+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68229+ return 1;
68230+
68231+ return 0;
68232+}
68233+
68234+int
68235+gr_check_protected_task(const struct task_struct *task)
68236+{
68237+ if (unlikely(!(gr_status & GR_READY) || !task))
68238+ return 0;
68239+
68240+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68241+ task->acl != current->acl)
68242+ return 1;
68243+
68244+ return 0;
68245+}
68246+
68247+int
68248+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68249+{
68250+ struct task_struct *p;
68251+ int ret = 0;
68252+
68253+ if (unlikely(!(gr_status & GR_READY) || !pid))
68254+ return ret;
68255+
68256+ read_lock(&tasklist_lock);
68257+ do_each_pid_task(pid, type, p) {
68258+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68259+ p->acl != current->acl) {
68260+ ret = 1;
68261+ goto out;
68262+ }
68263+ } while_each_pid_task(pid, type, p);
68264+out:
68265+ read_unlock(&tasklist_lock);
68266+
68267+ return ret;
68268+}
68269+
68270+void
68271+gr_copy_label(struct task_struct *tsk)
68272+{
68273+ struct task_struct *p = current;
68274+
68275+ tsk->inherited = p->inherited;
68276+ tsk->acl_sp_role = 0;
68277+ tsk->acl_role_id = p->acl_role_id;
68278+ tsk->acl = p->acl;
68279+ tsk->role = p->role;
68280+ tsk->signal->used_accept = 0;
68281+ tsk->signal->curr_ip = p->signal->curr_ip;
68282+ tsk->signal->saved_ip = p->signal->saved_ip;
68283+ if (p->exec_file)
68284+ get_file(p->exec_file);
68285+ tsk->exec_file = p->exec_file;
68286+ tsk->is_writable = p->is_writable;
68287+ if (unlikely(p->signal->used_accept)) {
68288+ p->signal->curr_ip = 0;
68289+ p->signal->saved_ip = 0;
68290+ }
68291+
68292+ return;
68293+}
68294+
68295+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68296+
68297+int
68298+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68299+{
68300+ unsigned int i;
68301+ __u16 num;
68302+ uid_t *uidlist;
68303+ uid_t curuid;
68304+ int realok = 0;
68305+ int effectiveok = 0;
68306+ int fsok = 0;
68307+ uid_t globalreal, globaleffective, globalfs;
68308+
68309+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68310+ struct user_struct *user;
68311+
68312+ if (!uid_valid(real))
68313+ goto skipit;
68314+
68315+ /* find user based on global namespace */
68316+
68317+ globalreal = GR_GLOBAL_UID(real);
68318+
68319+ user = find_user(make_kuid(&init_user_ns, globalreal));
68320+ if (user == NULL)
68321+ goto skipit;
68322+
68323+ if (gr_process_kernel_setuid_ban(user)) {
68324+ /* for find_user */
68325+ free_uid(user);
68326+ return 1;
68327+ }
68328+
68329+ /* for find_user */
68330+ free_uid(user);
68331+
68332+skipit:
68333+#endif
68334+
68335+ if (unlikely(!(gr_status & GR_READY)))
68336+ return 0;
68337+
68338+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68339+ gr_log_learn_uid_change(real, effective, fs);
68340+
68341+ num = current->acl->user_trans_num;
68342+ uidlist = current->acl->user_transitions;
68343+
68344+ if (uidlist == NULL)
68345+ return 0;
68346+
68347+ if (!uid_valid(real)) {
68348+ realok = 1;
68349+ globalreal = (uid_t)-1;
68350+ } else {
68351+ globalreal = GR_GLOBAL_UID(real);
68352+ }
68353+ if (!uid_valid(effective)) {
68354+ effectiveok = 1;
68355+ globaleffective = (uid_t)-1;
68356+ } else {
68357+ globaleffective = GR_GLOBAL_UID(effective);
68358+ }
68359+ if (!uid_valid(fs)) {
68360+ fsok = 1;
68361+ globalfs = (uid_t)-1;
68362+ } else {
68363+ globalfs = GR_GLOBAL_UID(fs);
68364+ }
68365+
68366+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
68367+ for (i = 0; i < num; i++) {
68368+ curuid = uidlist[i];
68369+ if (globalreal == curuid)
68370+ realok = 1;
68371+ if (globaleffective == curuid)
68372+ effectiveok = 1;
68373+ if (globalfs == curuid)
68374+ fsok = 1;
68375+ }
68376+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
68377+ for (i = 0; i < num; i++) {
68378+ curuid = uidlist[i];
68379+ if (globalreal == curuid)
68380+ break;
68381+ if (globaleffective == curuid)
68382+ break;
68383+ if (globalfs == curuid)
68384+ break;
68385+ }
68386+ /* not in deny list */
68387+ if (i == num) {
68388+ realok = 1;
68389+ effectiveok = 1;
68390+ fsok = 1;
68391+ }
68392+ }
68393+
68394+ if (realok && effectiveok && fsok)
68395+ return 0;
68396+ else {
68397+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68398+ return 1;
68399+ }
68400+}
68401+
68402+int
68403+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68404+{
68405+ unsigned int i;
68406+ __u16 num;
68407+ gid_t *gidlist;
68408+ gid_t curgid;
68409+ int realok = 0;
68410+ int effectiveok = 0;
68411+ int fsok = 0;
68412+ gid_t globalreal, globaleffective, globalfs;
68413+
68414+ if (unlikely(!(gr_status & GR_READY)))
68415+ return 0;
68416+
68417+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68418+ gr_log_learn_gid_change(real, effective, fs);
68419+
68420+ num = current->acl->group_trans_num;
68421+ gidlist = current->acl->group_transitions;
68422+
68423+ if (gidlist == NULL)
68424+ return 0;
68425+
68426+ if (!gid_valid(real)) {
68427+ realok = 1;
68428+ globalreal = (gid_t)-1;
68429+ } else {
68430+ globalreal = GR_GLOBAL_GID(real);
68431+ }
68432+ if (!gid_valid(effective)) {
68433+ effectiveok = 1;
68434+ globaleffective = (gid_t)-1;
68435+ } else {
68436+ globaleffective = GR_GLOBAL_GID(effective);
68437+ }
68438+ if (!gid_valid(fs)) {
68439+ fsok = 1;
68440+ globalfs = (gid_t)-1;
68441+ } else {
68442+ globalfs = GR_GLOBAL_GID(fs);
68443+ }
68444+
68445+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
68446+ for (i = 0; i < num; i++) {
68447+ curgid = gidlist[i];
68448+ if (globalreal == curgid)
68449+ realok = 1;
68450+ if (globaleffective == curgid)
68451+ effectiveok = 1;
68452+ if (globalfs == curgid)
68453+ fsok = 1;
68454+ }
68455+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
68456+ for (i = 0; i < num; i++) {
68457+ curgid = gidlist[i];
68458+ if (globalreal == curgid)
68459+ break;
68460+ if (globaleffective == curgid)
68461+ break;
68462+ if (globalfs == curgid)
68463+ break;
68464+ }
68465+ /* not in deny list */
68466+ if (i == num) {
68467+ realok = 1;
68468+ effectiveok = 1;
68469+ fsok = 1;
68470+ }
68471+ }
68472+
68473+ if (realok && effectiveok && fsok)
68474+ return 0;
68475+ else {
68476+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68477+ return 1;
68478+ }
68479+}
68480+
68481+extern int gr_acl_is_capable(const int cap);
68482+
68483+void
68484+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68485+{
68486+ struct acl_role_label *role = task->role;
68487+ struct acl_subject_label *subj = NULL;
68488+ struct acl_object_label *obj;
68489+ struct file *filp;
68490+ uid_t uid;
68491+ gid_t gid;
68492+
68493+ if (unlikely(!(gr_status & GR_READY)))
68494+ return;
68495+
68496+ uid = GR_GLOBAL_UID(kuid);
68497+ gid = GR_GLOBAL_GID(kgid);
68498+
68499+ filp = task->exec_file;
68500+
68501+ /* kernel process, we'll give them the kernel role */
68502+ if (unlikely(!filp)) {
68503+ task->role = running_polstate.kernel_role;
68504+ task->acl = running_polstate.kernel_role->root_label;
68505+ return;
68506+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68507+ /* save the current ip at time of role lookup so that the proper
68508+ IP will be learned for role_allowed_ip */
68509+ task->signal->saved_ip = task->signal->curr_ip;
68510+ role = lookup_acl_role_label(task, uid, gid);
68511+ }
68512+
68513+ /* don't change the role if we're not a privileged process */
68514+ if (role && task->role != role &&
68515+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68516+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68517+ return;
68518+
68519+ /* perform subject lookup in possibly new role
68520+ we can use this result below in the case where role == task->role
68521+ */
68522+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68523+
68524+ /* if we changed uid/gid, but result in the same role
68525+ and are using inheritance, don't lose the inherited subject
68526+ if current subject is other than what normal lookup
68527+ would result in, we arrived via inheritance, don't
68528+ lose subject
68529+ */
68530+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68531+ (subj == task->acl)))
68532+ task->acl = subj;
68533+
68534+ /* leave task->inherited unaffected */
68535+
68536+ task->role = role;
68537+
68538+ task->is_writable = 0;
68539+
68540+ /* ignore additional mmap checks for processes that are writable
68541+ by the default ACL */
68542+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68543+ if (unlikely(obj->mode & GR_WRITE))
68544+ task->is_writable = 1;
68545+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68546+ if (unlikely(obj->mode & GR_WRITE))
68547+ task->is_writable = 1;
68548+
68549+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68550+ 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);
68551+#endif
68552+
68553+ gr_set_proc_res(task);
68554+
68555+ return;
68556+}
68557+
68558+int
68559+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68560+ const int unsafe_flags)
68561+{
68562+ struct task_struct *task = current;
68563+ struct acl_subject_label *newacl;
68564+ struct acl_object_label *obj;
68565+ __u32 retmode;
68566+
68567+ if (unlikely(!(gr_status & GR_READY)))
68568+ return 0;
68569+
68570+ newacl = chk_subj_label(dentry, mnt, task->role);
68571+
68572+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68573+ did an exec
68574+ */
68575+ rcu_read_lock();
68576+ read_lock(&tasklist_lock);
68577+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68578+ (task->parent->acl->mode & GR_POVERRIDE))) {
68579+ read_unlock(&tasklist_lock);
68580+ rcu_read_unlock();
68581+ goto skip_check;
68582+ }
68583+ read_unlock(&tasklist_lock);
68584+ rcu_read_unlock();
68585+
68586+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68587+ !(task->role->roletype & GR_ROLE_GOD) &&
68588+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68589+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68590+ if (unsafe_flags & LSM_UNSAFE_SHARE)
68591+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68592+ else
68593+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68594+ return -EACCES;
68595+ }
68596+
68597+skip_check:
68598+
68599+ obj = chk_obj_label(dentry, mnt, task->acl);
68600+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68601+
68602+ if (!(task->acl->mode & GR_INHERITLEARN) &&
68603+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68604+ if (obj->nested)
68605+ task->acl = obj->nested;
68606+ else
68607+ task->acl = newacl;
68608+ task->inherited = 0;
68609+ } else {
68610+ task->inherited = 1;
68611+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68612+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68613+ }
68614+
68615+ task->is_writable = 0;
68616+
68617+ /* ignore additional mmap checks for processes that are writable
68618+ by the default ACL */
68619+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68620+ if (unlikely(obj->mode & GR_WRITE))
68621+ task->is_writable = 1;
68622+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
68623+ if (unlikely(obj->mode & GR_WRITE))
68624+ task->is_writable = 1;
68625+
68626+ gr_set_proc_res(task);
68627+
68628+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68629+ 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);
68630+#endif
68631+ return 0;
68632+}
68633+
68634+/* always called with valid inodev ptr */
68635+static void
68636+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68637+{
68638+ struct acl_object_label *matchpo;
68639+ struct acl_subject_label *matchps;
68640+ struct acl_subject_label *subj;
68641+ struct acl_role_label *role;
68642+ unsigned int x;
68643+
68644+ FOR_EACH_ROLE_START(role)
68645+ FOR_EACH_SUBJECT_START(role, subj, x)
68646+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68647+ matchpo->mode |= GR_DELETED;
68648+ FOR_EACH_SUBJECT_END(subj,x)
68649+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68650+ /* nested subjects aren't in the role's subj_hash table */
68651+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68652+ matchpo->mode |= GR_DELETED;
68653+ FOR_EACH_NESTED_SUBJECT_END(subj)
68654+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68655+ matchps->mode |= GR_DELETED;
68656+ FOR_EACH_ROLE_END(role)
68657+
68658+ inodev->nentry->deleted = 1;
68659+
68660+ return;
68661+}
68662+
68663+void
68664+gr_handle_delete(const ino_t ino, const dev_t dev)
68665+{
68666+ struct inodev_entry *inodev;
68667+
68668+ if (unlikely(!(gr_status & GR_READY)))
68669+ return;
68670+
68671+ write_lock(&gr_inode_lock);
68672+ inodev = lookup_inodev_entry(ino, dev);
68673+ if (inodev != NULL)
68674+ do_handle_delete(inodev, ino, dev);
68675+ write_unlock(&gr_inode_lock);
68676+
68677+ return;
68678+}
68679+
68680+static void
68681+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68682+ const ino_t newinode, const dev_t newdevice,
68683+ struct acl_subject_label *subj)
68684+{
68685+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68686+ struct acl_object_label *match;
68687+
68688+ match = subj->obj_hash[index];
68689+
68690+ while (match && (match->inode != oldinode ||
68691+ match->device != olddevice ||
68692+ !(match->mode & GR_DELETED)))
68693+ match = match->next;
68694+
68695+ if (match && (match->inode == oldinode)
68696+ && (match->device == olddevice)
68697+ && (match->mode & GR_DELETED)) {
68698+ if (match->prev == NULL) {
68699+ subj->obj_hash[index] = match->next;
68700+ if (match->next != NULL)
68701+ match->next->prev = NULL;
68702+ } else {
68703+ match->prev->next = match->next;
68704+ if (match->next != NULL)
68705+ match->next->prev = match->prev;
68706+ }
68707+ match->prev = NULL;
68708+ match->next = NULL;
68709+ match->inode = newinode;
68710+ match->device = newdevice;
68711+ match->mode &= ~GR_DELETED;
68712+
68713+ insert_acl_obj_label(match, subj);
68714+ }
68715+
68716+ return;
68717+}
68718+
68719+static void
68720+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68721+ const ino_t newinode, const dev_t newdevice,
68722+ struct acl_role_label *role)
68723+{
68724+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68725+ struct acl_subject_label *match;
68726+
68727+ match = role->subj_hash[index];
68728+
68729+ while (match && (match->inode != oldinode ||
68730+ match->device != olddevice ||
68731+ !(match->mode & GR_DELETED)))
68732+ match = match->next;
68733+
68734+ if (match && (match->inode == oldinode)
68735+ && (match->device == olddevice)
68736+ && (match->mode & GR_DELETED)) {
68737+ if (match->prev == NULL) {
68738+ role->subj_hash[index] = match->next;
68739+ if (match->next != NULL)
68740+ match->next->prev = NULL;
68741+ } else {
68742+ match->prev->next = match->next;
68743+ if (match->next != NULL)
68744+ match->next->prev = match->prev;
68745+ }
68746+ match->prev = NULL;
68747+ match->next = NULL;
68748+ match->inode = newinode;
68749+ match->device = newdevice;
68750+ match->mode &= ~GR_DELETED;
68751+
68752+ insert_acl_subj_label(match, role);
68753+ }
68754+
68755+ return;
68756+}
68757+
68758+static void
68759+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68760+ const ino_t newinode, const dev_t newdevice)
68761+{
68762+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68763+ struct inodev_entry *match;
68764+
68765+ match = running_polstate.inodev_set.i_hash[index];
68766+
68767+ while (match && (match->nentry->inode != oldinode ||
68768+ match->nentry->device != olddevice || !match->nentry->deleted))
68769+ match = match->next;
68770+
68771+ if (match && (match->nentry->inode == oldinode)
68772+ && (match->nentry->device == olddevice) &&
68773+ match->nentry->deleted) {
68774+ if (match->prev == NULL) {
68775+ running_polstate.inodev_set.i_hash[index] = match->next;
68776+ if (match->next != NULL)
68777+ match->next->prev = NULL;
68778+ } else {
68779+ match->prev->next = match->next;
68780+ if (match->next != NULL)
68781+ match->next->prev = match->prev;
68782+ }
68783+ match->prev = NULL;
68784+ match->next = NULL;
68785+ match->nentry->inode = newinode;
68786+ match->nentry->device = newdevice;
68787+ match->nentry->deleted = 0;
68788+
68789+ insert_inodev_entry(match);
68790+ }
68791+
68792+ return;
68793+}
68794+
68795+static void
68796+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68797+{
68798+ struct acl_subject_label *subj;
68799+ struct acl_role_label *role;
68800+ unsigned int x;
68801+
68802+ FOR_EACH_ROLE_START(role)
68803+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68804+
68805+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68806+ if ((subj->inode == ino) && (subj->device == dev)) {
68807+ subj->inode = ino;
68808+ subj->device = dev;
68809+ }
68810+ /* nested subjects aren't in the role's subj_hash table */
68811+ update_acl_obj_label(matchn->inode, matchn->device,
68812+ ino, dev, subj);
68813+ FOR_EACH_NESTED_SUBJECT_END(subj)
68814+ FOR_EACH_SUBJECT_START(role, subj, x)
68815+ update_acl_obj_label(matchn->inode, matchn->device,
68816+ ino, dev, subj);
68817+ FOR_EACH_SUBJECT_END(subj,x)
68818+ FOR_EACH_ROLE_END(role)
68819+
68820+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68821+
68822+ return;
68823+}
68824+
68825+static void
68826+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68827+ const struct vfsmount *mnt)
68828+{
68829+ ino_t ino = dentry->d_inode->i_ino;
68830+ dev_t dev = __get_dev(dentry);
68831+
68832+ __do_handle_create(matchn, ino, dev);
68833+
68834+ return;
68835+}
68836+
68837+void
68838+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68839+{
68840+ struct name_entry *matchn;
68841+
68842+ if (unlikely(!(gr_status & GR_READY)))
68843+ return;
68844+
68845+ preempt_disable();
68846+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68847+
68848+ if (unlikely((unsigned long)matchn)) {
68849+ write_lock(&gr_inode_lock);
68850+ do_handle_create(matchn, dentry, mnt);
68851+ write_unlock(&gr_inode_lock);
68852+ }
68853+ preempt_enable();
68854+
68855+ return;
68856+}
68857+
68858+void
68859+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68860+{
68861+ struct name_entry *matchn;
68862+
68863+ if (unlikely(!(gr_status & GR_READY)))
68864+ return;
68865+
68866+ preempt_disable();
68867+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68868+
68869+ if (unlikely((unsigned long)matchn)) {
68870+ write_lock(&gr_inode_lock);
68871+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68872+ write_unlock(&gr_inode_lock);
68873+ }
68874+ preempt_enable();
68875+
68876+ return;
68877+}
68878+
68879+void
68880+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68881+ struct dentry *old_dentry,
68882+ struct dentry *new_dentry,
68883+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
68884+{
68885+ struct name_entry *matchn;
68886+ struct name_entry *matchn2 = NULL;
68887+ struct inodev_entry *inodev;
68888+ struct inode *inode = new_dentry->d_inode;
68889+ ino_t old_ino = old_dentry->d_inode->i_ino;
68890+ dev_t old_dev = __get_dev(old_dentry);
68891+ unsigned int exchange = flags & RENAME_EXCHANGE;
68892+
68893+ /* vfs_rename swaps the name and parent link for old_dentry and
68894+ new_dentry
68895+ at this point, old_dentry has the new name, parent link, and inode
68896+ for the renamed file
68897+ if a file is being replaced by a rename, new_dentry has the inode
68898+ and name for the replaced file
68899+ */
68900+
68901+ if (unlikely(!(gr_status & GR_READY)))
68902+ return;
68903+
68904+ preempt_disable();
68905+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68906+
68907+ /* exchange cases:
68908+ a filename exists for the source, but not dest
68909+ do a recreate on source
68910+ a filename exists for the dest, but not source
68911+ do a recreate on dest
68912+ a filename exists for both source and dest
68913+ delete source and dest, then create source and dest
68914+ a filename exists for neither source nor dest
68915+ no updates needed
68916+
68917+ the name entry lookups get us the old inode/dev associated with
68918+ each name, so do the deletes first (if possible) so that when
68919+ we do the create, we pick up on the right entries
68920+ */
68921+
68922+ if (exchange)
68923+ matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
68924+
68925+ /* we wouldn't have to check d_inode if it weren't for
68926+ NFS silly-renaming
68927+ */
68928+
68929+ write_lock(&gr_inode_lock);
68930+ if (unlikely((replace || exchange) && inode)) {
68931+ ino_t new_ino = inode->i_ino;
68932+ dev_t new_dev = __get_dev(new_dentry);
68933+
68934+ inodev = lookup_inodev_entry(new_ino, new_dev);
68935+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68936+ do_handle_delete(inodev, new_ino, new_dev);
68937+ }
68938+
68939+ inodev = lookup_inodev_entry(old_ino, old_dev);
68940+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68941+ do_handle_delete(inodev, old_ino, old_dev);
68942+
68943+ if (unlikely(matchn != NULL))
68944+ do_handle_create(matchn, old_dentry, mnt);
68945+
68946+ if (unlikely(matchn2 != NULL))
68947+ do_handle_create(matchn2, new_dentry, mnt);
68948+
68949+ write_unlock(&gr_inode_lock);
68950+ preempt_enable();
68951+
68952+ return;
68953+}
68954+
68955+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68956+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68957+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
68958+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
68959+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
68960+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
68961+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
68962+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
68963+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
68964+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
68965+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
68966+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
68967+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
68968+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
68969+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
68970+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
68971+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
68972+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
68973+};
68974+
68975+void
68976+gr_learn_resource(const struct task_struct *task,
68977+ const int res, const unsigned long wanted, const int gt)
68978+{
68979+ struct acl_subject_label *acl;
68980+ const struct cred *cred;
68981+
68982+ if (unlikely((gr_status & GR_READY) &&
68983+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
68984+ goto skip_reslog;
68985+
68986+ gr_log_resource(task, res, wanted, gt);
68987+skip_reslog:
68988+
68989+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
68990+ return;
68991+
68992+ acl = task->acl;
68993+
68994+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
68995+ !(acl->resmask & (1U << (unsigned short) res))))
68996+ return;
68997+
68998+ if (wanted >= acl->res[res].rlim_cur) {
68999+ unsigned long res_add;
69000+
69001+ res_add = wanted + res_learn_bumps[res];
69002+
69003+ acl->res[res].rlim_cur = res_add;
69004+
69005+ if (wanted > acl->res[res].rlim_max)
69006+ acl->res[res].rlim_max = res_add;
69007+
69008+ /* only log the subject filename, since resource logging is supported for
69009+ single-subject learning only */
69010+ rcu_read_lock();
69011+ cred = __task_cred(task);
69012+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69013+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69014+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69015+ "", (unsigned long) res, &task->signal->saved_ip);
69016+ rcu_read_unlock();
69017+ }
69018+
69019+ return;
69020+}
69021+EXPORT_SYMBOL_GPL(gr_learn_resource);
69022+#endif
69023+
69024+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69025+void
69026+pax_set_initial_flags(struct linux_binprm *bprm)
69027+{
69028+ struct task_struct *task = current;
69029+ struct acl_subject_label *proc;
69030+ unsigned long flags;
69031+
69032+ if (unlikely(!(gr_status & GR_READY)))
69033+ return;
69034+
69035+ flags = pax_get_flags(task);
69036+
69037+ proc = task->acl;
69038+
69039+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69040+ flags &= ~MF_PAX_PAGEEXEC;
69041+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69042+ flags &= ~MF_PAX_SEGMEXEC;
69043+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69044+ flags &= ~MF_PAX_RANDMMAP;
69045+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69046+ flags &= ~MF_PAX_EMUTRAMP;
69047+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69048+ flags &= ~MF_PAX_MPROTECT;
69049+
69050+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69051+ flags |= MF_PAX_PAGEEXEC;
69052+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69053+ flags |= MF_PAX_SEGMEXEC;
69054+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69055+ flags |= MF_PAX_RANDMMAP;
69056+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69057+ flags |= MF_PAX_EMUTRAMP;
69058+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69059+ flags |= MF_PAX_MPROTECT;
69060+
69061+ pax_set_flags(task, flags);
69062+
69063+ return;
69064+}
69065+#endif
69066+
69067+int
69068+gr_handle_proc_ptrace(struct task_struct *task)
69069+{
69070+ struct file *filp;
69071+ struct task_struct *tmp = task;
69072+ struct task_struct *curtemp = current;
69073+ __u32 retmode;
69074+
69075+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69076+ if (unlikely(!(gr_status & GR_READY)))
69077+ return 0;
69078+#endif
69079+
69080+ read_lock(&tasklist_lock);
69081+ read_lock(&grsec_exec_file_lock);
69082+ filp = task->exec_file;
69083+
69084+ while (task_pid_nr(tmp) > 0) {
69085+ if (tmp == curtemp)
69086+ break;
69087+ tmp = tmp->real_parent;
69088+ }
69089+
69090+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69091+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69092+ read_unlock(&grsec_exec_file_lock);
69093+ read_unlock(&tasklist_lock);
69094+ return 1;
69095+ }
69096+
69097+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69098+ if (!(gr_status & GR_READY)) {
69099+ read_unlock(&grsec_exec_file_lock);
69100+ read_unlock(&tasklist_lock);
69101+ return 0;
69102+ }
69103+#endif
69104+
69105+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69106+ read_unlock(&grsec_exec_file_lock);
69107+ read_unlock(&tasklist_lock);
69108+
69109+ if (retmode & GR_NOPTRACE)
69110+ return 1;
69111+
69112+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69113+ && (current->acl != task->acl || (current->acl != current->role->root_label
69114+ && task_pid_nr(current) != task_pid_nr(task))))
69115+ return 1;
69116+
69117+ return 0;
69118+}
69119+
69120+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69121+{
69122+ if (unlikely(!(gr_status & GR_READY)))
69123+ return;
69124+
69125+ if (!(current->role->roletype & GR_ROLE_GOD))
69126+ return;
69127+
69128+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69129+ p->role->rolename, gr_task_roletype_to_char(p),
69130+ p->acl->filename);
69131+}
69132+
69133+int
69134+gr_handle_ptrace(struct task_struct *task, const long request)
69135+{
69136+ struct task_struct *tmp = task;
69137+ struct task_struct *curtemp = current;
69138+ __u32 retmode;
69139+
69140+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69141+ if (unlikely(!(gr_status & GR_READY)))
69142+ return 0;
69143+#endif
69144+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69145+ read_lock(&tasklist_lock);
69146+ while (task_pid_nr(tmp) > 0) {
69147+ if (tmp == curtemp)
69148+ break;
69149+ tmp = tmp->real_parent;
69150+ }
69151+
69152+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69153+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69154+ read_unlock(&tasklist_lock);
69155+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69156+ return 1;
69157+ }
69158+ read_unlock(&tasklist_lock);
69159+ }
69160+
69161+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69162+ if (!(gr_status & GR_READY))
69163+ return 0;
69164+#endif
69165+
69166+ read_lock(&grsec_exec_file_lock);
69167+ if (unlikely(!task->exec_file)) {
69168+ read_unlock(&grsec_exec_file_lock);
69169+ return 0;
69170+ }
69171+
69172+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69173+ read_unlock(&grsec_exec_file_lock);
69174+
69175+ if (retmode & GR_NOPTRACE) {
69176+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69177+ return 1;
69178+ }
69179+
69180+ if (retmode & GR_PTRACERD) {
69181+ switch (request) {
69182+ case PTRACE_SEIZE:
69183+ case PTRACE_POKETEXT:
69184+ case PTRACE_POKEDATA:
69185+ case PTRACE_POKEUSR:
69186+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69187+ case PTRACE_SETREGS:
69188+ case PTRACE_SETFPREGS:
69189+#endif
69190+#ifdef CONFIG_X86
69191+ case PTRACE_SETFPXREGS:
69192+#endif
69193+#ifdef CONFIG_ALTIVEC
69194+ case PTRACE_SETVRREGS:
69195+#endif
69196+ return 1;
69197+ default:
69198+ return 0;
69199+ }
69200+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
69201+ !(current->role->roletype & GR_ROLE_GOD) &&
69202+ (current->acl != task->acl)) {
69203+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69204+ return 1;
69205+ }
69206+
69207+ return 0;
69208+}
69209+
69210+static int is_writable_mmap(const struct file *filp)
69211+{
69212+ struct task_struct *task = current;
69213+ struct acl_object_label *obj, *obj2;
69214+
69215+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69216+ !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))) {
69217+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69218+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69219+ task->role->root_label);
69220+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69221+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69222+ return 1;
69223+ }
69224+ }
69225+ return 0;
69226+}
69227+
69228+int
69229+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69230+{
69231+ __u32 mode;
69232+
69233+ if (unlikely(!file || !(prot & PROT_EXEC)))
69234+ return 1;
69235+
69236+ if (is_writable_mmap(file))
69237+ return 0;
69238+
69239+ mode =
69240+ gr_search_file(file->f_path.dentry,
69241+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69242+ file->f_path.mnt);
69243+
69244+ if (!gr_tpe_allow(file))
69245+ return 0;
69246+
69247+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69248+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69249+ return 0;
69250+ } else if (unlikely(!(mode & GR_EXEC))) {
69251+ return 0;
69252+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69253+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69254+ return 1;
69255+ }
69256+
69257+ return 1;
69258+}
69259+
69260+int
69261+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69262+{
69263+ __u32 mode;
69264+
69265+ if (unlikely(!file || !(prot & PROT_EXEC)))
69266+ return 1;
69267+
69268+ if (is_writable_mmap(file))
69269+ return 0;
69270+
69271+ mode =
69272+ gr_search_file(file->f_path.dentry,
69273+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69274+ file->f_path.mnt);
69275+
69276+ if (!gr_tpe_allow(file))
69277+ return 0;
69278+
69279+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69280+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69281+ return 0;
69282+ } else if (unlikely(!(mode & GR_EXEC))) {
69283+ return 0;
69284+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69285+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69286+ return 1;
69287+ }
69288+
69289+ return 1;
69290+}
69291+
69292+void
69293+gr_acl_handle_psacct(struct task_struct *task, const long code)
69294+{
69295+ unsigned long runtime, cputime;
69296+ cputime_t utime, stime;
69297+ unsigned int wday, cday;
69298+ __u8 whr, chr;
69299+ __u8 wmin, cmin;
69300+ __u8 wsec, csec;
69301+ struct timespec timeval;
69302+
69303+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69304+ !(task->acl->mode & GR_PROCACCT)))
69305+ return;
69306+
69307+ do_posix_clock_monotonic_gettime(&timeval);
69308+ runtime = timeval.tv_sec - task->start_time.tv_sec;
69309+ wday = runtime / (60 * 60 * 24);
69310+ runtime -= wday * (60 * 60 * 24);
69311+ whr = runtime / (60 * 60);
69312+ runtime -= whr * (60 * 60);
69313+ wmin = runtime / 60;
69314+ runtime -= wmin * 60;
69315+ wsec = runtime;
69316+
69317+ task_cputime(task, &utime, &stime);
69318+ cputime = cputime_to_secs(utime + stime);
69319+ cday = cputime / (60 * 60 * 24);
69320+ cputime -= cday * (60 * 60 * 24);
69321+ chr = cputime / (60 * 60);
69322+ cputime -= chr * (60 * 60);
69323+ cmin = cputime / 60;
69324+ cputime -= cmin * 60;
69325+ csec = cputime;
69326+
69327+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69328+
69329+ return;
69330+}
69331+
69332+#ifdef CONFIG_TASKSTATS
69333+int gr_is_taskstats_denied(int pid)
69334+{
69335+ struct task_struct *task;
69336+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69337+ const struct cred *cred;
69338+#endif
69339+ int ret = 0;
69340+
69341+ /* restrict taskstats viewing to un-chrooted root users
69342+ who have the 'view' subject flag if the RBAC system is enabled
69343+ */
69344+
69345+ rcu_read_lock();
69346+ read_lock(&tasklist_lock);
69347+ task = find_task_by_vpid(pid);
69348+ if (task) {
69349+#ifdef CONFIG_GRKERNSEC_CHROOT
69350+ if (proc_is_chrooted(task))
69351+ ret = -EACCES;
69352+#endif
69353+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69354+ cred = __task_cred(task);
69355+#ifdef CONFIG_GRKERNSEC_PROC_USER
69356+ if (gr_is_global_nonroot(cred->uid))
69357+ ret = -EACCES;
69358+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69359+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69360+ ret = -EACCES;
69361+#endif
69362+#endif
69363+ if (gr_status & GR_READY) {
69364+ if (!(task->acl->mode & GR_VIEW))
69365+ ret = -EACCES;
69366+ }
69367+ } else
69368+ ret = -ENOENT;
69369+
69370+ read_unlock(&tasklist_lock);
69371+ rcu_read_unlock();
69372+
69373+ return ret;
69374+}
69375+#endif
69376+
69377+/* AUXV entries are filled via a descendant of search_binary_handler
69378+ after we've already applied the subject for the target
69379+*/
69380+int gr_acl_enable_at_secure(void)
69381+{
69382+ if (unlikely(!(gr_status & GR_READY)))
69383+ return 0;
69384+
69385+ if (current->acl->mode & GR_ATSECURE)
69386+ return 1;
69387+
69388+ return 0;
69389+}
69390+
69391+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69392+{
69393+ struct task_struct *task = current;
69394+ struct dentry *dentry = file->f_path.dentry;
69395+ struct vfsmount *mnt = file->f_path.mnt;
69396+ struct acl_object_label *obj, *tmp;
69397+ struct acl_subject_label *subj;
69398+ unsigned int bufsize;
69399+ int is_not_root;
69400+ char *path;
69401+ dev_t dev = __get_dev(dentry);
69402+
69403+ if (unlikely(!(gr_status & GR_READY)))
69404+ return 1;
69405+
69406+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69407+ return 1;
69408+
69409+ /* ignore Eric Biederman */
69410+ if (IS_PRIVATE(dentry->d_inode))
69411+ return 1;
69412+
69413+ subj = task->acl;
69414+ read_lock(&gr_inode_lock);
69415+ do {
69416+ obj = lookup_acl_obj_label(ino, dev, subj);
69417+ if (obj != NULL) {
69418+ read_unlock(&gr_inode_lock);
69419+ return (obj->mode & GR_FIND) ? 1 : 0;
69420+ }
69421+ } while ((subj = subj->parent_subject));
69422+ read_unlock(&gr_inode_lock);
69423+
69424+ /* this is purely an optimization since we're looking for an object
69425+ for the directory we're doing a readdir on
69426+ if it's possible for any globbed object to match the entry we're
69427+ filling into the directory, then the object we find here will be
69428+ an anchor point with attached globbed objects
69429+ */
69430+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69431+ if (obj->globbed == NULL)
69432+ return (obj->mode & GR_FIND) ? 1 : 0;
69433+
69434+ is_not_root = ((obj->filename[0] == '/') &&
69435+ (obj->filename[1] == '\0')) ? 0 : 1;
69436+ bufsize = PAGE_SIZE - namelen - is_not_root;
69437+
69438+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
69439+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69440+ return 1;
69441+
69442+ preempt_disable();
69443+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69444+ bufsize);
69445+
69446+ bufsize = strlen(path);
69447+
69448+ /* if base is "/", don't append an additional slash */
69449+ if (is_not_root)
69450+ *(path + bufsize) = '/';
69451+ memcpy(path + bufsize + is_not_root, name, namelen);
69452+ *(path + bufsize + namelen + is_not_root) = '\0';
69453+
69454+ tmp = obj->globbed;
69455+ while (tmp) {
69456+ if (!glob_match(tmp->filename, path)) {
69457+ preempt_enable();
69458+ return (tmp->mode & GR_FIND) ? 1 : 0;
69459+ }
69460+ tmp = tmp->next;
69461+ }
69462+ preempt_enable();
69463+ return (obj->mode & GR_FIND) ? 1 : 0;
69464+}
69465+
69466+void gr_put_exec_file(struct task_struct *task)
69467+{
69468+ struct file *filp;
69469+
69470+ write_lock(&grsec_exec_file_lock);
69471+ filp = task->exec_file;
69472+ task->exec_file = NULL;
69473+ write_unlock(&grsec_exec_file_lock);
69474+
69475+ if (filp)
69476+ fput(filp);
69477+
69478+ return;
69479+}
69480+
69481+
69482+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69483+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69484+#endif
69485+#ifdef CONFIG_SECURITY
69486+EXPORT_SYMBOL_GPL(gr_check_user_change);
69487+EXPORT_SYMBOL_GPL(gr_check_group_change);
69488+#endif
69489+
69490diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69491new file mode 100644
69492index 0000000..18ffbbd
69493--- /dev/null
69494+++ b/grsecurity/gracl_alloc.c
69495@@ -0,0 +1,105 @@
69496+#include <linux/kernel.h>
69497+#include <linux/mm.h>
69498+#include <linux/slab.h>
69499+#include <linux/vmalloc.h>
69500+#include <linux/gracl.h>
69501+#include <linux/grsecurity.h>
69502+
69503+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69504+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69505+
69506+static __inline__ int
69507+alloc_pop(void)
69508+{
69509+ if (current_alloc_state->alloc_stack_next == 1)
69510+ return 0;
69511+
69512+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69513+
69514+ current_alloc_state->alloc_stack_next--;
69515+
69516+ return 1;
69517+}
69518+
69519+static __inline__ int
69520+alloc_push(void *buf)
69521+{
69522+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69523+ return 1;
69524+
69525+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69526+
69527+ current_alloc_state->alloc_stack_next++;
69528+
69529+ return 0;
69530+}
69531+
69532+void *
69533+acl_alloc(unsigned long len)
69534+{
69535+ void *ret = NULL;
69536+
69537+ if (!len || len > PAGE_SIZE)
69538+ goto out;
69539+
69540+ ret = kmalloc(len, GFP_KERNEL);
69541+
69542+ if (ret) {
69543+ if (alloc_push(ret)) {
69544+ kfree(ret);
69545+ ret = NULL;
69546+ }
69547+ }
69548+
69549+out:
69550+ return ret;
69551+}
69552+
69553+void *
69554+acl_alloc_num(unsigned long num, unsigned long len)
69555+{
69556+ if (!len || (num > (PAGE_SIZE / len)))
69557+ return NULL;
69558+
69559+ return acl_alloc(num * len);
69560+}
69561+
69562+void
69563+acl_free_all(void)
69564+{
69565+ if (!current_alloc_state->alloc_stack)
69566+ return;
69567+
69568+ while (alloc_pop()) ;
69569+
69570+ if (current_alloc_state->alloc_stack) {
69571+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69572+ kfree(current_alloc_state->alloc_stack);
69573+ else
69574+ vfree(current_alloc_state->alloc_stack);
69575+ }
69576+
69577+ current_alloc_state->alloc_stack = NULL;
69578+ current_alloc_state->alloc_stack_size = 1;
69579+ current_alloc_state->alloc_stack_next = 1;
69580+
69581+ return;
69582+}
69583+
69584+int
69585+acl_alloc_stack_init(unsigned long size)
69586+{
69587+ if ((size * sizeof (void *)) <= PAGE_SIZE)
69588+ current_alloc_state->alloc_stack =
69589+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69590+ else
69591+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69592+
69593+ current_alloc_state->alloc_stack_size = size;
69594+ current_alloc_state->alloc_stack_next = 1;
69595+
69596+ if (!current_alloc_state->alloc_stack)
69597+ return 0;
69598+ else
69599+ return 1;
69600+}
69601diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69602new file mode 100644
69603index 0000000..bdd51ea
69604--- /dev/null
69605+++ b/grsecurity/gracl_cap.c
69606@@ -0,0 +1,110 @@
69607+#include <linux/kernel.h>
69608+#include <linux/module.h>
69609+#include <linux/sched.h>
69610+#include <linux/gracl.h>
69611+#include <linux/grsecurity.h>
69612+#include <linux/grinternal.h>
69613+
69614+extern const char *captab_log[];
69615+extern int captab_log_entries;
69616+
69617+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69618+{
69619+ struct acl_subject_label *curracl;
69620+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69621+ kernel_cap_t cap_audit = __cap_empty_set;
69622+
69623+ if (!gr_acl_is_enabled())
69624+ return 1;
69625+
69626+ curracl = task->acl;
69627+
69628+ cap_drop = curracl->cap_lower;
69629+ cap_mask = curracl->cap_mask;
69630+ cap_audit = curracl->cap_invert_audit;
69631+
69632+ while ((curracl = curracl->parent_subject)) {
69633+ /* if the cap isn't specified in the current computed mask but is specified in the
69634+ current level subject, and is lowered in the current level subject, then add
69635+ it to the set of dropped capabilities
69636+ otherwise, add the current level subject's mask to the current computed mask
69637+ */
69638+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69639+ cap_raise(cap_mask, cap);
69640+ if (cap_raised(curracl->cap_lower, cap))
69641+ cap_raise(cap_drop, cap);
69642+ if (cap_raised(curracl->cap_invert_audit, cap))
69643+ cap_raise(cap_audit, cap);
69644+ }
69645+ }
69646+
69647+ if (!cap_raised(cap_drop, cap)) {
69648+ if (cap_raised(cap_audit, cap))
69649+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69650+ return 1;
69651+ }
69652+
69653+ curracl = task->acl;
69654+
69655+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69656+ && cap_raised(cred->cap_effective, cap)) {
69657+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69658+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
69659+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
69660+ gr_to_filename(task->exec_file->f_path.dentry,
69661+ task->exec_file->f_path.mnt) : curracl->filename,
69662+ curracl->filename, 0UL,
69663+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69664+ return 1;
69665+ }
69666+
69667+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69668+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69669+
69670+ return 0;
69671+}
69672+
69673+int
69674+gr_acl_is_capable(const int cap)
69675+{
69676+ return gr_task_acl_is_capable(current, current_cred(), cap);
69677+}
69678+
69679+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69680+{
69681+ struct acl_subject_label *curracl;
69682+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69683+
69684+ if (!gr_acl_is_enabled())
69685+ return 1;
69686+
69687+ curracl = task->acl;
69688+
69689+ cap_drop = curracl->cap_lower;
69690+ cap_mask = curracl->cap_mask;
69691+
69692+ while ((curracl = curracl->parent_subject)) {
69693+ /* if the cap isn't specified in the current computed mask but is specified in the
69694+ current level subject, and is lowered in the current level subject, then add
69695+ it to the set of dropped capabilities
69696+ otherwise, add the current level subject's mask to the current computed mask
69697+ */
69698+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69699+ cap_raise(cap_mask, cap);
69700+ if (cap_raised(curracl->cap_lower, cap))
69701+ cap_raise(cap_drop, cap);
69702+ }
69703+ }
69704+
69705+ if (!cap_raised(cap_drop, cap))
69706+ return 1;
69707+
69708+ return 0;
69709+}
69710+
69711+int
69712+gr_acl_is_capable_nolog(const int cap)
69713+{
69714+ return gr_task_acl_is_capable_nolog(current, cap);
69715+}
69716+
69717diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69718new file mode 100644
69719index 0000000..ca25605
69720--- /dev/null
69721+++ b/grsecurity/gracl_compat.c
69722@@ -0,0 +1,270 @@
69723+#include <linux/kernel.h>
69724+#include <linux/gracl.h>
69725+#include <linux/compat.h>
69726+#include <linux/gracl_compat.h>
69727+
69728+#include <asm/uaccess.h>
69729+
69730+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69731+{
69732+ struct gr_arg_wrapper_compat uwrapcompat;
69733+
69734+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69735+ return -EFAULT;
69736+
69737+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69738+ (uwrapcompat.version != 0x2901)) ||
69739+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69740+ return -EINVAL;
69741+
69742+ uwrap->arg = compat_ptr(uwrapcompat.arg);
69743+ uwrap->version = uwrapcompat.version;
69744+ uwrap->size = sizeof(struct gr_arg);
69745+
69746+ return 0;
69747+}
69748+
69749+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69750+{
69751+ struct gr_arg_compat argcompat;
69752+
69753+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69754+ return -EFAULT;
69755+
69756+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69757+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69758+ arg->role_db.num_roles = argcompat.role_db.num_roles;
69759+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69760+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69761+ arg->role_db.num_objects = argcompat.role_db.num_objects;
69762+
69763+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69764+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69765+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69766+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69767+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69768+ arg->segv_device = argcompat.segv_device;
69769+ arg->segv_inode = argcompat.segv_inode;
69770+ arg->segv_uid = argcompat.segv_uid;
69771+ arg->num_sprole_pws = argcompat.num_sprole_pws;
69772+ arg->mode = argcompat.mode;
69773+
69774+ return 0;
69775+}
69776+
69777+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69778+{
69779+ struct acl_object_label_compat objcompat;
69780+
69781+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69782+ return -EFAULT;
69783+
69784+ obj->filename = compat_ptr(objcompat.filename);
69785+ obj->inode = objcompat.inode;
69786+ obj->device = objcompat.device;
69787+ obj->mode = objcompat.mode;
69788+
69789+ obj->nested = compat_ptr(objcompat.nested);
69790+ obj->globbed = compat_ptr(objcompat.globbed);
69791+
69792+ obj->prev = compat_ptr(objcompat.prev);
69793+ obj->next = compat_ptr(objcompat.next);
69794+
69795+ return 0;
69796+}
69797+
69798+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69799+{
69800+ unsigned int i;
69801+ struct acl_subject_label_compat subjcompat;
69802+
69803+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69804+ return -EFAULT;
69805+
69806+ subj->filename = compat_ptr(subjcompat.filename);
69807+ subj->inode = subjcompat.inode;
69808+ subj->device = subjcompat.device;
69809+ subj->mode = subjcompat.mode;
69810+ subj->cap_mask = subjcompat.cap_mask;
69811+ subj->cap_lower = subjcompat.cap_lower;
69812+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
69813+
69814+ for (i = 0; i < GR_NLIMITS; i++) {
69815+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69816+ subj->res[i].rlim_cur = RLIM_INFINITY;
69817+ else
69818+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69819+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69820+ subj->res[i].rlim_max = RLIM_INFINITY;
69821+ else
69822+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69823+ }
69824+ subj->resmask = subjcompat.resmask;
69825+
69826+ subj->user_trans_type = subjcompat.user_trans_type;
69827+ subj->group_trans_type = subjcompat.group_trans_type;
69828+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69829+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69830+ subj->user_trans_num = subjcompat.user_trans_num;
69831+ subj->group_trans_num = subjcompat.group_trans_num;
69832+
69833+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69834+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69835+ subj->ip_type = subjcompat.ip_type;
69836+ subj->ips = compat_ptr(subjcompat.ips);
69837+ subj->ip_num = subjcompat.ip_num;
69838+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
69839+
69840+ subj->crashes = subjcompat.crashes;
69841+ subj->expires = subjcompat.expires;
69842+
69843+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69844+ subj->hash = compat_ptr(subjcompat.hash);
69845+ subj->prev = compat_ptr(subjcompat.prev);
69846+ subj->next = compat_ptr(subjcompat.next);
69847+
69848+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69849+ subj->obj_hash_size = subjcompat.obj_hash_size;
69850+ subj->pax_flags = subjcompat.pax_flags;
69851+
69852+ return 0;
69853+}
69854+
69855+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69856+{
69857+ struct acl_role_label_compat rolecompat;
69858+
69859+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69860+ return -EFAULT;
69861+
69862+ role->rolename = compat_ptr(rolecompat.rolename);
69863+ role->uidgid = rolecompat.uidgid;
69864+ role->roletype = rolecompat.roletype;
69865+
69866+ role->auth_attempts = rolecompat.auth_attempts;
69867+ role->expires = rolecompat.expires;
69868+
69869+ role->root_label = compat_ptr(rolecompat.root_label);
69870+ role->hash = compat_ptr(rolecompat.hash);
69871+
69872+ role->prev = compat_ptr(rolecompat.prev);
69873+ role->next = compat_ptr(rolecompat.next);
69874+
69875+ role->transitions = compat_ptr(rolecompat.transitions);
69876+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69877+ role->domain_children = compat_ptr(rolecompat.domain_children);
69878+ role->domain_child_num = rolecompat.domain_child_num;
69879+
69880+ role->umask = rolecompat.umask;
69881+
69882+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
69883+ role->subj_hash_size = rolecompat.subj_hash_size;
69884+
69885+ return 0;
69886+}
69887+
69888+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69889+{
69890+ struct role_allowed_ip_compat roleip_compat;
69891+
69892+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69893+ return -EFAULT;
69894+
69895+ roleip->addr = roleip_compat.addr;
69896+ roleip->netmask = roleip_compat.netmask;
69897+
69898+ roleip->prev = compat_ptr(roleip_compat.prev);
69899+ roleip->next = compat_ptr(roleip_compat.next);
69900+
69901+ return 0;
69902+}
69903+
69904+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69905+{
69906+ struct role_transition_compat trans_compat;
69907+
69908+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69909+ return -EFAULT;
69910+
69911+ trans->rolename = compat_ptr(trans_compat.rolename);
69912+
69913+ trans->prev = compat_ptr(trans_compat.prev);
69914+ trans->next = compat_ptr(trans_compat.next);
69915+
69916+ return 0;
69917+
69918+}
69919+
69920+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69921+{
69922+ struct gr_hash_struct_compat hash_compat;
69923+
69924+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69925+ return -EFAULT;
69926+
69927+ hash->table = compat_ptr(hash_compat.table);
69928+ hash->nametable = compat_ptr(hash_compat.nametable);
69929+ hash->first = compat_ptr(hash_compat.first);
69930+
69931+ hash->table_size = hash_compat.table_size;
69932+ hash->used_size = hash_compat.used_size;
69933+
69934+ hash->type = hash_compat.type;
69935+
69936+ return 0;
69937+}
69938+
69939+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69940+{
69941+ compat_uptr_t ptrcompat;
69942+
69943+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69944+ return -EFAULT;
69945+
69946+ *(void **)ptr = compat_ptr(ptrcompat);
69947+
69948+ return 0;
69949+}
69950+
69951+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69952+{
69953+ struct acl_ip_label_compat ip_compat;
69954+
69955+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69956+ return -EFAULT;
69957+
69958+ ip->iface = compat_ptr(ip_compat.iface);
69959+ ip->addr = ip_compat.addr;
69960+ ip->netmask = ip_compat.netmask;
69961+ ip->low = ip_compat.low;
69962+ ip->high = ip_compat.high;
69963+ ip->mode = ip_compat.mode;
69964+ ip->type = ip_compat.type;
69965+
69966+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
69967+
69968+ ip->prev = compat_ptr(ip_compat.prev);
69969+ ip->next = compat_ptr(ip_compat.next);
69970+
69971+ return 0;
69972+}
69973+
69974+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69975+{
69976+ struct sprole_pw_compat pw_compat;
69977+
69978+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
69979+ return -EFAULT;
69980+
69981+ pw->rolename = compat_ptr(pw_compat.rolename);
69982+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
69983+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
69984+
69985+ return 0;
69986+}
69987+
69988+size_t get_gr_arg_wrapper_size_compat(void)
69989+{
69990+ return sizeof(struct gr_arg_wrapper_compat);
69991+}
69992+
69993diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
69994new file mode 100644
69995index 0000000..4008fdc
69996--- /dev/null
69997+++ b/grsecurity/gracl_fs.c
69998@@ -0,0 +1,445 @@
69999+#include <linux/kernel.h>
70000+#include <linux/sched.h>
70001+#include <linux/types.h>
70002+#include <linux/fs.h>
70003+#include <linux/file.h>
70004+#include <linux/stat.h>
70005+#include <linux/grsecurity.h>
70006+#include <linux/grinternal.h>
70007+#include <linux/gracl.h>
70008+
70009+umode_t
70010+gr_acl_umask(void)
70011+{
70012+ if (unlikely(!gr_acl_is_enabled()))
70013+ return 0;
70014+
70015+ return current->role->umask;
70016+}
70017+
70018+__u32
70019+gr_acl_handle_hidden_file(const struct dentry * dentry,
70020+ const struct vfsmount * mnt)
70021+{
70022+ __u32 mode;
70023+
70024+ if (unlikely(d_is_negative(dentry)))
70025+ return GR_FIND;
70026+
70027+ mode =
70028+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70029+
70030+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70031+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70032+ return mode;
70033+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70034+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70035+ return 0;
70036+ } else if (unlikely(!(mode & GR_FIND)))
70037+ return 0;
70038+
70039+ return GR_FIND;
70040+}
70041+
70042+__u32
70043+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70044+ int acc_mode)
70045+{
70046+ __u32 reqmode = GR_FIND;
70047+ __u32 mode;
70048+
70049+ if (unlikely(d_is_negative(dentry)))
70050+ return reqmode;
70051+
70052+ if (acc_mode & MAY_APPEND)
70053+ reqmode |= GR_APPEND;
70054+ else if (acc_mode & MAY_WRITE)
70055+ reqmode |= GR_WRITE;
70056+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70057+ reqmode |= GR_READ;
70058+
70059+ mode =
70060+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70061+ mnt);
70062+
70063+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70064+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70065+ reqmode & GR_READ ? " reading" : "",
70066+ reqmode & GR_WRITE ? " writing" : reqmode &
70067+ GR_APPEND ? " appending" : "");
70068+ return reqmode;
70069+ } else
70070+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70071+ {
70072+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70073+ reqmode & GR_READ ? " reading" : "",
70074+ reqmode & GR_WRITE ? " writing" : reqmode &
70075+ GR_APPEND ? " appending" : "");
70076+ return 0;
70077+ } else if (unlikely((mode & reqmode) != reqmode))
70078+ return 0;
70079+
70080+ return reqmode;
70081+}
70082+
70083+__u32
70084+gr_acl_handle_creat(const struct dentry * dentry,
70085+ const struct dentry * p_dentry,
70086+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70087+ const int imode)
70088+{
70089+ __u32 reqmode = GR_WRITE | GR_CREATE;
70090+ __u32 mode;
70091+
70092+ if (acc_mode & MAY_APPEND)
70093+ reqmode |= GR_APPEND;
70094+ // if a directory was required or the directory already exists, then
70095+ // don't count this open as a read
70096+ if ((acc_mode & MAY_READ) &&
70097+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70098+ reqmode |= GR_READ;
70099+ if ((open_flags & O_CREAT) &&
70100+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70101+ reqmode |= GR_SETID;
70102+
70103+ mode =
70104+ gr_check_create(dentry, p_dentry, p_mnt,
70105+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70106+
70107+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70108+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70109+ reqmode & GR_READ ? " reading" : "",
70110+ reqmode & GR_WRITE ? " writing" : reqmode &
70111+ GR_APPEND ? " appending" : "");
70112+ return reqmode;
70113+ } else
70114+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70115+ {
70116+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70117+ reqmode & GR_READ ? " reading" : "",
70118+ reqmode & GR_WRITE ? " writing" : reqmode &
70119+ GR_APPEND ? " appending" : "");
70120+ return 0;
70121+ } else if (unlikely((mode & reqmode) != reqmode))
70122+ return 0;
70123+
70124+ return reqmode;
70125+}
70126+
70127+__u32
70128+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70129+ const int fmode)
70130+{
70131+ __u32 mode, reqmode = GR_FIND;
70132+
70133+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70134+ reqmode |= GR_EXEC;
70135+ if (fmode & S_IWOTH)
70136+ reqmode |= GR_WRITE;
70137+ if (fmode & S_IROTH)
70138+ reqmode |= GR_READ;
70139+
70140+ mode =
70141+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70142+ mnt);
70143+
70144+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70145+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70146+ reqmode & GR_READ ? " reading" : "",
70147+ reqmode & GR_WRITE ? " writing" : "",
70148+ reqmode & GR_EXEC ? " executing" : "");
70149+ return reqmode;
70150+ } else
70151+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70152+ {
70153+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70154+ reqmode & GR_READ ? " reading" : "",
70155+ reqmode & GR_WRITE ? " writing" : "",
70156+ reqmode & GR_EXEC ? " executing" : "");
70157+ return 0;
70158+ } else if (unlikely((mode & reqmode) != reqmode))
70159+ return 0;
70160+
70161+ return reqmode;
70162+}
70163+
70164+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70165+{
70166+ __u32 mode;
70167+
70168+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70169+
70170+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70171+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70172+ return mode;
70173+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70174+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70175+ return 0;
70176+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70177+ return 0;
70178+
70179+ return (reqmode);
70180+}
70181+
70182+__u32
70183+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70184+{
70185+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70186+}
70187+
70188+__u32
70189+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70190+{
70191+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70192+}
70193+
70194+__u32
70195+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70196+{
70197+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70198+}
70199+
70200+__u32
70201+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70202+{
70203+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70204+}
70205+
70206+__u32
70207+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70208+ umode_t *modeptr)
70209+{
70210+ umode_t mode;
70211+
70212+ *modeptr &= ~gr_acl_umask();
70213+ mode = *modeptr;
70214+
70215+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70216+ return 1;
70217+
70218+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70219+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70220+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70221+ GR_CHMOD_ACL_MSG);
70222+ } else {
70223+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70224+ }
70225+}
70226+
70227+__u32
70228+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70229+{
70230+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70231+}
70232+
70233+__u32
70234+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70235+{
70236+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70237+}
70238+
70239+__u32
70240+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70241+{
70242+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70243+}
70244+
70245+__u32
70246+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70247+{
70248+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70249+}
70250+
70251+__u32
70252+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70253+{
70254+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70255+ GR_UNIXCONNECT_ACL_MSG);
70256+}
70257+
70258+/* hardlinks require at minimum create and link permission,
70259+ any additional privilege required is based on the
70260+ privilege of the file being linked to
70261+*/
70262+__u32
70263+gr_acl_handle_link(const struct dentry * new_dentry,
70264+ const struct dentry * parent_dentry,
70265+ const struct vfsmount * parent_mnt,
70266+ const struct dentry * old_dentry,
70267+ const struct vfsmount * old_mnt, const struct filename *to)
70268+{
70269+ __u32 mode;
70270+ __u32 needmode = GR_CREATE | GR_LINK;
70271+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70272+
70273+ mode =
70274+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70275+ old_mnt);
70276+
70277+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70278+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70279+ return mode;
70280+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70281+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70282+ return 0;
70283+ } else if (unlikely((mode & needmode) != needmode))
70284+ return 0;
70285+
70286+ return 1;
70287+}
70288+
70289+__u32
70290+gr_acl_handle_symlink(const struct dentry * new_dentry,
70291+ const struct dentry * parent_dentry,
70292+ const struct vfsmount * parent_mnt, const struct filename *from)
70293+{
70294+ __u32 needmode = GR_WRITE | GR_CREATE;
70295+ __u32 mode;
70296+
70297+ mode =
70298+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
70299+ GR_CREATE | GR_AUDIT_CREATE |
70300+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70301+
70302+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70303+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70304+ return mode;
70305+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70306+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70307+ return 0;
70308+ } else if (unlikely((mode & needmode) != needmode))
70309+ return 0;
70310+
70311+ return (GR_WRITE | GR_CREATE);
70312+}
70313+
70314+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)
70315+{
70316+ __u32 mode;
70317+
70318+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70319+
70320+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70321+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70322+ return mode;
70323+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70324+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70325+ return 0;
70326+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
70327+ return 0;
70328+
70329+ return (reqmode);
70330+}
70331+
70332+__u32
70333+gr_acl_handle_mknod(const struct dentry * new_dentry,
70334+ const struct dentry * parent_dentry,
70335+ const struct vfsmount * parent_mnt,
70336+ const int mode)
70337+{
70338+ __u32 reqmode = GR_WRITE | GR_CREATE;
70339+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70340+ reqmode |= GR_SETID;
70341+
70342+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70343+ reqmode, GR_MKNOD_ACL_MSG);
70344+}
70345+
70346+__u32
70347+gr_acl_handle_mkdir(const struct dentry *new_dentry,
70348+ const struct dentry *parent_dentry,
70349+ const struct vfsmount *parent_mnt)
70350+{
70351+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70352+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70353+}
70354+
70355+#define RENAME_CHECK_SUCCESS(old, new) \
70356+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70357+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70358+
70359+int
70360+gr_acl_handle_rename(struct dentry *new_dentry,
70361+ struct dentry *parent_dentry,
70362+ const struct vfsmount *parent_mnt,
70363+ struct dentry *old_dentry,
70364+ struct inode *old_parent_inode,
70365+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
70366+{
70367+ __u32 comp1, comp2;
70368+ int error = 0;
70369+
70370+ if (unlikely(!gr_acl_is_enabled()))
70371+ return 0;
70372+
70373+ if (flags & RENAME_EXCHANGE) {
70374+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70375+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70376+ GR_SUPPRESS, parent_mnt);
70377+ comp2 =
70378+ gr_search_file(old_dentry,
70379+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70380+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70381+ } else if (d_is_negative(new_dentry)) {
70382+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70383+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70384+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70385+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70386+ GR_DELETE | GR_AUDIT_DELETE |
70387+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70388+ GR_SUPPRESS, old_mnt);
70389+ } else {
70390+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70391+ GR_CREATE | GR_DELETE |
70392+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70393+ GR_AUDIT_READ | GR_AUDIT_WRITE |
70394+ GR_SUPPRESS, parent_mnt);
70395+ comp2 =
70396+ gr_search_file(old_dentry,
70397+ GR_READ | GR_WRITE | GR_AUDIT_READ |
70398+ GR_DELETE | GR_AUDIT_DELETE |
70399+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70400+ }
70401+
70402+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70403+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70404+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70405+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70406+ && !(comp2 & GR_SUPPRESS)) {
70407+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70408+ error = -EACCES;
70409+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70410+ error = -EACCES;
70411+
70412+ return error;
70413+}
70414+
70415+void
70416+gr_acl_handle_exit(void)
70417+{
70418+ u16 id;
70419+ char *rolename;
70420+
70421+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70422+ !(current->role->roletype & GR_ROLE_PERSIST))) {
70423+ id = current->acl_role_id;
70424+ rolename = current->role->rolename;
70425+ gr_set_acls(1);
70426+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70427+ }
70428+
70429+ gr_put_exec_file(current);
70430+ return;
70431+}
70432+
70433+int
70434+gr_acl_handle_procpidmem(const struct task_struct *task)
70435+{
70436+ if (unlikely(!gr_acl_is_enabled()))
70437+ return 0;
70438+
70439+ if (task != current && task->acl->mode & GR_PROTPROCFD)
70440+ return -EACCES;
70441+
70442+ return 0;
70443+}
70444diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70445new file mode 100644
70446index 0000000..f056b81
70447--- /dev/null
70448+++ b/grsecurity/gracl_ip.c
70449@@ -0,0 +1,386 @@
70450+#include <linux/kernel.h>
70451+#include <asm/uaccess.h>
70452+#include <asm/errno.h>
70453+#include <net/sock.h>
70454+#include <linux/file.h>
70455+#include <linux/fs.h>
70456+#include <linux/net.h>
70457+#include <linux/in.h>
70458+#include <linux/skbuff.h>
70459+#include <linux/ip.h>
70460+#include <linux/udp.h>
70461+#include <linux/types.h>
70462+#include <linux/sched.h>
70463+#include <linux/netdevice.h>
70464+#include <linux/inetdevice.h>
70465+#include <linux/gracl.h>
70466+#include <linux/grsecurity.h>
70467+#include <linux/grinternal.h>
70468+
70469+#define GR_BIND 0x01
70470+#define GR_CONNECT 0x02
70471+#define GR_INVERT 0x04
70472+#define GR_BINDOVERRIDE 0x08
70473+#define GR_CONNECTOVERRIDE 0x10
70474+#define GR_SOCK_FAMILY 0x20
70475+
70476+static const char * gr_protocols[IPPROTO_MAX] = {
70477+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70478+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70479+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70480+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70481+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70482+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70483+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70484+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70485+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70486+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70487+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70488+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70489+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70490+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70491+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70492+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70493+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70494+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70495+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70496+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70497+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70498+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70499+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70500+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70501+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70502+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70503+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70504+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70505+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70506+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70507+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70508+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70509+ };
70510+
70511+static const char * gr_socktypes[SOCK_MAX] = {
70512+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70513+ "unknown:7", "unknown:8", "unknown:9", "packet"
70514+ };
70515+
70516+static const char * gr_sockfamilies[AF_MAX+1] = {
70517+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70518+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70519+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70520+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70521+ };
70522+
70523+const char *
70524+gr_proto_to_name(unsigned char proto)
70525+{
70526+ return gr_protocols[proto];
70527+}
70528+
70529+const char *
70530+gr_socktype_to_name(unsigned char type)
70531+{
70532+ return gr_socktypes[type];
70533+}
70534+
70535+const char *
70536+gr_sockfamily_to_name(unsigned char family)
70537+{
70538+ return gr_sockfamilies[family];
70539+}
70540+
70541+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70542+
70543+int
70544+gr_search_socket(const int domain, const int type, const int protocol)
70545+{
70546+ struct acl_subject_label *curr;
70547+ const struct cred *cred = current_cred();
70548+
70549+ if (unlikely(!gr_acl_is_enabled()))
70550+ goto exit;
70551+
70552+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
70553+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70554+ goto exit; // let the kernel handle it
70555+
70556+ curr = current->acl;
70557+
70558+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70559+ /* the family is allowed, if this is PF_INET allow it only if
70560+ the extra sock type/protocol checks pass */
70561+ if (domain == PF_INET)
70562+ goto inet_check;
70563+ goto exit;
70564+ } else {
70565+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70566+ __u32 fakeip = 0;
70567+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70568+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70569+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70570+ gr_to_filename(current->exec_file->f_path.dentry,
70571+ current->exec_file->f_path.mnt) :
70572+ curr->filename, curr->filename,
70573+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70574+ &current->signal->saved_ip);
70575+ goto exit;
70576+ }
70577+ goto exit_fail;
70578+ }
70579+
70580+inet_check:
70581+ /* the rest of this checking is for IPv4 only */
70582+ if (!curr->ips)
70583+ goto exit;
70584+
70585+ if ((curr->ip_type & (1U << type)) &&
70586+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70587+ goto exit;
70588+
70589+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70590+ /* we don't place acls on raw sockets , and sometimes
70591+ dgram/ip sockets are opened for ioctl and not
70592+ bind/connect, so we'll fake a bind learn log */
70593+ if (type == SOCK_RAW || type == SOCK_PACKET) {
70594+ __u32 fakeip = 0;
70595+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70596+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70597+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70598+ gr_to_filename(current->exec_file->f_path.dentry,
70599+ current->exec_file->f_path.mnt) :
70600+ curr->filename, curr->filename,
70601+ &fakeip, 0, type,
70602+ protocol, GR_CONNECT, &current->signal->saved_ip);
70603+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70604+ __u32 fakeip = 0;
70605+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70606+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70607+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70608+ gr_to_filename(current->exec_file->f_path.dentry,
70609+ current->exec_file->f_path.mnt) :
70610+ curr->filename, curr->filename,
70611+ &fakeip, 0, type,
70612+ protocol, GR_BIND, &current->signal->saved_ip);
70613+ }
70614+ /* we'll log when they use connect or bind */
70615+ goto exit;
70616+ }
70617+
70618+exit_fail:
70619+ if (domain == PF_INET)
70620+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70621+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
70622+ else if (rcu_access_pointer(net_families[domain]) != NULL)
70623+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70624+ gr_socktype_to_name(type), protocol);
70625+
70626+ return 0;
70627+exit:
70628+ return 1;
70629+}
70630+
70631+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)
70632+{
70633+ if ((ip->mode & mode) &&
70634+ (ip_port >= ip->low) &&
70635+ (ip_port <= ip->high) &&
70636+ ((ntohl(ip_addr) & our_netmask) ==
70637+ (ntohl(our_addr) & our_netmask))
70638+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70639+ && (ip->type & (1U << type))) {
70640+ if (ip->mode & GR_INVERT)
70641+ return 2; // specifically denied
70642+ else
70643+ return 1; // allowed
70644+ }
70645+
70646+ return 0; // not specifically allowed, may continue parsing
70647+}
70648+
70649+static int
70650+gr_search_connectbind(const int full_mode, struct sock *sk,
70651+ struct sockaddr_in *addr, const int type)
70652+{
70653+ char iface[IFNAMSIZ] = {0};
70654+ struct acl_subject_label *curr;
70655+ struct acl_ip_label *ip;
70656+ struct inet_sock *isk;
70657+ struct net_device *dev;
70658+ struct in_device *idev;
70659+ unsigned long i;
70660+ int ret;
70661+ int mode = full_mode & (GR_BIND | GR_CONNECT);
70662+ __u32 ip_addr = 0;
70663+ __u32 our_addr;
70664+ __u32 our_netmask;
70665+ char *p;
70666+ __u16 ip_port = 0;
70667+ const struct cred *cred = current_cred();
70668+
70669+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70670+ return 0;
70671+
70672+ curr = current->acl;
70673+ isk = inet_sk(sk);
70674+
70675+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70676+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70677+ addr->sin_addr.s_addr = curr->inaddr_any_override;
70678+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70679+ struct sockaddr_in saddr;
70680+ int err;
70681+
70682+ saddr.sin_family = AF_INET;
70683+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
70684+ saddr.sin_port = isk->inet_sport;
70685+
70686+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70687+ if (err)
70688+ return err;
70689+
70690+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70691+ if (err)
70692+ return err;
70693+ }
70694+
70695+ if (!curr->ips)
70696+ return 0;
70697+
70698+ ip_addr = addr->sin_addr.s_addr;
70699+ ip_port = ntohs(addr->sin_port);
70700+
70701+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70702+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70703+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70704+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70705+ gr_to_filename(current->exec_file->f_path.dentry,
70706+ current->exec_file->f_path.mnt) :
70707+ curr->filename, curr->filename,
70708+ &ip_addr, ip_port, type,
70709+ sk->sk_protocol, mode, &current->signal->saved_ip);
70710+ return 0;
70711+ }
70712+
70713+ for (i = 0; i < curr->ip_num; i++) {
70714+ ip = *(curr->ips + i);
70715+ if (ip->iface != NULL) {
70716+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
70717+ p = strchr(iface, ':');
70718+ if (p != NULL)
70719+ *p = '\0';
70720+ dev = dev_get_by_name(sock_net(sk), iface);
70721+ if (dev == NULL)
70722+ continue;
70723+ idev = in_dev_get(dev);
70724+ if (idev == NULL) {
70725+ dev_put(dev);
70726+ continue;
70727+ }
70728+ rcu_read_lock();
70729+ for_ifa(idev) {
70730+ if (!strcmp(ip->iface, ifa->ifa_label)) {
70731+ our_addr = ifa->ifa_address;
70732+ our_netmask = 0xffffffff;
70733+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70734+ if (ret == 1) {
70735+ rcu_read_unlock();
70736+ in_dev_put(idev);
70737+ dev_put(dev);
70738+ return 0;
70739+ } else if (ret == 2) {
70740+ rcu_read_unlock();
70741+ in_dev_put(idev);
70742+ dev_put(dev);
70743+ goto denied;
70744+ }
70745+ }
70746+ } endfor_ifa(idev);
70747+ rcu_read_unlock();
70748+ in_dev_put(idev);
70749+ dev_put(dev);
70750+ } else {
70751+ our_addr = ip->addr;
70752+ our_netmask = ip->netmask;
70753+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70754+ if (ret == 1)
70755+ return 0;
70756+ else if (ret == 2)
70757+ goto denied;
70758+ }
70759+ }
70760+
70761+denied:
70762+ if (mode == GR_BIND)
70763+ 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));
70764+ else if (mode == GR_CONNECT)
70765+ 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));
70766+
70767+ return -EACCES;
70768+}
70769+
70770+int
70771+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70772+{
70773+ /* always allow disconnection of dgram sockets with connect */
70774+ if (addr->sin_family == AF_UNSPEC)
70775+ return 0;
70776+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70777+}
70778+
70779+int
70780+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70781+{
70782+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70783+}
70784+
70785+int gr_search_listen(struct socket *sock)
70786+{
70787+ struct sock *sk = sock->sk;
70788+ struct sockaddr_in addr;
70789+
70790+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70791+ addr.sin_port = inet_sk(sk)->inet_sport;
70792+
70793+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70794+}
70795+
70796+int gr_search_accept(struct socket *sock)
70797+{
70798+ struct sock *sk = sock->sk;
70799+ struct sockaddr_in addr;
70800+
70801+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70802+ addr.sin_port = inet_sk(sk)->inet_sport;
70803+
70804+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70805+}
70806+
70807+int
70808+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70809+{
70810+ if (addr)
70811+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70812+ else {
70813+ struct sockaddr_in sin;
70814+ const struct inet_sock *inet = inet_sk(sk);
70815+
70816+ sin.sin_addr.s_addr = inet->inet_daddr;
70817+ sin.sin_port = inet->inet_dport;
70818+
70819+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70820+ }
70821+}
70822+
70823+int
70824+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70825+{
70826+ struct sockaddr_in sin;
70827+
70828+ if (unlikely(skb->len < sizeof (struct udphdr)))
70829+ return 0; // skip this packet
70830+
70831+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70832+ sin.sin_port = udp_hdr(skb)->source;
70833+
70834+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70835+}
70836diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70837new file mode 100644
70838index 0000000..25f54ef
70839--- /dev/null
70840+++ b/grsecurity/gracl_learn.c
70841@@ -0,0 +1,207 @@
70842+#include <linux/kernel.h>
70843+#include <linux/mm.h>
70844+#include <linux/sched.h>
70845+#include <linux/poll.h>
70846+#include <linux/string.h>
70847+#include <linux/file.h>
70848+#include <linux/types.h>
70849+#include <linux/vmalloc.h>
70850+#include <linux/grinternal.h>
70851+
70852+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70853+ size_t count, loff_t *ppos);
70854+extern int gr_acl_is_enabled(void);
70855+
70856+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70857+static int gr_learn_attached;
70858+
70859+/* use a 512k buffer */
70860+#define LEARN_BUFFER_SIZE (512 * 1024)
70861+
70862+static DEFINE_SPINLOCK(gr_learn_lock);
70863+static DEFINE_MUTEX(gr_learn_user_mutex);
70864+
70865+/* we need to maintain two buffers, so that the kernel context of grlearn
70866+ uses a semaphore around the userspace copying, and the other kernel contexts
70867+ use a spinlock when copying into the buffer, since they cannot sleep
70868+*/
70869+static char *learn_buffer;
70870+static char *learn_buffer_user;
70871+static int learn_buffer_len;
70872+static int learn_buffer_user_len;
70873+
70874+static ssize_t
70875+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70876+{
70877+ DECLARE_WAITQUEUE(wait, current);
70878+ ssize_t retval = 0;
70879+
70880+ add_wait_queue(&learn_wait, &wait);
70881+ set_current_state(TASK_INTERRUPTIBLE);
70882+ do {
70883+ mutex_lock(&gr_learn_user_mutex);
70884+ spin_lock(&gr_learn_lock);
70885+ if (learn_buffer_len)
70886+ break;
70887+ spin_unlock(&gr_learn_lock);
70888+ mutex_unlock(&gr_learn_user_mutex);
70889+ if (file->f_flags & O_NONBLOCK) {
70890+ retval = -EAGAIN;
70891+ goto out;
70892+ }
70893+ if (signal_pending(current)) {
70894+ retval = -ERESTARTSYS;
70895+ goto out;
70896+ }
70897+
70898+ schedule();
70899+ } while (1);
70900+
70901+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70902+ learn_buffer_user_len = learn_buffer_len;
70903+ retval = learn_buffer_len;
70904+ learn_buffer_len = 0;
70905+
70906+ spin_unlock(&gr_learn_lock);
70907+
70908+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70909+ retval = -EFAULT;
70910+
70911+ mutex_unlock(&gr_learn_user_mutex);
70912+out:
70913+ set_current_state(TASK_RUNNING);
70914+ remove_wait_queue(&learn_wait, &wait);
70915+ return retval;
70916+}
70917+
70918+static unsigned int
70919+poll_learn(struct file * file, poll_table * wait)
70920+{
70921+ poll_wait(file, &learn_wait, wait);
70922+
70923+ if (learn_buffer_len)
70924+ return (POLLIN | POLLRDNORM);
70925+
70926+ return 0;
70927+}
70928+
70929+void
70930+gr_clear_learn_entries(void)
70931+{
70932+ char *tmp;
70933+
70934+ mutex_lock(&gr_learn_user_mutex);
70935+ spin_lock(&gr_learn_lock);
70936+ tmp = learn_buffer;
70937+ learn_buffer = NULL;
70938+ spin_unlock(&gr_learn_lock);
70939+ if (tmp)
70940+ vfree(tmp);
70941+ if (learn_buffer_user != NULL) {
70942+ vfree(learn_buffer_user);
70943+ learn_buffer_user = NULL;
70944+ }
70945+ learn_buffer_len = 0;
70946+ mutex_unlock(&gr_learn_user_mutex);
70947+
70948+ return;
70949+}
70950+
70951+void
70952+gr_add_learn_entry(const char *fmt, ...)
70953+{
70954+ va_list args;
70955+ unsigned int len;
70956+
70957+ if (!gr_learn_attached)
70958+ return;
70959+
70960+ spin_lock(&gr_learn_lock);
70961+
70962+ /* leave a gap at the end so we know when it's "full" but don't have to
70963+ compute the exact length of the string we're trying to append
70964+ */
70965+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
70966+ spin_unlock(&gr_learn_lock);
70967+ wake_up_interruptible(&learn_wait);
70968+ return;
70969+ }
70970+ if (learn_buffer == NULL) {
70971+ spin_unlock(&gr_learn_lock);
70972+ return;
70973+ }
70974+
70975+ va_start(args, fmt);
70976+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
70977+ va_end(args);
70978+
70979+ learn_buffer_len += len + 1;
70980+
70981+ spin_unlock(&gr_learn_lock);
70982+ wake_up_interruptible(&learn_wait);
70983+
70984+ return;
70985+}
70986+
70987+static int
70988+open_learn(struct inode *inode, struct file *file)
70989+{
70990+ if (file->f_mode & FMODE_READ && gr_learn_attached)
70991+ return -EBUSY;
70992+ if (file->f_mode & FMODE_READ) {
70993+ int retval = 0;
70994+ mutex_lock(&gr_learn_user_mutex);
70995+ if (learn_buffer == NULL)
70996+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
70997+ if (learn_buffer_user == NULL)
70998+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
70999+ if (learn_buffer == NULL) {
71000+ retval = -ENOMEM;
71001+ goto out_error;
71002+ }
71003+ if (learn_buffer_user == NULL) {
71004+ retval = -ENOMEM;
71005+ goto out_error;
71006+ }
71007+ learn_buffer_len = 0;
71008+ learn_buffer_user_len = 0;
71009+ gr_learn_attached = 1;
71010+out_error:
71011+ mutex_unlock(&gr_learn_user_mutex);
71012+ return retval;
71013+ }
71014+ return 0;
71015+}
71016+
71017+static int
71018+close_learn(struct inode *inode, struct file *file)
71019+{
71020+ if (file->f_mode & FMODE_READ) {
71021+ char *tmp = NULL;
71022+ mutex_lock(&gr_learn_user_mutex);
71023+ spin_lock(&gr_learn_lock);
71024+ tmp = learn_buffer;
71025+ learn_buffer = NULL;
71026+ spin_unlock(&gr_learn_lock);
71027+ if (tmp)
71028+ vfree(tmp);
71029+ if (learn_buffer_user != NULL) {
71030+ vfree(learn_buffer_user);
71031+ learn_buffer_user = NULL;
71032+ }
71033+ learn_buffer_len = 0;
71034+ learn_buffer_user_len = 0;
71035+ gr_learn_attached = 0;
71036+ mutex_unlock(&gr_learn_user_mutex);
71037+ }
71038+
71039+ return 0;
71040+}
71041+
71042+const struct file_operations grsec_fops = {
71043+ .read = read_learn,
71044+ .write = write_grsec_handler,
71045+ .open = open_learn,
71046+ .release = close_learn,
71047+ .poll = poll_learn,
71048+};
71049diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71050new file mode 100644
71051index 0000000..361a099
71052--- /dev/null
71053+++ b/grsecurity/gracl_policy.c
71054@@ -0,0 +1,1782 @@
71055+#include <linux/kernel.h>
71056+#include <linux/module.h>
71057+#include <linux/sched.h>
71058+#include <linux/mm.h>
71059+#include <linux/file.h>
71060+#include <linux/fs.h>
71061+#include <linux/namei.h>
71062+#include <linux/mount.h>
71063+#include <linux/tty.h>
71064+#include <linux/proc_fs.h>
71065+#include <linux/lglock.h>
71066+#include <linux/slab.h>
71067+#include <linux/vmalloc.h>
71068+#include <linux/types.h>
71069+#include <linux/sysctl.h>
71070+#include <linux/netdevice.h>
71071+#include <linux/ptrace.h>
71072+#include <linux/gracl.h>
71073+#include <linux/gralloc.h>
71074+#include <linux/security.h>
71075+#include <linux/grinternal.h>
71076+#include <linux/pid_namespace.h>
71077+#include <linux/stop_machine.h>
71078+#include <linux/fdtable.h>
71079+#include <linux/percpu.h>
71080+#include <linux/lglock.h>
71081+#include <linux/hugetlb.h>
71082+#include <linux/posix-timers.h>
71083+#include "../fs/mount.h"
71084+
71085+#include <asm/uaccess.h>
71086+#include <asm/errno.h>
71087+#include <asm/mman.h>
71088+
71089+extern struct gr_policy_state *polstate;
71090+
71091+#define FOR_EACH_ROLE_START(role) \
71092+ role = polstate->role_list; \
71093+ while (role) {
71094+
71095+#define FOR_EACH_ROLE_END(role) \
71096+ role = role->prev; \
71097+ }
71098+
71099+struct path gr_real_root;
71100+
71101+extern struct gr_alloc_state *current_alloc_state;
71102+
71103+u16 acl_sp_role_value;
71104+
71105+static DEFINE_MUTEX(gr_dev_mutex);
71106+
71107+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71108+extern void gr_clear_learn_entries(void);
71109+
71110+static struct gr_arg gr_usermode;
71111+static unsigned char gr_system_salt[GR_SALT_LEN];
71112+static unsigned char gr_system_sum[GR_SHA_LEN];
71113+
71114+static unsigned int gr_auth_attempts = 0;
71115+static unsigned long gr_auth_expires = 0UL;
71116+
71117+struct acl_object_label *fakefs_obj_rw;
71118+struct acl_object_label *fakefs_obj_rwx;
71119+
71120+extern int gr_init_uidset(void);
71121+extern void gr_free_uidset(void);
71122+extern void gr_remove_uid(uid_t uid);
71123+extern int gr_find_uid(uid_t uid);
71124+
71125+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71126+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71127+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71128+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71129+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);
71130+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71131+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71132+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71133+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71134+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71135+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71136+extern void assign_special_role(const char *rolename);
71137+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71138+extern int gr_rbac_disable(void *unused);
71139+extern void gr_enable_rbac_system(void);
71140+
71141+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71142+{
71143+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71144+ return -EFAULT;
71145+
71146+ return 0;
71147+}
71148+
71149+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71150+{
71151+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71152+ return -EFAULT;
71153+
71154+ return 0;
71155+}
71156+
71157+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71158+{
71159+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71160+ return -EFAULT;
71161+
71162+ return 0;
71163+}
71164+
71165+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71166+{
71167+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71168+ return -EFAULT;
71169+
71170+ return 0;
71171+}
71172+
71173+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71174+{
71175+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71176+ return -EFAULT;
71177+
71178+ return 0;
71179+}
71180+
71181+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71182+{
71183+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71184+ return -EFAULT;
71185+
71186+ return 0;
71187+}
71188+
71189+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71190+{
71191+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71192+ return -EFAULT;
71193+
71194+ return 0;
71195+}
71196+
71197+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71198+{
71199+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71200+ return -EFAULT;
71201+
71202+ return 0;
71203+}
71204+
71205+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71206+{
71207+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71208+ return -EFAULT;
71209+
71210+ return 0;
71211+}
71212+
71213+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71214+{
71215+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71216+ return -EFAULT;
71217+
71218+ if (((uwrap->version != GRSECURITY_VERSION) &&
71219+ (uwrap->version != 0x2901)) ||
71220+ (uwrap->size != sizeof(struct gr_arg)))
71221+ return -EINVAL;
71222+
71223+ return 0;
71224+}
71225+
71226+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71227+{
71228+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71229+ return -EFAULT;
71230+
71231+ return 0;
71232+}
71233+
71234+static size_t get_gr_arg_wrapper_size_normal(void)
71235+{
71236+ return sizeof(struct gr_arg_wrapper);
71237+}
71238+
71239+#ifdef CONFIG_COMPAT
71240+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71241+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71242+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71243+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71244+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71245+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71246+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71247+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71248+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71249+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71250+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71251+extern size_t get_gr_arg_wrapper_size_compat(void);
71252+
71253+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71254+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71255+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71256+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71257+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71258+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71259+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71260+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71261+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71262+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71263+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71264+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71265+
71266+#else
71267+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71268+#define copy_gr_arg copy_gr_arg_normal
71269+#define copy_gr_hash_struct copy_gr_hash_struct_normal
71270+#define copy_acl_object_label copy_acl_object_label_normal
71271+#define copy_acl_subject_label copy_acl_subject_label_normal
71272+#define copy_acl_role_label copy_acl_role_label_normal
71273+#define copy_acl_ip_label copy_acl_ip_label_normal
71274+#define copy_pointer_from_array copy_pointer_from_array_normal
71275+#define copy_sprole_pw copy_sprole_pw_normal
71276+#define copy_role_transition copy_role_transition_normal
71277+#define copy_role_allowed_ip copy_role_allowed_ip_normal
71278+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71279+#endif
71280+
71281+static struct acl_subject_label *
71282+lookup_subject_map(const struct acl_subject_label *userp)
71283+{
71284+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71285+ struct subject_map *match;
71286+
71287+ match = polstate->subj_map_set.s_hash[index];
71288+
71289+ while (match && match->user != userp)
71290+ match = match->next;
71291+
71292+ if (match != NULL)
71293+ return match->kernel;
71294+ else
71295+ return NULL;
71296+}
71297+
71298+static void
71299+insert_subj_map_entry(struct subject_map *subjmap)
71300+{
71301+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71302+ struct subject_map **curr;
71303+
71304+ subjmap->prev = NULL;
71305+
71306+ curr = &polstate->subj_map_set.s_hash[index];
71307+ if (*curr != NULL)
71308+ (*curr)->prev = subjmap;
71309+
71310+ subjmap->next = *curr;
71311+ *curr = subjmap;
71312+
71313+ return;
71314+}
71315+
71316+static void
71317+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71318+{
71319+ unsigned int index =
71320+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71321+ struct acl_role_label **curr;
71322+ struct acl_role_label *tmp, *tmp2;
71323+
71324+ curr = &polstate->acl_role_set.r_hash[index];
71325+
71326+ /* simple case, slot is empty, just set it to our role */
71327+ if (*curr == NULL) {
71328+ *curr = role;
71329+ } else {
71330+ /* example:
71331+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
71332+ 2 -> 3
71333+ */
71334+ /* first check to see if we can already be reached via this slot */
71335+ tmp = *curr;
71336+ while (tmp && tmp != role)
71337+ tmp = tmp->next;
71338+ if (tmp == role) {
71339+ /* we don't need to add ourselves to this slot's chain */
71340+ return;
71341+ }
71342+ /* we need to add ourselves to this chain, two cases */
71343+ if (role->next == NULL) {
71344+ /* simple case, append the current chain to our role */
71345+ role->next = *curr;
71346+ *curr = role;
71347+ } else {
71348+ /* 1 -> 2 -> 3 -> 4
71349+ 2 -> 3 -> 4
71350+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71351+ */
71352+ /* trickier case: walk our role's chain until we find
71353+ the role for the start of the current slot's chain */
71354+ tmp = role;
71355+ tmp2 = *curr;
71356+ while (tmp->next && tmp->next != tmp2)
71357+ tmp = tmp->next;
71358+ if (tmp->next == tmp2) {
71359+ /* from example above, we found 3, so just
71360+ replace this slot's chain with ours */
71361+ *curr = role;
71362+ } else {
71363+ /* we didn't find a subset of our role's chain
71364+ in the current slot's chain, so append their
71365+ chain to ours, and set us as the first role in
71366+ the slot's chain
71367+
71368+ we could fold this case with the case above,
71369+ but making it explicit for clarity
71370+ */
71371+ tmp->next = tmp2;
71372+ *curr = role;
71373+ }
71374+ }
71375+ }
71376+
71377+ return;
71378+}
71379+
71380+static void
71381+insert_acl_role_label(struct acl_role_label *role)
71382+{
71383+ int i;
71384+
71385+ if (polstate->role_list == NULL) {
71386+ polstate->role_list = role;
71387+ role->prev = NULL;
71388+ } else {
71389+ role->prev = polstate->role_list;
71390+ polstate->role_list = role;
71391+ }
71392+
71393+ /* used for hash chains */
71394+ role->next = NULL;
71395+
71396+ if (role->roletype & GR_ROLE_DOMAIN) {
71397+ for (i = 0; i < role->domain_child_num; i++)
71398+ __insert_acl_role_label(role, role->domain_children[i]);
71399+ } else
71400+ __insert_acl_role_label(role, role->uidgid);
71401+}
71402+
71403+static int
71404+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71405+{
71406+ struct name_entry **curr, *nentry;
71407+ struct inodev_entry *ientry;
71408+ unsigned int len = strlen(name);
71409+ unsigned int key = full_name_hash(name, len);
71410+ unsigned int index = key % polstate->name_set.n_size;
71411+
71412+ curr = &polstate->name_set.n_hash[index];
71413+
71414+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71415+ curr = &((*curr)->next);
71416+
71417+ if (*curr != NULL)
71418+ return 1;
71419+
71420+ nentry = acl_alloc(sizeof (struct name_entry));
71421+ if (nentry == NULL)
71422+ return 0;
71423+ ientry = acl_alloc(sizeof (struct inodev_entry));
71424+ if (ientry == NULL)
71425+ return 0;
71426+ ientry->nentry = nentry;
71427+
71428+ nentry->key = key;
71429+ nentry->name = name;
71430+ nentry->inode = inode;
71431+ nentry->device = device;
71432+ nentry->len = len;
71433+ nentry->deleted = deleted;
71434+
71435+ nentry->prev = NULL;
71436+ curr = &polstate->name_set.n_hash[index];
71437+ if (*curr != NULL)
71438+ (*curr)->prev = nentry;
71439+ nentry->next = *curr;
71440+ *curr = nentry;
71441+
71442+ /* insert us into the table searchable by inode/dev */
71443+ __insert_inodev_entry(polstate, ientry);
71444+
71445+ return 1;
71446+}
71447+
71448+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71449+
71450+static void *
71451+create_table(__u32 * len, int elementsize)
71452+{
71453+ unsigned int table_sizes[] = {
71454+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71455+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71456+ 4194301, 8388593, 16777213, 33554393, 67108859
71457+ };
71458+ void *newtable = NULL;
71459+ unsigned int pwr = 0;
71460+
71461+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71462+ table_sizes[pwr] <= *len)
71463+ pwr++;
71464+
71465+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71466+ return newtable;
71467+
71468+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71469+ newtable =
71470+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71471+ else
71472+ newtable = vmalloc(table_sizes[pwr] * elementsize);
71473+
71474+ *len = table_sizes[pwr];
71475+
71476+ return newtable;
71477+}
71478+
71479+static int
71480+init_variables(const struct gr_arg *arg, bool reload)
71481+{
71482+ struct task_struct *reaper = init_pid_ns.child_reaper;
71483+ unsigned int stacksize;
71484+
71485+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71486+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71487+ polstate->name_set.n_size = arg->role_db.num_objects;
71488+ polstate->inodev_set.i_size = arg->role_db.num_objects;
71489+
71490+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71491+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71492+ return 1;
71493+
71494+ if (!reload) {
71495+ if (!gr_init_uidset())
71496+ return 1;
71497+ }
71498+
71499+ /* set up the stack that holds allocation info */
71500+
71501+ stacksize = arg->role_db.num_pointers + 5;
71502+
71503+ if (!acl_alloc_stack_init(stacksize))
71504+ return 1;
71505+
71506+ if (!reload) {
71507+ /* grab reference for the real root dentry and vfsmount */
71508+ get_fs_root(reaper->fs, &gr_real_root);
71509+
71510+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71511+ 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);
71512+#endif
71513+
71514+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71515+ if (fakefs_obj_rw == NULL)
71516+ return 1;
71517+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71518+
71519+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71520+ if (fakefs_obj_rwx == NULL)
71521+ return 1;
71522+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71523+ }
71524+
71525+ polstate->subj_map_set.s_hash =
71526+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71527+ polstate->acl_role_set.r_hash =
71528+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71529+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71530+ polstate->inodev_set.i_hash =
71531+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71532+
71533+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71534+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71535+ return 1;
71536+
71537+ memset(polstate->subj_map_set.s_hash, 0,
71538+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71539+ memset(polstate->acl_role_set.r_hash, 0,
71540+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71541+ memset(polstate->name_set.n_hash, 0,
71542+ sizeof (struct name_entry *) * polstate->name_set.n_size);
71543+ memset(polstate->inodev_set.i_hash, 0,
71544+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71545+
71546+ return 0;
71547+}
71548+
71549+/* free information not needed after startup
71550+ currently contains user->kernel pointer mappings for subjects
71551+*/
71552+
71553+static void
71554+free_init_variables(void)
71555+{
71556+ __u32 i;
71557+
71558+ if (polstate->subj_map_set.s_hash) {
71559+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71560+ if (polstate->subj_map_set.s_hash[i]) {
71561+ kfree(polstate->subj_map_set.s_hash[i]);
71562+ polstate->subj_map_set.s_hash[i] = NULL;
71563+ }
71564+ }
71565+
71566+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71567+ PAGE_SIZE)
71568+ kfree(polstate->subj_map_set.s_hash);
71569+ else
71570+ vfree(polstate->subj_map_set.s_hash);
71571+ }
71572+
71573+ return;
71574+}
71575+
71576+static void
71577+free_variables(bool reload)
71578+{
71579+ struct acl_subject_label *s;
71580+ struct acl_role_label *r;
71581+ struct task_struct *task, *task2;
71582+ unsigned int x;
71583+
71584+ if (!reload) {
71585+ gr_clear_learn_entries();
71586+
71587+ read_lock(&tasklist_lock);
71588+ do_each_thread(task2, task) {
71589+ task->acl_sp_role = 0;
71590+ task->acl_role_id = 0;
71591+ task->inherited = 0;
71592+ task->acl = NULL;
71593+ task->role = NULL;
71594+ } while_each_thread(task2, task);
71595+ read_unlock(&tasklist_lock);
71596+
71597+ kfree(fakefs_obj_rw);
71598+ fakefs_obj_rw = NULL;
71599+ kfree(fakefs_obj_rwx);
71600+ fakefs_obj_rwx = NULL;
71601+
71602+ /* release the reference to the real root dentry and vfsmount */
71603+ path_put(&gr_real_root);
71604+ memset(&gr_real_root, 0, sizeof(gr_real_root));
71605+ }
71606+
71607+ /* free all object hash tables */
71608+
71609+ FOR_EACH_ROLE_START(r)
71610+ if (r->subj_hash == NULL)
71611+ goto next_role;
71612+ FOR_EACH_SUBJECT_START(r, s, x)
71613+ if (s->obj_hash == NULL)
71614+ break;
71615+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71616+ kfree(s->obj_hash);
71617+ else
71618+ vfree(s->obj_hash);
71619+ FOR_EACH_SUBJECT_END(s, x)
71620+ FOR_EACH_NESTED_SUBJECT_START(r, s)
71621+ if (s->obj_hash == NULL)
71622+ break;
71623+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71624+ kfree(s->obj_hash);
71625+ else
71626+ vfree(s->obj_hash);
71627+ FOR_EACH_NESTED_SUBJECT_END(s)
71628+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71629+ kfree(r->subj_hash);
71630+ else
71631+ vfree(r->subj_hash);
71632+ r->subj_hash = NULL;
71633+next_role:
71634+ FOR_EACH_ROLE_END(r)
71635+
71636+ acl_free_all();
71637+
71638+ if (polstate->acl_role_set.r_hash) {
71639+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71640+ PAGE_SIZE)
71641+ kfree(polstate->acl_role_set.r_hash);
71642+ else
71643+ vfree(polstate->acl_role_set.r_hash);
71644+ }
71645+ if (polstate->name_set.n_hash) {
71646+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71647+ PAGE_SIZE)
71648+ kfree(polstate->name_set.n_hash);
71649+ else
71650+ vfree(polstate->name_set.n_hash);
71651+ }
71652+
71653+ if (polstate->inodev_set.i_hash) {
71654+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71655+ PAGE_SIZE)
71656+ kfree(polstate->inodev_set.i_hash);
71657+ else
71658+ vfree(polstate->inodev_set.i_hash);
71659+ }
71660+
71661+ if (!reload)
71662+ gr_free_uidset();
71663+
71664+ memset(&polstate->name_set, 0, sizeof (struct name_db));
71665+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71666+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71667+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71668+
71669+ polstate->default_role = NULL;
71670+ polstate->kernel_role = NULL;
71671+ polstate->role_list = NULL;
71672+
71673+ return;
71674+}
71675+
71676+static struct acl_subject_label *
71677+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71678+
71679+static int alloc_and_copy_string(char **name, unsigned int maxlen)
71680+{
71681+ unsigned int len = strnlen_user(*name, maxlen);
71682+ char *tmp;
71683+
71684+ if (!len || len >= maxlen)
71685+ return -EINVAL;
71686+
71687+ if ((tmp = (char *) acl_alloc(len)) == NULL)
71688+ return -ENOMEM;
71689+
71690+ if (copy_from_user(tmp, *name, len))
71691+ return -EFAULT;
71692+
71693+ tmp[len-1] = '\0';
71694+ *name = tmp;
71695+
71696+ return 0;
71697+}
71698+
71699+static int
71700+copy_user_glob(struct acl_object_label *obj)
71701+{
71702+ struct acl_object_label *g_tmp, **guser;
71703+ int error;
71704+
71705+ if (obj->globbed == NULL)
71706+ return 0;
71707+
71708+ guser = &obj->globbed;
71709+ while (*guser) {
71710+ g_tmp = (struct acl_object_label *)
71711+ acl_alloc(sizeof (struct acl_object_label));
71712+ if (g_tmp == NULL)
71713+ return -ENOMEM;
71714+
71715+ if (copy_acl_object_label(g_tmp, *guser))
71716+ return -EFAULT;
71717+
71718+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71719+ if (error)
71720+ return error;
71721+
71722+ *guser = g_tmp;
71723+ guser = &(g_tmp->next);
71724+ }
71725+
71726+ return 0;
71727+}
71728+
71729+static int
71730+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71731+ struct acl_role_label *role)
71732+{
71733+ struct acl_object_label *o_tmp;
71734+ int ret;
71735+
71736+ while (userp) {
71737+ if ((o_tmp = (struct acl_object_label *)
71738+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
71739+ return -ENOMEM;
71740+
71741+ if (copy_acl_object_label(o_tmp, userp))
71742+ return -EFAULT;
71743+
71744+ userp = o_tmp->prev;
71745+
71746+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71747+ if (ret)
71748+ return ret;
71749+
71750+ insert_acl_obj_label(o_tmp, subj);
71751+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71752+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71753+ return -ENOMEM;
71754+
71755+ ret = copy_user_glob(o_tmp);
71756+ if (ret)
71757+ return ret;
71758+
71759+ if (o_tmp->nested) {
71760+ int already_copied;
71761+
71762+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71763+ if (IS_ERR(o_tmp->nested))
71764+ return PTR_ERR(o_tmp->nested);
71765+
71766+ /* insert into nested subject list if we haven't copied this one yet
71767+ to prevent duplicate entries */
71768+ if (!already_copied) {
71769+ o_tmp->nested->next = role->hash->first;
71770+ role->hash->first = o_tmp->nested;
71771+ }
71772+ }
71773+ }
71774+
71775+ return 0;
71776+}
71777+
71778+static __u32
71779+count_user_subjs(struct acl_subject_label *userp)
71780+{
71781+ struct acl_subject_label s_tmp;
71782+ __u32 num = 0;
71783+
71784+ while (userp) {
71785+ if (copy_acl_subject_label(&s_tmp, userp))
71786+ break;
71787+
71788+ userp = s_tmp.prev;
71789+ }
71790+
71791+ return num;
71792+}
71793+
71794+static int
71795+copy_user_allowedips(struct acl_role_label *rolep)
71796+{
71797+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71798+
71799+ ruserip = rolep->allowed_ips;
71800+
71801+ while (ruserip) {
71802+ rlast = rtmp;
71803+
71804+ if ((rtmp = (struct role_allowed_ip *)
71805+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71806+ return -ENOMEM;
71807+
71808+ if (copy_role_allowed_ip(rtmp, ruserip))
71809+ return -EFAULT;
71810+
71811+ ruserip = rtmp->prev;
71812+
71813+ if (!rlast) {
71814+ rtmp->prev = NULL;
71815+ rolep->allowed_ips = rtmp;
71816+ } else {
71817+ rlast->next = rtmp;
71818+ rtmp->prev = rlast;
71819+ }
71820+
71821+ if (!ruserip)
71822+ rtmp->next = NULL;
71823+ }
71824+
71825+ return 0;
71826+}
71827+
71828+static int
71829+copy_user_transitions(struct acl_role_label *rolep)
71830+{
71831+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
71832+ int error;
71833+
71834+ rusertp = rolep->transitions;
71835+
71836+ while (rusertp) {
71837+ rlast = rtmp;
71838+
71839+ if ((rtmp = (struct role_transition *)
71840+ acl_alloc(sizeof (struct role_transition))) == NULL)
71841+ return -ENOMEM;
71842+
71843+ if (copy_role_transition(rtmp, rusertp))
71844+ return -EFAULT;
71845+
71846+ rusertp = rtmp->prev;
71847+
71848+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71849+ if (error)
71850+ return error;
71851+
71852+ if (!rlast) {
71853+ rtmp->prev = NULL;
71854+ rolep->transitions = rtmp;
71855+ } else {
71856+ rlast->next = rtmp;
71857+ rtmp->prev = rlast;
71858+ }
71859+
71860+ if (!rusertp)
71861+ rtmp->next = NULL;
71862+ }
71863+
71864+ return 0;
71865+}
71866+
71867+static __u32 count_user_objs(const struct acl_object_label __user *userp)
71868+{
71869+ struct acl_object_label o_tmp;
71870+ __u32 num = 0;
71871+
71872+ while (userp) {
71873+ if (copy_acl_object_label(&o_tmp, userp))
71874+ break;
71875+
71876+ userp = o_tmp.prev;
71877+ num++;
71878+ }
71879+
71880+ return num;
71881+}
71882+
71883+static struct acl_subject_label *
71884+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71885+{
71886+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71887+ __u32 num_objs;
71888+ struct acl_ip_label **i_tmp, *i_utmp2;
71889+ struct gr_hash_struct ghash;
71890+ struct subject_map *subjmap;
71891+ unsigned int i_num;
71892+ int err;
71893+
71894+ if (already_copied != NULL)
71895+ *already_copied = 0;
71896+
71897+ s_tmp = lookup_subject_map(userp);
71898+
71899+ /* we've already copied this subject into the kernel, just return
71900+ the reference to it, and don't copy it over again
71901+ */
71902+ if (s_tmp) {
71903+ if (already_copied != NULL)
71904+ *already_copied = 1;
71905+ return(s_tmp);
71906+ }
71907+
71908+ if ((s_tmp = (struct acl_subject_label *)
71909+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71910+ return ERR_PTR(-ENOMEM);
71911+
71912+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71913+ if (subjmap == NULL)
71914+ return ERR_PTR(-ENOMEM);
71915+
71916+ subjmap->user = userp;
71917+ subjmap->kernel = s_tmp;
71918+ insert_subj_map_entry(subjmap);
71919+
71920+ if (copy_acl_subject_label(s_tmp, userp))
71921+ return ERR_PTR(-EFAULT);
71922+
71923+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71924+ if (err)
71925+ return ERR_PTR(err);
71926+
71927+ if (!strcmp(s_tmp->filename, "/"))
71928+ role->root_label = s_tmp;
71929+
71930+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71931+ return ERR_PTR(-EFAULT);
71932+
71933+ /* copy user and group transition tables */
71934+
71935+ if (s_tmp->user_trans_num) {
71936+ uid_t *uidlist;
71937+
71938+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71939+ if (uidlist == NULL)
71940+ return ERR_PTR(-ENOMEM);
71941+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71942+ return ERR_PTR(-EFAULT);
71943+
71944+ s_tmp->user_transitions = uidlist;
71945+ }
71946+
71947+ if (s_tmp->group_trans_num) {
71948+ gid_t *gidlist;
71949+
71950+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71951+ if (gidlist == NULL)
71952+ return ERR_PTR(-ENOMEM);
71953+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71954+ return ERR_PTR(-EFAULT);
71955+
71956+ s_tmp->group_transitions = gidlist;
71957+ }
71958+
71959+ /* set up object hash table */
71960+ num_objs = count_user_objs(ghash.first);
71961+
71962+ s_tmp->obj_hash_size = num_objs;
71963+ s_tmp->obj_hash =
71964+ (struct acl_object_label **)
71965+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
71966+
71967+ if (!s_tmp->obj_hash)
71968+ return ERR_PTR(-ENOMEM);
71969+
71970+ memset(s_tmp->obj_hash, 0,
71971+ s_tmp->obj_hash_size *
71972+ sizeof (struct acl_object_label *));
71973+
71974+ /* add in objects */
71975+ err = copy_user_objs(ghash.first, s_tmp, role);
71976+
71977+ if (err)
71978+ return ERR_PTR(err);
71979+
71980+ /* set pointer for parent subject */
71981+ if (s_tmp->parent_subject) {
71982+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
71983+
71984+ if (IS_ERR(s_tmp2))
71985+ return s_tmp2;
71986+
71987+ s_tmp->parent_subject = s_tmp2;
71988+ }
71989+
71990+ /* add in ip acls */
71991+
71992+ if (!s_tmp->ip_num) {
71993+ s_tmp->ips = NULL;
71994+ goto insert;
71995+ }
71996+
71997+ i_tmp =
71998+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
71999+ sizeof (struct acl_ip_label *));
72000+
72001+ if (!i_tmp)
72002+ return ERR_PTR(-ENOMEM);
72003+
72004+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72005+ *(i_tmp + i_num) =
72006+ (struct acl_ip_label *)
72007+ acl_alloc(sizeof (struct acl_ip_label));
72008+ if (!*(i_tmp + i_num))
72009+ return ERR_PTR(-ENOMEM);
72010+
72011+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72012+ return ERR_PTR(-EFAULT);
72013+
72014+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72015+ return ERR_PTR(-EFAULT);
72016+
72017+ if ((*(i_tmp + i_num))->iface == NULL)
72018+ continue;
72019+
72020+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72021+ if (err)
72022+ return ERR_PTR(err);
72023+ }
72024+
72025+ s_tmp->ips = i_tmp;
72026+
72027+insert:
72028+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72029+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72030+ return ERR_PTR(-ENOMEM);
72031+
72032+ return s_tmp;
72033+}
72034+
72035+static int
72036+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72037+{
72038+ struct acl_subject_label s_pre;
72039+ struct acl_subject_label * ret;
72040+ int err;
72041+
72042+ while (userp) {
72043+ if (copy_acl_subject_label(&s_pre, userp))
72044+ return -EFAULT;
72045+
72046+ ret = do_copy_user_subj(userp, role, NULL);
72047+
72048+ err = PTR_ERR(ret);
72049+ if (IS_ERR(ret))
72050+ return err;
72051+
72052+ insert_acl_subj_label(ret, role);
72053+
72054+ userp = s_pre.prev;
72055+ }
72056+
72057+ return 0;
72058+}
72059+
72060+static int
72061+copy_user_acl(struct gr_arg *arg)
72062+{
72063+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72064+ struct acl_subject_label *subj_list;
72065+ struct sprole_pw *sptmp;
72066+ struct gr_hash_struct *ghash;
72067+ uid_t *domainlist;
72068+ unsigned int r_num;
72069+ int err = 0;
72070+ __u16 i;
72071+ __u32 num_subjs;
72072+
72073+ /* we need a default and kernel role */
72074+ if (arg->role_db.num_roles < 2)
72075+ return -EINVAL;
72076+
72077+ /* copy special role authentication info from userspace */
72078+
72079+ polstate->num_sprole_pws = arg->num_sprole_pws;
72080+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72081+
72082+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72083+ return -ENOMEM;
72084+
72085+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72086+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72087+ if (!sptmp)
72088+ return -ENOMEM;
72089+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72090+ return -EFAULT;
72091+
72092+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72093+ if (err)
72094+ return err;
72095+
72096+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72097+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72098+#endif
72099+
72100+ polstate->acl_special_roles[i] = sptmp;
72101+ }
72102+
72103+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72104+
72105+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72106+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
72107+
72108+ if (!r_tmp)
72109+ return -ENOMEM;
72110+
72111+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72112+ return -EFAULT;
72113+
72114+ if (copy_acl_role_label(r_tmp, r_utmp2))
72115+ return -EFAULT;
72116+
72117+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72118+ if (err)
72119+ return err;
72120+
72121+ if (!strcmp(r_tmp->rolename, "default")
72122+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72123+ polstate->default_role = r_tmp;
72124+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72125+ polstate->kernel_role = r_tmp;
72126+ }
72127+
72128+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72129+ return -ENOMEM;
72130+
72131+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
72132+ return -EFAULT;
72133+
72134+ r_tmp->hash = ghash;
72135+
72136+ num_subjs = count_user_subjs(r_tmp->hash->first);
72137+
72138+ r_tmp->subj_hash_size = num_subjs;
72139+ r_tmp->subj_hash =
72140+ (struct acl_subject_label **)
72141+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72142+
72143+ if (!r_tmp->subj_hash)
72144+ return -ENOMEM;
72145+
72146+ err = copy_user_allowedips(r_tmp);
72147+ if (err)
72148+ return err;
72149+
72150+ /* copy domain info */
72151+ if (r_tmp->domain_children != NULL) {
72152+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72153+ if (domainlist == NULL)
72154+ return -ENOMEM;
72155+
72156+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72157+ return -EFAULT;
72158+
72159+ r_tmp->domain_children = domainlist;
72160+ }
72161+
72162+ err = copy_user_transitions(r_tmp);
72163+ if (err)
72164+ return err;
72165+
72166+ memset(r_tmp->subj_hash, 0,
72167+ r_tmp->subj_hash_size *
72168+ sizeof (struct acl_subject_label *));
72169+
72170+ /* acquire the list of subjects, then NULL out
72171+ the list prior to parsing the subjects for this role,
72172+ as during this parsing the list is replaced with a list
72173+ of *nested* subjects for the role
72174+ */
72175+ subj_list = r_tmp->hash->first;
72176+
72177+ /* set nested subject list to null */
72178+ r_tmp->hash->first = NULL;
72179+
72180+ err = copy_user_subjs(subj_list, r_tmp);
72181+
72182+ if (err)
72183+ return err;
72184+
72185+ insert_acl_role_label(r_tmp);
72186+ }
72187+
72188+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72189+ return -EINVAL;
72190+
72191+ return err;
72192+}
72193+
72194+static int gracl_reload_apply_policies(void *reload)
72195+{
72196+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72197+ struct task_struct *task, *task2;
72198+ struct acl_role_label *role, *rtmp;
72199+ struct acl_subject_label *subj;
72200+ const struct cred *cred;
72201+ int role_applied;
72202+ int ret = 0;
72203+
72204+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72205+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72206+
72207+ /* first make sure we'll be able to apply the new policy cleanly */
72208+ do_each_thread(task2, task) {
72209+ if (task->exec_file == NULL)
72210+ continue;
72211+ role_applied = 0;
72212+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72213+ /* preserve special roles */
72214+ FOR_EACH_ROLE_START(role)
72215+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72216+ rtmp = task->role;
72217+ task->role = role;
72218+ role_applied = 1;
72219+ break;
72220+ }
72221+ FOR_EACH_ROLE_END(role)
72222+ }
72223+ if (!role_applied) {
72224+ cred = __task_cred(task);
72225+ rtmp = task->role;
72226+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72227+ }
72228+ /* this handles non-nested inherited subjects, nested subjects will still
72229+ be dropped currently */
72230+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72231+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72232+ /* change the role back so that we've made no modifications to the policy */
72233+ task->role = rtmp;
72234+
72235+ if (subj == NULL || task->tmpacl == NULL) {
72236+ ret = -EINVAL;
72237+ goto out;
72238+ }
72239+ } while_each_thread(task2, task);
72240+
72241+ /* now actually apply the policy */
72242+
72243+ do_each_thread(task2, task) {
72244+ if (task->exec_file) {
72245+ role_applied = 0;
72246+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72247+ /* preserve special roles */
72248+ FOR_EACH_ROLE_START(role)
72249+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72250+ task->role = role;
72251+ role_applied = 1;
72252+ break;
72253+ }
72254+ FOR_EACH_ROLE_END(role)
72255+ }
72256+ if (!role_applied) {
72257+ cred = __task_cred(task);
72258+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72259+ }
72260+ /* this handles non-nested inherited subjects, nested subjects will still
72261+ be dropped currently */
72262+ if (!reload_state->oldmode && task->inherited)
72263+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72264+ else {
72265+ /* looked up and tagged to the task previously */
72266+ subj = task->tmpacl;
72267+ }
72268+ /* subj will be non-null */
72269+ __gr_apply_subject_to_task(polstate, task, subj);
72270+ if (reload_state->oldmode) {
72271+ task->acl_role_id = 0;
72272+ task->acl_sp_role = 0;
72273+ task->inherited = 0;
72274+ }
72275+ } else {
72276+ // it's a kernel process
72277+ task->role = polstate->kernel_role;
72278+ task->acl = polstate->kernel_role->root_label;
72279+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72280+ task->acl->mode &= ~GR_PROCFIND;
72281+#endif
72282+ }
72283+ } while_each_thread(task2, task);
72284+
72285+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72286+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72287+
72288+out:
72289+
72290+ return ret;
72291+}
72292+
72293+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72294+{
72295+ struct gr_reload_state new_reload_state = { };
72296+ int err;
72297+
72298+ new_reload_state.oldpolicy_ptr = polstate;
72299+ new_reload_state.oldalloc_ptr = current_alloc_state;
72300+ new_reload_state.oldmode = oldmode;
72301+
72302+ current_alloc_state = &new_reload_state.newalloc;
72303+ polstate = &new_reload_state.newpolicy;
72304+
72305+ /* everything relevant is now saved off, copy in the new policy */
72306+ if (init_variables(args, true)) {
72307+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72308+ err = -ENOMEM;
72309+ goto error;
72310+ }
72311+
72312+ err = copy_user_acl(args);
72313+ free_init_variables();
72314+ if (err)
72315+ goto error;
72316+ /* the new policy is copied in, with the old policy available via saved_state
72317+ first go through applying roles, making sure to preserve special roles
72318+ then apply new subjects, making sure to preserve inherited and nested subjects,
72319+ though currently only inherited subjects will be preserved
72320+ */
72321+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72322+ if (err)
72323+ goto error;
72324+
72325+ /* we've now applied the new policy, so restore the old policy state to free it */
72326+ polstate = &new_reload_state.oldpolicy;
72327+ current_alloc_state = &new_reload_state.oldalloc;
72328+ free_variables(true);
72329+
72330+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72331+ to running_polstate/current_alloc_state inside stop_machine
72332+ */
72333+ err = 0;
72334+ goto out;
72335+error:
72336+ /* on error of loading the new policy, we'll just keep the previous
72337+ policy set around
72338+ */
72339+ free_variables(true);
72340+
72341+ /* doesn't affect runtime, but maintains consistent state */
72342+out:
72343+ polstate = new_reload_state.oldpolicy_ptr;
72344+ current_alloc_state = new_reload_state.oldalloc_ptr;
72345+
72346+ return err;
72347+}
72348+
72349+static int
72350+gracl_init(struct gr_arg *args)
72351+{
72352+ int error = 0;
72353+
72354+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72355+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72356+
72357+ if (init_variables(args, false)) {
72358+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72359+ error = -ENOMEM;
72360+ goto out;
72361+ }
72362+
72363+ error = copy_user_acl(args);
72364+ free_init_variables();
72365+ if (error)
72366+ goto out;
72367+
72368+ error = gr_set_acls(0);
72369+ if (error)
72370+ goto out;
72371+
72372+ gr_enable_rbac_system();
72373+
72374+ return 0;
72375+
72376+out:
72377+ free_variables(false);
72378+ return error;
72379+}
72380+
72381+static int
72382+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72383+ unsigned char **sum)
72384+{
72385+ struct acl_role_label *r;
72386+ struct role_allowed_ip *ipp;
72387+ struct role_transition *trans;
72388+ unsigned int i;
72389+ int found = 0;
72390+ u32 curr_ip = current->signal->curr_ip;
72391+
72392+ current->signal->saved_ip = curr_ip;
72393+
72394+ /* check transition table */
72395+
72396+ for (trans = current->role->transitions; trans; trans = trans->next) {
72397+ if (!strcmp(rolename, trans->rolename)) {
72398+ found = 1;
72399+ break;
72400+ }
72401+ }
72402+
72403+ if (!found)
72404+ return 0;
72405+
72406+ /* handle special roles that do not require authentication
72407+ and check ip */
72408+
72409+ FOR_EACH_ROLE_START(r)
72410+ if (!strcmp(rolename, r->rolename) &&
72411+ (r->roletype & GR_ROLE_SPECIAL)) {
72412+ found = 0;
72413+ if (r->allowed_ips != NULL) {
72414+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72415+ if ((ntohl(curr_ip) & ipp->netmask) ==
72416+ (ntohl(ipp->addr) & ipp->netmask))
72417+ found = 1;
72418+ }
72419+ } else
72420+ found = 2;
72421+ if (!found)
72422+ return 0;
72423+
72424+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72425+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72426+ *salt = NULL;
72427+ *sum = NULL;
72428+ return 1;
72429+ }
72430+ }
72431+ FOR_EACH_ROLE_END(r)
72432+
72433+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72434+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72435+ *salt = polstate->acl_special_roles[i]->salt;
72436+ *sum = polstate->acl_special_roles[i]->sum;
72437+ return 1;
72438+ }
72439+ }
72440+
72441+ return 0;
72442+}
72443+
72444+int gr_check_secure_terminal(struct task_struct *task)
72445+{
72446+ struct task_struct *p, *p2, *p3;
72447+ struct files_struct *files;
72448+ struct fdtable *fdt;
72449+ struct file *our_file = NULL, *file;
72450+ int i;
72451+
72452+ if (task->signal->tty == NULL)
72453+ return 1;
72454+
72455+ files = get_files_struct(task);
72456+ if (files != NULL) {
72457+ rcu_read_lock();
72458+ fdt = files_fdtable(files);
72459+ for (i=0; i < fdt->max_fds; i++) {
72460+ file = fcheck_files(files, i);
72461+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72462+ get_file(file);
72463+ our_file = file;
72464+ }
72465+ }
72466+ rcu_read_unlock();
72467+ put_files_struct(files);
72468+ }
72469+
72470+ if (our_file == NULL)
72471+ return 1;
72472+
72473+ read_lock(&tasklist_lock);
72474+ do_each_thread(p2, p) {
72475+ files = get_files_struct(p);
72476+ if (files == NULL ||
72477+ (p->signal && p->signal->tty == task->signal->tty)) {
72478+ if (files != NULL)
72479+ put_files_struct(files);
72480+ continue;
72481+ }
72482+ rcu_read_lock();
72483+ fdt = files_fdtable(files);
72484+ for (i=0; i < fdt->max_fds; i++) {
72485+ file = fcheck_files(files, i);
72486+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72487+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72488+ p3 = task;
72489+ while (task_pid_nr(p3) > 0) {
72490+ if (p3 == p)
72491+ break;
72492+ p3 = p3->real_parent;
72493+ }
72494+ if (p3 == p)
72495+ break;
72496+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72497+ gr_handle_alertkill(p);
72498+ rcu_read_unlock();
72499+ put_files_struct(files);
72500+ read_unlock(&tasklist_lock);
72501+ fput(our_file);
72502+ return 0;
72503+ }
72504+ }
72505+ rcu_read_unlock();
72506+ put_files_struct(files);
72507+ } while_each_thread(p2, p);
72508+ read_unlock(&tasklist_lock);
72509+
72510+ fput(our_file);
72511+ return 1;
72512+}
72513+
72514+ssize_t
72515+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72516+{
72517+ struct gr_arg_wrapper uwrap;
72518+ unsigned char *sprole_salt = NULL;
72519+ unsigned char *sprole_sum = NULL;
72520+ int error = 0;
72521+ int error2 = 0;
72522+ size_t req_count = 0;
72523+ unsigned char oldmode = 0;
72524+
72525+ mutex_lock(&gr_dev_mutex);
72526+
72527+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72528+ error = -EPERM;
72529+ goto out;
72530+ }
72531+
72532+#ifdef CONFIG_COMPAT
72533+ pax_open_kernel();
72534+ if (is_compat_task()) {
72535+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72536+ copy_gr_arg = &copy_gr_arg_compat;
72537+ copy_acl_object_label = &copy_acl_object_label_compat;
72538+ copy_acl_subject_label = &copy_acl_subject_label_compat;
72539+ copy_acl_role_label = &copy_acl_role_label_compat;
72540+ copy_acl_ip_label = &copy_acl_ip_label_compat;
72541+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72542+ copy_role_transition = &copy_role_transition_compat;
72543+ copy_sprole_pw = &copy_sprole_pw_compat;
72544+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72545+ copy_pointer_from_array = &copy_pointer_from_array_compat;
72546+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72547+ } else {
72548+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72549+ copy_gr_arg = &copy_gr_arg_normal;
72550+ copy_acl_object_label = &copy_acl_object_label_normal;
72551+ copy_acl_subject_label = &copy_acl_subject_label_normal;
72552+ copy_acl_role_label = &copy_acl_role_label_normal;
72553+ copy_acl_ip_label = &copy_acl_ip_label_normal;
72554+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72555+ copy_role_transition = &copy_role_transition_normal;
72556+ copy_sprole_pw = &copy_sprole_pw_normal;
72557+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72558+ copy_pointer_from_array = &copy_pointer_from_array_normal;
72559+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72560+ }
72561+ pax_close_kernel();
72562+#endif
72563+
72564+ req_count = get_gr_arg_wrapper_size();
72565+
72566+ if (count != req_count) {
72567+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72568+ error = -EINVAL;
72569+ goto out;
72570+ }
72571+
72572+
72573+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72574+ gr_auth_expires = 0;
72575+ gr_auth_attempts = 0;
72576+ }
72577+
72578+ error = copy_gr_arg_wrapper(buf, &uwrap);
72579+ if (error)
72580+ goto out;
72581+
72582+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
72583+ if (error)
72584+ goto out;
72585+
72586+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72587+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72588+ time_after(gr_auth_expires, get_seconds())) {
72589+ error = -EBUSY;
72590+ goto out;
72591+ }
72592+
72593+ /* if non-root trying to do anything other than use a special role,
72594+ do not attempt authentication, do not count towards authentication
72595+ locking
72596+ */
72597+
72598+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72599+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72600+ gr_is_global_nonroot(current_uid())) {
72601+ error = -EPERM;
72602+ goto out;
72603+ }
72604+
72605+ /* ensure pw and special role name are null terminated */
72606+
72607+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72608+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72609+
72610+ /* Okay.
72611+ * We have our enough of the argument structure..(we have yet
72612+ * to copy_from_user the tables themselves) . Copy the tables
72613+ * only if we need them, i.e. for loading operations. */
72614+
72615+ switch (gr_usermode.mode) {
72616+ case GR_STATUS:
72617+ if (gr_acl_is_enabled()) {
72618+ error = 1;
72619+ if (!gr_check_secure_terminal(current))
72620+ error = 3;
72621+ } else
72622+ error = 2;
72623+ goto out;
72624+ case GR_SHUTDOWN:
72625+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72626+ stop_machine(gr_rbac_disable, NULL, NULL);
72627+ free_variables(false);
72628+ memset(&gr_usermode, 0, sizeof(gr_usermode));
72629+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72630+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72631+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72632+ } else if (gr_acl_is_enabled()) {
72633+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72634+ error = -EPERM;
72635+ } else {
72636+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72637+ error = -EAGAIN;
72638+ }
72639+ break;
72640+ case GR_ENABLE:
72641+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72642+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72643+ else {
72644+ if (gr_acl_is_enabled())
72645+ error = -EAGAIN;
72646+ else
72647+ error = error2;
72648+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72649+ }
72650+ break;
72651+ case GR_OLDRELOAD:
72652+ oldmode = 1;
72653+ case GR_RELOAD:
72654+ if (!gr_acl_is_enabled()) {
72655+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72656+ error = -EAGAIN;
72657+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72658+ error2 = gracl_reload(&gr_usermode, oldmode);
72659+ if (!error2)
72660+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72661+ else {
72662+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72663+ error = error2;
72664+ }
72665+ } else {
72666+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72667+ error = -EPERM;
72668+ }
72669+ break;
72670+ case GR_SEGVMOD:
72671+ if (unlikely(!gr_acl_is_enabled())) {
72672+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72673+ error = -EAGAIN;
72674+ break;
72675+ }
72676+
72677+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72678+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72679+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72680+ struct acl_subject_label *segvacl;
72681+ segvacl =
72682+ lookup_acl_subj_label(gr_usermode.segv_inode,
72683+ gr_usermode.segv_device,
72684+ current->role);
72685+ if (segvacl) {
72686+ segvacl->crashes = 0;
72687+ segvacl->expires = 0;
72688+ }
72689+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72690+ gr_remove_uid(gr_usermode.segv_uid);
72691+ }
72692+ } else {
72693+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72694+ error = -EPERM;
72695+ }
72696+ break;
72697+ case GR_SPROLE:
72698+ case GR_SPROLEPAM:
72699+ if (unlikely(!gr_acl_is_enabled())) {
72700+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72701+ error = -EAGAIN;
72702+ break;
72703+ }
72704+
72705+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72706+ current->role->expires = 0;
72707+ current->role->auth_attempts = 0;
72708+ }
72709+
72710+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72711+ time_after(current->role->expires, get_seconds())) {
72712+ error = -EBUSY;
72713+ goto out;
72714+ }
72715+
72716+ if (lookup_special_role_auth
72717+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72718+ && ((!sprole_salt && !sprole_sum)
72719+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72720+ char *p = "";
72721+ assign_special_role(gr_usermode.sp_role);
72722+ read_lock(&tasklist_lock);
72723+ if (current->real_parent)
72724+ p = current->real_parent->role->rolename;
72725+ read_unlock(&tasklist_lock);
72726+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72727+ p, acl_sp_role_value);
72728+ } else {
72729+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72730+ error = -EPERM;
72731+ if(!(current->role->auth_attempts++))
72732+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72733+
72734+ goto out;
72735+ }
72736+ break;
72737+ case GR_UNSPROLE:
72738+ if (unlikely(!gr_acl_is_enabled())) {
72739+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72740+ error = -EAGAIN;
72741+ break;
72742+ }
72743+
72744+ if (current->role->roletype & GR_ROLE_SPECIAL) {
72745+ char *p = "";
72746+ int i = 0;
72747+
72748+ read_lock(&tasklist_lock);
72749+ if (current->real_parent) {
72750+ p = current->real_parent->role->rolename;
72751+ i = current->real_parent->acl_role_id;
72752+ }
72753+ read_unlock(&tasklist_lock);
72754+
72755+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72756+ gr_set_acls(1);
72757+ } else {
72758+ error = -EPERM;
72759+ goto out;
72760+ }
72761+ break;
72762+ default:
72763+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72764+ error = -EINVAL;
72765+ break;
72766+ }
72767+
72768+ if (error != -EPERM)
72769+ goto out;
72770+
72771+ if(!(gr_auth_attempts++))
72772+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72773+
72774+ out:
72775+ mutex_unlock(&gr_dev_mutex);
72776+
72777+ if (!error)
72778+ error = req_count;
72779+
72780+ return error;
72781+}
72782+
72783+int
72784+gr_set_acls(const int type)
72785+{
72786+ struct task_struct *task, *task2;
72787+ struct acl_role_label *role = current->role;
72788+ struct acl_subject_label *subj;
72789+ __u16 acl_role_id = current->acl_role_id;
72790+ const struct cred *cred;
72791+ int ret;
72792+
72793+ rcu_read_lock();
72794+ read_lock(&tasklist_lock);
72795+ read_lock(&grsec_exec_file_lock);
72796+ do_each_thread(task2, task) {
72797+ /* check to see if we're called from the exit handler,
72798+ if so, only replace ACLs that have inherited the admin
72799+ ACL */
72800+
72801+ if (type && (task->role != role ||
72802+ task->acl_role_id != acl_role_id))
72803+ continue;
72804+
72805+ task->acl_role_id = 0;
72806+ task->acl_sp_role = 0;
72807+ task->inherited = 0;
72808+
72809+ if (task->exec_file) {
72810+ cred = __task_cred(task);
72811+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72812+ subj = __gr_get_subject_for_task(polstate, task, NULL);
72813+ if (subj == NULL) {
72814+ ret = -EINVAL;
72815+ read_unlock(&grsec_exec_file_lock);
72816+ read_unlock(&tasklist_lock);
72817+ rcu_read_unlock();
72818+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72819+ return ret;
72820+ }
72821+ __gr_apply_subject_to_task(polstate, task, subj);
72822+ } else {
72823+ // it's a kernel process
72824+ task->role = polstate->kernel_role;
72825+ task->acl = polstate->kernel_role->root_label;
72826+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72827+ task->acl->mode &= ~GR_PROCFIND;
72828+#endif
72829+ }
72830+ } while_each_thread(task2, task);
72831+ read_unlock(&grsec_exec_file_lock);
72832+ read_unlock(&tasklist_lock);
72833+ rcu_read_unlock();
72834+
72835+ return 0;
72836+}
72837diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72838new file mode 100644
72839index 0000000..39645c9
72840--- /dev/null
72841+++ b/grsecurity/gracl_res.c
72842@@ -0,0 +1,68 @@
72843+#include <linux/kernel.h>
72844+#include <linux/sched.h>
72845+#include <linux/gracl.h>
72846+#include <linux/grinternal.h>
72847+
72848+static const char *restab_log[] = {
72849+ [RLIMIT_CPU] = "RLIMIT_CPU",
72850+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72851+ [RLIMIT_DATA] = "RLIMIT_DATA",
72852+ [RLIMIT_STACK] = "RLIMIT_STACK",
72853+ [RLIMIT_CORE] = "RLIMIT_CORE",
72854+ [RLIMIT_RSS] = "RLIMIT_RSS",
72855+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
72856+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72857+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72858+ [RLIMIT_AS] = "RLIMIT_AS",
72859+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72860+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72861+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72862+ [RLIMIT_NICE] = "RLIMIT_NICE",
72863+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72864+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72865+ [GR_CRASH_RES] = "RLIMIT_CRASH"
72866+};
72867+
72868+void
72869+gr_log_resource(const struct task_struct *task,
72870+ const int res, const unsigned long wanted, const int gt)
72871+{
72872+ const struct cred *cred;
72873+ unsigned long rlim;
72874+
72875+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
72876+ return;
72877+
72878+ // not yet supported resource
72879+ if (unlikely(!restab_log[res]))
72880+ return;
72881+
72882+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72883+ rlim = task_rlimit_max(task, res);
72884+ else
72885+ rlim = task_rlimit(task, res);
72886+
72887+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72888+ return;
72889+
72890+ rcu_read_lock();
72891+ cred = __task_cred(task);
72892+
72893+ if (res == RLIMIT_NPROC &&
72894+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72895+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72896+ goto out_rcu_unlock;
72897+ else if (res == RLIMIT_MEMLOCK &&
72898+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72899+ goto out_rcu_unlock;
72900+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72901+ goto out_rcu_unlock;
72902+ rcu_read_unlock();
72903+
72904+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72905+
72906+ return;
72907+out_rcu_unlock:
72908+ rcu_read_unlock();
72909+ return;
72910+}
72911diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72912new file mode 100644
72913index 0000000..2040e61
72914--- /dev/null
72915+++ b/grsecurity/gracl_segv.c
72916@@ -0,0 +1,313 @@
72917+#include <linux/kernel.h>
72918+#include <linux/mm.h>
72919+#include <asm/uaccess.h>
72920+#include <asm/errno.h>
72921+#include <asm/mman.h>
72922+#include <net/sock.h>
72923+#include <linux/file.h>
72924+#include <linux/fs.h>
72925+#include <linux/net.h>
72926+#include <linux/in.h>
72927+#include <linux/slab.h>
72928+#include <linux/types.h>
72929+#include <linux/sched.h>
72930+#include <linux/timer.h>
72931+#include <linux/gracl.h>
72932+#include <linux/grsecurity.h>
72933+#include <linux/grinternal.h>
72934+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72935+#include <linux/magic.h>
72936+#include <linux/pagemap.h>
72937+#include "../fs/btrfs/async-thread.h"
72938+#include "../fs/btrfs/ctree.h"
72939+#include "../fs/btrfs/btrfs_inode.h"
72940+#endif
72941+
72942+static struct crash_uid *uid_set;
72943+static unsigned short uid_used;
72944+static DEFINE_SPINLOCK(gr_uid_lock);
72945+extern rwlock_t gr_inode_lock;
72946+extern struct acl_subject_label *
72947+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72948+ struct acl_role_label *role);
72949+
72950+static inline dev_t __get_dev(const struct dentry *dentry)
72951+{
72952+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72953+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72954+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
72955+ else
72956+#endif
72957+ return dentry->d_sb->s_dev;
72958+}
72959+
72960+int
72961+gr_init_uidset(void)
72962+{
72963+ uid_set =
72964+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
72965+ uid_used = 0;
72966+
72967+ return uid_set ? 1 : 0;
72968+}
72969+
72970+void
72971+gr_free_uidset(void)
72972+{
72973+ if (uid_set) {
72974+ struct crash_uid *tmpset;
72975+ spin_lock(&gr_uid_lock);
72976+ tmpset = uid_set;
72977+ uid_set = NULL;
72978+ uid_used = 0;
72979+ spin_unlock(&gr_uid_lock);
72980+ if (tmpset)
72981+ kfree(tmpset);
72982+ }
72983+
72984+ return;
72985+}
72986+
72987+int
72988+gr_find_uid(const uid_t uid)
72989+{
72990+ struct crash_uid *tmp = uid_set;
72991+ uid_t buid;
72992+ int low = 0, high = uid_used - 1, mid;
72993+
72994+ while (high >= low) {
72995+ mid = (low + high) >> 1;
72996+ buid = tmp[mid].uid;
72997+ if (buid == uid)
72998+ return mid;
72999+ if (buid > uid)
73000+ high = mid - 1;
73001+ if (buid < uid)
73002+ low = mid + 1;
73003+ }
73004+
73005+ return -1;
73006+}
73007+
73008+static __inline__ void
73009+gr_insertsort(void)
73010+{
73011+ unsigned short i, j;
73012+ struct crash_uid index;
73013+
73014+ for (i = 1; i < uid_used; i++) {
73015+ index = uid_set[i];
73016+ j = i;
73017+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73018+ uid_set[j] = uid_set[j - 1];
73019+ j--;
73020+ }
73021+ uid_set[j] = index;
73022+ }
73023+
73024+ return;
73025+}
73026+
73027+static __inline__ void
73028+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73029+{
73030+ int loc;
73031+ uid_t uid = GR_GLOBAL_UID(kuid);
73032+
73033+ if (uid_used == GR_UIDTABLE_MAX)
73034+ return;
73035+
73036+ loc = gr_find_uid(uid);
73037+
73038+ if (loc >= 0) {
73039+ uid_set[loc].expires = expires;
73040+ return;
73041+ }
73042+
73043+ uid_set[uid_used].uid = uid;
73044+ uid_set[uid_used].expires = expires;
73045+ uid_used++;
73046+
73047+ gr_insertsort();
73048+
73049+ return;
73050+}
73051+
73052+void
73053+gr_remove_uid(const unsigned short loc)
73054+{
73055+ unsigned short i;
73056+
73057+ for (i = loc + 1; i < uid_used; i++)
73058+ uid_set[i - 1] = uid_set[i];
73059+
73060+ uid_used--;
73061+
73062+ return;
73063+}
73064+
73065+int
73066+gr_check_crash_uid(const kuid_t kuid)
73067+{
73068+ int loc;
73069+ int ret = 0;
73070+ uid_t uid;
73071+
73072+ if (unlikely(!gr_acl_is_enabled()))
73073+ return 0;
73074+
73075+ uid = GR_GLOBAL_UID(kuid);
73076+
73077+ spin_lock(&gr_uid_lock);
73078+ loc = gr_find_uid(uid);
73079+
73080+ if (loc < 0)
73081+ goto out_unlock;
73082+
73083+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
73084+ gr_remove_uid(loc);
73085+ else
73086+ ret = 1;
73087+
73088+out_unlock:
73089+ spin_unlock(&gr_uid_lock);
73090+ return ret;
73091+}
73092+
73093+static __inline__ int
73094+proc_is_setxid(const struct cred *cred)
73095+{
73096+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73097+ !uid_eq(cred->uid, cred->fsuid))
73098+ return 1;
73099+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73100+ !gid_eq(cred->gid, cred->fsgid))
73101+ return 1;
73102+
73103+ return 0;
73104+}
73105+
73106+extern int gr_fake_force_sig(int sig, struct task_struct *t);
73107+
73108+void
73109+gr_handle_crash(struct task_struct *task, const int sig)
73110+{
73111+ struct acl_subject_label *curr;
73112+ struct task_struct *tsk, *tsk2;
73113+ const struct cred *cred;
73114+ const struct cred *cred2;
73115+
73116+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73117+ return;
73118+
73119+ if (unlikely(!gr_acl_is_enabled()))
73120+ return;
73121+
73122+ curr = task->acl;
73123+
73124+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
73125+ return;
73126+
73127+ if (time_before_eq(curr->expires, get_seconds())) {
73128+ curr->expires = 0;
73129+ curr->crashes = 0;
73130+ }
73131+
73132+ curr->crashes++;
73133+
73134+ if (!curr->expires)
73135+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73136+
73137+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73138+ time_after(curr->expires, get_seconds())) {
73139+ rcu_read_lock();
73140+ cred = __task_cred(task);
73141+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73142+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73143+ spin_lock(&gr_uid_lock);
73144+ gr_insert_uid(cred->uid, curr->expires);
73145+ spin_unlock(&gr_uid_lock);
73146+ curr->expires = 0;
73147+ curr->crashes = 0;
73148+ read_lock(&tasklist_lock);
73149+ do_each_thread(tsk2, tsk) {
73150+ cred2 = __task_cred(tsk);
73151+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
73152+ gr_fake_force_sig(SIGKILL, tsk);
73153+ } while_each_thread(tsk2, tsk);
73154+ read_unlock(&tasklist_lock);
73155+ } else {
73156+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73157+ read_lock(&tasklist_lock);
73158+ read_lock(&grsec_exec_file_lock);
73159+ do_each_thread(tsk2, tsk) {
73160+ if (likely(tsk != task)) {
73161+ // if this thread has the same subject as the one that triggered
73162+ // RES_CRASH and it's the same binary, kill it
73163+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73164+ gr_fake_force_sig(SIGKILL, tsk);
73165+ }
73166+ } while_each_thread(tsk2, tsk);
73167+ read_unlock(&grsec_exec_file_lock);
73168+ read_unlock(&tasklist_lock);
73169+ }
73170+ rcu_read_unlock();
73171+ }
73172+
73173+ return;
73174+}
73175+
73176+int
73177+gr_check_crash_exec(const struct file *filp)
73178+{
73179+ struct acl_subject_label *curr;
73180+
73181+ if (unlikely(!gr_acl_is_enabled()))
73182+ return 0;
73183+
73184+ read_lock(&gr_inode_lock);
73185+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73186+ __get_dev(filp->f_path.dentry),
73187+ current->role);
73188+ read_unlock(&gr_inode_lock);
73189+
73190+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73191+ (!curr->crashes && !curr->expires))
73192+ return 0;
73193+
73194+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73195+ time_after(curr->expires, get_seconds()))
73196+ return 1;
73197+ else if (time_before_eq(curr->expires, get_seconds())) {
73198+ curr->crashes = 0;
73199+ curr->expires = 0;
73200+ }
73201+
73202+ return 0;
73203+}
73204+
73205+void
73206+gr_handle_alertkill(struct task_struct *task)
73207+{
73208+ struct acl_subject_label *curracl;
73209+ __u32 curr_ip;
73210+ struct task_struct *p, *p2;
73211+
73212+ if (unlikely(!gr_acl_is_enabled()))
73213+ return;
73214+
73215+ curracl = task->acl;
73216+ curr_ip = task->signal->curr_ip;
73217+
73218+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73219+ read_lock(&tasklist_lock);
73220+ do_each_thread(p2, p) {
73221+ if (p->signal->curr_ip == curr_ip)
73222+ gr_fake_force_sig(SIGKILL, p);
73223+ } while_each_thread(p2, p);
73224+ read_unlock(&tasklist_lock);
73225+ } else if (curracl->mode & GR_KILLPROC)
73226+ gr_fake_force_sig(SIGKILL, task);
73227+
73228+ return;
73229+}
73230diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73231new file mode 100644
73232index 0000000..98011b0
73233--- /dev/null
73234+++ b/grsecurity/gracl_shm.c
73235@@ -0,0 +1,40 @@
73236+#include <linux/kernel.h>
73237+#include <linux/mm.h>
73238+#include <linux/sched.h>
73239+#include <linux/file.h>
73240+#include <linux/ipc.h>
73241+#include <linux/gracl.h>
73242+#include <linux/grsecurity.h>
73243+#include <linux/grinternal.h>
73244+
73245+int
73246+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73247+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73248+{
73249+ struct task_struct *task;
73250+
73251+ if (!gr_acl_is_enabled())
73252+ return 1;
73253+
73254+ rcu_read_lock();
73255+ read_lock(&tasklist_lock);
73256+
73257+ task = find_task_by_vpid(shm_cprid);
73258+
73259+ if (unlikely(!task))
73260+ task = find_task_by_vpid(shm_lapid);
73261+
73262+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73263+ (task_pid_nr(task) == shm_lapid)) &&
73264+ (task->acl->mode & GR_PROTSHM) &&
73265+ (task->acl != current->acl))) {
73266+ read_unlock(&tasklist_lock);
73267+ rcu_read_unlock();
73268+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73269+ return 0;
73270+ }
73271+ read_unlock(&tasklist_lock);
73272+ rcu_read_unlock();
73273+
73274+ return 1;
73275+}
73276diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73277new file mode 100644
73278index 0000000..bc0be01
73279--- /dev/null
73280+++ b/grsecurity/grsec_chdir.c
73281@@ -0,0 +1,19 @@
73282+#include <linux/kernel.h>
73283+#include <linux/sched.h>
73284+#include <linux/fs.h>
73285+#include <linux/file.h>
73286+#include <linux/grsecurity.h>
73287+#include <linux/grinternal.h>
73288+
73289+void
73290+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73291+{
73292+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73293+ if ((grsec_enable_chdir && grsec_enable_group &&
73294+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73295+ !grsec_enable_group)) {
73296+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73297+ }
73298+#endif
73299+ return;
73300+}
73301diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73302new file mode 100644
73303index 0000000..baa635c
73304--- /dev/null
73305+++ b/grsecurity/grsec_chroot.c
73306@@ -0,0 +1,387 @@
73307+#include <linux/kernel.h>
73308+#include <linux/module.h>
73309+#include <linux/sched.h>
73310+#include <linux/file.h>
73311+#include <linux/fs.h>
73312+#include <linux/mount.h>
73313+#include <linux/types.h>
73314+#include "../fs/mount.h"
73315+#include <linux/grsecurity.h>
73316+#include <linux/grinternal.h>
73317+
73318+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73319+int gr_init_ran;
73320+#endif
73321+
73322+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73323+{
73324+#ifdef CONFIG_GRKERNSEC
73325+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73326+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73327+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73328+ && gr_init_ran
73329+#endif
73330+ )
73331+ task->gr_is_chrooted = 1;
73332+ else {
73333+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73334+ if (task_pid_nr(task) == 1 && !gr_init_ran)
73335+ gr_init_ran = 1;
73336+#endif
73337+ task->gr_is_chrooted = 0;
73338+ }
73339+
73340+ task->gr_chroot_dentry = path->dentry;
73341+#endif
73342+ return;
73343+}
73344+
73345+void gr_clear_chroot_entries(struct task_struct *task)
73346+{
73347+#ifdef CONFIG_GRKERNSEC
73348+ task->gr_is_chrooted = 0;
73349+ task->gr_chroot_dentry = NULL;
73350+#endif
73351+ return;
73352+}
73353+
73354+int
73355+gr_handle_chroot_unix(const pid_t pid)
73356+{
73357+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73358+ struct task_struct *p;
73359+
73360+ if (unlikely(!grsec_enable_chroot_unix))
73361+ return 1;
73362+
73363+ if (likely(!proc_is_chrooted(current)))
73364+ return 1;
73365+
73366+ rcu_read_lock();
73367+ read_lock(&tasklist_lock);
73368+ p = find_task_by_vpid_unrestricted(pid);
73369+ if (unlikely(p && !have_same_root(current, p))) {
73370+ read_unlock(&tasklist_lock);
73371+ rcu_read_unlock();
73372+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73373+ return 0;
73374+ }
73375+ read_unlock(&tasklist_lock);
73376+ rcu_read_unlock();
73377+#endif
73378+ return 1;
73379+}
73380+
73381+int
73382+gr_handle_chroot_nice(void)
73383+{
73384+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73385+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73386+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73387+ return -EPERM;
73388+ }
73389+#endif
73390+ return 0;
73391+}
73392+
73393+int
73394+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73395+{
73396+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73397+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73398+ && proc_is_chrooted(current)) {
73399+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73400+ return -EACCES;
73401+ }
73402+#endif
73403+ return 0;
73404+}
73405+
73406+int
73407+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73408+{
73409+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73410+ struct task_struct *p;
73411+ int ret = 0;
73412+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73413+ return ret;
73414+
73415+ read_lock(&tasklist_lock);
73416+ do_each_pid_task(pid, type, p) {
73417+ if (!have_same_root(current, p)) {
73418+ ret = 1;
73419+ goto out;
73420+ }
73421+ } while_each_pid_task(pid, type, p);
73422+out:
73423+ read_unlock(&tasklist_lock);
73424+ return ret;
73425+#endif
73426+ return 0;
73427+}
73428+
73429+int
73430+gr_pid_is_chrooted(struct task_struct *p)
73431+{
73432+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73433+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73434+ return 0;
73435+
73436+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73437+ !have_same_root(current, p)) {
73438+ return 1;
73439+ }
73440+#endif
73441+ return 0;
73442+}
73443+
73444+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73445+
73446+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73447+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73448+{
73449+ struct path path, currentroot;
73450+ int ret = 0;
73451+
73452+ path.dentry = (struct dentry *)u_dentry;
73453+ path.mnt = (struct vfsmount *)u_mnt;
73454+ get_fs_root(current->fs, &currentroot);
73455+ if (path_is_under(&path, &currentroot))
73456+ ret = 1;
73457+ path_put(&currentroot);
73458+
73459+ return ret;
73460+}
73461+#endif
73462+
73463+int
73464+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73465+{
73466+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73467+ if (!grsec_enable_chroot_fchdir)
73468+ return 1;
73469+
73470+ if (!proc_is_chrooted(current))
73471+ return 1;
73472+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73473+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73474+ return 0;
73475+ }
73476+#endif
73477+ return 1;
73478+}
73479+
73480+int
73481+gr_chroot_fhandle(void)
73482+{
73483+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73484+ if (!grsec_enable_chroot_fchdir)
73485+ return 1;
73486+
73487+ if (!proc_is_chrooted(current))
73488+ return 1;
73489+ else {
73490+ gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
73491+ return 0;
73492+ }
73493+#endif
73494+ return 1;
73495+}
73496+
73497+int
73498+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73499+ const time_t shm_createtime)
73500+{
73501+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73502+ struct task_struct *p;
73503+ time_t starttime;
73504+
73505+ if (unlikely(!grsec_enable_chroot_shmat))
73506+ return 1;
73507+
73508+ if (likely(!proc_is_chrooted(current)))
73509+ return 1;
73510+
73511+ rcu_read_lock();
73512+ read_lock(&tasklist_lock);
73513+
73514+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73515+ starttime = p->start_time.tv_sec;
73516+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73517+ if (have_same_root(current, p)) {
73518+ goto allow;
73519+ } else {
73520+ read_unlock(&tasklist_lock);
73521+ rcu_read_unlock();
73522+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73523+ return 0;
73524+ }
73525+ }
73526+ /* creator exited, pid reuse, fall through to next check */
73527+ }
73528+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73529+ if (unlikely(!have_same_root(current, p))) {
73530+ read_unlock(&tasklist_lock);
73531+ rcu_read_unlock();
73532+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73533+ return 0;
73534+ }
73535+ }
73536+
73537+allow:
73538+ read_unlock(&tasklist_lock);
73539+ rcu_read_unlock();
73540+#endif
73541+ return 1;
73542+}
73543+
73544+void
73545+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73546+{
73547+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73548+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73549+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73550+#endif
73551+ return;
73552+}
73553+
73554+int
73555+gr_handle_chroot_mknod(const struct dentry *dentry,
73556+ const struct vfsmount *mnt, const int mode)
73557+{
73558+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73559+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73560+ proc_is_chrooted(current)) {
73561+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73562+ return -EPERM;
73563+ }
73564+#endif
73565+ return 0;
73566+}
73567+
73568+int
73569+gr_handle_chroot_mount(const struct dentry *dentry,
73570+ const struct vfsmount *mnt, const char *dev_name)
73571+{
73572+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73573+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73574+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73575+ return -EPERM;
73576+ }
73577+#endif
73578+ return 0;
73579+}
73580+
73581+int
73582+gr_handle_chroot_pivot(void)
73583+{
73584+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73585+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73586+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73587+ return -EPERM;
73588+ }
73589+#endif
73590+ return 0;
73591+}
73592+
73593+int
73594+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73595+{
73596+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73597+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73598+ !gr_is_outside_chroot(dentry, mnt)) {
73599+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73600+ return -EPERM;
73601+ }
73602+#endif
73603+ return 0;
73604+}
73605+
73606+extern const char *captab_log[];
73607+extern int captab_log_entries;
73608+
73609+int
73610+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73611+{
73612+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73613+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73614+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73615+ if (cap_raised(chroot_caps, cap)) {
73616+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73617+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73618+ }
73619+ return 0;
73620+ }
73621+ }
73622+#endif
73623+ return 1;
73624+}
73625+
73626+int
73627+gr_chroot_is_capable(const int cap)
73628+{
73629+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73630+ return gr_task_chroot_is_capable(current, current_cred(), cap);
73631+#endif
73632+ return 1;
73633+}
73634+
73635+int
73636+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73637+{
73638+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73639+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73640+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73641+ if (cap_raised(chroot_caps, cap)) {
73642+ return 0;
73643+ }
73644+ }
73645+#endif
73646+ return 1;
73647+}
73648+
73649+int
73650+gr_chroot_is_capable_nolog(const int cap)
73651+{
73652+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73653+ return gr_task_chroot_is_capable_nolog(current, cap);
73654+#endif
73655+ return 1;
73656+}
73657+
73658+int
73659+gr_handle_chroot_sysctl(const int op)
73660+{
73661+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73662+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73663+ proc_is_chrooted(current))
73664+ return -EACCES;
73665+#endif
73666+ return 0;
73667+}
73668+
73669+void
73670+gr_handle_chroot_chdir(const struct path *path)
73671+{
73672+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73673+ if (grsec_enable_chroot_chdir)
73674+ set_fs_pwd(current->fs, path);
73675+#endif
73676+ return;
73677+}
73678+
73679+int
73680+gr_handle_chroot_chmod(const struct dentry *dentry,
73681+ const struct vfsmount *mnt, const int mode)
73682+{
73683+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73684+ /* allow chmod +s on directories, but not files */
73685+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73686+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73687+ proc_is_chrooted(current)) {
73688+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73689+ return -EPERM;
73690+ }
73691+#endif
73692+ return 0;
73693+}
73694diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73695new file mode 100644
73696index 0000000..de31e65
73697--- /dev/null
73698+++ b/grsecurity/grsec_disabled.c
73699@@ -0,0 +1,434 @@
73700+#include <linux/kernel.h>
73701+#include <linux/module.h>
73702+#include <linux/sched.h>
73703+#include <linux/file.h>
73704+#include <linux/fs.h>
73705+#include <linux/kdev_t.h>
73706+#include <linux/net.h>
73707+#include <linux/in.h>
73708+#include <linux/ip.h>
73709+#include <linux/skbuff.h>
73710+#include <linux/sysctl.h>
73711+
73712+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73713+void
73714+pax_set_initial_flags(struct linux_binprm *bprm)
73715+{
73716+ return;
73717+}
73718+#endif
73719+
73720+#ifdef CONFIG_SYSCTL
73721+__u32
73722+gr_handle_sysctl(const struct ctl_table * table, const int op)
73723+{
73724+ return 0;
73725+}
73726+#endif
73727+
73728+#ifdef CONFIG_TASKSTATS
73729+int gr_is_taskstats_denied(int pid)
73730+{
73731+ return 0;
73732+}
73733+#endif
73734+
73735+int
73736+gr_acl_is_enabled(void)
73737+{
73738+ return 0;
73739+}
73740+
73741+void
73742+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73743+{
73744+ return;
73745+}
73746+
73747+int
73748+gr_handle_rawio(const struct inode *inode)
73749+{
73750+ return 0;
73751+}
73752+
73753+void
73754+gr_acl_handle_psacct(struct task_struct *task, const long code)
73755+{
73756+ return;
73757+}
73758+
73759+int
73760+gr_handle_ptrace(struct task_struct *task, const long request)
73761+{
73762+ return 0;
73763+}
73764+
73765+int
73766+gr_handle_proc_ptrace(struct task_struct *task)
73767+{
73768+ return 0;
73769+}
73770+
73771+int
73772+gr_set_acls(const int type)
73773+{
73774+ return 0;
73775+}
73776+
73777+int
73778+gr_check_hidden_task(const struct task_struct *tsk)
73779+{
73780+ return 0;
73781+}
73782+
73783+int
73784+gr_check_protected_task(const struct task_struct *task)
73785+{
73786+ return 0;
73787+}
73788+
73789+int
73790+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73791+{
73792+ return 0;
73793+}
73794+
73795+void
73796+gr_copy_label(struct task_struct *tsk)
73797+{
73798+ return;
73799+}
73800+
73801+void
73802+gr_set_pax_flags(struct task_struct *task)
73803+{
73804+ return;
73805+}
73806+
73807+int
73808+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73809+ const int unsafe_share)
73810+{
73811+ return 0;
73812+}
73813+
73814+void
73815+gr_handle_delete(const ino_t ino, const dev_t dev)
73816+{
73817+ return;
73818+}
73819+
73820+void
73821+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73822+{
73823+ return;
73824+}
73825+
73826+void
73827+gr_handle_crash(struct task_struct *task, const int sig)
73828+{
73829+ return;
73830+}
73831+
73832+int
73833+gr_check_crash_exec(const struct file *filp)
73834+{
73835+ return 0;
73836+}
73837+
73838+int
73839+gr_check_crash_uid(const kuid_t uid)
73840+{
73841+ return 0;
73842+}
73843+
73844+void
73845+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73846+ struct dentry *old_dentry,
73847+ struct dentry *new_dentry,
73848+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
73849+{
73850+ return;
73851+}
73852+
73853+int
73854+gr_search_socket(const int family, const int type, const int protocol)
73855+{
73856+ return 1;
73857+}
73858+
73859+int
73860+gr_search_connectbind(const int mode, const struct socket *sock,
73861+ const struct sockaddr_in *addr)
73862+{
73863+ return 0;
73864+}
73865+
73866+void
73867+gr_handle_alertkill(struct task_struct *task)
73868+{
73869+ return;
73870+}
73871+
73872+__u32
73873+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73874+{
73875+ return 1;
73876+}
73877+
73878+__u32
73879+gr_acl_handle_hidden_file(const struct dentry * dentry,
73880+ const struct vfsmount * mnt)
73881+{
73882+ return 1;
73883+}
73884+
73885+__u32
73886+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73887+ int acc_mode)
73888+{
73889+ return 1;
73890+}
73891+
73892+__u32
73893+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73894+{
73895+ return 1;
73896+}
73897+
73898+__u32
73899+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73900+{
73901+ return 1;
73902+}
73903+
73904+int
73905+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73906+ unsigned int *vm_flags)
73907+{
73908+ return 1;
73909+}
73910+
73911+__u32
73912+gr_acl_handle_truncate(const struct dentry * dentry,
73913+ const struct vfsmount * mnt)
73914+{
73915+ return 1;
73916+}
73917+
73918+__u32
73919+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73920+{
73921+ return 1;
73922+}
73923+
73924+__u32
73925+gr_acl_handle_access(const struct dentry * dentry,
73926+ const struct vfsmount * mnt, const int fmode)
73927+{
73928+ return 1;
73929+}
73930+
73931+__u32
73932+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73933+ umode_t *mode)
73934+{
73935+ return 1;
73936+}
73937+
73938+__u32
73939+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73940+{
73941+ return 1;
73942+}
73943+
73944+__u32
73945+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73946+{
73947+ return 1;
73948+}
73949+
73950+__u32
73951+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73952+{
73953+ return 1;
73954+}
73955+
73956+void
73957+grsecurity_init(void)
73958+{
73959+ return;
73960+}
73961+
73962+umode_t gr_acl_umask(void)
73963+{
73964+ return 0;
73965+}
73966+
73967+__u32
73968+gr_acl_handle_mknod(const struct dentry * new_dentry,
73969+ const struct dentry * parent_dentry,
73970+ const struct vfsmount * parent_mnt,
73971+ const int mode)
73972+{
73973+ return 1;
73974+}
73975+
73976+__u32
73977+gr_acl_handle_mkdir(const struct dentry * new_dentry,
73978+ const struct dentry * parent_dentry,
73979+ const struct vfsmount * parent_mnt)
73980+{
73981+ return 1;
73982+}
73983+
73984+__u32
73985+gr_acl_handle_symlink(const struct dentry * new_dentry,
73986+ const struct dentry * parent_dentry,
73987+ const struct vfsmount * parent_mnt, const struct filename *from)
73988+{
73989+ return 1;
73990+}
73991+
73992+__u32
73993+gr_acl_handle_link(const struct dentry * new_dentry,
73994+ const struct dentry * parent_dentry,
73995+ const struct vfsmount * parent_mnt,
73996+ const struct dentry * old_dentry,
73997+ const struct vfsmount * old_mnt, const struct filename *to)
73998+{
73999+ return 1;
74000+}
74001+
74002+int
74003+gr_acl_handle_rename(const struct dentry *new_dentry,
74004+ const struct dentry *parent_dentry,
74005+ const struct vfsmount *parent_mnt,
74006+ const struct dentry *old_dentry,
74007+ const struct inode *old_parent_inode,
74008+ const struct vfsmount *old_mnt, const struct filename *newname,
74009+ unsigned int flags)
74010+{
74011+ return 0;
74012+}
74013+
74014+int
74015+gr_acl_handle_filldir(const struct file *file, const char *name,
74016+ const int namelen, const ino_t ino)
74017+{
74018+ return 1;
74019+}
74020+
74021+int
74022+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74023+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
74024+{
74025+ return 1;
74026+}
74027+
74028+int
74029+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74030+{
74031+ return 0;
74032+}
74033+
74034+int
74035+gr_search_accept(const struct socket *sock)
74036+{
74037+ return 0;
74038+}
74039+
74040+int
74041+gr_search_listen(const struct socket *sock)
74042+{
74043+ return 0;
74044+}
74045+
74046+int
74047+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74048+{
74049+ return 0;
74050+}
74051+
74052+__u32
74053+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74054+{
74055+ return 1;
74056+}
74057+
74058+__u32
74059+gr_acl_handle_creat(const struct dentry * dentry,
74060+ const struct dentry * p_dentry,
74061+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74062+ const int imode)
74063+{
74064+ return 1;
74065+}
74066+
74067+void
74068+gr_acl_handle_exit(void)
74069+{
74070+ return;
74071+}
74072+
74073+int
74074+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74075+{
74076+ return 1;
74077+}
74078+
74079+void
74080+gr_set_role_label(const kuid_t uid, const kgid_t gid)
74081+{
74082+ return;
74083+}
74084+
74085+int
74086+gr_acl_handle_procpidmem(const struct task_struct *task)
74087+{
74088+ return 0;
74089+}
74090+
74091+int
74092+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74093+{
74094+ return 0;
74095+}
74096+
74097+int
74098+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74099+{
74100+ return 0;
74101+}
74102+
74103+int
74104+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74105+{
74106+ return 0;
74107+}
74108+
74109+int
74110+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74111+{
74112+ return 0;
74113+}
74114+
74115+int gr_acl_enable_at_secure(void)
74116+{
74117+ return 0;
74118+}
74119+
74120+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74121+{
74122+ return dentry->d_sb->s_dev;
74123+}
74124+
74125+void gr_put_exec_file(struct task_struct *task)
74126+{
74127+ return;
74128+}
74129+
74130+#ifdef CONFIG_SECURITY
74131+EXPORT_SYMBOL_GPL(gr_check_user_change);
74132+EXPORT_SYMBOL_GPL(gr_check_group_change);
74133+#endif
74134diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74135new file mode 100644
74136index 0000000..f35f454
74137--- /dev/null
74138+++ b/grsecurity/grsec_exec.c
74139@@ -0,0 +1,187 @@
74140+#include <linux/kernel.h>
74141+#include <linux/sched.h>
74142+#include <linux/file.h>
74143+#include <linux/binfmts.h>
74144+#include <linux/fs.h>
74145+#include <linux/types.h>
74146+#include <linux/grdefs.h>
74147+#include <linux/grsecurity.h>
74148+#include <linux/grinternal.h>
74149+#include <linux/capability.h>
74150+#include <linux/module.h>
74151+#include <linux/compat.h>
74152+
74153+#include <asm/uaccess.h>
74154+
74155+#ifdef CONFIG_GRKERNSEC_EXECLOG
74156+static char gr_exec_arg_buf[132];
74157+static DEFINE_MUTEX(gr_exec_arg_mutex);
74158+#endif
74159+
74160+struct user_arg_ptr {
74161+#ifdef CONFIG_COMPAT
74162+ bool is_compat;
74163+#endif
74164+ union {
74165+ const char __user *const __user *native;
74166+#ifdef CONFIG_COMPAT
74167+ const compat_uptr_t __user *compat;
74168+#endif
74169+ } ptr;
74170+};
74171+
74172+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74173+
74174+void
74175+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74176+{
74177+#ifdef CONFIG_GRKERNSEC_EXECLOG
74178+ char *grarg = gr_exec_arg_buf;
74179+ unsigned int i, x, execlen = 0;
74180+ char c;
74181+
74182+ if (!((grsec_enable_execlog && grsec_enable_group &&
74183+ in_group_p(grsec_audit_gid))
74184+ || (grsec_enable_execlog && !grsec_enable_group)))
74185+ return;
74186+
74187+ mutex_lock(&gr_exec_arg_mutex);
74188+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
74189+
74190+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
74191+ const char __user *p;
74192+ unsigned int len;
74193+
74194+ p = get_user_arg_ptr(argv, i);
74195+ if (IS_ERR(p))
74196+ goto log;
74197+
74198+ len = strnlen_user(p, 128 - execlen);
74199+ if (len > 128 - execlen)
74200+ len = 128 - execlen;
74201+ else if (len > 0)
74202+ len--;
74203+ if (copy_from_user(grarg + execlen, p, len))
74204+ goto log;
74205+
74206+ /* rewrite unprintable characters */
74207+ for (x = 0; x < len; x++) {
74208+ c = *(grarg + execlen + x);
74209+ if (c < 32 || c > 126)
74210+ *(grarg + execlen + x) = ' ';
74211+ }
74212+
74213+ execlen += len;
74214+ *(grarg + execlen) = ' ';
74215+ *(grarg + execlen + 1) = '\0';
74216+ execlen++;
74217+ }
74218+
74219+ log:
74220+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74221+ bprm->file->f_path.mnt, grarg);
74222+ mutex_unlock(&gr_exec_arg_mutex);
74223+#endif
74224+ return;
74225+}
74226+
74227+#ifdef CONFIG_GRKERNSEC
74228+extern int gr_acl_is_capable(const int cap);
74229+extern int gr_acl_is_capable_nolog(const int cap);
74230+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74231+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74232+extern int gr_chroot_is_capable(const int cap);
74233+extern int gr_chroot_is_capable_nolog(const int cap);
74234+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74235+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74236+#endif
74237+
74238+const char *captab_log[] = {
74239+ "CAP_CHOWN",
74240+ "CAP_DAC_OVERRIDE",
74241+ "CAP_DAC_READ_SEARCH",
74242+ "CAP_FOWNER",
74243+ "CAP_FSETID",
74244+ "CAP_KILL",
74245+ "CAP_SETGID",
74246+ "CAP_SETUID",
74247+ "CAP_SETPCAP",
74248+ "CAP_LINUX_IMMUTABLE",
74249+ "CAP_NET_BIND_SERVICE",
74250+ "CAP_NET_BROADCAST",
74251+ "CAP_NET_ADMIN",
74252+ "CAP_NET_RAW",
74253+ "CAP_IPC_LOCK",
74254+ "CAP_IPC_OWNER",
74255+ "CAP_SYS_MODULE",
74256+ "CAP_SYS_RAWIO",
74257+ "CAP_SYS_CHROOT",
74258+ "CAP_SYS_PTRACE",
74259+ "CAP_SYS_PACCT",
74260+ "CAP_SYS_ADMIN",
74261+ "CAP_SYS_BOOT",
74262+ "CAP_SYS_NICE",
74263+ "CAP_SYS_RESOURCE",
74264+ "CAP_SYS_TIME",
74265+ "CAP_SYS_TTY_CONFIG",
74266+ "CAP_MKNOD",
74267+ "CAP_LEASE",
74268+ "CAP_AUDIT_WRITE",
74269+ "CAP_AUDIT_CONTROL",
74270+ "CAP_SETFCAP",
74271+ "CAP_MAC_OVERRIDE",
74272+ "CAP_MAC_ADMIN",
74273+ "CAP_SYSLOG",
74274+ "CAP_WAKE_ALARM"
74275+};
74276+
74277+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74278+
74279+int gr_is_capable(const int cap)
74280+{
74281+#ifdef CONFIG_GRKERNSEC
74282+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74283+ return 1;
74284+ return 0;
74285+#else
74286+ return 1;
74287+#endif
74288+}
74289+
74290+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74291+{
74292+#ifdef CONFIG_GRKERNSEC
74293+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74294+ return 1;
74295+ return 0;
74296+#else
74297+ return 1;
74298+#endif
74299+}
74300+
74301+int gr_is_capable_nolog(const int cap)
74302+{
74303+#ifdef CONFIG_GRKERNSEC
74304+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74305+ return 1;
74306+ return 0;
74307+#else
74308+ return 1;
74309+#endif
74310+}
74311+
74312+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74313+{
74314+#ifdef CONFIG_GRKERNSEC
74315+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74316+ return 1;
74317+ return 0;
74318+#else
74319+ return 1;
74320+#endif
74321+}
74322+
74323+EXPORT_SYMBOL_GPL(gr_is_capable);
74324+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74325+EXPORT_SYMBOL_GPL(gr_task_is_capable);
74326+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74327diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74328new file mode 100644
74329index 0000000..06cc6ea
74330--- /dev/null
74331+++ b/grsecurity/grsec_fifo.c
74332@@ -0,0 +1,24 @@
74333+#include <linux/kernel.h>
74334+#include <linux/sched.h>
74335+#include <linux/fs.h>
74336+#include <linux/file.h>
74337+#include <linux/grinternal.h>
74338+
74339+int
74340+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74341+ const struct dentry *dir, const int flag, const int acc_mode)
74342+{
74343+#ifdef CONFIG_GRKERNSEC_FIFO
74344+ const struct cred *cred = current_cred();
74345+
74346+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74347+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74348+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74349+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74350+ if (!inode_permission(dentry->d_inode, acc_mode))
74351+ 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));
74352+ return -EACCES;
74353+ }
74354+#endif
74355+ return 0;
74356+}
74357diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74358new file mode 100644
74359index 0000000..8ca18bf
74360--- /dev/null
74361+++ b/grsecurity/grsec_fork.c
74362@@ -0,0 +1,23 @@
74363+#include <linux/kernel.h>
74364+#include <linux/sched.h>
74365+#include <linux/grsecurity.h>
74366+#include <linux/grinternal.h>
74367+#include <linux/errno.h>
74368+
74369+void
74370+gr_log_forkfail(const int retval)
74371+{
74372+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74373+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74374+ switch (retval) {
74375+ case -EAGAIN:
74376+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74377+ break;
74378+ case -ENOMEM:
74379+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74380+ break;
74381+ }
74382+ }
74383+#endif
74384+ return;
74385+}
74386diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74387new file mode 100644
74388index 0000000..ae6c028
74389--- /dev/null
74390+++ b/grsecurity/grsec_init.c
74391@@ -0,0 +1,272 @@
74392+#include <linux/kernel.h>
74393+#include <linux/sched.h>
74394+#include <linux/mm.h>
74395+#include <linux/gracl.h>
74396+#include <linux/slab.h>
74397+#include <linux/vmalloc.h>
74398+#include <linux/percpu.h>
74399+#include <linux/module.h>
74400+
74401+int grsec_enable_ptrace_readexec;
74402+int grsec_enable_setxid;
74403+int grsec_enable_symlinkown;
74404+kgid_t grsec_symlinkown_gid;
74405+int grsec_enable_brute;
74406+int grsec_enable_link;
74407+int grsec_enable_dmesg;
74408+int grsec_enable_harden_ptrace;
74409+int grsec_enable_harden_ipc;
74410+int grsec_enable_fifo;
74411+int grsec_enable_execlog;
74412+int grsec_enable_signal;
74413+int grsec_enable_forkfail;
74414+int grsec_enable_audit_ptrace;
74415+int grsec_enable_time;
74416+int grsec_enable_group;
74417+kgid_t grsec_audit_gid;
74418+int grsec_enable_chdir;
74419+int grsec_enable_mount;
74420+int grsec_enable_rofs;
74421+int grsec_deny_new_usb;
74422+int grsec_enable_chroot_findtask;
74423+int grsec_enable_chroot_mount;
74424+int grsec_enable_chroot_shmat;
74425+int grsec_enable_chroot_fchdir;
74426+int grsec_enable_chroot_double;
74427+int grsec_enable_chroot_pivot;
74428+int grsec_enable_chroot_chdir;
74429+int grsec_enable_chroot_chmod;
74430+int grsec_enable_chroot_mknod;
74431+int grsec_enable_chroot_nice;
74432+int grsec_enable_chroot_execlog;
74433+int grsec_enable_chroot_caps;
74434+int grsec_enable_chroot_sysctl;
74435+int grsec_enable_chroot_unix;
74436+int grsec_enable_tpe;
74437+kgid_t grsec_tpe_gid;
74438+int grsec_enable_blackhole;
74439+#ifdef CONFIG_IPV6_MODULE
74440+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74441+#endif
74442+int grsec_lastack_retries;
74443+int grsec_enable_tpe_all;
74444+int grsec_enable_tpe_invert;
74445+int grsec_enable_socket_all;
74446+kgid_t grsec_socket_all_gid;
74447+int grsec_enable_socket_client;
74448+kgid_t grsec_socket_client_gid;
74449+int grsec_enable_socket_server;
74450+kgid_t grsec_socket_server_gid;
74451+int grsec_resource_logging;
74452+int grsec_disable_privio;
74453+int grsec_enable_log_rwxmaps;
74454+int grsec_lock;
74455+
74456+DEFINE_SPINLOCK(grsec_alert_lock);
74457+unsigned long grsec_alert_wtime = 0;
74458+unsigned long grsec_alert_fyet = 0;
74459+
74460+DEFINE_SPINLOCK(grsec_audit_lock);
74461+
74462+DEFINE_RWLOCK(grsec_exec_file_lock);
74463+
74464+char *gr_shared_page[4];
74465+
74466+char *gr_alert_log_fmt;
74467+char *gr_audit_log_fmt;
74468+char *gr_alert_log_buf;
74469+char *gr_audit_log_buf;
74470+
74471+void __init
74472+grsecurity_init(void)
74473+{
74474+ int j;
74475+ /* create the per-cpu shared pages */
74476+
74477+#ifdef CONFIG_X86
74478+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74479+#endif
74480+
74481+ for (j = 0; j < 4; j++) {
74482+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74483+ if (gr_shared_page[j] == NULL) {
74484+ panic("Unable to allocate grsecurity shared page");
74485+ return;
74486+ }
74487+ }
74488+
74489+ /* allocate log buffers */
74490+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74491+ if (!gr_alert_log_fmt) {
74492+ panic("Unable to allocate grsecurity alert log format buffer");
74493+ return;
74494+ }
74495+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74496+ if (!gr_audit_log_fmt) {
74497+ panic("Unable to allocate grsecurity audit log format buffer");
74498+ return;
74499+ }
74500+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74501+ if (!gr_alert_log_buf) {
74502+ panic("Unable to allocate grsecurity alert log buffer");
74503+ return;
74504+ }
74505+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74506+ if (!gr_audit_log_buf) {
74507+ panic("Unable to allocate grsecurity audit log buffer");
74508+ return;
74509+ }
74510+
74511+#ifdef CONFIG_GRKERNSEC_IO
74512+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74513+ grsec_disable_privio = 1;
74514+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74515+ grsec_disable_privio = 1;
74516+#else
74517+ grsec_disable_privio = 0;
74518+#endif
74519+#endif
74520+
74521+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74522+ /* for backward compatibility, tpe_invert always defaults to on if
74523+ enabled in the kernel
74524+ */
74525+ grsec_enable_tpe_invert = 1;
74526+#endif
74527+
74528+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74529+#ifndef CONFIG_GRKERNSEC_SYSCTL
74530+ grsec_lock = 1;
74531+#endif
74532+
74533+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74534+ grsec_enable_log_rwxmaps = 1;
74535+#endif
74536+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74537+ grsec_enable_group = 1;
74538+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74539+#endif
74540+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74541+ grsec_enable_ptrace_readexec = 1;
74542+#endif
74543+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74544+ grsec_enable_chdir = 1;
74545+#endif
74546+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74547+ grsec_enable_harden_ptrace = 1;
74548+#endif
74549+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74550+ grsec_enable_harden_ipc = 1;
74551+#endif
74552+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74553+ grsec_enable_mount = 1;
74554+#endif
74555+#ifdef CONFIG_GRKERNSEC_LINK
74556+ grsec_enable_link = 1;
74557+#endif
74558+#ifdef CONFIG_GRKERNSEC_BRUTE
74559+ grsec_enable_brute = 1;
74560+#endif
74561+#ifdef CONFIG_GRKERNSEC_DMESG
74562+ grsec_enable_dmesg = 1;
74563+#endif
74564+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74565+ grsec_enable_blackhole = 1;
74566+ grsec_lastack_retries = 4;
74567+#endif
74568+#ifdef CONFIG_GRKERNSEC_FIFO
74569+ grsec_enable_fifo = 1;
74570+#endif
74571+#ifdef CONFIG_GRKERNSEC_EXECLOG
74572+ grsec_enable_execlog = 1;
74573+#endif
74574+#ifdef CONFIG_GRKERNSEC_SETXID
74575+ grsec_enable_setxid = 1;
74576+#endif
74577+#ifdef CONFIG_GRKERNSEC_SIGNAL
74578+ grsec_enable_signal = 1;
74579+#endif
74580+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74581+ grsec_enable_forkfail = 1;
74582+#endif
74583+#ifdef CONFIG_GRKERNSEC_TIME
74584+ grsec_enable_time = 1;
74585+#endif
74586+#ifdef CONFIG_GRKERNSEC_RESLOG
74587+ grsec_resource_logging = 1;
74588+#endif
74589+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74590+ grsec_enable_chroot_findtask = 1;
74591+#endif
74592+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74593+ grsec_enable_chroot_unix = 1;
74594+#endif
74595+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74596+ grsec_enable_chroot_mount = 1;
74597+#endif
74598+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74599+ grsec_enable_chroot_fchdir = 1;
74600+#endif
74601+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74602+ grsec_enable_chroot_shmat = 1;
74603+#endif
74604+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74605+ grsec_enable_audit_ptrace = 1;
74606+#endif
74607+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74608+ grsec_enable_chroot_double = 1;
74609+#endif
74610+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74611+ grsec_enable_chroot_pivot = 1;
74612+#endif
74613+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74614+ grsec_enable_chroot_chdir = 1;
74615+#endif
74616+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74617+ grsec_enable_chroot_chmod = 1;
74618+#endif
74619+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74620+ grsec_enable_chroot_mknod = 1;
74621+#endif
74622+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74623+ grsec_enable_chroot_nice = 1;
74624+#endif
74625+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74626+ grsec_enable_chroot_execlog = 1;
74627+#endif
74628+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74629+ grsec_enable_chroot_caps = 1;
74630+#endif
74631+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74632+ grsec_enable_chroot_sysctl = 1;
74633+#endif
74634+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74635+ grsec_enable_symlinkown = 1;
74636+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74637+#endif
74638+#ifdef CONFIG_GRKERNSEC_TPE
74639+ grsec_enable_tpe = 1;
74640+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74641+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74642+ grsec_enable_tpe_all = 1;
74643+#endif
74644+#endif
74645+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74646+ grsec_enable_socket_all = 1;
74647+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74648+#endif
74649+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74650+ grsec_enable_socket_client = 1;
74651+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74652+#endif
74653+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74654+ grsec_enable_socket_server = 1;
74655+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74656+#endif
74657+#endif
74658+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74659+ grsec_deny_new_usb = 1;
74660+#endif
74661+
74662+ return;
74663+}
74664diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74665new file mode 100644
74666index 0000000..1773300
74667--- /dev/null
74668+++ b/grsecurity/grsec_ipc.c
74669@@ -0,0 +1,48 @@
74670+#include <linux/kernel.h>
74671+#include <linux/mm.h>
74672+#include <linux/sched.h>
74673+#include <linux/file.h>
74674+#include <linux/ipc.h>
74675+#include <linux/ipc_namespace.h>
74676+#include <linux/grsecurity.h>
74677+#include <linux/grinternal.h>
74678+
74679+int
74680+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74681+{
74682+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74683+ int write;
74684+ int orig_granted_mode;
74685+ kuid_t euid;
74686+ kgid_t egid;
74687+
74688+ if (!grsec_enable_harden_ipc)
74689+ return 1;
74690+
74691+ euid = current_euid();
74692+ egid = current_egid();
74693+
74694+ write = requested_mode & 00002;
74695+ orig_granted_mode = ipcp->mode;
74696+
74697+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74698+ orig_granted_mode >>= 6;
74699+ else {
74700+ /* if likely wrong permissions, lock to user */
74701+ if (orig_granted_mode & 0007)
74702+ orig_granted_mode = 0;
74703+ /* otherwise do a egid-only check */
74704+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74705+ orig_granted_mode >>= 3;
74706+ /* otherwise, no access */
74707+ else
74708+ orig_granted_mode = 0;
74709+ }
74710+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74711+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74712+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74713+ return 0;
74714+ }
74715+#endif
74716+ return 1;
74717+}
74718diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74719new file mode 100644
74720index 0000000..5e05e20
74721--- /dev/null
74722+++ b/grsecurity/grsec_link.c
74723@@ -0,0 +1,58 @@
74724+#include <linux/kernel.h>
74725+#include <linux/sched.h>
74726+#include <linux/fs.h>
74727+#include <linux/file.h>
74728+#include <linux/grinternal.h>
74729+
74730+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74731+{
74732+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74733+ const struct inode *link_inode = link->dentry->d_inode;
74734+
74735+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74736+ /* ignore root-owned links, e.g. /proc/self */
74737+ gr_is_global_nonroot(link_inode->i_uid) && target &&
74738+ !uid_eq(link_inode->i_uid, target->i_uid)) {
74739+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74740+ return 1;
74741+ }
74742+#endif
74743+ return 0;
74744+}
74745+
74746+int
74747+gr_handle_follow_link(const struct inode *parent,
74748+ const struct inode *inode,
74749+ const struct dentry *dentry, const struct vfsmount *mnt)
74750+{
74751+#ifdef CONFIG_GRKERNSEC_LINK
74752+ const struct cred *cred = current_cred();
74753+
74754+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74755+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74756+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74757+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74758+ return -EACCES;
74759+ }
74760+#endif
74761+ return 0;
74762+}
74763+
74764+int
74765+gr_handle_hardlink(const struct dentry *dentry,
74766+ const struct vfsmount *mnt,
74767+ struct inode *inode, const int mode, const struct filename *to)
74768+{
74769+#ifdef CONFIG_GRKERNSEC_LINK
74770+ const struct cred *cred = current_cred();
74771+
74772+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74773+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74774+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74775+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74776+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74777+ return -EPERM;
74778+ }
74779+#endif
74780+ return 0;
74781+}
74782diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74783new file mode 100644
74784index 0000000..dbe0a6b
74785--- /dev/null
74786+++ b/grsecurity/grsec_log.c
74787@@ -0,0 +1,341 @@
74788+#include <linux/kernel.h>
74789+#include <linux/sched.h>
74790+#include <linux/file.h>
74791+#include <linux/tty.h>
74792+#include <linux/fs.h>
74793+#include <linux/mm.h>
74794+#include <linux/grinternal.h>
74795+
74796+#ifdef CONFIG_TREE_PREEMPT_RCU
74797+#define DISABLE_PREEMPT() preempt_disable()
74798+#define ENABLE_PREEMPT() preempt_enable()
74799+#else
74800+#define DISABLE_PREEMPT()
74801+#define ENABLE_PREEMPT()
74802+#endif
74803+
74804+#define BEGIN_LOCKS(x) \
74805+ DISABLE_PREEMPT(); \
74806+ rcu_read_lock(); \
74807+ read_lock(&tasklist_lock); \
74808+ read_lock(&grsec_exec_file_lock); \
74809+ if (x != GR_DO_AUDIT) \
74810+ spin_lock(&grsec_alert_lock); \
74811+ else \
74812+ spin_lock(&grsec_audit_lock)
74813+
74814+#define END_LOCKS(x) \
74815+ if (x != GR_DO_AUDIT) \
74816+ spin_unlock(&grsec_alert_lock); \
74817+ else \
74818+ spin_unlock(&grsec_audit_lock); \
74819+ read_unlock(&grsec_exec_file_lock); \
74820+ read_unlock(&tasklist_lock); \
74821+ rcu_read_unlock(); \
74822+ ENABLE_PREEMPT(); \
74823+ if (x == GR_DONT_AUDIT) \
74824+ gr_handle_alertkill(current)
74825+
74826+enum {
74827+ FLOODING,
74828+ NO_FLOODING
74829+};
74830+
74831+extern char *gr_alert_log_fmt;
74832+extern char *gr_audit_log_fmt;
74833+extern char *gr_alert_log_buf;
74834+extern char *gr_audit_log_buf;
74835+
74836+static int gr_log_start(int audit)
74837+{
74838+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74839+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74840+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74841+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74842+ unsigned long curr_secs = get_seconds();
74843+
74844+ if (audit == GR_DO_AUDIT)
74845+ goto set_fmt;
74846+
74847+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74848+ grsec_alert_wtime = curr_secs;
74849+ grsec_alert_fyet = 0;
74850+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74851+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74852+ grsec_alert_fyet++;
74853+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74854+ grsec_alert_wtime = curr_secs;
74855+ grsec_alert_fyet++;
74856+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74857+ return FLOODING;
74858+ }
74859+ else return FLOODING;
74860+
74861+set_fmt:
74862+#endif
74863+ memset(buf, 0, PAGE_SIZE);
74864+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
74865+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74866+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74867+ } else if (current->signal->curr_ip) {
74868+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74869+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74870+ } else if (gr_acl_is_enabled()) {
74871+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74872+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74873+ } else {
74874+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
74875+ strcpy(buf, fmt);
74876+ }
74877+
74878+ return NO_FLOODING;
74879+}
74880+
74881+static void gr_log_middle(int audit, const char *msg, va_list ap)
74882+ __attribute__ ((format (printf, 2, 0)));
74883+
74884+static void gr_log_middle(int audit, const char *msg, va_list ap)
74885+{
74886+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74887+ unsigned int len = strlen(buf);
74888+
74889+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74890+
74891+ return;
74892+}
74893+
74894+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74895+ __attribute__ ((format (printf, 2, 3)));
74896+
74897+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74898+{
74899+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74900+ unsigned int len = strlen(buf);
74901+ va_list ap;
74902+
74903+ va_start(ap, msg);
74904+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74905+ va_end(ap);
74906+
74907+ return;
74908+}
74909+
74910+static void gr_log_end(int audit, int append_default)
74911+{
74912+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74913+ if (append_default) {
74914+ struct task_struct *task = current;
74915+ struct task_struct *parent = task->real_parent;
74916+ const struct cred *cred = __task_cred(task);
74917+ const struct cred *pcred = __task_cred(parent);
74918+ unsigned int len = strlen(buf);
74919+
74920+ 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));
74921+ }
74922+
74923+ printk("%s\n", buf);
74924+
74925+ return;
74926+}
74927+
74928+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74929+{
74930+ int logtype;
74931+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74932+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74933+ void *voidptr = NULL;
74934+ int num1 = 0, num2 = 0;
74935+ unsigned long ulong1 = 0, ulong2 = 0;
74936+ struct dentry *dentry = NULL;
74937+ struct vfsmount *mnt = NULL;
74938+ struct file *file = NULL;
74939+ struct task_struct *task = NULL;
74940+ struct vm_area_struct *vma = NULL;
74941+ const struct cred *cred, *pcred;
74942+ va_list ap;
74943+
74944+ BEGIN_LOCKS(audit);
74945+ logtype = gr_log_start(audit);
74946+ if (logtype == FLOODING) {
74947+ END_LOCKS(audit);
74948+ return;
74949+ }
74950+ va_start(ap, argtypes);
74951+ switch (argtypes) {
74952+ case GR_TTYSNIFF:
74953+ task = va_arg(ap, struct task_struct *);
74954+ 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));
74955+ break;
74956+ case GR_SYSCTL_HIDDEN:
74957+ str1 = va_arg(ap, char *);
74958+ gr_log_middle_varargs(audit, msg, result, str1);
74959+ break;
74960+ case GR_RBAC:
74961+ dentry = va_arg(ap, struct dentry *);
74962+ mnt = va_arg(ap, struct vfsmount *);
74963+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
74964+ break;
74965+ case GR_RBAC_STR:
74966+ dentry = va_arg(ap, struct dentry *);
74967+ mnt = va_arg(ap, struct vfsmount *);
74968+ str1 = va_arg(ap, char *);
74969+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
74970+ break;
74971+ case GR_STR_RBAC:
74972+ str1 = va_arg(ap, char *);
74973+ dentry = va_arg(ap, struct dentry *);
74974+ mnt = va_arg(ap, struct vfsmount *);
74975+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
74976+ break;
74977+ case GR_RBAC_MODE2:
74978+ dentry = va_arg(ap, struct dentry *);
74979+ mnt = va_arg(ap, struct vfsmount *);
74980+ str1 = va_arg(ap, char *);
74981+ str2 = va_arg(ap, char *);
74982+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
74983+ break;
74984+ case GR_RBAC_MODE3:
74985+ dentry = va_arg(ap, struct dentry *);
74986+ mnt = va_arg(ap, struct vfsmount *);
74987+ str1 = va_arg(ap, char *);
74988+ str2 = va_arg(ap, char *);
74989+ str3 = va_arg(ap, char *);
74990+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
74991+ break;
74992+ case GR_FILENAME:
74993+ dentry = va_arg(ap, struct dentry *);
74994+ mnt = va_arg(ap, struct vfsmount *);
74995+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
74996+ break;
74997+ case GR_STR_FILENAME:
74998+ str1 = va_arg(ap, char *);
74999+ dentry = va_arg(ap, struct dentry *);
75000+ mnt = va_arg(ap, struct vfsmount *);
75001+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
75002+ break;
75003+ case GR_FILENAME_STR:
75004+ dentry = va_arg(ap, struct dentry *);
75005+ mnt = va_arg(ap, struct vfsmount *);
75006+ str1 = va_arg(ap, char *);
75007+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
75008+ break;
75009+ case GR_FILENAME_TWO_INT:
75010+ dentry = va_arg(ap, struct dentry *);
75011+ mnt = va_arg(ap, struct vfsmount *);
75012+ num1 = va_arg(ap, int);
75013+ num2 = va_arg(ap, int);
75014+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
75015+ break;
75016+ case GR_FILENAME_TWO_INT_STR:
75017+ dentry = va_arg(ap, struct dentry *);
75018+ mnt = va_arg(ap, struct vfsmount *);
75019+ num1 = va_arg(ap, int);
75020+ num2 = va_arg(ap, int);
75021+ str1 = va_arg(ap, char *);
75022+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75023+ break;
75024+ case GR_TEXTREL:
75025+ file = va_arg(ap, struct file *);
75026+ ulong1 = va_arg(ap, unsigned long);
75027+ ulong2 = va_arg(ap, unsigned long);
75028+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75029+ break;
75030+ case GR_PTRACE:
75031+ task = va_arg(ap, struct task_struct *);
75032+ 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));
75033+ break;
75034+ case GR_RESOURCE:
75035+ task = va_arg(ap, struct task_struct *);
75036+ cred = __task_cred(task);
75037+ pcred = __task_cred(task->real_parent);
75038+ ulong1 = va_arg(ap, unsigned long);
75039+ str1 = va_arg(ap, char *);
75040+ ulong2 = va_arg(ap, unsigned long);
75041+ 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));
75042+ break;
75043+ case GR_CAP:
75044+ task = va_arg(ap, struct task_struct *);
75045+ cred = __task_cred(task);
75046+ pcred = __task_cred(task->real_parent);
75047+ str1 = va_arg(ap, char *);
75048+ 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));
75049+ break;
75050+ case GR_SIG:
75051+ str1 = va_arg(ap, char *);
75052+ voidptr = va_arg(ap, void *);
75053+ gr_log_middle_varargs(audit, msg, str1, voidptr);
75054+ break;
75055+ case GR_SIG2:
75056+ task = va_arg(ap, struct task_struct *);
75057+ cred = __task_cred(task);
75058+ pcred = __task_cred(task->real_parent);
75059+ num1 = va_arg(ap, int);
75060+ 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));
75061+ break;
75062+ case GR_CRASH1:
75063+ task = va_arg(ap, struct task_struct *);
75064+ cred = __task_cred(task);
75065+ pcred = __task_cred(task->real_parent);
75066+ ulong1 = va_arg(ap, unsigned long);
75067+ 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);
75068+ break;
75069+ case GR_CRASH2:
75070+ task = va_arg(ap, struct task_struct *);
75071+ cred = __task_cred(task);
75072+ pcred = __task_cred(task->real_parent);
75073+ ulong1 = va_arg(ap, unsigned long);
75074+ 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);
75075+ break;
75076+ case GR_RWXMAP:
75077+ file = va_arg(ap, struct file *);
75078+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75079+ break;
75080+ case GR_RWXMAPVMA:
75081+ vma = va_arg(ap, struct vm_area_struct *);
75082+ if (vma->vm_file)
75083+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75084+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75085+ str1 = "<stack>";
75086+ else if (vma->vm_start <= current->mm->brk &&
75087+ vma->vm_end >= current->mm->start_brk)
75088+ str1 = "<heap>";
75089+ else
75090+ str1 = "<anonymous mapping>";
75091+ gr_log_middle_varargs(audit, msg, str1);
75092+ break;
75093+ case GR_PSACCT:
75094+ {
75095+ unsigned int wday, cday;
75096+ __u8 whr, chr;
75097+ __u8 wmin, cmin;
75098+ __u8 wsec, csec;
75099+ char cur_tty[64] = { 0 };
75100+ char parent_tty[64] = { 0 };
75101+
75102+ task = va_arg(ap, struct task_struct *);
75103+ wday = va_arg(ap, unsigned int);
75104+ cday = va_arg(ap, unsigned int);
75105+ whr = va_arg(ap, int);
75106+ chr = va_arg(ap, int);
75107+ wmin = va_arg(ap, int);
75108+ cmin = va_arg(ap, int);
75109+ wsec = va_arg(ap, int);
75110+ csec = va_arg(ap, int);
75111+ ulong1 = va_arg(ap, unsigned long);
75112+ cred = __task_cred(task);
75113+ pcred = __task_cred(task->real_parent);
75114+
75115+ 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));
75116+ }
75117+ break;
75118+ default:
75119+ gr_log_middle(audit, msg, ap);
75120+ }
75121+ va_end(ap);
75122+ // these don't need DEFAULTSECARGS printed on the end
75123+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75124+ gr_log_end(audit, 0);
75125+ else
75126+ gr_log_end(audit, 1);
75127+ END_LOCKS(audit);
75128+}
75129diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75130new file mode 100644
75131index 0000000..0e39d8c
75132--- /dev/null
75133+++ b/grsecurity/grsec_mem.c
75134@@ -0,0 +1,48 @@
75135+#include <linux/kernel.h>
75136+#include <linux/sched.h>
75137+#include <linux/mm.h>
75138+#include <linux/mman.h>
75139+#include <linux/module.h>
75140+#include <linux/grinternal.h>
75141+
75142+void gr_handle_msr_write(void)
75143+{
75144+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75145+ return;
75146+}
75147+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75148+
75149+void
75150+gr_handle_ioperm(void)
75151+{
75152+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75153+ return;
75154+}
75155+
75156+void
75157+gr_handle_iopl(void)
75158+{
75159+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75160+ return;
75161+}
75162+
75163+void
75164+gr_handle_mem_readwrite(u64 from, u64 to)
75165+{
75166+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75167+ return;
75168+}
75169+
75170+void
75171+gr_handle_vm86(void)
75172+{
75173+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75174+ return;
75175+}
75176+
75177+void
75178+gr_log_badprocpid(const char *entry)
75179+{
75180+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75181+ return;
75182+}
75183diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75184new file mode 100644
75185index 0000000..cd9e124
75186--- /dev/null
75187+++ b/grsecurity/grsec_mount.c
75188@@ -0,0 +1,65 @@
75189+#include <linux/kernel.h>
75190+#include <linux/sched.h>
75191+#include <linux/mount.h>
75192+#include <linux/major.h>
75193+#include <linux/grsecurity.h>
75194+#include <linux/grinternal.h>
75195+
75196+void
75197+gr_log_remount(const char *devname, const int retval)
75198+{
75199+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75200+ if (grsec_enable_mount && (retval >= 0))
75201+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75202+#endif
75203+ return;
75204+}
75205+
75206+void
75207+gr_log_unmount(const char *devname, const int retval)
75208+{
75209+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75210+ if (grsec_enable_mount && (retval >= 0))
75211+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75212+#endif
75213+ return;
75214+}
75215+
75216+void
75217+gr_log_mount(const char *from, const char *to, const int retval)
75218+{
75219+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75220+ if (grsec_enable_mount && (retval >= 0))
75221+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75222+#endif
75223+ return;
75224+}
75225+
75226+int
75227+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75228+{
75229+#ifdef CONFIG_GRKERNSEC_ROFS
75230+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75231+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75232+ return -EPERM;
75233+ } else
75234+ return 0;
75235+#endif
75236+ return 0;
75237+}
75238+
75239+int
75240+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75241+{
75242+#ifdef CONFIG_GRKERNSEC_ROFS
75243+ struct inode *inode = dentry->d_inode;
75244+
75245+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75246+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75247+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75248+ return -EPERM;
75249+ } else
75250+ return 0;
75251+#endif
75252+ return 0;
75253+}
75254diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75255new file mode 100644
75256index 0000000..6ee9d50
75257--- /dev/null
75258+++ b/grsecurity/grsec_pax.c
75259@@ -0,0 +1,45 @@
75260+#include <linux/kernel.h>
75261+#include <linux/sched.h>
75262+#include <linux/mm.h>
75263+#include <linux/file.h>
75264+#include <linux/grinternal.h>
75265+#include <linux/grsecurity.h>
75266+
75267+void
75268+gr_log_textrel(struct vm_area_struct * vma)
75269+{
75270+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75271+ if (grsec_enable_log_rwxmaps)
75272+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75273+#endif
75274+ return;
75275+}
75276+
75277+void gr_log_ptgnustack(struct file *file)
75278+{
75279+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75280+ if (grsec_enable_log_rwxmaps)
75281+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75282+#endif
75283+ return;
75284+}
75285+
75286+void
75287+gr_log_rwxmmap(struct file *file)
75288+{
75289+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75290+ if (grsec_enable_log_rwxmaps)
75291+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75292+#endif
75293+ return;
75294+}
75295+
75296+void
75297+gr_log_rwxmprotect(struct vm_area_struct *vma)
75298+{
75299+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75300+ if (grsec_enable_log_rwxmaps)
75301+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75302+#endif
75303+ return;
75304+}
75305diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75306new file mode 100644
75307index 0000000..2005a3a
75308--- /dev/null
75309+++ b/grsecurity/grsec_proc.c
75310@@ -0,0 +1,20 @@
75311+#include <linux/kernel.h>
75312+#include <linux/sched.h>
75313+#include <linux/grsecurity.h>
75314+#include <linux/grinternal.h>
75315+
75316+int gr_proc_is_restricted(void)
75317+{
75318+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75319+ const struct cred *cred = current_cred();
75320+#endif
75321+
75322+#ifdef CONFIG_GRKERNSEC_PROC_USER
75323+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75324+ return -EACCES;
75325+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75326+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75327+ return -EACCES;
75328+#endif
75329+ return 0;
75330+}
75331diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75332new file mode 100644
75333index 0000000..f7f29aa
75334--- /dev/null
75335+++ b/grsecurity/grsec_ptrace.c
75336@@ -0,0 +1,30 @@
75337+#include <linux/kernel.h>
75338+#include <linux/sched.h>
75339+#include <linux/grinternal.h>
75340+#include <linux/security.h>
75341+
75342+void
75343+gr_audit_ptrace(struct task_struct *task)
75344+{
75345+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75346+ if (grsec_enable_audit_ptrace)
75347+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75348+#endif
75349+ return;
75350+}
75351+
75352+int
75353+gr_ptrace_readexec(struct file *file, int unsafe_flags)
75354+{
75355+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75356+ const struct dentry *dentry = file->f_path.dentry;
75357+ const struct vfsmount *mnt = file->f_path.mnt;
75358+
75359+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75360+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75361+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75362+ return -EACCES;
75363+ }
75364+#endif
75365+ return 0;
75366+}
75367diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75368new file mode 100644
75369index 0000000..3860c7e
75370--- /dev/null
75371+++ b/grsecurity/grsec_sig.c
75372@@ -0,0 +1,236 @@
75373+#include <linux/kernel.h>
75374+#include <linux/sched.h>
75375+#include <linux/fs.h>
75376+#include <linux/delay.h>
75377+#include <linux/grsecurity.h>
75378+#include <linux/grinternal.h>
75379+#include <linux/hardirq.h>
75380+
75381+char *signames[] = {
75382+ [SIGSEGV] = "Segmentation fault",
75383+ [SIGILL] = "Illegal instruction",
75384+ [SIGABRT] = "Abort",
75385+ [SIGBUS] = "Invalid alignment/Bus error"
75386+};
75387+
75388+void
75389+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75390+{
75391+#ifdef CONFIG_GRKERNSEC_SIGNAL
75392+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75393+ (sig == SIGABRT) || (sig == SIGBUS))) {
75394+ if (task_pid_nr(t) == task_pid_nr(current)) {
75395+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75396+ } else {
75397+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75398+ }
75399+ }
75400+#endif
75401+ return;
75402+}
75403+
75404+int
75405+gr_handle_signal(const struct task_struct *p, const int sig)
75406+{
75407+#ifdef CONFIG_GRKERNSEC
75408+ /* ignore the 0 signal for protected task checks */
75409+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75410+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75411+ return -EPERM;
75412+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75413+ return -EPERM;
75414+ }
75415+#endif
75416+ return 0;
75417+}
75418+
75419+#ifdef CONFIG_GRKERNSEC
75420+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75421+
75422+int gr_fake_force_sig(int sig, struct task_struct *t)
75423+{
75424+ unsigned long int flags;
75425+ int ret, blocked, ignored;
75426+ struct k_sigaction *action;
75427+
75428+ spin_lock_irqsave(&t->sighand->siglock, flags);
75429+ action = &t->sighand->action[sig-1];
75430+ ignored = action->sa.sa_handler == SIG_IGN;
75431+ blocked = sigismember(&t->blocked, sig);
75432+ if (blocked || ignored) {
75433+ action->sa.sa_handler = SIG_DFL;
75434+ if (blocked) {
75435+ sigdelset(&t->blocked, sig);
75436+ recalc_sigpending_and_wake(t);
75437+ }
75438+ }
75439+ if (action->sa.sa_handler == SIG_DFL)
75440+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
75441+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75442+
75443+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
75444+
75445+ return ret;
75446+}
75447+#endif
75448+
75449+#define GR_USER_BAN_TIME (15 * 60)
75450+#define GR_DAEMON_BRUTE_TIME (30 * 60)
75451+
75452+void gr_handle_brute_attach(int dumpable)
75453+{
75454+#ifdef CONFIG_GRKERNSEC_BRUTE
75455+ struct task_struct *p = current;
75456+ kuid_t uid = GLOBAL_ROOT_UID;
75457+ int daemon = 0;
75458+
75459+ if (!grsec_enable_brute)
75460+ return;
75461+
75462+ rcu_read_lock();
75463+ read_lock(&tasklist_lock);
75464+ read_lock(&grsec_exec_file_lock);
75465+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75466+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75467+ p->real_parent->brute = 1;
75468+ daemon = 1;
75469+ } else {
75470+ const struct cred *cred = __task_cred(p), *cred2;
75471+ struct task_struct *tsk, *tsk2;
75472+
75473+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75474+ struct user_struct *user;
75475+
75476+ uid = cred->uid;
75477+
75478+ /* this is put upon execution past expiration */
75479+ user = find_user(uid);
75480+ if (user == NULL)
75481+ goto unlock;
75482+ user->suid_banned = 1;
75483+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75484+ if (user->suid_ban_expires == ~0UL)
75485+ user->suid_ban_expires--;
75486+
75487+ /* only kill other threads of the same binary, from the same user */
75488+ do_each_thread(tsk2, tsk) {
75489+ cred2 = __task_cred(tsk);
75490+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75491+ gr_fake_force_sig(SIGKILL, tsk);
75492+ } while_each_thread(tsk2, tsk);
75493+ }
75494+ }
75495+unlock:
75496+ read_unlock(&grsec_exec_file_lock);
75497+ read_unlock(&tasklist_lock);
75498+ rcu_read_unlock();
75499+
75500+ if (gr_is_global_nonroot(uid))
75501+ 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);
75502+ else if (daemon)
75503+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75504+
75505+#endif
75506+ return;
75507+}
75508+
75509+void gr_handle_brute_check(void)
75510+{
75511+#ifdef CONFIG_GRKERNSEC_BRUTE
75512+ struct task_struct *p = current;
75513+
75514+ if (unlikely(p->brute)) {
75515+ if (!grsec_enable_brute)
75516+ p->brute = 0;
75517+ else if (time_before(get_seconds(), p->brute_expires))
75518+ msleep(30 * 1000);
75519+ }
75520+#endif
75521+ return;
75522+}
75523+
75524+void gr_handle_kernel_exploit(void)
75525+{
75526+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75527+ const struct cred *cred;
75528+ struct task_struct *tsk, *tsk2;
75529+ struct user_struct *user;
75530+ kuid_t uid;
75531+
75532+ if (in_irq() || in_serving_softirq() || in_nmi())
75533+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75534+
75535+ uid = current_uid();
75536+
75537+ if (gr_is_global_root(uid))
75538+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
75539+ else {
75540+ /* kill all the processes of this user, hold a reference
75541+ to their creds struct, and prevent them from creating
75542+ another process until system reset
75543+ */
75544+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75545+ GR_GLOBAL_UID(uid));
75546+ /* we intentionally leak this ref */
75547+ user = get_uid(current->cred->user);
75548+ if (user)
75549+ user->kernel_banned = 1;
75550+
75551+ /* kill all processes of this user */
75552+ read_lock(&tasklist_lock);
75553+ do_each_thread(tsk2, tsk) {
75554+ cred = __task_cred(tsk);
75555+ if (uid_eq(cred->uid, uid))
75556+ gr_fake_force_sig(SIGKILL, tsk);
75557+ } while_each_thread(tsk2, tsk);
75558+ read_unlock(&tasklist_lock);
75559+ }
75560+#endif
75561+}
75562+
75563+#ifdef CONFIG_GRKERNSEC_BRUTE
75564+static bool suid_ban_expired(struct user_struct *user)
75565+{
75566+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75567+ user->suid_banned = 0;
75568+ user->suid_ban_expires = 0;
75569+ free_uid(user);
75570+ return true;
75571+ }
75572+
75573+ return false;
75574+}
75575+#endif
75576+
75577+int gr_process_kernel_exec_ban(void)
75578+{
75579+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75580+ if (unlikely(current->cred->user->kernel_banned))
75581+ return -EPERM;
75582+#endif
75583+ return 0;
75584+}
75585+
75586+int gr_process_kernel_setuid_ban(struct user_struct *user)
75587+{
75588+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75589+ if (unlikely(user->kernel_banned))
75590+ gr_fake_force_sig(SIGKILL, current);
75591+#endif
75592+ return 0;
75593+}
75594+
75595+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75596+{
75597+#ifdef CONFIG_GRKERNSEC_BRUTE
75598+ struct user_struct *user = current->cred->user;
75599+ if (unlikely(user->suid_banned)) {
75600+ if (suid_ban_expired(user))
75601+ return 0;
75602+ /* disallow execution of suid binaries only */
75603+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75604+ return -EPERM;
75605+ }
75606+#endif
75607+ return 0;
75608+}
75609diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75610new file mode 100644
75611index 0000000..c0aef3a
75612--- /dev/null
75613+++ b/grsecurity/grsec_sock.c
75614@@ -0,0 +1,244 @@
75615+#include <linux/kernel.h>
75616+#include <linux/module.h>
75617+#include <linux/sched.h>
75618+#include <linux/file.h>
75619+#include <linux/net.h>
75620+#include <linux/in.h>
75621+#include <linux/ip.h>
75622+#include <net/sock.h>
75623+#include <net/inet_sock.h>
75624+#include <linux/grsecurity.h>
75625+#include <linux/grinternal.h>
75626+#include <linux/gracl.h>
75627+
75628+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75629+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75630+
75631+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75632+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75633+
75634+#ifdef CONFIG_UNIX_MODULE
75635+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75636+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75637+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75638+EXPORT_SYMBOL_GPL(gr_handle_create);
75639+#endif
75640+
75641+#ifdef CONFIG_GRKERNSEC
75642+#define gr_conn_table_size 32749
75643+struct conn_table_entry {
75644+ struct conn_table_entry *next;
75645+ struct signal_struct *sig;
75646+};
75647+
75648+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75649+DEFINE_SPINLOCK(gr_conn_table_lock);
75650+
75651+extern const char * gr_socktype_to_name(unsigned char type);
75652+extern const char * gr_proto_to_name(unsigned char proto);
75653+extern const char * gr_sockfamily_to_name(unsigned char family);
75654+
75655+static __inline__ int
75656+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75657+{
75658+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75659+}
75660+
75661+static __inline__ int
75662+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75663+ __u16 sport, __u16 dport)
75664+{
75665+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75666+ sig->gr_sport == sport && sig->gr_dport == dport))
75667+ return 1;
75668+ else
75669+ return 0;
75670+}
75671+
75672+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75673+{
75674+ struct conn_table_entry **match;
75675+ unsigned int index;
75676+
75677+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75678+ sig->gr_sport, sig->gr_dport,
75679+ gr_conn_table_size);
75680+
75681+ newent->sig = sig;
75682+
75683+ match = &gr_conn_table[index];
75684+ newent->next = *match;
75685+ *match = newent;
75686+
75687+ return;
75688+}
75689+
75690+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75691+{
75692+ struct conn_table_entry *match, *last = NULL;
75693+ unsigned int index;
75694+
75695+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75696+ sig->gr_sport, sig->gr_dport,
75697+ gr_conn_table_size);
75698+
75699+ match = gr_conn_table[index];
75700+ while (match && !conn_match(match->sig,
75701+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75702+ sig->gr_dport)) {
75703+ last = match;
75704+ match = match->next;
75705+ }
75706+
75707+ if (match) {
75708+ if (last)
75709+ last->next = match->next;
75710+ else
75711+ gr_conn_table[index] = NULL;
75712+ kfree(match);
75713+ }
75714+
75715+ return;
75716+}
75717+
75718+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75719+ __u16 sport, __u16 dport)
75720+{
75721+ struct conn_table_entry *match;
75722+ unsigned int index;
75723+
75724+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75725+
75726+ match = gr_conn_table[index];
75727+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75728+ match = match->next;
75729+
75730+ if (match)
75731+ return match->sig;
75732+ else
75733+ return NULL;
75734+}
75735+
75736+#endif
75737+
75738+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75739+{
75740+#ifdef CONFIG_GRKERNSEC
75741+ struct signal_struct *sig = task->signal;
75742+ struct conn_table_entry *newent;
75743+
75744+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75745+ if (newent == NULL)
75746+ return;
75747+ /* no bh lock needed since we are called with bh disabled */
75748+ spin_lock(&gr_conn_table_lock);
75749+ gr_del_task_from_ip_table_nolock(sig);
75750+ sig->gr_saddr = inet->inet_rcv_saddr;
75751+ sig->gr_daddr = inet->inet_daddr;
75752+ sig->gr_sport = inet->inet_sport;
75753+ sig->gr_dport = inet->inet_dport;
75754+ gr_add_to_task_ip_table_nolock(sig, newent);
75755+ spin_unlock(&gr_conn_table_lock);
75756+#endif
75757+ return;
75758+}
75759+
75760+void gr_del_task_from_ip_table(struct task_struct *task)
75761+{
75762+#ifdef CONFIG_GRKERNSEC
75763+ spin_lock_bh(&gr_conn_table_lock);
75764+ gr_del_task_from_ip_table_nolock(task->signal);
75765+ spin_unlock_bh(&gr_conn_table_lock);
75766+#endif
75767+ return;
75768+}
75769+
75770+void
75771+gr_attach_curr_ip(const struct sock *sk)
75772+{
75773+#ifdef CONFIG_GRKERNSEC
75774+ struct signal_struct *p, *set;
75775+ const struct inet_sock *inet = inet_sk(sk);
75776+
75777+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75778+ return;
75779+
75780+ set = current->signal;
75781+
75782+ spin_lock_bh(&gr_conn_table_lock);
75783+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75784+ inet->inet_dport, inet->inet_sport);
75785+ if (unlikely(p != NULL)) {
75786+ set->curr_ip = p->curr_ip;
75787+ set->used_accept = 1;
75788+ gr_del_task_from_ip_table_nolock(p);
75789+ spin_unlock_bh(&gr_conn_table_lock);
75790+ return;
75791+ }
75792+ spin_unlock_bh(&gr_conn_table_lock);
75793+
75794+ set->curr_ip = inet->inet_daddr;
75795+ set->used_accept = 1;
75796+#endif
75797+ return;
75798+}
75799+
75800+int
75801+gr_handle_sock_all(const int family, const int type, const int protocol)
75802+{
75803+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75804+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75805+ (family != AF_UNIX)) {
75806+ if (family == AF_INET)
75807+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75808+ else
75809+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75810+ return -EACCES;
75811+ }
75812+#endif
75813+ return 0;
75814+}
75815+
75816+int
75817+gr_handle_sock_server(const struct sockaddr *sck)
75818+{
75819+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75820+ if (grsec_enable_socket_server &&
75821+ in_group_p(grsec_socket_server_gid) &&
75822+ sck && (sck->sa_family != AF_UNIX) &&
75823+ (sck->sa_family != AF_LOCAL)) {
75824+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75825+ return -EACCES;
75826+ }
75827+#endif
75828+ return 0;
75829+}
75830+
75831+int
75832+gr_handle_sock_server_other(const struct sock *sck)
75833+{
75834+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75835+ if (grsec_enable_socket_server &&
75836+ in_group_p(grsec_socket_server_gid) &&
75837+ sck && (sck->sk_family != AF_UNIX) &&
75838+ (sck->sk_family != AF_LOCAL)) {
75839+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75840+ return -EACCES;
75841+ }
75842+#endif
75843+ return 0;
75844+}
75845+
75846+int
75847+gr_handle_sock_client(const struct sockaddr *sck)
75848+{
75849+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75850+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75851+ sck && (sck->sa_family != AF_UNIX) &&
75852+ (sck->sa_family != AF_LOCAL)) {
75853+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75854+ return -EACCES;
75855+ }
75856+#endif
75857+ return 0;
75858+}
75859diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75860new file mode 100644
75861index 0000000..8159888
75862--- /dev/null
75863+++ b/grsecurity/grsec_sysctl.c
75864@@ -0,0 +1,479 @@
75865+#include <linux/kernel.h>
75866+#include <linux/sched.h>
75867+#include <linux/sysctl.h>
75868+#include <linux/grsecurity.h>
75869+#include <linux/grinternal.h>
75870+
75871+int
75872+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75873+{
75874+#ifdef CONFIG_GRKERNSEC_SYSCTL
75875+ if (dirname == NULL || name == NULL)
75876+ return 0;
75877+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75878+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75879+ return -EACCES;
75880+ }
75881+#endif
75882+ return 0;
75883+}
75884+
75885+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75886+static int __maybe_unused __read_only one = 1;
75887+#endif
75888+
75889+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75890+ defined(CONFIG_GRKERNSEC_DENYUSB)
75891+struct ctl_table grsecurity_table[] = {
75892+#ifdef CONFIG_GRKERNSEC_SYSCTL
75893+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75894+#ifdef CONFIG_GRKERNSEC_IO
75895+ {
75896+ .procname = "disable_priv_io",
75897+ .data = &grsec_disable_privio,
75898+ .maxlen = sizeof(int),
75899+ .mode = 0600,
75900+ .proc_handler = &proc_dointvec,
75901+ },
75902+#endif
75903+#endif
75904+#ifdef CONFIG_GRKERNSEC_LINK
75905+ {
75906+ .procname = "linking_restrictions",
75907+ .data = &grsec_enable_link,
75908+ .maxlen = sizeof(int),
75909+ .mode = 0600,
75910+ .proc_handler = &proc_dointvec,
75911+ },
75912+#endif
75913+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75914+ {
75915+ .procname = "enforce_symlinksifowner",
75916+ .data = &grsec_enable_symlinkown,
75917+ .maxlen = sizeof(int),
75918+ .mode = 0600,
75919+ .proc_handler = &proc_dointvec,
75920+ },
75921+ {
75922+ .procname = "symlinkown_gid",
75923+ .data = &grsec_symlinkown_gid,
75924+ .maxlen = sizeof(int),
75925+ .mode = 0600,
75926+ .proc_handler = &proc_dointvec,
75927+ },
75928+#endif
75929+#ifdef CONFIG_GRKERNSEC_BRUTE
75930+ {
75931+ .procname = "deter_bruteforce",
75932+ .data = &grsec_enable_brute,
75933+ .maxlen = sizeof(int),
75934+ .mode = 0600,
75935+ .proc_handler = &proc_dointvec,
75936+ },
75937+#endif
75938+#ifdef CONFIG_GRKERNSEC_FIFO
75939+ {
75940+ .procname = "fifo_restrictions",
75941+ .data = &grsec_enable_fifo,
75942+ .maxlen = sizeof(int),
75943+ .mode = 0600,
75944+ .proc_handler = &proc_dointvec,
75945+ },
75946+#endif
75947+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75948+ {
75949+ .procname = "ptrace_readexec",
75950+ .data = &grsec_enable_ptrace_readexec,
75951+ .maxlen = sizeof(int),
75952+ .mode = 0600,
75953+ .proc_handler = &proc_dointvec,
75954+ },
75955+#endif
75956+#ifdef CONFIG_GRKERNSEC_SETXID
75957+ {
75958+ .procname = "consistent_setxid",
75959+ .data = &grsec_enable_setxid,
75960+ .maxlen = sizeof(int),
75961+ .mode = 0600,
75962+ .proc_handler = &proc_dointvec,
75963+ },
75964+#endif
75965+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75966+ {
75967+ .procname = "ip_blackhole",
75968+ .data = &grsec_enable_blackhole,
75969+ .maxlen = sizeof(int),
75970+ .mode = 0600,
75971+ .proc_handler = &proc_dointvec,
75972+ },
75973+ {
75974+ .procname = "lastack_retries",
75975+ .data = &grsec_lastack_retries,
75976+ .maxlen = sizeof(int),
75977+ .mode = 0600,
75978+ .proc_handler = &proc_dointvec,
75979+ },
75980+#endif
75981+#ifdef CONFIG_GRKERNSEC_EXECLOG
75982+ {
75983+ .procname = "exec_logging",
75984+ .data = &grsec_enable_execlog,
75985+ .maxlen = sizeof(int),
75986+ .mode = 0600,
75987+ .proc_handler = &proc_dointvec,
75988+ },
75989+#endif
75990+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75991+ {
75992+ .procname = "rwxmap_logging",
75993+ .data = &grsec_enable_log_rwxmaps,
75994+ .maxlen = sizeof(int),
75995+ .mode = 0600,
75996+ .proc_handler = &proc_dointvec,
75997+ },
75998+#endif
75999+#ifdef CONFIG_GRKERNSEC_SIGNAL
76000+ {
76001+ .procname = "signal_logging",
76002+ .data = &grsec_enable_signal,
76003+ .maxlen = sizeof(int),
76004+ .mode = 0600,
76005+ .proc_handler = &proc_dointvec,
76006+ },
76007+#endif
76008+#ifdef CONFIG_GRKERNSEC_FORKFAIL
76009+ {
76010+ .procname = "forkfail_logging",
76011+ .data = &grsec_enable_forkfail,
76012+ .maxlen = sizeof(int),
76013+ .mode = 0600,
76014+ .proc_handler = &proc_dointvec,
76015+ },
76016+#endif
76017+#ifdef CONFIG_GRKERNSEC_TIME
76018+ {
76019+ .procname = "timechange_logging",
76020+ .data = &grsec_enable_time,
76021+ .maxlen = sizeof(int),
76022+ .mode = 0600,
76023+ .proc_handler = &proc_dointvec,
76024+ },
76025+#endif
76026+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76027+ {
76028+ .procname = "chroot_deny_shmat",
76029+ .data = &grsec_enable_chroot_shmat,
76030+ .maxlen = sizeof(int),
76031+ .mode = 0600,
76032+ .proc_handler = &proc_dointvec,
76033+ },
76034+#endif
76035+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76036+ {
76037+ .procname = "chroot_deny_unix",
76038+ .data = &grsec_enable_chroot_unix,
76039+ .maxlen = sizeof(int),
76040+ .mode = 0600,
76041+ .proc_handler = &proc_dointvec,
76042+ },
76043+#endif
76044+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76045+ {
76046+ .procname = "chroot_deny_mount",
76047+ .data = &grsec_enable_chroot_mount,
76048+ .maxlen = sizeof(int),
76049+ .mode = 0600,
76050+ .proc_handler = &proc_dointvec,
76051+ },
76052+#endif
76053+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76054+ {
76055+ .procname = "chroot_deny_fchdir",
76056+ .data = &grsec_enable_chroot_fchdir,
76057+ .maxlen = sizeof(int),
76058+ .mode = 0600,
76059+ .proc_handler = &proc_dointvec,
76060+ },
76061+#endif
76062+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76063+ {
76064+ .procname = "chroot_deny_chroot",
76065+ .data = &grsec_enable_chroot_double,
76066+ .maxlen = sizeof(int),
76067+ .mode = 0600,
76068+ .proc_handler = &proc_dointvec,
76069+ },
76070+#endif
76071+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76072+ {
76073+ .procname = "chroot_deny_pivot",
76074+ .data = &grsec_enable_chroot_pivot,
76075+ .maxlen = sizeof(int),
76076+ .mode = 0600,
76077+ .proc_handler = &proc_dointvec,
76078+ },
76079+#endif
76080+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76081+ {
76082+ .procname = "chroot_enforce_chdir",
76083+ .data = &grsec_enable_chroot_chdir,
76084+ .maxlen = sizeof(int),
76085+ .mode = 0600,
76086+ .proc_handler = &proc_dointvec,
76087+ },
76088+#endif
76089+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76090+ {
76091+ .procname = "chroot_deny_chmod",
76092+ .data = &grsec_enable_chroot_chmod,
76093+ .maxlen = sizeof(int),
76094+ .mode = 0600,
76095+ .proc_handler = &proc_dointvec,
76096+ },
76097+#endif
76098+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76099+ {
76100+ .procname = "chroot_deny_mknod",
76101+ .data = &grsec_enable_chroot_mknod,
76102+ .maxlen = sizeof(int),
76103+ .mode = 0600,
76104+ .proc_handler = &proc_dointvec,
76105+ },
76106+#endif
76107+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76108+ {
76109+ .procname = "chroot_restrict_nice",
76110+ .data = &grsec_enable_chroot_nice,
76111+ .maxlen = sizeof(int),
76112+ .mode = 0600,
76113+ .proc_handler = &proc_dointvec,
76114+ },
76115+#endif
76116+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76117+ {
76118+ .procname = "chroot_execlog",
76119+ .data = &grsec_enable_chroot_execlog,
76120+ .maxlen = sizeof(int),
76121+ .mode = 0600,
76122+ .proc_handler = &proc_dointvec,
76123+ },
76124+#endif
76125+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76126+ {
76127+ .procname = "chroot_caps",
76128+ .data = &grsec_enable_chroot_caps,
76129+ .maxlen = sizeof(int),
76130+ .mode = 0600,
76131+ .proc_handler = &proc_dointvec,
76132+ },
76133+#endif
76134+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76135+ {
76136+ .procname = "chroot_deny_sysctl",
76137+ .data = &grsec_enable_chroot_sysctl,
76138+ .maxlen = sizeof(int),
76139+ .mode = 0600,
76140+ .proc_handler = &proc_dointvec,
76141+ },
76142+#endif
76143+#ifdef CONFIG_GRKERNSEC_TPE
76144+ {
76145+ .procname = "tpe",
76146+ .data = &grsec_enable_tpe,
76147+ .maxlen = sizeof(int),
76148+ .mode = 0600,
76149+ .proc_handler = &proc_dointvec,
76150+ },
76151+ {
76152+ .procname = "tpe_gid",
76153+ .data = &grsec_tpe_gid,
76154+ .maxlen = sizeof(int),
76155+ .mode = 0600,
76156+ .proc_handler = &proc_dointvec,
76157+ },
76158+#endif
76159+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76160+ {
76161+ .procname = "tpe_invert",
76162+ .data = &grsec_enable_tpe_invert,
76163+ .maxlen = sizeof(int),
76164+ .mode = 0600,
76165+ .proc_handler = &proc_dointvec,
76166+ },
76167+#endif
76168+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76169+ {
76170+ .procname = "tpe_restrict_all",
76171+ .data = &grsec_enable_tpe_all,
76172+ .maxlen = sizeof(int),
76173+ .mode = 0600,
76174+ .proc_handler = &proc_dointvec,
76175+ },
76176+#endif
76177+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76178+ {
76179+ .procname = "socket_all",
76180+ .data = &grsec_enable_socket_all,
76181+ .maxlen = sizeof(int),
76182+ .mode = 0600,
76183+ .proc_handler = &proc_dointvec,
76184+ },
76185+ {
76186+ .procname = "socket_all_gid",
76187+ .data = &grsec_socket_all_gid,
76188+ .maxlen = sizeof(int),
76189+ .mode = 0600,
76190+ .proc_handler = &proc_dointvec,
76191+ },
76192+#endif
76193+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76194+ {
76195+ .procname = "socket_client",
76196+ .data = &grsec_enable_socket_client,
76197+ .maxlen = sizeof(int),
76198+ .mode = 0600,
76199+ .proc_handler = &proc_dointvec,
76200+ },
76201+ {
76202+ .procname = "socket_client_gid",
76203+ .data = &grsec_socket_client_gid,
76204+ .maxlen = sizeof(int),
76205+ .mode = 0600,
76206+ .proc_handler = &proc_dointvec,
76207+ },
76208+#endif
76209+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76210+ {
76211+ .procname = "socket_server",
76212+ .data = &grsec_enable_socket_server,
76213+ .maxlen = sizeof(int),
76214+ .mode = 0600,
76215+ .proc_handler = &proc_dointvec,
76216+ },
76217+ {
76218+ .procname = "socket_server_gid",
76219+ .data = &grsec_socket_server_gid,
76220+ .maxlen = sizeof(int),
76221+ .mode = 0600,
76222+ .proc_handler = &proc_dointvec,
76223+ },
76224+#endif
76225+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76226+ {
76227+ .procname = "audit_group",
76228+ .data = &grsec_enable_group,
76229+ .maxlen = sizeof(int),
76230+ .mode = 0600,
76231+ .proc_handler = &proc_dointvec,
76232+ },
76233+ {
76234+ .procname = "audit_gid",
76235+ .data = &grsec_audit_gid,
76236+ .maxlen = sizeof(int),
76237+ .mode = 0600,
76238+ .proc_handler = &proc_dointvec,
76239+ },
76240+#endif
76241+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76242+ {
76243+ .procname = "audit_chdir",
76244+ .data = &grsec_enable_chdir,
76245+ .maxlen = sizeof(int),
76246+ .mode = 0600,
76247+ .proc_handler = &proc_dointvec,
76248+ },
76249+#endif
76250+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76251+ {
76252+ .procname = "audit_mount",
76253+ .data = &grsec_enable_mount,
76254+ .maxlen = sizeof(int),
76255+ .mode = 0600,
76256+ .proc_handler = &proc_dointvec,
76257+ },
76258+#endif
76259+#ifdef CONFIG_GRKERNSEC_DMESG
76260+ {
76261+ .procname = "dmesg",
76262+ .data = &grsec_enable_dmesg,
76263+ .maxlen = sizeof(int),
76264+ .mode = 0600,
76265+ .proc_handler = &proc_dointvec,
76266+ },
76267+#endif
76268+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76269+ {
76270+ .procname = "chroot_findtask",
76271+ .data = &grsec_enable_chroot_findtask,
76272+ .maxlen = sizeof(int),
76273+ .mode = 0600,
76274+ .proc_handler = &proc_dointvec,
76275+ },
76276+#endif
76277+#ifdef CONFIG_GRKERNSEC_RESLOG
76278+ {
76279+ .procname = "resource_logging",
76280+ .data = &grsec_resource_logging,
76281+ .maxlen = sizeof(int),
76282+ .mode = 0600,
76283+ .proc_handler = &proc_dointvec,
76284+ },
76285+#endif
76286+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76287+ {
76288+ .procname = "audit_ptrace",
76289+ .data = &grsec_enable_audit_ptrace,
76290+ .maxlen = sizeof(int),
76291+ .mode = 0600,
76292+ .proc_handler = &proc_dointvec,
76293+ },
76294+#endif
76295+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76296+ {
76297+ .procname = "harden_ptrace",
76298+ .data = &grsec_enable_harden_ptrace,
76299+ .maxlen = sizeof(int),
76300+ .mode = 0600,
76301+ .proc_handler = &proc_dointvec,
76302+ },
76303+#endif
76304+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76305+ {
76306+ .procname = "harden_ipc",
76307+ .data = &grsec_enable_harden_ipc,
76308+ .maxlen = sizeof(int),
76309+ .mode = 0600,
76310+ .proc_handler = &proc_dointvec,
76311+ },
76312+#endif
76313+ {
76314+ .procname = "grsec_lock",
76315+ .data = &grsec_lock,
76316+ .maxlen = sizeof(int),
76317+ .mode = 0600,
76318+ .proc_handler = &proc_dointvec,
76319+ },
76320+#endif
76321+#ifdef CONFIG_GRKERNSEC_ROFS
76322+ {
76323+ .procname = "romount_protect",
76324+ .data = &grsec_enable_rofs,
76325+ .maxlen = sizeof(int),
76326+ .mode = 0600,
76327+ .proc_handler = &proc_dointvec_minmax,
76328+ .extra1 = &one,
76329+ .extra2 = &one,
76330+ },
76331+#endif
76332+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76333+ {
76334+ .procname = "deny_new_usb",
76335+ .data = &grsec_deny_new_usb,
76336+ .maxlen = sizeof(int),
76337+ .mode = 0600,
76338+ .proc_handler = &proc_dointvec,
76339+ },
76340+#endif
76341+ { }
76342+};
76343+#endif
76344diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76345new file mode 100644
76346index 0000000..61b514e
76347--- /dev/null
76348+++ b/grsecurity/grsec_time.c
76349@@ -0,0 +1,16 @@
76350+#include <linux/kernel.h>
76351+#include <linux/sched.h>
76352+#include <linux/grinternal.h>
76353+#include <linux/module.h>
76354+
76355+void
76356+gr_log_timechange(void)
76357+{
76358+#ifdef CONFIG_GRKERNSEC_TIME
76359+ if (grsec_enable_time)
76360+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76361+#endif
76362+ return;
76363+}
76364+
76365+EXPORT_SYMBOL_GPL(gr_log_timechange);
76366diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76367new file mode 100644
76368index 0000000..d1953de
76369--- /dev/null
76370+++ b/grsecurity/grsec_tpe.c
76371@@ -0,0 +1,78 @@
76372+#include <linux/kernel.h>
76373+#include <linux/sched.h>
76374+#include <linux/file.h>
76375+#include <linux/fs.h>
76376+#include <linux/grinternal.h>
76377+
76378+extern int gr_acl_tpe_check(void);
76379+
76380+int
76381+gr_tpe_allow(const struct file *file)
76382+{
76383+#ifdef CONFIG_GRKERNSEC
76384+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76385+ struct inode *file_inode = file->f_path.dentry->d_inode;
76386+ const struct cred *cred = current_cred();
76387+ char *msg = NULL;
76388+ char *msg2 = NULL;
76389+
76390+ // never restrict root
76391+ if (gr_is_global_root(cred->uid))
76392+ return 1;
76393+
76394+ if (grsec_enable_tpe) {
76395+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76396+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76397+ msg = "not being in trusted group";
76398+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76399+ msg = "being in untrusted group";
76400+#else
76401+ if (in_group_p(grsec_tpe_gid))
76402+ msg = "being in untrusted group";
76403+#endif
76404+ }
76405+ if (!msg && gr_acl_tpe_check())
76406+ msg = "being in untrusted role";
76407+
76408+ // not in any affected group/role
76409+ if (!msg)
76410+ goto next_check;
76411+
76412+ if (gr_is_global_nonroot(inode->i_uid))
76413+ msg2 = "file in non-root-owned directory";
76414+ else if (inode->i_mode & S_IWOTH)
76415+ msg2 = "file in world-writable directory";
76416+ else if (inode->i_mode & S_IWGRP)
76417+ msg2 = "file in group-writable directory";
76418+ else if (file_inode->i_mode & S_IWOTH)
76419+ msg2 = "file is world-writable";
76420+
76421+ if (msg && msg2) {
76422+ char fullmsg[70] = {0};
76423+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76424+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76425+ return 0;
76426+ }
76427+ msg = NULL;
76428+next_check:
76429+#ifdef CONFIG_GRKERNSEC_TPE_ALL
76430+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76431+ return 1;
76432+
76433+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76434+ msg = "directory not owned by user";
76435+ else if (inode->i_mode & S_IWOTH)
76436+ msg = "file in world-writable directory";
76437+ else if (inode->i_mode & S_IWGRP)
76438+ msg = "file in group-writable directory";
76439+ else if (file_inode->i_mode & S_IWOTH)
76440+ msg = "file is world-writable";
76441+
76442+ if (msg) {
76443+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76444+ return 0;
76445+ }
76446+#endif
76447+#endif
76448+ return 1;
76449+}
76450diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76451new file mode 100644
76452index 0000000..ae02d8e
76453--- /dev/null
76454+++ b/grsecurity/grsec_usb.c
76455@@ -0,0 +1,15 @@
76456+#include <linux/kernel.h>
76457+#include <linux/grinternal.h>
76458+#include <linux/module.h>
76459+
76460+int gr_handle_new_usb(void)
76461+{
76462+#ifdef CONFIG_GRKERNSEC_DENYUSB
76463+ if (grsec_deny_new_usb) {
76464+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76465+ return 1;
76466+ }
76467+#endif
76468+ return 0;
76469+}
76470+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76471diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76472new file mode 100644
76473index 0000000..9f7b1ac
76474--- /dev/null
76475+++ b/grsecurity/grsum.c
76476@@ -0,0 +1,61 @@
76477+#include <linux/err.h>
76478+#include <linux/kernel.h>
76479+#include <linux/sched.h>
76480+#include <linux/mm.h>
76481+#include <linux/scatterlist.h>
76482+#include <linux/crypto.h>
76483+#include <linux/gracl.h>
76484+
76485+
76486+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76487+#error "crypto and sha256 must be built into the kernel"
76488+#endif
76489+
76490+int
76491+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76492+{
76493+ char *p;
76494+ struct crypto_hash *tfm;
76495+ struct hash_desc desc;
76496+ struct scatterlist sg;
76497+ unsigned char temp_sum[GR_SHA_LEN];
76498+ volatile int retval = 0;
76499+ volatile int dummy = 0;
76500+ unsigned int i;
76501+
76502+ sg_init_table(&sg, 1);
76503+
76504+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76505+ if (IS_ERR(tfm)) {
76506+ /* should never happen, since sha256 should be built in */
76507+ return 1;
76508+ }
76509+
76510+ desc.tfm = tfm;
76511+ desc.flags = 0;
76512+
76513+ crypto_hash_init(&desc);
76514+
76515+ p = salt;
76516+ sg_set_buf(&sg, p, GR_SALT_LEN);
76517+ crypto_hash_update(&desc, &sg, sg.length);
76518+
76519+ p = entry->pw;
76520+ sg_set_buf(&sg, p, strlen(p));
76521+
76522+ crypto_hash_update(&desc, &sg, sg.length);
76523+
76524+ crypto_hash_final(&desc, temp_sum);
76525+
76526+ memset(entry->pw, 0, GR_PW_LEN);
76527+
76528+ for (i = 0; i < GR_SHA_LEN; i++)
76529+ if (sum[i] != temp_sum[i])
76530+ retval = 1;
76531+ else
76532+ dummy = 1; // waste a cycle
76533+
76534+ crypto_free_hash(tfm);
76535+
76536+ return retval;
76537+}
76538diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76539index 77ff547..181834f 100644
76540--- a/include/asm-generic/4level-fixup.h
76541+++ b/include/asm-generic/4level-fixup.h
76542@@ -13,8 +13,10 @@
76543 #define pmd_alloc(mm, pud, address) \
76544 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76545 NULL: pmd_offset(pud, address))
76546+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76547
76548 #define pud_alloc(mm, pgd, address) (pgd)
76549+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76550 #define pud_offset(pgd, start) (pgd)
76551 #define pud_none(pud) 0
76552 #define pud_bad(pud) 0
76553diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76554index b7babf0..97f4c4f 100644
76555--- a/include/asm-generic/atomic-long.h
76556+++ b/include/asm-generic/atomic-long.h
76557@@ -22,6 +22,12 @@
76558
76559 typedef atomic64_t atomic_long_t;
76560
76561+#ifdef CONFIG_PAX_REFCOUNT
76562+typedef atomic64_unchecked_t atomic_long_unchecked_t;
76563+#else
76564+typedef atomic64_t atomic_long_unchecked_t;
76565+#endif
76566+
76567 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76568
76569 static inline long atomic_long_read(atomic_long_t *l)
76570@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76571 return (long)atomic64_read(v);
76572 }
76573
76574+#ifdef CONFIG_PAX_REFCOUNT
76575+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76576+{
76577+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76578+
76579+ return (long)atomic64_read_unchecked(v);
76580+}
76581+#endif
76582+
76583 static inline void atomic_long_set(atomic_long_t *l, long i)
76584 {
76585 atomic64_t *v = (atomic64_t *)l;
76586@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76587 atomic64_set(v, i);
76588 }
76589
76590+#ifdef CONFIG_PAX_REFCOUNT
76591+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76592+{
76593+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76594+
76595+ atomic64_set_unchecked(v, i);
76596+}
76597+#endif
76598+
76599 static inline void atomic_long_inc(atomic_long_t *l)
76600 {
76601 atomic64_t *v = (atomic64_t *)l;
76602@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76603 atomic64_inc(v);
76604 }
76605
76606+#ifdef CONFIG_PAX_REFCOUNT
76607+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76608+{
76609+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76610+
76611+ atomic64_inc_unchecked(v);
76612+}
76613+#endif
76614+
76615 static inline void atomic_long_dec(atomic_long_t *l)
76616 {
76617 atomic64_t *v = (atomic64_t *)l;
76618@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76619 atomic64_dec(v);
76620 }
76621
76622+#ifdef CONFIG_PAX_REFCOUNT
76623+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76624+{
76625+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76626+
76627+ atomic64_dec_unchecked(v);
76628+}
76629+#endif
76630+
76631 static inline void atomic_long_add(long i, atomic_long_t *l)
76632 {
76633 atomic64_t *v = (atomic64_t *)l;
76634@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76635 atomic64_add(i, v);
76636 }
76637
76638+#ifdef CONFIG_PAX_REFCOUNT
76639+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76640+{
76641+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76642+
76643+ atomic64_add_unchecked(i, v);
76644+}
76645+#endif
76646+
76647 static inline void atomic_long_sub(long i, atomic_long_t *l)
76648 {
76649 atomic64_t *v = (atomic64_t *)l;
76650@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76651 atomic64_sub(i, v);
76652 }
76653
76654+#ifdef CONFIG_PAX_REFCOUNT
76655+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76656+{
76657+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76658+
76659+ atomic64_sub_unchecked(i, v);
76660+}
76661+#endif
76662+
76663 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76664 {
76665 atomic64_t *v = (atomic64_t *)l;
76666@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76667 return atomic64_add_negative(i, v);
76668 }
76669
76670-static inline long atomic_long_add_return(long i, atomic_long_t *l)
76671+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76672 {
76673 atomic64_t *v = (atomic64_t *)l;
76674
76675 return (long)atomic64_add_return(i, v);
76676 }
76677
76678+#ifdef CONFIG_PAX_REFCOUNT
76679+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76680+{
76681+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76682+
76683+ return (long)atomic64_add_return_unchecked(i, v);
76684+}
76685+#endif
76686+
76687 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76688 {
76689 atomic64_t *v = (atomic64_t *)l;
76690@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76691 return (long)atomic64_inc_return(v);
76692 }
76693
76694+#ifdef CONFIG_PAX_REFCOUNT
76695+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76696+{
76697+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76698+
76699+ return (long)atomic64_inc_return_unchecked(v);
76700+}
76701+#endif
76702+
76703 static inline long atomic_long_dec_return(atomic_long_t *l)
76704 {
76705 atomic64_t *v = (atomic64_t *)l;
76706@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76707
76708 typedef atomic_t atomic_long_t;
76709
76710+#ifdef CONFIG_PAX_REFCOUNT
76711+typedef atomic_unchecked_t atomic_long_unchecked_t;
76712+#else
76713+typedef atomic_t atomic_long_unchecked_t;
76714+#endif
76715+
76716 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76717 static inline long atomic_long_read(atomic_long_t *l)
76718 {
76719@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76720 return (long)atomic_read(v);
76721 }
76722
76723+#ifdef CONFIG_PAX_REFCOUNT
76724+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76725+{
76726+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76727+
76728+ return (long)atomic_read_unchecked(v);
76729+}
76730+#endif
76731+
76732 static inline void atomic_long_set(atomic_long_t *l, long i)
76733 {
76734 atomic_t *v = (atomic_t *)l;
76735@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76736 atomic_set(v, i);
76737 }
76738
76739+#ifdef CONFIG_PAX_REFCOUNT
76740+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76741+{
76742+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76743+
76744+ atomic_set_unchecked(v, i);
76745+}
76746+#endif
76747+
76748 static inline void atomic_long_inc(atomic_long_t *l)
76749 {
76750 atomic_t *v = (atomic_t *)l;
76751@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76752 atomic_inc(v);
76753 }
76754
76755+#ifdef CONFIG_PAX_REFCOUNT
76756+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76757+{
76758+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76759+
76760+ atomic_inc_unchecked(v);
76761+}
76762+#endif
76763+
76764 static inline void atomic_long_dec(atomic_long_t *l)
76765 {
76766 atomic_t *v = (atomic_t *)l;
76767@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76768 atomic_dec(v);
76769 }
76770
76771+#ifdef CONFIG_PAX_REFCOUNT
76772+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76773+{
76774+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76775+
76776+ atomic_dec_unchecked(v);
76777+}
76778+#endif
76779+
76780 static inline void atomic_long_add(long i, atomic_long_t *l)
76781 {
76782 atomic_t *v = (atomic_t *)l;
76783@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76784 atomic_add(i, v);
76785 }
76786
76787+#ifdef CONFIG_PAX_REFCOUNT
76788+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76789+{
76790+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76791+
76792+ atomic_add_unchecked(i, v);
76793+}
76794+#endif
76795+
76796 static inline void atomic_long_sub(long i, atomic_long_t *l)
76797 {
76798 atomic_t *v = (atomic_t *)l;
76799@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76800 atomic_sub(i, v);
76801 }
76802
76803+#ifdef CONFIG_PAX_REFCOUNT
76804+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76805+{
76806+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76807+
76808+ atomic_sub_unchecked(i, v);
76809+}
76810+#endif
76811+
76812 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76813 {
76814 atomic_t *v = (atomic_t *)l;
76815@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76816 return (long)atomic_add_return(i, v);
76817 }
76818
76819+#ifdef CONFIG_PAX_REFCOUNT
76820+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76821+{
76822+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76823+
76824+ return (long)atomic_add_return_unchecked(i, v);
76825+}
76826+
76827+#endif
76828+
76829 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76830 {
76831 atomic_t *v = (atomic_t *)l;
76832@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76833 return (long)atomic_inc_return(v);
76834 }
76835
76836+#ifdef CONFIG_PAX_REFCOUNT
76837+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76838+{
76839+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76840+
76841+ return (long)atomic_inc_return_unchecked(v);
76842+}
76843+#endif
76844+
76845 static inline long atomic_long_dec_return(atomic_long_t *l)
76846 {
76847 atomic_t *v = (atomic_t *)l;
76848@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76849
76850 #endif /* BITS_PER_LONG == 64 */
76851
76852+#ifdef CONFIG_PAX_REFCOUNT
76853+static inline void pax_refcount_needs_these_functions(void)
76854+{
76855+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
76856+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76857+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76858+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76859+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76860+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76861+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76862+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76863+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76864+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76865+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76866+#ifdef CONFIG_X86
76867+ atomic_clear_mask_unchecked(0, NULL);
76868+ atomic_set_mask_unchecked(0, NULL);
76869+#endif
76870+
76871+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76872+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76873+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76874+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76875+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76876+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76877+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76878+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76879+}
76880+#else
76881+#define atomic_read_unchecked(v) atomic_read(v)
76882+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76883+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76884+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76885+#define atomic_inc_unchecked(v) atomic_inc(v)
76886+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76887+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76888+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76889+#define atomic_dec_unchecked(v) atomic_dec(v)
76890+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76891+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76892+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76893+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76894+
76895+#define atomic_long_read_unchecked(v) atomic_long_read(v)
76896+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76897+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76898+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76899+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76900+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76901+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76902+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76903+#endif
76904+
76905 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76906diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76907index 33bd2de..f31bff97 100644
76908--- a/include/asm-generic/atomic.h
76909+++ b/include/asm-generic/atomic.h
76910@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76911 * Atomically clears the bits set in @mask from @v
76912 */
76913 #ifndef atomic_clear_mask
76914-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76915+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76916 {
76917 unsigned long flags;
76918
76919diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76920index b18ce4f..2ee2843 100644
76921--- a/include/asm-generic/atomic64.h
76922+++ b/include/asm-generic/atomic64.h
76923@@ -16,6 +16,8 @@ typedef struct {
76924 long long counter;
76925 } atomic64_t;
76926
76927+typedef atomic64_t atomic64_unchecked_t;
76928+
76929 #define ATOMIC64_INIT(i) { (i) }
76930
76931 extern long long atomic64_read(const atomic64_t *v);
76932@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76933 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76934 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76935
76936+#define atomic64_read_unchecked(v) atomic64_read(v)
76937+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76938+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76939+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76940+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76941+#define atomic64_inc_unchecked(v) atomic64_inc(v)
76942+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76943+#define atomic64_dec_unchecked(v) atomic64_dec(v)
76944+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76945+
76946 #endif /* _ASM_GENERIC_ATOMIC64_H */
76947diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
76948index 6f692f8..2ad9dd2 100644
76949--- a/include/asm-generic/barrier.h
76950+++ b/include/asm-generic/barrier.h
76951@@ -66,7 +66,7 @@
76952 do { \
76953 compiletime_assert_atomic_type(*p); \
76954 smp_mb(); \
76955- ACCESS_ONCE(*p) = (v); \
76956+ ACCESS_ONCE_RW(*p) = (v); \
76957 } while (0)
76958
76959 #define smp_load_acquire(p) \
76960diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
76961index a60a7cc..0fe12f2 100644
76962--- a/include/asm-generic/bitops/__fls.h
76963+++ b/include/asm-generic/bitops/__fls.h
76964@@ -9,7 +9,7 @@
76965 *
76966 * Undefined if no set bit exists, so code should check against 0 first.
76967 */
76968-static __always_inline unsigned long __fls(unsigned long word)
76969+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
76970 {
76971 int num = BITS_PER_LONG - 1;
76972
76973diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
76974index 0576d1f..dad6c71 100644
76975--- a/include/asm-generic/bitops/fls.h
76976+++ b/include/asm-generic/bitops/fls.h
76977@@ -9,7 +9,7 @@
76978 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
76979 */
76980
76981-static __always_inline int fls(int x)
76982+static __always_inline int __intentional_overflow(-1) fls(int x)
76983 {
76984 int r = 32;
76985
76986diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
76987index b097cf8..3d40e14 100644
76988--- a/include/asm-generic/bitops/fls64.h
76989+++ b/include/asm-generic/bitops/fls64.h
76990@@ -15,7 +15,7 @@
76991 * at position 64.
76992 */
76993 #if BITS_PER_LONG == 32
76994-static __always_inline int fls64(__u64 x)
76995+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76996 {
76997 __u32 h = x >> 32;
76998 if (h)
76999@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
77000 return fls(x);
77001 }
77002 #elif BITS_PER_LONG == 64
77003-static __always_inline int fls64(__u64 x)
77004+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77005 {
77006 if (x == 0)
77007 return 0;
77008diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
77009index 1bfcfe5..e04c5c9 100644
77010--- a/include/asm-generic/cache.h
77011+++ b/include/asm-generic/cache.h
77012@@ -6,7 +6,7 @@
77013 * cache lines need to provide their own cache.h.
77014 */
77015
77016-#define L1_CACHE_SHIFT 5
77017-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
77018+#define L1_CACHE_SHIFT 5UL
77019+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
77020
77021 #endif /* __ASM_GENERIC_CACHE_H */
77022diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
77023index 0d68a1e..b74a761 100644
77024--- a/include/asm-generic/emergency-restart.h
77025+++ b/include/asm-generic/emergency-restart.h
77026@@ -1,7 +1,7 @@
77027 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
77028 #define _ASM_GENERIC_EMERGENCY_RESTART_H
77029
77030-static inline void machine_emergency_restart(void)
77031+static inline __noreturn void machine_emergency_restart(void)
77032 {
77033 machine_restart(NULL);
77034 }
77035diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
77036index 975e1cc..0b8a083 100644
77037--- a/include/asm-generic/io.h
77038+++ b/include/asm-generic/io.h
77039@@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
77040 * These are pretty trivial
77041 */
77042 #ifndef virt_to_phys
77043-static inline unsigned long virt_to_phys(volatile void *address)
77044+static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
77045 {
77046 return __pa((unsigned long)address);
77047 }
77048diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
77049index 90f99c7..00ce236 100644
77050--- a/include/asm-generic/kmap_types.h
77051+++ b/include/asm-generic/kmap_types.h
77052@@ -2,9 +2,9 @@
77053 #define _ASM_GENERIC_KMAP_TYPES_H
77054
77055 #ifdef __WITH_KM_FENCE
77056-# define KM_TYPE_NR 41
77057+# define KM_TYPE_NR 42
77058 #else
77059-# define KM_TYPE_NR 20
77060+# define KM_TYPE_NR 21
77061 #endif
77062
77063 #endif
77064diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77065index 9ceb03b..62b0b8f 100644
77066--- a/include/asm-generic/local.h
77067+++ b/include/asm-generic/local.h
77068@@ -23,24 +23,37 @@ typedef struct
77069 atomic_long_t a;
77070 } local_t;
77071
77072+typedef struct {
77073+ atomic_long_unchecked_t a;
77074+} local_unchecked_t;
77075+
77076 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77077
77078 #define local_read(l) atomic_long_read(&(l)->a)
77079+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77080 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77081+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77082 #define local_inc(l) atomic_long_inc(&(l)->a)
77083+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77084 #define local_dec(l) atomic_long_dec(&(l)->a)
77085+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77086 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77087+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77088 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77089+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77090
77091 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77092 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77093 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77094 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77095 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77096+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77097 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77098 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77099+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77100
77101 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77102+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77103 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77104 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77105 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77106diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77107index 725612b..9cc513a 100644
77108--- a/include/asm-generic/pgtable-nopmd.h
77109+++ b/include/asm-generic/pgtable-nopmd.h
77110@@ -1,14 +1,19 @@
77111 #ifndef _PGTABLE_NOPMD_H
77112 #define _PGTABLE_NOPMD_H
77113
77114-#ifndef __ASSEMBLY__
77115-
77116 #include <asm-generic/pgtable-nopud.h>
77117
77118-struct mm_struct;
77119-
77120 #define __PAGETABLE_PMD_FOLDED
77121
77122+#define PMD_SHIFT PUD_SHIFT
77123+#define PTRS_PER_PMD 1
77124+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77125+#define PMD_MASK (~(PMD_SIZE-1))
77126+
77127+#ifndef __ASSEMBLY__
77128+
77129+struct mm_struct;
77130+
77131 /*
77132 * Having the pmd type consist of a pud gets the size right, and allows
77133 * us to conceptually access the pud entry that this pmd is folded into
77134@@ -16,11 +21,6 @@ struct mm_struct;
77135 */
77136 typedef struct { pud_t pud; } pmd_t;
77137
77138-#define PMD_SHIFT PUD_SHIFT
77139-#define PTRS_PER_PMD 1
77140-#define PMD_SIZE (1UL << PMD_SHIFT)
77141-#define PMD_MASK (~(PMD_SIZE-1))
77142-
77143 /*
77144 * The "pud_xxx()" functions here are trivial for a folded two-level
77145 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77146diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77147index 810431d..0ec4804f 100644
77148--- a/include/asm-generic/pgtable-nopud.h
77149+++ b/include/asm-generic/pgtable-nopud.h
77150@@ -1,10 +1,15 @@
77151 #ifndef _PGTABLE_NOPUD_H
77152 #define _PGTABLE_NOPUD_H
77153
77154-#ifndef __ASSEMBLY__
77155-
77156 #define __PAGETABLE_PUD_FOLDED
77157
77158+#define PUD_SHIFT PGDIR_SHIFT
77159+#define PTRS_PER_PUD 1
77160+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77161+#define PUD_MASK (~(PUD_SIZE-1))
77162+
77163+#ifndef __ASSEMBLY__
77164+
77165 /*
77166 * Having the pud type consist of a pgd gets the size right, and allows
77167 * us to conceptually access the pgd entry that this pud is folded into
77168@@ -12,11 +17,6 @@
77169 */
77170 typedef struct { pgd_t pgd; } pud_t;
77171
77172-#define PUD_SHIFT PGDIR_SHIFT
77173-#define PTRS_PER_PUD 1
77174-#define PUD_SIZE (1UL << PUD_SHIFT)
77175-#define PUD_MASK (~(PUD_SIZE-1))
77176-
77177 /*
77178 * The "pgd_xxx()" functions here are trivial for a folded two-level
77179 * setup: the pud is never bad, and a pud always exists (as it's folded
77180@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77181 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77182
77183 #define pgd_populate(mm, pgd, pud) do { } while (0)
77184+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77185 /*
77186 * (puds are folded into pgds so this doesn't get actually called,
77187 * but the define is needed for a generic inline function.)
77188diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77189index a8015a7..7a4407b 100644
77190--- a/include/asm-generic/pgtable.h
77191+++ b/include/asm-generic/pgtable.h
77192@@ -815,6 +815,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77193 }
77194 #endif /* CONFIG_NUMA_BALANCING */
77195
77196+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77197+#ifdef CONFIG_PAX_KERNEXEC
77198+#error KERNEXEC requires pax_open_kernel
77199+#else
77200+static inline unsigned long pax_open_kernel(void) { return 0; }
77201+#endif
77202+#endif
77203+
77204+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77205+#ifdef CONFIG_PAX_KERNEXEC
77206+#error KERNEXEC requires pax_close_kernel
77207+#else
77208+static inline unsigned long pax_close_kernel(void) { return 0; }
77209+#endif
77210+#endif
77211+
77212 #endif /* CONFIG_MMU */
77213
77214 #endif /* !__ASSEMBLY__ */
77215diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77216index 72d8803..cb9749c 100644
77217--- a/include/asm-generic/uaccess.h
77218+++ b/include/asm-generic/uaccess.h
77219@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77220 return __clear_user(to, n);
77221 }
77222
77223+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77224+#ifdef CONFIG_PAX_MEMORY_UDEREF
77225+#error UDEREF requires pax_open_userland
77226+#else
77227+static inline unsigned long pax_open_userland(void) { return 0; }
77228+#endif
77229+#endif
77230+
77231+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77232+#ifdef CONFIG_PAX_MEMORY_UDEREF
77233+#error UDEREF requires pax_close_userland
77234+#else
77235+static inline unsigned long pax_close_userland(void) { return 0; }
77236+#endif
77237+#endif
77238+
77239 #endif /* __ASM_GENERIC_UACCESS_H */
77240diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77241index 146e4ff..f4f9609 100644
77242--- a/include/asm-generic/vmlinux.lds.h
77243+++ b/include/asm-generic/vmlinux.lds.h
77244@@ -251,6 +251,7 @@
77245 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77246 VMLINUX_SYMBOL(__start_rodata) = .; \
77247 *(.rodata) *(.rodata.*) \
77248+ *(.data..read_only) \
77249 *(__vermagic) /* Kernel version magic */ \
77250 . = ALIGN(8); \
77251 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77252@@ -737,17 +738,18 @@
77253 * section in the linker script will go there too. @phdr should have
77254 * a leading colon.
77255 *
77256- * Note that this macros defines __per_cpu_load as an absolute symbol.
77257+ * Note that this macros defines per_cpu_load as an absolute symbol.
77258 * If there is no need to put the percpu section at a predetermined
77259 * address, use PERCPU_SECTION.
77260 */
77261 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77262- VMLINUX_SYMBOL(__per_cpu_load) = .; \
77263- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77264+ per_cpu_load = .; \
77265+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77266 - LOAD_OFFSET) { \
77267+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77268 PERCPU_INPUT(cacheline) \
77269 } phdr \
77270- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77271+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77272
77273 /**
77274 * PERCPU_SECTION - define output section for percpu area, simple version
77275diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77276index 016c2f1..c4baa98 100644
77277--- a/include/crypto/algapi.h
77278+++ b/include/crypto/algapi.h
77279@@ -34,7 +34,7 @@ struct crypto_type {
77280 unsigned int maskclear;
77281 unsigned int maskset;
77282 unsigned int tfmsize;
77283-};
77284+} __do_const;
77285
77286 struct crypto_instance {
77287 struct crypto_alg alg;
77288diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77289index a7c2a86..078f1b6 100644
77290--- a/include/drm/drmP.h
77291+++ b/include/drm/drmP.h
77292@@ -68,6 +68,7 @@
77293 #include <linux/workqueue.h>
77294 #include <linux/poll.h>
77295 #include <asm/pgalloc.h>
77296+#include <asm/local.h>
77297 #include <drm/drm.h>
77298 #include <drm/drm_sarea.h>
77299 #include <drm/drm_vma_manager.h>
77300@@ -268,10 +269,12 @@ do { \
77301 * \param cmd command.
77302 * \param arg argument.
77303 */
77304-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77305+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77306+ struct drm_file *file_priv);
77307+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77308 struct drm_file *file_priv);
77309
77310-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77311+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77312 unsigned long arg);
77313
77314 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77315@@ -287,10 +290,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77316 struct drm_ioctl_desc {
77317 unsigned int cmd;
77318 int flags;
77319- drm_ioctl_t *func;
77320+ drm_ioctl_t func;
77321 unsigned int cmd_drv;
77322 const char *name;
77323-};
77324+} __do_const;
77325
77326 /**
77327 * Creates a driver or general drm_ioctl_desc array entry for the given
77328@@ -1001,7 +1004,8 @@ struct drm_info_list {
77329 int (*show)(struct seq_file*, void*); /** show callback */
77330 u32 driver_features; /**< Required driver features for this entry */
77331 void *data;
77332-};
77333+} __do_const;
77334+typedef struct drm_info_list __no_const drm_info_list_no_const;
77335
77336 /**
77337 * debugfs node structure. This structure represents a debugfs file.
77338@@ -1083,7 +1087,7 @@ struct drm_device {
77339
77340 /** \name Usage Counters */
77341 /*@{ */
77342- int open_count; /**< Outstanding files open */
77343+ local_t open_count; /**< Outstanding files open */
77344 int buf_use; /**< Buffers in use -- cannot alloc */
77345 atomic_t buf_alloc; /**< Buffer allocation in progress */
77346 /*@} */
77347diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77348index 36a5feb..d9f01aa 100644
77349--- a/include/drm/drm_crtc_helper.h
77350+++ b/include/drm/drm_crtc_helper.h
77351@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77352 struct drm_connector *connector);
77353 /* disable encoder when not in use - more explicit than dpms off */
77354 void (*disable)(struct drm_encoder *encoder);
77355-};
77356+} __no_const;
77357
77358 /**
77359 * drm_connector_helper_funcs - helper operations for connectors
77360diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77361index 012d58f..d0a0642 100644
77362--- a/include/drm/i915_pciids.h
77363+++ b/include/drm/i915_pciids.h
77364@@ -37,7 +37,7 @@
77365 */
77366 #define INTEL_VGA_DEVICE(id, info) { \
77367 0x8086, id, \
77368- ~0, ~0, \
77369+ PCI_ANY_ID, PCI_ANY_ID, \
77370 0x030000, 0xff0000, \
77371 (unsigned long) info }
77372
77373diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77374index 72dcbe8..8db58d7 100644
77375--- a/include/drm/ttm/ttm_memory.h
77376+++ b/include/drm/ttm/ttm_memory.h
77377@@ -48,7 +48,7 @@
77378
77379 struct ttm_mem_shrink {
77380 int (*do_shrink) (struct ttm_mem_shrink *);
77381-};
77382+} __no_const;
77383
77384 /**
77385 * struct ttm_mem_global - Global memory accounting structure.
77386diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77387index 49a8284..9643967 100644
77388--- a/include/drm/ttm/ttm_page_alloc.h
77389+++ b/include/drm/ttm/ttm_page_alloc.h
77390@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77391 */
77392 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77393
77394+struct device;
77395 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77396 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77397
77398diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77399index 4b840e8..155d235 100644
77400--- a/include/keys/asymmetric-subtype.h
77401+++ b/include/keys/asymmetric-subtype.h
77402@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77403 /* Verify the signature on a key of this subtype (optional) */
77404 int (*verify_signature)(const struct key *key,
77405 const struct public_key_signature *sig);
77406-};
77407+} __do_const;
77408
77409 /**
77410 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77411diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77412index c1da539..1dcec55 100644
77413--- a/include/linux/atmdev.h
77414+++ b/include/linux/atmdev.h
77415@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77416 #endif
77417
77418 struct k_atm_aal_stats {
77419-#define __HANDLE_ITEM(i) atomic_t i
77420+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77421 __AAL_STAT_ITEMS
77422 #undef __HANDLE_ITEM
77423 };
77424@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77425 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77426 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77427 struct module *owner;
77428-};
77429+} __do_const ;
77430
77431 struct atmphy_ops {
77432 int (*start)(struct atm_dev *dev);
77433diff --git a/include/linux/audit.h b/include/linux/audit.h
77434index 22cfddb..ab759e8 100644
77435--- a/include/linux/audit.h
77436+++ b/include/linux/audit.h
77437@@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
77438 extern unsigned int audit_serial(void);
77439 extern int auditsc_get_stamp(struct audit_context *ctx,
77440 struct timespec *t, unsigned int *serial);
77441-extern int audit_set_loginuid(kuid_t loginuid);
77442+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77443
77444 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77445 {
77446diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77447index 61f29e5..e67c658 100644
77448--- a/include/linux/binfmts.h
77449+++ b/include/linux/binfmts.h
77450@@ -44,7 +44,7 @@ struct linux_binprm {
77451 unsigned interp_flags;
77452 unsigned interp_data;
77453 unsigned long loader, exec;
77454-};
77455+} __randomize_layout;
77456
77457 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77458 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77459@@ -73,8 +73,10 @@ struct linux_binfmt {
77460 int (*load_binary)(struct linux_binprm *);
77461 int (*load_shlib)(struct file *);
77462 int (*core_dump)(struct coredump_params *cprm);
77463+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77464+ void (*handle_mmap)(struct file *);
77465 unsigned long min_coredump; /* minimal dump size */
77466-};
77467+} __do_const __randomize_layout;
77468
77469 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77470
77471diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77472index be5fd38..d71192a 100644
77473--- a/include/linux/bitops.h
77474+++ b/include/linux/bitops.h
77475@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77476 * @word: value to rotate
77477 * @shift: bits to roll
77478 */
77479-static inline __u32 rol32(__u32 word, unsigned int shift)
77480+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77481 {
77482 return (word << shift) | (word >> (32 - shift));
77483 }
77484@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77485 * @word: value to rotate
77486 * @shift: bits to roll
77487 */
77488-static inline __u32 ror32(__u32 word, unsigned int shift)
77489+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77490 {
77491 return (word >> shift) | (word << (32 - shift));
77492 }
77493@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77494 return (__s32)(value << shift) >> shift;
77495 }
77496
77497-static inline unsigned fls_long(unsigned long l)
77498+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77499 {
77500 if (sizeof(l) == 4)
77501 return fls(l);
77502diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77503index 0d84981..bb741c0 100644
77504--- a/include/linux/blkdev.h
77505+++ b/include/linux/blkdev.h
77506@@ -1584,7 +1584,7 @@ struct block_device_operations {
77507 /* this callback is with swap_lock and sometimes page table lock held */
77508 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77509 struct module *owner;
77510-};
77511+} __do_const;
77512
77513 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77514 unsigned long);
77515diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77516index afc1343..9735539 100644
77517--- a/include/linux/blktrace_api.h
77518+++ b/include/linux/blktrace_api.h
77519@@ -25,7 +25,7 @@ struct blk_trace {
77520 struct dentry *dropped_file;
77521 struct dentry *msg_file;
77522 struct list_head running_list;
77523- atomic_t dropped;
77524+ atomic_unchecked_t dropped;
77525 };
77526
77527 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77528diff --git a/include/linux/cache.h b/include/linux/cache.h
77529index 17e7e82..1d7da26 100644
77530--- a/include/linux/cache.h
77531+++ b/include/linux/cache.h
77532@@ -16,6 +16,14 @@
77533 #define __read_mostly
77534 #endif
77535
77536+#ifndef __read_only
77537+#ifdef CONFIG_PAX_KERNEXEC
77538+#error KERNEXEC requires __read_only
77539+#else
77540+#define __read_only __read_mostly
77541+#endif
77542+#endif
77543+
77544 #ifndef ____cacheline_aligned
77545 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77546 #endif
77547diff --git a/include/linux/capability.h b/include/linux/capability.h
77548index 84b13ad..172cdee 100644
77549--- a/include/linux/capability.h
77550+++ b/include/linux/capability.h
77551@@ -211,9 +211,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
77552 extern bool capable(int cap);
77553 extern bool ns_capable(struct user_namespace *ns, int cap);
77554 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
77555+extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
77556 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77557+extern bool capable_nolog(int cap);
77558+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77559
77560 /* audit system wants to get cap info from files as well */
77561 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77562
77563+extern int is_privileged_binary(const struct dentry *dentry);
77564+
77565 #endif /* !_LINUX_CAPABILITY_H */
77566diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77567index 8609d57..86e4d79 100644
77568--- a/include/linux/cdrom.h
77569+++ b/include/linux/cdrom.h
77570@@ -87,7 +87,6 @@ struct cdrom_device_ops {
77571
77572 /* driver specifications */
77573 const int capability; /* capability flags */
77574- int n_minors; /* number of active minor devices */
77575 /* handle uniform packets for scsi type devices (scsi,atapi) */
77576 int (*generic_packet) (struct cdrom_device_info *,
77577 struct packet_command *);
77578diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77579index 4ce9056..86caac6 100644
77580--- a/include/linux/cleancache.h
77581+++ b/include/linux/cleancache.h
77582@@ -31,7 +31,7 @@ struct cleancache_ops {
77583 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77584 void (*invalidate_inode)(int, struct cleancache_filekey);
77585 void (*invalidate_fs)(int);
77586-};
77587+} __no_const;
77588
77589 extern struct cleancache_ops *
77590 cleancache_register_ops(struct cleancache_ops *ops);
77591diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77592index 5119174..8e264f8 100644
77593--- a/include/linux/clk-provider.h
77594+++ b/include/linux/clk-provider.h
77595@@ -174,6 +174,7 @@ struct clk_ops {
77596 void (*init)(struct clk_hw *hw);
77597 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
77598 };
77599+typedef struct clk_ops __no_const clk_ops_no_const;
77600
77601 /**
77602 * struct clk_init_data - holds init data that's common to all clocks and is
77603diff --git a/include/linux/compat.h b/include/linux/compat.h
77604index e649426..a74047b 100644
77605--- a/include/linux/compat.h
77606+++ b/include/linux/compat.h
77607@@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77608 compat_size_t __user *len_ptr);
77609
77610 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77611-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77612+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77613 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77614 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77615 compat_ssize_t msgsz, int msgflg);
77616@@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77617 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77618 compat_ulong_t addr, compat_ulong_t data);
77619 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77620- compat_long_t addr, compat_long_t data);
77621+ compat_ulong_t addr, compat_ulong_t data);
77622
77623 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77624 /*
77625diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77626index 2507fd2..55203f8 100644
77627--- a/include/linux/compiler-gcc4.h
77628+++ b/include/linux/compiler-gcc4.h
77629@@ -39,9 +39,34 @@
77630 # define __compiletime_warning(message) __attribute__((warning(message)))
77631 # define __compiletime_error(message) __attribute__((error(message)))
77632 #endif /* __CHECKER__ */
77633+
77634+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77635+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77636+#define __bos0(ptr) __bos((ptr), 0)
77637+#define __bos1(ptr) __bos((ptr), 1)
77638 #endif /* GCC_VERSION >= 40300 */
77639
77640 #if GCC_VERSION >= 40500
77641+
77642+#ifdef RANDSTRUCT_PLUGIN
77643+#define __randomize_layout __attribute__((randomize_layout))
77644+#define __no_randomize_layout __attribute__((no_randomize_layout))
77645+#endif
77646+
77647+#ifdef CONSTIFY_PLUGIN
77648+#define __no_const __attribute__((no_const))
77649+#define __do_const __attribute__((do_const))
77650+#endif
77651+
77652+#ifdef SIZE_OVERFLOW_PLUGIN
77653+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77654+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77655+#endif
77656+
77657+#ifdef LATENT_ENTROPY_PLUGIN
77658+#define __latent_entropy __attribute__((latent_entropy))
77659+#endif
77660+
77661 /*
77662 * Mark a position in code as unreachable. This can be used to
77663 * suppress control flow warnings after asm blocks that transfer
77664diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77665index ee7239e..7c11769 100644
77666--- a/include/linux/compiler.h
77667+++ b/include/linux/compiler.h
77668@@ -5,11 +5,14 @@
77669
77670 #ifdef __CHECKER__
77671 # define __user __attribute__((noderef, address_space(1)))
77672+# define __force_user __force __user
77673 # define __kernel __attribute__((address_space(0)))
77674+# define __force_kernel __force __kernel
77675 # define __safe __attribute__((safe))
77676 # define __force __attribute__((force))
77677 # define __nocast __attribute__((nocast))
77678 # define __iomem __attribute__((noderef, address_space(2)))
77679+# define __force_iomem __force __iomem
77680 # define __must_hold(x) __attribute__((context(x,1,1)))
77681 # define __acquires(x) __attribute__((context(x,0,1)))
77682 # define __releases(x) __attribute__((context(x,1,0)))
77683@@ -17,20 +20,37 @@
77684 # define __release(x) __context__(x,-1)
77685 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77686 # define __percpu __attribute__((noderef, address_space(3)))
77687+# define __force_percpu __force __percpu
77688 #ifdef CONFIG_SPARSE_RCU_POINTER
77689 # define __rcu __attribute__((noderef, address_space(4)))
77690+# define __force_rcu __force __rcu
77691 #else
77692 # define __rcu
77693+# define __force_rcu
77694 #endif
77695 extern void __chk_user_ptr(const volatile void __user *);
77696 extern void __chk_io_ptr(const volatile void __iomem *);
77697 #else
77698-# define __user
77699-# define __kernel
77700+# ifdef CHECKER_PLUGIN
77701+//# define __user
77702+//# define __force_user
77703+//# define __kernel
77704+//# define __force_kernel
77705+# else
77706+# ifdef STRUCTLEAK_PLUGIN
77707+# define __user __attribute__((user))
77708+# else
77709+# define __user
77710+# endif
77711+# define __force_user
77712+# define __kernel
77713+# define __force_kernel
77714+# endif
77715 # define __safe
77716 # define __force
77717 # define __nocast
77718 # define __iomem
77719+# define __force_iomem
77720 # define __chk_user_ptr(x) (void)0
77721 # define __chk_io_ptr(x) (void)0
77722 # define __builtin_warning(x, y...) (1)
77723@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77724 # define __release(x) (void)0
77725 # define __cond_lock(x,c) (c)
77726 # define __percpu
77727+# define __force_percpu
77728 # define __rcu
77729+# define __force_rcu
77730 #endif
77731
77732 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77733@@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77734 # define __attribute_const__ /* unimplemented */
77735 #endif
77736
77737+#ifndef __randomize_layout
77738+# define __randomize_layout
77739+#endif
77740+
77741+#ifndef __no_randomize_layout
77742+# define __no_randomize_layout
77743+#endif
77744+
77745+#ifndef __no_const
77746+# define __no_const
77747+#endif
77748+
77749+#ifndef __do_const
77750+# define __do_const
77751+#endif
77752+
77753+#ifndef __size_overflow
77754+# define __size_overflow(...)
77755+#endif
77756+
77757+#ifndef __intentional_overflow
77758+# define __intentional_overflow(...)
77759+#endif
77760+
77761+#ifndef __latent_entropy
77762+# define __latent_entropy
77763+#endif
77764+
77765 /*
77766 * Tell gcc if a function is cold. The compiler will assume any path
77767 * directly leading to the call is unlikely.
77768@@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77769 #define __cold
77770 #endif
77771
77772+#ifndef __alloc_size
77773+#define __alloc_size(...)
77774+#endif
77775+
77776+#ifndef __bos
77777+#define __bos(ptr, arg)
77778+#endif
77779+
77780+#ifndef __bos0
77781+#define __bos0(ptr)
77782+#endif
77783+
77784+#ifndef __bos1
77785+#define __bos1(ptr)
77786+#endif
77787+
77788 /* Simple shorthand for a section definition */
77789 #ifndef __section
77790 # define __section(S) __attribute__ ((__section__(#S)))
77791@@ -369,7 +435,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77792 * use is to mediate communication between process-level code and irq/NMI
77793 * handlers, all running on the same CPU.
77794 */
77795-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77796+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77797+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77798
77799 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77800 #ifdef CONFIG_KPROBES
77801diff --git a/include/linux/completion.h b/include/linux/completion.h
77802index 5d5aaae..0ea9b84 100644
77803--- a/include/linux/completion.h
77804+++ b/include/linux/completion.h
77805@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77806
77807 extern void wait_for_completion(struct completion *);
77808 extern void wait_for_completion_io(struct completion *);
77809-extern int wait_for_completion_interruptible(struct completion *x);
77810-extern int wait_for_completion_killable(struct completion *x);
77811+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77812+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77813 extern unsigned long wait_for_completion_timeout(struct completion *x,
77814- unsigned long timeout);
77815+ unsigned long timeout) __intentional_overflow(-1);
77816 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77817- unsigned long timeout);
77818+ unsigned long timeout) __intentional_overflow(-1);
77819 extern long wait_for_completion_interruptible_timeout(
77820- struct completion *x, unsigned long timeout);
77821+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77822 extern long wait_for_completion_killable_timeout(
77823- struct completion *x, unsigned long timeout);
77824+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77825 extern bool try_wait_for_completion(struct completion *x);
77826 extern bool completion_done(struct completion *x);
77827
77828diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77829index 34025df..d94bbbc 100644
77830--- a/include/linux/configfs.h
77831+++ b/include/linux/configfs.h
77832@@ -125,7 +125,7 @@ struct configfs_attribute {
77833 const char *ca_name;
77834 struct module *ca_owner;
77835 umode_t ca_mode;
77836-};
77837+} __do_const;
77838
77839 /*
77840 * Users often need to create attribute structures for their configurable
77841diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77842index 5ae5100..b809662 100644
77843--- a/include/linux/cpufreq.h
77844+++ b/include/linux/cpufreq.h
77845@@ -200,6 +200,7 @@ struct global_attr {
77846 ssize_t (*store)(struct kobject *a, struct attribute *b,
77847 const char *c, size_t count);
77848 };
77849+typedef struct global_attr __no_const global_attr_no_const;
77850
77851 #define define_one_global_ro(_name) \
77852 static struct global_attr _name = \
77853@@ -242,7 +243,7 @@ struct cpufreq_driver {
77854 bool boost_supported;
77855 bool boost_enabled;
77856 int (*set_boost) (int state);
77857-};
77858+} __do_const;
77859
77860 /* flags */
77861 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77862diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77863index b0238cb..db89e1e 100644
77864--- a/include/linux/cpuidle.h
77865+++ b/include/linux/cpuidle.h
77866@@ -50,7 +50,8 @@ struct cpuidle_state {
77867 int index);
77868
77869 int (*enter_dead) (struct cpuidle_device *dev, int index);
77870-};
77871+} __do_const;
77872+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77873
77874 /* Idle State Flags */
77875 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77876@@ -211,7 +212,7 @@ struct cpuidle_governor {
77877 void (*reflect) (struct cpuidle_device *dev, int index);
77878
77879 struct module *owner;
77880-};
77881+} __do_const;
77882
77883 #ifdef CONFIG_CPU_IDLE
77884 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77885diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77886index d08e4d2..95fad61 100644
77887--- a/include/linux/cpumask.h
77888+++ b/include/linux/cpumask.h
77889@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77890 }
77891
77892 /* Valid inputs for n are -1 and 0. */
77893-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77894+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77895 {
77896 return n+1;
77897 }
77898
77899-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77900+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77901 {
77902 return n+1;
77903 }
77904
77905-static inline unsigned int cpumask_next_and(int n,
77906+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77907 const struct cpumask *srcp,
77908 const struct cpumask *andp)
77909 {
77910@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77911 *
77912 * Returns >= nr_cpu_ids if no further cpus set.
77913 */
77914-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77915+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77916 {
77917 /* -1 is a legal arg here. */
77918 if (n != -1)
77919@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77920 *
77921 * Returns >= nr_cpu_ids if no further cpus unset.
77922 */
77923-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77924+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77925 {
77926 /* -1 is a legal arg here. */
77927 if (n != -1)
77928@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77929 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77930 }
77931
77932-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77933+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77934 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77935
77936 /**
77937diff --git a/include/linux/cred.h b/include/linux/cred.h
77938index f61d6c8..d372d95 100644
77939--- a/include/linux/cred.h
77940+++ b/include/linux/cred.h
77941@@ -35,7 +35,7 @@ struct group_info {
77942 int nblocks;
77943 kgid_t small_block[NGROUPS_SMALL];
77944 kgid_t *blocks[0];
77945-};
77946+} __randomize_layout;
77947
77948 /**
77949 * get_group_info - Get a reference to a group info structure
77950@@ -136,7 +136,7 @@ struct cred {
77951 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77952 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77953 struct rcu_head rcu; /* RCU deletion hook */
77954-};
77955+} __randomize_layout;
77956
77957 extern void __put_cred(struct cred *);
77958 extern void exit_creds(struct task_struct *);
77959@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
77960 static inline void validate_process_creds(void)
77961 {
77962 }
77963+static inline void validate_task_creds(struct task_struct *task)
77964+{
77965+}
77966 #endif
77967
77968 /**
77969@@ -322,6 +325,7 @@ static inline void put_cred(const struct cred *_cred)
77970
77971 #define task_uid(task) (task_cred_xxx((task), uid))
77972 #define task_euid(task) (task_cred_xxx((task), euid))
77973+#define task_securebits(task) (task_cred_xxx((task), securebits))
77974
77975 #define current_cred_xxx(xxx) \
77976 ({ \
77977diff --git a/include/linux/crypto.h b/include/linux/crypto.h
77978index b92eadf..b4ecdc1 100644
77979--- a/include/linux/crypto.h
77980+++ b/include/linux/crypto.h
77981@@ -373,7 +373,7 @@ struct cipher_tfm {
77982 const u8 *key, unsigned int keylen);
77983 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77984 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77985-};
77986+} __no_const;
77987
77988 struct hash_tfm {
77989 int (*init)(struct hash_desc *desc);
77990@@ -394,13 +394,13 @@ struct compress_tfm {
77991 int (*cot_decompress)(struct crypto_tfm *tfm,
77992 const u8 *src, unsigned int slen,
77993 u8 *dst, unsigned int *dlen);
77994-};
77995+} __no_const;
77996
77997 struct rng_tfm {
77998 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
77999 unsigned int dlen);
78000 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
78001-};
78002+} __no_const;
78003
78004 #define crt_ablkcipher crt_u.ablkcipher
78005 #define crt_aead crt_u.aead
78006diff --git a/include/linux/ctype.h b/include/linux/ctype.h
78007index 653589e..4ef254a 100644
78008--- a/include/linux/ctype.h
78009+++ b/include/linux/ctype.h
78010@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
78011 * Fast implementation of tolower() for internal usage. Do not use in your
78012 * code.
78013 */
78014-static inline char _tolower(const char c)
78015+static inline unsigned char _tolower(const unsigned char c)
78016 {
78017 return c | 0x20;
78018 }
78019diff --git a/include/linux/dcache.h b/include/linux/dcache.h
78020index 3c7ec32..4ca97cc 100644
78021--- a/include/linux/dcache.h
78022+++ b/include/linux/dcache.h
78023@@ -133,7 +133,7 @@ struct dentry {
78024 } d_u;
78025 struct list_head d_subdirs; /* our children */
78026 struct hlist_node d_alias; /* inode alias list */
78027-};
78028+} __randomize_layout;
78029
78030 /*
78031 * dentry->d_lock spinlock nesting subclasses:
78032diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
78033index 7925bf0..d5143d2 100644
78034--- a/include/linux/decompress/mm.h
78035+++ b/include/linux/decompress/mm.h
78036@@ -77,7 +77,7 @@ static void free(void *where)
78037 * warnings when not needed (indeed large_malloc / large_free are not
78038 * needed by inflate */
78039
78040-#define malloc(a) kmalloc(a, GFP_KERNEL)
78041+#define malloc(a) kmalloc((a), GFP_KERNEL)
78042 #define free(a) kfree(a)
78043
78044 #define large_malloc(a) vmalloc(a)
78045diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
78046index d48dc00..211ee54 100644
78047--- a/include/linux/devfreq.h
78048+++ b/include/linux/devfreq.h
78049@@ -114,7 +114,7 @@ struct devfreq_governor {
78050 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
78051 int (*event_handler)(struct devfreq *devfreq,
78052 unsigned int event, void *data);
78053-};
78054+} __do_const;
78055
78056 /**
78057 * struct devfreq - Device devfreq structure
78058diff --git a/include/linux/device.h b/include/linux/device.h
78059index d1d1c05..a90fdb0 100644
78060--- a/include/linux/device.h
78061+++ b/include/linux/device.h
78062@@ -310,7 +310,7 @@ struct subsys_interface {
78063 struct list_head node;
78064 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78065 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78066-};
78067+} __do_const;
78068
78069 int subsys_interface_register(struct subsys_interface *sif);
78070 void subsys_interface_unregister(struct subsys_interface *sif);
78071@@ -506,7 +506,7 @@ struct device_type {
78072 void (*release)(struct device *dev);
78073
78074 const struct dev_pm_ops *pm;
78075-};
78076+} __do_const;
78077
78078 /* interface for exporting device attributes */
78079 struct device_attribute {
78080@@ -516,11 +516,12 @@ struct device_attribute {
78081 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78082 const char *buf, size_t count);
78083 };
78084+typedef struct device_attribute __no_const device_attribute_no_const;
78085
78086 struct dev_ext_attribute {
78087 struct device_attribute attr;
78088 void *var;
78089-};
78090+} __do_const;
78091
78092 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78093 char *buf);
78094diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78095index fd4aee2..1f28db9 100644
78096--- a/include/linux/dma-mapping.h
78097+++ b/include/linux/dma-mapping.h
78098@@ -54,7 +54,7 @@ struct dma_map_ops {
78099 u64 (*get_required_mask)(struct device *dev);
78100 #endif
78101 int is_phys;
78102-};
78103+} __do_const;
78104
78105 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78106
78107diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78108index 72cb0dd..7fe9a4b 100644
78109--- a/include/linux/dmaengine.h
78110+++ b/include/linux/dmaengine.h
78111@@ -1147,9 +1147,9 @@ struct dma_pinned_list {
78112 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78113 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78114
78115-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78116+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78117 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78118-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78119+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78120 struct dma_pinned_list *pinned_list, struct page *page,
78121 unsigned int offset, size_t len);
78122
78123diff --git a/include/linux/efi.h b/include/linux/efi.h
78124index 6c100ff..e3289b4 100644
78125--- a/include/linux/efi.h
78126+++ b/include/linux/efi.h
78127@@ -1009,6 +1009,7 @@ struct efivar_operations {
78128 efi_set_variable_t *set_variable;
78129 efi_query_variable_store_t *query_variable_store;
78130 };
78131+typedef struct efivar_operations __no_const efivar_operations_no_const;
78132
78133 struct efivars {
78134 /*
78135diff --git a/include/linux/elf.h b/include/linux/elf.h
78136index 67a5fa7..b817372 100644
78137--- a/include/linux/elf.h
78138+++ b/include/linux/elf.h
78139@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78140 #define elf_note elf32_note
78141 #define elf_addr_t Elf32_Off
78142 #define Elf_Half Elf32_Half
78143+#define elf_dyn Elf32_Dyn
78144
78145 #else
78146
78147@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78148 #define elf_note elf64_note
78149 #define elf_addr_t Elf64_Off
78150 #define Elf_Half Elf64_Half
78151+#define elf_dyn Elf64_Dyn
78152
78153 #endif
78154
78155diff --git a/include/linux/err.h b/include/linux/err.h
78156index a729120..6ede2c9 100644
78157--- a/include/linux/err.h
78158+++ b/include/linux/err.h
78159@@ -20,12 +20,12 @@
78160
78161 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78162
78163-static inline void * __must_check ERR_PTR(long error)
78164+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78165 {
78166 return (void *) error;
78167 }
78168
78169-static inline long __must_check PTR_ERR(__force const void *ptr)
78170+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78171 {
78172 return (long) ptr;
78173 }
78174diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78175index f488145..3b6b04e 100644
78176--- a/include/linux/extcon.h
78177+++ b/include/linux/extcon.h
78178@@ -135,7 +135,7 @@ struct extcon_dev {
78179 /* /sys/class/extcon/.../mutually_exclusive/... */
78180 struct attribute_group attr_g_muex;
78181 struct attribute **attrs_muex;
78182- struct device_attribute *d_attrs_muex;
78183+ device_attribute_no_const *d_attrs_muex;
78184 };
78185
78186 /**
78187diff --git a/include/linux/fb.h b/include/linux/fb.h
78188index fe6ac95..898d41d 100644
78189--- a/include/linux/fb.h
78190+++ b/include/linux/fb.h
78191@@ -304,7 +304,7 @@ struct fb_ops {
78192 /* called at KDB enter and leave time to prepare the console */
78193 int (*fb_debug_enter)(struct fb_info *info);
78194 int (*fb_debug_leave)(struct fb_info *info);
78195-};
78196+} __do_const;
78197
78198 #ifdef CONFIG_FB_TILEBLITTING
78199 #define FB_TILE_CURSOR_NONE 0
78200diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78201index 230f87b..1fd0485 100644
78202--- a/include/linux/fdtable.h
78203+++ b/include/linux/fdtable.h
78204@@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78205 void put_files_struct(struct files_struct *fs);
78206 void reset_files_struct(struct files_struct *);
78207 int unshare_files(struct files_struct **);
78208-struct files_struct *dup_fd(struct files_struct *, int *);
78209+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78210 void do_close_on_exec(struct files_struct *);
78211 int iterate_fd(struct files_struct *, unsigned,
78212 int (*)(const void *, struct file *, unsigned),
78213diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78214index 8293262..2b3b8bd 100644
78215--- a/include/linux/frontswap.h
78216+++ b/include/linux/frontswap.h
78217@@ -11,7 +11,7 @@ struct frontswap_ops {
78218 int (*load)(unsigned, pgoff_t, struct page *);
78219 void (*invalidate_page)(unsigned, pgoff_t);
78220 void (*invalidate_area)(unsigned);
78221-};
78222+} __no_const;
78223
78224 extern bool frontswap_enabled;
78225 extern struct frontswap_ops *
78226diff --git a/include/linux/fs.h b/include/linux/fs.h
78227index 8780312..425cc22 100644
78228--- a/include/linux/fs.h
78229+++ b/include/linux/fs.h
78230@@ -398,7 +398,7 @@ struct address_space {
78231 spinlock_t private_lock; /* for use by the address_space */
78232 struct list_head private_list; /* ditto */
78233 void *private_data; /* ditto */
78234-} __attribute__((aligned(sizeof(long))));
78235+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78236 /*
78237 * On most architectures that alignment is already the case; but
78238 * must be enforced here for CRIS, to let the least significant bit
78239@@ -441,7 +441,7 @@ struct block_device {
78240 int bd_fsfreeze_count;
78241 /* Mutex for freeze */
78242 struct mutex bd_fsfreeze_mutex;
78243-};
78244+} __randomize_layout;
78245
78246 /*
78247 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78248@@ -585,7 +585,7 @@ struct inode {
78249 #endif
78250
78251 void *i_private; /* fs or device private pointer */
78252-};
78253+} __randomize_layout;
78254
78255 static inline int inode_unhashed(struct inode *inode)
78256 {
78257@@ -778,7 +778,7 @@ struct file {
78258 struct list_head f_tfile_llink;
78259 #endif /* #ifdef CONFIG_EPOLL */
78260 struct address_space *f_mapping;
78261-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78262+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78263
78264 struct file_handle {
78265 __u32 handle_bytes;
78266@@ -906,7 +906,7 @@ struct file_lock {
78267 int state; /* state of grant or error if -ve */
78268 } afs;
78269 } fl_u;
78270-};
78271+} __randomize_layout;
78272
78273 /* The following constant reflects the upper bound of the file/locking space */
78274 #ifndef OFFSET_MAX
78275@@ -1255,7 +1255,7 @@ struct super_block {
78276 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78277 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78278 struct rcu_head rcu;
78279-};
78280+} __randomize_layout;
78281
78282 extern struct timespec current_fs_time(struct super_block *sb);
78283
78284@@ -1477,7 +1477,8 @@ struct file_operations {
78285 long (*fallocate)(struct file *file, int mode, loff_t offset,
78286 loff_t len);
78287 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78288-};
78289+} __do_const __randomize_layout;
78290+typedef struct file_operations __no_const file_operations_no_const;
78291
78292 struct inode_operations {
78293 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78294@@ -2757,4 +2758,14 @@ static inline bool dir_relax(struct inode *inode)
78295 return !IS_DEADDIR(inode);
78296 }
78297
78298+static inline bool is_sidechannel_device(const struct inode *inode)
78299+{
78300+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78301+ umode_t mode = inode->i_mode;
78302+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78303+#else
78304+ return false;
78305+#endif
78306+}
78307+
78308 #endif /* _LINUX_FS_H */
78309diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78310index 0efc3e6..fd23610 100644
78311--- a/include/linux/fs_struct.h
78312+++ b/include/linux/fs_struct.h
78313@@ -6,13 +6,13 @@
78314 #include <linux/seqlock.h>
78315
78316 struct fs_struct {
78317- int users;
78318+ atomic_t users;
78319 spinlock_t lock;
78320 seqcount_t seq;
78321 int umask;
78322 int in_exec;
78323 struct path root, pwd;
78324-};
78325+} __randomize_layout;
78326
78327 extern struct kmem_cache *fs_cachep;
78328
78329diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78330index 7714849..a4a5c7a 100644
78331--- a/include/linux/fscache-cache.h
78332+++ b/include/linux/fscache-cache.h
78333@@ -113,7 +113,7 @@ struct fscache_operation {
78334 fscache_operation_release_t release;
78335 };
78336
78337-extern atomic_t fscache_op_debug_id;
78338+extern atomic_unchecked_t fscache_op_debug_id;
78339 extern void fscache_op_work_func(struct work_struct *work);
78340
78341 extern void fscache_enqueue_operation(struct fscache_operation *);
78342@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78343 INIT_WORK(&op->work, fscache_op_work_func);
78344 atomic_set(&op->usage, 1);
78345 op->state = FSCACHE_OP_ST_INITIALISED;
78346- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78347+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78348 op->processor = processor;
78349 op->release = release;
78350 INIT_LIST_HEAD(&op->pend_link);
78351diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78352index 115bb81..e7b812b 100644
78353--- a/include/linux/fscache.h
78354+++ b/include/linux/fscache.h
78355@@ -152,7 +152,7 @@ struct fscache_cookie_def {
78356 * - this is mandatory for any object that may have data
78357 */
78358 void (*now_uncached)(void *cookie_netfs_data);
78359-};
78360+} __do_const;
78361
78362 /*
78363 * fscache cached network filesystem type
78364diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78365index 1c804b0..1432c2b 100644
78366--- a/include/linux/fsnotify.h
78367+++ b/include/linux/fsnotify.h
78368@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78369 struct inode *inode = file_inode(file);
78370 __u32 mask = FS_ACCESS;
78371
78372+ if (is_sidechannel_device(inode))
78373+ return;
78374+
78375 if (S_ISDIR(inode->i_mode))
78376 mask |= FS_ISDIR;
78377
78378@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78379 struct inode *inode = file_inode(file);
78380 __u32 mask = FS_MODIFY;
78381
78382+ if (is_sidechannel_device(inode))
78383+ return;
78384+
78385 if (S_ISDIR(inode->i_mode))
78386 mask |= FS_ISDIR;
78387
78388@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78389 */
78390 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78391 {
78392- return kstrdup(name, GFP_KERNEL);
78393+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78394 }
78395
78396 /*
78397diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78398index 9f3c275..8bdff5d 100644
78399--- a/include/linux/genhd.h
78400+++ b/include/linux/genhd.h
78401@@ -194,7 +194,7 @@ struct gendisk {
78402 struct kobject *slave_dir;
78403
78404 struct timer_rand_state *random;
78405- atomic_t sync_io; /* RAID */
78406+ atomic_unchecked_t sync_io; /* RAID */
78407 struct disk_events *ev;
78408 #ifdef CONFIG_BLK_DEV_INTEGRITY
78409 struct blk_integrity *integrity;
78410@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78411 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78412
78413 /* drivers/char/random.c */
78414-extern void add_disk_randomness(struct gendisk *disk);
78415+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78416 extern void rand_initialize_disk(struct gendisk *disk);
78417
78418 static inline sector_t get_start_sect(struct block_device *bdev)
78419diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78420index c0894dd..2fbf10c 100644
78421--- a/include/linux/genl_magic_func.h
78422+++ b/include/linux/genl_magic_func.h
78423@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78424 },
78425
78426 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78427-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78428+static struct genl_ops ZZZ_genl_ops[] = {
78429 #include GENL_MAGIC_INCLUDE_FILE
78430 };
78431
78432diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78433index 39b81dc..819dc51 100644
78434--- a/include/linux/gfp.h
78435+++ b/include/linux/gfp.h
78436@@ -36,6 +36,13 @@ struct vm_area_struct;
78437 #define ___GFP_NO_KSWAPD 0x400000u
78438 #define ___GFP_OTHER_NODE 0x800000u
78439 #define ___GFP_WRITE 0x1000000u
78440+
78441+#ifdef CONFIG_PAX_USERCOPY_SLABS
78442+#define ___GFP_USERCOPY 0x2000000u
78443+#else
78444+#define ___GFP_USERCOPY 0
78445+#endif
78446+
78447 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78448
78449 /*
78450@@ -93,6 +100,7 @@ struct vm_area_struct;
78451 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78452 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78453 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78454+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78455
78456 /*
78457 * This may seem redundant, but it's a way of annotating false positives vs.
78458@@ -100,7 +108,7 @@ struct vm_area_struct;
78459 */
78460 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78461
78462-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78463+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78464 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78465
78466 /* This equals 0, but use constants in case they ever change */
78467@@ -158,6 +166,8 @@ struct vm_area_struct;
78468 /* 4GB DMA on some platforms */
78469 #define GFP_DMA32 __GFP_DMA32
78470
78471+#define GFP_USERCOPY __GFP_USERCOPY
78472+
78473 /* Convert GFP flags to their corresponding migrate type */
78474 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78475 {
78476diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78477new file mode 100644
78478index 0000000..edb2cb6
78479--- /dev/null
78480+++ b/include/linux/gracl.h
78481@@ -0,0 +1,340 @@
78482+#ifndef GR_ACL_H
78483+#define GR_ACL_H
78484+
78485+#include <linux/grdefs.h>
78486+#include <linux/resource.h>
78487+#include <linux/capability.h>
78488+#include <linux/dcache.h>
78489+#include <asm/resource.h>
78490+
78491+/* Major status information */
78492+
78493+#define GR_VERSION "grsecurity 3.0"
78494+#define GRSECURITY_VERSION 0x3000
78495+
78496+enum {
78497+ GR_SHUTDOWN = 0,
78498+ GR_ENABLE = 1,
78499+ GR_SPROLE = 2,
78500+ GR_OLDRELOAD = 3,
78501+ GR_SEGVMOD = 4,
78502+ GR_STATUS = 5,
78503+ GR_UNSPROLE = 6,
78504+ GR_PASSSET = 7,
78505+ GR_SPROLEPAM = 8,
78506+ GR_RELOAD = 9,
78507+};
78508+
78509+/* Password setup definitions
78510+ * kernel/grhash.c */
78511+enum {
78512+ GR_PW_LEN = 128,
78513+ GR_SALT_LEN = 16,
78514+ GR_SHA_LEN = 32,
78515+};
78516+
78517+enum {
78518+ GR_SPROLE_LEN = 64,
78519+};
78520+
78521+enum {
78522+ GR_NO_GLOB = 0,
78523+ GR_REG_GLOB,
78524+ GR_CREATE_GLOB
78525+};
78526+
78527+#define GR_NLIMITS 32
78528+
78529+/* Begin Data Structures */
78530+
78531+struct sprole_pw {
78532+ unsigned char *rolename;
78533+ unsigned char salt[GR_SALT_LEN];
78534+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78535+};
78536+
78537+struct name_entry {
78538+ __u32 key;
78539+ ino_t inode;
78540+ dev_t device;
78541+ char *name;
78542+ __u16 len;
78543+ __u8 deleted;
78544+ struct name_entry *prev;
78545+ struct name_entry *next;
78546+};
78547+
78548+struct inodev_entry {
78549+ struct name_entry *nentry;
78550+ struct inodev_entry *prev;
78551+ struct inodev_entry *next;
78552+};
78553+
78554+struct acl_role_db {
78555+ struct acl_role_label **r_hash;
78556+ __u32 r_size;
78557+};
78558+
78559+struct inodev_db {
78560+ struct inodev_entry **i_hash;
78561+ __u32 i_size;
78562+};
78563+
78564+struct name_db {
78565+ struct name_entry **n_hash;
78566+ __u32 n_size;
78567+};
78568+
78569+struct crash_uid {
78570+ uid_t uid;
78571+ unsigned long expires;
78572+};
78573+
78574+struct gr_hash_struct {
78575+ void **table;
78576+ void **nametable;
78577+ void *first;
78578+ __u32 table_size;
78579+ __u32 used_size;
78580+ int type;
78581+};
78582+
78583+/* Userspace Grsecurity ACL data structures */
78584+
78585+struct acl_subject_label {
78586+ char *filename;
78587+ ino_t inode;
78588+ dev_t device;
78589+ __u32 mode;
78590+ kernel_cap_t cap_mask;
78591+ kernel_cap_t cap_lower;
78592+ kernel_cap_t cap_invert_audit;
78593+
78594+ struct rlimit res[GR_NLIMITS];
78595+ __u32 resmask;
78596+
78597+ __u8 user_trans_type;
78598+ __u8 group_trans_type;
78599+ uid_t *user_transitions;
78600+ gid_t *group_transitions;
78601+ __u16 user_trans_num;
78602+ __u16 group_trans_num;
78603+
78604+ __u32 sock_families[2];
78605+ __u32 ip_proto[8];
78606+ __u32 ip_type;
78607+ struct acl_ip_label **ips;
78608+ __u32 ip_num;
78609+ __u32 inaddr_any_override;
78610+
78611+ __u32 crashes;
78612+ unsigned long expires;
78613+
78614+ struct acl_subject_label *parent_subject;
78615+ struct gr_hash_struct *hash;
78616+ struct acl_subject_label *prev;
78617+ struct acl_subject_label *next;
78618+
78619+ struct acl_object_label **obj_hash;
78620+ __u32 obj_hash_size;
78621+ __u16 pax_flags;
78622+};
78623+
78624+struct role_allowed_ip {
78625+ __u32 addr;
78626+ __u32 netmask;
78627+
78628+ struct role_allowed_ip *prev;
78629+ struct role_allowed_ip *next;
78630+};
78631+
78632+struct role_transition {
78633+ char *rolename;
78634+
78635+ struct role_transition *prev;
78636+ struct role_transition *next;
78637+};
78638+
78639+struct acl_role_label {
78640+ char *rolename;
78641+ uid_t uidgid;
78642+ __u16 roletype;
78643+
78644+ __u16 auth_attempts;
78645+ unsigned long expires;
78646+
78647+ struct acl_subject_label *root_label;
78648+ struct gr_hash_struct *hash;
78649+
78650+ struct acl_role_label *prev;
78651+ struct acl_role_label *next;
78652+
78653+ struct role_transition *transitions;
78654+ struct role_allowed_ip *allowed_ips;
78655+ uid_t *domain_children;
78656+ __u16 domain_child_num;
78657+
78658+ umode_t umask;
78659+
78660+ struct acl_subject_label **subj_hash;
78661+ __u32 subj_hash_size;
78662+};
78663+
78664+struct user_acl_role_db {
78665+ struct acl_role_label **r_table;
78666+ __u32 num_pointers; /* Number of allocations to track */
78667+ __u32 num_roles; /* Number of roles */
78668+ __u32 num_domain_children; /* Number of domain children */
78669+ __u32 num_subjects; /* Number of subjects */
78670+ __u32 num_objects; /* Number of objects */
78671+};
78672+
78673+struct acl_object_label {
78674+ char *filename;
78675+ ino_t inode;
78676+ dev_t device;
78677+ __u32 mode;
78678+
78679+ struct acl_subject_label *nested;
78680+ struct acl_object_label *globbed;
78681+
78682+ /* next two structures not used */
78683+
78684+ struct acl_object_label *prev;
78685+ struct acl_object_label *next;
78686+};
78687+
78688+struct acl_ip_label {
78689+ char *iface;
78690+ __u32 addr;
78691+ __u32 netmask;
78692+ __u16 low, high;
78693+ __u8 mode;
78694+ __u32 type;
78695+ __u32 proto[8];
78696+
78697+ /* next two structures not used */
78698+
78699+ struct acl_ip_label *prev;
78700+ struct acl_ip_label *next;
78701+};
78702+
78703+struct gr_arg {
78704+ struct user_acl_role_db role_db;
78705+ unsigned char pw[GR_PW_LEN];
78706+ unsigned char salt[GR_SALT_LEN];
78707+ unsigned char sum[GR_SHA_LEN];
78708+ unsigned char sp_role[GR_SPROLE_LEN];
78709+ struct sprole_pw *sprole_pws;
78710+ dev_t segv_device;
78711+ ino_t segv_inode;
78712+ uid_t segv_uid;
78713+ __u16 num_sprole_pws;
78714+ __u16 mode;
78715+};
78716+
78717+struct gr_arg_wrapper {
78718+ struct gr_arg *arg;
78719+ __u32 version;
78720+ __u32 size;
78721+};
78722+
78723+struct subject_map {
78724+ struct acl_subject_label *user;
78725+ struct acl_subject_label *kernel;
78726+ struct subject_map *prev;
78727+ struct subject_map *next;
78728+};
78729+
78730+struct acl_subj_map_db {
78731+ struct subject_map **s_hash;
78732+ __u32 s_size;
78733+};
78734+
78735+struct gr_policy_state {
78736+ struct sprole_pw **acl_special_roles;
78737+ __u16 num_sprole_pws;
78738+ struct acl_role_label *kernel_role;
78739+ struct acl_role_label *role_list;
78740+ struct acl_role_label *default_role;
78741+ struct acl_role_db acl_role_set;
78742+ struct acl_subj_map_db subj_map_set;
78743+ struct name_db name_set;
78744+ struct inodev_db inodev_set;
78745+};
78746+
78747+struct gr_alloc_state {
78748+ unsigned long alloc_stack_next;
78749+ unsigned long alloc_stack_size;
78750+ void **alloc_stack;
78751+};
78752+
78753+struct gr_reload_state {
78754+ struct gr_policy_state oldpolicy;
78755+ struct gr_alloc_state oldalloc;
78756+ struct gr_policy_state newpolicy;
78757+ struct gr_alloc_state newalloc;
78758+ struct gr_policy_state *oldpolicy_ptr;
78759+ struct gr_alloc_state *oldalloc_ptr;
78760+ unsigned char oldmode;
78761+};
78762+
78763+/* End Data Structures Section */
78764+
78765+/* Hash functions generated by empirical testing by Brad Spengler
78766+ Makes good use of the low bits of the inode. Generally 0-1 times
78767+ in loop for successful match. 0-3 for unsuccessful match.
78768+ Shift/add algorithm with modulus of table size and an XOR*/
78769+
78770+static __inline__ unsigned int
78771+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78772+{
78773+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
78774+}
78775+
78776+ static __inline__ unsigned int
78777+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78778+{
78779+ return ((const unsigned long)userp % sz);
78780+}
78781+
78782+static __inline__ unsigned int
78783+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78784+{
78785+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78786+}
78787+
78788+static __inline__ unsigned int
78789+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78790+{
78791+ return full_name_hash((const unsigned char *)name, len) % sz;
78792+}
78793+
78794+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78795+ subj = NULL; \
78796+ iter = 0; \
78797+ while (iter < role->subj_hash_size) { \
78798+ if (subj == NULL) \
78799+ subj = role->subj_hash[iter]; \
78800+ if (subj == NULL) { \
78801+ iter++; \
78802+ continue; \
78803+ }
78804+
78805+#define FOR_EACH_SUBJECT_END(subj,iter) \
78806+ subj = subj->next; \
78807+ if (subj == NULL) \
78808+ iter++; \
78809+ }
78810+
78811+
78812+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78813+ subj = role->hash->first; \
78814+ while (subj != NULL) {
78815+
78816+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78817+ subj = subj->next; \
78818+ }
78819+
78820+#endif
78821+
78822diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78823new file mode 100644
78824index 0000000..33ebd1f
78825--- /dev/null
78826+++ b/include/linux/gracl_compat.h
78827@@ -0,0 +1,156 @@
78828+#ifndef GR_ACL_COMPAT_H
78829+#define GR_ACL_COMPAT_H
78830+
78831+#include <linux/resource.h>
78832+#include <asm/resource.h>
78833+
78834+struct sprole_pw_compat {
78835+ compat_uptr_t rolename;
78836+ unsigned char salt[GR_SALT_LEN];
78837+ unsigned char sum[GR_SHA_LEN];
78838+};
78839+
78840+struct gr_hash_struct_compat {
78841+ compat_uptr_t table;
78842+ compat_uptr_t nametable;
78843+ compat_uptr_t first;
78844+ __u32 table_size;
78845+ __u32 used_size;
78846+ int type;
78847+};
78848+
78849+struct acl_subject_label_compat {
78850+ compat_uptr_t filename;
78851+ compat_ino_t inode;
78852+ __u32 device;
78853+ __u32 mode;
78854+ kernel_cap_t cap_mask;
78855+ kernel_cap_t cap_lower;
78856+ kernel_cap_t cap_invert_audit;
78857+
78858+ struct compat_rlimit res[GR_NLIMITS];
78859+ __u32 resmask;
78860+
78861+ __u8 user_trans_type;
78862+ __u8 group_trans_type;
78863+ compat_uptr_t user_transitions;
78864+ compat_uptr_t group_transitions;
78865+ __u16 user_trans_num;
78866+ __u16 group_trans_num;
78867+
78868+ __u32 sock_families[2];
78869+ __u32 ip_proto[8];
78870+ __u32 ip_type;
78871+ compat_uptr_t ips;
78872+ __u32 ip_num;
78873+ __u32 inaddr_any_override;
78874+
78875+ __u32 crashes;
78876+ compat_ulong_t expires;
78877+
78878+ compat_uptr_t parent_subject;
78879+ compat_uptr_t hash;
78880+ compat_uptr_t prev;
78881+ compat_uptr_t next;
78882+
78883+ compat_uptr_t obj_hash;
78884+ __u32 obj_hash_size;
78885+ __u16 pax_flags;
78886+};
78887+
78888+struct role_allowed_ip_compat {
78889+ __u32 addr;
78890+ __u32 netmask;
78891+
78892+ compat_uptr_t prev;
78893+ compat_uptr_t next;
78894+};
78895+
78896+struct role_transition_compat {
78897+ compat_uptr_t rolename;
78898+
78899+ compat_uptr_t prev;
78900+ compat_uptr_t next;
78901+};
78902+
78903+struct acl_role_label_compat {
78904+ compat_uptr_t rolename;
78905+ uid_t uidgid;
78906+ __u16 roletype;
78907+
78908+ __u16 auth_attempts;
78909+ compat_ulong_t expires;
78910+
78911+ compat_uptr_t root_label;
78912+ compat_uptr_t hash;
78913+
78914+ compat_uptr_t prev;
78915+ compat_uptr_t next;
78916+
78917+ compat_uptr_t transitions;
78918+ compat_uptr_t allowed_ips;
78919+ compat_uptr_t domain_children;
78920+ __u16 domain_child_num;
78921+
78922+ umode_t umask;
78923+
78924+ compat_uptr_t subj_hash;
78925+ __u32 subj_hash_size;
78926+};
78927+
78928+struct user_acl_role_db_compat {
78929+ compat_uptr_t r_table;
78930+ __u32 num_pointers;
78931+ __u32 num_roles;
78932+ __u32 num_domain_children;
78933+ __u32 num_subjects;
78934+ __u32 num_objects;
78935+};
78936+
78937+struct acl_object_label_compat {
78938+ compat_uptr_t filename;
78939+ compat_ino_t inode;
78940+ __u32 device;
78941+ __u32 mode;
78942+
78943+ compat_uptr_t nested;
78944+ compat_uptr_t globbed;
78945+
78946+ compat_uptr_t prev;
78947+ compat_uptr_t next;
78948+};
78949+
78950+struct acl_ip_label_compat {
78951+ compat_uptr_t iface;
78952+ __u32 addr;
78953+ __u32 netmask;
78954+ __u16 low, high;
78955+ __u8 mode;
78956+ __u32 type;
78957+ __u32 proto[8];
78958+
78959+ compat_uptr_t prev;
78960+ compat_uptr_t next;
78961+};
78962+
78963+struct gr_arg_compat {
78964+ struct user_acl_role_db_compat role_db;
78965+ unsigned char pw[GR_PW_LEN];
78966+ unsigned char salt[GR_SALT_LEN];
78967+ unsigned char sum[GR_SHA_LEN];
78968+ unsigned char sp_role[GR_SPROLE_LEN];
78969+ compat_uptr_t sprole_pws;
78970+ __u32 segv_device;
78971+ compat_ino_t segv_inode;
78972+ uid_t segv_uid;
78973+ __u16 num_sprole_pws;
78974+ __u16 mode;
78975+};
78976+
78977+struct gr_arg_wrapper_compat {
78978+ compat_uptr_t arg;
78979+ __u32 version;
78980+ __u32 size;
78981+};
78982+
78983+#endif
78984diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
78985new file mode 100644
78986index 0000000..323ecf2
78987--- /dev/null
78988+++ b/include/linux/gralloc.h
78989@@ -0,0 +1,9 @@
78990+#ifndef __GRALLOC_H
78991+#define __GRALLOC_H
78992+
78993+void acl_free_all(void);
78994+int acl_alloc_stack_init(unsigned long size);
78995+void *acl_alloc(unsigned long len);
78996+void *acl_alloc_num(unsigned long num, unsigned long len);
78997+
78998+#endif
78999diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
79000new file mode 100644
79001index 0000000..be66033
79002--- /dev/null
79003+++ b/include/linux/grdefs.h
79004@@ -0,0 +1,140 @@
79005+#ifndef GRDEFS_H
79006+#define GRDEFS_H
79007+
79008+/* Begin grsecurity status declarations */
79009+
79010+enum {
79011+ GR_READY = 0x01,
79012+ GR_STATUS_INIT = 0x00 // disabled state
79013+};
79014+
79015+/* Begin ACL declarations */
79016+
79017+/* Role flags */
79018+
79019+enum {
79020+ GR_ROLE_USER = 0x0001,
79021+ GR_ROLE_GROUP = 0x0002,
79022+ GR_ROLE_DEFAULT = 0x0004,
79023+ GR_ROLE_SPECIAL = 0x0008,
79024+ GR_ROLE_AUTH = 0x0010,
79025+ GR_ROLE_NOPW = 0x0020,
79026+ GR_ROLE_GOD = 0x0040,
79027+ GR_ROLE_LEARN = 0x0080,
79028+ GR_ROLE_TPE = 0x0100,
79029+ GR_ROLE_DOMAIN = 0x0200,
79030+ GR_ROLE_PAM = 0x0400,
79031+ GR_ROLE_PERSIST = 0x0800
79032+};
79033+
79034+/* ACL Subject and Object mode flags */
79035+enum {
79036+ GR_DELETED = 0x80000000
79037+};
79038+
79039+/* ACL Object-only mode flags */
79040+enum {
79041+ GR_READ = 0x00000001,
79042+ GR_APPEND = 0x00000002,
79043+ GR_WRITE = 0x00000004,
79044+ GR_EXEC = 0x00000008,
79045+ GR_FIND = 0x00000010,
79046+ GR_INHERIT = 0x00000020,
79047+ GR_SETID = 0x00000040,
79048+ GR_CREATE = 0x00000080,
79049+ GR_DELETE = 0x00000100,
79050+ GR_LINK = 0x00000200,
79051+ GR_AUDIT_READ = 0x00000400,
79052+ GR_AUDIT_APPEND = 0x00000800,
79053+ GR_AUDIT_WRITE = 0x00001000,
79054+ GR_AUDIT_EXEC = 0x00002000,
79055+ GR_AUDIT_FIND = 0x00004000,
79056+ GR_AUDIT_INHERIT= 0x00008000,
79057+ GR_AUDIT_SETID = 0x00010000,
79058+ GR_AUDIT_CREATE = 0x00020000,
79059+ GR_AUDIT_DELETE = 0x00040000,
79060+ GR_AUDIT_LINK = 0x00080000,
79061+ GR_PTRACERD = 0x00100000,
79062+ GR_NOPTRACE = 0x00200000,
79063+ GR_SUPPRESS = 0x00400000,
79064+ GR_NOLEARN = 0x00800000,
79065+ GR_INIT_TRANSFER= 0x01000000
79066+};
79067+
79068+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79069+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79070+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79071+
79072+/* ACL subject-only mode flags */
79073+enum {
79074+ GR_KILL = 0x00000001,
79075+ GR_VIEW = 0x00000002,
79076+ GR_PROTECTED = 0x00000004,
79077+ GR_LEARN = 0x00000008,
79078+ GR_OVERRIDE = 0x00000010,
79079+ /* just a placeholder, this mode is only used in userspace */
79080+ GR_DUMMY = 0x00000020,
79081+ GR_PROTSHM = 0x00000040,
79082+ GR_KILLPROC = 0x00000080,
79083+ GR_KILLIPPROC = 0x00000100,
79084+ /* just a placeholder, this mode is only used in userspace */
79085+ GR_NOTROJAN = 0x00000200,
79086+ GR_PROTPROCFD = 0x00000400,
79087+ GR_PROCACCT = 0x00000800,
79088+ GR_RELAXPTRACE = 0x00001000,
79089+ //GR_NESTED = 0x00002000,
79090+ GR_INHERITLEARN = 0x00004000,
79091+ GR_PROCFIND = 0x00008000,
79092+ GR_POVERRIDE = 0x00010000,
79093+ GR_KERNELAUTH = 0x00020000,
79094+ GR_ATSECURE = 0x00040000,
79095+ GR_SHMEXEC = 0x00080000
79096+};
79097+
79098+enum {
79099+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79100+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79101+ GR_PAX_ENABLE_MPROTECT = 0x0004,
79102+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
79103+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79104+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79105+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79106+ GR_PAX_DISABLE_MPROTECT = 0x0400,
79107+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
79108+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79109+};
79110+
79111+enum {
79112+ GR_ID_USER = 0x01,
79113+ GR_ID_GROUP = 0x02,
79114+};
79115+
79116+enum {
79117+ GR_ID_ALLOW = 0x01,
79118+ GR_ID_DENY = 0x02,
79119+};
79120+
79121+#define GR_CRASH_RES 31
79122+#define GR_UIDTABLE_MAX 500
79123+
79124+/* begin resource learning section */
79125+enum {
79126+ GR_RLIM_CPU_BUMP = 60,
79127+ GR_RLIM_FSIZE_BUMP = 50000,
79128+ GR_RLIM_DATA_BUMP = 10000,
79129+ GR_RLIM_STACK_BUMP = 1000,
79130+ GR_RLIM_CORE_BUMP = 10000,
79131+ GR_RLIM_RSS_BUMP = 500000,
79132+ GR_RLIM_NPROC_BUMP = 1,
79133+ GR_RLIM_NOFILE_BUMP = 5,
79134+ GR_RLIM_MEMLOCK_BUMP = 50000,
79135+ GR_RLIM_AS_BUMP = 500000,
79136+ GR_RLIM_LOCKS_BUMP = 2,
79137+ GR_RLIM_SIGPENDING_BUMP = 5,
79138+ GR_RLIM_MSGQUEUE_BUMP = 10000,
79139+ GR_RLIM_NICE_BUMP = 1,
79140+ GR_RLIM_RTPRIO_BUMP = 1,
79141+ GR_RLIM_RTTIME_BUMP = 1000000
79142+};
79143+
79144+#endif
79145diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79146new file mode 100644
79147index 0000000..d25522e
79148--- /dev/null
79149+++ b/include/linux/grinternal.h
79150@@ -0,0 +1,229 @@
79151+#ifndef __GRINTERNAL_H
79152+#define __GRINTERNAL_H
79153+
79154+#ifdef CONFIG_GRKERNSEC
79155+
79156+#include <linux/fs.h>
79157+#include <linux/mnt_namespace.h>
79158+#include <linux/nsproxy.h>
79159+#include <linux/gracl.h>
79160+#include <linux/grdefs.h>
79161+#include <linux/grmsg.h>
79162+
79163+void gr_add_learn_entry(const char *fmt, ...)
79164+ __attribute__ ((format (printf, 1, 2)));
79165+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79166+ const struct vfsmount *mnt);
79167+__u32 gr_check_create(const struct dentry *new_dentry,
79168+ const struct dentry *parent,
79169+ const struct vfsmount *mnt, const __u32 mode);
79170+int gr_check_protected_task(const struct task_struct *task);
79171+__u32 to_gr_audit(const __u32 reqmode);
79172+int gr_set_acls(const int type);
79173+int gr_acl_is_enabled(void);
79174+char gr_roletype_to_char(void);
79175+
79176+void gr_handle_alertkill(struct task_struct *task);
79177+char *gr_to_filename(const struct dentry *dentry,
79178+ const struct vfsmount *mnt);
79179+char *gr_to_filename1(const struct dentry *dentry,
79180+ const struct vfsmount *mnt);
79181+char *gr_to_filename2(const struct dentry *dentry,
79182+ const struct vfsmount *mnt);
79183+char *gr_to_filename3(const struct dentry *dentry,
79184+ const struct vfsmount *mnt);
79185+
79186+extern int grsec_enable_ptrace_readexec;
79187+extern int grsec_enable_harden_ptrace;
79188+extern int grsec_enable_link;
79189+extern int grsec_enable_fifo;
79190+extern int grsec_enable_execve;
79191+extern int grsec_enable_shm;
79192+extern int grsec_enable_execlog;
79193+extern int grsec_enable_signal;
79194+extern int grsec_enable_audit_ptrace;
79195+extern int grsec_enable_forkfail;
79196+extern int grsec_enable_time;
79197+extern int grsec_enable_rofs;
79198+extern int grsec_deny_new_usb;
79199+extern int grsec_enable_chroot_shmat;
79200+extern int grsec_enable_chroot_mount;
79201+extern int grsec_enable_chroot_double;
79202+extern int grsec_enable_chroot_pivot;
79203+extern int grsec_enable_chroot_chdir;
79204+extern int grsec_enable_chroot_chmod;
79205+extern int grsec_enable_chroot_mknod;
79206+extern int grsec_enable_chroot_fchdir;
79207+extern int grsec_enable_chroot_nice;
79208+extern int grsec_enable_chroot_execlog;
79209+extern int grsec_enable_chroot_caps;
79210+extern int grsec_enable_chroot_sysctl;
79211+extern int grsec_enable_chroot_unix;
79212+extern int grsec_enable_symlinkown;
79213+extern kgid_t grsec_symlinkown_gid;
79214+extern int grsec_enable_tpe;
79215+extern kgid_t grsec_tpe_gid;
79216+extern int grsec_enable_tpe_all;
79217+extern int grsec_enable_tpe_invert;
79218+extern int grsec_enable_socket_all;
79219+extern kgid_t grsec_socket_all_gid;
79220+extern int grsec_enable_socket_client;
79221+extern kgid_t grsec_socket_client_gid;
79222+extern int grsec_enable_socket_server;
79223+extern kgid_t grsec_socket_server_gid;
79224+extern kgid_t grsec_audit_gid;
79225+extern int grsec_enable_group;
79226+extern int grsec_enable_log_rwxmaps;
79227+extern int grsec_enable_mount;
79228+extern int grsec_enable_chdir;
79229+extern int grsec_resource_logging;
79230+extern int grsec_enable_blackhole;
79231+extern int grsec_lastack_retries;
79232+extern int grsec_enable_brute;
79233+extern int grsec_enable_harden_ipc;
79234+extern int grsec_lock;
79235+
79236+extern spinlock_t grsec_alert_lock;
79237+extern unsigned long grsec_alert_wtime;
79238+extern unsigned long grsec_alert_fyet;
79239+
79240+extern spinlock_t grsec_audit_lock;
79241+
79242+extern rwlock_t grsec_exec_file_lock;
79243+
79244+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79245+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79246+ (tsk)->exec_file->f_path.mnt) : "/")
79247+
79248+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79249+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79250+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79251+
79252+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79253+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
79254+ (tsk)->exec_file->f_path.mnt) : "/")
79255+
79256+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79257+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79258+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79259+
79260+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79261+
79262+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79263+
79264+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79265+{
79266+ if (file1 && file2) {
79267+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
79268+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
79269+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79270+ return true;
79271+ }
79272+
79273+ return false;
79274+}
79275+
79276+#define GR_CHROOT_CAPS {{ \
79277+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79278+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79279+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79280+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79281+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79282+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79283+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79284+
79285+#define security_learn(normal_msg,args...) \
79286+({ \
79287+ read_lock(&grsec_exec_file_lock); \
79288+ gr_add_learn_entry(normal_msg "\n", ## args); \
79289+ read_unlock(&grsec_exec_file_lock); \
79290+})
79291+
79292+enum {
79293+ GR_DO_AUDIT,
79294+ GR_DONT_AUDIT,
79295+ /* used for non-audit messages that we shouldn't kill the task on */
79296+ GR_DONT_AUDIT_GOOD
79297+};
79298+
79299+enum {
79300+ GR_TTYSNIFF,
79301+ GR_RBAC,
79302+ GR_RBAC_STR,
79303+ GR_STR_RBAC,
79304+ GR_RBAC_MODE2,
79305+ GR_RBAC_MODE3,
79306+ GR_FILENAME,
79307+ GR_SYSCTL_HIDDEN,
79308+ GR_NOARGS,
79309+ GR_ONE_INT,
79310+ GR_ONE_INT_TWO_STR,
79311+ GR_ONE_STR,
79312+ GR_STR_INT,
79313+ GR_TWO_STR_INT,
79314+ GR_TWO_INT,
79315+ GR_TWO_U64,
79316+ GR_THREE_INT,
79317+ GR_FIVE_INT_TWO_STR,
79318+ GR_TWO_STR,
79319+ GR_THREE_STR,
79320+ GR_FOUR_STR,
79321+ GR_STR_FILENAME,
79322+ GR_FILENAME_STR,
79323+ GR_FILENAME_TWO_INT,
79324+ GR_FILENAME_TWO_INT_STR,
79325+ GR_TEXTREL,
79326+ GR_PTRACE,
79327+ GR_RESOURCE,
79328+ GR_CAP,
79329+ GR_SIG,
79330+ GR_SIG2,
79331+ GR_CRASH1,
79332+ GR_CRASH2,
79333+ GR_PSACCT,
79334+ GR_RWXMAP,
79335+ GR_RWXMAPVMA
79336+};
79337+
79338+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79339+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79340+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79341+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79342+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79343+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79344+#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)
79345+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79346+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79347+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79348+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79349+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79350+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79351+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79352+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79353+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79354+#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)
79355+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79356+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79357+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79358+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79359+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79360+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79361+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79362+#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)
79363+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79364+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79365+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79366+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79367+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79368+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79369+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79370+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79371+#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)
79372+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79373+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79374+
79375+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79376+
79377+#endif
79378+
79379+#endif
79380diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79381new file mode 100644
79382index 0000000..b02ba9d
79383--- /dev/null
79384+++ b/include/linux/grmsg.h
79385@@ -0,0 +1,117 @@
79386+#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"
79387+#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"
79388+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79389+#define GR_STOPMOD_MSG "denied modification of module state by "
79390+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79391+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79392+#define GR_IOPERM_MSG "denied use of ioperm() by "
79393+#define GR_IOPL_MSG "denied use of iopl() by "
79394+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79395+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79396+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79397+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79398+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79399+#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"
79400+#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"
79401+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79402+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79403+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79404+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79405+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79406+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79407+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79408+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79409+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79410+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79411+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79412+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79413+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79414+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79415+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79416+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79417+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79418+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79419+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79420+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79421+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79422+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79423+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79424+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79425+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79426+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79427+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79428+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79429+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79430+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79431+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79432+#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
79433+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79434+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79435+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79436+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79437+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79438+#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"
79439+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79440+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79441+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79442+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79443+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79444+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79445+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79446+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79447+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79448+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79449+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79450+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79451+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79452+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79453+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79454+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79455+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79456+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79457+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79458+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79459+#define GR_FAILFORK_MSG "failed fork with errno %s by "
79460+#define GR_NICE_CHROOT_MSG "denied priority change by "
79461+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79462+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79463+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79464+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79465+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79466+#define GR_TIME_MSG "time set by "
79467+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79468+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79469+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79470+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79471+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79472+#define GR_BIND_MSG "denied bind() by "
79473+#define GR_CONNECT_MSG "denied connect() by "
79474+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79475+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79476+#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"
79477+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79478+#define GR_CAP_ACL_MSG "use of %s denied for "
79479+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79480+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79481+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79482+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79483+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79484+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79485+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79486+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79487+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79488+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79489+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79490+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79491+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79492+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79493+#define GR_VM86_MSG "denied use of vm86 by "
79494+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79495+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79496+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79497+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79498+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79499+#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 "
79500+#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 "
79501+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79502+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79503diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79504new file mode 100644
79505index 0000000..13ac2e2
79506--- /dev/null
79507+++ b/include/linux/grsecurity.h
79508@@ -0,0 +1,249 @@
79509+#ifndef GR_SECURITY_H
79510+#define GR_SECURITY_H
79511+#include <linux/fs.h>
79512+#include <linux/fs_struct.h>
79513+#include <linux/binfmts.h>
79514+#include <linux/gracl.h>
79515+
79516+/* notify of brain-dead configs */
79517+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79518+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79519+#endif
79520+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79521+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79522+#endif
79523+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79524+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79525+#endif
79526+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79527+#error "CONFIG_PAX enabled, but no PaX options are enabled."
79528+#endif
79529+
79530+int gr_handle_new_usb(void);
79531+
79532+void gr_handle_brute_attach(int dumpable);
79533+void gr_handle_brute_check(void);
79534+void gr_handle_kernel_exploit(void);
79535+
79536+char gr_roletype_to_char(void);
79537+
79538+int gr_proc_is_restricted(void);
79539+
79540+int gr_acl_enable_at_secure(void);
79541+
79542+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79543+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79544+
79545+void gr_del_task_from_ip_table(struct task_struct *p);
79546+
79547+int gr_pid_is_chrooted(struct task_struct *p);
79548+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79549+int gr_handle_chroot_nice(void);
79550+int gr_handle_chroot_sysctl(const int op);
79551+int gr_handle_chroot_setpriority(struct task_struct *p,
79552+ const int niceval);
79553+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79554+int gr_chroot_fhandle(void);
79555+int gr_handle_chroot_chroot(const struct dentry *dentry,
79556+ const struct vfsmount *mnt);
79557+void gr_handle_chroot_chdir(const struct path *path);
79558+int gr_handle_chroot_chmod(const struct dentry *dentry,
79559+ const struct vfsmount *mnt, const int mode);
79560+int gr_handle_chroot_mknod(const struct dentry *dentry,
79561+ const struct vfsmount *mnt, const int mode);
79562+int gr_handle_chroot_mount(const struct dentry *dentry,
79563+ const struct vfsmount *mnt,
79564+ const char *dev_name);
79565+int gr_handle_chroot_pivot(void);
79566+int gr_handle_chroot_unix(const pid_t pid);
79567+
79568+int gr_handle_rawio(const struct inode *inode);
79569+
79570+void gr_handle_ioperm(void);
79571+void gr_handle_iopl(void);
79572+void gr_handle_msr_write(void);
79573+
79574+umode_t gr_acl_umask(void);
79575+
79576+int gr_tpe_allow(const struct file *file);
79577+
79578+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79579+void gr_clear_chroot_entries(struct task_struct *task);
79580+
79581+void gr_log_forkfail(const int retval);
79582+void gr_log_timechange(void);
79583+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79584+void gr_log_chdir(const struct dentry *dentry,
79585+ const struct vfsmount *mnt);
79586+void gr_log_chroot_exec(const struct dentry *dentry,
79587+ const struct vfsmount *mnt);
79588+void gr_log_remount(const char *devname, const int retval);
79589+void gr_log_unmount(const char *devname, const int retval);
79590+void gr_log_mount(const char *from, const char *to, const int retval);
79591+void gr_log_textrel(struct vm_area_struct *vma);
79592+void gr_log_ptgnustack(struct file *file);
79593+void gr_log_rwxmmap(struct file *file);
79594+void gr_log_rwxmprotect(struct vm_area_struct *vma);
79595+
79596+int gr_handle_follow_link(const struct inode *parent,
79597+ const struct inode *inode,
79598+ const struct dentry *dentry,
79599+ const struct vfsmount *mnt);
79600+int gr_handle_fifo(const struct dentry *dentry,
79601+ const struct vfsmount *mnt,
79602+ const struct dentry *dir, const int flag,
79603+ const int acc_mode);
79604+int gr_handle_hardlink(const struct dentry *dentry,
79605+ const struct vfsmount *mnt,
79606+ struct inode *inode,
79607+ const int mode, const struct filename *to);
79608+
79609+int gr_is_capable(const int cap);
79610+int gr_is_capable_nolog(const int cap);
79611+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79612+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79613+
79614+void gr_copy_label(struct task_struct *tsk);
79615+void gr_handle_crash(struct task_struct *task, const int sig);
79616+int gr_handle_signal(const struct task_struct *p, const int sig);
79617+int gr_check_crash_uid(const kuid_t uid);
79618+int gr_check_protected_task(const struct task_struct *task);
79619+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79620+int gr_acl_handle_mmap(const struct file *file,
79621+ const unsigned long prot);
79622+int gr_acl_handle_mprotect(const struct file *file,
79623+ const unsigned long prot);
79624+int gr_check_hidden_task(const struct task_struct *tsk);
79625+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79626+ const struct vfsmount *mnt);
79627+__u32 gr_acl_handle_utime(const struct dentry *dentry,
79628+ const struct vfsmount *mnt);
79629+__u32 gr_acl_handle_access(const struct dentry *dentry,
79630+ const struct vfsmount *mnt, const int fmode);
79631+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79632+ const struct vfsmount *mnt, umode_t *mode);
79633+__u32 gr_acl_handle_chown(const struct dentry *dentry,
79634+ const struct vfsmount *mnt);
79635+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79636+ const struct vfsmount *mnt);
79637+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79638+ const struct vfsmount *mnt);
79639+int gr_handle_ptrace(struct task_struct *task, const long request);
79640+int gr_handle_proc_ptrace(struct task_struct *task);
79641+__u32 gr_acl_handle_execve(const struct dentry *dentry,
79642+ const struct vfsmount *mnt);
79643+int gr_check_crash_exec(const struct file *filp);
79644+int gr_acl_is_enabled(void);
79645+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79646+ const kgid_t gid);
79647+int gr_set_proc_label(const struct dentry *dentry,
79648+ const struct vfsmount *mnt,
79649+ const int unsafe_flags);
79650+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79651+ const struct vfsmount *mnt);
79652+__u32 gr_acl_handle_open(const struct dentry *dentry,
79653+ const struct vfsmount *mnt, int acc_mode);
79654+__u32 gr_acl_handle_creat(const struct dentry *dentry,
79655+ const struct dentry *p_dentry,
79656+ const struct vfsmount *p_mnt,
79657+ int open_flags, int acc_mode, const int imode);
79658+void gr_handle_create(const struct dentry *dentry,
79659+ const struct vfsmount *mnt);
79660+void gr_handle_proc_create(const struct dentry *dentry,
79661+ const struct inode *inode);
79662+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79663+ const struct dentry *parent_dentry,
79664+ const struct vfsmount *parent_mnt,
79665+ const int mode);
79666+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79667+ const struct dentry *parent_dentry,
79668+ const struct vfsmount *parent_mnt);
79669+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79670+ const struct vfsmount *mnt);
79671+void gr_handle_delete(const ino_t ino, const dev_t dev);
79672+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79673+ const struct vfsmount *mnt);
79674+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79675+ const struct dentry *parent_dentry,
79676+ const struct vfsmount *parent_mnt,
79677+ const struct filename *from);
79678+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79679+ const struct dentry *parent_dentry,
79680+ const struct vfsmount *parent_mnt,
79681+ const struct dentry *old_dentry,
79682+ const struct vfsmount *old_mnt, const struct filename *to);
79683+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79684+int gr_acl_handle_rename(struct dentry *new_dentry,
79685+ struct dentry *parent_dentry,
79686+ const struct vfsmount *parent_mnt,
79687+ struct dentry *old_dentry,
79688+ struct inode *old_parent_inode,
79689+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
79690+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79691+ struct dentry *old_dentry,
79692+ struct dentry *new_dentry,
79693+ struct vfsmount *mnt, const __u8 replace, unsigned int flags);
79694+__u32 gr_check_link(const struct dentry *new_dentry,
79695+ const struct dentry *parent_dentry,
79696+ const struct vfsmount *parent_mnt,
79697+ const struct dentry *old_dentry,
79698+ const struct vfsmount *old_mnt);
79699+int gr_acl_handle_filldir(const struct file *file, const char *name,
79700+ const unsigned int namelen, const ino_t ino);
79701+
79702+__u32 gr_acl_handle_unix(const struct dentry *dentry,
79703+ const struct vfsmount *mnt);
79704+void gr_acl_handle_exit(void);
79705+void gr_acl_handle_psacct(struct task_struct *task, const long code);
79706+int gr_acl_handle_procpidmem(const struct task_struct *task);
79707+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79708+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79709+void gr_audit_ptrace(struct task_struct *task);
79710+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79711+void gr_put_exec_file(struct task_struct *task);
79712+
79713+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79714+
79715+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79716+extern void gr_learn_resource(const struct task_struct *task, const int res,
79717+ const unsigned long wanted, const int gt);
79718+#else
79719+static inline void gr_learn_resource(const struct task_struct *task, const int res,
79720+ const unsigned long wanted, const int gt)
79721+{
79722+}
79723+#endif
79724+
79725+#ifdef CONFIG_GRKERNSEC_RESLOG
79726+extern void gr_log_resource(const struct task_struct *task, const int res,
79727+ const unsigned long wanted, const int gt);
79728+#else
79729+static inline void gr_log_resource(const struct task_struct *task, const int res,
79730+ const unsigned long wanted, const int gt)
79731+{
79732+}
79733+#endif
79734+
79735+#ifdef CONFIG_GRKERNSEC
79736+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79737+void gr_handle_vm86(void);
79738+void gr_handle_mem_readwrite(u64 from, u64 to);
79739+
79740+void gr_log_badprocpid(const char *entry);
79741+
79742+extern int grsec_enable_dmesg;
79743+extern int grsec_disable_privio;
79744+
79745+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79746+extern kgid_t grsec_proc_gid;
79747+#endif
79748+
79749+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79750+extern int grsec_enable_chroot_findtask;
79751+#endif
79752+#ifdef CONFIG_GRKERNSEC_SETXID
79753+extern int grsec_enable_setxid;
79754+#endif
79755+#endif
79756+
79757+#endif
79758diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79759new file mode 100644
79760index 0000000..e7ffaaf
79761--- /dev/null
79762+++ b/include/linux/grsock.h
79763@@ -0,0 +1,19 @@
79764+#ifndef __GRSOCK_H
79765+#define __GRSOCK_H
79766+
79767+extern void gr_attach_curr_ip(const struct sock *sk);
79768+extern int gr_handle_sock_all(const int family, const int type,
79769+ const int protocol);
79770+extern int gr_handle_sock_server(const struct sockaddr *sck);
79771+extern int gr_handle_sock_server_other(const struct sock *sck);
79772+extern int gr_handle_sock_client(const struct sockaddr *sck);
79773+extern int gr_search_connect(struct socket * sock,
79774+ struct sockaddr_in * addr);
79775+extern int gr_search_bind(struct socket * sock,
79776+ struct sockaddr_in * addr);
79777+extern int gr_search_listen(struct socket * sock);
79778+extern int gr_search_accept(struct socket * sock);
79779+extern int gr_search_socket(const int domain, const int type,
79780+ const int protocol);
79781+
79782+#endif
79783diff --git a/include/linux/hash.h b/include/linux/hash.h
79784index bd1754c..8240892 100644
79785--- a/include/linux/hash.h
79786+++ b/include/linux/hash.h
79787@@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
79788 struct fast_hash_ops {
79789 u32 (*hash)(const void *data, u32 len, u32 seed);
79790 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
79791-};
79792+} __no_const;
79793
79794 /**
79795 * arch_fast_hash - Caclulates a hash over a given buffer that can have
79796diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79797index 7fb31da..08b5114 100644
79798--- a/include/linux/highmem.h
79799+++ b/include/linux/highmem.h
79800@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79801 kunmap_atomic(kaddr);
79802 }
79803
79804+static inline void sanitize_highpage(struct page *page)
79805+{
79806+ void *kaddr;
79807+ unsigned long flags;
79808+
79809+ local_irq_save(flags);
79810+ kaddr = kmap_atomic(page);
79811+ clear_page(kaddr);
79812+ kunmap_atomic(kaddr);
79813+ local_irq_restore(flags);
79814+}
79815+
79816 static inline void zero_user_segments(struct page *page,
79817 unsigned start1, unsigned end1,
79818 unsigned start2, unsigned end2)
79819diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79820index 1c7b89a..7dda400 100644
79821--- a/include/linux/hwmon-sysfs.h
79822+++ b/include/linux/hwmon-sysfs.h
79823@@ -25,7 +25,8 @@
79824 struct sensor_device_attribute{
79825 struct device_attribute dev_attr;
79826 int index;
79827-};
79828+} __do_const;
79829+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79830 #define to_sensor_dev_attr(_dev_attr) \
79831 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79832
79833@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79834 struct device_attribute dev_attr;
79835 u8 index;
79836 u8 nr;
79837-};
79838+} __do_const;
79839+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79840 #define to_sensor_dev_attr_2(_dev_attr) \
79841 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79842
79843diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79844index b556e0a..c10a515 100644
79845--- a/include/linux/i2c.h
79846+++ b/include/linux/i2c.h
79847@@ -378,6 +378,7 @@ struct i2c_algorithm {
79848 /* To determine what the adapter supports */
79849 u32 (*functionality) (struct i2c_adapter *);
79850 };
79851+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79852
79853 /**
79854 * struct i2c_bus_recovery_info - I2C bus recovery information
79855diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79856index d23c3c2..eb63c81 100644
79857--- a/include/linux/i2o.h
79858+++ b/include/linux/i2o.h
79859@@ -565,7 +565,7 @@ struct i2o_controller {
79860 struct i2o_device *exec; /* Executive */
79861 #if BITS_PER_LONG == 64
79862 spinlock_t context_list_lock; /* lock for context_list */
79863- atomic_t context_list_counter; /* needed for unique contexts */
79864+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79865 struct list_head context_list; /* list of context id's
79866 and pointers */
79867 #endif
79868diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79869index aff7ad8..3942bbd 100644
79870--- a/include/linux/if_pppox.h
79871+++ b/include/linux/if_pppox.h
79872@@ -76,7 +76,7 @@ struct pppox_proto {
79873 int (*ioctl)(struct socket *sock, unsigned int cmd,
79874 unsigned long arg);
79875 struct module *owner;
79876-};
79877+} __do_const;
79878
79879 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79880 extern void unregister_pppox_proto(int proto_num);
79881diff --git a/include/linux/init.h b/include/linux/init.h
79882index a3ba270..a1b6604 100644
79883--- a/include/linux/init.h
79884+++ b/include/linux/init.h
79885@@ -37,9 +37,17 @@
79886 * section.
79887 */
79888
79889+#define add_init_latent_entropy __latent_entropy
79890+
79891+#ifdef CONFIG_MEMORY_HOTPLUG
79892+#define add_meminit_latent_entropy
79893+#else
79894+#define add_meminit_latent_entropy __latent_entropy
79895+#endif
79896+
79897 /* These are for everybody (although not all archs will actually
79898 discard it in modules) */
79899-#define __init __section(.init.text) __cold notrace
79900+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79901 #define __initdata __section(.init.data)
79902 #define __initconst __constsection(.init.rodata)
79903 #define __exitdata __section(.exit.data)
79904@@ -100,7 +108,7 @@
79905 #define __cpuexitconst
79906
79907 /* Used for MEMORY_HOTPLUG */
79908-#define __meminit __section(.meminit.text) __cold notrace
79909+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79910 #define __meminitdata __section(.meminit.data)
79911 #define __meminitconst __constsection(.meminit.rodata)
79912 #define __memexit __section(.memexit.text) __exitused __cold notrace
79913diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79914index 6df7f9f..d0bf699 100644
79915--- a/include/linux/init_task.h
79916+++ b/include/linux/init_task.h
79917@@ -156,6 +156,12 @@ extern struct task_group root_task_group;
79918
79919 #define INIT_TASK_COMM "swapper"
79920
79921+#ifdef CONFIG_X86
79922+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79923+#else
79924+#define INIT_TASK_THREAD_INFO
79925+#endif
79926+
79927 #ifdef CONFIG_RT_MUTEXES
79928 # define INIT_RT_MUTEXES(tsk) \
79929 .pi_waiters = RB_ROOT, \
79930@@ -203,6 +209,7 @@ extern struct task_group root_task_group;
79931 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79932 .comm = INIT_TASK_COMM, \
79933 .thread = INIT_THREAD, \
79934+ INIT_TASK_THREAD_INFO \
79935 .fs = &init_fs, \
79936 .files = &init_files, \
79937 .signal = &init_signals, \
79938diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79939index 051c850..431f83a 100644
79940--- a/include/linux/interrupt.h
79941+++ b/include/linux/interrupt.h
79942@@ -412,8 +412,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
79943
79944 struct softirq_action
79945 {
79946- void (*action)(struct softirq_action *);
79947-};
79948+ void (*action)(void);
79949+} __no_const;
79950
79951 asmlinkage void do_softirq(void);
79952 asmlinkage void __do_softirq(void);
79953@@ -427,7 +427,7 @@ static inline void do_softirq_own_stack(void)
79954 }
79955 #endif
79956
79957-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
79958+extern void open_softirq(int nr, void (*action)(void));
79959 extern void softirq_init(void);
79960 extern void __raise_softirq_irqoff(unsigned int nr);
79961
79962diff --git a/include/linux/iommu.h b/include/linux/iommu.h
79963index b96a5b2..2732d1c 100644
79964--- a/include/linux/iommu.h
79965+++ b/include/linux/iommu.h
79966@@ -131,7 +131,7 @@ struct iommu_ops {
79967 u32 (*domain_get_windows)(struct iommu_domain *domain);
79968
79969 unsigned long pgsize_bitmap;
79970-};
79971+} __do_const;
79972
79973 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
79974 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
79975diff --git a/include/linux/ioport.h b/include/linux/ioport.h
79976index 5e3a906..3131d0f 100644
79977--- a/include/linux/ioport.h
79978+++ b/include/linux/ioport.h
79979@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
79980 int adjust_resource(struct resource *res, resource_size_t start,
79981 resource_size_t size);
79982 resource_size_t resource_alignment(struct resource *res);
79983-static inline resource_size_t resource_size(const struct resource *res)
79984+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
79985 {
79986 return res->end - res->start + 1;
79987 }
79988diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
79989index 35e7eca..6afb7ad 100644
79990--- a/include/linux/ipc_namespace.h
79991+++ b/include/linux/ipc_namespace.h
79992@@ -69,7 +69,7 @@ struct ipc_namespace {
79993 struct user_namespace *user_ns;
79994
79995 unsigned int proc_inum;
79996-};
79997+} __randomize_layout;
79998
79999 extern struct ipc_namespace init_ipc_ns;
80000 extern atomic_t nr_ipc_ns;
80001diff --git a/include/linux/irq.h b/include/linux/irq.h
80002index 5c57efb..965a62b 100644
80003--- a/include/linux/irq.h
80004+++ b/include/linux/irq.h
80005@@ -344,7 +344,8 @@ struct irq_chip {
80006 void (*irq_release_resources)(struct irq_data *data);
80007
80008 unsigned long flags;
80009-};
80010+} __do_const;
80011+typedef struct irq_chip __no_const irq_chip_no_const;
80012
80013 /*
80014 * irq_chip specific flags
80015diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
80016index 7ed92d0..589abf5 100644
80017--- a/include/linux/irqchip/arm-gic.h
80018+++ b/include/linux/irqchip/arm-gic.h
80019@@ -73,9 +73,11 @@
80020
80021 #ifndef __ASSEMBLY__
80022
80023+#include <linux/irq.h>
80024+
80025 struct device_node;
80026
80027-extern struct irq_chip gic_arch_extn;
80028+extern irq_chip_no_const gic_arch_extn;
80029
80030 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
80031 u32 offset, struct device_node *);
80032diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
80033index 1f44466..b481806 100644
80034--- a/include/linux/jiffies.h
80035+++ b/include/linux/jiffies.h
80036@@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
80037 /*
80038 * Convert various time units to each other:
80039 */
80040-extern unsigned int jiffies_to_msecs(const unsigned long j);
80041-extern unsigned int jiffies_to_usecs(const unsigned long j);
80042+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
80043+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
80044
80045-static inline u64 jiffies_to_nsecs(const unsigned long j)
80046+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
80047 {
80048 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
80049 }
80050
80051-extern unsigned long msecs_to_jiffies(const unsigned int m);
80052-extern unsigned long usecs_to_jiffies(const unsigned int u);
80053+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
80054+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
80055 extern unsigned long timespec_to_jiffies(const struct timespec *value);
80056 extern void jiffies_to_timespec(const unsigned long jiffies,
80057- struct timespec *value);
80058-extern unsigned long timeval_to_jiffies(const struct timeval *value);
80059+ struct timespec *value) __intentional_overflow(-1);
80060+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
80061 extern void jiffies_to_timeval(const unsigned long jiffies,
80062 struct timeval *value);
80063
80064diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80065index 6883e19..e854fcb 100644
80066--- a/include/linux/kallsyms.h
80067+++ b/include/linux/kallsyms.h
80068@@ -15,7 +15,8 @@
80069
80070 struct module;
80071
80072-#ifdef CONFIG_KALLSYMS
80073+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80074+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80075 /* Lookup the address for a symbol. Returns 0 if not found. */
80076 unsigned long kallsyms_lookup_name(const char *name);
80077
80078@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80079 /* Stupid that this does nothing, but I didn't create this mess. */
80080 #define __print_symbol(fmt, addr)
80081 #endif /*CONFIG_KALLSYMS*/
80082+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80083+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80084+extern unsigned long kallsyms_lookup_name(const char *name);
80085+extern void __print_symbol(const char *fmt, unsigned long address);
80086+extern int sprint_backtrace(char *buffer, unsigned long address);
80087+extern int sprint_symbol(char *buffer, unsigned long address);
80088+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80089+const char *kallsyms_lookup(unsigned long addr,
80090+ unsigned long *symbolsize,
80091+ unsigned long *offset,
80092+ char **modname, char *namebuf);
80093+extern int kallsyms_lookup_size_offset(unsigned long addr,
80094+ unsigned long *symbolsize,
80095+ unsigned long *offset);
80096+#endif
80097
80098 /* This macro allows us to keep printk typechecking */
80099 static __printf(1, 2)
80100diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80101index a74c3a8..28d3f21 100644
80102--- a/include/linux/key-type.h
80103+++ b/include/linux/key-type.h
80104@@ -131,7 +131,7 @@ struct key_type {
80105 /* internal fields */
80106 struct list_head link; /* link in types list */
80107 struct lock_class_key lock_class; /* key->sem lock class */
80108-};
80109+} __do_const;
80110
80111 extern struct key_type key_type_keyring;
80112
80113diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80114index 6b06d37..c134867 100644
80115--- a/include/linux/kgdb.h
80116+++ b/include/linux/kgdb.h
80117@@ -52,7 +52,7 @@ extern int kgdb_connected;
80118 extern int kgdb_io_module_registered;
80119
80120 extern atomic_t kgdb_setting_breakpoint;
80121-extern atomic_t kgdb_cpu_doing_single_step;
80122+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80123
80124 extern struct task_struct *kgdb_usethread;
80125 extern struct task_struct *kgdb_contthread;
80126@@ -254,7 +254,7 @@ struct kgdb_arch {
80127 void (*correct_hw_break)(void);
80128
80129 void (*enable_nmi)(bool on);
80130-};
80131+} __do_const;
80132
80133 /**
80134 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80135@@ -279,7 +279,7 @@ struct kgdb_io {
80136 void (*pre_exception) (void);
80137 void (*post_exception) (void);
80138 int is_console;
80139-};
80140+} __do_const;
80141
80142 extern struct kgdb_arch arch_kgdb_ops;
80143
80144diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80145index 0555cc6..40116ce 100644
80146--- a/include/linux/kmod.h
80147+++ b/include/linux/kmod.h
80148@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80149 * usually useless though. */
80150 extern __printf(2, 3)
80151 int __request_module(bool wait, const char *name, ...);
80152+extern __printf(3, 4)
80153+int ___request_module(bool wait, char *param_name, const char *name, ...);
80154 #define request_module(mod...) __request_module(true, mod)
80155 #define request_module_nowait(mod...) __request_module(false, mod)
80156 #define try_then_request_module(x, mod...) \
80157@@ -57,6 +59,9 @@ struct subprocess_info {
80158 struct work_struct work;
80159 struct completion *complete;
80160 char *path;
80161+#ifdef CONFIG_GRKERNSEC
80162+ char *origpath;
80163+#endif
80164 char **argv;
80165 char **envp;
80166 int wait;
80167diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80168index f896a33..f2eb10f 100644
80169--- a/include/linux/kobject.h
80170+++ b/include/linux/kobject.h
80171@@ -116,7 +116,7 @@ struct kobj_type {
80172 struct attribute **default_attrs;
80173 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80174 const void *(*namespace)(struct kobject *kobj);
80175-};
80176+} __do_const;
80177
80178 struct kobj_uevent_env {
80179 char *argv[3];
80180@@ -140,6 +140,7 @@ struct kobj_attribute {
80181 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80182 const char *buf, size_t count);
80183 };
80184+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80185
80186 extern const struct sysfs_ops kobj_sysfs_ops;
80187
80188@@ -167,7 +168,7 @@ struct kset {
80189 spinlock_t list_lock;
80190 struct kobject kobj;
80191 const struct kset_uevent_ops *uevent_ops;
80192-};
80193+} __randomize_layout;
80194
80195 extern void kset_init(struct kset *kset);
80196 extern int __must_check kset_register(struct kset *kset);
80197diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80198index df32d25..fb52e27 100644
80199--- a/include/linux/kobject_ns.h
80200+++ b/include/linux/kobject_ns.h
80201@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80202 const void *(*netlink_ns)(struct sock *sk);
80203 const void *(*initial_ns)(void);
80204 void (*drop_ns)(void *);
80205-};
80206+} __do_const;
80207
80208 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80209 int kobj_ns_type_registered(enum kobj_ns_type type);
80210diff --git a/include/linux/kref.h b/include/linux/kref.h
80211index 484604d..0f6c5b6 100644
80212--- a/include/linux/kref.h
80213+++ b/include/linux/kref.h
80214@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80215 static inline int kref_sub(struct kref *kref, unsigned int count,
80216 void (*release)(struct kref *kref))
80217 {
80218- WARN_ON(release == NULL);
80219+ BUG_ON(release == NULL);
80220
80221 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80222 release(kref);
80223diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80224index 7d21cf9..bc0c81f 100644
80225--- a/include/linux/kvm_host.h
80226+++ b/include/linux/kvm_host.h
80227@@ -466,7 +466,7 @@ static inline void kvm_irqfd_exit(void)
80228 {
80229 }
80230 #endif
80231-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80232+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80233 struct module *module);
80234 void kvm_exit(void);
80235
80236@@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80237 struct kvm_guest_debug *dbg);
80238 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80239
80240-int kvm_arch_init(void *opaque);
80241+int kvm_arch_init(const void *opaque);
80242 void kvm_arch_exit(void);
80243
80244 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80245diff --git a/include/linux/libata.h b/include/linux/libata.h
80246index 5ab4e3a..2fe237b 100644
80247--- a/include/linux/libata.h
80248+++ b/include/linux/libata.h
80249@@ -975,7 +975,7 @@ struct ata_port_operations {
80250 * fields must be pointers.
80251 */
80252 const struct ata_port_operations *inherits;
80253-};
80254+} __do_const;
80255
80256 struct ata_port_info {
80257 unsigned long flags;
80258diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80259index a6a42dd..6c5ebce 100644
80260--- a/include/linux/linkage.h
80261+++ b/include/linux/linkage.h
80262@@ -36,6 +36,7 @@
80263 #endif
80264
80265 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80266+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80267 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80268
80269 /*
80270diff --git a/include/linux/list.h b/include/linux/list.h
80271index ef95941..82db65a 100644
80272--- a/include/linux/list.h
80273+++ b/include/linux/list.h
80274@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80275 extern void list_del(struct list_head *entry);
80276 #endif
80277
80278+extern void __pax_list_add(struct list_head *new,
80279+ struct list_head *prev,
80280+ struct list_head *next);
80281+static inline void pax_list_add(struct list_head *new, struct list_head *head)
80282+{
80283+ __pax_list_add(new, head, head->next);
80284+}
80285+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80286+{
80287+ __pax_list_add(new, head->prev, head);
80288+}
80289+extern void pax_list_del(struct list_head *entry);
80290+
80291 /**
80292 * list_replace - replace old entry by new one
80293 * @old : the element to be replaced
80294@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80295 INIT_LIST_HEAD(entry);
80296 }
80297
80298+extern void pax_list_del_init(struct list_head *entry);
80299+
80300 /**
80301 * list_move - delete from one list and add as another's head
80302 * @list: the entry to move
80303diff --git a/include/linux/math64.h b/include/linux/math64.h
80304index c45c089..298841c 100644
80305--- a/include/linux/math64.h
80306+++ b/include/linux/math64.h
80307@@ -15,7 +15,7 @@
80308 * This is commonly provided by 32bit archs to provide an optimized 64bit
80309 * divide.
80310 */
80311-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80312+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80313 {
80314 *remainder = dividend % divisor;
80315 return dividend / divisor;
80316@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80317 /**
80318 * div64_u64 - unsigned 64bit divide with 64bit divisor
80319 */
80320-static inline u64 div64_u64(u64 dividend, u64 divisor)
80321+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80322 {
80323 return dividend / divisor;
80324 }
80325@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80326 #define div64_ul(x, y) div_u64((x), (y))
80327
80328 #ifndef div_u64_rem
80329-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80330+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80331 {
80332 *remainder = do_div(dividend, divisor);
80333 return dividend;
80334@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80335 #endif
80336
80337 #ifndef div64_u64
80338-extern u64 div64_u64(u64 dividend, u64 divisor);
80339+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80340 #endif
80341
80342 #ifndef div64_s64
80343@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80344 * divide.
80345 */
80346 #ifndef div_u64
80347-static inline u64 div_u64(u64 dividend, u32 divisor)
80348+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80349 {
80350 u32 remainder;
80351 return div_u64_rem(dividend, divisor, &remainder);
80352diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80353index f230a97..714c006 100644
80354--- a/include/linux/mempolicy.h
80355+++ b/include/linux/mempolicy.h
80356@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80357 }
80358
80359 #define vma_policy(vma) ((vma)->vm_policy)
80360+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80361+{
80362+ vma->vm_policy = pol;
80363+}
80364
80365 static inline void mpol_get(struct mempolicy *pol)
80366 {
80367@@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80368 }
80369
80370 #define vma_policy(vma) NULL
80371+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80372+{
80373+}
80374
80375 static inline int
80376 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80377diff --git a/include/linux/mm.h b/include/linux/mm.h
80378index d677706..673408c 100644
80379--- a/include/linux/mm.h
80380+++ b/include/linux/mm.h
80381@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80382 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80383 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80384 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80385+
80386+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80387+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80388+#endif
80389+
80390 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80391
80392 #ifdef CONFIG_MEM_SOFT_DIRTY
80393@@ -237,8 +242,8 @@ struct vm_operations_struct {
80394 /* called by access_process_vm when get_user_pages() fails, typically
80395 * for use by special VMAs that can switch between memory and hardware
80396 */
80397- int (*access)(struct vm_area_struct *vma, unsigned long addr,
80398- void *buf, int len, int write);
80399+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80400+ void *buf, size_t len, int write);
80401 #ifdef CONFIG_NUMA
80402 /*
80403 * set_policy() op must add a reference to any non-NULL @new mempolicy
80404@@ -268,6 +273,7 @@ struct vm_operations_struct {
80405 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80406 unsigned long size, pgoff_t pgoff);
80407 };
80408+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80409
80410 struct mmu_gather;
80411 struct inode;
80412@@ -1133,8 +1139,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80413 unsigned long *pfn);
80414 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80415 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80416-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80417- void *buf, int len, int write);
80418+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80419+ void *buf, size_t len, int write);
80420
80421 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80422 loff_t const holebegin, loff_t const holelen)
80423@@ -1173,9 +1179,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80424 }
80425 #endif
80426
80427-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80428-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80429- void *buf, int len, int write);
80430+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80431+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80432+ void *buf, size_t len, int write);
80433
80434 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80435 unsigned long start, unsigned long nr_pages,
80436@@ -1208,34 +1214,6 @@ int set_page_dirty_lock(struct page *page);
80437 int clear_page_dirty_for_io(struct page *page);
80438 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
80439
80440-/* Is the vma a continuation of the stack vma above it? */
80441-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80442-{
80443- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80444-}
80445-
80446-static inline int stack_guard_page_start(struct vm_area_struct *vma,
80447- unsigned long addr)
80448-{
80449- return (vma->vm_flags & VM_GROWSDOWN) &&
80450- (vma->vm_start == addr) &&
80451- !vma_growsdown(vma->vm_prev, addr);
80452-}
80453-
80454-/* Is the vma a continuation of the stack vma below it? */
80455-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80456-{
80457- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80458-}
80459-
80460-static inline int stack_guard_page_end(struct vm_area_struct *vma,
80461- unsigned long addr)
80462-{
80463- return (vma->vm_flags & VM_GROWSUP) &&
80464- (vma->vm_end == addr) &&
80465- !vma_growsup(vma->vm_next, addr);
80466-}
80467-
80468 extern pid_t
80469 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80470
80471@@ -1335,6 +1313,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80472 }
80473 #endif
80474
80475+#ifdef CONFIG_MMU
80476+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80477+#else
80478+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80479+{
80480+ return __pgprot(0);
80481+}
80482+#endif
80483+
80484 int vma_wants_writenotify(struct vm_area_struct *vma);
80485
80486 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80487@@ -1353,8 +1340,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80488 {
80489 return 0;
80490 }
80491+
80492+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80493+ unsigned long address)
80494+{
80495+ return 0;
80496+}
80497 #else
80498 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80499+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80500 #endif
80501
80502 #ifdef __PAGETABLE_PMD_FOLDED
80503@@ -1363,8 +1357,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80504 {
80505 return 0;
80506 }
80507+
80508+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80509+ unsigned long address)
80510+{
80511+ return 0;
80512+}
80513 #else
80514 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80515+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80516 #endif
80517
80518 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80519@@ -1382,11 +1383,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80520 NULL: pud_offset(pgd, address);
80521 }
80522
80523+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80524+{
80525+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80526+ NULL: pud_offset(pgd, address);
80527+}
80528+
80529 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80530 {
80531 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80532 NULL: pmd_offset(pud, address);
80533 }
80534+
80535+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80536+{
80537+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80538+ NULL: pmd_offset(pud, address);
80539+}
80540 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80541
80542 #if USE_SPLIT_PTE_PTLOCKS
80543@@ -1783,7 +1796,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80544 unsigned long addr, unsigned long len,
80545 unsigned long flags, struct page **pages);
80546
80547-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80548+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80549
80550 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80551 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80552@@ -1791,6 +1804,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80553 unsigned long len, unsigned long prot, unsigned long flags,
80554 unsigned long pgoff, unsigned long *populate);
80555 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80556+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80557
80558 #ifdef CONFIG_MMU
80559 extern int __mm_populate(unsigned long addr, unsigned long len,
80560@@ -1819,10 +1833,11 @@ struct vm_unmapped_area_info {
80561 unsigned long high_limit;
80562 unsigned long align_mask;
80563 unsigned long align_offset;
80564+ unsigned long threadstack_offset;
80565 };
80566
80567-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80568-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80569+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80570+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80571
80572 /*
80573 * Search for an unmapped address range.
80574@@ -1834,7 +1849,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80575 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80576 */
80577 static inline unsigned long
80578-vm_unmapped_area(struct vm_unmapped_area_info *info)
80579+vm_unmapped_area(const struct vm_unmapped_area_info *info)
80580 {
80581 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80582 return unmapped_area(info);
80583@@ -1896,6 +1911,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80584 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80585 struct vm_area_struct **pprev);
80586
80587+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80588+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80589+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80590+
80591 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80592 NULL if none. Assume start_addr < end_addr. */
80593 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80594@@ -1924,15 +1943,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80595 return vma;
80596 }
80597
80598-#ifdef CONFIG_MMU
80599-pgprot_t vm_get_page_prot(unsigned long vm_flags);
80600-#else
80601-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80602-{
80603- return __pgprot(0);
80604-}
80605-#endif
80606-
80607 #ifdef CONFIG_NUMA_BALANCING
80608 unsigned long change_prot_numa(struct vm_area_struct *vma,
80609 unsigned long start, unsigned long end);
80610@@ -1984,6 +1994,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80611 static inline void vm_stat_account(struct mm_struct *mm,
80612 unsigned long flags, struct file *file, long pages)
80613 {
80614+
80615+#ifdef CONFIG_PAX_RANDMMAP
80616+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80617+#endif
80618+
80619 mm->total_vm += pages;
80620 }
80621 #endif /* CONFIG_PROC_FS */
80622@@ -2065,7 +2080,7 @@ extern int unpoison_memory(unsigned long pfn);
80623 extern int sysctl_memory_failure_early_kill;
80624 extern int sysctl_memory_failure_recovery;
80625 extern void shake_page(struct page *p, int access);
80626-extern atomic_long_t num_poisoned_pages;
80627+extern atomic_long_unchecked_t num_poisoned_pages;
80628 extern int soft_offline_page(struct page *page, int flags);
80629
80630 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
80631@@ -2100,5 +2115,11 @@ void __init setup_nr_node_ids(void);
80632 static inline void setup_nr_node_ids(void) {}
80633 #endif
80634
80635+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80636+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80637+#else
80638+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80639+#endif
80640+
80641 #endif /* __KERNEL__ */
80642 #endif /* _LINUX_MM_H */
80643diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80644index 8967e20..61f7900 100644
80645--- a/include/linux/mm_types.h
80646+++ b/include/linux/mm_types.h
80647@@ -308,7 +308,9 @@ struct vm_area_struct {
80648 #ifdef CONFIG_NUMA
80649 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80650 #endif
80651-};
80652+
80653+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80654+} __randomize_layout;
80655
80656 struct core_thread {
80657 struct task_struct *task;
80658@@ -454,7 +456,25 @@ struct mm_struct {
80659 bool tlb_flush_pending;
80660 #endif
80661 struct uprobes_state uprobes_state;
80662-};
80663+
80664+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80665+ unsigned long pax_flags;
80666+#endif
80667+
80668+#ifdef CONFIG_PAX_DLRESOLVE
80669+ unsigned long call_dl_resolve;
80670+#endif
80671+
80672+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80673+ unsigned long call_syscall;
80674+#endif
80675+
80676+#ifdef CONFIG_PAX_ASLR
80677+ unsigned long delta_mmap; /* randomized offset */
80678+ unsigned long delta_stack; /* randomized offset */
80679+#endif
80680+
80681+} __randomize_layout;
80682
80683 static inline void mm_init_cpumask(struct mm_struct *mm)
80684 {
80685diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80686index c5d5278..f0b68c8 100644
80687--- a/include/linux/mmiotrace.h
80688+++ b/include/linux/mmiotrace.h
80689@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80690 /* Called from ioremap.c */
80691 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80692 void __iomem *addr);
80693-extern void mmiotrace_iounmap(volatile void __iomem *addr);
80694+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80695
80696 /* For anyone to insert markers. Remember trailing newline. */
80697 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80698@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80699 {
80700 }
80701
80702-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80703+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80704 {
80705 }
80706
80707diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80708index 835aa3d..676b387 100644
80709--- a/include/linux/mmzone.h
80710+++ b/include/linux/mmzone.h
80711@@ -406,7 +406,7 @@ struct zone {
80712 unsigned long flags; /* zone flags, see below */
80713
80714 /* Zone statistics */
80715- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80716+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80717
80718 /*
80719 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80720diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80721index 44eeef0..a92d3f9 100644
80722--- a/include/linux/mod_devicetable.h
80723+++ b/include/linux/mod_devicetable.h
80724@@ -139,7 +139,7 @@ struct usb_device_id {
80725 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80726 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80727
80728-#define HID_ANY_ID (~0)
80729+#define HID_ANY_ID (~0U)
80730 #define HID_BUS_ANY 0xffff
80731 #define HID_GROUP_ANY 0x0000
80732
80733@@ -475,7 +475,7 @@ struct dmi_system_id {
80734 const char *ident;
80735 struct dmi_strmatch matches[4];
80736 void *driver_data;
80737-};
80738+} __do_const;
80739 /*
80740 * struct dmi_device_id appears during expansion of
80741 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80742diff --git a/include/linux/module.h b/include/linux/module.h
80743index f520a76..5f898ef 100644
80744--- a/include/linux/module.h
80745+++ b/include/linux/module.h
80746@@ -17,9 +17,11 @@
80747 #include <linux/moduleparam.h>
80748 #include <linux/jump_label.h>
80749 #include <linux/export.h>
80750+#include <linux/fs.h>
80751
80752 #include <linux/percpu.h>
80753 #include <asm/module.h>
80754+#include <asm/pgtable.h>
80755
80756 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80757 #define MODULE_SIG_STRING "~Module signature appended~\n"
80758@@ -42,7 +44,7 @@ struct module_kobject {
80759 struct kobject *drivers_dir;
80760 struct module_param_attrs *mp;
80761 struct completion *kobj_completion;
80762-};
80763+} __randomize_layout;
80764
80765 struct module_attribute {
80766 struct attribute attr;
80767@@ -54,12 +56,13 @@ struct module_attribute {
80768 int (*test)(struct module *);
80769 void (*free)(struct module *);
80770 };
80771+typedef struct module_attribute __no_const module_attribute_no_const;
80772
80773 struct module_version_attribute {
80774 struct module_attribute mattr;
80775 const char *module_name;
80776 const char *version;
80777-} __attribute__ ((__aligned__(sizeof(void *))));
80778+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80779
80780 extern ssize_t __modver_version_show(struct module_attribute *,
80781 struct module_kobject *, char *);
80782@@ -235,7 +238,7 @@ struct module {
80783
80784 /* Sysfs stuff. */
80785 struct module_kobject mkobj;
80786- struct module_attribute *modinfo_attrs;
80787+ module_attribute_no_const *modinfo_attrs;
80788 const char *version;
80789 const char *srcversion;
80790 struct kobject *holders_dir;
80791@@ -284,19 +287,16 @@ struct module {
80792 int (*init)(void);
80793
80794 /* If this is non-NULL, vfree after init() returns */
80795- void *module_init;
80796+ void *module_init_rx, *module_init_rw;
80797
80798 /* Here is the actual code + data, vfree'd on unload. */
80799- void *module_core;
80800+ void *module_core_rx, *module_core_rw;
80801
80802 /* Here are the sizes of the init and core sections */
80803- unsigned int init_size, core_size;
80804+ unsigned int init_size_rw, core_size_rw;
80805
80806 /* The size of the executable code in each section. */
80807- unsigned int init_text_size, core_text_size;
80808-
80809- /* Size of RO sections of the module (text+rodata) */
80810- unsigned int init_ro_size, core_ro_size;
80811+ unsigned int init_size_rx, core_size_rx;
80812
80813 /* Arch-specific module values */
80814 struct mod_arch_specific arch;
80815@@ -352,6 +352,10 @@ struct module {
80816 #ifdef CONFIG_EVENT_TRACING
80817 struct ftrace_event_call **trace_events;
80818 unsigned int num_trace_events;
80819+ struct file_operations trace_id;
80820+ struct file_operations trace_enable;
80821+ struct file_operations trace_format;
80822+ struct file_operations trace_filter;
80823 #endif
80824 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80825 unsigned int num_ftrace_callsites;
80826@@ -375,7 +379,7 @@ struct module {
80827 ctor_fn_t *ctors;
80828 unsigned int num_ctors;
80829 #endif
80830-};
80831+} __randomize_layout;
80832 #ifndef MODULE_ARCH_INIT
80833 #define MODULE_ARCH_INIT {}
80834 #endif
80835@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
80836 bool is_module_percpu_address(unsigned long addr);
80837 bool is_module_text_address(unsigned long addr);
80838
80839+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80840+{
80841+
80842+#ifdef CONFIG_PAX_KERNEXEC
80843+ if (ktla_ktva(addr) >= (unsigned long)start &&
80844+ ktla_ktva(addr) < (unsigned long)start + size)
80845+ return 1;
80846+#endif
80847+
80848+ return ((void *)addr >= start && (void *)addr < start + size);
80849+}
80850+
80851+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80852+{
80853+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80854+}
80855+
80856+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80857+{
80858+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80859+}
80860+
80861+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80862+{
80863+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80864+}
80865+
80866+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80867+{
80868+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80869+}
80870+
80871 static inline int within_module_core(unsigned long addr, const struct module *mod)
80872 {
80873- return (unsigned long)mod->module_core <= addr &&
80874- addr < (unsigned long)mod->module_core + mod->core_size;
80875+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80876 }
80877
80878 static inline int within_module_init(unsigned long addr, const struct module *mod)
80879 {
80880- return (unsigned long)mod->module_init <= addr &&
80881- addr < (unsigned long)mod->module_init + mod->init_size;
80882+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80883 }
80884
80885 /* Search for module by name: must hold module_mutex. */
80886diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80887index 560ca53..ef621ef 100644
80888--- a/include/linux/moduleloader.h
80889+++ b/include/linux/moduleloader.h
80890@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80891 sections. Returns NULL on failure. */
80892 void *module_alloc(unsigned long size);
80893
80894+#ifdef CONFIG_PAX_KERNEXEC
80895+void *module_alloc_exec(unsigned long size);
80896+#else
80897+#define module_alloc_exec(x) module_alloc(x)
80898+#endif
80899+
80900 /* Free memory returned from module_alloc. */
80901 void module_free(struct module *mod, void *module_region);
80902
80903+#ifdef CONFIG_PAX_KERNEXEC
80904+void module_free_exec(struct module *mod, void *module_region);
80905+#else
80906+#define module_free_exec(x, y) module_free((x), (y))
80907+#endif
80908+
80909 /*
80910 * Apply the given relocation to the (simplified) ELF. Return -error
80911 * or 0.
80912@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80913 unsigned int relsec,
80914 struct module *me)
80915 {
80916+#ifdef CONFIG_MODULES
80917 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80918+#endif
80919 return -ENOEXEC;
80920 }
80921 #endif
80922@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80923 unsigned int relsec,
80924 struct module *me)
80925 {
80926+#ifdef CONFIG_MODULES
80927 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80928+#endif
80929 return -ENOEXEC;
80930 }
80931 #endif
80932diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80933index 204a677..e9b486a 100644
80934--- a/include/linux/moduleparam.h
80935+++ b/include/linux/moduleparam.h
80936@@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
80937 * @len is usually just sizeof(string).
80938 */
80939 #define module_param_string(name, string, len, perm) \
80940- static const struct kparam_string __param_string_##name \
80941+ static const struct kparam_string __param_string_##name __used \
80942 = { len, string }; \
80943 __module_param_call(MODULE_PARAM_PREFIX, name, \
80944 &param_ops_string, \
80945@@ -432,7 +432,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80946 */
80947 #define module_param_array_named(name, array, type, nump, perm) \
80948 param_check_##type(name, &(array)[0]); \
80949- static const struct kparam_array __param_arr_##name \
80950+ static const struct kparam_array __param_arr_##name __used \
80951 = { .max = ARRAY_SIZE(array), .num = nump, \
80952 .ops = &param_ops_##type, \
80953 .elemsize = sizeof(array[0]), .elem = array }; \
80954diff --git a/include/linux/mount.h b/include/linux/mount.h
80955index 839bac2..a96b37c 100644
80956--- a/include/linux/mount.h
80957+++ b/include/linux/mount.h
80958@@ -59,7 +59,7 @@ struct vfsmount {
80959 struct dentry *mnt_root; /* root of the mounted tree */
80960 struct super_block *mnt_sb; /* pointer to superblock */
80961 int mnt_flags;
80962-};
80963+} __randomize_layout;
80964
80965 struct file; /* forward dec */
80966
80967diff --git a/include/linux/namei.h b/include/linux/namei.h
80968index 492de72..1bddcd4 100644
80969--- a/include/linux/namei.h
80970+++ b/include/linux/namei.h
80971@@ -19,7 +19,7 @@ struct nameidata {
80972 unsigned seq, m_seq;
80973 int last_type;
80974 unsigned depth;
80975- char *saved_names[MAX_NESTED_LINKS + 1];
80976+ const char *saved_names[MAX_NESTED_LINKS + 1];
80977 };
80978
80979 /*
80980@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
80981
80982 extern void nd_jump_link(struct nameidata *nd, struct path *path);
80983
80984-static inline void nd_set_link(struct nameidata *nd, char *path)
80985+static inline void nd_set_link(struct nameidata *nd, const char *path)
80986 {
80987 nd->saved_names[nd->depth] = path;
80988 }
80989
80990-static inline char *nd_get_link(struct nameidata *nd)
80991+static inline const char *nd_get_link(const struct nameidata *nd)
80992 {
80993 return nd->saved_names[nd->depth];
80994 }
80995diff --git a/include/linux/net.h b/include/linux/net.h
80996index 17d8339..81656c0 100644
80997--- a/include/linux/net.h
80998+++ b/include/linux/net.h
80999@@ -192,7 +192,7 @@ struct net_proto_family {
81000 int (*create)(struct net *net, struct socket *sock,
81001 int protocol, int kern);
81002 struct module *owner;
81003-};
81004+} __do_const;
81005
81006 struct iovec;
81007 struct kvec;
81008diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
81009index b42d07b..7f45ae2 100644
81010--- a/include/linux/netdevice.h
81011+++ b/include/linux/netdevice.h
81012@@ -1146,6 +1146,7 @@ struct net_device_ops {
81013 void *priv);
81014 int (*ndo_get_lock_subclass)(struct net_device *dev);
81015 };
81016+typedef struct net_device_ops __no_const net_device_ops_no_const;
81017
81018 /**
81019 * enum net_device_priv_flags - &struct net_device priv_flags
81020@@ -1313,11 +1314,11 @@ struct net_device {
81021 struct net_device_stats stats;
81022
81023 /* dropped packets by core network, Do not use this in drivers */
81024- atomic_long_t rx_dropped;
81025- atomic_long_t tx_dropped;
81026+ atomic_long_unchecked_t rx_dropped;
81027+ atomic_long_unchecked_t tx_dropped;
81028
81029 /* Stats to monitor carrier on<->off transitions */
81030- atomic_t carrier_changes;
81031+ atomic_unchecked_t carrier_changes;
81032
81033 #ifdef CONFIG_WIRELESS_EXT
81034 /* List of functions to handle Wireless Extensions (instead of ioctl).
81035diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
81036index 2077489..a15e561 100644
81037--- a/include/linux/netfilter.h
81038+++ b/include/linux/netfilter.h
81039@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
81040 #endif
81041 /* Use the module struct to lock set/get code in place */
81042 struct module *owner;
81043-};
81044+} __do_const;
81045
81046 /* Function to register/unregister hook points. */
81047 int nf_register_hook(struct nf_hook_ops *reg);
81048diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
81049index e955d47..04a5338 100644
81050--- a/include/linux/netfilter/nfnetlink.h
81051+++ b/include/linux/netfilter/nfnetlink.h
81052@@ -19,7 +19,7 @@ struct nfnl_callback {
81053 const struct nlattr * const cda[]);
81054 const struct nla_policy *policy; /* netlink attribute policy */
81055 const u_int16_t attr_count; /* number of nlattr's */
81056-};
81057+} __do_const;
81058
81059 struct nfnetlink_subsystem {
81060 const char *name;
81061diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81062new file mode 100644
81063index 0000000..33f4af8
81064--- /dev/null
81065+++ b/include/linux/netfilter/xt_gradm.h
81066@@ -0,0 +1,9 @@
81067+#ifndef _LINUX_NETFILTER_XT_GRADM_H
81068+#define _LINUX_NETFILTER_XT_GRADM_H 1
81069+
81070+struct xt_gradm_mtinfo {
81071+ __u16 flags;
81072+ __u16 invflags;
81073+};
81074+
81075+#endif
81076diff --git a/include/linux/nls.h b/include/linux/nls.h
81077index 520681b..1d67ed2 100644
81078--- a/include/linux/nls.h
81079+++ b/include/linux/nls.h
81080@@ -31,7 +31,7 @@ struct nls_table {
81081 const unsigned char *charset2upper;
81082 struct module *owner;
81083 struct nls_table *next;
81084-};
81085+} __do_const;
81086
81087 /* this value hold the maximum octet of charset */
81088 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81089diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81090index d14a4c3..a078786 100644
81091--- a/include/linux/notifier.h
81092+++ b/include/linux/notifier.h
81093@@ -54,7 +54,8 @@ struct notifier_block {
81094 notifier_fn_t notifier_call;
81095 struct notifier_block __rcu *next;
81096 int priority;
81097-};
81098+} __do_const;
81099+typedef struct notifier_block __no_const notifier_block_no_const;
81100
81101 struct atomic_notifier_head {
81102 spinlock_t lock;
81103diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81104index b2a0f15..4d7da32 100644
81105--- a/include/linux/oprofile.h
81106+++ b/include/linux/oprofile.h
81107@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81108 int oprofilefs_create_ro_ulong(struct dentry * root,
81109 char const * name, ulong * val);
81110
81111-/** Create a file for read-only access to an atomic_t. */
81112+/** Create a file for read-only access to an atomic_unchecked_t. */
81113 int oprofilefs_create_ro_atomic(struct dentry * root,
81114- char const * name, atomic_t * val);
81115+ char const * name, atomic_unchecked_t * val);
81116
81117 /** create a directory */
81118 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81119diff --git a/include/linux/padata.h b/include/linux/padata.h
81120index 4386946..f50c615 100644
81121--- a/include/linux/padata.h
81122+++ b/include/linux/padata.h
81123@@ -129,7 +129,7 @@ struct parallel_data {
81124 struct padata_serial_queue __percpu *squeue;
81125 atomic_t reorder_objects;
81126 atomic_t refcnt;
81127- atomic_t seq_nr;
81128+ atomic_unchecked_t seq_nr;
81129 struct padata_cpumask cpumask;
81130 spinlock_t lock ____cacheline_aligned;
81131 unsigned int processed;
81132diff --git a/include/linux/path.h b/include/linux/path.h
81133index d137218..be0c176 100644
81134--- a/include/linux/path.h
81135+++ b/include/linux/path.h
81136@@ -1,13 +1,15 @@
81137 #ifndef _LINUX_PATH_H
81138 #define _LINUX_PATH_H
81139
81140+#include <linux/compiler.h>
81141+
81142 struct dentry;
81143 struct vfsmount;
81144
81145 struct path {
81146 struct vfsmount *mnt;
81147 struct dentry *dentry;
81148-};
81149+} __randomize_layout;
81150
81151 extern void path_get(const struct path *);
81152 extern void path_put(const struct path *);
81153diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81154index 5f2e559..7d59314 100644
81155--- a/include/linux/pci_hotplug.h
81156+++ b/include/linux/pci_hotplug.h
81157@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81158 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81159 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81160 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81161-};
81162+} __do_const;
81163+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81164
81165 /**
81166 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81167diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81168index 3ef6ea1..ed1a248 100644
81169--- a/include/linux/perf_event.h
81170+++ b/include/linux/perf_event.h
81171@@ -328,8 +328,8 @@ struct perf_event {
81172
81173 enum perf_event_active_state state;
81174 unsigned int attach_state;
81175- local64_t count;
81176- atomic64_t child_count;
81177+ local64_t count; /* PaX: fix it one day */
81178+ atomic64_unchecked_t child_count;
81179
81180 /*
81181 * These are the total time in nanoseconds that the event
81182@@ -380,8 +380,8 @@ struct perf_event {
81183 * These accumulate total time (in nanoseconds) that children
81184 * events have been enabled and running, respectively.
81185 */
81186- atomic64_t child_total_time_enabled;
81187- atomic64_t child_total_time_running;
81188+ atomic64_unchecked_t child_total_time_enabled;
81189+ atomic64_unchecked_t child_total_time_running;
81190
81191 /*
81192 * Protect attach/detach and child_list:
81193@@ -710,7 +710,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81194 entry->ip[entry->nr++] = ip;
81195 }
81196
81197-extern int sysctl_perf_event_paranoid;
81198+extern int sysctl_perf_event_legitimately_concerned;
81199 extern int sysctl_perf_event_mlock;
81200 extern int sysctl_perf_event_sample_rate;
81201 extern int sysctl_perf_cpu_time_max_percent;
81202@@ -725,19 +725,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81203 loff_t *ppos);
81204
81205
81206+static inline bool perf_paranoid_any(void)
81207+{
81208+ return sysctl_perf_event_legitimately_concerned > 2;
81209+}
81210+
81211 static inline bool perf_paranoid_tracepoint_raw(void)
81212 {
81213- return sysctl_perf_event_paranoid > -1;
81214+ return sysctl_perf_event_legitimately_concerned > -1;
81215 }
81216
81217 static inline bool perf_paranoid_cpu(void)
81218 {
81219- return sysctl_perf_event_paranoid > 0;
81220+ return sysctl_perf_event_legitimately_concerned > 0;
81221 }
81222
81223 static inline bool perf_paranoid_kernel(void)
81224 {
81225- return sysctl_perf_event_paranoid > 1;
81226+ return sysctl_perf_event_legitimately_concerned > 1;
81227 }
81228
81229 extern void perf_event_init(void);
81230@@ -867,7 +872,7 @@ struct perf_pmu_events_attr {
81231 struct device_attribute attr;
81232 u64 id;
81233 const char *event_str;
81234-};
81235+} __do_const;
81236
81237 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81238 static struct perf_pmu_events_attr _var = { \
81239diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81240index 7246ef3..1539ea4 100644
81241--- a/include/linux/pid_namespace.h
81242+++ b/include/linux/pid_namespace.h
81243@@ -43,7 +43,7 @@ struct pid_namespace {
81244 int hide_pid;
81245 int reboot; /* group exit code if this pidns was rebooted */
81246 unsigned int proc_inum;
81247-};
81248+} __randomize_layout;
81249
81250 extern struct pid_namespace init_pid_ns;
81251
81252diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81253index eb8b8ac..62649e1 100644
81254--- a/include/linux/pipe_fs_i.h
81255+++ b/include/linux/pipe_fs_i.h
81256@@ -47,10 +47,10 @@ struct pipe_inode_info {
81257 struct mutex mutex;
81258 wait_queue_head_t wait;
81259 unsigned int nrbufs, curbuf, buffers;
81260- unsigned int readers;
81261- unsigned int writers;
81262- unsigned int files;
81263- unsigned int waiting_writers;
81264+ atomic_t readers;
81265+ atomic_t writers;
81266+ atomic_t files;
81267+ atomic_t waiting_writers;
81268 unsigned int r_counter;
81269 unsigned int w_counter;
81270 struct page *tmp_page;
81271diff --git a/include/linux/pm.h b/include/linux/pm.h
81272index d915d03..0531037 100644
81273--- a/include/linux/pm.h
81274+++ b/include/linux/pm.h
81275@@ -600,6 +600,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81276 struct dev_pm_domain {
81277 struct dev_pm_ops ops;
81278 };
81279+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81280
81281 /*
81282 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81283diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81284index 7c1d252..0e7061d 100644
81285--- a/include/linux/pm_domain.h
81286+++ b/include/linux/pm_domain.h
81287@@ -44,11 +44,11 @@ struct gpd_dev_ops {
81288 int (*thaw_early)(struct device *dev);
81289 int (*thaw)(struct device *dev);
81290 bool (*active_wakeup)(struct device *dev);
81291-};
81292+} __no_const;
81293
81294 struct gpd_cpu_data {
81295 unsigned int saved_exit_latency;
81296- struct cpuidle_state *idle_state;
81297+ cpuidle_state_no_const *idle_state;
81298 };
81299
81300 struct generic_pm_domain {
81301diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81302index 2a5897a..4f9af63 100644
81303--- a/include/linux/pm_runtime.h
81304+++ b/include/linux/pm_runtime.h
81305@@ -113,7 +113,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81306
81307 static inline void pm_runtime_mark_last_busy(struct device *dev)
81308 {
81309- ACCESS_ONCE(dev->power.last_busy) = jiffies;
81310+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81311 }
81312
81313 #else /* !CONFIG_PM_RUNTIME */
81314diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81315index 195aafc..49a7bc2 100644
81316--- a/include/linux/pnp.h
81317+++ b/include/linux/pnp.h
81318@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81319 struct pnp_fixup {
81320 char id[7];
81321 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81322-};
81323+} __do_const;
81324
81325 /* config parameters */
81326 #define PNP_CONFIG_NORMAL 0x0001
81327diff --git a/include/linux/poison.h b/include/linux/poison.h
81328index 2110a81..13a11bb 100644
81329--- a/include/linux/poison.h
81330+++ b/include/linux/poison.h
81331@@ -19,8 +19,8 @@
81332 * under normal circumstances, used to verify that nobody uses
81333 * non-initialized list entries.
81334 */
81335-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81336-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81337+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81338+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81339
81340 /********** include/linux/timer.h **********/
81341 /*
81342diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81343index d8b187c3..9a9257a 100644
81344--- a/include/linux/power/smartreflex.h
81345+++ b/include/linux/power/smartreflex.h
81346@@ -238,7 +238,7 @@ struct omap_sr_class_data {
81347 int (*notify)(struct omap_sr *sr, u32 status);
81348 u8 notify_flags;
81349 u8 class_type;
81350-};
81351+} __do_const;
81352
81353 /**
81354 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81355diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81356index 4ea1d37..80f4b33 100644
81357--- a/include/linux/ppp-comp.h
81358+++ b/include/linux/ppp-comp.h
81359@@ -84,7 +84,7 @@ struct compressor {
81360 struct module *owner;
81361 /* Extra skb space needed by the compressor algorithm */
81362 unsigned int comp_extra;
81363-};
81364+} __do_const;
81365
81366 /*
81367 * The return value from decompress routine is the length of the
81368diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81369index de83b4e..c4b997d 100644
81370--- a/include/linux/preempt.h
81371+++ b/include/linux/preempt.h
81372@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81373 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81374 #endif
81375
81376+#define raw_preempt_count_add(val) __preempt_count_add(val)
81377+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81378+
81379 #define __preempt_count_inc() __preempt_count_add(1)
81380 #define __preempt_count_dec() __preempt_count_sub(1)
81381
81382 #define preempt_count_inc() preempt_count_add(1)
81383+#define raw_preempt_count_inc() raw_preempt_count_add(1)
81384 #define preempt_count_dec() preempt_count_sub(1)
81385+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81386
81387 #ifdef CONFIG_PREEMPT_COUNT
81388
81389@@ -41,6 +46,12 @@ do { \
81390 barrier(); \
81391 } while (0)
81392
81393+#define raw_preempt_disable() \
81394+do { \
81395+ raw_preempt_count_inc(); \
81396+ barrier(); \
81397+} while (0)
81398+
81399 #define sched_preempt_enable_no_resched() \
81400 do { \
81401 barrier(); \
81402@@ -49,6 +60,12 @@ do { \
81403
81404 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81405
81406+#define raw_preempt_enable_no_resched() \
81407+do { \
81408+ barrier(); \
81409+ raw_preempt_count_dec(); \
81410+} while (0)
81411+
81412 #ifdef CONFIG_PREEMPT
81413 #define preempt_enable() \
81414 do { \
81415@@ -113,8 +130,10 @@ do { \
81416 * region.
81417 */
81418 #define preempt_disable() barrier()
81419+#define raw_preempt_disable() barrier()
81420 #define sched_preempt_enable_no_resched() barrier()
81421 #define preempt_enable_no_resched() barrier()
81422+#define raw_preempt_enable_no_resched() barrier()
81423 #define preempt_enable() barrier()
81424 #define preempt_check_resched() do { } while (0)
81425
81426@@ -128,11 +147,13 @@ do { \
81427 /*
81428 * Modules have no business playing preemption tricks.
81429 */
81430+#ifndef CONFIG_PAX_KERNEXEC
81431 #undef sched_preempt_enable_no_resched
81432 #undef preempt_enable_no_resched
81433 #undef preempt_enable_no_resched_notrace
81434 #undef preempt_check_resched
81435 #endif
81436+#endif
81437
81438 #define preempt_set_need_resched() \
81439 do { \
81440diff --git a/include/linux/printk.h b/include/linux/printk.h
81441index 8752f75..2b80c0f 100644
81442--- a/include/linux/printk.h
81443+++ b/include/linux/printk.h
81444@@ -110,6 +110,8 @@ static inline __printf(1, 2) __cold
81445 void early_printk(const char *s, ...) { }
81446 #endif
81447
81448+extern int kptr_restrict;
81449+
81450 #ifdef CONFIG_PRINTK
81451 asmlinkage __printf(5, 0)
81452 int vprintk_emit(int facility, int level,
81453@@ -144,7 +146,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81454
81455 extern int printk_delay_msec;
81456 extern int dmesg_restrict;
81457-extern int kptr_restrict;
81458
81459 extern void wake_up_klogd(void);
81460
81461diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81462index 608e60a..79cfb18 100644
81463--- a/include/linux/proc_fs.h
81464+++ b/include/linux/proc_fs.h
81465@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81466 extern struct proc_dir_entry *proc_symlink(const char *,
81467 struct proc_dir_entry *, const char *);
81468 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81469+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81470 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81471 struct proc_dir_entry *, void *);
81472+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81473+ struct proc_dir_entry *, void *);
81474 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81475 struct proc_dir_entry *);
81476
81477@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81478 return proc_create_data(name, mode, parent, proc_fops, NULL);
81479 }
81480
81481+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81482+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81483+{
81484+#ifdef CONFIG_GRKERNSEC_PROC_USER
81485+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81486+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81487+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81488+#else
81489+ return proc_create_data(name, mode, parent, proc_fops, NULL);
81490+#endif
81491+}
81492+
81493+
81494 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81495 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81496 extern void *PDE_DATA(const struct inode *);
81497@@ -52,8 +68,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
81498 struct proc_dir_entry *parent,const char *dest) { return NULL;}
81499 static inline struct proc_dir_entry *proc_mkdir(const char *name,
81500 struct proc_dir_entry *parent) {return NULL;}
81501+static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
81502+ struct proc_dir_entry *parent) { return NULL; }
81503 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
81504 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81505+static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
81506+ umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81507 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
81508 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
81509 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
81510@@ -73,7 +93,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81511 static inline struct proc_dir_entry *proc_net_mkdir(
81512 struct net *net, const char *name, struct proc_dir_entry *parent)
81513 {
81514- return proc_mkdir_data(name, 0, parent, net);
81515+ return proc_mkdir_data_restrict(name, 0, parent, net);
81516 }
81517
81518 #endif /* _LINUX_PROC_FS_H */
81519diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81520index 34a1e10..70f6bde 100644
81521--- a/include/linux/proc_ns.h
81522+++ b/include/linux/proc_ns.h
81523@@ -14,7 +14,7 @@ struct proc_ns_operations {
81524 void (*put)(void *ns);
81525 int (*install)(struct nsproxy *nsproxy, void *ns);
81526 unsigned int (*inum)(void *ns);
81527-};
81528+} __do_const __randomize_layout;
81529
81530 struct proc_ns {
81531 void *ns;
81532diff --git a/include/linux/quota.h b/include/linux/quota.h
81533index cc7494a..1e27036 100644
81534--- a/include/linux/quota.h
81535+++ b/include/linux/quota.h
81536@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81537
81538 extern bool qid_eq(struct kqid left, struct kqid right);
81539 extern bool qid_lt(struct kqid left, struct kqid right);
81540-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81541+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81542 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81543 extern bool qid_valid(struct kqid qid);
81544
81545diff --git a/include/linux/random.h b/include/linux/random.h
81546index 57fbbff..2331f3f 100644
81547--- a/include/linux/random.h
81548+++ b/include/linux/random.h
81549@@ -9,9 +9,19 @@
81550 #include <uapi/linux/random.h>
81551
81552 extern void add_device_randomness(const void *, unsigned int);
81553+
81554+static inline void add_latent_entropy(void)
81555+{
81556+
81557+#ifdef LATENT_ENTROPY_PLUGIN
81558+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81559+#endif
81560+
81561+}
81562+
81563 extern void add_input_randomness(unsigned int type, unsigned int code,
81564- unsigned int value);
81565-extern void add_interrupt_randomness(int irq, int irq_flags);
81566+ unsigned int value) __latent_entropy;
81567+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81568
81569 extern void get_random_bytes(void *buf, int nbytes);
81570 extern void get_random_bytes_arch(void *buf, int nbytes);
81571@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
81572 extern const struct file_operations random_fops, urandom_fops;
81573 #endif
81574
81575-unsigned int get_random_int(void);
81576+unsigned int __intentional_overflow(-1) get_random_int(void);
81577 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81578
81579-u32 prandom_u32(void);
81580+u32 prandom_u32(void) __intentional_overflow(-1);
81581 void prandom_bytes(void *buf, int nbytes);
81582 void prandom_seed(u32 seed);
81583 void prandom_reseed_late(void);
81584@@ -37,6 +47,11 @@ struct rnd_state {
81585 u32 prandom_u32_state(struct rnd_state *state);
81586 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81587
81588+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81589+{
81590+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81591+}
81592+
81593 /**
81594 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
81595 * @ep_ro: right open interval endpoint
81596diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81597index fea49b5..2ac22bb 100644
81598--- a/include/linux/rbtree_augmented.h
81599+++ b/include/linux/rbtree_augmented.h
81600@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81601 old->rbaugmented = rbcompute(old); \
81602 } \
81603 rbstatic const struct rb_augment_callbacks rbname = { \
81604- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81605+ .propagate = rbname ## _propagate, \
81606+ .copy = rbname ## _copy, \
81607+ .rotate = rbname ## _rotate \
81608 };
81609
81610
81611diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81612index 8183b46..a388711 100644
81613--- a/include/linux/rculist.h
81614+++ b/include/linux/rculist.h
81615@@ -29,8 +29,8 @@
81616 */
81617 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81618 {
81619- ACCESS_ONCE(list->next) = list;
81620- ACCESS_ONCE(list->prev) = list;
81621+ ACCESS_ONCE_RW(list->next) = list;
81622+ ACCESS_ONCE_RW(list->prev) = list;
81623 }
81624
81625 /*
81626@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
81627 struct list_head *prev, struct list_head *next);
81628 #endif
81629
81630+void __pax_list_add_rcu(struct list_head *new,
81631+ struct list_head *prev, struct list_head *next);
81632+
81633 /**
81634 * list_add_rcu - add a new entry to rcu-protected list
81635 * @new: new entry to be added
81636@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81637 __list_add_rcu(new, head, head->next);
81638 }
81639
81640+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81641+{
81642+ __pax_list_add_rcu(new, head, head->next);
81643+}
81644+
81645 /**
81646 * list_add_tail_rcu - add a new entry to rcu-protected list
81647 * @new: new entry to be added
81648@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81649 __list_add_rcu(new, head->prev, head);
81650 }
81651
81652+static inline void pax_list_add_tail_rcu(struct list_head *new,
81653+ struct list_head *head)
81654+{
81655+ __pax_list_add_rcu(new, head->prev, head);
81656+}
81657+
81658 /**
81659 * list_del_rcu - deletes entry from list without re-initialization
81660 * @entry: the element to delete from the list.
81661@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81662 entry->prev = LIST_POISON2;
81663 }
81664
81665+extern void pax_list_del_rcu(struct list_head *entry);
81666+
81667 /**
81668 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81669 * @n: the element to delete from the hash list.
81670diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81671index 48bf152..d38b785 100644
81672--- a/include/linux/reboot.h
81673+++ b/include/linux/reboot.h
81674@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81675 */
81676
81677 extern void migrate_to_reboot_cpu(void);
81678-extern void machine_restart(char *cmd);
81679-extern void machine_halt(void);
81680-extern void machine_power_off(void);
81681+extern void machine_restart(char *cmd) __noreturn;
81682+extern void machine_halt(void) __noreturn;
81683+extern void machine_power_off(void) __noreturn;
81684
81685 extern void machine_shutdown(void);
81686 struct pt_regs;
81687@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81688 */
81689
81690 extern void kernel_restart_prepare(char *cmd);
81691-extern void kernel_restart(char *cmd);
81692-extern void kernel_halt(void);
81693-extern void kernel_power_off(void);
81694+extern void kernel_restart(char *cmd) __noreturn;
81695+extern void kernel_halt(void) __noreturn;
81696+extern void kernel_power_off(void) __noreturn;
81697
81698 extern int C_A_D; /* for sysctl */
81699 void ctrl_alt_del(void);
81700@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81701 * Emergency restart, callable from an interrupt handler.
81702 */
81703
81704-extern void emergency_restart(void);
81705+extern void emergency_restart(void) __noreturn;
81706 #include <asm/emergency-restart.h>
81707
81708 #endif /* _LINUX_REBOOT_H */
81709diff --git a/include/linux/regset.h b/include/linux/regset.h
81710index 8e0c9fe..ac4d221 100644
81711--- a/include/linux/regset.h
81712+++ b/include/linux/regset.h
81713@@ -161,7 +161,8 @@ struct user_regset {
81714 unsigned int align;
81715 unsigned int bias;
81716 unsigned int core_note_type;
81717-};
81718+} __do_const;
81719+typedef struct user_regset __no_const user_regset_no_const;
81720
81721 /**
81722 * struct user_regset_view - available regsets
81723diff --git a/include/linux/relay.h b/include/linux/relay.h
81724index d7c8359..818daf5 100644
81725--- a/include/linux/relay.h
81726+++ b/include/linux/relay.h
81727@@ -157,7 +157,7 @@ struct rchan_callbacks
81728 * The callback should return 0 if successful, negative if not.
81729 */
81730 int (*remove_buf_file)(struct dentry *dentry);
81731-};
81732+} __no_const;
81733
81734 /*
81735 * CONFIG_RELAY kernel API, kernel/relay.c
81736diff --git a/include/linux/rio.h b/include/linux/rio.h
81737index 6bda06f..bf39a9b 100644
81738--- a/include/linux/rio.h
81739+++ b/include/linux/rio.h
81740@@ -358,7 +358,7 @@ struct rio_ops {
81741 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81742 u64 rstart, u32 size, u32 flags);
81743 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81744-};
81745+} __no_const;
81746
81747 #define RIO_RESOURCE_MEM 0x00000100
81748 #define RIO_RESOURCE_DOORBELL 0x00000200
81749diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81750index b66c211..13d2915 100644
81751--- a/include/linux/rmap.h
81752+++ b/include/linux/rmap.h
81753@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81754 void anon_vma_init(void); /* create anon_vma_cachep */
81755 int anon_vma_prepare(struct vm_area_struct *);
81756 void unlink_anon_vmas(struct vm_area_struct *);
81757-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81758-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81759+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81760+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81761
81762 static inline void anon_vma_merge(struct vm_area_struct *vma,
81763 struct vm_area_struct *next)
81764diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
81765index a964f72..b475afb 100644
81766--- a/include/linux/scatterlist.h
81767+++ b/include/linux/scatterlist.h
81768@@ -1,6 +1,7 @@
81769 #ifndef _LINUX_SCATTERLIST_H
81770 #define _LINUX_SCATTERLIST_H
81771
81772+#include <linux/sched.h>
81773 #include <linux/string.h>
81774 #include <linux/bug.h>
81775 #include <linux/mm.h>
81776@@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
81777 #ifdef CONFIG_DEBUG_SG
81778 BUG_ON(!virt_addr_valid(buf));
81779 #endif
81780+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
81781+ if (object_starts_on_stack(buf)) {
81782+ void *adjbuf = buf - current->stack + current->lowmem_stack;
81783+ sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
81784+ } else
81785+#endif
81786 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
81787 }
81788
81789diff --git a/include/linux/sched.h b/include/linux/sched.h
81790index 221b2bd..e2e5f82 100644
81791--- a/include/linux/sched.h
81792+++ b/include/linux/sched.h
81793@@ -131,6 +131,7 @@ struct fs_struct;
81794 struct perf_event_context;
81795 struct blk_plug;
81796 struct filename;
81797+struct linux_binprm;
81798
81799 #define VMACACHE_BITS 2
81800 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
81801@@ -380,7 +381,7 @@ extern char __sched_text_start[], __sched_text_end[];
81802 extern int in_sched_functions(unsigned long addr);
81803
81804 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81805-extern signed long schedule_timeout(signed long timeout);
81806+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81807 extern signed long schedule_timeout_interruptible(signed long timeout);
81808 extern signed long schedule_timeout_killable(signed long timeout);
81809 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81810@@ -391,6 +392,19 @@ struct nsproxy;
81811 struct user_namespace;
81812
81813 #ifdef CONFIG_MMU
81814+
81815+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81816+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81817+#else
81818+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81819+{
81820+ return 0;
81821+}
81822+#endif
81823+
81824+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81825+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81826+
81827 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81828 extern unsigned long
81829 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81830@@ -688,6 +702,17 @@ struct signal_struct {
81831 #ifdef CONFIG_TASKSTATS
81832 struct taskstats *stats;
81833 #endif
81834+
81835+#ifdef CONFIG_GRKERNSEC
81836+ u32 curr_ip;
81837+ u32 saved_ip;
81838+ u32 gr_saddr;
81839+ u32 gr_daddr;
81840+ u16 gr_sport;
81841+ u16 gr_dport;
81842+ u8 used_accept:1;
81843+#endif
81844+
81845 #ifdef CONFIG_AUDIT
81846 unsigned audit_tty;
81847 unsigned audit_tty_log_passwd;
81848@@ -714,7 +739,7 @@ struct signal_struct {
81849 struct mutex cred_guard_mutex; /* guard against foreign influences on
81850 * credential calculations
81851 * (notably. ptrace) */
81852-};
81853+} __randomize_layout;
81854
81855 /*
81856 * Bits in flags field of signal_struct.
81857@@ -768,6 +793,14 @@ struct user_struct {
81858 struct key *session_keyring; /* UID's default session keyring */
81859 #endif
81860
81861+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81862+ unsigned char kernel_banned;
81863+#endif
81864+#ifdef CONFIG_GRKERNSEC_BRUTE
81865+ unsigned char suid_banned;
81866+ unsigned long suid_ban_expires;
81867+#endif
81868+
81869 /* Hash table maintenance information */
81870 struct hlist_node uidhash_node;
81871 kuid_t uid;
81872@@ -775,7 +808,7 @@ struct user_struct {
81873 #ifdef CONFIG_PERF_EVENTS
81874 atomic_long_t locked_vm;
81875 #endif
81876-};
81877+} __randomize_layout;
81878
81879 extern int uids_sysfs_init(void);
81880
81881@@ -1179,6 +1212,9 @@ enum perf_event_task_context {
81882 struct task_struct {
81883 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
81884 void *stack;
81885+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
81886+ void *lowmem_stack;
81887+#endif
81888 atomic_t usage;
81889 unsigned int flags; /* per process flags, defined below */
81890 unsigned int ptrace;
81891@@ -1304,8 +1340,8 @@ struct task_struct {
81892 struct list_head thread_node;
81893
81894 struct completion *vfork_done; /* for vfork() */
81895- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81896- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81897+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81898+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81899
81900 cputime_t utime, stime, utimescaled, stimescaled;
81901 cputime_t gtime;
81902@@ -1330,11 +1366,6 @@ struct task_struct {
81903 struct task_cputime cputime_expires;
81904 struct list_head cpu_timers[3];
81905
81906-/* process credentials */
81907- const struct cred __rcu *real_cred; /* objective and real subjective task
81908- * credentials (COW) */
81909- const struct cred __rcu *cred; /* effective (overridable) subjective task
81910- * credentials (COW) */
81911 char comm[TASK_COMM_LEN]; /* executable name excluding path
81912 - access with [gs]et_task_comm (which lock
81913 it with task_lock())
81914@@ -1351,6 +1382,10 @@ struct task_struct {
81915 #endif
81916 /* CPU-specific state of this task */
81917 struct thread_struct thread;
81918+/* thread_info moved to task_struct */
81919+#ifdef CONFIG_X86
81920+ struct thread_info tinfo;
81921+#endif
81922 /* filesystem information */
81923 struct fs_struct *fs;
81924 /* open file information */
81925@@ -1427,6 +1462,10 @@ struct task_struct {
81926 gfp_t lockdep_reclaim_gfp;
81927 #endif
81928
81929+/* process credentials */
81930+ const struct cred __rcu *real_cred; /* objective and real subjective task
81931+ * credentials (COW) */
81932+
81933 /* journalling filesystem info */
81934 void *journal_info;
81935
81936@@ -1465,6 +1504,10 @@ struct task_struct {
81937 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81938 struct list_head cg_list;
81939 #endif
81940+
81941+ const struct cred __rcu *cred; /* effective (overridable) subjective task
81942+ * credentials (COW) */
81943+
81944 #ifdef CONFIG_FUTEX
81945 struct robust_list_head __user *robust_list;
81946 #ifdef CONFIG_COMPAT
81947@@ -1610,7 +1653,78 @@ struct task_struct {
81948 unsigned int sequential_io;
81949 unsigned int sequential_io_avg;
81950 #endif
81951-};
81952+
81953+#ifdef CONFIG_GRKERNSEC
81954+ /* grsecurity */
81955+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81956+ u64 exec_id;
81957+#endif
81958+#ifdef CONFIG_GRKERNSEC_SETXID
81959+ const struct cred *delayed_cred;
81960+#endif
81961+ struct dentry *gr_chroot_dentry;
81962+ struct acl_subject_label *acl;
81963+ struct acl_subject_label *tmpacl;
81964+ struct acl_role_label *role;
81965+ struct file *exec_file;
81966+ unsigned long brute_expires;
81967+ u16 acl_role_id;
81968+ u8 inherited;
81969+ /* is this the task that authenticated to the special role */
81970+ u8 acl_sp_role;
81971+ u8 is_writable;
81972+ u8 brute;
81973+ u8 gr_is_chrooted;
81974+#endif
81975+
81976+} __randomize_layout;
81977+
81978+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
81979+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
81980+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
81981+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
81982+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
81983+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
81984+
81985+#ifdef CONFIG_PAX_SOFTMODE
81986+extern int pax_softmode;
81987+#endif
81988+
81989+extern int pax_check_flags(unsigned long *);
81990+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
81991+
81992+/* if tsk != current then task_lock must be held on it */
81993+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81994+static inline unsigned long pax_get_flags(struct task_struct *tsk)
81995+{
81996+ if (likely(tsk->mm))
81997+ return tsk->mm->pax_flags;
81998+ else
81999+ return 0UL;
82000+}
82001+
82002+/* if tsk != current then task_lock must be held on it */
82003+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
82004+{
82005+ if (likely(tsk->mm)) {
82006+ tsk->mm->pax_flags = flags;
82007+ return 0;
82008+ }
82009+ return -EINVAL;
82010+}
82011+#endif
82012+
82013+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
82014+extern void pax_set_initial_flags(struct linux_binprm *bprm);
82015+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
82016+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
82017+#endif
82018+
82019+struct path;
82020+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
82021+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
82022+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
82023+extern void pax_report_refcount_overflow(struct pt_regs *regs);
82024
82025 /* Future-safe accessor for struct task_struct's cpus_allowed. */
82026 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
82027@@ -1692,7 +1806,7 @@ struct pid_namespace;
82028 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
82029 struct pid_namespace *ns);
82030
82031-static inline pid_t task_pid_nr(struct task_struct *tsk)
82032+static inline pid_t task_pid_nr(const struct task_struct *tsk)
82033 {
82034 return tsk->pid;
82035 }
82036@@ -2039,6 +2153,25 @@ extern u64 sched_clock_cpu(int cpu);
82037
82038 extern void sched_clock_init(void);
82039
82040+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82041+static inline void populate_stack(void)
82042+{
82043+ struct task_struct *curtask = current;
82044+ int c;
82045+ int *ptr = curtask->stack;
82046+ int *end = curtask->stack + THREAD_SIZE;
82047+
82048+ while (ptr < end) {
82049+ c = *(volatile int *)ptr;
82050+ ptr += PAGE_SIZE/sizeof(int);
82051+ }
82052+}
82053+#else
82054+static inline void populate_stack(void)
82055+{
82056+}
82057+#endif
82058+
82059 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
82060 static inline void sched_clock_tick(void)
82061 {
82062@@ -2172,7 +2305,9 @@ void yield(void);
82063 extern struct exec_domain default_exec_domain;
82064
82065 union thread_union {
82066+#ifndef CONFIG_X86
82067 struct thread_info thread_info;
82068+#endif
82069 unsigned long stack[THREAD_SIZE/sizeof(long)];
82070 };
82071
82072@@ -2205,6 +2340,7 @@ extern struct pid_namespace init_pid_ns;
82073 */
82074
82075 extern struct task_struct *find_task_by_vpid(pid_t nr);
82076+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82077 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82078 struct pid_namespace *ns);
82079
82080@@ -2367,7 +2503,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82081 extern void exit_itimers(struct signal_struct *);
82082 extern void flush_itimer_signals(void);
82083
82084-extern void do_group_exit(int);
82085+extern __noreturn void do_group_exit(int);
82086
82087 extern int allow_signal(int);
82088 extern int disallow_signal(int);
82089@@ -2568,9 +2704,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82090
82091 #endif
82092
82093-static inline int object_is_on_stack(void *obj)
82094+static inline int object_starts_on_stack(const void *obj)
82095 {
82096- void *stack = task_stack_page(current);
82097+ const void *stack = task_stack_page(current);
82098
82099 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82100 }
82101diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82102index 8045a55..c959cd5 100644
82103--- a/include/linux/sched/sysctl.h
82104+++ b/include/linux/sched/sysctl.h
82105@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82106 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82107
82108 extern int sysctl_max_map_count;
82109+extern unsigned long sysctl_heap_stack_gap;
82110
82111 extern unsigned int sysctl_sched_latency;
82112 extern unsigned int sysctl_sched_min_granularity;
82113diff --git a/include/linux/security.h b/include/linux/security.h
82114index 6478ce3..5e6ad6e 100644
82115--- a/include/linux/security.h
82116+++ b/include/linux/security.h
82117@@ -27,6 +27,7 @@
82118 #include <linux/slab.h>
82119 #include <linux/err.h>
82120 #include <linux/string.h>
82121+#include <linux/grsecurity.h>
82122
82123 struct linux_binprm;
82124 struct cred;
82125@@ -116,8 +117,6 @@ struct seq_file;
82126
82127 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82128
82129-void reset_security_ops(void);
82130-
82131 #ifdef CONFIG_MMU
82132 extern unsigned long mmap_min_addr;
82133 extern unsigned long dac_mmap_min_addr;
82134@@ -1719,7 +1718,7 @@ struct security_operations {
82135 struct audit_context *actx);
82136 void (*audit_rule_free) (void *lsmrule);
82137 #endif /* CONFIG_AUDIT */
82138-};
82139+} __randomize_layout;
82140
82141 /* prototypes */
82142 extern int security_init(void);
82143diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82144index dc368b8..e895209 100644
82145--- a/include/linux/semaphore.h
82146+++ b/include/linux/semaphore.h
82147@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82148 }
82149
82150 extern void down(struct semaphore *sem);
82151-extern int __must_check down_interruptible(struct semaphore *sem);
82152+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82153 extern int __must_check down_killable(struct semaphore *sem);
82154 extern int __must_check down_trylock(struct semaphore *sem);
82155 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82156diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82157index 52e0097..383f21d 100644
82158--- a/include/linux/seq_file.h
82159+++ b/include/linux/seq_file.h
82160@@ -27,6 +27,9 @@ struct seq_file {
82161 struct mutex lock;
82162 const struct seq_operations *op;
82163 int poll_event;
82164+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82165+ u64 exec_id;
82166+#endif
82167 #ifdef CONFIG_USER_NS
82168 struct user_namespace *user_ns;
82169 #endif
82170@@ -39,6 +42,7 @@ struct seq_operations {
82171 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82172 int (*show) (struct seq_file *m, void *v);
82173 };
82174+typedef struct seq_operations __no_const seq_operations_no_const;
82175
82176 #define SEQ_SKIP 1
82177
82178@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82179
82180 char *mangle_path(char *s, const char *p, const char *esc);
82181 int seq_open(struct file *, const struct seq_operations *);
82182+int seq_open_restrict(struct file *, const struct seq_operations *);
82183 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82184 loff_t seq_lseek(struct file *, loff_t, int);
82185 int seq_release(struct inode *, struct file *);
82186@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82187 }
82188
82189 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82190+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82191 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82192 int single_release(struct inode *, struct file *);
82193 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82194diff --git a/include/linux/shm.h b/include/linux/shm.h
82195index 1e2cd2e..0288750 100644
82196--- a/include/linux/shm.h
82197+++ b/include/linux/shm.h
82198@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82199
82200 /* The task created the shm object. NULL if the task is dead. */
82201 struct task_struct *shm_creator;
82202+#ifdef CONFIG_GRKERNSEC
82203+ time_t shm_createtime;
82204+ pid_t shm_lapid;
82205+#endif
82206 };
82207
82208 /* shm_mode upper byte flags */
82209diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82210index 08074a8..e2ae280 100644
82211--- a/include/linux/skbuff.h
82212+++ b/include/linux/skbuff.h
82213@@ -717,7 +717,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82214 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82215 int node);
82216 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82217-static inline struct sk_buff *alloc_skb(unsigned int size,
82218+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82219 gfp_t priority)
82220 {
82221 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82222@@ -1825,7 +1825,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82223 return skb->inner_transport_header - skb->inner_network_header;
82224 }
82225
82226-static inline int skb_network_offset(const struct sk_buff *skb)
82227+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82228 {
82229 return skb_network_header(skb) - skb->data;
82230 }
82231@@ -1885,7 +1885,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82232 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82233 */
82234 #ifndef NET_SKB_PAD
82235-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82236+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82237 #endif
82238
82239 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82240@@ -2484,7 +2484,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82241 int *err);
82242 unsigned int datagram_poll(struct file *file, struct socket *sock,
82243 struct poll_table_struct *wait);
82244-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82245+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82246 struct iovec *to, int size);
82247 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82248 struct iovec *iov);
82249@@ -2776,6 +2776,9 @@ static inline void nf_reset(struct sk_buff *skb)
82250 nf_bridge_put(skb->nf_bridge);
82251 skb->nf_bridge = NULL;
82252 #endif
82253+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82254+ skb->nf_trace = 0;
82255+#endif
82256 }
82257
82258 static inline void nf_reset_trace(struct sk_buff *skb)
82259diff --git a/include/linux/slab.h b/include/linux/slab.h
82260index 307bfbe..a999cf3 100644
82261--- a/include/linux/slab.h
82262+++ b/include/linux/slab.h
82263@@ -14,15 +14,29 @@
82264 #include <linux/gfp.h>
82265 #include <linux/types.h>
82266 #include <linux/workqueue.h>
82267-
82268+#include <linux/err.h>
82269
82270 /*
82271 * Flags to pass to kmem_cache_create().
82272 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82273 */
82274 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82275+
82276+#ifdef CONFIG_PAX_USERCOPY_SLABS
82277+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82278+#else
82279+#define SLAB_USERCOPY 0x00000000UL
82280+#endif
82281+
82282 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82283 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82284+
82285+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82286+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82287+#else
82288+#define SLAB_NO_SANITIZE 0x00000000UL
82289+#endif
82290+
82291 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82292 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82293 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82294@@ -98,10 +112,13 @@
82295 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82296 * Both make kfree a no-op.
82297 */
82298-#define ZERO_SIZE_PTR ((void *)16)
82299+#define ZERO_SIZE_PTR \
82300+({ \
82301+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82302+ (void *)(-MAX_ERRNO-1L); \
82303+})
82304
82305-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82306- (unsigned long)ZERO_SIZE_PTR)
82307+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82308
82309 #include <linux/kmemleak.h>
82310
82311@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82312 void kfree(const void *);
82313 void kzfree(const void *);
82314 size_t ksize(const void *);
82315+const char *check_heap_object(const void *ptr, unsigned long n);
82316+bool is_usercopy_object(const void *ptr);
82317
82318 /*
82319 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82320@@ -174,7 +193,7 @@ struct kmem_cache {
82321 unsigned int align; /* Alignment as calculated */
82322 unsigned long flags; /* Active flags on the slab */
82323 const char *name; /* Slab name for sysfs */
82324- int refcount; /* Use counter */
82325+ atomic_t refcount; /* Use counter */
82326 void (*ctor)(void *); /* Called on object slot creation */
82327 struct list_head list; /* List of all slab caches on the system */
82328 };
82329@@ -259,6 +278,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82330 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82331 #endif
82332
82333+#ifdef CONFIG_PAX_USERCOPY_SLABS
82334+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82335+#endif
82336+
82337 /*
82338 * Figure out which kmalloc slab an allocation of a certain size
82339 * belongs to.
82340@@ -267,7 +290,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82341 * 2 = 120 .. 192 bytes
82342 * n = 2^(n-1) .. 2^n -1
82343 */
82344-static __always_inline int kmalloc_index(size_t size)
82345+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82346 {
82347 if (!size)
82348 return 0;
82349@@ -310,11 +333,11 @@ static __always_inline int kmalloc_index(size_t size)
82350 }
82351 #endif /* !CONFIG_SLOB */
82352
82353-void *__kmalloc(size_t size, gfp_t flags);
82354+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82355 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82356
82357 #ifdef CONFIG_NUMA
82358-void *__kmalloc_node(size_t size, gfp_t flags, int node);
82359+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82360 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82361 #else
82362 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82363diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82364index 8235dfb..47ce586 100644
82365--- a/include/linux/slab_def.h
82366+++ b/include/linux/slab_def.h
82367@@ -38,7 +38,7 @@ struct kmem_cache {
82368 /* 4) cache creation/removal */
82369 const char *name;
82370 struct list_head list;
82371- int refcount;
82372+ atomic_t refcount;
82373 int object_size;
82374 int align;
82375
82376@@ -54,10 +54,14 @@ struct kmem_cache {
82377 unsigned long node_allocs;
82378 unsigned long node_frees;
82379 unsigned long node_overflow;
82380- atomic_t allochit;
82381- atomic_t allocmiss;
82382- atomic_t freehit;
82383- atomic_t freemiss;
82384+ atomic_unchecked_t allochit;
82385+ atomic_unchecked_t allocmiss;
82386+ atomic_unchecked_t freehit;
82387+ atomic_unchecked_t freemiss;
82388+#ifdef CONFIG_PAX_MEMORY_SANITIZE
82389+ atomic_unchecked_t sanitized;
82390+ atomic_unchecked_t not_sanitized;
82391+#endif
82392
82393 /*
82394 * If debugging is enabled, then the allocator can add additional
82395diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82396index d82abd4..408c3a0 100644
82397--- a/include/linux/slub_def.h
82398+++ b/include/linux/slub_def.h
82399@@ -74,7 +74,7 @@ struct kmem_cache {
82400 struct kmem_cache_order_objects max;
82401 struct kmem_cache_order_objects min;
82402 gfp_t allocflags; /* gfp flags to use on each alloc */
82403- int refcount; /* Refcount for slab cache destroy */
82404+ atomic_t refcount; /* Refcount for slab cache destroy */
82405 void (*ctor)(void *);
82406 int inuse; /* Offset to metadata */
82407 int align; /* Alignment */
82408diff --git a/include/linux/smp.h b/include/linux/smp.h
82409index 633f5ed..6c3dc3f 100644
82410--- a/include/linux/smp.h
82411+++ b/include/linux/smp.h
82412@@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
82413 #endif
82414
82415 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82416+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82417 #define put_cpu() preempt_enable()
82418+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82419
82420 /*
82421 * Callback to arch code if there's nosmp or maxcpus=0 on the
82422diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82423index 46cca4c..3323536 100644
82424--- a/include/linux/sock_diag.h
82425+++ b/include/linux/sock_diag.h
82426@@ -11,7 +11,7 @@ struct sock;
82427 struct sock_diag_handler {
82428 __u8 family;
82429 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82430-};
82431+} __do_const;
82432
82433 int sock_diag_register(const struct sock_diag_handler *h);
82434 void sock_diag_unregister(const struct sock_diag_handler *h);
82435diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82436index 680f9a3..f13aeb0 100644
82437--- a/include/linux/sonet.h
82438+++ b/include/linux/sonet.h
82439@@ -7,7 +7,7 @@
82440 #include <uapi/linux/sonet.h>
82441
82442 struct k_sonet_stats {
82443-#define __HANDLE_ITEM(i) atomic_t i
82444+#define __HANDLE_ITEM(i) atomic_unchecked_t i
82445 __SONET_ITEMS
82446 #undef __HANDLE_ITEM
82447 };
82448diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82449index 07d8e53..dc934c9 100644
82450--- a/include/linux/sunrpc/addr.h
82451+++ b/include/linux/sunrpc/addr.h
82452@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82453 {
82454 switch (sap->sa_family) {
82455 case AF_INET:
82456- return ntohs(((struct sockaddr_in *)sap)->sin_port);
82457+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82458 case AF_INET6:
82459- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82460+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82461 }
82462 return 0;
82463 }
82464@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82465 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82466 const struct sockaddr *src)
82467 {
82468- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82469+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82470 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82471
82472 dsin->sin_family = ssin->sin_family;
82473@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82474 if (sa->sa_family != AF_INET6)
82475 return 0;
82476
82477- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82478+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82479 }
82480
82481 #endif /* _LINUX_SUNRPC_ADDR_H */
82482diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82483index 70736b9..37f33db 100644
82484--- a/include/linux/sunrpc/clnt.h
82485+++ b/include/linux/sunrpc/clnt.h
82486@@ -97,7 +97,7 @@ struct rpc_procinfo {
82487 unsigned int p_timer; /* Which RTT timer to use */
82488 u32 p_statidx; /* Which procedure to account */
82489 const char * p_name; /* name of procedure */
82490-};
82491+} __do_const;
82492
82493 #ifdef __KERNEL__
82494
82495diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82496index 04e7632..2e2a8a3 100644
82497--- a/include/linux/sunrpc/svc.h
82498+++ b/include/linux/sunrpc/svc.h
82499@@ -412,7 +412,7 @@ struct svc_procedure {
82500 unsigned int pc_count; /* call count */
82501 unsigned int pc_cachetype; /* cache info (NFS) */
82502 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82503-};
82504+} __do_const;
82505
82506 /*
82507 * Function prototypes.
82508diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82509index 0b8e3e6..33e0a01 100644
82510--- a/include/linux/sunrpc/svc_rdma.h
82511+++ b/include/linux/sunrpc/svc_rdma.h
82512@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82513 extern unsigned int svcrdma_max_requests;
82514 extern unsigned int svcrdma_max_req_size;
82515
82516-extern atomic_t rdma_stat_recv;
82517-extern atomic_t rdma_stat_read;
82518-extern atomic_t rdma_stat_write;
82519-extern atomic_t rdma_stat_sq_starve;
82520-extern atomic_t rdma_stat_rq_starve;
82521-extern atomic_t rdma_stat_rq_poll;
82522-extern atomic_t rdma_stat_rq_prod;
82523-extern atomic_t rdma_stat_sq_poll;
82524-extern atomic_t rdma_stat_sq_prod;
82525+extern atomic_unchecked_t rdma_stat_recv;
82526+extern atomic_unchecked_t rdma_stat_read;
82527+extern atomic_unchecked_t rdma_stat_write;
82528+extern atomic_unchecked_t rdma_stat_sq_starve;
82529+extern atomic_unchecked_t rdma_stat_rq_starve;
82530+extern atomic_unchecked_t rdma_stat_rq_poll;
82531+extern atomic_unchecked_t rdma_stat_rq_prod;
82532+extern atomic_unchecked_t rdma_stat_sq_poll;
82533+extern atomic_unchecked_t rdma_stat_sq_prod;
82534
82535 #define RPCRDMA_VERSION 1
82536
82537diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82538index 8d71d65..f79586e 100644
82539--- a/include/linux/sunrpc/svcauth.h
82540+++ b/include/linux/sunrpc/svcauth.h
82541@@ -120,7 +120,7 @@ struct auth_ops {
82542 int (*release)(struct svc_rqst *rq);
82543 void (*domain_release)(struct auth_domain *);
82544 int (*set_client)(struct svc_rqst *rq);
82545-};
82546+} __do_const;
82547
82548 #define SVC_GARBAGE 1
82549 #define SVC_SYSERR 2
82550diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82551index a5ffd32..0935dea 100644
82552--- a/include/linux/swiotlb.h
82553+++ b/include/linux/swiotlb.h
82554@@ -60,7 +60,8 @@ extern void
82555
82556 extern void
82557 swiotlb_free_coherent(struct device *hwdev, size_t size,
82558- void *vaddr, dma_addr_t dma_handle);
82559+ void *vaddr, dma_addr_t dma_handle,
82560+ struct dma_attrs *attrs);
82561
82562 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82563 unsigned long offset, size_t size,
82564diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82565index a4a0588..752870e 100644
82566--- a/include/linux/syscalls.h
82567+++ b/include/linux/syscalls.h
82568@@ -98,10 +98,16 @@ struct sigaltstack;
82569 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82570
82571 #define __SC_DECL(t, a) t a
82572+#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))
82573 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
82574 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
82575 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82576-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82577+#define __SC_LONG(t, a) __typeof( \
82578+ __builtin_choose_expr( \
82579+ sizeof(t) > sizeof(int), \
82580+ (t) 0, \
82581+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82582+ )) a
82583 #define __SC_CAST(t, a) (t) a
82584 #define __SC_ARGS(t, a) a
82585 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82586@@ -379,11 +385,11 @@ asmlinkage long sys_sync(void);
82587 asmlinkage long sys_fsync(unsigned int fd);
82588 asmlinkage long sys_fdatasync(unsigned int fd);
82589 asmlinkage long sys_bdflush(int func, long data);
82590-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82591- char __user *type, unsigned long flags,
82592+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82593+ const char __user *type, unsigned long flags,
82594 void __user *data);
82595-asmlinkage long sys_umount(char __user *name, int flags);
82596-asmlinkage long sys_oldumount(char __user *name);
82597+asmlinkage long sys_umount(const char __user *name, int flags);
82598+asmlinkage long sys_oldumount(const char __user *name);
82599 asmlinkage long sys_truncate(const char __user *path, long length);
82600 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82601 asmlinkage long sys_stat(const char __user *filename,
82602@@ -595,7 +601,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82603 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82604 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82605 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82606- struct sockaddr __user *, int);
82607+ struct sockaddr __user *, int) __intentional_overflow(0);
82608 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82609 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82610 unsigned int vlen, unsigned flags);
82611diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82612index 27b3b0b..e093dd9 100644
82613--- a/include/linux/syscore_ops.h
82614+++ b/include/linux/syscore_ops.h
82615@@ -16,7 +16,7 @@ struct syscore_ops {
82616 int (*suspend)(void);
82617 void (*resume)(void);
82618 void (*shutdown)(void);
82619-};
82620+} __do_const;
82621
82622 extern void register_syscore_ops(struct syscore_ops *ops);
82623 extern void unregister_syscore_ops(struct syscore_ops *ops);
82624diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82625index 14a8ff2..fa95f3a 100644
82626--- a/include/linux/sysctl.h
82627+++ b/include/linux/sysctl.h
82628@@ -34,13 +34,13 @@ struct ctl_table_root;
82629 struct ctl_table_header;
82630 struct ctl_dir;
82631
82632-typedef struct ctl_table ctl_table;
82633-
82634 typedef int proc_handler (struct ctl_table *ctl, int write,
82635 void __user *buffer, size_t *lenp, loff_t *ppos);
82636
82637 extern int proc_dostring(struct ctl_table *, int,
82638 void __user *, size_t *, loff_t *);
82639+extern int proc_dostring_modpriv(struct ctl_table *, int,
82640+ void __user *, size_t *, loff_t *);
82641 extern int proc_dointvec(struct ctl_table *, int,
82642 void __user *, size_t *, loff_t *);
82643 extern int proc_dointvec_minmax(struct ctl_table *, int,
82644@@ -115,7 +115,9 @@ struct ctl_table
82645 struct ctl_table_poll *poll;
82646 void *extra1;
82647 void *extra2;
82648-};
82649+} __do_const __randomize_layout;
82650+typedef struct ctl_table __no_const ctl_table_no_const;
82651+typedef struct ctl_table ctl_table;
82652
82653 struct ctl_node {
82654 struct rb_node node;
82655diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82656index 5ffaa34..fe3e31c 100644
82657--- a/include/linux/sysfs.h
82658+++ b/include/linux/sysfs.h
82659@@ -34,7 +34,8 @@ struct attribute {
82660 struct lock_class_key *key;
82661 struct lock_class_key skey;
82662 #endif
82663-};
82664+} __do_const;
82665+typedef struct attribute __no_const attribute_no_const;
82666
82667 /**
82668 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82669@@ -63,7 +64,8 @@ struct attribute_group {
82670 struct attribute *, int);
82671 struct attribute **attrs;
82672 struct bin_attribute **bin_attrs;
82673-};
82674+} __do_const;
82675+typedef struct attribute_group __no_const attribute_group_no_const;
82676
82677 /**
82678 * Use these macros to make defining attributes easier. See include/linux/device.h
82679@@ -128,7 +130,8 @@ struct bin_attribute {
82680 char *, loff_t, size_t);
82681 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82682 struct vm_area_struct *vma);
82683-};
82684+} __do_const;
82685+typedef struct bin_attribute __no_const bin_attribute_no_const;
82686
82687 /**
82688 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82689diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82690index 387fa7d..3fcde6b 100644
82691--- a/include/linux/sysrq.h
82692+++ b/include/linux/sysrq.h
82693@@ -16,6 +16,7 @@
82694
82695 #include <linux/errno.h>
82696 #include <linux/types.h>
82697+#include <linux/compiler.h>
82698
82699 /* Possible values of bitmask for enabling sysrq functions */
82700 /* 0x0001 is reserved for enable everything */
82701@@ -33,7 +34,7 @@ struct sysrq_key_op {
82702 char *help_msg;
82703 char *action_msg;
82704 int enable_mask;
82705-};
82706+} __do_const;
82707
82708 #ifdef CONFIG_MAGIC_SYSRQ
82709
82710diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82711index fddbe20..a0e76ab 100644
82712--- a/include/linux/thread_info.h
82713+++ b/include/linux/thread_info.h
82714@@ -161,6 +161,13 @@ static inline bool test_and_clear_restore_sigmask(void)
82715 #error "no set_restore_sigmask() provided and default one won't work"
82716 #endif
82717
82718+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
82719+
82720+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82721+{
82722+ __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
82723+}
82724+
82725 #endif /* __KERNEL__ */
82726
82727 #endif /* _LINUX_THREAD_INFO_H */
82728diff --git a/include/linux/tty.h b/include/linux/tty.h
82729index 1c3316a..ae83b9f 100644
82730--- a/include/linux/tty.h
82731+++ b/include/linux/tty.h
82732@@ -202,7 +202,7 @@ struct tty_port {
82733 const struct tty_port_operations *ops; /* Port operations */
82734 spinlock_t lock; /* Lock protecting tty field */
82735 int blocked_open; /* Waiting to open */
82736- int count; /* Usage count */
82737+ atomic_t count; /* Usage count */
82738 wait_queue_head_t open_wait; /* Open waiters */
82739 wait_queue_head_t close_wait; /* Close waiters */
82740 wait_queue_head_t delta_msr_wait; /* Modem status change */
82741@@ -284,7 +284,7 @@ struct tty_struct {
82742 /* If the tty has a pending do_SAK, queue it here - akpm */
82743 struct work_struct SAK_work;
82744 struct tty_port *port;
82745-};
82746+} __randomize_layout;
82747
82748 /* Each of a tty's open files has private_data pointing to tty_file_private */
82749 struct tty_file_private {
82750@@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
82751 struct tty_struct *tty, struct file *filp);
82752 static inline int tty_port_users(struct tty_port *port)
82753 {
82754- return port->count + port->blocked_open;
82755+ return atomic_read(&port->count) + port->blocked_open;
82756 }
82757
82758 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82759diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82760index 756a609..89db85e 100644
82761--- a/include/linux/tty_driver.h
82762+++ b/include/linux/tty_driver.h
82763@@ -285,7 +285,7 @@ struct tty_operations {
82764 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82765 #endif
82766 const struct file_operations *proc_fops;
82767-};
82768+} __do_const __randomize_layout;
82769
82770 struct tty_driver {
82771 int magic; /* magic number for this structure */
82772@@ -319,7 +319,7 @@ struct tty_driver {
82773
82774 const struct tty_operations *ops;
82775 struct list_head tty_drivers;
82776-};
82777+} __randomize_layout;
82778
82779 extern struct list_head tty_drivers;
82780
82781diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82782index add26da..22c00bef 100644
82783--- a/include/linux/tty_ldisc.h
82784+++ b/include/linux/tty_ldisc.h
82785@@ -212,7 +212,7 @@ struct tty_ldisc_ops {
82786
82787 struct module *owner;
82788
82789- int refcount;
82790+ atomic_t refcount;
82791 };
82792
82793 struct tty_ldisc {
82794diff --git a/include/linux/types.h b/include/linux/types.h
82795index 4d118ba..c3ee9bf 100644
82796--- a/include/linux/types.h
82797+++ b/include/linux/types.h
82798@@ -176,10 +176,26 @@ typedef struct {
82799 int counter;
82800 } atomic_t;
82801
82802+#ifdef CONFIG_PAX_REFCOUNT
82803+typedef struct {
82804+ int counter;
82805+} atomic_unchecked_t;
82806+#else
82807+typedef atomic_t atomic_unchecked_t;
82808+#endif
82809+
82810 #ifdef CONFIG_64BIT
82811 typedef struct {
82812 long counter;
82813 } atomic64_t;
82814+
82815+#ifdef CONFIG_PAX_REFCOUNT
82816+typedef struct {
82817+ long counter;
82818+} atomic64_unchecked_t;
82819+#else
82820+typedef atomic64_t atomic64_unchecked_t;
82821+#endif
82822 #endif
82823
82824 struct list_head {
82825diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
82826index ecd3319..8a36ded 100644
82827--- a/include/linux/uaccess.h
82828+++ b/include/linux/uaccess.h
82829@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
82830 long ret; \
82831 mm_segment_t old_fs = get_fs(); \
82832 \
82833- set_fs(KERNEL_DS); \
82834 pagefault_disable(); \
82835- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
82836- pagefault_enable(); \
82837+ set_fs(KERNEL_DS); \
82838+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
82839 set_fs(old_fs); \
82840+ pagefault_enable(); \
82841 ret; \
82842 })
82843
82844diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
82845index 2d1f9b6..d7a9fce 100644
82846--- a/include/linux/uidgid.h
82847+++ b/include/linux/uidgid.h
82848@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
82849
82850 #endif /* CONFIG_USER_NS */
82851
82852+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
82853+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
82854+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
82855+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
82856+
82857 #endif /* _LINUX_UIDGID_H */
82858diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82859index 99c1b4d..562e6f3 100644
82860--- a/include/linux/unaligned/access_ok.h
82861+++ b/include/linux/unaligned/access_ok.h
82862@@ -4,34 +4,34 @@
82863 #include <linux/kernel.h>
82864 #include <asm/byteorder.h>
82865
82866-static inline u16 get_unaligned_le16(const void *p)
82867+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82868 {
82869- return le16_to_cpup((__le16 *)p);
82870+ return le16_to_cpup((const __le16 *)p);
82871 }
82872
82873-static inline u32 get_unaligned_le32(const void *p)
82874+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82875 {
82876- return le32_to_cpup((__le32 *)p);
82877+ return le32_to_cpup((const __le32 *)p);
82878 }
82879
82880-static inline u64 get_unaligned_le64(const void *p)
82881+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82882 {
82883- return le64_to_cpup((__le64 *)p);
82884+ return le64_to_cpup((const __le64 *)p);
82885 }
82886
82887-static inline u16 get_unaligned_be16(const void *p)
82888+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82889 {
82890- return be16_to_cpup((__be16 *)p);
82891+ return be16_to_cpup((const __be16 *)p);
82892 }
82893
82894-static inline u32 get_unaligned_be32(const void *p)
82895+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82896 {
82897- return be32_to_cpup((__be32 *)p);
82898+ return be32_to_cpup((const __be32 *)p);
82899 }
82900
82901-static inline u64 get_unaligned_be64(const void *p)
82902+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82903 {
82904- return be64_to_cpup((__be64 *)p);
82905+ return be64_to_cpup((const __be64 *)p);
82906 }
82907
82908 static inline void put_unaligned_le16(u16 val, void *p)
82909diff --git a/include/linux/usb.h b/include/linux/usb.h
82910index 6b7ec37..4428419 100644
82911--- a/include/linux/usb.h
82912+++ b/include/linux/usb.h
82913@@ -569,7 +569,7 @@ struct usb_device {
82914 int maxchild;
82915
82916 u32 quirks;
82917- atomic_t urbnum;
82918+ atomic_unchecked_t urbnum;
82919
82920 unsigned long active_duration;
82921
82922@@ -1653,7 +1653,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82923
82924 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82925 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82926- void *data, __u16 size, int timeout);
82927+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
82928 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82929 void *data, int len, int *actual_length, int timeout);
82930 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82931diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82932index e452ba6..78f8e80 100644
82933--- a/include/linux/usb/renesas_usbhs.h
82934+++ b/include/linux/usb/renesas_usbhs.h
82935@@ -39,7 +39,7 @@ enum {
82936 */
82937 struct renesas_usbhs_driver_callback {
82938 int (*notify_hotplug)(struct platform_device *pdev);
82939-};
82940+} __no_const;
82941
82942 /*
82943 * callback functions for platform
82944diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
82945index 4836ba3..603f6ee 100644
82946--- a/include/linux/user_namespace.h
82947+++ b/include/linux/user_namespace.h
82948@@ -33,7 +33,7 @@ struct user_namespace {
82949 struct key *persistent_keyring_register;
82950 struct rw_semaphore persistent_keyring_register_sem;
82951 #endif
82952-};
82953+} __randomize_layout;
82954
82955 extern struct user_namespace init_user_ns;
82956
82957diff --git a/include/linux/utsname.h b/include/linux/utsname.h
82958index 239e277..22a5cf5 100644
82959--- a/include/linux/utsname.h
82960+++ b/include/linux/utsname.h
82961@@ -24,7 +24,7 @@ struct uts_namespace {
82962 struct new_utsname name;
82963 struct user_namespace *user_ns;
82964 unsigned int proc_inum;
82965-};
82966+} __randomize_layout;
82967 extern struct uts_namespace init_uts_ns;
82968
82969 #ifdef CONFIG_UTS_NS
82970diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
82971index 6f8fbcf..4efc177 100644
82972--- a/include/linux/vermagic.h
82973+++ b/include/linux/vermagic.h
82974@@ -25,9 +25,42 @@
82975 #define MODULE_ARCH_VERMAGIC ""
82976 #endif
82977
82978+#ifdef CONFIG_PAX_REFCOUNT
82979+#define MODULE_PAX_REFCOUNT "REFCOUNT "
82980+#else
82981+#define MODULE_PAX_REFCOUNT ""
82982+#endif
82983+
82984+#ifdef CONSTIFY_PLUGIN
82985+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
82986+#else
82987+#define MODULE_CONSTIFY_PLUGIN ""
82988+#endif
82989+
82990+#ifdef STACKLEAK_PLUGIN
82991+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
82992+#else
82993+#define MODULE_STACKLEAK_PLUGIN ""
82994+#endif
82995+
82996+#ifdef RANDSTRUCT_PLUGIN
82997+#include <generated/randomize_layout_hash.h>
82998+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
82999+#else
83000+#define MODULE_RANDSTRUCT_PLUGIN
83001+#endif
83002+
83003+#ifdef CONFIG_GRKERNSEC
83004+#define MODULE_GRSEC "GRSEC "
83005+#else
83006+#define MODULE_GRSEC ""
83007+#endif
83008+
83009 #define VERMAGIC_STRING \
83010 UTS_RELEASE " " \
83011 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
83012 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
83013- MODULE_ARCH_VERMAGIC
83014+ MODULE_ARCH_VERMAGIC \
83015+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
83016+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
83017
83018diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
83019index 502073a..a7de024 100644
83020--- a/include/linux/vga_switcheroo.h
83021+++ b/include/linux/vga_switcheroo.h
83022@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
83023
83024 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
83025
83026-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
83027-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
83028+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
83029+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
83030 #else
83031
83032 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
83033@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
83034
83035 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
83036
83037-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83038-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83039+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83040+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83041
83042 #endif
83043 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
83044diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
83045index 4b8a891..e9a2863 100644
83046--- a/include/linux/vmalloc.h
83047+++ b/include/linux/vmalloc.h
83048@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
83049 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
83050 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
83051 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
83052+
83053+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83054+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
83055+#endif
83056+
83057 /* bits [20..32] reserved for arch specific ioremap internals */
83058
83059 /*
83060@@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
83061 unsigned long flags, pgprot_t prot);
83062 extern void vunmap(const void *addr);
83063
83064+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
83065+extern void unmap_process_stacks(struct task_struct *task);
83066+#endif
83067+
83068 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
83069 unsigned long uaddr, void *kaddr,
83070 unsigned long size);
83071@@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
83072
83073 /* for /dev/kmem */
83074 extern long vread(char *buf, char *addr, unsigned long count);
83075-extern long vwrite(char *buf, char *addr, unsigned long count);
83076+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83077
83078 /*
83079 * Internals. Dont't use..
83080diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83081index 45c9cd1..20bd0bf 100644
83082--- a/include/linux/vmstat.h
83083+++ b/include/linux/vmstat.h
83084@@ -102,18 +102,18 @@ static inline void vm_events_fold_cpu(int cpu)
83085 /*
83086 * Zone based page accounting with per cpu differentials.
83087 */
83088-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83089+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83090
83091 static inline void zone_page_state_add(long x, struct zone *zone,
83092 enum zone_stat_item item)
83093 {
83094- atomic_long_add(x, &zone->vm_stat[item]);
83095- atomic_long_add(x, &vm_stat[item]);
83096+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83097+ atomic_long_add_unchecked(x, &vm_stat[item]);
83098 }
83099
83100-static inline unsigned long global_page_state(enum zone_stat_item item)
83101+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83102 {
83103- long x = atomic_long_read(&vm_stat[item]);
83104+ long x = atomic_long_read_unchecked(&vm_stat[item]);
83105 #ifdef CONFIG_SMP
83106 if (x < 0)
83107 x = 0;
83108@@ -121,10 +121,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83109 return x;
83110 }
83111
83112-static inline unsigned long zone_page_state(struct zone *zone,
83113+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83114 enum zone_stat_item item)
83115 {
83116- long x = atomic_long_read(&zone->vm_stat[item]);
83117+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83118 #ifdef CONFIG_SMP
83119 if (x < 0)
83120 x = 0;
83121@@ -141,7 +141,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83122 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83123 enum zone_stat_item item)
83124 {
83125- long x = atomic_long_read(&zone->vm_stat[item]);
83126+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83127
83128 #ifdef CONFIG_SMP
83129 int cpu;
83130@@ -228,14 +228,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
83131
83132 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83133 {
83134- atomic_long_inc(&zone->vm_stat[item]);
83135- atomic_long_inc(&vm_stat[item]);
83136+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
83137+ atomic_long_inc_unchecked(&vm_stat[item]);
83138 }
83139
83140 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83141 {
83142- atomic_long_dec(&zone->vm_stat[item]);
83143- atomic_long_dec(&vm_stat[item]);
83144+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
83145+ atomic_long_dec_unchecked(&vm_stat[item]);
83146 }
83147
83148 static inline void __inc_zone_page_state(struct page *page,
83149diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83150index 91b0a68..0e9adf6 100644
83151--- a/include/linux/xattr.h
83152+++ b/include/linux/xattr.h
83153@@ -28,7 +28,7 @@ struct xattr_handler {
83154 size_t size, int handler_flags);
83155 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83156 size_t size, int flags, int handler_flags);
83157-};
83158+} __do_const;
83159
83160 struct xattr {
83161 const char *name;
83162@@ -37,6 +37,9 @@ struct xattr {
83163 };
83164
83165 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83166+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83167+ssize_t pax_getxattr(struct dentry *, void *, size_t);
83168+#endif
83169 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83170 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83171 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83172diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83173index 9c5a6b4..09c9438 100644
83174--- a/include/linux/zlib.h
83175+++ b/include/linux/zlib.h
83176@@ -31,6 +31,7 @@
83177 #define _ZLIB_H
83178
83179 #include <linux/zconf.h>
83180+#include <linux/compiler.h>
83181
83182 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83183 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83184@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83185
83186 /* basic functions */
83187
83188-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83189+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83190 /*
83191 Returns the number of bytes that needs to be allocated for a per-
83192 stream workspace with the specified parameters. A pointer to this
83193diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83194index eec6e46..82d5641 100644
83195--- a/include/media/v4l2-dev.h
83196+++ b/include/media/v4l2-dev.h
83197@@ -77,7 +77,7 @@ struct v4l2_file_operations {
83198 int (*mmap) (struct file *, struct vm_area_struct *);
83199 int (*open) (struct file *);
83200 int (*release) (struct file *);
83201-};
83202+} __do_const;
83203
83204 /*
83205 * Newer version of video_device, handled by videodev2.c
83206diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83207index c9b1593..a572459 100644
83208--- a/include/media/v4l2-device.h
83209+++ b/include/media/v4l2-device.h
83210@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83211 this function returns 0. If the name ends with a digit (e.g. cx18),
83212 then the name will be set to cx18-0 since cx180 looks really odd. */
83213 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83214- atomic_t *instance);
83215+ atomic_unchecked_t *instance);
83216
83217 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83218 Since the parent disappears this ensures that v4l2_dev doesn't have an
83219diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83220index d9fa68f..45c88d1 100644
83221--- a/include/net/9p/transport.h
83222+++ b/include/net/9p/transport.h
83223@@ -63,7 +63,7 @@ struct p9_trans_module {
83224 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
83225 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83226 char *, char *, int , int, int, int);
83227-};
83228+} __do_const;
83229
83230 void v9fs_register_trans(struct p9_trans_module *m);
83231 void v9fs_unregister_trans(struct p9_trans_module *m);
83232diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83233index a175ba4..196eb82 100644
83234--- a/include/net/af_unix.h
83235+++ b/include/net/af_unix.h
83236@@ -36,7 +36,7 @@ struct unix_skb_parms {
83237 u32 secid; /* Security ID */
83238 #endif
83239 u32 consumed;
83240-};
83241+} __randomize_layout;
83242
83243 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83244 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83245diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83246index 4abdcb2..945c5cc 100644
83247--- a/include/net/bluetooth/l2cap.h
83248+++ b/include/net/bluetooth/l2cap.h
83249@@ -601,7 +601,7 @@ struct l2cap_ops {
83250 long (*get_sndtimeo) (struct l2cap_chan *chan);
83251 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83252 unsigned long len, int nb);
83253-};
83254+} __do_const;
83255
83256 struct l2cap_conn {
83257 struct hci_conn *hcon;
83258diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83259index f2ae33d..c457cf0 100644
83260--- a/include/net/caif/cfctrl.h
83261+++ b/include/net/caif/cfctrl.h
83262@@ -52,7 +52,7 @@ struct cfctrl_rsp {
83263 void (*radioset_rsp)(void);
83264 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83265 struct cflayer *client_layer);
83266-};
83267+} __no_const;
83268
83269 /* Link Setup Parameters for CAIF-Links. */
83270 struct cfctrl_link_param {
83271@@ -101,8 +101,8 @@ struct cfctrl_request_info {
83272 struct cfctrl {
83273 struct cfsrvl serv;
83274 struct cfctrl_rsp res;
83275- atomic_t req_seq_no;
83276- atomic_t rsp_seq_no;
83277+ atomic_unchecked_t req_seq_no;
83278+ atomic_unchecked_t rsp_seq_no;
83279 struct list_head list;
83280 /* Protects from simultaneous access to first_req list */
83281 spinlock_t info_list_lock;
83282diff --git a/include/net/flow.h b/include/net/flow.h
83283index 8109a15..504466d 100644
83284--- a/include/net/flow.h
83285+++ b/include/net/flow.h
83286@@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
83287
83288 void flow_cache_flush(struct net *net);
83289 void flow_cache_flush_deferred(struct net *net);
83290-extern atomic_t flow_cache_genid;
83291+extern atomic_unchecked_t flow_cache_genid;
83292
83293 #endif
83294diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83295index 93695f0..766d71c 100644
83296--- a/include/net/genetlink.h
83297+++ b/include/net/genetlink.h
83298@@ -120,7 +120,7 @@ struct genl_ops {
83299 u8 cmd;
83300 u8 internal_flags;
83301 u8 flags;
83302-};
83303+} __do_const;
83304
83305 int __genl_register_family(struct genl_family *family);
83306
83307diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83308index 734d9b5..48a9a4b 100644
83309--- a/include/net/gro_cells.h
83310+++ b/include/net/gro_cells.h
83311@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83312 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83313
83314 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83315- atomic_long_inc(&dev->rx_dropped);
83316+ atomic_long_inc_unchecked(&dev->rx_dropped);
83317 kfree_skb(skb);
83318 return;
83319 }
83320diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83321index 7a43138..bc76865 100644
83322--- a/include/net/inet_connection_sock.h
83323+++ b/include/net/inet_connection_sock.h
83324@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83325 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83326 int (*bind_conflict)(const struct sock *sk,
83327 const struct inet_bind_bucket *tb, bool relax);
83328-};
83329+} __do_const;
83330
83331 /** inet_connection_sock - INET connection oriented sock
83332 *
83333diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83334index 058271b..1a44af7 100644
83335--- a/include/net/inetpeer.h
83336+++ b/include/net/inetpeer.h
83337@@ -47,8 +47,8 @@ struct inet_peer {
83338 */
83339 union {
83340 struct {
83341- atomic_t rid; /* Frag reception counter */
83342- atomic_t ip_id_count; /* IP ID for the next packet */
83343+ atomic_unchecked_t rid; /* Frag reception counter */
83344+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
83345 };
83346 struct rcu_head rcu;
83347 struct inet_peer *gc_next;
83348@@ -179,7 +179,7 @@ static inline int inet_getid(struct inet_peer *p, int more)
83349 {
83350 more++;
83351 inet_peer_refcheck(p);
83352- return atomic_add_return(more, &p->ip_id_count) - more;
83353+ return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
83354 }
83355
83356 #endif /* _NET_INETPEER_H */
83357diff --git a/include/net/ip.h b/include/net/ip.h
83358index 3ec2b0f..72435b6 100644
83359--- a/include/net/ip.h
83360+++ b/include/net/ip.h
83361@@ -220,7 +220,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83362
83363 void inet_get_local_port_range(struct net *net, int *low, int *high);
83364
83365-extern unsigned long *sysctl_local_reserved_ports;
83366+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83367 static inline int inet_is_reserved_local_port(int port)
83368 {
83369 return test_bit(port, sysctl_local_reserved_ports);
83370diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83371index 9922093..a1755d6 100644
83372--- a/include/net/ip_fib.h
83373+++ b/include/net/ip_fib.h
83374@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83375
83376 #define FIB_RES_SADDR(net, res) \
83377 ((FIB_RES_NH(res).nh_saddr_genid == \
83378- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83379+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83380 FIB_RES_NH(res).nh_saddr : \
83381 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83382 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83383diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83384index 5679d92..2e7a690 100644
83385--- a/include/net/ip_vs.h
83386+++ b/include/net/ip_vs.h
83387@@ -558,7 +558,7 @@ struct ip_vs_conn {
83388 struct ip_vs_conn *control; /* Master control connection */
83389 atomic_t n_control; /* Number of controlled ones */
83390 struct ip_vs_dest *dest; /* real server */
83391- atomic_t in_pkts; /* incoming packet counter */
83392+ atomic_unchecked_t in_pkts; /* incoming packet counter */
83393
83394 /* packet transmitter for different forwarding methods. If it
83395 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83396@@ -705,7 +705,7 @@ struct ip_vs_dest {
83397 __be16 port; /* port number of the server */
83398 union nf_inet_addr addr; /* IP address of the server */
83399 volatile unsigned int flags; /* dest status flags */
83400- atomic_t conn_flags; /* flags to copy to conn */
83401+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
83402 atomic_t weight; /* server weight */
83403
83404 atomic_t refcnt; /* reference counter */
83405@@ -960,11 +960,11 @@ struct netns_ipvs {
83406 /* ip_vs_lblc */
83407 int sysctl_lblc_expiration;
83408 struct ctl_table_header *lblc_ctl_header;
83409- struct ctl_table *lblc_ctl_table;
83410+ ctl_table_no_const *lblc_ctl_table;
83411 /* ip_vs_lblcr */
83412 int sysctl_lblcr_expiration;
83413 struct ctl_table_header *lblcr_ctl_header;
83414- struct ctl_table *lblcr_ctl_table;
83415+ ctl_table_no_const *lblcr_ctl_table;
83416 /* ip_vs_est */
83417 struct list_head est_list; /* estimator list */
83418 spinlock_t est_lock;
83419diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83420index 8d4f588..2e37ad2 100644
83421--- a/include/net/irda/ircomm_tty.h
83422+++ b/include/net/irda/ircomm_tty.h
83423@@ -33,6 +33,7 @@
83424 #include <linux/termios.h>
83425 #include <linux/timer.h>
83426 #include <linux/tty.h> /* struct tty_struct */
83427+#include <asm/local.h>
83428
83429 #include <net/irda/irias_object.h>
83430 #include <net/irda/ircomm_core.h>
83431diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83432index 714cc9a..ea05f3e 100644
83433--- a/include/net/iucv/af_iucv.h
83434+++ b/include/net/iucv/af_iucv.h
83435@@ -149,7 +149,7 @@ struct iucv_skb_cb {
83436 struct iucv_sock_list {
83437 struct hlist_head head;
83438 rwlock_t lock;
83439- atomic_t autobind_name;
83440+ atomic_unchecked_t autobind_name;
83441 };
83442
83443 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83444diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83445index f3be818..bf46196 100644
83446--- a/include/net/llc_c_ac.h
83447+++ b/include/net/llc_c_ac.h
83448@@ -87,7 +87,7 @@
83449 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83450 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83451
83452-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83453+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83454
83455 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83456 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83457diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83458index 3948cf1..83b28c4 100644
83459--- a/include/net/llc_c_ev.h
83460+++ b/include/net/llc_c_ev.h
83461@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83462 return (struct llc_conn_state_ev *)skb->cb;
83463 }
83464
83465-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83466-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83467+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83468+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83469
83470 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83471 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83472diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83473index 0e79cfb..f46db31 100644
83474--- a/include/net/llc_c_st.h
83475+++ b/include/net/llc_c_st.h
83476@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83477 u8 next_state;
83478 llc_conn_ev_qfyr_t *ev_qualifiers;
83479 llc_conn_action_t *ev_actions;
83480-};
83481+} __do_const;
83482
83483 struct llc_conn_state {
83484 u8 current_state;
83485diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83486index a61b98c..aade1eb 100644
83487--- a/include/net/llc_s_ac.h
83488+++ b/include/net/llc_s_ac.h
83489@@ -23,7 +23,7 @@
83490 #define SAP_ACT_TEST_IND 9
83491
83492 /* All action functions must look like this */
83493-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83494+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83495
83496 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83497 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83498diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83499index 567c681..cd73ac02 100644
83500--- a/include/net/llc_s_st.h
83501+++ b/include/net/llc_s_st.h
83502@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83503 llc_sap_ev_t ev;
83504 u8 next_state;
83505 llc_sap_action_t *ev_actions;
83506-};
83507+} __do_const;
83508
83509 struct llc_sap_state {
83510 u8 curr_state;
83511diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83512index 8248e39..7610eec 100644
83513--- a/include/net/mac80211.h
83514+++ b/include/net/mac80211.h
83515@@ -4467,7 +4467,7 @@ struct rate_control_ops {
83516 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83517 struct dentry *dir);
83518 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83519-};
83520+} __do_const;
83521
83522 static inline int rate_supported(struct ieee80211_sta *sta,
83523 enum ieee80211_band band,
83524diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83525index 7277caf..fd095bc 100644
83526--- a/include/net/neighbour.h
83527+++ b/include/net/neighbour.h
83528@@ -163,7 +163,7 @@ struct neigh_ops {
83529 void (*error_report)(struct neighbour *, struct sk_buff *);
83530 int (*output)(struct neighbour *, struct sk_buff *);
83531 int (*connected_output)(struct neighbour *, struct sk_buff *);
83532-};
83533+} __do_const;
83534
83535 struct pneigh_entry {
83536 struct pneigh_entry *next;
83537@@ -203,7 +203,6 @@ struct neigh_table {
83538 void (*proxy_redo)(struct sk_buff *skb);
83539 char *id;
83540 struct neigh_parms parms;
83541- /* HACK. gc_* should follow parms without a gap! */
83542 int gc_interval;
83543 int gc_thresh1;
83544 int gc_thresh2;
83545@@ -218,7 +217,7 @@ struct neigh_table {
83546 struct neigh_statistics __percpu *stats;
83547 struct neigh_hash_table __rcu *nht;
83548 struct pneigh_entry **phash_buckets;
83549-};
83550+} __randomize_layout;
83551
83552 static inline int neigh_parms_family(struct neigh_parms *p)
83553 {
83554diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83555index 5f9eb26..85699c4 100644
83556--- a/include/net/net_namespace.h
83557+++ b/include/net/net_namespace.h
83558@@ -129,8 +129,8 @@ struct net {
83559 struct netns_ipvs *ipvs;
83560 #endif
83561 struct sock *diag_nlsk;
83562- atomic_t fnhe_genid;
83563-};
83564+ atomic_unchecked_t fnhe_genid;
83565+} __randomize_layout;
83566
83567 #include <linux/seq_file_net.h>
83568
83569@@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83570 #define __net_init __init
83571 #define __net_exit __exit_refok
83572 #define __net_initdata __initdata
83573+#ifdef CONSTIFY_PLUGIN
83574 #define __net_initconst __initconst
83575+#else
83576+#define __net_initconst __initdata
83577+#endif
83578 #endif
83579
83580 struct pernet_operations {
83581@@ -296,7 +300,7 @@ struct pernet_operations {
83582 void (*exit_batch)(struct list_head *net_exit_list);
83583 int *id;
83584 size_t size;
83585-};
83586+} __do_const;
83587
83588 /*
83589 * Use these carefully. If you implement a network device and it
83590@@ -344,23 +348,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83591
83592 static inline int rt_genid_ipv4(struct net *net)
83593 {
83594- return atomic_read(&net->ipv4.rt_genid);
83595+ return atomic_read_unchecked(&net->ipv4.rt_genid);
83596 }
83597
83598 static inline void rt_genid_bump_ipv4(struct net *net)
83599 {
83600- atomic_inc(&net->ipv4.rt_genid);
83601+ atomic_inc_unchecked(&net->ipv4.rt_genid);
83602 }
83603
83604 #if IS_ENABLED(CONFIG_IPV6)
83605 static inline int rt_genid_ipv6(struct net *net)
83606 {
83607- return atomic_read(&net->ipv6.rt_genid);
83608+ return atomic_read_unchecked(&net->ipv6.rt_genid);
83609 }
83610
83611 static inline void rt_genid_bump_ipv6(struct net *net)
83612 {
83613- atomic_inc(&net->ipv6.rt_genid);
83614+ atomic_inc_unchecked(&net->ipv6.rt_genid);
83615 }
83616 #else
83617 static inline int rt_genid_ipv6(struct net *net)
83618@@ -382,12 +386,12 @@ static inline void rt_genid_bump_all(struct net *net)
83619
83620 static inline int fnhe_genid(struct net *net)
83621 {
83622- return atomic_read(&net->fnhe_genid);
83623+ return atomic_read_unchecked(&net->fnhe_genid);
83624 }
83625
83626 static inline void fnhe_genid_bump(struct net *net)
83627 {
83628- atomic_inc(&net->fnhe_genid);
83629+ atomic_inc_unchecked(&net->fnhe_genid);
83630 }
83631
83632 #endif /* __NET_NET_NAMESPACE_H */
83633diff --git a/include/net/netdma.h b/include/net/netdma.h
83634index 8ba8ce2..99b7fff 100644
83635--- a/include/net/netdma.h
83636+++ b/include/net/netdma.h
83637@@ -24,7 +24,7 @@
83638 #include <linux/dmaengine.h>
83639 #include <linux/skbuff.h>
83640
83641-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83642+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83643 struct sk_buff *skb, int offset, struct iovec *to,
83644 size_t len, struct dma_pinned_list *pinned_list);
83645
83646diff --git a/include/net/netlink.h b/include/net/netlink.h
83647index 2b47eaa..6d5bcc2 100644
83648--- a/include/net/netlink.h
83649+++ b/include/net/netlink.h
83650@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83651 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83652 {
83653 if (mark)
83654- skb_trim(skb, (unsigned char *) mark - skb->data);
83655+ skb_trim(skb, (const unsigned char *) mark - skb->data);
83656 }
83657
83658 /**
83659diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
83660index 773cce3..6a11852 100644
83661--- a/include/net/netns/conntrack.h
83662+++ b/include/net/netns/conntrack.h
83663@@ -13,10 +13,10 @@ struct nf_conntrack_ecache;
83664 struct nf_proto_net {
83665 #ifdef CONFIG_SYSCTL
83666 struct ctl_table_header *ctl_table_header;
83667- struct ctl_table *ctl_table;
83668+ ctl_table_no_const *ctl_table;
83669 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83670 struct ctl_table_header *ctl_compat_header;
83671- struct ctl_table *ctl_compat_table;
83672+ ctl_table_no_const *ctl_compat_table;
83673 #endif
83674 #endif
83675 unsigned int users;
83676@@ -59,7 +59,7 @@ struct nf_ip_net {
83677 struct nf_icmp_net icmpv6;
83678 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83679 struct ctl_table_header *ctl_table_header;
83680- struct ctl_table *ctl_table;
83681+ ctl_table_no_const *ctl_table;
83682 #endif
83683 };
83684
83685diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83686index b2704fd0..421d717 100644
83687--- a/include/net/netns/ipv4.h
83688+++ b/include/net/netns/ipv4.h
83689@@ -79,7 +79,7 @@ struct netns_ipv4 {
83690
83691 struct ping_group_range ping_group_range;
83692
83693- atomic_t dev_addr_genid;
83694+ atomic_unchecked_t dev_addr_genid;
83695
83696 #ifdef CONFIG_IP_MROUTE
83697 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83698@@ -89,6 +89,6 @@ struct netns_ipv4 {
83699 struct fib_rules_ops *mr_rules_ops;
83700 #endif
83701 #endif
83702- atomic_t rt_genid;
83703+ atomic_unchecked_t rt_genid;
83704 };
83705 #endif
83706diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83707index 21edaf1..4c5faae 100644
83708--- a/include/net/netns/ipv6.h
83709+++ b/include/net/netns/ipv6.h
83710@@ -73,8 +73,8 @@ struct netns_ipv6 {
83711 struct fib_rules_ops *mr6_rules_ops;
83712 #endif
83713 #endif
83714- atomic_t dev_addr_genid;
83715- atomic_t rt_genid;
83716+ atomic_unchecked_t dev_addr_genid;
83717+ atomic_unchecked_t rt_genid;
83718 };
83719
83720 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83721diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
83722index 3492434..209f58c 100644
83723--- a/include/net/netns/xfrm.h
83724+++ b/include/net/netns/xfrm.h
83725@@ -64,7 +64,7 @@ struct netns_xfrm {
83726
83727 /* flow cache part */
83728 struct flow_cache flow_cache_global;
83729- atomic_t flow_cache_genid;
83730+ atomic_unchecked_t flow_cache_genid;
83731 struct list_head flow_cache_gc_list;
83732 spinlock_t flow_cache_gc_lock;
83733 struct work_struct flow_cache_gc_work;
83734diff --git a/include/net/ping.h b/include/net/ping.h
83735index 026479b..d9b2829 100644
83736--- a/include/net/ping.h
83737+++ b/include/net/ping.h
83738@@ -54,7 +54,7 @@ struct ping_iter_state {
83739
83740 extern struct proto ping_prot;
83741 #if IS_ENABLED(CONFIG_IPV6)
83742-extern struct pingv6_ops pingv6_ops;
83743+extern struct pingv6_ops *pingv6_ops;
83744 #endif
83745
83746 struct pingfakehdr {
83747diff --git a/include/net/protocol.h b/include/net/protocol.h
83748index a7e986b..dc67bce 100644
83749--- a/include/net/protocol.h
83750+++ b/include/net/protocol.h
83751@@ -49,7 +49,7 @@ struct net_protocol {
83752 * socket lookup?
83753 */
83754 icmp_strict_tag_validation:1;
83755-};
83756+} __do_const;
83757
83758 #if IS_ENABLED(CONFIG_IPV6)
83759 struct inet6_protocol {
83760@@ -62,7 +62,7 @@ struct inet6_protocol {
83761 u8 type, u8 code, int offset,
83762 __be32 info);
83763 unsigned int flags; /* INET6_PROTO_xxx */
83764-};
83765+} __do_const;
83766
83767 #define INET6_PROTO_NOPOLICY 0x1
83768 #define INET6_PROTO_FINAL 0x2
83769diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83770index 72240e5..8c14bef 100644
83771--- a/include/net/rtnetlink.h
83772+++ b/include/net/rtnetlink.h
83773@@ -93,7 +93,7 @@ struct rtnl_link_ops {
83774 int (*fill_slave_info)(struct sk_buff *skb,
83775 const struct net_device *dev,
83776 const struct net_device *slave_dev);
83777-};
83778+} __do_const;
83779
83780 int __rtnl_link_register(struct rtnl_link_ops *ops);
83781 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83782diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83783index 4a5b9a3..ca27d73 100644
83784--- a/include/net/sctp/checksum.h
83785+++ b/include/net/sctp/checksum.h
83786@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83787 unsigned int offset)
83788 {
83789 struct sctphdr *sh = sctp_hdr(skb);
83790- __le32 ret, old = sh->checksum;
83791- const struct skb_checksum_ops ops = {
83792+ __le32 ret, old = sh->checksum;
83793+ static const struct skb_checksum_ops ops = {
83794 .update = sctp_csum_update,
83795 .combine = sctp_csum_combine,
83796 };
83797diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83798index 7f4eeb3..37e8fe1 100644
83799--- a/include/net/sctp/sm.h
83800+++ b/include/net/sctp/sm.h
83801@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83802 typedef struct {
83803 sctp_state_fn_t *fn;
83804 const char *name;
83805-} sctp_sm_table_entry_t;
83806+} __do_const sctp_sm_table_entry_t;
83807
83808 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83809 * currently in use.
83810@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83811 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83812
83813 /* Extern declarations for major data structures. */
83814-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83815+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83816
83817
83818 /* Get the size of a DATA chunk payload. */
83819diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83820index 0dfcc92..7967849 100644
83821--- a/include/net/sctp/structs.h
83822+++ b/include/net/sctp/structs.h
83823@@ -507,7 +507,7 @@ struct sctp_pf {
83824 struct sctp_association *asoc);
83825 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
83826 struct sctp_af *af;
83827-};
83828+} __do_const;
83829
83830
83831 /* Structure to track chunk fragments that have been acked, but peer
83832diff --git a/include/net/sock.h b/include/net/sock.h
83833index 21569cf..dd60300 100644
83834--- a/include/net/sock.h
83835+++ b/include/net/sock.h
83836@@ -348,7 +348,7 @@ struct sock {
83837 unsigned int sk_napi_id;
83838 unsigned int sk_ll_usec;
83839 #endif
83840- atomic_t sk_drops;
83841+ atomic_unchecked_t sk_drops;
83842 int sk_rcvbuf;
83843
83844 struct sk_filter __rcu *sk_filter;
83845@@ -1036,7 +1036,7 @@ struct proto {
83846 void (*destroy_cgroup)(struct mem_cgroup *memcg);
83847 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
83848 #endif
83849-};
83850+} __randomize_layout;
83851
83852 /*
83853 * Bits in struct cg_proto.flags
83854@@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
83855 return ret >> PAGE_SHIFT;
83856 }
83857
83858-static inline long
83859+static inline long __intentional_overflow(-1)
83860 sk_memory_allocated(const struct sock *sk)
83861 {
83862 struct proto *prot = sk->sk_prot;
83863@@ -1368,7 +1368,7 @@ struct sock_iocb {
83864 struct scm_cookie *scm;
83865 struct msghdr *msg, async_msg;
83866 struct kiocb *kiocb;
83867-};
83868+} __randomize_layout;
83869
83870 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
83871 {
83872@@ -1728,8 +1728,8 @@ sk_dst_get(struct sock *sk)
83873
83874 rcu_read_lock();
83875 dst = rcu_dereference(sk->sk_dst_cache);
83876- if (dst)
83877- dst_hold(dst);
83878+ if (dst && !atomic_inc_not_zero(&dst->__refcnt))
83879+ dst = NULL;
83880 rcu_read_unlock();
83881 return dst;
83882 }
83883@@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
83884 }
83885
83886 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
83887- char __user *from, char *to,
83888+ char __user *from, unsigned char *to,
83889 int copy, int offset)
83890 {
83891 if (skb->ip_summed == CHECKSUM_NONE) {
83892@@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
83893 }
83894 }
83895
83896-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83897+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83898
83899 /**
83900 * sk_page_frag - return an appropriate page_frag
83901diff --git a/include/net/tcp.h b/include/net/tcp.h
83902index 87d8774..cf214f8 100644
83903--- a/include/net/tcp.h
83904+++ b/include/net/tcp.h
83905@@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
83906 void tcp_xmit_retransmit_queue(struct sock *);
83907 void tcp_simple_retransmit(struct sock *);
83908 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83909-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83910+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83911
83912 void tcp_send_probe0(struct sock *);
83913 void tcp_send_partial(struct sock *);
83914@@ -715,8 +715,8 @@ struct tcp_skb_cb {
83915 struct inet6_skb_parm h6;
83916 #endif
83917 } header; /* For incoming frames */
83918- __u32 seq; /* Starting sequence number */
83919- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83920+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
83921+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83922 __u32 when; /* used to compute rtt's */
83923 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83924
83925@@ -730,7 +730,7 @@ struct tcp_skb_cb {
83926
83927 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83928 /* 1 byte hole */
83929- __u32 ack_seq; /* Sequence number ACK'd */
83930+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83931 };
83932
83933 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83934diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83935index 116e9c7..3070537 100644
83936--- a/include/net/xfrm.h
83937+++ b/include/net/xfrm.h
83938@@ -285,7 +285,6 @@ struct xfrm_dst;
83939 struct xfrm_policy_afinfo {
83940 unsigned short family;
83941 struct dst_ops *dst_ops;
83942- void (*garbage_collect)(struct net *net);
83943 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
83944 const xfrm_address_t *saddr,
83945 const xfrm_address_t *daddr);
83946@@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
83947 struct net_device *dev,
83948 const struct flowi *fl);
83949 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
83950-};
83951+} __do_const;
83952
83953 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
83954 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
83955@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
83956 int (*transport_finish)(struct sk_buff *skb,
83957 int async);
83958 void (*local_error)(struct sk_buff *skb, u32 mtu);
83959-};
83960+} __do_const;
83961
83962 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
83963 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
83964@@ -437,7 +436,7 @@ struct xfrm_mode {
83965 struct module *owner;
83966 unsigned int encap;
83967 int flags;
83968-};
83969+} __do_const;
83970
83971 /* Flags for xfrm_mode. */
83972 enum {
83973@@ -534,7 +533,7 @@ struct xfrm_policy {
83974 struct timer_list timer;
83975
83976 struct flow_cache_object flo;
83977- atomic_t genid;
83978+ atomic_unchecked_t genid;
83979 u32 priority;
83980 u32 index;
83981 struct xfrm_mark mark;
83982@@ -1180,6 +1179,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
83983 }
83984
83985 void xfrm_garbage_collect(struct net *net);
83986+void xfrm_garbage_collect_deferred(struct net *net);
83987
83988 #else
83989
83990@@ -1218,6 +1218,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
83991 static inline void xfrm_garbage_collect(struct net *net)
83992 {
83993 }
83994+static inline void xfrm_garbage_collect_deferred(struct net *net)
83995+{
83996+}
83997 #endif
83998
83999 static __inline__
84000diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
84001index 1017e0b..227aa4d 100644
84002--- a/include/rdma/iw_cm.h
84003+++ b/include/rdma/iw_cm.h
84004@@ -122,7 +122,7 @@ struct iw_cm_verbs {
84005 int backlog);
84006
84007 int (*destroy_listen)(struct iw_cm_id *cm_id);
84008-};
84009+} __no_const;
84010
84011 /**
84012 * iw_create_cm_id - Create an IW CM identifier.
84013diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
84014index 52beadf..598734c 100644
84015--- a/include/scsi/libfc.h
84016+++ b/include/scsi/libfc.h
84017@@ -771,6 +771,7 @@ struct libfc_function_template {
84018 */
84019 void (*disc_stop_final) (struct fc_lport *);
84020 };
84021+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
84022
84023 /**
84024 * struct fc_disc - Discovery context
84025@@ -875,7 +876,7 @@ struct fc_lport {
84026 struct fc_vport *vport;
84027
84028 /* Operational Information */
84029- struct libfc_function_template tt;
84030+ libfc_function_template_no_const tt;
84031 u8 link_up;
84032 u8 qfull;
84033 enum fc_lport_state state;
84034diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
84035index 27ab310..60dc245 100644
84036--- a/include/scsi/scsi_device.h
84037+++ b/include/scsi/scsi_device.h
84038@@ -187,9 +187,9 @@ struct scsi_device {
84039 unsigned int max_device_blocked; /* what device_blocked counts down from */
84040 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
84041
84042- atomic_t iorequest_cnt;
84043- atomic_t iodone_cnt;
84044- atomic_t ioerr_cnt;
84045+ atomic_unchecked_t iorequest_cnt;
84046+ atomic_unchecked_t iodone_cnt;
84047+ atomic_unchecked_t ioerr_cnt;
84048
84049 struct device sdev_gendev,
84050 sdev_dev;
84051diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
84052index 8c79980..723f6f9 100644
84053--- a/include/scsi/scsi_transport_fc.h
84054+++ b/include/scsi/scsi_transport_fc.h
84055@@ -752,7 +752,8 @@ struct fc_function_template {
84056 unsigned long show_host_system_hostname:1;
84057
84058 unsigned long disable_target_scan:1;
84059-};
84060+} __do_const;
84061+typedef struct fc_function_template __no_const fc_function_template_no_const;
84062
84063
84064 /**
84065diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84066index ae6c3b8..fd748ac 100644
84067--- a/include/sound/compress_driver.h
84068+++ b/include/sound/compress_driver.h
84069@@ -128,7 +128,7 @@ struct snd_compr_ops {
84070 struct snd_compr_caps *caps);
84071 int (*get_codec_caps) (struct snd_compr_stream *stream,
84072 struct snd_compr_codec_caps *codec);
84073-};
84074+} __no_const;
84075
84076 /**
84077 * struct snd_compr: Compressed device
84078diff --git a/include/sound/soc.h b/include/sound/soc.h
84079index 0b83168..d67280a 100644
84080--- a/include/sound/soc.h
84081+++ b/include/sound/soc.h
84082@@ -782,7 +782,7 @@ struct snd_soc_codec_driver {
84083 /* probe ordering - for components with runtime dependencies */
84084 int probe_order;
84085 int remove_order;
84086-};
84087+} __do_const;
84088
84089 /* SoC platform interface */
84090 struct snd_soc_platform_driver {
84091@@ -828,7 +828,7 @@ struct snd_soc_platform_driver {
84092 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84093 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84094 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84095-};
84096+} __do_const;
84097
84098 struct snd_soc_platform {
84099 const char *name;
84100diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84101index 9ec9864..e2ee1ee 100644
84102--- a/include/target/target_core_base.h
84103+++ b/include/target/target_core_base.h
84104@@ -761,7 +761,7 @@ struct se_device {
84105 atomic_long_t write_bytes;
84106 /* Active commands on this virtual SE device */
84107 atomic_t simple_cmds;
84108- atomic_t dev_ordered_id;
84109+ atomic_unchecked_t dev_ordered_id;
84110 atomic_t dev_ordered_sync;
84111 atomic_t dev_qf_count;
84112 int export_count;
84113diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84114new file mode 100644
84115index 0000000..fb634b7
84116--- /dev/null
84117+++ b/include/trace/events/fs.h
84118@@ -0,0 +1,53 @@
84119+#undef TRACE_SYSTEM
84120+#define TRACE_SYSTEM fs
84121+
84122+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84123+#define _TRACE_FS_H
84124+
84125+#include <linux/fs.h>
84126+#include <linux/tracepoint.h>
84127+
84128+TRACE_EVENT(do_sys_open,
84129+
84130+ TP_PROTO(const char *filename, int flags, int mode),
84131+
84132+ TP_ARGS(filename, flags, mode),
84133+
84134+ TP_STRUCT__entry(
84135+ __string( filename, filename )
84136+ __field( int, flags )
84137+ __field( int, mode )
84138+ ),
84139+
84140+ TP_fast_assign(
84141+ __assign_str(filename, filename);
84142+ __entry->flags = flags;
84143+ __entry->mode = mode;
84144+ ),
84145+
84146+ TP_printk("\"%s\" %x %o",
84147+ __get_str(filename), __entry->flags, __entry->mode)
84148+);
84149+
84150+TRACE_EVENT(open_exec,
84151+
84152+ TP_PROTO(const char *filename),
84153+
84154+ TP_ARGS(filename),
84155+
84156+ TP_STRUCT__entry(
84157+ __string( filename, filename )
84158+ ),
84159+
84160+ TP_fast_assign(
84161+ __assign_str(filename, filename);
84162+ ),
84163+
84164+ TP_printk("\"%s\"",
84165+ __get_str(filename))
84166+);
84167+
84168+#endif /* _TRACE_FS_H */
84169+
84170+/* This part must be outside protection */
84171+#include <trace/define_trace.h>
84172diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84173index 1c09820..7f5ec79 100644
84174--- a/include/trace/events/irq.h
84175+++ b/include/trace/events/irq.h
84176@@ -36,7 +36,7 @@ struct softirq_action;
84177 */
84178 TRACE_EVENT(irq_handler_entry,
84179
84180- TP_PROTO(int irq, struct irqaction *action),
84181+ TP_PROTO(int irq, const struct irqaction *action),
84182
84183 TP_ARGS(irq, action),
84184
84185@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84186 */
84187 TRACE_EVENT(irq_handler_exit,
84188
84189- TP_PROTO(int irq, struct irqaction *action, int ret),
84190+ TP_PROTO(int irq, const struct irqaction *action, int ret),
84191
84192 TP_ARGS(irq, action, ret),
84193
84194diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84195index 7caf44c..23c6f27 100644
84196--- a/include/uapi/linux/a.out.h
84197+++ b/include/uapi/linux/a.out.h
84198@@ -39,6 +39,14 @@ enum machine_type {
84199 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84200 };
84201
84202+/* Constants for the N_FLAGS field */
84203+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84204+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84205+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84206+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84207+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84208+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84209+
84210 #if !defined (N_MAGIC)
84211 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84212 #endif
84213diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84214index 22b6ad3..aeba37e 100644
84215--- a/include/uapi/linux/bcache.h
84216+++ b/include/uapi/linux/bcache.h
84217@@ -5,6 +5,7 @@
84218 * Bcache on disk data structures
84219 */
84220
84221+#include <linux/compiler.h>
84222 #include <asm/types.h>
84223
84224 #define BITMASK(name, type, field, offset, size) \
84225@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84226 /* Btree keys - all units are in sectors */
84227
84228 struct bkey {
84229- __u64 high;
84230- __u64 low;
84231+ __u64 high __intentional_overflow(-1);
84232+ __u64 low __intentional_overflow(-1);
84233 __u64 ptr[];
84234 };
84235
84236diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84237index d876736..ccce5c0 100644
84238--- a/include/uapi/linux/byteorder/little_endian.h
84239+++ b/include/uapi/linux/byteorder/little_endian.h
84240@@ -42,51 +42,51 @@
84241
84242 static inline __le64 __cpu_to_le64p(const __u64 *p)
84243 {
84244- return (__force __le64)*p;
84245+ return (__force const __le64)*p;
84246 }
84247-static inline __u64 __le64_to_cpup(const __le64 *p)
84248+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84249 {
84250- return (__force __u64)*p;
84251+ return (__force const __u64)*p;
84252 }
84253 static inline __le32 __cpu_to_le32p(const __u32 *p)
84254 {
84255- return (__force __le32)*p;
84256+ return (__force const __le32)*p;
84257 }
84258 static inline __u32 __le32_to_cpup(const __le32 *p)
84259 {
84260- return (__force __u32)*p;
84261+ return (__force const __u32)*p;
84262 }
84263 static inline __le16 __cpu_to_le16p(const __u16 *p)
84264 {
84265- return (__force __le16)*p;
84266+ return (__force const __le16)*p;
84267 }
84268 static inline __u16 __le16_to_cpup(const __le16 *p)
84269 {
84270- return (__force __u16)*p;
84271+ return (__force const __u16)*p;
84272 }
84273 static inline __be64 __cpu_to_be64p(const __u64 *p)
84274 {
84275- return (__force __be64)__swab64p(p);
84276+ return (__force const __be64)__swab64p(p);
84277 }
84278 static inline __u64 __be64_to_cpup(const __be64 *p)
84279 {
84280- return __swab64p((__u64 *)p);
84281+ return __swab64p((const __u64 *)p);
84282 }
84283 static inline __be32 __cpu_to_be32p(const __u32 *p)
84284 {
84285- return (__force __be32)__swab32p(p);
84286+ return (__force const __be32)__swab32p(p);
84287 }
84288-static inline __u32 __be32_to_cpup(const __be32 *p)
84289+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84290 {
84291- return __swab32p((__u32 *)p);
84292+ return __swab32p((const __u32 *)p);
84293 }
84294 static inline __be16 __cpu_to_be16p(const __u16 *p)
84295 {
84296- return (__force __be16)__swab16p(p);
84297+ return (__force const __be16)__swab16p(p);
84298 }
84299 static inline __u16 __be16_to_cpup(const __be16 *p)
84300 {
84301- return __swab16p((__u16 *)p);
84302+ return __swab16p((const __u16 *)p);
84303 }
84304 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84305 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84306diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84307index ef6103b..d4e65dd 100644
84308--- a/include/uapi/linux/elf.h
84309+++ b/include/uapi/linux/elf.h
84310@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84311 #define PT_GNU_EH_FRAME 0x6474e550
84312
84313 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84314+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84315+
84316+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84317+
84318+/* Constants for the e_flags field */
84319+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84320+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84321+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84322+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84323+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84324+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84325
84326 /*
84327 * Extended Numbering
84328@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84329 #define DT_DEBUG 21
84330 #define DT_TEXTREL 22
84331 #define DT_JMPREL 23
84332+#define DT_FLAGS 30
84333+ #define DF_TEXTREL 0x00000004
84334 #define DT_ENCODING 32
84335 #define OLD_DT_LOOS 0x60000000
84336 #define DT_LOOS 0x6000000d
84337@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84338 #define PF_W 0x2
84339 #define PF_X 0x1
84340
84341+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84342+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84343+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84344+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84345+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84346+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84347+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84348+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84349+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84350+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84351+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84352+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84353+
84354 typedef struct elf32_phdr{
84355 Elf32_Word p_type;
84356 Elf32_Off p_offset;
84357@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84358 #define EI_OSABI 7
84359 #define EI_PAD 8
84360
84361+#define EI_PAX 14
84362+
84363 #define ELFMAG0 0x7f /* EI_MAG */
84364 #define ELFMAG1 'E'
84365 #define ELFMAG2 'L'
84366diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84367index aa169c4..6a2771d 100644
84368--- a/include/uapi/linux/personality.h
84369+++ b/include/uapi/linux/personality.h
84370@@ -30,6 +30,7 @@ enum {
84371 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84372 ADDR_NO_RANDOMIZE | \
84373 ADDR_COMPAT_LAYOUT | \
84374+ ADDR_LIMIT_3GB | \
84375 MMAP_PAGE_ZERO)
84376
84377 /*
84378diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84379index 7530e74..e714828 100644
84380--- a/include/uapi/linux/screen_info.h
84381+++ b/include/uapi/linux/screen_info.h
84382@@ -43,7 +43,8 @@ struct screen_info {
84383 __u16 pages; /* 0x32 */
84384 __u16 vesa_attributes; /* 0x34 */
84385 __u32 capabilities; /* 0x36 */
84386- __u8 _reserved[6]; /* 0x3a */
84387+ __u16 vesapm_size; /* 0x3a */
84388+ __u8 _reserved[4]; /* 0x3c */
84389 } __attribute__((packed));
84390
84391 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84392diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84393index 0e011eb..82681b1 100644
84394--- a/include/uapi/linux/swab.h
84395+++ b/include/uapi/linux/swab.h
84396@@ -43,7 +43,7 @@
84397 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84398 */
84399
84400-static inline __attribute_const__ __u16 __fswab16(__u16 val)
84401+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84402 {
84403 #ifdef __HAVE_BUILTIN_BSWAP16__
84404 return __builtin_bswap16(val);
84405@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84406 #endif
84407 }
84408
84409-static inline __attribute_const__ __u32 __fswab32(__u32 val)
84410+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84411 {
84412 #ifdef __HAVE_BUILTIN_BSWAP32__
84413 return __builtin_bswap32(val);
84414@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84415 #endif
84416 }
84417
84418-static inline __attribute_const__ __u64 __fswab64(__u64 val)
84419+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84420 {
84421 #ifdef __HAVE_BUILTIN_BSWAP64__
84422 return __builtin_bswap64(val);
84423diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84424index 6d67213..552fdd9 100644
84425--- a/include/uapi/linux/sysctl.h
84426+++ b/include/uapi/linux/sysctl.h
84427@@ -155,8 +155,6 @@ enum
84428 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84429 };
84430
84431-
84432-
84433 /* CTL_VM names: */
84434 enum
84435 {
84436diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84437index ea468ee..4d367a5 100644
84438--- a/include/uapi/linux/videodev2.h
84439+++ b/include/uapi/linux/videodev2.h
84440@@ -1248,7 +1248,7 @@ struct v4l2_ext_control {
84441 union {
84442 __s32 value;
84443 __s64 value64;
84444- char *string;
84445+ char __user *string;
84446 };
84447 } __attribute__ ((packed));
84448
84449diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84450index c38355c..17a57bc 100644
84451--- a/include/uapi/linux/xattr.h
84452+++ b/include/uapi/linux/xattr.h
84453@@ -73,5 +73,9 @@
84454 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84455 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84456
84457+/* User namespace */
84458+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84459+#define XATTR_PAX_FLAGS_SUFFIX "flags"
84460+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84461
84462 #endif /* _UAPI_LINUX_XATTR_H */
84463diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84464index f9466fa..f4e2b81 100644
84465--- a/include/video/udlfb.h
84466+++ b/include/video/udlfb.h
84467@@ -53,10 +53,10 @@ struct dlfb_data {
84468 u32 pseudo_palette[256];
84469 int blank_mode; /*one of FB_BLANK_ */
84470 /* blit-only rendering path metrics, exposed through sysfs */
84471- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84472- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84473- atomic_t bytes_sent; /* to usb, after compression including overhead */
84474- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84475+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84476+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84477+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84478+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84479 };
84480
84481 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84482diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84483index 30f5362..8ed8ac9 100644
84484--- a/include/video/uvesafb.h
84485+++ b/include/video/uvesafb.h
84486@@ -122,6 +122,7 @@ struct uvesafb_par {
84487 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84488 u8 pmi_setpal; /* PMI for palette changes */
84489 u16 *pmi_base; /* protected mode interface location */
84490+ u8 *pmi_code; /* protected mode code location */
84491 void *pmi_start;
84492 void *pmi_pal;
84493 u8 *vbe_state_orig; /*
84494diff --git a/init/Kconfig b/init/Kconfig
84495index 9d3585b..ad45d34 100644
84496--- a/init/Kconfig
84497+++ b/init/Kconfig
84498@@ -1093,6 +1093,7 @@ endif # CGROUPS
84499
84500 config CHECKPOINT_RESTORE
84501 bool "Checkpoint/restore support" if EXPERT
84502+ depends on !GRKERNSEC
84503 default n
84504 help
84505 Enables additional kernel features in a sake of checkpoint/restore.
84506@@ -1570,7 +1571,7 @@ config SLUB_DEBUG
84507
84508 config COMPAT_BRK
84509 bool "Disable heap randomization"
84510- default y
84511+ default n
84512 help
84513 Randomizing heap placement makes heap exploits harder, but it
84514 also breaks ancient binaries (including anything libc5 based).
84515@@ -1858,7 +1859,7 @@ config INIT_ALL_POSSIBLE
84516 config STOP_MACHINE
84517 bool
84518 default y
84519- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84520+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84521 help
84522 Need stop_machine() primitive.
84523
84524diff --git a/init/Makefile b/init/Makefile
84525index 7bc47ee..6da2dc7 100644
84526--- a/init/Makefile
84527+++ b/init/Makefile
84528@@ -2,6 +2,9 @@
84529 # Makefile for the linux kernel.
84530 #
84531
84532+ccflags-y := $(GCC_PLUGINS_CFLAGS)
84533+asflags-y := $(GCC_PLUGINS_AFLAGS)
84534+
84535 obj-y := main.o version.o mounts.o
84536 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84537 obj-y += noinitramfs.o
84538diff --git a/init/do_mounts.c b/init/do_mounts.c
84539index 82f2288..ea1430a 100644
84540--- a/init/do_mounts.c
84541+++ b/init/do_mounts.c
84542@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84543 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84544 {
84545 struct super_block *s;
84546- int err = sys_mount(name, "/root", fs, flags, data);
84547+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84548 if (err)
84549 return err;
84550
84551- sys_chdir("/root");
84552+ sys_chdir((const char __force_user *)"/root");
84553 s = current->fs->pwd.dentry->d_sb;
84554 ROOT_DEV = s->s_dev;
84555 printk(KERN_INFO
84556@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84557 va_start(args, fmt);
84558 vsprintf(buf, fmt, args);
84559 va_end(args);
84560- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84561+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84562 if (fd >= 0) {
84563 sys_ioctl(fd, FDEJECT, 0);
84564 sys_close(fd);
84565 }
84566 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84567- fd = sys_open("/dev/console", O_RDWR, 0);
84568+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84569 if (fd >= 0) {
84570 sys_ioctl(fd, TCGETS, (long)&termios);
84571 termios.c_lflag &= ~ICANON;
84572 sys_ioctl(fd, TCSETSF, (long)&termios);
84573- sys_read(fd, &c, 1);
84574+ sys_read(fd, (char __user *)&c, 1);
84575 termios.c_lflag |= ICANON;
84576 sys_ioctl(fd, TCSETSF, (long)&termios);
84577 sys_close(fd);
84578@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84579 mount_root();
84580 out:
84581 devtmpfs_mount("dev");
84582- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84583- sys_chroot(".");
84584+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84585+ sys_chroot((const char __force_user *)".");
84586 }
84587
84588 static bool is_tmpfs;
84589diff --git a/init/do_mounts.h b/init/do_mounts.h
84590index f5b978a..69dbfe8 100644
84591--- a/init/do_mounts.h
84592+++ b/init/do_mounts.h
84593@@ -15,15 +15,15 @@ extern int root_mountflags;
84594
84595 static inline int create_dev(char *name, dev_t dev)
84596 {
84597- sys_unlink(name);
84598- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84599+ sys_unlink((char __force_user *)name);
84600+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84601 }
84602
84603 #if BITS_PER_LONG == 32
84604 static inline u32 bstat(char *name)
84605 {
84606 struct stat64 stat;
84607- if (sys_stat64(name, &stat) != 0)
84608+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84609 return 0;
84610 if (!S_ISBLK(stat.st_mode))
84611 return 0;
84612@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84613 static inline u32 bstat(char *name)
84614 {
84615 struct stat stat;
84616- if (sys_newstat(name, &stat) != 0)
84617+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84618 return 0;
84619 if (!S_ISBLK(stat.st_mode))
84620 return 0;
84621diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84622index 3e0878e..8a9d7a0 100644
84623--- a/init/do_mounts_initrd.c
84624+++ b/init/do_mounts_initrd.c
84625@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84626 {
84627 sys_unshare(CLONE_FS | CLONE_FILES);
84628 /* stdin/stdout/stderr for /linuxrc */
84629- sys_open("/dev/console", O_RDWR, 0);
84630+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84631 sys_dup(0);
84632 sys_dup(0);
84633 /* move initrd over / and chdir/chroot in initrd root */
84634- sys_chdir("/root");
84635- sys_mount(".", "/", NULL, MS_MOVE, NULL);
84636- sys_chroot(".");
84637+ sys_chdir((const char __force_user *)"/root");
84638+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84639+ sys_chroot((const char __force_user *)".");
84640 sys_setsid();
84641 return 0;
84642 }
84643@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84644 create_dev("/dev/root.old", Root_RAM0);
84645 /* mount initrd on rootfs' /root */
84646 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84647- sys_mkdir("/old", 0700);
84648- sys_chdir("/old");
84649+ sys_mkdir((const char __force_user *)"/old", 0700);
84650+ sys_chdir((const char __force_user *)"/old");
84651
84652 /* try loading default modules from initrd */
84653 load_default_modules();
84654@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84655 current->flags &= ~PF_FREEZER_SKIP;
84656
84657 /* move initrd to rootfs' /old */
84658- sys_mount("..", ".", NULL, MS_MOVE, NULL);
84659+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84660 /* switch root and cwd back to / of rootfs */
84661- sys_chroot("..");
84662+ sys_chroot((const char __force_user *)"..");
84663
84664 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84665- sys_chdir("/old");
84666+ sys_chdir((const char __force_user *)"/old");
84667 return;
84668 }
84669
84670- sys_chdir("/");
84671+ sys_chdir((const char __force_user *)"/");
84672 ROOT_DEV = new_decode_dev(real_root_dev);
84673 mount_root();
84674
84675 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84676- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
84677+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
84678 if (!error)
84679 printk("okay\n");
84680 else {
84681- int fd = sys_open("/dev/root.old", O_RDWR, 0);
84682+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
84683 if (error == -ENOENT)
84684 printk("/initrd does not exist. Ignored.\n");
84685 else
84686 printk("failed\n");
84687 printk(KERN_NOTICE "Unmounting old root\n");
84688- sys_umount("/old", MNT_DETACH);
84689+ sys_umount((char __force_user *)"/old", MNT_DETACH);
84690 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
84691 if (fd < 0) {
84692 error = fd;
84693@@ -127,11 +127,11 @@ int __init initrd_load(void)
84694 * mounted in the normal path.
84695 */
84696 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
84697- sys_unlink("/initrd.image");
84698+ sys_unlink((const char __force_user *)"/initrd.image");
84699 handle_initrd();
84700 return 1;
84701 }
84702 }
84703- sys_unlink("/initrd.image");
84704+ sys_unlink((const char __force_user *)"/initrd.image");
84705 return 0;
84706 }
84707diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84708index 8cb6db5..d729f50 100644
84709--- a/init/do_mounts_md.c
84710+++ b/init/do_mounts_md.c
84711@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84712 partitioned ? "_d" : "", minor,
84713 md_setup_args[ent].device_names);
84714
84715- fd = sys_open(name, 0, 0);
84716+ fd = sys_open((char __force_user *)name, 0, 0);
84717 if (fd < 0) {
84718 printk(KERN_ERR "md: open failed - cannot start "
84719 "array %s\n", name);
84720@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84721 * array without it
84722 */
84723 sys_close(fd);
84724- fd = sys_open(name, 0, 0);
84725+ fd = sys_open((char __force_user *)name, 0, 0);
84726 sys_ioctl(fd, BLKRRPART, 0);
84727 }
84728 sys_close(fd);
84729@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84730
84731 wait_for_device_probe();
84732
84733- fd = sys_open("/dev/md0", 0, 0);
84734+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84735 if (fd >= 0) {
84736 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84737 sys_close(fd);
84738diff --git a/init/init_task.c b/init/init_task.c
84739index ba0a7f36..2bcf1d5 100644
84740--- a/init/init_task.c
84741+++ b/init/init_task.c
84742@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84743 * Initial thread structure. Alignment of this is handled by a special
84744 * linker map entry.
84745 */
84746+#ifdef CONFIG_X86
84747+union thread_union init_thread_union __init_task_data;
84748+#else
84749 union thread_union init_thread_union __init_task_data =
84750 { INIT_THREAD_INFO(init_task) };
84751+#endif
84752diff --git a/init/initramfs.c b/init/initramfs.c
84753index a8497fa..35b3c90 100644
84754--- a/init/initramfs.c
84755+++ b/init/initramfs.c
84756@@ -84,7 +84,7 @@ static void __init free_hash(void)
84757 }
84758 }
84759
84760-static long __init do_utime(char *filename, time_t mtime)
84761+static long __init do_utime(char __force_user *filename, time_t mtime)
84762 {
84763 struct timespec t[2];
84764
84765@@ -119,7 +119,7 @@ static void __init dir_utime(void)
84766 struct dir_entry *de, *tmp;
84767 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84768 list_del(&de->list);
84769- do_utime(de->name, de->mtime);
84770+ do_utime((char __force_user *)de->name, de->mtime);
84771 kfree(de->name);
84772 kfree(de);
84773 }
84774@@ -281,7 +281,7 @@ static int __init maybe_link(void)
84775 if (nlink >= 2) {
84776 char *old = find_link(major, minor, ino, mode, collected);
84777 if (old)
84778- return (sys_link(old, collected) < 0) ? -1 : 1;
84779+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84780 }
84781 return 0;
84782 }
84783@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84784 {
84785 struct stat st;
84786
84787- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84788+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84789 if (S_ISDIR(st.st_mode))
84790- sys_rmdir(path);
84791+ sys_rmdir((char __force_user *)path);
84792 else
84793- sys_unlink(path);
84794+ sys_unlink((char __force_user *)path);
84795 }
84796 }
84797
84798@@ -315,7 +315,7 @@ static int __init do_name(void)
84799 int openflags = O_WRONLY|O_CREAT;
84800 if (ml != 1)
84801 openflags |= O_TRUNC;
84802- wfd = sys_open(collected, openflags, mode);
84803+ wfd = sys_open((char __force_user *)collected, openflags, mode);
84804
84805 if (wfd >= 0) {
84806 sys_fchown(wfd, uid, gid);
84807@@ -327,17 +327,17 @@ static int __init do_name(void)
84808 }
84809 }
84810 } else if (S_ISDIR(mode)) {
84811- sys_mkdir(collected, mode);
84812- sys_chown(collected, uid, gid);
84813- sys_chmod(collected, mode);
84814+ sys_mkdir((char __force_user *)collected, mode);
84815+ sys_chown((char __force_user *)collected, uid, gid);
84816+ sys_chmod((char __force_user *)collected, mode);
84817 dir_add(collected, mtime);
84818 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84819 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84820 if (maybe_link() == 0) {
84821- sys_mknod(collected, mode, rdev);
84822- sys_chown(collected, uid, gid);
84823- sys_chmod(collected, mode);
84824- do_utime(collected, mtime);
84825+ sys_mknod((char __force_user *)collected, mode, rdev);
84826+ sys_chown((char __force_user *)collected, uid, gid);
84827+ sys_chmod((char __force_user *)collected, mode);
84828+ do_utime((char __force_user *)collected, mtime);
84829 }
84830 }
84831 return 0;
84832@@ -346,15 +346,15 @@ static int __init do_name(void)
84833 static int __init do_copy(void)
84834 {
84835 if (count >= body_len) {
84836- sys_write(wfd, victim, body_len);
84837+ sys_write(wfd, (char __force_user *)victim, body_len);
84838 sys_close(wfd);
84839- do_utime(vcollected, mtime);
84840+ do_utime((char __force_user *)vcollected, mtime);
84841 kfree(vcollected);
84842 eat(body_len);
84843 state = SkipIt;
84844 return 0;
84845 } else {
84846- sys_write(wfd, victim, count);
84847+ sys_write(wfd, (char __force_user *)victim, count);
84848 body_len -= count;
84849 eat(count);
84850 return 1;
84851@@ -365,9 +365,9 @@ static int __init do_symlink(void)
84852 {
84853 collected[N_ALIGN(name_len) + body_len] = '\0';
84854 clean_path(collected, 0);
84855- sys_symlink(collected + N_ALIGN(name_len), collected);
84856- sys_lchown(collected, uid, gid);
84857- do_utime(collected, mtime);
84858+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
84859+ sys_lchown((char __force_user *)collected, uid, gid);
84860+ do_utime((char __force_user *)collected, mtime);
84861 state = SkipIt;
84862 next_state = Reset;
84863 return 0;
84864diff --git a/init/main.c b/init/main.c
84865index 48655ce..d0113e4 100644
84866--- a/init/main.c
84867+++ b/init/main.c
84868@@ -97,6 +97,8 @@ extern void radix_tree_init(void);
84869 static inline void mark_rodata_ro(void) { }
84870 #endif
84871
84872+extern void grsecurity_init(void);
84873+
84874 /*
84875 * Debug helper: via this flag we know that we are in 'early bootup code'
84876 * where only the boot processor is running with IRQ disabled. This means
84877@@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
84878
84879 __setup("reset_devices", set_reset_devices);
84880
84881+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84882+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
84883+static int __init setup_grsec_proc_gid(char *str)
84884+{
84885+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
84886+ return 1;
84887+}
84888+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
84889+#endif
84890+
84891+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
84892+unsigned long pax_user_shadow_base __read_only;
84893+EXPORT_SYMBOL(pax_user_shadow_base);
84894+extern char pax_enter_kernel_user[];
84895+extern char pax_exit_kernel_user[];
84896+#endif
84897+
84898+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
84899+static int __init setup_pax_nouderef(char *str)
84900+{
84901+#ifdef CONFIG_X86_32
84902+ unsigned int cpu;
84903+ struct desc_struct *gdt;
84904+
84905+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
84906+ gdt = get_cpu_gdt_table(cpu);
84907+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
84908+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
84909+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
84910+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
84911+ }
84912+ loadsegment(ds, __KERNEL_DS);
84913+ loadsegment(es, __KERNEL_DS);
84914+ loadsegment(ss, __KERNEL_DS);
84915+#else
84916+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
84917+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
84918+ clone_pgd_mask = ~(pgdval_t)0UL;
84919+ pax_user_shadow_base = 0UL;
84920+ setup_clear_cpu_cap(X86_FEATURE_PCID);
84921+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
84922+#endif
84923+
84924+ return 0;
84925+}
84926+early_param("pax_nouderef", setup_pax_nouderef);
84927+
84928+#ifdef CONFIG_X86_64
84929+static int __init setup_pax_weakuderef(char *str)
84930+{
84931+ if (clone_pgd_mask != ~(pgdval_t)0UL)
84932+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84933+ return 1;
84934+}
84935+__setup("pax_weakuderef", setup_pax_weakuderef);
84936+#endif
84937+#endif
84938+
84939+#ifdef CONFIG_PAX_SOFTMODE
84940+int pax_softmode;
84941+
84942+static int __init setup_pax_softmode(char *str)
84943+{
84944+ get_option(&str, &pax_softmode);
84945+ return 1;
84946+}
84947+__setup("pax_softmode=", setup_pax_softmode);
84948+#endif
84949+
84950 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
84951 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
84952 static const char *panic_later, *panic_param;
84953@@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
84954 {
84955 int count = preempt_count();
84956 int ret;
84957- char msgbuf[64];
84958+ const char *msg1 = "", *msg2 = "";
84959
84960 if (initcall_debug)
84961 ret = do_one_initcall_debug(fn);
84962 else
84963 ret = fn();
84964
84965- msgbuf[0] = 0;
84966-
84967 if (preempt_count() != count) {
84968- sprintf(msgbuf, "preemption imbalance ");
84969+ msg1 = " preemption imbalance";
84970 preempt_count_set(count);
84971 }
84972 if (irqs_disabled()) {
84973- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
84974+ msg2 = " disabled interrupts";
84975 local_irq_enable();
84976 }
84977- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
84978+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
84979
84980+ add_latent_entropy();
84981 return ret;
84982 }
84983
84984@@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
84985 {
84986 argv_init[0] = init_filename;
84987 return do_execve(getname_kernel(init_filename),
84988- (const char __user *const __user *)argv_init,
84989- (const char __user *const __user *)envp_init);
84990+ (const char __user *const __force_user *)argv_init,
84991+ (const char __user *const __force_user *)envp_init);
84992 }
84993
84994 static int try_to_run_init_process(const char *init_filename)
84995@@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
84996 return ret;
84997 }
84998
84999+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85000+extern int gr_init_ran;
85001+#endif
85002+
85003 static noinline void __init kernel_init_freeable(void);
85004
85005 static int __ref kernel_init(void *unused)
85006@@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
85007 ramdisk_execute_command, ret);
85008 }
85009
85010+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85011+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
85012+ gr_init_ran = 1;
85013+#endif
85014+
85015 /*
85016 * We try each of these until one succeeds.
85017 *
85018@@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
85019 do_basic_setup();
85020
85021 /* Open the /dev/console on the rootfs, this should never fail */
85022- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
85023+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
85024 pr_err("Warning: unable to open an initial console.\n");
85025
85026 (void) sys_dup(0);
85027@@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
85028 if (!ramdisk_execute_command)
85029 ramdisk_execute_command = "/init";
85030
85031- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
85032+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
85033 ramdisk_execute_command = NULL;
85034 prepare_namespace();
85035 }
85036
85037+ grsecurity_init();
85038+
85039 /*
85040 * Ok, we have completed the initial bootup, and
85041 * we're essentially up and running. Get rid of the
85042diff --git a/ipc/compat.c b/ipc/compat.c
85043index 45d035d..e4a7f99 100644
85044--- a/ipc/compat.c
85045+++ b/ipc/compat.c
85046@@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
85047 COMPAT_SHMLBA);
85048 if (err < 0)
85049 return err;
85050- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
85051+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
85052 }
85053 case SHMDT:
85054 return sys_shmdt(compat_ptr(ptr));
85055diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
85056index 998d31b..30c24df 100644
85057--- a/ipc/ipc_sysctl.c
85058+++ b/ipc/ipc_sysctl.c
85059@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
85060 static int proc_ipc_dointvec(ctl_table *table, int write,
85061 void __user *buffer, size_t *lenp, loff_t *ppos)
85062 {
85063- struct ctl_table ipc_table;
85064+ ctl_table_no_const ipc_table;
85065
85066 memcpy(&ipc_table, table, sizeof(ipc_table));
85067 ipc_table.data = get_ipc(table);
85068@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85069 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85070 void __user *buffer, size_t *lenp, loff_t *ppos)
85071 {
85072- struct ctl_table ipc_table;
85073+ ctl_table_no_const ipc_table;
85074
85075 memcpy(&ipc_table, table, sizeof(ipc_table));
85076 ipc_table.data = get_ipc(table);
85077@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85078 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85079 void __user *buffer, size_t *lenp, loff_t *ppos)
85080 {
85081- struct ctl_table ipc_table;
85082+ ctl_table_no_const ipc_table;
85083 size_t lenp_bef = *lenp;
85084 int rc;
85085
85086@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85087 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85088 void __user *buffer, size_t *lenp, loff_t *ppos)
85089 {
85090- struct ctl_table ipc_table;
85091+ ctl_table_no_const ipc_table;
85092 memcpy(&ipc_table, table, sizeof(ipc_table));
85093 ipc_table.data = get_ipc(table);
85094
85095@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85096 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85097 void __user *buffer, size_t *lenp, loff_t *ppos)
85098 {
85099- struct ctl_table ipc_table;
85100+ ctl_table_no_const ipc_table;
85101 size_t lenp_bef = *lenp;
85102 int oldval;
85103 int rc;
85104diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85105index 5bb8bfe..a38ec05 100644
85106--- a/ipc/mq_sysctl.c
85107+++ b/ipc/mq_sysctl.c
85108@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85109 static int proc_mq_dointvec(ctl_table *table, int write,
85110 void __user *buffer, size_t *lenp, loff_t *ppos)
85111 {
85112- struct ctl_table mq_table;
85113+ ctl_table_no_const mq_table;
85114 memcpy(&mq_table, table, sizeof(mq_table));
85115 mq_table.data = get_mq(table);
85116
85117@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85118 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85119 void __user *buffer, size_t *lenp, loff_t *ppos)
85120 {
85121- struct ctl_table mq_table;
85122+ ctl_table_no_const mq_table;
85123 memcpy(&mq_table, table, sizeof(mq_table));
85124 mq_table.data = get_mq(table);
85125
85126diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85127index 4fcf39a..d3cc2ec 100644
85128--- a/ipc/mqueue.c
85129+++ b/ipc/mqueue.c
85130@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85131 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85132 info->attr.mq_msgsize);
85133
85134+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85135 spin_lock(&mq_lock);
85136 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85137 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85138diff --git a/ipc/msg.c b/ipc/msg.c
85139index 6498531..b0ff3c8 100644
85140--- a/ipc/msg.c
85141+++ b/ipc/msg.c
85142@@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85143 return security_msg_queue_associate(msq, msgflg);
85144 }
85145
85146+static struct ipc_ops msg_ops = {
85147+ .getnew = newque,
85148+ .associate = msg_security,
85149+ .more_checks = NULL
85150+};
85151+
85152 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85153 {
85154 struct ipc_namespace *ns;
85155- struct ipc_ops msg_ops;
85156 struct ipc_params msg_params;
85157
85158 ns = current->nsproxy->ipc_ns;
85159
85160- msg_ops.getnew = newque;
85161- msg_ops.associate = msg_security;
85162- msg_ops.more_checks = NULL;
85163-
85164 msg_params.key = key;
85165 msg_params.flg = msgflg;
85166
85167diff --git a/ipc/sem.c b/ipc/sem.c
85168index bee5554..e9af81dd 100644
85169--- a/ipc/sem.c
85170+++ b/ipc/sem.c
85171@@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85172 return 0;
85173 }
85174
85175+static struct ipc_ops sem_ops = {
85176+ .getnew = newary,
85177+ .associate = sem_security,
85178+ .more_checks = sem_more_checks
85179+};
85180+
85181 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85182 {
85183 struct ipc_namespace *ns;
85184- struct ipc_ops sem_ops;
85185 struct ipc_params sem_params;
85186
85187 ns = current->nsproxy->ipc_ns;
85188@@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85189 if (nsems < 0 || nsems > ns->sc_semmsl)
85190 return -EINVAL;
85191
85192- sem_ops.getnew = newary;
85193- sem_ops.associate = sem_security;
85194- sem_ops.more_checks = sem_more_checks;
85195-
85196 sem_params.key = key;
85197 sem_params.flg = semflg;
85198 sem_params.u.nsems = nsems;
85199diff --git a/ipc/shm.c b/ipc/shm.c
85200index 7645961..afc7f02 100644
85201--- a/ipc/shm.c
85202+++ b/ipc/shm.c
85203@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85204 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85205 #endif
85206
85207+#ifdef CONFIG_GRKERNSEC
85208+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85209+ const time_t shm_createtime, const kuid_t cuid,
85210+ const int shmid);
85211+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85212+ const time_t shm_createtime);
85213+#endif
85214+
85215 void shm_init_ns(struct ipc_namespace *ns)
85216 {
85217 ns->shm_ctlmax = SHMMAX;
85218@@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85219 shp->shm_lprid = 0;
85220 shp->shm_atim = shp->shm_dtim = 0;
85221 shp->shm_ctim = get_seconds();
85222+#ifdef CONFIG_GRKERNSEC
85223+ {
85224+ struct timespec timeval;
85225+ do_posix_clock_monotonic_gettime(&timeval);
85226+
85227+ shp->shm_createtime = timeval.tv_sec;
85228+ }
85229+#endif
85230 shp->shm_segsz = size;
85231 shp->shm_nattch = 0;
85232 shp->shm_file = file;
85233@@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85234 return 0;
85235 }
85236
85237+static struct ipc_ops shm_ops = {
85238+ .getnew = newseg,
85239+ .associate = shm_security,
85240+ .more_checks = shm_more_checks
85241+};
85242+
85243 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85244 {
85245 struct ipc_namespace *ns;
85246- struct ipc_ops shm_ops;
85247 struct ipc_params shm_params;
85248
85249 ns = current->nsproxy->ipc_ns;
85250
85251- shm_ops.getnew = newseg;
85252- shm_ops.associate = shm_security;
85253- shm_ops.more_checks = shm_more_checks;
85254-
85255 shm_params.key = key;
85256 shm_params.flg = shmflg;
85257 shm_params.u.size = size;
85258@@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85259 f_mode = FMODE_READ | FMODE_WRITE;
85260 }
85261 if (shmflg & SHM_EXEC) {
85262+
85263+#ifdef CONFIG_PAX_MPROTECT
85264+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
85265+ goto out;
85266+#endif
85267+
85268 prot |= PROT_EXEC;
85269 acc_mode |= S_IXUGO;
85270 }
85271@@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85272 if (err)
85273 goto out_unlock;
85274
85275+#ifdef CONFIG_GRKERNSEC
85276+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85277+ shp->shm_perm.cuid, shmid) ||
85278+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85279+ err = -EACCES;
85280+ goto out_unlock;
85281+ }
85282+#endif
85283+
85284 ipc_lock_object(&shp->shm_perm);
85285
85286 /* check if shm_destroy() is tearing down shp */
85287@@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85288 path = shp->shm_file->f_path;
85289 path_get(&path);
85290 shp->shm_nattch++;
85291+#ifdef CONFIG_GRKERNSEC
85292+ shp->shm_lapid = current->pid;
85293+#endif
85294 size = i_size_read(path.dentry->d_inode);
85295 ipc_unlock_object(&shp->shm_perm);
85296 rcu_read_unlock();
85297diff --git a/ipc/util.c b/ipc/util.c
85298index 2eb0d1e..0308564 100644
85299--- a/ipc/util.c
85300+++ b/ipc/util.c
85301@@ -71,6 +71,8 @@ struct ipc_proc_iface {
85302 int (*show)(struct seq_file *, void *);
85303 };
85304
85305+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85306+
85307 static void ipc_memory_notifier(struct work_struct *work)
85308 {
85309 ipcns_notify(IPCNS_MEMCHANGED);
85310@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85311 granted_mode >>= 6;
85312 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85313 granted_mode >>= 3;
85314+
85315+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85316+ return -1;
85317+
85318 /* is there some bit set in requested_mode but not in granted_mode? */
85319 if ((requested_mode & ~granted_mode & 0007) &&
85320 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85321diff --git a/kernel/acct.c b/kernel/acct.c
85322index 8d6e145..33e0b1e 100644
85323--- a/kernel/acct.c
85324+++ b/kernel/acct.c
85325@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85326 */
85327 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85328 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85329- file->f_op->write(file, (char *)&ac,
85330+ file->f_op->write(file, (char __force_user *)&ac,
85331 sizeof(acct_t), &file->f_pos);
85332 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85333 set_fs(fs);
85334diff --git a/kernel/audit.c b/kernel/audit.c
85335index 47845c5..bd9dd5b 100644
85336--- a/kernel/audit.c
85337+++ b/kernel/audit.c
85338@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85339 3) suppressed due to audit_rate_limit
85340 4) suppressed due to audit_backlog_limit
85341 */
85342-static atomic_t audit_lost = ATOMIC_INIT(0);
85343+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85344
85345 /* The netlink socket. */
85346 static struct sock *audit_sock;
85347@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85348 unsigned long now;
85349 int print;
85350
85351- atomic_inc(&audit_lost);
85352+ atomic_inc_unchecked(&audit_lost);
85353
85354 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85355
85356@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85357 if (print) {
85358 if (printk_ratelimit())
85359 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85360- atomic_read(&audit_lost),
85361+ atomic_read_unchecked(&audit_lost),
85362 audit_rate_limit,
85363 audit_backlog_limit);
85364 audit_panic(message);
85365@@ -808,7 +808,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85366 s.pid = audit_pid;
85367 s.rate_limit = audit_rate_limit;
85368 s.backlog_limit = audit_backlog_limit;
85369- s.lost = atomic_read(&audit_lost);
85370+ s.lost = atomic_read_unchecked(&audit_lost);
85371 s.backlog = skb_queue_len(&audit_skb_queue);
85372 s.version = AUDIT_VERSION_LATEST;
85373 s.backlog_wait_time = audit_backlog_wait_time;
85374diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85375index 21eae3c..66db239 100644
85376--- a/kernel/auditsc.c
85377+++ b/kernel/auditsc.c
85378@@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85379 }
85380
85381 /* global counter which is incremented every time something logs in */
85382-static atomic_t session_id = ATOMIC_INIT(0);
85383+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85384
85385 static int audit_set_loginuid_perm(kuid_t loginuid)
85386 {
85387@@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
85388
85389 /* are we setting or clearing? */
85390 if (uid_valid(loginuid))
85391- sessionid = (unsigned int)atomic_inc_return(&session_id);
85392+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85393
85394 task->sessionid = sessionid;
85395 task->loginuid = loginuid;
85396diff --git a/kernel/capability.c b/kernel/capability.c
85397index 24663b3..b926ae1 100644
85398--- a/kernel/capability.c
85399+++ b/kernel/capability.c
85400@@ -193,6 +193,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85401 * before modification is attempted and the application
85402 * fails.
85403 */
85404+ if (tocopy > ARRAY_SIZE(kdata))
85405+ return -EFAULT;
85406+
85407 if (copy_to_user(dataptr, kdata, tocopy
85408 * sizeof(struct __user_cap_data_struct))) {
85409 return -EFAULT;
85410@@ -294,10 +297,11 @@ bool has_ns_capability(struct task_struct *t,
85411 int ret;
85412
85413 rcu_read_lock();
85414- ret = security_capable(__task_cred(t), ns, cap);
85415+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85416+ gr_task_is_capable(t, __task_cred(t), cap);
85417 rcu_read_unlock();
85418
85419- return (ret == 0);
85420+ return ret;
85421 }
85422
85423 /**
85424@@ -334,10 +338,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85425 int ret;
85426
85427 rcu_read_lock();
85428- ret = security_capable_noaudit(__task_cred(t), ns, cap);
85429+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85430 rcu_read_unlock();
85431
85432- return (ret == 0);
85433+ return ret;
85434 }
85435
85436 /**
85437@@ -375,7 +379,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85438 BUG();
85439 }
85440
85441- if (security_capable(current_cred(), ns, cap) == 0) {
85442+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85443 current->flags |= PF_SUPERPRIV;
85444 return true;
85445 }
85446@@ -383,6 +387,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85447 }
85448 EXPORT_SYMBOL(ns_capable);
85449
85450+bool ns_capable_nolog(struct user_namespace *ns, int cap)
85451+{
85452+ if (unlikely(!cap_valid(cap))) {
85453+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85454+ BUG();
85455+ }
85456+
85457+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85458+ current->flags |= PF_SUPERPRIV;
85459+ return true;
85460+ }
85461+ return false;
85462+}
85463+EXPORT_SYMBOL(ns_capable_nolog);
85464+
85465 /**
85466 * file_ns_capable - Determine if the file's opener had a capability in effect
85467 * @file: The file we want to check
85468@@ -423,6 +442,12 @@ bool capable(int cap)
85469 }
85470 EXPORT_SYMBOL(capable);
85471
85472+bool capable_nolog(int cap)
85473+{
85474+ return ns_capable_nolog(&init_user_ns, cap);
85475+}
85476+EXPORT_SYMBOL(capable_nolog);
85477+
85478 /**
85479 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
85480 * @inode: The inode in question
85481@@ -440,3 +465,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
85482 kgid_has_mapping(ns, inode->i_gid);
85483 }
85484 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
85485+
85486+bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
85487+{
85488+ struct user_namespace *ns = current_user_ns();
85489+
85490+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
85491+ kgid_has_mapping(ns, inode->i_gid);
85492+}
85493+EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
85494diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85495index ceee0c5..d6f81dd 100644
85496--- a/kernel/cgroup.c
85497+++ b/kernel/cgroup.c
85498@@ -4757,7 +4757,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85499 struct task_struct *task;
85500 int count = 0;
85501
85502- seq_printf(seq, "css_set %p\n", cset);
85503+ seq_printf(seq, "css_set %pK\n", cset);
85504
85505 list_for_each_entry(task, &cset->tasks, cg_list) {
85506 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
85507diff --git a/kernel/compat.c b/kernel/compat.c
85508index e40b043..3da8f51 100644
85509--- a/kernel/compat.c
85510+++ b/kernel/compat.c
85511@@ -13,6 +13,7 @@
85512
85513 #include <linux/linkage.h>
85514 #include <linux/compat.h>
85515+#include <linux/module.h>
85516 #include <linux/errno.h>
85517 #include <linux/time.h>
85518 #include <linux/signal.h>
85519@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85520 mm_segment_t oldfs;
85521 long ret;
85522
85523- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85524+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85525 oldfs = get_fs();
85526 set_fs(KERNEL_DS);
85527 ret = hrtimer_nanosleep_restart(restart);
85528@@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
85529 oldfs = get_fs();
85530 set_fs(KERNEL_DS);
85531 ret = hrtimer_nanosleep(&tu,
85532- rmtp ? (struct timespec __user *)&rmt : NULL,
85533+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
85534 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85535 set_fs(oldfs);
85536
85537@@ -361,7 +362,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
85538 mm_segment_t old_fs = get_fs();
85539
85540 set_fs(KERNEL_DS);
85541- ret = sys_sigpending((old_sigset_t __user *) &s);
85542+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
85543 set_fs(old_fs);
85544 if (ret == 0)
85545 ret = put_user(s, set);
85546@@ -451,7 +452,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
85547 mm_segment_t old_fs = get_fs();
85548
85549 set_fs(KERNEL_DS);
85550- ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
85551+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85552 set_fs(old_fs);
85553
85554 if (!ret) {
85555@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85556 set_fs (KERNEL_DS);
85557 ret = sys_wait4(pid,
85558 (stat_addr ?
85559- (unsigned int __user *) &status : NULL),
85560- options, (struct rusage __user *) &r);
85561+ (unsigned int __force_user *) &status : NULL),
85562+ options, (struct rusage __force_user *) &r);
85563 set_fs (old_fs);
85564
85565 if (ret > 0) {
85566@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85567 memset(&info, 0, sizeof(info));
85568
85569 set_fs(KERNEL_DS);
85570- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85571- uru ? (struct rusage __user *)&ru : NULL);
85572+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85573+ uru ? (struct rusage __force_user *)&ru : NULL);
85574 set_fs(old_fs);
85575
85576 if ((ret < 0) || (info.si_signo == 0))
85577@@ -695,8 +696,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
85578 oldfs = get_fs();
85579 set_fs(KERNEL_DS);
85580 err = sys_timer_settime(timer_id, flags,
85581- (struct itimerspec __user *) &newts,
85582- (struct itimerspec __user *) &oldts);
85583+ (struct itimerspec __force_user *) &newts,
85584+ (struct itimerspec __force_user *) &oldts);
85585 set_fs(oldfs);
85586 if (!err && old && put_compat_itimerspec(old, &oldts))
85587 return -EFAULT;
85588@@ -713,7 +714,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
85589 oldfs = get_fs();
85590 set_fs(KERNEL_DS);
85591 err = sys_timer_gettime(timer_id,
85592- (struct itimerspec __user *) &ts);
85593+ (struct itimerspec __force_user *) &ts);
85594 set_fs(oldfs);
85595 if (!err && put_compat_itimerspec(setting, &ts))
85596 return -EFAULT;
85597@@ -732,7 +733,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
85598 oldfs = get_fs();
85599 set_fs(KERNEL_DS);
85600 err = sys_clock_settime(which_clock,
85601- (struct timespec __user *) &ts);
85602+ (struct timespec __force_user *) &ts);
85603 set_fs(oldfs);
85604 return err;
85605 }
85606@@ -747,7 +748,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
85607 oldfs = get_fs();
85608 set_fs(KERNEL_DS);
85609 err = sys_clock_gettime(which_clock,
85610- (struct timespec __user *) &ts);
85611+ (struct timespec __force_user *) &ts);
85612 set_fs(oldfs);
85613 if (!err && compat_put_timespec(&ts, tp))
85614 return -EFAULT;
85615@@ -767,7 +768,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
85616
85617 oldfs = get_fs();
85618 set_fs(KERNEL_DS);
85619- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85620+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85621 set_fs(oldfs);
85622
85623 err = compat_put_timex(utp, &txc);
85624@@ -787,7 +788,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
85625 oldfs = get_fs();
85626 set_fs(KERNEL_DS);
85627 err = sys_clock_getres(which_clock,
85628- (struct timespec __user *) &ts);
85629+ (struct timespec __force_user *) &ts);
85630 set_fs(oldfs);
85631 if (!err && tp && compat_put_timespec(&ts, tp))
85632 return -EFAULT;
85633@@ -801,7 +802,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85634 struct timespec tu;
85635 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85636
85637- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85638+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85639 oldfs = get_fs();
85640 set_fs(KERNEL_DS);
85641 err = clock_nanosleep_restart(restart);
85642@@ -833,8 +834,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
85643 oldfs = get_fs();
85644 set_fs(KERNEL_DS);
85645 err = sys_clock_nanosleep(which_clock, flags,
85646- (struct timespec __user *) &in,
85647- (struct timespec __user *) &out);
85648+ (struct timespec __force_user *) &in,
85649+ (struct timespec __force_user *) &out);
85650 set_fs(oldfs);
85651
85652 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85653@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85654 mm_segment_t old_fs = get_fs();
85655
85656 set_fs(KERNEL_DS);
85657- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85658+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85659 set_fs(old_fs);
85660 if (compat_put_timespec(&t, interval))
85661 return -EFAULT;
85662diff --git a/kernel/configs.c b/kernel/configs.c
85663index c18b1f1..b9a0132 100644
85664--- a/kernel/configs.c
85665+++ b/kernel/configs.c
85666@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85667 struct proc_dir_entry *entry;
85668
85669 /* create the current config file */
85670+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85671+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85672+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85673+ &ikconfig_file_ops);
85674+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85675+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
85676+ &ikconfig_file_ops);
85677+#endif
85678+#else
85679 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
85680 &ikconfig_file_ops);
85681+#endif
85682+
85683 if (!entry)
85684 return -ENOMEM;
85685
85686diff --git a/kernel/cred.c b/kernel/cred.c
85687index e0573a4..26c0fd3 100644
85688--- a/kernel/cred.c
85689+++ b/kernel/cred.c
85690@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85691 validate_creds(cred);
85692 alter_cred_subscribers(cred, -1);
85693 put_cred(cred);
85694+
85695+#ifdef CONFIG_GRKERNSEC_SETXID
85696+ cred = (struct cred *) tsk->delayed_cred;
85697+ if (cred != NULL) {
85698+ tsk->delayed_cred = NULL;
85699+ validate_creds(cred);
85700+ alter_cred_subscribers(cred, -1);
85701+ put_cred(cred);
85702+ }
85703+#endif
85704 }
85705
85706 /**
85707@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85708 * Always returns 0 thus allowing this function to be tail-called at the end
85709 * of, say, sys_setgid().
85710 */
85711-int commit_creds(struct cred *new)
85712+static int __commit_creds(struct cred *new)
85713 {
85714 struct task_struct *task = current;
85715 const struct cred *old = task->real_cred;
85716@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85717
85718 get_cred(new); /* we will require a ref for the subj creds too */
85719
85720+ gr_set_role_label(task, new->uid, new->gid);
85721+
85722 /* dumpability changes */
85723 if (!uid_eq(old->euid, new->euid) ||
85724 !gid_eq(old->egid, new->egid) ||
85725@@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
85726 put_cred(old);
85727 return 0;
85728 }
85729+#ifdef CONFIG_GRKERNSEC_SETXID
85730+extern int set_user(struct cred *new);
85731+
85732+void gr_delayed_cred_worker(void)
85733+{
85734+ const struct cred *new = current->delayed_cred;
85735+ struct cred *ncred;
85736+
85737+ current->delayed_cred = NULL;
85738+
85739+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85740+ // from doing get_cred on it when queueing this
85741+ put_cred(new);
85742+ return;
85743+ } else if (new == NULL)
85744+ return;
85745+
85746+ ncred = prepare_creds();
85747+ if (!ncred)
85748+ goto die;
85749+ // uids
85750+ ncred->uid = new->uid;
85751+ ncred->euid = new->euid;
85752+ ncred->suid = new->suid;
85753+ ncred->fsuid = new->fsuid;
85754+ // gids
85755+ ncred->gid = new->gid;
85756+ ncred->egid = new->egid;
85757+ ncred->sgid = new->sgid;
85758+ ncred->fsgid = new->fsgid;
85759+ // groups
85760+ set_groups(ncred, new->group_info);
85761+ // caps
85762+ ncred->securebits = new->securebits;
85763+ ncred->cap_inheritable = new->cap_inheritable;
85764+ ncred->cap_permitted = new->cap_permitted;
85765+ ncred->cap_effective = new->cap_effective;
85766+ ncred->cap_bset = new->cap_bset;
85767+
85768+ if (set_user(ncred)) {
85769+ abort_creds(ncred);
85770+ goto die;
85771+ }
85772+
85773+ // from doing get_cred on it when queueing this
85774+ put_cred(new);
85775+
85776+ __commit_creds(ncred);
85777+ return;
85778+die:
85779+ // from doing get_cred on it when queueing this
85780+ put_cred(new);
85781+ do_group_exit(SIGKILL);
85782+}
85783+#endif
85784+
85785+int commit_creds(struct cred *new)
85786+{
85787+#ifdef CONFIG_GRKERNSEC_SETXID
85788+ int ret;
85789+ int schedule_it = 0;
85790+ struct task_struct *t;
85791+ unsigned oldsecurebits = current_cred()->securebits;
85792+
85793+ /* we won't get called with tasklist_lock held for writing
85794+ and interrupts disabled as the cred struct in that case is
85795+ init_cred
85796+ */
85797+ if (grsec_enable_setxid && !current_is_single_threaded() &&
85798+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85799+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85800+ schedule_it = 1;
85801+ }
85802+ ret = __commit_creds(new);
85803+ if (schedule_it) {
85804+ rcu_read_lock();
85805+ read_lock(&tasklist_lock);
85806+ for (t = next_thread(current); t != current;
85807+ t = next_thread(t)) {
85808+ /* we'll check if the thread has uid 0 in
85809+ * the delayed worker routine
85810+ */
85811+ if (task_securebits(t) == oldsecurebits &&
85812+ t->delayed_cred == NULL) {
85813+ t->delayed_cred = get_cred(new);
85814+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85815+ set_tsk_need_resched(t);
85816+ }
85817+ }
85818+ read_unlock(&tasklist_lock);
85819+ rcu_read_unlock();
85820+ }
85821+
85822+ return ret;
85823+#else
85824+ return __commit_creds(new);
85825+#endif
85826+}
85827+
85828 EXPORT_SYMBOL(commit_creds);
85829
85830 /**
85831diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
85832index 2956c8d..cfe1e2e 100644
85833--- a/kernel/debug/debug_core.c
85834+++ b/kernel/debug/debug_core.c
85835@@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
85836 */
85837 static atomic_t masters_in_kgdb;
85838 static atomic_t slaves_in_kgdb;
85839-static atomic_t kgdb_break_tasklet_var;
85840+static atomic_unchecked_t kgdb_break_tasklet_var;
85841 atomic_t kgdb_setting_breakpoint;
85842
85843 struct task_struct *kgdb_usethread;
85844@@ -134,7 +134,7 @@ int kgdb_single_step;
85845 static pid_t kgdb_sstep_pid;
85846
85847 /* to keep track of the CPU which is doing the single stepping*/
85848-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85849+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85850
85851 /*
85852 * If you are debugging a problem where roundup (the collection of
85853@@ -549,7 +549,7 @@ return_normal:
85854 * kernel will only try for the value of sstep_tries before
85855 * giving up and continuing on.
85856 */
85857- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
85858+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
85859 (kgdb_info[cpu].task &&
85860 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
85861 atomic_set(&kgdb_active, -1);
85862@@ -647,8 +647,8 @@ cpu_master_loop:
85863 }
85864
85865 kgdb_restore:
85866- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
85867- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
85868+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
85869+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
85870 if (kgdb_info[sstep_cpu].task)
85871 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
85872 else
85873@@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
85874 static void kgdb_tasklet_bpt(unsigned long ing)
85875 {
85876 kgdb_breakpoint();
85877- atomic_set(&kgdb_break_tasklet_var, 0);
85878+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
85879 }
85880
85881 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
85882
85883 void kgdb_schedule_breakpoint(void)
85884 {
85885- if (atomic_read(&kgdb_break_tasklet_var) ||
85886+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
85887 atomic_read(&kgdb_active) != -1 ||
85888 atomic_read(&kgdb_setting_breakpoint))
85889 return;
85890- atomic_inc(&kgdb_break_tasklet_var);
85891+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
85892 tasklet_schedule(&kgdb_tasklet_breakpoint);
85893 }
85894 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
85895diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
85896index 0b097c8..11dd5c5 100644
85897--- a/kernel/debug/kdb/kdb_main.c
85898+++ b/kernel/debug/kdb/kdb_main.c
85899@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
85900 continue;
85901
85902 kdb_printf("%-20s%8u 0x%p ", mod->name,
85903- mod->core_size, (void *)mod);
85904+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
85905 #ifdef CONFIG_MODULE_UNLOAD
85906 kdb_printf("%4ld ", module_refcount(mod));
85907 #endif
85908@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
85909 kdb_printf(" (Loading)");
85910 else
85911 kdb_printf(" (Live)");
85912- kdb_printf(" 0x%p", mod->module_core);
85913+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
85914
85915 #ifdef CONFIG_MODULE_UNLOAD
85916 {
85917diff --git a/kernel/events/core.c b/kernel/events/core.c
85918index 440eefc..0909f02 100644
85919--- a/kernel/events/core.c
85920+++ b/kernel/events/core.c
85921@@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
85922 * 0 - disallow raw tracepoint access for unpriv
85923 * 1 - disallow cpu events for unpriv
85924 * 2 - disallow kernel profiling for unpriv
85925+ * 3 - disallow all unpriv perf event use
85926 */
85927-int sysctl_perf_event_paranoid __read_mostly = 1;
85928+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85929+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85930+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85931+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85932+#else
85933+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85934+#endif
85935
85936 /* Minimum for 512 kiB + 1 user control page */
85937 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85938@@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
85939
85940 tmp *= sysctl_perf_cpu_time_max_percent;
85941 do_div(tmp, 100);
85942- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85943+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
85944 }
85945
85946 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
85947@@ -291,7 +298,7 @@ void perf_sample_event_took(u64 sample_len_ns)
85948 }
85949 }
85950
85951-static atomic64_t perf_event_id;
85952+static atomic64_unchecked_t perf_event_id;
85953
85954 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
85955 enum event_type_t event_type);
85956@@ -3002,7 +3009,7 @@ static void __perf_event_read(void *info)
85957
85958 static inline u64 perf_event_count(struct perf_event *event)
85959 {
85960- return local64_read(&event->count) + atomic64_read(&event->child_count);
85961+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
85962 }
85963
85964 static u64 perf_event_read(struct perf_event *event)
85965@@ -3361,9 +3368,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
85966 mutex_lock(&event->child_mutex);
85967 total += perf_event_read(event);
85968 *enabled += event->total_time_enabled +
85969- atomic64_read(&event->child_total_time_enabled);
85970+ atomic64_read_unchecked(&event->child_total_time_enabled);
85971 *running += event->total_time_running +
85972- atomic64_read(&event->child_total_time_running);
85973+ atomic64_read_unchecked(&event->child_total_time_running);
85974
85975 list_for_each_entry(child, &event->child_list, child_list) {
85976 total += perf_event_read(child);
85977@@ -3792,10 +3799,10 @@ void perf_event_update_userpage(struct perf_event *event)
85978 userpg->offset -= local64_read(&event->hw.prev_count);
85979
85980 userpg->time_enabled = enabled +
85981- atomic64_read(&event->child_total_time_enabled);
85982+ atomic64_read_unchecked(&event->child_total_time_enabled);
85983
85984 userpg->time_running = running +
85985- atomic64_read(&event->child_total_time_running);
85986+ atomic64_read_unchecked(&event->child_total_time_running);
85987
85988 arch_perf_update_userpage(userpg, now);
85989
85990@@ -4359,7 +4366,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
85991
85992 /* Data. */
85993 sp = perf_user_stack_pointer(regs);
85994- rem = __output_copy_user(handle, (void *) sp, dump_size);
85995+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
85996 dyn_size = dump_size - rem;
85997
85998 perf_output_skip(handle, rem);
85999@@ -4450,11 +4457,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
86000 values[n++] = perf_event_count(event);
86001 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
86002 values[n++] = enabled +
86003- atomic64_read(&event->child_total_time_enabled);
86004+ atomic64_read_unchecked(&event->child_total_time_enabled);
86005 }
86006 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
86007 values[n++] = running +
86008- atomic64_read(&event->child_total_time_running);
86009+ atomic64_read_unchecked(&event->child_total_time_running);
86010 }
86011 if (read_format & PERF_FORMAT_ID)
86012 values[n++] = primary_event_id(event);
86013@@ -6733,7 +6740,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
86014 event->parent = parent_event;
86015
86016 event->ns = get_pid_ns(task_active_pid_ns(current));
86017- event->id = atomic64_inc_return(&perf_event_id);
86018+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
86019
86020 event->state = PERF_EVENT_STATE_INACTIVE;
86021
86022@@ -7015,6 +7022,11 @@ SYSCALL_DEFINE5(perf_event_open,
86023 if (flags & ~PERF_FLAG_ALL)
86024 return -EINVAL;
86025
86026+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86027+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
86028+ return -EACCES;
86029+#endif
86030+
86031 err = perf_copy_attr(attr_uptr, &attr);
86032 if (err)
86033 return err;
86034@@ -7353,10 +7365,10 @@ static void sync_child_event(struct perf_event *child_event,
86035 /*
86036 * Add back the child's count to the parent's count:
86037 */
86038- atomic64_add(child_val, &parent_event->child_count);
86039- atomic64_add(child_event->total_time_enabled,
86040+ atomic64_add_unchecked(child_val, &parent_event->child_count);
86041+ atomic64_add_unchecked(child_event->total_time_enabled,
86042 &parent_event->child_total_time_enabled);
86043- atomic64_add(child_event->total_time_running,
86044+ atomic64_add_unchecked(child_event->total_time_running,
86045 &parent_event->child_total_time_running);
86046
86047 /*
86048diff --git a/kernel/events/internal.h b/kernel/events/internal.h
86049index 569b2187..19940d9 100644
86050--- a/kernel/events/internal.h
86051+++ b/kernel/events/internal.h
86052@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
86053 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
86054 }
86055
86056-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
86057+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
86058 static inline unsigned long \
86059 func_name(struct perf_output_handle *handle, \
86060- const void *buf, unsigned long len) \
86061+ const void user *buf, unsigned long len) \
86062 { \
86063 unsigned long size, written; \
86064 \
86065@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86066 return 0;
86067 }
86068
86069-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86070+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86071
86072 static inline unsigned long
86073 memcpy_skip(void *dst, const void *src, unsigned long n)
86074@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86075 return 0;
86076 }
86077
86078-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86079+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86080
86081 #ifndef arch_perf_out_copy_user
86082 #define arch_perf_out_copy_user arch_perf_out_copy_user
86083@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86084 }
86085 #endif
86086
86087-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86088+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86089
86090 /* Callchain handling */
86091 extern struct perf_callchain_entry *
86092diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86093index 04709b6..d330828 100644
86094--- a/kernel/events/uprobes.c
86095+++ b/kernel/events/uprobes.c
86096@@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86097 {
86098 struct page *page;
86099 uprobe_opcode_t opcode;
86100- int result;
86101+ long result;
86102
86103 pagefault_disable();
86104 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86105diff --git a/kernel/exit.c b/kernel/exit.c
86106index 6ed6a1d..edecb0e 100644
86107--- a/kernel/exit.c
86108+++ b/kernel/exit.c
86109@@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86110 struct task_struct *leader;
86111 int zap_leader;
86112 repeat:
86113+#ifdef CONFIG_NET
86114+ gr_del_task_from_ip_table(p);
86115+#endif
86116+
86117 /* don't need to get the RCU readlock here - the process is dead and
86118 * can't be modifying its own credentials. But shut RCU-lockdep up */
86119 rcu_read_lock();
86120@@ -330,7 +334,7 @@ int allow_signal(int sig)
86121 * know it'll be handled, so that they don't get converted to
86122 * SIGKILL or just silently dropped.
86123 */
86124- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86125+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86126 recalc_sigpending();
86127 spin_unlock_irq(&current->sighand->siglock);
86128 return 0;
86129@@ -699,6 +703,8 @@ void do_exit(long code)
86130 struct task_struct *tsk = current;
86131 int group_dead;
86132
86133+ set_fs(USER_DS);
86134+
86135 profile_task_exit(tsk);
86136
86137 WARN_ON(blk_needs_flush_plug(tsk));
86138@@ -715,7 +721,6 @@ void do_exit(long code)
86139 * mm_release()->clear_child_tid() from writing to a user-controlled
86140 * kernel address.
86141 */
86142- set_fs(USER_DS);
86143
86144 ptrace_event(PTRACE_EVENT_EXIT, code);
86145
86146@@ -774,6 +779,9 @@ void do_exit(long code)
86147 tsk->exit_code = code;
86148 taskstats_exit(tsk, group_dead);
86149
86150+ gr_acl_handle_psacct(tsk, code);
86151+ gr_acl_handle_exit();
86152+
86153 exit_mm(tsk);
86154
86155 if (group_dead)
86156@@ -893,7 +901,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86157 * Take down every thread in the group. This is called by fatal signals
86158 * as well as by sys_exit_group (below).
86159 */
86160-void
86161+__noreturn void
86162 do_group_exit(int exit_code)
86163 {
86164 struct signal_struct *sig = current->signal;
86165diff --git a/kernel/fork.c b/kernel/fork.c
86166index 68b9226..0700bf6 100644
86167--- a/kernel/fork.c
86168+++ b/kernel/fork.c
86169@@ -183,6 +183,48 @@ void thread_info_cache_init(void)
86170 # endif
86171 #endif
86172
86173+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86174+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86175+ int node, void **lowmem_stack)
86176+{
86177+ struct page *pages[THREAD_SIZE / PAGE_SIZE];
86178+ void *ret = NULL;
86179+ unsigned int i;
86180+
86181+ *lowmem_stack = alloc_thread_info_node(tsk, node);
86182+ if (*lowmem_stack == NULL)
86183+ goto out;
86184+
86185+ for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
86186+ pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
86187+
86188+ /* use VM_IOREMAP to gain THREAD_SIZE alignment */
86189+ ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
86190+ if (ret == NULL) {
86191+ free_thread_info(*lowmem_stack);
86192+ *lowmem_stack = NULL;
86193+ }
86194+
86195+out:
86196+ return ret;
86197+}
86198+
86199+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86200+{
86201+ unmap_process_stacks(tsk);
86202+}
86203+#else
86204+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86205+ int node, void **lowmem_stack)
86206+{
86207+ return alloc_thread_info_node(tsk, node);
86208+}
86209+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86210+{
86211+ free_thread_info(ti);
86212+}
86213+#endif
86214+
86215 /* SLAB cache for signal_struct structures (tsk->signal) */
86216 static struct kmem_cache *signal_cachep;
86217
86218@@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
86219 /* SLAB cache for mm_struct structures (tsk->mm) */
86220 static struct kmem_cache *mm_cachep;
86221
86222-static void account_kernel_stack(struct thread_info *ti, int account)
86223+static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
86224 {
86225+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86226+ struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
86227+#else
86228 struct zone *zone = page_zone(virt_to_page(ti));
86229+#endif
86230
86231 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
86232 }
86233
86234 void free_task(struct task_struct *tsk)
86235 {
86236- account_kernel_stack(tsk->stack, -1);
86237+ account_kernel_stack(tsk, tsk->stack, -1);
86238 arch_release_thread_info(tsk->stack);
86239- free_thread_info(tsk->stack);
86240+ gr_free_thread_info(tsk, tsk->stack);
86241 rt_mutex_debug_task_free(tsk);
86242 ftrace_graph_exit_task(tsk);
86243 put_seccomp_filter(tsk);
86244@@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86245 struct task_struct *tsk;
86246 struct thread_info *ti;
86247 unsigned long *stackend;
86248+ void *lowmem_stack;
86249 int node = tsk_fork_get_node(orig);
86250 int err;
86251
86252@@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86253 if (!tsk)
86254 return NULL;
86255
86256- ti = alloc_thread_info_node(tsk, node);
86257+ ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
86258 if (!ti)
86259 goto free_tsk;
86260
86261@@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86262 goto free_ti;
86263
86264 tsk->stack = ti;
86265+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86266+ tsk->lowmem_stack = lowmem_stack;
86267+#endif
86268
86269 setup_thread_stack(tsk, orig);
86270 clear_user_return_notifier(tsk);
86271@@ -323,7 +373,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86272 *stackend = STACK_END_MAGIC; /* for overflow detection */
86273
86274 #ifdef CONFIG_CC_STACKPROTECTOR
86275- tsk->stack_canary = get_random_int();
86276+ tsk->stack_canary = pax_get_random_long();
86277 #endif
86278
86279 /*
86280@@ -337,24 +387,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86281 tsk->splice_pipe = NULL;
86282 tsk->task_frag.page = NULL;
86283
86284- account_kernel_stack(ti, 1);
86285+ account_kernel_stack(tsk, ti, 1);
86286
86287 return tsk;
86288
86289 free_ti:
86290- free_thread_info(ti);
86291+ gr_free_thread_info(tsk, ti);
86292 free_tsk:
86293 free_task_struct(tsk);
86294 return NULL;
86295 }
86296
86297 #ifdef CONFIG_MMU
86298-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86299+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
86300+{
86301+ struct vm_area_struct *tmp;
86302+ unsigned long charge;
86303+ struct file *file;
86304+ int retval;
86305+
86306+ charge = 0;
86307+ if (mpnt->vm_flags & VM_ACCOUNT) {
86308+ unsigned long len = vma_pages(mpnt);
86309+
86310+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86311+ goto fail_nomem;
86312+ charge = len;
86313+ }
86314+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86315+ if (!tmp)
86316+ goto fail_nomem;
86317+ *tmp = *mpnt;
86318+ tmp->vm_mm = mm;
86319+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
86320+ retval = vma_dup_policy(mpnt, tmp);
86321+ if (retval)
86322+ goto fail_nomem_policy;
86323+ if (anon_vma_fork(tmp, mpnt))
86324+ goto fail_nomem_anon_vma_fork;
86325+ tmp->vm_flags &= ~VM_LOCKED;
86326+ tmp->vm_next = tmp->vm_prev = NULL;
86327+ tmp->vm_mirror = NULL;
86328+ file = tmp->vm_file;
86329+ if (file) {
86330+ struct inode *inode = file_inode(file);
86331+ struct address_space *mapping = file->f_mapping;
86332+
86333+ get_file(file);
86334+ if (tmp->vm_flags & VM_DENYWRITE)
86335+ atomic_dec(&inode->i_writecount);
86336+ mutex_lock(&mapping->i_mmap_mutex);
86337+ if (tmp->vm_flags & VM_SHARED)
86338+ mapping->i_mmap_writable++;
86339+ flush_dcache_mmap_lock(mapping);
86340+ /* insert tmp into the share list, just after mpnt */
86341+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86342+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
86343+ else
86344+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
86345+ flush_dcache_mmap_unlock(mapping);
86346+ mutex_unlock(&mapping->i_mmap_mutex);
86347+ }
86348+
86349+ /*
86350+ * Clear hugetlb-related page reserves for children. This only
86351+ * affects MAP_PRIVATE mappings. Faults generated by the child
86352+ * are not guaranteed to succeed, even if read-only
86353+ */
86354+ if (is_vm_hugetlb_page(tmp))
86355+ reset_vma_resv_huge_pages(tmp);
86356+
86357+ return tmp;
86358+
86359+fail_nomem_anon_vma_fork:
86360+ mpol_put(vma_policy(tmp));
86361+fail_nomem_policy:
86362+ kmem_cache_free(vm_area_cachep, tmp);
86363+fail_nomem:
86364+ vm_unacct_memory(charge);
86365+ return NULL;
86366+}
86367+
86368+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86369 {
86370 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86371 struct rb_node **rb_link, *rb_parent;
86372 int retval;
86373- unsigned long charge;
86374
86375 uprobe_start_dup_mmap();
86376 down_write(&oldmm->mmap_sem);
86377@@ -383,55 +501,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86378
86379 prev = NULL;
86380 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86381- struct file *file;
86382-
86383 if (mpnt->vm_flags & VM_DONTCOPY) {
86384 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86385 -vma_pages(mpnt));
86386 continue;
86387 }
86388- charge = 0;
86389- if (mpnt->vm_flags & VM_ACCOUNT) {
86390- unsigned long len = vma_pages(mpnt);
86391-
86392- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86393- goto fail_nomem;
86394- charge = len;
86395- }
86396- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86397- if (!tmp)
86398- goto fail_nomem;
86399- *tmp = *mpnt;
86400- INIT_LIST_HEAD(&tmp->anon_vma_chain);
86401- retval = vma_dup_policy(mpnt, tmp);
86402- if (retval)
86403- goto fail_nomem_policy;
86404- tmp->vm_mm = mm;
86405- if (anon_vma_fork(tmp, mpnt))
86406- goto fail_nomem_anon_vma_fork;
86407- tmp->vm_flags &= ~VM_LOCKED;
86408- tmp->vm_next = tmp->vm_prev = NULL;
86409- file = tmp->vm_file;
86410- if (file) {
86411- struct inode *inode = file_inode(file);
86412- struct address_space *mapping = file->f_mapping;
86413-
86414- get_file(file);
86415- if (tmp->vm_flags & VM_DENYWRITE)
86416- atomic_dec(&inode->i_writecount);
86417- mutex_lock(&mapping->i_mmap_mutex);
86418- if (tmp->vm_flags & VM_SHARED)
86419- mapping->i_mmap_writable++;
86420- flush_dcache_mmap_lock(mapping);
86421- /* insert tmp into the share list, just after mpnt */
86422- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86423- vma_nonlinear_insert(tmp,
86424- &mapping->i_mmap_nonlinear);
86425- else
86426- vma_interval_tree_insert_after(tmp, mpnt,
86427- &mapping->i_mmap);
86428- flush_dcache_mmap_unlock(mapping);
86429- mutex_unlock(&mapping->i_mmap_mutex);
86430+ tmp = dup_vma(mm, oldmm, mpnt);
86431+ if (!tmp) {
86432+ retval = -ENOMEM;
86433+ goto out;
86434 }
86435
86436 /*
86437@@ -463,6 +541,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86438 if (retval)
86439 goto out;
86440 }
86441+
86442+#ifdef CONFIG_PAX_SEGMEXEC
86443+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86444+ struct vm_area_struct *mpnt_m;
86445+
86446+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86447+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86448+
86449+ if (!mpnt->vm_mirror)
86450+ continue;
86451+
86452+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86453+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86454+ mpnt->vm_mirror = mpnt_m;
86455+ } else {
86456+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86457+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86458+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86459+ mpnt->vm_mirror->vm_mirror = mpnt;
86460+ }
86461+ }
86462+ BUG_ON(mpnt_m);
86463+ }
86464+#endif
86465+
86466 /* a new mm has just been created */
86467 arch_dup_mmap(oldmm, mm);
86468 retval = 0;
86469@@ -472,14 +575,6 @@ out:
86470 up_write(&oldmm->mmap_sem);
86471 uprobe_end_dup_mmap();
86472 return retval;
86473-fail_nomem_anon_vma_fork:
86474- mpol_put(vma_policy(tmp));
86475-fail_nomem_policy:
86476- kmem_cache_free(vm_area_cachep, tmp);
86477-fail_nomem:
86478- retval = -ENOMEM;
86479- vm_unacct_memory(charge);
86480- goto out;
86481 }
86482
86483 static inline int mm_alloc_pgd(struct mm_struct *mm)
86484@@ -698,8 +793,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86485 return ERR_PTR(err);
86486
86487 mm = get_task_mm(task);
86488- if (mm && mm != current->mm &&
86489- !ptrace_may_access(task, mode)) {
86490+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86491+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86492 mmput(mm);
86493 mm = ERR_PTR(-EACCES);
86494 }
86495@@ -918,13 +1013,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86496 spin_unlock(&fs->lock);
86497 return -EAGAIN;
86498 }
86499- fs->users++;
86500+ atomic_inc(&fs->users);
86501 spin_unlock(&fs->lock);
86502 return 0;
86503 }
86504 tsk->fs = copy_fs_struct(fs);
86505 if (!tsk->fs)
86506 return -ENOMEM;
86507+ /* Carry through gr_chroot_dentry and is_chrooted instead
86508+ of recomputing it here. Already copied when the task struct
86509+ is duplicated. This allows pivot_root to not be treated as
86510+ a chroot
86511+ */
86512+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
86513+
86514 return 0;
86515 }
86516
86517@@ -1133,7 +1235,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86518 * parts of the process environment (as per the clone
86519 * flags). The actual kick-off is left to the caller.
86520 */
86521-static struct task_struct *copy_process(unsigned long clone_flags,
86522+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86523 unsigned long stack_start,
86524 unsigned long stack_size,
86525 int __user *child_tidptr,
86526@@ -1205,6 +1307,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86527 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86528 #endif
86529 retval = -EAGAIN;
86530+
86531+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86532+
86533 if (atomic_read(&p->real_cred->user->processes) >=
86534 task_rlimit(p, RLIMIT_NPROC)) {
86535 if (p->real_cred->user != INIT_USER &&
86536@@ -1452,6 +1557,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86537 goto bad_fork_free_pid;
86538 }
86539
86540+ /* synchronizes with gr_set_acls()
86541+ we need to call this past the point of no return for fork()
86542+ */
86543+ gr_copy_label(p);
86544+
86545 if (likely(p->pid)) {
86546 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86547
86548@@ -1541,6 +1651,8 @@ bad_fork_cleanup_count:
86549 bad_fork_free:
86550 free_task(p);
86551 fork_out:
86552+ gr_log_forkfail(retval);
86553+
86554 return ERR_PTR(retval);
86555 }
86556
86557@@ -1602,6 +1714,7 @@ long do_fork(unsigned long clone_flags,
86558
86559 p = copy_process(clone_flags, stack_start, stack_size,
86560 child_tidptr, NULL, trace);
86561+ add_latent_entropy();
86562 /*
86563 * Do this prior waking up the new thread - the thread pointer
86564 * might get invalid after that point, if the thread exits quickly.
86565@@ -1618,6 +1731,8 @@ long do_fork(unsigned long clone_flags,
86566 if (clone_flags & CLONE_PARENT_SETTID)
86567 put_user(nr, parent_tidptr);
86568
86569+ gr_handle_brute_check();
86570+
86571 if (clone_flags & CLONE_VFORK) {
86572 p->vfork_done = &vfork;
86573 init_completion(&vfork);
86574@@ -1736,7 +1851,7 @@ void __init proc_caches_init(void)
86575 mm_cachep = kmem_cache_create("mm_struct",
86576 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
86577 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
86578- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
86579+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
86580 mmap_init();
86581 nsproxy_cache_init();
86582 }
86583@@ -1776,7 +1891,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
86584 return 0;
86585
86586 /* don't need lock here; in the worst case we'll do useless copy */
86587- if (fs->users == 1)
86588+ if (atomic_read(&fs->users) == 1)
86589 return 0;
86590
86591 *new_fsp = copy_fs_struct(fs);
86592@@ -1883,7 +1998,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
86593 fs = current->fs;
86594 spin_lock(&fs->lock);
86595 current->fs = new_fs;
86596- if (--fs->users)
86597+ gr_set_chroot_entries(current, &current->fs->root);
86598+ if (atomic_dec_return(&fs->users))
86599 new_fs = NULL;
86600 else
86601 new_fs = fs;
86602diff --git a/kernel/futex.c b/kernel/futex.c
86603index de938d2..c566038 100644
86604--- a/kernel/futex.c
86605+++ b/kernel/futex.c
86606@@ -202,7 +202,7 @@ struct futex_pi_state {
86607 atomic_t refcount;
86608
86609 union futex_key key;
86610-};
86611+} __randomize_layout;
86612
86613 /**
86614 * struct futex_q - The hashed futex queue entry, one per waiting task
86615@@ -236,7 +236,7 @@ struct futex_q {
86616 struct rt_mutex_waiter *rt_waiter;
86617 union futex_key *requeue_pi_key;
86618 u32 bitset;
86619-};
86620+} __randomize_layout;
86621
86622 static const struct futex_q futex_q_init = {
86623 /* list gets initialized in queue_me()*/
86624@@ -394,6 +394,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86625 struct page *page, *page_head;
86626 int err, ro = 0;
86627
86628+#ifdef CONFIG_PAX_SEGMEXEC
86629+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86630+ return -EFAULT;
86631+#endif
86632+
86633 /*
86634 * The futex address must be "naturally" aligned.
86635 */
86636@@ -593,7 +598,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
86637
86638 static int get_futex_value_locked(u32 *dest, u32 __user *from)
86639 {
86640- int ret;
86641+ unsigned long ret;
86642
86643 pagefault_disable();
86644 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
86645@@ -3033,6 +3038,7 @@ static void __init futex_detect_cmpxchg(void)
86646 {
86647 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
86648 u32 curval;
86649+ mm_segment_t oldfs;
86650
86651 /*
86652 * This will fail and we want it. Some arch implementations do
86653@@ -3044,8 +3050,11 @@ static void __init futex_detect_cmpxchg(void)
86654 * implementation, the non-functional ones will return
86655 * -ENOSYS.
86656 */
86657+ oldfs = get_fs();
86658+ set_fs(USER_DS);
86659 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
86660 futex_cmpxchg_enabled = 1;
86661+ set_fs(oldfs);
86662 #endif
86663 }
86664
86665diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
86666index 55c8c93..9ba7ad6 100644
86667--- a/kernel/futex_compat.c
86668+++ b/kernel/futex_compat.c
86669@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
86670 return 0;
86671 }
86672
86673-static void __user *futex_uaddr(struct robust_list __user *entry,
86674+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
86675 compat_long_t futex_offset)
86676 {
86677 compat_uptr_t base = ptr_to_compat(entry);
86678diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
86679index f45b75b..bfac6d5 100644
86680--- a/kernel/gcov/base.c
86681+++ b/kernel/gcov/base.c
86682@@ -108,11 +108,6 @@ void gcov_enable_events(void)
86683 }
86684
86685 #ifdef CONFIG_MODULES
86686-static inline int within(void *addr, void *start, unsigned long size)
86687-{
86688- return ((addr >= start) && (addr < start + size));
86689-}
86690-
86691 /* Update list and generate events when modules are unloaded. */
86692 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86693 void *data)
86694@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86695
86696 /* Remove entries located in module from linked list. */
86697 while ((info = gcov_info_next(info))) {
86698- if (within(info, mod->module_core, mod->core_size)) {
86699+ if (within_module_core_rw((unsigned long)info, mod)) {
86700 gcov_info_unlink(prev, info);
86701 if (gcov_events_enabled)
86702 gcov_event(GCOV_REMOVE, info);
86703diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
86704index e0501fe..312edd6 100644
86705--- a/kernel/hrtimer.c
86706+++ b/kernel/hrtimer.c
86707@@ -1448,7 +1448,7 @@ void hrtimer_peek_ahead_timers(void)
86708 local_irq_restore(flags);
86709 }
86710
86711-static void run_hrtimer_softirq(struct softirq_action *h)
86712+static __latent_entropy void run_hrtimer_softirq(void)
86713 {
86714 hrtimer_peek_ahead_timers();
86715 }
86716diff --git a/kernel/irq_work.c b/kernel/irq_work.c
86717index a82170e..5b01e7f 100644
86718--- a/kernel/irq_work.c
86719+++ b/kernel/irq_work.c
86720@@ -191,12 +191,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
86721 return NOTIFY_OK;
86722 }
86723
86724-static struct notifier_block cpu_notify;
86725+static struct notifier_block cpu_notify = {
86726+ .notifier_call = irq_work_cpu_notify,
86727+ .priority = 0,
86728+};
86729
86730 static __init int irq_work_init_cpu_notifier(void)
86731 {
86732- cpu_notify.notifier_call = irq_work_cpu_notify;
86733- cpu_notify.priority = 0;
86734 register_cpu_notifier(&cpu_notify);
86735 return 0;
86736 }
86737diff --git a/kernel/jump_label.c b/kernel/jump_label.c
86738index 9019f15..9a3c42e 100644
86739--- a/kernel/jump_label.c
86740+++ b/kernel/jump_label.c
86741@@ -14,6 +14,7 @@
86742 #include <linux/err.h>
86743 #include <linux/static_key.h>
86744 #include <linux/jump_label_ratelimit.h>
86745+#include <linux/mm.h>
86746
86747 #ifdef HAVE_JUMP_LABEL
86748
86749@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86750
86751 size = (((unsigned long)stop - (unsigned long)start)
86752 / sizeof(struct jump_entry));
86753+ pax_open_kernel();
86754 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86755+ pax_close_kernel();
86756 }
86757
86758 static void jump_label_update(struct static_key *key, int enable);
86759@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86760 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86761 struct jump_entry *iter;
86762
86763+ pax_open_kernel();
86764 for (iter = iter_start; iter < iter_stop; iter++) {
86765 if (within_module_init(iter->code, mod))
86766 iter->code = 0;
86767 }
86768+ pax_close_kernel();
86769 }
86770
86771 static int
86772diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
86773index cb0cf37..b69e161 100644
86774--- a/kernel/kallsyms.c
86775+++ b/kernel/kallsyms.c
86776@@ -11,6 +11,9 @@
86777 * Changed the compression method from stem compression to "table lookup"
86778 * compression (see scripts/kallsyms.c for a more complete description)
86779 */
86780+#ifdef CONFIG_GRKERNSEC_HIDESYM
86781+#define __INCLUDED_BY_HIDESYM 1
86782+#endif
86783 #include <linux/kallsyms.h>
86784 #include <linux/module.h>
86785 #include <linux/init.h>
86786@@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
86787
86788 static inline int is_kernel_inittext(unsigned long addr)
86789 {
86790+ if (system_state != SYSTEM_BOOTING)
86791+ return 0;
86792+
86793 if (addr >= (unsigned long)_sinittext
86794 && addr <= (unsigned long)_einittext)
86795 return 1;
86796 return 0;
86797 }
86798
86799+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86800+#ifdef CONFIG_MODULES
86801+static inline int is_module_text(unsigned long addr)
86802+{
86803+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
86804+ return 1;
86805+
86806+ addr = ktla_ktva(addr);
86807+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
86808+}
86809+#else
86810+static inline int is_module_text(unsigned long addr)
86811+{
86812+ return 0;
86813+}
86814+#endif
86815+#endif
86816+
86817 static inline int is_kernel_text(unsigned long addr)
86818 {
86819 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86820@@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
86821
86822 static inline int is_kernel(unsigned long addr)
86823 {
86824+
86825+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86826+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
86827+ return 1;
86828+
86829+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86830+#else
86831 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86832+#endif
86833+
86834 return 1;
86835 return in_gate_area_no_mm(addr);
86836 }
86837
86838 static int is_ksym_addr(unsigned long addr)
86839 {
86840+
86841+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86842+ if (is_module_text(addr))
86843+ return 0;
86844+#endif
86845+
86846 if (all_var)
86847 return is_kernel(addr);
86848
86849@@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86850
86851 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86852 {
86853- iter->name[0] = '\0';
86854 iter->nameoff = get_symbol_offset(new_pos);
86855 iter->pos = new_pos;
86856 }
86857@@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
86858 {
86859 struct kallsym_iter *iter = m->private;
86860
86861+#ifdef CONFIG_GRKERNSEC_HIDESYM
86862+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86863+ return 0;
86864+#endif
86865+
86866 /* Some debugging symbols have no name. Ignore them. */
86867 if (!iter->name[0])
86868 return 0;
86869@@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
86870 */
86871 type = iter->exported ? toupper(iter->type) :
86872 tolower(iter->type);
86873+
86874 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
86875 type, iter->name, iter->module_name);
86876 } else
86877@@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
86878 struct kallsym_iter *iter;
86879 int ret;
86880
86881- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86882+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86883 if (!iter)
86884 return -ENOMEM;
86885 reset_iter(iter, 0);
86886diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86887index e30ac0f..3528cac 100644
86888--- a/kernel/kcmp.c
86889+++ b/kernel/kcmp.c
86890@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86891 struct task_struct *task1, *task2;
86892 int ret;
86893
86894+#ifdef CONFIG_GRKERNSEC
86895+ return -ENOSYS;
86896+#endif
86897+
86898 rcu_read_lock();
86899
86900 /*
86901diff --git a/kernel/kexec.c b/kernel/kexec.c
86902index 28c5706..bfc8388 100644
86903--- a/kernel/kexec.c
86904+++ b/kernel/kexec.c
86905@@ -1046,7 +1046,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
86906 compat_ulong_t, flags)
86907 {
86908 struct compat_kexec_segment in;
86909- struct kexec_segment out, __user *ksegments;
86910+ struct kexec_segment out;
86911+ struct kexec_segment __user *ksegments;
86912 unsigned long i, result;
86913
86914 /* Don't allow clients that don't understand the native
86915diff --git a/kernel/kmod.c b/kernel/kmod.c
86916index 6b375af..eaff670 100644
86917--- a/kernel/kmod.c
86918+++ b/kernel/kmod.c
86919@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86920 kfree(info->argv);
86921 }
86922
86923-static int call_modprobe(char *module_name, int wait)
86924+static int call_modprobe(char *module_name, char *module_param, int wait)
86925 {
86926 struct subprocess_info *info;
86927 static char *envp[] = {
86928@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86929 NULL
86930 };
86931
86932- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86933+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86934 if (!argv)
86935 goto out;
86936
86937@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86938 argv[1] = "-q";
86939 argv[2] = "--";
86940 argv[3] = module_name; /* check free_modprobe_argv() */
86941- argv[4] = NULL;
86942+ argv[4] = module_param;
86943+ argv[5] = NULL;
86944
86945 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
86946 NULL, free_modprobe_argv, NULL);
86947@@ -129,9 +130,8 @@ out:
86948 * If module auto-loading support is disabled then this function
86949 * becomes a no-operation.
86950 */
86951-int __request_module(bool wait, const char *fmt, ...)
86952+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
86953 {
86954- va_list args;
86955 char module_name[MODULE_NAME_LEN];
86956 unsigned int max_modprobes;
86957 int ret;
86958@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
86959 if (!modprobe_path[0])
86960 return 0;
86961
86962- va_start(args, fmt);
86963- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
86964- va_end(args);
86965+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
86966 if (ret >= MODULE_NAME_LEN)
86967 return -ENAMETOOLONG;
86968
86969@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
86970 if (ret)
86971 return ret;
86972
86973+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86974+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86975+ /* hack to workaround consolekit/udisks stupidity */
86976+ read_lock(&tasklist_lock);
86977+ if (!strcmp(current->comm, "mount") &&
86978+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
86979+ read_unlock(&tasklist_lock);
86980+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
86981+ return -EPERM;
86982+ }
86983+ read_unlock(&tasklist_lock);
86984+ }
86985+#endif
86986+
86987 /* If modprobe needs a service that is in a module, we get a recursive
86988 * loop. Limit the number of running kmod threads to max_threads/2 or
86989 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
86990@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
86991
86992 trace_module_request(module_name, wait, _RET_IP_);
86993
86994- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86995+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86996
86997 atomic_dec(&kmod_concurrent);
86998 return ret;
86999 }
87000+
87001+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
87002+{
87003+ va_list args;
87004+ int ret;
87005+
87006+ va_start(args, fmt);
87007+ ret = ____request_module(wait, module_param, fmt, args);
87008+ va_end(args);
87009+
87010+ return ret;
87011+}
87012+
87013+int __request_module(bool wait, const char *fmt, ...)
87014+{
87015+ va_list args;
87016+ int ret;
87017+
87018+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87019+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87020+ char module_param[MODULE_NAME_LEN];
87021+
87022+ memset(module_param, 0, sizeof(module_param));
87023+
87024+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
87025+
87026+ va_start(args, fmt);
87027+ ret = ____request_module(wait, module_param, fmt, args);
87028+ va_end(args);
87029+
87030+ return ret;
87031+ }
87032+#endif
87033+
87034+ va_start(args, fmt);
87035+ ret = ____request_module(wait, NULL, fmt, args);
87036+ va_end(args);
87037+
87038+ return ret;
87039+}
87040+
87041 EXPORT_SYMBOL(__request_module);
87042 #endif /* CONFIG_MODULES */
87043
87044@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
87045 */
87046 set_user_nice(current, 0);
87047
87048+#ifdef CONFIG_GRKERNSEC
87049+ /* this is race-free as far as userland is concerned as we copied
87050+ out the path to be used prior to this point and are now operating
87051+ on that copy
87052+ */
87053+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
87054+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
87055+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
87056+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
87057+ retval = -EPERM;
87058+ goto fail;
87059+ }
87060+#endif
87061+
87062 retval = -ENOMEM;
87063 new = prepare_kernel_cred(current);
87064 if (!new)
87065@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87066 commit_creds(new);
87067
87068 retval = do_execve(getname_kernel(sub_info->path),
87069- (const char __user *const __user *)sub_info->argv,
87070- (const char __user *const __user *)sub_info->envp);
87071+ (const char __user *const __force_user *)sub_info->argv,
87072+ (const char __user *const __force_user *)sub_info->envp);
87073 if (!retval)
87074 return 0;
87075
87076@@ -260,6 +327,10 @@ static int call_helper(void *data)
87077
87078 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87079 {
87080+#ifdef CONFIG_GRKERNSEC
87081+ kfree(info->path);
87082+ info->path = info->origpath;
87083+#endif
87084 if (info->cleanup)
87085 (*info->cleanup)(info);
87086 kfree(info);
87087@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87088 *
87089 * Thus the __user pointer cast is valid here.
87090 */
87091- sys_wait4(pid, (int __user *)&ret, 0, NULL);
87092+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87093
87094 /*
87095 * If ret is 0, either ____call_usermodehelper failed and the
87096@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87097 goto out;
87098
87099 INIT_WORK(&sub_info->work, __call_usermodehelper);
87100+#ifdef CONFIG_GRKERNSEC
87101+ sub_info->origpath = path;
87102+ sub_info->path = kstrdup(path, gfp_mask);
87103+#else
87104 sub_info->path = path;
87105+#endif
87106 sub_info->argv = argv;
87107 sub_info->envp = envp;
87108
87109@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87110 static int proc_cap_handler(struct ctl_table *table, int write,
87111 void __user *buffer, size_t *lenp, loff_t *ppos)
87112 {
87113- struct ctl_table t;
87114+ ctl_table_no_const t;
87115 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87116 kernel_cap_t new_cap;
87117 int err, i;
87118diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87119index ceeadfc..11c18b6 100644
87120--- a/kernel/kprobes.c
87121+++ b/kernel/kprobes.c
87122@@ -31,6 +31,9 @@
87123 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87124 * <prasanna@in.ibm.com> added function-return probes.
87125 */
87126+#ifdef CONFIG_GRKERNSEC_HIDESYM
87127+#define __INCLUDED_BY_HIDESYM 1
87128+#endif
87129 #include <linux/kprobes.h>
87130 #include <linux/hash.h>
87131 #include <linux/init.h>
87132@@ -135,12 +138,12 @@ enum kprobe_slot_state {
87133
87134 static void *alloc_insn_page(void)
87135 {
87136- return module_alloc(PAGE_SIZE);
87137+ return module_alloc_exec(PAGE_SIZE);
87138 }
87139
87140 static void free_insn_page(void *page)
87141 {
87142- module_free(NULL, page);
87143+ module_free_exec(NULL, page);
87144 }
87145
87146 struct kprobe_insn_cache kprobe_insn_slots = {
87147@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87148 kprobe_type = "k";
87149
87150 if (sym)
87151- seq_printf(pi, "%p %s %s+0x%x %s ",
87152+ seq_printf(pi, "%pK %s %s+0x%x %s ",
87153 p->addr, kprobe_type, sym, offset,
87154 (modname ? modname : " "));
87155 else
87156- seq_printf(pi, "%p %s %p ",
87157+ seq_printf(pi, "%pK %s %pK ",
87158 p->addr, kprobe_type, p->addr);
87159
87160 if (!pp)
87161diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87162index 2495a9b..071b906 100644
87163--- a/kernel/ksysfs.c
87164+++ b/kernel/ksysfs.c
87165@@ -49,6 +49,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87166 {
87167 if (count+1 > UEVENT_HELPER_PATH_LEN)
87168 return -ENOENT;
87169+ if (!capable(CAP_SYS_ADMIN))
87170+ return -EPERM;
87171 memcpy(uevent_helper, buf, count);
87172 uevent_helper[count] = '\0';
87173 if (count && uevent_helper[count-1] == '\n')
87174@@ -175,7 +177,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87175 return count;
87176 }
87177
87178-static struct bin_attribute notes_attr = {
87179+static bin_attribute_no_const notes_attr __read_only = {
87180 .attr = {
87181 .name = "notes",
87182 .mode = S_IRUGO,
87183diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87184index d24e433..fa04fb8 100644
87185--- a/kernel/locking/lockdep.c
87186+++ b/kernel/locking/lockdep.c
87187@@ -597,6 +597,10 @@ static int static_obj(void *obj)
87188 end = (unsigned long) &_end,
87189 addr = (unsigned long) obj;
87190
87191+#ifdef CONFIG_PAX_KERNEXEC
87192+ start = ktla_ktva(start);
87193+#endif
87194+
87195 /*
87196 * static variable?
87197 */
87198@@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87199 if (!static_obj(lock->key)) {
87200 debug_locks_off();
87201 printk("INFO: trying to register non-static key.\n");
87202+ printk("lock:%pS key:%pS.\n", lock, lock->key);
87203 printk("the code is fine but needs lockdep annotation.\n");
87204 printk("turning off the locking correctness validator.\n");
87205 dump_stack();
87206@@ -3079,7 +3084,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87207 if (!class)
87208 return 0;
87209 }
87210- atomic_inc((atomic_t *)&class->ops);
87211+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87212 if (very_verbose(class)) {
87213 printk("\nacquire class [%p] %s", class->key, class->name);
87214 if (class->name_version > 1)
87215diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87216index ef43ac4..2720dfa 100644
87217--- a/kernel/locking/lockdep_proc.c
87218+++ b/kernel/locking/lockdep_proc.c
87219@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87220 return 0;
87221 }
87222
87223- seq_printf(m, "%p", class->key);
87224+ seq_printf(m, "%pK", class->key);
87225 #ifdef CONFIG_DEBUG_LOCKDEP
87226 seq_printf(m, " OPS:%8ld", class->ops);
87227 #endif
87228@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87229
87230 list_for_each_entry(entry, &class->locks_after, entry) {
87231 if (entry->distance == 1) {
87232- seq_printf(m, " -> [%p] ", entry->class->key);
87233+ seq_printf(m, " -> [%pK] ", entry->class->key);
87234 print_name(m, entry->class);
87235 seq_puts(m, "\n");
87236 }
87237@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87238 if (!class->key)
87239 continue;
87240
87241- seq_printf(m, "[%p] ", class->key);
87242+ seq_printf(m, "[%pK] ", class->key);
87243 print_name(m, class);
87244 seq_puts(m, "\n");
87245 }
87246@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87247 if (!i)
87248 seq_line(m, '-', 40-namelen, namelen);
87249
87250- snprintf(ip, sizeof(ip), "[<%p>]",
87251+ snprintf(ip, sizeof(ip), "[<%pK>]",
87252 (void *)class->contention_point[i]);
87253 seq_printf(m, "%40s %14lu %29s %pS\n",
87254 name, stats->contention_point[i],
87255@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87256 if (!i)
87257 seq_line(m, '-', 40-namelen, namelen);
87258
87259- snprintf(ip, sizeof(ip), "[<%p>]",
87260+ snprintf(ip, sizeof(ip), "[<%pK>]",
87261 (void *)class->contending_point[i]);
87262 seq_printf(m, "%40s %14lu %29s %pS\n",
87263 name, stats->contending_point[i],
87264diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
87265index 838dc9e..760e158 100644
87266--- a/kernel/locking/mcs_spinlock.c
87267+++ b/kernel/locking/mcs_spinlock.c
87268@@ -71,7 +71,7 @@ bool osq_lock(struct optimistic_spin_queue **lock)
87269 if (likely(prev == NULL))
87270 return true;
87271
87272- ACCESS_ONCE(prev->next) = node;
87273+ ACCESS_ONCE_RW(prev->next) = node;
87274
87275 /*
87276 * Normally @prev is untouchable after the above store; because at that
87277@@ -143,8 +143,8 @@ unqueue:
87278 * it will wait in Step-A.
87279 */
87280
87281- ACCESS_ONCE(next->prev) = prev;
87282- ACCESS_ONCE(prev->next) = next;
87283+ ACCESS_ONCE_RW(next->prev) = prev;
87284+ ACCESS_ONCE_RW(prev->next) = next;
87285
87286 return false;
87287 }
87288@@ -165,13 +165,13 @@ void osq_unlock(struct optimistic_spin_queue **lock)
87289 */
87290 next = xchg(&node->next, NULL);
87291 if (next) {
87292- ACCESS_ONCE(next->locked) = 1;
87293+ ACCESS_ONCE_RW(next->locked) = 1;
87294 return;
87295 }
87296
87297 next = osq_wait_next(lock, node, NULL);
87298 if (next)
87299- ACCESS_ONCE(next->locked) = 1;
87300+ ACCESS_ONCE_RW(next->locked) = 1;
87301 }
87302
87303 #endif
87304diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
87305index a2dbac4..e02a34a 100644
87306--- a/kernel/locking/mcs_spinlock.h
87307+++ b/kernel/locking/mcs_spinlock.h
87308@@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
87309 */
87310 return;
87311 }
87312- ACCESS_ONCE(prev->next) = node;
87313+ ACCESS_ONCE_RW(prev->next) = node;
87314
87315 /* Wait until the lock holder passes the lock down. */
87316 arch_mcs_spin_lock_contended(&node->locked);
87317diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
87318index 5cf6731..ce3bc5a 100644
87319--- a/kernel/locking/mutex-debug.c
87320+++ b/kernel/locking/mutex-debug.c
87321@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
87322 }
87323
87324 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87325- struct thread_info *ti)
87326+ struct task_struct *task)
87327 {
87328 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
87329
87330 /* Mark the current thread as blocked on the lock: */
87331- ti->task->blocked_on = waiter;
87332+ task->blocked_on = waiter;
87333 }
87334
87335 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87336- struct thread_info *ti)
87337+ struct task_struct *task)
87338 {
87339 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
87340- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
87341- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
87342- ti->task->blocked_on = NULL;
87343+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
87344+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
87345+ task->blocked_on = NULL;
87346
87347 list_del_init(&waiter->list);
87348 waiter->task = NULL;
87349diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
87350index 0799fd3..d06ae3b 100644
87351--- a/kernel/locking/mutex-debug.h
87352+++ b/kernel/locking/mutex-debug.h
87353@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
87354 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
87355 extern void debug_mutex_add_waiter(struct mutex *lock,
87356 struct mutex_waiter *waiter,
87357- struct thread_info *ti);
87358+ struct task_struct *task);
87359 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87360- struct thread_info *ti);
87361+ struct task_struct *task);
87362 extern void debug_mutex_unlock(struct mutex *lock);
87363 extern void debug_mutex_init(struct mutex *lock, const char *name,
87364 struct lock_class_key *key);
87365diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
87366index bc73d33..6f308aa 100644
87367--- a/kernel/locking/mutex.c
87368+++ b/kernel/locking/mutex.c
87369@@ -490,7 +490,7 @@ slowpath:
87370 goto skip_wait;
87371
87372 debug_mutex_lock_common(lock, &waiter);
87373- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
87374+ debug_mutex_add_waiter(lock, &waiter, task);
87375
87376 /* add waiting tasks to the end of the waitqueue (FIFO): */
87377 list_add_tail(&waiter.list, &lock->wait_list);
87378@@ -534,7 +534,7 @@ slowpath:
87379 schedule_preempt_disabled();
87380 spin_lock_mutex(&lock->wait_lock, flags);
87381 }
87382- mutex_remove_waiter(lock, &waiter, current_thread_info());
87383+ mutex_remove_waiter(lock, &waiter, task);
87384 /* set it to 0 if there are no waiters left: */
87385 if (likely(list_empty(&lock->wait_list)))
87386 atomic_set(&lock->count, 0);
87387@@ -571,7 +571,7 @@ skip_wait:
87388 return 0;
87389
87390 err:
87391- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87392+ mutex_remove_waiter(lock, &waiter, task);
87393 spin_unlock_mutex(&lock->wait_lock, flags);
87394 debug_mutex_free_waiter(&waiter);
87395 mutex_release(&lock->dep_map, 1, ip);
87396diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87397index 1d96dd0..994ff19 100644
87398--- a/kernel/locking/rtmutex-tester.c
87399+++ b/kernel/locking/rtmutex-tester.c
87400@@ -22,7 +22,7 @@
87401 #define MAX_RT_TEST_MUTEXES 8
87402
87403 static spinlock_t rttest_lock;
87404-static atomic_t rttest_event;
87405+static atomic_unchecked_t rttest_event;
87406
87407 struct test_thread_data {
87408 int opcode;
87409@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87410
87411 case RTTEST_LOCKCONT:
87412 td->mutexes[td->opdata] = 1;
87413- td->event = atomic_add_return(1, &rttest_event);
87414+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87415 return 0;
87416
87417 case RTTEST_RESET:
87418@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87419 return 0;
87420
87421 case RTTEST_RESETEVENT:
87422- atomic_set(&rttest_event, 0);
87423+ atomic_set_unchecked(&rttest_event, 0);
87424 return 0;
87425
87426 default:
87427@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87428 return ret;
87429
87430 td->mutexes[id] = 1;
87431- td->event = atomic_add_return(1, &rttest_event);
87432+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87433 rt_mutex_lock(&mutexes[id]);
87434- td->event = atomic_add_return(1, &rttest_event);
87435+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87436 td->mutexes[id] = 4;
87437 return 0;
87438
87439@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87440 return ret;
87441
87442 td->mutexes[id] = 1;
87443- td->event = atomic_add_return(1, &rttest_event);
87444+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87445 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87446- td->event = atomic_add_return(1, &rttest_event);
87447+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87448 td->mutexes[id] = ret ? 0 : 4;
87449 return ret ? -EINTR : 0;
87450
87451@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87452 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87453 return ret;
87454
87455- td->event = atomic_add_return(1, &rttest_event);
87456+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87457 rt_mutex_unlock(&mutexes[id]);
87458- td->event = atomic_add_return(1, &rttest_event);
87459+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87460 td->mutexes[id] = 0;
87461 return 0;
87462
87463@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87464 break;
87465
87466 td->mutexes[dat] = 2;
87467- td->event = atomic_add_return(1, &rttest_event);
87468+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87469 break;
87470
87471 default:
87472@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87473 return;
87474
87475 td->mutexes[dat] = 3;
87476- td->event = atomic_add_return(1, &rttest_event);
87477+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87478 break;
87479
87480 case RTTEST_LOCKNOWAIT:
87481@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87482 return;
87483
87484 td->mutexes[dat] = 1;
87485- td->event = atomic_add_return(1, &rttest_event);
87486+ td->event = atomic_add_return_unchecked(1, &rttest_event);
87487 return;
87488
87489 default:
87490diff --git a/kernel/module.c b/kernel/module.c
87491index 079c461..741f79c 100644
87492--- a/kernel/module.c
87493+++ b/kernel/module.c
87494@@ -61,6 +61,7 @@
87495 #include <linux/pfn.h>
87496 #include <linux/bsearch.h>
87497 #include <linux/fips.h>
87498+#include <linux/grsecurity.h>
87499 #include <uapi/linux/module.h>
87500 #include "module-internal.h"
87501
87502@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87503
87504 /* Bounds of module allocation, for speeding __module_address.
87505 * Protected by module_mutex. */
87506-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87507+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87508+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87509
87510 int register_module_notifier(struct notifier_block * nb)
87511 {
87512@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87513 return true;
87514
87515 list_for_each_entry_rcu(mod, &modules, list) {
87516- struct symsearch arr[] = {
87517+ struct symsearch modarr[] = {
87518 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87519 NOT_GPL_ONLY, false },
87520 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87521@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87522 if (mod->state == MODULE_STATE_UNFORMED)
87523 continue;
87524
87525- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87526+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87527 return true;
87528 }
87529 return false;
87530@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87531 if (!pcpusec->sh_size)
87532 return 0;
87533
87534- if (align > PAGE_SIZE) {
87535+ if (align-1 >= PAGE_SIZE) {
87536 pr_warn("%s: per-cpu alignment %li > %li\n",
87537 mod->name, align, PAGE_SIZE);
87538 align = PAGE_SIZE;
87539@@ -1061,7 +1063,7 @@ struct module_attribute module_uevent =
87540 static ssize_t show_coresize(struct module_attribute *mattr,
87541 struct module_kobject *mk, char *buffer)
87542 {
87543- return sprintf(buffer, "%u\n", mk->mod->core_size);
87544+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87545 }
87546
87547 static struct module_attribute modinfo_coresize =
87548@@ -1070,7 +1072,7 @@ static struct module_attribute modinfo_coresize =
87549 static ssize_t show_initsize(struct module_attribute *mattr,
87550 struct module_kobject *mk, char *buffer)
87551 {
87552- return sprintf(buffer, "%u\n", mk->mod->init_size);
87553+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87554 }
87555
87556 static struct module_attribute modinfo_initsize =
87557@@ -1162,12 +1164,29 @@ static int check_version(Elf_Shdr *sechdrs,
87558 goto bad_version;
87559 }
87560
87561+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87562+ /*
87563+ * avoid potentially printing jibberish on attempted load
87564+ * of a module randomized with a different seed
87565+ */
87566+ pr_warn("no symbol version for %s\n", symname);
87567+#else
87568 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
87569+#endif
87570 return 0;
87571
87572 bad_version:
87573+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87574+ /*
87575+ * avoid potentially printing jibberish on attempted load
87576+ * of a module randomized with a different seed
87577+ */
87578+ printk("attempted module disagrees about version of symbol %s\n",
87579+ symname);
87580+#else
87581 printk("%s: disagrees about version of symbol %s\n",
87582 mod->name, symname);
87583+#endif
87584 return 0;
87585 }
87586
87587@@ -1283,7 +1302,7 @@ resolve_symbol_wait(struct module *mod,
87588 */
87589 #ifdef CONFIG_SYSFS
87590
87591-#ifdef CONFIG_KALLSYMS
87592+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
87593 static inline bool sect_empty(const Elf_Shdr *sect)
87594 {
87595 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
87596@@ -1423,7 +1442,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
87597 {
87598 unsigned int notes, loaded, i;
87599 struct module_notes_attrs *notes_attrs;
87600- struct bin_attribute *nattr;
87601+ bin_attribute_no_const *nattr;
87602
87603 /* failed to create section attributes, so can't create notes */
87604 if (!mod->sect_attrs)
87605@@ -1535,7 +1554,7 @@ static void del_usage_links(struct module *mod)
87606 static int module_add_modinfo_attrs(struct module *mod)
87607 {
87608 struct module_attribute *attr;
87609- struct module_attribute *temp_attr;
87610+ module_attribute_no_const *temp_attr;
87611 int error = 0;
87612 int i;
87613
87614@@ -1756,21 +1775,21 @@ static void set_section_ro_nx(void *base,
87615
87616 static void unset_module_core_ro_nx(struct module *mod)
87617 {
87618- set_page_attributes(mod->module_core + mod->core_text_size,
87619- mod->module_core + mod->core_size,
87620+ set_page_attributes(mod->module_core_rw,
87621+ mod->module_core_rw + mod->core_size_rw,
87622 set_memory_x);
87623- set_page_attributes(mod->module_core,
87624- mod->module_core + mod->core_ro_size,
87625+ set_page_attributes(mod->module_core_rx,
87626+ mod->module_core_rx + mod->core_size_rx,
87627 set_memory_rw);
87628 }
87629
87630 static void unset_module_init_ro_nx(struct module *mod)
87631 {
87632- set_page_attributes(mod->module_init + mod->init_text_size,
87633- mod->module_init + mod->init_size,
87634+ set_page_attributes(mod->module_init_rw,
87635+ mod->module_init_rw + mod->init_size_rw,
87636 set_memory_x);
87637- set_page_attributes(mod->module_init,
87638- mod->module_init + mod->init_ro_size,
87639+ set_page_attributes(mod->module_init_rx,
87640+ mod->module_init_rx + mod->init_size_rx,
87641 set_memory_rw);
87642 }
87643
87644@@ -1783,14 +1802,14 @@ void set_all_modules_text_rw(void)
87645 list_for_each_entry_rcu(mod, &modules, list) {
87646 if (mod->state == MODULE_STATE_UNFORMED)
87647 continue;
87648- if ((mod->module_core) && (mod->core_text_size)) {
87649- set_page_attributes(mod->module_core,
87650- mod->module_core + mod->core_text_size,
87651+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87652+ set_page_attributes(mod->module_core_rx,
87653+ mod->module_core_rx + mod->core_size_rx,
87654 set_memory_rw);
87655 }
87656- if ((mod->module_init) && (mod->init_text_size)) {
87657- set_page_attributes(mod->module_init,
87658- mod->module_init + mod->init_text_size,
87659+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87660+ set_page_attributes(mod->module_init_rx,
87661+ mod->module_init_rx + mod->init_size_rx,
87662 set_memory_rw);
87663 }
87664 }
87665@@ -1806,14 +1825,14 @@ void set_all_modules_text_ro(void)
87666 list_for_each_entry_rcu(mod, &modules, list) {
87667 if (mod->state == MODULE_STATE_UNFORMED)
87668 continue;
87669- if ((mod->module_core) && (mod->core_text_size)) {
87670- set_page_attributes(mod->module_core,
87671- mod->module_core + mod->core_text_size,
87672+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
87673+ set_page_attributes(mod->module_core_rx,
87674+ mod->module_core_rx + mod->core_size_rx,
87675 set_memory_ro);
87676 }
87677- if ((mod->module_init) && (mod->init_text_size)) {
87678- set_page_attributes(mod->module_init,
87679- mod->module_init + mod->init_text_size,
87680+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
87681+ set_page_attributes(mod->module_init_rx,
87682+ mod->module_init_rx + mod->init_size_rx,
87683 set_memory_ro);
87684 }
87685 }
87686@@ -1864,16 +1883,19 @@ static void free_module(struct module *mod)
87687
87688 /* This may be NULL, but that's OK */
87689 unset_module_init_ro_nx(mod);
87690- module_free(mod, mod->module_init);
87691+ module_free(mod, mod->module_init_rw);
87692+ module_free_exec(mod, mod->module_init_rx);
87693 kfree(mod->args);
87694 percpu_modfree(mod);
87695
87696 /* Free lock-classes: */
87697- lockdep_free_key_range(mod->module_core, mod->core_size);
87698+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
87699+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
87700
87701 /* Finally, free the core (containing the module structure) */
87702 unset_module_core_ro_nx(mod);
87703- module_free(mod, mod->module_core);
87704+ module_free_exec(mod, mod->module_core_rx);
87705+ module_free(mod, mod->module_core_rw);
87706
87707 #ifdef CONFIG_MPU
87708 update_protections(current->mm);
87709@@ -1942,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87710 int ret = 0;
87711 const struct kernel_symbol *ksym;
87712
87713+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87714+ int is_fs_load = 0;
87715+ int register_filesystem_found = 0;
87716+ char *p;
87717+
87718+ p = strstr(mod->args, "grsec_modharden_fs");
87719+ if (p) {
87720+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
87721+ /* copy \0 as well */
87722+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
87723+ is_fs_load = 1;
87724+ }
87725+#endif
87726+
87727 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
87728 const char *name = info->strtab + sym[i].st_name;
87729
87730+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87731+ /* it's a real shame this will never get ripped and copied
87732+ upstream! ;(
87733+ */
87734+ if (is_fs_load && !strcmp(name, "register_filesystem"))
87735+ register_filesystem_found = 1;
87736+#endif
87737+
87738 switch (sym[i].st_shndx) {
87739 case SHN_COMMON:
87740 /* Ignore common symbols */
87741@@ -1969,7 +2013,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87742 ksym = resolve_symbol_wait(mod, info, name);
87743 /* Ok if resolved. */
87744 if (ksym && !IS_ERR(ksym)) {
87745+ pax_open_kernel();
87746 sym[i].st_value = ksym->value;
87747+ pax_close_kernel();
87748 break;
87749 }
87750
87751@@ -1988,11 +2034,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87752 secbase = (unsigned long)mod_percpu(mod);
87753 else
87754 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
87755+ pax_open_kernel();
87756 sym[i].st_value += secbase;
87757+ pax_close_kernel();
87758 break;
87759 }
87760 }
87761
87762+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87763+ if (is_fs_load && !register_filesystem_found) {
87764+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
87765+ ret = -EPERM;
87766+ }
87767+#endif
87768+
87769 return ret;
87770 }
87771
87772@@ -2076,22 +2131,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
87773 || s->sh_entsize != ~0UL
87774 || strstarts(sname, ".init"))
87775 continue;
87776- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
87777+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87778+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
87779+ else
87780+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87781 pr_debug("\t%s\n", sname);
87782 }
87783- switch (m) {
87784- case 0: /* executable */
87785- mod->core_size = debug_align(mod->core_size);
87786- mod->core_text_size = mod->core_size;
87787- break;
87788- case 1: /* RO: text and ro-data */
87789- mod->core_size = debug_align(mod->core_size);
87790- mod->core_ro_size = mod->core_size;
87791- break;
87792- case 3: /* whole core */
87793- mod->core_size = debug_align(mod->core_size);
87794- break;
87795- }
87796 }
87797
87798 pr_debug("Init section allocation order:\n");
87799@@ -2105,23 +2150,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
87800 || s->sh_entsize != ~0UL
87801 || !strstarts(sname, ".init"))
87802 continue;
87803- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
87804- | INIT_OFFSET_MASK);
87805+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87806+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
87807+ else
87808+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
87809+ s->sh_entsize |= INIT_OFFSET_MASK;
87810 pr_debug("\t%s\n", sname);
87811 }
87812- switch (m) {
87813- case 0: /* executable */
87814- mod->init_size = debug_align(mod->init_size);
87815- mod->init_text_size = mod->init_size;
87816- break;
87817- case 1: /* RO: text and ro-data */
87818- mod->init_size = debug_align(mod->init_size);
87819- mod->init_ro_size = mod->init_size;
87820- break;
87821- case 3: /* whole init */
87822- mod->init_size = debug_align(mod->init_size);
87823- break;
87824- }
87825 }
87826 }
87827
87828@@ -2294,7 +2329,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87829
87830 /* Put symbol section at end of init part of module. */
87831 symsect->sh_flags |= SHF_ALLOC;
87832- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
87833+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
87834 info->index.sym) | INIT_OFFSET_MASK;
87835 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
87836
87837@@ -2311,13 +2346,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
87838 }
87839
87840 /* Append room for core symbols at end of core part. */
87841- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
87842- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
87843- mod->core_size += strtab_size;
87844+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
87845+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
87846+ mod->core_size_rx += strtab_size;
87847
87848 /* Put string table section at end of init part of module. */
87849 strsect->sh_flags |= SHF_ALLOC;
87850- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87851+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87852 info->index.str) | INIT_OFFSET_MASK;
87853 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87854 }
87855@@ -2335,12 +2370,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87856 /* Make sure we get permanent strtab: don't use info->strtab. */
87857 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87858
87859+ pax_open_kernel();
87860+
87861 /* Set types up while we still have access to sections. */
87862 for (i = 0; i < mod->num_symtab; i++)
87863 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87864
87865- mod->core_symtab = dst = mod->module_core + info->symoffs;
87866- mod->core_strtab = s = mod->module_core + info->stroffs;
87867+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87868+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87869 src = mod->symtab;
87870 for (ndst = i = 0; i < mod->num_symtab; i++) {
87871 if (i == 0 ||
87872@@ -2352,6 +2389,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87873 }
87874 }
87875 mod->core_num_syms = ndst;
87876+
87877+ pax_close_kernel();
87878 }
87879 #else
87880 static inline void layout_symtab(struct module *mod, struct load_info *info)
87881@@ -2385,17 +2424,33 @@ void * __weak module_alloc(unsigned long size)
87882 return vmalloc_exec(size);
87883 }
87884
87885-static void *module_alloc_update_bounds(unsigned long size)
87886+static void *module_alloc_update_bounds_rw(unsigned long size)
87887 {
87888 void *ret = module_alloc(size);
87889
87890 if (ret) {
87891 mutex_lock(&module_mutex);
87892 /* Update module bounds. */
87893- if ((unsigned long)ret < module_addr_min)
87894- module_addr_min = (unsigned long)ret;
87895- if ((unsigned long)ret + size > module_addr_max)
87896- module_addr_max = (unsigned long)ret + size;
87897+ if ((unsigned long)ret < module_addr_min_rw)
87898+ module_addr_min_rw = (unsigned long)ret;
87899+ if ((unsigned long)ret + size > module_addr_max_rw)
87900+ module_addr_max_rw = (unsigned long)ret + size;
87901+ mutex_unlock(&module_mutex);
87902+ }
87903+ return ret;
87904+}
87905+
87906+static void *module_alloc_update_bounds_rx(unsigned long size)
87907+{
87908+ void *ret = module_alloc_exec(size);
87909+
87910+ if (ret) {
87911+ mutex_lock(&module_mutex);
87912+ /* Update module bounds. */
87913+ if ((unsigned long)ret < module_addr_min_rx)
87914+ module_addr_min_rx = (unsigned long)ret;
87915+ if ((unsigned long)ret + size > module_addr_max_rx)
87916+ module_addr_max_rx = (unsigned long)ret + size;
87917 mutex_unlock(&module_mutex);
87918 }
87919 return ret;
87920@@ -2652,7 +2707,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87921 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87922
87923 if (info->index.sym == 0) {
87924+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87925+ /*
87926+ * avoid potentially printing jibberish on attempted load
87927+ * of a module randomized with a different seed
87928+ */
87929+ pr_warn("module has no symbols (stripped?)\n");
87930+#else
87931 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87932+#endif
87933 return ERR_PTR(-ENOEXEC);
87934 }
87935
87936@@ -2668,8 +2731,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87937 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87938 {
87939 const char *modmagic = get_modinfo(info, "vermagic");
87940+ const char *license = get_modinfo(info, "license");
87941 int err;
87942
87943+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
87944+ if (!license || !license_is_gpl_compatible(license))
87945+ return -ENOEXEC;
87946+#endif
87947+
87948 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
87949 modmagic = NULL;
87950
87951@@ -2694,7 +2763,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87952 }
87953
87954 /* Set up license info based on the info section */
87955- set_license(mod, get_modinfo(info, "license"));
87956+ set_license(mod, license);
87957
87958 return 0;
87959 }
87960@@ -2788,7 +2857,7 @@ static int move_module(struct module *mod, struct load_info *info)
87961 void *ptr;
87962
87963 /* Do the allocs. */
87964- ptr = module_alloc_update_bounds(mod->core_size);
87965+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87966 /*
87967 * The pointer to this block is stored in the module structure
87968 * which is inside the block. Just mark it as not being a
87969@@ -2798,11 +2867,11 @@ static int move_module(struct module *mod, struct load_info *info)
87970 if (!ptr)
87971 return -ENOMEM;
87972
87973- memset(ptr, 0, mod->core_size);
87974- mod->module_core = ptr;
87975+ memset(ptr, 0, mod->core_size_rw);
87976+ mod->module_core_rw = ptr;
87977
87978- if (mod->init_size) {
87979- ptr = module_alloc_update_bounds(mod->init_size);
87980+ if (mod->init_size_rw) {
87981+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
87982 /*
87983 * The pointer to this block is stored in the module structure
87984 * which is inside the block. This block doesn't need to be
87985@@ -2811,13 +2880,45 @@ static int move_module(struct module *mod, struct load_info *info)
87986 */
87987 kmemleak_ignore(ptr);
87988 if (!ptr) {
87989- module_free(mod, mod->module_core);
87990+ module_free(mod, mod->module_core_rw);
87991 return -ENOMEM;
87992 }
87993- memset(ptr, 0, mod->init_size);
87994- mod->module_init = ptr;
87995+ memset(ptr, 0, mod->init_size_rw);
87996+ mod->module_init_rw = ptr;
87997 } else
87998- mod->module_init = NULL;
87999+ mod->module_init_rw = NULL;
88000+
88001+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
88002+ kmemleak_not_leak(ptr);
88003+ if (!ptr) {
88004+ if (mod->module_init_rw)
88005+ module_free(mod, mod->module_init_rw);
88006+ module_free(mod, mod->module_core_rw);
88007+ return -ENOMEM;
88008+ }
88009+
88010+ pax_open_kernel();
88011+ memset(ptr, 0, mod->core_size_rx);
88012+ pax_close_kernel();
88013+ mod->module_core_rx = ptr;
88014+
88015+ if (mod->init_size_rx) {
88016+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
88017+ kmemleak_ignore(ptr);
88018+ if (!ptr && mod->init_size_rx) {
88019+ module_free_exec(mod, mod->module_core_rx);
88020+ if (mod->module_init_rw)
88021+ module_free(mod, mod->module_init_rw);
88022+ module_free(mod, mod->module_core_rw);
88023+ return -ENOMEM;
88024+ }
88025+
88026+ pax_open_kernel();
88027+ memset(ptr, 0, mod->init_size_rx);
88028+ pax_close_kernel();
88029+ mod->module_init_rx = ptr;
88030+ } else
88031+ mod->module_init_rx = NULL;
88032
88033 /* Transfer each section which specifies SHF_ALLOC */
88034 pr_debug("final section addresses:\n");
88035@@ -2828,16 +2929,45 @@ static int move_module(struct module *mod, struct load_info *info)
88036 if (!(shdr->sh_flags & SHF_ALLOC))
88037 continue;
88038
88039- if (shdr->sh_entsize & INIT_OFFSET_MASK)
88040- dest = mod->module_init
88041- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88042- else
88043- dest = mod->module_core + shdr->sh_entsize;
88044+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
88045+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88046+ dest = mod->module_init_rw
88047+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88048+ else
88049+ dest = mod->module_init_rx
88050+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88051+ } else {
88052+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88053+ dest = mod->module_core_rw + shdr->sh_entsize;
88054+ else
88055+ dest = mod->module_core_rx + shdr->sh_entsize;
88056+ }
88057+
88058+ if (shdr->sh_type != SHT_NOBITS) {
88059+
88060+#ifdef CONFIG_PAX_KERNEXEC
88061+#ifdef CONFIG_X86_64
88062+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
88063+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88064+#endif
88065+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88066+ pax_open_kernel();
88067+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88068+ pax_close_kernel();
88069+ } else
88070+#endif
88071
88072- if (shdr->sh_type != SHT_NOBITS)
88073 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88074+ }
88075 /* Update sh_addr to point to copy in image. */
88076- shdr->sh_addr = (unsigned long)dest;
88077+
88078+#ifdef CONFIG_PAX_KERNEXEC
88079+ if (shdr->sh_flags & SHF_EXECINSTR)
88080+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
88081+ else
88082+#endif
88083+
88084+ shdr->sh_addr = (unsigned long)dest;
88085 pr_debug("\t0x%lx %s\n",
88086 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88087 }
88088@@ -2894,12 +3024,12 @@ static void flush_module_icache(const struct module *mod)
88089 * Do it before processing of module parameters, so the module
88090 * can provide parameter accessor functions of its own.
88091 */
88092- if (mod->module_init)
88093- flush_icache_range((unsigned long)mod->module_init,
88094- (unsigned long)mod->module_init
88095- + mod->init_size);
88096- flush_icache_range((unsigned long)mod->module_core,
88097- (unsigned long)mod->module_core + mod->core_size);
88098+ if (mod->module_init_rx)
88099+ flush_icache_range((unsigned long)mod->module_init_rx,
88100+ (unsigned long)mod->module_init_rx
88101+ + mod->init_size_rx);
88102+ flush_icache_range((unsigned long)mod->module_core_rx,
88103+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
88104
88105 set_fs(old_fs);
88106 }
88107@@ -2956,8 +3086,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88108 static void module_deallocate(struct module *mod, struct load_info *info)
88109 {
88110 percpu_modfree(mod);
88111- module_free(mod, mod->module_init);
88112- module_free(mod, mod->module_core);
88113+ module_free_exec(mod, mod->module_init_rx);
88114+ module_free_exec(mod, mod->module_core_rx);
88115+ module_free(mod, mod->module_init_rw);
88116+ module_free(mod, mod->module_core_rw);
88117 }
88118
88119 int __weak module_finalize(const Elf_Ehdr *hdr,
88120@@ -2970,7 +3102,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88121 static int post_relocation(struct module *mod, const struct load_info *info)
88122 {
88123 /* Sort exception table now relocations are done. */
88124+ pax_open_kernel();
88125 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88126+ pax_close_kernel();
88127
88128 /* Copy relocated percpu area over. */
88129 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88130@@ -3024,16 +3158,16 @@ static int do_init_module(struct module *mod)
88131 MODULE_STATE_COMING, mod);
88132
88133 /* Set RO and NX regions for core */
88134- set_section_ro_nx(mod->module_core,
88135- mod->core_text_size,
88136- mod->core_ro_size,
88137- mod->core_size);
88138+ set_section_ro_nx(mod->module_core_rx,
88139+ mod->core_size_rx,
88140+ mod->core_size_rx,
88141+ mod->core_size_rx);
88142
88143 /* Set RO and NX regions for init */
88144- set_section_ro_nx(mod->module_init,
88145- mod->init_text_size,
88146- mod->init_ro_size,
88147- mod->init_size);
88148+ set_section_ro_nx(mod->module_init_rx,
88149+ mod->init_size_rx,
88150+ mod->init_size_rx,
88151+ mod->init_size_rx);
88152
88153 do_mod_ctors(mod);
88154 /* Start the module */
88155@@ -3094,11 +3228,12 @@ static int do_init_module(struct module *mod)
88156 mod->strtab = mod->core_strtab;
88157 #endif
88158 unset_module_init_ro_nx(mod);
88159- module_free(mod, mod->module_init);
88160- mod->module_init = NULL;
88161- mod->init_size = 0;
88162- mod->init_ro_size = 0;
88163- mod->init_text_size = 0;
88164+ module_free(mod, mod->module_init_rw);
88165+ module_free_exec(mod, mod->module_init_rx);
88166+ mod->module_init_rw = NULL;
88167+ mod->module_init_rx = NULL;
88168+ mod->init_size_rw = 0;
88169+ mod->init_size_rx = 0;
88170 mutex_unlock(&module_mutex);
88171 wake_up_all(&module_wq);
88172
88173@@ -3241,9 +3376,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88174 if (err)
88175 goto free_unload;
88176
88177+ /* Now copy in args */
88178+ mod->args = strndup_user(uargs, ~0UL >> 1);
88179+ if (IS_ERR(mod->args)) {
88180+ err = PTR_ERR(mod->args);
88181+ goto free_unload;
88182+ }
88183+
88184 /* Set up MODINFO_ATTR fields */
88185 setup_modinfo(mod, info);
88186
88187+#ifdef CONFIG_GRKERNSEC_MODHARDEN
88188+ {
88189+ char *p, *p2;
88190+
88191+ if (strstr(mod->args, "grsec_modharden_netdev")) {
88192+ 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);
88193+ err = -EPERM;
88194+ goto free_modinfo;
88195+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88196+ p += sizeof("grsec_modharden_normal") - 1;
88197+ p2 = strstr(p, "_");
88198+ if (p2) {
88199+ *p2 = '\0';
88200+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88201+ *p2 = '_';
88202+ }
88203+ err = -EPERM;
88204+ goto free_modinfo;
88205+ }
88206+ }
88207+#endif
88208+
88209 /* Fix up syms, so that st_value is a pointer to location. */
88210 err = simplify_symbols(mod, info);
88211 if (err < 0)
88212@@ -3259,13 +3423,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88213
88214 flush_module_icache(mod);
88215
88216- /* Now copy in args */
88217- mod->args = strndup_user(uargs, ~0UL >> 1);
88218- if (IS_ERR(mod->args)) {
88219- err = PTR_ERR(mod->args);
88220- goto free_arch_cleanup;
88221- }
88222-
88223 dynamic_debug_setup(info->debug, info->num_debug);
88224
88225 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
88226@@ -3303,11 +3460,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88227 ddebug_cleanup:
88228 dynamic_debug_remove(info->debug);
88229 synchronize_sched();
88230- kfree(mod->args);
88231- free_arch_cleanup:
88232 module_arch_cleanup(mod);
88233 free_modinfo:
88234 free_modinfo(mod);
88235+ kfree(mod->args);
88236 free_unload:
88237 module_unload_free(mod);
88238 unlink_mod:
88239@@ -3390,10 +3546,16 @@ static const char *get_ksymbol(struct module *mod,
88240 unsigned long nextval;
88241
88242 /* At worse, next value is at end of module */
88243- if (within_module_init(addr, mod))
88244- nextval = (unsigned long)mod->module_init+mod->init_text_size;
88245+ if (within_module_init_rx(addr, mod))
88246+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88247+ else if (within_module_init_rw(addr, mod))
88248+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88249+ else if (within_module_core_rx(addr, mod))
88250+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88251+ else if (within_module_core_rw(addr, mod))
88252+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88253 else
88254- nextval = (unsigned long)mod->module_core+mod->core_text_size;
88255+ return NULL;
88256
88257 /* Scan for closest preceding symbol, and next symbol. (ELF
88258 starts real symbols at 1). */
88259@@ -3644,7 +3806,7 @@ static int m_show(struct seq_file *m, void *p)
88260 return 0;
88261
88262 seq_printf(m, "%s %u",
88263- mod->name, mod->init_size + mod->core_size);
88264+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88265 print_unload_info(m, mod);
88266
88267 /* Informative for users. */
88268@@ -3653,7 +3815,7 @@ static int m_show(struct seq_file *m, void *p)
88269 mod->state == MODULE_STATE_COMING ? "Loading":
88270 "Live");
88271 /* Used by oprofile and other similar tools. */
88272- seq_printf(m, " 0x%pK", mod->module_core);
88273+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88274
88275 /* Taints info */
88276 if (mod->taints)
88277@@ -3689,7 +3851,17 @@ static const struct file_operations proc_modules_operations = {
88278
88279 static int __init proc_modules_init(void)
88280 {
88281+#ifndef CONFIG_GRKERNSEC_HIDESYM
88282+#ifdef CONFIG_GRKERNSEC_PROC_USER
88283+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88284+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88285+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
88286+#else
88287 proc_create("modules", 0, NULL, &proc_modules_operations);
88288+#endif
88289+#else
88290+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88291+#endif
88292 return 0;
88293 }
88294 module_init(proc_modules_init);
88295@@ -3750,14 +3922,14 @@ struct module *__module_address(unsigned long addr)
88296 {
88297 struct module *mod;
88298
88299- if (addr < module_addr_min || addr > module_addr_max)
88300+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
88301+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
88302 return NULL;
88303
88304 list_for_each_entry_rcu(mod, &modules, list) {
88305 if (mod->state == MODULE_STATE_UNFORMED)
88306 continue;
88307- if (within_module_core(addr, mod)
88308- || within_module_init(addr, mod))
88309+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
88310 return mod;
88311 }
88312 return NULL;
88313@@ -3792,11 +3964,20 @@ bool is_module_text_address(unsigned long addr)
88314 */
88315 struct module *__module_text_address(unsigned long addr)
88316 {
88317- struct module *mod = __module_address(addr);
88318+ struct module *mod;
88319+
88320+#ifdef CONFIG_X86_32
88321+ addr = ktla_ktva(addr);
88322+#endif
88323+
88324+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
88325+ return NULL;
88326+
88327+ mod = __module_address(addr);
88328+
88329 if (mod) {
88330 /* Make sure it's within the text section. */
88331- if (!within(addr, mod->module_init, mod->init_text_size)
88332- && !within(addr, mod->module_core, mod->core_text_size))
88333+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
88334 mod = NULL;
88335 }
88336 return mod;
88337diff --git a/kernel/notifier.c b/kernel/notifier.c
88338index db4c8b0..ad011c5 100644
88339--- a/kernel/notifier.c
88340+++ b/kernel/notifier.c
88341@@ -5,6 +5,7 @@
88342 #include <linux/rcupdate.h>
88343 #include <linux/vmalloc.h>
88344 #include <linux/reboot.h>
88345+#include <linux/mm.h>
88346
88347 /*
88348 * Notifier list for kernel code which wants to be called
88349@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
88350 while ((*nl) != NULL) {
88351 if (n->priority > (*nl)->priority)
88352 break;
88353- nl = &((*nl)->next);
88354+ nl = (struct notifier_block **)&((*nl)->next);
88355 }
88356- n->next = *nl;
88357+ pax_open_kernel();
88358+ *(const void **)&n->next = *nl;
88359 rcu_assign_pointer(*nl, n);
88360+ pax_close_kernel();
88361 return 0;
88362 }
88363
88364@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
88365 return 0;
88366 if (n->priority > (*nl)->priority)
88367 break;
88368- nl = &((*nl)->next);
88369+ nl = (struct notifier_block **)&((*nl)->next);
88370 }
88371- n->next = *nl;
88372+ pax_open_kernel();
88373+ *(const void **)&n->next = *nl;
88374 rcu_assign_pointer(*nl, n);
88375+ pax_close_kernel();
88376 return 0;
88377 }
88378
88379@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
88380 {
88381 while ((*nl) != NULL) {
88382 if ((*nl) == n) {
88383+ pax_open_kernel();
88384 rcu_assign_pointer(*nl, n->next);
88385+ pax_close_kernel();
88386 return 0;
88387 }
88388- nl = &((*nl)->next);
88389+ nl = (struct notifier_block **)&((*nl)->next);
88390 }
88391 return -ENOENT;
88392 }
88393diff --git a/kernel/padata.c b/kernel/padata.c
88394index 161402f..598814c 100644
88395--- a/kernel/padata.c
88396+++ b/kernel/padata.c
88397@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88398 * seq_nr mod. number of cpus in use.
88399 */
88400
88401- seq_nr = atomic_inc_return(&pd->seq_nr);
88402+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88403 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88404
88405 return padata_index_to_cpu(pd, cpu_index);
88406@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88407 padata_init_pqueues(pd);
88408 padata_init_squeues(pd);
88409 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88410- atomic_set(&pd->seq_nr, -1);
88411+ atomic_set_unchecked(&pd->seq_nr, -1);
88412 atomic_set(&pd->reorder_objects, 0);
88413 atomic_set(&pd->refcnt, 0);
88414 pd->pinst = pinst;
88415diff --git a/kernel/panic.c b/kernel/panic.c
88416index d02fa9f..9faec0a 100644
88417--- a/kernel/panic.c
88418+++ b/kernel/panic.c
88419@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88420 /*
88421 * Stop ourself in panic -- architecture code may override this
88422 */
88423-void __weak panic_smp_self_stop(void)
88424+void __weak __noreturn panic_smp_self_stop(void)
88425 {
88426 while (1)
88427 cpu_relax();
88428@@ -408,7 +408,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88429 disable_trace_on_warning();
88430
88431 pr_warn("------------[ cut here ]------------\n");
88432- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88433+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88434 raw_smp_processor_id(), current->pid, file, line, caller);
88435
88436 if (args)
88437@@ -462,7 +462,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88438 */
88439 __visible void __stack_chk_fail(void)
88440 {
88441- panic("stack-protector: Kernel stack is corrupted in: %p\n",
88442+ dump_stack();
88443+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88444 __builtin_return_address(0));
88445 }
88446 EXPORT_SYMBOL(__stack_chk_fail);
88447diff --git a/kernel/pid.c b/kernel/pid.c
88448index 9b9a266..c20ef80 100644
88449--- a/kernel/pid.c
88450+++ b/kernel/pid.c
88451@@ -33,6 +33,7 @@
88452 #include <linux/rculist.h>
88453 #include <linux/bootmem.h>
88454 #include <linux/hash.h>
88455+#include <linux/security.h>
88456 #include <linux/pid_namespace.h>
88457 #include <linux/init_task.h>
88458 #include <linux/syscalls.h>
88459@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88460
88461 int pid_max = PID_MAX_DEFAULT;
88462
88463-#define RESERVED_PIDS 300
88464+#define RESERVED_PIDS 500
88465
88466 int pid_max_min = RESERVED_PIDS + 1;
88467 int pid_max_max = PID_MAX_LIMIT;
88468@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88469 */
88470 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88471 {
88472+ struct task_struct *task;
88473+
88474 rcu_lockdep_assert(rcu_read_lock_held(),
88475 "find_task_by_pid_ns() needs rcu_read_lock()"
88476 " protection");
88477- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88478+
88479+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88480+
88481+ if (gr_pid_is_chrooted(task))
88482+ return NULL;
88483+
88484+ return task;
88485 }
88486
88487 struct task_struct *find_task_by_vpid(pid_t vnr)
88488@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88489 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88490 }
88491
88492+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88493+{
88494+ rcu_lockdep_assert(rcu_read_lock_held(),
88495+ "find_task_by_pid_ns() needs rcu_read_lock()"
88496+ " protection");
88497+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88498+}
88499+
88500 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88501 {
88502 struct pid *pid;
88503diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88504index db95d8e..a0ca23f 100644
88505--- a/kernel/pid_namespace.c
88506+++ b/kernel/pid_namespace.c
88507@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88508 void __user *buffer, size_t *lenp, loff_t *ppos)
88509 {
88510 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88511- struct ctl_table tmp = *table;
88512+ ctl_table_no_const tmp = *table;
88513
88514 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88515 return -EPERM;
88516diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88517index 3b89464..5e38379 100644
88518--- a/kernel/posix-cpu-timers.c
88519+++ b/kernel/posix-cpu-timers.c
88520@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88521
88522 static __init int init_posix_cpu_timers(void)
88523 {
88524- struct k_clock process = {
88525+ static struct k_clock process = {
88526 .clock_getres = process_cpu_clock_getres,
88527 .clock_get = process_cpu_clock_get,
88528 .timer_create = process_cpu_timer_create,
88529 .nsleep = process_cpu_nsleep,
88530 .nsleep_restart = process_cpu_nsleep_restart,
88531 };
88532- struct k_clock thread = {
88533+ static struct k_clock thread = {
88534 .clock_getres = thread_cpu_clock_getres,
88535 .clock_get = thread_cpu_clock_get,
88536 .timer_create = thread_cpu_timer_create,
88537diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88538index 424c2d4..679242f 100644
88539--- a/kernel/posix-timers.c
88540+++ b/kernel/posix-timers.c
88541@@ -43,6 +43,7 @@
88542 #include <linux/hash.h>
88543 #include <linux/posix-clock.h>
88544 #include <linux/posix-timers.h>
88545+#include <linux/grsecurity.h>
88546 #include <linux/syscalls.h>
88547 #include <linux/wait.h>
88548 #include <linux/workqueue.h>
88549@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88550 * which we beg off on and pass to do_sys_settimeofday().
88551 */
88552
88553-static struct k_clock posix_clocks[MAX_CLOCKS];
88554+static struct k_clock *posix_clocks[MAX_CLOCKS];
88555
88556 /*
88557 * These ones are defined below.
88558@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88559 */
88560 static __init int init_posix_timers(void)
88561 {
88562- struct k_clock clock_realtime = {
88563+ static struct k_clock clock_realtime = {
88564 .clock_getres = hrtimer_get_res,
88565 .clock_get = posix_clock_realtime_get,
88566 .clock_set = posix_clock_realtime_set,
88567@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
88568 .timer_get = common_timer_get,
88569 .timer_del = common_timer_del,
88570 };
88571- struct k_clock clock_monotonic = {
88572+ static struct k_clock clock_monotonic = {
88573 .clock_getres = hrtimer_get_res,
88574 .clock_get = posix_ktime_get_ts,
88575 .nsleep = common_nsleep,
88576@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
88577 .timer_get = common_timer_get,
88578 .timer_del = common_timer_del,
88579 };
88580- struct k_clock clock_monotonic_raw = {
88581+ static struct k_clock clock_monotonic_raw = {
88582 .clock_getres = hrtimer_get_res,
88583 .clock_get = posix_get_monotonic_raw,
88584 };
88585- struct k_clock clock_realtime_coarse = {
88586+ static struct k_clock clock_realtime_coarse = {
88587 .clock_getres = posix_get_coarse_res,
88588 .clock_get = posix_get_realtime_coarse,
88589 };
88590- struct k_clock clock_monotonic_coarse = {
88591+ static struct k_clock clock_monotonic_coarse = {
88592 .clock_getres = posix_get_coarse_res,
88593 .clock_get = posix_get_monotonic_coarse,
88594 };
88595- struct k_clock clock_tai = {
88596+ static struct k_clock clock_tai = {
88597 .clock_getres = hrtimer_get_res,
88598 .clock_get = posix_get_tai,
88599 .nsleep = common_nsleep,
88600@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
88601 .timer_get = common_timer_get,
88602 .timer_del = common_timer_del,
88603 };
88604- struct k_clock clock_boottime = {
88605+ static struct k_clock clock_boottime = {
88606 .clock_getres = hrtimer_get_res,
88607 .clock_get = posix_get_boottime,
88608 .nsleep = common_nsleep,
88609@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
88610 return;
88611 }
88612
88613- posix_clocks[clock_id] = *new_clock;
88614+ posix_clocks[clock_id] = new_clock;
88615 }
88616 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
88617
88618@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
88619 return (id & CLOCKFD_MASK) == CLOCKFD ?
88620 &clock_posix_dynamic : &clock_posix_cpu;
88621
88622- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
88623+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
88624 return NULL;
88625- return &posix_clocks[id];
88626+ return posix_clocks[id];
88627 }
88628
88629 static int common_timer_create(struct k_itimer *new_timer)
88630@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
88631 struct k_clock *kc = clockid_to_kclock(which_clock);
88632 struct k_itimer *new_timer;
88633 int error, new_timer_id;
88634- sigevent_t event;
88635+ sigevent_t event = { };
88636 int it_id_set = IT_ID_NOT_SET;
88637
88638 if (!kc)
88639@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
88640 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
88641 return -EFAULT;
88642
88643+ /* only the CLOCK_REALTIME clock can be set, all other clocks
88644+ have their clock_set fptr set to a nosettime dummy function
88645+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
88646+ call common_clock_set, which calls do_sys_settimeofday, which
88647+ we hook
88648+ */
88649+
88650 return kc->clock_set(which_clock, &new_tp);
88651 }
88652
88653diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
88654index 2fac9cc..56fef29 100644
88655--- a/kernel/power/Kconfig
88656+++ b/kernel/power/Kconfig
88657@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
88658 config HIBERNATION
88659 bool "Hibernation (aka 'suspend to disk')"
88660 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
88661+ depends on !GRKERNSEC_KMEM
88662+ depends on !PAX_MEMORY_SANITIZE
88663 select HIBERNATE_CALLBACKS
88664 select LZO_COMPRESS
88665 select LZO_DECOMPRESS
88666diff --git a/kernel/power/process.c b/kernel/power/process.c
88667index 06ec886..9dba35e 100644
88668--- a/kernel/power/process.c
88669+++ b/kernel/power/process.c
88670@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
88671 unsigned int elapsed_msecs;
88672 bool wakeup = false;
88673 int sleep_usecs = USEC_PER_MSEC;
88674+ bool timedout = false;
88675
88676 do_gettimeofday(&start);
88677
88678@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
88679
88680 while (true) {
88681 todo = 0;
88682+ if (time_after(jiffies, end_time))
88683+ timedout = true;
88684 read_lock(&tasklist_lock);
88685 do_each_thread(g, p) {
88686 if (p == current || !freeze_task(p))
88687 continue;
88688
88689- if (!freezer_should_skip(p))
88690+ if (!freezer_should_skip(p)) {
88691 todo++;
88692+ if (timedout) {
88693+ printk(KERN_ERR "Task refusing to freeze:\n");
88694+ sched_show_task(p);
88695+ }
88696+ }
88697 } while_each_thread(g, p);
88698 read_unlock(&tasklist_lock);
88699
88700@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
88701 todo += wq_busy;
88702 }
88703
88704- if (!todo || time_after(jiffies, end_time))
88705+ if (!todo || timedout)
88706 break;
88707
88708 if (pm_wakeup_pending()) {
88709diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
88710index 221229c..c76ca0a 100644
88711--- a/kernel/printk/printk.c
88712+++ b/kernel/printk/printk.c
88713@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
88714 if (from_file && type != SYSLOG_ACTION_OPEN)
88715 return 0;
88716
88717+#ifdef CONFIG_GRKERNSEC_DMESG
88718+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
88719+ return -EPERM;
88720+#endif
88721+
88722 if (syslog_action_restricted(type)) {
88723 if (capable(CAP_SYSLOG))
88724 return 0;
88725diff --git a/kernel/profile.c b/kernel/profile.c
88726index cb980f0..ccd8782 100644
88727--- a/kernel/profile.c
88728+++ b/kernel/profile.c
88729@@ -37,7 +37,7 @@ struct profile_hit {
88730 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
88731 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
88732
88733-static atomic_t *prof_buffer;
88734+static atomic_unchecked_t *prof_buffer;
88735 static unsigned long prof_len, prof_shift;
88736
88737 int prof_on __read_mostly;
88738@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
88739 hits[i].pc = 0;
88740 continue;
88741 }
88742- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88743+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88744 hits[i].hits = hits[i].pc = 0;
88745 }
88746 }
88747@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88748 * Add the current hit(s) and flush the write-queue out
88749 * to the global buffer:
88750 */
88751- atomic_add(nr_hits, &prof_buffer[pc]);
88752+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
88753 for (i = 0; i < NR_PROFILE_HIT; ++i) {
88754- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88755+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88756 hits[i].pc = hits[i].hits = 0;
88757 }
88758 out:
88759@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88760 {
88761 unsigned long pc;
88762 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
88763- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88764+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88765 }
88766 #endif /* !CONFIG_SMP */
88767
88768@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
88769 return -EFAULT;
88770 buf++; p++; count--; read++;
88771 }
88772- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88773+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88774 if (copy_to_user(buf, (void *)pnt, count))
88775 return -EFAULT;
88776 read += count;
88777@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88778 }
88779 #endif
88780 profile_discard_flip_buffers();
88781- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88782+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88783 return count;
88784 }
88785
88786diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88787index adf9862..9d86345 100644
88788--- a/kernel/ptrace.c
88789+++ b/kernel/ptrace.c
88790@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88791 if (seize)
88792 flags |= PT_SEIZED;
88793 rcu_read_lock();
88794- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88795+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88796 flags |= PT_PTRACE_CAP;
88797 rcu_read_unlock();
88798 task->ptrace = flags;
88799@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
88800 break;
88801 return -EIO;
88802 }
88803- if (copy_to_user(dst, buf, retval))
88804+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
88805 return -EFAULT;
88806 copied += retval;
88807 src += retval;
88808@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
88809 bool seized = child->ptrace & PT_SEIZED;
88810 int ret = -EIO;
88811 siginfo_t siginfo, *si;
88812- void __user *datavp = (void __user *) data;
88813+ void __user *datavp = (__force void __user *) data;
88814 unsigned long __user *datalp = datavp;
88815 unsigned long flags;
88816
88817@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
88818 goto out;
88819 }
88820
88821+ if (gr_handle_ptrace(child, request)) {
88822+ ret = -EPERM;
88823+ goto out_put_task_struct;
88824+ }
88825+
88826 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88827 ret = ptrace_attach(child, request, addr, data);
88828 /*
88829 * Some architectures need to do book-keeping after
88830 * a ptrace attach.
88831 */
88832- if (!ret)
88833+ if (!ret) {
88834 arch_ptrace_attach(child);
88835+ gr_audit_ptrace(child);
88836+ }
88837 goto out_put_task_struct;
88838 }
88839
88840@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
88841 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
88842 if (copied != sizeof(tmp))
88843 return -EIO;
88844- return put_user(tmp, (unsigned long __user *)data);
88845+ return put_user(tmp, (__force unsigned long __user *)data);
88846 }
88847
88848 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88849@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88850 }
88851
88852 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
88853- compat_long_t, addr, compat_long_t, data)
88854+ compat_ulong_t, addr, compat_ulong_t, data)
88855 {
88856 struct task_struct *child;
88857 long ret;
88858@@ -1197,14 +1204,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
88859 goto out;
88860 }
88861
88862+ if (gr_handle_ptrace(child, request)) {
88863+ ret = -EPERM;
88864+ goto out_put_task_struct;
88865+ }
88866+
88867 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88868 ret = ptrace_attach(child, request, addr, data);
88869 /*
88870 * Some architectures need to do book-keeping after
88871 * a ptrace attach.
88872 */
88873- if (!ret)
88874+ if (!ret) {
88875 arch_ptrace_attach(child);
88876+ gr_audit_ptrace(child);
88877+ }
88878 goto out_put_task_struct;
88879 }
88880
88881diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
88882index bd30bc6..dce23da 100644
88883--- a/kernel/rcu/rcutorture.c
88884+++ b/kernel/rcu/rcutorture.c
88885@@ -122,12 +122,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
88886 rcu_torture_count) = { 0 };
88887 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
88888 rcu_torture_batch) = { 0 };
88889-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88890-static atomic_t n_rcu_torture_alloc;
88891-static atomic_t n_rcu_torture_alloc_fail;
88892-static atomic_t n_rcu_torture_free;
88893-static atomic_t n_rcu_torture_mberror;
88894-static atomic_t n_rcu_torture_error;
88895+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88896+static atomic_unchecked_t n_rcu_torture_alloc;
88897+static atomic_unchecked_t n_rcu_torture_alloc_fail;
88898+static atomic_unchecked_t n_rcu_torture_free;
88899+static atomic_unchecked_t n_rcu_torture_mberror;
88900+static atomic_unchecked_t n_rcu_torture_error;
88901 static long n_rcu_torture_barrier_error;
88902 static long n_rcu_torture_boost_ktrerror;
88903 static long n_rcu_torture_boost_rterror;
88904@@ -186,11 +186,11 @@ rcu_torture_alloc(void)
88905
88906 spin_lock_bh(&rcu_torture_lock);
88907 if (list_empty(&rcu_torture_freelist)) {
88908- atomic_inc(&n_rcu_torture_alloc_fail);
88909+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88910 spin_unlock_bh(&rcu_torture_lock);
88911 return NULL;
88912 }
88913- atomic_inc(&n_rcu_torture_alloc);
88914+ atomic_inc_unchecked(&n_rcu_torture_alloc);
88915 p = rcu_torture_freelist.next;
88916 list_del_init(p);
88917 spin_unlock_bh(&rcu_torture_lock);
88918@@ -203,7 +203,7 @@ rcu_torture_alloc(void)
88919 static void
88920 rcu_torture_free(struct rcu_torture *p)
88921 {
88922- atomic_inc(&n_rcu_torture_free);
88923+ atomic_inc_unchecked(&n_rcu_torture_free);
88924 spin_lock_bh(&rcu_torture_lock);
88925 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88926 spin_unlock_bh(&rcu_torture_lock);
88927@@ -287,7 +287,7 @@ rcu_torture_cb(struct rcu_head *p)
88928 i = rp->rtort_pipe_count;
88929 if (i > RCU_TORTURE_PIPE_LEN)
88930 i = RCU_TORTURE_PIPE_LEN;
88931- atomic_inc(&rcu_torture_wcount[i]);
88932+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88933 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88934 rp->rtort_mbtest = 0;
88935 rcu_torture_free(rp);
88936@@ -714,7 +714,7 @@ rcu_torture_writer(void *arg)
88937 i = old_rp->rtort_pipe_count;
88938 if (i > RCU_TORTURE_PIPE_LEN)
88939 i = RCU_TORTURE_PIPE_LEN;
88940- atomic_inc(&rcu_torture_wcount[i]);
88941+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88942 old_rp->rtort_pipe_count++;
88943 if (gp_normal == gp_exp)
88944 exp = !!(torture_random(&rand) & 0x80);
88945@@ -732,7 +732,7 @@ rcu_torture_writer(void *arg)
88946 i = rp->rtort_pipe_count;
88947 if (i > RCU_TORTURE_PIPE_LEN)
88948 i = RCU_TORTURE_PIPE_LEN;
88949- atomic_inc(&rcu_torture_wcount[i]);
88950+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88951 if (++rp->rtort_pipe_count >=
88952 RCU_TORTURE_PIPE_LEN) {
88953 rp->rtort_mbtest = 0;
88954@@ -825,7 +825,7 @@ static void rcu_torture_timer(unsigned long unused)
88955 return;
88956 }
88957 if (p->rtort_mbtest == 0)
88958- atomic_inc(&n_rcu_torture_mberror);
88959+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88960 spin_lock(&rand_lock);
88961 cur_ops->read_delay(&rand);
88962 n_rcu_torture_timers++;
88963@@ -895,7 +895,7 @@ rcu_torture_reader(void *arg)
88964 continue;
88965 }
88966 if (p->rtort_mbtest == 0)
88967- atomic_inc(&n_rcu_torture_mberror);
88968+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88969 cur_ops->read_delay(&rand);
88970 preempt_disable();
88971 pipe_count = p->rtort_pipe_count;
88972@@ -950,15 +950,15 @@ rcu_torture_printk(char *page)
88973 }
88974 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
88975 page += sprintf(page,
88976- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
88977+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
88978 rcu_torture_current,
88979 rcu_torture_current_version,
88980 list_empty(&rcu_torture_freelist),
88981- atomic_read(&n_rcu_torture_alloc),
88982- atomic_read(&n_rcu_torture_alloc_fail),
88983- atomic_read(&n_rcu_torture_free));
88984+ atomic_read_unchecked(&n_rcu_torture_alloc),
88985+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
88986+ atomic_read_unchecked(&n_rcu_torture_free));
88987 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
88988- atomic_read(&n_rcu_torture_mberror),
88989+ atomic_read_unchecked(&n_rcu_torture_mberror),
88990 n_rcu_torture_boost_ktrerror,
88991 n_rcu_torture_boost_rterror);
88992 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
88993@@ -971,14 +971,14 @@ rcu_torture_printk(char *page)
88994 n_barrier_attempts,
88995 n_rcu_torture_barrier_error);
88996 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
88997- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
88998+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
88999 n_rcu_torture_barrier_error != 0 ||
89000 n_rcu_torture_boost_ktrerror != 0 ||
89001 n_rcu_torture_boost_rterror != 0 ||
89002 n_rcu_torture_boost_failure != 0 ||
89003 i > 1) {
89004 page += sprintf(page, "!!! ");
89005- atomic_inc(&n_rcu_torture_error);
89006+ atomic_inc_unchecked(&n_rcu_torture_error);
89007 WARN_ON_ONCE(1);
89008 }
89009 page += sprintf(page, "Reader Pipe: ");
89010@@ -992,7 +992,7 @@ rcu_torture_printk(char *page)
89011 page += sprintf(page, "Free-Block Circulation: ");
89012 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89013 page += sprintf(page, " %d",
89014- atomic_read(&rcu_torture_wcount[i]));
89015+ atomic_read_unchecked(&rcu_torture_wcount[i]));
89016 }
89017 page += sprintf(page, "\n");
89018 if (cur_ops->stats)
89019@@ -1341,7 +1341,7 @@ rcu_torture_cleanup(void)
89020
89021 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
89022
89023- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89024+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89025 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
89026 else if (torture_onoff_failures())
89027 rcu_torture_print_module_parms(cur_ops,
89028@@ -1460,18 +1460,18 @@ rcu_torture_init(void)
89029
89030 rcu_torture_current = NULL;
89031 rcu_torture_current_version = 0;
89032- atomic_set(&n_rcu_torture_alloc, 0);
89033- atomic_set(&n_rcu_torture_alloc_fail, 0);
89034- atomic_set(&n_rcu_torture_free, 0);
89035- atomic_set(&n_rcu_torture_mberror, 0);
89036- atomic_set(&n_rcu_torture_error, 0);
89037+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
89038+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
89039+ atomic_set_unchecked(&n_rcu_torture_free, 0);
89040+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
89041+ atomic_set_unchecked(&n_rcu_torture_error, 0);
89042 n_rcu_torture_barrier_error = 0;
89043 n_rcu_torture_boost_ktrerror = 0;
89044 n_rcu_torture_boost_rterror = 0;
89045 n_rcu_torture_boost_failure = 0;
89046 n_rcu_torture_boosts = 0;
89047 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
89048- atomic_set(&rcu_torture_wcount[i], 0);
89049+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
89050 for_each_possible_cpu(cpu) {
89051 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89052 per_cpu(rcu_torture_count, cpu)[i] = 0;
89053diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
89054index c639556..cf0a0d5 100644
89055--- a/kernel/rcu/srcu.c
89056+++ b/kernel/rcu/srcu.c
89057@@ -298,9 +298,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
89058
89059 idx = ACCESS_ONCE(sp->completed) & 0x1;
89060 preempt_disable();
89061- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89062+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89063 smp_mb(); /* B */ /* Avoid leaking the critical section. */
89064- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89065+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89066 preempt_enable();
89067 return idx;
89068 }
89069diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
89070index d9efcc1..ea543e9 100644
89071--- a/kernel/rcu/tiny.c
89072+++ b/kernel/rcu/tiny.c
89073@@ -42,7 +42,7 @@
89074 /* Forward declarations for tiny_plugin.h. */
89075 struct rcu_ctrlblk;
89076 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
89077-static void rcu_process_callbacks(struct softirq_action *unused);
89078+static void rcu_process_callbacks(void);
89079 static void __call_rcu(struct rcu_head *head,
89080 void (*func)(struct rcu_head *rcu),
89081 struct rcu_ctrlblk *rcp);
89082@@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
89083 false));
89084 }
89085
89086-static void rcu_process_callbacks(struct softirq_action *unused)
89087+static __latent_entropy void rcu_process_callbacks(void)
89088 {
89089 __rcu_process_callbacks(&rcu_sched_ctrlblk);
89090 __rcu_process_callbacks(&rcu_bh_ctrlblk);
89091diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89092index 0c47e30..a084591 100644
89093--- a/kernel/rcu/tree.c
89094+++ b/kernel/rcu/tree.c
89095@@ -388,9 +388,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89096 rcu_prepare_for_idle(smp_processor_id());
89097 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89098 smp_mb__before_atomic_inc(); /* See above. */
89099- atomic_inc(&rdtp->dynticks);
89100+ atomic_inc_unchecked(&rdtp->dynticks);
89101 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89102- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89103+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89104
89105 /*
89106 * It is illegal to enter an extended quiescent state while
89107@@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89108 int user)
89109 {
89110 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89111- atomic_inc(&rdtp->dynticks);
89112+ atomic_inc_unchecked(&rdtp->dynticks);
89113 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89114 smp_mb__after_atomic_inc(); /* See above. */
89115- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89116+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89117 rcu_cleanup_after_idle(smp_processor_id());
89118 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89119 if (!user && !is_idle_task(current)) {
89120@@ -632,14 +632,14 @@ void rcu_nmi_enter(void)
89121 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89122
89123 if (rdtp->dynticks_nmi_nesting == 0 &&
89124- (atomic_read(&rdtp->dynticks) & 0x1))
89125+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89126 return;
89127 rdtp->dynticks_nmi_nesting++;
89128 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89129- atomic_inc(&rdtp->dynticks);
89130+ atomic_inc_unchecked(&rdtp->dynticks);
89131 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89132 smp_mb__after_atomic_inc(); /* See above. */
89133- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89134+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89135 }
89136
89137 /**
89138@@ -658,9 +658,9 @@ void rcu_nmi_exit(void)
89139 return;
89140 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89141 smp_mb__before_atomic_inc(); /* See above. */
89142- atomic_inc(&rdtp->dynticks);
89143+ atomic_inc_unchecked(&rdtp->dynticks);
89144 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89145- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89146+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89147 }
89148
89149 /**
89150@@ -673,7 +673,7 @@ void rcu_nmi_exit(void)
89151 */
89152 bool notrace __rcu_is_watching(void)
89153 {
89154- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89155+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89156 }
89157
89158 /**
89159@@ -756,7 +756,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89160 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89161 bool *isidle, unsigned long *maxj)
89162 {
89163- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89164+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89165 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89166 return (rdp->dynticks_snap & 0x1) == 0;
89167 }
89168@@ -779,7 +779,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89169 unsigned int curr;
89170 unsigned int snap;
89171
89172- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89173+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89174 snap = (unsigned int)rdp->dynticks_snap;
89175
89176 /*
89177@@ -1449,9 +1449,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89178 rdp = this_cpu_ptr(rsp->rda);
89179 rcu_preempt_check_blocked_tasks(rnp);
89180 rnp->qsmask = rnp->qsmaskinit;
89181- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89182+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89183 WARN_ON_ONCE(rnp->completed != rsp->completed);
89184- ACCESS_ONCE(rnp->completed) = rsp->completed;
89185+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89186 if (rnp == rdp->mynode)
89187 __note_gp_changes(rsp, rnp, rdp);
89188 rcu_preempt_boost_start_gp(rnp);
89189@@ -1545,7 +1545,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89190 rcu_for_each_node_breadth_first(rsp, rnp) {
89191 raw_spin_lock_irq(&rnp->lock);
89192 smp_mb__after_unlock_lock();
89193- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89194+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89195 rdp = this_cpu_ptr(rsp->rda);
89196 if (rnp == rdp->mynode)
89197 __note_gp_changes(rsp, rnp, rdp);
89198@@ -1560,7 +1560,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89199 rcu_nocb_gp_set(rnp, nocb);
89200
89201 /* Declare grace period done. */
89202- ACCESS_ONCE(rsp->completed) = rsp->gpnum;
89203+ ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
89204 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
89205 rsp->fqs_state = RCU_GP_IDLE;
89206 rdp = this_cpu_ptr(rsp->rda);
89207@@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89208 rsp->qlen += rdp->qlen;
89209 rdp->n_cbs_orphaned += rdp->qlen;
89210 rdp->qlen_lazy = 0;
89211- ACCESS_ONCE(rdp->qlen) = 0;
89212+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89213 }
89214
89215 /*
89216@@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89217 }
89218 smp_mb(); /* List handling before counting for rcu_barrier(). */
89219 rdp->qlen_lazy -= count_lazy;
89220- ACCESS_ONCE(rdp->qlen) -= count;
89221+ ACCESS_ONCE_RW(rdp->qlen) -= count;
89222 rdp->n_cbs_invoked += count;
89223
89224 /* Reinstate batch limit if we have worked down the excess. */
89225@@ -2304,7 +2304,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89226 if (rnp_old != NULL)
89227 raw_spin_unlock(&rnp_old->fqslock);
89228 if (ret) {
89229- ACCESS_ONCE(rsp->n_force_qs_lh)++;
89230+ ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89231 return;
89232 }
89233 rnp_old = rnp;
89234@@ -2316,7 +2316,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89235 smp_mb__after_unlock_lock();
89236 raw_spin_unlock(&rnp_old->fqslock);
89237 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
89238- ACCESS_ONCE(rsp->n_force_qs_lh)++;
89239+ ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89240 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
89241 return; /* Someone beat us to it. */
89242 }
89243@@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89244 /*
89245 * Do RCU core processing for the current CPU.
89246 */
89247-static void rcu_process_callbacks(struct softirq_action *unused)
89248+static void rcu_process_callbacks(void)
89249 {
89250 struct rcu_state *rsp;
89251
89252@@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89253 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89254 if (debug_rcu_head_queue(head)) {
89255 /* Probable double call_rcu(), so leak the callback. */
89256- ACCESS_ONCE(head->func) = rcu_leak_callback;
89257+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89258 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89259 return;
89260 }
89261@@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89262 local_irq_restore(flags);
89263 return;
89264 }
89265- ACCESS_ONCE(rdp->qlen)++;
89266+ ACCESS_ONCE_RW(rdp->qlen)++;
89267 if (lazy)
89268 rdp->qlen_lazy++;
89269 else
89270@@ -2759,11 +2759,11 @@ void synchronize_sched_expedited(void)
89271 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89272 * course be required on a 64-bit system.
89273 */
89274- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89275+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89276 (ulong)atomic_long_read(&rsp->expedited_done) +
89277 ULONG_MAX / 8)) {
89278 synchronize_sched();
89279- atomic_long_inc(&rsp->expedited_wrap);
89280+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
89281 return;
89282 }
89283
89284@@ -2771,7 +2771,7 @@ void synchronize_sched_expedited(void)
89285 * Take a ticket. Note that atomic_inc_return() implies a
89286 * full memory barrier.
89287 */
89288- snap = atomic_long_inc_return(&rsp->expedited_start);
89289+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
89290 firstsnap = snap;
89291 get_online_cpus();
89292 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
89293@@ -2784,14 +2784,14 @@ void synchronize_sched_expedited(void)
89294 synchronize_sched_expedited_cpu_stop,
89295 NULL) == -EAGAIN) {
89296 put_online_cpus();
89297- atomic_long_inc(&rsp->expedited_tryfail);
89298+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
89299
89300 /* Check to see if someone else did our work for us. */
89301 s = atomic_long_read(&rsp->expedited_done);
89302 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89303 /* ensure test happens before caller kfree */
89304 smp_mb__before_atomic_inc(); /* ^^^ */
89305- atomic_long_inc(&rsp->expedited_workdone1);
89306+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
89307 return;
89308 }
89309
89310@@ -2800,7 +2800,7 @@ void synchronize_sched_expedited(void)
89311 udelay(trycount * num_online_cpus());
89312 } else {
89313 wait_rcu_gp(call_rcu_sched);
89314- atomic_long_inc(&rsp->expedited_normal);
89315+ atomic_long_inc_unchecked(&rsp->expedited_normal);
89316 return;
89317 }
89318
89319@@ -2809,7 +2809,7 @@ void synchronize_sched_expedited(void)
89320 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89321 /* ensure test happens before caller kfree */
89322 smp_mb__before_atomic_inc(); /* ^^^ */
89323- atomic_long_inc(&rsp->expedited_workdone2);
89324+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
89325 return;
89326 }
89327
89328@@ -2821,10 +2821,10 @@ void synchronize_sched_expedited(void)
89329 * period works for us.
89330 */
89331 get_online_cpus();
89332- snap = atomic_long_read(&rsp->expedited_start);
89333+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
89334 smp_mb(); /* ensure read is before try_stop_cpus(). */
89335 }
89336- atomic_long_inc(&rsp->expedited_stoppedcpus);
89337+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
89338
89339 /*
89340 * Everyone up to our most recent fetch is covered by our grace
89341@@ -2833,16 +2833,16 @@ void synchronize_sched_expedited(void)
89342 * than we did already did their update.
89343 */
89344 do {
89345- atomic_long_inc(&rsp->expedited_done_tries);
89346+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
89347 s = atomic_long_read(&rsp->expedited_done);
89348 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
89349 /* ensure test happens before caller kfree */
89350 smp_mb__before_atomic_inc(); /* ^^^ */
89351- atomic_long_inc(&rsp->expedited_done_lost);
89352+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
89353 break;
89354 }
89355 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
89356- atomic_long_inc(&rsp->expedited_done_exit);
89357+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
89358
89359 put_online_cpus();
89360 }
89361@@ -3048,7 +3048,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89362 * ACCESS_ONCE() to prevent the compiler from speculating
89363 * the increment to precede the early-exit check.
89364 */
89365- ACCESS_ONCE(rsp->n_barrier_done)++;
89366+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89367 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
89368 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
89369 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
89370@@ -3098,7 +3098,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89371
89372 /* Increment ->n_barrier_done to prevent duplicate work. */
89373 smp_mb(); /* Keep increment after above mechanism. */
89374- ACCESS_ONCE(rsp->n_barrier_done)++;
89375+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89376 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
89377 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
89378 smp_mb(); /* Keep increment before caller's subsequent code. */
89379@@ -3143,10 +3143,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
89380 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
89381 init_callback_list(rdp);
89382 rdp->qlen_lazy = 0;
89383- ACCESS_ONCE(rdp->qlen) = 0;
89384+ ACCESS_ONCE_RW(rdp->qlen) = 0;
89385 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
89386 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
89387- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
89388+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
89389 rdp->cpu = cpu;
89390 rdp->rsp = rsp;
89391 rcu_boot_init_nocb_percpu_data(rdp);
89392@@ -3180,8 +3180,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
89393 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
89394 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
89395 rcu_sysidle_init_percpu_data(rdp->dynticks);
89396- atomic_set(&rdp->dynticks->dynticks,
89397- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
89398+ atomic_set_unchecked(&rdp->dynticks->dynticks,
89399+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
89400 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
89401
89402 /* Add CPU to rcu_node bitmasks. */
89403diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
89404index 75dc3c3..b95d624 100644
89405--- a/kernel/rcu/tree.h
89406+++ b/kernel/rcu/tree.h
89407@@ -87,11 +87,11 @@ struct rcu_dynticks {
89408 long long dynticks_nesting; /* Track irq/process nesting level. */
89409 /* Process level is worth LLONG_MAX/2. */
89410 int dynticks_nmi_nesting; /* Track NMI nesting level. */
89411- atomic_t dynticks; /* Even value for idle, else odd. */
89412+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
89413 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
89414 long long dynticks_idle_nesting;
89415 /* irq/process nesting level from idle. */
89416- atomic_t dynticks_idle; /* Even value for idle, else odd. */
89417+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
89418 /* "Idle" excludes userspace execution. */
89419 unsigned long dynticks_idle_jiffies;
89420 /* End of last non-NMI non-idle period. */
89421@@ -431,17 +431,17 @@ struct rcu_state {
89422 /* _rcu_barrier(). */
89423 /* End of fields guarded by barrier_mutex. */
89424
89425- atomic_long_t expedited_start; /* Starting ticket. */
89426- atomic_long_t expedited_done; /* Done ticket. */
89427- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89428- atomic_long_t expedited_tryfail; /* # acquisition failures. */
89429- atomic_long_t expedited_workdone1; /* # done by others #1. */
89430- atomic_long_t expedited_workdone2; /* # done by others #2. */
89431- atomic_long_t expedited_normal; /* # fallbacks to normal. */
89432- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89433- atomic_long_t expedited_done_tries; /* # tries to update _done. */
89434- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89435- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89436+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89437+ atomic_long_t expedited_done; /* Done ticket. */
89438+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89439+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89440+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89441+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89442+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89443+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89444+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89445+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89446+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89447
89448 unsigned long jiffies_force_qs; /* Time at which to invoke */
89449 /* force_quiescent_state(). */
89450diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89451index 962d1d5..c6c62d12d 100644
89452--- a/kernel/rcu/tree_plugin.h
89453+++ b/kernel/rcu/tree_plugin.h
89454@@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89455 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89456 {
89457 return !rcu_preempted_readers_exp(rnp) &&
89458- ACCESS_ONCE(rnp->expmask) == 0;
89459+ ACCESS_ONCE_RW(rnp->expmask) == 0;
89460 }
89461
89462 /*
89463@@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89464
89465 /* Clean up and exit. */
89466 smp_mb(); /* ensure expedited GP seen before counter increment. */
89467- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89468+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89469 unlock_mb_ret:
89470 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89471 mb_ret:
89472@@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89473 free_cpumask_var(cm);
89474 }
89475
89476-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89477+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89478 .store = &rcu_cpu_kthread_task,
89479 .thread_should_run = rcu_cpu_kthread_should_run,
89480 .thread_fn = rcu_cpu_kthread,
89481@@ -1972,7 +1972,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89482 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89483 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89484 cpu, ticks_value, ticks_title,
89485- atomic_read(&rdtp->dynticks) & 0xfff,
89486+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89487 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89488 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89489 fast_no_hz);
89490@@ -2138,7 +2138,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89491
89492 /* Enqueue the callback on the nocb list and update counts. */
89493 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89494- ACCESS_ONCE(*old_rhpp) = rhp;
89495+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
89496 atomic_long_add(rhcount, &rdp->nocb_q_count);
89497 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89498
89499@@ -2311,12 +2311,12 @@ static int rcu_nocb_kthread(void *arg)
89500 * Extract queued callbacks, update counts, and wait
89501 * for a grace period to elapse.
89502 */
89503- ACCESS_ONCE(rdp->nocb_head) = NULL;
89504+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89505 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89506 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89507 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89508- ACCESS_ONCE(rdp->nocb_p_count) += c;
89509- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89510+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89511+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89512 rcu_nocb_wait_gp(rdp);
89513
89514 /* Each pass through the following loop invokes a callback. */
89515@@ -2342,8 +2342,8 @@ static int rcu_nocb_kthread(void *arg)
89516 list = next;
89517 }
89518 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89519- ACCESS_ONCE(rdp->nocb_p_count) -= c;
89520- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89521+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89522+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89523 rdp->n_nocbs_invoked += c;
89524 }
89525 return 0;
89526@@ -2360,7 +2360,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89527 {
89528 if (!rcu_nocb_need_deferred_wakeup(rdp))
89529 return;
89530- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89531+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89532 wake_up(&rdp->nocb_wq);
89533 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89534 }
89535@@ -2386,7 +2386,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89536 t = kthread_run(rcu_nocb_kthread, rdp,
89537 "rcuo%c/%d", rsp->abbr, cpu);
89538 BUG_ON(IS_ERR(t));
89539- ACCESS_ONCE(rdp->nocb_kthread) = t;
89540+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89541 }
89542 }
89543
89544@@ -2522,11 +2522,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89545
89546 /* Record start of fully idle period. */
89547 j = jiffies;
89548- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89549+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89550 smp_mb__before_atomic_inc();
89551- atomic_inc(&rdtp->dynticks_idle);
89552+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89553 smp_mb__after_atomic_inc();
89554- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89555+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89556 }
89557
89558 /*
89559@@ -2591,9 +2591,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89560
89561 /* Record end of idle period. */
89562 smp_mb__before_atomic_inc();
89563- atomic_inc(&rdtp->dynticks_idle);
89564+ atomic_inc_unchecked(&rdtp->dynticks_idle);
89565 smp_mb__after_atomic_inc();
89566- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
89567+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
89568
89569 /*
89570 * If we are the timekeeping CPU, we are permitted to be non-idle
89571@@ -2634,7 +2634,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
89572 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
89573
89574 /* Pick up current idle and NMI-nesting counter and check. */
89575- cur = atomic_read(&rdtp->dynticks_idle);
89576+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
89577 if (cur & 0x1) {
89578 *isidle = false; /* We are not idle! */
89579 return;
89580@@ -2697,7 +2697,7 @@ static void rcu_sysidle(unsigned long j)
89581 case RCU_SYSIDLE_NOT:
89582
89583 /* First time all are idle, so note a short idle period. */
89584- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89585+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89586 break;
89587
89588 case RCU_SYSIDLE_SHORT:
89589@@ -2734,7 +2734,7 @@ static void rcu_sysidle(unsigned long j)
89590 static void rcu_sysidle_cancel(void)
89591 {
89592 smp_mb();
89593- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
89594+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
89595 }
89596
89597 /*
89598@@ -2782,7 +2782,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
89599 smp_mb(); /* grace period precedes setting inuse. */
89600
89601 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
89602- ACCESS_ONCE(rshp->inuse) = 0;
89603+ ACCESS_ONCE_RW(rshp->inuse) = 0;
89604 }
89605
89606 /*
89607diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
89608index 5cdc62e..cc52e88 100644
89609--- a/kernel/rcu/tree_trace.c
89610+++ b/kernel/rcu/tree_trace.c
89611@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
89612 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
89613 rdp->passed_quiesce, rdp->qs_pending);
89614 seq_printf(m, " dt=%d/%llx/%d df=%lu",
89615- atomic_read(&rdp->dynticks->dynticks),
89616+ atomic_read_unchecked(&rdp->dynticks->dynticks),
89617 rdp->dynticks->dynticks_nesting,
89618 rdp->dynticks->dynticks_nmi_nesting,
89619 rdp->dynticks_fqs);
89620@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
89621 struct rcu_state *rsp = (struct rcu_state *)m->private;
89622
89623 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",
89624- atomic_long_read(&rsp->expedited_start),
89625+ atomic_long_read_unchecked(&rsp->expedited_start),
89626 atomic_long_read(&rsp->expedited_done),
89627- atomic_long_read(&rsp->expedited_wrap),
89628- atomic_long_read(&rsp->expedited_tryfail),
89629- atomic_long_read(&rsp->expedited_workdone1),
89630- atomic_long_read(&rsp->expedited_workdone2),
89631- atomic_long_read(&rsp->expedited_normal),
89632- atomic_long_read(&rsp->expedited_stoppedcpus),
89633- atomic_long_read(&rsp->expedited_done_tries),
89634- atomic_long_read(&rsp->expedited_done_lost),
89635- atomic_long_read(&rsp->expedited_done_exit));
89636+ atomic_long_read_unchecked(&rsp->expedited_wrap),
89637+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
89638+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
89639+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
89640+ atomic_long_read_unchecked(&rsp->expedited_normal),
89641+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
89642+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
89643+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
89644+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
89645 return 0;
89646 }
89647
89648diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
89649index 4c0a9b0..7e81362 100644
89650--- a/kernel/rcu/update.c
89651+++ b/kernel/rcu/update.c
89652@@ -311,10 +311,10 @@ int rcu_jiffies_till_stall_check(void)
89653 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
89654 */
89655 if (till_stall_check < 3) {
89656- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
89657+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
89658 till_stall_check = 3;
89659 } else if (till_stall_check > 300) {
89660- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
89661+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
89662 till_stall_check = 300;
89663 }
89664 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
89665diff --git a/kernel/resource.c b/kernel/resource.c
89666index 8957d68..770cbe4 100644
89667--- a/kernel/resource.c
89668+++ b/kernel/resource.c
89669@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
89670
89671 static int __init ioresources_init(void)
89672 {
89673+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89674+#ifdef CONFIG_GRKERNSEC_PROC_USER
89675+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
89676+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
89677+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89678+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
89679+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
89680+#endif
89681+#else
89682 proc_create("ioports", 0, NULL, &proc_ioports_operations);
89683 proc_create("iomem", 0, NULL, &proc_iomem_operations);
89684+#endif
89685 return 0;
89686 }
89687 __initcall(ioresources_init);
89688diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
89689index e73efba..c9bfbd4 100644
89690--- a/kernel/sched/auto_group.c
89691+++ b/kernel/sched/auto_group.c
89692@@ -11,7 +11,7 @@
89693
89694 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
89695 static struct autogroup autogroup_default;
89696-static atomic_t autogroup_seq_nr;
89697+static atomic_unchecked_t autogroup_seq_nr;
89698
89699 void __init autogroup_init(struct task_struct *init_task)
89700 {
89701@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
89702
89703 kref_init(&ag->kref);
89704 init_rwsem(&ag->lock);
89705- ag->id = atomic_inc_return(&autogroup_seq_nr);
89706+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
89707 ag->tg = tg;
89708 #ifdef CONFIG_RT_GROUP_SCHED
89709 /*
89710diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
89711index a63f4dc..349bbb0 100644
89712--- a/kernel/sched/completion.c
89713+++ b/kernel/sched/completion.c
89714@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
89715 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89716 * or number of jiffies left till timeout) if completed.
89717 */
89718-long __sched
89719+long __sched __intentional_overflow(-1)
89720 wait_for_completion_interruptible_timeout(struct completion *x,
89721 unsigned long timeout)
89722 {
89723@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
89724 *
89725 * Return: -ERESTARTSYS if interrupted, 0 if completed.
89726 */
89727-int __sched wait_for_completion_killable(struct completion *x)
89728+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
89729 {
89730 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
89731 if (t == -ERESTARTSYS)
89732@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
89733 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89734 * or number of jiffies left till timeout) if completed.
89735 */
89736-long __sched
89737+long __sched __intentional_overflow(-1)
89738 wait_for_completion_killable_timeout(struct completion *x,
89739 unsigned long timeout)
89740 {
89741diff --git a/kernel/sched/core.c b/kernel/sched/core.c
89742index 084d17f..e416b9f 100644
89743--- a/kernel/sched/core.c
89744+++ b/kernel/sched/core.c
89745@@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
89746 int sysctl_numa_balancing(struct ctl_table *table, int write,
89747 void __user *buffer, size_t *lenp, loff_t *ppos)
89748 {
89749- struct ctl_table t;
89750+ ctl_table_no_const t;
89751 int err;
89752 int state = numabalancing_enabled;
89753
89754@@ -2238,8 +2238,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
89755 next->active_mm = oldmm;
89756 atomic_inc(&oldmm->mm_count);
89757 enter_lazy_tlb(oldmm, next);
89758- } else
89759+ } else {
89760 switch_mm(oldmm, mm, next);
89761+ populate_stack();
89762+ }
89763
89764 if (!prev->mm) {
89765 prev->active_mm = NULL;
89766@@ -3004,6 +3006,8 @@ int can_nice(const struct task_struct *p, const int nice)
89767 /* convert nice value [19,-20] to rlimit style value [1,40] */
89768 int nice_rlim = 20 - nice;
89769
89770+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
89771+
89772 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
89773 capable(CAP_SYS_NICE));
89774 }
89775@@ -3037,7 +3041,8 @@ SYSCALL_DEFINE1(nice, int, increment)
89776 if (nice > MAX_NICE)
89777 nice = MAX_NICE;
89778
89779- if (increment < 0 && !can_nice(current, nice))
89780+ if (increment < 0 && (!can_nice(current, nice) ||
89781+ gr_handle_chroot_nice()))
89782 return -EPERM;
89783
89784 retval = security_task_setnice(current, nice);
89785@@ -3310,6 +3315,7 @@ recheck:
89786 if (policy != p->policy && !rlim_rtprio)
89787 return -EPERM;
89788
89789+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
89790 /* can't increase priority */
89791 if (attr->sched_priority > p->rt_priority &&
89792 attr->sched_priority > rlim_rtprio)
89793@@ -4708,6 +4714,7 @@ void idle_task_exit(void)
89794
89795 if (mm != &init_mm) {
89796 switch_mm(mm, &init_mm, current);
89797+ populate_stack();
89798 finish_arch_post_lock_switch();
89799 }
89800 mmdrop(mm);
89801@@ -4803,7 +4810,7 @@ static void migrate_tasks(unsigned int dead_cpu)
89802
89803 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
89804
89805-static struct ctl_table sd_ctl_dir[] = {
89806+static ctl_table_no_const sd_ctl_dir[] __read_only = {
89807 {
89808 .procname = "sched_domain",
89809 .mode = 0555,
89810@@ -4820,17 +4827,17 @@ static struct ctl_table sd_ctl_root[] = {
89811 {}
89812 };
89813
89814-static struct ctl_table *sd_alloc_ctl_entry(int n)
89815+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
89816 {
89817- struct ctl_table *entry =
89818+ ctl_table_no_const *entry =
89819 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
89820
89821 return entry;
89822 }
89823
89824-static void sd_free_ctl_entry(struct ctl_table **tablep)
89825+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
89826 {
89827- struct ctl_table *entry;
89828+ ctl_table_no_const *entry;
89829
89830 /*
89831 * In the intermediate directories, both the child directory and
89832@@ -4838,22 +4845,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
89833 * will always be set. In the lowest directory the names are
89834 * static strings and all have proc handlers.
89835 */
89836- for (entry = *tablep; entry->mode; entry++) {
89837- if (entry->child)
89838- sd_free_ctl_entry(&entry->child);
89839+ for (entry = tablep; entry->mode; entry++) {
89840+ if (entry->child) {
89841+ sd_free_ctl_entry(entry->child);
89842+ pax_open_kernel();
89843+ entry->child = NULL;
89844+ pax_close_kernel();
89845+ }
89846 if (entry->proc_handler == NULL)
89847 kfree(entry->procname);
89848 }
89849
89850- kfree(*tablep);
89851- *tablep = NULL;
89852+ kfree(tablep);
89853 }
89854
89855 static int min_load_idx = 0;
89856 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
89857
89858 static void
89859-set_table_entry(struct ctl_table *entry,
89860+set_table_entry(ctl_table_no_const *entry,
89861 const char *procname, void *data, int maxlen,
89862 umode_t mode, proc_handler *proc_handler,
89863 bool load_idx)
89864@@ -4873,7 +4883,7 @@ set_table_entry(struct ctl_table *entry,
89865 static struct ctl_table *
89866 sd_alloc_ctl_domain_table(struct sched_domain *sd)
89867 {
89868- struct ctl_table *table = sd_alloc_ctl_entry(14);
89869+ ctl_table_no_const *table = sd_alloc_ctl_entry(14);
89870
89871 if (table == NULL)
89872 return NULL;
89873@@ -4911,9 +4921,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
89874 return table;
89875 }
89876
89877-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
89878+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
89879 {
89880- struct ctl_table *entry, *table;
89881+ ctl_table_no_const *entry, *table;
89882 struct sched_domain *sd;
89883 int domain_num = 0, i;
89884 char buf[32];
89885@@ -4940,11 +4950,13 @@ static struct ctl_table_header *sd_sysctl_header;
89886 static void register_sched_domain_sysctl(void)
89887 {
89888 int i, cpu_num = num_possible_cpus();
89889- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
89890+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
89891 char buf[32];
89892
89893 WARN_ON(sd_ctl_dir[0].child);
89894+ pax_open_kernel();
89895 sd_ctl_dir[0].child = entry;
89896+ pax_close_kernel();
89897
89898 if (entry == NULL)
89899 return;
89900@@ -4967,8 +4979,12 @@ static void unregister_sched_domain_sysctl(void)
89901 if (sd_sysctl_header)
89902 unregister_sysctl_table(sd_sysctl_header);
89903 sd_sysctl_header = NULL;
89904- if (sd_ctl_dir[0].child)
89905- sd_free_ctl_entry(&sd_ctl_dir[0].child);
89906+ if (sd_ctl_dir[0].child) {
89907+ sd_free_ctl_entry(sd_ctl_dir[0].child);
89908+ pax_open_kernel();
89909+ sd_ctl_dir[0].child = NULL;
89910+ pax_close_kernel();
89911+ }
89912 }
89913 #else
89914 static void register_sched_domain_sysctl(void)
89915diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89916index 8cbe2d2..61f20a1 100644
89917--- a/kernel/sched/fair.c
89918+++ b/kernel/sched/fair.c
89919@@ -1806,7 +1806,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
89920
89921 static void reset_ptenuma_scan(struct task_struct *p)
89922 {
89923- ACCESS_ONCE(p->mm->numa_scan_seq)++;
89924+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89925 p->mm->numa_scan_offset = 0;
89926 }
89927
89928@@ -7181,7 +7181,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
89929 * run_rebalance_domains is triggered when needed from the scheduler tick.
89930 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89931 */
89932-static void run_rebalance_domains(struct softirq_action *h)
89933+static __latent_entropy void run_rebalance_domains(void)
89934 {
89935 struct rq *this_rq = this_rq();
89936 enum cpu_idle_type idle = this_rq->idle_balance ?
89937diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89938index 369b4d6..fa4eb3b 100644
89939--- a/kernel/sched/sched.h
89940+++ b/kernel/sched/sched.h
89941@@ -1157,7 +1157,7 @@ struct sched_class {
89942 #ifdef CONFIG_FAIR_GROUP_SCHED
89943 void (*task_move_group) (struct task_struct *p, int on_rq);
89944 #endif
89945-};
89946+} __do_const;
89947
89948 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
89949 {
89950diff --git a/kernel/signal.c b/kernel/signal.c
89951index 6ea13c0..31e3b25 100644
89952--- a/kernel/signal.c
89953+++ b/kernel/signal.c
89954@@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
89955
89956 int print_fatal_signals __read_mostly;
89957
89958-static void __user *sig_handler(struct task_struct *t, int sig)
89959+static __sighandler_t sig_handler(struct task_struct *t, int sig)
89960 {
89961 return t->sighand->action[sig - 1].sa.sa_handler;
89962 }
89963
89964-static int sig_handler_ignored(void __user *handler, int sig)
89965+static int sig_handler_ignored(__sighandler_t handler, int sig)
89966 {
89967 /* Is it explicitly or implicitly ignored? */
89968 return handler == SIG_IGN ||
89969@@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
89970
89971 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
89972 {
89973- void __user *handler;
89974+ __sighandler_t handler;
89975
89976 handler = sig_handler(t, sig);
89977
89978@@ -371,6 +371,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
89979 atomic_inc(&user->sigpending);
89980 rcu_read_unlock();
89981
89982+ if (!override_rlimit)
89983+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
89984+
89985 if (override_rlimit ||
89986 atomic_read(&user->sigpending) <=
89987 task_rlimit(t, RLIMIT_SIGPENDING)) {
89988@@ -498,7 +501,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
89989
89990 int unhandled_signal(struct task_struct *tsk, int sig)
89991 {
89992- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
89993+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
89994 if (is_global_init(tsk))
89995 return 1;
89996 if (handler != SIG_IGN && handler != SIG_DFL)
89997@@ -818,6 +821,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89998 }
89999 }
90000
90001+ /* allow glibc communication via tgkill to other threads in our
90002+ thread group */
90003+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
90004+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
90005+ && gr_handle_signal(t, sig))
90006+ return -EPERM;
90007+
90008 return security_task_kill(t, info, sig, 0);
90009 }
90010
90011@@ -1201,7 +1211,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90012 return send_signal(sig, info, p, 1);
90013 }
90014
90015-static int
90016+int
90017 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90018 {
90019 return send_signal(sig, info, t, 0);
90020@@ -1238,6 +1248,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90021 unsigned long int flags;
90022 int ret, blocked, ignored;
90023 struct k_sigaction *action;
90024+ int is_unhandled = 0;
90025
90026 spin_lock_irqsave(&t->sighand->siglock, flags);
90027 action = &t->sighand->action[sig-1];
90028@@ -1252,9 +1263,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90029 }
90030 if (action->sa.sa_handler == SIG_DFL)
90031 t->signal->flags &= ~SIGNAL_UNKILLABLE;
90032+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
90033+ is_unhandled = 1;
90034 ret = specific_send_sig_info(sig, info, t);
90035 spin_unlock_irqrestore(&t->sighand->siglock, flags);
90036
90037+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
90038+ normal operation */
90039+ if (is_unhandled) {
90040+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
90041+ gr_handle_crash(t, sig);
90042+ }
90043+
90044 return ret;
90045 }
90046
90047@@ -1321,8 +1341,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90048 ret = check_kill_permission(sig, info, p);
90049 rcu_read_unlock();
90050
90051- if (!ret && sig)
90052+ if (!ret && sig) {
90053 ret = do_send_sig_info(sig, info, p, true);
90054+ if (!ret)
90055+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
90056+ }
90057
90058 return ret;
90059 }
90060@@ -2928,7 +2951,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
90061 int error = -ESRCH;
90062
90063 rcu_read_lock();
90064- p = find_task_by_vpid(pid);
90065+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90066+ /* allow glibc communication via tgkill to other threads in our
90067+ thread group */
90068+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90069+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
90070+ p = find_task_by_vpid_unrestricted(pid);
90071+ else
90072+#endif
90073+ p = find_task_by_vpid(pid);
90074 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90075 error = check_kill_permission(sig, info, p);
90076 /*
90077@@ -3241,8 +3272,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90078 }
90079 seg = get_fs();
90080 set_fs(KERNEL_DS);
90081- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90082- (stack_t __force __user *) &uoss,
90083+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90084+ (stack_t __force_user *) &uoss,
90085 compat_user_stack_pointer());
90086 set_fs(seg);
90087 if (ret >= 0 && uoss_ptr) {
90088diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90089index eb89e18..a4e6792 100644
90090--- a/kernel/smpboot.c
90091+++ b/kernel/smpboot.c
90092@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90093 }
90094 smpboot_unpark_thread(plug_thread, cpu);
90095 }
90096- list_add(&plug_thread->list, &hotplug_threads);
90097+ pax_list_add(&plug_thread->list, &hotplug_threads);
90098 out:
90099 mutex_unlock(&smpboot_threads_lock);
90100 return ret;
90101@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90102 {
90103 get_online_cpus();
90104 mutex_lock(&smpboot_threads_lock);
90105- list_del(&plug_thread->list);
90106+ pax_list_del(&plug_thread->list);
90107 smpboot_destroy_threads(plug_thread);
90108 mutex_unlock(&smpboot_threads_lock);
90109 put_online_cpus();
90110diff --git a/kernel/softirq.c b/kernel/softirq.c
90111index 92f24f5..db41501 100644
90112--- a/kernel/softirq.c
90113+++ b/kernel/softirq.c
90114@@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90115 EXPORT_SYMBOL(irq_stat);
90116 #endif
90117
90118-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90119+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90120
90121 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90122
90123@@ -268,7 +268,7 @@ restart:
90124 kstat_incr_softirqs_this_cpu(vec_nr);
90125
90126 trace_softirq_entry(vec_nr);
90127- h->action(h);
90128+ h->action();
90129 trace_softirq_exit(vec_nr);
90130 if (unlikely(prev_count != preempt_count())) {
90131 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90132@@ -428,7 +428,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90133 or_softirq_pending(1UL << nr);
90134 }
90135
90136-void open_softirq(int nr, void (*action)(struct softirq_action *))
90137+void __init open_softirq(int nr, void (*action)(void))
90138 {
90139 softirq_vec[nr].action = action;
90140 }
90141@@ -480,7 +480,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90142 }
90143 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90144
90145-static void tasklet_action(struct softirq_action *a)
90146+static void tasklet_action(void)
90147 {
90148 struct tasklet_struct *list;
90149
90150@@ -516,7 +516,7 @@ static void tasklet_action(struct softirq_action *a)
90151 }
90152 }
90153
90154-static void tasklet_hi_action(struct softirq_action *a)
90155+static __latent_entropy void tasklet_hi_action(void)
90156 {
90157 struct tasklet_struct *list;
90158
90159@@ -743,7 +743,7 @@ static struct notifier_block cpu_nfb = {
90160 .notifier_call = cpu_callback
90161 };
90162
90163-static struct smp_hotplug_thread softirq_threads = {
90164+static struct smp_hotplug_thread softirq_threads __read_only = {
90165 .store = &ksoftirqd,
90166 .thread_should_run = ksoftirqd_should_run,
90167 .thread_fn = run_ksoftirqd,
90168diff --git a/kernel/sys.c b/kernel/sys.c
90169index fba0f29..84400e2 100644
90170--- a/kernel/sys.c
90171+++ b/kernel/sys.c
90172@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90173 error = -EACCES;
90174 goto out;
90175 }
90176+
90177+ if (gr_handle_chroot_setpriority(p, niceval)) {
90178+ error = -EACCES;
90179+ goto out;
90180+ }
90181+
90182 no_nice = security_task_setnice(p, niceval);
90183 if (no_nice) {
90184 error = no_nice;
90185@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90186 goto error;
90187 }
90188
90189+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90190+ goto error;
90191+
90192 if (rgid != (gid_t) -1 ||
90193 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90194 new->sgid = new->egid;
90195@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90196 old = current_cred();
90197
90198 retval = -EPERM;
90199+
90200+ if (gr_check_group_change(kgid, kgid, kgid))
90201+ goto error;
90202+
90203 if (ns_capable(old->user_ns, CAP_SETGID))
90204 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90205 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90206@@ -403,7 +416,7 @@ error:
90207 /*
90208 * change the user struct in a credentials set to match the new UID
90209 */
90210-static int set_user(struct cred *new)
90211+int set_user(struct cred *new)
90212 {
90213 struct user_struct *new_user;
90214
90215@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90216 goto error;
90217 }
90218
90219+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90220+ goto error;
90221+
90222 if (!uid_eq(new->uid, old->uid)) {
90223 retval = set_user(new);
90224 if (retval < 0)
90225@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90226 old = current_cred();
90227
90228 retval = -EPERM;
90229+
90230+ if (gr_check_crash_uid(kuid))
90231+ goto error;
90232+ if (gr_check_user_change(kuid, kuid, kuid))
90233+ goto error;
90234+
90235 if (ns_capable(old->user_ns, CAP_SETUID)) {
90236 new->suid = new->uid = kuid;
90237 if (!uid_eq(kuid, old->uid)) {
90238@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90239 goto error;
90240 }
90241
90242+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
90243+ goto error;
90244+
90245 if (ruid != (uid_t) -1) {
90246 new->uid = kruid;
90247 if (!uid_eq(kruid, old->uid)) {
90248@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90249 goto error;
90250 }
90251
90252+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
90253+ goto error;
90254+
90255 if (rgid != (gid_t) -1)
90256 new->gid = krgid;
90257 if (egid != (gid_t) -1)
90258@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90259 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90260 ns_capable(old->user_ns, CAP_SETUID)) {
90261 if (!uid_eq(kuid, old->fsuid)) {
90262+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90263+ goto error;
90264+
90265 new->fsuid = kuid;
90266 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90267 goto change_okay;
90268 }
90269 }
90270
90271+error:
90272 abort_creds(new);
90273 return old_fsuid;
90274
90275@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90276 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90277 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
90278 ns_capable(old->user_ns, CAP_SETGID)) {
90279+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
90280+ goto error;
90281+
90282 if (!gid_eq(kgid, old->fsgid)) {
90283 new->fsgid = kgid;
90284 goto change_okay;
90285 }
90286 }
90287
90288+error:
90289 abort_creds(new);
90290 return old_fsgid;
90291
90292@@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
90293 return -EFAULT;
90294
90295 down_read(&uts_sem);
90296- error = __copy_to_user(&name->sysname, &utsname()->sysname,
90297+ error = __copy_to_user(name->sysname, &utsname()->sysname,
90298 __OLD_UTS_LEN);
90299 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
90300- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
90301+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
90302 __OLD_UTS_LEN);
90303 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
90304- error |= __copy_to_user(&name->release, &utsname()->release,
90305+ error |= __copy_to_user(name->release, &utsname()->release,
90306 __OLD_UTS_LEN);
90307 error |= __put_user(0, name->release + __OLD_UTS_LEN);
90308- error |= __copy_to_user(&name->version, &utsname()->version,
90309+ error |= __copy_to_user(name->version, &utsname()->version,
90310 __OLD_UTS_LEN);
90311 error |= __put_user(0, name->version + __OLD_UTS_LEN);
90312- error |= __copy_to_user(&name->machine, &utsname()->machine,
90313+ error |= __copy_to_user(name->machine, &utsname()->machine,
90314 __OLD_UTS_LEN);
90315 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
90316 up_read(&uts_sem);
90317@@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
90318 */
90319 new_rlim->rlim_cur = 1;
90320 }
90321+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
90322+ is changed to a lower value. Since tasks can be created by the same
90323+ user in between this limit change and an execve by this task, force
90324+ a recheck only for this task by setting PF_NPROC_EXCEEDED
90325+ */
90326+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
90327+ tsk->flags |= PF_NPROC_EXCEEDED;
90328 }
90329 if (!retval) {
90330 if (old_rlim)
90331diff --git a/kernel/sysctl.c b/kernel/sysctl.c
90332index 0e0373f..69f5181 100644
90333--- a/kernel/sysctl.c
90334+++ b/kernel/sysctl.c
90335@@ -94,7 +94,6 @@
90336
90337
90338 #if defined(CONFIG_SYSCTL)
90339-
90340 /* External variables not in a header file. */
90341 extern int max_threads;
90342 extern int suid_dumpable;
90343@@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
90344
90345 /* Constants used for minimum and maximum */
90346 #ifdef CONFIG_LOCKUP_DETECTOR
90347-static int sixty = 60;
90348+static int sixty __read_only = 60;
90349 #endif
90350
90351-static int __maybe_unused neg_one = -1;
90352+static int __maybe_unused neg_one __read_only = -1;
90353
90354-static int zero;
90355-static int __maybe_unused one = 1;
90356-static int __maybe_unused two = 2;
90357-static int __maybe_unused four = 4;
90358-static unsigned long one_ul = 1;
90359-static int one_hundred = 100;
90360+static int zero __read_only = 0;
90361+static int __maybe_unused one __read_only = 1;
90362+static int __maybe_unused two __read_only = 2;
90363+static int __maybe_unused three __read_only = 3;
90364+static int __maybe_unused four __read_only = 4;
90365+static unsigned long one_ul __read_only = 1;
90366+static int one_hundred __read_only = 100;
90367 #ifdef CONFIG_PRINTK
90368-static int ten_thousand = 10000;
90369+static int ten_thousand __read_only = 10000;
90370 #endif
90371
90372 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
90373@@ -178,10 +178,8 @@ static int proc_taint(struct ctl_table *table, int write,
90374 void __user *buffer, size_t *lenp, loff_t *ppos);
90375 #endif
90376
90377-#ifdef CONFIG_PRINTK
90378 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90379 void __user *buffer, size_t *lenp, loff_t *ppos);
90380-#endif
90381
90382 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
90383 void __user *buffer, size_t *lenp, loff_t *ppos);
90384@@ -212,6 +210,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
90385
90386 #endif
90387
90388+extern struct ctl_table grsecurity_table[];
90389+
90390 static struct ctl_table kern_table[];
90391 static struct ctl_table vm_table[];
90392 static struct ctl_table fs_table[];
90393@@ -226,6 +226,20 @@ extern struct ctl_table epoll_table[];
90394 int sysctl_legacy_va_layout;
90395 #endif
90396
90397+#ifdef CONFIG_PAX_SOFTMODE
90398+static ctl_table pax_table[] = {
90399+ {
90400+ .procname = "softmode",
90401+ .data = &pax_softmode,
90402+ .maxlen = sizeof(unsigned int),
90403+ .mode = 0600,
90404+ .proc_handler = &proc_dointvec,
90405+ },
90406+
90407+ { }
90408+};
90409+#endif
90410+
90411 /* The default sysctl tables: */
90412
90413 static struct ctl_table sysctl_base_table[] = {
90414@@ -274,6 +288,22 @@ static int max_extfrag_threshold = 1000;
90415 #endif
90416
90417 static struct ctl_table kern_table[] = {
90418+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
90419+ {
90420+ .procname = "grsecurity",
90421+ .mode = 0500,
90422+ .child = grsecurity_table,
90423+ },
90424+#endif
90425+
90426+#ifdef CONFIG_PAX_SOFTMODE
90427+ {
90428+ .procname = "pax",
90429+ .mode = 0500,
90430+ .child = pax_table,
90431+ },
90432+#endif
90433+
90434 {
90435 .procname = "sched_child_runs_first",
90436 .data = &sysctl_sched_child_runs_first,
90437@@ -629,7 +659,7 @@ static struct ctl_table kern_table[] = {
90438 .data = &modprobe_path,
90439 .maxlen = KMOD_PATH_LEN,
90440 .mode = 0644,
90441- .proc_handler = proc_dostring,
90442+ .proc_handler = proc_dostring_modpriv,
90443 },
90444 {
90445 .procname = "modules_disabled",
90446@@ -796,16 +826,20 @@ static struct ctl_table kern_table[] = {
90447 .extra1 = &zero,
90448 .extra2 = &one,
90449 },
90450+#endif
90451 {
90452 .procname = "kptr_restrict",
90453 .data = &kptr_restrict,
90454 .maxlen = sizeof(int),
90455 .mode = 0644,
90456 .proc_handler = proc_dointvec_minmax_sysadmin,
90457+#ifdef CONFIG_GRKERNSEC_HIDESYM
90458+ .extra1 = &two,
90459+#else
90460 .extra1 = &zero,
90461+#endif
90462 .extra2 = &two,
90463 },
90464-#endif
90465 {
90466 .procname = "ngroups_max",
90467 .data = &ngroups_max,
90468@@ -1050,10 +1084,17 @@ static struct ctl_table kern_table[] = {
90469 */
90470 {
90471 .procname = "perf_event_paranoid",
90472- .data = &sysctl_perf_event_paranoid,
90473- .maxlen = sizeof(sysctl_perf_event_paranoid),
90474+ .data = &sysctl_perf_event_legitimately_concerned,
90475+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90476 .mode = 0644,
90477- .proc_handler = proc_dointvec,
90478+ /* go ahead, be a hero */
90479+ .proc_handler = proc_dointvec_minmax_sysadmin,
90480+ .extra1 = &neg_one,
90481+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90482+ .extra2 = &three,
90483+#else
90484+ .extra2 = &two,
90485+#endif
90486 },
90487 {
90488 .procname = "perf_event_mlock_kb",
90489@@ -1315,6 +1356,13 @@ static struct ctl_table vm_table[] = {
90490 .proc_handler = proc_dointvec_minmax,
90491 .extra1 = &zero,
90492 },
90493+ {
90494+ .procname = "heap_stack_gap",
90495+ .data = &sysctl_heap_stack_gap,
90496+ .maxlen = sizeof(sysctl_heap_stack_gap),
90497+ .mode = 0644,
90498+ .proc_handler = proc_doulongvec_minmax,
90499+ },
90500 #else
90501 {
90502 .procname = "nr_trim_pages",
90503@@ -1779,6 +1827,16 @@ int proc_dostring(struct ctl_table *table, int write,
90504 buffer, lenp, ppos);
90505 }
90506
90507+int proc_dostring_modpriv(struct ctl_table *table, int write,
90508+ void __user *buffer, size_t *lenp, loff_t *ppos)
90509+{
90510+ if (write && !capable(CAP_SYS_MODULE))
90511+ return -EPERM;
90512+
90513+ return _proc_do_string(table->data, table->maxlen, write,
90514+ buffer, lenp, ppos);
90515+}
90516+
90517 static size_t proc_skip_spaces(char **buf)
90518 {
90519 size_t ret;
90520@@ -1884,6 +1942,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90521 len = strlen(tmp);
90522 if (len > *size)
90523 len = *size;
90524+ if (len > sizeof(tmp))
90525+ len = sizeof(tmp);
90526 if (copy_to_user(*buf, tmp, len))
90527 return -EFAULT;
90528 *size -= len;
90529@@ -2048,7 +2108,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90530 static int proc_taint(struct ctl_table *table, int write,
90531 void __user *buffer, size_t *lenp, loff_t *ppos)
90532 {
90533- struct ctl_table t;
90534+ ctl_table_no_const t;
90535 unsigned long tmptaint = get_taint();
90536 int err;
90537
90538@@ -2076,7 +2136,6 @@ static int proc_taint(struct ctl_table *table, int write,
90539 return err;
90540 }
90541
90542-#ifdef CONFIG_PRINTK
90543 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90544 void __user *buffer, size_t *lenp, loff_t *ppos)
90545 {
90546@@ -2085,7 +2144,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90547
90548 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90549 }
90550-#endif
90551
90552 struct do_proc_dointvec_minmax_conv_param {
90553 int *min;
90554@@ -2632,6 +2690,12 @@ int proc_dostring(struct ctl_table *table, int write,
90555 return -ENOSYS;
90556 }
90557
90558+int proc_dostring_modpriv(struct ctl_table *table, int write,
90559+ void __user *buffer, size_t *lenp, loff_t *ppos)
90560+{
90561+ return -ENOSYS;
90562+}
90563+
90564 int proc_dointvec(struct ctl_table *table, int write,
90565 void __user *buffer, size_t *lenp, loff_t *ppos)
90566 {
90567@@ -2688,5 +2752,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
90568 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
90569 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
90570 EXPORT_SYMBOL(proc_dostring);
90571+EXPORT_SYMBOL(proc_dostring_modpriv);
90572 EXPORT_SYMBOL(proc_doulongvec_minmax);
90573 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
90574diff --git a/kernel/taskstats.c b/kernel/taskstats.c
90575index 13d2f7c..c93d0b0 100644
90576--- a/kernel/taskstats.c
90577+++ b/kernel/taskstats.c
90578@@ -28,9 +28,12 @@
90579 #include <linux/fs.h>
90580 #include <linux/file.h>
90581 #include <linux/pid_namespace.h>
90582+#include <linux/grsecurity.h>
90583 #include <net/genetlink.h>
90584 #include <linux/atomic.h>
90585
90586+extern int gr_is_taskstats_denied(int pid);
90587+
90588 /*
90589 * Maximum length of a cpumask that can be specified in
90590 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
90591@@ -576,6 +579,9 @@ err:
90592
90593 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
90594 {
90595+ if (gr_is_taskstats_denied(current->pid))
90596+ return -EACCES;
90597+
90598 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
90599 return cmd_attr_register_cpumask(info);
90600 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
90601diff --git a/kernel/time.c b/kernel/time.c
90602index 7c7964c..2a0d412 100644
90603--- a/kernel/time.c
90604+++ b/kernel/time.c
90605@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
90606 return error;
90607
90608 if (tz) {
90609+ /* we log in do_settimeofday called below, so don't log twice
90610+ */
90611+ if (!tv)
90612+ gr_log_timechange();
90613+
90614 sys_tz = *tz;
90615 update_vsyscall_tz();
90616 if (firsttime) {
90617diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
90618index 88c9c65..7497ebc 100644
90619--- a/kernel/time/alarmtimer.c
90620+++ b/kernel/time/alarmtimer.c
90621@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
90622 struct platform_device *pdev;
90623 int error = 0;
90624 int i;
90625- struct k_clock alarm_clock = {
90626+ static struct k_clock alarm_clock = {
90627 .clock_getres = alarm_clock_getres,
90628 .clock_get = alarm_clock_get,
90629 .timer_create = alarm_timer_create,
90630diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
90631index f7df8ea..0810193 100644
90632--- a/kernel/time/timekeeping.c
90633+++ b/kernel/time/timekeeping.c
90634@@ -15,6 +15,7 @@
90635 #include <linux/init.h>
90636 #include <linux/mm.h>
90637 #include <linux/sched.h>
90638+#include <linux/grsecurity.h>
90639 #include <linux/syscore_ops.h>
90640 #include <linux/clocksource.h>
90641 #include <linux/jiffies.h>
90642@@ -502,6 +503,8 @@ int do_settimeofday(const struct timespec *tv)
90643 if (!timespec_valid_strict(tv))
90644 return -EINVAL;
90645
90646+ gr_log_timechange();
90647+
90648 raw_spin_lock_irqsave(&timekeeper_lock, flags);
90649 write_seqcount_begin(&timekeeper_seq);
90650
90651diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
90652index 61ed862..3b52c65 100644
90653--- a/kernel/time/timer_list.c
90654+++ b/kernel/time/timer_list.c
90655@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
90656
90657 static void print_name_offset(struct seq_file *m, void *sym)
90658 {
90659+#ifdef CONFIG_GRKERNSEC_HIDESYM
90660+ SEQ_printf(m, "<%p>", NULL);
90661+#else
90662 char symname[KSYM_NAME_LEN];
90663
90664 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
90665 SEQ_printf(m, "<%pK>", sym);
90666 else
90667 SEQ_printf(m, "%s", symname);
90668+#endif
90669 }
90670
90671 static void
90672@@ -119,7 +123,11 @@ next_one:
90673 static void
90674 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
90675 {
90676+#ifdef CONFIG_GRKERNSEC_HIDESYM
90677+ SEQ_printf(m, " .base: %p\n", NULL);
90678+#else
90679 SEQ_printf(m, " .base: %pK\n", base);
90680+#endif
90681 SEQ_printf(m, " .index: %d\n",
90682 base->index);
90683 SEQ_printf(m, " .resolution: %Lu nsecs\n",
90684@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
90685 {
90686 struct proc_dir_entry *pe;
90687
90688+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90689+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
90690+#else
90691 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
90692+#endif
90693 if (!pe)
90694 return -ENOMEM;
90695 return 0;
90696diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
90697index 1fb08f2..ca4bb1e 100644
90698--- a/kernel/time/timer_stats.c
90699+++ b/kernel/time/timer_stats.c
90700@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
90701 static unsigned long nr_entries;
90702 static struct entry entries[MAX_ENTRIES];
90703
90704-static atomic_t overflow_count;
90705+static atomic_unchecked_t overflow_count;
90706
90707 /*
90708 * The entries are in a hash-table, for fast lookup:
90709@@ -140,7 +140,7 @@ static void reset_entries(void)
90710 nr_entries = 0;
90711 memset(entries, 0, sizeof(entries));
90712 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
90713- atomic_set(&overflow_count, 0);
90714+ atomic_set_unchecked(&overflow_count, 0);
90715 }
90716
90717 static struct entry *alloc_entry(void)
90718@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90719 if (likely(entry))
90720 entry->count++;
90721 else
90722- atomic_inc(&overflow_count);
90723+ atomic_inc_unchecked(&overflow_count);
90724
90725 out_unlock:
90726 raw_spin_unlock_irqrestore(lock, flags);
90727@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90728
90729 static void print_name_offset(struct seq_file *m, unsigned long addr)
90730 {
90731+#ifdef CONFIG_GRKERNSEC_HIDESYM
90732+ seq_printf(m, "<%p>", NULL);
90733+#else
90734 char symname[KSYM_NAME_LEN];
90735
90736 if (lookup_symbol_name(addr, symname) < 0)
90737- seq_printf(m, "<%p>", (void *)addr);
90738+ seq_printf(m, "<%pK>", (void *)addr);
90739 else
90740 seq_printf(m, "%s", symname);
90741+#endif
90742 }
90743
90744 static int tstats_show(struct seq_file *m, void *v)
90745@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
90746
90747 seq_puts(m, "Timer Stats Version: v0.3\n");
90748 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
90749- if (atomic_read(&overflow_count))
90750- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
90751+ if (atomic_read_unchecked(&overflow_count))
90752+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
90753 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
90754
90755 for (i = 0; i < nr_entries; i++) {
90756@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
90757 {
90758 struct proc_dir_entry *pe;
90759
90760+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90761+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
90762+#else
90763 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
90764+#endif
90765 if (!pe)
90766 return -ENOMEM;
90767 return 0;
90768diff --git a/kernel/timer.c b/kernel/timer.c
90769index 3bb01a3..0e7760e 100644
90770--- a/kernel/timer.c
90771+++ b/kernel/timer.c
90772@@ -1393,7 +1393,7 @@ void update_process_times(int user_tick)
90773 /*
90774 * This function runs timers and the timer-tq in bottom half context.
90775 */
90776-static void run_timer_softirq(struct softirq_action *h)
90777+static __latent_entropy void run_timer_softirq(void)
90778 {
90779 struct tvec_base *base = __this_cpu_read(tvec_bases);
90780
90781@@ -1456,7 +1456,7 @@ static void process_timeout(unsigned long __data)
90782 *
90783 * In all cases the return value is guaranteed to be non-negative.
90784 */
90785-signed long __sched schedule_timeout(signed long timeout)
90786+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
90787 {
90788 struct timer_list timer;
90789 unsigned long expire;
90790diff --git a/kernel/torture.c b/kernel/torture.c
90791index acc9afc..4f9eb49 100644
90792--- a/kernel/torture.c
90793+++ b/kernel/torture.c
90794@@ -489,7 +489,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
90795 mutex_lock(&fullstop_mutex);
90796 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
90797 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
90798- ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
90799+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
90800 } else {
90801 pr_warn("Concurrent rmmod and shutdown illegal!\n");
90802 }
90803@@ -551,11 +551,11 @@ static int torture_stutter(void *arg)
90804 do {
90805 if (!torture_must_stop()) {
90806 schedule_timeout_interruptible(stutter);
90807- ACCESS_ONCE(stutter_pause_test) = 1;
90808+ ACCESS_ONCE_RW(stutter_pause_test) = 1;
90809 }
90810 if (!torture_must_stop())
90811 schedule_timeout_interruptible(stutter);
90812- ACCESS_ONCE(stutter_pause_test) = 0;
90813+ ACCESS_ONCE_RW(stutter_pause_test) = 0;
90814 torture_shutdown_absorb("torture_stutter");
90815 } while (!torture_must_stop());
90816 torture_kthread_stopping("torture_stutter");
90817@@ -636,7 +636,7 @@ bool torture_cleanup(void)
90818 schedule_timeout_uninterruptible(10);
90819 return true;
90820 }
90821- ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
90822+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
90823 mutex_unlock(&fullstop_mutex);
90824 torture_shutdown_cleanup();
90825 torture_shuffle_cleanup();
90826diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
90827index c1bd4ad..4b861dc 100644
90828--- a/kernel/trace/blktrace.c
90829+++ b/kernel/trace/blktrace.c
90830@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
90831 struct blk_trace *bt = filp->private_data;
90832 char buf[16];
90833
90834- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
90835+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
90836
90837 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
90838 }
90839@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
90840 return 1;
90841
90842 bt = buf->chan->private_data;
90843- atomic_inc(&bt->dropped);
90844+ atomic_inc_unchecked(&bt->dropped);
90845 return 0;
90846 }
90847
90848@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
90849
90850 bt->dir = dir;
90851 bt->dev = dev;
90852- atomic_set(&bt->dropped, 0);
90853+ atomic_set_unchecked(&bt->dropped, 0);
90854 INIT_LIST_HEAD(&bt->running_list);
90855
90856 ret = -EIO;
90857diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
90858index 4a54a25..7ca9c89 100644
90859--- a/kernel/trace/ftrace.c
90860+++ b/kernel/trace/ftrace.c
90861@@ -1960,12 +1960,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
90862 if (unlikely(ftrace_disabled))
90863 return 0;
90864
90865+ ret = ftrace_arch_code_modify_prepare();
90866+ FTRACE_WARN_ON(ret);
90867+ if (ret)
90868+ return 0;
90869+
90870 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
90871+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
90872 if (ret) {
90873 ftrace_bug(ret, ip);
90874- return 0;
90875 }
90876- return 1;
90877+ return ret ? 0 : 1;
90878 }
90879
90880 /*
90881@@ -4195,8 +4200,10 @@ static int ftrace_process_locs(struct module *mod,
90882 if (!count)
90883 return 0;
90884
90885+ pax_open_kernel();
90886 sort(start, count, sizeof(*start),
90887 ftrace_cmp_ips, ftrace_swap_ips);
90888+ pax_close_kernel();
90889
90890 start_pg = ftrace_allocate_pages(count);
90891 if (!start_pg)
90892@@ -4908,8 +4915,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
90893 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
90894
90895 static int ftrace_graph_active;
90896-static struct notifier_block ftrace_suspend_notifier;
90897-
90898 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
90899 {
90900 return 0;
90901@@ -5085,6 +5090,10 @@ static void update_function_graph_func(void)
90902 ftrace_graph_entry = ftrace_graph_entry_test;
90903 }
90904
90905+static struct notifier_block ftrace_suspend_notifier = {
90906+ .notifier_call = ftrace_suspend_notifier_call
90907+};
90908+
90909 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90910 trace_func_graph_ent_t entryfunc)
90911 {
90912@@ -5098,7 +5107,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
90913 goto out;
90914 }
90915
90916- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
90917 register_pm_notifier(&ftrace_suspend_notifier);
90918
90919 ftrace_graph_active++;
90920diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
90921index c634868..00d0d19 100644
90922--- a/kernel/trace/ring_buffer.c
90923+++ b/kernel/trace/ring_buffer.c
90924@@ -352,9 +352,9 @@ struct buffer_data_page {
90925 */
90926 struct buffer_page {
90927 struct list_head list; /* list of buffer pages */
90928- local_t write; /* index for next write */
90929+ local_unchecked_t write; /* index for next write */
90930 unsigned read; /* index for next read */
90931- local_t entries; /* entries on this page */
90932+ local_unchecked_t entries; /* entries on this page */
90933 unsigned long real_end; /* real end of data */
90934 struct buffer_data_page *page; /* Actual data page */
90935 };
90936@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
90937 unsigned long last_overrun;
90938 local_t entries_bytes;
90939 local_t entries;
90940- local_t overrun;
90941- local_t commit_overrun;
90942+ local_unchecked_t overrun;
90943+ local_unchecked_t commit_overrun;
90944 local_t dropped_events;
90945 local_t committing;
90946 local_t commits;
90947@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90948 *
90949 * We add a counter to the write field to denote this.
90950 */
90951- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
90952- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
90953+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
90954+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
90955
90956 /*
90957 * Just make sure we have seen our old_write and synchronize
90958@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90959 * cmpxchg to only update if an interrupt did not already
90960 * do it for us. If the cmpxchg fails, we don't care.
90961 */
90962- (void)local_cmpxchg(&next_page->write, old_write, val);
90963- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90964+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90965+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90966
90967 /*
90968 * No need to worry about races with clearing out the commit.
90969@@ -1389,12 +1389,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90970
90971 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90972 {
90973- return local_read(&bpage->entries) & RB_WRITE_MASK;
90974+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90975 }
90976
90977 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90978 {
90979- return local_read(&bpage->write) & RB_WRITE_MASK;
90980+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90981 }
90982
90983 static int
90984@@ -1489,7 +1489,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90985 * bytes consumed in ring buffer from here.
90986 * Increment overrun to account for the lost events.
90987 */
90988- local_add(page_entries, &cpu_buffer->overrun);
90989+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
90990 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90991 }
90992
90993@@ -2067,7 +2067,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
90994 * it is our responsibility to update
90995 * the counters.
90996 */
90997- local_add(entries, &cpu_buffer->overrun);
90998+ local_add_unchecked(entries, &cpu_buffer->overrun);
90999 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91000
91001 /*
91002@@ -2217,7 +2217,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91003 if (tail == BUF_PAGE_SIZE)
91004 tail_page->real_end = 0;
91005
91006- local_sub(length, &tail_page->write);
91007+ local_sub_unchecked(length, &tail_page->write);
91008 return;
91009 }
91010
91011@@ -2252,7 +2252,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91012 rb_event_set_padding(event);
91013
91014 /* Set the write back to the previous setting */
91015- local_sub(length, &tail_page->write);
91016+ local_sub_unchecked(length, &tail_page->write);
91017 return;
91018 }
91019
91020@@ -2264,7 +2264,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91021
91022 /* Set write to end of buffer */
91023 length = (tail + length) - BUF_PAGE_SIZE;
91024- local_sub(length, &tail_page->write);
91025+ local_sub_unchecked(length, &tail_page->write);
91026 }
91027
91028 /*
91029@@ -2290,7 +2290,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91030 * about it.
91031 */
91032 if (unlikely(next_page == commit_page)) {
91033- local_inc(&cpu_buffer->commit_overrun);
91034+ local_inc_unchecked(&cpu_buffer->commit_overrun);
91035 goto out_reset;
91036 }
91037
91038@@ -2346,7 +2346,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91039 cpu_buffer->tail_page) &&
91040 (cpu_buffer->commit_page ==
91041 cpu_buffer->reader_page))) {
91042- local_inc(&cpu_buffer->commit_overrun);
91043+ local_inc_unchecked(&cpu_buffer->commit_overrun);
91044 goto out_reset;
91045 }
91046 }
91047@@ -2394,7 +2394,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91048 length += RB_LEN_TIME_EXTEND;
91049
91050 tail_page = cpu_buffer->tail_page;
91051- write = local_add_return(length, &tail_page->write);
91052+ write = local_add_return_unchecked(length, &tail_page->write);
91053
91054 /* set write to only the index of the write */
91055 write &= RB_WRITE_MASK;
91056@@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91057 kmemcheck_annotate_bitfield(event, bitfield);
91058 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
91059
91060- local_inc(&tail_page->entries);
91061+ local_inc_unchecked(&tail_page->entries);
91062
91063 /*
91064 * If this is the first commit on the page, then update
91065@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91066
91067 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91068 unsigned long write_mask =
91069- local_read(&bpage->write) & ~RB_WRITE_MASK;
91070+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91071 unsigned long event_length = rb_event_length(event);
91072 /*
91073 * This is on the tail page. It is possible that
91074@@ -2461,7 +2461,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91075 */
91076 old_index += write_mask;
91077 new_index += write_mask;
91078- index = local_cmpxchg(&bpage->write, old_index, new_index);
91079+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91080 if (index == old_index) {
91081 /* update counters */
91082 local_sub(event_length, &cpu_buffer->entries_bytes);
91083@@ -2853,7 +2853,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91084
91085 /* Do the likely case first */
91086 if (likely(bpage->page == (void *)addr)) {
91087- local_dec(&bpage->entries);
91088+ local_dec_unchecked(&bpage->entries);
91089 return;
91090 }
91091
91092@@ -2865,7 +2865,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91093 start = bpage;
91094 do {
91095 if (bpage->page == (void *)addr) {
91096- local_dec(&bpage->entries);
91097+ local_dec_unchecked(&bpage->entries);
91098 return;
91099 }
91100 rb_inc_page(cpu_buffer, &bpage);
91101@@ -3149,7 +3149,7 @@ static inline unsigned long
91102 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91103 {
91104 return local_read(&cpu_buffer->entries) -
91105- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91106+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91107 }
91108
91109 /**
91110@@ -3238,7 +3238,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91111 return 0;
91112
91113 cpu_buffer = buffer->buffers[cpu];
91114- ret = local_read(&cpu_buffer->overrun);
91115+ ret = local_read_unchecked(&cpu_buffer->overrun);
91116
91117 return ret;
91118 }
91119@@ -3261,7 +3261,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91120 return 0;
91121
91122 cpu_buffer = buffer->buffers[cpu];
91123- ret = local_read(&cpu_buffer->commit_overrun);
91124+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91125
91126 return ret;
91127 }
91128@@ -3346,7 +3346,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91129 /* if you care about this being correct, lock the buffer */
91130 for_each_buffer_cpu(buffer, cpu) {
91131 cpu_buffer = buffer->buffers[cpu];
91132- overruns += local_read(&cpu_buffer->overrun);
91133+ overruns += local_read_unchecked(&cpu_buffer->overrun);
91134 }
91135
91136 return overruns;
91137@@ -3522,8 +3522,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91138 /*
91139 * Reset the reader page to size zero.
91140 */
91141- local_set(&cpu_buffer->reader_page->write, 0);
91142- local_set(&cpu_buffer->reader_page->entries, 0);
91143+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91144+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91145 local_set(&cpu_buffer->reader_page->page->commit, 0);
91146 cpu_buffer->reader_page->real_end = 0;
91147
91148@@ -3557,7 +3557,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91149 * want to compare with the last_overrun.
91150 */
91151 smp_mb();
91152- overwrite = local_read(&(cpu_buffer->overrun));
91153+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91154
91155 /*
91156 * Here's the tricky part.
91157@@ -4127,8 +4127,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91158
91159 cpu_buffer->head_page
91160 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91161- local_set(&cpu_buffer->head_page->write, 0);
91162- local_set(&cpu_buffer->head_page->entries, 0);
91163+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
91164+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91165 local_set(&cpu_buffer->head_page->page->commit, 0);
91166
91167 cpu_buffer->head_page->read = 0;
91168@@ -4138,14 +4138,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91169
91170 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91171 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91172- local_set(&cpu_buffer->reader_page->write, 0);
91173- local_set(&cpu_buffer->reader_page->entries, 0);
91174+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91175+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91176 local_set(&cpu_buffer->reader_page->page->commit, 0);
91177 cpu_buffer->reader_page->read = 0;
91178
91179 local_set(&cpu_buffer->entries_bytes, 0);
91180- local_set(&cpu_buffer->overrun, 0);
91181- local_set(&cpu_buffer->commit_overrun, 0);
91182+ local_set_unchecked(&cpu_buffer->overrun, 0);
91183+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91184 local_set(&cpu_buffer->dropped_events, 0);
91185 local_set(&cpu_buffer->entries, 0);
91186 local_set(&cpu_buffer->committing, 0);
91187@@ -4550,8 +4550,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91188 rb_init_page(bpage);
91189 bpage = reader->page;
91190 reader->page = *data_page;
91191- local_set(&reader->write, 0);
91192- local_set(&reader->entries, 0);
91193+ local_set_unchecked(&reader->write, 0);
91194+ local_set_unchecked(&reader->entries, 0);
91195 reader->read = 0;
91196 *data_page = bpage;
91197
91198diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91199index 1848dc6..5fc244c 100644
91200--- a/kernel/trace/trace.c
91201+++ b/kernel/trace/trace.c
91202@@ -3447,7 +3447,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91203 return 0;
91204 }
91205
91206-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91207+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91208 {
91209 /* do nothing if flag is already set */
91210 if (!!(trace_flags & mask) == !!enabled)
91211diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91212index 2e29d7b..61367d7 100644
91213--- a/kernel/trace/trace.h
91214+++ b/kernel/trace/trace.h
91215@@ -1264,7 +1264,7 @@ extern const char *__stop___tracepoint_str[];
91216 void trace_printk_init_buffers(void);
91217 void trace_printk_start_comm(void);
91218 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91219-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91220+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91221
91222 /*
91223 * Normal trace_printk() and friends allocates special buffers
91224diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91225index 26dc348..8708ca7 100644
91226--- a/kernel/trace/trace_clock.c
91227+++ b/kernel/trace/trace_clock.c
91228@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
91229 return now;
91230 }
91231
91232-static atomic64_t trace_counter;
91233+static atomic64_unchecked_t trace_counter;
91234
91235 /*
91236 * trace_clock_counter(): simply an atomic counter.
91237@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
91238 */
91239 u64 notrace trace_clock_counter(void)
91240 {
91241- return atomic64_add_return(1, &trace_counter);
91242+ return atomic64_inc_return_unchecked(&trace_counter);
91243 }
91244diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91245index 3ddfd8f..41a10fe 100644
91246--- a/kernel/trace/trace_events.c
91247+++ b/kernel/trace/trace_events.c
91248@@ -1718,7 +1718,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91249 return 0;
91250 }
91251
91252-struct ftrace_module_file_ops;
91253 static void __add_event_to_tracers(struct ftrace_event_call *call);
91254
91255 /* Add an additional event_call dynamically */
91256diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91257index 0abd9b8..6a663a2 100644
91258--- a/kernel/trace/trace_mmiotrace.c
91259+++ b/kernel/trace/trace_mmiotrace.c
91260@@ -24,7 +24,7 @@ struct header_iter {
91261 static struct trace_array *mmio_trace_array;
91262 static bool overrun_detected;
91263 static unsigned long prev_overruns;
91264-static atomic_t dropped_count;
91265+static atomic_unchecked_t dropped_count;
91266
91267 static void mmio_reset_data(struct trace_array *tr)
91268 {
91269@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91270
91271 static unsigned long count_overruns(struct trace_iterator *iter)
91272 {
91273- unsigned long cnt = atomic_xchg(&dropped_count, 0);
91274+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91275 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91276
91277 if (over > prev_overruns)
91278@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
91279 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
91280 sizeof(*entry), 0, pc);
91281 if (!event) {
91282- atomic_inc(&dropped_count);
91283+ atomic_inc_unchecked(&dropped_count);
91284 return;
91285 }
91286 entry = ring_buffer_event_data(event);
91287@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
91288 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
91289 sizeof(*entry), 0, pc);
91290 if (!event) {
91291- atomic_inc(&dropped_count);
91292+ atomic_inc_unchecked(&dropped_count);
91293 return;
91294 }
91295 entry = ring_buffer_event_data(event);
91296diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
91297index a436de1..f64dde2 100644
91298--- a/kernel/trace/trace_output.c
91299+++ b/kernel/trace/trace_output.c
91300@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
91301
91302 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
91303 if (!IS_ERR(p)) {
91304- p = mangle_path(s->buffer + s->len, p, "\n");
91305+ p = mangle_path(s->buffer + s->len, p, "\n\\");
91306 if (p) {
91307 s->len = p - s->buffer;
91308 return 1;
91309@@ -939,14 +939,16 @@ int register_ftrace_event(struct trace_event *event)
91310 goto out;
91311 }
91312
91313+ pax_open_kernel();
91314 if (event->funcs->trace == NULL)
91315- event->funcs->trace = trace_nop_print;
91316+ *(void **)&event->funcs->trace = trace_nop_print;
91317 if (event->funcs->raw == NULL)
91318- event->funcs->raw = trace_nop_print;
91319+ *(void **)&event->funcs->raw = trace_nop_print;
91320 if (event->funcs->hex == NULL)
91321- event->funcs->hex = trace_nop_print;
91322+ *(void **)&event->funcs->hex = trace_nop_print;
91323 if (event->funcs->binary == NULL)
91324- event->funcs->binary = trace_nop_print;
91325+ *(void **)&event->funcs->binary = trace_nop_print;
91326+ pax_close_kernel();
91327
91328 key = event->type & (EVENT_HASHSIZE - 1);
91329
91330diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
91331index 21b320e..40607bc 100644
91332--- a/kernel/trace/trace_stack.c
91333+++ b/kernel/trace/trace_stack.c
91334@@ -69,7 +69,7 @@ check_stack(unsigned long ip, unsigned long *stack)
91335 return;
91336
91337 /* we do not handle interrupt stacks yet */
91338- if (!object_is_on_stack(stack))
91339+ if (!object_starts_on_stack(stack))
91340 return;
91341
91342 local_irq_save(flags);
91343diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
91344index bf71b4b..04dee68 100644
91345--- a/kernel/user_namespace.c
91346+++ b/kernel/user_namespace.c
91347@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
91348 !kgid_has_mapping(parent_ns, group))
91349 return -EPERM;
91350
91351+#ifdef CONFIG_GRKERNSEC
91352+ /*
91353+ * This doesn't really inspire confidence:
91354+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
91355+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
91356+ * Increases kernel attack surface in areas developers
91357+ * previously cared little about ("low importance due
91358+ * to requiring "root" capability")
91359+ * To be removed when this code receives *proper* review
91360+ */
91361+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
91362+ !capable(CAP_SETGID))
91363+ return -EPERM;
91364+#endif
91365+
91366 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
91367 if (!ns)
91368 return -ENOMEM;
91369@@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
91370 if (atomic_read(&current->mm->mm_users) > 1)
91371 return -EINVAL;
91372
91373- if (current->fs->users != 1)
91374+ if (atomic_read(&current->fs->users) != 1)
91375 return -EINVAL;
91376
91377 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
91378diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
91379index 4f69f9a..7c6f8f8 100644
91380--- a/kernel/utsname_sysctl.c
91381+++ b/kernel/utsname_sysctl.c
91382@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
91383 static int proc_do_uts_string(ctl_table *table, int write,
91384 void __user *buffer, size_t *lenp, loff_t *ppos)
91385 {
91386- struct ctl_table uts_table;
91387+ ctl_table_no_const uts_table;
91388 int r;
91389 memcpy(&uts_table, table, sizeof(uts_table));
91390 uts_table.data = get_uts(table, write);
91391diff --git a/kernel/watchdog.c b/kernel/watchdog.c
91392index 30e4822..dd2b854 100644
91393--- a/kernel/watchdog.c
91394+++ b/kernel/watchdog.c
91395@@ -479,7 +479,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
91396 static void watchdog_nmi_disable(unsigned int cpu) { return; }
91397 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
91398
91399-static struct smp_hotplug_thread watchdog_threads = {
91400+static struct smp_hotplug_thread watchdog_threads __read_only = {
91401 .store = &softlockup_watchdog,
91402 .thread_should_run = watchdog_should_run,
91403 .thread_fn = watchdog,
91404diff --git a/kernel/workqueue.c b/kernel/workqueue.c
91405index 8edc8718..b6a70b9 100644
91406--- a/kernel/workqueue.c
91407+++ b/kernel/workqueue.c
91408@@ -4709,7 +4709,7 @@ static void rebind_workers(struct worker_pool *pool)
91409 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
91410 worker_flags |= WORKER_REBOUND;
91411 worker_flags &= ~WORKER_UNBOUND;
91412- ACCESS_ONCE(worker->flags) = worker_flags;
91413+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
91414 }
91415
91416 spin_unlock_irq(&pool->lock);
91417diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
91418index 819ac51..1c8a65e 100644
91419--- a/lib/Kconfig.debug
91420+++ b/lib/Kconfig.debug
91421@@ -853,7 +853,7 @@ config DEBUG_MUTEXES
91422
91423 config DEBUG_WW_MUTEX_SLOWPATH
91424 bool "Wait/wound mutex debugging: Slowpath testing"
91425- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91426+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91427 select DEBUG_LOCK_ALLOC
91428 select DEBUG_SPINLOCK
91429 select DEBUG_MUTEXES
91430@@ -866,7 +866,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
91431
91432 config DEBUG_LOCK_ALLOC
91433 bool "Lock debugging: detect incorrect freeing of live locks"
91434- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91435+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91436 select DEBUG_SPINLOCK
91437 select DEBUG_MUTEXES
91438 select LOCKDEP
91439@@ -880,7 +880,7 @@ config DEBUG_LOCK_ALLOC
91440
91441 config PROVE_LOCKING
91442 bool "Lock debugging: prove locking correctness"
91443- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91444+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91445 select LOCKDEP
91446 select DEBUG_SPINLOCK
91447 select DEBUG_MUTEXES
91448@@ -931,7 +931,7 @@ config LOCKDEP
91449
91450 config LOCK_STAT
91451 bool "Lock usage statistics"
91452- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91453+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91454 select LOCKDEP
91455 select DEBUG_SPINLOCK
91456 select DEBUG_MUTEXES
91457@@ -1403,6 +1403,7 @@ config LATENCYTOP
91458 depends on DEBUG_KERNEL
91459 depends on STACKTRACE_SUPPORT
91460 depends on PROC_FS
91461+ depends on !GRKERNSEC_HIDESYM
91462 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
91463 select KALLSYMS
91464 select KALLSYMS_ALL
91465@@ -1419,7 +1420,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91466 config DEBUG_STRICT_USER_COPY_CHECKS
91467 bool "Strict user copy size checks"
91468 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91469- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
91470+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
91471 help
91472 Enabling this option turns a certain set of sanity checks for user
91473 copy operations into compile time failures.
91474@@ -1538,7 +1539,7 @@ endmenu # runtime tests
91475
91476 config PROVIDE_OHCI1394_DMA_INIT
91477 bool "Remote debugging over FireWire early on boot"
91478- depends on PCI && X86
91479+ depends on PCI && X86 && !GRKERNSEC
91480 help
91481 If you want to debug problems which hang or crash the kernel early
91482 on boot and the crashing machine has a FireWire port, you can use
91483diff --git a/lib/Makefile b/lib/Makefile
91484index 0cd7b68..e149e37 100644
91485--- a/lib/Makefile
91486+++ b/lib/Makefile
91487@@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91488 obj-$(CONFIG_BTREE) += btree.o
91489 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91490 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91491-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91492+obj-y += list_debug.o
91493 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91494
91495 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91496diff --git a/lib/average.c b/lib/average.c
91497index 114d1be..ab0350c 100644
91498--- a/lib/average.c
91499+++ b/lib/average.c
91500@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91501 {
91502 unsigned long internal = ACCESS_ONCE(avg->internal);
91503
91504- ACCESS_ONCE(avg->internal) = internal ?
91505+ ACCESS_ONCE_RW(avg->internal) = internal ?
91506 (((internal << avg->weight) - internal) +
91507 (val << avg->factor)) >> avg->weight :
91508 (val << avg->factor);
91509diff --git a/lib/bitmap.c b/lib/bitmap.c
91510index 06f7e4f..f3cf2b0 100644
91511--- a/lib/bitmap.c
91512+++ b/lib/bitmap.c
91513@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91514 {
91515 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91516 u32 chunk;
91517- const char __user __force *ubuf = (const char __user __force *)buf;
91518+ const char __user *ubuf = (const char __force_user *)buf;
91519
91520 bitmap_zero(maskp, nmaskbits);
91521
91522@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91523 {
91524 if (!access_ok(VERIFY_READ, ubuf, ulen))
91525 return -EFAULT;
91526- return __bitmap_parse((const char __force *)ubuf,
91527+ return __bitmap_parse((const char __force_kernel *)ubuf,
91528 ulen, 1, maskp, nmaskbits);
91529
91530 }
91531@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91532 {
91533 unsigned a, b;
91534 int c, old_c, totaldigits;
91535- const char __user __force *ubuf = (const char __user __force *)buf;
91536+ const char __user *ubuf = (const char __force_user *)buf;
91537 int exp_digit, in_range;
91538
91539 totaldigits = c = 0;
91540@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
91541 {
91542 if (!access_ok(VERIFY_READ, ubuf, ulen))
91543 return -EFAULT;
91544- return __bitmap_parselist((const char __force *)ubuf,
91545+ return __bitmap_parselist((const char __force_kernel *)ubuf,
91546 ulen, 1, maskp, nmaskbits);
91547 }
91548 EXPORT_SYMBOL(bitmap_parselist_user);
91549diff --git a/lib/bug.c b/lib/bug.c
91550index 1686034..a9c00c8 100644
91551--- a/lib/bug.c
91552+++ b/lib/bug.c
91553@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
91554 return BUG_TRAP_TYPE_NONE;
91555
91556 bug = find_bug(bugaddr);
91557+ if (!bug)
91558+ return BUG_TRAP_TYPE_NONE;
91559
91560 file = NULL;
91561 line = 0;
91562diff --git a/lib/debugobjects.c b/lib/debugobjects.c
91563index e0731c3..ad66444 100644
91564--- a/lib/debugobjects.c
91565+++ b/lib/debugobjects.c
91566@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
91567 if (limit > 4)
91568 return;
91569
91570- is_on_stack = object_is_on_stack(addr);
91571+ is_on_stack = object_starts_on_stack(addr);
91572 if (is_on_stack == onstack)
91573 return;
91574
91575diff --git a/lib/div64.c b/lib/div64.c
91576index 4382ad7..08aa558 100644
91577--- a/lib/div64.c
91578+++ b/lib/div64.c
91579@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
91580 EXPORT_SYMBOL(__div64_32);
91581
91582 #ifndef div_s64_rem
91583-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91584+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91585 {
91586 u64 quotient;
91587
91588@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
91589 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
91590 */
91591 #ifndef div64_u64
91592-u64 div64_u64(u64 dividend, u64 divisor)
91593+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
91594 {
91595 u32 high = divisor >> 32;
91596 u64 quot;
91597diff --git a/lib/dma-debug.c b/lib/dma-debug.c
91598index 98f2d7e..899da5c 100644
91599--- a/lib/dma-debug.c
91600+++ b/lib/dma-debug.c
91601@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
91602
91603 void dma_debug_add_bus(struct bus_type *bus)
91604 {
91605- struct notifier_block *nb;
91606+ notifier_block_no_const *nb;
91607
91608 if (global_disable)
91609 return;
91610@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
91611
91612 static void check_for_stack(struct device *dev, void *addr)
91613 {
91614- if (object_is_on_stack(addr))
91615+ if (object_starts_on_stack(addr))
91616 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
91617 "stack [addr=%p]\n", addr);
91618 }
91619diff --git a/lib/hash.c b/lib/hash.c
91620index fea973f..386626f 100644
91621--- a/lib/hash.c
91622+++ b/lib/hash.c
91623@@ -14,7 +14,7 @@
91624 #include <linux/hash.h>
91625 #include <linux/cache.h>
91626
91627-static struct fast_hash_ops arch_hash_ops __read_mostly = {
91628+static struct fast_hash_ops arch_hash_ops __read_only = {
91629 .hash = jhash,
91630 .hash2 = jhash2,
91631 };
91632diff --git a/lib/inflate.c b/lib/inflate.c
91633index 013a761..c28f3fc 100644
91634--- a/lib/inflate.c
91635+++ b/lib/inflate.c
91636@@ -269,7 +269,7 @@ static void free(void *where)
91637 malloc_ptr = free_mem_ptr;
91638 }
91639 #else
91640-#define malloc(a) kmalloc(a, GFP_KERNEL)
91641+#define malloc(a) kmalloc((a), GFP_KERNEL)
91642 #define free(a) kfree(a)
91643 #endif
91644
91645diff --git a/lib/ioremap.c b/lib/ioremap.c
91646index 0c9216c..863bd89 100644
91647--- a/lib/ioremap.c
91648+++ b/lib/ioremap.c
91649@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
91650 unsigned long next;
91651
91652 phys_addr -= addr;
91653- pmd = pmd_alloc(&init_mm, pud, addr);
91654+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91655 if (!pmd)
91656 return -ENOMEM;
91657 do {
91658@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
91659 unsigned long next;
91660
91661 phys_addr -= addr;
91662- pud = pud_alloc(&init_mm, pgd, addr);
91663+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
91664 if (!pud)
91665 return -ENOMEM;
91666 do {
91667diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
91668index bd2bea9..6b3c95e 100644
91669--- a/lib/is_single_threaded.c
91670+++ b/lib/is_single_threaded.c
91671@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
91672 struct task_struct *p, *t;
91673 bool ret;
91674
91675+ if (!mm)
91676+ return true;
91677+
91678 if (atomic_read(&task->signal->live) != 1)
91679 return false;
91680
91681diff --git a/lib/kobject.c b/lib/kobject.c
91682index 58751bb..93a1853 100644
91683--- a/lib/kobject.c
91684+++ b/lib/kobject.c
91685@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
91686
91687
91688 static DEFINE_SPINLOCK(kobj_ns_type_lock);
91689-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
91690+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
91691
91692-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91693+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91694 {
91695 enum kobj_ns_type type = ops->type;
91696 int error;
91697diff --git a/lib/list_debug.c b/lib/list_debug.c
91698index c24c2f7..f0296f4 100644
91699--- a/lib/list_debug.c
91700+++ b/lib/list_debug.c
91701@@ -11,7 +11,9 @@
91702 #include <linux/bug.h>
91703 #include <linux/kernel.h>
91704 #include <linux/rculist.h>
91705+#include <linux/mm.h>
91706
91707+#ifdef CONFIG_DEBUG_LIST
91708 /*
91709 * Insert a new entry between two known consecutive entries.
91710 *
91711@@ -19,21 +21,40 @@
91712 * the prev/next entries already!
91713 */
91714
91715+static bool __list_add_debug(struct list_head *new,
91716+ struct list_head *prev,
91717+ struct list_head *next)
91718+{
91719+ if (unlikely(next->prev != prev)) {
91720+ printk(KERN_ERR "list_add corruption. next->prev should be "
91721+ "prev (%p), but was %p. (next=%p).\n",
91722+ prev, next->prev, next);
91723+ BUG();
91724+ return false;
91725+ }
91726+ if (unlikely(prev->next != next)) {
91727+ printk(KERN_ERR "list_add corruption. prev->next should be "
91728+ "next (%p), but was %p. (prev=%p).\n",
91729+ next, prev->next, prev);
91730+ BUG();
91731+ return false;
91732+ }
91733+ if (unlikely(new == prev || new == next)) {
91734+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
91735+ new, prev, next);
91736+ BUG();
91737+ return false;
91738+ }
91739+ return true;
91740+}
91741+
91742 void __list_add(struct list_head *new,
91743- struct list_head *prev,
91744- struct list_head *next)
91745+ struct list_head *prev,
91746+ struct list_head *next)
91747 {
91748- WARN(next->prev != prev,
91749- "list_add corruption. next->prev should be "
91750- "prev (%p), but was %p. (next=%p).\n",
91751- prev, next->prev, next);
91752- WARN(prev->next != next,
91753- "list_add corruption. prev->next should be "
91754- "next (%p), but was %p. (prev=%p).\n",
91755- next, prev->next, prev);
91756- WARN(new == prev || new == next,
91757- "list_add double add: new=%p, prev=%p, next=%p.\n",
91758- new, prev, next);
91759+ if (!__list_add_debug(new, prev, next))
91760+ return;
91761+
91762 next->prev = new;
91763 new->next = next;
91764 new->prev = prev;
91765@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
91766 }
91767 EXPORT_SYMBOL(__list_add);
91768
91769-void __list_del_entry(struct list_head *entry)
91770+static bool __list_del_entry_debug(struct list_head *entry)
91771 {
91772 struct list_head *prev, *next;
91773
91774 prev = entry->prev;
91775 next = entry->next;
91776
91777- if (WARN(next == LIST_POISON1,
91778- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91779- entry, LIST_POISON1) ||
91780- WARN(prev == LIST_POISON2,
91781- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91782- entry, LIST_POISON2) ||
91783- WARN(prev->next != entry,
91784- "list_del corruption. prev->next should be %p, "
91785- "but was %p\n", entry, prev->next) ||
91786- WARN(next->prev != entry,
91787- "list_del corruption. next->prev should be %p, "
91788- "but was %p\n", entry, next->prev))
91789+ if (unlikely(next == LIST_POISON1)) {
91790+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91791+ entry, LIST_POISON1);
91792+ BUG();
91793+ return false;
91794+ }
91795+ if (unlikely(prev == LIST_POISON2)) {
91796+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91797+ entry, LIST_POISON2);
91798+ BUG();
91799+ return false;
91800+ }
91801+ if (unlikely(entry->prev->next != entry)) {
91802+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
91803+ "but was %p\n", entry, prev->next);
91804+ BUG();
91805+ return false;
91806+ }
91807+ if (unlikely(entry->next->prev != entry)) {
91808+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
91809+ "but was %p\n", entry, next->prev);
91810+ BUG();
91811+ return false;
91812+ }
91813+ return true;
91814+}
91815+
91816+void __list_del_entry(struct list_head *entry)
91817+{
91818+ if (!__list_del_entry_debug(entry))
91819 return;
91820
91821- __list_del(prev, next);
91822+ __list_del(entry->prev, entry->next);
91823 }
91824 EXPORT_SYMBOL(__list_del_entry);
91825
91826@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
91827 void __list_add_rcu(struct list_head *new,
91828 struct list_head *prev, struct list_head *next)
91829 {
91830- WARN(next->prev != prev,
91831- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
91832- prev, next->prev, next);
91833- WARN(prev->next != next,
91834- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
91835- next, prev->next, prev);
91836+ if (!__list_add_debug(new, prev, next))
91837+ return;
91838+
91839 new->next = next;
91840 new->prev = prev;
91841 rcu_assign_pointer(list_next_rcu(prev), new);
91842 next->prev = new;
91843 }
91844 EXPORT_SYMBOL(__list_add_rcu);
91845+#endif
91846+
91847+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
91848+{
91849+#ifdef CONFIG_DEBUG_LIST
91850+ if (!__list_add_debug(new, prev, next))
91851+ return;
91852+#endif
91853+
91854+ pax_open_kernel();
91855+ next->prev = new;
91856+ new->next = next;
91857+ new->prev = prev;
91858+ prev->next = new;
91859+ pax_close_kernel();
91860+}
91861+EXPORT_SYMBOL(__pax_list_add);
91862+
91863+void pax_list_del(struct list_head *entry)
91864+{
91865+#ifdef CONFIG_DEBUG_LIST
91866+ if (!__list_del_entry_debug(entry))
91867+ return;
91868+#endif
91869+
91870+ pax_open_kernel();
91871+ __list_del(entry->prev, entry->next);
91872+ entry->next = LIST_POISON1;
91873+ entry->prev = LIST_POISON2;
91874+ pax_close_kernel();
91875+}
91876+EXPORT_SYMBOL(pax_list_del);
91877+
91878+void pax_list_del_init(struct list_head *entry)
91879+{
91880+ pax_open_kernel();
91881+ __list_del(entry->prev, entry->next);
91882+ INIT_LIST_HEAD(entry);
91883+ pax_close_kernel();
91884+}
91885+EXPORT_SYMBOL(pax_list_del_init);
91886+
91887+void __pax_list_add_rcu(struct list_head *new,
91888+ struct list_head *prev, struct list_head *next)
91889+{
91890+#ifdef CONFIG_DEBUG_LIST
91891+ if (!__list_add_debug(new, prev, next))
91892+ return;
91893+#endif
91894+
91895+ pax_open_kernel();
91896+ new->next = next;
91897+ new->prev = prev;
91898+ rcu_assign_pointer(list_next_rcu(prev), new);
91899+ next->prev = new;
91900+ pax_close_kernel();
91901+}
91902+EXPORT_SYMBOL(__pax_list_add_rcu);
91903+
91904+void pax_list_del_rcu(struct list_head *entry)
91905+{
91906+#ifdef CONFIG_DEBUG_LIST
91907+ if (!__list_del_entry_debug(entry))
91908+ return;
91909+#endif
91910+
91911+ pax_open_kernel();
91912+ __list_del(entry->prev, entry->next);
91913+ entry->next = LIST_POISON1;
91914+ entry->prev = LIST_POISON2;
91915+ pax_close_kernel();
91916+}
91917+EXPORT_SYMBOL(pax_list_del_rcu);
91918diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
91919index 963b703..438bc51 100644
91920--- a/lib/percpu-refcount.c
91921+++ b/lib/percpu-refcount.c
91922@@ -29,7 +29,7 @@
91923 * can't hit 0 before we've added up all the percpu refs.
91924 */
91925
91926-#define PCPU_COUNT_BIAS (1U << 31)
91927+#define PCPU_COUNT_BIAS (1U << 30)
91928
91929 /**
91930 * percpu_ref_init - initialize a percpu refcount
91931diff --git a/lib/radix-tree.c b/lib/radix-tree.c
91932index 9599aa7..9cf6c72 100644
91933--- a/lib/radix-tree.c
91934+++ b/lib/radix-tree.c
91935@@ -66,7 +66,7 @@ struct radix_tree_preload {
91936 int nr;
91937 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
91938 };
91939-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
91940+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
91941
91942 static inline void *ptr_to_indirect(void *ptr)
91943 {
91944diff --git a/lib/random32.c b/lib/random32.c
91945index fa5da61..35fe9af 100644
91946--- a/lib/random32.c
91947+++ b/lib/random32.c
91948@@ -42,7 +42,7 @@
91949 static void __init prandom_state_selftest(void);
91950 #endif
91951
91952-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91953+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91954
91955 /**
91956 * prandom_u32_state - seeded pseudo-random number generator.
91957diff --git a/lib/rbtree.c b/lib/rbtree.c
91958index 65f4eff..2cfa167 100644
91959--- a/lib/rbtree.c
91960+++ b/lib/rbtree.c
91961@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91962 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91963
91964 static const struct rb_augment_callbacks dummy_callbacks = {
91965- dummy_propagate, dummy_copy, dummy_rotate
91966+ .propagate = dummy_propagate,
91967+ .copy = dummy_copy,
91968+ .rotate = dummy_rotate
91969 };
91970
91971 void rb_insert_color(struct rb_node *node, struct rb_root *root)
91972diff --git a/lib/show_mem.c b/lib/show_mem.c
91973index 0922579..9d7adb9 100644
91974--- a/lib/show_mem.c
91975+++ b/lib/show_mem.c
91976@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
91977 quicklist_total_size());
91978 #endif
91979 #ifdef CONFIG_MEMORY_FAILURE
91980- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
91981+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
91982 #endif
91983 }
91984diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
91985index bb2b201..46abaf9 100644
91986--- a/lib/strncpy_from_user.c
91987+++ b/lib/strncpy_from_user.c
91988@@ -21,7 +21,7 @@
91989 */
91990 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
91991 {
91992- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91993+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91994 long res = 0;
91995
91996 /*
91997diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
91998index a28df52..3d55877 100644
91999--- a/lib/strnlen_user.c
92000+++ b/lib/strnlen_user.c
92001@@ -26,7 +26,7 @@
92002 */
92003 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
92004 {
92005- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92006+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92007 long align, res = 0;
92008 unsigned long c;
92009
92010diff --git a/lib/swiotlb.c b/lib/swiotlb.c
92011index b604b83..c0547f6 100644
92012--- a/lib/swiotlb.c
92013+++ b/lib/swiotlb.c
92014@@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
92015
92016 void
92017 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
92018- dma_addr_t dev_addr)
92019+ dma_addr_t dev_addr, struct dma_attrs *attrs)
92020 {
92021 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
92022
92023diff --git a/lib/usercopy.c b/lib/usercopy.c
92024index 4f5b1dd..7cab418 100644
92025--- a/lib/usercopy.c
92026+++ b/lib/usercopy.c
92027@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
92028 WARN(1, "Buffer overflow detected!\n");
92029 }
92030 EXPORT_SYMBOL(copy_from_user_overflow);
92031+
92032+void copy_to_user_overflow(void)
92033+{
92034+ WARN(1, "Buffer overflow detected!\n");
92035+}
92036+EXPORT_SYMBOL(copy_to_user_overflow);
92037diff --git a/lib/vsprintf.c b/lib/vsprintf.c
92038index 0648291..42bf42b 100644
92039--- a/lib/vsprintf.c
92040+++ b/lib/vsprintf.c
92041@@ -16,6 +16,9 @@
92042 * - scnprintf and vscnprintf
92043 */
92044
92045+#ifdef CONFIG_GRKERNSEC_HIDESYM
92046+#define __INCLUDED_BY_HIDESYM 1
92047+#endif
92048 #include <stdarg.h>
92049 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
92050 #include <linux/types.h>
92051@@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
92052 return number(buf, end, num, spec);
92053 }
92054
92055+#ifdef CONFIG_GRKERNSEC_HIDESYM
92056+int kptr_restrict __read_mostly = 2;
92057+#else
92058 int kptr_restrict __read_mostly;
92059+#endif
92060
92061 /*
92062 * Show a '%p' thing. A kernel extension is that the '%p' is followed
92063@@ -1196,6 +1203,7 @@ int kptr_restrict __read_mostly;
92064 * - 'f' For simple symbolic function names without offset
92065 * - 'S' For symbolic direct pointers with offset
92066 * - 's' For symbolic direct pointers without offset
92067+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92068 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92069 * - 'B' For backtraced symbolic direct pointers with offset
92070 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92071@@ -1263,12 +1271,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92072
92073 if (!ptr && *fmt != 'K') {
92074 /*
92075- * Print (null) with the same width as a pointer so it makes
92076+ * Print (nil) with the same width as a pointer so it makes
92077 * tabular output look nice.
92078 */
92079 if (spec.field_width == -1)
92080 spec.field_width = default_width;
92081- return string(buf, end, "(null)", spec);
92082+ return string(buf, end, "(nil)", spec);
92083 }
92084
92085 switch (*fmt) {
92086@@ -1278,6 +1286,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92087 /* Fallthrough */
92088 case 'S':
92089 case 's':
92090+#ifdef CONFIG_GRKERNSEC_HIDESYM
92091+ break;
92092+#else
92093+ return symbol_string(buf, end, ptr, spec, fmt);
92094+#endif
92095+ case 'A':
92096 case 'B':
92097 return symbol_string(buf, end, ptr, spec, fmt);
92098 case 'R':
92099@@ -1333,6 +1347,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92100 va_end(va);
92101 return buf;
92102 }
92103+ case 'P':
92104+ break;
92105 case 'K':
92106 /*
92107 * %pK cannot be used in IRQ context because its test
92108@@ -1390,6 +1406,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92109 ((const struct file *)ptr)->f_path.dentry,
92110 spec, fmt);
92111 }
92112+
92113+#ifdef CONFIG_GRKERNSEC_HIDESYM
92114+ /* 'P' = approved pointers to copy to userland,
92115+ as in the /proc/kallsyms case, as we make it display nothing
92116+ for non-root users, and the real contents for root users
92117+ Also ignore 'K' pointers, since we force their NULLing for non-root users
92118+ above
92119+ */
92120+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92121+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92122+ dump_stack();
92123+ ptr = NULL;
92124+ }
92125+#endif
92126+
92127 spec.flags |= SMALL;
92128 if (spec.field_width == -1) {
92129 spec.field_width = default_width;
92130@@ -2089,11 +2120,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92131 typeof(type) value; \
92132 if (sizeof(type) == 8) { \
92133 args = PTR_ALIGN(args, sizeof(u32)); \
92134- *(u32 *)&value = *(u32 *)args; \
92135- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92136+ *(u32 *)&value = *(const u32 *)args; \
92137+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92138 } else { \
92139 args = PTR_ALIGN(args, sizeof(type)); \
92140- value = *(typeof(type) *)args; \
92141+ value = *(const typeof(type) *)args; \
92142 } \
92143 args += sizeof(type); \
92144 value; \
92145@@ -2156,7 +2187,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92146 case FORMAT_TYPE_STR: {
92147 const char *str_arg = args;
92148 args += strlen(str_arg) + 1;
92149- str = string(str, end, (char *)str_arg, spec);
92150+ str = string(str, end, str_arg, spec);
92151 break;
92152 }
92153
92154diff --git a/localversion-grsec b/localversion-grsec
92155new file mode 100644
92156index 0000000..7cd6065
92157--- /dev/null
92158+++ b/localversion-grsec
92159@@ -0,0 +1 @@
92160+-grsec
92161diff --git a/mm/Kconfig b/mm/Kconfig
92162index 2f42b9c..6095e14 100644
92163--- a/mm/Kconfig
92164+++ b/mm/Kconfig
92165@@ -330,10 +330,11 @@ config KSM
92166 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92167
92168 config DEFAULT_MMAP_MIN_ADDR
92169- int "Low address space to protect from user allocation"
92170+ int "Low address space to protect from user allocation"
92171 depends on MMU
92172- default 4096
92173- help
92174+ default 32768 if ALPHA || ARM || PARISC || SPARC32
92175+ default 65536
92176+ help
92177 This is the portion of low virtual memory which should be protected
92178 from userspace allocation. Keeping a user from writing to low pages
92179 can help reduce the impact of kernel NULL pointer bugs.
92180@@ -364,7 +365,7 @@ config MEMORY_FAILURE
92181
92182 config HWPOISON_INJECT
92183 tristate "HWPoison pages injector"
92184- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92185+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92186 select PROC_PAGE_MONITOR
92187
92188 config NOMMU_INITIAL_TRIM_EXCESS
92189diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92190index 09d9591..165bb75 100644
92191--- a/mm/backing-dev.c
92192+++ b/mm/backing-dev.c
92193@@ -12,7 +12,7 @@
92194 #include <linux/device.h>
92195 #include <trace/events/writeback.h>
92196
92197-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92198+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92199
92200 struct backing_dev_info default_backing_dev_info = {
92201 .name = "default",
92202@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92203 return err;
92204
92205 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92206- atomic_long_inc_return(&bdi_seq));
92207+ atomic_long_inc_return_unchecked(&bdi_seq));
92208 if (err) {
92209 bdi_destroy(bdi);
92210 return err;
92211diff --git a/mm/filemap.c b/mm/filemap.c
92212index 088358c..bb415bf 100644
92213--- a/mm/filemap.c
92214+++ b/mm/filemap.c
92215@@ -2125,7 +2125,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92216 struct address_space *mapping = file->f_mapping;
92217
92218 if (!mapping->a_ops->readpage)
92219- return -ENOEXEC;
92220+ return -ENODEV;
92221 file_accessed(file);
92222 vma->vm_ops = &generic_file_vm_ops;
92223 return 0;
92224@@ -2303,6 +2303,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92225 *pos = i_size_read(inode);
92226
92227 if (limit != RLIM_INFINITY) {
92228+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92229 if (*pos >= limit) {
92230 send_sig(SIGXFSZ, current, 0);
92231 return -EFBIG;
92232diff --git a/mm/fremap.c b/mm/fremap.c
92233index 34feba6..315fe78 100644
92234--- a/mm/fremap.c
92235+++ b/mm/fremap.c
92236@@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92237 retry:
92238 vma = find_vma(mm, start);
92239
92240+#ifdef CONFIG_PAX_SEGMEXEC
92241+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92242+ goto out;
92243+#endif
92244+
92245 /*
92246 * Make sure the vma is shared, that it supports prefaulting,
92247 * and that the remapped range is valid and fully within
92248diff --git a/mm/highmem.c b/mm/highmem.c
92249index b32b70c..e512eb0 100644
92250--- a/mm/highmem.c
92251+++ b/mm/highmem.c
92252@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92253 * So no dangers, even with speculative execution.
92254 */
92255 page = pte_page(pkmap_page_table[i]);
92256+ pax_open_kernel();
92257 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92258-
92259+ pax_close_kernel();
92260 set_page_address(page, NULL);
92261 need_flush = 1;
92262 }
92263@@ -198,9 +199,11 @@ start:
92264 }
92265 }
92266 vaddr = PKMAP_ADDR(last_pkmap_nr);
92267+
92268+ pax_open_kernel();
92269 set_pte_at(&init_mm, vaddr,
92270 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92271-
92272+ pax_close_kernel();
92273 pkmap_count[last_pkmap_nr] = 1;
92274 set_page_address(page, (void *)vaddr);
92275
92276diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92277index a646f15..f55da4c 100644
92278--- a/mm/hugetlb.c
92279+++ b/mm/hugetlb.c
92280@@ -2107,6 +2107,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92281 struct hstate *h = &default_hstate;
92282 unsigned long tmp;
92283 int ret;
92284+ ctl_table_no_const hugetlb_table;
92285
92286 if (!hugepages_supported())
92287 return -ENOTSUPP;
92288@@ -2116,9 +2117,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92289 if (write && h->order >= MAX_ORDER)
92290 return -EINVAL;
92291
92292- table->data = &tmp;
92293- table->maxlen = sizeof(unsigned long);
92294- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92295+ hugetlb_table = *table;
92296+ hugetlb_table.data = &tmp;
92297+ hugetlb_table.maxlen = sizeof(unsigned long);
92298+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92299 if (ret)
92300 goto out;
92301
92302@@ -2163,6 +2165,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92303 struct hstate *h = &default_hstate;
92304 unsigned long tmp;
92305 int ret;
92306+ ctl_table_no_const hugetlb_table;
92307
92308 if (!hugepages_supported())
92309 return -ENOTSUPP;
92310@@ -2172,9 +2175,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92311 if (write && h->order >= MAX_ORDER)
92312 return -EINVAL;
92313
92314- table->data = &tmp;
92315- table->maxlen = sizeof(unsigned long);
92316- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92317+ hugetlb_table = *table;
92318+ hugetlb_table.data = &tmp;
92319+ hugetlb_table.maxlen = sizeof(unsigned long);
92320+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92321 if (ret)
92322 goto out;
92323
92324@@ -2654,6 +2658,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
92325 return 1;
92326 }
92327
92328+#ifdef CONFIG_PAX_SEGMEXEC
92329+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
92330+{
92331+ struct mm_struct *mm = vma->vm_mm;
92332+ struct vm_area_struct *vma_m;
92333+ unsigned long address_m;
92334+ pte_t *ptep_m;
92335+
92336+ vma_m = pax_find_mirror_vma(vma);
92337+ if (!vma_m)
92338+ return;
92339+
92340+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92341+ address_m = address + SEGMEXEC_TASK_SIZE;
92342+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
92343+ get_page(page_m);
92344+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
92345+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
92346+}
92347+#endif
92348+
92349 /*
92350 * Hugetlb_cow() should be called with page lock of the original hugepage held.
92351 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
92352@@ -2771,6 +2796,11 @@ retry_avoidcopy:
92353 make_huge_pte(vma, new_page, 1));
92354 page_remove_rmap(old_page);
92355 hugepage_add_new_anon_rmap(new_page, vma, address);
92356+
92357+#ifdef CONFIG_PAX_SEGMEXEC
92358+ pax_mirror_huge_pte(vma, address, new_page);
92359+#endif
92360+
92361 /* Make the old page be freed below */
92362 new_page = old_page;
92363 }
92364@@ -2930,6 +2960,10 @@ retry:
92365 && (vma->vm_flags & VM_SHARED)));
92366 set_huge_pte_at(mm, address, ptep, new_pte);
92367
92368+#ifdef CONFIG_PAX_SEGMEXEC
92369+ pax_mirror_huge_pte(vma, address, page);
92370+#endif
92371+
92372 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
92373 /* Optimization, do the COW without a second fault */
92374 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
92375@@ -2996,6 +3030,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92376 struct hstate *h = hstate_vma(vma);
92377 struct address_space *mapping;
92378
92379+#ifdef CONFIG_PAX_SEGMEXEC
92380+ struct vm_area_struct *vma_m;
92381+#endif
92382+
92383 address &= huge_page_mask(h);
92384
92385 ptep = huge_pte_offset(mm, address);
92386@@ -3009,6 +3047,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92387 VM_FAULT_SET_HINDEX(hstate_index(h));
92388 }
92389
92390+#ifdef CONFIG_PAX_SEGMEXEC
92391+ vma_m = pax_find_mirror_vma(vma);
92392+ if (vma_m) {
92393+ unsigned long address_m;
92394+
92395+ if (vma->vm_start > vma_m->vm_start) {
92396+ address_m = address;
92397+ address -= SEGMEXEC_TASK_SIZE;
92398+ vma = vma_m;
92399+ h = hstate_vma(vma);
92400+ } else
92401+ address_m = address + SEGMEXEC_TASK_SIZE;
92402+
92403+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
92404+ return VM_FAULT_OOM;
92405+ address_m &= HPAGE_MASK;
92406+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
92407+ }
92408+#endif
92409+
92410 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
92411 if (!ptep)
92412 return VM_FAULT_OOM;
92413diff --git a/mm/internal.h b/mm/internal.h
92414index 07b6736..ae8da20 100644
92415--- a/mm/internal.h
92416+++ b/mm/internal.h
92417@@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
92418 * in mm/page_alloc.c
92419 */
92420 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92421+extern void free_compound_page(struct page *page);
92422 extern void prep_compound_page(struct page *page, unsigned long order);
92423 #ifdef CONFIG_MEMORY_FAILURE
92424 extern bool is_free_buddy_page(struct page *page);
92425@@ -367,7 +368,7 @@ extern u32 hwpoison_filter_enable;
92426
92427 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92428 unsigned long, unsigned long,
92429- unsigned long, unsigned long);
92430+ unsigned long, unsigned long) __intentional_overflow(-1);
92431
92432 extern void set_pageblock_order(void);
92433 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92434diff --git a/mm/iov_iter.c b/mm/iov_iter.c
92435index 10e46cd..e3052f6 100644
92436--- a/mm/iov_iter.c
92437+++ b/mm/iov_iter.c
92438@@ -87,7 +87,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
92439
92440 while (bytes) {
92441 char __user *buf = iov->iov_base + base;
92442- int copy = min(bytes, iov->iov_len - base);
92443+ size_t copy = min(bytes, iov->iov_len - base);
92444
92445 base = 0;
92446 left = __copy_from_user_inatomic(vaddr, buf, copy);
92447@@ -115,7 +115,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
92448
92449 kaddr = kmap_atomic(page);
92450 if (likely(i->nr_segs == 1)) {
92451- int left;
92452+ size_t left;
92453 char __user *buf = i->iov->iov_base + i->iov_offset;
92454 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
92455 copied = bytes - left;
92456@@ -143,7 +143,7 @@ size_t iov_iter_copy_from_user(struct page *page,
92457
92458 kaddr = kmap(page);
92459 if (likely(i->nr_segs == 1)) {
92460- int left;
92461+ size_t left;
92462 char __user *buf = i->iov->iov_base + i->iov_offset;
92463 left = __copy_from_user(kaddr + offset, buf, bytes);
92464 copied = bytes - left;
92465@@ -173,7 +173,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
92466 * zero-length segments (without overruning the iovec).
92467 */
92468 while (bytes || unlikely(i->count && !iov->iov_len)) {
92469- int copy;
92470+ size_t copy;
92471
92472 copy = min(bytes, iov->iov_len - base);
92473 BUG_ON(!i->count || i->count < copy);
92474diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92475index 8d2fcdf..6dd9f1a 100644
92476--- a/mm/kmemleak.c
92477+++ b/mm/kmemleak.c
92478@@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
92479
92480 for (i = 0; i < object->trace_len; i++) {
92481 void *ptr = (void *)object->trace[i];
92482- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92483+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92484 }
92485 }
92486
92487@@ -1871,7 +1871,7 @@ static int __init kmemleak_late_init(void)
92488 return -ENOMEM;
92489 }
92490
92491- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92492+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92493 &kmemleak_fops);
92494 if (!dentry)
92495 pr_warning("Failed to create the debugfs kmemleak file\n");
92496diff --git a/mm/maccess.c b/mm/maccess.c
92497index d53adf9..03a24bf 100644
92498--- a/mm/maccess.c
92499+++ b/mm/maccess.c
92500@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92501 set_fs(KERNEL_DS);
92502 pagefault_disable();
92503 ret = __copy_from_user_inatomic(dst,
92504- (__force const void __user *)src, size);
92505+ (const void __force_user *)src, size);
92506 pagefault_enable();
92507 set_fs(old_fs);
92508
92509@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92510
92511 set_fs(KERNEL_DS);
92512 pagefault_disable();
92513- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92514+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92515 pagefault_enable();
92516 set_fs(old_fs);
92517
92518diff --git a/mm/madvise.c b/mm/madvise.c
92519index a402f8f..f5e5daa 100644
92520--- a/mm/madvise.c
92521+++ b/mm/madvise.c
92522@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92523 pgoff_t pgoff;
92524 unsigned long new_flags = vma->vm_flags;
92525
92526+#ifdef CONFIG_PAX_SEGMEXEC
92527+ struct vm_area_struct *vma_m;
92528+#endif
92529+
92530 switch (behavior) {
92531 case MADV_NORMAL:
92532 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92533@@ -126,6 +130,13 @@ success:
92534 /*
92535 * vm_flags is protected by the mmap_sem held in write mode.
92536 */
92537+
92538+#ifdef CONFIG_PAX_SEGMEXEC
92539+ vma_m = pax_find_mirror_vma(vma);
92540+ if (vma_m)
92541+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
92542+#endif
92543+
92544 vma->vm_flags = new_flags;
92545
92546 out:
92547@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92548 struct vm_area_struct **prev,
92549 unsigned long start, unsigned long end)
92550 {
92551+
92552+#ifdef CONFIG_PAX_SEGMEXEC
92553+ struct vm_area_struct *vma_m;
92554+#endif
92555+
92556 *prev = vma;
92557 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
92558 return -EINVAL;
92559@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92560 zap_page_range(vma, start, end - start, &details);
92561 } else
92562 zap_page_range(vma, start, end - start, NULL);
92563+
92564+#ifdef CONFIG_PAX_SEGMEXEC
92565+ vma_m = pax_find_mirror_vma(vma);
92566+ if (vma_m) {
92567+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
92568+ struct zap_details details = {
92569+ .nonlinear_vma = vma_m,
92570+ .last_index = ULONG_MAX,
92571+ };
92572+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
92573+ } else
92574+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
92575+ }
92576+#endif
92577+
92578 return 0;
92579 }
92580
92581@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
92582 if (end < start)
92583 return error;
92584
92585+#ifdef CONFIG_PAX_SEGMEXEC
92586+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92587+ if (end > SEGMEXEC_TASK_SIZE)
92588+ return error;
92589+ } else
92590+#endif
92591+
92592+ if (end > TASK_SIZE)
92593+ return error;
92594+
92595 error = 0;
92596 if (end == start)
92597 return error;
92598diff --git a/mm/memory-failure.c b/mm/memory-failure.c
92599index eb8fb72..ae36cf3 100644
92600--- a/mm/memory-failure.c
92601+++ b/mm/memory-failure.c
92602@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
92603
92604 int sysctl_memory_failure_recovery __read_mostly = 1;
92605
92606-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92607+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92608
92609 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
92610
92611@@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
92612 pfn, t->comm, t->pid);
92613 si.si_signo = SIGBUS;
92614 si.si_errno = 0;
92615- si.si_addr = (void *)addr;
92616+ si.si_addr = (void __user *)addr;
92617 #ifdef __ARCH_SI_TRAPNO
92618 si.si_trapno = trapno;
92619 #endif
92620@@ -791,7 +791,7 @@ static struct page_state {
92621 unsigned long res;
92622 char *msg;
92623 int (*action)(struct page *p, unsigned long pfn);
92624-} error_states[] = {
92625+} __do_const error_states[] = {
92626 { reserved, reserved, "reserved kernel", me_kernel },
92627 /*
92628 * free pages are specially detected outside this table:
92629@@ -1091,7 +1091,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92630 nr_pages = 1 << compound_order(hpage);
92631 else /* normal page or thp */
92632 nr_pages = 1;
92633- atomic_long_add(nr_pages, &num_poisoned_pages);
92634+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
92635
92636 /*
92637 * We need/can do nothing about count=0 pages.
92638@@ -1120,7 +1120,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92639 if (PageHWPoison(hpage)) {
92640 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
92641 || (p != hpage && TestSetPageHWPoison(hpage))) {
92642- atomic_long_sub(nr_pages, &num_poisoned_pages);
92643+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92644 unlock_page(hpage);
92645 return 0;
92646 }
92647@@ -1186,14 +1186,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92648 */
92649 if (!PageHWPoison(p)) {
92650 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
92651- atomic_long_sub(nr_pages, &num_poisoned_pages);
92652+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92653 put_page(hpage);
92654 res = 0;
92655 goto out;
92656 }
92657 if (hwpoison_filter(p)) {
92658 if (TestClearPageHWPoison(p))
92659- atomic_long_sub(nr_pages, &num_poisoned_pages);
92660+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92661 unlock_page(hpage);
92662 put_page(hpage);
92663 return 0;
92664@@ -1415,7 +1415,7 @@ int unpoison_memory(unsigned long pfn)
92665 return 0;
92666 }
92667 if (TestClearPageHWPoison(p))
92668- atomic_long_dec(&num_poisoned_pages);
92669+ atomic_long_dec_unchecked(&num_poisoned_pages);
92670 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
92671 return 0;
92672 }
92673@@ -1429,7 +1429,7 @@ int unpoison_memory(unsigned long pfn)
92674 */
92675 if (TestClearPageHWPoison(page)) {
92676 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
92677- atomic_long_sub(nr_pages, &num_poisoned_pages);
92678+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92679 freeit = 1;
92680 if (PageHuge(page))
92681 clear_page_hwpoison_huge_page(page);
92682@@ -1554,11 +1554,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
92683 if (PageHuge(page)) {
92684 set_page_hwpoison_huge_page(hpage);
92685 dequeue_hwpoisoned_huge_page(hpage);
92686- atomic_long_add(1 << compound_order(hpage),
92687+ atomic_long_add_unchecked(1 << compound_order(hpage),
92688 &num_poisoned_pages);
92689 } else {
92690 SetPageHWPoison(page);
92691- atomic_long_inc(&num_poisoned_pages);
92692+ atomic_long_inc_unchecked(&num_poisoned_pages);
92693 }
92694 }
92695 return ret;
92696@@ -1597,7 +1597,7 @@ static int __soft_offline_page(struct page *page, int flags)
92697 put_page(page);
92698 pr_info("soft_offline: %#lx: invalidated\n", pfn);
92699 SetPageHWPoison(page);
92700- atomic_long_inc(&num_poisoned_pages);
92701+ atomic_long_inc_unchecked(&num_poisoned_pages);
92702 return 0;
92703 }
92704
92705@@ -1648,7 +1648,7 @@ static int __soft_offline_page(struct page *page, int flags)
92706 if (!is_free_buddy_page(page))
92707 pr_info("soft offline: %#lx: page leaked\n",
92708 pfn);
92709- atomic_long_inc(&num_poisoned_pages);
92710+ atomic_long_inc_unchecked(&num_poisoned_pages);
92711 }
92712 } else {
92713 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
92714@@ -1722,11 +1722,11 @@ int soft_offline_page(struct page *page, int flags)
92715 if (PageHuge(page)) {
92716 set_page_hwpoison_huge_page(hpage);
92717 dequeue_hwpoisoned_huge_page(hpage);
92718- atomic_long_add(1 << compound_order(hpage),
92719+ atomic_long_add_unchecked(1 << compound_order(hpage),
92720 &num_poisoned_pages);
92721 } else {
92722 SetPageHWPoison(page);
92723- atomic_long_inc(&num_poisoned_pages);
92724+ atomic_long_inc_unchecked(&num_poisoned_pages);
92725 }
92726 }
92727 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
92728diff --git a/mm/memory.c b/mm/memory.c
92729index e302ae1..c0ef712 100644
92730--- a/mm/memory.c
92731+++ b/mm/memory.c
92732@@ -413,6 +413,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92733 free_pte_range(tlb, pmd, addr);
92734 } while (pmd++, addr = next, addr != end);
92735
92736+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
92737 start &= PUD_MASK;
92738 if (start < floor)
92739 return;
92740@@ -427,6 +428,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92741 pmd = pmd_offset(pud, start);
92742 pud_clear(pud);
92743 pmd_free_tlb(tlb, pmd, start);
92744+#endif
92745+
92746 }
92747
92748 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92749@@ -446,6 +449,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92750 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
92751 } while (pud++, addr = next, addr != end);
92752
92753+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
92754 start &= PGDIR_MASK;
92755 if (start < floor)
92756 return;
92757@@ -460,6 +464,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92758 pud = pud_offset(pgd, start);
92759 pgd_clear(pgd);
92760 pud_free_tlb(tlb, pud, start);
92761+#endif
92762+
92763 }
92764
92765 /*
92766@@ -1652,12 +1658,6 @@ no_page_table:
92767 return page;
92768 }
92769
92770-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
92771-{
92772- return stack_guard_page_start(vma, addr) ||
92773- stack_guard_page_end(vma, addr+PAGE_SIZE);
92774-}
92775-
92776 /**
92777 * __get_user_pages() - pin user pages in memory
92778 * @tsk: task_struct of target task
92779@@ -1735,10 +1735,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92780
92781 i = 0;
92782
92783- do {
92784+ while (nr_pages) {
92785 struct vm_area_struct *vma;
92786
92787- vma = find_extend_vma(mm, start);
92788+ vma = find_vma(mm, start);
92789 if (!vma && in_gate_area(mm, start)) {
92790 unsigned long pg = start & PAGE_MASK;
92791 pgd_t *pgd;
92792@@ -1787,7 +1787,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92793 goto next_page;
92794 }
92795
92796- if (!vma)
92797+ if (!vma || start < vma->vm_start)
92798 goto efault;
92799 vm_flags = vma->vm_flags;
92800 if (vm_flags & (VM_IO | VM_PFNMAP))
92801@@ -1848,11 +1848,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92802 int ret;
92803 unsigned int fault_flags = 0;
92804
92805- /* For mlock, just skip the stack guard page. */
92806- if (foll_flags & FOLL_MLOCK) {
92807- if (stack_guard_page(vma, start))
92808- goto next_page;
92809- }
92810 if (foll_flags & FOLL_WRITE)
92811 fault_flags |= FAULT_FLAG_WRITE;
92812 if (nonblocking)
92813@@ -1932,7 +1927,7 @@ next_page:
92814 start += page_increm * PAGE_SIZE;
92815 nr_pages -= page_increm;
92816 } while (nr_pages && start < vma->vm_end);
92817- } while (nr_pages);
92818+ }
92819 return i;
92820 efault:
92821 return i ? : -EFAULT;
92822@@ -2145,6 +2140,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
92823 page_add_file_rmap(page);
92824 set_pte_at(mm, addr, pte, mk_pte(page, prot));
92825
92826+#ifdef CONFIG_PAX_SEGMEXEC
92827+ pax_mirror_file_pte(vma, addr, page, ptl);
92828+#endif
92829+
92830 retval = 0;
92831 pte_unmap_unlock(pte, ptl);
92832 return retval;
92833@@ -2189,9 +2188,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
92834 if (!page_count(page))
92835 return -EINVAL;
92836 if (!(vma->vm_flags & VM_MIXEDMAP)) {
92837+
92838+#ifdef CONFIG_PAX_SEGMEXEC
92839+ struct vm_area_struct *vma_m;
92840+#endif
92841+
92842 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
92843 BUG_ON(vma->vm_flags & VM_PFNMAP);
92844 vma->vm_flags |= VM_MIXEDMAP;
92845+
92846+#ifdef CONFIG_PAX_SEGMEXEC
92847+ vma_m = pax_find_mirror_vma(vma);
92848+ if (vma_m)
92849+ vma_m->vm_flags |= VM_MIXEDMAP;
92850+#endif
92851+
92852 }
92853 return insert_page(vma, addr, page, vma->vm_page_prot);
92854 }
92855@@ -2274,6 +2285,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
92856 unsigned long pfn)
92857 {
92858 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
92859+ BUG_ON(vma->vm_mirror);
92860
92861 if (addr < vma->vm_start || addr >= vma->vm_end)
92862 return -EFAULT;
92863@@ -2521,7 +2533,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
92864
92865 BUG_ON(pud_huge(*pud));
92866
92867- pmd = pmd_alloc(mm, pud, addr);
92868+ pmd = (mm == &init_mm) ?
92869+ pmd_alloc_kernel(mm, pud, addr) :
92870+ pmd_alloc(mm, pud, addr);
92871 if (!pmd)
92872 return -ENOMEM;
92873 do {
92874@@ -2541,7 +2555,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
92875 unsigned long next;
92876 int err;
92877
92878- pud = pud_alloc(mm, pgd, addr);
92879+ pud = (mm == &init_mm) ?
92880+ pud_alloc_kernel(mm, pgd, addr) :
92881+ pud_alloc(mm, pgd, addr);
92882 if (!pud)
92883 return -ENOMEM;
92884 do {
92885@@ -2663,6 +2679,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
92886 return ret;
92887 }
92888
92889+#ifdef CONFIG_PAX_SEGMEXEC
92890+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
92891+{
92892+ struct mm_struct *mm = vma->vm_mm;
92893+ spinlock_t *ptl;
92894+ pte_t *pte, entry;
92895+
92896+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
92897+ entry = *pte;
92898+ if (!pte_present(entry)) {
92899+ if (!pte_none(entry)) {
92900+ BUG_ON(pte_file(entry));
92901+ free_swap_and_cache(pte_to_swp_entry(entry));
92902+ pte_clear_not_present_full(mm, address, pte, 0);
92903+ }
92904+ } else {
92905+ struct page *page;
92906+
92907+ flush_cache_page(vma, address, pte_pfn(entry));
92908+ entry = ptep_clear_flush(vma, address, pte);
92909+ BUG_ON(pte_dirty(entry));
92910+ page = vm_normal_page(vma, address, entry);
92911+ if (page) {
92912+ update_hiwater_rss(mm);
92913+ if (PageAnon(page))
92914+ dec_mm_counter_fast(mm, MM_ANONPAGES);
92915+ else
92916+ dec_mm_counter_fast(mm, MM_FILEPAGES);
92917+ page_remove_rmap(page);
92918+ page_cache_release(page);
92919+ }
92920+ }
92921+ pte_unmap_unlock(pte, ptl);
92922+}
92923+
92924+/* PaX: if vma is mirrored, synchronize the mirror's PTE
92925+ *
92926+ * the ptl of the lower mapped page is held on entry and is not released on exit
92927+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
92928+ */
92929+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92930+{
92931+ struct mm_struct *mm = vma->vm_mm;
92932+ unsigned long address_m;
92933+ spinlock_t *ptl_m;
92934+ struct vm_area_struct *vma_m;
92935+ pmd_t *pmd_m;
92936+ pte_t *pte_m, entry_m;
92937+
92938+ BUG_ON(!page_m || !PageAnon(page_m));
92939+
92940+ vma_m = pax_find_mirror_vma(vma);
92941+ if (!vma_m)
92942+ return;
92943+
92944+ BUG_ON(!PageLocked(page_m));
92945+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92946+ address_m = address + SEGMEXEC_TASK_SIZE;
92947+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92948+ pte_m = pte_offset_map(pmd_m, address_m);
92949+ ptl_m = pte_lockptr(mm, pmd_m);
92950+ if (ptl != ptl_m) {
92951+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92952+ if (!pte_none(*pte_m))
92953+ goto out;
92954+ }
92955+
92956+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92957+ page_cache_get(page_m);
92958+ page_add_anon_rmap(page_m, vma_m, address_m);
92959+ inc_mm_counter_fast(mm, MM_ANONPAGES);
92960+ set_pte_at(mm, address_m, pte_m, entry_m);
92961+ update_mmu_cache(vma_m, address_m, pte_m);
92962+out:
92963+ if (ptl != ptl_m)
92964+ spin_unlock(ptl_m);
92965+ pte_unmap(pte_m);
92966+ unlock_page(page_m);
92967+}
92968+
92969+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92970+{
92971+ struct mm_struct *mm = vma->vm_mm;
92972+ unsigned long address_m;
92973+ spinlock_t *ptl_m;
92974+ struct vm_area_struct *vma_m;
92975+ pmd_t *pmd_m;
92976+ pte_t *pte_m, entry_m;
92977+
92978+ BUG_ON(!page_m || PageAnon(page_m));
92979+
92980+ vma_m = pax_find_mirror_vma(vma);
92981+ if (!vma_m)
92982+ return;
92983+
92984+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92985+ address_m = address + SEGMEXEC_TASK_SIZE;
92986+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92987+ pte_m = pte_offset_map(pmd_m, address_m);
92988+ ptl_m = pte_lockptr(mm, pmd_m);
92989+ if (ptl != ptl_m) {
92990+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92991+ if (!pte_none(*pte_m))
92992+ goto out;
92993+ }
92994+
92995+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92996+ page_cache_get(page_m);
92997+ page_add_file_rmap(page_m);
92998+ inc_mm_counter_fast(mm, MM_FILEPAGES);
92999+ set_pte_at(mm, address_m, pte_m, entry_m);
93000+ update_mmu_cache(vma_m, address_m, pte_m);
93001+out:
93002+ if (ptl != ptl_m)
93003+ spin_unlock(ptl_m);
93004+ pte_unmap(pte_m);
93005+}
93006+
93007+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
93008+{
93009+ struct mm_struct *mm = vma->vm_mm;
93010+ unsigned long address_m;
93011+ spinlock_t *ptl_m;
93012+ struct vm_area_struct *vma_m;
93013+ pmd_t *pmd_m;
93014+ pte_t *pte_m, entry_m;
93015+
93016+ vma_m = pax_find_mirror_vma(vma);
93017+ if (!vma_m)
93018+ return;
93019+
93020+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93021+ address_m = address + SEGMEXEC_TASK_SIZE;
93022+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93023+ pte_m = pte_offset_map(pmd_m, address_m);
93024+ ptl_m = pte_lockptr(mm, pmd_m);
93025+ if (ptl != ptl_m) {
93026+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93027+ if (!pte_none(*pte_m))
93028+ goto out;
93029+ }
93030+
93031+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
93032+ set_pte_at(mm, address_m, pte_m, entry_m);
93033+out:
93034+ if (ptl != ptl_m)
93035+ spin_unlock(ptl_m);
93036+ pte_unmap(pte_m);
93037+}
93038+
93039+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
93040+{
93041+ struct page *page_m;
93042+ pte_t entry;
93043+
93044+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
93045+ goto out;
93046+
93047+ entry = *pte;
93048+ page_m = vm_normal_page(vma, address, entry);
93049+ if (!page_m)
93050+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
93051+ else if (PageAnon(page_m)) {
93052+ if (pax_find_mirror_vma(vma)) {
93053+ pte_unmap_unlock(pte, ptl);
93054+ lock_page(page_m);
93055+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
93056+ if (pte_same(entry, *pte))
93057+ pax_mirror_anon_pte(vma, address, page_m, ptl);
93058+ else
93059+ unlock_page(page_m);
93060+ }
93061+ } else
93062+ pax_mirror_file_pte(vma, address, page_m, ptl);
93063+
93064+out:
93065+ pte_unmap_unlock(pte, ptl);
93066+}
93067+#endif
93068+
93069 /*
93070 * This routine handles present pages, when users try to write
93071 * to a shared page. It is done by copying the page to a new address
93072@@ -2860,6 +3056,12 @@ gotten:
93073 */
93074 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93075 if (likely(pte_same(*page_table, orig_pte))) {
93076+
93077+#ifdef CONFIG_PAX_SEGMEXEC
93078+ if (pax_find_mirror_vma(vma))
93079+ BUG_ON(!trylock_page(new_page));
93080+#endif
93081+
93082 if (old_page) {
93083 if (!PageAnon(old_page)) {
93084 dec_mm_counter_fast(mm, MM_FILEPAGES);
93085@@ -2911,6 +3113,10 @@ gotten:
93086 page_remove_rmap(old_page);
93087 }
93088
93089+#ifdef CONFIG_PAX_SEGMEXEC
93090+ pax_mirror_anon_pte(vma, address, new_page, ptl);
93091+#endif
93092+
93093 /* Free the old page.. */
93094 new_page = old_page;
93095 ret |= VM_FAULT_WRITE;
93096@@ -3184,6 +3390,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93097 swap_free(entry);
93098 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93099 try_to_free_swap(page);
93100+
93101+#ifdef CONFIG_PAX_SEGMEXEC
93102+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93103+#endif
93104+
93105 unlock_page(page);
93106 if (page != swapcache) {
93107 /*
93108@@ -3207,6 +3418,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93109
93110 /* No need to invalidate - it was non-present before */
93111 update_mmu_cache(vma, address, page_table);
93112+
93113+#ifdef CONFIG_PAX_SEGMEXEC
93114+ pax_mirror_anon_pte(vma, address, page, ptl);
93115+#endif
93116+
93117 unlock:
93118 pte_unmap_unlock(page_table, ptl);
93119 out:
93120@@ -3226,40 +3442,6 @@ out_release:
93121 }
93122
93123 /*
93124- * This is like a special single-page "expand_{down|up}wards()",
93125- * except we must first make sure that 'address{-|+}PAGE_SIZE'
93126- * doesn't hit another vma.
93127- */
93128-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93129-{
93130- address &= PAGE_MASK;
93131- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93132- struct vm_area_struct *prev = vma->vm_prev;
93133-
93134- /*
93135- * Is there a mapping abutting this one below?
93136- *
93137- * That's only ok if it's the same stack mapping
93138- * that has gotten split..
93139- */
93140- if (prev && prev->vm_end == address)
93141- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93142-
93143- expand_downwards(vma, address - PAGE_SIZE);
93144- }
93145- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93146- struct vm_area_struct *next = vma->vm_next;
93147-
93148- /* As VM_GROWSDOWN but s/below/above/ */
93149- if (next && next->vm_start == address + PAGE_SIZE)
93150- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93151-
93152- expand_upwards(vma, address + PAGE_SIZE);
93153- }
93154- return 0;
93155-}
93156-
93157-/*
93158 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93159 * but allow concurrent faults), and pte mapped but not yet locked.
93160 * We return with mmap_sem still held, but pte unmapped and unlocked.
93161@@ -3268,27 +3450,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93162 unsigned long address, pte_t *page_table, pmd_t *pmd,
93163 unsigned int flags)
93164 {
93165- struct page *page;
93166+ struct page *page = NULL;
93167 spinlock_t *ptl;
93168 pte_t entry;
93169
93170- pte_unmap(page_table);
93171-
93172- /* Check if we need to add a guard page to the stack */
93173- if (check_stack_guard_page(vma, address) < 0)
93174- return VM_FAULT_SIGBUS;
93175-
93176- /* Use the zero-page for reads */
93177 if (!(flags & FAULT_FLAG_WRITE)) {
93178 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93179 vma->vm_page_prot));
93180- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93181+ ptl = pte_lockptr(mm, pmd);
93182+ spin_lock(ptl);
93183 if (!pte_none(*page_table))
93184 goto unlock;
93185 goto setpte;
93186 }
93187
93188 /* Allocate our own private page. */
93189+ pte_unmap(page_table);
93190+
93191 if (unlikely(anon_vma_prepare(vma)))
93192 goto oom;
93193 page = alloc_zeroed_user_highpage_movable(vma, address);
93194@@ -3312,6 +3490,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93195 if (!pte_none(*page_table))
93196 goto release;
93197
93198+#ifdef CONFIG_PAX_SEGMEXEC
93199+ if (pax_find_mirror_vma(vma))
93200+ BUG_ON(!trylock_page(page));
93201+#endif
93202+
93203 inc_mm_counter_fast(mm, MM_ANONPAGES);
93204 page_add_new_anon_rmap(page, vma, address);
93205 setpte:
93206@@ -3319,6 +3502,12 @@ setpte:
93207
93208 /* No need to invalidate - it was non-present before */
93209 update_mmu_cache(vma, address, page_table);
93210+
93211+#ifdef CONFIG_PAX_SEGMEXEC
93212+ if (page)
93213+ pax_mirror_anon_pte(vma, address, page, ptl);
93214+#endif
93215+
93216 unlock:
93217 pte_unmap_unlock(page_table, ptl);
93218 return 0;
93219@@ -3535,6 +3724,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93220 return ret;
93221 }
93222 do_set_pte(vma, address, fault_page, pte, false, false);
93223+
93224+#ifdef CONFIG_PAX_SEGMEXEC
93225+ pax_mirror_file_pte(vma, address, fault_page, ptl);
93226+#endif
93227+
93228 unlock_page(fault_page);
93229 unlock_out:
93230 pte_unmap_unlock(pte, ptl);
93231@@ -3576,7 +3770,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93232 page_cache_release(fault_page);
93233 goto uncharge_out;
93234 }
93235+
93236+#ifdef CONFIG_PAX_SEGMEXEC
93237+ if (pax_find_mirror_vma(vma))
93238+ BUG_ON(!trylock_page(new_page));
93239+#endif
93240+
93241 do_set_pte(vma, address, new_page, pte, true, true);
93242+
93243+#ifdef CONFIG_PAX_SEGMEXEC
93244+ pax_mirror_anon_pte(vma, address, new_page, ptl);
93245+#endif
93246+
93247 pte_unmap_unlock(pte, ptl);
93248 unlock_page(fault_page);
93249 page_cache_release(fault_page);
93250@@ -3624,6 +3829,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93251 return ret;
93252 }
93253 do_set_pte(vma, address, fault_page, pte, true, false);
93254+
93255+#ifdef CONFIG_PAX_SEGMEXEC
93256+ pax_mirror_file_pte(vma, address, fault_page, ptl);
93257+#endif
93258+
93259 pte_unmap_unlock(pte, ptl);
93260
93261 if (set_page_dirty(fault_page))
93262@@ -3854,6 +4064,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93263 if (flags & FAULT_FLAG_WRITE)
93264 flush_tlb_fix_spurious_fault(vma, address);
93265 }
93266+
93267+#ifdef CONFIG_PAX_SEGMEXEC
93268+ pax_mirror_pte(vma, address, pte, pmd, ptl);
93269+ return 0;
93270+#endif
93271+
93272 unlock:
93273 pte_unmap_unlock(pte, ptl);
93274 return 0;
93275@@ -3870,9 +4086,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93276 pmd_t *pmd;
93277 pte_t *pte;
93278
93279+#ifdef CONFIG_PAX_SEGMEXEC
93280+ struct vm_area_struct *vma_m;
93281+#endif
93282+
93283 if (unlikely(is_vm_hugetlb_page(vma)))
93284 return hugetlb_fault(mm, vma, address, flags);
93285
93286+#ifdef CONFIG_PAX_SEGMEXEC
93287+ vma_m = pax_find_mirror_vma(vma);
93288+ if (vma_m) {
93289+ unsigned long address_m;
93290+ pgd_t *pgd_m;
93291+ pud_t *pud_m;
93292+ pmd_t *pmd_m;
93293+
93294+ if (vma->vm_start > vma_m->vm_start) {
93295+ address_m = address;
93296+ address -= SEGMEXEC_TASK_SIZE;
93297+ vma = vma_m;
93298+ } else
93299+ address_m = address + SEGMEXEC_TASK_SIZE;
93300+
93301+ pgd_m = pgd_offset(mm, address_m);
93302+ pud_m = pud_alloc(mm, pgd_m, address_m);
93303+ if (!pud_m)
93304+ return VM_FAULT_OOM;
93305+ pmd_m = pmd_alloc(mm, pud_m, address_m);
93306+ if (!pmd_m)
93307+ return VM_FAULT_OOM;
93308+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
93309+ return VM_FAULT_OOM;
93310+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
93311+ }
93312+#endif
93313+
93314 pgd = pgd_offset(mm, address);
93315 pud = pud_alloc(mm, pgd, address);
93316 if (!pud)
93317@@ -4000,6 +4248,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93318 spin_unlock(&mm->page_table_lock);
93319 return 0;
93320 }
93321+
93322+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93323+{
93324+ pud_t *new = pud_alloc_one(mm, address);
93325+ if (!new)
93326+ return -ENOMEM;
93327+
93328+ smp_wmb(); /* See comment in __pte_alloc */
93329+
93330+ spin_lock(&mm->page_table_lock);
93331+ if (pgd_present(*pgd)) /* Another has populated it */
93332+ pud_free(mm, new);
93333+ else
93334+ pgd_populate_kernel(mm, pgd, new);
93335+ spin_unlock(&mm->page_table_lock);
93336+ return 0;
93337+}
93338 #endif /* __PAGETABLE_PUD_FOLDED */
93339
93340 #ifndef __PAGETABLE_PMD_FOLDED
93341@@ -4030,6 +4295,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
93342 spin_unlock(&mm->page_table_lock);
93343 return 0;
93344 }
93345+
93346+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
93347+{
93348+ pmd_t *new = pmd_alloc_one(mm, address);
93349+ if (!new)
93350+ return -ENOMEM;
93351+
93352+ smp_wmb(); /* See comment in __pte_alloc */
93353+
93354+ spin_lock(&mm->page_table_lock);
93355+#ifndef __ARCH_HAS_4LEVEL_HACK
93356+ if (pud_present(*pud)) /* Another has populated it */
93357+ pmd_free(mm, new);
93358+ else
93359+ pud_populate_kernel(mm, pud, new);
93360+#else
93361+ if (pgd_present(*pud)) /* Another has populated it */
93362+ pmd_free(mm, new);
93363+ else
93364+ pgd_populate_kernel(mm, pud, new);
93365+#endif /* __ARCH_HAS_4LEVEL_HACK */
93366+ spin_unlock(&mm->page_table_lock);
93367+ return 0;
93368+}
93369 #endif /* __PAGETABLE_PMD_FOLDED */
93370
93371 #if !defined(__HAVE_ARCH_GATE_AREA)
93372@@ -4043,7 +4332,7 @@ static int __init gate_vma_init(void)
93373 gate_vma.vm_start = FIXADDR_USER_START;
93374 gate_vma.vm_end = FIXADDR_USER_END;
93375 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
93376- gate_vma.vm_page_prot = __P101;
93377+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
93378
93379 return 0;
93380 }
93381@@ -4177,8 +4466,8 @@ out:
93382 return ret;
93383 }
93384
93385-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93386- void *buf, int len, int write)
93387+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93388+ void *buf, size_t len, int write)
93389 {
93390 resource_size_t phys_addr;
93391 unsigned long prot = 0;
93392@@ -4204,8 +4493,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
93393 * Access another process' address space as given in mm. If non-NULL, use the
93394 * given task for page fault accounting.
93395 */
93396-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93397- unsigned long addr, void *buf, int len, int write)
93398+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93399+ unsigned long addr, void *buf, size_t len, int write)
93400 {
93401 struct vm_area_struct *vma;
93402 void *old_buf = buf;
93403@@ -4213,7 +4502,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93404 down_read(&mm->mmap_sem);
93405 /* ignore errors, just check how much was successfully transferred */
93406 while (len) {
93407- int bytes, ret, offset;
93408+ ssize_t bytes, ret, offset;
93409 void *maddr;
93410 struct page *page = NULL;
93411
93412@@ -4272,8 +4561,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93413 *
93414 * The caller must hold a reference on @mm.
93415 */
93416-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93417- void *buf, int len, int write)
93418+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93419+ void *buf, size_t len, int write)
93420 {
93421 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93422 }
93423@@ -4283,11 +4572,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93424 * Source/target buffer must be kernel space,
93425 * Do not walk the page table directly, use get_user_pages
93426 */
93427-int access_process_vm(struct task_struct *tsk, unsigned long addr,
93428- void *buf, int len, int write)
93429+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
93430+ void *buf, size_t len, int write)
93431 {
93432 struct mm_struct *mm;
93433- int ret;
93434+ ssize_t ret;
93435
93436 mm = get_task_mm(tsk);
93437 if (!mm)
93438diff --git a/mm/mempolicy.c b/mm/mempolicy.c
93439index 35f9f91..bed4575 100644
93440--- a/mm/mempolicy.c
93441+++ b/mm/mempolicy.c
93442@@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93443 unsigned long vmstart;
93444 unsigned long vmend;
93445
93446+#ifdef CONFIG_PAX_SEGMEXEC
93447+ struct vm_area_struct *vma_m;
93448+#endif
93449+
93450 vma = find_vma(mm, start);
93451 if (!vma || vma->vm_start > start)
93452 return -EFAULT;
93453@@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93454 err = vma_replace_policy(vma, new_pol);
93455 if (err)
93456 goto out;
93457+
93458+#ifdef CONFIG_PAX_SEGMEXEC
93459+ vma_m = pax_find_mirror_vma(vma);
93460+ if (vma_m) {
93461+ err = vma_replace_policy(vma_m, new_pol);
93462+ if (err)
93463+ goto out;
93464+ }
93465+#endif
93466+
93467 }
93468
93469 out:
93470@@ -1222,6 +1236,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93471
93472 if (end < start)
93473 return -EINVAL;
93474+
93475+#ifdef CONFIG_PAX_SEGMEXEC
93476+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93477+ if (end > SEGMEXEC_TASK_SIZE)
93478+ return -EINVAL;
93479+ } else
93480+#endif
93481+
93482+ if (end > TASK_SIZE)
93483+ return -EINVAL;
93484+
93485 if (end == start)
93486 return 0;
93487
93488@@ -1447,8 +1472,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93489 */
93490 tcred = __task_cred(task);
93491 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93492- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93493- !capable(CAP_SYS_NICE)) {
93494+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93495 rcu_read_unlock();
93496 err = -EPERM;
93497 goto out_put;
93498@@ -1479,6 +1503,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93499 goto out;
93500 }
93501
93502+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93503+ if (mm != current->mm &&
93504+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93505+ mmput(mm);
93506+ err = -EPERM;
93507+ goto out;
93508+ }
93509+#endif
93510+
93511 err = do_migrate_pages(mm, old, new,
93512 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93513
93514diff --git a/mm/migrate.c b/mm/migrate.c
93515index bed4880..a493f67 100644
93516--- a/mm/migrate.c
93517+++ b/mm/migrate.c
93518@@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93519 */
93520 tcred = __task_cred(task);
93521 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93522- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93523- !capable(CAP_SYS_NICE)) {
93524+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93525 rcu_read_unlock();
93526 err = -EPERM;
93527 goto out;
93528diff --git a/mm/mlock.c b/mm/mlock.c
93529index b1eb536..091d154 100644
93530--- a/mm/mlock.c
93531+++ b/mm/mlock.c
93532@@ -14,6 +14,7 @@
93533 #include <linux/pagevec.h>
93534 #include <linux/mempolicy.h>
93535 #include <linux/syscalls.h>
93536+#include <linux/security.h>
93537 #include <linux/sched.h>
93538 #include <linux/export.h>
93539 #include <linux/rmap.h>
93540@@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
93541 {
93542 unsigned long nstart, end, tmp;
93543 struct vm_area_struct * vma, * prev;
93544- int error;
93545+ int error = 0;
93546
93547 VM_BUG_ON(start & ~PAGE_MASK);
93548 VM_BUG_ON(len != PAGE_ALIGN(len));
93549@@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
93550 return -EINVAL;
93551 if (end == start)
93552 return 0;
93553+ if (end > TASK_SIZE)
93554+ return -EINVAL;
93555+
93556 vma = find_vma(current->mm, start);
93557 if (!vma || vma->vm_start > start)
93558 return -ENOMEM;
93559@@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
93560 for (nstart = start ; ; ) {
93561 vm_flags_t newflags;
93562
93563+#ifdef CONFIG_PAX_SEGMEXEC
93564+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93565+ break;
93566+#endif
93567+
93568 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
93569
93570 newflags = vma->vm_flags & ~VM_LOCKED;
93571@@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
93572 locked += current->mm->locked_vm;
93573
93574 /* check against resource limits */
93575+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
93576 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
93577 error = do_mlock(start, len, 1);
93578
93579@@ -776,6 +786,11 @@ static int do_mlockall(int flags)
93580 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
93581 vm_flags_t newflags;
93582
93583+#ifdef CONFIG_PAX_SEGMEXEC
93584+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93585+ break;
93586+#endif
93587+
93588 newflags = vma->vm_flags & ~VM_LOCKED;
93589 if (flags & MCL_CURRENT)
93590 newflags |= VM_LOCKED;
93591@@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
93592 lock_limit >>= PAGE_SHIFT;
93593
93594 ret = -ENOMEM;
93595+
93596+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
93597+
93598 down_write(&current->mm->mmap_sem);
93599-
93600 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
93601 capable(CAP_IPC_LOCK))
93602 ret = do_mlockall(flags);
93603diff --git a/mm/mmap.c b/mm/mmap.c
93604index b1202cf..ee487f8 100644
93605--- a/mm/mmap.c
93606+++ b/mm/mmap.c
93607@@ -37,6 +37,7 @@
93608 #include <linux/sched/sysctl.h>
93609 #include <linux/notifier.h>
93610 #include <linux/memory.h>
93611+#include <linux/random.h>
93612
93613 #include <asm/uaccess.h>
93614 #include <asm/cacheflush.h>
93615@@ -53,6 +54,16 @@
93616 #define arch_rebalance_pgtables(addr, len) (addr)
93617 #endif
93618
93619+static inline void verify_mm_writelocked(struct mm_struct *mm)
93620+{
93621+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
93622+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93623+ up_read(&mm->mmap_sem);
93624+ BUG();
93625+ }
93626+#endif
93627+}
93628+
93629 static void unmap_region(struct mm_struct *mm,
93630 struct vm_area_struct *vma, struct vm_area_struct *prev,
93631 unsigned long start, unsigned long end);
93632@@ -72,16 +83,25 @@ static void unmap_region(struct mm_struct *mm,
93633 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
93634 *
93635 */
93636-pgprot_t protection_map[16] = {
93637+pgprot_t protection_map[16] __read_only = {
93638 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
93639 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
93640 };
93641
93642-pgprot_t vm_get_page_prot(unsigned long vm_flags)
93643+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
93644 {
93645- return __pgprot(pgprot_val(protection_map[vm_flags &
93646+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
93647 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
93648 pgprot_val(arch_vm_get_page_prot(vm_flags)));
93649+
93650+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93651+ if (!(__supported_pte_mask & _PAGE_NX) &&
93652+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
93653+ (vm_flags & (VM_READ | VM_WRITE)))
93654+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
93655+#endif
93656+
93657+ return prot;
93658 }
93659 EXPORT_SYMBOL(vm_get_page_prot);
93660
93661@@ -91,6 +111,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
93662 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
93663 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93664 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93665+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
93666 /*
93667 * Make sure vm_committed_as in one cacheline and not cacheline shared with
93668 * other variables. It can be updated by several CPUs frequently.
93669@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
93670 struct vm_area_struct *next = vma->vm_next;
93671
93672 might_sleep();
93673+ BUG_ON(vma->vm_mirror);
93674 if (vma->vm_ops && vma->vm_ops->close)
93675 vma->vm_ops->close(vma);
93676 if (vma->vm_file)
93677@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
93678 * not page aligned -Ram Gupta
93679 */
93680 rlim = rlimit(RLIMIT_DATA);
93681+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
93682 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
93683 (mm->end_data - mm->start_data) > rlim)
93684 goto out;
93685@@ -942,6 +965,12 @@ static int
93686 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
93687 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93688 {
93689+
93690+#ifdef CONFIG_PAX_SEGMEXEC
93691+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
93692+ return 0;
93693+#endif
93694+
93695 if (is_mergeable_vma(vma, file, vm_flags) &&
93696 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93697 if (vma->vm_pgoff == vm_pgoff)
93698@@ -961,6 +990,12 @@ static int
93699 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93700 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93701 {
93702+
93703+#ifdef CONFIG_PAX_SEGMEXEC
93704+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
93705+ return 0;
93706+#endif
93707+
93708 if (is_mergeable_vma(vma, file, vm_flags) &&
93709 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93710 pgoff_t vm_pglen;
93711@@ -1003,13 +1038,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93712 struct vm_area_struct *vma_merge(struct mm_struct *mm,
93713 struct vm_area_struct *prev, unsigned long addr,
93714 unsigned long end, unsigned long vm_flags,
93715- struct anon_vma *anon_vma, struct file *file,
93716+ struct anon_vma *anon_vma, struct file *file,
93717 pgoff_t pgoff, struct mempolicy *policy)
93718 {
93719 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
93720 struct vm_area_struct *area, *next;
93721 int err;
93722
93723+#ifdef CONFIG_PAX_SEGMEXEC
93724+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
93725+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
93726+
93727+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
93728+#endif
93729+
93730 /*
93731 * We later require that vma->vm_flags == vm_flags,
93732 * so this tests vma->vm_flags & VM_SPECIAL, too.
93733@@ -1025,6 +1067,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93734 if (next && next->vm_end == end) /* cases 6, 7, 8 */
93735 next = next->vm_next;
93736
93737+#ifdef CONFIG_PAX_SEGMEXEC
93738+ if (prev)
93739+ prev_m = pax_find_mirror_vma(prev);
93740+ if (area)
93741+ area_m = pax_find_mirror_vma(area);
93742+ if (next)
93743+ next_m = pax_find_mirror_vma(next);
93744+#endif
93745+
93746 /*
93747 * Can it merge with the predecessor?
93748 */
93749@@ -1044,9 +1095,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93750 /* cases 1, 6 */
93751 err = vma_adjust(prev, prev->vm_start,
93752 next->vm_end, prev->vm_pgoff, NULL);
93753- } else /* cases 2, 5, 7 */
93754+
93755+#ifdef CONFIG_PAX_SEGMEXEC
93756+ if (!err && prev_m)
93757+ err = vma_adjust(prev_m, prev_m->vm_start,
93758+ next_m->vm_end, prev_m->vm_pgoff, NULL);
93759+#endif
93760+
93761+ } else { /* cases 2, 5, 7 */
93762 err = vma_adjust(prev, prev->vm_start,
93763 end, prev->vm_pgoff, NULL);
93764+
93765+#ifdef CONFIG_PAX_SEGMEXEC
93766+ if (!err && prev_m)
93767+ err = vma_adjust(prev_m, prev_m->vm_start,
93768+ end_m, prev_m->vm_pgoff, NULL);
93769+#endif
93770+
93771+ }
93772 if (err)
93773 return NULL;
93774 khugepaged_enter_vma_merge(prev);
93775@@ -1060,12 +1126,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93776 mpol_equal(policy, vma_policy(next)) &&
93777 can_vma_merge_before(next, vm_flags,
93778 anon_vma, file, pgoff+pglen)) {
93779- if (prev && addr < prev->vm_end) /* case 4 */
93780+ if (prev && addr < prev->vm_end) { /* case 4 */
93781 err = vma_adjust(prev, prev->vm_start,
93782 addr, prev->vm_pgoff, NULL);
93783- else /* cases 3, 8 */
93784+
93785+#ifdef CONFIG_PAX_SEGMEXEC
93786+ if (!err && prev_m)
93787+ err = vma_adjust(prev_m, prev_m->vm_start,
93788+ addr_m, prev_m->vm_pgoff, NULL);
93789+#endif
93790+
93791+ } else { /* cases 3, 8 */
93792 err = vma_adjust(area, addr, next->vm_end,
93793 next->vm_pgoff - pglen, NULL);
93794+
93795+#ifdef CONFIG_PAX_SEGMEXEC
93796+ if (!err && area_m)
93797+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
93798+ next_m->vm_pgoff - pglen, NULL);
93799+#endif
93800+
93801+ }
93802 if (err)
93803 return NULL;
93804 khugepaged_enter_vma_merge(area);
93805@@ -1174,8 +1255,10 @@ none:
93806 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93807 struct file *file, long pages)
93808 {
93809- const unsigned long stack_flags
93810- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
93811+
93812+#ifdef CONFIG_PAX_RANDMMAP
93813+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93814+#endif
93815
93816 mm->total_vm += pages;
93817
93818@@ -1183,7 +1266,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93819 mm->shared_vm += pages;
93820 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
93821 mm->exec_vm += pages;
93822- } else if (flags & stack_flags)
93823+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
93824 mm->stack_vm += pages;
93825 }
93826 #endif /* CONFIG_PROC_FS */
93827@@ -1213,6 +1296,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
93828 locked += mm->locked_vm;
93829 lock_limit = rlimit(RLIMIT_MEMLOCK);
93830 lock_limit >>= PAGE_SHIFT;
93831+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93832 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
93833 return -EAGAIN;
93834 }
93835@@ -1239,7 +1323,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93836 * (the exception is when the underlying filesystem is noexec
93837 * mounted, in which case we dont add PROT_EXEC.)
93838 */
93839- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93840+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93841 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
93842 prot |= PROT_EXEC;
93843
93844@@ -1265,7 +1349,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93845 /* Obtain the address to map to. we verify (or select) it and ensure
93846 * that it represents a valid section of the address space.
93847 */
93848- addr = get_unmapped_area(file, addr, len, pgoff, flags);
93849+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
93850 if (addr & ~PAGE_MASK)
93851 return addr;
93852
93853@@ -1276,6 +1360,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93854 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
93855 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
93856
93857+#ifdef CONFIG_PAX_MPROTECT
93858+ if (mm->pax_flags & MF_PAX_MPROTECT) {
93859+
93860+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
93861+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
93862+ mm->binfmt->handle_mmap)
93863+ mm->binfmt->handle_mmap(file);
93864+#endif
93865+
93866+#ifndef CONFIG_PAX_MPROTECT_COMPAT
93867+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
93868+ gr_log_rwxmmap(file);
93869+
93870+#ifdef CONFIG_PAX_EMUPLT
93871+ vm_flags &= ~VM_EXEC;
93872+#else
93873+ return -EPERM;
93874+#endif
93875+
93876+ }
93877+
93878+ if (!(vm_flags & VM_EXEC))
93879+ vm_flags &= ~VM_MAYEXEC;
93880+#else
93881+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93882+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93883+#endif
93884+ else
93885+ vm_flags &= ~VM_MAYWRITE;
93886+ }
93887+#endif
93888+
93889+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93890+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
93891+ vm_flags &= ~VM_PAGEEXEC;
93892+#endif
93893+
93894 if (flags & MAP_LOCKED)
93895 if (!can_do_mlock())
93896 return -EPERM;
93897@@ -1363,6 +1484,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
93898 vm_flags |= VM_NORESERVE;
93899 }
93900
93901+ if (!gr_acl_handle_mmap(file, prot))
93902+ return -EACCES;
93903+
93904 addr = mmap_region(file, addr, len, vm_flags, pgoff);
93905 if (!IS_ERR_VALUE(addr) &&
93906 ((vm_flags & VM_LOCKED) ||
93907@@ -1456,7 +1580,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
93908 vm_flags_t vm_flags = vma->vm_flags;
93909
93910 /* If it was private or non-writable, the write bit is already clear */
93911- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
93912+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
93913 return 0;
93914
93915 /* The backer wishes to know when pages are first written to? */
93916@@ -1502,7 +1626,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93917 struct rb_node **rb_link, *rb_parent;
93918 unsigned long charged = 0;
93919
93920+#ifdef CONFIG_PAX_SEGMEXEC
93921+ struct vm_area_struct *vma_m = NULL;
93922+#endif
93923+
93924+ /*
93925+ * mm->mmap_sem is required to protect against another thread
93926+ * changing the mappings in case we sleep.
93927+ */
93928+ verify_mm_writelocked(mm);
93929+
93930 /* Check against address space limit. */
93931+
93932+#ifdef CONFIG_PAX_RANDMMAP
93933+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93934+#endif
93935+
93936 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
93937 unsigned long nr_pages;
93938
93939@@ -1521,11 +1660,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
93940
93941 /* Clear old maps */
93942 error = -ENOMEM;
93943-munmap_back:
93944 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93945 if (do_munmap(mm, addr, len))
93946 return -ENOMEM;
93947- goto munmap_back;
93948+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93949 }
93950
93951 /*
93952@@ -1556,6 +1694,16 @@ munmap_back:
93953 goto unacct_error;
93954 }
93955
93956+#ifdef CONFIG_PAX_SEGMEXEC
93957+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
93958+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93959+ if (!vma_m) {
93960+ error = -ENOMEM;
93961+ goto free_vma;
93962+ }
93963+ }
93964+#endif
93965+
93966 vma->vm_mm = mm;
93967 vma->vm_start = addr;
93968 vma->vm_end = addr + len;
93969@@ -1575,6 +1723,13 @@ munmap_back:
93970 if (error)
93971 goto unmap_and_free_vma;
93972
93973+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93974+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
93975+ vma->vm_flags |= VM_PAGEEXEC;
93976+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93977+ }
93978+#endif
93979+
93980 /* Can addr have changed??
93981 *
93982 * Answer: Yes, several device drivers can do it in their
93983@@ -1608,6 +1763,12 @@ munmap_back:
93984 }
93985
93986 vma_link(mm, vma, prev, rb_link, rb_parent);
93987+
93988+#ifdef CONFIG_PAX_SEGMEXEC
93989+ if (vma_m)
93990+ BUG_ON(pax_mirror_vma(vma_m, vma));
93991+#endif
93992+
93993 /* Once vma denies write, undo our temporary denial count */
93994 if (vm_flags & VM_DENYWRITE)
93995 allow_write_access(file);
93996@@ -1616,6 +1777,7 @@ out:
93997 perf_event_mmap(vma);
93998
93999 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
94000+ track_exec_limit(mm, addr, addr + len, vm_flags);
94001 if (vm_flags & VM_LOCKED) {
94002 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
94003 vma == get_gate_vma(current->mm)))
94004@@ -1648,6 +1810,12 @@ unmap_and_free_vma:
94005 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
94006 charged = 0;
94007 free_vma:
94008+
94009+#ifdef CONFIG_PAX_SEGMEXEC
94010+ if (vma_m)
94011+ kmem_cache_free(vm_area_cachep, vma_m);
94012+#endif
94013+
94014 kmem_cache_free(vm_area_cachep, vma);
94015 unacct_error:
94016 if (charged)
94017@@ -1655,7 +1823,63 @@ unacct_error:
94018 return error;
94019 }
94020
94021-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94022+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
94023+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
94024+{
94025+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
94026+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
94027+
94028+ return 0;
94029+}
94030+#endif
94031+
94032+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
94033+{
94034+ if (!vma) {
94035+#ifdef CONFIG_STACK_GROWSUP
94036+ if (addr > sysctl_heap_stack_gap)
94037+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
94038+ else
94039+ vma = find_vma(current->mm, 0);
94040+ if (vma && (vma->vm_flags & VM_GROWSUP))
94041+ return false;
94042+#endif
94043+ return true;
94044+ }
94045+
94046+ if (addr + len > vma->vm_start)
94047+ return false;
94048+
94049+ if (vma->vm_flags & VM_GROWSDOWN)
94050+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
94051+#ifdef CONFIG_STACK_GROWSUP
94052+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
94053+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
94054+#endif
94055+ else if (offset)
94056+ return offset <= vma->vm_start - addr - len;
94057+
94058+ return true;
94059+}
94060+
94061+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
94062+{
94063+ if (vma->vm_start < len)
94064+ return -ENOMEM;
94065+
94066+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
94067+ if (offset <= vma->vm_start - len)
94068+ return vma->vm_start - len - offset;
94069+ else
94070+ return -ENOMEM;
94071+ }
94072+
94073+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
94074+ return vma->vm_start - len - sysctl_heap_stack_gap;
94075+ return -ENOMEM;
94076+}
94077+
94078+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94079 {
94080 /*
94081 * We implement the search by looking for an rbtree node that
94082@@ -1703,11 +1927,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94083 }
94084 }
94085
94086- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94087+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94088 check_current:
94089 /* Check if current node has a suitable gap */
94090 if (gap_start > high_limit)
94091 return -ENOMEM;
94092+
94093+ if (gap_end - gap_start > info->threadstack_offset)
94094+ gap_start += info->threadstack_offset;
94095+ else
94096+ gap_start = gap_end;
94097+
94098+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94099+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94100+ gap_start += sysctl_heap_stack_gap;
94101+ else
94102+ gap_start = gap_end;
94103+ }
94104+ if (vma->vm_flags & VM_GROWSDOWN) {
94105+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94106+ gap_end -= sysctl_heap_stack_gap;
94107+ else
94108+ gap_end = gap_start;
94109+ }
94110 if (gap_end >= low_limit && gap_end - gap_start >= length)
94111 goto found;
94112
94113@@ -1757,7 +1999,7 @@ found:
94114 return gap_start;
94115 }
94116
94117-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94118+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94119 {
94120 struct mm_struct *mm = current->mm;
94121 struct vm_area_struct *vma;
94122@@ -1811,6 +2053,24 @@ check_current:
94123 gap_end = vma->vm_start;
94124 if (gap_end < low_limit)
94125 return -ENOMEM;
94126+
94127+ if (gap_end - gap_start > info->threadstack_offset)
94128+ gap_end -= info->threadstack_offset;
94129+ else
94130+ gap_end = gap_start;
94131+
94132+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94133+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94134+ gap_start += sysctl_heap_stack_gap;
94135+ else
94136+ gap_start = gap_end;
94137+ }
94138+ if (vma->vm_flags & VM_GROWSDOWN) {
94139+ if (gap_end - gap_start > sysctl_heap_stack_gap)
94140+ gap_end -= sysctl_heap_stack_gap;
94141+ else
94142+ gap_end = gap_start;
94143+ }
94144 if (gap_start <= high_limit && gap_end - gap_start >= length)
94145 goto found;
94146
94147@@ -1874,6 +2134,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94148 struct mm_struct *mm = current->mm;
94149 struct vm_area_struct *vma;
94150 struct vm_unmapped_area_info info;
94151+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94152
94153 if (len > TASK_SIZE - mmap_min_addr)
94154 return -ENOMEM;
94155@@ -1881,11 +2142,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94156 if (flags & MAP_FIXED)
94157 return addr;
94158
94159+#ifdef CONFIG_PAX_RANDMMAP
94160+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94161+#endif
94162+
94163 if (addr) {
94164 addr = PAGE_ALIGN(addr);
94165 vma = find_vma(mm, addr);
94166 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94167- (!vma || addr + len <= vma->vm_start))
94168+ check_heap_stack_gap(vma, addr, len, offset))
94169 return addr;
94170 }
94171
94172@@ -1894,6 +2159,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94173 info.low_limit = mm->mmap_base;
94174 info.high_limit = TASK_SIZE;
94175 info.align_mask = 0;
94176+ info.threadstack_offset = offset;
94177 return vm_unmapped_area(&info);
94178 }
94179 #endif
94180@@ -1912,6 +2178,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94181 struct mm_struct *mm = current->mm;
94182 unsigned long addr = addr0;
94183 struct vm_unmapped_area_info info;
94184+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94185
94186 /* requested length too big for entire address space */
94187 if (len > TASK_SIZE - mmap_min_addr)
94188@@ -1920,12 +2187,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94189 if (flags & MAP_FIXED)
94190 return addr;
94191
94192+#ifdef CONFIG_PAX_RANDMMAP
94193+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94194+#endif
94195+
94196 /* requesting a specific address */
94197 if (addr) {
94198 addr = PAGE_ALIGN(addr);
94199 vma = find_vma(mm, addr);
94200 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94201- (!vma || addr + len <= vma->vm_start))
94202+ check_heap_stack_gap(vma, addr, len, offset))
94203 return addr;
94204 }
94205
94206@@ -1934,6 +2205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94207 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94208 info.high_limit = mm->mmap_base;
94209 info.align_mask = 0;
94210+ info.threadstack_offset = offset;
94211 addr = vm_unmapped_area(&info);
94212
94213 /*
94214@@ -1946,6 +2218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94215 VM_BUG_ON(addr != -ENOMEM);
94216 info.flags = 0;
94217 info.low_limit = TASK_UNMAPPED_BASE;
94218+
94219+#ifdef CONFIG_PAX_RANDMMAP
94220+ if (mm->pax_flags & MF_PAX_RANDMMAP)
94221+ info.low_limit += mm->delta_mmap;
94222+#endif
94223+
94224 info.high_limit = TASK_SIZE;
94225 addr = vm_unmapped_area(&info);
94226 }
94227@@ -2046,6 +2324,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94228 return vma;
94229 }
94230
94231+#ifdef CONFIG_PAX_SEGMEXEC
94232+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94233+{
94234+ struct vm_area_struct *vma_m;
94235+
94236+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94237+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94238+ BUG_ON(vma->vm_mirror);
94239+ return NULL;
94240+ }
94241+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94242+ vma_m = vma->vm_mirror;
94243+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94244+ BUG_ON(vma->vm_file != vma_m->vm_file);
94245+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94246+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94247+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94248+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94249+ return vma_m;
94250+}
94251+#endif
94252+
94253 /*
94254 * Verify that the stack growth is acceptable and
94255 * update accounting. This is shared with both the
94256@@ -2062,6 +2362,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94257 return -ENOMEM;
94258
94259 /* Stack limit test */
94260+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
94261 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94262 return -ENOMEM;
94263
94264@@ -2072,6 +2373,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94265 locked = mm->locked_vm + grow;
94266 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94267 limit >>= PAGE_SHIFT;
94268+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94269 if (locked > limit && !capable(CAP_IPC_LOCK))
94270 return -ENOMEM;
94271 }
94272@@ -2101,37 +2403,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94273 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
94274 * vma is the last one with address > vma->vm_end. Have to extend vma.
94275 */
94276+#ifndef CONFIG_IA64
94277+static
94278+#endif
94279 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94280 {
94281 int error;
94282+ bool locknext;
94283
94284 if (!(vma->vm_flags & VM_GROWSUP))
94285 return -EFAULT;
94286
94287+ /* Also guard against wrapping around to address 0. */
94288+ if (address < PAGE_ALIGN(address+1))
94289+ address = PAGE_ALIGN(address+1);
94290+ else
94291+ return -ENOMEM;
94292+
94293 /*
94294 * We must make sure the anon_vma is allocated
94295 * so that the anon_vma locking is not a noop.
94296 */
94297 if (unlikely(anon_vma_prepare(vma)))
94298 return -ENOMEM;
94299+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
94300+ if (locknext && anon_vma_prepare(vma->vm_next))
94301+ return -ENOMEM;
94302 vma_lock_anon_vma(vma);
94303+ if (locknext)
94304+ vma_lock_anon_vma(vma->vm_next);
94305
94306 /*
94307 * vma->vm_start/vm_end cannot change under us because the caller
94308 * is required to hold the mmap_sem in read mode. We need the
94309- * anon_vma lock to serialize against concurrent expand_stacks.
94310- * Also guard against wrapping around to address 0.
94311+ * anon_vma locks to serialize against concurrent expand_stacks
94312+ * and expand_upwards.
94313 */
94314- if (address < PAGE_ALIGN(address+4))
94315- address = PAGE_ALIGN(address+4);
94316- else {
94317- vma_unlock_anon_vma(vma);
94318- return -ENOMEM;
94319- }
94320 error = 0;
94321
94322 /* Somebody else might have raced and expanded it already */
94323- if (address > vma->vm_end) {
94324+ 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)
94325+ error = -ENOMEM;
94326+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
94327 unsigned long size, grow;
94328
94329 size = address - vma->vm_start;
94330@@ -2166,6 +2479,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94331 }
94332 }
94333 }
94334+ if (locknext)
94335+ vma_unlock_anon_vma(vma->vm_next);
94336 vma_unlock_anon_vma(vma);
94337 khugepaged_enter_vma_merge(vma);
94338 validate_mm(vma->vm_mm);
94339@@ -2180,6 +2495,8 @@ int expand_downwards(struct vm_area_struct *vma,
94340 unsigned long address)
94341 {
94342 int error;
94343+ bool lockprev = false;
94344+ struct vm_area_struct *prev;
94345
94346 /*
94347 * We must make sure the anon_vma is allocated
94348@@ -2193,6 +2510,15 @@ int expand_downwards(struct vm_area_struct *vma,
94349 if (error)
94350 return error;
94351
94352+ prev = vma->vm_prev;
94353+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
94354+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
94355+#endif
94356+ if (lockprev && anon_vma_prepare(prev))
94357+ return -ENOMEM;
94358+ if (lockprev)
94359+ vma_lock_anon_vma(prev);
94360+
94361 vma_lock_anon_vma(vma);
94362
94363 /*
94364@@ -2202,9 +2528,17 @@ int expand_downwards(struct vm_area_struct *vma,
94365 */
94366
94367 /* Somebody else might have raced and expanded it already */
94368- if (address < vma->vm_start) {
94369+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
94370+ error = -ENOMEM;
94371+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
94372 unsigned long size, grow;
94373
94374+#ifdef CONFIG_PAX_SEGMEXEC
94375+ struct vm_area_struct *vma_m;
94376+
94377+ vma_m = pax_find_mirror_vma(vma);
94378+#endif
94379+
94380 size = vma->vm_end - address;
94381 grow = (vma->vm_start - address) >> PAGE_SHIFT;
94382
94383@@ -2229,13 +2563,27 @@ int expand_downwards(struct vm_area_struct *vma,
94384 vma->vm_pgoff -= grow;
94385 anon_vma_interval_tree_post_update_vma(vma);
94386 vma_gap_update(vma);
94387+
94388+#ifdef CONFIG_PAX_SEGMEXEC
94389+ if (vma_m) {
94390+ anon_vma_interval_tree_pre_update_vma(vma_m);
94391+ vma_m->vm_start -= grow << PAGE_SHIFT;
94392+ vma_m->vm_pgoff -= grow;
94393+ anon_vma_interval_tree_post_update_vma(vma_m);
94394+ vma_gap_update(vma_m);
94395+ }
94396+#endif
94397+
94398 spin_unlock(&vma->vm_mm->page_table_lock);
94399
94400+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
94401 perf_event_mmap(vma);
94402 }
94403 }
94404 }
94405 vma_unlock_anon_vma(vma);
94406+ if (lockprev)
94407+ vma_unlock_anon_vma(prev);
94408 khugepaged_enter_vma_merge(vma);
94409 validate_mm(vma->vm_mm);
94410 return error;
94411@@ -2333,6 +2681,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
94412 do {
94413 long nrpages = vma_pages(vma);
94414
94415+#ifdef CONFIG_PAX_SEGMEXEC
94416+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
94417+ vma = remove_vma(vma);
94418+ continue;
94419+ }
94420+#endif
94421+
94422 if (vma->vm_flags & VM_ACCOUNT)
94423 nr_accounted += nrpages;
94424 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
94425@@ -2377,6 +2732,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
94426 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
94427 vma->vm_prev = NULL;
94428 do {
94429+
94430+#ifdef CONFIG_PAX_SEGMEXEC
94431+ if (vma->vm_mirror) {
94432+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
94433+ vma->vm_mirror->vm_mirror = NULL;
94434+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
94435+ vma->vm_mirror = NULL;
94436+ }
94437+#endif
94438+
94439 vma_rb_erase(vma, &mm->mm_rb);
94440 mm->map_count--;
94441 tail_vma = vma;
94442@@ -2404,14 +2769,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94443 struct vm_area_struct *new;
94444 int err = -ENOMEM;
94445
94446+#ifdef CONFIG_PAX_SEGMEXEC
94447+ struct vm_area_struct *vma_m, *new_m = NULL;
94448+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
94449+#endif
94450+
94451 if (is_vm_hugetlb_page(vma) && (addr &
94452 ~(huge_page_mask(hstate_vma(vma)))))
94453 return -EINVAL;
94454
94455+#ifdef CONFIG_PAX_SEGMEXEC
94456+ vma_m = pax_find_mirror_vma(vma);
94457+#endif
94458+
94459 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94460 if (!new)
94461 goto out_err;
94462
94463+#ifdef CONFIG_PAX_SEGMEXEC
94464+ if (vma_m) {
94465+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94466+ if (!new_m) {
94467+ kmem_cache_free(vm_area_cachep, new);
94468+ goto out_err;
94469+ }
94470+ }
94471+#endif
94472+
94473 /* most fields are the same, copy all, and then fixup */
94474 *new = *vma;
94475
94476@@ -2424,6 +2808,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94477 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94478 }
94479
94480+#ifdef CONFIG_PAX_SEGMEXEC
94481+ if (vma_m) {
94482+ *new_m = *vma_m;
94483+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
94484+ new_m->vm_mirror = new;
94485+ new->vm_mirror = new_m;
94486+
94487+ if (new_below)
94488+ new_m->vm_end = addr_m;
94489+ else {
94490+ new_m->vm_start = addr_m;
94491+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94492+ }
94493+ }
94494+#endif
94495+
94496 err = vma_dup_policy(vma, new);
94497 if (err)
94498 goto out_free_vma;
94499@@ -2443,6 +2843,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94500 else
94501 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94502
94503+#ifdef CONFIG_PAX_SEGMEXEC
94504+ if (!err && vma_m) {
94505+ struct mempolicy *pol = vma_policy(new);
94506+
94507+ if (anon_vma_clone(new_m, vma_m))
94508+ goto out_free_mpol;
94509+
94510+ mpol_get(pol);
94511+ set_vma_policy(new_m, pol);
94512+
94513+ if (new_m->vm_file)
94514+ get_file(new_m->vm_file);
94515+
94516+ if (new_m->vm_ops && new_m->vm_ops->open)
94517+ new_m->vm_ops->open(new_m);
94518+
94519+ if (new_below)
94520+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94521+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94522+ else
94523+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94524+
94525+ if (err) {
94526+ if (new_m->vm_ops && new_m->vm_ops->close)
94527+ new_m->vm_ops->close(new_m);
94528+ if (new_m->vm_file)
94529+ fput(new_m->vm_file);
94530+ mpol_put(pol);
94531+ }
94532+ }
94533+#endif
94534+
94535 /* Success. */
94536 if (!err)
94537 return 0;
94538@@ -2452,10 +2884,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94539 new->vm_ops->close(new);
94540 if (new->vm_file)
94541 fput(new->vm_file);
94542- unlink_anon_vmas(new);
94543 out_free_mpol:
94544 mpol_put(vma_policy(new));
94545 out_free_vma:
94546+
94547+#ifdef CONFIG_PAX_SEGMEXEC
94548+ if (new_m) {
94549+ unlink_anon_vmas(new_m);
94550+ kmem_cache_free(vm_area_cachep, new_m);
94551+ }
94552+#endif
94553+
94554+ unlink_anon_vmas(new);
94555 kmem_cache_free(vm_area_cachep, new);
94556 out_err:
94557 return err;
94558@@ -2468,6 +2908,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94559 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94560 unsigned long addr, int new_below)
94561 {
94562+
94563+#ifdef CONFIG_PAX_SEGMEXEC
94564+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94565+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
94566+ if (mm->map_count >= sysctl_max_map_count-1)
94567+ return -ENOMEM;
94568+ } else
94569+#endif
94570+
94571 if (mm->map_count >= sysctl_max_map_count)
94572 return -ENOMEM;
94573
94574@@ -2479,11 +2928,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94575 * work. This now handles partial unmappings.
94576 * Jeremy Fitzhardinge <jeremy@goop.org>
94577 */
94578+#ifdef CONFIG_PAX_SEGMEXEC
94579 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94580 {
94581+ int ret = __do_munmap(mm, start, len);
94582+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
94583+ return ret;
94584+
94585+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
94586+}
94587+
94588+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94589+#else
94590+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94591+#endif
94592+{
94593 unsigned long end;
94594 struct vm_area_struct *vma, *prev, *last;
94595
94596+ /*
94597+ * mm->mmap_sem is required to protect against another thread
94598+ * changing the mappings in case we sleep.
94599+ */
94600+ verify_mm_writelocked(mm);
94601+
94602 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
94603 return -EINVAL;
94604
94605@@ -2558,6 +3026,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94606 /* Fix up all other VM information */
94607 remove_vma_list(mm, vma);
94608
94609+ track_exec_limit(mm, start, end, 0UL);
94610+
94611 return 0;
94612 }
94613
94614@@ -2566,6 +3036,13 @@ int vm_munmap(unsigned long start, size_t len)
94615 int ret;
94616 struct mm_struct *mm = current->mm;
94617
94618+
94619+#ifdef CONFIG_PAX_SEGMEXEC
94620+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
94621+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
94622+ return -EINVAL;
94623+#endif
94624+
94625 down_write(&mm->mmap_sem);
94626 ret = do_munmap(mm, start, len);
94627 up_write(&mm->mmap_sem);
94628@@ -2579,16 +3056,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
94629 return vm_munmap(addr, len);
94630 }
94631
94632-static inline void verify_mm_writelocked(struct mm_struct *mm)
94633-{
94634-#ifdef CONFIG_DEBUG_VM
94635- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94636- WARN_ON(1);
94637- up_read(&mm->mmap_sem);
94638- }
94639-#endif
94640-}
94641-
94642 /*
94643 * this is really a simplified "do_mmap". it only handles
94644 * anonymous maps. eventually we may be able to do some
94645@@ -2602,6 +3069,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94646 struct rb_node ** rb_link, * rb_parent;
94647 pgoff_t pgoff = addr >> PAGE_SHIFT;
94648 int error;
94649+ unsigned long charged;
94650
94651 len = PAGE_ALIGN(len);
94652 if (!len)
94653@@ -2609,10 +3077,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94654
94655 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
94656
94657+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
94658+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
94659+ flags &= ~VM_EXEC;
94660+
94661+#ifdef CONFIG_PAX_MPROTECT
94662+ if (mm->pax_flags & MF_PAX_MPROTECT)
94663+ flags &= ~VM_MAYEXEC;
94664+#endif
94665+
94666+ }
94667+#endif
94668+
94669 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
94670 if (error & ~PAGE_MASK)
94671 return error;
94672
94673+ charged = len >> PAGE_SHIFT;
94674+
94675 error = mlock_future_check(mm, mm->def_flags, len);
94676 if (error)
94677 return error;
94678@@ -2626,21 +3108,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94679 /*
94680 * Clear old maps. this also does some error checking for us
94681 */
94682- munmap_back:
94683 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94684 if (do_munmap(mm, addr, len))
94685 return -ENOMEM;
94686- goto munmap_back;
94687+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94688 }
94689
94690 /* Check against address space limits *after* clearing old maps... */
94691- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
94692+ if (!may_expand_vm(mm, charged))
94693 return -ENOMEM;
94694
94695 if (mm->map_count > sysctl_max_map_count)
94696 return -ENOMEM;
94697
94698- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
94699+ if (security_vm_enough_memory_mm(mm, charged))
94700 return -ENOMEM;
94701
94702 /* Can we just expand an old private anonymous mapping? */
94703@@ -2654,7 +3135,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94704 */
94705 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94706 if (!vma) {
94707- vm_unacct_memory(len >> PAGE_SHIFT);
94708+ vm_unacct_memory(charged);
94709 return -ENOMEM;
94710 }
94711
94712@@ -2668,10 +3149,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94713 vma_link(mm, vma, prev, rb_link, rb_parent);
94714 out:
94715 perf_event_mmap(vma);
94716- mm->total_vm += len >> PAGE_SHIFT;
94717+ mm->total_vm += charged;
94718 if (flags & VM_LOCKED)
94719- mm->locked_vm += (len >> PAGE_SHIFT);
94720+ mm->locked_vm += charged;
94721 vma->vm_flags |= VM_SOFTDIRTY;
94722+ track_exec_limit(mm, addr, addr + len, flags);
94723 return addr;
94724 }
94725
94726@@ -2733,6 +3215,7 @@ void exit_mmap(struct mm_struct *mm)
94727 while (vma) {
94728 if (vma->vm_flags & VM_ACCOUNT)
94729 nr_accounted += vma_pages(vma);
94730+ vma->vm_mirror = NULL;
94731 vma = remove_vma(vma);
94732 }
94733 vm_unacct_memory(nr_accounted);
94734@@ -2750,6 +3233,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94735 struct vm_area_struct *prev;
94736 struct rb_node **rb_link, *rb_parent;
94737
94738+#ifdef CONFIG_PAX_SEGMEXEC
94739+ struct vm_area_struct *vma_m = NULL;
94740+#endif
94741+
94742+ if (security_mmap_addr(vma->vm_start))
94743+ return -EPERM;
94744+
94745 /*
94746 * The vm_pgoff of a purely anonymous vma should be irrelevant
94747 * until its first write fault, when page's anon_vma and index
94748@@ -2773,7 +3263,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94749 security_vm_enough_memory_mm(mm, vma_pages(vma)))
94750 return -ENOMEM;
94751
94752+#ifdef CONFIG_PAX_SEGMEXEC
94753+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
94754+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94755+ if (!vma_m)
94756+ return -ENOMEM;
94757+ }
94758+#endif
94759+
94760 vma_link(mm, vma, prev, rb_link, rb_parent);
94761+
94762+#ifdef CONFIG_PAX_SEGMEXEC
94763+ if (vma_m)
94764+ BUG_ON(pax_mirror_vma(vma_m, vma));
94765+#endif
94766+
94767 return 0;
94768 }
94769
94770@@ -2792,6 +3296,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94771 struct rb_node **rb_link, *rb_parent;
94772 bool faulted_in_anon_vma = true;
94773
94774+ BUG_ON(vma->vm_mirror);
94775+
94776 /*
94777 * If anonymous vma has not yet been faulted, update new pgoff
94778 * to match new location, to increase its chance of merging.
94779@@ -2856,6 +3362,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94780 return NULL;
94781 }
94782
94783+#ifdef CONFIG_PAX_SEGMEXEC
94784+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
94785+{
94786+ struct vm_area_struct *prev_m;
94787+ struct rb_node **rb_link_m, *rb_parent_m;
94788+ struct mempolicy *pol_m;
94789+
94790+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
94791+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
94792+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
94793+ *vma_m = *vma;
94794+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
94795+ if (anon_vma_clone(vma_m, vma))
94796+ return -ENOMEM;
94797+ pol_m = vma_policy(vma_m);
94798+ mpol_get(pol_m);
94799+ set_vma_policy(vma_m, pol_m);
94800+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
94801+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
94802+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
94803+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
94804+ if (vma_m->vm_file)
94805+ get_file(vma_m->vm_file);
94806+ if (vma_m->vm_ops && vma_m->vm_ops->open)
94807+ vma_m->vm_ops->open(vma_m);
94808+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
94809+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
94810+ vma_m->vm_mirror = vma;
94811+ vma->vm_mirror = vma_m;
94812+ return 0;
94813+}
94814+#endif
94815+
94816 /*
94817 * Return true if the calling process may expand its vm space by the passed
94818 * number of pages
94819@@ -2867,6 +3406,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
94820
94821 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
94822
94823+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
94824 if (cur + npages > lim)
94825 return 0;
94826 return 1;
94827@@ -2937,6 +3477,22 @@ struct vm_area_struct *_install_special_mapping(struct mm_struct *mm,
94828 vma->vm_start = addr;
94829 vma->vm_end = addr + len;
94830
94831+#ifdef CONFIG_PAX_MPROTECT
94832+ if (mm->pax_flags & MF_PAX_MPROTECT) {
94833+#ifndef CONFIG_PAX_MPROTECT_COMPAT
94834+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
94835+ return ERR_PTR(-EPERM);
94836+ if (!(vm_flags & VM_EXEC))
94837+ vm_flags &= ~VM_MAYEXEC;
94838+#else
94839+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94840+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94841+#endif
94842+ else
94843+ vm_flags &= ~VM_MAYWRITE;
94844+ }
94845+#endif
94846+
94847 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
94848 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94849
94850diff --git a/mm/mprotect.c b/mm/mprotect.c
94851index c43d557..0b7ccd2 100644
94852--- a/mm/mprotect.c
94853+++ b/mm/mprotect.c
94854@@ -24,10 +24,18 @@
94855 #include <linux/migrate.h>
94856 #include <linux/perf_event.h>
94857 #include <linux/ksm.h>
94858+#include <linux/sched/sysctl.h>
94859+
94860+#ifdef CONFIG_PAX_MPROTECT
94861+#include <linux/elf.h>
94862+#include <linux/binfmts.h>
94863+#endif
94864+
94865 #include <asm/uaccess.h>
94866 #include <asm/pgtable.h>
94867 #include <asm/cacheflush.h>
94868 #include <asm/tlbflush.h>
94869+#include <asm/mmu_context.h>
94870
94871 #ifndef pgprot_modify
94872 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
94873@@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
94874 return pages;
94875 }
94876
94877+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94878+/* called while holding the mmap semaphor for writing except stack expansion */
94879+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
94880+{
94881+ unsigned long oldlimit, newlimit = 0UL;
94882+
94883+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
94884+ return;
94885+
94886+ spin_lock(&mm->page_table_lock);
94887+ oldlimit = mm->context.user_cs_limit;
94888+ if ((prot & VM_EXEC) && oldlimit < end)
94889+ /* USER_CS limit moved up */
94890+ newlimit = end;
94891+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
94892+ /* USER_CS limit moved down */
94893+ newlimit = start;
94894+
94895+ if (newlimit) {
94896+ mm->context.user_cs_limit = newlimit;
94897+
94898+#ifdef CONFIG_SMP
94899+ wmb();
94900+ cpus_clear(mm->context.cpu_user_cs_mask);
94901+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
94902+#endif
94903+
94904+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
94905+ }
94906+ spin_unlock(&mm->page_table_lock);
94907+ if (newlimit == end) {
94908+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
94909+
94910+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
94911+ if (is_vm_hugetlb_page(vma))
94912+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
94913+ else
94914+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
94915+ }
94916+}
94917+#endif
94918+
94919 int
94920 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94921 unsigned long start, unsigned long end, unsigned long newflags)
94922@@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94923 int error;
94924 int dirty_accountable = 0;
94925
94926+#ifdef CONFIG_PAX_SEGMEXEC
94927+ struct vm_area_struct *vma_m = NULL;
94928+ unsigned long start_m, end_m;
94929+
94930+ start_m = start + SEGMEXEC_TASK_SIZE;
94931+ end_m = end + SEGMEXEC_TASK_SIZE;
94932+#endif
94933+
94934 if (newflags == oldflags) {
94935 *pprev = vma;
94936 return 0;
94937 }
94938
94939+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
94940+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
94941+
94942+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
94943+ return -ENOMEM;
94944+
94945+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
94946+ return -ENOMEM;
94947+ }
94948+
94949 /*
94950 * If we make a private mapping writable we increase our commit;
94951 * but (without finer accounting) cannot reduce our commit if we
94952@@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94953 }
94954 }
94955
94956+#ifdef CONFIG_PAX_SEGMEXEC
94957+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
94958+ if (start != vma->vm_start) {
94959+ error = split_vma(mm, vma, start, 1);
94960+ if (error)
94961+ goto fail;
94962+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
94963+ *pprev = (*pprev)->vm_next;
94964+ }
94965+
94966+ if (end != vma->vm_end) {
94967+ error = split_vma(mm, vma, end, 0);
94968+ if (error)
94969+ goto fail;
94970+ }
94971+
94972+ if (pax_find_mirror_vma(vma)) {
94973+ error = __do_munmap(mm, start_m, end_m - start_m);
94974+ if (error)
94975+ goto fail;
94976+ } else {
94977+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94978+ if (!vma_m) {
94979+ error = -ENOMEM;
94980+ goto fail;
94981+ }
94982+ vma->vm_flags = newflags;
94983+ error = pax_mirror_vma(vma_m, vma);
94984+ if (error) {
94985+ vma->vm_flags = oldflags;
94986+ goto fail;
94987+ }
94988+ }
94989+ }
94990+#endif
94991+
94992 /*
94993 * First try to merge with previous and/or next vma.
94994 */
94995@@ -319,9 +423,21 @@ success:
94996 * vm_flags and vm_page_prot are protected by the mmap_sem
94997 * held in write mode.
94998 */
94999+
95000+#ifdef CONFIG_PAX_SEGMEXEC
95001+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
95002+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
95003+#endif
95004+
95005 vma->vm_flags = newflags;
95006+
95007+#ifdef CONFIG_PAX_MPROTECT
95008+ if (mm->binfmt && mm->binfmt->handle_mprotect)
95009+ mm->binfmt->handle_mprotect(vma, newflags);
95010+#endif
95011+
95012 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
95013- vm_get_page_prot(newflags));
95014+ vm_get_page_prot(vma->vm_flags));
95015
95016 if (vma_wants_writenotify(vma)) {
95017 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
95018@@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95019 end = start + len;
95020 if (end <= start)
95021 return -ENOMEM;
95022+
95023+#ifdef CONFIG_PAX_SEGMEXEC
95024+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95025+ if (end > SEGMEXEC_TASK_SIZE)
95026+ return -EINVAL;
95027+ } else
95028+#endif
95029+
95030+ if (end > TASK_SIZE)
95031+ return -EINVAL;
95032+
95033 if (!arch_validate_prot(prot))
95034 return -EINVAL;
95035
95036@@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95037 /*
95038 * Does the application expect PROT_READ to imply PROT_EXEC:
95039 */
95040- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
95041+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
95042 prot |= PROT_EXEC;
95043
95044 vm_flags = calc_vm_prot_bits(prot);
95045@@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95046 if (start > vma->vm_start)
95047 prev = vma;
95048
95049+#ifdef CONFIG_PAX_MPROTECT
95050+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
95051+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
95052+#endif
95053+
95054 for (nstart = start ; ; ) {
95055 unsigned long newflags;
95056
95057@@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95058
95059 /* newflags >> 4 shift VM_MAY% in place of VM_% */
95060 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
95061+ if (prot & (PROT_WRITE | PROT_EXEC))
95062+ gr_log_rwxmprotect(vma);
95063+
95064+ error = -EACCES;
95065+ goto out;
95066+ }
95067+
95068+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95069 error = -EACCES;
95070 goto out;
95071 }
95072@@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95073 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95074 if (error)
95075 goto out;
95076+
95077+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
95078+
95079 nstart = tmp;
95080
95081 if (nstart < prev->vm_end)
95082diff --git a/mm/mremap.c b/mm/mremap.c
95083index 05f1180..c3cde48 100644
95084--- a/mm/mremap.c
95085+++ b/mm/mremap.c
95086@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95087 continue;
95088 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95089 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95090+
95091+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95092+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95093+ pte = pte_exprotect(pte);
95094+#endif
95095+
95096 pte = move_soft_dirty_pte(pte);
95097 set_pte_at(mm, new_addr, new_pte, pte);
95098 }
95099@@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95100 if (is_vm_hugetlb_page(vma))
95101 goto Einval;
95102
95103+#ifdef CONFIG_PAX_SEGMEXEC
95104+ if (pax_find_mirror_vma(vma))
95105+ goto Einval;
95106+#endif
95107+
95108 /* We can't remap across vm area boundaries */
95109 if (old_len > vma->vm_end - addr)
95110 goto Efault;
95111@@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95112 unsigned long ret = -EINVAL;
95113 unsigned long charged = 0;
95114 unsigned long map_flags;
95115+ unsigned long pax_task_size = TASK_SIZE;
95116
95117 if (new_addr & ~PAGE_MASK)
95118 goto out;
95119
95120- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95121+#ifdef CONFIG_PAX_SEGMEXEC
95122+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95123+ pax_task_size = SEGMEXEC_TASK_SIZE;
95124+#endif
95125+
95126+ pax_task_size -= PAGE_SIZE;
95127+
95128+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95129 goto out;
95130
95131 /* Check if the location we're moving into overlaps the
95132 * old location at all, and fail if it does.
95133 */
95134- if ((new_addr <= addr) && (new_addr+new_len) > addr)
95135- goto out;
95136-
95137- if ((addr <= new_addr) && (addr+old_len) > new_addr)
95138+ if (addr + old_len > new_addr && new_addr + new_len > addr)
95139 goto out;
95140
95141 ret = do_munmap(mm, new_addr, new_len);
95142@@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95143 unsigned long ret = -EINVAL;
95144 unsigned long charged = 0;
95145 bool locked = false;
95146+ unsigned long pax_task_size = TASK_SIZE;
95147
95148 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95149 return ret;
95150@@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95151 if (!new_len)
95152 return ret;
95153
95154+#ifdef CONFIG_PAX_SEGMEXEC
95155+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
95156+ pax_task_size = SEGMEXEC_TASK_SIZE;
95157+#endif
95158+
95159+ pax_task_size -= PAGE_SIZE;
95160+
95161+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95162+ old_len > pax_task_size || addr > pax_task_size-old_len)
95163+ return ret;
95164+
95165 down_write(&current->mm->mmap_sem);
95166
95167 if (flags & MREMAP_FIXED) {
95168@@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95169 new_addr = addr;
95170 }
95171 ret = addr;
95172+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95173 goto out;
95174 }
95175 }
95176@@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95177 goto out;
95178 }
95179
95180+ map_flags = vma->vm_flags;
95181 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95182+ if (!(ret & ~PAGE_MASK)) {
95183+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95184+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95185+ }
95186 }
95187 out:
95188 if (ret & ~PAGE_MASK)
95189diff --git a/mm/nommu.c b/mm/nommu.c
95190index 431fd7c..8674512 100644
95191--- a/mm/nommu.c
95192+++ b/mm/nommu.c
95193@@ -67,7 +67,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95194 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95195 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95196 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95197-int heap_stack_gap = 0;
95198
95199 atomic_long_t mmap_pages_allocated;
95200
95201@@ -854,15 +853,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95202 EXPORT_SYMBOL(find_vma);
95203
95204 /*
95205- * find a VMA
95206- * - we don't extend stack VMAs under NOMMU conditions
95207- */
95208-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95209-{
95210- return find_vma(mm, addr);
95211-}
95212-
95213-/*
95214 * expand a stack to a given address
95215 * - not supported under NOMMU conditions
95216 */
95217@@ -1569,6 +1559,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95218
95219 /* most fields are the same, copy all, and then fixup */
95220 *new = *vma;
95221+ INIT_LIST_HEAD(&new->anon_vma_chain);
95222 *region = *vma->vm_region;
95223 new->vm_region = region;
95224
95225@@ -2004,8 +1995,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95226 }
95227 EXPORT_SYMBOL(generic_file_remap_pages);
95228
95229-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95230- unsigned long addr, void *buf, int len, int write)
95231+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95232+ unsigned long addr, void *buf, size_t len, int write)
95233 {
95234 struct vm_area_struct *vma;
95235
95236@@ -2046,8 +2037,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95237 *
95238 * The caller must hold a reference on @mm.
95239 */
95240-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95241- void *buf, int len, int write)
95242+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95243+ void *buf, size_t len, int write)
95244 {
95245 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95246 }
95247@@ -2056,7 +2047,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95248 * Access another process' address space.
95249 * - source/target buffer must be kernel space
95250 */
95251-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95252+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95253 {
95254 struct mm_struct *mm;
95255
95256diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95257index 154af21..86e447f 100644
95258--- a/mm/page-writeback.c
95259+++ b/mm/page-writeback.c
95260@@ -685,7 +685,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
95261 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95262 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95263 */
95264-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95265+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95266 unsigned long thresh,
95267 unsigned long bg_thresh,
95268 unsigned long dirty,
95269diff --git a/mm/page_alloc.c b/mm/page_alloc.c
95270index d64f5f9..9005ab5 100644
95271--- a/mm/page_alloc.c
95272+++ b/mm/page_alloc.c
95273@@ -61,6 +61,7 @@
95274 #include <linux/page-debug-flags.h>
95275 #include <linux/hugetlb.h>
95276 #include <linux/sched/rt.h>
95277+#include <linux/random.h>
95278
95279 #include <asm/sections.h>
95280 #include <asm/tlbflush.h>
95281@@ -356,7 +357,7 @@ out:
95282 * This usage means that zero-order pages may not be compound.
95283 */
95284
95285-static void free_compound_page(struct page *page)
95286+void free_compound_page(struct page *page)
95287 {
95288 __free_pages_ok(page, compound_order(page));
95289 }
95290@@ -730,6 +731,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95291 int i;
95292 int bad = 0;
95293
95294+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95295+ unsigned long index = 1UL << order;
95296+#endif
95297+
95298 trace_mm_page_free(page, order);
95299 kmemcheck_free_shadow(page, order);
95300
95301@@ -746,6 +751,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95302 debug_check_no_obj_freed(page_address(page),
95303 PAGE_SIZE << order);
95304 }
95305+
95306+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95307+ for (; index; --index)
95308+ sanitize_highpage(page + index - 1);
95309+#endif
95310+
95311 arch_free_page(page, order);
95312 kernel_map_pages(page, 1 << order, 0);
95313
95314@@ -768,6 +779,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
95315 local_irq_restore(flags);
95316 }
95317
95318+#ifdef CONFIG_PAX_LATENT_ENTROPY
95319+bool __meminitdata extra_latent_entropy;
95320+
95321+static int __init setup_pax_extra_latent_entropy(char *str)
95322+{
95323+ extra_latent_entropy = true;
95324+ return 0;
95325+}
95326+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
95327+
95328+volatile u64 latent_entropy __latent_entropy;
95329+EXPORT_SYMBOL(latent_entropy);
95330+#endif
95331+
95332 void __init __free_pages_bootmem(struct page *page, unsigned int order)
95333 {
95334 unsigned int nr_pages = 1 << order;
95335@@ -783,6 +808,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
95336 __ClearPageReserved(p);
95337 set_page_count(p, 0);
95338
95339+#ifdef CONFIG_PAX_LATENT_ENTROPY
95340+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
95341+ u64 hash = 0;
95342+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
95343+ const u64 *data = lowmem_page_address(page);
95344+
95345+ for (index = 0; index < end; index++)
95346+ hash ^= hash + data[index];
95347+ latent_entropy ^= hash;
95348+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
95349+ }
95350+#endif
95351+
95352 page_zone(page)->managed_pages += nr_pages;
95353 set_page_refcounted(page);
95354 __free_pages(page, order);
95355@@ -911,8 +949,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
95356 arch_alloc_page(page, order);
95357 kernel_map_pages(page, 1 << order, 1);
95358
95359+#ifndef CONFIG_PAX_MEMORY_SANITIZE
95360 if (gfp_flags & __GFP_ZERO)
95361 prep_zero_page(page, order, gfp_flags);
95362+#endif
95363
95364 if (order && (gfp_flags & __GFP_COMP))
95365 prep_compound_page(page, order);
95366@@ -2415,7 +2455,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
95367 continue;
95368 mod_zone_page_state(zone, NR_ALLOC_BATCH,
95369 high_wmark_pages(zone) - low_wmark_pages(zone) -
95370- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
95371+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
95372 }
95373 }
95374
95375diff --git a/mm/page_io.c b/mm/page_io.c
95376index 7c59ef6..1358905 100644
95377--- a/mm/page_io.c
95378+++ b/mm/page_io.c
95379@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
95380 struct file *swap_file = sis->swap_file;
95381 struct address_space *mapping = swap_file->f_mapping;
95382 struct iovec iov = {
95383- .iov_base = kmap(page),
95384+ .iov_base = (void __force_user *)kmap(page),
95385 .iov_len = PAGE_SIZE,
95386 };
95387
95388diff --git a/mm/percpu.c b/mm/percpu.c
95389index 2ddf9a9..f8fc075 100644
95390--- a/mm/percpu.c
95391+++ b/mm/percpu.c
95392@@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
95393 static unsigned int pcpu_high_unit_cpu __read_mostly;
95394
95395 /* the address of the first chunk which starts with the kernel static area */
95396-void *pcpu_base_addr __read_mostly;
95397+void *pcpu_base_addr __read_only;
95398 EXPORT_SYMBOL_GPL(pcpu_base_addr);
95399
95400 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
95401diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
95402index 8505c92..946bfc9 100644
95403--- a/mm/process_vm_access.c
95404+++ b/mm/process_vm_access.c
95405@@ -13,6 +13,7 @@
95406 #include <linux/uio.h>
95407 #include <linux/sched.h>
95408 #include <linux/highmem.h>
95409+#include <linux/security.h>
95410 #include <linux/ptrace.h>
95411 #include <linux/slab.h>
95412 #include <linux/syscalls.h>
95413@@ -161,19 +162,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95414 ssize_t iov_len;
95415 size_t total_len = iov_iter_count(iter);
95416
95417+ return -ENOSYS; // PaX: until properly audited
95418+
95419 /*
95420 * Work out how many pages of struct pages we're going to need
95421 * when eventually calling get_user_pages
95422 */
95423 for (i = 0; i < riovcnt; i++) {
95424 iov_len = rvec[i].iov_len;
95425- if (iov_len > 0) {
95426- nr_pages_iov = ((unsigned long)rvec[i].iov_base
95427- + iov_len)
95428- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
95429- / PAGE_SIZE + 1;
95430- nr_pages = max(nr_pages, nr_pages_iov);
95431- }
95432+ if (iov_len <= 0)
95433+ continue;
95434+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
95435+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
95436+ nr_pages = max(nr_pages, nr_pages_iov);
95437 }
95438
95439 if (nr_pages == 0)
95440@@ -201,6 +202,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95441 goto free_proc_pages;
95442 }
95443
95444+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
95445+ rc = -EPERM;
95446+ goto put_task_struct;
95447+ }
95448+
95449 mm = mm_access(task, PTRACE_MODE_ATTACH);
95450 if (!mm || IS_ERR(mm)) {
95451 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
95452diff --git a/mm/rmap.c b/mm/rmap.c
95453index 14d1e28..3777962 100644
95454--- a/mm/rmap.c
95455+++ b/mm/rmap.c
95456@@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95457 struct anon_vma *anon_vma = vma->anon_vma;
95458 struct anon_vma_chain *avc;
95459
95460+#ifdef CONFIG_PAX_SEGMEXEC
95461+ struct anon_vma_chain *avc_m = NULL;
95462+#endif
95463+
95464 might_sleep();
95465 if (unlikely(!anon_vma)) {
95466 struct mm_struct *mm = vma->vm_mm;
95467@@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95468 if (!avc)
95469 goto out_enomem;
95470
95471+#ifdef CONFIG_PAX_SEGMEXEC
95472+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
95473+ if (!avc_m)
95474+ goto out_enomem_free_avc;
95475+#endif
95476+
95477 anon_vma = find_mergeable_anon_vma(vma);
95478 allocated = NULL;
95479 if (!anon_vma) {
95480@@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95481 /* page_table_lock to protect against threads */
95482 spin_lock(&mm->page_table_lock);
95483 if (likely(!vma->anon_vma)) {
95484+
95485+#ifdef CONFIG_PAX_SEGMEXEC
95486+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95487+
95488+ if (vma_m) {
95489+ BUG_ON(vma_m->anon_vma);
95490+ vma_m->anon_vma = anon_vma;
95491+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
95492+ avc_m = NULL;
95493+ }
95494+#endif
95495+
95496 vma->anon_vma = anon_vma;
95497 anon_vma_chain_link(vma, avc, anon_vma);
95498 allocated = NULL;
95499@@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95500
95501 if (unlikely(allocated))
95502 put_anon_vma(allocated);
95503+
95504+#ifdef CONFIG_PAX_SEGMEXEC
95505+ if (unlikely(avc_m))
95506+ anon_vma_chain_free(avc_m);
95507+#endif
95508+
95509 if (unlikely(avc))
95510 anon_vma_chain_free(avc);
95511 }
95512 return 0;
95513
95514 out_enomem_free_avc:
95515+
95516+#ifdef CONFIG_PAX_SEGMEXEC
95517+ if (avc_m)
95518+ anon_vma_chain_free(avc_m);
95519+#endif
95520+
95521 anon_vma_chain_free(avc);
95522 out_enomem:
95523 return -ENOMEM;
95524@@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
95525 * Attach the anon_vmas from src to dst.
95526 * Returns 0 on success, -ENOMEM on failure.
95527 */
95528-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95529+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
95530 {
95531 struct anon_vma_chain *avc, *pavc;
95532 struct anon_vma *root = NULL;
95533@@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95534 * the corresponding VMA in the parent process is attached to.
95535 * Returns 0 on success, non-zero on failure.
95536 */
95537-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
95538+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
95539 {
95540 struct anon_vma_chain *avc;
95541 struct anon_vma *anon_vma;
95542@@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
95543 void __init anon_vma_init(void)
95544 {
95545 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
95546- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
95547- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
95548+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
95549+ anon_vma_ctor);
95550+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
95551+ SLAB_PANIC|SLAB_NO_SANITIZE);
95552 }
95553
95554 /*
95555diff --git a/mm/shmem.c b/mm/shmem.c
95556index a2801ba..b8651e6 100644
95557--- a/mm/shmem.c
95558+++ b/mm/shmem.c
95559@@ -33,7 +33,7 @@
95560 #include <linux/swap.h>
95561 #include <linux/aio.h>
95562
95563-static struct vfsmount *shm_mnt;
95564+struct vfsmount *shm_mnt;
95565
95566 #ifdef CONFIG_SHMEM
95567 /*
95568@@ -77,14 +77,15 @@ static struct vfsmount *shm_mnt;
95569 #define BOGO_DIRENT_SIZE 20
95570
95571 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
95572-#define SHORT_SYMLINK_LEN 128
95573+#define SHORT_SYMLINK_LEN 64
95574
95575 /*
95576- * shmem_fallocate and shmem_writepage communicate via inode->i_private
95577- * (with i_mutex making sure that it has only one user at a time):
95578- * we would prefer not to enlarge the shmem inode just for that.
95579+ * shmem_fallocate communicates with shmem_fault or shmem_writepage via
95580+ * inode->i_private (with i_mutex making sure that it has only one user at
95581+ * a time): we would prefer not to enlarge the shmem inode just for that.
95582 */
95583 struct shmem_falloc {
95584+ int mode; /* FALLOC_FL mode currently operating */
95585 pgoff_t start; /* start of range currently being fallocated */
95586 pgoff_t next; /* the next page offset to be fallocated */
95587 pgoff_t nr_falloced; /* how many new pages have been fallocated */
95588@@ -759,6 +760,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
95589 spin_lock(&inode->i_lock);
95590 shmem_falloc = inode->i_private;
95591 if (shmem_falloc &&
95592+ !shmem_falloc->mode &&
95593 index >= shmem_falloc->start &&
95594 index < shmem_falloc->next)
95595 shmem_falloc->nr_unswapped++;
95596@@ -1233,6 +1235,43 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
95597 int error;
95598 int ret = VM_FAULT_LOCKED;
95599
95600+ /*
95601+ * Trinity finds that probing a hole which tmpfs is punching can
95602+ * prevent the hole-punch from ever completing: which in turn
95603+ * locks writers out with its hold on i_mutex. So refrain from
95604+ * faulting pages into the hole while it's being punched, and
95605+ * wait on i_mutex to be released if vmf->flags permits,
95606+ */
95607+ if (unlikely(inode->i_private)) {
95608+ struct shmem_falloc *shmem_falloc;
95609+ spin_lock(&inode->i_lock);
95610+ shmem_falloc = inode->i_private;
95611+ if (!shmem_falloc ||
95612+ shmem_falloc->mode != FALLOC_FL_PUNCH_HOLE ||
95613+ vmf->pgoff < shmem_falloc->start ||
95614+ vmf->pgoff >= shmem_falloc->next)
95615+ shmem_falloc = NULL;
95616+ spin_unlock(&inode->i_lock);
95617+ /*
95618+ * i_lock has protected us from taking shmem_falloc seriously
95619+ * once return from shmem_fallocate() went back up that stack.
95620+ * i_lock does not serialize with i_mutex at all, but it does
95621+ * not matter if sometimes we wait unnecessarily, or sometimes
95622+ * miss out on waiting: we just need to make those cases rare.
95623+ */
95624+ if (shmem_falloc) {
95625+ if ((vmf->flags & FAULT_FLAG_ALLOW_RETRY) &&
95626+ !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
95627+ up_read(&vma->vm_mm->mmap_sem);
95628+ mutex_lock(&inode->i_mutex);
95629+ mutex_unlock(&inode->i_mutex);
95630+ return VM_FAULT_RETRY;
95631+ }
95632+ /* cond_resched? Leave that to GUP or return to user */
95633+ return VM_FAULT_NOPAGE;
95634+ }
95635+ }
95636+
95637 error = shmem_getpage(inode, vmf->pgoff, &vmf->page, SGP_CACHE, &ret);
95638 if (error)
95639 return ((error == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS);
95640@@ -1733,18 +1772,26 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset,
95641
95642 mutex_lock(&inode->i_mutex);
95643
95644+ shmem_falloc.mode = mode & ~FALLOC_FL_KEEP_SIZE;
95645+
95646 if (mode & FALLOC_FL_PUNCH_HOLE) {
95647 struct address_space *mapping = file->f_mapping;
95648 loff_t unmap_start = round_up(offset, PAGE_SIZE);
95649 loff_t unmap_end = round_down(offset + len, PAGE_SIZE) - 1;
95650
95651+ shmem_falloc.start = unmap_start >> PAGE_SHIFT;
95652+ shmem_falloc.next = (unmap_end + 1) >> PAGE_SHIFT;
95653+ spin_lock(&inode->i_lock);
95654+ inode->i_private = &shmem_falloc;
95655+ spin_unlock(&inode->i_lock);
95656+
95657 if ((u64)unmap_end > (u64)unmap_start)
95658 unmap_mapping_range(mapping, unmap_start,
95659 1 + unmap_end - unmap_start, 0);
95660 shmem_truncate_range(inode, offset, offset + len - 1);
95661 /* No need to unmap again: hole-punching leaves COWed pages */
95662 error = 0;
95663- goto out;
95664+ goto undone;
95665 }
95666
95667 /* We need to check rlimit even when FALLOC_FL_KEEP_SIZE */
95668@@ -2138,6 +2185,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
95669 static int shmem_xattr_validate(const char *name)
95670 {
95671 struct { const char *prefix; size_t len; } arr[] = {
95672+
95673+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95674+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
95675+#endif
95676+
95677 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
95678 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
95679 };
95680@@ -2193,6 +2245,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
95681 if (err)
95682 return err;
95683
95684+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95685+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
95686+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
95687+ return -EOPNOTSUPP;
95688+ if (size > 8)
95689+ return -EINVAL;
95690+ }
95691+#endif
95692+
95693 return simple_xattr_set(&info->xattrs, name, value, size, flags);
95694 }
95695
95696@@ -2505,8 +2566,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
95697 int err = -ENOMEM;
95698
95699 /* Round up to L1_CACHE_BYTES to resist false sharing */
95700- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
95701- L1_CACHE_BYTES), GFP_KERNEL);
95702+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
95703 if (!sbinfo)
95704 return -ENOMEM;
95705
95706diff --git a/mm/slab.c b/mm/slab.c
95707index 9432556..e0dc685 100644
95708--- a/mm/slab.c
95709+++ b/mm/slab.c
95710@@ -311,10 +311,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95711 if ((x)->max_freeable < i) \
95712 (x)->max_freeable = i; \
95713 } while (0)
95714-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
95715-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
95716-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
95717-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
95718+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
95719+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
95720+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
95721+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
95722+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
95723+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
95724 #else
95725 #define STATS_INC_ACTIVE(x) do { } while (0)
95726 #define STATS_DEC_ACTIVE(x) do { } while (0)
95727@@ -331,6 +333,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95728 #define STATS_INC_ALLOCMISS(x) do { } while (0)
95729 #define STATS_INC_FREEHIT(x) do { } while (0)
95730 #define STATS_INC_FREEMISS(x) do { } while (0)
95731+#define STATS_INC_SANITIZED(x) do { } while (0)
95732+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
95733 #endif
95734
95735 #if DEBUG
95736@@ -447,7 +451,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
95737 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
95738 */
95739 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
95740- const struct page *page, void *obj)
95741+ const struct page *page, const void *obj)
95742 {
95743 u32 offset = (obj - page->s_mem);
95744 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
95745@@ -1558,12 +1562,12 @@ void __init kmem_cache_init(void)
95746 */
95747
95748 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
95749- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
95750+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95751
95752 if (INDEX_AC != INDEX_NODE)
95753 kmalloc_caches[INDEX_NODE] =
95754 create_kmalloc_cache("kmalloc-node",
95755- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
95756+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95757
95758 slab_early_init = 0;
95759
95760@@ -3525,6 +3529,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
95761 struct array_cache *ac = cpu_cache_get(cachep);
95762
95763 check_irq_off();
95764+
95765+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95766+ if (pax_sanitize_slab) {
95767+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
95768+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
95769+
95770+ if (cachep->ctor)
95771+ cachep->ctor(objp);
95772+
95773+ STATS_INC_SANITIZED(cachep);
95774+ } else
95775+ STATS_INC_NOT_SANITIZED(cachep);
95776+ }
95777+#endif
95778+
95779 kmemleak_free_recursive(objp, cachep->flags);
95780 objp = cache_free_debugcheck(cachep, objp, caller);
95781
95782@@ -3748,6 +3767,7 @@ void kfree(const void *objp)
95783
95784 if (unlikely(ZERO_OR_NULL_PTR(objp)))
95785 return;
95786+ VM_BUG_ON(!virt_addr_valid(objp));
95787 local_irq_save(flags);
95788 kfree_debugcheck(objp);
95789 c = virt_to_cache(objp);
95790@@ -4189,14 +4209,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
95791 }
95792 /* cpu stats */
95793 {
95794- unsigned long allochit = atomic_read(&cachep->allochit);
95795- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
95796- unsigned long freehit = atomic_read(&cachep->freehit);
95797- unsigned long freemiss = atomic_read(&cachep->freemiss);
95798+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
95799+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
95800+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
95801+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
95802
95803 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
95804 allochit, allocmiss, freehit, freemiss);
95805 }
95806+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95807+ {
95808+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
95809+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
95810+
95811+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
95812+ }
95813+#endif
95814 #endif
95815 }
95816
95817@@ -4417,13 +4445,69 @@ static const struct file_operations proc_slabstats_operations = {
95818 static int __init slab_proc_init(void)
95819 {
95820 #ifdef CONFIG_DEBUG_SLAB_LEAK
95821- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
95822+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
95823 #endif
95824 return 0;
95825 }
95826 module_init(slab_proc_init);
95827 #endif
95828
95829+bool is_usercopy_object(const void *ptr)
95830+{
95831+ struct page *page;
95832+ struct kmem_cache *cachep;
95833+
95834+ if (ZERO_OR_NULL_PTR(ptr))
95835+ return false;
95836+
95837+ if (!slab_is_available())
95838+ return false;
95839+
95840+ if (!virt_addr_valid(ptr))
95841+ return false;
95842+
95843+ page = virt_to_head_page(ptr);
95844+
95845+ if (!PageSlab(page))
95846+ return false;
95847+
95848+ cachep = page->slab_cache;
95849+ return cachep->flags & SLAB_USERCOPY;
95850+}
95851+
95852+#ifdef CONFIG_PAX_USERCOPY
95853+const char *check_heap_object(const void *ptr, unsigned long n)
95854+{
95855+ struct page *page;
95856+ struct kmem_cache *cachep;
95857+ unsigned int objnr;
95858+ unsigned long offset;
95859+
95860+ if (ZERO_OR_NULL_PTR(ptr))
95861+ return "<null>";
95862+
95863+ if (!virt_addr_valid(ptr))
95864+ return NULL;
95865+
95866+ page = virt_to_head_page(ptr);
95867+
95868+ if (!PageSlab(page))
95869+ return NULL;
95870+
95871+ cachep = page->slab_cache;
95872+ if (!(cachep->flags & SLAB_USERCOPY))
95873+ return cachep->name;
95874+
95875+ objnr = obj_to_index(cachep, page, ptr);
95876+ BUG_ON(objnr >= cachep->num);
95877+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
95878+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
95879+ return NULL;
95880+
95881+ return cachep->name;
95882+}
95883+#endif
95884+
95885 /**
95886 * ksize - get the actual amount of memory allocated for a given object
95887 * @objp: Pointer to the object
95888diff --git a/mm/slab.h b/mm/slab.h
95889index 6bd4c35..97565a1 100644
95890--- a/mm/slab.h
95891+++ b/mm/slab.h
95892@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
95893 /* The slab cache that manages slab cache information */
95894 extern struct kmem_cache *kmem_cache;
95895
95896+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95897+#ifdef CONFIG_X86_64
95898+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
95899+#else
95900+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
95901+#endif
95902+extern bool pax_sanitize_slab;
95903+#endif
95904+
95905 unsigned long calculate_alignment(unsigned long flags,
95906 unsigned long align, unsigned long size);
95907
95908@@ -67,7 +76,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
95909
95910 /* Legal flag mask for kmem_cache_create(), for various configurations */
95911 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
95912- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
95913+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
95914+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
95915
95916 #if defined(CONFIG_DEBUG_SLAB)
95917 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
95918@@ -245,6 +255,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
95919 return s;
95920
95921 page = virt_to_head_page(x);
95922+
95923+ BUG_ON(!PageSlab(page));
95924+
95925 cachep = page->slab_cache;
95926 if (slab_equal_or_root(cachep, s))
95927 return cachep;
95928diff --git a/mm/slab_common.c b/mm/slab_common.c
95929index 102cc6f..c7aab3d 100644
95930--- a/mm/slab_common.c
95931+++ b/mm/slab_common.c
95932@@ -23,11 +23,22 @@
95933
95934 #include "slab.h"
95935
95936-enum slab_state slab_state;
95937+enum slab_state slab_state __read_only;
95938 LIST_HEAD(slab_caches);
95939 DEFINE_MUTEX(slab_mutex);
95940 struct kmem_cache *kmem_cache;
95941
95942+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95943+bool pax_sanitize_slab __read_only = true;
95944+static int __init pax_sanitize_slab_setup(char *str)
95945+{
95946+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
95947+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
95948+ return 1;
95949+}
95950+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
95951+#endif
95952+
95953 #ifdef CONFIG_DEBUG_VM
95954 static int kmem_cache_sanity_check(const char *name, size_t size)
95955 {
95956@@ -158,7 +169,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
95957 if (err)
95958 goto out_free_cache;
95959
95960- s->refcount = 1;
95961+ atomic_set(&s->refcount, 1);
95962 list_add(&s->list, &slab_caches);
95963 memcg_register_cache(s);
95964 out:
95965@@ -334,8 +345,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
95966 get_online_cpus();
95967 mutex_lock(&slab_mutex);
95968
95969- s->refcount--;
95970- if (s->refcount)
95971+ if (!atomic_dec_and_test(&s->refcount))
95972 goto out_unlock;
95973
95974 if (kmem_cache_destroy_memcg_children(s) != 0)
95975@@ -358,7 +368,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
95976 rcu_barrier();
95977
95978 memcg_free_cache_params(s);
95979-#ifdef SLAB_SUPPORTS_SYSFS
95980+#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95981 sysfs_slab_remove(s);
95982 #else
95983 slab_kmem_cache_release(s);
95984@@ -393,7 +403,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
95985 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
95986 name, size, err);
95987
95988- s->refcount = -1; /* Exempt from merging for now */
95989+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
95990 }
95991
95992 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95993@@ -406,7 +416,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
95994
95995 create_boot_cache(s, name, size, flags);
95996 list_add(&s->list, &slab_caches);
95997- s->refcount = 1;
95998+ atomic_set(&s->refcount, 1);
95999 return s;
96000 }
96001
96002@@ -418,6 +428,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
96003 EXPORT_SYMBOL(kmalloc_dma_caches);
96004 #endif
96005
96006+#ifdef CONFIG_PAX_USERCOPY_SLABS
96007+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
96008+EXPORT_SYMBOL(kmalloc_usercopy_caches);
96009+#endif
96010+
96011 /*
96012 * Conversion table for small slabs sizes / 8 to the index in the
96013 * kmalloc array. This is necessary for slabs < 192 since we have non power
96014@@ -482,6 +497,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
96015 return kmalloc_dma_caches[index];
96016
96017 #endif
96018+
96019+#ifdef CONFIG_PAX_USERCOPY_SLABS
96020+ if (unlikely((flags & GFP_USERCOPY)))
96021+ return kmalloc_usercopy_caches[index];
96022+
96023+#endif
96024+
96025 return kmalloc_caches[index];
96026 }
96027
96028@@ -538,7 +560,7 @@ void __init create_kmalloc_caches(unsigned long flags)
96029 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
96030 if (!kmalloc_caches[i]) {
96031 kmalloc_caches[i] = create_kmalloc_cache(NULL,
96032- 1 << i, flags);
96033+ 1 << i, SLAB_USERCOPY | flags);
96034 }
96035
96036 /*
96037@@ -547,10 +569,10 @@ void __init create_kmalloc_caches(unsigned long flags)
96038 * earlier power of two caches
96039 */
96040 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
96041- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
96042+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
96043
96044 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
96045- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
96046+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
96047 }
96048
96049 /* Kmalloc array is now usable */
96050@@ -583,6 +605,23 @@ void __init create_kmalloc_caches(unsigned long flags)
96051 }
96052 }
96053 #endif
96054+
96055+#ifdef CONFIG_PAX_USERCOPY_SLABS
96056+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
96057+ struct kmem_cache *s = kmalloc_caches[i];
96058+
96059+ if (s) {
96060+ int size = kmalloc_size(i);
96061+ char *n = kasprintf(GFP_NOWAIT,
96062+ "usercopy-kmalloc-%d", size);
96063+
96064+ BUG_ON(!n);
96065+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
96066+ size, SLAB_USERCOPY | flags);
96067+ }
96068+ }
96069+#endif
96070+
96071 }
96072 #endif /* !CONFIG_SLOB */
96073
96074@@ -623,6 +662,9 @@ void print_slabinfo_header(struct seq_file *m)
96075 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
96076 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
96077 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
96078+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96079+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
96080+#endif
96081 #endif
96082 seq_putc(m, '\n');
96083 }
96084diff --git a/mm/slob.c b/mm/slob.c
96085index 730cad4..8cfd442 100644
96086--- a/mm/slob.c
96087+++ b/mm/slob.c
96088@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
96089 /*
96090 * Return the size of a slob block.
96091 */
96092-static slobidx_t slob_units(slob_t *s)
96093+static slobidx_t slob_units(const slob_t *s)
96094 {
96095 if (s->units > 0)
96096 return s->units;
96097@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
96098 /*
96099 * Return the next free slob block pointer after this one.
96100 */
96101-static slob_t *slob_next(slob_t *s)
96102+static slob_t *slob_next(const slob_t *s)
96103 {
96104 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
96105 slobidx_t next;
96106@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
96107 /*
96108 * Returns true if s is the last free block in its page.
96109 */
96110-static int slob_last(slob_t *s)
96111+static int slob_last(const slob_t *s)
96112 {
96113 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
96114 }
96115
96116-static void *slob_new_pages(gfp_t gfp, int order, int node)
96117+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
96118 {
96119- void *page;
96120+ struct page *page;
96121
96122 #ifdef CONFIG_NUMA
96123 if (node != NUMA_NO_NODE)
96124@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96125 if (!page)
96126 return NULL;
96127
96128- return page_address(page);
96129+ __SetPageSlab(page);
96130+ return page;
96131 }
96132
96133-static void slob_free_pages(void *b, int order)
96134+static void slob_free_pages(struct page *sp, int order)
96135 {
96136 if (current->reclaim_state)
96137 current->reclaim_state->reclaimed_slab += 1 << order;
96138- free_pages((unsigned long)b, order);
96139+ __ClearPageSlab(sp);
96140+ page_mapcount_reset(sp);
96141+ sp->private = 0;
96142+ __free_pages(sp, order);
96143 }
96144
96145 /*
96146@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96147
96148 /* Not enough space: must allocate a new page */
96149 if (!b) {
96150- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96151- if (!b)
96152+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96153+ if (!sp)
96154 return NULL;
96155- sp = virt_to_page(b);
96156- __SetPageSlab(sp);
96157+ b = page_address(sp);
96158
96159 spin_lock_irqsave(&slob_lock, flags);
96160 sp->units = SLOB_UNITS(PAGE_SIZE);
96161 sp->freelist = b;
96162+ sp->private = 0;
96163 INIT_LIST_HEAD(&sp->lru);
96164 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96165 set_slob_page_free(sp, slob_list);
96166@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96167 if (slob_page_free(sp))
96168 clear_slob_page_free(sp);
96169 spin_unlock_irqrestore(&slob_lock, flags);
96170- __ClearPageSlab(sp);
96171- page_mapcount_reset(sp);
96172- slob_free_pages(b, 0);
96173+ slob_free_pages(sp, 0);
96174 return;
96175 }
96176
96177+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96178+ if (pax_sanitize_slab)
96179+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96180+#endif
96181+
96182 if (!slob_page_free(sp)) {
96183 /* This slob page is about to become partially free. Easy! */
96184 sp->units = units;
96185@@ -424,11 +431,10 @@ out:
96186 */
96187
96188 static __always_inline void *
96189-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96190+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96191 {
96192- unsigned int *m;
96193- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96194- void *ret;
96195+ slob_t *m;
96196+ void *ret = NULL;
96197
96198 gfp &= gfp_allowed_mask;
96199
96200@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96201
96202 if (!m)
96203 return NULL;
96204- *m = size;
96205+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96206+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96207+ m[0].units = size;
96208+ m[1].units = align;
96209 ret = (void *)m + align;
96210
96211 trace_kmalloc_node(caller, ret,
96212 size, size + align, gfp, node);
96213 } else {
96214 unsigned int order = get_order(size);
96215+ struct page *page;
96216
96217 if (likely(order))
96218 gfp |= __GFP_COMP;
96219- ret = slob_new_pages(gfp, order, node);
96220+ page = slob_new_pages(gfp, order, node);
96221+ if (page) {
96222+ ret = page_address(page);
96223+ page->private = size;
96224+ }
96225
96226 trace_kmalloc_node(caller, ret,
96227 size, PAGE_SIZE << order, gfp, node);
96228 }
96229
96230- kmemleak_alloc(ret, size, 1, gfp);
96231+ return ret;
96232+}
96233+
96234+static __always_inline void *
96235+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96236+{
96237+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96238+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96239+
96240+ if (!ZERO_OR_NULL_PTR(ret))
96241+ kmemleak_alloc(ret, size, 1, gfp);
96242 return ret;
96243 }
96244
96245@@ -493,34 +517,112 @@ void kfree(const void *block)
96246 return;
96247 kmemleak_free(block);
96248
96249+ VM_BUG_ON(!virt_addr_valid(block));
96250 sp = virt_to_page(block);
96251- if (PageSlab(sp)) {
96252+ VM_BUG_ON(!PageSlab(sp));
96253+ if (!sp->private) {
96254 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96255- unsigned int *m = (unsigned int *)(block - align);
96256- slob_free(m, *m + align);
96257- } else
96258+ slob_t *m = (slob_t *)(block - align);
96259+ slob_free(m, m[0].units + align);
96260+ } else {
96261+ __ClearPageSlab(sp);
96262+ page_mapcount_reset(sp);
96263+ sp->private = 0;
96264 __free_pages(sp, compound_order(sp));
96265+ }
96266 }
96267 EXPORT_SYMBOL(kfree);
96268
96269+bool is_usercopy_object(const void *ptr)
96270+{
96271+ if (!slab_is_available())
96272+ return false;
96273+
96274+ // PAX: TODO
96275+
96276+ return false;
96277+}
96278+
96279+#ifdef CONFIG_PAX_USERCOPY
96280+const char *check_heap_object(const void *ptr, unsigned long n)
96281+{
96282+ struct page *page;
96283+ const slob_t *free;
96284+ const void *base;
96285+ unsigned long flags;
96286+
96287+ if (ZERO_OR_NULL_PTR(ptr))
96288+ return "<null>";
96289+
96290+ if (!virt_addr_valid(ptr))
96291+ return NULL;
96292+
96293+ page = virt_to_head_page(ptr);
96294+ if (!PageSlab(page))
96295+ return NULL;
96296+
96297+ if (page->private) {
96298+ base = page;
96299+ if (base <= ptr && n <= page->private - (ptr - base))
96300+ return NULL;
96301+ return "<slob>";
96302+ }
96303+
96304+ /* some tricky double walking to find the chunk */
96305+ spin_lock_irqsave(&slob_lock, flags);
96306+ base = (void *)((unsigned long)ptr & PAGE_MASK);
96307+ free = page->freelist;
96308+
96309+ while (!slob_last(free) && (void *)free <= ptr) {
96310+ base = free + slob_units(free);
96311+ free = slob_next(free);
96312+ }
96313+
96314+ while (base < (void *)free) {
96315+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96316+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
96317+ int offset;
96318+
96319+ if (ptr < base + align)
96320+ break;
96321+
96322+ offset = ptr - base - align;
96323+ if (offset >= m) {
96324+ base += size;
96325+ continue;
96326+ }
96327+
96328+ if (n > m - offset)
96329+ break;
96330+
96331+ spin_unlock_irqrestore(&slob_lock, flags);
96332+ return NULL;
96333+ }
96334+
96335+ spin_unlock_irqrestore(&slob_lock, flags);
96336+ return "<slob>";
96337+}
96338+#endif
96339+
96340 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96341 size_t ksize(const void *block)
96342 {
96343 struct page *sp;
96344 int align;
96345- unsigned int *m;
96346+ slob_t *m;
96347
96348 BUG_ON(!block);
96349 if (unlikely(block == ZERO_SIZE_PTR))
96350 return 0;
96351
96352 sp = virt_to_page(block);
96353- if (unlikely(!PageSlab(sp)))
96354- return PAGE_SIZE << compound_order(sp);
96355+ VM_BUG_ON(!PageSlab(sp));
96356+ if (sp->private)
96357+ return sp->private;
96358
96359 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96360- m = (unsigned int *)(block - align);
96361- return SLOB_UNITS(*m) * SLOB_UNIT;
96362+ m = (slob_t *)(block - align);
96363+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
96364 }
96365 EXPORT_SYMBOL(ksize);
96366
96367@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
96368
96369 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
96370 {
96371- void *b;
96372+ void *b = NULL;
96373
96374 flags &= gfp_allowed_mask;
96375
96376 lockdep_trace_alloc(flags);
96377
96378+#ifdef CONFIG_PAX_USERCOPY_SLABS
96379+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
96380+#else
96381 if (c->size < PAGE_SIZE) {
96382 b = slob_alloc(c->size, flags, c->align, node);
96383 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96384 SLOB_UNITS(c->size) * SLOB_UNIT,
96385 flags, node);
96386 } else {
96387- b = slob_new_pages(flags, get_order(c->size), node);
96388+ struct page *sp;
96389+
96390+ sp = slob_new_pages(flags, get_order(c->size), node);
96391+ if (sp) {
96392+ b = page_address(sp);
96393+ sp->private = c->size;
96394+ }
96395 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96396 PAGE_SIZE << get_order(c->size),
96397 flags, node);
96398 }
96399+#endif
96400
96401 if (b && c->ctor)
96402 c->ctor(b);
96403@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
96404
96405 static void __kmem_cache_free(void *b, int size)
96406 {
96407- if (size < PAGE_SIZE)
96408+ struct page *sp;
96409+
96410+ sp = virt_to_page(b);
96411+ BUG_ON(!PageSlab(sp));
96412+ if (!sp->private)
96413 slob_free(b, size);
96414 else
96415- slob_free_pages(b, get_order(size));
96416+ slob_free_pages(sp, get_order(size));
96417 }
96418
96419 static void kmem_rcu_free(struct rcu_head *head)
96420@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
96421
96422 void kmem_cache_free(struct kmem_cache *c, void *b)
96423 {
96424+ int size = c->size;
96425+
96426+#ifdef CONFIG_PAX_USERCOPY_SLABS
96427+ if (size + c->align < PAGE_SIZE) {
96428+ size += c->align;
96429+ b -= c->align;
96430+ }
96431+#endif
96432+
96433 kmemleak_free_recursive(b, c->flags);
96434 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
96435 struct slob_rcu *slob_rcu;
96436- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
96437- slob_rcu->size = c->size;
96438+ slob_rcu = b + (size - sizeof(struct slob_rcu));
96439+ slob_rcu->size = size;
96440 call_rcu(&slob_rcu->head, kmem_rcu_free);
96441 } else {
96442- __kmem_cache_free(b, c->size);
96443+ __kmem_cache_free(b, size);
96444 }
96445
96446+#ifdef CONFIG_PAX_USERCOPY_SLABS
96447+ trace_kfree(_RET_IP_, b);
96448+#else
96449 trace_kmem_cache_free(_RET_IP_, b);
96450+#endif
96451+
96452 }
96453 EXPORT_SYMBOL(kmem_cache_free);
96454
96455diff --git a/mm/slub.c b/mm/slub.c
96456index 2b1ce69..4a2193f 100644
96457--- a/mm/slub.c
96458+++ b/mm/slub.c
96459@@ -207,7 +207,7 @@ struct track {
96460
96461 enum track_item { TRACK_ALLOC, TRACK_FREE };
96462
96463-#ifdef CONFIG_SYSFS
96464+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96465 static int sysfs_slab_add(struct kmem_cache *);
96466 static int sysfs_slab_alias(struct kmem_cache *, const char *);
96467 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
96468@@ -546,7 +546,7 @@ static void print_track(const char *s, struct track *t)
96469 if (!t->addr)
96470 return;
96471
96472- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
96473+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
96474 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
96475 #ifdef CONFIG_STACKTRACE
96476 {
96477@@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
96478
96479 slab_free_hook(s, x);
96480
96481+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96482+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
96483+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
96484+ if (s->ctor)
96485+ s->ctor(x);
96486+ }
96487+#endif
96488+
96489 redo:
96490 /*
96491 * Determine the currently cpus per cpu slab.
96492@@ -2733,7 +2741,7 @@ static int slub_min_objects;
96493 * Merge control. If this is set then no merging of slab caches will occur.
96494 * (Could be removed. This was introduced to pacify the merge skeptics.)
96495 */
96496-static int slub_nomerge;
96497+static int slub_nomerge = 1;
96498
96499 /*
96500 * Calculate the order of allocation given an slab object size.
96501@@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
96502 s->inuse = size;
96503
96504 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
96505+#ifdef CONFIG_PAX_MEMORY_SANITIZE
96506+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
96507+#endif
96508 s->ctor)) {
96509 /*
96510 * Relocate free pointer after the object if it is not
96511@@ -3343,6 +3354,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
96512 EXPORT_SYMBOL(__kmalloc_node);
96513 #endif
96514
96515+bool is_usercopy_object(const void *ptr)
96516+{
96517+ struct page *page;
96518+ struct kmem_cache *s;
96519+
96520+ if (ZERO_OR_NULL_PTR(ptr))
96521+ return false;
96522+
96523+ if (!slab_is_available())
96524+ return false;
96525+
96526+ if (!virt_addr_valid(ptr))
96527+ return false;
96528+
96529+ page = virt_to_head_page(ptr);
96530+
96531+ if (!PageSlab(page))
96532+ return false;
96533+
96534+ s = page->slab_cache;
96535+ return s->flags & SLAB_USERCOPY;
96536+}
96537+
96538+#ifdef CONFIG_PAX_USERCOPY
96539+const char *check_heap_object(const void *ptr, unsigned long n)
96540+{
96541+ struct page *page;
96542+ struct kmem_cache *s;
96543+ unsigned long offset;
96544+
96545+ if (ZERO_OR_NULL_PTR(ptr))
96546+ return "<null>";
96547+
96548+ if (!virt_addr_valid(ptr))
96549+ return NULL;
96550+
96551+ page = virt_to_head_page(ptr);
96552+
96553+ if (!PageSlab(page))
96554+ return NULL;
96555+
96556+ s = page->slab_cache;
96557+ if (!(s->flags & SLAB_USERCOPY))
96558+ return s->name;
96559+
96560+ offset = (ptr - page_address(page)) % s->size;
96561+ if (offset <= s->object_size && n <= s->object_size - offset)
96562+ return NULL;
96563+
96564+ return s->name;
96565+}
96566+#endif
96567+
96568 size_t ksize(const void *object)
96569 {
96570 struct page *page;
96571@@ -3371,6 +3435,7 @@ void kfree(const void *x)
96572 if (unlikely(ZERO_OR_NULL_PTR(x)))
96573 return;
96574
96575+ VM_BUG_ON(!virt_addr_valid(x));
96576 page = virt_to_head_page(x);
96577 if (unlikely(!PageSlab(page))) {
96578 BUG_ON(!PageCompound(page));
96579@@ -3679,7 +3744,7 @@ static int slab_unmergeable(struct kmem_cache *s)
96580 /*
96581 * We may have set a slab to be unmergeable during bootstrap.
96582 */
96583- if (s->refcount < 0)
96584+ if (atomic_read(&s->refcount) < 0)
96585 return 1;
96586
96587 return 0;
96588@@ -3736,7 +3801,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96589 int i;
96590 struct kmem_cache *c;
96591
96592- s->refcount++;
96593+ atomic_inc(&s->refcount);
96594
96595 /*
96596 * Adjust the object sizes so that we clear
96597@@ -3755,7 +3820,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96598 }
96599
96600 if (sysfs_slab_alias(s, name)) {
96601- s->refcount--;
96602+ atomic_dec(&s->refcount);
96603 s = NULL;
96604 }
96605 }
96606@@ -3872,7 +3937,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
96607 }
96608 #endif
96609
96610-#ifdef CONFIG_SYSFS
96611+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96612 static int count_inuse(struct page *page)
96613 {
96614 return page->inuse;
96615@@ -4156,7 +4221,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
96616 len += sprintf(buf + len, "%7ld ", l->count);
96617
96618 if (l->addr)
96619+#ifdef CONFIG_GRKERNSEC_HIDESYM
96620+ len += sprintf(buf + len, "%pS", NULL);
96621+#else
96622 len += sprintf(buf + len, "%pS", (void *)l->addr);
96623+#endif
96624 else
96625 len += sprintf(buf + len, "<not-available>");
96626
96627@@ -4261,12 +4330,12 @@ static void resiliency_test(void)
96628 validate_slab_cache(kmalloc_caches[9]);
96629 }
96630 #else
96631-#ifdef CONFIG_SYSFS
96632+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96633 static void resiliency_test(void) {};
96634 #endif
96635 #endif
96636
96637-#ifdef CONFIG_SYSFS
96638+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96639 enum slab_stat_type {
96640 SL_ALL, /* All slabs */
96641 SL_PARTIAL, /* Only partially allocated slabs */
96642@@ -4506,13 +4575,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
96643 {
96644 if (!s->ctor)
96645 return 0;
96646+#ifdef CONFIG_GRKERNSEC_HIDESYM
96647+ return sprintf(buf, "%pS\n", NULL);
96648+#else
96649 return sprintf(buf, "%pS\n", s->ctor);
96650+#endif
96651 }
96652 SLAB_ATTR_RO(ctor);
96653
96654 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
96655 {
96656- return sprintf(buf, "%d\n", s->refcount - 1);
96657+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
96658 }
96659 SLAB_ATTR_RO(aliases);
96660
96661@@ -4600,6 +4673,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
96662 SLAB_ATTR_RO(cache_dma);
96663 #endif
96664
96665+#ifdef CONFIG_PAX_USERCOPY_SLABS
96666+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
96667+{
96668+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
96669+}
96670+SLAB_ATTR_RO(usercopy);
96671+#endif
96672+
96673 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
96674 {
96675 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
96676@@ -4934,6 +5015,9 @@ static struct attribute *slab_attrs[] = {
96677 #ifdef CONFIG_ZONE_DMA
96678 &cache_dma_attr.attr,
96679 #endif
96680+#ifdef CONFIG_PAX_USERCOPY_SLABS
96681+ &usercopy_attr.attr,
96682+#endif
96683 #ifdef CONFIG_NUMA
96684 &remote_node_defrag_ratio_attr.attr,
96685 #endif
96686@@ -5184,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
96687 return name;
96688 }
96689
96690+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96691 static int sysfs_slab_add(struct kmem_cache *s)
96692 {
96693 int err;
96694@@ -5257,6 +5342,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
96695 kobject_del(&s->kobj);
96696 kobject_put(&s->kobj);
96697 }
96698+#endif
96699
96700 /*
96701 * Need to buffer aliases during bootup until sysfs becomes
96702@@ -5270,6 +5356,7 @@ struct saved_alias {
96703
96704 static struct saved_alias *alias_list;
96705
96706+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96707 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96708 {
96709 struct saved_alias *al;
96710@@ -5292,6 +5379,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96711 alias_list = al;
96712 return 0;
96713 }
96714+#endif
96715
96716 static int __init slab_sysfs_init(void)
96717 {
96718diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
96719index 4cba9c2..b4f9fcc 100644
96720--- a/mm/sparse-vmemmap.c
96721+++ b/mm/sparse-vmemmap.c
96722@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
96723 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96724 if (!p)
96725 return NULL;
96726- pud_populate(&init_mm, pud, p);
96727+ pud_populate_kernel(&init_mm, pud, p);
96728 }
96729 return pud;
96730 }
96731@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
96732 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96733 if (!p)
96734 return NULL;
96735- pgd_populate(&init_mm, pgd, p);
96736+ pgd_populate_kernel(&init_mm, pgd, p);
96737 }
96738 return pgd;
96739 }
96740diff --git a/mm/sparse.c b/mm/sparse.c
96741index d1b48b6..6e8590e 100644
96742--- a/mm/sparse.c
96743+++ b/mm/sparse.c
96744@@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
96745
96746 for (i = 0; i < PAGES_PER_SECTION; i++) {
96747 if (PageHWPoison(&memmap[i])) {
96748- atomic_long_sub(1, &num_poisoned_pages);
96749+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
96750 ClearPageHWPoison(&memmap[i]);
96751 }
96752 }
96753diff --git a/mm/swap.c b/mm/swap.c
96754index 9ce43ba..43bdc4c 100644
96755--- a/mm/swap.c
96756+++ b/mm/swap.c
96757@@ -31,6 +31,7 @@
96758 #include <linux/memcontrol.h>
96759 #include <linux/gfp.h>
96760 #include <linux/uio.h>
96761+#include <linux/hugetlb.h>
96762
96763 #include "internal.h"
96764
96765@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
96766
96767 __page_cache_release(page);
96768 dtor = get_compound_page_dtor(page);
96769+ if (!PageHuge(page))
96770+ BUG_ON(dtor != free_compound_page);
96771 (*dtor)(page);
96772 }
96773
96774diff --git a/mm/swapfile.c b/mm/swapfile.c
96775index 4a7f7e6..22cddf5 100644
96776--- a/mm/swapfile.c
96777+++ b/mm/swapfile.c
96778@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
96779
96780 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
96781 /* Activity counter to indicate that a swapon or swapoff has occurred */
96782-static atomic_t proc_poll_event = ATOMIC_INIT(0);
96783+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
96784
96785 static inline unsigned char swap_count(unsigned char ent)
96786 {
96787@@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
96788 spin_unlock(&swap_lock);
96789
96790 err = 0;
96791- atomic_inc(&proc_poll_event);
96792+ atomic_inc_unchecked(&proc_poll_event);
96793 wake_up_interruptible(&proc_poll_wait);
96794
96795 out_dput:
96796@@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
96797
96798 poll_wait(file, &proc_poll_wait, wait);
96799
96800- if (seq->poll_event != atomic_read(&proc_poll_event)) {
96801- seq->poll_event = atomic_read(&proc_poll_event);
96802+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
96803+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96804 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
96805 }
96806
96807@@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
96808 return ret;
96809
96810 seq = file->private_data;
96811- seq->poll_event = atomic_read(&proc_poll_event);
96812+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96813 return 0;
96814 }
96815
96816@@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
96817 (frontswap_map) ? "FS" : "");
96818
96819 mutex_unlock(&swapon_mutex);
96820- atomic_inc(&proc_poll_event);
96821+ atomic_inc_unchecked(&proc_poll_event);
96822 wake_up_interruptible(&proc_poll_wait);
96823
96824 if (S_ISREG(inode->i_mode))
96825diff --git a/mm/util.c b/mm/util.c
96826index d5ea733..e8953f9 100644
96827--- a/mm/util.c
96828+++ b/mm/util.c
96829@@ -299,6 +299,12 @@ done:
96830 void arch_pick_mmap_layout(struct mm_struct *mm)
96831 {
96832 mm->mmap_base = TASK_UNMAPPED_BASE;
96833+
96834+#ifdef CONFIG_PAX_RANDMMAP
96835+ if (mm->pax_flags & MF_PAX_RANDMMAP)
96836+ mm->mmap_base += mm->delta_mmap;
96837+#endif
96838+
96839 mm->get_unmapped_area = arch_get_unmapped_area;
96840 }
96841 #endif
96842@@ -475,6 +481,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
96843 if (!mm->arg_end)
96844 goto out_mm; /* Shh! No looking before we're done */
96845
96846+ if (gr_acl_handle_procpidmem(task))
96847+ goto out_mm;
96848+
96849 len = mm->arg_end - mm->arg_start;
96850
96851 if (len > buflen)
96852diff --git a/mm/vmalloc.c b/mm/vmalloc.c
96853index bf233b2..1dfa1bc 100644
96854--- a/mm/vmalloc.c
96855+++ b/mm/vmalloc.c
96856@@ -40,6 +40,21 @@ struct vfree_deferred {
96857 };
96858 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
96859
96860+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
96861+struct stack_deferred_llist {
96862+ struct llist_head list;
96863+ void *stack;
96864+ void *lowmem_stack;
96865+};
96866+
96867+struct stack_deferred {
96868+ struct stack_deferred_llist list;
96869+ struct work_struct wq;
96870+};
96871+
96872+static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
96873+#endif
96874+
96875 static void __vunmap(const void *, int);
96876
96877 static void free_work(struct work_struct *w)
96878@@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
96879 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
96880 struct llist_node *llnode = llist_del_all(&p->list);
96881 while (llnode) {
96882- void *p = llnode;
96883+ void *x = llnode;
96884 llnode = llist_next(llnode);
96885- __vunmap(p, 1);
96886+ __vunmap(x, 1);
96887 }
96888 }
96889
96890+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
96891+static void unmap_work(struct work_struct *w)
96892+{
96893+ struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
96894+ struct llist_node *llnode = llist_del_all(&p->list.list);
96895+ while (llnode) {
96896+ struct stack_deferred_llist *x =
96897+ llist_entry((struct llist_head *)llnode,
96898+ struct stack_deferred_llist, list);
96899+ void *stack = ACCESS_ONCE(x->stack);
96900+ void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
96901+ llnode = llist_next(llnode);
96902+ __vunmap(stack, 0);
96903+ free_memcg_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
96904+ }
96905+}
96906+#endif
96907+
96908 /*** Page table manipulation functions ***/
96909
96910 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96911@@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
96912
96913 pte = pte_offset_kernel(pmd, addr);
96914 do {
96915- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96916- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96917+
96918+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96919+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
96920+ BUG_ON(!pte_exec(*pte));
96921+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
96922+ continue;
96923+ }
96924+#endif
96925+
96926+ {
96927+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
96928+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
96929+ }
96930 } while (pte++, addr += PAGE_SIZE, addr != end);
96931 }
96932
96933@@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
96934 pte = pte_alloc_kernel(pmd, addr);
96935 if (!pte)
96936 return -ENOMEM;
96937+
96938+ pax_open_kernel();
96939 do {
96940 struct page *page = pages[*nr];
96941
96942- if (WARN_ON(!pte_none(*pte)))
96943+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96944+ if (pgprot_val(prot) & _PAGE_NX)
96945+#endif
96946+
96947+ if (!pte_none(*pte)) {
96948+ pax_close_kernel();
96949+ WARN_ON(1);
96950 return -EBUSY;
96951- if (WARN_ON(!page))
96952+ }
96953+ if (!page) {
96954+ pax_close_kernel();
96955+ WARN_ON(1);
96956 return -ENOMEM;
96957+ }
96958 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
96959 (*nr)++;
96960 } while (pte++, addr += PAGE_SIZE, addr != end);
96961+ pax_close_kernel();
96962 return 0;
96963 }
96964
96965@@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
96966 pmd_t *pmd;
96967 unsigned long next;
96968
96969- pmd = pmd_alloc(&init_mm, pud, addr);
96970+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
96971 if (!pmd)
96972 return -ENOMEM;
96973 do {
96974@@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
96975 pud_t *pud;
96976 unsigned long next;
96977
96978- pud = pud_alloc(&init_mm, pgd, addr);
96979+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
96980 if (!pud)
96981 return -ENOMEM;
96982 do {
96983@@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
96984 if (addr >= MODULES_VADDR && addr < MODULES_END)
96985 return 1;
96986 #endif
96987+
96988+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
96989+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
96990+ return 1;
96991+#endif
96992+
96993 return is_vmalloc_addr(x);
96994 }
96995
96996@@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
96997
96998 if (!pgd_none(*pgd)) {
96999 pud_t *pud = pud_offset(pgd, addr);
97000+#ifdef CONFIG_X86
97001+ if (!pud_large(*pud))
97002+#endif
97003 if (!pud_none(*pud)) {
97004 pmd_t *pmd = pmd_offset(pud, addr);
97005+#ifdef CONFIG_X86
97006+ if (!pmd_large(*pmd))
97007+#endif
97008 if (!pmd_none(*pmd)) {
97009 pte_t *ptep, pte;
97010
97011@@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
97012 for_each_possible_cpu(i) {
97013 struct vmap_block_queue *vbq;
97014 struct vfree_deferred *p;
97015+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97016+ struct stack_deferred *p2;
97017+#endif
97018
97019 vbq = &per_cpu(vmap_block_queue, i);
97020 spin_lock_init(&vbq->lock);
97021 INIT_LIST_HEAD(&vbq->free);
97022+
97023 p = &per_cpu(vfree_deferred, i);
97024 init_llist_head(&p->list);
97025 INIT_WORK(&p->wq, free_work);
97026+
97027+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97028+ p2 = &per_cpu(stack_deferred, i);
97029+ init_llist_head(&p2->list.list);
97030+ INIT_WORK(&p2->wq, unmap_work);
97031+#endif
97032 }
97033
97034 /* Import existing vmlist entries. */
97035@@ -1317,6 +1396,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
97036 struct vm_struct *area;
97037
97038 BUG_ON(in_interrupt());
97039+
97040+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97041+ if (flags & VM_KERNEXEC) {
97042+ if (start != VMALLOC_START || end != VMALLOC_END)
97043+ return NULL;
97044+ start = (unsigned long)MODULES_EXEC_VADDR;
97045+ end = (unsigned long)MODULES_EXEC_END;
97046+ }
97047+#endif
97048+
97049 if (flags & VM_IOREMAP)
97050 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
97051
97052@@ -1522,6 +1611,23 @@ void vunmap(const void *addr)
97053 }
97054 EXPORT_SYMBOL(vunmap);
97055
97056+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97057+void unmap_process_stacks(struct task_struct *task)
97058+{
97059+ if (unlikely(in_interrupt())) {
97060+ struct stack_deferred *p = &__get_cpu_var(stack_deferred);
97061+ struct stack_deferred_llist *list = task->stack;
97062+ list->stack = task->stack;
97063+ list->lowmem_stack = task->lowmem_stack;
97064+ if (llist_add((struct llist_node *)&list->list, &p->list.list))
97065+ schedule_work(&p->wq);
97066+ } else {
97067+ __vunmap(task->stack, 0);
97068+ free_memcg_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
97069+ }
97070+}
97071+#endif
97072+
97073 /**
97074 * vmap - map an array of pages into virtually contiguous space
97075 * @pages: array of page pointers
97076@@ -1542,6 +1648,11 @@ void *vmap(struct page **pages, unsigned int count,
97077 if (count > totalram_pages)
97078 return NULL;
97079
97080+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97081+ if (!(pgprot_val(prot) & _PAGE_NX))
97082+ flags |= VM_KERNEXEC;
97083+#endif
97084+
97085 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
97086 __builtin_return_address(0));
97087 if (!area)
97088@@ -1642,6 +1753,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
97089 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
97090 goto fail;
97091
97092+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97093+ if (!(pgprot_val(prot) & _PAGE_NX))
97094+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
97095+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
97096+ else
97097+#endif
97098+
97099 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
97100 start, end, node, gfp_mask, caller);
97101 if (!area)
97102@@ -1818,10 +1936,9 @@ EXPORT_SYMBOL(vzalloc_node);
97103 * For tight control over page level allocator and protection flags
97104 * use __vmalloc() instead.
97105 */
97106-
97107 void *vmalloc_exec(unsigned long size)
97108 {
97109- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
97110+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
97111 NUMA_NO_NODE, __builtin_return_address(0));
97112 }
97113
97114@@ -2128,6 +2245,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
97115 {
97116 struct vm_struct *area;
97117
97118+ BUG_ON(vma->vm_mirror);
97119+
97120 size = PAGE_ALIGN(size);
97121
97122 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
97123@@ -2610,7 +2729,11 @@ static int s_show(struct seq_file *m, void *p)
97124 v->addr, v->addr + v->size, v->size);
97125
97126 if (v->caller)
97127+#ifdef CONFIG_GRKERNSEC_HIDESYM
97128+ seq_printf(m, " %pK", v->caller);
97129+#else
97130 seq_printf(m, " %pS", v->caller);
97131+#endif
97132
97133 if (v->nr_pages)
97134 seq_printf(m, " pages=%d", v->nr_pages);
97135diff --git a/mm/vmstat.c b/mm/vmstat.c
97136index 302dd07..3841f1c 100644
97137--- a/mm/vmstat.c
97138+++ b/mm/vmstat.c
97139@@ -20,6 +20,7 @@
97140 #include <linux/writeback.h>
97141 #include <linux/compaction.h>
97142 #include <linux/mm_inline.h>
97143+#include <linux/grsecurity.h>
97144
97145 #include "internal.h"
97146
97147@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
97148 *
97149 * vm_stat contains the global counters
97150 */
97151-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97152+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97153 EXPORT_SYMBOL(vm_stat);
97154
97155 #ifdef CONFIG_SMP
97156@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
97157
97158 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97159 if (diff[i])
97160- atomic_long_add(diff[i], &vm_stat[i]);
97161+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
97162 }
97163
97164 /*
97165@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
97166 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
97167 if (v) {
97168
97169- atomic_long_add(v, &zone->vm_stat[i]);
97170+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97171 global_diff[i] += v;
97172 #ifdef CONFIG_NUMA
97173 /* 3 seconds idle till flush */
97174@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
97175
97176 v = p->vm_stat_diff[i];
97177 p->vm_stat_diff[i] = 0;
97178- atomic_long_add(v, &zone->vm_stat[i]);
97179+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97180 global_diff[i] += v;
97181 }
97182 }
97183@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
97184 if (pset->vm_stat_diff[i]) {
97185 int v = pset->vm_stat_diff[i];
97186 pset->vm_stat_diff[i] = 0;
97187- atomic_long_add(v, &zone->vm_stat[i]);
97188- atomic_long_add(v, &vm_stat[i]);
97189+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97190+ atomic_long_add_unchecked(v, &vm_stat[i]);
97191 }
97192 }
97193 #endif
97194@@ -1156,10 +1157,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
97195 stat_items_size += sizeof(struct vm_event_state);
97196 #endif
97197
97198- v = kmalloc(stat_items_size, GFP_KERNEL);
97199+ v = kzalloc(stat_items_size, GFP_KERNEL);
97200 m->private = v;
97201 if (!v)
97202 return ERR_PTR(-ENOMEM);
97203+
97204+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97205+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
97206+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
97207+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
97208+ && !in_group_p(grsec_proc_gid)
97209+#endif
97210+ )
97211+ return (unsigned long *)m->private + *pos;
97212+#endif
97213+#endif
97214+
97215 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97216 v[i] = global_page_state(i);
97217 v += NR_VM_ZONE_STAT_ITEMS;
97218@@ -1308,10 +1321,16 @@ static int __init setup_vmstat(void)
97219 cpu_notifier_register_done();
97220 #endif
97221 #ifdef CONFIG_PROC_FS
97222- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
97223- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
97224- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97225- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
97226+ {
97227+ mode_t gr_mode = S_IRUGO;
97228+#ifdef CONFIG_GRKERNSEC_PROC_ADD
97229+ gr_mode = S_IRUSR;
97230+#endif
97231+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
97232+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
97233+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97234+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
97235+ }
97236 #endif
97237 return 0;
97238 }
97239diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
97240index 44ebd5c..1f732bae 100644
97241--- a/net/8021q/vlan.c
97242+++ b/net/8021q/vlan.c
97243@@ -475,7 +475,7 @@ out:
97244 return NOTIFY_DONE;
97245 }
97246
97247-static struct notifier_block vlan_notifier_block __read_mostly = {
97248+static struct notifier_block vlan_notifier_block = {
97249 .notifier_call = vlan_device_event,
97250 };
97251
97252@@ -550,8 +550,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
97253 err = -EPERM;
97254 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
97255 break;
97256- if ((args.u.name_type >= 0) &&
97257- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
97258+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
97259 struct vlan_net *vn;
97260
97261 vn = net_generic(net, vlan_net_id);
97262diff --git a/net/9p/client.c b/net/9p/client.c
97263index 0004cba..feba240 100644
97264--- a/net/9p/client.c
97265+++ b/net/9p/client.c
97266@@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97267 len - inline_len);
97268 } else {
97269 err = copy_from_user(ename + inline_len,
97270- uidata, len - inline_len);
97271+ (char __force_user *)uidata, len - inline_len);
97272 if (err) {
97273 err = -EFAULT;
97274 goto out_err;
97275@@ -1571,7 +1571,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97276 kernel_buf = 1;
97277 indata = data;
97278 } else
97279- indata = (__force char *)udata;
97280+ indata = (__force_kernel char *)udata;
97281 /*
97282 * response header len is 11
97283 * PDU Header(7) + IO Size (4)
97284@@ -1646,7 +1646,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97285 kernel_buf = 1;
97286 odata = data;
97287 } else
97288- odata = (char *)udata;
97289+ odata = (char __force_kernel *)udata;
97290 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97291 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97292 fid->fid, offset, rsize);
97293diff --git a/net/9p/mod.c b/net/9p/mod.c
97294index 6ab36ae..6f1841b 100644
97295--- a/net/9p/mod.c
97296+++ b/net/9p/mod.c
97297@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97298 void v9fs_register_trans(struct p9_trans_module *m)
97299 {
97300 spin_lock(&v9fs_trans_lock);
97301- list_add_tail(&m->list, &v9fs_trans_list);
97302+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97303 spin_unlock(&v9fs_trans_lock);
97304 }
97305 EXPORT_SYMBOL(v9fs_register_trans);
97306@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97307 void v9fs_unregister_trans(struct p9_trans_module *m)
97308 {
97309 spin_lock(&v9fs_trans_lock);
97310- list_del_init(&m->list);
97311+ pax_list_del_init((struct list_head *)&m->list);
97312 spin_unlock(&v9fs_trans_lock);
97313 }
97314 EXPORT_SYMBOL(v9fs_unregister_trans);
97315diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97316index 80d08f6..de63fd1 100644
97317--- a/net/9p/trans_fd.c
97318+++ b/net/9p/trans_fd.c
97319@@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97320 oldfs = get_fs();
97321 set_fs(get_ds());
97322 /* The cast to a user pointer is valid due to the set_fs() */
97323- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97324+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97325 set_fs(oldfs);
97326
97327 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97328diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97329index af46bc4..f9adfcd 100644
97330--- a/net/appletalk/atalk_proc.c
97331+++ b/net/appletalk/atalk_proc.c
97332@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97333 struct proc_dir_entry *p;
97334 int rc = -ENOMEM;
97335
97336- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97337+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97338 if (!atalk_proc_dir)
97339 goto out;
97340
97341diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97342index 876fbe8..8bbea9f 100644
97343--- a/net/atm/atm_misc.c
97344+++ b/net/atm/atm_misc.c
97345@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97346 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97347 return 1;
97348 atm_return(vcc, truesize);
97349- atomic_inc(&vcc->stats->rx_drop);
97350+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97351 return 0;
97352 }
97353 EXPORT_SYMBOL(atm_charge);
97354@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97355 }
97356 }
97357 atm_return(vcc, guess);
97358- atomic_inc(&vcc->stats->rx_drop);
97359+ atomic_inc_unchecked(&vcc->stats->rx_drop);
97360 return NULL;
97361 }
97362 EXPORT_SYMBOL(atm_alloc_charge);
97363@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
97364
97365 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97366 {
97367-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97368+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97369 __SONET_ITEMS
97370 #undef __HANDLE_ITEM
97371 }
97372@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
97373
97374 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97375 {
97376-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97377+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
97378 __SONET_ITEMS
97379 #undef __HANDLE_ITEM
97380 }
97381diff --git a/net/atm/lec.c b/net/atm/lec.c
97382index 4c5b8ba..95f7005 100644
97383--- a/net/atm/lec.c
97384+++ b/net/atm/lec.c
97385@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
97386 }
97387
97388 static struct lane2_ops lane2_ops = {
97389- lane2_resolve, /* resolve, spec 3.1.3 */
97390- lane2_associate_req, /* associate_req, spec 3.1.4 */
97391- NULL /* associate indicator, spec 3.1.5 */
97392+ .resolve = lane2_resolve,
97393+ .associate_req = lane2_associate_req,
97394+ .associate_indicator = NULL
97395 };
97396
97397 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
97398diff --git a/net/atm/lec.h b/net/atm/lec.h
97399index 4149db1..f2ab682 100644
97400--- a/net/atm/lec.h
97401+++ b/net/atm/lec.h
97402@@ -48,7 +48,7 @@ struct lane2_ops {
97403 const u8 *tlvs, u32 sizeoftlvs);
97404 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
97405 const u8 *tlvs, u32 sizeoftlvs);
97406-};
97407+} __no_const;
97408
97409 /*
97410 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
97411diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
97412index d1b2d9a..d549f7f 100644
97413--- a/net/atm/mpoa_caches.c
97414+++ b/net/atm/mpoa_caches.c
97415@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
97416
97417
97418 static struct in_cache_ops ingress_ops = {
97419- in_cache_add_entry, /* add_entry */
97420- in_cache_get, /* get */
97421- in_cache_get_with_mask, /* get_with_mask */
97422- in_cache_get_by_vcc, /* get_by_vcc */
97423- in_cache_put, /* put */
97424- in_cache_remove_entry, /* remove_entry */
97425- cache_hit, /* cache_hit */
97426- clear_count_and_expired, /* clear_count */
97427- check_resolving_entries, /* check_resolving */
97428- refresh_entries, /* refresh */
97429- in_destroy_cache /* destroy_cache */
97430+ .add_entry = in_cache_add_entry,
97431+ .get = in_cache_get,
97432+ .get_with_mask = in_cache_get_with_mask,
97433+ .get_by_vcc = in_cache_get_by_vcc,
97434+ .put = in_cache_put,
97435+ .remove_entry = in_cache_remove_entry,
97436+ .cache_hit = cache_hit,
97437+ .clear_count = clear_count_and_expired,
97438+ .check_resolving = check_resolving_entries,
97439+ .refresh = refresh_entries,
97440+ .destroy_cache = in_destroy_cache
97441 };
97442
97443 static struct eg_cache_ops egress_ops = {
97444- eg_cache_add_entry, /* add_entry */
97445- eg_cache_get_by_cache_id, /* get_by_cache_id */
97446- eg_cache_get_by_tag, /* get_by_tag */
97447- eg_cache_get_by_vcc, /* get_by_vcc */
97448- eg_cache_get_by_src_ip, /* get_by_src_ip */
97449- eg_cache_put, /* put */
97450- eg_cache_remove_entry, /* remove_entry */
97451- update_eg_cache_entry, /* update */
97452- clear_expired, /* clear_expired */
97453- eg_destroy_cache /* destroy_cache */
97454+ .add_entry = eg_cache_add_entry,
97455+ .get_by_cache_id = eg_cache_get_by_cache_id,
97456+ .get_by_tag = eg_cache_get_by_tag,
97457+ .get_by_vcc = eg_cache_get_by_vcc,
97458+ .get_by_src_ip = eg_cache_get_by_src_ip,
97459+ .put = eg_cache_put,
97460+ .remove_entry = eg_cache_remove_entry,
97461+ .update = update_eg_cache_entry,
97462+ .clear_expired = clear_expired,
97463+ .destroy_cache = eg_destroy_cache
97464 };
97465
97466
97467diff --git a/net/atm/proc.c b/net/atm/proc.c
97468index bbb6461..cf04016 100644
97469--- a/net/atm/proc.c
97470+++ b/net/atm/proc.c
97471@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
97472 const struct k_atm_aal_stats *stats)
97473 {
97474 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
97475- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
97476- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
97477- atomic_read(&stats->rx_drop));
97478+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
97479+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
97480+ atomic_read_unchecked(&stats->rx_drop));
97481 }
97482
97483 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
97484diff --git a/net/atm/resources.c b/net/atm/resources.c
97485index 0447d5d..3cf4728 100644
97486--- a/net/atm/resources.c
97487+++ b/net/atm/resources.c
97488@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
97489 static void copy_aal_stats(struct k_atm_aal_stats *from,
97490 struct atm_aal_stats *to)
97491 {
97492-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97493+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97494 __AAL_STAT_ITEMS
97495 #undef __HANDLE_ITEM
97496 }
97497@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
97498 static void subtract_aal_stats(struct k_atm_aal_stats *from,
97499 struct atm_aal_stats *to)
97500 {
97501-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97502+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
97503 __AAL_STAT_ITEMS
97504 #undef __HANDLE_ITEM
97505 }
97506diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
97507index 919a5ce..cc6b444 100644
97508--- a/net/ax25/sysctl_net_ax25.c
97509+++ b/net/ax25/sysctl_net_ax25.c
97510@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
97511 {
97512 char path[sizeof("net/ax25/") + IFNAMSIZ];
97513 int k;
97514- struct ctl_table *table;
97515+ ctl_table_no_const *table;
97516
97517 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
97518 if (!table)
97519diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
97520index f04224c..f326579 100644
97521--- a/net/batman-adv/bat_iv_ogm.c
97522+++ b/net/batman-adv/bat_iv_ogm.c
97523@@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
97524
97525 /* randomize initial seqno to avoid collision */
97526 get_random_bytes(&random_seqno, sizeof(random_seqno));
97527- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97528+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97529
97530 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
97531 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
97532@@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
97533 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
97534
97535 /* change sequence number to network order */
97536- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
97537+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
97538 batadv_ogm_packet->seqno = htonl(seqno);
97539- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
97540+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
97541
97542 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
97543
97544@@ -1596,7 +1596,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
97545 return;
97546
97547 /* could be changed by schedule_own_packet() */
97548- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
97549+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
97550
97551 if (ogm_packet->flags & BATADV_DIRECTLINK)
97552 has_directlink_flag = true;
97553diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
97554index f14e54a..66f3e2e 100644
97555--- a/net/batman-adv/fragmentation.c
97556+++ b/net/batman-adv/fragmentation.c
97557@@ -446,7 +446,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
97558 frag_header.packet_type = BATADV_UNICAST_FRAG;
97559 frag_header.version = BATADV_COMPAT_VERSION;
97560 frag_header.ttl = BATADV_TTL;
97561- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
97562+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
97563 frag_header.reserved = 0;
97564 frag_header.no = 0;
97565 frag_header.total_size = htons(skb->len);
97566diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
97567index 744a59b..8fd037c 100644
97568--- a/net/batman-adv/soft-interface.c
97569+++ b/net/batman-adv/soft-interface.c
97570@@ -296,7 +296,7 @@ send:
97571 primary_if->net_dev->dev_addr);
97572
97573 /* set broadcast sequence number */
97574- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
97575+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
97576 bcast_packet->seqno = htonl(seqno);
97577
97578 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
97579@@ -729,7 +729,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97580 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
97581
97582 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
97583- atomic_set(&bat_priv->bcast_seqno, 1);
97584+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
97585 atomic_set(&bat_priv->tt.vn, 0);
97586 atomic_set(&bat_priv->tt.local_changes, 0);
97587 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
97588@@ -743,7 +743,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97589
97590 /* randomize initial seqno to avoid collision */
97591 get_random_bytes(&random_seqno, sizeof(random_seqno));
97592- atomic_set(&bat_priv->frag_seqno, random_seqno);
97593+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
97594
97595 bat_priv->primary_if = NULL;
97596 bat_priv->num_ifaces = 0;
97597diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
97598index 34891a5..3cfece0 100644
97599--- a/net/batman-adv/types.h
97600+++ b/net/batman-adv/types.h
97601@@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
97602 struct batadv_hard_iface_bat_iv {
97603 unsigned char *ogm_buff;
97604 int ogm_buff_len;
97605- atomic_t ogm_seqno;
97606+ atomic_unchecked_t ogm_seqno;
97607 };
97608
97609 /**
97610@@ -766,7 +766,7 @@ struct batadv_priv {
97611 atomic_t bonding;
97612 atomic_t fragmentation;
97613 atomic_t packet_size_max;
97614- atomic_t frag_seqno;
97615+ atomic_unchecked_t frag_seqno;
97616 #ifdef CONFIG_BATMAN_ADV_BLA
97617 atomic_t bridge_loop_avoidance;
97618 #endif
97619@@ -785,7 +785,7 @@ struct batadv_priv {
97620 #endif
97621 uint32_t isolation_mark;
97622 uint32_t isolation_mark_mask;
97623- atomic_t bcast_seqno;
97624+ atomic_unchecked_t bcast_seqno;
97625 atomic_t bcast_queue_left;
97626 atomic_t batman_queue_left;
97627 char num_ifaces;
97628diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
97629index b9a418e..2af862a 100644
97630--- a/net/bluetooth/hci_sock.c
97631+++ b/net/bluetooth/hci_sock.c
97632@@ -1053,7 +1053,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
97633 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
97634 }
97635
97636- len = min_t(unsigned int, len, sizeof(uf));
97637+ len = min((size_t)len, sizeof(uf));
97638 if (copy_from_user(&uf, optval, len)) {
97639 err = -EFAULT;
97640 break;
97641diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
97642index 1c97b7a..9171d69 100644
97643--- a/net/bluetooth/l2cap_core.c
97644+++ b/net/bluetooth/l2cap_core.c
97645@@ -3542,8 +3542,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
97646 break;
97647
97648 case L2CAP_CONF_RFC:
97649- if (olen == sizeof(rfc))
97650- memcpy(&rfc, (void *)val, olen);
97651+ if (olen != sizeof(rfc))
97652+ break;
97653+
97654+ memcpy(&rfc, (void *)val, olen);
97655
97656 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
97657 rfc.mode != chan->mode)
97658diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
97659index e137869..33f3ebd 100644
97660--- a/net/bluetooth/l2cap_sock.c
97661+++ b/net/bluetooth/l2cap_sock.c
97662@@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97663 struct sock *sk = sock->sk;
97664 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
97665 struct l2cap_options opts;
97666- int len, err = 0;
97667+ int err = 0;
97668+ size_t len = optlen;
97669 u32 opt;
97670
97671 BT_DBG("sk %p", sk);
97672@@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97673 opts.max_tx = chan->max_tx;
97674 opts.txwin_size = chan->tx_win;
97675
97676- len = min_t(unsigned int, sizeof(opts), optlen);
97677+ len = min(sizeof(opts), len);
97678 if (copy_from_user((char *) &opts, optval, len)) {
97679 err = -EFAULT;
97680 break;
97681@@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97682 struct bt_security sec;
97683 struct bt_power pwr;
97684 struct l2cap_conn *conn;
97685- int len, err = 0;
97686+ int err = 0;
97687+ size_t len = optlen;
97688 u32 opt;
97689
97690 BT_DBG("sk %p", sk);
97691@@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97692
97693 sec.level = BT_SECURITY_LOW;
97694
97695- len = min_t(unsigned int, sizeof(sec), optlen);
97696+ len = min(sizeof(sec), len);
97697 if (copy_from_user((char *) &sec, optval, len)) {
97698 err = -EFAULT;
97699 break;
97700@@ -861,7 +863,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97701
97702 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
97703
97704- len = min_t(unsigned int, sizeof(pwr), optlen);
97705+ len = min(sizeof(pwr), len);
97706 if (copy_from_user((char *) &pwr, optval, len)) {
97707 err = -EFAULT;
97708 break;
97709diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
97710index c603a5e..7f08991 100644
97711--- a/net/bluetooth/rfcomm/sock.c
97712+++ b/net/bluetooth/rfcomm/sock.c
97713@@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97714 struct sock *sk = sock->sk;
97715 struct bt_security sec;
97716 int err = 0;
97717- size_t len;
97718+ size_t len = optlen;
97719 u32 opt;
97720
97721 BT_DBG("sk %p", sk);
97722@@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97723
97724 sec.level = BT_SECURITY_LOW;
97725
97726- len = min_t(unsigned int, sizeof(sec), optlen);
97727+ len = min(sizeof(sec), len);
97728 if (copy_from_user((char *) &sec, optval, len)) {
97729 err = -EFAULT;
97730 break;
97731diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
97732index 403ec09..a21a003 100644
97733--- a/net/bluetooth/rfcomm/tty.c
97734+++ b/net/bluetooth/rfcomm/tty.c
97735@@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
97736 BT_DBG("tty %p id %d", tty, tty->index);
97737
97738 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
97739- dev->channel, dev->port.count);
97740+ dev->channel, atomic_read(&dev->port.count));
97741
97742 err = tty_port_open(&dev->port, tty, filp);
97743 if (err)
97744@@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
97745 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
97746
97747 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
97748- dev->port.count);
97749+ atomic_read(&dev->port.count));
97750
97751 tty_port_close(&dev->port, tty, filp);
97752 }
97753diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
97754index 1059ed3..d70846a 100644
97755--- a/net/bridge/netfilter/ebtables.c
97756+++ b/net/bridge/netfilter/ebtables.c
97757@@ -1524,7 +1524,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97758 tmp.valid_hooks = t->table->valid_hooks;
97759 }
97760 mutex_unlock(&ebt_mutex);
97761- if (copy_to_user(user, &tmp, *len) != 0) {
97762+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97763 BUGPRINT("c2u Didn't work\n");
97764 ret = -EFAULT;
97765 break;
97766@@ -2330,7 +2330,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97767 goto out;
97768 tmp.valid_hooks = t->valid_hooks;
97769
97770- if (copy_to_user(user, &tmp, *len) != 0) {
97771+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97772 ret = -EFAULT;
97773 break;
97774 }
97775@@ -2341,7 +2341,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97776 tmp.entries_size = t->table->entries_size;
97777 tmp.valid_hooks = t->table->valid_hooks;
97778
97779- if (copy_to_user(user, &tmp, *len) != 0) {
97780+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97781 ret = -EFAULT;
97782 break;
97783 }
97784diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
97785index 0f45522..dab651f 100644
97786--- a/net/caif/cfctrl.c
97787+++ b/net/caif/cfctrl.c
97788@@ -10,6 +10,7 @@
97789 #include <linux/spinlock.h>
97790 #include <linux/slab.h>
97791 #include <linux/pkt_sched.h>
97792+#include <linux/sched.h>
97793 #include <net/caif/caif_layer.h>
97794 #include <net/caif/cfpkt.h>
97795 #include <net/caif/cfctrl.h>
97796@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
97797 memset(&dev_info, 0, sizeof(dev_info));
97798 dev_info.id = 0xff;
97799 cfsrvl_init(&this->serv, 0, &dev_info, false);
97800- atomic_set(&this->req_seq_no, 1);
97801- atomic_set(&this->rsp_seq_no, 1);
97802+ atomic_set_unchecked(&this->req_seq_no, 1);
97803+ atomic_set_unchecked(&this->rsp_seq_no, 1);
97804 this->serv.layer.receive = cfctrl_recv;
97805 sprintf(this->serv.layer.name, "ctrl");
97806 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
97807@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
97808 struct cfctrl_request_info *req)
97809 {
97810 spin_lock_bh(&ctrl->info_list_lock);
97811- atomic_inc(&ctrl->req_seq_no);
97812- req->sequence_no = atomic_read(&ctrl->req_seq_no);
97813+ atomic_inc_unchecked(&ctrl->req_seq_no);
97814+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
97815 list_add_tail(&req->list, &ctrl->list);
97816 spin_unlock_bh(&ctrl->info_list_lock);
97817 }
97818@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
97819 if (p != first)
97820 pr_warn("Requests are not received in order\n");
97821
97822- atomic_set(&ctrl->rsp_seq_no,
97823+ atomic_set_unchecked(&ctrl->rsp_seq_no,
97824 p->sequence_no);
97825 list_del(&p->list);
97826 goto out;
97827diff --git a/net/can/af_can.c b/net/can/af_can.c
97828index a27f8aa..67174a3 100644
97829--- a/net/can/af_can.c
97830+++ b/net/can/af_can.c
97831@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
97832 };
97833
97834 /* notifier block for netdevice event */
97835-static struct notifier_block can_netdev_notifier __read_mostly = {
97836+static struct notifier_block can_netdev_notifier = {
97837 .notifier_call = can_notifier,
97838 };
97839
97840diff --git a/net/can/bcm.c b/net/can/bcm.c
97841index dcb75c0..24b1b43 100644
97842--- a/net/can/bcm.c
97843+++ b/net/can/bcm.c
97844@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
97845 }
97846
97847 /* create /proc/net/can-bcm directory */
97848- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
97849+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
97850 return 0;
97851 }
97852
97853diff --git a/net/can/gw.c b/net/can/gw.c
97854index 050a211..bb9fe33 100644
97855--- a/net/can/gw.c
97856+++ b/net/can/gw.c
97857@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
97858 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
97859
97860 static HLIST_HEAD(cgw_list);
97861-static struct notifier_block notifier;
97862
97863 static struct kmem_cache *cgw_cache __read_mostly;
97864
97865@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
97866 return err;
97867 }
97868
97869+static struct notifier_block notifier = {
97870+ .notifier_call = cgw_notifier
97871+};
97872+
97873 static __init int cgw_module_init(void)
97874 {
97875 /* sanitize given module parameter */
97876@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
97877 return -ENOMEM;
97878
97879 /* set notifier */
97880- notifier.notifier_call = cgw_notifier;
97881 register_netdevice_notifier(&notifier);
97882
97883 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
97884diff --git a/net/can/proc.c b/net/can/proc.c
97885index b543470..d2ddae2 100644
97886--- a/net/can/proc.c
97887+++ b/net/can/proc.c
97888@@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
97889 void can_init_proc(void)
97890 {
97891 /* create /proc/net/can directory */
97892- can_dir = proc_mkdir("can", init_net.proc_net);
97893+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
97894
97895 if (!can_dir) {
97896 printk(KERN_INFO "can: failed to create /proc/net/can . "
97897diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
97898index 1948d59..9e854d5 100644
97899--- a/net/ceph/messenger.c
97900+++ b/net/ceph/messenger.c
97901@@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
97902 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
97903
97904 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
97905-static atomic_t addr_str_seq = ATOMIC_INIT(0);
97906+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
97907
97908 static struct page *zero_page; /* used in certain error cases */
97909
97910@@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
97911 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
97912 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
97913
97914- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97915+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
97916 s = addr_str[i];
97917
97918 switch (ss->ss_family) {
97919diff --git a/net/compat.c b/net/compat.c
97920index 9a76eaf..5b8ccfd 100644
97921--- a/net/compat.c
97922+++ b/net/compat.c
97923@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
97924 return -EFAULT;
97925 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
97926 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
97927- kmsg->msg_name = compat_ptr(tmp1);
97928- kmsg->msg_iov = compat_ptr(tmp2);
97929- kmsg->msg_control = compat_ptr(tmp3);
97930+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
97931+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
97932+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
97933 return 0;
97934 }
97935
97936@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97937
97938 if (kern_msg->msg_namelen) {
97939 if (mode == VERIFY_READ) {
97940- int err = move_addr_to_kernel(kern_msg->msg_name,
97941+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
97942 kern_msg->msg_namelen,
97943 kern_address);
97944 if (err < 0)
97945@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97946 kern_msg->msg_name = NULL;
97947
97948 tot_len = iov_from_user_compat_to_kern(kern_iov,
97949- (struct compat_iovec __user *)kern_msg->msg_iov,
97950+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
97951 kern_msg->msg_iovlen);
97952 if (tot_len >= 0)
97953 kern_msg->msg_iov = kern_iov;
97954@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
97955
97956 #define CMSG_COMPAT_FIRSTHDR(msg) \
97957 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
97958- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
97959+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
97960 (struct compat_cmsghdr __user *)NULL)
97961
97962 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
97963 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
97964 (ucmlen) <= (unsigned long) \
97965 ((mhdr)->msg_controllen - \
97966- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
97967+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
97968
97969 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
97970 struct compat_cmsghdr __user *cmsg, int cmsg_len)
97971 {
97972 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
97973- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
97974+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
97975 msg->msg_controllen)
97976 return NULL;
97977 return (struct compat_cmsghdr __user *)ptr;
97978@@ -222,7 +222,7 @@ Efault:
97979
97980 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
97981 {
97982- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97983+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97984 struct compat_cmsghdr cmhdr;
97985 struct compat_timeval ctv;
97986 struct compat_timespec cts[3];
97987@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
97988
97989 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
97990 {
97991- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
97992+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
97993 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
97994 int fdnum = scm->fp->count;
97995 struct file **fp = scm->fp->fp;
97996@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
97997 return -EFAULT;
97998 old_fs = get_fs();
97999 set_fs(KERNEL_DS);
98000- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
98001+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
98002 set_fs(old_fs);
98003
98004 return err;
98005@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
98006 len = sizeof(ktime);
98007 old_fs = get_fs();
98008 set_fs(KERNEL_DS);
98009- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
98010+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
98011 set_fs(old_fs);
98012
98013 if (!err) {
98014@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98015 case MCAST_JOIN_GROUP:
98016 case MCAST_LEAVE_GROUP:
98017 {
98018- struct compat_group_req __user *gr32 = (void *)optval;
98019+ struct compat_group_req __user *gr32 = (void __user *)optval;
98020 struct group_req __user *kgr =
98021 compat_alloc_user_space(sizeof(struct group_req));
98022 u32 interface;
98023@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98024 case MCAST_BLOCK_SOURCE:
98025 case MCAST_UNBLOCK_SOURCE:
98026 {
98027- struct compat_group_source_req __user *gsr32 = (void *)optval;
98028+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
98029 struct group_source_req __user *kgsr = compat_alloc_user_space(
98030 sizeof(struct group_source_req));
98031 u32 interface;
98032@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98033 }
98034 case MCAST_MSFILTER:
98035 {
98036- struct compat_group_filter __user *gf32 = (void *)optval;
98037+ struct compat_group_filter __user *gf32 = (void __user *)optval;
98038 struct group_filter __user *kgf;
98039 u32 interface, fmode, numsrc;
98040
98041@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
98042 char __user *optval, int __user *optlen,
98043 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
98044 {
98045- struct compat_group_filter __user *gf32 = (void *)optval;
98046+ struct compat_group_filter __user *gf32 = (void __user *)optval;
98047 struct group_filter __user *kgf;
98048 int __user *koptlen;
98049 u32 interface, fmode, numsrc;
98050@@ -803,7 +803,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
98051
98052 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
98053 return -EINVAL;
98054- if (copy_from_user(a, args, nas[call]))
98055+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
98056 return -EFAULT;
98057 a0 = a[0];
98058 a1 = a[1];
98059diff --git a/net/core/datagram.c b/net/core/datagram.c
98060index a16ed7b..eb44d17 100644
98061--- a/net/core/datagram.c
98062+++ b/net/core/datagram.c
98063@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
98064 }
98065
98066 kfree_skb(skb);
98067- atomic_inc(&sk->sk_drops);
98068+ atomic_inc_unchecked(&sk->sk_drops);
98069 sk_mem_reclaim_partial(sk);
98070
98071 return err;
98072diff --git a/net/core/dev.c b/net/core/dev.c
98073index a30bef1..51d3e33 100644
98074--- a/net/core/dev.c
98075+++ b/net/core/dev.c
98076@@ -1683,14 +1683,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
98077 {
98078 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
98079 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
98080- atomic_long_inc(&dev->rx_dropped);
98081+ atomic_long_inc_unchecked(&dev->rx_dropped);
98082 kfree_skb(skb);
98083 return NET_RX_DROP;
98084 }
98085 }
98086
98087 if (unlikely(!is_skb_forwardable(dev, skb))) {
98088- atomic_long_inc(&dev->rx_dropped);
98089+ atomic_long_inc_unchecked(&dev->rx_dropped);
98090 kfree_skb(skb);
98091 return NET_RX_DROP;
98092 }
98093@@ -2463,7 +2463,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
98094
98095 struct dev_gso_cb {
98096 void (*destructor)(struct sk_buff *skb);
98097-};
98098+} __no_const;
98099
98100 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
98101
98102@@ -2893,7 +2893,7 @@ recursion_alert:
98103 rc = -ENETDOWN;
98104 rcu_read_unlock_bh();
98105
98106- atomic_long_inc(&dev->tx_dropped);
98107+ atomic_long_inc_unchecked(&dev->tx_dropped);
98108 kfree_skb(skb);
98109 return rc;
98110 out:
98111@@ -3237,7 +3237,7 @@ enqueue:
98112
98113 local_irq_restore(flags);
98114
98115- atomic_long_inc(&skb->dev->rx_dropped);
98116+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98117 kfree_skb(skb);
98118 return NET_RX_DROP;
98119 }
98120@@ -3314,7 +3314,7 @@ int netif_rx_ni(struct sk_buff *skb)
98121 }
98122 EXPORT_SYMBOL(netif_rx_ni);
98123
98124-static void net_tx_action(struct softirq_action *h)
98125+static __latent_entropy void net_tx_action(void)
98126 {
98127 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98128
98129@@ -3647,7 +3647,7 @@ ncls:
98130 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
98131 } else {
98132 drop:
98133- atomic_long_inc(&skb->dev->rx_dropped);
98134+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98135 kfree_skb(skb);
98136 /* Jamal, now you will not able to escape explaining
98137 * me how you were going to use this. :-)
98138@@ -4366,7 +4366,7 @@ void netif_napi_del(struct napi_struct *napi)
98139 }
98140 EXPORT_SYMBOL(netif_napi_del);
98141
98142-static void net_rx_action(struct softirq_action *h)
98143+static __latent_entropy void net_rx_action(void)
98144 {
98145 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98146 unsigned long time_limit = jiffies + 2;
98147@@ -6366,8 +6366,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
98148 } else {
98149 netdev_stats_to_stats64(storage, &dev->stats);
98150 }
98151- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
98152- storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
98153+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
98154+ storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
98155 return storage;
98156 }
98157 EXPORT_SYMBOL(dev_get_stats);
98158diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
98159index cf999e0..c59a975 100644
98160--- a/net/core/dev_ioctl.c
98161+++ b/net/core/dev_ioctl.c
98162@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
98163 if (no_module && capable(CAP_NET_ADMIN))
98164 no_module = request_module("netdev-%s", name);
98165 if (no_module && capable(CAP_SYS_MODULE)) {
98166+#ifdef CONFIG_GRKERNSEC_MODHARDEN
98167+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
98168+#else
98169 if (!request_module("%s", name))
98170 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
98171 name);
98172+#endif
98173 }
98174 }
98175 EXPORT_SYMBOL(dev_load);
98176diff --git a/net/core/dst.c b/net/core/dst.c
98177index 80d6286..a028409 100644
98178--- a/net/core/dst.c
98179+++ b/net/core/dst.c
98180@@ -269,6 +269,15 @@ again:
98181 }
98182 EXPORT_SYMBOL(dst_destroy);
98183
98184+static void dst_destroy_rcu(struct rcu_head *head)
98185+{
98186+ struct dst_entry *dst = container_of(head, struct dst_entry, rcu_head);
98187+
98188+ dst = dst_destroy(dst);
98189+ if (dst)
98190+ __dst_free(dst);
98191+}
98192+
98193 void dst_release(struct dst_entry *dst)
98194 {
98195 if (dst) {
98196@@ -276,11 +285,8 @@ void dst_release(struct dst_entry *dst)
98197
98198 newrefcnt = atomic_dec_return(&dst->__refcnt);
98199 WARN_ON(newrefcnt < 0);
98200- if (unlikely(dst->flags & DST_NOCACHE) && !newrefcnt) {
98201- dst = dst_destroy(dst);
98202- if (dst)
98203- __dst_free(dst);
98204- }
98205+ if (unlikely(dst->flags & DST_NOCACHE) && !newrefcnt)
98206+ call_rcu(&dst->rcu_head, dst_destroy_rcu);
98207 }
98208 }
98209 EXPORT_SYMBOL(dst_release);
98210diff --git a/net/core/filter.c b/net/core/filter.c
98211index 4aec7b9..5cf605c 100644
98212--- a/net/core/filter.c
98213+++ b/net/core/filter.c
98214@@ -1121,7 +1121,11 @@ do_pass:
98215 break;
98216
98217 default:
98218- goto err;
98219+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
98220+ fp->code, fp->jt, fp->jf, fp->k);
98221+ kfree(addrs);
98222+ BUG();
98223+ return -EINVAL;
98224 }
98225
98226 insn++;
98227@@ -1170,7 +1174,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
98228 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
98229 int pc, ret = 0;
98230
98231- BUILD_BUG_ON(BPF_MEMWORDS > 16);
98232+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
98233 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
98234 if (!masks)
98235 return -ENOMEM;
98236@@ -1605,7 +1609,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
98237 if (!fp)
98238 return -ENOMEM;
98239
98240- memcpy(fp->insns, fprog->filter, fsize);
98241+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
98242
98243 atomic_set(&fp->refcnt, 1);
98244 fp->len = fprog->len;
98245diff --git a/net/core/flow.c b/net/core/flow.c
98246index a0348fd..6951c76 100644
98247--- a/net/core/flow.c
98248+++ b/net/core/flow.c
98249@@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98250 static int flow_entry_valid(struct flow_cache_entry *fle,
98251 struct netns_xfrm *xfrm)
98252 {
98253- if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
98254+ if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
98255 return 0;
98256 if (fle->object && !fle->object->ops->check(fle->object))
98257 return 0;
98258@@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98259 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98260 fcp->hash_count++;
98261 }
98262- } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
98263+ } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
98264 flo = fle->object;
98265 if (!flo)
98266 goto ret_object;
98267@@ -263,7 +263,7 @@ nocache:
98268 }
98269 flo = resolver(net, key, family, dir, flo, ctx);
98270 if (fle) {
98271- fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
98272+ fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
98273 if (!IS_ERR(flo))
98274 fle->object = flo;
98275 else
98276diff --git a/net/core/iovec.c b/net/core/iovec.c
98277index b618694..192bbba 100644
98278--- a/net/core/iovec.c
98279+++ b/net/core/iovec.c
98280@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98281 if (m->msg_namelen) {
98282 if (mode == VERIFY_READ) {
98283 void __user *namep;
98284- namep = (void __user __force *) m->msg_name;
98285+ namep = (void __force_user *) m->msg_name;
98286 err = move_addr_to_kernel(namep, m->msg_namelen,
98287 address);
98288 if (err < 0)
98289@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98290 }
98291
98292 size = m->msg_iovlen * sizeof(struct iovec);
98293- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98294+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98295 return -EFAULT;
98296
98297 m->msg_iov = iov;
98298diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98299index 32d872e..487e769 100644
98300--- a/net/core/neighbour.c
98301+++ b/net/core/neighbour.c
98302@@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98303 void __user *buffer, size_t *lenp, loff_t *ppos)
98304 {
98305 int size, ret;
98306- struct ctl_table tmp = *ctl;
98307+ ctl_table_no_const tmp = *ctl;
98308
98309 tmp.extra1 = &zero;
98310 tmp.extra2 = &unres_qlen_max;
98311@@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98312 void __user *buffer,
98313 size_t *lenp, loff_t *ppos)
98314 {
98315- struct ctl_table tmp = *ctl;
98316+ ctl_table_no_const tmp = *ctl;
98317 int ret;
98318
98319 tmp.extra1 = &zero;
98320@@ -3059,11 +3059,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98321 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98322 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98323 } else {
98324+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98325 dev_name_source = "default";
98326- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98327- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98328- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98329- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98330+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98331+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98332+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98333+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98334 }
98335
98336 if (handler) {
98337diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98338index 2bf8329..2eb1423 100644
98339--- a/net/core/net-procfs.c
98340+++ b/net/core/net-procfs.c
98341@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98342 struct rtnl_link_stats64 temp;
98343 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98344
98345- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98346+ if (gr_proc_is_restricted())
98347+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98348+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98349+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98350+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98351+ else
98352+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98353 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98354 dev->name, stats->rx_bytes, stats->rx_packets,
98355 stats->rx_errors,
98356@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98357 return 0;
98358 }
98359
98360-static const struct seq_operations dev_seq_ops = {
98361+const struct seq_operations dev_seq_ops = {
98362 .start = dev_seq_start,
98363 .next = dev_seq_next,
98364 .stop = dev_seq_stop,
98365@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98366
98367 static int softnet_seq_open(struct inode *inode, struct file *file)
98368 {
98369- return seq_open(file, &softnet_seq_ops);
98370+ return seq_open_restrict(file, &softnet_seq_ops);
98371 }
98372
98373 static const struct file_operations softnet_seq_fops = {
98374@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98375 else
98376 seq_printf(seq, "%04x", ntohs(pt->type));
98377
98378+#ifdef CONFIG_GRKERNSEC_HIDESYM
98379+ seq_printf(seq, " %-8s %pf\n",
98380+ pt->dev ? pt->dev->name : "", NULL);
98381+#else
98382 seq_printf(seq, " %-8s %pf\n",
98383 pt->dev ? pt->dev->name : "", pt->func);
98384+#endif
98385 }
98386
98387 return 0;
98388diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
98389index 1cac29e..fb482f3 100644
98390--- a/net/core/net-sysfs.c
98391+++ b/net/core/net-sysfs.c
98392@@ -259,7 +259,7 @@ static ssize_t carrier_changes_show(struct device *dev,
98393 {
98394 struct net_device *netdev = to_net_dev(dev);
98395 return sprintf(buf, fmt_dec,
98396- atomic_read(&netdev->carrier_changes));
98397+ atomic_read_unchecked(&netdev->carrier_changes));
98398 }
98399 static DEVICE_ATTR_RO(carrier_changes);
98400
98401diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
98402index 7c8ffd9..0cb3687 100644
98403--- a/net/core/net_namespace.c
98404+++ b/net/core/net_namespace.c
98405@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
98406 int error;
98407 LIST_HEAD(net_exit_list);
98408
98409- list_add_tail(&ops->list, list);
98410+ pax_list_add_tail((struct list_head *)&ops->list, list);
98411 if (ops->init || (ops->id && ops->size)) {
98412 for_each_net(net) {
98413 error = ops_init(ops, net);
98414@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
98415
98416 out_undo:
98417 /* If I have an error cleanup all namespaces I initialized */
98418- list_del(&ops->list);
98419+ pax_list_del((struct list_head *)&ops->list);
98420 ops_exit_list(ops, &net_exit_list);
98421 ops_free_list(ops, &net_exit_list);
98422 return error;
98423@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
98424 struct net *net;
98425 LIST_HEAD(net_exit_list);
98426
98427- list_del(&ops->list);
98428+ pax_list_del((struct list_head *)&ops->list);
98429 for_each_net(net)
98430 list_add_tail(&net->exit_list, &net_exit_list);
98431 ops_exit_list(ops, &net_exit_list);
98432@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
98433 mutex_lock(&net_mutex);
98434 error = register_pernet_operations(&pernet_list, ops);
98435 if (!error && (first_device == &pernet_list))
98436- first_device = &ops->list;
98437+ first_device = (struct list_head *)&ops->list;
98438 mutex_unlock(&net_mutex);
98439 return error;
98440 }
98441diff --git a/net/core/netpoll.c b/net/core/netpoll.c
98442index e33937f..b2b4981 100644
98443--- a/net/core/netpoll.c
98444+++ b/net/core/netpoll.c
98445@@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98446 struct udphdr *udph;
98447 struct iphdr *iph;
98448 struct ethhdr *eth;
98449- static atomic_t ip_ident;
98450+ static atomic_unchecked_t ip_ident;
98451 struct ipv6hdr *ip6h;
98452
98453 udp_len = len + sizeof(*udph);
98454@@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98455 put_unaligned(0x45, (unsigned char *)iph);
98456 iph->tos = 0;
98457 put_unaligned(htons(ip_len), &(iph->tot_len));
98458- iph->id = htons(atomic_inc_return(&ip_ident));
98459+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
98460 iph->frag_off = 0;
98461 iph->ttl = 64;
98462 iph->protocol = IPPROTO_UDP;
98463diff --git a/net/core/pktgen.c b/net/core/pktgen.c
98464index 0304f98..ddfead6 100644
98465--- a/net/core/pktgen.c
98466+++ b/net/core/pktgen.c
98467@@ -3725,7 +3725,7 @@ static int __net_init pg_net_init(struct net *net)
98468 pn->net = net;
98469 INIT_LIST_HEAD(&pn->pktgen_threads);
98470 pn->pktgen_exiting = false;
98471- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
98472+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
98473 if (!pn->proc_dir) {
98474 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
98475 return -ENODEV;
98476diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
98477index 1999ed8..1e6e58a 100644
98478--- a/net/core/rtnetlink.c
98479+++ b/net/core/rtnetlink.c
98480@@ -58,7 +58,7 @@ struct rtnl_link {
98481 rtnl_doit_func doit;
98482 rtnl_dumpit_func dumpit;
98483 rtnl_calcit_func calcit;
98484-};
98485+} __no_const;
98486
98487 static DEFINE_MUTEX(rtnl_mutex);
98488
98489@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
98490 if (rtnl_link_ops_get(ops->kind))
98491 return -EEXIST;
98492
98493- if (!ops->dellink)
98494- ops->dellink = unregister_netdevice_queue;
98495+ if (!ops->dellink) {
98496+ pax_open_kernel();
98497+ *(void **)&ops->dellink = unregister_netdevice_queue;
98498+ pax_close_kernel();
98499+ }
98500
98501- list_add_tail(&ops->list, &link_ops);
98502+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
98503 return 0;
98504 }
98505 EXPORT_SYMBOL_GPL(__rtnl_link_register);
98506@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
98507 for_each_net(net) {
98508 __rtnl_kill_links(net, ops);
98509 }
98510- list_del(&ops->list);
98511+ pax_list_del((struct list_head *)&ops->list);
98512 }
98513 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
98514
98515@@ -1008,7 +1011,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
98516 (dev->ifalias &&
98517 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
98518 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
98519- atomic_read(&dev->carrier_changes)))
98520+ atomic_read_unchecked(&dev->carrier_changes)))
98521 goto nla_put_failure;
98522
98523 if (1) {
98524diff --git a/net/core/scm.c b/net/core/scm.c
98525index b442e7e..6f5b5a2 100644
98526--- a/net/core/scm.c
98527+++ b/net/core/scm.c
98528@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
98529 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98530 {
98531 struct cmsghdr __user *cm
98532- = (__force struct cmsghdr __user *)msg->msg_control;
98533+ = (struct cmsghdr __force_user *)msg->msg_control;
98534 struct cmsghdr cmhdr;
98535 int cmlen = CMSG_LEN(len);
98536 int err;
98537@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98538 err = -EFAULT;
98539 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
98540 goto out;
98541- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
98542+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
98543 goto out;
98544 cmlen = CMSG_SPACE(len);
98545 if (msg->msg_controllen < cmlen)
98546@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
98547 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98548 {
98549 struct cmsghdr __user *cm
98550- = (__force struct cmsghdr __user*)msg->msg_control;
98551+ = (struct cmsghdr __force_user *)msg->msg_control;
98552
98553 int fdmax = 0;
98554 int fdnum = scm->fp->count;
98555@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98556 if (fdnum < fdmax)
98557 fdmax = fdnum;
98558
98559- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
98560+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
98561 i++, cmfptr++)
98562 {
98563 struct socket *sock;
98564diff --git a/net/core/skbuff.c b/net/core/skbuff.c
98565index 8383b2b..6397efb 100644
98566--- a/net/core/skbuff.c
98567+++ b/net/core/skbuff.c
98568@@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
98569 __wsum skb_checksum(const struct sk_buff *skb, int offset,
98570 int len, __wsum csum)
98571 {
98572- const struct skb_checksum_ops ops = {
98573+ static const struct skb_checksum_ops ops = {
98574 .update = csum_partial_ext,
98575 .combine = csum_block_add_ext,
98576 };
98577@@ -3220,13 +3220,15 @@ void __init skb_init(void)
98578 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
98579 sizeof(struct sk_buff),
98580 0,
98581- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98582+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98583+ SLAB_NO_SANITIZE,
98584 NULL);
98585 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
98586 (2*sizeof(struct sk_buff)) +
98587 sizeof(atomic_t),
98588 0,
98589- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98590+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98591+ SLAB_NO_SANITIZE,
98592 NULL);
98593 }
98594
98595diff --git a/net/core/sock.c b/net/core/sock.c
98596index 664ee42..aaf9e6e 100644
98597--- a/net/core/sock.c
98598+++ b/net/core/sock.c
98599@@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98600 struct sk_buff_head *list = &sk->sk_receive_queue;
98601
98602 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
98603- atomic_inc(&sk->sk_drops);
98604+ atomic_inc_unchecked(&sk->sk_drops);
98605 trace_sock_rcvqueue_full(sk, skb);
98606 return -ENOMEM;
98607 }
98608@@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98609 return err;
98610
98611 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
98612- atomic_inc(&sk->sk_drops);
98613+ atomic_inc_unchecked(&sk->sk_drops);
98614 return -ENOBUFS;
98615 }
98616
98617@@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98618 skb_dst_force(skb);
98619
98620 spin_lock_irqsave(&list->lock, flags);
98621- skb->dropcount = atomic_read(&sk->sk_drops);
98622+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
98623 __skb_queue_tail(list, skb);
98624 spin_unlock_irqrestore(&list->lock, flags);
98625
98626@@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98627 skb->dev = NULL;
98628
98629 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
98630- atomic_inc(&sk->sk_drops);
98631+ atomic_inc_unchecked(&sk->sk_drops);
98632 goto discard_and_relse;
98633 }
98634 if (nested)
98635@@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98636 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
98637 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
98638 bh_unlock_sock(sk);
98639- atomic_inc(&sk->sk_drops);
98640+ atomic_inc_unchecked(&sk->sk_drops);
98641 goto discard_and_relse;
98642 }
98643
98644@@ -998,12 +998,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98645 struct timeval tm;
98646 } v;
98647
98648- int lv = sizeof(int);
98649- int len;
98650+ unsigned int lv = sizeof(int);
98651+ unsigned int len;
98652
98653 if (get_user(len, optlen))
98654 return -EFAULT;
98655- if (len < 0)
98656+ if (len > INT_MAX)
98657 return -EINVAL;
98658
98659 memset(&v, 0, sizeof(v));
98660@@ -1155,11 +1155,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98661
98662 case SO_PEERNAME:
98663 {
98664- char address[128];
98665+ char address[_K_SS_MAXSIZE];
98666
98667 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
98668 return -ENOTCONN;
98669- if (lv < len)
98670+ if (lv < len || sizeof address < len)
98671 return -EINVAL;
98672 if (copy_to_user(optval, address, len))
98673 return -EFAULT;
98674@@ -1240,7 +1240,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98675
98676 if (len > lv)
98677 len = lv;
98678- if (copy_to_user(optval, &v, len))
98679+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
98680 return -EFAULT;
98681 lenout:
98682 if (put_user(len, optlen))
98683@@ -2375,7 +2375,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
98684 */
98685 smp_wmb();
98686 atomic_set(&sk->sk_refcnt, 1);
98687- atomic_set(&sk->sk_drops, 0);
98688+ atomic_set_unchecked(&sk->sk_drops, 0);
98689 }
98690 EXPORT_SYMBOL(sock_init_data);
98691
98692@@ -2503,6 +2503,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
98693 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98694 int level, int type)
98695 {
98696+ struct sock_extended_err ee;
98697 struct sock_exterr_skb *serr;
98698 struct sk_buff *skb, *skb2;
98699 int copied, err;
98700@@ -2524,7 +2525,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98701 sock_recv_timestamp(msg, sk, skb);
98702
98703 serr = SKB_EXT_ERR(skb);
98704- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
98705+ ee = serr->ee;
98706+ put_cmsg(msg, level, type, sizeof ee, &ee);
98707
98708 msg->msg_flags |= MSG_ERRQUEUE;
98709 err = copied;
98710diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
98711index a4216a4..1c07687 100644
98712--- a/net/core/sock_diag.c
98713+++ b/net/core/sock_diag.c
98714@@ -9,26 +9,33 @@
98715 #include <linux/inet_diag.h>
98716 #include <linux/sock_diag.h>
98717
98718-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
98719+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
98720 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
98721 static DEFINE_MUTEX(sock_diag_table_mutex);
98722
98723 int sock_diag_check_cookie(void *sk, __u32 *cookie)
98724 {
98725+#ifndef CONFIG_GRKERNSEC_HIDESYM
98726 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
98727 cookie[1] != INET_DIAG_NOCOOKIE) &&
98728 ((u32)(unsigned long)sk != cookie[0] ||
98729 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
98730 return -ESTALE;
98731 else
98732+#endif
98733 return 0;
98734 }
98735 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
98736
98737 void sock_diag_save_cookie(void *sk, __u32 *cookie)
98738 {
98739+#ifdef CONFIG_GRKERNSEC_HIDESYM
98740+ cookie[0] = 0;
98741+ cookie[1] = 0;
98742+#else
98743 cookie[0] = (u32)(unsigned long)sk;
98744 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
98745+#endif
98746 }
98747 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
98748
98749@@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
98750 mutex_lock(&sock_diag_table_mutex);
98751 if (sock_diag_handlers[hndl->family])
98752 err = -EBUSY;
98753- else
98754+ else {
98755+ pax_open_kernel();
98756 sock_diag_handlers[hndl->family] = hndl;
98757+ pax_close_kernel();
98758+ }
98759 mutex_unlock(&sock_diag_table_mutex);
98760
98761 return err;
98762@@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
98763
98764 mutex_lock(&sock_diag_table_mutex);
98765 BUG_ON(sock_diag_handlers[family] != hnld);
98766+ pax_open_kernel();
98767 sock_diag_handlers[family] = NULL;
98768+ pax_close_kernel();
98769 mutex_unlock(&sock_diag_table_mutex);
98770 }
98771 EXPORT_SYMBOL_GPL(sock_diag_unregister);
98772diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
98773index cf9cd13..8b56af3 100644
98774--- a/net/core/sysctl_net_core.c
98775+++ b/net/core/sysctl_net_core.c
98776@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
98777 {
98778 unsigned int orig_size, size;
98779 int ret, i;
98780- struct ctl_table tmp = {
98781+ ctl_table_no_const tmp = {
98782 .data = &size,
98783 .maxlen = sizeof(size),
98784 .mode = table->mode
98785@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
98786 void __user *buffer, size_t *lenp, loff_t *ppos)
98787 {
98788 char id[IFNAMSIZ];
98789- struct ctl_table tbl = {
98790+ ctl_table_no_const tbl = {
98791 .data = id,
98792 .maxlen = IFNAMSIZ,
98793 };
98794@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
98795
98796 static __net_init int sysctl_core_net_init(struct net *net)
98797 {
98798- struct ctl_table *tbl;
98799+ ctl_table_no_const *tbl = NULL;
98800
98801 net->core.sysctl_somaxconn = SOMAXCONN;
98802
98803- tbl = netns_core_table;
98804 if (!net_eq(net, &init_net)) {
98805- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
98806+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
98807 if (tbl == NULL)
98808 goto err_dup;
98809
98810@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
98811 if (net->user_ns != &init_user_ns) {
98812 tbl[0].procname = NULL;
98813 }
98814- }
98815-
98816- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98817+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98818+ } else
98819+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
98820 if (net->core.sysctl_hdr == NULL)
98821 goto err_reg;
98822
98823 return 0;
98824
98825 err_reg:
98826- if (tbl != netns_core_table)
98827- kfree(tbl);
98828+ kfree(tbl);
98829 err_dup:
98830 return -ENOMEM;
98831 }
98832@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
98833 kfree(tbl);
98834 }
98835
98836-static __net_initdata struct pernet_operations sysctl_core_ops = {
98837+static __net_initconst struct pernet_operations sysctl_core_ops = {
98838 .init = sysctl_core_net_init,
98839 .exit = sysctl_core_net_exit,
98840 };
98841diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
98842index 4c04848..f575934 100644
98843--- a/net/decnet/af_decnet.c
98844+++ b/net/decnet/af_decnet.c
98845@@ -465,6 +465,7 @@ static struct proto dn_proto = {
98846 .sysctl_rmem = sysctl_decnet_rmem,
98847 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
98848 .obj_size = sizeof(struct dn_sock),
98849+ .slab_flags = SLAB_USERCOPY,
98850 };
98851
98852 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
98853diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
98854index 3b726f3..1af6368 100644
98855--- a/net/decnet/dn_dev.c
98856+++ b/net/decnet/dn_dev.c
98857@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
98858 .extra1 = &min_t3,
98859 .extra2 = &max_t3
98860 },
98861- {0}
98862+ { }
98863 },
98864 };
98865
98866diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
98867index 5325b54..a0d4d69 100644
98868--- a/net/decnet/sysctl_net_decnet.c
98869+++ b/net/decnet/sysctl_net_decnet.c
98870@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
98871
98872 if (len > *lenp) len = *lenp;
98873
98874- if (copy_to_user(buffer, addr, len))
98875+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
98876 return -EFAULT;
98877
98878 *lenp = len;
98879@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
98880
98881 if (len > *lenp) len = *lenp;
98882
98883- if (copy_to_user(buffer, devname, len))
98884+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
98885 return -EFAULT;
98886
98887 *lenp = len;
98888diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
98889index ef2d543..5b9b73f 100644
98890--- a/net/ieee802154/reassembly.c
98891+++ b/net/ieee802154/reassembly.c
98892@@ -434,12 +434,11 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
98893
98894 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
98895 {
98896- struct ctl_table *table;
98897+ ctl_table_no_const *table = NULL;
98898 struct ctl_table_header *hdr;
98899
98900- table = lowpan_frags_ns_ctl_table;
98901 if (!net_eq(net, &init_net)) {
98902- table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
98903+ table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
98904 GFP_KERNEL);
98905 if (table == NULL)
98906 goto err_alloc;
98907@@ -452,9 +451,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
98908 /* Don't export sysctls to unprivileged users */
98909 if (net->user_ns != &init_user_ns)
98910 table[0].procname = NULL;
98911- }
98912-
98913- hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
98914+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
98915+ } else
98916+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
98917 if (hdr == NULL)
98918 goto err_reg;
98919
98920@@ -462,8 +461,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
98921 return 0;
98922
98923 err_reg:
98924- if (!net_eq(net, &init_net))
98925- kfree(table);
98926+ kfree(table);
98927 err_alloc:
98928 return -ENOMEM;
98929 }
98930diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
98931index 6d6dd34..e5c9bec 100644
98932--- a/net/ipv4/af_inet.c
98933+++ b/net/ipv4/af_inet.c
98934@@ -1736,13 +1736,9 @@ static int __init inet_init(void)
98935
98936 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
98937
98938- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
98939- if (!sysctl_local_reserved_ports)
98940- goto out;
98941-
98942 rc = proto_register(&tcp_prot, 1);
98943 if (rc)
98944- goto out_free_reserved_ports;
98945+ goto out;
98946
98947 rc = proto_register(&udp_prot, 1);
98948 if (rc)
98949@@ -1852,8 +1848,6 @@ out_unregister_udp_proto:
98950 proto_unregister(&udp_prot);
98951 out_unregister_tcp_proto:
98952 proto_unregister(&tcp_prot);
98953-out_free_reserved_ports:
98954- kfree(sysctl_local_reserved_ports);
98955 goto out;
98956 }
98957
98958diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
98959index bdbf68b..deb4759 100644
98960--- a/net/ipv4/devinet.c
98961+++ b/net/ipv4/devinet.c
98962@@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
98963 idx = 0;
98964 head = &net->dev_index_head[h];
98965 rcu_read_lock();
98966- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98967+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98968 net->dev_base_seq;
98969 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98970 if (idx < s_idx)
98971@@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
98972 idx = 0;
98973 head = &net->dev_index_head[h];
98974 rcu_read_lock();
98975- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
98976+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
98977 net->dev_base_seq;
98978 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98979 if (idx < s_idx)
98980@@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
98981 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
98982 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
98983
98984-static struct devinet_sysctl_table {
98985+static const struct devinet_sysctl_table {
98986 struct ctl_table_header *sysctl_header;
98987 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
98988 } devinet_sysctl = {
98989@@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
98990 int err;
98991 struct ipv4_devconf *all, *dflt;
98992 #ifdef CONFIG_SYSCTL
98993- struct ctl_table *tbl = ctl_forward_entry;
98994+ ctl_table_no_const *tbl = NULL;
98995 struct ctl_table_header *forw_hdr;
98996 #endif
98997
98998@@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
98999 goto err_alloc_dflt;
99000
99001 #ifdef CONFIG_SYSCTL
99002- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
99003+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
99004 if (tbl == NULL)
99005 goto err_alloc_ctl;
99006
99007@@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
99008 goto err_reg_dflt;
99009
99010 err = -ENOMEM;
99011- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99012+ if (!net_eq(net, &init_net))
99013+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99014+ else
99015+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
99016 if (forw_hdr == NULL)
99017 goto err_reg_ctl;
99018 net->ipv4.forw_hdr = forw_hdr;
99019@@ -2272,8 +2275,7 @@ err_reg_ctl:
99020 err_reg_dflt:
99021 __devinet_sysctl_unregister(all);
99022 err_reg_all:
99023- if (tbl != ctl_forward_entry)
99024- kfree(tbl);
99025+ kfree(tbl);
99026 err_alloc_ctl:
99027 #endif
99028 if (dflt != &ipv4_devconf_dflt)
99029diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
99030index 255aa99..45c78f8 100644
99031--- a/net/ipv4/fib_frontend.c
99032+++ b/net/ipv4/fib_frontend.c
99033@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
99034 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99035 fib_sync_up(dev);
99036 #endif
99037- atomic_inc(&net->ipv4.dev_addr_genid);
99038+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99039 rt_cache_flush(dev_net(dev));
99040 break;
99041 case NETDEV_DOWN:
99042 fib_del_ifaddr(ifa, NULL);
99043- atomic_inc(&net->ipv4.dev_addr_genid);
99044+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99045 if (ifa->ifa_dev->ifa_list == NULL) {
99046 /* Last address was deleted from this interface.
99047 * Disable IP.
99048@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
99049 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99050 fib_sync_up(dev);
99051 #endif
99052- atomic_inc(&net->ipv4.dev_addr_genid);
99053+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99054 rt_cache_flush(net);
99055 break;
99056 case NETDEV_DOWN:
99057diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
99058index b10cd43a..22327f9 100644
99059--- a/net/ipv4/fib_semantics.c
99060+++ b/net/ipv4/fib_semantics.c
99061@@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
99062 nh->nh_saddr = inet_select_addr(nh->nh_dev,
99063 nh->nh_gw,
99064 nh->nh_parent->fib_scope);
99065- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
99066+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
99067
99068 return nh->nh_saddr;
99069 }
99070diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
99071index a56b8e6..5be2a30 100644
99072--- a/net/ipv4/inet_connection_sock.c
99073+++ b/net/ipv4/inet_connection_sock.c
99074@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
99075 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
99076 #endif
99077
99078-unsigned long *sysctl_local_reserved_ports;
99079+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
99080 EXPORT_SYMBOL(sysctl_local_reserved_ports);
99081
99082 void inet_get_local_port_range(struct net *net, int *low, int *high)
99083diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
99084index 8b9cf27..0d8d592 100644
99085--- a/net/ipv4/inet_hashtables.c
99086+++ b/net/ipv4/inet_hashtables.c
99087@@ -18,6 +18,7 @@
99088 #include <linux/sched.h>
99089 #include <linux/slab.h>
99090 #include <linux/wait.h>
99091+#include <linux/security.h>
99092
99093 #include <net/inet_connection_sock.h>
99094 #include <net/inet_hashtables.h>
99095@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
99096 return inet_ehashfn(net, laddr, lport, faddr, fport);
99097 }
99098
99099+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
99100+
99101 /*
99102 * Allocate and initialize a new local port bind bucket.
99103 * The bindhash mutex for snum's hash chain must be held here.
99104@@ -554,6 +557,8 @@ ok:
99105 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
99106 spin_unlock(&head->lock);
99107
99108+ gr_update_task_in_ip_table(current, inet_sk(sk));
99109+
99110 if (tw) {
99111 inet_twsk_deschedule(tw, death_row);
99112 while (twrefcnt) {
99113diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
99114index 48f4244..f56d83a 100644
99115--- a/net/ipv4/inetpeer.c
99116+++ b/net/ipv4/inetpeer.c
99117@@ -496,8 +496,8 @@ relookup:
99118 if (p) {
99119 p->daddr = *daddr;
99120 atomic_set(&p->refcnt, 1);
99121- atomic_set(&p->rid, 0);
99122- atomic_set(&p->ip_id_count,
99123+ atomic_set_unchecked(&p->rid, 0);
99124+ atomic_set_unchecked(&p->ip_id_count,
99125 (daddr->family == AF_INET) ?
99126 secure_ip_id(daddr->addr.a4) :
99127 secure_ipv6_id(daddr->addr.a6));
99128diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
99129index ed32313..3762abe 100644
99130--- a/net/ipv4/ip_fragment.c
99131+++ b/net/ipv4/ip_fragment.c
99132@@ -284,7 +284,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
99133 return 0;
99134
99135 start = qp->rid;
99136- end = atomic_inc_return(&peer->rid);
99137+ end = atomic_inc_return_unchecked(&peer->rid);
99138 qp->rid = end;
99139
99140 rc = qp->q.fragments && (end - start) > max;
99141@@ -761,12 +761,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
99142
99143 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99144 {
99145- struct ctl_table *table;
99146+ ctl_table_no_const *table = NULL;
99147 struct ctl_table_header *hdr;
99148
99149- table = ip4_frags_ns_ctl_table;
99150 if (!net_eq(net, &init_net)) {
99151- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99152+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99153 if (table == NULL)
99154 goto err_alloc;
99155
99156@@ -777,9 +776,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99157 /* Don't export sysctls to unprivileged users */
99158 if (net->user_ns != &init_user_ns)
99159 table[0].procname = NULL;
99160- }
99161+ hdr = register_net_sysctl(net, "net/ipv4", table);
99162+ } else
99163+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
99164
99165- hdr = register_net_sysctl(net, "net/ipv4", table);
99166 if (hdr == NULL)
99167 goto err_reg;
99168
99169@@ -787,8 +787,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99170 return 0;
99171
99172 err_reg:
99173- if (!net_eq(net, &init_net))
99174- kfree(table);
99175+ kfree(table);
99176 err_alloc:
99177 return -ENOMEM;
99178 }
99179diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
99180index 94213c8..8bdb342 100644
99181--- a/net/ipv4/ip_gre.c
99182+++ b/net/ipv4/ip_gre.c
99183@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
99184 module_param(log_ecn_error, bool, 0644);
99185 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99186
99187-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
99188+static struct rtnl_link_ops ipgre_link_ops;
99189 static int ipgre_tunnel_init(struct net_device *dev);
99190
99191 static int ipgre_net_id __read_mostly;
99192@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
99193 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
99194 };
99195
99196-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99197+static struct rtnl_link_ops ipgre_link_ops = {
99198 .kind = "gre",
99199 .maxtype = IFLA_GRE_MAX,
99200 .policy = ipgre_policy,
99201@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99202 .fill_info = ipgre_fill_info,
99203 };
99204
99205-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
99206+static struct rtnl_link_ops ipgre_tap_ops = {
99207 .kind = "gretap",
99208 .maxtype = IFLA_GRE_MAX,
99209 .policy = ipgre_policy,
99210diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
99211index 64741b9..6f334a2 100644
99212--- a/net/ipv4/ip_sockglue.c
99213+++ b/net/ipv4/ip_sockglue.c
99214@@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99215 len = min_t(unsigned int, len, opt->optlen);
99216 if (put_user(len, optlen))
99217 return -EFAULT;
99218- if (copy_to_user(optval, opt->__data, len))
99219+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
99220+ copy_to_user(optval, opt->__data, len))
99221 return -EFAULT;
99222 return 0;
99223 }
99224@@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99225 if (sk->sk_type != SOCK_STREAM)
99226 return -ENOPROTOOPT;
99227
99228- msg.msg_control = optval;
99229+ msg.msg_control = (void __force_kernel *)optval;
99230 msg.msg_controllen = len;
99231 msg.msg_flags = flags;
99232
99233diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
99234index 2acc233..b93143f 100644
99235--- a/net/ipv4/ip_tunnel.c
99236+++ b/net/ipv4/ip_tunnel.c
99237@@ -73,12 +73,7 @@ static void __tunnel_dst_set(struct ip_tunnel_dst *idst,
99238 {
99239 struct dst_entry *old_dst;
99240
99241- if (dst) {
99242- if (dst->flags & DST_NOCACHE)
99243- dst = NULL;
99244- else
99245- dst_clone(dst);
99246- }
99247+ dst_clone(dst);
99248 old_dst = xchg((__force struct dst_entry **)&idst->dst, dst);
99249 dst_release(old_dst);
99250 }
99251@@ -108,13 +103,14 @@ static struct rtable *tunnel_rtable_get(struct ip_tunnel *t, u32 cookie)
99252
99253 rcu_read_lock();
99254 dst = rcu_dereference(this_cpu_ptr(t->dst_cache)->dst);
99255+ if (dst && !atomic_inc_not_zero(&dst->__refcnt))
99256+ dst = NULL;
99257 if (dst) {
99258 if (dst->obsolete && dst->ops->check(dst, cookie) == NULL) {
99259- rcu_read_unlock();
99260 tunnel_dst_reset(t);
99261- return NULL;
99262+ dst_release(dst);
99263+ dst = NULL;
99264 }
99265- dst_hold(dst);
99266 }
99267 rcu_read_unlock();
99268 return (struct rtable *)dst;
99269diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
99270index 13ef00f..8ffca25 100644
99271--- a/net/ipv4/ip_vti.c
99272+++ b/net/ipv4/ip_vti.c
99273@@ -45,7 +45,7 @@
99274 #include <net/net_namespace.h>
99275 #include <net/netns/generic.h>
99276
99277-static struct rtnl_link_ops vti_link_ops __read_mostly;
99278+static struct rtnl_link_ops vti_link_ops;
99279
99280 static int vti_net_id __read_mostly;
99281 static int vti_tunnel_init(struct net_device *dev);
99282@@ -513,7 +513,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
99283 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
99284 };
99285
99286-static struct rtnl_link_ops vti_link_ops __read_mostly = {
99287+static struct rtnl_link_ops vti_link_ops = {
99288 .kind = "vti",
99289 .maxtype = IFLA_VTI_MAX,
99290 .policy = vti_policy,
99291diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
99292index b3e86ea..18ce98c 100644
99293--- a/net/ipv4/ipconfig.c
99294+++ b/net/ipv4/ipconfig.c
99295@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
99296
99297 mm_segment_t oldfs = get_fs();
99298 set_fs(get_ds());
99299- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99300+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99301 set_fs(oldfs);
99302 return res;
99303 }
99304@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
99305
99306 mm_segment_t oldfs = get_fs();
99307 set_fs(get_ds());
99308- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99309+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99310 set_fs(oldfs);
99311 return res;
99312 }
99313@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
99314
99315 mm_segment_t oldfs = get_fs();
99316 set_fs(get_ds());
99317- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
99318+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99319 set_fs(oldfs);
99320 return res;
99321 }
99322diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99323index 62eaa00..29b2dc2 100644
99324--- a/net/ipv4/ipip.c
99325+++ b/net/ipv4/ipip.c
99326@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99327 static int ipip_net_id __read_mostly;
99328
99329 static int ipip_tunnel_init(struct net_device *dev);
99330-static struct rtnl_link_ops ipip_link_ops __read_mostly;
99331+static struct rtnl_link_ops ipip_link_ops;
99332
99333 static int ipip_err(struct sk_buff *skb, u32 info)
99334 {
99335@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99336 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99337 };
99338
99339-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99340+static struct rtnl_link_ops ipip_link_ops = {
99341 .kind = "ipip",
99342 .maxtype = IFLA_IPTUN_MAX,
99343 .policy = ipip_policy,
99344diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99345index f95b6f9..2ee2097 100644
99346--- a/net/ipv4/netfilter/arp_tables.c
99347+++ b/net/ipv4/netfilter/arp_tables.c
99348@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99349 #endif
99350
99351 static int get_info(struct net *net, void __user *user,
99352- const int *len, int compat)
99353+ int len, int compat)
99354 {
99355 char name[XT_TABLE_MAXNAMELEN];
99356 struct xt_table *t;
99357 int ret;
99358
99359- if (*len != sizeof(struct arpt_getinfo)) {
99360- duprintf("length %u != %Zu\n", *len,
99361+ if (len != sizeof(struct arpt_getinfo)) {
99362+ duprintf("length %u != %Zu\n", len,
99363 sizeof(struct arpt_getinfo));
99364 return -EINVAL;
99365 }
99366@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99367 info.size = private->size;
99368 strcpy(info.name, name);
99369
99370- if (copy_to_user(user, &info, *len) != 0)
99371+ if (copy_to_user(user, &info, len) != 0)
99372 ret = -EFAULT;
99373 else
99374 ret = 0;
99375@@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99376
99377 switch (cmd) {
99378 case ARPT_SO_GET_INFO:
99379- ret = get_info(sock_net(sk), user, len, 1);
99380+ ret = get_info(sock_net(sk), user, *len, 1);
99381 break;
99382 case ARPT_SO_GET_ENTRIES:
99383 ret = compat_get_entries(sock_net(sk), user, len);
99384@@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99385
99386 switch (cmd) {
99387 case ARPT_SO_GET_INFO:
99388- ret = get_info(sock_net(sk), user, len, 0);
99389+ ret = get_info(sock_net(sk), user, *len, 0);
99390 break;
99391
99392 case ARPT_SO_GET_ENTRIES:
99393diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99394index 99e810f..3711b81 100644
99395--- a/net/ipv4/netfilter/ip_tables.c
99396+++ b/net/ipv4/netfilter/ip_tables.c
99397@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99398 #endif
99399
99400 static int get_info(struct net *net, void __user *user,
99401- const int *len, int compat)
99402+ int len, int compat)
99403 {
99404 char name[XT_TABLE_MAXNAMELEN];
99405 struct xt_table *t;
99406 int ret;
99407
99408- if (*len != sizeof(struct ipt_getinfo)) {
99409- duprintf("length %u != %zu\n", *len,
99410+ if (len != sizeof(struct ipt_getinfo)) {
99411+ duprintf("length %u != %zu\n", len,
99412 sizeof(struct ipt_getinfo));
99413 return -EINVAL;
99414 }
99415@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99416 info.size = private->size;
99417 strcpy(info.name, name);
99418
99419- if (copy_to_user(user, &info, *len) != 0)
99420+ if (copy_to_user(user, &info, len) != 0)
99421 ret = -EFAULT;
99422 else
99423 ret = 0;
99424@@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99425
99426 switch (cmd) {
99427 case IPT_SO_GET_INFO:
99428- ret = get_info(sock_net(sk), user, len, 1);
99429+ ret = get_info(sock_net(sk), user, *len, 1);
99430 break;
99431 case IPT_SO_GET_ENTRIES:
99432 ret = compat_get_entries(sock_net(sk), user, len);
99433@@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99434
99435 switch (cmd) {
99436 case IPT_SO_GET_INFO:
99437- ret = get_info(sock_net(sk), user, len, 0);
99438+ ret = get_info(sock_net(sk), user, *len, 0);
99439 break;
99440
99441 case IPT_SO_GET_ENTRIES:
99442diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99443index 2510c02..cfb34fa 100644
99444--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
99445+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99446@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
99447 spin_lock_init(&cn->lock);
99448
99449 #ifdef CONFIG_PROC_FS
99450- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
99451+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
99452 if (!cn->procdir) {
99453 pr_err("Unable to proc dir entry\n");
99454 return -ENOMEM;
99455diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
99456index 044a0dd..e0c1971 100644
99457--- a/net/ipv4/ping.c
99458+++ b/net/ipv4/ping.c
99459@@ -59,7 +59,7 @@ struct ping_table {
99460 };
99461
99462 static struct ping_table ping_table;
99463-struct pingv6_ops pingv6_ops;
99464+struct pingv6_ops *pingv6_ops;
99465 EXPORT_SYMBOL_GPL(pingv6_ops);
99466
99467 static u16 ping_port_rover;
99468@@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
99469 return -ENODEV;
99470 }
99471 }
99472- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
99473+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
99474 scoped);
99475 rcu_read_unlock();
99476
99477@@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99478 }
99479 #if IS_ENABLED(CONFIG_IPV6)
99480 } else if (skb->protocol == htons(ETH_P_IPV6)) {
99481- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
99482+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
99483 #endif
99484 }
99485
99486@@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99487 info, (u8 *)icmph);
99488 #if IS_ENABLED(CONFIG_IPV6)
99489 } else if (family == AF_INET6) {
99490- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
99491+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
99492 info, (u8 *)icmph);
99493 #endif
99494 }
99495@@ -844,6 +844,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99496 {
99497 struct inet_sock *isk = inet_sk(sk);
99498 int family = sk->sk_family;
99499+ struct sockaddr_in *sin;
99500+ struct sockaddr_in6 *sin6;
99501 struct sk_buff *skb;
99502 int copied, err;
99503
99504@@ -853,12 +855,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99505 if (flags & MSG_OOB)
99506 goto out;
99507
99508+ if (addr_len) {
99509+ if (family == AF_INET)
99510+ *addr_len = sizeof(*sin);
99511+ else if (family == AF_INET6 && addr_len)
99512+ *addr_len = sizeof(*sin6);
99513+ }
99514+
99515 if (flags & MSG_ERRQUEUE) {
99516 if (family == AF_INET) {
99517 return ip_recv_error(sk, msg, len, addr_len);
99518 #if IS_ENABLED(CONFIG_IPV6)
99519 } else if (family == AF_INET6) {
99520- return pingv6_ops.ipv6_recv_error(sk, msg, len,
99521+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
99522 addr_len);
99523 #endif
99524 }
99525@@ -890,7 +899,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99526 sin->sin_port = 0 /* skb->h.uh->source */;
99527 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99528 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99529- *addr_len = sizeof(*sin);
99530 }
99531
99532 if (isk->cmsg_flags)
99533@@ -912,14 +920,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99534 sin6->sin6_scope_id =
99535 ipv6_iface_scope_id(&sin6->sin6_addr,
99536 IP6CB(skb)->iif);
99537- *addr_len = sizeof(*sin6);
99538 }
99539
99540 if (inet6_sk(sk)->rxopt.all)
99541- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
99542+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
99543 if (skb->protocol == htons(ETH_P_IPV6) &&
99544 inet6_sk(sk)->rxopt.all)
99545- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
99546+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
99547 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
99548 ip_cmsg_recv(msg, skb);
99549 #endif
99550@@ -1111,7 +1118,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
99551 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99552 0, sock_i_ino(sp),
99553 atomic_read(&sp->sk_refcnt), sp,
99554- atomic_read(&sp->sk_drops));
99555+ atomic_read_unchecked(&sp->sk_drops));
99556 }
99557
99558 static int ping_v4_seq_show(struct seq_file *seq, void *v)
99559diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
99560index a9dbe58..46f577f 100644
99561--- a/net/ipv4/raw.c
99562+++ b/net/ipv4/raw.c
99563@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
99564 int raw_rcv(struct sock *sk, struct sk_buff *skb)
99565 {
99566 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
99567- atomic_inc(&sk->sk_drops);
99568+ atomic_inc_unchecked(&sk->sk_drops);
99569 kfree_skb(skb);
99570 return NET_RX_DROP;
99571 }
99572@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99573 if (flags & MSG_OOB)
99574 goto out;
99575
99576+ if (addr_len)
99577+ *addr_len = sizeof(*sin);
99578+
99579 if (flags & MSG_ERRQUEUE) {
99580 err = ip_recv_error(sk, msg, len, addr_len);
99581 goto out;
99582@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99583 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99584 sin->sin_port = 0;
99585 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99586- *addr_len = sizeof(*sin);
99587 }
99588 if (inet->cmsg_flags)
99589 ip_cmsg_recv(msg, skb);
99590@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
99591
99592 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
99593 {
99594+ struct icmp_filter filter;
99595+
99596 if (optlen > sizeof(struct icmp_filter))
99597 optlen = sizeof(struct icmp_filter);
99598- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
99599+ if (copy_from_user(&filter, optval, optlen))
99600 return -EFAULT;
99601+ raw_sk(sk)->filter = filter;
99602 return 0;
99603 }
99604
99605 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
99606 {
99607 int len, ret = -EFAULT;
99608+ struct icmp_filter filter;
99609
99610 if (get_user(len, optlen))
99611 goto out;
99612@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
99613 if (len > sizeof(struct icmp_filter))
99614 len = sizeof(struct icmp_filter);
99615 ret = -EFAULT;
99616- if (put_user(len, optlen) ||
99617- copy_to_user(optval, &raw_sk(sk)->filter, len))
99618+ filter = raw_sk(sk)->filter;
99619+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
99620 goto out;
99621 ret = 0;
99622 out: return ret;
99623@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
99624 0, 0L, 0,
99625 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
99626 0, sock_i_ino(sp),
99627- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
99628+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
99629 }
99630
99631 static int raw_seq_show(struct seq_file *seq, void *v)
99632diff --git a/net/ipv4/route.c b/net/ipv4/route.c
99633index 5e676be..f6c62f1 100644
99634--- a/net/ipv4/route.c
99635+++ b/net/ipv4/route.c
99636@@ -227,7 +227,7 @@ static const struct seq_operations rt_cache_seq_ops = {
99637
99638 static int rt_cache_seq_open(struct inode *inode, struct file *file)
99639 {
99640- return seq_open(file, &rt_cache_seq_ops);
99641+ return seq_open_restrict(file, &rt_cache_seq_ops);
99642 }
99643
99644 static const struct file_operations rt_cache_seq_fops = {
99645@@ -318,7 +318,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
99646
99647 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
99648 {
99649- return seq_open(file, &rt_cpu_seq_ops);
99650+ return seq_open_restrict(file, &rt_cpu_seq_ops);
99651 }
99652
99653 static const struct file_operations rt_cpu_seq_fops = {
99654@@ -356,7 +356,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
99655
99656 static int rt_acct_proc_open(struct inode *inode, struct file *file)
99657 {
99658- return single_open(file, rt_acct_proc_show, NULL);
99659+ return single_open_restrict(file, rt_acct_proc_show, NULL);
99660 }
99661
99662 static const struct file_operations rt_acct_proc_fops = {
99663@@ -2610,34 +2610,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
99664 .maxlen = sizeof(int),
99665 .mode = 0200,
99666 .proc_handler = ipv4_sysctl_rtcache_flush,
99667+ .extra1 = &init_net,
99668 },
99669 { },
99670 };
99671
99672 static __net_init int sysctl_route_net_init(struct net *net)
99673 {
99674- struct ctl_table *tbl;
99675+ ctl_table_no_const *tbl = NULL;
99676
99677- tbl = ipv4_route_flush_table;
99678 if (!net_eq(net, &init_net)) {
99679- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99680+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99681 if (tbl == NULL)
99682 goto err_dup;
99683
99684 /* Don't export sysctls to unprivileged users */
99685 if (net->user_ns != &init_user_ns)
99686 tbl[0].procname = NULL;
99687- }
99688- tbl[0].extra1 = net;
99689+ tbl[0].extra1 = net;
99690+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99691+ } else
99692+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
99693
99694- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99695 if (net->ipv4.route_hdr == NULL)
99696 goto err_reg;
99697 return 0;
99698
99699 err_reg:
99700- if (tbl != ipv4_route_flush_table)
99701- kfree(tbl);
99702+ kfree(tbl);
99703 err_dup:
99704 return -ENOMEM;
99705 }
99706@@ -2660,8 +2660,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
99707
99708 static __net_init int rt_genid_init(struct net *net)
99709 {
99710- atomic_set(&net->ipv4.rt_genid, 0);
99711- atomic_set(&net->fnhe_genid, 0);
99712+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
99713+ atomic_set_unchecked(&net->fnhe_genid, 0);
99714 get_random_bytes(&net->ipv4.dev_addr_genid,
99715 sizeof(net->ipv4.dev_addr_genid));
99716 return 0;
99717diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
99718index 5cde8f2..5f5684e 100644
99719--- a/net/ipv4/sysctl_net_ipv4.c
99720+++ b/net/ipv4/sysctl_net_ipv4.c
99721@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
99722 container_of(table->data, struct net, ipv4.ip_local_ports.range);
99723 int ret;
99724 int range[2];
99725- struct ctl_table tmp = {
99726+ ctl_table_no_const tmp = {
99727 .data = &range,
99728 .maxlen = sizeof(range),
99729 .mode = table->mode,
99730@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
99731 int ret;
99732 gid_t urange[2];
99733 kgid_t low, high;
99734- struct ctl_table tmp = {
99735+ ctl_table_no_const tmp = {
99736 .data = &urange,
99737 .maxlen = sizeof(urange),
99738 .mode = table->mode,
99739@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
99740 void __user *buffer, size_t *lenp, loff_t *ppos)
99741 {
99742 char val[TCP_CA_NAME_MAX];
99743- struct ctl_table tbl = {
99744+ ctl_table_no_const tbl = {
99745 .data = val,
99746 .maxlen = TCP_CA_NAME_MAX,
99747 };
99748@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
99749 void __user *buffer, size_t *lenp,
99750 loff_t *ppos)
99751 {
99752- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
99753+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
99754 int ret;
99755
99756 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99757@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
99758 void __user *buffer, size_t *lenp,
99759 loff_t *ppos)
99760 {
99761- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
99762+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
99763 int ret;
99764
99765 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99766@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
99767 void __user *buffer, size_t *lenp,
99768 loff_t *ppos)
99769 {
99770- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99771+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99772 struct tcp_fastopen_context *ctxt;
99773 int ret;
99774 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
99775@@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
99776 },
99777 {
99778 .procname = "ip_local_reserved_ports",
99779- .data = NULL, /* initialized in sysctl_ipv4_init */
99780+ .data = sysctl_local_reserved_ports,
99781 .maxlen = 65536,
99782 .mode = 0644,
99783 .proc_handler = proc_do_large_bitmap,
99784@@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
99785
99786 static __net_init int ipv4_sysctl_init_net(struct net *net)
99787 {
99788- struct ctl_table *table;
99789+ ctl_table_no_const *table = NULL;
99790
99791- table = ipv4_net_table;
99792 if (!net_eq(net, &init_net)) {
99793 int i;
99794
99795- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
99796+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
99797 if (table == NULL)
99798 goto err_alloc;
99799
99800@@ -858,15 +857,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
99801 table[i].data += (void *)net - (void *)&init_net;
99802 }
99803
99804- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99805+ if (!net_eq(net, &init_net))
99806+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99807+ else
99808+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
99809 if (net->ipv4.ipv4_hdr == NULL)
99810 goto err_reg;
99811
99812 return 0;
99813
99814 err_reg:
99815- if (!net_eq(net, &init_net))
99816- kfree(table);
99817+ kfree(table);
99818 err_alloc:
99819 return -ENOMEM;
99820 }
99821@@ -888,16 +889,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
99822 static __init int sysctl_ipv4_init(void)
99823 {
99824 struct ctl_table_header *hdr;
99825- struct ctl_table *i;
99826-
99827- for (i = ipv4_table; i->procname; i++) {
99828- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
99829- i->data = sysctl_local_reserved_ports;
99830- break;
99831- }
99832- }
99833- if (!i->procname)
99834- return -EINVAL;
99835
99836 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
99837 if (hdr == NULL)
99838diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
99839index 3a26b3b..8bbe4ae 100644
99840--- a/net/ipv4/tcp_input.c
99841+++ b/net/ipv4/tcp_input.c
99842@@ -754,7 +754,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
99843 * without any lock. We want to make sure compiler wont store
99844 * intermediate values in this location.
99845 */
99846- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
99847+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
99848 sk->sk_max_pacing_rate);
99849 }
99850
99851@@ -4478,7 +4478,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
99852 * simplifies code)
99853 */
99854 static void
99855-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99856+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
99857 struct sk_buff *head, struct sk_buff *tail,
99858 u32 start, u32 end)
99859 {
99860@@ -5558,6 +5558,7 @@ discard:
99861 tcp_paws_reject(&tp->rx_opt, 0))
99862 goto discard_and_undo;
99863
99864+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
99865 if (th->syn) {
99866 /* We see SYN without ACK. It is attempt of
99867 * simultaneous connect with crossed SYNs.
99868@@ -5608,6 +5609,7 @@ discard:
99869 goto discard;
99870 #endif
99871 }
99872+#endif
99873 /* "fifth, if neither of the SYN or RST bits is set then
99874 * drop the segment and return."
99875 */
99876@@ -5654,7 +5656,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
99877 goto discard;
99878
99879 if (th->syn) {
99880- if (th->fin)
99881+ if (th->fin || th->urg || th->psh)
99882 goto discard;
99883 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
99884 return 1;
99885diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
99886index 438f3b9..bc9e1ad 100644
99887--- a/net/ipv4/tcp_ipv4.c
99888+++ b/net/ipv4/tcp_ipv4.c
99889@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
99890 EXPORT_SYMBOL(sysctl_tcp_low_latency);
99891
99892
99893+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99894+extern int grsec_enable_blackhole;
99895+#endif
99896+
99897 #ifdef CONFIG_TCP_MD5SIG
99898 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
99899 __be32 daddr, __be32 saddr, const struct tcphdr *th);
99900@@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
99901 return 0;
99902
99903 reset:
99904+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99905+ if (!grsec_enable_blackhole)
99906+#endif
99907 tcp_v4_send_reset(rsk, skb);
99908 discard:
99909 kfree_skb(skb);
99910@@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
99911 TCP_SKB_CB(skb)->sacked = 0;
99912
99913 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99914- if (!sk)
99915+ if (!sk) {
99916+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99917+ ret = 1;
99918+#endif
99919 goto no_tcp_socket;
99920-
99921+ }
99922 process:
99923- if (sk->sk_state == TCP_TIME_WAIT)
99924+ if (sk->sk_state == TCP_TIME_WAIT) {
99925+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99926+ ret = 2;
99927+#endif
99928 goto do_time_wait;
99929+ }
99930
99931 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
99932 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99933@@ -2033,6 +2047,10 @@ csum_error:
99934 bad_packet:
99935 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99936 } else {
99937+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99938+ if (!grsec_enable_blackhole || (ret == 1 &&
99939+ (skb->dev->flags & IFF_LOOPBACK)))
99940+#endif
99941 tcp_v4_send_reset(NULL, skb);
99942 }
99943
99944diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
99945index 05c1b15..3e9344b 100644
99946--- a/net/ipv4/tcp_minisocks.c
99947+++ b/net/ipv4/tcp_minisocks.c
99948@@ -27,6 +27,10 @@
99949 #include <net/inet_common.h>
99950 #include <net/xfrm.h>
99951
99952+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99953+extern int grsec_enable_blackhole;
99954+#endif
99955+
99956 int sysctl_tcp_syncookies __read_mostly = 1;
99957 EXPORT_SYMBOL(sysctl_tcp_syncookies);
99958
99959@@ -709,7 +713,10 @@ embryonic_reset:
99960 * avoid becoming vulnerable to outside attack aiming at
99961 * resetting legit local connections.
99962 */
99963- req->rsk_ops->send_reset(sk, skb);
99964+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99965+ if (!grsec_enable_blackhole)
99966+#endif
99967+ req->rsk_ops->send_reset(sk, skb);
99968 } else if (fastopen) { /* received a valid RST pkt */
99969 reqsk_fastopen_remove(sk, req, true);
99970 tcp_reset(sk);
99971diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
99972index 3b66610..bfbe23a 100644
99973--- a/net/ipv4/tcp_probe.c
99974+++ b/net/ipv4/tcp_probe.c
99975@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
99976 if (cnt + width >= len)
99977 break;
99978
99979- if (copy_to_user(buf + cnt, tbuf, width))
99980+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
99981 return -EFAULT;
99982 cnt += width;
99983 }
99984diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
99985index 286227a..c495a76 100644
99986--- a/net/ipv4/tcp_timer.c
99987+++ b/net/ipv4/tcp_timer.c
99988@@ -22,6 +22,10 @@
99989 #include <linux/gfp.h>
99990 #include <net/tcp.h>
99991
99992+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99993+extern int grsec_lastack_retries;
99994+#endif
99995+
99996 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
99997 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
99998 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
99999@@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
100000 }
100001 }
100002
100003+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100004+ if ((sk->sk_state == TCP_LAST_ACK) &&
100005+ (grsec_lastack_retries > 0) &&
100006+ (grsec_lastack_retries < retry_until))
100007+ retry_until = grsec_lastack_retries;
100008+#endif
100009+
100010 if (retransmits_timed_out(sk, retry_until,
100011 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
100012 /* Has it gone just too far? */
100013diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
100014index 54a5fe9..78fea00 100644
100015--- a/net/ipv4/udp.c
100016+++ b/net/ipv4/udp.c
100017@@ -87,6 +87,7 @@
100018 #include <linux/types.h>
100019 #include <linux/fcntl.h>
100020 #include <linux/module.h>
100021+#include <linux/security.h>
100022 #include <linux/socket.h>
100023 #include <linux/sockios.h>
100024 #include <linux/igmp.h>
100025@@ -113,6 +114,10 @@
100026 #include <net/busy_poll.h>
100027 #include "udp_impl.h"
100028
100029+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100030+extern int grsec_enable_blackhole;
100031+#endif
100032+
100033 struct udp_table udp_table __read_mostly;
100034 EXPORT_SYMBOL(udp_table);
100035
100036@@ -615,6 +620,9 @@ found:
100037 return s;
100038 }
100039
100040+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
100041+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
100042+
100043 /*
100044 * This routine is called by the ICMP module when it gets some
100045 * sort of error condition. If err < 0 then the socket should
100046@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100047 dport = usin->sin_port;
100048 if (dport == 0)
100049 return -EINVAL;
100050+
100051+ err = gr_search_udp_sendmsg(sk, usin);
100052+ if (err)
100053+ return err;
100054 } else {
100055 if (sk->sk_state != TCP_ESTABLISHED)
100056 return -EDESTADDRREQ;
100057+
100058+ err = gr_search_udp_sendmsg(sk, NULL);
100059+ if (err)
100060+ return err;
100061+
100062 daddr = inet->inet_daddr;
100063 dport = inet->inet_dport;
100064 /* Open fast path for connected socket.
100065@@ -1164,7 +1181,7 @@ static unsigned int first_packet_length(struct sock *sk)
100066 IS_UDPLITE(sk));
100067 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100068 IS_UDPLITE(sk));
100069- atomic_inc(&sk->sk_drops);
100070+ atomic_inc_unchecked(&sk->sk_drops);
100071 __skb_unlink(skb, rcvq);
100072 __skb_queue_tail(&list_kill, skb);
100073 }
100074@@ -1235,6 +1252,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100075 int is_udplite = IS_UDPLITE(sk);
100076 bool slow;
100077
100078+ /*
100079+ * Check any passed addresses
100080+ */
100081+ if (addr_len)
100082+ *addr_len = sizeof(*sin);
100083+
100084 if (flags & MSG_ERRQUEUE)
100085 return ip_recv_error(sk, msg, len, addr_len);
100086
100087@@ -1244,6 +1267,10 @@ try_again:
100088 if (!skb)
100089 goto out;
100090
100091+ err = gr_search_udp_recvmsg(sk, skb);
100092+ if (err)
100093+ goto out_free;
100094+
100095 ulen = skb->len - sizeof(struct udphdr);
100096 copied = len;
100097 if (copied > ulen)
100098@@ -1277,7 +1304,7 @@ try_again:
100099 if (unlikely(err)) {
100100 trace_kfree_skb(skb, udp_recvmsg);
100101 if (!peeked) {
100102- atomic_inc(&sk->sk_drops);
100103+ atomic_inc_unchecked(&sk->sk_drops);
100104 UDP_INC_STATS_USER(sock_net(sk),
100105 UDP_MIB_INERRORS, is_udplite);
100106 }
100107@@ -1296,7 +1323,6 @@ try_again:
100108 sin->sin_port = udp_hdr(skb)->source;
100109 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100110 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
100111- *addr_len = sizeof(*sin);
100112 }
100113 if (inet->cmsg_flags)
100114 ip_cmsg_recv(msg, skb);
100115@@ -1567,7 +1593,7 @@ csum_error:
100116 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100117 drop:
100118 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100119- atomic_inc(&sk->sk_drops);
100120+ atomic_inc_unchecked(&sk->sk_drops);
100121 kfree_skb(skb);
100122 return -1;
100123 }
100124@@ -1586,7 +1612,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100125 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100126
100127 if (!skb1) {
100128- atomic_inc(&sk->sk_drops);
100129+ atomic_inc_unchecked(&sk->sk_drops);
100130 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100131 IS_UDPLITE(sk));
100132 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100133@@ -1787,6 +1813,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100134 goto csum_error;
100135
100136 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100137+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100138+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100139+#endif
100140 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
100141
100142 /*
100143@@ -2355,7 +2384,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
100144 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
100145 0, sock_i_ino(sp),
100146 atomic_read(&sp->sk_refcnt), sp,
100147- atomic_read(&sp->sk_drops));
100148+ atomic_read_unchecked(&sp->sk_drops));
100149 }
100150
100151 int udp4_seq_show(struct seq_file *seq, void *v)
100152diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
100153index 6156f68..d6ab46d 100644
100154--- a/net/ipv4/xfrm4_policy.c
100155+++ b/net/ipv4/xfrm4_policy.c
100156@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
100157 fl4->flowi4_tos = iph->tos;
100158 }
100159
100160-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
100161+static int xfrm4_garbage_collect(struct dst_ops *ops)
100162 {
100163 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
100164
100165- xfrm4_policy_afinfo.garbage_collect(net);
100166+ xfrm_garbage_collect_deferred(net);
100167 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
100168 }
100169
100170@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
100171
100172 static int __net_init xfrm4_net_init(struct net *net)
100173 {
100174- struct ctl_table *table;
100175+ ctl_table_no_const *table = NULL;
100176 struct ctl_table_header *hdr;
100177
100178- table = xfrm4_policy_table;
100179 if (!net_eq(net, &init_net)) {
100180- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100181+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100182 if (!table)
100183 goto err_alloc;
100184
100185 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
100186- }
100187-
100188- hdr = register_net_sysctl(net, "net/ipv4", table);
100189+ hdr = register_net_sysctl(net, "net/ipv4", table);
100190+ } else
100191+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
100192 if (!hdr)
100193 goto err_reg;
100194
100195@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
100196 return 0;
100197
100198 err_reg:
100199- if (!net_eq(net, &init_net))
100200- kfree(table);
100201+ kfree(table);
100202 err_alloc:
100203 return -ENOMEM;
100204 }
100205diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
100206index 6c7fa08..8a31430 100644
100207--- a/net/ipv6/addrconf.c
100208+++ b/net/ipv6/addrconf.c
100209@@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
100210 idx = 0;
100211 head = &net->dev_index_head[h];
100212 rcu_read_lock();
100213- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
100214+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
100215 net->dev_base_seq;
100216 hlist_for_each_entry_rcu(dev, head, index_hlist) {
100217 if (idx < s_idx)
100218@@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
100219 p.iph.ihl = 5;
100220 p.iph.protocol = IPPROTO_IPV6;
100221 p.iph.ttl = 64;
100222- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
100223+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
100224
100225 if (ops->ndo_do_ioctl) {
100226 mm_segment_t oldfs = get_fs();
100227@@ -3528,16 +3528,23 @@ static const struct file_operations if6_fops = {
100228 .release = seq_release_net,
100229 };
100230
100231+extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
100232+extern void unregister_ipv6_seq_ops_addr(void);
100233+
100234 static int __net_init if6_proc_net_init(struct net *net)
100235 {
100236- if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
100237+ register_ipv6_seq_ops_addr(&if6_seq_ops);
100238+ if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
100239+ unregister_ipv6_seq_ops_addr();
100240 return -ENOMEM;
100241+ }
100242 return 0;
100243 }
100244
100245 static void __net_exit if6_proc_net_exit(struct net *net)
100246 {
100247 remove_proc_entry("if_inet6", net->proc_net);
100248+ unregister_ipv6_seq_ops_addr();
100249 }
100250
100251 static struct pernet_operations if6_proc_net_ops = {
100252@@ -4146,7 +4153,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
100253 s_ip_idx = ip_idx = cb->args[2];
100254
100255 rcu_read_lock();
100256- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100257+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100258 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
100259 idx = 0;
100260 head = &net->dev_index_head[h];
100261@@ -4758,7 +4765,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
100262 dst_free(&ifp->rt->dst);
100263 break;
100264 }
100265- atomic_inc(&net->ipv6.dev_addr_genid);
100266+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
100267 rt_genid_bump_ipv6(net);
100268 }
100269
100270@@ -4779,7 +4786,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
100271 int *valp = ctl->data;
100272 int val = *valp;
100273 loff_t pos = *ppos;
100274- struct ctl_table lctl;
100275+ ctl_table_no_const lctl;
100276 int ret;
100277
100278 /*
100279@@ -4864,7 +4871,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
100280 int *valp = ctl->data;
100281 int val = *valp;
100282 loff_t pos = *ppos;
100283- struct ctl_table lctl;
100284+ ctl_table_no_const lctl;
100285 int ret;
100286
100287 /*
100288diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
100289index d935889..2f64330 100644
100290--- a/net/ipv6/af_inet6.c
100291+++ b/net/ipv6/af_inet6.c
100292@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
100293 net->ipv6.sysctl.bindv6only = 0;
100294 net->ipv6.sysctl.icmpv6_time = 1*HZ;
100295 net->ipv6.sysctl.flowlabel_consistency = 1;
100296- atomic_set(&net->ipv6.rt_genid, 0);
100297+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
100298
100299 err = ipv6_init_mibs(net);
100300 if (err)
100301diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
100302index c3bf2d2..1f00573 100644
100303--- a/net/ipv6/datagram.c
100304+++ b/net/ipv6/datagram.c
100305@@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
100306 0,
100307 sock_i_ino(sp),
100308 atomic_read(&sp->sk_refcnt), sp,
100309- atomic_read(&sp->sk_drops));
100310+ atomic_read_unchecked(&sp->sk_drops));
100311 }
100312diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100313index 7b32652..0bc348b 100644
100314--- a/net/ipv6/icmp.c
100315+++ b/net/ipv6/icmp.c
100316@@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100317
100318 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100319 {
100320- struct ctl_table *table;
100321+ ctl_table_no_const *table;
100322
100323 table = kmemdup(ipv6_icmp_table_template,
100324 sizeof(ipv6_icmp_table_template),
100325diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100326index 9d92146..d986c6a 100644
100327--- a/net/ipv6/ip6_gre.c
100328+++ b/net/ipv6/ip6_gre.c
100329@@ -71,7 +71,7 @@ struct ip6gre_net {
100330 struct net_device *fb_tunnel_dev;
100331 };
100332
100333-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100334+static struct rtnl_link_ops ip6gre_link_ops;
100335 static int ip6gre_tunnel_init(struct net_device *dev);
100336 static void ip6gre_tunnel_setup(struct net_device *dev);
100337 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100338@@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100339 }
100340
100341
100342-static struct inet6_protocol ip6gre_protocol __read_mostly = {
100343+static struct inet6_protocol ip6gre_protocol = {
100344 .handler = ip6gre_rcv,
100345 .err_handler = ip6gre_err,
100346 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100347@@ -1636,7 +1636,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100348 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100349 };
100350
100351-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100352+static struct rtnl_link_ops ip6gre_link_ops = {
100353 .kind = "ip6gre",
100354 .maxtype = IFLA_GRE_MAX,
100355 .policy = ip6gre_policy,
100356@@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100357 .fill_info = ip6gre_fill_info,
100358 };
100359
100360-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100361+static struct rtnl_link_ops ip6gre_tap_ops = {
100362 .kind = "ip6gretap",
100363 .maxtype = IFLA_GRE_MAX,
100364 .policy = ip6gre_policy,
100365diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100366index afa0824..04ba530 100644
100367--- a/net/ipv6/ip6_tunnel.c
100368+++ b/net/ipv6/ip6_tunnel.c
100369@@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100370
100371 static int ip6_tnl_dev_init(struct net_device *dev);
100372 static void ip6_tnl_dev_setup(struct net_device *dev);
100373-static struct rtnl_link_ops ip6_link_ops __read_mostly;
100374+static struct rtnl_link_ops ip6_link_ops;
100375
100376 static int ip6_tnl_net_id __read_mostly;
100377 struct ip6_tnl_net {
100378@@ -1708,7 +1708,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100379 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100380 };
100381
100382-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100383+static struct rtnl_link_ops ip6_link_ops = {
100384 .kind = "ip6tnl",
100385 .maxtype = IFLA_IPTUN_MAX,
100386 .policy = ip6_tnl_policy,
100387diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100388index 6cc9f93..6e5bb7c 100644
100389--- a/net/ipv6/ip6_vti.c
100390+++ b/net/ipv6/ip6_vti.c
100391@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100392
100393 static int vti6_dev_init(struct net_device *dev);
100394 static void vti6_dev_setup(struct net_device *dev);
100395-static struct rtnl_link_ops vti6_link_ops __read_mostly;
100396+static struct rtnl_link_ops vti6_link_ops;
100397
100398 static int vti6_net_id __read_mostly;
100399 struct vti6_net {
100400@@ -980,7 +980,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100401 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100402 };
100403
100404-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100405+static struct rtnl_link_ops vti6_link_ops = {
100406 .kind = "vti6",
100407 .maxtype = IFLA_VTI_MAX,
100408 .policy = vti6_policy,
100409diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100410index edb58af..78de133 100644
100411--- a/net/ipv6/ipv6_sockglue.c
100412+++ b/net/ipv6/ipv6_sockglue.c
100413@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
100414 if (sk->sk_type != SOCK_STREAM)
100415 return -ENOPROTOOPT;
100416
100417- msg.msg_control = optval;
100418+ msg.msg_control = (void __force_kernel *)optval;
100419 msg.msg_controllen = len;
100420 msg.msg_flags = flags;
100421
100422diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
100423index e080fbb..412b3cf 100644
100424--- a/net/ipv6/netfilter/ip6_tables.c
100425+++ b/net/ipv6/netfilter/ip6_tables.c
100426@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
100427 #endif
100428
100429 static int get_info(struct net *net, void __user *user,
100430- const int *len, int compat)
100431+ int len, int compat)
100432 {
100433 char name[XT_TABLE_MAXNAMELEN];
100434 struct xt_table *t;
100435 int ret;
100436
100437- if (*len != sizeof(struct ip6t_getinfo)) {
100438- duprintf("length %u != %zu\n", *len,
100439+ if (len != sizeof(struct ip6t_getinfo)) {
100440+ duprintf("length %u != %zu\n", len,
100441 sizeof(struct ip6t_getinfo));
100442 return -EINVAL;
100443 }
100444@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
100445 info.size = private->size;
100446 strcpy(info.name, name);
100447
100448- if (copy_to_user(user, &info, *len) != 0)
100449+ if (copy_to_user(user, &info, len) != 0)
100450 ret = -EFAULT;
100451 else
100452 ret = 0;
100453@@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100454
100455 switch (cmd) {
100456 case IP6T_SO_GET_INFO:
100457- ret = get_info(sock_net(sk), user, len, 1);
100458+ ret = get_info(sock_net(sk), user, *len, 1);
100459 break;
100460 case IP6T_SO_GET_ENTRIES:
100461 ret = compat_get_entries(sock_net(sk), user, len);
100462@@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100463
100464 switch (cmd) {
100465 case IP6T_SO_GET_INFO:
100466- ret = get_info(sock_net(sk), user, len, 0);
100467+ ret = get_info(sock_net(sk), user, *len, 0);
100468 break;
100469
100470 case IP6T_SO_GET_ENTRIES:
100471diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
100472index 767ab8d..c5ec70a 100644
100473--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
100474+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
100475@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
100476
100477 static int nf_ct_frag6_sysctl_register(struct net *net)
100478 {
100479- struct ctl_table *table;
100480+ ctl_table_no_const *table = NULL;
100481 struct ctl_table_header *hdr;
100482
100483- table = nf_ct_frag6_sysctl_table;
100484 if (!net_eq(net, &init_net)) {
100485- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
100486+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
100487 GFP_KERNEL);
100488 if (table == NULL)
100489 goto err_alloc;
100490@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100491 table[0].data = &net->nf_frag.frags.timeout;
100492 table[1].data = &net->nf_frag.frags.low_thresh;
100493 table[2].data = &net->nf_frag.frags.high_thresh;
100494- }
100495-
100496- hdr = register_net_sysctl(net, "net/netfilter", table);
100497+ hdr = register_net_sysctl(net, "net/netfilter", table);
100498+ } else
100499+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
100500 if (hdr == NULL)
100501 goto err_reg;
100502
100503@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100504 return 0;
100505
100506 err_reg:
100507- if (!net_eq(net, &init_net))
100508- kfree(table);
100509+ kfree(table);
100510 err_alloc:
100511 return -ENOMEM;
100512 }
100513diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
100514index 56596ce..c734618 100644
100515--- a/net/ipv6/output_core.c
100516+++ b/net/ipv6/output_core.c
100517@@ -10,7 +10,7 @@
100518
100519 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100520 {
100521- static atomic_t ipv6_fragmentation_id;
100522+ static atomic_unchecked_t ipv6_fragmentation_id;
100523 struct in6_addr addr;
100524 int ident;
100525
100526@@ -26,7 +26,7 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100527 return;
100528 }
100529 #endif
100530- ident = atomic_inc_return(&ipv6_fragmentation_id);
100531+ ident = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100532
100533 addr = rt->rt6i_dst.addr;
100534 addr.s6_addr32[0] ^= (__force __be32)ident;
100535diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
100536index bda7429..469b26b 100644
100537--- a/net/ipv6/ping.c
100538+++ b/net/ipv6/ping.c
100539@@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
100540 };
100541 #endif
100542
100543+static struct pingv6_ops real_pingv6_ops = {
100544+ .ipv6_recv_error = ipv6_recv_error,
100545+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
100546+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
100547+ .icmpv6_err_convert = icmpv6_err_convert,
100548+ .ipv6_icmp_error = ipv6_icmp_error,
100549+ .ipv6_chk_addr = ipv6_chk_addr,
100550+};
100551+
100552+static struct pingv6_ops dummy_pingv6_ops = {
100553+ .ipv6_recv_error = dummy_ipv6_recv_error,
100554+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
100555+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
100556+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
100557+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
100558+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
100559+};
100560+
100561 int __init pingv6_init(void)
100562 {
100563 #ifdef CONFIG_PROC_FS
100564@@ -253,13 +271,7 @@ int __init pingv6_init(void)
100565 if (ret)
100566 return ret;
100567 #endif
100568- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
100569- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
100570- pingv6_ops.ip6_datagram_recv_specific_ctl =
100571- ip6_datagram_recv_specific_ctl;
100572- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
100573- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
100574- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
100575+ pingv6_ops = &real_pingv6_ops;
100576 return inet6_register_protosw(&pingv6_protosw);
100577 }
100578
100579@@ -268,14 +280,9 @@ int __init pingv6_init(void)
100580 */
100581 void pingv6_exit(void)
100582 {
100583- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
100584- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
100585- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
100586- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
100587- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
100588- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
100589 #ifdef CONFIG_PROC_FS
100590 unregister_pernet_subsys(&ping_v6_net_ops);
100591 #endif
100592+ pingv6_ops = &dummy_pingv6_ops;
100593 inet6_unregister_protosw(&pingv6_protosw);
100594 }
100595diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
100596index 091d066..139d410 100644
100597--- a/net/ipv6/proc.c
100598+++ b/net/ipv6/proc.c
100599@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
100600 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
100601 goto proc_snmp6_fail;
100602
100603- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
100604+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
100605 if (!net->mib.proc_net_devsnmp6)
100606 goto proc_dev_snmp6_fail;
100607 return 0;
100608diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
100609index 1f29996..46fe0c7 100644
100610--- a/net/ipv6/raw.c
100611+++ b/net/ipv6/raw.c
100612@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
100613 {
100614 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
100615 skb_checksum_complete(skb)) {
100616- atomic_inc(&sk->sk_drops);
100617+ atomic_inc_unchecked(&sk->sk_drops);
100618 kfree_skb(skb);
100619 return NET_RX_DROP;
100620 }
100621@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100622 struct raw6_sock *rp = raw6_sk(sk);
100623
100624 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
100625- atomic_inc(&sk->sk_drops);
100626+ atomic_inc_unchecked(&sk->sk_drops);
100627 kfree_skb(skb);
100628 return NET_RX_DROP;
100629 }
100630@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100631
100632 if (inet->hdrincl) {
100633 if (skb_checksum_complete(skb)) {
100634- atomic_inc(&sk->sk_drops);
100635+ atomic_inc_unchecked(&sk->sk_drops);
100636 kfree_skb(skb);
100637 return NET_RX_DROP;
100638 }
100639@@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100640 if (flags & MSG_OOB)
100641 return -EOPNOTSUPP;
100642
100643+ if (addr_len)
100644+ *addr_len=sizeof(*sin6);
100645+
100646 if (flags & MSG_ERRQUEUE)
100647 return ipv6_recv_error(sk, msg, len, addr_len);
100648
100649@@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100650 sin6->sin6_flowinfo = 0;
100651 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
100652 IP6CB(skb)->iif);
100653- *addr_len = sizeof(*sin6);
100654 }
100655
100656 sock_recv_ts_and_drops(msg, sk, skb);
100657@@ -610,7 +612,7 @@ out:
100658 return err;
100659 }
100660
100661-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
100662+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
100663 struct flowi6 *fl6, struct dst_entry **dstp,
100664 unsigned int flags)
100665 {
100666@@ -922,12 +924,15 @@ do_confirm:
100667 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
100668 char __user *optval, int optlen)
100669 {
100670+ struct icmp6_filter filter;
100671+
100672 switch (optname) {
100673 case ICMPV6_FILTER:
100674 if (optlen > sizeof(struct icmp6_filter))
100675 optlen = sizeof(struct icmp6_filter);
100676- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
100677+ if (copy_from_user(&filter, optval, optlen))
100678 return -EFAULT;
100679+ raw6_sk(sk)->filter = filter;
100680 return 0;
100681 default:
100682 return -ENOPROTOOPT;
100683@@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100684 char __user *optval, int __user *optlen)
100685 {
100686 int len;
100687+ struct icmp6_filter filter;
100688
100689 switch (optname) {
100690 case ICMPV6_FILTER:
100691@@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100692 len = sizeof(struct icmp6_filter);
100693 if (put_user(len, optlen))
100694 return -EFAULT;
100695- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
100696+ filter = raw6_sk(sk)->filter;
100697+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
100698 return -EFAULT;
100699 return 0;
100700 default:
100701diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
100702index cc85a9b..526a133 100644
100703--- a/net/ipv6/reassembly.c
100704+++ b/net/ipv6/reassembly.c
100705@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
100706
100707 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100708 {
100709- struct ctl_table *table;
100710+ ctl_table_no_const *table = NULL;
100711 struct ctl_table_header *hdr;
100712
100713- table = ip6_frags_ns_ctl_table;
100714 if (!net_eq(net, &init_net)) {
100715- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100716+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100717 if (table == NULL)
100718 goto err_alloc;
100719
100720@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100721 /* Don't export sysctls to unprivileged users */
100722 if (net->user_ns != &init_user_ns)
100723 table[0].procname = NULL;
100724- }
100725+ hdr = register_net_sysctl(net, "net/ipv6", table);
100726+ } else
100727+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
100728
100729- hdr = register_net_sysctl(net, "net/ipv6", table);
100730 if (hdr == NULL)
100731 goto err_reg;
100732
100733@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100734 return 0;
100735
100736 err_reg:
100737- if (!net_eq(net, &init_net))
100738- kfree(table);
100739+ kfree(table);
100740 err_alloc:
100741 return -ENOMEM;
100742 }
100743diff --git a/net/ipv6/route.c b/net/ipv6/route.c
100744index 6ebdb7b6..f225ab1 100644
100745--- a/net/ipv6/route.c
100746+++ b/net/ipv6/route.c
100747@@ -2971,7 +2971,7 @@ struct ctl_table ipv6_route_table_template[] = {
100748
100749 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
100750 {
100751- struct ctl_table *table;
100752+ ctl_table_no_const *table;
100753
100754 table = kmemdup(ipv6_route_table_template,
100755 sizeof(ipv6_route_table_template),
100756diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
100757index 4f40817..54dcbef 100644
100758--- a/net/ipv6/sit.c
100759+++ b/net/ipv6/sit.c
100760@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
100761 static void ipip6_dev_free(struct net_device *dev);
100762 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
100763 __be32 *v4dst);
100764-static struct rtnl_link_ops sit_link_ops __read_mostly;
100765+static struct rtnl_link_ops sit_link_ops;
100766
100767 static int sit_net_id __read_mostly;
100768 struct sit_net {
100769@@ -1661,7 +1661,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
100770 unregister_netdevice_queue(dev, head);
100771 }
100772
100773-static struct rtnl_link_ops sit_link_ops __read_mostly = {
100774+static struct rtnl_link_ops sit_link_ops = {
100775 .kind = "sit",
100776 .maxtype = IFLA_IPTUN_MAX,
100777 .policy = ipip6_policy,
100778diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
100779index 7f405a1..eabef92 100644
100780--- a/net/ipv6/sysctl_net_ipv6.c
100781+++ b/net/ipv6/sysctl_net_ipv6.c
100782@@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
100783
100784 static int __net_init ipv6_sysctl_net_init(struct net *net)
100785 {
100786- struct ctl_table *ipv6_table;
100787+ ctl_table_no_const *ipv6_table;
100788 struct ctl_table *ipv6_route_table;
100789 struct ctl_table *ipv6_icmp_table;
100790 int err;
100791diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
100792index e289830..79a5718 100644
100793--- a/net/ipv6/tcp_ipv6.c
100794+++ b/net/ipv6/tcp_ipv6.c
100795@@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
100796 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
100797 }
100798
100799+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100800+extern int grsec_enable_blackhole;
100801+#endif
100802+
100803 static void tcp_v6_hash(struct sock *sk)
100804 {
100805 if (sk->sk_state != TCP_CLOSE) {
100806@@ -1416,6 +1420,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
100807 return 0;
100808
100809 reset:
100810+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100811+ if (!grsec_enable_blackhole)
100812+#endif
100813 tcp_v6_send_reset(sk, skb);
100814 discard:
100815 if (opt_skb)
100816@@ -1500,12 +1507,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
100817 TCP_SKB_CB(skb)->sacked = 0;
100818
100819 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100820- if (!sk)
100821+ if (!sk) {
100822+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100823+ ret = 1;
100824+#endif
100825 goto no_tcp_socket;
100826+ }
100827
100828 process:
100829- if (sk->sk_state == TCP_TIME_WAIT)
100830+ if (sk->sk_state == TCP_TIME_WAIT) {
100831+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100832+ ret = 2;
100833+#endif
100834 goto do_time_wait;
100835+ }
100836
100837 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
100838 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100839@@ -1557,6 +1572,10 @@ csum_error:
100840 bad_packet:
100841 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100842 } else {
100843+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100844+ if (!grsec_enable_blackhole || (ret == 1 &&
100845+ (skb->dev->flags & IFF_LOOPBACK)))
100846+#endif
100847 tcp_v6_send_reset(NULL, skb);
100848 }
100849
100850diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
100851index 20b63d2..13be908 100644
100852--- a/net/ipv6/udp.c
100853+++ b/net/ipv6/udp.c
100854@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
100855 udp_ipv6_hash_secret + net_hash_mix(net));
100856 }
100857
100858+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100859+extern int grsec_enable_blackhole;
100860+#endif
100861+
100862 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
100863 {
100864 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
100865@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100866 int is_udp4;
100867 bool slow;
100868
100869+ if (addr_len)
100870+ *addr_len = sizeof(struct sockaddr_in6);
100871+
100872 if (flags & MSG_ERRQUEUE)
100873 return ipv6_recv_error(sk, msg, len, addr_len);
100874
100875@@ -435,7 +442,7 @@ try_again:
100876 if (unlikely(err)) {
100877 trace_kfree_skb(skb, udpv6_recvmsg);
100878 if (!peeked) {
100879- atomic_inc(&sk->sk_drops);
100880+ atomic_inc_unchecked(&sk->sk_drops);
100881 if (is_udp4)
100882 UDP_INC_STATS_USER(sock_net(sk),
100883 UDP_MIB_INERRORS,
100884@@ -475,7 +482,7 @@ try_again:
100885 ipv6_iface_scope_id(&sin6->sin6_addr,
100886 IP6CB(skb)->iif);
100887 }
100888- *addr_len = sizeof(*sin6);
100889+
100890 }
100891
100892 if (np->rxopt.all)
100893@@ -690,7 +697,7 @@ csum_error:
100894 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100895 drop:
100896 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100897- atomic_inc(&sk->sk_drops);
100898+ atomic_inc_unchecked(&sk->sk_drops);
100899 kfree_skb(skb);
100900 return -1;
100901 }
100902@@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100903 if (likely(skb1 == NULL))
100904 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100905 if (!skb1) {
100906- atomic_inc(&sk->sk_drops);
100907+ atomic_inc_unchecked(&sk->sk_drops);
100908 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100909 IS_UDPLITE(sk));
100910 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100911@@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100912 goto csum_error;
100913
100914 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100915+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100916+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100917+#endif
100918 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
100919
100920 kfree_skb(skb);
100921diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
100922index 2a0bbda..d75ca57 100644
100923--- a/net/ipv6/xfrm6_policy.c
100924+++ b/net/ipv6/xfrm6_policy.c
100925@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
100926 }
100927 }
100928
100929-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
100930+static int xfrm6_garbage_collect(struct dst_ops *ops)
100931 {
100932 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
100933
100934- xfrm6_policy_afinfo.garbage_collect(net);
100935+ xfrm_garbage_collect_deferred(net);
100936 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
100937 }
100938
100939@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
100940
100941 static int __net_init xfrm6_net_init(struct net *net)
100942 {
100943- struct ctl_table *table;
100944+ ctl_table_no_const *table = NULL;
100945 struct ctl_table_header *hdr;
100946
100947- table = xfrm6_policy_table;
100948 if (!net_eq(net, &init_net)) {
100949- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100950+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
100951 if (!table)
100952 goto err_alloc;
100953
100954 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
100955- }
100956+ hdr = register_net_sysctl(net, "net/ipv6", table);
100957+ } else
100958+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
100959
100960- hdr = register_net_sysctl(net, "net/ipv6", table);
100961 if (!hdr)
100962 goto err_reg;
100963
100964@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
100965 return 0;
100966
100967 err_reg:
100968- if (!net_eq(net, &init_net))
100969- kfree(table);
100970+ kfree(table);
100971 err_alloc:
100972 return -ENOMEM;
100973 }
100974diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
100975index e15c16a..7cf07aa 100644
100976--- a/net/ipx/ipx_proc.c
100977+++ b/net/ipx/ipx_proc.c
100978@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
100979 struct proc_dir_entry *p;
100980 int rc = -ENOMEM;
100981
100982- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
100983+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
100984
100985 if (!ipx_proc_dir)
100986 goto out;
100987diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
100988index 2ba8b97..6d33010 100644
100989--- a/net/irda/ircomm/ircomm_tty.c
100990+++ b/net/irda/ircomm/ircomm_tty.c
100991@@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
100992 add_wait_queue(&port->open_wait, &wait);
100993
100994 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
100995- __FILE__, __LINE__, tty->driver->name, port->count);
100996+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
100997
100998 spin_lock_irqsave(&port->lock, flags);
100999 if (!tty_hung_up_p(filp))
101000- port->count--;
101001+ atomic_dec(&port->count);
101002 port->blocked_open++;
101003 spin_unlock_irqrestore(&port->lock, flags);
101004
101005@@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101006 }
101007
101008 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
101009- __FILE__, __LINE__, tty->driver->name, port->count);
101010+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101011
101012 schedule();
101013 }
101014@@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101015
101016 spin_lock_irqsave(&port->lock, flags);
101017 if (!tty_hung_up_p(filp))
101018- port->count++;
101019+ atomic_inc(&port->count);
101020 port->blocked_open--;
101021 spin_unlock_irqrestore(&port->lock, flags);
101022
101023 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
101024- __FILE__, __LINE__, tty->driver->name, port->count);
101025+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101026
101027 if (!retval)
101028 port->flags |= ASYNC_NORMAL_ACTIVE;
101029@@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
101030
101031 /* ++ is not atomic, so this should be protected - Jean II */
101032 spin_lock_irqsave(&self->port.lock, flags);
101033- self->port.count++;
101034+ atomic_inc(&self->port.count);
101035 spin_unlock_irqrestore(&self->port.lock, flags);
101036 tty_port_tty_set(&self->port, tty);
101037
101038 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
101039- self->line, self->port.count);
101040+ self->line, atomic_read(&self->port.count));
101041
101042 /* Not really used by us, but lets do it anyway */
101043 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
101044@@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
101045 tty_kref_put(port->tty);
101046 }
101047 port->tty = NULL;
101048- port->count = 0;
101049+ atomic_set(&port->count, 0);
101050 spin_unlock_irqrestore(&port->lock, flags);
101051
101052 wake_up_interruptible(&port->open_wait);
101053@@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
101054 seq_putc(m, '\n');
101055
101056 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
101057- seq_printf(m, "Open count: %d\n", self->port.count);
101058+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
101059 seq_printf(m, "Max data size: %d\n", self->max_data_size);
101060 seq_printf(m, "Max header size: %d\n", self->max_header_size);
101061
101062diff --git a/net/irda/irproc.c b/net/irda/irproc.c
101063index b9ac598..f88cc56 100644
101064--- a/net/irda/irproc.c
101065+++ b/net/irda/irproc.c
101066@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
101067 {
101068 int i;
101069
101070- proc_irda = proc_mkdir("irda", init_net.proc_net);
101071+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
101072 if (proc_irda == NULL)
101073 return;
101074
101075diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
101076index 8c9d730..66c6305 100644
101077--- a/net/iucv/af_iucv.c
101078+++ b/net/iucv/af_iucv.c
101079@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
101080
101081 write_lock_bh(&iucv_sk_list.lock);
101082
101083- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
101084+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101085 while (__iucv_get_sock_by_name(name)) {
101086 sprintf(name, "%08x",
101087- atomic_inc_return(&iucv_sk_list.autobind_name));
101088+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101089 }
101090
101091 write_unlock_bh(&iucv_sk_list.lock);
101092diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
101093index da78793..bdd78cf 100644
101094--- a/net/iucv/iucv.c
101095+++ b/net/iucv/iucv.c
101096@@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
101097 return NOTIFY_OK;
101098 }
101099
101100-static struct notifier_block __refdata iucv_cpu_notifier = {
101101+static struct notifier_block iucv_cpu_notifier = {
101102 .notifier_call = iucv_cpu_notify,
101103 };
101104
101105diff --git a/net/key/af_key.c b/net/key/af_key.c
101106index f3c8307..7127791 100644
101107--- a/net/key/af_key.c
101108+++ b/net/key/af_key.c
101109@@ -3070,10 +3070,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
101110 static u32 get_acqseq(void)
101111 {
101112 u32 res;
101113- static atomic_t acqseq;
101114+ static atomic_unchecked_t acqseq;
101115
101116 do {
101117- res = atomic_inc_return(&acqseq);
101118+ res = atomic_inc_return_unchecked(&acqseq);
101119 } while (!res);
101120 return res;
101121 }
101122diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
101123index 76125c5..e474828 100644
101124--- a/net/l2tp/l2tp_eth.c
101125+++ b/net/l2tp/l2tp_eth.c
101126@@ -42,12 +42,12 @@ struct l2tp_eth {
101127 struct sock *tunnel_sock;
101128 struct l2tp_session *session;
101129 struct list_head list;
101130- atomic_long_t tx_bytes;
101131- atomic_long_t tx_packets;
101132- atomic_long_t tx_dropped;
101133- atomic_long_t rx_bytes;
101134- atomic_long_t rx_packets;
101135- atomic_long_t rx_errors;
101136+ atomic_long_unchecked_t tx_bytes;
101137+ atomic_long_unchecked_t tx_packets;
101138+ atomic_long_unchecked_t tx_dropped;
101139+ atomic_long_unchecked_t rx_bytes;
101140+ atomic_long_unchecked_t rx_packets;
101141+ atomic_long_unchecked_t rx_errors;
101142 };
101143
101144 /* via l2tp_session_priv() */
101145@@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
101146 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
101147
101148 if (likely(ret == NET_XMIT_SUCCESS)) {
101149- atomic_long_add(len, &priv->tx_bytes);
101150- atomic_long_inc(&priv->tx_packets);
101151+ atomic_long_add_unchecked(len, &priv->tx_bytes);
101152+ atomic_long_inc_unchecked(&priv->tx_packets);
101153 } else {
101154- atomic_long_inc(&priv->tx_dropped);
101155+ atomic_long_inc_unchecked(&priv->tx_dropped);
101156 }
101157 return NETDEV_TX_OK;
101158 }
101159@@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
101160 {
101161 struct l2tp_eth *priv = netdev_priv(dev);
101162
101163- stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
101164- stats->tx_packets = atomic_long_read(&priv->tx_packets);
101165- stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
101166- stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
101167- stats->rx_packets = atomic_long_read(&priv->rx_packets);
101168- stats->rx_errors = atomic_long_read(&priv->rx_errors);
101169+ stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
101170+ stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
101171+ stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
101172+ stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
101173+ stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
101174+ stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
101175 return stats;
101176 }
101177
101178@@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
101179 nf_reset(skb);
101180
101181 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
101182- atomic_long_inc(&priv->rx_packets);
101183- atomic_long_add(data_len, &priv->rx_bytes);
101184+ atomic_long_inc_unchecked(&priv->rx_packets);
101185+ atomic_long_add_unchecked(data_len, &priv->rx_bytes);
101186 } else {
101187- atomic_long_inc(&priv->rx_errors);
101188+ atomic_long_inc_unchecked(&priv->rx_errors);
101189 }
101190 return;
101191
101192 error:
101193- atomic_long_inc(&priv->rx_errors);
101194+ atomic_long_inc_unchecked(&priv->rx_errors);
101195 kfree_skb(skb);
101196 }
101197
101198diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
101199index 3397fe6..861fd1a 100644
101200--- a/net/l2tp/l2tp_ip.c
101201+++ b/net/l2tp/l2tp_ip.c
101202@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101203 if (flags & MSG_OOB)
101204 goto out;
101205
101206+ if (addr_len)
101207+ *addr_len = sizeof(*sin);
101208+
101209 skb = skb_recv_datagram(sk, flags, noblock, &err);
101210 if (!skb)
101211 goto out;
101212@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101213 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
101214 sin->sin_port = 0;
101215 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
101216- *addr_len = sizeof(*sin);
101217 }
101218 if (inet->cmsg_flags)
101219 ip_cmsg_recv(msg, skb);
101220diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
101221index 1a3c7e0..80f8b0c 100644
101222--- a/net/llc/llc_proc.c
101223+++ b/net/llc/llc_proc.c
101224@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
101225 int rc = -ENOMEM;
101226 struct proc_dir_entry *p;
101227
101228- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
101229+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
101230 if (!llc_proc_dir)
101231 goto out;
101232
101233diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
101234index aaa59d7..21a2c4a 100644
101235--- a/net/mac80211/cfg.c
101236+++ b/net/mac80211/cfg.c
101237@@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
101238 ret = ieee80211_vif_use_channel(sdata, chandef,
101239 IEEE80211_CHANCTX_EXCLUSIVE);
101240 }
101241- } else if (local->open_count == local->monitors) {
101242+ } else if (local_read(&local->open_count) == local->monitors) {
101243 local->_oper_chandef = *chandef;
101244 ieee80211_hw_config(local, 0);
101245 }
101246@@ -3440,7 +3440,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
101247 else
101248 local->probe_req_reg--;
101249
101250- if (!local->open_count)
101251+ if (!local_read(&local->open_count))
101252 break;
101253
101254 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
101255@@ -3903,8 +3903,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
101256 if (chanctx_conf) {
101257 *chandef = chanctx_conf->def;
101258 ret = 0;
101259- } else if (local->open_count > 0 &&
101260- local->open_count == local->monitors &&
101261+ } else if (local_read(&local->open_count) > 0 &&
101262+ local_read(&local->open_count) == local->monitors &&
101263 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
101264 if (local->use_chanctx)
101265 *chandef = local->monitor_chandef;
101266diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
101267index f169b6e..a5dc4eb 100644
101268--- a/net/mac80211/ieee80211_i.h
101269+++ b/net/mac80211/ieee80211_i.h
101270@@ -28,6 +28,7 @@
101271 #include <net/ieee80211_radiotap.h>
101272 #include <net/cfg80211.h>
101273 #include <net/mac80211.h>
101274+#include <asm/local.h>
101275 #include "key.h"
101276 #include "sta_info.h"
101277 #include "debug.h"
101278@@ -999,7 +1000,7 @@ struct ieee80211_local {
101279 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
101280 spinlock_t queue_stop_reason_lock;
101281
101282- int open_count;
101283+ local_t open_count;
101284 int monitors, cooked_mntrs;
101285 /* number of interfaces with corresponding FIF_ flags */
101286 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
101287diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
101288index 34799e0..b411290 100644
101289--- a/net/mac80211/iface.c
101290+++ b/net/mac80211/iface.c
101291@@ -524,7 +524,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101292 break;
101293 }
101294
101295- if (local->open_count == 0) {
101296+ if (local_read(&local->open_count) == 0) {
101297 res = drv_start(local);
101298 if (res)
101299 goto err_del_bss;
101300@@ -571,7 +571,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101301 res = drv_add_interface(local, sdata);
101302 if (res)
101303 goto err_stop;
101304- } else if (local->monitors == 0 && local->open_count == 0) {
101305+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
101306 res = ieee80211_add_virtual_monitor(local);
101307 if (res)
101308 goto err_stop;
101309@@ -680,7 +680,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101310 atomic_inc(&local->iff_promiscs);
101311
101312 if (coming_up)
101313- local->open_count++;
101314+ local_inc(&local->open_count);
101315
101316 if (hw_reconf_flags)
101317 ieee80211_hw_config(local, hw_reconf_flags);
101318@@ -718,7 +718,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101319 err_del_interface:
101320 drv_remove_interface(local, sdata);
101321 err_stop:
101322- if (!local->open_count)
101323+ if (!local_read(&local->open_count))
101324 drv_stop(local);
101325 err_del_bss:
101326 sdata->bss = NULL;
101327@@ -871,7 +871,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101328 }
101329
101330 if (going_down)
101331- local->open_count--;
101332+ local_dec(&local->open_count);
101333
101334 switch (sdata->vif.type) {
101335 case NL80211_IFTYPE_AP_VLAN:
101336@@ -930,7 +930,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101337 }
101338 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
101339
101340- if (local->open_count == 0)
101341+ if (local_read(&local->open_count) == 0)
101342 ieee80211_clear_tx_pending(local);
101343
101344 /*
101345@@ -970,7 +970,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101346
101347 ieee80211_recalc_ps(local, -1);
101348
101349- if (local->open_count == 0) {
101350+ if (local_read(&local->open_count) == 0) {
101351 ieee80211_stop_device(local);
101352
101353 /* no reconfiguring after stop! */
101354@@ -981,7 +981,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101355 ieee80211_configure_filter(local);
101356 ieee80211_hw_config(local, hw_reconf_flags);
101357
101358- if (local->monitors == local->open_count)
101359+ if (local->monitors == local_read(&local->open_count))
101360 ieee80211_add_virtual_monitor(local);
101361 }
101362
101363diff --git a/net/mac80211/main.c b/net/mac80211/main.c
101364index 4c1bf61..00b449b 100644
101365--- a/net/mac80211/main.c
101366+++ b/net/mac80211/main.c
101367@@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
101368 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
101369 IEEE80211_CONF_CHANGE_POWER);
101370
101371- if (changed && local->open_count) {
101372+ if (changed && local_read(&local->open_count)) {
101373 ret = drv_config(local, changed);
101374 /*
101375 * Goal:
101376diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101377index d478b88..8c8d157 100644
101378--- a/net/mac80211/pm.c
101379+++ b/net/mac80211/pm.c
101380@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101381 struct ieee80211_sub_if_data *sdata;
101382 struct sta_info *sta;
101383
101384- if (!local->open_count)
101385+ if (!local_read(&local->open_count))
101386 goto suspend;
101387
101388 ieee80211_scan_cancel(local);
101389@@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101390 cancel_work_sync(&local->dynamic_ps_enable_work);
101391 del_timer_sync(&local->dynamic_ps_timer);
101392
101393- local->wowlan = wowlan && local->open_count;
101394+ local->wowlan = wowlan && local_read(&local->open_count);
101395 if (local->wowlan) {
101396 int err = drv_suspend(local, wowlan);
101397 if (err < 0) {
101398@@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101399 WARN_ON(!list_empty(&local->chanctx_list));
101400
101401 /* stop hardware - this must stop RX */
101402- if (local->open_count)
101403+ if (local_read(&local->open_count))
101404 ieee80211_stop_device(local);
101405
101406 suspend:
101407diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101408index 8fdadfd..a4f72b8 100644
101409--- a/net/mac80211/rate.c
101410+++ b/net/mac80211/rate.c
101411@@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101412
101413 ASSERT_RTNL();
101414
101415- if (local->open_count)
101416+ if (local_read(&local->open_count))
101417 return -EBUSY;
101418
101419 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101420diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101421index 6ff1346..936ca9a 100644
101422--- a/net/mac80211/rc80211_pid_debugfs.c
101423+++ b/net/mac80211/rc80211_pid_debugfs.c
101424@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
101425
101426 spin_unlock_irqrestore(&events->lock, status);
101427
101428- if (copy_to_user(buf, pb, p))
101429+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
101430 return -EFAULT;
101431
101432 return p;
101433diff --git a/net/mac80211/util.c b/net/mac80211/util.c
101434index 3c36583..12887fe 100644
101435--- a/net/mac80211/util.c
101436+++ b/net/mac80211/util.c
101437@@ -1509,7 +1509,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101438 }
101439 #endif
101440 /* everything else happens only if HW was up & running */
101441- if (!local->open_count)
101442+ if (!local_read(&local->open_count))
101443 goto wake_up;
101444
101445 /*
101446@@ -1734,7 +1734,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101447 local->in_reconfig = false;
101448 barrier();
101449
101450- if (local->monitors == local->open_count && local->monitors > 0)
101451+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
101452 ieee80211_add_virtual_monitor(local);
101453
101454 /*
101455diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
101456index e9410d1..77b6378 100644
101457--- a/net/netfilter/Kconfig
101458+++ b/net/netfilter/Kconfig
101459@@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
101460
101461 To compile it as a module, choose M here. If unsure, say N.
101462
101463+config NETFILTER_XT_MATCH_GRADM
101464+ tristate '"gradm" match support'
101465+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
101466+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
101467+ ---help---
101468+ The gradm match allows to match on grsecurity RBAC being enabled.
101469+ It is useful when iptables rules are applied early on bootup to
101470+ prevent connections to the machine (except from a trusted host)
101471+ while the RBAC system is disabled.
101472+
101473 config NETFILTER_XT_MATCH_HASHLIMIT
101474 tristate '"hashlimit" match support'
101475 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
101476diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
101477index bffdad7..f9317d1 100644
101478--- a/net/netfilter/Makefile
101479+++ b/net/netfilter/Makefile
101480@@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
101481 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
101482 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
101483 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
101484+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
101485 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
101486 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
101487 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
101488diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
101489index 1172083..986f1c1 100644
101490--- a/net/netfilter/ipset/ip_set_core.c
101491+++ b/net/netfilter/ipset/ip_set_core.c
101492@@ -1924,7 +1924,7 @@ done:
101493 return ret;
101494 }
101495
101496-static struct nf_sockopt_ops so_set __read_mostly = {
101497+static struct nf_sockopt_ops so_set = {
101498 .pf = PF_INET,
101499 .get_optmin = SO_IP_SET,
101500 .get_optmax = SO_IP_SET + 1,
101501diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
101502index a8eb0a8..86f2de4 100644
101503--- a/net/netfilter/ipvs/ip_vs_conn.c
101504+++ b/net/netfilter/ipvs/ip_vs_conn.c
101505@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
101506 /* Increase the refcnt counter of the dest */
101507 ip_vs_dest_hold(dest);
101508
101509- conn_flags = atomic_read(&dest->conn_flags);
101510+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
101511 if (cp->protocol != IPPROTO_UDP)
101512 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
101513 flags = cp->flags;
101514@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
101515
101516 cp->control = NULL;
101517 atomic_set(&cp->n_control, 0);
101518- atomic_set(&cp->in_pkts, 0);
101519+ atomic_set_unchecked(&cp->in_pkts, 0);
101520
101521 cp->packet_xmit = NULL;
101522 cp->app = NULL;
101523@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
101524
101525 /* Don't drop the entry if its number of incoming packets is not
101526 located in [0, 8] */
101527- i = atomic_read(&cp->in_pkts);
101528+ i = atomic_read_unchecked(&cp->in_pkts);
101529 if (i > 8 || i < 0) return 0;
101530
101531 if (!todrop_rate[i]) return 0;
101532diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
101533index 3d2d2c8..c87e4d3 100644
101534--- a/net/netfilter/ipvs/ip_vs_core.c
101535+++ b/net/netfilter/ipvs/ip_vs_core.c
101536@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
101537 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
101538 /* do not touch skb anymore */
101539
101540- atomic_inc(&cp->in_pkts);
101541+ atomic_inc_unchecked(&cp->in_pkts);
101542 ip_vs_conn_put(cp);
101543 return ret;
101544 }
101545@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
101546 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
101547 pkts = sysctl_sync_threshold(ipvs);
101548 else
101549- pkts = atomic_add_return(1, &cp->in_pkts);
101550+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101551
101552 if (ipvs->sync_state & IP_VS_STATE_MASTER)
101553 ip_vs_sync_conn(net, cp, pkts);
101554diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
101555index c42e83d..a6a3f8b 100644
101556--- a/net/netfilter/ipvs/ip_vs_ctl.c
101557+++ b/net/netfilter/ipvs/ip_vs_ctl.c
101558@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
101559 */
101560 ip_vs_rs_hash(ipvs, dest);
101561 }
101562- atomic_set(&dest->conn_flags, conn_flags);
101563+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
101564
101565 /* bind the service */
101566 old_svc = rcu_dereference_protected(dest->svc, 1);
101567@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
101568 * align with netns init in ip_vs_control_net_init()
101569 */
101570
101571-static struct ctl_table vs_vars[] = {
101572+static ctl_table_no_const vs_vars[] __read_only = {
101573 {
101574 .procname = "amemthresh",
101575 .maxlen = sizeof(int),
101576@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101577 " %-7s %-6d %-10d %-10d\n",
101578 &dest->addr.in6,
101579 ntohs(dest->port),
101580- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101581+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101582 atomic_read(&dest->weight),
101583 atomic_read(&dest->activeconns),
101584 atomic_read(&dest->inactconns));
101585@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101586 "%-7s %-6d %-10d %-10d\n",
101587 ntohl(dest->addr.ip),
101588 ntohs(dest->port),
101589- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101590+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101591 atomic_read(&dest->weight),
101592 atomic_read(&dest->activeconns),
101593 atomic_read(&dest->inactconns));
101594@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
101595
101596 entry.addr = dest->addr.ip;
101597 entry.port = dest->port;
101598- entry.conn_flags = atomic_read(&dest->conn_flags);
101599+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
101600 entry.weight = atomic_read(&dest->weight);
101601 entry.u_threshold = dest->u_threshold;
101602 entry.l_threshold = dest->l_threshold;
101603@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
101604 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
101605 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
101606 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
101607- (atomic_read(&dest->conn_flags) &
101608+ (atomic_read_unchecked(&dest->conn_flags) &
101609 IP_VS_CONN_F_FWD_MASK)) ||
101610 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
101611 atomic_read(&dest->weight)) ||
101612@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
101613 {
101614 int idx;
101615 struct netns_ipvs *ipvs = net_ipvs(net);
101616- struct ctl_table *tbl;
101617+ ctl_table_no_const *tbl;
101618
101619 atomic_set(&ipvs->dropentry, 0);
101620 spin_lock_init(&ipvs->dropentry_lock);
101621diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
101622index 547ff33..c8c8117 100644
101623--- a/net/netfilter/ipvs/ip_vs_lblc.c
101624+++ b/net/netfilter/ipvs/ip_vs_lblc.c
101625@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
101626 * IPVS LBLC sysctl table
101627 */
101628 #ifdef CONFIG_SYSCTL
101629-static struct ctl_table vs_vars_table[] = {
101630+static ctl_table_no_const vs_vars_table[] __read_only = {
101631 {
101632 .procname = "lblc_expiration",
101633 .data = NULL,
101634diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
101635index 3f21a2f..a112e85 100644
101636--- a/net/netfilter/ipvs/ip_vs_lblcr.c
101637+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
101638@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
101639 * IPVS LBLCR sysctl table
101640 */
101641
101642-static struct ctl_table vs_vars_table[] = {
101643+static ctl_table_no_const vs_vars_table[] __read_only = {
101644 {
101645 .procname = "lblcr_expiration",
101646 .data = NULL,
101647diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
101648index db80126..ef7110e 100644
101649--- a/net/netfilter/ipvs/ip_vs_sync.c
101650+++ b/net/netfilter/ipvs/ip_vs_sync.c
101651@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
101652 cp = cp->control;
101653 if (cp) {
101654 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101655- pkts = atomic_add_return(1, &cp->in_pkts);
101656+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101657 else
101658 pkts = sysctl_sync_threshold(ipvs);
101659 ip_vs_sync_conn(net, cp->control, pkts);
101660@@ -771,7 +771,7 @@ control:
101661 if (!cp)
101662 return;
101663 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101664- pkts = atomic_add_return(1, &cp->in_pkts);
101665+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101666 else
101667 pkts = sysctl_sync_threshold(ipvs);
101668 goto sloop;
101669@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
101670
101671 if (opt)
101672 memcpy(&cp->in_seq, opt, sizeof(*opt));
101673- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101674+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101675 cp->state = state;
101676 cp->old_state = cp->state;
101677 /*
101678diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
101679index c47444e..b0961c6 100644
101680--- a/net/netfilter/ipvs/ip_vs_xmit.c
101681+++ b/net/netfilter/ipvs/ip_vs_xmit.c
101682@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
101683 else
101684 rc = NF_ACCEPT;
101685 /* do not touch skb anymore */
101686- atomic_inc(&cp->in_pkts);
101687+ atomic_inc_unchecked(&cp->in_pkts);
101688 goto out;
101689 }
101690
101691@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
101692 else
101693 rc = NF_ACCEPT;
101694 /* do not touch skb anymore */
101695- atomic_inc(&cp->in_pkts);
101696+ atomic_inc_unchecked(&cp->in_pkts);
101697 goto out;
101698 }
101699
101700diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
101701index a4b5e2a..13b1de3 100644
101702--- a/net/netfilter/nf_conntrack_acct.c
101703+++ b/net/netfilter/nf_conntrack_acct.c
101704@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
101705 #ifdef CONFIG_SYSCTL
101706 static int nf_conntrack_acct_init_sysctl(struct net *net)
101707 {
101708- struct ctl_table *table;
101709+ ctl_table_no_const *table;
101710
101711 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
101712 GFP_KERNEL);
101713diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
101714index 75421f2..0e69621 100644
101715--- a/net/netfilter/nf_conntrack_core.c
101716+++ b/net/netfilter/nf_conntrack_core.c
101717@@ -1789,6 +1789,10 @@ void nf_conntrack_init_end(void)
101718 #define DYING_NULLS_VAL ((1<<30)+1)
101719 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
101720
101721+#ifdef CONFIG_GRKERNSEC_HIDESYM
101722+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
101723+#endif
101724+
101725 int nf_conntrack_init_net(struct net *net)
101726 {
101727 int ret = -ENOMEM;
101728@@ -1814,7 +1818,11 @@ int nf_conntrack_init_net(struct net *net)
101729 if (!net->ct.stat)
101730 goto err_pcpu_lists;
101731
101732+#ifdef CONFIG_GRKERNSEC_HIDESYM
101733+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
101734+#else
101735 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
101736+#endif
101737 if (!net->ct.slabname)
101738 goto err_slabname;
101739
101740diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
101741index 1df1761..ce8b88a 100644
101742--- a/net/netfilter/nf_conntrack_ecache.c
101743+++ b/net/netfilter/nf_conntrack_ecache.c
101744@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
101745 #ifdef CONFIG_SYSCTL
101746 static int nf_conntrack_event_init_sysctl(struct net *net)
101747 {
101748- struct ctl_table *table;
101749+ ctl_table_no_const *table;
101750
101751 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
101752 GFP_KERNEL);
101753diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
101754index 5b3eae7..dd4b8fe 100644
101755--- a/net/netfilter/nf_conntrack_helper.c
101756+++ b/net/netfilter/nf_conntrack_helper.c
101757@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
101758
101759 static int nf_conntrack_helper_init_sysctl(struct net *net)
101760 {
101761- struct ctl_table *table;
101762+ ctl_table_no_const *table;
101763
101764 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
101765 GFP_KERNEL);
101766diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
101767index b65d586..beec902 100644
101768--- a/net/netfilter/nf_conntrack_proto.c
101769+++ b/net/netfilter/nf_conntrack_proto.c
101770@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
101771
101772 static void
101773 nf_ct_unregister_sysctl(struct ctl_table_header **header,
101774- struct ctl_table **table,
101775+ ctl_table_no_const **table,
101776 unsigned int users)
101777 {
101778 if (users > 0)
101779diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
101780index f641751..d3c5b51 100644
101781--- a/net/netfilter/nf_conntrack_standalone.c
101782+++ b/net/netfilter/nf_conntrack_standalone.c
101783@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
101784
101785 static int nf_conntrack_standalone_init_sysctl(struct net *net)
101786 {
101787- struct ctl_table *table;
101788+ ctl_table_no_const *table;
101789
101790 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
101791 GFP_KERNEL);
101792diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
101793index 7a394df..bd91a8a 100644
101794--- a/net/netfilter/nf_conntrack_timestamp.c
101795+++ b/net/netfilter/nf_conntrack_timestamp.c
101796@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
101797 #ifdef CONFIG_SYSCTL
101798 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
101799 {
101800- struct ctl_table *table;
101801+ ctl_table_no_const *table;
101802
101803 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
101804 GFP_KERNEL);
101805diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
101806index 85296d4..8becdec 100644
101807--- a/net/netfilter/nf_log.c
101808+++ b/net/netfilter/nf_log.c
101809@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
101810
101811 #ifdef CONFIG_SYSCTL
101812 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
101813-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
101814+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
101815
101816 static int nf_log_proc_dostring(struct ctl_table *table, int write,
101817 void __user *buffer, size_t *lenp, loff_t *ppos)
101818@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
101819 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
101820 mutex_unlock(&nf_log_mutex);
101821 } else {
101822+ ctl_table_no_const nf_log_table = *table;
101823+
101824 mutex_lock(&nf_log_mutex);
101825 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
101826 lockdep_is_held(&nf_log_mutex));
101827 if (!logger)
101828- table->data = "NONE";
101829+ nf_log_table.data = "NONE";
101830 else
101831- table->data = logger->name;
101832- r = proc_dostring(table, write, buffer, lenp, ppos);
101833+ nf_log_table.data = logger->name;
101834+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
101835 mutex_unlock(&nf_log_mutex);
101836 }
101837
101838diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
101839index f042ae5..30ea486 100644
101840--- a/net/netfilter/nf_sockopt.c
101841+++ b/net/netfilter/nf_sockopt.c
101842@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
101843 }
101844 }
101845
101846- list_add(&reg->list, &nf_sockopts);
101847+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
101848 out:
101849 mutex_unlock(&nf_sockopt_mutex);
101850 return ret;
101851@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
101852 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
101853 {
101854 mutex_lock(&nf_sockopt_mutex);
101855- list_del(&reg->list);
101856+ pax_list_del((struct list_head *)&reg->list);
101857 mutex_unlock(&nf_sockopt_mutex);
101858 }
101859 EXPORT_SYMBOL(nf_unregister_sockopt);
101860diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
101861index d292c8d..9f1e166 100644
101862--- a/net/netfilter/nfnetlink_log.c
101863+++ b/net/netfilter/nfnetlink_log.c
101864@@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
101865 struct nfnl_log_net {
101866 spinlock_t instances_lock;
101867 struct hlist_head instance_table[INSTANCE_BUCKETS];
101868- atomic_t global_seq;
101869+ atomic_unchecked_t global_seq;
101870 };
101871
101872 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
101873@@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
101874 /* global sequence number */
101875 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
101876 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
101877- htonl(atomic_inc_return(&log->global_seq))))
101878+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
101879 goto nla_put_failure;
101880
101881 if (data_len) {
101882diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
101883index 8a779be..1551d4c 100644
101884--- a/net/netfilter/nft_compat.c
101885+++ b/net/netfilter/nft_compat.c
101886@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
101887 /* We want to reuse existing compat_to_user */
101888 old_fs = get_fs();
101889 set_fs(KERNEL_DS);
101890- t->compat_to_user(out, in);
101891+ t->compat_to_user((void __force_user *)out, in);
101892 set_fs(old_fs);
101893 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
101894 kfree(out);
101895@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
101896 /* We want to reuse existing compat_to_user */
101897 old_fs = get_fs();
101898 set_fs(KERNEL_DS);
101899- m->compat_to_user(out, in);
101900+ m->compat_to_user((void __force_user *)out, in);
101901 set_fs(old_fs);
101902 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
101903 kfree(out);
101904diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
101905new file mode 100644
101906index 0000000..c566332
101907--- /dev/null
101908+++ b/net/netfilter/xt_gradm.c
101909@@ -0,0 +1,51 @@
101910+/*
101911+ * gradm match for netfilter
101912